summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-10-23 04:14:47 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-10-23 04:14:47 (GMT)
commitd7133797672a66cbdab759e32daaf0cb1f52e78d (patch)
tree893089b0a5ac77b51871791695dad87b48858a3e
parent3386479da9526f0ae8978cd9e0afdd0559049ef9 (diff)
downloadQt-d7133797672a66cbdab759e32daaf0cb1f52e78d.zip
Qt-d7133797672a66cbdab759e32daaf0cb1f52e78d.tar.gz
Qt-d7133797672a66cbdab759e32daaf0cb1f52e78d.tar.bz2
Use QmlScriptString for Connection script
(instead of AST special-case handling) Fixes QT-734
-rw-r--r--src/declarative/qml/qmlscriptparser.cpp41
-rw-r--r--src/declarative/util/qmlconnection.cpp23
-rw-r--r--src/declarative/util/qmlconnection.h7
3 files changed, 18 insertions, 53 deletions
diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp
index 6e5f315..fb84651 100644
--- a/src/declarative/qml/qmlscriptparser.cpp
+++ b/src/declarative/qml/qmlscriptparser.cpp
@@ -365,46 +365,7 @@ Object *ProcessAST::defineObjectBinding(AST::UiQualifiedId *qualifiedId,
const QString objectType = asString(objectTypeName);
const AST::SourceLocation typeLocation = objectTypeName->identifierToken;
- if (objectType == QLatin1String("Connection")) {
-
- Object *obj = defineObjectBinding_helper(/*propertyName = */0, objectType, typeLocation, location);
-
- _stateStack.pushObject(obj);
-
- AST::UiObjectMemberList *it = initializer->members;
- for (; it; it = it->next) {
- AST::UiScriptBinding *scriptBinding = AST::cast<AST::UiScriptBinding *>(it->member);
- if (! scriptBinding)
- continue;
-
- QString propertyName = asString(scriptBinding->qualifiedId);
- if (propertyName == QLatin1String("script")) {
- QString script;
-
- if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement *>(scriptBinding->statement)) {
- script = getVariant(stmt->expression).asScript();
- } else {
- script = asString(scriptBinding->statement);
- }
-
- LocationSpan l = this->location(scriptBinding->statement->firstSourceLocation(),
- scriptBinding->statement->lastSourceLocation());
-
- _stateStack.pushProperty(QLatin1String("script"), l);
- Value *value = new Value;
- value->value = QmlParser::Variant(script);
- value->location = l;
- currentProperty()->addValue(value);
- _stateStack.pop();
- } else {
- accept(it->member);
- }
- }
-
- _stateStack.pop(); // object
-
- return obj;
- } else if (objectType == QLatin1String("Script")) {
+ if (objectType == QLatin1String("Script")) {
AST::UiObjectMemberList *it = initializer->members;
for (; it; it = it->next) {
diff --git a/src/declarative/util/qmlconnection.cpp b/src/declarative/util/qmlconnection.cpp
index 2a7cf6c..5475fb2 100644
--- a/src/declarative/util/qmlconnection.cpp
+++ b/src/declarative/util/qmlconnection.cpp
@@ -51,11 +51,12 @@ QT_BEGIN_NAMESPACE
class QmlConnectionPrivate : public QObjectPrivate
{
public:
- QmlConnectionPrivate() : boundsignal(0), signalSender(0), componentcomplete(false) {}
+ QmlConnectionPrivate() : boundsignal(0), signalSender(0), scriptset(false), componentcomplete(false) {}
QmlBoundSignal *boundsignal;
QObject *signalSender;
- QString script;
+ QmlScriptString script;
+ bool scriptset;
QString signal;
bool componentcomplete;
};
@@ -154,7 +155,7 @@ void QmlConnection::connectIfValid()
if (!d->componentcomplete)
return;
// boundsignal must not exist
- if ((d->signalSender || parent()) && !d->signal.isEmpty() && !d->script.isEmpty()) {
+ if ((d->signalSender || parent()) && !d->signal.isEmpty() && d->scriptset) {
// create
// XXX scope?
int sigIdx = -1;
@@ -187,7 +188,7 @@ void QmlConnection::connectIfValid()
return;
}
- d->boundsignal = new QmlBoundSignal(qmlContext(this), d->script, sender, mo->method(sigIdx), this);
+ d->boundsignal = new QmlBoundSignal(qmlContext(this), d->script.script(), sender, mo->method(sigIdx), this);
}
}
@@ -196,7 +197,7 @@ void QmlConnection::disconnectIfValid()
Q_D(QmlConnection);
if (!d->componentcomplete)
return;
- if ((d->signalSender || parent()) && !d->signal.isEmpty() && !d->script.isEmpty()) {
+ if ((d->signalSender || parent()) && !d->signal.isEmpty() && d->scriptset) {
// boundsignal must exist
// destroy
delete d->boundsignal;
@@ -213,31 +214,33 @@ void QmlConnection::componentComplete()
/*!
- \qmlproperty string Connection::script
+ \qmlproperty script Connection::script
This property holds the JavaScript executed whenever the signal is sent.
This is the default attribute of Connection.
*/
-QString QmlConnection::script() const
+QmlScriptString QmlConnection::script() const
{
Q_D(const QmlConnection);
return d->script;
}
-void QmlConnection::setScript(const QString& script)
+void QmlConnection::setScript(const QmlScriptString& script)
{
Q_D(QmlConnection);
if ((d->signalSender || parent()) && !d->signal.isEmpty()) {
- if (d->script.isEmpty()) {
+ if (!d->scriptset) {
// mustn't exist - create
+ d->scriptset = true;
d->script = script;
connectIfValid();
} else {
// must exist - update
d->script = script;
- d->boundsignal->expression()->setExpression(script);
+ d->boundsignal->expression()->setExpression(script.script());
}
} else {
+ d->scriptset = true;
d->script = script;
}
}
diff --git a/src/declarative/util/qmlconnection.h b/src/declarative/util/qmlconnection.h
index dcaac34..3d69c6f 100644
--- a/src/declarative/util/qmlconnection.h
+++ b/src/declarative/util/qmlconnection.h
@@ -45,6 +45,7 @@
#include <QtCore/qobject.h>
#include <QtCore/qstring.h>
#include <QtDeclarative/qml.h>
+#include <QtDeclarative/qmlscriptstring.h>
QT_BEGIN_HEADER
@@ -62,7 +63,7 @@ class Q_DECLARATIVE_EXPORT QmlConnection : public QObject, public QmlParserStatu
Q_INTERFACES(QmlParserStatus)
Q_PROPERTY(QObject *sender READ signalSender WRITE setSignalSender)
- Q_PROPERTY(QString script READ script WRITE setScript)
+ Q_PROPERTY(QmlScriptString script READ script WRITE setScript)
Q_PROPERTY(QString signal READ signal WRITE setSignal)
public:
@@ -71,8 +72,8 @@ public:
QObject *signalSender() const;
void setSignalSender(QObject *);
- QString script() const;
- void setScript(const QString&);
+ QmlScriptString script() const;
+ void setScript(const QmlScriptString&);
QString signal() const;
void setSignal(const QString&);