+
+SyncableObject::SyncableObject(const SyncableObject &other, QObject *parent)
+ : QObject(parent),
+ _initialized(other._initialized),
+ _allowClientUpdates(other._allowClientUpdates)
+{
+}
+
+
+SyncableObject::~SyncableObject()
+{
+ QList<SignalProxy *>::iterator proxyIter = _signalProxies.begin();
+ while (proxyIter != _signalProxies.end()) {
+ 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();
+
+ // we collect data from properties
+ QMetaProperty prop;
+ QString propName;
+ for (int i = 0; i < meta->propertyCount(); i++) {
+ 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"
+ for (int i = 0; i < meta->methodCount(); i++) {
+ QMetaMethod method = meta->method(i);
+ QString methodname(SignalProxy::ExtendedMetaObject::methodName(method));
+ if (!methodname.startsWith("init") || methodname.startsWith("initSet") || methodname.startsWith("initDone"))
+ continue;
+
+ 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
+ continue;
+ }
+
+ QVariant value(variantType, (const void *)0);
+ QGenericReturnArgument genericvalue = QGenericReturnArgument(method.typeName(), value.data());
+ QMetaObject::invokeMethod(this, methodname.toLatin1(), genericvalue);
+
+ properties[SignalProxy::ExtendedMetaObject::methodBaseName(method)] = value;
+ }
+ return properties;