aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2011-10-11 14:21:42 +1000
committerQt by Nokia <qt-info@nokia.com>2011-10-18 03:20:24 +0200
commit910cd60ef998a41434105478fb6df6efc0b94113 (patch)
tree07c4e134bf8bfdc92d89d56520a63ff2ff5b97d9 /src
parent277ee9a676cb976b27a7b8667cac1ec0ba1e4ce0 (diff)
Simplify expression guard logic
Change-Id: I7d191bc8786452c5a1f14d024ff62d223adebd8b Reviewed-by: Martin Jones <martin.jones@nokia.com> Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/qml/qdeclarativeexpression.cpp41
-rw-r--r--src/declarative/qml/qdeclarativenotifier.cpp6
-rw-r--r--src/declarative/qml/qdeclarativenotifier_p.h35
3 files changed, 44 insertions, 38 deletions
diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp
index 27979afb9c..d3ba92ab42 100644
--- a/src/declarative/qml/qdeclarativeexpression.cpp
+++ b/src/declarative/qml/qdeclarativeexpression.cpp
@@ -515,45 +515,18 @@ QDeclarativeJavaScriptExpression::GuardList::updateGuards(QDeclarativeJavaScript
if (property.notifier != 0) {
- if (!noChanges && guard.isConnected(property.notifier)) {
- // Nothing to do
-
+ if (guard.isConnected(property.notifier)) {
+ guard.cancelNotify();
} else {
- noChanges = false;
-
- bool existing = false;
- for (int jj = 0; !existing && jj < ii; ++jj)
- if (endpoints[jj].isConnected(property.notifier))
- existing = true;
-
- if (existing) {
- // duplicate
- guard.disconnect();
- } else {
- guard.connect(property.notifier);
- }
+ guard.connect(property.notifier);
}
-
} else if (property.notifyIndex != -1) {
- if (!noChanges && guard.isConnected(property.object, property.notifyIndex)) {
- // Nothing to do
-
- } else {
- noChanges = false;
-
- bool existing = false;
- for (int jj = 0; !existing && jj < ii; ++jj)
- if (endpoints[jj].isConnected(property.object, property.notifyIndex))
- existing = true;
-
- if (existing) {
- // duplicate
- guard.disconnect();
- } else {
- guard.connect(property.object, property.notifyIndex);
- }
+ if (guard.isConnected(property.object, property.notifyIndex)) {
+ guard.cancelNotify();
+ } else {
+ guard.connect(property.object, property.notifyIndex);
}
} else {
diff --git a/src/declarative/qml/qdeclarativenotifier.cpp b/src/declarative/qml/qdeclarativenotifier.cpp
index a195280316..842cbf00b5 100644
--- a/src/declarative/qml/qdeclarativenotifier.cpp
+++ b/src/declarative/qml/qdeclarativenotifier.cpp
@@ -48,14 +48,15 @@ void QDeclarativeNotifier::emitNotify(QDeclarativeNotifierEndpoint *endpoint)
{
QDeclarativeNotifierEndpoint **oldDisconnected = endpoint->disconnected;
endpoint->disconnected = &endpoint;
+ endpoint->notifying = 1;
if (endpoint->next)
emitNotify(endpoint->next);
if (endpoint) {
- void *args[] = { 0 };
Q_ASSERT(endpoint->callback);
+
endpoint->callback(endpoint);
if (endpoint)
@@ -63,6 +64,7 @@ void QDeclarativeNotifier::emitNotify(QDeclarativeNotifierEndpoint *endpoint)
}
if (oldDisconnected) *oldDisconnected = endpoint;
+ else if (endpoint) endpoint->notifying = 0;
}
void QDeclarativeNotifierEndpoint::connect(QObject *source, int sourceSignal)
@@ -91,6 +93,7 @@ void QDeclarativeNotifierEndpoint::copyAndClear(QDeclarativeNotifierEndpoint &ot
other.notifier = notifier;
other.sourceSignal = sourceSignal;
other.disconnected = disconnected;
+ other.notifying = notifying;
if (other.disconnected) *other.disconnected = &other;
if (next) {
@@ -104,6 +107,7 @@ void QDeclarativeNotifierEndpoint::copyAndClear(QDeclarativeNotifierEndpoint &ot
next = 0;
disconnected = 0;
notifier = 0;
+ notifying = 0;
sourceSignal = -1;
}
diff --git a/src/declarative/qml/qdeclarativenotifier_p.h b/src/declarative/qml/qdeclarativenotifier_p.h
index 1d0d4fc6f5..06c0ba0918 100644
--- a/src/declarative/qml/qdeclarativenotifier_p.h
+++ b/src/declarative/qml/qdeclarativenotifier_p.h
@@ -80,6 +80,9 @@ public:
inline void connect(QDeclarativeNotifier *);
inline void disconnect();
+ inline bool isNotifying() const;
+ inline void cancelNotify();
+
void copyAndClear(QDeclarativeNotifierEndpoint &other);
private:
@@ -90,7 +93,8 @@ private:
QDeclarativeNotifier *notifier;
QObject *source;
};
- int sourceSignal;
+ unsigned int notifying : 1;
+ signed int sourceSignal : 31;
QDeclarativeNotifierEndpoint **disconnected;
QDeclarativeNotifierEndpoint *next;
QDeclarativeNotifierEndpoint **prev;
@@ -124,7 +128,7 @@ void QDeclarativeNotifier::notify()
}
QDeclarativeNotifierEndpoint::QDeclarativeNotifierEndpoint()
-: callback(0), notifier(0), sourceSignal(-1), disconnected(0), next(0), prev(0)
+: callback(0), notifier(0), notifying(0), sourceSignal(-1), disconnected(0), next(0), prev(0)
{
}
@@ -140,7 +144,7 @@ bool QDeclarativeNotifierEndpoint::isConnected()
bool QDeclarativeNotifierEndpoint::isConnected(QObject *source, int sourceSignal)
{
- return sourceSignal != -1 && this->source == source && this->sourceSignal == sourceSignal;
+ return this->sourceSignal != -1 && this->source == source && this->sourceSignal == sourceSignal;
}
bool QDeclarativeNotifierEndpoint::isConnected(QDeclarativeNotifier *notifier)
@@ -168,9 +172,34 @@ void QDeclarativeNotifierEndpoint::disconnect()
prev = 0;
disconnected = 0;
notifier = 0;
+ notifying = 0;
sourceSignal = -1;
}
+/*!
+Returns true if a notify is in progress. This means that the signal or QDeclarativeNotifier
+that this endpoing is connected to has been triggered, but this endpoint's callback has not
+yet been called.
+
+An in progress notify can be cancelled by calling cancelNotify.
+*/
+bool QDeclarativeNotifierEndpoint::isNotifying() const
+{
+ return notifying == 1;
+}
+
+/*!
+Cancel any notifies that are in progress.
+*/
+void QDeclarativeNotifierEndpoint::cancelNotify()
+{
+ notifying = 0;
+ if (disconnected) {
+ *disconnected = 0;
+ disconnected = 0;
+ }
+}
+
QT_END_NAMESPACE
#endif // QDECLARATIVENOTIFIER_P_H