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_AccountRegister );
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
174{
175 Gui::AccountRegister::Widget * retVal = dynamic_cast< Gui::AccountRegister::Widget * >( tabWidget()-> widget( tabWidget()-> currentIndex() ) );
176
177 return retVal;
178
179} // endcurrentAccountRegister() const-> Gui::AccountRegister::Widget *
180
181auto
183open_CustomerReportWidget( const std::string & _customerGuid )-> void
184{
185 /*
186 ** Grab the account so we can fetch things from it.
187 */
188 auto customerItem = GCW::Dbo::Customers::byGuid( _customerGuid );
189
190 /*
191 ** If we didn't get a customer (this shouldn't happen) then
192 ** there's nothing for us to do... perhaps pop an error dialog
193 ** or something.
194 */
195 if( !customerItem )
196 return;
197
198 /*
199 ** build a tab name
200 */
201 auto tabName = TR8( "gcw.cw.tabName.Customer" ) + ": " + customerItem-> name();
202
203 /*
204 ** See if this tab exists, if not, then add it.
205 **
206 */
207 if( tabIndex( tabName ) == -1 )
208 {
209 /*
210 ** Open a new CustomerReportWidget tab that is connected to the account.
211 ** When inserting the tab, insert it immediately after the currently
212 ** selected customer.
213 */
214#ifdef NEVER
215 auto tab =
216 tabWidget()->
217 insertTab
218 ( tabWidget()-> currentIndex() + 1,
219 std::make_unique< GCW::Gui::CustomerReportWidget >( _customerGuid ),
220 tabName
221 );
222
223 tab-> setCloseable( true );
224#endif
225
226 } // endif( tabIndex( _account-> name() ) == -1 )
227
228 /*
229 ** Go straight to the tab.
230 */
231 tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
232
233} // endopen_CustomerReportWidget( const std::string & _customerGuid )-> void
234
235auto
238{
239 auto tabName = TR8( "gcw.cw.tabName.Customers" );
240
241 /*
242 ** See if this tab exists, if not, then add it.
243 */
244 if( tabIndex( tabName ) == -1 )
245 {
246 /*
247 ** Open a new CustomersWidget tab that is connected to the account
248 */
249 auto widget = std::make_unique< GCW::Gui::Customer::MainWidget >();
250 auto w = widget.get();
251
252 /*
253 ** Double Clicking on a customer causes the customer report
254 ** widget to open.
255 */
256 w->
257 doubleClicked().connect( [=]( const std::string & _customerGuid )
258 {
259 open_CustomerReportWidget( _customerGuid );
260 });
261
262 auto tab =
263 tabWidget()->
264 insertTab
265 ( 1,
266 std::move( widget ),
267 tabName
268 );
269
270 tab-> setCloseable( true );
271
272 } // endif( tabIndex( _account-> name() ) == -1 )
273
274 /*
275 ** Go straight to the tab.
276 */
277 tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
278
279} // endopen_CustomersWidget()-> void
280
281auto
284{
285 auto tabName = TR8( "gcw.cw.tabName.Employees" );
286
287 /*
288 ** See if this tab exists, if not, then add it.
289 */
290 if( tabIndex( tabName ) == -1 )
291 {
292 /*
293 ** Open a new EmployeesWidget tab that is connected to the account
294 */
295 auto widget = std::make_unique< GCW::Gui::EmployeesWidget >();
296 auto w = widget.get();
297
298 /*
299 ** Double Clicking on a employee causes the customer report
300 ** widget to open.
301 */
302 w->
303 doubleClicked().connect( [=]( const std::string & _customerGuid )
304 {
305 open_EmployeesWidget();
306 });
307
308 auto tab =
309 tabWidget()->
310 insertTab
311 ( 1,
312 std::move( widget ),
313 tabName
314 );
315
316 tab-> setCloseable( true );
317
318 } // endif( tabIndex( _account-> name() ) == -1 )
319
320 /*
321 ** Go straight to the tab.
322 */
323 tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
324
325} // endopen_CustomersWidget()-> void
326
327#ifdef ENABLE_BILLPAY
328auto
330open_BillPayWidget()-> void
331{
332 auto tabName = TR8( "gcw.cw.tabName.BillPay" );
333
334 /*
335 ** See if this tab exists, if not, then add it.
336 */
337 if( tabIndex( tabName ) == -1 )
338 {
339 /*
340 ** Open a new CustomersWidget tab that is connected to the account
341 */
342 auto widget = std::make_unique< GCW::Gui::BillPay::MainWidget >();
343 auto w = widget.get();
344
345 auto tab =
346 tabWidget()->
347 insertTab
348 ( 1,
349 std::move( widget ),
350 tabName
351 );
352
353 tab-> setCloseable( true );
354
355 } // endif( tabIndex( _account-> name() ) == -1 )
356
357 /*
358 ** Go straight to the tab.
359 */
360 tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
361
362} // endopen_BillPayWidget()-> void
363#endif
364
365auto
367open_GeneralJournal()-> void
368{
369 auto tabName = "General Journal";
370
371 /*
372 ** See if this tab exists, if not, then add it.
373 */
374 if( tabIndex( tabName ) == -1 )
375 {
376 auto u_ = std::make_unique< GCW::Gui::AccountRegister::Widget >();
377 auto accountRegister = u_.get();
378
379 auto tab =
380 tabWidget()->
381 insertTab
382 ( 1,
383 std::move( u_ ),
384 tabName
385 );
386
387 tab-> setCloseable( true );
388
389 } // endif( tabIndex( _account-> name() ) == -1 )
390
391 /*
392 ** Go straight to the tab.
393 */
394 tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
395
396} // endopen_TablesWidget()-> void
397
398auto
400open_TablesWidget()-> void
401{
402 auto tabName = "RawTables";
403
404 /*
405 ** See if this tab exists, if not, then add it.
406 */
407 if( tabIndex( tabName ) == -1 )
408 {
409 auto widget = std::make_unique< Wt::WTabWidget >();
410
411 auto tw = widget.get();
412
413 auto tab =
414 tabWidget()->
415 insertTab
416 ( 1,
417 std::move( widget ),
418 tabName
419 );
420
421 tab-> setCloseable( true );
422
423 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Accounts ::Item > >( "accounts" ), "accounts" );
424 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Books ::Item > >( "books" ), "books" );
425 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: BillTerms ::Item > >( "billterms" ), "billterms" );
426 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Commodities ::Item > >( "commodities" ), "commodities" );
427 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Customers ::Item > >( "customers" ), "customers" );
428 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Entries ::Item > >( "entries" ), "entries" );
429 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Employees ::Item > >( "employees" ), "employees" );
430 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: GncLock ::Item > >( "gnclock" ), "gnclock" );
431 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Invoices ::Item > >( "invoices" ), "invoices" );
432 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Jobs ::Item > >( "jobs" ), "jobs" );
433 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Slots ::Item > >( "slots" ), "slots" );
434 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Splits ::Item > >( "splits" ), "splits" );
435 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Transactions ::Item > >( "transactions" ), "transactions" );
436 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Vars ::Item > >( "gcw_vars" ), "gcw_vars" );
437 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Versions ::Item > >( "versions" ), "versions" );
438
439#ifdef NEVER
440 tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: BudgetAmounts ::Item > >( "budget" ), "budget" );
441 budgets
442 gcw_identity
443 gcw_info
444 gcw_token
445 gcw_users
446 gcw_vars
447 gnclock
448 lots
449 orders
450 prices
451 recurrences
452 schedxactions
453 taxtable_entries
454 taxtables
455 vendors
456 versions
457#endif
458
459 } // endif( tabIndex( _account-> name() ) == -1 )
460
461 /*
462 ** Go straight to the tab.
463 */
464 tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
465
466} // endopen_TablesWidget()-> void
467
468auto
470test()-> void
471{
472 if( auto registerWidget = dynamic_cast< GCW::Gui::AccountRegister::Widget* >( tabWidget()-> widget( tabWidget()-> currentIndex() ) ) )
473 {
474 registerWidget-> test();
475 }
476
477} // endtest()-> void
478
479
480
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
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
App * app()
Definition App.cpp:75