refs #452, added getClassName for variant

(as discussed with MS)
This commit is contained in:
Klaus Basan
2015-09-23 02:27:51 +02:00
committed by Mathew Sutcliffe
parent ab46ed615c
commit 51e8a6a208
2 changed files with 11 additions and 1 deletions

View File

@@ -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));

View File

@@ -50,12 +50,19 @@ namespace BlackMisc
Private::MetaTypeHelper<Derived>::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<Derived>::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<DERIVED>::registerMetadata; \
using ::BlackMisc::Mixin::MetaType<DERIVED>::getMetaTypeId; \
using ::BlackMisc::Mixin::MetaType<DERIVED>::getClassName; \
using ::BlackMisc::Mixin::MetaType<DERIVED>::isA;
} // Mixin