X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fsyncableobject.cpp;h=426bc86cf28dd3d8f122a7e85285c6af44c5e87c;hp=781dd15109e5123d63cf70df0440d0a8ce429913;hb=997a62b68d7469a93f373476dd955c44eb051be0;hpb=ad801015af3afad53e0b245afc3a2214373a1b44 diff --git a/src/common/syncableobject.cpp b/src/common/syncableobject.cpp index 781dd151..426bc86c 100644 --- a/src/common/syncableobject.cpp +++ b/src/common/syncableobject.cpp @@ -27,13 +27,18 @@ #include "signalproxy.h" #include "util.h" -SyncableObject::SyncableObject(QObject *parent) : QObject(parent) { - _initialized = false; +SyncableObject::SyncableObject(QObject *parent) + : QObject(parent), + _initialized(false), + _allowClientUpdates(false) +{ } -SyncableObject::SyncableObject(const SyncableObject &other, QObject *parent) : QObject(parent) { - _initialized = other._initialized; - +SyncableObject::SyncableObject(const SyncableObject &other, QObject *parent) + : QObject(parent), + _initialized(other._initialized), + _allowClientUpdates(false) +{ } bool SyncableObject::isInitialized() const { @@ -51,9 +56,14 @@ QVariantMap SyncableObject::toVariantMap() { const QMetaObject* meta = metaObject(); // we collect data from properties + QMetaProperty prop; + QString propName; for(int i = 0; i < meta->propertyCount(); i++) { - QMetaProperty prop = meta->property(i); - properties[QString(prop.name())] = prop.read(this); + prop = meta->property(i); + propName = QString(prop.name()); + if(propName == "objectName") + continue; + properties[propName] = prop.read(this); } // ...as well as methods, which have names starting with "init" @@ -84,14 +94,20 @@ void SyncableObject::fromVariantMap(const QVariantMap &properties) { const QMetaObject *meta = metaObject(); QVariantMap::const_iterator iterator = properties.constBegin(); + QString propName; while(iterator != properties.constEnd()) { - QString name = iterator.key(); - int propertyIndex = meta->indexOfProperty(name.toAscii()); + propName = iterator.key(); + if(propName == "objectName") { + iterator++; + continue; + } + + int propertyIndex = meta->indexOfProperty(propName.toAscii()); if(propertyIndex == -1 || !meta->property(propertyIndex).isWritable()) - setInitValue(name, iterator.value()); + setInitValue(propName, iterator.value()); else - setProperty(name.toAscii(), iterator.value()); + setProperty(propName.toAscii(), iterator.value()); // qDebug() << "<<< SYNC:" << name << iterator.value(); iterator++; } @@ -111,3 +127,15 @@ void SyncableObject::renameObject(const QString &newName) { emit objectRenamed(newName, oldName); } } + +void SyncableObject::update(const QVariantMap &properties) { + fromVariantMap(properties); + emit updated(properties); +} + +void SyncableObject::requestUpdate(const QVariantMap &properties) { + if(allowClientUpdates()) { + update(properties); + } + emit updateRequested(properties); +}