From 1414c682c532a95a2204bc1b2d01d2493357b686 Mon Sep 17 00:00:00 2001 From: Frans Englich Date: Mon, 29 Jun 2009 17:17:51 +0200 Subject: QXmlQuery: add setFocus(const QString &). Requested by Girish and Jurgen. Useful for training and small examples. Task-number: 245219 Reviewed-by: Tobias Koenig AutoTest: Included in this submit. --- dist/changes-4.6.0 | 3 +- src/xmlpatterns/api/qxmlquery.cpp | 19 +++++++++++++ src/xmlpatterns/api/qxmlquery.h | 1 + tests/auto/qxmlquery/tst_qxmlquery.cpp | 52 ++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/dist/changes-4.6.0 b/dist/changes-4.6.0 index 661fc3e..4c7bf52 100644 --- a/dist/changes-4.6.0 +++ b/dist/changes-4.6.0 @@ -25,12 +25,13 @@ information about a particular change. * Library * **************************************************************************** + * [245219] Added QXmlQuery::setFocus(const QString &focus); **************************************************************************** * Platform Specific Changes * **************************************************************************** - + **************************************************************************** * Important Behavior Changes * diff --git a/src/xmlpatterns/api/qxmlquery.cpp b/src/xmlpatterns/api/qxmlquery.cpp index 2513725..3d023a0 100644 --- a/src/xmlpatterns/api/qxmlquery.cpp +++ b/src/xmlpatterns/api/qxmlquery.cpp @@ -1039,6 +1039,25 @@ bool QXmlQuery::setFocus(QIODevice *document) } /*! + This function behaves identically to calling the setFocus() overload with a + QIODevice whose content is \a focus encoded as UTF-8. That is, \a focus is + treated as if it contained an XML document. + + Returns the same result as the overload. + + \overload + \since 4.6 + */ +bool QXmlQuery::setFocus(const QString &focus) +{ + QBuffer device; + device.setData(focus.toUtf8()); + device.open(QIODevice::ReadOnly); + + return setFocusHelper(this, &device); +} + +/*! Returns a value indicating what this QXmlQuery is being used for. The default is QXmlQuery::XQuery10, which means the QXmlQuery is being used for running XQuery and XPath queries. QXmlQuery::XSLT20 diff --git a/src/xmlpatterns/api/qxmlquery.h b/src/xmlpatterns/api/qxmlquery.h index 28ef5cb..4ddfc76 100644 --- a/src/xmlpatterns/api/qxmlquery.h +++ b/src/xmlpatterns/api/qxmlquery.h @@ -122,6 +122,7 @@ public: void setFocus(const QXmlItem &item); bool setFocus(const QUrl &documentURI); bool setFocus(QIODevice *document); + bool setFocus(const QString &focus); void setInitialTemplateName(const QXmlName &name); void setInitialTemplateName(const QString &name); diff --git a/tests/auto/qxmlquery/tst_qxmlquery.cpp b/tests/auto/qxmlquery/tst_qxmlquery.cpp index 28af641..30b3f50 100644 --- a/tests/auto/qxmlquery/tst_qxmlquery.cpp +++ b/tests/auto/qxmlquery/tst_qxmlquery.cpp @@ -155,6 +155,9 @@ private Q_SLOTS: void setFocusQIODeviceAvoidVariableClash() const; void setFocusQIODeviceFailure() const; void setFocusQIODeviceTriggerWarnings() const; + void setFocusQString() const; + void setFocusQStringFailure() const; + void setFocusQStringSignature() const; void recompilationWithEvaluateToResultFailing() const; void secondEvaluationWithEvaluateToResultFailing() const; void recompilationWithEvaluateToReceiver() const; @@ -1894,6 +1897,55 @@ void tst_QXmlQuery::setFocusQIODeviceFailure() const } } +void tst_QXmlQuery::setFocusQString() const +{ + QXmlQuery query; + + /* Basic use of focus. */ + { + QVERIFY(query.setFocus(QLatin1String("textNode"))); + query.setQuery(QLatin1String("string()")); + QVERIFY(query.isValid()); + QString out; + query.evaluateTo(&out); + QCOMPARE(out, QString::fromLatin1("textNode\n")); + } + + /* Set to a new focus, make sure it changes and works. */ + { + QVERIFY(query.setFocus(QLatin1String("newFocus"))); + QString out; + query.evaluateTo(&out); + QCOMPARE(out, QString::fromLatin1("newFocus\n")); + } +} + +void tst_QXmlQuery::setFocusQStringFailure() const +{ + QXmlQuery query; + MessageSilencer silencer; + + query.setMessageHandler(&silencer); + QVERIFY(!query.setFocus(QLatin1String("(query.setFocus(QString())); +} + void tst_QXmlQuery::setFocusQIODeviceTriggerWarnings() const { /* A null pointer. */ -- cgit v0.12