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::Right );
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
91} // endloadData()-> void
92
93template <class C>
94auto
96on_search()-> void
97{
98 auto regex = std::make_unique< std::regex >( Wt::WString(".*{1}.*").arg( m_search-> valueText() ).toUTF8() );
99 m_proxy-> invalidate();
100 m_proxy-> setFilterRegExp( std::move( regex ) );
101
102} // endon_search()-> void
103
104#endif // __GUI_RAWTABLEWIDGETIMPL_H___
105
106
RawTableWidget(const std::string &_viewName)
Constructor.
virtual void load() override
App * app()
Definition App.cpp:75