diff options
-rw-r--r-- | src/tools/moc/generator.cpp | 16 | ||||
-rw-r--r-- | src/tools/moc/moc.cpp | 16 | ||||
-rw-r--r-- | tests/auto/tools/moc/tst_moc.cpp | 5 |
3 files changed, 32 insertions, 5 deletions
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index c0e1dca748..acb7cdffe9 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -1504,8 +1504,12 @@ void Generator::generateStaticMetacall() const PropertyDef &p = cdef->propertyList.at(propindex); if (!p.isQProperty) continue; - fprintf(out, " case %d: observer->setSource(_t->%s); break;\n", - propindex, p.name.constData()); + QByteArray prefix = "_t->"; + if (p.inPrivateClass.size()) { + prefix += p.inPrivateClass + "->"; + } + fprintf(out, " case %d: observer->setSource(%s%s); break;\n", + propindex, prefix.constData(), p.name.constData()); } fprintf(out, " default: break;\n"); fprintf(out, " }\n"); @@ -1521,8 +1525,12 @@ void Generator::generateStaticMetacall() const PropertyDef &p = cdef->propertyList.at(propindex); if (!p.isQProperty) continue; - fprintf(out, " case %d: _t->%s.setBinding(*reinterpret_cast<QPropertyBinding<%s> *>(_a[0])); break;\n", - propindex, p.name.constData(), p.type.constData()); + QByteArray prefix = "_t->"; + if (p.inPrivateClass.size()) { + prefix += p.inPrivateClass + "->"; + } + fprintf(out, " case %d: %s%s.setBinding(*reinterpret_cast<QPropertyBinding<%s> *>(_a[0])); break;\n", + propindex, prefix.constData(), p.name.constData(), p.type.constData()); } fprintf(out, " default: break;\n"); fprintf(out, " }\n"); diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index edef9d3f04..2444d0db90 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -1228,9 +1228,23 @@ void Moc::createPropertyDef(PropertyDef &propDef) { propDef.location = index; + const bool isPrivateProperty = !propDef.inPrivateClass.isEmpty(); + bool typeWrappedInQProperty = false; + if (isPrivateProperty) { + const int rewind = index; + if (test(IDENTIFIER) && lexem() == "QProperty" && test(LANGLE)) { + typeWrappedInQProperty = true; + propDef.isQProperty = true; + } else { + index = rewind; + } + } + QByteArray type = parseType().name; if (type.isEmpty()) error(); + if (typeWrappedInQProperty) + next(RANGLE); propDef.designable = propDef.scriptable = propDef.stored = "true"; propDef.user = "false"; @@ -1806,7 +1820,7 @@ void Moc::checkProperties(ClassDef *cdef) definedProperties.insert(p.name); if (p.read.isEmpty() && p.member.isEmpty()) { - if (!cdef->qPropertyMembers.contains(p.name)) { + if (!cdef->qPropertyMembers.contains(p.name) && !p.isQProperty) { const int rewind = index; if (p.location >= 0) index = p.location; diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index 08dae7f6ca..f3cc21f502 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -1542,6 +1542,7 @@ class PrivatePropertyTest : public QObject Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, QString blub4 MEMBER mBlub NOTIFY blub4Changed) Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, QString blub5 MEMBER mBlub NOTIFY blub5Changed) Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, QString blub6 MEMBER mConst CONSTANT) + Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, QProperty<int> x) class MyDPointer { public: MyDPointer() : mConst("const"), mBar(0), mPlop(0) {} @@ -1555,6 +1556,7 @@ class PrivatePropertyTest : public QObject void setBlub(const QString &value) { mBlub = value; } QString mBlub; const QString mConst; + QProperty<int> x; private: int mBar; int mPlop; @@ -1590,6 +1592,9 @@ void tst_Moc::qprivateproperties() test.setProperty("baz", 4); QCOMPARE(test.property("baz"), QVariant::fromValue(4)); + test.setProperty("x", 100); + QCOMPARE(test.property("x"), QVariant::fromValue(100)); + QVERIFY(test.metaObject()->property(test.metaObject()->indexOfProperty("x")).isQProperty()); } void tst_Moc::warnOnPropertyWithoutREAD() |