mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 11:25:33 +08:00
Issue #77 Break cyclic dependency between CVariant and CVariantList
This commit is contained in:
@@ -14,7 +14,6 @@
|
|||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
#include "blackmisc/propertyindexref.h"
|
#include "blackmisc/propertyindexref.h"
|
||||||
#include "blackmisc/statusmessage.h"
|
#include "blackmisc/statusmessage.h"
|
||||||
#include "blackmisc/variantlist.h"
|
|
||||||
#include "blackmisc/stringutils.h"
|
#include "blackmisc/stringutils.h"
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
@@ -33,6 +32,9 @@
|
|||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
//! \private
|
||||||
|
int qMetaTypeId_CVariantList = -1; // referenced in variantlist.cpp
|
||||||
|
|
||||||
Private::IValueObjectMetaInfo *Private::getValueObjectMetaInfo(int typeId)
|
Private::IValueObjectMetaInfo *Private::getValueObjectMetaInfo(int typeId)
|
||||||
{
|
{
|
||||||
return getValueObjectMetaInfo(QVariant(typeId, nullptr));
|
return getValueObjectMetaInfo(QVariant(typeId, nullptr));
|
||||||
@@ -49,11 +51,11 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (typeId == qMetaTypeId<CVariantList>())
|
if (typeId == qMetaTypeId_CVariantList)
|
||||||
{
|
{
|
||||||
return m_v.canConvert<QVector<CVariant>>() || m_v.canConvert<QVariantList>();
|
return m_v.canConvert<QVector<CVariant>>() || m_v.canConvert<QVariantList>();
|
||||||
}
|
}
|
||||||
if (userType() == qMetaTypeId<CVariantList>())
|
if (userType() == qMetaTypeId_CVariantList)
|
||||||
{
|
{
|
||||||
return QVariant::fromValue(QVector<CVariant>()).canConvert(typeId)
|
return QVariant::fromValue(QVector<CVariant>()).canConvert(typeId)
|
||||||
|| QVariant(typeId, nullptr).canConvert<QVariantList>();
|
|| QVariant(typeId, nullptr).canConvert<QVariantList>();
|
||||||
@@ -66,7 +68,7 @@ namespace BlackMisc
|
|||||||
if (!m_v.canConvert(typeId))
|
if (!m_v.canConvert(typeId))
|
||||||
{
|
{
|
||||||
if (!canConvert(typeId)) { return false; }
|
if (!canConvert(typeId)) { return false; }
|
||||||
if (typeId == qMetaTypeId<CVariantList>())
|
if (typeId == qMetaTypeId_CVariantList)
|
||||||
{
|
{
|
||||||
if (m_v.canConvert<QVector<CVariant>>())
|
if (m_v.canConvert<QVector<CVariant>>())
|
||||||
{
|
{
|
||||||
@@ -74,11 +76,15 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
else if (m_v.canConvert<QVariantList>())
|
else if (m_v.canConvert<QVariantList>())
|
||||||
{
|
{
|
||||||
m_v.setValue(CVariantList(m_v.value<QSequentialIterable>()));
|
QVector<CVariant> vec;
|
||||||
|
const auto seqit = m_v.value<QSequentialIterable>();
|
||||||
|
vec.reserve(seqit.size());
|
||||||
|
for (auto it = seqit.begin(); it != seqit.end(); ++it) { vec.push_back(*it); }
|
||||||
|
m_v.setValue(vec);
|
||||||
}
|
}
|
||||||
else { return false; }
|
else { return false; }
|
||||||
}
|
}
|
||||||
if (userType() == qMetaTypeId<CVariantList>())
|
if (userType() == qMetaTypeId_CVariantList)
|
||||||
{
|
{
|
||||||
if (QVariant::fromValue(QVector<CVariant>()).canConvert(typeId))
|
if (QVariant::fromValue(QVector<CVariant>()).canConvert(typeId))
|
||||||
{
|
{
|
||||||
@@ -92,7 +98,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
bool CVariant::isVariantList() const
|
bool CVariant::isVariantList() const
|
||||||
{
|
{
|
||||||
return userType() == qMetaTypeId<CVariantList>();
|
return userType() == qMetaTypeId_CVariantList;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CVariant::convertToQString(bool i18n) const
|
QString CVariant::convertToQString(bool i18n) const
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
class CIcon;
|
class CIcon;
|
||||||
class CPropertyIndex;
|
class CPropertyIndex;
|
||||||
class CVariantList;
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Wrapper around QVariant which provides transparent access to CValueObject methods
|
* Wrapper around QVariant which provides transparent access to CValueObject methods
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
//! \private
|
||||||
|
extern int qMetaTypeId_CVariantList; // defined in variant.cpp
|
||||||
|
|
||||||
CVariantList::CVariantList(const CSequence &other) : CSequence(other)
|
CVariantList::CVariantList(const CSequence &other) : CSequence(other)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -25,16 +28,12 @@ namespace BlackMisc
|
|||||||
std::move(other.begin(), other.end(), std::back_inserter(*this));
|
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()
|
void CVariantList::registerMetadata()
|
||||||
{
|
{
|
||||||
Mixin::MetaType<CVariantList>::registerMetadata();
|
Mixin::MetaType<CVariantList>::registerMetadata();
|
||||||
QMetaType::registerConverter<CVariantList, QVector<CVariant>>([](const CVariantList &list) { return list.toVector(); });
|
QMetaType::registerConverter<CVariantList, QVector<CVariant>>([](const CVariantList &list) { return list.toVector(); });
|
||||||
QMetaType::registerConverter<QVector<CVariant>, CVariantList>([](const QVector<CVariant> &list) { return CSequence(list); });
|
QMetaType::registerConverter<QVector<CVariant>, CVariantList>([](const QVector<CVariant> &list) { return CSequence(list); });
|
||||||
|
qMetaTypeId_CVariantList = qMetaTypeId<CVariantList>();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CVariantList::matches(const CVariant &event) const
|
bool CVariantList::matches(const CVariant &event) const
|
||||||
|
|||||||
@@ -46,9 +46,6 @@ namespace BlackMisc
|
|||||||
//! Construct from a moved QVariantList.
|
//! Construct from a moved QVariantList.
|
||||||
CVariantList(QVariantList &&other);
|
CVariantList(QVariantList &&other);
|
||||||
|
|
||||||
//! Construct from a QSequentialIterable.
|
|
||||||
CVariantList(const QSequentialIterable &other);
|
|
||||||
|
|
||||||
//! Convert to a sequence type by converting all elements.
|
//! Convert to a sequence type by converting all elements.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T to() const { return CVariant::from(*this).template to<T>(); }
|
T to() const { return CVariant::from(*this).template to<T>(); }
|
||||||
|
|||||||
Reference in New Issue
Block a user