GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
Editor.cpp
Go to the documentation of this file.
1#line 2 "src/Gui/AccountRegister/Editor.cpp"
2
3#include <Wt/WDateEdit.h>
4#include <Wt/WPushButton.h>
5#include <Wt/WSuggestionPopup.h>
6#include <Wt/WText.h>
7#include <Wt/WTableView.h>
8#include <Wt/WTheme.h>
9#include <Wt/WVBoxLayout.h>
10#include <Wt/WHBoxLayout.h>
11#include <Wt/WMessageBox.h>
12
13#include "../define.h"
14#include "../App.h"
15#include "../Dbo/Accounts/Accounts.h"
16#include "../Dbo/Prefrences.h"
17#include "../Dbo/Splits/Splits.h"
18#include "../Eng/TransactionManager.h"
19#include "DelegateBase.h"
20#include "DelegateAccount.h"
21#include "DelegateBalance.h"
22#include "DelegateDate.h"
23#include "DelegateHeader.h"
24#include "DelegateReconcile.h"
25#include "DelegateSuggestion.h"
26#include "DelegateValue.h"
27#include "SuggestionPopup.h"
28#include "Editor.h"
29
30/* * * * * * * * * * * * * * * * * * * * * * * * * * */
31/* * * * * * * * * * * * * * * * * * * * * * * * * * */
32
33
35Editor()
36{
37} // endAccountRegisterEditor()
38
40Editor( GCW::Gui::TableView * _tableView )
41: m_tableView( _tableView )
42{
43} // endEditor( GCW::Gui::TableView * _tableView )
44
45
46auto
48model( Wt::WModelIndex _index )-> Model *
49{
50 return
51 const_cast< Model * >( static_cast< const Model* >( _index.model() ) );
52
53} // endmodel( Wt::WModelIndex _index )-> Model *
54
55auto
57delegateHeader()-> std::shared_ptr< DelegateHeader >
58{
59 return
60 std::static_pointer_cast< DelegateHeader >
61 (
62 tableView()-> headerItemDelegate()
63 );
64}
65
66auto
68delegateDate()-> std::shared_ptr< DelegateDate >
69{
70 return
71 std::static_pointer_cast< DelegateDate >
72 (
73 tableView()-> itemDelegateForColumn( asInt( Col::DATE ) )
74 );
75}
76
77auto
79delegateNum()-> std::shared_ptr< DelegateSuggestion >
80{
81 return
82 std::static_pointer_cast< DelegateSuggestion >
83 (
84 tableView()-> itemDelegateForColumn( asInt( Col::ACTION ) )
85 );
86}
87
88auto
90delegateMemo()-> std::shared_ptr< DelegateSuggestion >
91{
92 return
93 std::static_pointer_cast< DelegateSuggestion >
94 (
95 tableView()-> itemDelegateForColumn( asInt( Col::DESCRIPTION ) )
96 );
97}
98
99auto
101delegateAcct()-> std::shared_ptr< DelegateAccount >
102{
103 return
104 std::static_pointer_cast< DelegateAccount >
105 (
106 tableView()-> itemDelegateForColumn( asInt( Col::TRANSFER ) )
107 );
108}
109
110auto
112delegateReco()-> std::shared_ptr< DelegateReconcile >
113{
114 return
115 std::static_pointer_cast< DelegateReconcile >
116 (
117 tableView()-> itemDelegateForColumn( asInt( Col::RECONCILE ) )
118 );
119}
120
121auto
123delegateDr()-> std::shared_ptr< DelegateValue >
124{
125 return
126 std::static_pointer_cast< DelegateValue >
127 (
128 tableView()-> itemDelegateForColumn( asInt( Col::DEBIT ) )
129 );
130}
131
132auto
134delegateCr()-> std::shared_ptr< DelegateValue >
135{
136 return
137 std::static_pointer_cast< DelegateValue >
138 (
139 tableView()-> itemDelegateForColumn( asInt( Col::CREDIT ) )
140 );
141}
142
143auto
145delegateBal()-> std::shared_ptr< DelegateBalance >
146{
147 return
148 std::static_pointer_cast< DelegateBalance >
149 (
150 tableView()-> itemDelegateForColumn( asInt( Col::BALANCE ) )
151 );
152}
153
154auto
156applyDelegates( GCW::Gui::TableView * _tableView )-> void
157{
158 _tableView-> setHeaderItemDelegate ( std::make_shared< DelegateHeader >() );
159 _tableView-> setItemDelegateForColumn ( asInt( Col::DATE ), std::make_shared< DelegateDate >() );
160 _tableView-> setItemDelegateForColumn ( asInt( Col::ACTION ), std::make_shared< DelegateSuggestion >() );
161 _tableView-> setItemDelegateForColumn ( asInt( Col::DESCRIPTION ), std::make_shared< DelegateSuggestion >() );
162 _tableView-> setItemDelegateForColumn ( asInt( Col::TRANSFER ), std::make_shared< DelegateAccount >() );
163 _tableView-> setItemDelegateForColumn ( asInt( Col::RECONCILE ), std::make_shared< DelegateReconcile >() );
164 _tableView-> setItemDelegateForColumn ( asInt( Col::DEBIT ), std::make_shared< DelegateValue >() );
165 _tableView-> setItemDelegateForColumn ( asInt( Col::CREDIT ), std::make_shared< DelegateValue >() );
166 _tableView-> setItemDelegateForColumn ( asInt( Col::BALANCE ), std::make_shared< DelegateBalance >() );
167
168} // endapplyDelegates( GCW::Gui::TableView * _tableView )-> void
169
170auto
172editRow( Wt::WModelIndex _index )-> void
173{
174 std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << "(" << _index.row() << "," << _index.column() << ")" << std::endl;
175
176 auto row = _index.row();
177 auto mdl = model( _index );
178
179 /*
180 ** edit all the columns
181 */
182 for( int col=0; col< mdl-> columnCount(); col++ )
183 {
184 auto item = mdl-> item( row, col );
185 auto index = mdl-> indexFromItem( item );
186
187 item-> setFlags( Wt::ItemFlag::Editable );
188 m_tableView-> edit( index );
189
190 } // for( ..all columns except balance.. )
191
192 return;
193
194#ifndef NEVER
195 if( _index.isValid() )
196 {
197 std::cout << __FILE__ << ":" << __LINE__
198 << " " << __FUNCTION__ << "(" << _index.row() << "," << _index.column() << ")"
199 << std::endl;
200 }
201#endif
202
203 /*
204 ** before editing the row, ask if the user wants to
205 ** save the existing row
206 */
207 if( m_index.isValid() )
208 {
209 if( m_index.row() != _index.row() )
210 {
211
212
213
214// Wt::WMessageBox::show( "Data Changed", "Do you want to record these changes?", Wt::StandardButton::Yes | Wt::StandardButton::No );
215 }
216 }
217
218 if( _index.isValid() )
219 {
220 /*
221 ** if more than one other row is selected (should NEVER happen!)
222 ** then for sure we'll clear any selections. But, if the row
223 ** number is the same, then we don't want to clear, since it's
224 ** the same row.
225 */
226 if( tableView()-> selectedIndexes().size() > 1
227 || tableView()-> selectedIndexes().begin()-> row() != _index.row()
228 )
229 {
230 tableView()-> clearSelection();
231 tableView()-> closeEditors( true );
232 }
233
234 /*
235 ** make sure it is in view.
236 */
237 tableView()-> scrollTo( _index );
238
239 for( int column=0; column< tableView()-> model()-> columnCount(); column++ )
240 {
241 tableView()-> edit( tableView()-> model()-> index( _index.row(), column ) );
242 }
243
244 } // endif( _index.isValid() )
245
246 /*
247 ** remember what we're editing
248 */
249 m_index = _index;
250
251} // endeditRow( Wt::WModelIndex _index )-> void
252
253
254auto
256setDirty( Wt::WModelIndex _index ) const-> void
257{
258 std::cout << __FILE__ << ":" << __LINE__ << " " << std::endl;
259#ifdef NEVER
260 std::cout << __FILE__ << ":" << __LINE__ << " " << _index.isValid() << std::endl;
261
262 std::cout << __FILE__ << ":" << __LINE__ << " " << m_index.isValid() << std::endl;
263
264 std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__
265 << "(): " << m_index.isValid()
266 << "(): " << _index.row()
267 << std::endl;
268#endif
269
270} // endsetDirty( Wt::WModelIndex _index )-> void
271
272
auto delegateNum() -> std::shared_ptr< DelegateSuggestion >
Definition Editor.cpp:79
auto delegateMemo() -> std::shared_ptr< DelegateSuggestion >
Definition Editor.cpp:90
auto model(Wt::WModelIndex _index) -> Model *
Definition Editor.cpp:48
auto setDirty(Wt::WModelIndex _index) const -> void
Definition Editor.cpp:256
auto delegateDate() -> std::shared_ptr< DelegateDate >
Definition Editor.cpp:68
auto delegateCr() -> std::shared_ptr< DelegateValue >
Definition Editor.cpp:134
auto editRow(Wt::WModelIndex _index) -> void
Edit Row.
Definition Editor.cpp:172
auto delegateBal() -> std::shared_ptr< DelegateBalance >
Definition Editor.cpp:145
auto delegateHeader() -> std::shared_ptr< DelegateHeader >
Delegate Handles.
Definition Editor.cpp:57
auto delegateDr() -> std::shared_ptr< DelegateValue >
Definition Editor.cpp:123
auto delegateAcct() -> std::shared_ptr< DelegateAccount >
Definition Editor.cpp:101
auto delegateReco() -> std::shared_ptr< DelegateReconcile >
Definition Editor.cpp:112
static auto applyDelegates(GCW::Gui::TableView *_tableView) -> void
Apply Delegates.
Definition Editor.cpp:156
Account Register Model.
Definition Model.h:30
Custom Table View Class.
Definition TableView.h:25
constexpr int asInt(Col col) noexcept
Definition ViewMode.h:67