diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2011-09-22 13:14:00 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-27 06:16:46 +0200 |
commit | ffeadf7a7c09971fab09ed08b1f3f503c6facb7e (patch) | |
tree | 07264779d1a55ffc6641c316c371feabdd252848 /src/declarative/qml/qdeclarativeglobal_p.h | |
parent | 1ec3460d838c05ddbd9b991d7edf9fded31fe684 (diff) |
Add convenience macro for fast connects in declarative.
We already follow this pattern several places, so
this commit creates a convenience macro for it, and replaces
previous usage where appropriate. Also adds the macro
several places as further optimization.
Change-Id: Ieff5ed6cc51c34d0a1c8aa42ac40314ea243477a
Reviewed-on: http://codereview.qt-project.org/5342
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'src/declarative/qml/qdeclarativeglobal_p.h')
-rw-r--r-- | src/declarative/qml/qdeclarativeglobal_p.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/declarative/qml/qdeclarativeglobal_p.h b/src/declarative/qml/qdeclarativeglobal_p.h index 87be79f171..cc0a4b6b1d 100644 --- a/src/declarative/qml/qdeclarativeglobal_p.h +++ b/src/declarative/qml/qdeclarativeglobal_p.h @@ -64,6 +64,32 @@ QT_MODULE(Declarative) return status == Yes; \ } +#define FAST_CONNECT(Sender, Signal, Receiver, Method) \ +{ \ + QObject *sender = (Sender); \ + QObject *receiver = (Receiver); \ + const char *signal = (Signal); \ + const char *method = (Method); \ + static int signalIdx = -1; \ + static int methodIdx = -1; \ + if (signalIdx < 0) { \ + if (((int)(*signal) - '0') == QSIGNAL_CODE) \ + signalIdx = sender->metaObject()->indexOfSignal(signal+1); \ + else \ + qWarning("FAST_CONNECT: Invalid signal %s. Please make sure you are using the SIGNAL macro.", signal); \ + } \ + if (methodIdx < 0) { \ + int code = ((int)(*method) - '0'); \ + if (code == QSLOT_CODE) \ + methodIdx = receiver->metaObject()->indexOfSlot(method+1); \ + else if (code == QSIGNAL_CODE) \ + methodIdx = receiver->metaObject()->indexOfSignal(method+1); \ + else \ + qWarning("FAST_CONNECT: Invalid method %s. Please make sure you are using the SIGNAL or SLOT macro.", method); \ + } \ + QMetaObject::connect(sender, signalIdx, receiver, methodIdx, Qt::DirectConnection); \ +} + #ifdef Q_OS_SYMBIAN #define Q_DECLARATIVE_PRIVATE_EXPORT Q_AUTOTEST_EXPORT #else |