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{
31 using RowItem = std::vector< std::unique_ptr< Wt::WStandardItem > > ;
33
34 public:
35
36 /*!
37 ** \brief ctor
38 **
39 ** This constructs the model, empty.
40 */
41 Model() ;
42
43 auto setAccountGuid( const std::string & _accountGuid )-> void ;
44 auto refreshFromDisk()-> void ;
45 auto saveToDisk()-> void ;
46
47 auto viewMode() const-> ViewMode { return m_viewMode; }
48 auto setViewMode( ViewMode _viewMode )-> void ;
49
50 auto doubleLine() const-> bool { return m_doubleLine; }
51 auto setDoubleLine( bool _doubleLine )-> void ;
52
53 /*!
54 ** \brief Split Count
55 **
56 ** This is ~slightly~ different than the rowCount() since
57 ** rowCount will return the number of rows in the model, and
58 ** splitCount will return the number of splits used to build
59 ** the model.
60 **
61 */
62 auto splitCount()-> int ;
63
64 /*!
65 ** \brief Is Read Only
66 **
67 ** This returns .true. if the item can be deleted.
68 */
69 auto isDeletable( const Wt::WModelIndex & _index )-> bool ;
70
71 /*!
72 ** \brief Is Jumpable
73 **
74 ** This returns .true. if the item can be jumped to
75 ** the other account in the split
76 */
77 auto isJumpable( const Wt::WModelIndex & _index )-> bool ;
78
79 auto isReadOnly()-> bool ;
80 auto isReadOnly( int _row )-> bool ;
81 auto isReadOnly( const Wt::WModelIndex & _index )-> bool ;
82
83 auto setReadOnly( bool _state ) { m_readOnly = _state; }
84
85 /*!
86 ** \brief Get GUID from row
87 **
88 ** This will retrieve the GUID value from the row.
89 */
90 auto getSplitGuid( const Wt::WModelIndex & _index )-> std::string ;
91 auto getSplitGuid( int _row )-> std::string ;
92
93 /*!
94 ** \brief Get Date from the index
95 **
96 ** This pulls the 'date' column out and returns it as a WDateTime
97 ** value.
98 **
99 ** \note This will 'force' the 'time' component to be equal to
100 ** the default time of '10:59:00', since the 'date' column
101 ** does not support a time component... this seems to be
102 ** consistent with GnuCash.
103 */
104 auto getDate( const Wt::WModelIndex & _index )-> Wt::WDateTime ;
105
106 /*!
107 ** \brief Get Action
108 */
109 auto getAction( const Wt::WModelIndex & _index )-> std::string ;
110
111 /*!
112 ** \brief Get Description
113 */
114 auto getDescription( const Wt::WModelIndex & _index )-> std::string ;
115
116 /*!
117 ** \brief Get Transfer Account Text
118 */
119 auto getTransferText( const Wt::WModelIndex & _index )-> std::string ;
120
121 /*!
122 ** \brief Get Transfer Account GUID
123 */
124 auto getTransferGuid( const Wt::WModelIndex & _index )-> std::string;
125
126 /*!
127 ** \brief Get Reconciliation
128 */
129 auto getReconcile( const Wt::WModelIndex & _index )-> std::string ;
130
131 /*!
132 ** \brief Get numeric value
133 **
134 ** This returns the numeric value of the line. This is suitable
135 ** for querying either the debit or credit column values (and is really
136 ** intended for internal use). The 'value' is pulled from the Display
137 ** value of the index and converted to a GCW_NUMERIC value.
138 */
139 auto getNumeric( const Wt::WModelIndex & _index )-> GCW_NUMERIC ;
140
141 /*!
142 ** \brief Get Debit value
143 */
144 auto getDebit( const Wt::WModelIndex & _index )-> GCW_NUMERIC ;
145
146 /*!
147 ** \brief Get Credit value
148 */
149 auto getCredit( const Wt::WModelIndex & _index )-> GCW_NUMERIC ;
150
151 /*!
152 ** \brief Get Value (positive or negative)
153 **
154 ** The value that gets stored in the back-end database is either positive
155 ** for debit, and negative for credit. This function will read-out the
156 ** debit and credit columns in the register display and figure out if
157 ** the returned value should be returned positive or negative corrected.
158 **
159 ** This function always positive for debit, and negative for credit values.
160 */
161 auto getValue( const Wt::WModelIndex & _index )-> GCW_NUMERIC ;
162
163 /*!
164 ** \brief Get Balance (positive or negative)
165 */
166 auto getBalance ( const Wt::WModelIndex & _index )-> GCW_NUMERIC ;
167
168 auto present () const-> GCW_NUMERIC { return m_present ; }
169 auto future () const-> GCW_NUMERIC { return m_future ; }
170 auto cleared () const-> GCW_NUMERIC { return m_cleared ; }
171 auto reconciled () const-> GCW_NUMERIC { return m_reconciled ; }
172 auto projected () const-> GCW_NUMERIC { return m_projected ; }
173
174 auto makeRow( const std::string & _splitGuid )-> RowItem ;
175
176 /*!
177 ** \brief Column Suggestions
178 **
179 ** This produces a unique-set of items that represent all the text-values
180 ** for that particular column. This is used to produce a suggestion-box
181 ** for the register.
182 */
183 auto suggestionsFromColumn( int _column ) const-> std::set< std::string > ;
184
185 auto setData( const Wt::WModelIndex & _index, const Wt::cpp17::any & _value, Wt::ItemDataRole _role )-> bool ;
186
188
189 private:
190
191 auto setStyleClass( int _row, const std::string & _class )-> void ;
192 auto removeStyleClass( int _row, const std::string & _class )-> void ;
193
194 auto getString( const Wt::WModelIndex & _index, int column )-> std::string ;
195
196 auto saveToDisk( const Wt::WModelIndex & _index )-> void ;
197
198#ifdef NEVER
199 template <typename T>
200 bool matchValue( const Wt::cpp17::any & _any1, const Wt::cpp17::any & _any2 )
201 {
202 auto v1 = Wt::cpp17::any_cast< T >( _any1 ) ;
203 auto v2 = Wt::cpp17::any_cast< T >( _any2 ) ;
204 return v1 == v2;
205 }
206#endif
207
208 /*
209 ** Send a signal when a index is being updated
210 ** because it was dirty.
211 */
213
214 /*
215 ** keep track of rows as they go dirty.
216 */
217// std::set< int > m_dirtyRows;
218
219 /*!
220 ** \brief Editable Indicator
221 **
222 ** The model can be either R/W (read-write) or R/O (read-only).
223 */
224 bool m_readOnly = false ;
225
227 bool m_doubleLine = false ;
228
229 /*!
230 ** \brief Account GUID
231 **
232 ** The model is associated with a single account.
233 */
234 std::string m_accountGuid ;
235
236 /*
237 ** Keep track of the last date entered for pre-populating
238 ** the next row.
239 */
241
242/*!
243** \brief Accumulators
244**
245** \todo these are additional values that need to be available
246**
247** balance
248** balance limit
249** balance (Period)
250** balance usd
251** cleared
252** cleared usd
253** fiture minimum
254** future minimum usa
255** last num
256** last reconcile date
257** opening balance
258** present
259** present usd
260** reconciled reconciled usd
261** total total period
262** total usd
263*/
264
265 int m_splitCount ; // different than rowCount depending on 'viewMode'
272
274
275}; // endclass Model
276
277 } // namespace AccountRegister {
278 } // namespace Gui {
279} // endnamespace GCW {
280
281#endif // #ifndef __ENG_ACCOUNTREGISTER_MODEL_H___
282
283
284
Account Register Model.
Definition Model.h:30
int m_splitCount
Accumulators.
Definition Model.h:265
auto isDeletable(const Wt::WModelIndex &_index) -> bool
Is Read Only.
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:47
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:169
auto setStyleClass(int _row, const std::string &_class) -> void
Definition Model.cpp:836
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:172
auto getCredit(const Wt::WModelIndex &_index) -> GCW_NUMERIC
Get Credit value.
Definition Model.cpp:319
auto present() const -> GCW_NUMERIC
Definition Model.h:168
auto getString(const Wt::WModelIndex &_index, int column) -> std::string
Definition Model.cpp:222
auto setReadOnly(bool _state)
Definition Model.h:83
auto cleared() const -> GCW_NUMERIC
Definition Model.h:170
auto reconciled() const -> GCW_NUMERIC
Definition Model.h:171
auto goneDirty() -> Wt::Signal< Wt::WModelIndex > &
Definition Model.h:187
std::string m_accountGuid
Account GUID.
Definition Model.h:234
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:224
auto getSplitGuid(const Wt::WModelIndex &_index) -> std::string
Get GUID from row.
Definition Model.cpp:343
auto removeStyleClass(int _row, const std::string &_class) -> void
Definition Model.cpp:844
auto refreshFromDisk() -> void
Refresh From Disk.
Definition Model.cpp:604
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 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:50
auto isJumpable(const Wt::WModelIndex &_index) -> bool
Is Jumpable.
Definition Model.cpp:128
std::vector< std::unique_ptr< Wt::WStandardItem > > RowItem
Definition Model.h:31
auto setData(const Wt::WModelIndex &_index, const Wt::cpp17::any &_value, Wt::ItemDataRole _role) -> bool
Definition Model.cpp:467
Wt::Signal< Wt::WModelIndex > m_goneDirty
Definition Model.h:212
auto makeRow(const std::string &_splitGuid) -> RowItem
Definition Model.cpp:811
auto suggestionsFromColumn(int _column) const -> std::set< std::string >
Column Suggestions.
Definition Model.cpp:821
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:38
@ BASIC_LEDGER
basic one-line per transaction
Definition App.h:18