Wtx ~ Wt Extension Library
WtxLib
FieldDefBase.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
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 <memory>
47 #include <iostream>
48 #include <vector>
49 
50 #include <Wt/WItemDelegate.h>
51 #include <Wt/WLineEdit.h>
52 #include <Wt/WText.h>
53 
54 #include <Wtx/Wtx.h>
55 
56 #include "TableDef.h"
57 #include "FieldDefBase.h"
58 
60 (
61  TableDef & td,
62  const char * fn,
63  int w,
64  int h,
65  Flags f,
66  std::string lb,
67  std::string ph,
68  std::string inf,
69  std::string tt,
70  int ht
71 )
72 : Wt::WObject(),
73  m_tableDef(td),
74  m_fieldName(fn),
75  m_width(w),
76  m_height(h),
77  m_flags(f),
78  m_label(lb),
79  m_placeholderText(ph),
80  m_info(inf),
81  m_toolTip(tt),
82  m_helpTopic(ht)
83 {
84  init();
85 }
86 
88 (
89  TableDef & td,
90  const char * fn,
91  std::string lb,
92  std::string ph,
93  std::string inf,
94  std::string tt,
95  int ht
96 )
97 : Wt::WObject(),
98  m_tableDef(td),
99  m_fieldName(fn),
100  m_width(-1),
101  m_height(-1),
102  m_label(lb),
103  m_placeholderText(ph),
104  m_info(inf),
105  m_toolTip(tt),
106  m_helpTopic(ht)
107 {
108  init();
109 }
110 
111 void Wtx::Dbo::FieldDefBase::init()
112 {
113  /*
114  ** push this field definition up in to the table
115  ** definition.
116  **
117  */
118  tableDef().push_back( *this );
119 }
120 
121 Wtx::Dbo::TableDef & Wtx::Dbo::FieldDefBase::tableDef() const
122 {
123  return m_tableDef;
124 }
125 
126 const char * Wtx::Dbo::FieldDefBase::fieldName() const
127 {
128  return m_fieldName;
129 }
130 
131 const std::string & Wtx::Dbo::FieldDefBase::aliasName() const
132 {
133  return m_aliasName;
134 }
135 
136 int Wtx::Dbo::FieldDefBase::width() const
137 {
138  return m_width;
139 }
140 
141 void Wtx::Dbo::FieldDefBase::setWidth( int value )
142 {
143  m_width = value;
144 }
145 
146 int Wtx::Dbo::FieldDefBase::height() const
147 {
148  return m_height;
149 }
150 
151 void Wtx::Dbo::FieldDefBase::setHeight( int value )
152 {
153  m_height = value;
154 }
155 
156 bool Wtx::Dbo::FieldDefBase::isReadOnly() const
157 {
158  return m_isReadOnly;
159 }
160 
161 void Wtx::Dbo::FieldDefBase::setIsReadOnly( bool value )
162 {
163  m_isReadOnly = value;
164 }
165 
166 bool Wtx::Dbo::FieldDefBase::isUnique() const
167 {
168  return m_isUnique;
169 }
170 
171 void Wtx::Dbo::FieldDefBase::setIsUnique( bool value )
172 {
173  m_isUnique = value;
174 }
175 
176 bool Wtx::Dbo::FieldDefBase::isVisible() const
177 {
178  return m_isVisible;
179 }
180 
181 void Wtx::Dbo::FieldDefBase::setIsVisible( bool value )
182 {
183  m_isVisible = value;
184 }
185 
186 const std::string & Wtx::Dbo::FieldDefBase::label() const
187 {
188  return m_label;
189 }
190 
191 void Wtx::Dbo::FieldDefBase::setLabel( const std::string & value )
192 {
193  m_label = value;
194 }
195 
196 const std::string & Wtx::Dbo::FieldDefBase::placeholderText() const
197 {
198  return m_placeholderText;
199 }
200 
201 void Wtx::Dbo::FieldDefBase::setPlaceholderText( const std::string & value )
202 {
203  m_placeholderText = value;
204 }
205 
206 const std::string & Wtx::Dbo::FieldDefBase::info() const
207 {
208  return m_info;
209 }
210 
211 void Wtx::Dbo::FieldDefBase::setInfo( const std::string & value )
212 {
213  m_info = value;
214 }
215 
216 const std::string & Wtx::Dbo::FieldDefBase::toolTip() const
217 {
218  return m_toolTip;
219 }
220 
221 void Wtx::Dbo::FieldDefBase::setToolTip( const std::string & value )
222 {
223  m_toolTip = value;
224 }
225 
226 int Wtx::Dbo::FieldDefBase::helpTopic() const
227 {
228  return m_helpTopic;
229 }
230 
231 void Wtx::Dbo::FieldDefBase::setHelpTopic( int value )
232 {
233  m_helpTopic = value;
234 }
235 
236 const Wtx::Dbo::FieldDefBase::Flags & Wtx::Dbo::FieldDefBase::flags() const
237 {
238  return m_flags;
239 }
240 
241 void Wtx::Dbo::FieldDefBase::setFlags( const Wtx::Dbo::FieldDefBase::Flags value )
242 {
243  m_flags = value;
244 }
245 
246 const std::string & Wtx::Dbo::FieldDefBase::defaultValue() const
247 {
248  return m_defaultValue;
249 }
250 
251 void Wtx::Dbo::FieldDefBase::setDefaultValue( const std::string & value )
252 {
253  m_defaultValue = value;
254 }
255 
256 bool Wtx::Dbo::FieldDefBase::forceUppercase() const
257 {
258  return m_forceUppercase || Wtx::forceUppercase();
259 }
260 
261 void Wtx::Dbo::FieldDefBase::setForceUppercase( bool value )
262 {
263  m_forceUppercase = value;
264 }
265 
266 const std::string & Wtx::Dbo::FieldDefBase::inputMask() const
267 {
268  return m_inputMask;
269 }
270 
271 void Wtx::Dbo::FieldDefBase::setInputMask( const std::string & mask, Wt::WFlags< Wt::InputMaskFlag > flags )
272 {
273  m_inputMask = mask;
274  m_inputMaskFlags = flags;
275 }
276 
277 std::unique_ptr<Wt::WItemDelegate> Wtx::Dbo::FieldDefBase::createItemDelegate( int sid, Wtx::Dbo::Session & session ) const
278 {
279 // std::cout << __FILE__ << ":" << __LINE__ << " " << __PRETTY_FUNCTION__ << std::endl;
280  return std::make_unique<Wt::WItemDelegate>();
281 }
282 
283 std::unique_ptr<Wt::WWidget> Wtx::Dbo::FieldDefBase::createLabelWidget( int sid, Wtx::Dbo::Session & session ) const
284 {
285 // std::cout << __FILE__ << ":" << __LINE__ << " " << __PRETTY_FUNCTION__ << std::endl;
286  return std::make_unique<Wt::WText>(m_label);
287 }
288 
289 std::unique_ptr<Wt::WWidget> Wtx::Dbo::FieldDefBase::createEditWidget( int sid, Wtx::Dbo::Session & session ) const
290 {
291  auto retVal = std::make_unique<Wt::WLineEdit>();
292 
293  retVal-> setPlaceholderText( placeholderText() );
294  retVal-> setInputMask( inputMask(), m_inputMaskFlags );
295 
296  return retVal;
297 }
298 
299 std::unique_ptr<Wt::WWidget> Wtx::Dbo::FieldDefBase::createDisplayWidget( int sid, Wtx::Dbo::Session & session ) const
300 {
301 // std::cout << __FILE__ << ":" << __LINE__ << " " << __PRETTY_FUNCTION__ << std::endl;
302  return std::make_unique<Wt::WText>();
303 }
304 
305 std::string Wtx::Dbo::FieldDefBase::toJson() const
306 {
307  std::string retVal;
308 
309  retVal += "{";
310 
311  retVal += " \"fieldName\":";
312  retVal += " \"" + std::string(m_fieldName) + "\"";
313 
314  retVal += ",\n \"width\":";
315  retVal += " " + std::to_string(m_width);
316 
317  retVal += ",\n \"label\":";
318  retVal += " \"" + std::string(m_label) + "\"";
319 
320  retVal += "}";
321 
322  return retVal;
323 }
324 
325 void Wtx::Dbo::FieldDefBase::fromJson( const std::string & value )
326 {
327 }
328 
Table Definition.
Definition: TableDef.h:72
FieldDefBase(TableDef &td, const char *fn, int w=-1, int h=-1, Flags f=Flags::None, std::string lb="", std::string ph="", std::string inf="", std::string tt="", int ht=-1)
ctor field definition object
Flags
Field Definition Flags.
Definition: FieldDefBase.h:101