GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
Model.h
Go to the documentation of this file.
1#line 2 "src/Gui/AccountRegister/Model.h"
2
3#ifndef __ENG_ACCOUNTREGISTER_MODEL_H___
4#define __ENG_ACCOUNTREGISTER_MODEL_H___
5
6#include <Wt/WDateTime.h>
7#include <Wt/WStandardItemModel.h>
8
9#include "../Glb/gcwglobal.h"
10#include "ViewMode.h"
11
12namespace GCW {
13 namespace Eng {
14 namespace Transaction {
15 class Manager;
16 } // endnamespace Transaction {
17 } // endnamespace Eng {
18
19 namespace Gui {
20 namespace AccountRegister {
21
22/*!
23** \brief Account Register Model
24**
25** This model is used to present account details to the 'editor register' (the spreadsheet-looking
26** book-like-looking thing that the user posts transactions through.
27*/
28class Model
30{
32 : public std::vector< std::unique_ptr< Wt::WStandardItem > >
33 {
35 {
36 /// empty row, used for nothing, undefined (shouldn't happen?)
37 EmptyRow = 0x00,
38
39 /// blank row, used for doubleLine
40 BlankRow = 0x01,
41
42 /// basic Ledger row, everything on one line
43 BasicRow = 0x02,
44
45 /// split Ledger row, multiple lines follow
46 SplitRow = 0x03,
47
48 /// one of the split lines following SplitRow
49 SplitLine = 0x04,
50
51 /// row is condensed (using reduced columns, for small displays)
52 Condensed = 0x08
53
54 }; // endenum SetType
55
56 public:
57
59 {
60 }
61
62 /*
63 ** create an empty set for this type
64 */
66 : m_type( _type )
67 {}
68
69 /*
70 ** create a set on an existing row using the index
71 */
73 {
74 }
75
77
78 }; // endclass ColumnSet
79
81
82 public:
83
84 /*!
85 ** \brief ctor
86 **
87 ** This constructs the model, empty.
88 */
89 Model() ;
90
91 auto setAccountGuid( const std::string & _accountGuid )-> void ;
92 auto refreshFromDisk()-> void ;
93 auto applyDoubleLine()-> void ;
94 auto saveToDisk()-> void ;
95
96 auto viewMode() const-> ViewMode { return m_viewMode; }
97 auto setViewMode( ViewMode _viewMode )-> void ;
98
99 auto doubleLine() const-> bool { return m_doubleLine; }
100 auto setDoubleLine( bool _doubleLine )-> void ;
101
102 /*!
103 ** \brief Split Count
104 **
105 ** This is ~slightly~ different than the rowCount() since
106 ** rowCount will return the number of rows in the model, and
107 ** splitCount will return the number of splits used to build
108 ** the model.
109 **
110 */
111 auto splitCount()-> int ;
112
113 /*!
114 ** \brief Is Deletable
115 **
116 ** This returns .true. if the item can be deleted.
117 */
118 auto isDeletable( const Wt::WModelIndex & _index )-> bool ;
119
120 /*!
121 ** \brief Is Jumpable
122 **
123 ** This returns .true. if the item can be jumped to
124 ** the other account in the split
125 */
126 auto isJumpable( const Wt::WModelIndex & _index )-> bool ;
127
128 auto isReadOnly()-> bool ;
129 auto isReadOnly( int _row )-> bool ;
130 auto isReadOnly( const Wt::WModelIndex & _index )-> bool ;
131
132 auto setReadOnly( bool _state ) { m_readOnly = _state; }
133
134 /*!
135 ** \brief Get GUID from index
136 **
137 ** This will retrieve the GUID value from the row.
138 */
139 auto getSplitGuid( const Wt::WModelIndex & _index )-> std::string ;
140
141 /*!
142 ** \brief Get GUID from row
143 **
144 ** This will retrieve the GUID value from the row.
145 */
146 auto getSplitGuid( int _row )-> std::string ;
147
148 /*!
149 ** \brief Get Split Row
150 **
151 ** This will locate a split by its GUID and return the
152 ** row number that it is a part of
153 **
154 */
155 auto getSplitRow( const std::string & _guid )-> int ;
156
157 /*!
158 ** \brief Get Date from the index
159 **
160 ** This pulls the 'date' column out and returns it as a WDateTime
161 ** value.
162 **
163 ** \note This will 'force' the 'time' component to be equal to
164 ** the default time of '10:59:00', since the 'date' column
165 ** does not support a time component... this seems to be
166 ** consistent with GnuCash.
167 */
168 auto getDate( const Wt::WModelIndex & _index )-> Wt::WDateTime ;
169
170 /*!
171 ** \brief Get Action
172 */
173 auto getAction( const Wt::WModelIndex & _index )-> std::string ;
174
175 /*!
176 ** \brief Get Description
177 */
178 auto getDescription( const Wt::WModelIndex & _index )-> std::string ;
179
180 /*!
181 ** \brief Get Transfer Account Text
182 */
183 auto getTransferText( const Wt::WModelIndex & _index )-> std::string ;
184
185 /*!
186 ** \brief Get Transfer Account GUID
187 */
188 auto getTransferGuid( const Wt::WModelIndex & _index )-> std::string;
189
190 /*!
191 ** \brief Get Reconciliation
192 */
193 auto getReconcile( const Wt::WModelIndex & _index )-> std::string ;
194
195 /*!
196 ** \brief Get numeric value
197 **
198 ** This returns the numeric value of the line. This is suitable
199 ** for querying either the debit or credit column values (and is really
200 ** intended for internal use). The 'value' is pulled from the Display
201 ** value of the index and converted to a GCW_NUMERIC value.
202 */
203 auto getNumeric( const Wt::WModelIndex & _index )-> GCW_NUMERIC ;
204
205 /*!
206 ** \brief Get Debit value
207 */
208 auto getDebit( const Wt::WModelIndex & _index )-> GCW_NUMERIC ;
209
210 /*!
211 ** \brief Get Credit value
212 */
213 auto getCredit( const Wt::WModelIndex & _index )-> GCW_NUMERIC ;
214
215 /*!
216 ** \brief Get Value (positive or negative)
217 **
218 ** The value that gets stored in the back-end database is either positive
219 ** for debit, and negative for credit. This function will read-out the
220 ** debit and credit columns in the register display and figure out if
221 ** the returned value should be returned positive or negative corrected.
222 **
223 ** This function always positive for debit, and negative for credit values.
224 */
225 auto getValue( const Wt::WModelIndex & _index )-> GCW_NUMERIC ;
226
227 /*!
228 ** \brief Get Balance (positive or negative)
229 */
230 auto getBalance ( const Wt::WModelIndex & _index )-> GCW_NUMERIC ;
231
232 auto present () const-> GCW_NUMERIC { return m_present ; }
233 auto future () const-> GCW_NUMERIC { return m_future ; }
234 auto cleared () const-> GCW_NUMERIC { return m_cleared ; }
235 auto reconciled () const-> GCW_NUMERIC { return m_reconciled ; }
236 auto projected () const-> GCW_NUMERIC { return m_projected ; }
237
238 auto makeColumnSet( const std::string & _splitGuid )-> ColumnSet ;
239
240 /*!
241 ** \brief Column Suggestions
242 **
243 ** This produces a unique-set of items that represent all the text-values
244 ** for that particular column. This is used to produce a suggestion-box
245 ** for the register.
246 */
247 auto suggestionsFromColumn( int _column ) const-> std::set< std::string > ;
248
249 auto setData( const Wt::WModelIndex & _index, const Wt::cpp17::any & _value, Wt::ItemDataRole _role )-> bool ;
250
252
253 private:
254
255 auto setStyleClass( int _row, const std::string & _class )-> void ;
256 auto removeStyleClass( int _row, const std::string & _class )-> void ;
257
258 auto getString( const Wt::WModelIndex & _index, int column )-> std::string ;
259
260 auto saveToDisk( const Wt::WModelIndex & _index )-> void ;
261
262#ifdef NEVER
263 template <typename T>
264 bool matchValue( const Wt::cpp17::any & _any1, const Wt::cpp17::any & _any2 )
265 {
266 auto v1 = Wt::cpp17::any_cast< T >( _any1 ) ;
267 auto v2 = Wt::cpp17::any_cast< T >( _any2 ) ;
268 return v1 == v2;
269 }
270#endif
271
272 /*
273 ** Send a signal when a index is being updated
274 ** because it was dirty.
275 */
277
278 /*
279 ** keep track of rows as they go dirty.
280 */
281// std::set< int > m_dirtyRows;
282
283 /*!
284 ** \brief Editable Indicator
285 **
286 ** The model can be either R/W (read-write) or R/O (read-only).
287 */
288 bool m_readOnly = false ;
289
291 bool m_doubleLine = false ;
292
293 /*!
294 ** \brief Account GUID
295 **
296 ** The model is associated with a single account.
297 */
298 std::string m_accountGuid ;
299
300 /*
301 ** Keep track of the last date entered for pre-populating
302 ** the next row.
303 */
305
306/*!
307** \brief Accumulators
308**
309** \todo these are additional values that need to be available
310**
311** \code
312** balance
313** balance limit
314** balance (Period)
315** balance usd
316** cleared
317** cleared usd
318** fiture minimum
319** future minimum usa
320** last num
321** last reconcile date
322** opening balance
323** present
324** present usd
325** reconciled reconciled usd
326** total total period
327** total usd
328** \endcode
329**
330*/
331
332 int m_splitCount ; // different than rowCount depending on 'viewMode'
339
341
342}; // endclass Model
343
344 } // namespace AccountRegister {
345 } // namespace Gui {
346} // endnamespace GCW {
347
348#endif // #ifndef __ENG_ACCOUNTREGISTER_MODEL_H___
349
350
351
ColumnSet(Wt::WModelIndex _index)
Definition Model.h:72
@ BasicRow
basic Ledger row, everything on one line
Definition Model.h:43
@ BlankRow
blank row, used for doubleLine
Definition Model.h:40
@ Condensed
row is condensed (using reduced columns, for small displays)
Definition Model.h:52
@ SplitLine
one of the split lines following SplitRow
Definition Model.h:49
@ SplitRow
split Ledger row, multiple lines follow
Definition Model.h:46
@ EmptyRow
empty row, used for nothing, undefined (shouldn't happen?)
Definition Model.h:37
Account Register Model.
Definition Model.h:30
int m_splitCount
Accumulators.
Definition Model.h:332
auto isDeletable(const Wt::WModelIndex &_index) -> bool
Is Deletable.
Definition Model.cpp:102
auto getDate(const Wt::WModelIndex &_index) -> Wt::WDateTime
Get Date from the index.
Definition Model.cpp:236
auto viewMode() const -> ViewMode
Definition Model.h:96
auto setViewMode(ViewMode _viewMode) -> void
Definition Model.cpp:76
auto getValue(const Wt::WModelIndex &_index) -> GCW_NUMERIC
Get Value (positive or negative)
Definition Model.cpp:328
auto getReconcile(const Wt::WModelIndex &_index) -> std::string
Get Reconciliation.
Definition Model.cpp:289
auto future() const -> GCW_NUMERIC
Definition Model.h:233
auto setStyleClass(int _row, const std::string &_class) -> void
Definition Model.cpp:859
auto setAccountGuid(const std::string &_accountGuid) -> void
Definition Model.cpp:67
auto getDebit(const Wt::WModelIndex &_index) -> GCW_NUMERIC
Get Debit value.
Definition Model.cpp:310
auto getAction(const Wt::WModelIndex &_index) -> std::string
Get Action.
Definition Model.cpp:256
auto projected() const -> GCW_NUMERIC
Definition Model.h:236
auto getCredit(const Wt::WModelIndex &_index) -> GCW_NUMERIC
Get Credit value.
Definition Model.cpp:319
auto present() const -> GCW_NUMERIC
Definition Model.h:232
auto getString(const Wt::WModelIndex &_index, int column) -> std::string
Definition Model.cpp:222
auto setReadOnly(bool _state)
Definition Model.h:132
auto cleared() const -> GCW_NUMERIC
Definition Model.h:234
auto reconciled() const -> GCW_NUMERIC
Definition Model.h:235
auto goneDirty() -> Wt::Signal< Wt::WModelIndex > &
Definition Model.h:251
std::string m_accountGuid
Account GUID.
Definition Model.h:298
auto getNumeric(const Wt::WModelIndex &_index) -> GCW_NUMERIC
Get numeric value.
Definition Model.cpp:297
auto splitCount() -> int
Split Count.
Definition Model.cpp:94
bool m_readOnly
Editable Indicator.
Definition Model.h:288
auto getSplitGuid(const Wt::WModelIndex &_index) -> std::string
Get GUID from index.
Definition Model.cpp:343
auto removeStyleClass(int _row, const std::string &_class) -> void
Definition Model.cpp:867
auto refreshFromDisk() -> void
Refresh From Disk.
Definition Model.cpp:653
auto getDescription(const Wt::WModelIndex &_index) -> std::string
Get Description.
Definition Model.cpp:264
auto getBalance(const Wt::WModelIndex &_index) -> GCW_NUMERIC
Get Balance (positive or negative)
auto getSplitRow(const std::string &_guid) -> int
Get Split Row.
Definition Model.cpp:371
auto getTransferGuid(const Wt::WModelIndex &_index) -> std::string
Get Transfer Account GUID.
Definition Model.cpp:280
auto setDoubleLine(bool _doubleLine) -> void
Definition Model.cpp:85
auto doubleLine() const -> bool
Definition Model.h:99
auto isJumpable(const Wt::WModelIndex &_index) -> bool
Is Jumpable.
Definition Model.cpp:128
auto setData(const Wt::WModelIndex &_index, const Wt::cpp17::any &_value, Wt::ItemDataRole _role) -> bool
Definition Model.cpp:488
auto makeColumnSet(const std::string &_splitGuid) -> ColumnSet
Definition Model.cpp:834
Wt::Signal< Wt::WModelIndex > m_goneDirty
Definition Model.h:276
auto suggestionsFromColumn(int _column) const -> std::set< std::string >
Column Suggestions.
Definition Model.cpp:844
auto getTransferText(const Wt::WModelIndex &_index) -> std::string
Get Transfer Account Text.
Definition Model.cpp:272
#define GCW_NUMERIC
Internal Numeric Type.
Definition gcwglobal.h:40
@ BASIC_LEDGER
basic one-line per transaction
Definition App.h:18