diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-05-21 02:48:32 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-05-21 02:49:25 (GMT) |
commit | 54e9fdb0ddf673b3c8ee9a5ffce561114db2329c (patch) | |
tree | 0f0f7851cf3f9ed154898dd0f1ba733690bf4039 | |
parent | 58e154ec33ec1b1aea70fa35a1c5c692fe035df2 (diff) | |
download | Qt-54e9fdb0ddf673b3c8ee9a5ffce561114db2329c.zip Qt-54e9fdb0ddf673b3c8ee9a5ffce561114db2329c.tar.gz Qt-54e9fdb0ddf673b3c8ee9a5ffce561114db2329c.tar.bz2 |
Also show file/line numbers on XML query errors.
Task-number: QTBUG-10797
Reviewed-by: Bea Lam
3 files changed, 21 insertions, 2 deletions
diff --git a/src/declarative/util/qdeclarativexmllistmodel.cpp b/src/declarative/util/qdeclarativexmllistmodel.cpp index 062e30e..9b8b26c 100644 --- a/src/declarative/util/qdeclarativexmllistmodel.cpp +++ b/src/declarative/util/qdeclarativexmllistmodel.cpp @@ -124,6 +124,7 @@ struct XmlQueryJob QString query; QString namespaces; QStringList roleQueries; + QList<void*> roleQueryErrorId; // the ptr to send back if there is an error QStringList keyRoleQueries; QStringList keyRoleResultsCache; }; @@ -167,6 +168,7 @@ public: continue; } job.roleQueries << roleObjects->at(i)->query(); + job.roleQueryErrorId << static_cast<void*>(roleObjects->at(i)); if (roleObjects->at(i)->isKey()) job.keyRoleQueries << job.roleQueries.last(); } @@ -182,6 +184,7 @@ public: Q_SIGNALS: void queryCompleted(const QDeclarativeXmlQueryResult &); + void error(void*, const QString&); protected: void run() { @@ -363,7 +366,7 @@ void QDeclarativeXmlQuery::doSubQueryJob() item = resultItems.next(); } } else { - qWarning().nospace() << "XmlListModel: invalid query: " << queries[i]; + emit error(job.roleQueryErrorId.at(i), queries[i]); } } //### should warn here if things have gone wrong. @@ -565,6 +568,8 @@ QDeclarativeXmlListModel::QDeclarativeXmlListModel(QObject *parent) { connect(globalXmlQuery(), SIGNAL(queryCompleted(QDeclarativeXmlQueryResult)), this, SLOT(queryCompleted(QDeclarativeXmlQueryResult))); + connect(globalXmlQuery(), SIGNAL(error(void*,QString)), + this, SLOT(queryError(void*,QString))); } QDeclarativeXmlListModel::~QDeclarativeXmlListModel() @@ -959,6 +964,19 @@ void QDeclarativeXmlListModel::dataCleared() queryCompleted(r); } +void QDeclarativeXmlListModel::queryError(void* object, const QString& error) +{ + // Be extra careful, object may no longer exist, it's just an ID. + Q_D(QDeclarativeXmlListModel); + for (int i=0; i<d->roleObjects.count(); i++) { + if (d->roleObjects.at(i) == static_cast<QDeclarativeXmlListModelRole*>(object)) { + qmlInfo(d->roleObjects.at(i)) << QObject::tr("invalid query: \"%1\"").arg(error); + return; + } + } + qmlInfo(this) << QObject::tr("invalid query: \"%1\"").arg(error); +} + void QDeclarativeXmlListModel::queryCompleted(const QDeclarativeXmlQueryResult &result) { Q_D(QDeclarativeXmlListModel); diff --git a/src/declarative/util/qdeclarativexmllistmodel_p.h b/src/declarative/util/qdeclarativexmllistmodel_p.h index 4460f24..8d848c8 100644 --- a/src/declarative/util/qdeclarativexmllistmodel_p.h +++ b/src/declarative/util/qdeclarativexmllistmodel_p.h @@ -142,6 +142,7 @@ private Q_SLOTS: void requestProgress(qint64,qint64); void dataCleared(); void queryCompleted(const QDeclarativeXmlQueryResult &); + void queryError(void* object, const QString& error); private: Q_DECLARE_PRIVATE(QDeclarativeXmlListModel) diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp index 464f9e0..35790e4 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp +++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp @@ -224,7 +224,7 @@ void tst_qdeclarativexmllistmodel::roleErrors() { QDeclarativeComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/roleErrors.qml")); QTest::ignoreMessage(QtWarningMsg, (QUrl::fromLocalFile(SRCDIR "/data/roleErrors.qml").toString() + ":6:5: QML XmlRole: An XmlRole query must not start with '/'").toUtf8().constData()); - QTest::ignoreMessage(QtWarningMsg, "XmlListModel: invalid query: \"age/\""); + QTest::ignoreMessage(QtWarningMsg, (QUrl::fromLocalFile(SRCDIR "/data/roleErrors.qml").toString() + ":9:5: QML XmlRole: invalid query: \"age/\"").toUtf8().constData()); //### make sure we receive all expected warning messages. QDeclarativeXmlListModel *model = qobject_cast<QDeclarativeXmlListModel*>(component.create()); |