X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fsyncableobject.cpp;h=825b97db32d62a2a787fe1a6e7b533f8581c5969;hp=3a1799e2883a88db5f4bb41a4e979eaf84f8be52;hb=673ded0d543cbdc2cf6e746b6bee7c1d21af8f90;hpb=83662b607de9eb742fe9de4dd9445914a6bd9456 diff --git a/src/common/syncableobject.cpp b/src/common/syncableobject.cpp index 3a1799e2..825b97db 100644 --- a/src/common/syncableobject.cpp +++ b/src/common/syncableobject.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 by the Quassel Project * + * Copyright (C) 2005-2020 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,81 +18,58 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include +#include "syncableobject.h" #include - -#include "syncableobject.h" +#include #include "signalproxy.h" #include "util.h" -INIT_SYNCABLE_OBJECT(SyncableObject) -SyncableObject::SyncableObject(QObject *parent) - : QObject(parent), - _initialized(false), - _allowClientUpdates(false) -{ -} +SyncableObject::SyncableObject(QObject* parent) + : SyncableObject(QString{}, parent) +{} - -SyncableObject::SyncableObject(const QString &objectName, QObject *parent) - : QObject(parent), - _initialized(false), - _allowClientUpdates(false) +SyncableObject::SyncableObject(const QString& objectName, QObject* parent) + : QObject(parent) { + _objectName = objectName; setObjectName(objectName); -} - -SyncableObject::SyncableObject(const SyncableObject &other, QObject *parent) - : QObject(parent), - _initialized(other._initialized), - _allowClientUpdates(other._allowClientUpdates) -{ + connect(this, &QObject::objectNameChanged, this, [this](auto&& newName) { + for (auto&& proxy : _signalProxies) { + proxy->renameObject(this, newName, _objectName); + } + _objectName = newName; + }); } - SyncableObject::~SyncableObject() { - QList::iterator proxyIter = _signalProxies.begin(); + QList::iterator proxyIter = _signalProxies.begin(); while (proxyIter != _signalProxies.end()) { - SignalProxy *proxy = (*proxyIter); + SignalProxy* proxy = (*proxyIter); proxyIter = _signalProxies.erase(proxyIter); proxy->stopSynchronize(this); } } - -SyncableObject &SyncableObject::operator=(const SyncableObject &other) -{ - if (this == &other) - return *this; - - _initialized = other._initialized; - _allowClientUpdates = other._allowClientUpdates; - return *this; -} - - bool SyncableObject::isInitialized() const { return _initialized; } - void SyncableObject::setInitialized() { _initialized = true; emit initDone(); } - QVariantMap SyncableObject::toVariantMap() { QVariantMap properties; - const QMetaObject *meta = metaObject(); + const QMetaObject* meta = metaObject(); // we collect data from properties QMetaProperty prop; @@ -114,15 +91,12 @@ QVariantMap SyncableObject::toVariantMap() QVariant::Type variantType = QVariant::nameToType(method.typeName()); if (variantType == QVariant::Invalid && !QByteArray(method.typeName()).isEmpty()) { -#if QT_VERSION >= 0x050000 - qWarning() << "SyncableObject::toVariantMap(): cannot fetch init data for:" << this << method.methodSignature() << "- Returntype is unknown to Qt's MetaSystem:" << QByteArray(method.typeName()); -#else - qWarning() << "SyncableObject::toVariantMap(): cannot fetch init data for:" << this << method.signature() << "- Returntype is unknown to Qt's MetaSystem:" << QByteArray(method.typeName()); -#endif + qWarning() << "SyncableObject::toVariantMap(): cannot fetch init data for:" << this << method.methodSignature() + << "- Returntype is unknown to Qt's MetaSystem:" << QByteArray(method.typeName()); continue; } - QVariant value(variantType, (const void *)0); + QVariant value(variantType, (const void*)nullptr); QGenericReturnArgument genericvalue = QGenericReturnArgument(method.typeName(), value.data()); QMetaObject::invokeMethod(this, methodname.toLatin1(), genericvalue); @@ -131,10 +105,9 @@ QVariantMap SyncableObject::toVariantMap() return properties; } - -void SyncableObject::fromVariantMap(const QVariantMap &properties) +void SyncableObject::fromVariantMap(const QVariantMap& properties) { - const QMetaObject *meta = metaObject(); + const QMetaObject* meta = metaObject(); QVariantMap::const_iterator iterator = properties.constBegin(); QString propName; @@ -156,15 +129,14 @@ void SyncableObject::fromVariantMap(const QVariantMap &properties) } } - -bool SyncableObject::setInitValue(const QString &property, const QVariant &value) +bool SyncableObject::setInitValue(const QString& property, const QVariant& value) { QString handlername = QString("initSet") + property; handlername[7] = handlername[7].toUpper(); QString methodSignature = QString("%1(%2)").arg(handlername).arg(value.typeName()); int methodIdx = metaObject()->indexOfMethod(methodSignature.toLatin1().constData()); - if (methodIdx < 0) { + if (methodIdx < 0) { QByteArray normedMethodName = QMetaObject::normalizedSignature(methodSignature.toLatin1().constData()); methodIdx = metaObject()->indexOfMethod(normedMethodName.constData()); } @@ -176,28 +148,14 @@ bool SyncableObject::setInitValue(const QString &property, const QVariant &value return QMetaObject::invokeMethod(this, handlername.toLatin1(), param); } - -void SyncableObject::renameObject(const QString &newName) -{ - const QString oldName = objectName(); - if (oldName != newName) { - setObjectName(newName); - foreach(SignalProxy *proxy, _signalProxies) { - proxy->renameObject(this, newName, oldName); - } - } -} - - -void SyncableObject::update(const QVariantMap &properties) +void SyncableObject::update(const QVariantMap& properties) { fromVariantMap(properties); SYNC(ARG(properties)) emit updated(); } - -void SyncableObject::requestUpdate(const QVariantMap &properties) +void SyncableObject::requestUpdate(const QVariantMap& properties) { if (allowClientUpdates()) { update(properties); @@ -205,11 +163,10 @@ void SyncableObject::requestUpdate(const QVariantMap &properties) REQUEST(ARG(properties)) } - -void SyncableObject::sync_call__(SignalProxy::ProxyMode modeType, const char *funcname, ...) const +void SyncableObject::sync_call__(SignalProxy::ProxyMode modeType, const char* funcname, ...) const { - //qDebug() << Q_FUNC_INFO << modeType << funcname; - foreach(SignalProxy *proxy, _signalProxies) { + // qDebug() << Q_FUNC_INFO << modeType << funcname; + foreach (SignalProxy* proxy, _signalProxies) { va_list ap; va_start(ap, funcname); proxy->sync_call__(this, modeType, funcname, ap); @@ -217,16 +174,14 @@ void SyncableObject::sync_call__(SignalProxy::ProxyMode modeType, const char *fu } } - -void SyncableObject::synchronize(SignalProxy *proxy) +void SyncableObject::synchronize(SignalProxy* proxy) { if (_signalProxies.contains(proxy)) return; _signalProxies << proxy; } - -void SyncableObject::stopSynchronize(SignalProxy *proxy) +void SyncableObject::stopSynchronize(SignalProxy* proxy) { for (int i = 0; i < _signalProxies.count(); i++) { if (_signalProxies[i] == proxy) {