mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 11:05:44 +08:00
refs #116 using CVariant in the implementation of CIndexVariantMap
This commit is contained in:
@@ -42,16 +42,16 @@ namespace BlackMisc
|
|||||||
QString s;
|
QString s;
|
||||||
foreach(int index, this->m_values.keys())
|
foreach(int index, this->m_values.keys())
|
||||||
{
|
{
|
||||||
QVariant qv = this->m_values.value(index);
|
CVariant v = this->m_values.value(index);
|
||||||
|
|
||||||
s.isEmpty() ?
|
s.isEmpty() ?
|
||||||
s.append("{wildcard: ").append(this->m_wildcard ? "true" : "false").append(" ") :
|
s.append("{wildcard: ").append(this->m_wildcard ? "true" : "false").append(" ") :
|
||||||
s.append(", ");
|
s.append(", ");
|
||||||
|
|
||||||
s.append('{').append(QString::number(index)).append(": ");
|
s.append('{').append(QString::number(index)).append(": ");
|
||||||
s.append("(").append(QString::number(qv.userType())).append(") ");
|
s.append("(").append(QString::number(v.userType())).append(") ");
|
||||||
QString qvs = BlackMisc::qVariantToString(qv, i18n);
|
QString vs = v.toString(i18n);
|
||||||
s.append(qvs);
|
s.append(vs);
|
||||||
s.append('}');
|
s.append('}');
|
||||||
}
|
}
|
||||||
s = s.append("}");
|
s = s.append("}");
|
||||||
@@ -90,18 +90,8 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
void CIndexVariantMap::marshallToDbus(QDBusArgument &argument) const
|
void CIndexVariantMap::marshallToDbus(QDBusArgument &argument) const
|
||||||
{
|
{
|
||||||
// remark, tried both sending as QDbusVariant and QVariant
|
argument << this->m_values.keys();
|
||||||
// does not make a difference
|
argument << this->m_values.values();
|
||||||
QList<int> unifiedBlackTypeIds;
|
|
||||||
QList<QDBusVariant> dbusVariants;
|
|
||||||
foreach(QVariant qv, m_values.values())
|
|
||||||
{
|
|
||||||
unifiedBlackTypeIds << qv.userType() - BlackMisc::firstBlackMetaType();
|
|
||||||
dbusVariants << QDBusVariant(qv);
|
|
||||||
}
|
|
||||||
argument << this->m_values.keys(); // indexes
|
|
||||||
argument << dbusVariants;
|
|
||||||
argument << unifiedBlackTypeIds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -110,27 +100,14 @@ namespace BlackMisc
|
|||||||
void CIndexVariantMap::unmarshallFromDbus(const QDBusArgument &argument)
|
void CIndexVariantMap::unmarshallFromDbus(const QDBusArgument &argument)
|
||||||
{
|
{
|
||||||
QList<int> indexes;
|
QList<int> indexes;
|
||||||
QList<QDBusVariant> values;
|
QList<CVariant> values;
|
||||||
QList<int> unifiedBlackTypeIds;
|
|
||||||
argument >> indexes;
|
argument >> indexes;
|
||||||
argument >> values;
|
argument >> values;
|
||||||
argument >> unifiedBlackTypeIds;
|
Q_ASSERT(indexes.size() == values.size());
|
||||||
QMap<int, QVariant> newMap;
|
QMap<int, CVariant> newMap;
|
||||||
for (int i = 0; i < indexes.size(); i++)
|
for (int i = 0; i < indexes.size(); i++)
|
||||||
{
|
{
|
||||||
QVariant qv = values.at(i).variant();
|
newMap.insert(indexes[i], values[i]);
|
||||||
int index = indexes.at(i);
|
|
||||||
if (qv.canConvert<QDBusArgument>())
|
|
||||||
{
|
|
||||||
int userType = unifiedBlackTypeIds.at(i) + BlackMisc::firstBlackMetaType();
|
|
||||||
QVariant concrete = BlackMisc::fixQVariantFromDbusArgument(qv, userType);
|
|
||||||
newMap.insert(index, concrete);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// value already OK
|
|
||||||
newMap.insert(index, qv);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// replace values in one step
|
// replace values in one step
|
||||||
this->m_values.swap(newMap);
|
this->m_values.swap(newMap);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "valueobject.h"
|
#include "valueobject.h"
|
||||||
|
#include "variant.h"
|
||||||
#include <QVariantMap>
|
#include <QVariantMap>
|
||||||
#include <QDBusArgument>
|
#include <QDBusArgument>
|
||||||
|
|
||||||
@@ -45,13 +46,13 @@ namespace BlackMisc
|
|||||||
|
|
||||||
|
|
||||||
//! Add a value as non QVariant
|
//! Add a value as non QVariant
|
||||||
template<class T> void addValue(int index, const T &value) { this->m_values.insert(index, QVariant::fromValue(value)); }
|
template<class T> void addValue(int index, const T &value) { this->m_values.insert(index, CVariant::fromValue(value)); }
|
||||||
|
|
||||||
//! Is empty?
|
//! Is empty?
|
||||||
bool isEmpty() const { return this->m_values.isEmpty(); }
|
bool isEmpty() const { return this->m_values.isEmpty(); }
|
||||||
|
|
||||||
//! Value
|
//! Value
|
||||||
QVariant value(int index) const { return this->m_values.value(index); }
|
QVariant value(int index) const { return this->m_values.value(index).toQVariant(); }
|
||||||
|
|
||||||
//! Set value
|
//! Set value
|
||||||
void value(int index, const QVariant &value) { this->m_values.value(index, value); }
|
void value(int index, const QVariant &value) { this->m_values.value(index, value); }
|
||||||
@@ -63,7 +64,7 @@ namespace BlackMisc
|
|||||||
bool contains(int index) const { return this->m_values.contains(index); }
|
bool contains(int index) const { return this->m_values.contains(index); }
|
||||||
|
|
||||||
//! values
|
//! values
|
||||||
QList<QVariant> values() const { return this->m_values.values(); }
|
QList<CVariant> values() const { return this->m_values.values(); }
|
||||||
|
|
||||||
//! \brief Wildcard, only relevant when used in search
|
//! \brief Wildcard, only relevant when used in search
|
||||||
bool isWildcard() const { return this->m_wildcard; }
|
bool isWildcard() const { return this->m_wildcard; }
|
||||||
@@ -81,7 +82,7 @@ namespace BlackMisc
|
|||||||
bool operator !=(const CIndexVariantMap &other) const;
|
bool operator !=(const CIndexVariantMap &other) const;
|
||||||
|
|
||||||
//! Map
|
//! Map
|
||||||
const QMap<int, QVariant> &map() const { return this->m_values; }
|
const QMap<int, CVariant> &map() const { return this->m_values; }
|
||||||
|
|
||||||
//! \copydoc CValueObject::getValueHash
|
//! \copydoc CValueObject::getValueHash
|
||||||
virtual uint getValueHash() const override;
|
virtual uint getValueHash() const override;
|
||||||
@@ -90,7 +91,7 @@ namespace BlackMisc
|
|||||||
static void registerMetadata();
|
static void registerMetadata();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QMap<int, QVariant> m_values; //!< values
|
QMap<int, CVariant> m_values; //!< values
|
||||||
bool m_wildcard; //!< wildcard
|
bool m_wildcard; //!< wildcard
|
||||||
|
|
||||||
//! \copydoc CValueObject::convertToQString
|
//! \copydoc CValueObject::convertToQString
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ namespace BlackMisc
|
|||||||
const auto &map = indexMap.map();
|
const auto &map = indexMap.map();
|
||||||
for (auto it = map.begin(); it != map.end(); ++it)
|
for (auto it = map.begin(); it != map.end(); ++it)
|
||||||
{
|
{
|
||||||
this->setPropertyByIndex(it.value(), it.key());
|
this->setPropertyByIndex(it.value().toQVariant(), it.key());
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
// QVariant cannot be compared directly
|
// QVariant cannot be compared directly
|
||||||
QVariant p = valueObject.propertyByIndex(it.key()); // from value object
|
QVariant p = valueObject.propertyByIndex(it.key()); // from value object
|
||||||
QVariant v = it.value(); // from map
|
QVariant v = it.value().toQVariant(); // from map
|
||||||
if (!BlackMisc::equalQVariants(p, v)) return false;
|
if (!BlackMisc::equalQVariants(p, v)) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user