moc: Support BINDABLE for private properties

Hopefully we won't need it but let's have it still at least for
consistency

Change-Id: I72289e65e5e5613174ad4d98cf8d614f9caae8e6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Andrei Golubev 2021-08-04 10:28:33 +02:00
parent 6ba6e7585d
commit d4e62f2c5a
2 changed files with 19 additions and 1 deletions

View File

@ -1415,7 +1415,14 @@ void Generator::generateStaticMetacall()
const PropertyDef &p = cdef->propertyList.at(propindex);
if (p.bind.isEmpty())
continue;
fprintf(out, " case %d: *static_cast<QUntypedBindable *>(_a[0]) = _t->%s(); break;\n", propindex, p.bind.constData());
QByteArray prefix = "_t->";
if (p.inPrivateClass.size()) {
prefix += p.inPrivateClass + "->";
}
fprintf(out,
" case %d: *static_cast<QUntypedBindable *>(_a[0]) = %s%s(); "
"break;\n",
propindex, prefix.constData(), p.bind.constData());
}
fprintf(out, " default: break;\n");
fprintf(out, " }\n");

View File

@ -1569,6 +1569,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, int zap READ zap WRITE setZap BINDABLE bindableZap)
class MyDPointer {
public:
MyDPointer() : mConst("const"), mBar(0), mPlop(0) {}
@ -1580,12 +1581,16 @@ class PrivatePropertyTest : public QObject
void setBaz(int value) { mBaz = value; }
QString blub() const { return mBlub; }
void setBlub(const QString &value) { mBlub = value; }
int zap() { return mZap; }
void setZap(int zap) { mZap = zap; }
QBindable<int> bindableZap() { return QBindable<int>(&mZap); }
QString mBlub;
const QString mConst;
private:
int mBar;
int mPlop;
int mBaz;
QProperty<int> mZap;
};
public:
PrivatePropertyTest(QObject *parent = nullptr) : QObject(parent), mFoo(0), d (new MyDPointer) {}
@ -1617,6 +1622,12 @@ void tst_Moc::qprivateproperties()
test.setProperty("baz", 4);
QCOMPARE(test.property("baz"), QVariant::fromValue(4));
QMetaProperty zap = test.metaObject()->property(test.metaObject()->indexOfProperty("zap"));
QVERIFY(zap.isValid());
QVERIFY(zap.isBindable());
auto zapBindable = zap.bindable(&test);
QVERIFY(zapBindable.isBindable());
}
void tst_Moc::warnOnPropertyWithoutREAD()