QSignalSpy: Extract Method init() from three ctors

Ideally, this wouldn't be a named function, but a delegatee
constructor, but the current structure of the three constructors
doesn't, yet, lend itself to extracting a delegatee constructor (the
tail is copied, not the head). To get there, we need more work (coming
up in follow-up commits).

Task-number: QTBUG-123544
Change-Id: I46dd030e314d67c2ab624279d669db76e58bc569
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Marc Mutz 2024-03-19 09:03:31 +01:00
parent e5bb392f72
commit edb8bac39b

View File

@ -43,11 +43,7 @@ public:
return; return;
} }
initArgs(mo->method(sigIndex), obj); init(obj, mo->method(sigIndex));
if (!connectToSignal(obj, sigIndex))
return;
sig = ba;
} }
#ifdef Q_QDOC #ifdef Q_QDOC
@ -65,30 +61,15 @@ public:
return; return;
} }
const QMetaObject * const mo = obj->metaObject();
const QMetaMethod signalMetaMethod = QMetaMethod::fromSignal(signal0); const QMetaMethod signalMetaMethod = QMetaMethod::fromSignal(signal0);
const int sigIndex = signalMetaMethod.methodIndex(); init(obj, signalMetaMethod);
if (!isSignalMetaMethodValid(signalMetaMethod))
return;
initArgs(mo->method(sigIndex), obj);
if (!connectToSignal(obj, sigIndex))
return;
sig = signalMetaMethod.methodSignature();
} }
#endif // Q_QDOC #endif // Q_QDOC
QSignalSpy(const QObject *obj, QMetaMethod signal) QSignalSpy(const QObject *obj, QMetaMethod signal)
{ {
if (isObjectValid(obj) && isSignalMetaMethodValid(signal)) { if (isObjectValid(obj))
initArgs(signal, obj); init(obj, signal);
if (!connectToSignal(obj, signal.methodIndex()))
return;
sig = signal.methodSignature();
}
} }
inline bool isValid() const { return !sig.isEmpty(); } inline bool isValid() const { return !sig.isEmpty(); }
@ -128,6 +109,18 @@ public:
} }
private: private:
void init(const QObject *obj, QMetaMethod signal)
{
if (!isSignalMetaMethodValid(signal))
return;
initArgs(signal, obj);
if (!connectToSignal(obj, signal.methodIndex()))
return;
sig = signal.methodSignature();
}
bool connectToSignal(const QObject *sender, int sigIndex) bool connectToSignal(const QObject *sender, int sigIndex)
{ {
static const int memberOffset = QObject::staticMetaObject.methodCount(); static const int memberOffset = QObject::staticMetaObject.methodCount();