GnuCashew ~ GnuCash Enabled Web
GCW
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/Accounts/Accounts.h"
10 #include "../Dbo/BillTerms/BillTerms.h"
11 #include "../Dbo/Books/Books.h"
12 #include "../Dbo/Customers/Customers.h"
13 #include "../Dbo/Commodities/Commodities.h"
14 #include "../Dbo/Entries/Entries.h"
15 #include "../Dbo/GncLock/GncLock.h"
16 #include "../Dbo/Invoices/Invoices.h"
17 #include "../Dbo/Slots/Slots.h"
18 #include "../Dbo/Splits/Splits.h"
19 #include "../Dbo/Transactions/Transactions.h"
20 #include "../Dbo/Versions/Versions.h"
21 #include "BillPay/MainWidget.h"
22 #include "Customer/MainWidget.h"
23 #include "CentralWidget.h"
24 #include "EmployeesWidget.h"
25 #include "RawTableWidget.h"
26 
27 /*!
28 ** \brief Central Widget
29 **
30 ** The CentralWidget is the component on the main user interface that
31 ** acts as a tab widget for being able to select from one tab to
32 ** another.
33 **
34 ** The first tab is usually the 'accounts' tab. This tab normally cannot
35 ** be closed. The other tabs open and close on reports or other views
36 ** as they are requested.
37 **
38 */
41 {
42  addStyleClass( "CentralWidget" );
43 
44  /*
45  ** Always use a layout
46  **
47  */
48  m_gridLayout = setLayout( std::make_unique< Wt::WGridLayout >() );
49 // m_gridLayout-> setSpacing( 0 );
50 
51  /*
52  ** Build the tab-widget
53  **
54  */
55  m_tabWidget = m_gridLayout-> addWidget( std::make_unique< Wt::WTabWidget >(), 0, 0 );
56 
57  /*
58  ** This procedure will ~delete~ the tab and its contents when the tab
59  ** is closed. Normally, on 'close' the tab is only 'hidden' and not
60  ** actually deleted. This prevents the widgets from remaining in
61  ** memory when the tabs are closed.
62  **
63  */
64  tabWidget()->
65  tabClosed().connect( [=]( int tabIndex )
66  {
67  tabWidget()-> removeTab( tabWidget()-> widget( tabIndex ) );
68  });
69 
70  /*
71  ** Attach the accounts widget tree view as a non-closeable-tab, so that the
72  ** user can navigate around the accounts.
73  **
74  */
75  {
76  auto widget = std::make_unique< GCW::Gui::AccountsTreeView >( 7 );
77  m_accountsTreeView = widget.get();
78  tabWidget()-> addTab( std::move( widget ), TR( "gcw.AccountsTreeView.tabName" ) );
79 
80  accountsTreeView()-> doubleClicked().connect( this, &GCW::Gui::CentralWidget::open_AccountRegister );
81  }
82 
83 } // endGCW::CentralWidget::CentralWidget()
84 
85 auto
87 tabIndex( const std::string & _text )-> int
88 {
89  for( int i=0; i< tabWidget()-> count(); i++ )
90  if( tabWidget()-> tabText( i ) == _text )
91  return i;
92 
93  return -1;
94 
95 } // endtabIndex( const std::string & _text )-> int
96 
97 auto
99 open_AccountRegister( const std::string & _accountGuid )-> void
100 {
101  Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
102 
103  /*
104  ** Grab the account so we can fetch things from it.
105  **
106  */
107  auto accountItem = GCW::Dbo::Accounts::byGuid( _accountGuid );
108 
109  /*
110  ** If we didn't get an account (this shouldn't happen) then
111  ** there's nothing for us to do... perhaps pop an error dialog
112  ** or something.
113  **
114  ** \todo add pop-up dialog message here
115  */
116  if( !accountItem )
117  return;
118 
119  /*
120  ** See if this tab exists, if not, then add it.
121  **
122  */
123  if( tabIndex( accountItem-> name() ) == -1 )
124  {
125  auto u_ = std::make_unique< GCW::Gui::AccountRegister >( _accountGuid );
126  auto accountRegister = u_.get();
127 
128  /*
129  ** Open a new AccountRegister tab that is connected to the account
130  **
131  */
132  auto tab =
133  tabWidget()->
134  insertTab
135  ( 1,
136  std::move( u_ ),
137  accountItem-> name()
138  );
139 
140  tabWidget()-> setTabToolTip( 1, fullName( accountItem ) );
141 
142  tab-> setCloseable( true );
143 
144  accountRegister-> setAccountGuid( _accountGuid );
145 
146  } // endif( tabIndex( _account-> name() ) == -1 )
147 
148  /*
149  ** Go straight to the tab.
150  **
151  */
152  tabWidget()-> setCurrentIndex( tabIndex( accountItem-> name() ) );
153 
154 } // endopen_AccountRegister( const std::string & _accountGuid )-> void
155 
156 auto
158 open_CustomerReportWidget( const std::string & _customerGuid )-> void
159 {
160  /*
161  ** Grab the account so we can fetch things from it.
162  **
163  */
164  auto customerItem = GCW::Dbo::Customers::byGuid( _customerGuid );
165 
166  /*
167  ** If we didn't get a customer (this shouldn't happen) then
168  ** there's nothing for us to do... perhaps pop an error dialog
169  ** or something.
170  **
171  */
172  if( !customerItem )
173  return;
174 
175  /*
176  ** build a tab name
177  **
178  */
179  auto tabName = TR8( "gcw.cw.tabName.Customer" ) + ": " + customerItem-> name();
180 
181  /*
182  ** See if this tab exists, if not, then add it.
183  **
184  */
185  if( tabIndex( tabName ) == -1 )
186  {
187  /*
188  ** Open a new CustomerReportWidget tab that is connected to the account.
189  ** When inserting the tab, insert it immediately after the currently
190  ** selected customer.
191  **
192  */
193 #ifdef NEVER
194  auto tab =
195  tabWidget()->
196  insertTab
197  ( tabWidget()-> currentIndex() + 1,
198  std::make_unique< GCW::Gui::CustomerReportWidget >( _customerGuid ),
199  tabName
200  );
201 
202  tab-> setCloseable( true );
203 #endif
204 
205  } // endif( tabIndex( _account-> name() ) == -1 )
206 
207  /*
208  ** Go straight to the tab.
209  **
210  */
211  tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
212 
213 } // endopen_CustomerReportWidget( const std::string & _customerGuid )-> void
214 
215 auto
217 open_CustomersWidget()-> void
218 {
219  auto tabName = TR8( "gcw.cw.tabName.Customers" );
220 
221  /*
222  ** See if this tab exists, if not, then add it.
223  **
224  */
225  if( tabIndex( tabName ) == -1 )
226  {
227  /*
228  ** Open a new CustomersWidget tab that is connected to the account
229  **
230  */
231  auto widget = std::make_unique< GCW::Gui::Customer::MainWidget >();
232  auto w = widget.get();
233 
234  /*
235  ** Double Clicking on a customer causes the customer report
236  ** widget to open.
237  **
238  */
239  w->
240  doubleClicked().connect( [=]( const std::string & _customerGuid )
241  {
242  open_CustomerReportWidget( _customerGuid );
243  });
244 
245  auto tab =
246  tabWidget()->
247  insertTab
248  ( 1,
249  std::move( widget ),
250  tabName
251  );
252 
253  tab-> setCloseable( true );
254 
255  } // endif( tabIndex( _account-> name() ) == -1 )
256 
257  /*
258  ** Go straight to the tab.
259  **
260  */
261  tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
262 
263 } // endopen_CustomersWidget()-> void
264 
265 auto
267 open_EmployeesWidget()-> void
268 {
269  auto tabName = TR8( "gcw.cw.tabName.Employees" );
270 
271  /*
272  ** See if this tab exists, if not, then add it.
273  **
274  */
275  if( tabIndex( tabName ) == -1 )
276  {
277  /*
278  ** Open a new EmployeesWidget tab that is connected to the account
279  **
280  */
281  auto widget = std::make_unique< GCW::Gui::EmployeesWidget >();
282  auto w = widget.get();
283 
284  /*
285  ** Double Clicking on a employee causes the customer report
286  ** widget to open.
287  **
288  */
289  w->
290  doubleClicked().connect( [=]( const std::string & _customerGuid )
291  {
292  open_EmployeesWidget();
293  });
294 
295  auto tab =
296  tabWidget()->
297  insertTab
298  ( 1,
299  std::move( widget ),
300  tabName
301  );
302 
303  tab-> setCloseable( true );
304 
305  } // endif( tabIndex( _account-> name() ) == -1 )
306 
307  /*
308  ** Go straight to the tab.
309  **
310  */
311  tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
312 
313 } // endopen_CustomersWidget()-> void
314 
315 auto
317 open_BillPayWidget()-> void
318 {
319  auto tabName = TR8( "gcw.cw.tabName.BillPay" );
320 
321  /*
322  ** See if this tab exists, if not, then add it.
323  **
324  */
325  if( tabIndex( tabName ) == -1 )
326  {
327  /*
328  ** Open a new CustomersWidget tab that is connected to the account
329  **
330  */
331  auto widget = std::make_unique< GCW::Gui::BillPay::MainWidget >();
332  auto w = widget.get();
333 
334  auto tab =
335  tabWidget()->
336  insertTab
337  ( 1,
338  std::move( widget ),
339  tabName
340  );
341 
342  tab-> setCloseable( true );
343 
344  } // endif( tabIndex( _account-> name() ) == -1 )
345 
346  /*
347  ** Go straight to the tab.
348  **
349  */
350  tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
351 
352 } // endopen_BillPayWidget()-> void
353 
354 auto
356 open_TablesWidget()-> void
357 {
358  auto tabName = "RawTables";
359 
360  /*
361  ** See if this tab exists, if not, then add it.
362  **
363  */
364  if( tabIndex( tabName ) == -1 )
365  {
366  auto widget = std::make_unique< Wt::WTabWidget >();
367 
368  auto tw = widget.get();
369 
370  auto tab =
371  tabWidget()->
372  insertTab
373  ( 1,
374  std::move( widget ),
375  tabName
376  );
377 
378  tab-> setCloseable( true );
379 
380  tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Accounts ::Item > >( "accounts" ), "accounts" );
381  tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Books ::Item > >( "books" ), "books" );
382  tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: BillTerms ::Item > >( "billterms" ), "billterms" );
383  tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Commodities ::Item > >( "commodities" ), "commodities" );
384  tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Customers ::Item > >( "customers" ), "customers" );
385  tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Entries ::Item > >( "entries" ), "entries" );
386  tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: GncLock ::Item > >( "gnclock" ), "gnclock" );
387  tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Invoices ::Item > >( "invoices" ), "invoices" );
388  tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Slots ::Item > >( "slots" ), "slots" );
389  tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Splits ::Item > >( "splits" ), "splits" );
390  tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Transactions ::Item > >( "transactions" ), "transactions" );
391  tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Vars ::Item > >( "vars" ), "vars" );
392  tw-> addTab( std::make_unique< GCW::Gui::RawTableWidget< typename GCW::Dbo:: Versions ::Item > >( "versions" ), "versions" );
393 
394  } // endif( tabIndex( _account-> name() ) == -1 )
395 
396  /*
397  ** Go straight to the tab.
398  **
399  */
400  tabWidget()-> setCurrentIndex( tabIndex( tabName ) );
401 
402 } // endopen_TablesWidget()-> void
403 
404 auto
406 test()-> void
407 {
408  if( auto registerWidget = dynamic_cast< GCW::Gui::AccountRegister* >( tabWidget()-> widget( tabWidget()-> currentIndex() ) ) )
409  {
410  registerWidget-> test();
411  }
412 
413 } // endtest()-> void
414 
415 
416 
auto tabWidget() -> Wt::WTabWidget *
Definition: CentralWidget.h:36
auto open_BillPayWidget() -> void
auto open_AccountRegister(const std::string &_accountGuid) -> void
auto open_EmployeesWidget() -> void
GCW::Gui::AccountsTreeView * m_accountsTreeView
Definition: CentralWidget.h:68
auto tabIndex(const std::string &_text) -> int
Index of Tab matching 'text'.
auto accountsTreeView() -> GCW::Gui::AccountsTreeView *
Definition: CentralWidget.h:37
Wt::WGridLayout * m_gridLayout
Definition: CentralWidget.h:66
CentralWidget()
Central Widget.
auto open_CustomerReportWidget(const std::string &_customerGuid) -> void
auto open_TablesWidget() -> void
auto open_CustomersWidget() -> void
Wt::WTabWidget * m_tabWidget
Definition: CentralWidget.h:67
#define TR8(X)
Definition: define.h:18
#define TR(X)
Definition: define.h:17
const Wt::WFormModel::Field name
Definition: Accounts.cpp:47
auto byGuid(const std::string &_guid) -> Item::Ptr
Load Account by GUID.
Definition: Accounts.cpp:162
auto fullName(const std::string &_guid) -> std::string
Account Fullname via GUID.
Definition: Accounts.cpp:282
Item::Ptr byGuid(const std::string &_guid)
Load Customer by Guid.
Definition: Customers.cpp:41
App * app()
Definition: App.cpp:67