diff --git a/src/blackmisc/variant.cpp b/src/blackmisc/variant.cpp index f9cef52ba..c33801109 100644 --- a/src/blackmisc/variant.cpp +++ b/src/blackmisc/variant.cpp @@ -14,7 +14,6 @@ #include "blackmisc/logmessage.h" #include "blackmisc/propertyindexref.h" #include "blackmisc/statusmessage.h" -#include "blackmisc/variantlist.h" #include "blackmisc/stringutils.h" #include @@ -33,6 +32,9 @@ namespace BlackMisc { + //! \private + int qMetaTypeId_CVariantList = -1; // referenced in variantlist.cpp + Private::IValueObjectMetaInfo *Private::getValueObjectMetaInfo(int typeId) { return getValueObjectMetaInfo(QVariant(typeId, nullptr)); @@ -49,11 +51,11 @@ namespace BlackMisc { return true; } - if (typeId == qMetaTypeId()) + if (typeId == qMetaTypeId_CVariantList) { return m_v.canConvert>() || m_v.canConvert(); } - if (userType() == qMetaTypeId()) + if (userType() == qMetaTypeId_CVariantList) { return QVariant::fromValue(QVector()).canConvert(typeId) || QVariant(typeId, nullptr).canConvert(); @@ -66,7 +68,7 @@ namespace BlackMisc if (!m_v.canConvert(typeId)) { if (!canConvert(typeId)) { return false; } - if (typeId == qMetaTypeId()) + if (typeId == qMetaTypeId_CVariantList) { if (m_v.canConvert>()) { @@ -74,11 +76,15 @@ namespace BlackMisc } else if (m_v.canConvert()) { - m_v.setValue(CVariantList(m_v.value())); + QVector vec; + const auto seqit = m_v.value(); + vec.reserve(seqit.size()); + for (auto it = seqit.begin(); it != seqit.end(); ++it) { vec.push_back(*it); } + m_v.setValue(vec); } else { return false; } } - if (userType() == qMetaTypeId()) + if (userType() == qMetaTypeId_CVariantList) { if (QVariant::fromValue(QVector()).canConvert(typeId)) { @@ -92,7 +98,7 @@ namespace BlackMisc bool CVariant::isVariantList() const { - return userType() == qMetaTypeId(); + return userType() == qMetaTypeId_CVariantList; } QString CVariant::convertToQString(bool i18n) const diff --git a/src/blackmisc/variant.h b/src/blackmisc/variant.h index eccd8c56a..ffba8c687 100644 --- a/src/blackmisc/variant.h +++ b/src/blackmisc/variant.h @@ -39,7 +39,6 @@ namespace BlackMisc { class CIcon; class CPropertyIndex; - class CVariantList; /*! * Wrapper around QVariant which provides transparent access to CValueObject methods diff --git a/src/blackmisc/variantlist.cpp b/src/blackmisc/variantlist.cpp index 84a7037fc..e72c96d98 100644 --- a/src/blackmisc/variantlist.cpp +++ b/src/blackmisc/variantlist.cpp @@ -12,6 +12,9 @@ namespace BlackMisc { + //! \private + extern int qMetaTypeId_CVariantList; // defined in variant.cpp + CVariantList::CVariantList(const CSequence &other) : CSequence(other) {} @@ -25,16 +28,12 @@ namespace BlackMisc std::move(other.begin(), other.end(), std::back_inserter(*this)); } - CVariantList::CVariantList(const QSequentialIterable &other) - { - for (auto it = other.begin(); it != other.end(); ++it) { push_back(*it); } - } - void CVariantList::registerMetadata() { Mixin::MetaType::registerMetadata(); QMetaType::registerConverter>([](const CVariantList &list) { return list.toVector(); }); QMetaType::registerConverter, CVariantList>([](const QVector &list) { return CSequence(list); }); + qMetaTypeId_CVariantList = qMetaTypeId(); } bool CVariantList::matches(const CVariant &event) const diff --git a/src/blackmisc/variantlist.h b/src/blackmisc/variantlist.h index b3ef55648..41c424471 100644 --- a/src/blackmisc/variantlist.h +++ b/src/blackmisc/variantlist.h @@ -46,9 +46,6 @@ namespace BlackMisc //! Construct from a moved QVariantList. CVariantList(QVariantList &&other); - //! Construct from a QSequentialIterable. - CVariantList(const QSequentialIterable &other); - //! Convert to a sequence type by converting all elements. template T to() const { return CVariant::from(*this).template to(); }