summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrans Englich <frans.englich@nokia.com>2009-06-29 15:17:51 (GMT)
committerFrans Englich <frans.englich@nokia.com>2009-06-29 16:25:51 (GMT)
commit1414c682c532a95a2204bc1b2d01d2493357b686 (patch)
tree3b4312d7d45eb609f5d7a1440d3211906fa24faa
parent555c481145ff87347c0f0be12f81632c9b5ef0be (diff)
downloadQt-1414c682c532a95a2204bc1b2d01d2493357b686.zip
Qt-1414c682c532a95a2204bc1b2d01d2493357b686.tar.gz
Qt-1414c682c532a95a2204bc1b2d01d2493357b686.tar.bz2
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.
-rw-r--r--dist/changes-4.6.03
-rw-r--r--src/xmlpatterns/api/qxmlquery.cpp19
-rw-r--r--src/xmlpatterns/api/qxmlquery.h1
-rw-r--r--tests/auto/qxmlquery/tst_qxmlquery.cpp52
4 files changed, 74 insertions, 1 deletions
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("<e>textNode</e>")));
+ 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("<e>newFocus</e>")));
+ 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("<notWellformed")));
+
+ /* Let's try the slight special case of a null string. */
+ QVERIFY(!query.setFocus(QString()));
+}
+
+void tst_QXmlQuery::setFocusQStringSignature() const
+{
+ QXmlQuery query;
+ MessageSilencer silencer;
+ query.setMessageHandler(&silencer);
+
+ const QString argument;
+ /* We should take a const ref. */
+ query.setFocus(argument);
+
+ /* We should return a bool. */
+ static_cast<bool>(query.setFocus(QString()));
+}
+
void tst_QXmlQuery::setFocusQIODeviceTriggerWarnings() const
{
/* A null pointer. */