Added copyTo and copyTouchedTo methods to DbMsgFieldBase
This commit is contained in:
@@ -8,17 +8,28 @@ int main(int argc, char **argv)
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
MyMessage message("Daniel", QDate(1996, 11, 12), QDateTime::currentDateTime(), 21, 80);
|
||||
message.debug();
|
||||
|
||||
qDebug() << "changing name...";
|
||||
QVariantMap map;
|
||||
message.copyTo(map);
|
||||
qDebug() << "full" << map;
|
||||
|
||||
message.setName("Peter");
|
||||
message.debug();
|
||||
|
||||
map.clear();
|
||||
message.copyTo(map);
|
||||
qDebug() << "full" << map;
|
||||
|
||||
map.clear();
|
||||
message.copyTouchedTo(map);
|
||||
qDebug() << "delta:" << map;
|
||||
|
||||
qDebug() << "clearing touched...";
|
||||
|
||||
message.setTouched(false);
|
||||
message.debug();
|
||||
|
||||
map.clear();
|
||||
message.copyTouchedTo(map);
|
||||
qDebug() << "delta:" << map;
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
#include "dbmsglib.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QJsonObject>
|
||||
#include <QVariantMap>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -49,3 +51,30 @@ void DbMsgBase::debug() const
|
||||
for(auto iter = fields.cbegin(); iter != fields.cend(); iter++)
|
||||
qDebug() << iter.key() << iter.value()->getVariant() << iter.value()->touched();
|
||||
}
|
||||
|
||||
void DbMsgBase::copyTo(QJsonObject &jsonObject) const
|
||||
{
|
||||
Q_UNUSED(jsonObject)
|
||||
qCritical() << "has not been implemented for json yet";
|
||||
}
|
||||
|
||||
void DbMsgBase::copyTo(QVariantMap &variantMap) const
|
||||
{
|
||||
const auto fields = getFields();
|
||||
for(auto iter = fields.cbegin(); iter != fields.cend(); iter++)
|
||||
variantMap.insert(iter.key(), iter.value()->getVariant());
|
||||
}
|
||||
|
||||
void DbMsgBase::copyTouchedTo(QJsonObject &jsonObject) const
|
||||
{
|
||||
Q_UNUSED(jsonObject)
|
||||
qCritical() << "has not been implemented for json yet";
|
||||
}
|
||||
|
||||
void DbMsgBase::copyTouchedTo(QVariantMap &variantMap) const
|
||||
{
|
||||
const auto fields = getFields();
|
||||
for(auto iter = fields.cbegin(); iter != fields.cend(); iter++)
|
||||
if(iter.value()->touched())
|
||||
variantMap.insert(iter.key(), iter.value()->getVariant());
|
||||
}
|
||||
|
@@ -4,6 +4,8 @@
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
|
||||
class QJsonObject;
|
||||
|
||||
class DbMsgFieldBase
|
||||
{
|
||||
public:
|
||||
@@ -97,6 +99,12 @@ public:
|
||||
|
||||
void debug() const;
|
||||
|
||||
void copyTo(QJsonObject &jsonObject) const;
|
||||
void copyTo(QVariantMap &variantMap) const;
|
||||
|
||||
void copyTouchedTo(QJsonObject &jsonObject) const;
|
||||
void copyTouchedTo(QVariantMap &variantMap) const;
|
||||
|
||||
protected:
|
||||
virtual QMap<QString, DbMsgFieldBase*> getFields() = 0;
|
||||
virtual QMap<QString, const DbMsgFieldBase*> getFields() const = 0;
|
||||
|
Reference in New Issue
Block a user