GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
DelegateBase.cpp
Go to the documentation of this file.
1#line 2 "src/Gui/AccountRegister/DelegateBase.cpp"
2
3#include <Wt/WDateTime.h>
4
5#include "DelegateBase.h"
6
7/* * * * * * * * * * * * * * * * * * * * * * * * * * */
8
9/*!
10** \brief Base Delegate
11**
12** This class is strictly for debugging and tracing purposes. It
13** facilitates the hooking of the various calls in to the delegate
14** classes so that their behaviour and interaction with the view
15** can be studied, understood (and perhaps documented).
16**
17*/
20{
21// std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << "(): " << std::endl;
22}
23
26{
27// std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << "(): " << std::endl;
28}
29
30auto
32createEditor( const Wt::WModelIndex &_index, Wt::WFlags< Wt::ViewItemRenderFlag > _flags ) const-> std::unique_ptr< Wt::WWidget >
33{
34#ifdef NEVER
35 std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__
36 << " (" << _index.row() << "," << _index.column() << ")"
37 << std::endl;
38#endif
39
40 return Wt::WItemDelegate::createEditor( _index, _flags );
41
42} // endcreateEditor( ... ) const-> std::unique_ptr< WWidget >
43
44auto
46update( Wt::WWidget * _widget, const Wt::WModelIndex & _index, Wt::WFlags< Wt::ViewItemRenderFlag > _flags )-> std::unique_ptr< Wt::WWidget >
47{
48#ifdef NEVER
49 std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__
50 << "(): " << widget
51 << " (" << _index.row() << "," << _index.column() << ")"
52 << std::endl;
53#endif
54
55 return Wt::WItemDelegate::update( _widget, _index, _flags );
56
57} //endupdate( Wt::WWidget * _widget, const Wt::WModelIndex & _index, Wt::WFlags< Wt::ViewItemRenderFlag > _flags )-> std::unique_ptr< Wt::WWidget >
58
59auto
61updateModelIndex( Wt::WWidget * _widget, const Wt::WModelIndex & _index )-> void
62{
63#ifdef NEVER
64 std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__
65 << "(): " << _widget
66 << " (" << _index.row() << "," << _index.column() << ")"
67 << std::endl;
68#endif
69
70 Wt::WItemDelegate::updateModelIndex( _widget, _index );
71
72} // endupdateModelIndex( Wt::WWidget * _widget, const Wt::WModelIndex & _index )-> void
73
74auto
76validate( const Wt::WModelIndex & _index, const Wt::cpp17::any & _editState ) const-> Wt::ValidationState
77{
78#ifdef NEVER
79 std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__
80 << " (" << _index.row() << "," << _index.column() << ")"
81 << std::endl;
82#endif
83
84 return Wt::WItemDelegate::validate( _index, _editState );
85
86} // endvalidate( const Wt::WModelIndex & _index, const Wt::cpp17::any & _editState ) const-> Wt::ValidationState
87
88auto
90editState( Wt::WWidget * _widget, const Wt::WModelIndex & _index ) const-> Wt::cpp17::any
91{
92 auto retVal = Wt::WItemDelegate::editState( _widget, _index );
93
94#ifdef NEVER
95 std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__
96 << " (" << _index.row() << "," << _index.column() << ")"
97 << "(): " << typeid( _widget ).name()
98 << "(): " << typeid( *_widget ).name()
99 << " '" << Wt::asString( retVal ) << "'"
100 << std::endl;
101#endif
102
103 return retVal;
104
105} // endeditState( Wt::WWidget * _widget, const Wt::WModelIndex & _index ) const-> Wt::cpp17::any
106
107auto
109setEditState( Wt::WWidget * _widget, const Wt::WModelIndex & _index, const Wt::cpp17::any & _value ) const-> void
110{
111#ifdef NEVER
112 std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__
113 << "(): " << _widget
114 << " (" << _index.row() << "," << _index.column() << ")"
115 << " " << _value.type().name()
116 << " '" << Wt::asString( _value ) << "'"
117 << std::endl;
118#endif
119
120// Wt::WItemDelegate::setEditState( widget, index, value );
121
122} // endsetEditState( Wt::WWidget * _widget, const Wt::WModelIndex & _index, const Wt::cpp17::any & _value ) const-> void
123
124auto
126setModelData( const Wt::cpp17::any & _editState, Wt::WAbstractItemModel * _model, const Wt::WModelIndex & _index ) const-> void
127{
128#ifdef NEVER
129 std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__
130 << " (" << _index.row() << "," << _index.column() << ")"
131 << std::endl;
132#endif
133
134 /*
135 ** in order to compare .any. type, check the types,
136 ** and then ultimately cast the type correctly and
137 ** then compare the actual values.
138 */
139 auto _equal = []( Wt::cpp17::any _a, Wt::cpp17::any _b )
140 {
141 if( !_a.has_value() && !_b.has_value() )
142 return true; // both empty
143
144 if( _a.type() != _b.type() )
145 return false; // different types
146
147 // compare based on type
148 if( _a.type() == typeid(int) )
149 return Wt::cpp17::any_cast<int>(_a)
150 == Wt::cpp17::any_cast<int>(_b);
151
152 if( _a.type() == typeid(std::string) )
153 return Wt::cpp17::any_cast<std::string>(_a)
154 == Wt::cpp17::any_cast<std::string>(_b);
155
156 if( _a.type() == typeid(double) )
157 return Wt::cpp17::any_cast<double>(_a)
158 == Wt::cpp17::any_cast<double>(_b);
159
160 if( _a.type() == typeid(Wt::WString) )
161 return Wt::cpp17::any_cast<Wt::WString>(_a)
162 == Wt::cpp17::any_cast<Wt::WString>(_b);
163
164 if( _a.type() == typeid(Wt::WDateTime) )
165 return Wt::cpp17::any_cast<Wt::WDateTime>(_a)
166 == Wt::cpp17::any_cast<Wt::WDateTime>(_b);
167
168 std::cout << __FILE__ << ":" << __LINE__ << " unhandled type: " << _a.type().name() << std::endl;
169
170 return false;
171
172 }; // endauto _equal = []( Wt::cpp17::any _a, Wt::cpp17::any _b )
173
174 auto modelData = _index.data( Wt::ItemDataRole::Edit );
175
176 Wt::WItemDelegate::setModelData( _editState, _model, _index );
177
178 /*
179 ** if the data changed then signal the editor
180 */
181 if( !_equal( modelData, _editState ) )
182 {
183#ifdef NEVER
184 std::cout << __FILE__ << ":" << __LINE__ << " data changed"
185 << " " << Wt::asString( modelData )
186 << " " << Wt::asString( _editState )
187 << std::endl;
188#endif
189
190// editor()-> setDirty( _index );
191
192 } // endif( !_equal( modelData, _editState ) )
193
194} // endsetModelData( const Wt::cpp17::any & _editState, Wt::WAbstractItemModel * _model, const Wt::WModelIndex & _index ) const-> void
195
196
virtual auto update(Wt::WWidget *_widget, const Wt::WModelIndex &_index, Wt::WFlags< Wt::ViewItemRenderFlag > _flags) -> std::unique_ptr< Wt::WWidget >
virtual auto setModelData(const Wt::cpp17::any &_editState, Wt::WAbstractItemModel *_model, const Wt::WModelIndex &_index) const -> void
virtual auto editState(Wt::WWidget *_widget, const Wt::WModelIndex &_index) const -> Wt::cpp17::any
virtual auto updateModelIndex(Wt::WWidget *_widget, const Wt::WModelIndex &_index) -> void
virtual auto setEditState(Wt::WWidget *_widget, const Wt::WModelIndex &_index, const Wt::cpp17::any &_value) const -> void
virtual auto createEditor(const Wt::WModelIndex &index, Wt::WFlags< Wt::ViewItemRenderFlag > flags) const -> std::unique_ptr< Wt::WWidget >
virtual auto validate(const Wt::WModelIndex &_index, const Wt::cpp17::any &_editState) const -> Wt::ValidationState
static constexpr const int Edit
virtual ValidationState validate(const WModelIndex &index, const cpp17::any &editState) const
virtual std::unique_ptr< WWidget > createEditor(const WModelIndex &index, WFlags< ViewItemRenderFlag > flags) const
virtual void updateModelIndex(WWidget *widget, const WModelIndex &index) override
virtual std::unique_ptr< WWidget > update(WWidget *widget, const WModelIndex &index, WFlags< ViewItemRenderFlag > flags) override
virtual cpp17::any editState(WWidget *editor, const WModelIndex &index) const override
virtual void setModelData(const cpp17::any &editState, WAbstractItemModel *model, const WModelIndex &index) const override
WString asString(const cpp17::any &v, const WString &formatString=WString())
ValidationState