From 54e9fdb0ddf673b3c8ee9a5ffce561114db2329c Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 21 May 2010 12:48:32 +1000 Subject: Also show file/line numbers on XML query errors. Task-number: QTBUG-10797 Reviewed-by: Bea Lam --- src/declarative/util/qdeclarativexmllistmodel.cpp | 20 +++++++++++++++++++- src/declarative/util/qdeclarativexmllistmodel_p.h | 1 + .../tst_qdeclarativexmllistmodel.cpp | 2 +- 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 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(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; iroleObjects.count(); i++) { + if (d->roleObjects.at(i) == static_cast(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(component.create()); -- cgit v0.12