GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
CentralWidget.cpp
Go to the documentation of this file.
1#line 2 "src/Gui/CentralWidget.cpp"
2
3#include <Wt/WMenuItem.h>
4#include <Wt/WTabWidget.h>
5#include <Wt/WText.h>
6
7#include "../define.h"
8#include "../App.h"
9#include "../Dbo/Dbo.h"
10
11#ifdef ENABLE_BILLPAY
12#include "BillPay/MainWidget.h"
13#endif
14
15#include "Customer/MainWidget.h"
16#include "EmployeesWidget.h"
17#include "RawTableWidget.h"
18#include "CentralWidget.h"
19
20/*!
21** \brief Central Widget
22**
23** The CentralWidget is the component on the main user interface that
24** acts as a tab widget for being able to select from one tab to
25** another.
26**
27** The first tab is usually the 'accounts' tab. This tab normally cannot
28** be closed. The other tabs open and close on reports or other views
29** as they are requested.
30**
31*/
34{
35 addStyleClass( "CentralWidget" );
36
37 /*
38 ** Always use a layout
39 **
40 */
41 m_gridLayout = setLayout( std::make_unique< Wt::WGridLayout >() );
42// m_gridLayout-> setSpacing( 0 );
43
44 /*
45 ** Build the tab-widget
46 **
47 */
48 m_tabWidget = m_gridLayout-> addWidget( std::make_unique< Wt::WTabWidget >(), 0, 0 );
49
50 /*
51 ** This procedure will ~delete~ the tab and its contents when the tab
52 ** is closed. Normally, on 'close' the tab is only 'hidden' and not
53 ** actually deleted. This prevents the widgets from remaining in
54 ** memory when the tabs are closed.
55 **
56 */
57 tabWidget()->
58 tabClosed().connect( [=]( int tabIndex )
59 {
60 tabWidget()-> removeTab( tabWidget()-> widget( tabIndex ) );
61 });
62
63 /*
64 ** Attach the accounts widget tree view as a non-closeable-tab, so that the
65 ** user can navigate around the accounts.
66 **
67 */
68 {
69 auto widget = std::make_unique< GCW::Gui::AccountsTreeView >( 7 );
71 tabWidget()-> addTab( std::move( widget ), TR( "gcw.AccountsTreeView.tabName" ) );
72
74 }
75
76} // endGCW::CentralWidget::CentralWidget()
77
78auto
81{
82 auto index = tabIndex( TR8( "gcw.AccountsTreeView.tabName" ) );
83
84 if( index != -1 )
85 {
86 tabWidget()-> setCurrentIndex( index );
87 }
88
89} // endactivateAccountsTreeView() const-> void
90
91auto
93tabIndex( const std::string & _text )-> int
94{
95 for( int i=0; i< tabWidget()-> count(); i++ )
96 if( tabWidget()-> tabText( i ) == _text )
97 return i;
98
99 return -1;
100
101} // endtabIndex( const std::string & _text )-> int
102
103auto
105open_AccountRegister( const std::string & _accountGuid )-> void
106{
107 /*!
108 ** \todo handle row selection also
109 **
110 ** This needs to also receive the 'split-guid' of the item
111 ** to jump to.
112 */
113 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
114
115 /*
116 ** Grab the account so we can fetch things from it.
117 */
118 auto accountItem = GCW::Dbo::Accounts::byGuid( _accountGuid );
119
120 /*
121 ** If we didn't get an account (this shouldn't happen) then
122 ** there's nothing for us to do... perhaps pop an error dialog
123 ** or something.
124 **
125 ** \todo add pop-up dialog message here
126 */
127 if( !accountItem )
128 return;
129
130 /*
131 ** See if this tab exists, if not, then add it.
132 */
133 if( tabIndex( accountItem-> name() ) == -1 )
134 {
135 auto u_ = std::make_unique< AccountRegister::Widget >();
136 auto accountRegister = u_.get();
137
138 /*
139 ** on signal jump, open the other account
140 */
141 accountRegister->
142 jumpToAccount()
143 .connect( this, &CentralWidget::open_AccountBySplit );
144
145 /*
146 ** Open a new AccountRegister tab that is connected to the account
147 */
148 auto tab =
149 tabWidget()->
150 insertTab
151 ( 1,
152 std::move( u_ ),
153 accountItem-> name()
154 );
155
156 tabWidget()-> setTabToolTip( 1, fullName( accountItem ) );
157
158 tab-> setCloseable( true );
159
160 accountRegister-> setAccountGuid( _accountGuid );
161
162 } // endif( tabIndex( _account-> name() ) == -1 )
163
164 /*
165 ** Go straight to the tab.
166 */
167 tabWidget()-> setCurrentIndex( tabIndex( accountItem-> name() ) );
168
169} // endopen_AccountRegister( const std::string & _accountGuid )-> void
170
171auto
173open_AccountBySplit( const std::string & _splitGuid )-> void
174{
175 /*
176 ** Grab the split so we can fetch things from it.
177 */
178 auto splitItem = GCW::Dbo::Splits::byGuid( _splitGuid );
179
180 /*
181 ** If we didn't get a split (this shouldn't happen) then
182 ** there's nothing for us to do... perhaps pop an error dialog
183 ** or something.
184 **
185 ** \todo add pop-up dialog message here
186 */
187 if( !splitItem )
188 return;
189
190 /*
191 ** open the register (it automatically becomes 'current')
192 */
193 open_AccountRegister( splitItem-> account_guid() );
194
195 /*
196 ** scroll to the item
197 */
198 currentAccountRegister()-> selectSplit( splitItem-> guid() );
199
200} // endopen_AccountRegister( const std::string & _accountGuid )-> void
201
202auto
205{
206 Gui::AccountRegister::Widget * retVal = dynamic_cast< Gui::AccountRegister::Widget * >( tabWidget()-> widget( tabWidget()-> currentIndex() ) );
207
208 return retVal;
209
210} // endcurrentAccountRegister() const-> Gui::AccountRegister::Widget *
211
212auto
214open_CustomerReportWidget( const std::string & _customerGuid )-> void
215{
216 /*
217 ** Grab the account so we can fetch things from it.
218 */
219 auto customerItem = GCW::Dbo::Customers::byGuid( _customerGuid );
220
221 /*
222 ** If we didn't get a customer (this shouldn't happen) then
223 ** there's nothing for us to do... perhaps pop an error dialog
224 ** or something.
225 */
226 if( !customerItem )
227 return;
228
229 /*
230 ** build a tab name
231 */
232 auto tabName = TR8( "gcw.cw.tabName.Customer" ) + ": " + customerItem-> name();
233
234 /*
235 ** See if this tab exists, if not, then add it.
236 **
237 */
238 if( tabIndex( tabName ) == -1 )
239 {
240 /*
241 ** Open a new CustomerReportWidget tab that is connected to the account.
242 ** When inserting the tab, insert it immediately after the currently
243 ** selected customer.
244 */
245#ifdef NEVER
246 auto tab =
247 tabWidget()->
248 insertTab
249 ( tabWidget()-> currentIndex() + 1,
250 std::make_unique< GCW::Gui::CustomerReportWidget >( _customerGuid ),
251 tabName
252 );
253
254 tab-> setCloseable( true );
255#endif
256
257 } // endif( tabIndex( _account-> name() ) == -1 )
258
259 /*
260 ** Go straight to the tab.
261 */
262 tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
263
264} // endopen_CustomerReportWidget( const std::string & _customerGuid )-> void
265
266auto
269{
270 auto tabName = TR8( "gcw.cw.tabName.Customers" );
271
272 /*
273 ** See if this tab exists, if not, then add it.
274 */
275 if( tabIndex( tabName ) == -1 )
276 {
277 /*
278 ** Open a new CustomersWidget tab that is connected to the account
279 */
280 auto widget = std::make_unique< GCW::Gui::Customer::MainWidget >();
281 auto w = widget.get();
282
283 /*
284 ** Double Clicking on a customer causes the customer report
285 ** widget to open.
286 */
287 w->
288 doubleClicked().connect( [=]( const std::string & _customerGuid )
289 {
290 open_CustomerReportWidget( _customerGuid );
291 });
292
293 auto tab =
294 tabWidget()->
295 insertTab
296 ( 1,
297 std::move( widget ),
298 tabName
299 );
300
301 tab-> setCloseable( true );
302
303 } // endif( tabIndex( _account-> name() ) == -1 )
304
305 /*
306 ** Go straight to the tab.
307 */
308 tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
309
310} // endopen_CustomersWidget()-> void
311
312auto
315{
316 auto tabName = TR8( "gcw.cw.tabName.Employees" );
317
318 /*
319 ** See if this tab exists, if not, then add it.
320 */
321 if( tabIndex( tabName ) == -1 )
322 {
323 /*
324 ** Open a new EmployeesWidget tab that is connected to the account
325 */
326 auto widget = std::make_unique< GCW::Gui::EmployeesWidget >();
327 auto w = widget.get();
328
329 /*
330 ** Double Clicking on a employee causes the customer report
331 ** widget to open.
332 */
333 w->
334 doubleClicked().connect( [=]( const std::string & _customerGuid )
335 {
336 open_EmployeesWidget();
337 });
338
339 auto tab =
340 tabWidget()->
341 insertTab
342 ( 1,
343 std::move( widget ),
344 tabName
345 );
346
347 tab-> setCloseable( true );
348
349 } // endif( tabIndex( _account-> name() ) == -1 )
350
351 /*
352 ** Go straight to the tab.
353 */
354 tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
355
356} // endopen_CustomersWidget()-> void
357
358#ifdef ENABLE_BILLPAY
359auto
361open_BillPayWidget()-> void
362{
363 auto tabName = TR8( "gcw.cw.tabName.BillPay" );
364
365 /*
366 ** See if this tab exists, if not, then add it.
367 */
368 if( tabIndex( tabName ) == -1 )
369 {
370 /*
371 ** Open a new CustomersWidget tab that is connected to the account
372 */
373 auto widget = std::make_unique< GCW::Gui::BillPay::MainWidget >();
374 auto w = widget.get();
375
376 auto tab =
377 tabWidget()->
378 insertTab
379 ( 1,
380 std::move( widget ),
381 tabName
382 );
383
384 tab-> setCloseable( true );
385
386 } // endif( tabIndex( _account-> name() ) == -1 )
387
388 /*
389 ** Go straight to the tab.
390 */
391 tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
392
393} // endopen_BillPayWidget()-> void
394#endif
395
396auto
398open_GeneralJournal()-> void
399{
400 auto tabName = "General Journal";
401
402 /*
403 ** See if this tab exists, if not, then add it.
404 */
405 if( tabIndex( tabName ) == -1 )
406 {
407 auto u_ = std::make_unique< GCW::Gui::AccountRegister::Widget >();
408 auto accountRegister = u_.get();
409
410 auto tab =
411 tabWidget()->
412 insertTab
413 ( 1,
414 std::move( u_ ),
415 tabName
416 );
417
418 tab-> setCloseable( true );
419
420 } // endif( tabIndex( _account-> name() ) == -1 )
421
422 /*
423 ** Go straight to the tab.
424 */
425 tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
426
427} // endopen_TablesWidget()-> void
428
429auto
431open_TablesWidget()-> void
432{
433 auto tabName = "RawTables";
434
435 /*
436 ** See if this tab exists, if not, then add it.
437 */
438 if( tabIndex( tabName ) == -1 )
439 {
440 auto widget = std::make_unique< Wt::WTabWidget >();
441
442 auto tw = widget.get();
443
444 auto tab =
445 tabWidget()->
446 insertTab
447 ( 1,
448 std::move( widget ),
449 tabName
450 );
451
452 tab-> setCloseable( true );
453
454 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Accounts ::Item > >( "accounts" ), "accounts" );
455 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Books ::Item > >( "books" ), "books" );
456 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: BillTerms ::Item > >( "billterms" ), "billterms" );
457 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Commodities ::Item > >( "commodities" ), "commodities" );
458 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Customers ::Item > >( "customers" ), "customers" );
459 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Entries ::Item > >( "entries" ), "entries" );
460 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Employees ::Item > >( "employees" ), "employees" );
461 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: GncLock ::Item > >( "gnclock" ), "gnclock" );
462 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Invoices ::Item > >( "invoices" ), "invoices" );
463 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Jobs ::Item > >( "jobs" ), "jobs" );
464 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Slots ::Item > >( "slots" ), "slots" );
465 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Splits ::Item > >( "splits" ), "splits" );
466 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Transactions ::Item > >( "transactions" ), "transactions" );
467 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Vars ::Item > >( "gcw_vars" ), "gcw_vars" );
468 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Versions ::Item > >( "versions" ), "versions" );
469
470#ifdef NEVER
471 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: BudgetAmounts ::Item > >( "budget" ), "budget" );
472 budgets
473 gcw_identity
474 gcw_info
475 gcw_token
476 gcw_users
477 gcw_vars
478 gnclock
479 lots
480 orders
481 prices
482 recurrences
483 schedxactions
484 taxtable_entries
485 taxtables
486 vendors
487 versions
488#endif
489
490 } // endif( tabIndex( _account-> name() ) == -1 )
491
492 /*
493 ** Go straight to the tab.
494 */
495 tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
496
497} // endopen_TablesWidget()-> void
498
499auto
501test()-> void
502{
503 if( auto registerWidget = dynamic_cast< GCW::Gui::AccountRegister::Widget* >( tabWidget()-> widget( tabWidget()-> currentIndex() ) ) )
504 {
505 registerWidget-> test();
506 }
507
508} // endtest()-> void
509
510
511
auto tabWidget() -> Wt::WTabWidget *
auto open_AccountRegister(const std::string &_accountGuid) -> void
auto open_EmployeesWidget() -> void
auto open_GeneralJournal() -> void
auto activateAccountsTreeView() -> void
GCW::Gui::AccountsTreeView * m_accountsTreeView
auto accountsTreeView() -> GCW::Gui::AccountsTreeView *
Wt::WGridLayout * m_gridLayout
CentralWidget()
Central Widget.
auto open_CustomerReportWidget(const std::string &_customerGuid) -> void
auto open_TablesWidget() -> void
auto open_CustomersWidget() -> void
auto currentAccountRegister() -> Gui::AccountRegister::Widget *
Wt::WTabWidget * m_tabWidget
auto open_AccountBySplit(const std::string &_splitGuid) -> void
Widget * addNew(Args &&...args)
virtual WWidget * widget(int index) const
void setLayout(std::unique_ptr< WLayout > layout)
virtual void addWidget(std::unique_ptr< WWidget > widget)
EventSignal< WMouseEvent > & doubleClicked()
virtual void addStyleClass(const WString &styleClass, bool force=false) override
virtual int tabIndex() const override
#define TR8(X)
Definition define.h:18
#define TR(X)
Definition define.h:17
auto byGuid(const std::string &_guid) -> Item::Ptr
Load Account by GUID.
Item::Ptr byGuid(const std::string &_guid)
Load Customer by Guid.
Definition Customers.cpp:41
auto byGuid(const std::string &_splitGuid) -> Item::Ptr
Load a single split.
Definition Splits.h:331
App * app()
Definition App.cpp:75