From 51e8a6a208ae2f3ec75dfaed93b553425bab2a1d Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 23 Sep 2015 02:27:51 +0200 Subject: [PATCH] refs #452, added getClassName for variant (as discussed with MS) --- src/blackmisc/variant.cpp | 2 ++ src/blackmisc/variant.h | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/blackmisc/variant.cpp b/src/blackmisc/variant.cpp index a165b5e69..8844d2c6c 100644 --- a/src/blackmisc/variant.cpp +++ b/src/blackmisc/variant.cpp @@ -119,6 +119,8 @@ namespace BlackMisc void CVariant::convertFromJson(const QJsonObject &json) { + // Remark: Names "type" and "value" are also used for drag and drop + // Changing the names here requires the change for drag and drop too QString typeName = json.value("type").toString(); int typeId = QMetaType::type(qPrintable(typeName)); diff --git a/src/blackmisc/variant.h b/src/blackmisc/variant.h index 28bb856b9..741eeb2d3 100644 --- a/src/blackmisc/variant.h +++ b/src/blackmisc/variant.h @@ -50,12 +50,19 @@ namespace BlackMisc Private::MetaTypeHelper::maybeRegisterMetaType(); } - //! Returns the Qt meta type ID of this object. + //! Returns the Qt meta type ID of this object + //! \remark for CVariant this returns the id of CVariant, not of the encapsulated object. valueVariant.userType()` returns metatype of the contained object int getMetaTypeId() const { return Private::MetaTypeHelper::maybeGetMetaTypeId(); } + //! Class name + QString getClassName() const + { + return QMetaType::typeName(getMetaTypeId()); + } + //! Returns true if this object is an instance of the class with the given meta type ID, or one of its subclasses. bool isA(int metaTypeId) const { @@ -79,6 +86,7 @@ namespace BlackMisc # define BLACKMISC_DECLARE_USING_MIXIN_METATYPE(DERIVED) \ using ::BlackMisc::Mixin::MetaType::registerMetadata; \ using ::BlackMisc::Mixin::MetaType::getMetaTypeId; \ + using ::BlackMisc::Mixin::MetaType::getClassName; \ using ::BlackMisc::Mixin::MetaType::isA; } // Mixin