Wtx ~ Wt Extension Library
WtxLib
FormModel.cpp
1 /**************************************************************************
2 ###########################################################################
3 ##
4 ## $SHOWOFFDB_BEGIN_LICENSE$
5 ## Copyright (C) 2011 Lorimark Solutions, LLC and/or its subsidiary(-ies).
6 ## All rights reserved.
7 ## Contact: Lorimark Solutions, LLC (info@showoff-db.org)
8 ##
9 ## This file is part of the Showoff Database Application Framework.
10 ##
11 ## Commercial Usage
12 ## Licensees holding valid ShowoffDB Commercial licenses may use this file in
13 ## accordance with the ShowoffDB Commercial License Agreement provided with the
14 ## Software or, alternatively, in accordance with the terms contained in
15 ## a written agreement between you and Lorimark Solutions, LLC.
16 ##
17 ## GNU Lesser General Public License Usage
18 ## Alternatively, this file may be used under the terms of the GNU Lesser
19 ## General Public License version 2.1 as published by the Free Software
20 ## Foundation and appearing in the file LICENSE.LGPL included in the bu-+
21 ## packaging of this file. Please review the following information to
22 ## ensure the GNU Lesser General Public License version 2.1 requirements
23 ## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ##
25 ## In addition, as a special exception, Lorimark Solutions, LLC gives
26 ## you certain additional rights. These rights are described in the
27 ## Lorimark Solutions, LLC ShowoffDB LGPL Exception version 1.0, included in
28 ## the file LGPL_EXCEPTION.txt in this package.
29 ##
30 ## GNU General Public License Usage
31 ## Alternatively, this file may be used under the terms of the GNU
32 ## General Public License version 3.0 as published by the Free Software
33 ## Foundation and appearing in the file LICENSE.GPL included in the
34 ## packaging of this file. Please review the following information to
35 ## ensure the GNU General Public License version 3.0 requirements will be
36 ## met: http://www.gnu.org/copyleft/gpl.html.
37 ##
38 ## If you have questions regarding the use of this file, please contact
39 ## Lorimark Solutions, LLC at info@showoff-db.org.
40 ## $SHOWOFFDB_END_LICENSE$
41 ##
42 #############################################################################
43 ****************************************************************************/
44 
45 
46 #include <Wt/WString.h>
47 #include <Wt/WLineEdit.h>
48 #include <Wt/WWidget.h>
49 
50 #include "FormModel.h"
51 #include "Dbo/FieldDefBase.h"
52 
53 #ifdef FM_DEBUG_TRACE
54 #define COUT_LINE \
55  std::cout << __FILE__ << ":" << __LINE__ << std::endl;
56 #else
57 #define COUT_LINE
58 #endif
59 
60 Wtx::FormModel::FormModel( Wtx::Dbo::TableDef & td )
61 : Wt::WFormModel(),
62  m_tableDef(td)
63 {
64  init();
65 }
66 
67 Wtx::FormModel::~FormModel()
68 {
69 }
70 
71 void Wtx::FormModel::init()
72 {
73  for( auto fieldDef : tableDef().fieldDefs() )
74  {
75  auto fieldName = fieldDef-> fieldName();
76 
77  addField( fieldName );
78 
86 // std::cout << __FILE__ << ":" << __LINE__ << " " << fieldName << " " << fieldDef-> isReadOnly() << std::endl;
87 
88  setReadOnly( fieldName, fieldDef-> isReadOnly() );
89  setVisible( fieldName, fieldDef-> isVisible() );
90 
91  if( fieldDef-> flags() & Wtx::Dbo::FieldDefBase::NoUi )
92  setVisible( fieldName, false );
93 
94 
95  } // endfor( auto fieldDef : tableDef().fieldDefs() )
96 
97 }
98 
99 std::unique_ptr<Wt::WWidget> Wtx::FormModel::createWidget( Wtx::Dbo::Session & session )
100 {
101  COUT_LINE;
102  return std::make_unique<Wt::WLineEdit>();
103 }
104 
105 void Wtx::FormModel::reset()
106 {
107  COUT_LINE;
108  Wt::WFormModel::reset();
109 }
110 
111 bool Wtx::FormModel::validate()
112 {
113  COUT_LINE;
114  return Wt::WFormModel::validate();
115 }
116 
117 
118 bool Wtx::FormModel::isVisible( Wt::WFormModel::Field field ) const
119 {
120  COUT_LINE;
121  return Wt::WFormModel::isVisible( field );
122 }
123 
124 
125 bool Wtx::FormModel::isReadOnly( Wt::WFormModel::Field field ) const
126 {
127  COUT_LINE;
128  return Wt::WFormModel::isReadOnly( field );
129 }
130 
137 Wt::WString Wtx::FormModel::label( Wt::WFormModel::Field field ) const
138 {
139  COUT_LINE;
140 
145  Wt::WString retVal = tableDef().fieldDef(field)-> label();
146 
157  if( retVal == "" )
158  retVal = Wt::WFormModel::label( field );
159 
166  if( retVal.toUTF8().substr(0,2) == "??" )
167  retVal = field;
168 
169  return retVal;
170 
171 } // endWt::WString Wtx::FormModel::label( Wt::WFormModel::Field field ) const
172 
173 
174 void Wtx::FormModel::setValue( Wt::WFormModel::Field field, const Wt::cpp17::any &value )
175 {
176  COUT_LINE;
177  Wt::WFormModel::setValue( field, value );
178 }
179 
180 
181 const Wt::cpp17::any & Wtx::FormModel::value( Wt::WFormModel::Field field ) const
182 {
183  COUT_LINE;
184  return Wt::WFormModel::value( field );
185 }
186 
187 
188 Wt::WString Wtx::FormModel::valueText( Wt::WFormModel::Field field ) const
189 {
190  COUT_LINE;
191  return Wt::WFormModel::valueText( field );
192 }
193 
194 
195 void Wtx::FormModel::setValidator( Wt::WFormModel::Field field, const std::shared_ptr< Wt::WValidator > &validator )
196 {
197  COUT_LINE;
198  Wt::WFormModel::setValidator( field, validator );
199 }
200 
201 
202 std::shared_ptr< Wt::WValidator > Wtx::FormModel::validator( Wt::WFormModel::Field field ) const
203 {
204  COUT_LINE;
205  return Wt::WFormModel::validator( field );
206 }
207 
208 
209 bool Wtx::FormModel::validateField( Wt::WFormModel::Field field )
210 {
211  COUT_LINE;
212  return Wt::WFormModel::validateField( field );
213 }
214 
215 
216 void Wtx::FormModel::setValidated( Wt::WFormModel::Field field, bool validated )
217 {
218  COUT_LINE;
219  Wt::WFormModel::setValidated( field, validated );
220 }
221 
222 
223 bool Wtx::FormModel::isValidated( Wt::WFormModel::Field field ) const
224 {
225  COUT_LINE;
226  return Wt::WFormModel::isValidated( field );
227 }
228 
229 
230 void Wtx::FormModel::setValidation( Wt::WFormModel::Field field, const Wt::WValidator::Result &result )
231 {
232  COUT_LINE;
233  Wt::WFormModel::setValidation( field, result );
234 }
235 
236 
237 
Table Definition.
Definition: TableDef.h:72
0x0010 ~ the field will not call upon createWidget
Definition: FieldDefBase.h:119
virtual Wt::WString label(Wt::WFormModel::Field field) const
Get Field Label.
Definition: FormModel.cpp:137