Provide receivers count from QQmlData.

Change-Id: I70b06507158797df3083dc23a119935497aa19f4
Reviewed-by: Kent Hansen <kent.hansen@nokia.com>
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
This commit is contained in:
Michael Brasser 2012-04-05 13:30:00 +10:00 committed by Qt by Nokia
parent 22408c96cd
commit 955bac4940
6 changed files with 64 additions and 0 deletions

View File

@ -91,12 +91,14 @@ public:
QAbstractDeclarativeData::parentChanged = parentChanged;
QAbstractDeclarativeData::objectNameChanged = objectNameChanged;
QAbstractDeclarativeData::signalEmitted = signalEmitted;
QAbstractDeclarativeData::receivers = receivers;
}
static void destroyed(QAbstractDeclarativeData *, QObject *);
static void parentChanged(QAbstractDeclarativeData *, QObject *, QObject *);
static void objectNameChanged(QAbstractDeclarativeData *, QObject *);
static void signalEmitted(QAbstractDeclarativeData *, QObject *, int, void **);
static int receivers(QAbstractDeclarativeData *, const QObject *, int);
void destroyed(QObject *);
void parentChanged(QObject *, QObject *);
@ -130,6 +132,7 @@ public:
inline QQmlNotifierEndpoint *notify(int index);
void addNotify(int index, QQmlNotifierEndpoint *);
int endpointCount(int index);
// The context that created the C++ object
QQmlContextData *context;

View File

@ -457,6 +457,25 @@ void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int in
if (ep) QQmlNotifier::emitNotify(ep);
}
int QQmlData::receivers(QAbstractDeclarativeData *d, const QObject *, int index)
{
return static_cast<QQmlData *>(d)->endpointCount(index);
}
int QQmlData::endpointCount(int index)
{
int count = 0;
QQmlNotifierEndpoint *ep = notify(index);
if (!ep)
return count;
++count;
while (ep->next) {
++count;
ep = ep->next;
}
return count;
}
void QQmlEnginePrivate::init()
{
Q_Q(QQmlEngine);

View File

@ -0,0 +1,8 @@
import Test 1.0
MyReceiversTestObject {
property int dummy: prop
onPropChanged: { var a = 0; } //do nothing
onMySignal: { var a = 0; } //do nothing
}

View File

@ -81,6 +81,8 @@ void registerTypes()
qmlRegisterType<MyEnum1Class>("Test",1,0,"MyEnum1Class");
qmlRegisterType<MyEnum2Class>("Test",1,0,"MyEnum2Class");
qmlRegisterType<MyEnumDerivedClass>("Test",1,0,"MyEnumDerivedClass");
qmlRegisterType<MyReceiversTestObject>("Test",1,0,"MyReceiversTestObject");
}
QVariant myCustomVariantTypeConverter(const QString &data)

View File

@ -526,6 +526,24 @@ public:
UnavailableType() {}
};
class MyReceiversTestObject : public QObject
{
Q_OBJECT
Q_PROPERTY(int prop READ prop NOTIFY propChanged)
public:
MyReceiversTestObject() {}
int prop() const { return 5; }
int mySignalCount() { return receivers(SIGNAL(mySignal())); }
int propChangedCount() { return receivers(SIGNAL(propChanged())); }
signals:
void mySignal();
void propChanged();
};
class MyDotPropertyObject : public QObject
{
Q_OBJECT
@ -907,6 +925,7 @@ QML_DECLARE_TYPE(MyRevisionedBaseClassUnregistered)
QML_DECLARE_TYPE(MyRevisionedClass)
QML_DECLARE_TYPE(MyRevisionedSubclass)
QML_DECLARE_TYPE(MySubclass)
QML_DECLARE_TYPE(MyReceiversTestObject)
void registerTypes();

View File

@ -146,6 +146,7 @@ private slots:
void nestedComponentRoots();
void registrationOrder();
void readonly();
void receivers();
void basicRemote_data();
void basicRemote();
@ -2285,6 +2286,18 @@ void tst_qqmllanguage::readonly()
delete o;
}
void tst_qqmllanguage::receivers()
{
QQmlComponent component(&engine, TEST_FILE("receivers.qml"));
MyReceiversTestObject *o = qobject_cast<MyReceiversTestObject*>(component.create());
QVERIFY(o != 0);
QCOMPARE(o->mySignalCount(), 1);
QCOMPARE(o->propChangedCount(), 2);
delete o;
}
// QTBUG-18268
void tst_qqmllanguage::remoteLoadCrash()
{