Remove const char *-based connectNotify() API

This completes the transition from connectNotify(const char *) and
disconnectNotify(const char *) to the new QMetaMethod-based
functions.

Removed the old connectNotify autotests and renamed the
connectNotifyMethodXXX autotests to connectNotify, since there is
no longer any ambiguity about which overload is being tested.

Change-Id: Icf108a80177155f21bb73c165fb8ab5d4e997bc2
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Kent Hansen 2012-04-24 23:57:42 +02:00 committed by Qt by Nokia
parent 57c755fef0
commit f544d7189e
4 changed files with 28 additions and 151 deletions

5
dist/changes-5.0.0 vendored
View File

@ -12,6 +12,11 @@ information about a particular change.
****************************************************************************
- QObject
* The signatures of the connectNotify() and disconnectNotify() functions
have changed. The functions now get passed a QMetaMethod that identifies
the signal, rather than a const char *.
- QSslCertificate::subjectInfo() and QSslCertificate::issuerInfo() now
return a QStringList instead of a QString

View File

@ -2509,8 +2509,6 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const char *sign
#endif
QMetaObject::Connection handle = QMetaObject::Connection(QMetaObjectPrivate::connect(
sender, signal_index, smeta, receiver, method_index_relative, rmeta ,type, types));
if (handle)
const_cast<QObject*>(sender)->connectNotify(signal - 1);
return handle;
}
@ -2552,12 +2550,6 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho
return QMetaObject::Connection(0);
}
// Reconstructing SIGNAL() macro result for signal.methodSignature() string
QByteArray signalSignature;
signalSignature.reserve(signal.methodSignature().size()+1);
signalSignature.append((char)(QSIGNAL_CODE + '0'));
signalSignature.append(signal.methodSignature());
int signal_index;
int method_index;
{
@ -2597,8 +2589,6 @@ QMetaObject::Connection QObject::connect(const QObject *sender, const QMetaMetho
#endif
QMetaObject::Connection handle = QMetaObject::Connection(QMetaObjectPrivate::connect(
sender, signal_index, signal.enclosingMetaObject(), receiver, method_index, 0, type, types));
if (handle)
const_cast<QObject*>(sender)->connectNotify(signalSignature.constData());
return handle;
}
@ -2782,7 +2772,6 @@ bool QObject::disconnect(const QObject *sender, const char *signal,
if (res) {
if (!signal)
const_cast<QObject*>(sender)->disconnectNotify(QMetaMethod());
const_cast<QObject*>(sender)->disconnectNotify(signal ? (signal - 1) : 0);
}
return res;
}
@ -2878,7 +2867,6 @@ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal,
// QMetaMethod as argument, as documented.
const_cast<QObject*>(sender)->disconnectNotify(signal);
}
const_cast<QObject*>(sender)->disconnectNotify(method.mobj ? signalSignature.constData() : 0);
return true;
}
@ -2906,22 +2894,6 @@ bool QObject::disconnect(const QObject *sender, const QMetaMethod &signal,
*/
/*!
\fn void QObject::connectNotify(const char *signal)
\obsolete
*/
void QObject::connectNotify(const char *)
{
}
/*!
\fn void QObject::disconnectNotify(const char *signal)
\obsolete
*/
void QObject::disconnectNotify(const char *)
{
}
/*!
\since 5.0
@ -4238,15 +4210,6 @@ QMetaObject::Connection QObject::connectImpl(const QObject *sender, void **signa
Q_ASSERT(method.isValid());
s->connectNotify(method);
// reconstruct the signature to call connectNotify
const char *sig;
QByteArray tmp_sig = method.methodSignature();
sig = tmp_sig.constData();
QVarLengthArray<char> signalSignature(qstrlen(sig) + 2);
signalSignature.data()[0] = char(QSIGNAL_CODE + '0');
strcpy(signalSignature.data() + 1 , sig);
s->connectNotify(signalSignature.data());
return ret;
}

View File

@ -373,9 +373,6 @@ protected:
virtual void connectNotify(const QMetaMethod &signal);
virtual void disconnectNotify(const QMetaMethod &signal);
// Deprecated; to be removed before Qt 5.0
virtual void connectNotify(const char *signal);
virtual void disconnectNotify(const char *signal);
protected:
QObject(QObjectPrivate &dd, QObject *parent = 0);

View File

@ -76,13 +76,10 @@ private slots:
void findChildren();
void connectDisconnectNotify_data();
void connectDisconnectNotify();
void connectNotifyPtr();
void connectDisconnectNotifyMethod_data();
void connectDisconnectNotifyMethod();
void connectDisconnectNotifyMethodPMF();
void disconnectNotifyMethod_receiverDestroyed();
void connectNotifyMethod_connectSlotsByName();
void connectDisconnectNotifyMethod_shadowing();
void connectDisconnectNotifyPMF();
void disconnectNotify_receiverDestroyed();
void connectNotify_connectSlotsByName();
void connectDisconnectNotify_shadowing();
void emitInDefinedOrder();
void customTypes();
void streamCustomTypes();
@ -807,20 +804,18 @@ public:
NotifyObject() : SenderObject(), ReceiverObject()
{}
QString org_signal;
QString nw_signal;
QList<QMetaMethod> connectedSignals;
QList<QMetaMethod> disconnectedSignals;
void clearNotifications()
{
connectedSignals.clear();
disconnectedSignals.clear();
}
protected:
void connectNotify( const char *signal )
{
org_signal = signal;
nw_signal = QMetaObject::normalizedSignature(signal);
};
void disconnectNotify( const char *signal )
{
org_signal = signal;
nw_signal = QMetaObject::normalizedSignature(signal);
};
void connectNotify(const QMetaMethod &signal)
{ connectedSignals.append(signal); }
void disconnectNotify(const QMetaMethod &signal)
{ disconnectedSignals.append(signal); }
};
void tst_QObject::connectDisconnectNotify_data()
@ -845,89 +840,6 @@ void tst_QObject::connectDisconnectNotify()
QFETCH(QString, a_signal);
QFETCH(QString, a_slot);
// Test connectNotify
connect( (SenderObject*)s, a_signal.toLatin1(), (ReceiverObject*)r, a_slot.toLatin1() );
QCOMPARE( s->org_signal, s->nw_signal );
QCOMPARE( s->org_signal.toLatin1(), QMetaObject::normalizedSignature(a_signal.toLatin1().constData()) );
// Test disconnectNotify
QObject::disconnect( (SenderObject*)s, a_signal.toLatin1(), (ReceiverObject*)r, a_slot.toLatin1() );
QCOMPARE( s->org_signal, s->nw_signal );
QCOMPARE( s->org_signal.toLatin1(), QMetaObject::normalizedSignature(a_signal.toLatin1().constData()) );
// Reconnect
connect( (SenderObject*)s, a_signal.toLatin1(), (ReceiverObject*)r, a_slot.toLatin1() );
// Test disconnectNotify for a complete disconnect
((SenderObject*)s)->disconnect((ReceiverObject*)r);
// Obtaining meta methods
int signalIndx = ((SenderObject*)s)->metaObject()->indexOfSignal(
QMetaObject::normalizedSignature(a_signal.toLatin1().constData()+1).constData());
int methodIndx = ((ReceiverObject*)r)->metaObject()->indexOfMethod(
QMetaObject::normalizedSignature(a_slot.toLatin1().constData()+1).constData());
QMetaMethod signal = ((SenderObject*)s)->metaObject()->method(signalIndx);
QMetaMethod method = ((ReceiverObject*)r)->metaObject()->method(methodIndx);
// Test connectNotify when connecting by QMetaMethod
connect( (SenderObject*)s, signal, (ReceiverObject*)r, method );
QCOMPARE( s->org_signal, s->nw_signal );
QCOMPARE( s->org_signal.toLatin1(), QMetaObject::normalizedSignature(a_signal.toLatin1().constData()) );
// Test disconnectNotify when disconnecting by QMetaMethod
QObject::disconnect( (SenderObject*)s, signal, (ReceiverObject*)r, method );
QCOMPARE( s->org_signal, s->nw_signal );
QCOMPARE( s->org_signal.toLatin1(), QMetaObject::normalizedSignature(a_signal.toLatin1().constData()) );
delete s;
delete r;
}
void tst_QObject::connectNotifyPtr()
{
NotifyObject *s = new NotifyObject;
NotifyObject *r = new NotifyObject;
connect( (SenderObject*)s, &SenderObject::signal1, (ReceiverObject*)r, &ReceiverObject::slot1 );
QCOMPARE( s->org_signal, s->nw_signal );
QCOMPARE( s->org_signal.toLatin1(), QMetaObject::normalizedSignature(SIGNAL(signal1())));
delete s;
delete r;
}
class NotifyMethodObject : public SenderObject, public ReceiverObject
{
public:
NotifyMethodObject() : SenderObject(), ReceiverObject()
{}
QList<QMetaMethod> connectedSignals;
QList<QMetaMethod> disconnectedSignals;
void clearNotifications()
{
connectedSignals.clear();
disconnectedSignals.clear();
}
protected:
void connectNotify(const QMetaMethod &signal)
{ connectedSignals.append(signal); }
void disconnectNotify(const QMetaMethod &signal)
{ disconnectedSignals.append(signal); }
};
void tst_QObject::connectDisconnectNotifyMethod_data()
{
tst_QObject::connectDisconnectNotify_data();
}
void tst_QObject::connectDisconnectNotifyMethod()
{
NotifyMethodObject *s = new NotifyMethodObject;
NotifyMethodObject *r = new NotifyMethodObject;
QFETCH(QString, a_signal);
QFETCH(QString, a_slot);
// Obtaining meta methods
int signalIndx = ((SenderObject*)s)->metaObject()->indexOfSignal(
QMetaObject::normalizedSignature(a_signal.toLatin1().constData()+1).constData());
@ -1005,10 +917,10 @@ void tst_QObject::connectDisconnectNotifyMethod()
static void connectDisconnectNotifyTestSlot() {}
void tst_QObject::connectDisconnectNotifyMethodPMF()
void tst_QObject::connectDisconnectNotifyPMF()
{
NotifyMethodObject *s = new NotifyMethodObject;
NotifyMethodObject *r = new NotifyMethodObject;
NotifyObject *s = new NotifyObject;
NotifyObject *r = new NotifyObject;
QMetaMethod signal = QMetaMethod::fromSignal(&SenderObject::signal1);
@ -1058,10 +970,10 @@ void tst_QObject::connectDisconnectNotifyMethodPMF()
delete r;
}
void tst_QObject::disconnectNotifyMethod_receiverDestroyed()
void tst_QObject::disconnectNotify_receiverDestroyed()
{
NotifyMethodObject *s = new NotifyMethodObject;
NotifyMethodObject *r = new NotifyMethodObject;
NotifyObject *s = new NotifyObject;
NotifyObject *r = new NotifyObject;
QVERIFY(QObject::connect((SenderObject*)s, SIGNAL(signal1()), (ReceiverObject*)r, SLOT(slot1())));
@ -1115,7 +1027,7 @@ public Q_SLOTS:
void on_baz_signal1() {}
};
void tst_QObject::connectNotifyMethod_connectSlotsByName()
void tst_QObject::connectNotify_connectSlotsByName()
{
ConnectByNameNotifyReceiverObject testObject;
QList<ConnectByNameNotifySenderObject *> senders =
@ -1146,7 +1058,7 @@ Q_SIGNALS:
void signal1();
};
void tst_QObject::connectDisconnectNotifyMethod_shadowing()
void tst_QObject::connectDisconnectNotify_shadowing()
{
ConnectDisconnectNotifyShadowObject s;
// Obtain QMetaMethods