From 7f85fb4654f0d6f9058336af53148d81fc700497 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 10 Jun 2015 14:28:57 +0200 Subject: Allow types with a comma in Q_PROPERTY This allows for example properties with QMap [ChangeLog][QtCore] Types in the Q_PROPERTY macro can now contain commas (for example, QMap) Change-Id: Ibf5c8c9cf20a7c8b3dfec9e891fb8a9ca1bdba7c Reviewed-by: Marc Mutz Reviewed-by: Gabriel de Dietrich Reviewed-by: Thiago Macieira --- src/corelib/doc/src/objectmodel/properties.qdoc | 9 ++------- src/corelib/kernel/qobjectdefs.h | 4 ++++ .../auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp | 12 ++++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/corelib/doc/src/objectmodel/properties.qdoc b/src/corelib/doc/src/objectmodel/properties.qdoc index abb0720fe9..55622dd56b 100644 --- a/src/corelib/doc/src/objectmodel/properties.qdoc +++ b/src/corelib/doc/src/objectmodel/properties.qdoc @@ -160,13 +160,8 @@ Because QDate is user-defined, you must include the \c{} header file with the property declaration. - For QMap, QList, and QValueList properties, the property value is - a QVariant whose value is the entire list or map. Note that the - Q_PROPERTY string cannot contain commas, because commas separate - macro arguments. Therefore, you must use \c QMap as the property - type instead of \c QMap. For consistency, also - use \c QList and \c QValueList instead of \c QList and - \c QValueList. + For historical reasons, \a QMap and \a QList as property types + are synonym of \a QVariantMap and \a QVariantList. \section1 Reading and Writing Properties with the Meta-Object System diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h index 4d01264906..a64f2fd2b1 100644 --- a/src/corelib/kernel/qobjectdefs.h +++ b/src/corelib/kernel/qobjectdefs.h @@ -78,7 +78,11 @@ class QString; #define Q_CLASSINFO(name, value) #define Q_PLUGIN_METADATA(x) #define Q_INTERFACES(x) +#ifdef Q_COMPILER_VARIADIC_MACROS +#define Q_PROPERTY(...) +#else #define Q_PROPERTY(text) +#endif #define Q_PRIVATE_PROPERTY(d, text) #define Q_REVISION(v) #define Q_OVERRIDE(text) diff --git a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp index a18c9eb370..4d54aa4dc8 100644 --- a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp +++ b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp @@ -46,6 +46,7 @@ class tst_QMetaProperty : public QObject Q_PROPERTY(int value8 READ value8) Q_PROPERTY(int value9 READ value9 CONSTANT) Q_PROPERTY(int value10 READ value10 FINAL) + Q_PROPERTY(QMap map MEMBER map) private slots: void hasStdCppSet(); @@ -53,6 +54,7 @@ private slots: void isFinal(); void gadget(); void readAndWriteWithLazyRegistration(); + void mapProperty(); public: enum EnumType { EnumType1 }; @@ -65,6 +67,8 @@ public: int value8() const { return 1; } int value9() const { return 1; } int value10() const { return 1; } + + QMap map; }; void tst_QMetaProperty::hasStdCppSet() @@ -182,6 +186,14 @@ void tst_QMetaProperty::readAndWriteWithLazyRegistration() QCOMPARE(o.property("write").value(), &data); } +void tst_QMetaProperty::mapProperty() +{ + map.insert(5, 9); + QVariant v1 = QVariant::fromValue(map); + QVariant v = property("map"); + QVERIFY(v.isValid()); + QCOMPARE(map, (v.value >())); +} QTEST_MAIN(tst_QMetaProperty) #include "tst_qmetaproperty.moc" -- cgit v1.2.3