diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-06-25 15:25:48 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-06-25 15:32:13 (GMT) |
commit | 47c9e7b1b3551ff6dbe71590461a45ae398a9501 (patch) | |
tree | f965ed1cb23bbdb2116dfba945e44b1d2dfc2532 /src | |
parent | 3984253ac58e0cca1c0b94fad1549dd4e0e3c2e1 (diff) | |
download | Qt-47c9e7b1b3551ff6dbe71590461a45ae398a9501.zip Qt-47c9e7b1b3551ff6dbe71590461a45ae398a9501.tar.gz Qt-47c9e7b1b3551ff6dbe71590461a45ae398a9501.tar.bz2 |
make it possible to support queued connections in qtscript
This change doesn't actually add public API for it, but makes it
trivial to add.
On the C++ side, qScriptConnect() would get an overload that
takes an additional argument, the connection type (d'oh, it
should have had a default argument to begin with!).
On the script side, it's a bit more tricky to "overload" the
existing connect(), since it's already "overloaded" (can have
either one or two parameters). Plus, I'd like connect() to be
able to support bind-like functionality so you can pass
additional arguments to it that will be passed to the signal
handler at signal emission time. Oh well, we'll see.
Diffstat (limited to 'src')
-rw-r--r-- | src/script/qscriptecmafunction.cpp | 2 | ||||
-rw-r--r-- | src/script/qscriptengine.cpp | 3 | ||||
-rw-r--r-- | src/script/qscriptengine_p.cpp | 15 | ||||
-rw-r--r-- | src/script/qscriptenginefwd_p.h | 9 | ||||
-rw-r--r-- | src/script/qscriptextqobject.cpp | 13 | ||||
-rw-r--r-- | src/script/qscriptextqobject_p.h | 3 |
6 files changed, 28 insertions, 17 deletions
diff --git a/src/script/qscriptecmafunction.cpp b/src/script/qscriptecmafunction.cpp index 87b0639..0bb5f12 100644 --- a/src/script/qscriptecmafunction.cpp +++ b/src/script/qscriptecmafunction.cpp @@ -436,7 +436,7 @@ QScriptValueImpl Function::method_connect(QScriptContextPrivate *context, QScrip QLatin1String("Function.prototype.connect: target is not a function")); } - bool ok = eng->scriptConnect(self, receiver, slot); + bool ok = eng->scriptConnect(self, receiver, slot, Qt::AutoConnection); if (!ok) { return context->throwError( QString::fromLatin1("Function.prototype.connect: failed to connect to %0::%1") diff --git a/src/script/qscriptengine.cpp b/src/script/qscriptengine.cpp index de8bd8d..de78403 100644 --- a/src/script/qscriptengine.cpp +++ b/src/script/qscriptengine.cpp @@ -1616,7 +1616,8 @@ bool qScriptConnect(QObject *sender, const char *signal, QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(function.engine()); return eng_p->scriptConnect(sender, signal, eng_p->toImpl(receiver), - eng_p->toImpl(function)); + eng_p->toImpl(function), + Qt::AutoConnection); } /*! diff --git a/src/script/qscriptengine_p.cpp b/src/script/qscriptengine_p.cpp index 0a238bc..ffb5a27 100644 --- a/src/script/qscriptengine_p.cpp +++ b/src/script/qscriptengine_p.cpp @@ -2312,7 +2312,8 @@ void QScriptEnginePrivate::deletePendingQObjects() bool QScriptEnginePrivate::scriptConnect(QObject *sender, const char *signal, const QScriptValueImpl &receiver, - const QScriptValueImpl &function) + const QScriptValueImpl &function, + Qt::ConnectionType type) { Q_ASSERT(sender); Q_ASSERT(signal); @@ -2320,7 +2321,7 @@ bool QScriptEnginePrivate::scriptConnect(QObject *sender, const char *signal, int index = meta->indexOfSignal(QMetaObject::normalizedSignature(signal+1)); if (index == -1) return false; - return scriptConnect(sender, index, receiver, function); + return scriptConnect(sender, index, receiver, function, /*wrapper=*/QScriptValueImpl(), type); } bool QScriptEnginePrivate::scriptDisconnect(QObject *sender, const char *signal, @@ -2339,10 +2340,11 @@ bool QScriptEnginePrivate::scriptDisconnect(QObject *sender, const char *signal, bool QScriptEnginePrivate::scriptConnect(QObject *sender, int signalIndex, const QScriptValueImpl &receiver, const QScriptValueImpl &function, - const QScriptValueImpl &senderWrapper) + const QScriptValueImpl &senderWrapper, + Qt::ConnectionType type) { QScriptQObjectData *data = qobjectData(sender); - return data->addSignalHandler(sender, signalIndex, receiver, function, senderWrapper); + return data->addSignalHandler(sender, signalIndex, receiver, function, senderWrapper, type); } bool QScriptEnginePrivate::scriptDisconnect(QObject *sender, int signalIndex, @@ -2357,11 +2359,12 @@ bool QScriptEnginePrivate::scriptDisconnect(QObject *sender, int signalIndex, bool QScriptEnginePrivate::scriptConnect(const QScriptValueImpl &signal, const QScriptValueImpl &receiver, - const QScriptValueImpl &function) + const QScriptValueImpl &function, + Qt::ConnectionType type) { QScript::QtFunction *fun = static_cast<QScript::QtFunction*>(signal.toFunction()); int index = fun->mostGeneralMethod(); - return scriptConnect(fun->qobject(), index, receiver, function, fun->object()); + return scriptConnect(fun->qobject(), index, receiver, function, fun->object(), type); } bool QScriptEnginePrivate::scriptDisconnect(const QScriptValueImpl &signal, diff --git a/src/script/qscriptenginefwd_p.h b/src/script/qscriptenginefwd_p.h index 11cd839..62942a5 100644 --- a/src/script/qscriptenginefwd_p.h +++ b/src/script/qscriptenginefwd_p.h @@ -385,7 +385,8 @@ public: bool scriptConnect(QObject *sender, const char *signal, const QScriptValueImpl &receiver, - const QScriptValueImpl &function); + const QScriptValueImpl &function, + Qt::ConnectionType type); bool scriptDisconnect(QObject *sender, const char *signal, const QScriptValueImpl &receiver, const QScriptValueImpl &function); @@ -393,14 +394,16 @@ public: bool scriptConnect(QObject *sender, int index, const QScriptValueImpl &receiver, const QScriptValueImpl &function, - const QScriptValueImpl &senderWrapper = QScriptValueImpl()); + const QScriptValueImpl &senderWrapper, + Qt::ConnectionType type); bool scriptDisconnect(QObject *sender, int index, const QScriptValueImpl &receiver, const QScriptValueImpl &function); bool scriptConnect(const QScriptValueImpl &signal, const QScriptValueImpl &receiver, - const QScriptValueImpl &function); + const QScriptValueImpl &function, + Qt::ConnectionType type); bool scriptDisconnect(const QScriptValueImpl &signal, const QScriptValueImpl &receiver, const QScriptValueImpl &function); diff --git a/src/script/qscriptextqobject.cpp b/src/script/qscriptextqobject.cpp index 00963a7..a3cb4e6 100644 --- a/src/script/qscriptextqobject.cpp +++ b/src/script/qscriptextqobject.cpp @@ -1420,7 +1420,8 @@ public: bool addSignalHandler(QObject *sender, int signalIndex, const QScriptValueImpl &receiver, const QScriptValueImpl &slot, - const QScriptValueImpl &senderWrapper = QScriptValueImpl()); + const QScriptValueImpl &senderWrapper, + Qt::ConnectionType type); bool removeSignalHandler( QObject *sender, int signalIndex, const QScriptValueImpl &receiver, @@ -1741,13 +1742,14 @@ void QScript::QObjectConnectionManager::mark(int generation) bool QScript::QObjectConnectionManager::addSignalHandler( QObject *sender, int signalIndex, const QScriptValueImpl &receiver, - const QScriptValueImpl &function, const QScriptValueImpl &senderWrapper) + const QScriptValueImpl &function, const QScriptValueImpl &senderWrapper, + Qt::ConnectionType type) { if (connections.size() <= signalIndex) connections.resize(signalIndex+1); QVector<QObjectConnection> &cs = connections[signalIndex]; int absSlotIndex = m_slotCounter + metaObject()->methodOffset(); - bool ok = QMetaObject::connect(sender, signalIndex, this, absSlotIndex); + bool ok = QMetaObject::connect(sender, signalIndex, this, absSlotIndex, type); if (ok) { cs.append(QScript::QObjectConnection(m_slotCounter++, receiver, function, senderWrapper)); QMetaMethod signal = sender->metaObject()->method(signalIndex); @@ -2176,12 +2178,13 @@ bool QScriptQObjectData::addSignalHandler(QObject *sender, int signalIndex, const QScriptValueImpl &receiver, const QScriptValueImpl &slot, - const QScriptValueImpl &senderWrapper) + const QScriptValueImpl &senderWrapper, + Qt::ConnectionType type) { if (!m_connectionManager) m_connectionManager = new QScript::QObjectConnectionManager(); return m_connectionManager->addSignalHandler( - sender, signalIndex, receiver, slot, senderWrapper); + sender, signalIndex, receiver, slot, senderWrapper, type); } bool QScriptQObjectData::removeSignalHandler(QObject *sender, diff --git a/src/script/qscriptextqobject_p.h b/src/script/qscriptextqobject_p.h index 764644f..8f10823 100644 --- a/src/script/qscriptextqobject_p.h +++ b/src/script/qscriptextqobject_p.h @@ -216,7 +216,8 @@ public: int signalIndex, const QScriptValueImpl &receiver, const QScriptValueImpl &slot, - const QScriptValueImpl &senderWrapper = QScriptValueImpl()); + const QScriptValueImpl &senderWrapper, + Qt::ConnectionType type); bool removeSignalHandler(QObject *sender, int signalIndex, const QScriptValueImpl &receiver, |