diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2020-12-14 12:27:53 +0100 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2021-04-21 15:34:28 +0200 |
commit | 1a65a4faf52f83ba3fbbba88cea1c4bb800e8de7 (patch) | |
tree | 3873a758298aba37faade1b1cd60c755815eae1c /src/corelib/kernel/qobject.cpp | |
parent | 696f5ffc64ac90e92520fd8cf9e8313fe80e3b76 (diff) |
QObject: port to new property system
Extended QObjectPrivate::ExtraData to store a pointer
to its parent, and reimplemented qGetBindingStorage()
function for QObjectPrivate::ExtraData.
This allows to use Q_OBJECT_COMPAT_PROPERTY macro
for a property, stored in QObjectPrivate::ExtraData
and solves all the problems with calling a custom
setter.
Task-number: QTBUG-85520
Change-Id: I40e01c29430846359ef9160fa1ae97c702be9a18
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 343922581c..b115066dce 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -1214,6 +1214,11 @@ QObjectPrivate::Connection::~Connection() QString QObject::objectName() const { Q_D(const QObject); + if (!d->extraData && QtPrivate::isAnyBindingEvaluating()) { + QObjectPrivate *dd = const_cast<QObjectPrivate *>(d); + // extraData is mutable, so this should be safe + dd->extraData = new QObjectPrivate::ExtraData(dd); + } return d->extraData ? d->extraData->objectName : QString(); } @@ -1223,15 +1228,28 @@ QString QObject::objectName() const void QObject::setObjectName(const QString &name) { Q_D(QObject); + if (!d->extraData) - d->extraData = new QObjectPrivate::ExtraData; + d->extraData = new QObjectPrivate::ExtraData(d); + + d->extraData->objectName.removeBindingUnlessInWrapper(); if (d->extraData->objectName != name) { - d->extraData->objectName = name; - emit objectNameChanged(d->extraData->objectName, QPrivateSignal()); + d->extraData->objectName.setValueBypassingBindings(name); + d->extraData->objectName.notify(); // also emits a signal } } +QBindable<QString> QObject::bindableObjectName() +{ + Q_D(QObject); + + if (!d->extraData) + d->extraData = new QObjectPrivate::ExtraData(d); + + return QBindable<QString>(&d->extraData->objectName); +} + /*! \fn void QObject::objectNameChanged(const QString &objectName) This signal is emitted after the object's name has been changed. The new object name is passed as \a objectName. @@ -1731,7 +1749,7 @@ int QObject::startTimer(int interval, Qt::TimerType timerType) } int timerId = thisThreadData->eventDispatcher.loadRelaxed()->registerTimer(interval, timerType, this); if (!d->extraData) - d->extraData = new QObjectPrivate::ExtraData; + d->extraData = new QObjectPrivate::ExtraData(d); d->extraData->runningTimers.append(timerId); return timerId; } @@ -2164,7 +2182,7 @@ void QObject::installEventFilter(QObject *obj) } if (!d->extraData) - d->extraData = new QObjectPrivate::ExtraData; + d->extraData = new QObjectPrivate::ExtraData(d); // clean up unused items in the list d->extraData->eventFilters.removeAll((QObject *)nullptr); @@ -3971,7 +3989,7 @@ bool QObject::setProperty(const char *name, const QVariant &value) int id = meta->indexOfProperty(name); if (id < 0) { if (!d->extraData) - d->extraData = new QObjectPrivate::ExtraData; + d->extraData = new QObjectPrivate::ExtraData(d); const int idx = d->extraData->propertyNames.indexOf(name); |