GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
RawTableWidget_impl.h
Go to the documentation of this file.
1#line 2 "src/Gui/RawTableWidget_impl.h"
2
3#ifndef __GUI_RAWTABLEWIDGETIMPL_H___
4#define __GUI_RAWTABLEWIDGETIMPL_H___
5
6#include <Wt/WVBoxLayout.h>
7
8template <class C>
10RawTableWidget( const std::string & _viewName )
11{
12 /*
13 ** Look in gcw.css for styling.
14 */
15 addStyleClass( "RawTableWidget_" + _viewName );
16
17 /*
18 ** use a layout manager to install the table view into, so
19 ** that the widget will fit and scroll properly.
20 */
21 auto lw = setLayout( std::make_unique< Wt::WVBoxLayout >() );
22
23 auto tb = std::make_unique< Wt::WToolBar >();
24 m_toolBar = tb.get();
25
26 auto w_ = std::make_unique< Wt::WLineEdit >();
27 m_search = w_.get();
28 m_toolBar-> addWidget( std::move( w_ ), Wt::AlignmentFlag::Left );
29 m_toolBar-> addWidget( std::make_unique< Wt::WText >( "<span style=\"color:red;\">these tables have been designed to facilitate the complete destruction of your database. clicking can ruin your day! use caution!</span>" ) );
30 m_search -> setPlaceholderText( "Search" );
31 m_search -> textInput().connect( this, &RawTableWidget<C>::on_search );
32
33 /*
34 ** Configure the table view.
35 */
36 auto tv = std::make_unique< GCW::Gui::TableView >();
37 m_tableView = tv.get();
38 tableView()-> setSortingEnabled ( true );
39 tableView()-> setAlternatingRowColors ( true );
40 tableView()-> setSelectionBehavior ( Wt::SelectionBehavior::Items );
41 tableView()-> setSelectionMode ( Wt::SelectionMode::Single );
42 tableView()-> setEditTriggers ( Wt::EditTrigger::SingleClicked );
43 tableView()-> setEditOptions ( Wt::EditOption::SingleEditor | Wt::EditOption::SaveWhenClosed );
44
45 auto sb = std::make_unique< Wt::WContainerWidget >();
46 m_statusBar = sb.get();
47
48 lw-> addWidget( std::move( tb ) );
49 lw-> addWidget( std::move( tv ), 1 );
50 lw-> addWidget( std::move( sb ) );
51
52} // endSlotsWidget()
53
54template <class C>
55auto
57load()-> void
58{
60
61 loadData();
62
63 m_statusBar-> addNew< Wt::WText >( Wt::WString( "{1} Rows" ).arg( tableView()-> model()-> rowCount() ) );
64
65} // endload()-> void
66
67template <class C>
68auto
70loadData()-> void
71{
72 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
73
74 auto query =
75 GCW::app()-> gnucashew_session().find< typename C::Item >()
76// .orderBy( "id" )
77 ;
78
79 m_model = std::make_shared< Model >();
80 m_model-> setQuery( query );
81 m_model-> reload();
82 m_model-> addAllFieldsAsColumns();
83
84// m_proxy = std::make_shared< Wt::WSortFilterProxyModel >();
85// m_proxy-> setSourceModel( m_model );
86// m_proxy-> setDynamicSortFilter( true );
87// m_proxy-> setFilterKeyColumn( 0 );
88
89// tableView()-> setModel( m_proxy );
90 tableView()-> setModel( m_model );
91
92} // endloadData()-> void
93
94template <class C>
95auto
97on_search()-> void
98{
99// auto regex = std::make_unique< std::regex >( Wt::WString(".*{1}.*").arg( m_search-> valueText() ).toUTF8() );
100// m_proxy-> invalidate();
101// m_proxy-> setFilterRegExp( std::move( regex ) );
102
103 std::cout << __FILE__ << ":" << __LINE__ << " " << m_search-> valueText() << std::endl;
104
105// auto sql =
106// Wt::WString()
107// .arg()
108// .toUTF8()
109// ;
110
111// auto query =
112// GCW::app()-> gnucashew_session().find( typename C::Item >()
113
114 auto item = std::make_unique< GCW::Dbo::Accounts::Item >();
115// item-> persist( []( GCW::Dbo::Accounts::Item::Ptr _item, const std::string & _name, auto _x ){ } );
116
117#ifdef NEVER
118 {
119 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
120 auto splits =
121 GCW::app()-> gnucashew_session().query< std::string >( "select name from sqlite_master where type = 'table'" )
122 .resultList();
123
124 std::cout << __FILE__ << ":" << __LINE__ << " " << splits.size() << " tables" << std::endl;
125 for( auto tableName : splits )
126 std::cout << __FILE__ << ":" << __LINE__ << " " << tableName << std::endl;
127 }
128#endif
129
130#ifdef NEVER
131 {
132 Wt::Dbo::Transaction t( GCW::app()-> gnucashew_session() );
133 auto splits =
134 GCW::app()-> gnucashew_session().query< std::string >( "select sql from sqlite_master where type = 'table'" )
135 .resultList();
136
137 std::cout << __FILE__ << ":" << __LINE__ << " " << splits.size() << " tables" << std::endl;
138 for( auto tableName : splits )
139 std::cout << __FILE__ << ":" << __LINE__ << " " << tableName << std::endl;
140 }
141#endif
142
143} // endon_search()-> void
144
145#endif // __GUI_RAWTABLEWIDGETIMPL_H___
146
147
RawTableWidget(const std::string &_viewName)
Constructor.
virtual void load() override
App * app()
Definition App.cpp:75