From c63f97389b2a654de76713f20266f45ffc83062d Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Mon, 20 Apr 2009 15:13:51 +0200 Subject: Added a dummy button on top of the webview to show how input events are delayed. --- examples/gestures/pannablewebview/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/gestures/pannablewebview/main.cpp b/examples/gestures/pannablewebview/main.cpp index 5b7a67a..7c74bbd 100644 --- a/examples/gestures/pannablewebview/main.cpp +++ b/examples/gestures/pannablewebview/main.cpp @@ -7,6 +7,11 @@ public: PannableWebView(QWidget *parent = 0) : QWebView(parent) { +#if 0 + QPushButton *btn = new QPushButton("Some test button", this); + btn->resize(300, 200); + btn->move(40, 300); +#endif grabGesture(Qt::PanGesture); } protected: -- cgit v0.12 ber of QML elements that operate using data models: \o ListView \o GridView \o PathView -\o \l {qml-repeater}{Repeater} +\o \l Repeater \endlist QML supports several types of data model, which may be provided by QML diff --git a/src/declarative/fx/qfxborderimage.cpp b/src/declarative/fx/qfxborderimage.cpp index 6616912..8f98a11 100644 --- a/src/declarative/fx/qfxborderimage.cpp +++ b/src/declarative/fx/qfxborderimage.cpp @@ -273,7 +273,7 @@ void QFxBorderImage::setHorizontalTileMode(TileMode t) Q_D(QFxBorderImage); if (t != d->horizontalTileMode) { d->horizontalTileMode = t; - emit tileModeChanged(); + emit horizontalTileModeChanged(); update(); } } @@ -289,7 +289,7 @@ void QFxBorderImage::setVerticalTileMode(TileMode t) Q_D(QFxBorderImage); if (t != d->verticalTileMode) { d->verticalTileMode = t; - emit tileModeChanged(); + emit verticalTileModeChanged(); update(); } } diff --git a/src/declarative/fx/qfxborderimage.h b/src/declarative/fx/qfxborderimage.h index eae9bd1..5bc1067 100644 --- a/src/declarative/fx/qfxborderimage.h +++ b/src/declarative/fx/qfxborderimage.h @@ -59,8 +59,8 @@ class Q_DECLARATIVE_EXPORT QFxBorderImage : public QFxImageBase Q_ENUMS(TileMode) Q_PROPERTY(QFxScaleGrid *border READ border CONSTANT) - Q_PROPERTY(TileMode horizontalTileMode READ horizontalTileMode WRITE setHorizontalTileMode NOTIFY tileModeChanged) - Q_PROPERTY(TileMode verticalTileMode READ verticalTileMode WRITE setVerticalTileMode NOTIFY tileModeChanged) + Q_PROPERTY(TileMode horizontalTileMode READ horizontalTileMode WRITE setHorizontalTileMode NOTIFY horizontalTileModeChanged) + Q_PROPERTY(TileMode verticalTileMode READ verticalTileMode WRITE setVerticalTileMode NOTIFY verticalTileModeChanged) public: QFxBorderImage(QFxItem *parent=0); @@ -80,7 +80,8 @@ public: void setSource(const QUrl &url); Q_SIGNALS: - void tileModeChanged(); + void horizontalTileModeChanged(); + void verticalTileModeChanged(); protected: QFxBorderImage(QFxBorderImagePrivate &dd, QFxItem *parent); diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index a8b27f4..2ed704e 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -1000,7 +1000,7 @@ void QFxGridView::setCellWidth(int cellWidth) if (cellWidth != d->cellWidth && cellWidth > 0) { d->cellWidth = qMax(1, cellWidth); d->updateGrid(); - emit cellSizeChanged(); + emit cellWidthChanged(); d->layout(); } } @@ -1017,7 +1017,7 @@ void QFxGridView::setCellHeight(int cellHeight) if (cellHeight != d->cellHeight && cellHeight > 0) { d->cellHeight = qMax(1, cellHeight); d->updateGrid(); - emit cellSizeChanged(); + emit cellHeightChanged(); d->layout(); } } diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h index 08a7565..7f30f03 100644 --- a/src/declarative/fx/qfxgridview.h +++ b/src/declarative/fx/qfxgridview.h @@ -67,8 +67,8 @@ class Q_DECLARATIVE_EXPORT QFxGridView : public QFxFlickable Q_PROPERTY(Flow flow READ flow WRITE setFlow) Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) - Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellSizeChanged) - Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellSizeChanged) + Q_PROPERTY(int cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged) + Q_PROPERTY(int cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged) Q_CLASSINFO("DefaultProperty", "data") public: @@ -121,7 +121,8 @@ public Q_SLOTS: Q_SIGNALS: void countChanged(); void currentIndexChanged(); - void cellSizeChanged(); + void cellWidthChanged(); + void cellHeightChanged(); protected: virtual void viewportMoved(); diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 1247021..aa8ccfd 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -1180,6 +1180,7 @@ void QFxListView::setOrientation(Qt::Orientation orientation) setViewportHeight(-1); d->clear(); refill(); + emit orientationChanged(); d->updateCurrent(d->currentIndex); } } diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index 3cff422..5a83604 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -72,7 +72,7 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_PROPERTY(bool strictlyEnforceHighlightRange READ strictlyEnforceHighlightRange WRITE setStrictlyEnforceHighlightRange) Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) - Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) + Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged) Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) Q_PROPERTY(QString sectionExpression READ sectionExpression WRITE setSectionExpression NOTIFY sectionExpressionChanged) @@ -106,7 +106,7 @@ public: bool strictlyEnforceHighlightRange() const; void setStrictlyEnforceHighlightRange(bool strict); - + qreal preferredHighlightBegin() const; void setPreferredHighlightBegin(qreal); @@ -144,6 +144,7 @@ public Q_SLOTS: Q_SIGNALS: void countChanged(); void spacingChanged(); + void orientationChanged(); void currentIndexChanged(); void currentSectionChanged(); void sectionExpressionChanged(); diff --git a/src/declarative/fx/qfxpositioners.cpp b/src/declarative/fx/qfxpositioners.cpp index e4500aa..f8e7213 100644 --- a/src/declarative/fx/qfxpositioners.cpp +++ b/src/declarative/fx/qfxpositioners.cpp @@ -97,6 +97,7 @@ void QFxBasePositioner::setSpacing(int s) return; d->_spacing = s; prePositioning(); + emit spacingChanged(); } QmlTransition *QFxBasePositioner::move() const diff --git a/src/declarative/fx/qfxpositioners.h b/src/declarative/fx/qfxpositioners.h index 89a61d7..d62da08 100644 --- a/src/declarative/fx/qfxpositioners.h +++ b/src/declarative/fx/qfxpositioners.h @@ -59,7 +59,7 @@ class Q_DECLARATIVE_EXPORT QFxBasePositioner : public QFxItem { Q_OBJECT - Q_PROPERTY(int spacing READ spacing WRITE setSpacing) + Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) Q_PROPERTY(QmlTransition *move READ move WRITE setMove) Q_PROPERTY(QmlTransition *add READ add WRITE setAdd) Q_PROPERTY(QmlTransition *remove READ remove WRITE setRemove) @@ -93,6 +93,7 @@ protected: Q_SIGNALS: void layoutItemChanged(); + void spacingChanged(); protected Q_SLOTS: virtual void doPositioning()=0; -- cgit v0.12 From 04511e3dbbcdf40489852babbf4753e0f744c26f Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 9 Oct 2009 14:25:22 +1000 Subject: Improve qdoc generated QML documentation. --- doc/src/declarative/elements.qdoc | 2 +- tools/qdoc3/config.h | 4 ++++ tools/qdoc3/cppcodemarker.cpp | 12 ++++++------ tools/qdoc3/doc.cpp | 4 ++++ tools/qdoc3/helpprojectwriter.cpp | 12 ++++++++++-- tools/qdoc3/node.cpp | 4 +++- tools/qdoc3/node.h | 2 ++ tools/qdoc3/test/qml.qdocconf | 5 ++++- 8 files changed, 34 insertions(+), 11 deletions(-) diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index cb30a6e..98c4ee1 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -40,7 +40,7 @@ ****************************************************************************/ /*! -\page elements.html +\page qmlelements.html \target elements \title QML Elements diff --git a/tools/qdoc3/config.h b/tools/qdoc3/config.h index 07cdb59..725129a 100644 --- a/tools/qdoc3/config.h +++ b/tools/qdoc3/config.h @@ -162,6 +162,10 @@ class Config #define CONFIG_FILEEXTENSIONS "fileextensions" +#ifdef QDOC_QML +#define CONFIG_QMLONLY "qmlonly" +#endif + QT_END_NAMESPACE #endif diff --git a/tools/qdoc3/cppcodemarker.cpp b/tools/qdoc3/cppcodemarker.cpp index ed3d150..1062f9c 100644 --- a/tools/qdoc3/cppcodemarker.cpp +++ b/tools/qdoc3/cppcodemarker.cpp @@ -1109,15 +1109,15 @@ QList
CppCodeMarker::qmlSections(const QmlClassNode* qmlClassNode, if (qmlClassNode) { if (style == Summary) { FastSection qmlproperties(qmlClassNode, - "QML Properties", + "Properties", "property", "properties"); FastSection qmlsignals(qmlClassNode, - "QML Signals", + "Signals", "signal", "signals"); FastSection qmlmethods(qmlClassNode, - "QML Methods", + "Methods", "method", "methods"); @@ -1146,9 +1146,9 @@ QList
CppCodeMarker::qmlSections(const QmlClassNode* qmlClassNode, append(sections,qmlmethods); } else if (style == Detailed) { - FastSection qmlproperties(qmlClassNode,"QML Property Documentation"); - FastSection qmlsignals(qmlClassNode,"QML Signal Documentation"); - FastSection qmlmethods(qmlClassNode,"QML Method Documentation"); + FastSection qmlproperties(qmlClassNode, "Property Documentation"); + FastSection qmlsignals(qmlClassNode,"Signal Documentation"); + FastSection qmlmethods(qmlClassNode,"Method Documentation"); NodeList::ConstIterator c = qmlClassNode->childNodes().begin(); while (c != qmlClassNode->childNodes().end()) { if ((*c)->subType() == Node::QmlPropertyGroup) { diff --git a/tools/qdoc3/doc.cpp b/tools/qdoc3/doc.cpp index 748390f..f4931b8 100644 --- a/tools/qdoc3/doc.cpp +++ b/tools/qdoc3/doc.cpp @@ -2841,6 +2841,10 @@ void Doc::initialize(const Config& config) DocParser::sourceDirs = config.getStringList(CONFIG_SOURCEDIRS); DocParser::quoting = config.getBool(CONFIG_QUOTINGINFORMATION); +#ifdef QDOC_QML + QmlClassNode::qmlOnly = config.getBool(CONFIG_QMLONLY); +#endif + QStringMap reverseAliasMap; QSet commands = config.subVars(CONFIG_ALIAS); diff --git a/tools/qdoc3/helpprojectwriter.cpp b/tools/qdoc3/helpprojectwriter.cpp index 4973387..52f54c0 100644 --- a/tools/qdoc3/helpprojectwriter.cpp +++ b/tools/qdoc3/helpprojectwriter.cpp @@ -187,8 +187,16 @@ QStringList HelpProjectWriter::keywordDetails(const Node *node) const details << node->parent()->name()+"::"+node->name(); } else if (node->type() == Node::Fake) { const FakeNode *fake = static_cast(node); - details << fake->fullTitle(); - details << fake->fullTitle(); +#ifdef QDOC_QML + if (fake->subType() == Node::QmlClass) { + details << (QmlClassNode::qmlOnly ? fake->name() : fake->fullTitle()); + details << "QML." + fake->name(); + } else +#endif + { + details << fake->fullTitle(); + details << fake->fullTitle(); + } } else { details << node->name(); details << node->name(); diff --git a/tools/qdoc3/node.cpp b/tools/qdoc3/node.cpp index d547d20..42b73d9 100644 --- a/tools/qdoc3/node.cpp +++ b/tools/qdoc3/node.cpp @@ -1057,6 +1057,8 @@ bool TargetNode::isInnerNode() const } #ifdef QDOC_QML +bool QmlClassNode::qmlOnly = false; + /*! Constructor for the Qml class node. */ @@ -1065,7 +1067,7 @@ QmlClassNode::QmlClassNode(InnerNode *parent, const ClassNode* cn) : FakeNode(parent, name, QmlClass), cnode(cn) { - setTitle("QML " + name + " Element Reference"); + setTitle((qmlOnly ? "" : "QML ") + name + " Element Reference"); } /*! diff --git a/tools/qdoc3/node.h b/tools/qdoc3/node.h index 09f38d2..dfe882c 100644 --- a/tools/qdoc3/node.h +++ b/tools/qdoc3/node.h @@ -364,6 +364,8 @@ class QmlClassNode : public FakeNode const ClassNode* classNode() const { return cnode; } virtual QString fileBase() const; + static bool qmlOnly; + private: const ClassNode* cnode; }; diff --git a/tools/qdoc3/test/qml.qdocconf b/tools/qdoc3/test/qml.qdocconf index 3a7d76a..3b5d8dc 100644 --- a/tools/qdoc3/test/qml.qdocconf +++ b/tools/qdoc3/test/qml.qdocconf @@ -7,6 +7,7 @@ include(qt-defines.qdocconf) project = Qml description = Qml Reference Documentation url = http://doc.qtsoftware.com/4.6 +qmlonly = true edition.Console.modules = QtCore QtDBus QtNetwork QtScript QtSql QtXml \ QtXmlPatterns QtTest @@ -72,6 +73,8 @@ HTML.postheader = "  " \ "\n" \ "
" \ "" \ - "Home" \ + "Home ·" \ + " " \ + "Elements" \ "
" -- cgit v0.12 From 0dc2fe6685323a8aa6bc0e79f908aa9f2dafe6f2 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 9 Oct 2009 14:51:40 +1000 Subject: Output file/line for script errors --- src/declarative/qml/qmlbinding.cpp | 4 +- src/declarative/qml/qmlbinding.h | 3 +- src/declarative/qml/qmlcompiler.cpp | 18 ++++++-- src/declarative/qml/qmlcontext.cpp | 20 +++------ src/declarative/qml/qmlcontext_p.h | 3 +- src/declarative/qml/qmlexpression.cpp | 48 ++++++++++++++-------- src/declarative/qml/qmlexpression.h | 4 +- src/declarative/qml/qmlexpression_p.h | 4 +- src/declarative/qml/qmlinstruction_p.h | 2 + src/declarative/qml/qmlparser_p.h | 2 + src/declarative/qml/qmlvme.cpp | 7 ++-- .../declarative/qmlecmascript/data/scriptErrors.js | 2 + .../qmlecmascript/data/scriptErrors.qml | 10 +++++ .../qmlecmascript/tst_qmlecmascript.cpp | 20 +++++++++ 14 files changed, 102 insertions(+), 45 deletions(-) create mode 100644 tests/auto/declarative/qmlecmascript/data/scriptErrors.js create mode 100644 tests/auto/declarative/qmlecmascript/data/scriptErrors.qml diff --git a/src/declarative/qml/qmlbinding.cpp b/src/declarative/qml/qmlbinding.cpp index 3a34f46..58ce02c 100644 --- a/src/declarative/qml/qmlbinding.cpp +++ b/src/declarative/qml/qmlbinding.cpp @@ -67,8 +67,8 @@ QmlBindingPrivate::QmlBindingPrivate() { } -QmlBinding::QmlBinding(void *data, QmlRefCount *rc, QObject *obj, QmlContext *ctxt, QObject *parent) -: QmlExpression(ctxt, data, rc, obj, *new QmlBindingPrivate) +QmlBinding::QmlBinding(void *data, QmlRefCount *rc, QObject *obj, QmlContext *ctxt, const QUrl &url, int lineNumber, QObject *parent) +: QmlExpression(ctxt, data, rc, obj, url, lineNumber, *new QmlBindingPrivate) { setParent(parent); } diff --git a/src/declarative/qml/qmlbinding.h b/src/declarative/qml/qmlbinding.h index e3a297c..1c0ccf1 100644 --- a/src/declarative/qml/qmlbinding.h +++ b/src/declarative/qml/qmlbinding.h @@ -90,7 +90,8 @@ class Q_DECLARATIVE_EXPORT QmlBinding : public QmlExpression, Q_OBJECT public: QmlBinding(const QString &, QObject *, QmlContext *, QObject *parent=0); - QmlBinding(void *, QmlRefCount *, QObject *, QmlContext *, QObject *parent); + QmlBinding(void *, QmlRefCount *, QObject *, QmlContext *, const QUrl &, int, + QObject *parent); ~QmlBinding(); void setTarget(const QmlMetaProperty &); diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 12e8101..5e6a8aa 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -833,6 +833,8 @@ void QmlCompiler::genObject(QmlParser::Object *obj) QmlInstruction script; script.type = QmlInstruction::StoreScript; script.line = -1; // ### + script.storeScript.fileName = output->indexForString(obj->scriptBlocksFile.at(ii)); + script.storeScript.lineNumber = obj->scriptBlocksLineNumber.at(ii); script.storeScript.value = output->indexForString(obj->scriptBlocks.at(ii)); output->bytecode << script; } @@ -1054,6 +1056,8 @@ bool QmlCompiler::buildComponent(QmlParser::Object *obj, bool QmlCompiler::buildScript(QmlParser::Object *obj, QmlParser::Object *script) { QString scriptCode; + QString sourceUrl; + int lineNumber = 1; if (script->properties.count() == 1 && script->properties.begin().key() == QByteArray("source")) { @@ -1066,8 +1070,7 @@ bool QmlCompiler::buildScript(QmlParser::Object *obj, QmlParser::Object *script) source->values.at(0)->object || !source->values.at(0)->value.isString()) COMPILE_EXCEPTION(source, "Invalid Script source value"); - QString sourceUrl = - output->url.resolved(QUrl(source->values.at(0)->value.asString())).toString(); + sourceUrl = output->url.resolved(QUrl(source->values.at(0)->value.asString())).toString(); for (int ii = 0; ii < unit->resources.count(); ++ii) { if (unit->resources.at(ii)->url == sourceUrl) { @@ -1079,10 +1082,14 @@ bool QmlCompiler::buildScript(QmlParser::Object *obj, QmlParser::Object *script) } else if (!script->properties.isEmpty()) { COMPILE_EXCEPTION(*script->properties.begin(), "Properties cannot be set on Script block"); } else if (script->defaultProperty) { + sourceUrl = output->url.toString(); + QmlParser::Location currentLocation; for (int ii = 0; ii < script->defaultProperty->values.count(); ++ii) { Value *v = script->defaultProperty->values.at(ii); + if (lineNumber == 1) + lineNumber = v->location.start.line; if (v->object || !v->value.isString()) COMPILE_EXCEPTION(v, "Invalid Script block"); @@ -1105,8 +1112,11 @@ bool QmlCompiler::buildScript(QmlParser::Object *obj, QmlParser::Object *script) } } - if (!scriptCode.isEmpty()) + if (!scriptCode.isEmpty()) { obj->scriptBlocks.append(scriptCode); + obj->scriptBlocksFile.append(sourceUrl); + obj->scriptBlocksLineNumber.append(lineNumber); + } return true; } @@ -2322,7 +2332,7 @@ void QmlCompiler::genBindingAssignment(QmlParser::Value *binding, store.assignBinding.value = output->indexForByteArray(ref.compiledData); store.assignBinding.context = ref.bindingContext.stack; store.assignBinding.owner = ref.bindingContext.owner; - store.line = prop->location.end.line; + store.line = binding->location.start.line; Q_ASSERT(ref.bindingContext.owner == 0 || (ref.bindingContext.owner != 0 && valueTypeProperty)); diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index f6795aa..3f61867 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -61,7 +61,8 @@ QmlContextPrivate::QmlContextPrivate() { } -void QmlContextPrivate::addScript(const QString &script, QObject *scopeObject) +void QmlContextPrivate::addScript(const QString &script, QObject *scopeObject, + const QString &fileName, int lineNumber) { if (!engine) return; @@ -78,21 +79,10 @@ void QmlContextPrivate::addScript(const QString &script, QObject *scopeObject) QScriptValue scope = scriptEngine->newObject(); scriptContext->setActivationObject(scope); - QScriptValue val = scriptEngine->evaluate(script); + QScriptValue val = scriptEngine->evaluate(script, fileName, lineNumber); - if (scriptEngine->hasUncaughtException()) { - if (scriptEngine->uncaughtException().isError()){ - QScriptValue exception = scriptEngine->uncaughtException(); - if (!exception.property(QLatin1String("fileName")).toString().isEmpty()){ - qWarning() << exception.property(QLatin1String("fileName")).toString() - << scriptEngine->uncaughtExceptionLineNumber() - << exception.toString(); - - } else { - qmlInfo(scopeObject) << exception.toString(); - } - } - } + if (scriptEngine->hasUncaughtException()) + QmlExpressionPrivate::printException(scriptEngine); scriptEngine->popContext(); diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h index d18bfda..fe74e28 100644 --- a/src/declarative/qml/qmlcontext_p.h +++ b/src/declarative/qml/qmlcontext_p.h @@ -94,7 +94,8 @@ public: QScriptValue scriptValue; QList scripts; - void addScript(const QString &script, QObject *scope); + void addScript(const QString &script, QObject *scope, + const QString &fileName = QString(), int lineNumber = 1); QUrl url; diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index 23e1700..6a6ef5d 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -89,8 +89,11 @@ void QmlExpressionPrivate::init(QmlContext *ctxt, const QString &expr, } void QmlExpressionPrivate::init(QmlContext *ctxt, void *expr, QmlRefCount *rc, - QObject *me) + QObject *me, const QUrl &url, int lineNumber) { + data->fileName = url.toString(); + data->line = lineNumber; + quint32 *exprData = (quint32 *)expr; Q_ASSERT(*exprData == BasicScriptEngineData || *exprData == PreTransformedQtScriptData); @@ -107,7 +110,8 @@ void QmlExpressionPrivate::init(QmlContext *ctxt, void *expr, QmlRefCount *rc, QmlEnginePrivate *ep = QmlEnginePrivate::get(engine); QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); if (!dd->programs.at(progIdx)) { - dd->programs[progIdx] = new QScriptProgram(scriptEngine->compile(data->expression)); + dd->programs[progIdx] = + new QScriptProgram(scriptEngine->compile(data->expression, data->fileName, data->line)); } QmlContextPrivate *ctxtPriv = ctxt->d_func(); @@ -145,11 +149,12 @@ QmlExpression::QmlExpression() /*! \internal */ QmlExpression::QmlExpression(QmlContext *ctxt, void *expr, QmlRefCount *rc, QObject *me, + const QUrl &url, int lineNumber, QmlExpressionPrivate &dd) : QObject(dd, 0) { Q_D(QmlExpression); - d->init(ctxt, expr, rc, me); + d->init(ctxt, expr, rc, me, url, lineNumber); } /*! @@ -251,6 +256,28 @@ QVariant QmlExpressionPrivate::evalSSE() return rv; } +void QmlExpressionPrivate::printException(QScriptEngine *scriptEngine) +{ + if (scriptEngine->hasUncaughtException() && + scriptEngine->uncaughtException().isError()) { + + QString fileName; + int lineNumber = scriptEngine->uncaughtExceptionLineNumber(); + + QScriptValue exception = scriptEngine->uncaughtException(); + QLatin1String fileNameProp("fileName"); + + if (!exception.property(fileNameProp).toString().isEmpty()){ + fileName = exception.property(fileNameProp).toString(); + } else { + fileName = QLatin1String(""); + } + + qWarning().nospace() << qPrintable(fileName) << ":" << lineNumber << ": " + << qPrintable(exception.toString()); + } +} + QVariant QmlExpressionPrivate::evalQtScript(QObject *secondaryScope) { #ifdef Q_ENABLE_PERFORMANCE_LOG @@ -291,19 +318,8 @@ QVariant QmlExpressionPrivate::evalQtScript(QObject *secondaryScope) QScriptValue svalue = data->expressionFunction.call(); - if (scriptEngine->hasUncaughtException()) { - if (scriptEngine->uncaughtException().isError()){ - QScriptValue exception = scriptEngine->uncaughtException(); - QLatin1String fileNameProp("fileName"); - if (!exception.property(fileNameProp).toString().isEmpty()){ - qWarning() << exception.property(fileNameProp).toString() - << scriptEngine->uncaughtExceptionLineNumber() - << exception.toString(); - } else { - qWarning() << exception.toString(); - } - } - } + if (scriptEngine->hasUncaughtException()) + printException(scriptEngine); if (secondaryScope) ctxtPriv->defaultObjects.removeAt(ctxtPriv->highPriorityCount); diff --git a/src/declarative/qml/qmlexpression.h b/src/declarative/qml/qmlexpression.h index c295a1c..b85e0a7 100644 --- a/src/declarative/qml/qmlexpression.h +++ b/src/declarative/qml/qmlexpression.h @@ -89,8 +89,8 @@ Q_SIGNALS: protected: QmlExpression(QmlContext *, const QString &, QObject *, QmlExpressionPrivate &dd); - QmlExpression(QmlContext *, void *, QmlRefCount *rc, QObject *me, - QmlExpressionPrivate &dd); + QmlExpression(QmlContext *, void *, QmlRefCount *rc, QObject *me, const QUrl &, + int, QmlExpressionPrivate &dd); private Q_SLOTS: void __q_notify(); diff --git a/src/declarative/qml/qmlexpression_p.h b/src/declarative/qml/qmlexpression_p.h index 33016e6..d9bb27b 100644 --- a/src/declarative/qml/qmlexpression_p.h +++ b/src/declarative/qml/qmlexpression_p.h @@ -136,7 +136,7 @@ public: }; void init(QmlContext *, const QString &, QObject *); - void init(QmlContext *, void *, QmlRefCount *, QObject *); + void init(QmlContext *, void *, QmlRefCount *, QObject *, const QUrl &, int); QmlExpressionData *data; @@ -150,6 +150,8 @@ public: static QmlExpressionPrivate *get(QmlExpression *expr) { return static_cast(QObjectPrivate::get(expr)); } + + static void printException(QScriptEngine *); }; QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlinstruction_p.h b/src/declarative/qml/qmlinstruction_p.h index 1dcdace..0da40c3 100644 --- a/src/declarative/qml/qmlinstruction_p.h +++ b/src/declarative/qml/qmlinstruction_p.h @@ -240,6 +240,8 @@ public: } storeString; struct { int value; + int fileName; + int lineNumber; } storeScript; struct { int propertyIndex; diff --git a/src/declarative/qml/qmlparser_p.h b/src/declarative/qml/qmlparser_p.h index 16862eb..d05cc73 100644 --- a/src/declarative/qml/qmlparser_p.h +++ b/src/declarative/qml/qmlparser_p.h @@ -168,6 +168,8 @@ namespace QmlParser // Script blocks that were nested under this object QStringList scriptBlocks; + QStringList scriptBlocksFile; + QList scriptBlocksLineNumber; // The bytes to cast instances by to get to the QmlParserStatus // interface. -1 indicates the type doesn't support this interface. diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index e4eef64..a057f11 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -567,7 +567,9 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, case QmlInstruction::StoreScript: { QObject *target = stack.top(); - cp->addScript(primitives.at(instr.storeScript.value), target); + cp->addScript(primitives.at(instr.storeScript.value), target, + primitives.at(instr.storeScript.fileName), + instr.storeScript.lineNumber); } break; @@ -597,12 +599,11 @@ QObject *QmlVME::run(QStack &stack, QmlContext *ctxt, if (stack.count() == 1 && bindingSkipList.testBit(coreIndex)) break; - QmlBinding *bind = new QmlBinding((void *)datas.at(instr.assignBinding.value).constData(), comp, context, ctxt, 0); + QmlBinding *bind = new QmlBinding((void *)datas.at(instr.assignBinding.value).constData(), comp, context, ctxt, comp->url, instr.line, 0); bindValues.append(bind); bind->m_mePtr = &bindValues.values[bindValues.count - 1]; bind->setTarget(mp); bind->addToObject(target); - bind->setSourceLocation(comp->url, instr.line); } break; diff --git a/tests/auto/declarative/qmlecmascript/data/scriptErrors.js b/tests/auto/declarative/qmlecmascript/data/scriptErrors.js new file mode 100644 index 0000000..1d7b357 --- /dev/null +++ b/tests/auto/declarative/qmlecmascript/data/scriptErrors.js @@ -0,0 +1,2 @@ +// Comment +a = 10 diff --git a/tests/auto/declarative/qmlecmascript/data/scriptErrors.qml b/tests/auto/declarative/qmlecmascript/data/scriptErrors.qml new file mode 100644 index 0000000..3fb8ff7 --- /dev/null +++ b/tests/auto/declarative/qmlecmascript/data/scriptErrors.qml @@ -0,0 +1,10 @@ +import Qt 4.6 + +Object { + Script { source: "scriptErrors.js" } + Script { function getValue() { a = 10; return 0; } } + + property int x: a.value + property int y: getValue(); +} + diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp index dde3bb7..673be35 100644 --- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp +++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp @@ -61,6 +61,7 @@ private slots: void objectToString(); void selfDeletingBinding(); void extendedObjectPropertyLookup(); + void scriptErrors(); private: QmlEngine engine; @@ -724,6 +725,25 @@ void tst_qmlecmascript::extendedObjectPropertyLookup() QVERIFY(object != 0); } +/* +Test file/lineNumbers for binding/Script errors. +*/ +void tst_qmlecmascript::scriptErrors() +{ + QmlComponent component(&engine, TEST_FILE("scriptErrors.qml")); + QString url = component.url().toString(); + + QString warning1 = url.left(url.length() - 3) + "js:2: Error: Invalid write to global property \"a\""; + QString warning2 = url + ":7: TypeError: Result of expression 'a' [undefined] is not an object."; + QString warning3 = url + ":5: Error: Invalid write to global property \"a\""; + + QTest::ignoreMessage(QtWarningMsg, warning1.toLatin1().constData()); + QTest::ignoreMessage(QtWarningMsg, warning2.toLatin1().constData()); + QTest::ignoreMessage(QtWarningMsg, warning3.toLatin1().constData()); + QObject *object = component.create(); + QVERIFY(object != 0); +} + QTEST_MAIN(tst_qmlecmascript) #include "tst_qmlecmascript.moc" -- cgit v0.12 From a6743af8705a93fb30e278dd634ff37597ddb627 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 9 Oct 2009 15:40:03 +1000 Subject: Remove deprecated write to signal property support --- src/declarative/qml/qmlmetaproperty.cpp | 30 +----------------------------- src/declarative/qml/qmlmetaproperty_p.h | 2 -- 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 302ce8c..a43f6c3 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -698,30 +698,6 @@ QVariant QmlMetaProperty::read() const return QVariant(); } -void QmlMetaPropertyPrivate::writeSignalProperty(const QVariant &value) -{ - QString expr = value.toString(); - const QObjectList &children = object->children(); - - for (int ii = 0; ii < children.count(); ++ii) { - QmlBoundSignal *sig = QmlBoundSignal::cast(children.at(ii)); - if (sig && sig->index() == core.coreIndex) { - if (expr.isEmpty()) { - sig->disconnect(); - sig->deleteLater(); - } else { - sig->expression()->setExpression(expr); - } - return; - } - } - - if (!expr.isEmpty()) { - // XXX scope - (void *)new QmlBoundSignal(qmlContext(object), expr, object, q->method(), object); - } -} - QVariant QmlMetaPropertyPrivate::readValueProperty() { uint type = q->type(); @@ -963,11 +939,7 @@ void QmlMetaProperty::write(const QVariant &value, WriteSource source) const if (!d->object) return; - if (type() & SignalProperty) { - - d->writeSignalProperty(value); - - } else if (d->core.isValid()) { + if (type() & Property && d->core.isValid()) { d->writeValueProperty(value, source); diff --git a/src/declarative/qml/qmlmetaproperty_p.h b/src/declarative/qml/qmlmetaproperty_p.h index 00b9c3a..4576b71 100644 --- a/src/declarative/qml/qmlmetaproperty_p.h +++ b/src/declarative/qml/qmlmetaproperty_p.h @@ -96,8 +96,6 @@ public: int propertyType() const; QmlMetaProperty::PropertyCategory propertyCategory() const; - void writeSignalProperty(const QVariant &); - QVariant readValueProperty(); void writeValueProperty(const QVariant &, QmlMetaProperty::WriteSource); static void write(QObject *, const QmlPropertyCache::Data &, const QVariant &, QmlContext *); -- cgit v0.12 From 89a5a33d5643eb31bb44adce8a8fd65986d76c20 Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Fri, 9 Oct 2009 15:56:36 +1000 Subject: Fixes yahoonews.qml Task-number: QT-2281 --- examples/declarative/xmldata/yahoonews.qml | 146 ++++++++++++----------------- 1 file changed, 60 insertions(+), 86 deletions(-) diff --git a/examples/declarative/xmldata/yahoonews.qml b/examples/declarative/xmldata/yahoonews.qml index 6d43f46..7d8b8a2 100644 --- a/examples/declarative/xmldata/yahoonews.qml +++ b/examples/declarative/xmldata/yahoonews.qml @@ -5,100 +5,74 @@ Rectangle { GradientStop { position: 0; color: "black" } GradientStop { position: 1.0; color: "#AAAAAA" } } - width: 600 - height: 600 - resources: [ - XmlListModel { - id: feedModel - source: "http://rss.news.yahoo.com/rss/oceania" - query: "/rss/channel/item" - XmlRole { - name: "title" - query: "title/string()" - } - XmlRole { - name: "link" - query: "link/string()" - } - XmlRole { - name: "description" - query: "description/string()" + width: 600; height: 600 + + XmlListModel { + id: feedModel + source: "http://rss.news.yahoo.com/rss/oceania" + query: "/rss/channel/item" + XmlRole { name: "title"; query: "title/string()" } + XmlRole { name: "link"; query: "link/string()" } + XmlRole { name: "description"; query: "description/string()" } + } + + Component { + id: feedDelegate + Item { + id: delegate + height: wrapper.height + 10 + + MouseRegion { + anchors.fill: wrapper + onPressed: delegate.ListView.view.currentIndex = index; + onClicked: if (wrapper.state == 'Details') wrapper.state = ''; else wrapper.state = 'Details'; } - }, - Component { - id: feedDelegate - Item { - id: delegate - height: wrapper.height + 10 - MouseRegion { - anchors.fill: wrapper - onPressed: { delegate.ListView.view.currentIndex = index; } - onClicked: { if (wrapper.state == 'Details') { wrapper.state = '';} else {wrapper.state = 'Details';} } + + Rectangle { + id: wrapper + y: 5; height: titleText.height + 10; width: 580 + color: "#F0F0F0"; radius: 5 + Text { + id: titleText + x: 10; y: 5 + text: '' + title + '' + font.bold: true; font.family: "Helvetica"; font.pointSize: 14 + onLinkActivated: { print('link clicked: ' + link) } } - Rectangle { - id: wrapper - y: 5 - height: titleText.height + 10 - width: 580 - color: "#F0F0F0" - radius: 5 - Text { - x: 10 - y: 5 - id: titleText - text: '' + title + '' - font.bold: true - font.family: "Helvetica" - font.pointSize: 14 - onLinkActivated: { print('link clicked: ' + link) } - } - Text { - x: 10 - id: description - text: description - width: 560 - wrap: true - font.family: "Helvetica" - anchors.top: titleText.bottom - anchors.topMargin: 5 - opacity: 0 + + Text { + x: 10 + id: descriptionText + text: description + width: 560 + wrap: true + font.family: "Helvetica" + anchors.top: titleText.bottom + anchors.topMargin: 5 + opacity: 0 + } + + states: State { + name: "Details" + PropertyChanges { target: wrapper; height: childrenRect.height + 10 } + PropertyChanges { target: descriptionText; opacity: 1 } + } + + transitions: Transition { + from: "*"; to: "Details"; reversible: true + SequentialAnimation { + NumberAnimation { duration: 200; properties: "height"; easing: "easeOutQuad" } + NumberAnimation { duration: 200; properties: "opacity" } } - states: [ - State { - name: "Details" - PropertyChanges { target: wrapper; height: childrenRect.height + 10 } - PropertyChanges { target: description; opacity: 1 } - } - ] - transitions: [ - Transition { - from: "*" - to: "Details" - reversible: true -