Allow types with a comma in Q_PROPERTY
This allows for example properties with QMap<Foo, Bar> [ChangeLog][QtCore] Types in the Q_PROPERTY macro can now contain commas (for example, QMap<Foo, Bar>) Change-Id: Ibf5c8c9cf20a7c8b3dfec9e891fb8a9ca1bdba7c Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
55df2e54a5
commit
7f85fb4654
|
|
@ -160,13 +160,8 @@
|
|||
Because QDate is user-defined, you must include the \c{<QDate>}
|
||||
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<QString,QVariant>. For consistency, also
|
||||
use \c QList and \c QValueList instead of \c QList<QVariant> and
|
||||
\c QValueList<QVariant>.
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<int, int> 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<int, int> map;
|
||||
};
|
||||
|
||||
void tst_QMetaProperty::hasStdCppSet()
|
||||
|
|
@ -182,6 +186,14 @@ void tst_QMetaProperty::readAndWriteWithLazyRegistration()
|
|||
QCOMPARE(o.property("write").value<CustomWriteObjectChild*>(), &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<QMap<int,int> >()));
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QMetaProperty)
|
||||
#include "tst_qmetaproperty.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue