22
33CWF_BEGIN_NAMESPACE
44
5- Model::Model (const QString &name) : QObject(nullptr )
6- {
7- m_name = name;
8- }
9-
10- Model::~Model ()
11- {
12-
13- }
14-
155void Model::updateDB ()
166{
177 // ****************************************************************
@@ -45,7 +35,7 @@ void Model::build(const QMap<QString, QVariant> &selectCondition)
4535
4636 QStringList properties = listAllProperties ();
4737
48- QMap<QString, QVariant> propValueMap = m_basicOperation .build (m_name , selectCondition, properties);
38+ QMap<QString, QVariant> propValueMap = basicOperation .build (name , selectCondition, properties);
4939
5040 // Loop on all the prop value to update the current object
5141 for (const auto & it : propValueMap.toStdMap () )
@@ -56,9 +46,9 @@ void Model::build(const QMap<QString, QVariant> &selectCondition)
5646 // Depending on the content of propValueMap, we set the built flag to true or false.
5747 // If the db query failed then the list is empty here.
5848 if (propValueMap.empty () )
59- m_built = false ;
49+ built = false ;
6050 else
61- m_built = true ;
51+ built = true ;
6252}
6353
6454void Model::buildFromJson (const QJsonObject &json, bool withTableNamePrefix)
@@ -79,7 +69,7 @@ void Model::buildFromJson(const QJsonObject &json, bool withTableNamePrefix)
7969
8070 if (jsonValue.isUndefined () )
8171 {
82- m_built = false ;
72+ built = false ;
8373 break ;
8474 }
8575
@@ -89,7 +79,7 @@ void Model::buildFromJson(const QJsonObject &json, bool withTableNamePrefix)
8979
9080 if (!success)
9181 {
92- m_built = false ;
82+ built = false ;
9383 break ;
9484 }
9585 }
@@ -113,14 +103,14 @@ bool Model::save()
113103 QDateTime currentDt = QDateTime::currentDateTime ();
114104
115105 // Creation of a new object
116- if (m_id == -1 )
106+ if (id == -1 )
117107 {
118- this ->setProperty (" createdDateTime" , currentDt.toString (m_dtFormat ) );
108+ this ->setProperty (" createdDateTime" , currentDt.toString (dtFormat ) );
119109 setCreatedDt (currentDt);
120110 }
121111
122112 // Modification
123- this ->setProperty (" lastModifiedDateTime" , currentDt.toString (m_dtFormat ) );
113+ this ->setProperty (" lastModifiedDateTime" , currentDt.toString (dtFormat ) );
124114 setLastModifiedDt (currentDt);
125115
126116 // --------------------------------------------------
@@ -133,7 +123,7 @@ bool Model::save()
133123
134124 QMap<QString, QVariant> propsMap = computePropsMap (*this );
135125
136- qint64 id = m_basicOperation .save (m_name , propsMap);
126+ qint64 id = basicOperation .save (name , propsMap);
137127
138128 setProperty (" id" , id);
139129
@@ -147,27 +137,27 @@ bool Model::remove()
147137{
148138 const qint64& id = getId ();
149139
150- return m_basicOperation .remove (getTableName (), id);
140+ return basicOperation .remove (getTableName (), id);
151141}
152142
153143QString Model::getCreatedDtStr () const
154144{
155- return m_createdDateTime ;
145+ return createdDateTime ;
156146}
157147
158148QDateTime Model::getCreatedDt () const
159149{
160- return QDateTime::fromString (m_createdDateTime, m_dtFormat );
150+ return QDateTime::fromString (createdDateTime, dtFormat );
161151}
162152
163153QDateTime Model::getLastModifiedDt () const
164154{
165- return QDateTime::fromString (m_lastModifiedDateTime, m_dtFormat );
155+ return QDateTime::fromString (lastModifiedDateTime, dtFormat );
166156}
167157
168158QString Model::getLastModifiedDtStr () const
169159{
170- return m_lastModifiedDateTime ;
160+ return lastModifiedDateTime ;
171161}
172162
173163QStringList Model::listAllProperties () const
@@ -207,15 +197,15 @@ bool Model::preSaveCheck() const
207197
208198void Model::verifyDbTableExist ()
209199{
210- bool tableExistInDb = m_basicOperation .isTableInDb (m_name );
200+ bool tableExistInDb = basicOperation .isTableInDb (name );
211201
212202 if (!tableExistInDb)
213203 {
214- bool success = m_basicOperation .createTable (m_name );
204+ bool success = basicOperation .createTable (name );
215205
216206 if (success)
217207 {
218- qInfo () << " Model::verifyDbTableExist:" << " Table " << m_name << " was successfuly created" ;
208+ qInfo () << " Model::verifyDbTableExist:" << " Table " << name << " was successfuly created" ;
219209 }
220210 }
221211}
@@ -229,7 +219,7 @@ void Model::verifyDbFields()
229219 QStringList fieldsFromObject = listAllProperties ();
230220
231221 // Then get all the fields of the object that are stored in the db
232- QStringList fieldsFromDb = m_basicOperation .fields (m_name );
222+ QStringList fieldsFromDb = basicOperation .fields (name );
233223
234224 // Loop on all the fields of the object and check if they are in the database
235225 for (const QString& fieldName : fieldsFromObject)
@@ -240,7 +230,7 @@ void Model::verifyDbFields()
240230 {
241231 // The field is not present in the db and we need to add it
242232
243- qInfo () << " Model::verifyDbFields:" << " In" << m_name
233+ qInfo () << " Model::verifyDbFields:" << " In" << name
244234 << " the field" << fieldName << " is present in the object but was not found in database."
245235 << " We update the database."
246236 ;
@@ -250,9 +240,9 @@ void Model::verifyDbFields()
250240
251241 QVariant::Type propertyType = this ->propertyType (fieldName);
252242
253- m_basicOperation .addFieldToTable (fieldName, propertyType, m_name );
243+ basicOperation .addFieldToTable (fieldName, propertyType, name );
254244
255- customizeField (fieldName, propertyType, m_name );
245+ customizeField (fieldName, propertyType, name );
256246 }
257247 }
258248
@@ -272,13 +262,13 @@ void Model::verifyDbFields()
272262 // If we performed a change in the db
273263 if (dbChangedPerformed)
274264 {
275- qInfo () << " The database was modified to update the table" << m_name << " ."
265+ qInfo () << " The database was modified to update the table" << name << " ."
276266 << " We will update the version for this table."
277267 ;
278268
279- qint32 tableVersion = m_basicOperation .tableVersion (m_name );
269+ qint32 tableVersion = basicOperation .tableVersion (name );
280270 tableVersion += 1 ;
281- m_basicOperation .changeTableVersion (m_name , tableVersion);
271+ basicOperation .changeTableVersion (name , tableVersion);
282272 }
283273}
284274
@@ -310,7 +300,7 @@ QMetaProperty Model::findProperty(const QString &propertyName) const
310300
311301 if (!found)
312302 {
313- QString msg = QString (" " ) + " Model::findProperty:" + " The property " + propertyName + " was not found in " + m_name ;
303+ QString msg = QString (" " ) + " Model::findProperty:" + " The property " + propertyName + " was not found in " + name ;
314304 qDebug () << msg;
315305 qFatal (" Property should always be found here" );
316306 }
@@ -362,7 +352,7 @@ void Model::setCreatedDt(const QDateTime &dt)
362352{
363353 if (dt != getCreatedDt () )
364354 {
365- m_createdDateTime = dt.toString (m_dtFormat );
355+ createdDateTime = dt.toString (dtFormat );
366356
367357 createdDateTimeChanged ();
368358 }
@@ -372,7 +362,7 @@ void Model::setLastModifiedDt(const QDateTime &dt)
372362{
373363 if (dt != getLastModifiedDt () )
374364 {
375- m_lastModifiedDateTime = dt.toString (m_dtFormat );
365+ lastModifiedDateTime = dt.toString (dtFormat );
376366
377367 lastModifiedDateTimeChanged ();
378368 }
0 commit comments