GnuCashew ~ Web Application compatible with GnuCash sql data files.
GCW
Loading...
Searching...
No Matches
DelegateReconcile.cpp
Go to the documentation of this file.
1#line 2 "src/Gui/AccountRegister/DelegateReconcile.cpp"
2
3#include <Wt/WHBoxLayout.h>
4#include <Wt/WDateTime.h>
5
6#include "DelegateReconcile.h"
7
8/* * * * * * * * * * * * * * * * * * * * * * * * * * */
9
12{
13// std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << "(): " << std::endl;
14}
15
18{
19// std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << "(): " << std::endl;
20}
21
22auto
24createEditor( const Wt::WModelIndex & _index, Wt::WFlags< Wt::ViewItemRenderFlag > _flags ) const-> std::unique_ptr< Wt::WWidget >
25{
26#ifdef NEVER
27 std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__
28 << " (" << _index.row() << "," << _index.column() << ")"
29 << std::endl;
30#endif
31
32#ifdef NEVER
33 std::cout << __FILE__ << ":" << __LINE__
34 << "(): " << _index.row() << "," << _index.column()
35 << " ReconcileDelegate::" << __FUNCTION__
36 << " '" << Wt::asString( _index.data( Wt::ItemDataRole::Edit ) ) << "'"
37 << std::endl;
38#endif
39
40 /*
41 ** The editor is placed in to a container for layout
42 ** management
43 **
44 */
45 auto retVal = std::make_unique< Wt::WContainerWidget >();
46 retVal-> setSelectable( true );
47
48 /*
49 ** Get the data from the string value
50 **
51 */
52 auto reconciled = Wt::asString( _index.data( Wt::ItemDataRole::Edit ) );
53
54 /*
55 ** Build an editor
56 **
57 ** This is actually only a WText object, since it's not really an editor,
58 ** it is a widget that responds to clicks. It's not a push-button (doesn't
59 ** need to be) it's just text, and upon clicking on the widget it will respond
60 ** and change values accordingly.
61 **
62 */
63 auto reconciledEdit = std::make_unique< Wt::WText >();
64// reconciledEdit-> setReadOnly( true );
65 reconciledEdit-> setText( reconciled );
66
67 /*!
68 ** \todo applying styles here; this needs to be moved to the .css files
69 */
70 reconciledEdit-> setAttributeValue( "style", "background-color:yellow;border-radius:4px;border:1px solid rgb(204,204,204)" );
71
72// reconciledEdit-> enterPressed ().connect( [&]()
73// {
74// std::cout << __FILE__ << ":" << __LINE__ << " " << std::endl;
75//
76// doCloseEditor( reconciledEdit.get(), true );
77// });
78// reconciledEdit-> escapePressed ().connect( [&](){ doCloseEditor( reconciledEdit.get(), false ); });
79// reconciledEdit-> keyWentDown ().connect( [&]( Wt::WKeyEvent _keyEvent ){ doTabAction( _keyEvent ); });
80
81 /*
82 ** Stuff it in to the layout
83 **
84 */
85 retVal-> setLayout( std::make_unique< Wt::WHBoxLayout >() );
86 retVal-> layout()-> setContentsMargins( 0,0,0,0 );
87 retVal-> layout()-> addWidget( std::move( reconciledEdit ) );
88
89 return retVal;
90
91} // endcreateEditor( const Wt::WModelIndex & _index, Wt::WFlags< Wt::ViewItemRenderFlag > _flags ) const-> std::unique_ptr< Wt::WWidget >
92
93auto
95doCloseEditor( Wt::WLineEdit * _editor, bool _save ) const-> void
96{
97#ifdef NEVER
98 std::cout << __FILE__ << ":" << __LINE__ << " ReconciledDelegate::doCloseEditor()" << std::endl;
99#endif
100
101 closeEditor().emit( _editor, _save );
102
103#ifdef NEVER
104 m_editorClosed.emit( m_row, m_col );
105 m_row = -1;
106 m_col = -1;
107#endif
108
109} // enddoCloseEditor( Wt::WLineEdit * _editor, bool save ) const-> void
110
111auto
113doTabAction( Wt::WKeyEvent _keyEvent ) const-> void
114{
115#ifdef NEVER
116 std::cout << __FILE__ << ":" << __LINE__ << " ReconciledDelegate::doTabAction()" << std::endl;
117#endif
118
119} // enddoTabAction( Wt::WKeyEvent _keyEvent ) const-> void
120
121auto
123editState( Wt::WWidget * _editor, const Wt::WModelIndex & _index ) const-> Wt::cpp17::any
124{
125 auto cw = dynamic_cast< Wt::WContainerWidget* >( _editor );
126
127 auto ed = dynamic_cast< Wt::WText* >( cw-> children().at(0) );
128
129#ifdef NEVER
130 std::cout << __FILE__ << ":" << __LINE__
131 << " Wt::cpp17::any ReconcileDelegate::editState()"
132 << " r:" << _index.row()
133 << " c:" << _index.column()
134 << " i:" << cw-> id()
135 << " n:" << cw-> objectName()
136 << " s:" << cw-> children().size()
137 << " t:" << typeid( cw-> children().at(0) ).name()
138 << " d:" << ed
139 << std::endl
140 ;
141#endif
142
143 return ed-> text();
144
145} // endeditState( Wt::WWidget * _editor, const Wt::WModelIndex & _index ) const-> Wt::cpp17::any
146
147auto
149setEditState( Wt::WWidget * _editor, const Wt::WModelIndex & _index, const Wt::cpp17::any & _value ) const-> void
150{
151#ifdef NEVER
152 std::cout << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__
153 << "(): " << _editor
154 << " " << _index.row() << "," << _index.column()
155 << " " << _value.type().name()
156 << " '" << Wt::asString( _value ) << "'"
157 << std::endl;
158#endif
159
160// the '_editor' and 'm_dateEdit' are not the same widget
161// std::cout << __FILE__ << ":" << __LINE__ << " " << _editor << " " << typeid( _editor ).name() << std::endl;
162// std::cout << __FILE__ << ":" << __LINE__ << " " << m_dateEdit << " " << typeid( m_dateEdit ).name() << std::endl;
163
164
165} // endsetEditState( Wt::WWidget * _editor, const Wt::WModelIndex & _index, const Wt::cpp17::any & _value ) const-> void
166
167auto
169setModelData( const Wt::cpp17::any & _editState, Wt::WAbstractItemModel * _model, const Wt::WModelIndex & _index ) const-> void
170{
171#ifdef NEVER
172 std::cout << __FILE__ << ":" << __LINE__
173 << " ReconciledDelegate::setModelData()"
174 << " " << _index.row()
175 << " " << _index.column()
176 << " " << Wt::asString( _editState )
177 << " " << _model
178 << std::endl;
179#endif
180
181 DelegateBase::setModelData( _editState, _model, _index );
182
183} // endsetModelData( const Wt::cpp17::any & _editState, Wt::WAbstractItemModel * _model, const Wt::WModelIndex & _index ) const-> void
184
185
186
virtual auto setModelData(const Wt::cpp17::any &_editState, Wt::WAbstractItemModel *_model, const Wt::WModelIndex &_index) const -> void
virtual auto setModelData(const Wt::cpp17::any &_editState, Wt::WAbstractItemModel *_model, const Wt::WModelIndex &_index) const -> void
virtual auto setEditState(Wt::WWidget *_editor, 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 doTabAction(Wt::WKeyEvent _keyEvent) const -> void
virtual auto doCloseEditor(Wt::WLineEdit *_editor, bool _save) const -> void
virtual auto editState(Wt::WWidget *_editor, const Wt::WModelIndex &_index) const -> Wt::cpp17::any override
static constexpr const int Edit
WString asString(const cpp17::any &v, const WString &formatString=WString())