GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
BillPay/MainWidget.cpp
Go to the documentation of this file.
1#line 2 "src/Gui/BillPay/MainWidget.cpp"
2
3#include <Wt/WVBoxLayout.h>
4#include <Wt/WHBoxLayout.h>
5#include <Wt/WTable.h>
6#include <Wt/WPushButton.h>
7
8#include "BillPay.h"
9
12{
13 // identify
14 addStyleClass( "BillPay" );
15 addStyleClass( "MainWidget" );
16
18
19} // endMainWidget()
20
21auto
23buildContent()-> void
24{
25 clear();
26
27 // layout
28 m_hlw = setLayout( std::make_unique< Wt::WHBoxLayout >() );
29
30 m_summaryView = m_hlw-> addWidget( std::make_unique< SummaryWidget >() );
31 m_summaryView-> clicked().connect( this, &MainWidget::summaryClicked );
32 m_hlw-> setResizable( 0, true, Wt::WLength( 20, Wt::LengthUnit::Percentage ) );
33
34 auto cw = m_hlw-> addWidget( std::make_unique< Wt::WContainerWidget >() );
35
36 // toolbar
37 {
38 m_toolBar = cw-> addWidget( std::make_unique< ToolBar >() );
39 m_toolBar -> addClicked () .connect( this, &MainWidget:: do_addClicked );
40 m_toolBar -> editClicked() .connect( this, &MainWidget:: do_editClicked );
41 m_toolBar-> inactiveButton() -> clicked () .connect( this, &MainWidget:: do_inactiveClicked );
42 m_toolBar-> summaryButton () -> clicked () .connect( this, &MainWidget:: do_summaryClicked );
43 m_toolBar-> importClicked () .connect( this, &MainWidget:: importClicked );
44 m_toolBar-> exportClicked () .connect( this, &MainWidget:: exportClicked );
45
46 } // toolbar
47
48 // recall selected month
49 m_selectedMonth = configItem()-> getVarInt( "selectedMonth" );
50 if( m_selectedMonth < 1
51 || m_selectedMonth > 12 )
52 m_selectedMonth = 1;
53
54 // unpaid items
55 {
56 m_unpaidView = cw-> addWidget( std::make_unique< TableView >( m_selectedMonth, Status::Unpaid ) );
57 m_unpaidView->
58 clicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
59 {
60 /*
61 ** remember the clicked index
62 */
63 m_selectedIndex = _index;
64 clearSelectionExcept( m_unpaidView );
65 });
66 m_unpaidView->
67 doubleClicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
68 {
69 clearSelectionExcept( m_unpaidView );
70 editClicked( m_unpaidView, _index );
71 });
72
73 /*
74 ** unpaid items has a header, whereas the other two item-tables do not have a
75 ** header and clicking on the header changes the selected month
76 */
77 m_unpaidView->
78 headerClicked().connect( this, &MainWidget::on_headerClicked );
79
80 } // endunpaid items
81
82 // pending items
83 {
84 m_pendingView = cw-> addWidget( std::make_unique< TableView >( m_selectedMonth, Status::Pending ) );
85 m_pendingView->
86 clicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
87 {
88 /*
89 ** remember the clicked index
90 */
91 m_selectedIndex = _index;
92 clearSelectionExcept( m_pendingView );
93 });
94 m_pendingView->
95 doubleClicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
96 {
97 clearSelectionExcept( m_pendingView );
98 editClicked( m_pendingView, _index );
99 });
100
101 } // endpending items
102
103 // paid items
104 {
105 m_paidView = cw-> addWidget( std::make_unique< TableView >( m_selectedMonth, Status::Paid ) );
106 m_paidView->
107 clicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
108 {
109 /*
110 ** remember the clicked index
111 */
112 m_selectedIndex = _index;
113 clearSelectionExcept( m_paidView );
114 });
115 m_paidView->
116 doubleClicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
117 {
118 clearSelectionExcept( m_paidView );
119 editClicked( m_paidView, _index );
120 });
121
122 } // endpaid items
123
124 // inactive items
125 {
126 m_inactiveView = cw-> addWidget( std::make_unique< TableView >( m_selectedMonth, Status::Inactive ) );
127 m_inactiveView->
128 clicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
129 {
130 /*
131 ** remember the clicked index
132 */
133 m_selectedIndex = _index;
134 clearSelectionExcept( m_inactiveView );
135 });
136 m_inactiveView->
137 doubleClicked().connect( [&]( Wt::WModelIndex _index, Wt::WMouseEvent _event )
138 {
139 clearSelectionExcept( m_inactiveView );
140 editClicked( m_inactiveView, _index );
141 });
142
143 } // endinactive items
144
145 do_summaryClicked();
146
147 refreshViews();
148
149} // endbuildContent()-> void
150
151
152auto
154summaryClicked( const std::string & _itemIdent )-> void
155{
156 m_unpaidView -> selectItem( _itemIdent );
157 m_pendingView -> selectItem( _itemIdent );
158 m_paidView -> selectItem( _itemIdent );
159 m_inactiveView -> selectItem( _itemIdent );
160
161} // endsummaryClicked( const std::string & _txGuid )-> void
162
163
164auto
166clearSelectionExcept( TableView * _view )-> void
167{
168 if( _view != m_unpaidView ) m_unpaidView -> clearSelection();
169 if( _view != m_pendingView ) m_pendingView -> clearSelection();
170 if( _view != m_paidView ) m_paidView -> clearSelection();
171 if( _view != m_inactiveView ) m_inactiveView -> clearSelection();
172
173 wApp-> processEvents();
174
175} // endclearSelectionExcept( TableView * )-> void
176
177
178auto
180openEditor( const std::string & _bpGuid )-> void
181{
182
183 /*
184 ** if the edit widget is open, then we can't do anything.
185 */
186 if( m_editWidget )
187 return;
188
189 /*
190 ** Split the page to open/edit this item
191 **
192 */
193 auto u_ = std::make_unique< GCW::Gui::BillPay::EditWidget >( _bpGuid );
194 m_editWidget = u_.get();
195// m_gridLayout-> addWidget( std::move( u_), 1, 1 );
196// m_gridLayout-> setColumnResizable( 0, true, "30%" );
197
198 m_hlw-> addWidget( std::move( u_ ) );
199 m_hlw-> setResizable( 1, true, Wt::WLength( 20, Wt::LengthUnit::Percentage ) );
200
201 m_editWidget->
202 deleted().connect( [=]()
203 {
204 Wt::WMessageBox::show( TR("gcw.billPay.lbl.billPay"), TR("gcw.not-yet-implemented"), Wt::StandardButton::Ok );
205 });
206
207 m_editWidget->
208 saved().connect( [=]()
209 {
210 refreshViews();
211 m_hlw-> removeWidget( m_editWidget.get() );
212 m_hlw-> setResizable( 1, true, Wt::WLength::Auto );
213 });
214
215 m_editWidget->
216 canceled().connect( [=]()
217 {
218 m_hlw-> removeWidget( m_editWidget.get() );
219 m_hlw-> setResizable( 1, true, Wt::WLength::Auto );
220 });
221
222} // endopenEditor( const std::string & _nickname )-> void
223
224auto
226do_addClicked()-> void
227{
228 addClicked();
229
230} // enddo_addClicked()-> void
231
232auto
234do_editClicked()-> void
235{
236 if( !m_selectedIndex.isValid() )
237 return;
238
239 auto zcolIndex = m_selectedIndex.model()-> index( m_selectedIndex.row(), 0 );
240 auto bpGuid = Wt::asString( zcolIndex.data( Wt::ItemDataRole::User ) ).toUTF8();
241 openEditor( bpGuid );
242
243} // enddo_editClicked()-> void
244
245auto
247addClicked()-> void
248{
249 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
250 openEditor( "" );
251
252} // endaddClicked()-> void
253
254auto
256editClicked( TableView * _table, Wt::WModelIndex _index )-> void
257{
258 /*
259 ** remember the index
260 */
261 m_selectedIndex = _index;
262
263 /*
264 ** Get the 0-col index and use that to get the guid of this
265 ** row, and use that to get the Edit dialog open on that
266 ** guid.
267 */
268 if( _index.isValid() )
269 {
270 auto zcolIndex = _index.model()-> index( _index.row(), 0 );
271 auto bpGuid = Wt::asString( zcolIndex.data( Wt::ItemDataRole::User ) ).toUTF8();
272 openEditor( bpGuid );
273 }
274
275} // endeditClicked( TableView * _table, Wt::WModelIndex _index )-> void
276
277auto
279do_inactiveClicked()-> void
280{
281 if( m_toolBar-> showInactive() )
282 m_inactiveView-> setHidden( false );
283 else
284 m_inactiveView-> setHidden( true );
285
286} // endinactiveClicked()-> void
287
288auto
290do_summaryClicked()-> void
291{
292 if( m_toolBar-> showSummary() )
293 m_summaryView-> setHidden( false );
294 else
295 m_summaryView-> setHidden( true );
296
297// m_summaryView-> setMonth( m_selectedMonth );
298
299} // enddo_summaryClicked()-> void
300
301auto
303setMonth( int _month )-> void
304{
305 m_selectedMonth = _month;
306
307 if( m_unpaidView ) m_unpaidView -> setMonth( _month );
308 if( m_pendingView ) m_pendingView -> setMonth( _month );
309 if( m_paidView ) m_paidView -> setMonth( _month );
310 if( m_inactiveView ) m_inactiveView -> setMonth( _month );
311 if( m_summaryView ) m_summaryView -> setMonth( _month );
312
313 if( m_pendingView-> rowCount() > 0 )
314 m_pendingView-> setHidden( false );
315 else
316 m_pendingView-> setHidden( true );
317
318 if( m_paidView-> rowCount() > 0 )
319 m_paidView-> setHidden( false );
320 else
321 m_paidView-> setHidden( true );
322
323 /*
324 ** BUGBUG: not sure why i tested all of this just to make the same call... weird!
325 */
326// if( m_inactiveView-> rowCount() > 0 )
327// do_inactiveClicked();
328// else
329 do_inactiveClicked();
330
331 /*
332 ** in the words of Spock; "remember"
333 */
334 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
335 configItem().modify()-> setVar( "selectedMonth", m_selectedMonth );
336
337} // endsetMonth( int _month )-> void
338
339auto
341refreshViews()-> void
342{
343 setMonth( m_selectedMonth );
344
345} // endrefreshViews()-> void
346
347auto
349importClicked()-> void
350{
351 std::cout << __FILE__ << ":" << __LINE__ << " " << std::endl;
352
353} // endimportClicked()-> void
354
355auto
357exportClicked()-> void
358{
359 std::cout << __FILE__ << ":" << __LINE__ << " " << std::endl;
360
361} // endexportClicked()-> void
362
363auto
365on_headerClicked( int _col, const Wt::WMouseEvent _me )-> void
366{
367 if( _col >= 9 )
368 setMonth( _col - 8 );
369
370} // endon_headerClicked( int _col, const Wt::WMouseEvent _me )-> void
371
372
auto summaryClicked(const std::string &_txGuid) -> void
auto openEditor(const std::string &_bpGuid) -> void
auto editClicked(TableView *_table, Wt::WModelIndex _index) -> void
auto clearSelectionExcept(TableView *=nullptr) -> void
auto setMonth(int _month) -> void
auto on_headerClicked(int _col, const Wt::WMouseEvent _me) -> void
static constexpr const int User
static WLength Auto
std::string toUTF8() const
virtual void addStyleClass(const WString &styleClass, bool force=false) override
#define TR(X)
Definition define.h:17
WString asString(const cpp17::any &v, const WString &formatString=WString())
@ Pending
Pending Status.
@ Inactive
Disabled Status.
@ Unpaid
Unpaid Status.
auto configItem() -> GCW::Dbo::Vars::Item::Ptr
Config Item.
Definition BillPay.cpp:7
App * app()
Definition App.cpp:75