Extract Method QObjectPrivate::ensureExtraData()

... to centralize the creation of QObjectPrivate::extraData.

Change-Id: I04e97779ceb0168fa7660e77e0dab2ed3e1ad03e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
This commit is contained in:
Marc Mutz 2022-03-10 14:23:55 +01:00
parent de699decb4
commit 6313a1adf5
2 changed files with 11 additions and 10 deletions

View File

@ -1272,8 +1272,7 @@ void QObject::setObjectName(const QString &name)
{
Q_D(QObject);
if (!d->extraData)
d->extraData = new QObjectPrivate::ExtraData(d);
d->ensureExtraData();
d->extraData->objectName.removeBindingUnlessInWrapper();
@ -1287,8 +1286,7 @@ QBindable<QString> QObject::bindableObjectName()
{
Q_D(QObject);
if (!d->extraData)
d->extraData = new QObjectPrivate::ExtraData(d);
d->ensureExtraData();
return QBindable<QString>(&d->extraData->objectName);
}
@ -1817,8 +1815,7 @@ int QObject::startTimer(int interval, Qt::TimerType timerType)
return 0;
}
int timerId = thisThreadData->eventDispatcher.loadRelaxed()->registerTimer(interval, timerType, this);
if (!d->extraData)
d->extraData = new QObjectPrivate::ExtraData(d);
d->ensureExtraData();
d->extraData->runningTimers.append(timerId);
return timerId;
}
@ -2278,8 +2275,7 @@ void QObject::installEventFilter(QObject *obj)
return;
}
if (!d->extraData)
d->extraData = new QObjectPrivate::ExtraData(d);
d->ensureExtraData();
// clean up unused items in the list
d->extraData->eventFilters.removeAll((QObject *)nullptr);
@ -4101,8 +4097,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);
d->ensureExtraData();
const int idx = d->extraData->propertyNames.indexOf(name);

View File

@ -125,6 +125,12 @@ public:
QObjectPrivate *parent;
};
void ensureExtraData()
{
if (!extraData)
extraData = new ExtraData(this);
}
typedef void (*StaticMetaCallFunction)(QObject *, QMetaObject::Call, int, void **);
struct Connection;
struct SignalVector;