From 747b39db66cc0a8683b05ec5f09a22c9d04a9ab0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 26 Feb 2016 11:07:31 +0100 Subject: [PATCH] ibus: de-virtualize QIBusSerializable hierarchy These types don't inherit to be reused, they inherit to reuse. Consequently, change the inheritance to private, remove the virtual ~QIBusSerializable and rewrite the streaming operators as member functions. Remove the now-unused QIBusSerializable streaming operators and meta-type registration. Change-Id: Icf7a89174592ba62b39f73f0f016c8296cab5993 Reviewed-by: Takao Fujiwara Reviewed-by: Lars Knoll --- .../platforminputcontexts/ibus/main.cpp | 1 - .../platforminputcontexts/ibus/qibustypes.cpp | 162 ++++++++---------- .../platforminputcontexts/ibus/qibustypes.h | 53 ++++-- 3 files changed, 112 insertions(+), 104 deletions(-) diff --git a/src/plugins/platforminputcontexts/ibus/main.cpp b/src/plugins/platforminputcontexts/ibus/main.cpp index b47c0b40de..2846f52c8c 100644 --- a/src/plugins/platforminputcontexts/ibus/main.cpp +++ b/src/plugins/platforminputcontexts/ibus/main.cpp @@ -59,7 +59,6 @@ QIBusPlatformInputContext *QIbusPlatformInputContextPlugin::create(const QString Q_UNUSED(paramList); if (system.compare(system, QLatin1String("ibus"), Qt::CaseInsensitive) == 0) { - qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); diff --git a/src/plugins/platforminputcontexts/ibus/qibustypes.cpp b/src/plugins/platforminputcontexts/ibus/qibustypes.cpp index a168836a06..9d219ff8c1 100644 --- a/src/plugins/platforminputcontexts/ibus/qibustypes.cpp +++ b/src/plugins/platforminputcontexts/ibus/qibustypes.cpp @@ -54,9 +54,9 @@ QIBusSerializable::~QIBusSerializable() { } -const QDBusArgument &operator>>(const QDBusArgument &argument, QIBusSerializable &object) +void QIBusSerializable::deserializeFrom(const QDBusArgument &argument) { - argument >> object.name; + argument >> name; argument.beginMap(); while (!argument.atEnd()) { @@ -66,19 +66,18 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, QIBusSerializable argument >> key; argument >> value; argument.endMapEntry(); - object.attachments[key] = value.variant().value(); + attachments[key] = value.variant().value(); } argument.endMap(); - return argument; } -QDBusArgument &operator<<(QDBusArgument &argument, const QIBusSerializable &object) +void QIBusSerializable::serializeTo(QDBusArgument &argument) const { - argument << object.name; + argument << name; argument.beginMap(qMetaTypeId(), qMetaTypeId()); - QHashIterator i(object.attachments); + QHashIterator i(attachments); while (i.hasNext()) { i.next(); @@ -91,7 +90,6 @@ QDBusArgument &operator<<(QDBusArgument &argument, const QIBusSerializable &obje argument.endMapEntry(); } argument.endMap(); - return argument; } QIBusAttribute::QIBusAttribute() @@ -107,39 +105,35 @@ QIBusAttribute::~QIBusAttribute() { } -QDBusArgument &operator<<(QDBusArgument &argument, const QIBusAttribute &attribute) +void QIBusAttribute::serializeTo(QDBusArgument &argument) const { argument.beginStructure(); - argument << static_cast(attribute); + QIBusSerializable::serializeTo(argument); - quint32 t = (quint32) attribute.type; + quint32 t = (quint32) type; argument << t; - argument << attribute.value; - argument << attribute.start; - argument << attribute.end; + argument << value; + argument << start; + argument << end; argument.endStructure(); - - return argument; } -const QDBusArgument &operator>>(const QDBusArgument &argument, QIBusAttribute &attribute) +void QIBusAttribute::deserializeFrom(const QDBusArgument &argument) { argument.beginStructure(); - argument >> static_cast(attribute); + QIBusSerializable::deserializeFrom(argument); quint32 t; argument >> t; - attribute.type = (QIBusAttribute::Type) t; - argument >> attribute.value; - argument >> attribute.start; - argument >> attribute.end; + type = (QIBusAttribute::Type) t; + argument >> value; + argument >> start; + argument >> end; argument.endStructure(); - - return argument; } QTextCharFormat QIBusAttribute::format() const @@ -191,30 +185,30 @@ QIBusAttributeList::~QIBusAttributeList() { } -QDBusArgument &operator<<(QDBusArgument &argument, const QIBusAttributeList &attrList) +void QIBusAttributeList::serializeTo(QDBusArgument &argument) const { argument.beginStructure(); - argument << static_cast(attrList); + QIBusSerializable::serializeTo(argument); argument.beginArray(qMetaTypeId()); - for (int i = 0; i < attrList.attributes.size(); ++i) { + for (int i = 0; i < attributes.size(); ++i) { QVariant variant; - variant.setValue(attrList.attributes.at(i)); + variant.setValue(attributes.at(i)); argument << QDBusVariant (variant); } argument.endArray(); argument.endStructure(); - return argument; } -const QDBusArgument &operator>>(const QDBusArgument &arg, QIBusAttributeList &attrList) +void QIBusAttributeList::deserializeFrom(const QDBusArgument &arg) { qCDebug(qtQpaInputMethodsSerialize) << "QIBusAttributeList::fromDBusArgument()" << arg.currentSignature(); + arg.beginStructure(); - arg >> static_cast(attrList); + QIBusSerializable::deserializeFrom(arg); arg.beginArray(); while (!arg.atEnd()) { @@ -223,12 +217,11 @@ const QDBusArgument &operator>>(const QDBusArgument &arg, QIBusAttributeList &at QIBusAttribute attr; var.variant().value() >> attr; - attrList.attributes.append(attr); + attributes.append(attr); } arg.endArray(); arg.endStructure(); - return arg; } QList QIBusAttributeList::imAttributes() const @@ -273,31 +266,30 @@ QIBusText::~QIBusText() { } -QDBusArgument &operator<<(QDBusArgument &argument, const QIBusText &text) +void QIBusText::serializeTo(QDBusArgument &argument) const { argument.beginStructure(); - argument << static_cast(text); + QIBusSerializable::serializeTo(argument); - argument << text.text << text.attributes; + argument << text << attributes; argument.endStructure(); - return argument; } -const QDBusArgument &operator>>(const QDBusArgument &argument, QIBusText &text) +void QIBusText::deserializeFrom(const QDBusArgument &argument) { qCDebug(qtQpaInputMethodsSerialize) << "QIBusText::fromDBusArgument()" << argument.currentSignature(); + argument.beginStructure(); - argument >> static_cast(text); + QIBusSerializable::deserializeFrom(argument); - argument >> text.text; + argument >> text; QDBusVariant variant; argument >> variant; - variant.variant().value() >> text.attributes; + variant.variant().value() >> attributes; argument.endStructure(); - return argument; } QIBusEngineDesc::QIBusEngineDesc() @@ -326,81 +318,79 @@ QIBusEngineDesc::~QIBusEngineDesc() { } -QDBusArgument &operator<<(QDBusArgument &argument, const QIBusEngineDesc &desc) +void QIBusEngineDesc::serializeTo(QDBusArgument &argument) const { argument.beginStructure(); - argument << static_cast(desc); + QIBusSerializable::serializeTo(argument); - argument << desc.engine_name; - argument << desc.longname; - argument << desc.description; - argument << desc.language; - argument << desc.license; - argument << desc.author; - argument << desc.icon; - argument << desc.layout; - argument << desc.rank; - argument << desc.hotkeys; - argument << desc.symbol; - argument << desc.setup; - argument << desc.layout_variant; - argument << desc.layout_option; - argument << desc.version; - argument << desc.textdomain; - argument << desc.iconpropkey; + argument << engine_name; + argument << longname; + argument << description; + argument << language; + argument << license; + argument << author; + argument << icon; + argument << layout; + argument << rank; + argument << hotkeys; + argument << symbol; + argument << setup; + argument << layout_variant; + argument << layout_option; + argument << version; + argument << textdomain; + argument << iconpropkey; argument.endStructure(); - return argument; } -const QDBusArgument &operator>>(const QDBusArgument &argument, QIBusEngineDesc &desc) +void QIBusEngineDesc::deserializeFrom(const QDBusArgument &argument) { qCDebug(qtQpaInputMethodsSerialize) << "QIBusEngineDesc::fromDBusArgument()" << argument.currentSignature(); argument.beginStructure(); - argument >> static_cast(desc); + QIBusSerializable::deserializeFrom(argument); - argument >> desc.engine_name; - argument >> desc.longname; - argument >> desc.description; - argument >> desc.language; - argument >> desc.license; - argument >> desc.author; - argument >> desc.icon; - argument >> desc.layout; - argument >> desc.rank; - argument >> desc.hotkeys; - argument >> desc.symbol; - argument >> desc.setup; + argument >> engine_name; + argument >> longname; + argument >> description; + argument >> language; + argument >> license; + argument >> author; + argument >> icon; + argument >> layout; + argument >> rank; + argument >> hotkeys; + argument >> symbol; + argument >> setup; // Previous IBusEngineDesc supports the arguments between engine_name // and setup. if (argument.currentSignature() == "") { argument.endStructure(); - return argument; + return; } - argument >> desc.layout_variant; - argument >> desc.layout_option; + argument >> layout_variant; + argument >> layout_option; // Previous IBusEngineDesc supports the arguments between engine_name // and layout_option. if (argument.currentSignature() == "") { argument.endStructure(); - return argument; + return; } - argument >> desc.version; + argument >> version; if (argument.currentSignature() == "") { argument.endStructure(); - return argument; + return; } - argument >> desc.textdomain; + argument >> textdomain; if (argument.currentSignature() == "") { argument.endStructure(); - return argument; + return; } - argument >> desc.iconpropkey; + argument >> iconpropkey; argument.endStructure(); - return argument; } QT_END_NAMESPACE diff --git a/src/plugins/platforminputcontexts/ibus/qibustypes.h b/src/plugins/platforminputcontexts/ibus/qibustypes.h index 9dca7e3903..9f2b0eb41f 100644 --- a/src/plugins/platforminputcontexts/ibus/qibustypes.h +++ b/src/plugins/platforminputcontexts/ibus/qibustypes.h @@ -54,13 +54,16 @@ class QIBusSerializable { public: QIBusSerializable(); - virtual ~QIBusSerializable(); + ~QIBusSerializable(); + + void serializeTo(QDBusArgument &argument) const; + void deserializeFrom(const QDBusArgument &argument); QString name; QHash attachments; }; -class QIBusAttribute : public QIBusSerializable +class QIBusAttribute : private QIBusSerializable { public: enum Type { @@ -83,13 +86,16 @@ public: QTextCharFormat format() const; + void serializeTo(QDBusArgument &argument) const; + void deserializeFrom(const QDBusArgument &argument); + Type type; quint32 value; quint32 start; quint32 end; }; -class QIBusAttributeList : public QIBusSerializable +class QIBusAttributeList : private QIBusSerializable { public: QIBusAttributeList(); @@ -97,25 +103,34 @@ public: QList imAttributes() const; + void serializeTo(QDBusArgument &argument) const; + void deserializeFrom(const QDBusArgument &argument); + QVector attributes; }; -class QIBusText : public QIBusSerializable +class QIBusText : private QIBusSerializable { public: QIBusText(); ~QIBusText(); + void serializeTo(QDBusArgument &argument) const; + void deserializeFrom(const QDBusArgument &argument); + QString text; QIBusAttributeList attributes; }; -class QIBusEngineDesc : public QIBusSerializable +class QIBusEngineDesc : private QIBusSerializable { public: QIBusEngineDesc(); ~QIBusEngineDesc(); + void serializeTo(QDBusArgument &argument) const; + void deserializeFrom(const QDBusArgument &argument); + QString engine_name; QString longname; QString description; @@ -135,24 +150,28 @@ public: QString iconpropkey; }; -QDBusArgument &operator<<(QDBusArgument &argument, const QIBusSerializable &object); -const QDBusArgument &operator>>(const QDBusArgument &argument, QIBusSerializable &object); +inline QDBusArgument &operator<<(QDBusArgument &argument, const QIBusAttribute &attribute) +{ attribute.serializeTo(argument); return argument; } +inline const QDBusArgument &operator>>(const QDBusArgument &argument, QIBusAttribute &attribute) +{ attribute.deserializeFrom(argument); return argument; } -QDBusArgument &operator<<(QDBusArgument &argument, const QIBusAttribute &attribute); -const QDBusArgument &operator>>(const QDBusArgument &argument, QIBusAttribute &attribute); +inline QDBusArgument &operator<<(QDBusArgument &argument, const QIBusAttributeList &attributeList) +{ attributeList.serializeTo(argument); return argument; } +inline const QDBusArgument &operator>>(const QDBusArgument &argument, QIBusAttributeList &attributeList) +{ attributeList.deserializeFrom(argument); return argument; } -QDBusArgument &operator<<(QDBusArgument &argument, const QIBusAttributeList &attributeList); -const QDBusArgument &operator>>(const QDBusArgument &arg, QIBusAttributeList &attrList); +inline QDBusArgument &operator<<(QDBusArgument &argument, const QIBusText &text) +{ text.serializeTo(argument); return argument; } +inline const QDBusArgument &operator>>(const QDBusArgument &argument, QIBusText &text) +{ text.deserializeFrom(argument); return argument; } -QDBusArgument &operator<<(QDBusArgument &argument, const QIBusText &text); -const QDBusArgument &operator>>(const QDBusArgument &argument, QIBusText &text); - -QDBusArgument &operator<<(QDBusArgument &argument, const QIBusEngineDesc &desc); -const QDBusArgument &operator>>(const QDBusArgument &argument, QIBusEngineDesc &desc); +inline QDBusArgument &operator<<(QDBusArgument &argument, const QIBusEngineDesc &desc) +{ desc.serializeTo(argument); return argument; } +inline const QDBusArgument &operator>>(const QDBusArgument &argument, QIBusEngineDesc &desc) +{ desc.deserializeFrom(argument); return argument; } QT_END_NAMESPACE -Q_DECLARE_METATYPE(QIBusSerializable) Q_DECLARE_METATYPE(QIBusAttribute) Q_DECLARE_METATYPE(QIBusAttributeList) Q_DECLARE_METATYPE(QIBusText)