Don't hardcode the order of elements in QHashes
Instead use QMap if we want a stable order. Task-number: QTBUG-24995 Change-Id: I93f643df236f5078768f539615fa47163e5262e8 Reviewed-by: Giuseppe D'Angelo <dangelog@gmail.com> Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
parent
2cf466312b
commit
bc4f74f586
@ -85,8 +85,8 @@ Q_DECLARE_METATYPE(QList<QList<QDBusSignature> >)
|
||||
typedef QMap<int, QString> IntStringMap;
|
||||
typedef QMap<QString, QString> StringStringMap;
|
||||
typedef QMap<QDBusObjectPath, QString> ObjectPathStringMap;
|
||||
typedef QHash<qlonglong, QDateTime> LLDateTimeMap;
|
||||
typedef QHash<QDBusSignature, QString> SignatureStringMap;
|
||||
typedef QMap<qlonglong, QDateTime> LLDateTimeMap;
|
||||
typedef QMap<QDBusSignature, QString> SignatureStringMap;
|
||||
Q_DECLARE_METATYPE(IntStringMap)
|
||||
Q_DECLARE_METATYPE(StringStringMap)
|
||||
Q_DECLARE_METATYPE(ObjectPathStringMap)
|
||||
@ -209,8 +209,8 @@ void commonInit()
|
||||
qDBusRegisterMetaType<QMap<int, QString> >();
|
||||
qDBusRegisterMetaType<QMap<QString, QString> >();
|
||||
qDBusRegisterMetaType<QMap<QDBusObjectPath, QString> >();
|
||||
qDBusRegisterMetaType<QHash<qlonglong, QDateTime> >();
|
||||
qDBusRegisterMetaType<QHash<QDBusSignature, QString> >();
|
||||
qDBusRegisterMetaType<QMap<qlonglong, QDateTime> >();
|
||||
qDBusRegisterMetaType<QMap<QDBusSignature, QString> >();
|
||||
|
||||
qDBusRegisterMetaType<MyStruct>();
|
||||
qDBusRegisterMetaType<MyVariantMapStruct>();
|
||||
@ -420,23 +420,6 @@ bool compare(const QMap<Key, T> &m1, const QMap<Key, T> &m2)
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename Key, typename T>
|
||||
bool compare(const QHash<Key, T> &m1, const QHash<Key, T> &m2)
|
||||
{
|
||||
if (m1.count() != m2.size())
|
||||
return false;
|
||||
typename QHash<Key, T>::ConstIterator i1 = m1.constBegin();
|
||||
typename QHash<Key, T>::ConstIterator end = m1.constEnd();
|
||||
for ( ; i1 != end; ++i1) {
|
||||
typename QHash<Key, T>::ConstIterator i2 = m2.find(i1.key());
|
||||
if (i2 == m2.constEnd())
|
||||
return false;
|
||||
if (!compare(*i1, *i2))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool compare(const QDBusArgument &arg, const QVariant &v2, T * = 0)
|
||||
{
|
||||
@ -538,10 +521,10 @@ bool compareToArgument(const QDBusArgument &arg, const QVariant &v2)
|
||||
return compare<QMap<QString, QString> >(arg, v2);
|
||||
else if (id == qMetaTypeId<QMap<QDBusObjectPath, QString> >())
|
||||
return compare<QMap<QDBusObjectPath, QString> >(arg, v2);
|
||||
else if (id == qMetaTypeId<QHash<qlonglong, QDateTime> >())
|
||||
return compare<QHash<qlonglong, QDateTime> >(arg, v2);
|
||||
else if (id == qMetaTypeId<QHash<QDBusSignature, QString> >())
|
||||
return compare<QHash<QDBusSignature, QString> >(arg, v2);
|
||||
else if (id == qMetaTypeId<QMap<qlonglong, QDateTime> >())
|
||||
return compare<QMap<qlonglong, QDateTime> >(arg, v2);
|
||||
else if (id == qMetaTypeId<QMap<QDBusSignature, QString> >())
|
||||
return compare<QMap<QDBusSignature, QString> >(arg, v2);
|
||||
|
||||
else if (id == qMetaTypeId<QList<QByteArray> >())
|
||||
return compare<QList<QByteArray> >(arg, v2);
|
||||
@ -703,11 +686,11 @@ template<> bool compare(const QVariant &v1, const QVariant &v2)
|
||||
else if (id == qMetaTypeId<QMap<QDBusObjectPath, QString> >())
|
||||
return compare(qvariant_cast<QMap<QDBusObjectPath, QString> >(v1), qvariant_cast<QMap<QDBusObjectPath, QString> >(v2));
|
||||
|
||||
else if (id == qMetaTypeId<QHash<qlonglong, QDateTime> >()) // lldtmap
|
||||
return compare(qvariant_cast<QHash<qint64, QDateTime> >(v1), qvariant_cast<QHash<qint64, QDateTime> >(v2));
|
||||
else if (id == qMetaTypeId<QMap<qlonglong, QDateTime> >()) // lldtmap
|
||||
return compare(qvariant_cast<QMap<qint64, QDateTime> >(v1), qvariant_cast<QMap<qint64, QDateTime> >(v2));
|
||||
|
||||
else if (id == qMetaTypeId<QHash<QDBusSignature, QString> >())
|
||||
return compare(qvariant_cast<QHash<QDBusSignature, QString> >(v1), qvariant_cast<QHash<QDBusSignature, QString> >(v2));
|
||||
else if (id == qMetaTypeId<QMap<QDBusSignature, QString> >())
|
||||
return compare(qvariant_cast<QMap<QDBusSignature, QString> >(v1), qvariant_cast<QMap<QDBusSignature, QString> >(v2));
|
||||
|
||||
else if (id == qMetaTypeId<MyStruct>()) // (is)
|
||||
return qvariant_cast<MyStruct>(v1) == qvariant_cast<MyStruct>(v2);
|
||||
|
@ -502,7 +502,7 @@ void tst_QDBusMarshall::sendMaps_data()
|
||||
QTest::newRow("os-map") << qVariantFromValue(osmap) << "a{os}"
|
||||
<< "[Argument: a{os} {[ObjectPath: /] = \"root\", [ObjectPath: /bar/baz] = \"bar and baz\", [ObjectPath: /foo] = \"foo\"}]";
|
||||
|
||||
QHash<QDBusSignature, QString> gsmap;
|
||||
QMap<QDBusSignature, QString> gsmap;
|
||||
QTest::newRow("empty-gs-map") << qVariantFromValue(gsmap) << "a{gs}"
|
||||
<< "[Argument: a{gs} {}]";
|
||||
gsmap[QDBusSignature("i")] = "int32";
|
||||
@ -601,7 +601,7 @@ void tst_QDBusMarshall::sendComplex_data()
|
||||
QTest::newRow("datetimelist") << qVariantFromValue(dtlist) << "a((iii)(iiii)i)"
|
||||
<< "[Argument: a((iii)(iiii)i) {[Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) -1, -1, -1, -1], 0], [Argument: ((iii)(iiii)i) [Argument: (iii) 1977, 9, 13], [Argument: (iiii) 0, 0, 0, 0], 0], [Argument: ((iii)(iiii)i) [Argument: (iii) 2006, 6, 18], [Argument: (iiii) 13, 14, 0, 0], 0]}]";
|
||||
|
||||
QHash<qlonglong, QDateTime> lldtmap;
|
||||
QMap<qlonglong, QDateTime> lldtmap;
|
||||
QTest::newRow("empty-lldtmap") << qVariantFromValue(lldtmap) << "a{x((iii)(iiii)i)}"
|
||||
<< "[Argument: a{x((iii)(iiii)i)} {}]";
|
||||
lldtmap[0] = QDateTime();
|
||||
@ -621,7 +621,7 @@ void tst_QDBusMarshall::sendComplex_data()
|
||||
ssmap["c"] = "b";
|
||||
ssmap["b"] = "c";
|
||||
|
||||
QHash<QDBusSignature, QString> gsmap;
|
||||
QMap<QDBusSignature, QString> gsmap;
|
||||
gsmap[QDBusSignature("i")] = "int32";
|
||||
gsmap[QDBusSignature("s")] = "string";
|
||||
gsmap[QDBusSignature("a{gs}")] = "array of dict_entry of (signature, string)";
|
||||
|
Loading…
Reference in New Issue
Block a user