summaryrefslogtreecommitdiffstats
path: root/examples/xmlpatterns
diff options
context:
space:
mode:
authoraxis <qt-info@nokia.com>2009-04-24 11:34:15 (GMT)
committeraxis <qt-info@nokia.com>2009-04-24 11:34:15 (GMT)
commit8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76 (patch)
treea17e1a767a89542ab59907462206d7dcf2e504b2 /examples/xmlpatterns
downloadQt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.zip
Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.tar.gz
Qt-8f427b2b914d5b575a4a7c0ed65d2fb8f45acc76.tar.bz2
Long live Qt for S60!
Diffstat (limited to 'examples/xmlpatterns')
-rw-r--r--examples/xmlpatterns/README38
-rw-r--r--examples/xmlpatterns/filetree/filetree.cpp372
-rw-r--r--examples/xmlpatterns/filetree/filetree.h103
-rw-r--r--examples/xmlpatterns/filetree/filetree.pro15
-rw-r--r--examples/xmlpatterns/filetree/forms/mainwindow.ui200
-rw-r--r--examples/xmlpatterns/filetree/main.cpp54
-rw-r--r--examples/xmlpatterns/filetree/mainwindow.cpp166
-rw-r--r--examples/xmlpatterns/filetree/mainwindow.h73
-rw-r--r--examples/xmlpatterns/filetree/queries.qrc7
-rw-r--r--examples/xmlpatterns/filetree/queries/listCPPFiles.xq19
-rw-r--r--examples/xmlpatterns/filetree/queries/wholeTree.xq1
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/forms/mainwindow.ui196
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/main.cpp53
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/mainwindow.cpp135
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/mainwindow.h64
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.cpp459
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.h139
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.pro13
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/queries.qrc7
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/queries/statisticsInHTML.xq58
-rw-r--r--examples/xmlpatterns/qobjectxmlmodel/queries/wholeTree.xq3
-rw-r--r--examples/xmlpatterns/recipes/files/allRecipes.xq4
-rw-r--r--examples/xmlpatterns/recipes/files/cookbook.xml62
-rw-r--r--examples/xmlpatterns/recipes/files/liquidIngredientsInSoup.xq5
-rw-r--r--examples/xmlpatterns/recipes/files/mushroomSoup.xq5
-rw-r--r--examples/xmlpatterns/recipes/files/preparationLessThan30.xq9
-rw-r--r--examples/xmlpatterns/recipes/files/preparationTimes.xq5
-rw-r--r--examples/xmlpatterns/recipes/forms/querywidget.ui151
-rw-r--r--examples/xmlpatterns/recipes/main.cpp54
-rw-r--r--examples/xmlpatterns/recipes/querymainwindow.cpp124
-rw-r--r--examples/xmlpatterns/recipes/querymainwindow.h72
-rw-r--r--examples/xmlpatterns/recipes/recipes.pro13
-rw-r--r--examples/xmlpatterns/recipes/recipes.qrc11
-rw-r--r--examples/xmlpatterns/shared/xmlsyntaxhighlighter.cpp106
-rw-r--r--examples/xmlpatterns/shared/xmlsyntaxhighlighter.h72
-rw-r--r--examples/xmlpatterns/trafficinfo/main.cpp54
-rw-r--r--examples/xmlpatterns/trafficinfo/mainwindow.cpp181
-rw-r--r--examples/xmlpatterns/trafficinfo/mainwindow.h77
-rw-r--r--examples/xmlpatterns/trafficinfo/station_example.wml31
-rw-r--r--examples/xmlpatterns/trafficinfo/stationdialog.cpp164
-rw-r--r--examples/xmlpatterns/trafficinfo/stationdialog.h70
-rw-r--r--examples/xmlpatterns/trafficinfo/stationdialog.ui104
-rw-r--r--examples/xmlpatterns/trafficinfo/stationquery.cpp94
-rw-r--r--examples/xmlpatterns/trafficinfo/stationquery.h74
-rw-r--r--examples/xmlpatterns/trafficinfo/time_example.wml56
-rw-r--r--examples/xmlpatterns/trafficinfo/timequery.cpp116
-rw-r--r--examples/xmlpatterns/trafficinfo/timequery.h74
-rw-r--r--examples/xmlpatterns/trafficinfo/trafficinfo.pro9
-rw-r--r--examples/xmlpatterns/xmlpatterns.pro16
-rw-r--r--examples/xmlpatterns/xquery/globalVariables/globalVariables.pro11
-rw-r--r--examples/xmlpatterns/xquery/globalVariables/globals.cpp67
-rw-r--r--examples/xmlpatterns/xquery/globalVariables/globals.gccxml33
-rw-r--r--examples/xmlpatterns/xquery/globalVariables/globals.html40
-rw-r--r--examples/xmlpatterns/xquery/globalVariables/reportGlobals.xq110
-rw-r--r--examples/xmlpatterns/xquery/xquery.pro10
55 files changed, 4259 insertions, 0 deletions
diff --git a/examples/xmlpatterns/README b/examples/xmlpatterns/README
new file mode 100644
index 0000000..5d585dc
--- /dev/null
+++ b/examples/xmlpatterns/README
@@ -0,0 +1,38 @@
+XQuery queries and XPath expressions can be used in Qt with the
+QtXmlPatterns module.
+
+XQuery is a query language used to query XML in a concise and safe manner.
+
+The example launcher provided with Qt can be used to explore each of the
+examples in this directory.
+
+Documentation for these examples can be found via the Tutorial and Examples
+link in the main Qt documentation.
+
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/xmlpatterns/filetree/filetree.cpp b/examples/xmlpatterns/filetree/filetree.cpp
new file mode 100644
index 0000000..6695a96
--- /dev/null
+++ b/examples/xmlpatterns/filetree/filetree.cpp
@@ -0,0 +1,372 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QUrl>
+#include <QtCore/QVariant>
+#include <QtXmlPatterns/QXmlNamePool>
+#include "filetree.h"
+
+/*
+The model has two types of nodes: elements & attributes.
+
+ <directory name="">
+ <file name="">
+ </file>
+ </directory>
+
+ In QXmlNodeModelIndex we store two values. QXmlNodeIndex::data()
+ is treated as a signed int, and it is an index into m_fileInfos
+ unless it is -1, in which case it has no meaning and the value
+ of QXmlNodeModelIndex::additionalData() is a Type name instead.
+ */
+
+/*!
+ The constructor passes \a pool to the base class, then loads an
+ internal vector with an instance of QXmlName for each of the
+ strings "file", "directory", "fileName", "filePath", "size",
+ "mimeType", and "suffix".
+ */
+//! [2]
+FileTree::FileTree(const QXmlNamePool& pool)
+ : QSimpleXmlNodeModel(pool),
+ m_filterAllowAll(QDir::AllEntries |
+ QDir::AllDirs |
+ QDir::NoDotAndDotDot |
+ QDir::Hidden),
+ m_sortFlags(QDir::Name)
+{
+ QXmlNamePool np = namePool();
+ m_names.resize(7);
+ m_names[File] = QXmlName(np, QLatin1String("file"));
+ m_names[Directory] = QXmlName(np, QLatin1String("directory"));
+ m_names[AttributeFileName] = QXmlName(np, QLatin1String("fileName"));
+ m_names[AttributeFilePath] = QXmlName(np, QLatin1String("filePath"));
+ m_names[AttributeSize] = QXmlName(np, QLatin1String("size"));
+ m_names[AttributeMIMEType] = QXmlName(np, QLatin1String("mimeType"));
+ m_names[AttributeSuffix] = QXmlName(np, QLatin1String("suffix"));
+}
+//! [2]
+
+/*!
+ Returns the QXmlNodeModelIndex for the model node representing
+ the directory \a dirName.
+
+ It calls QDir::cleanPath(), because an instance of QFileInfo
+ constructed for a path ending in '/' will return the empty string in
+ fileName(), instead of the directory name.
+*/
+QXmlNodeModelIndex FileTree::nodeFor(const QString& dirName) const
+{
+ QFileInfo dirInfo(QDir::cleanPath(dirName));
+ Q_ASSERT(dirInfo.exists());
+ return toNodeIndex(dirInfo);
+}
+
+/*!
+ Since the value will always be in m_fileInfos, it is safe for
+ us to return a const reference to it.
+ */
+//! [6]
+const QFileInfo&
+FileTree::toFileInfo(const QXmlNodeModelIndex &nodeIndex) const
+{
+ return m_fileInfos.at(nodeIndex.data());
+}
+//! [6]
+
+/*!
+ Returns the model node index for the node specified by the
+ QFileInfo and node Type.
+ */
+//! [1]
+QXmlNodeModelIndex
+FileTree::toNodeIndex(const QFileInfo &fileInfo, Type attributeName) const
+{
+ const int indexOf = m_fileInfos.indexOf(fileInfo);
+
+ if (indexOf == -1) {
+ m_fileInfos.append(fileInfo);
+ return createIndex(m_fileInfos.count()-1, attributeName);
+ }
+ else
+ return createIndex(indexOf, attributeName);
+}
+//! [1]
+
+/*!
+ Returns the model node index for the node specified by the
+ QFileInfo, which must be a Type::File or Type::Directory.
+ */
+//! [0]
+QXmlNodeModelIndex FileTree::toNodeIndex(const QFileInfo &fileInfo) const
+{
+ return toNodeIndex(fileInfo, fileInfo.isDir() ? Directory : File);
+}
+//! [0]
+
+/*!
+ This private helper function is only called by nextFromSimpleAxis().
+ It is called whenever nextFromSimpleAxis() is called with an axis
+ parameter of either \c{PreviousSibling} or \c{NextSibling}.
+ */
+//! [5]
+QXmlNodeModelIndex FileTree::nextSibling(const QXmlNodeModelIndex &nodeIndex,
+ const QFileInfo &fileInfo,
+ qint8 offset) const
+{
+ Q_ASSERT(offset == -1 || offset == 1);
+
+ // Get the context node's parent.
+ const QXmlNodeModelIndex parent(nextFromSimpleAxis(Parent, nodeIndex));
+
+ if (parent.isNull())
+ return QXmlNodeModelIndex();
+
+ // Get the parent's child list.
+ const QFileInfo parentFI(toFileInfo(parent));
+ Q_ASSERT(Type(parent.additionalData()) == Directory);
+ const QFileInfoList siblings(QDir(parentFI.absoluteFilePath()).entryInfoList(QStringList(),
+ m_filterAllowAll,
+ m_sortFlags));
+ Q_ASSERT_X(!siblings.isEmpty(), Q_FUNC_INFO, "Can't happen! We started at a child.");
+
+ // Find the index of the child where we started.
+ const int indexOfMe = siblings.indexOf(fileInfo);
+
+ // Apply the offset.
+ const int siblingIndex = indexOfMe + offset;
+ if (siblingIndex < 0 || siblingIndex > siblings.count() - 1)
+ return QXmlNodeModelIndex();
+ else
+ return toNodeIndex(siblings.at(siblingIndex));
+}
+//! [5]
+
+/*!
+ This function is called by the QtXmlPatterns query engine when it
+ wants to move to the next node in the model. It moves along an \a
+ axis, \e from the node specified by \a nodeIndex.
+
+ This function is usually the one that requires the most design and
+ implementation work, because the implementation depends on the
+ perhaps unique structure of your non-XML data.
+
+ There are \l {QAbstractXmlNodeModel::SimpleAxis} {four values} for
+ \a axis that the implementation must handle, but there are really
+ only two axes, i.e., vertical and horizontal. Two of the four values
+ specify direction on the vertical axis (\c{Parent} and
+ \c{FirstChild}), and the other two values specify direction on the
+ horizontal axis (\c{PreviousSibling} and \c{NextSibling}).
+
+ The typical implementation will be a \c switch statement with
+ a case for each of the four \a axis values.
+ */
+//! [4]
+QXmlNodeModelIndex
+FileTree::nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &nodeIndex) const
+{
+ const QFileInfo fi(toFileInfo(nodeIndex));
+ const Type type = Type(nodeIndex.additionalData());
+
+ if (type != File && type != Directory) {
+ Q_ASSERT_X(axis == Parent, Q_FUNC_INFO, "An attribute only has a parent!");
+ return toNodeIndex(fi, Directory);
+ }
+
+ switch (axis) {
+ case Parent:
+ return toNodeIndex(QFileInfo(fi.path()), Directory);
+
+ case FirstChild:
+ {
+ if (type == File) // A file has no children.
+ return QXmlNodeModelIndex();
+ else {
+ Q_ASSERT(type == Directory);
+ Q_ASSERT_X(fi.isDir(), Q_FUNC_INFO, "It isn't really a directory!");
+ const QDir dir(fi.absoluteFilePath());
+ Q_ASSERT(dir.exists());
+
+ const QFileInfoList children(dir.entryInfoList(QStringList(),
+ m_filterAllowAll,
+ m_sortFlags));
+ if (children.isEmpty())
+ return QXmlNodeModelIndex();
+ const QFileInfo firstChild(children.first());
+ return toNodeIndex(firstChild);
+ }
+ }
+
+ case PreviousSibling:
+ return nextSibling(nodeIndex, fi, -1);
+
+ case NextSibling:
+ return nextSibling(nodeIndex, fi, 1);
+ }
+
+ Q_ASSERT_X(false, Q_FUNC_INFO, "Don't ever get here!");
+ return QXmlNodeModelIndex();
+}
+//! [4]
+
+/*!
+ No matter what part of the file system we model (the whole file
+ tree or a subtree), \a node will always have \c{file:///} as
+ the document URI.
+ */
+QUrl FileTree::documentUri(const QXmlNodeModelIndex &node) const
+{
+ Q_UNUSED(node);
+ return QUrl("file:///");
+}
+
+/*!
+ This function returns QXmlNodeModelIndex::Element if \a node
+ is a directory or a file, and QXmlNodeModelIndex::Attribute
+ otherwise.
+ */
+QXmlNodeModelIndex::NodeKind
+FileTree::kind(const QXmlNodeModelIndex &node) const
+{
+ switch (Type(node.additionalData())) {
+ case Directory:
+ case File:
+ return QXmlNodeModelIndex::Element;
+ default:
+ return QXmlNodeModelIndex::Attribute;
+ }
+}
+
+/*!
+ No order is defined for this example, so we always return
+ QXmlNodeModelIndex::Precedes, just to keep everyone happy.
+ */
+QXmlNodeModelIndex::DocumentOrder
+FileTree::compareOrder(const QXmlNodeModelIndex&,
+ const QXmlNodeModelIndex&) const
+{
+ return QXmlNodeModelIndex::Precedes;
+}
+
+/*!
+ Returns the name of \a node. The caller guarantees that \a node is
+ not null and that it is contained in this node model.
+ */
+//! [3]
+QXmlName FileTree::name(const QXmlNodeModelIndex &node) const
+{
+ return m_names.at(node.additionalData());
+}
+//! [3]
+
+/*!
+ Always returns the QXmlNodeModelIndex for the root of the
+ file system, i.e. "/".
+ */
+QXmlNodeModelIndex FileTree::root(const QXmlNodeModelIndex &node) const
+{
+ Q_UNUSED(node);
+ return toNodeIndex(QFileInfo(QLatin1String("/")));
+}
+
+/*!
+ Returns the typed value for \a node, which must be either an
+ attribute or an element. The QVariant returned represents the atomic
+ value of an attribute or the atomic value contained in an element.
+
+ If the QVariant is returned as a default constructed variant,
+ it means that \a node has no typed value.
+ */
+QVariant FileTree::typedValue(const QXmlNodeModelIndex &node) const
+{
+ const QFileInfo &fi = toFileInfo(node);
+
+ switch (Type(node.additionalData())) {
+ case Directory:
+ // deliberate fall through.
+ case File:
+ return QString();
+ case AttributeFileName:
+ return fi.fileName();
+ case AttributeFilePath:
+ return fi.filePath();
+ case AttributeSize:
+ return fi.size();
+ case AttributeMIMEType:
+ {
+ /* We don't have any MIME detection code currently, so return
+ * the most generic one. */
+ return QLatin1String("application/octet-stream");
+ }
+ case AttributeSuffix:
+ return fi.suffix();
+ }
+
+ Q_ASSERT_X(false, Q_FUNC_INFO, "This line should never be reached.");
+ return QString();
+}
+
+/*!
+ Returns the attributes of \a element. The caller guarantees
+ that \a element is an element in this node model.
+ */
+QVector<QXmlNodeModelIndex>
+FileTree::attributes(const QXmlNodeModelIndex &element) const
+{
+ QVector<QXmlNodeModelIndex> result;
+
+ /* Both elements has this attribute. */
+ const QFileInfo &forElement = toFileInfo(element);
+ result.append(toNodeIndex(forElement, AttributeFilePath));
+ result.append(toNodeIndex(forElement, AttributeFileName));
+
+ if (Type(element.additionalData() == File)) {
+ result.append(toNodeIndex(forElement, AttributeSize));
+ result.append(toNodeIndex(forElement, AttributeSuffix));
+ //result.append(toNodeIndex(forElement, AttributeMIMEType));
+ }
+ else {
+ Q_ASSERT(element.additionalData() == Directory);
+ }
+
+ return result;
+}
+
diff --git a/examples/xmlpatterns/filetree/filetree.h b/examples/xmlpatterns/filetree/filetree.h
new file mode 100644
index 0000000..7c8f3ca
--- /dev/null
+++ b/examples/xmlpatterns/filetree/filetree.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QFileInfo>
+#include <QtCore/QDir>
+#include <QtCore/QVector>
+#include <QtXmlPatterns/QSimpleXmlNodeModel>
+
+class FileTree : public QSimpleXmlNodeModel
+{
+ public:
+ FileTree(const QXmlNamePool &namePool);
+
+ QXmlNodeModelIndex nodeFor(const QString &fileName) const;
+
+ //! [0]
+ virtual QXmlNodeModelIndex::DocumentOrder compareOrder(const QXmlNodeModelIndex&, const QXmlNodeModelIndex&) const;
+ virtual QXmlName name(const QXmlNodeModelIndex &node) const;
+ virtual QUrl documentUri(const QXmlNodeModelIndex &node) const;
+ virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &node) const;
+ virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &node) const;
+ virtual QVariant typedValue(const QXmlNodeModelIndex &node) const;
+ //! [0]
+ protected:
+ //! [1]
+ virtual QVector<QXmlNodeModelIndex> attributes(const QXmlNodeModelIndex &element) const;
+ virtual QXmlNodeModelIndex nextFromSimpleAxis(SimpleAxis, const QXmlNodeModelIndex&) const;
+ //! [1]
+
+ private:
+ //! [4]
+ enum Type {
+ File,
+ Directory,
+ AttributeFileName,
+ AttributeFilePath,
+ AttributeSize,
+ AttributeMIMEType,
+ AttributeSuffix
+ };
+ //! [4]
+
+ inline QXmlNodeModelIndex nextSibling(const QXmlNodeModelIndex &nodeIndex,
+ const QFileInfo &from,
+ qint8 offset) const;
+ inline const QFileInfo &toFileInfo(const QXmlNodeModelIndex &index) const;
+ inline QXmlNodeModelIndex toNodeIndex(const QFileInfo &index,
+ Type attributeName) const;
+ inline QXmlNodeModelIndex toNodeIndex(const QFileInfo &index) const;
+
+ /*
+ One possible improvement is to use a hash, and use the &*&value()
+ trick to get a pointer, which would be stored in data() instead
+ of the index.
+ */
+ //! [2]
+ mutable QVector<QFileInfo> m_fileInfos;
+ const QDir::Filters m_filterAllowAll;
+ const QDir::SortFlags m_sortFlags;
+ QVector<QXmlName> m_names;
+ //! [2]
+};
+
+ //! [3]
+ //! [3]
diff --git a/examples/xmlpatterns/filetree/filetree.pro b/examples/xmlpatterns/filetree/filetree.pro
new file mode 100644
index 0000000..e30f2cf
--- /dev/null
+++ b/examples/xmlpatterns/filetree/filetree.pro
@@ -0,0 +1,15 @@
+SOURCES += main.cpp filetree.cpp mainwindow.cpp ../shared/xmlsyntaxhighlighter.cpp
+HEADERS += filetree.h mainwindow.h ../shared/xmlsyntaxhighlighter.h
+FORMS += forms/mainwindow.ui
+QT += xmlpatterns
+CONFIG -= app_bundle
+RESOURCES += queries.qrc
+INCLUDEPATH += ../shared/
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/filetree
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.xq *.html
+sources.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/filetree
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/xmlpatterns/filetree/forms/mainwindow.ui b/examples/xmlpatterns/filetree/forms/mainwindow.ui
new file mode 100644
index 0000000..993050f
--- /dev/null
+++ b/examples/xmlpatterns/filetree/forms/mainwindow.ui
@@ -0,0 +1,200 @@
+<ui version="4.0" >
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>910</width>
+ <height>676</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>File Tree</string>
+ </property>
+ <widget class="QWidget" name="centralwidget" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>29</y>
+ <width>910</width>
+ <height>625</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3" >
+ <item>
+ <widget class="QLabel" name="label" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font" >
+ <font>
+ <italic>true</italic>
+ </font>
+ </property>
+ <property name="text" >
+ <string></string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSplitter" name="splitter_2" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <widget class="QWidget" name="" >
+ <layout class="QVBoxLayout" name="verticalLayout_2" >
+ <item>
+ <widget class="QLabel" name="treeInfo" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>TextLabel</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QTextEdit" name="fileTree" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ <property name="html" >
+ <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
+p, li { white-space: pre-wrap; }
+&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
+&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;/p>&lt;/body>&lt;/html></string>
+ </property>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="" >
+ <layout class="QVBoxLayout" name="verticalLayout" >
+ <item>
+ <widget class="QComboBox" name="queryBox" />
+ </item>
+ <item>
+ <widget class="QSplitter" name="splitter" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <widget class="QTextEdit" name="queryEdit" >
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ <property name="html" >
+ <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
+p, li { white-space: pre-wrap; }
+&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
+&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;/p>&lt;/body>&lt;/html></string>
+ </property>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ <widget class="QTextEdit" name="output" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ <property name="html" >
+ <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
+p, li { white-space: pre-wrap; }
+&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
+&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;/p>&lt;/body>&lt;/html></string>
+ </property>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ <zorder>label</zorder>
+ <zorder>splitter_2</zorder>
+ <zorder>queryBox</zorder>
+ <zorder>treeInfo</zorder>
+ <zorder>splitter</zorder>
+ </widget>
+ <widget class="QMenuBar" name="menubar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>910</width>
+ <height>29</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuFile" >
+ <property name="title" >
+ <string>&amp;File</string>
+ </property>
+ <addaction name="actionOpenDirectory" />
+ </widget>
+ <widget class="QMenu" name="menu_Help" >
+ <property name="title" >
+ <string>&amp;Help</string>
+ </property>
+ <addaction name="actionAbout" />
+ </widget>
+ <addaction name="menuFile" />
+ <addaction name="menu_Help" />
+ </widget>
+ <widget class="QStatusBar" name="statusbar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>654</y>
+ <width>910</width>
+ <height>22</height>
+ </rect>
+ </property>
+ </widget>
+ <action name="actionOpenDirectory" >
+ <property name="text" >
+ <string>Open Directory...</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+O</string>
+ </property>
+ </action>
+ <action name="actionAbout" >
+ <property name="text" >
+ <string>&amp;About</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+A</string>
+ </property>
+ </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/xmlpatterns/filetree/main.cpp b/examples/xmlpatterns/filetree/main.cpp
new file mode 100644
index 0000000..e407a45
--- /dev/null
+++ b/examples/xmlpatterns/filetree/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char **argv)
+{
+ Q_INIT_RESOURCE(queries);
+ QApplication app(argc, argv);
+ MainWindow mainWindow;
+
+ mainWindow.show();
+ return app.exec();
+}
diff --git a/examples/xmlpatterns/filetree/mainwindow.cpp b/examples/xmlpatterns/filetree/mainwindow.cpp
new file mode 100644
index 0000000..341128a
--- /dev/null
+++ b/examples/xmlpatterns/filetree/mainwindow.cpp
@@ -0,0 +1,166 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QLibraryInfo>
+#include <QtXmlPatterns>
+
+#include "mainwindow.h"
+#include "xmlsyntaxhighlighter.h"
+
+//! [0]
+MainWindow::MainWindow() : m_fileTree(m_namePool)
+{
+ setupUi(this);
+
+ new XmlSyntaxHighlighter(fileTree->document());
+
+ // Set up the font.
+ {
+ QFont font("Courier",10);
+ font.setFixedPitch(true);
+
+ fileTree->setFont(font);
+ queryEdit->setFont(font);
+ output->setFont(font);
+ }
+
+ const QString dir(QLibraryInfo::location(QLibraryInfo::ExamplesPath) + "/xmlpatterns/filetree");
+ qDebug() << dir;
+
+ if (QDir(dir).exists())
+ loadDirectory(dir);
+ else
+ fileTree->setPlainText(tr("Use the Open menu entry to select a directory."));
+
+ const QStringList queries(QDir(":/queries/", "*.xq").entryList());
+ int len = queries.count();
+
+ for (int i = 0; i < len; ++i)
+ queryBox->addItem(queries.at(i));
+
+}
+//! [0]
+
+//! [2]
+void MainWindow::on_queryBox_currentIndexChanged()
+{
+ QFile queryFile(":/queries/" + queryBox->currentText());
+ queryFile.open(QIODevice::ReadOnly);
+
+ queryEdit->setPlainText(QString::fromLatin1(queryFile.readAll()));
+ evaluateResult();
+}
+//! [2]
+
+//! [3]
+void MainWindow::evaluateResult()
+{
+ if (queryBox->currentText().isEmpty())
+ return;
+
+ QXmlQuery query(m_namePool);
+ query.bindVariable("fileTree", m_fileNode);
+ query.setQuery(QUrl("qrc:/queries/" + queryBox->currentText()));
+
+ QByteArray formatterOutput;
+ QBuffer buffer(&formatterOutput);
+ buffer.open(QIODevice::WriteOnly);
+
+ QXmlFormatter formatter(query, &buffer);
+ query.evaluateTo(&formatter);
+
+ output->setText(QString::fromLatin1(formatterOutput.constData()));
+}
+//! [3]
+
+//! [1]
+void MainWindow::on_actionOpenDirectory_triggered()
+{
+ const QString directoryName = QFileDialog::getExistingDirectory(this);
+ if (!directoryName.isEmpty())
+ loadDirectory(directoryName);
+}
+//! [1]
+
+//! [4]
+//! [5]
+void MainWindow::loadDirectory(const QString &directory)
+{
+ Q_ASSERT(QDir(directory).exists());
+
+ m_fileNode = m_fileTree.nodeFor(directory);
+//! [5]
+
+ QXmlQuery query(m_namePool);
+ query.bindVariable("fileTree", m_fileNode);
+ query.setQuery(QUrl("qrc:/queries/wholeTree.xq"));
+
+ QByteArray output;
+ QBuffer buffer(&output);
+ buffer.open(QIODevice::WriteOnly);
+
+ QXmlFormatter formatter(query, &buffer);
+ query.evaluateTo(&formatter);
+
+ treeInfo->setText((QString(tr("Model of %1 output as XML.")).arg(directory)));
+ fileTree->setText(QString::fromLatin1(output.constData()));
+ evaluateResult();
+//! [6]
+}
+//! [6]
+//! [4]
+
+void MainWindow::on_actionAbout_triggered()
+{
+ QMessageBox::about(this, tr("About File Tree"),
+ tr("<p>Select <b>File->Open Directory</b> and "
+ "choose a directory. The directory is then "
+ "loaded into the model, and the model is "
+ "displayed on the left as XML.</p>"
+
+ "<p>From the query menu on the right, select "
+ "a query. The query is displayed and then run "
+ "on the model. The results are displayed below "
+ "the query.</p>"));
+}
+
+
diff --git a/examples/xmlpatterns/filetree/mainwindow.h b/examples/xmlpatterns/filetree/mainwindow.h
new file mode 100644
index 0000000..6651c80
--- /dev/null
+++ b/examples/xmlpatterns/filetree/mainwindow.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QFile>
+#include <QMainWindow>
+#include <QXmlNamePool>
+//! [0]
+#include "filetree.h"
+#include "ui_mainwindow.h"
+
+class MainWindow : public QMainWindow, private Ui_MainWindow
+{
+ Q_OBJECT
+
+ public:
+ MainWindow();
+
+ private slots:
+ void on_actionOpenDirectory_triggered();
+ void on_actionAbout_triggered();
+ void on_queryBox_currentIndexChanged();
+
+ private:
+ void loadDirectory(const QString &directory);
+ void evaluateResult();
+
+ const QXmlNamePool m_namePool;
+ const FileTree m_fileTree;
+ QXmlNodeModelIndex m_fileNode;
+};
+//! [0]
+#endif
diff --git a/examples/xmlpatterns/filetree/queries.qrc b/examples/xmlpatterns/filetree/queries.qrc
new file mode 100644
index 0000000..2e48601
--- /dev/null
+++ b/examples/xmlpatterns/filetree/queries.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC>
+ <RCC version="1.0">
+<qresource>
+ <file>queries/listCPPFiles.xq</file>
+ <file>queries/wholeTree.xq</file>
+</qresource>
+</RCC>
diff --git a/examples/xmlpatterns/filetree/queries/listCPPFiles.xq b/examples/xmlpatterns/filetree/queries/listCPPFiles.xq
new file mode 100644
index 0000000..e311d27
--- /dev/null
+++ b/examples/xmlpatterns/filetree/queries/listCPPFiles.xq
@@ -0,0 +1,19 @@
+declare variable $where as xs:string := string($fileTree/@filePath);
+<html>
+ <head>
+ <title>All cpp files in: {$where}</title>
+ </head>
+ <body>
+ <p>
+ cpp-files found in {$where} sorted by size:
+ </p>
+ <ul> {
+ for $file in $fileTree//file[@suffix = "cpp"]
+ order by xs:integer($file/@size)
+ return
+ <li>
+ {string($file/@fileName)}, size: {string($file/@size)}
+ </li>
+ } </ul>
+ </body>
+</html>
diff --git a/examples/xmlpatterns/filetree/queries/wholeTree.xq b/examples/xmlpatterns/filetree/queries/wholeTree.xq
new file mode 100644
index 0000000..ec2977b
--- /dev/null
+++ b/examples/xmlpatterns/filetree/queries/wholeTree.xq
@@ -0,0 +1 @@
+$fileTree
diff --git a/examples/xmlpatterns/qobjectxmlmodel/forms/mainwindow.ui b/examples/xmlpatterns/qobjectxmlmodel/forms/mainwindow.ui
new file mode 100644
index 0000000..ad43284
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/forms/mainwindow.ui
@@ -0,0 +1,196 @@
+<ui version="4.0" >
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>QObjectXmlModel Example</string>
+ </property>
+ <widget class="QWidget" name="centralwidget" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>29</y>
+ <width>800</width>
+ <height>549</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_4" >
+ <item>
+ <widget class="QLabel" name="label" >
+ <property name="font" >
+ <font>
+ <italic>true</italic>
+ </font>
+ </property>
+ <property name="text" >
+ <string>See the About menu entry for a description of this example.</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QTabWidget" name="inheritanceTab" >
+ <property name="autoFillBackground" >
+ <bool>true</bool>
+ </property>
+ <property name="currentIndex" >
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="wholeTreeTab" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>778</width>
+ <height>475</height>
+ </rect>
+ </property>
+ <attribute name="title" >
+ <string>Whole QObjectTree</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout" >
+ <item>
+ <widget class="QSplitter" name="splitter" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <widget class="QTextEdit" name="wholeTree" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ <property name="html" >
+ <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
+p, li { white-space: pre-wrap; }
+&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
+&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;/p>&lt;/body>&lt;/html></string>
+ </property>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ <widget class="QTextEdit" name="wholeTreeOutput" >
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ <property name="html" >
+ <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
+p, li { white-space: pre-wrap; }
+&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
+&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;/p>&lt;/body>&lt;/html></string>
+ </property>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="htmlTab" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>778</width>
+ <height>475</height>
+ </rect>
+ </property>
+ <attribute name="title" >
+ <string>Statistics in HTML </string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_2" >
+ <item>
+ <widget class="QSplitter" name="splitter_2" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <widget class="QTextEdit" name="htmlQueryEdit" >
+ <property name="readOnly" >
+ <bool>true</bool>
+ </property>
+ <property name="html" >
+ <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
+p, li { white-space: pre-wrap; }
+&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
+&lt;p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;/p>&lt;/body>&lt;/html></string>
+ </property>
+ <property name="acceptRichText" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ <widget class="QWebView" name="htmlOutput" >
+ <property name="url" >
+ <url>
+ <string>about:blank</string>
+ </url>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>29</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuHelp" >
+ <property name="title" >
+ <string>Help</string>
+ </property>
+ <addaction name="actionAbout" />
+ </widget>
+ <addaction name="menuHelp" />
+ </widget>
+ <widget class="QStatusBar" name="statusbar" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>578</y>
+ <width>800</width>
+ <height>22</height>
+ </rect>
+ </property>
+ </widget>
+ <action name="actionAbout" >
+ <property name="text" >
+ <string>About</string>
+ </property>
+ <property name="shortcut" >
+ <string>Ctrl+B</string>
+ </property>
+ </action>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>QWebView</class>
+ <extends>QWidget</extends>
+ <header>QtWebKit/QWebView</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/xmlpatterns/qobjectxmlmodel/main.cpp b/examples/xmlpatterns/qobjectxmlmodel/main.cpp
new file mode 100644
index 0000000..c73d211
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+
+#include "mainwindow.h"
+
+int main(int argc, char* argv[])
+{
+ Q_INIT_RESOURCE(queries);
+ QApplication app(argc, argv);
+ MainWindow mainWindow;
+ mainWindow.show();
+ return app.exec();
+}
diff --git a/examples/xmlpatterns/qobjectxmlmodel/mainwindow.cpp b/examples/xmlpatterns/qobjectxmlmodel/mainwindow.cpp
new file mode 100644
index 0000000..056ebae
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/mainwindow.cpp
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtXmlPatterns>
+
+#include "mainwindow.h"
+#include "qobjectxmlmodel.h"
+#include "xmlsyntaxhighlighter.h"
+
+MainWindow::MainWindow()
+{
+ setupUi(this);
+
+ new XmlSyntaxHighlighter(wholeTreeOutput->document());
+
+ /* Setup the font. */
+ {
+ QFont font("Courier");
+ font.setFixedPitch(true);
+
+ wholeTree->setFont(font);
+ wholeTreeOutput->setFont(font);
+ htmlQueryEdit->setFont(font);
+ }
+
+ QXmlNamePool namePool;
+ QObjectXmlModel qObjectModel(this, namePool);
+ QXmlQuery query(namePool);
+
+ /* The QObject tree as XML view. */
+ {
+ query.bindVariable("root", qObjectModel.root());
+ query.setQuery(QUrl("qrc:/queries/wholeTree.xq"));
+
+ Q_ASSERT(query.isValid());
+ QByteArray output;
+ QBuffer buffer(&output);
+ buffer.open(QIODevice::WriteOnly);
+
+ /* Let's the use the formatter, so it's a bit easier to read. */
+ QXmlFormatter serializer(query, &buffer);
+
+ query.evaluateTo(&serializer);
+ buffer.close();
+
+ {
+ QFile queryFile(":/queries/wholeTree.xq");
+ queryFile.open(QIODevice::ReadOnly);
+ wholeTree->setPlainText(QString::fromUtf8(queryFile.readAll()));
+ wholeTreeOutput->setPlainText(QString::fromUtf8(output.constData()));
+ }
+ }
+
+ /* The QObject occurrence statistics as HTML view. */
+ {
+ query.setQuery(QUrl("qrc:/queries/statisticsInHTML.xq"));
+ Q_ASSERT(query.isValid());
+
+ QByteArray output;
+ QBuffer buffer(&output);
+ buffer.open(QIODevice::WriteOnly);
+
+ /* Let's the use the serializer, so we gain a bit of speed. */
+ QXmlSerializer serializer(query, &buffer);
+
+ query.evaluateTo(&serializer);
+ buffer.close();
+
+ {
+ QFile queryFile(":/queries/statisticsInHTML.xq");
+ queryFile.open(QIODevice::ReadOnly);
+ htmlQueryEdit->setPlainText(QString::fromUtf8(queryFile.readAll()));
+ htmlOutput->setHtml(QString(output));
+ }
+ }
+}
+
+void MainWindow::on_actionAbout_triggered()
+{
+ QMessageBox::about(this,
+ tr("About QObject XML Model"),
+ tr("<p>The <b>QObject XML Model</b> example shows "
+ "how to use XQuery on top of data of your choice "
+ "without converting it to an XML document.</p>"
+ "<p>In this example a QSimpleXmlNodeModel subclass "
+ "makes it possible to query a QObject tree using "
+ "XQuery and retrieve the result as pointers to "
+ "QObjects, or as XML.</p>"
+ "<p>A possible use case of this could be to write "
+ "an application that tests a graphical interface "
+ "against Human Interface Guidelines, or that "
+ "queries an application's data which is modeled "
+ "using a QObject tree and dynamic properties."));
+}
+
+
diff --git a/examples/xmlpatterns/qobjectxmlmodel/mainwindow.h b/examples/xmlpatterns/qobjectxmlmodel/mainwindow.h
new file mode 100644
index 0000000..362bd0e
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/mainwindow.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QFile>
+
+#include "ui_mainwindow.h"
+
+//! [0]
+class MainWindow : public QMainWindow,
+ private Ui_MainWindow
+{
+ Q_OBJECT
+
+ public:
+ MainWindow();
+
+ private slots:
+ void on_actionAbout_triggered();
+};
+//! [0]
+
+#endif
diff --git a/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.cpp b/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.cpp
new file mode 100644
index 0000000..3eee67a
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.cpp
@@ -0,0 +1,459 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QVector>
+#include <QtDebug>
+
+#include <QCoreApplication>
+#include <QMetaProperty>
+#include <QXmlQuery>
+#include <QXmlResultItems>
+
+#include "qobjectxmlmodel.h"
+
+QT_BEGIN_NAMESPACE
+
+/*
+<metaObjects>
+ <metaObject className="QObject"/>
+ <metaObject className="QWidget" superClass="QObject">
+ </metaObject>
+ ...
+</metaObjects>
+<QObject objectName="MyWidget" property1="..." property2="..."> <!-- This is root() -->
+ <QObject objectName="MyFOO" property1="..."/>
+ ....
+</QObject>
+*/
+
+QObjectXmlModel::QObjectXmlModel(QObject *const object, const QXmlNamePool &np)
+ : QSimpleXmlNodeModel(np),
+ m_baseURI(QUrl::fromLocalFile(QCoreApplication::applicationFilePath())),
+ m_root(object),
+ m_allMetaObjects(allMetaObjects())
+{
+ Q_ASSERT(m_baseURI.isValid());
+}
+
+//! [5]
+QXmlNodeModelIndex QObjectXmlModel::qObjectSibling(const int pos, const QXmlNodeModelIndex &n) const
+{
+ Q_ASSERT(pos == 1 || pos == -1);
+ Q_ASSERT(asQObject(n));
+
+ const QObject *parent = asQObject(n)->parent();
+ if (parent) {
+ const QList<QObject *> &children = parent->children();
+ const int siblingPos = children.indexOf(asQObject(n)) + pos;
+
+ if (siblingPos >= 0 && siblingPos < children.count())
+ return createIndex(children.at(siblingPos));
+ else
+ return QXmlNodeModelIndex();
+ }
+ else
+ return QXmlNodeModelIndex();
+}
+//! [5]
+
+//! [1]
+QObjectXmlModel::QObjectNodeType QObjectXmlModel::toNodeType(const QXmlNodeModelIndex &n)
+{
+ return QObjectNodeType(n.additionalData() & (15 << 26));
+}
+//! [1]
+
+//! [9]
+QObjectXmlModel::AllMetaObjects QObjectXmlModel::allMetaObjects() const
+{
+ QXmlQuery query(namePool());
+ query.bindVariable("root", root());
+ query.setQuery("declare variable $root external;"
+ "$root/descendant-or-self::QObject");
+ Q_ASSERT(query.isValid());
+
+ QXmlResultItems result;
+ query.evaluateTo(&result);
+ QXmlItem i(result.next());
+
+ AllMetaObjects objects;
+ while (!i.isNull()) {
+ const QMetaObject *moo = asQObject(i.toNodeModelIndex())->metaObject();
+ while (moo) {
+ if (!objects.contains(moo))
+ objects.append(moo);
+ moo = moo->superClass();
+ }
+ i = result.next();
+ }
+
+ Q_ASSERT(!objects.contains(0));
+ return objects;
+}
+//! [9]
+
+QXmlNodeModelIndex QObjectXmlModel::metaObjectSibling(const int pos, const QXmlNodeModelIndex &n) const
+{
+ Q_ASSERT(pos == 1 || pos == -1);
+ Q_ASSERT(!n.isNull());
+
+ const int indexOf = m_allMetaObjects.indexOf(static_cast<const QMetaObject *>(n.internalPointer())) + pos;
+
+ if (indexOf >= 0 && indexOf < m_allMetaObjects.count())
+ return createIndex(const_cast<QMetaObject *>(m_allMetaObjects.at(indexOf)), MetaObject);
+ else
+ return QXmlNodeModelIndex();
+}
+
+//! [2]
+QXmlNodeModelIndex QObjectXmlModel::nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &n) const
+{
+ switch (toNodeType(n))
+ {
+ case IsQObject:
+ {
+ switch (axis)
+ {
+ case Parent:
+ return createIndex(asQObject(n)->parent());
+
+ case FirstChild:
+ {
+ if (!asQObject(n) || asQObject(n)->children().isEmpty())
+ return QXmlNodeModelIndex();
+ else
+ return createIndex(asQObject(n)->children().first());
+ }
+
+ case NextSibling:
+ return qObjectSibling(1, n);
+
+//! [10]
+ case PreviousSibling:
+ {
+ if (asQObject(n) == m_root)
+ return createIndex(qint64(0), MetaObjects);
+ else
+ return qObjectSibling(-1, n);
+ }
+//! [10]
+ }
+ Q_ASSERT(false);
+ }
+
+//! [7]
+ case QObjectClassName:
+ case QObjectProperty:
+ {
+ Q_ASSERT(axis == Parent);
+ return createIndex(asQObject(n));
+ }
+//! [7]
+//! [2]
+//! [3]
+
+//! [11]
+ case MetaObjects:
+ {
+ switch (axis)
+ {
+ case Parent:
+ return QXmlNodeModelIndex();
+ case PreviousSibling:
+ return QXmlNodeModelIndex();
+ case NextSibling:
+ return root();
+ case FirstChild:
+ {
+ return createIndex(const_cast<QMetaObject*>(m_allMetaObjects.first()),MetaObject);
+ }
+ }
+ Q_ASSERT(false);
+ }
+//! [11]
+
+ case MetaObject:
+ {
+ switch (axis)
+ {
+ case FirstChild:
+ return QXmlNodeModelIndex();
+ case Parent:
+ return createIndex(qint64(0), MetaObjects);
+ case PreviousSibling:
+ return metaObjectSibling(-1, n);
+ case NextSibling:
+ return metaObjectSibling(1, n);
+ }
+ }
+
+ case MetaObjectClassName:
+ case MetaObjectSuperClass:
+ {
+ Q_ASSERT(axis == Parent);
+ return createIndex(asQObject(n), MetaObject);
+ }
+//! [3]
+//! [4]
+ }
+
+ Q_ASSERT(false);
+ return QXmlNodeModelIndex();
+}
+//! [4]
+
+//! [6]
+QVector<QXmlNodeModelIndex> QObjectXmlModel::attributes(const QXmlNodeModelIndex& n) const
+{
+ QVector<QXmlNodeModelIndex> result;
+ QObject *const object = asQObject(n);
+
+ switch(toNodeType(n))
+ {
+ case IsQObject:
+ {
+ const QMetaObject *const metaObject = object->metaObject();
+ const int count = metaObject->propertyCount();
+ result.append(createIndex(object, QObjectClassName));
+
+ for (int i = 0; i < count; ++i) {
+ const QMetaProperty qmp(metaObject->property(i));
+ const int ii = metaObject->indexOfProperty(qmp.name());
+ if (i == ii)
+ result.append(createIndex(object, QObjectProperty | i));
+ }
+ return result;
+ }
+//! [6]
+
+ case MetaObject:
+ {
+ result.append(createIndex(object, MetaObjectClassName));
+ result.append(createIndex(object, MetaObjectSuperClass));
+ return result;
+ }
+//! [8]
+ default:
+ return QVector<QXmlNodeModelIndex>();
+ }
+}
+//! [8]
+
+QObject *QObjectXmlModel::asQObject(const QXmlNodeModelIndex &n)
+{
+ return static_cast<QObject *>(n.internalPointer());
+}
+
+bool QObjectXmlModel::isProperty(const QXmlNodeModelIndex n)
+{
+ return n.additionalData() & QObjectProperty;
+}
+
+QUrl QObjectXmlModel::documentUri(const QXmlNodeModelIndex& ) const
+{
+ return m_baseURI;
+}
+
+QXmlNodeModelIndex::NodeKind QObjectXmlModel::kind(const QXmlNodeModelIndex& n) const
+{
+ switch (toNodeType(n))
+ {
+ case IsQObject:
+ case MetaObject:
+ case MetaObjects:
+ return QXmlNodeModelIndex::Element;
+
+ case QObjectProperty:
+ case MetaObjectClassName:
+ case MetaObjectSuperClass:
+ case QObjectClassName:
+ return QXmlNodeModelIndex::Attribute;
+ }
+
+ Q_ASSERT(false);
+ return QXmlNodeModelIndex::Element;
+}
+
+QXmlNodeModelIndex::DocumentOrder QObjectXmlModel::compareOrder(const QXmlNodeModelIndex& , const QXmlNodeModelIndex& ) const
+{
+ return QXmlNodeModelIndex::Follows; // TODO
+}
+
+//! [0]
+QXmlNodeModelIndex QObjectXmlModel::root() const
+{
+ return createIndex(m_root);
+}
+//! [0]
+
+QXmlNodeModelIndex QObjectXmlModel::root(const QXmlNodeModelIndex& n) const
+{
+ QObject *p = asQObject(n);
+ Q_ASSERT(p);
+
+ do {
+ QObject *const candidate = p->parent();
+ if (candidate)
+ p = candidate;
+ else
+ break;
+ }
+ while (true);
+
+ return createIndex(p);
+}
+
+/*!
+ We simply throw all of them into a QList and
+ return an iterator over it.
+ */
+QXmlNodeModelIndex::List QObjectXmlModel::ancestors(const QXmlNodeModelIndex n) const
+{
+ const QObject *p = asQObject(n);
+ Q_ASSERT(p);
+
+ QXmlNodeModelIndex::List result;
+ do {
+ QObject *const candidate = p->parent();
+ if (candidate) {
+ result.append(createIndex(candidate, 0));
+ p = candidate;
+ }
+ else
+ break;
+ }
+ while (true);
+
+ return result;
+}
+
+QMetaProperty QObjectXmlModel::toMetaProperty(const QXmlNodeModelIndex &n)
+{
+ const int propertyOffset = n.additionalData() & (~QObjectProperty);
+ const QObject *const qo = asQObject(n);
+ return qo->metaObject()->property(propertyOffset);
+}
+
+QXmlName QObjectXmlModel::name(const QXmlNodeModelIndex &n) const
+{
+ switch (toNodeType(n))
+ {
+ case IsQObject:
+ return QXmlName(namePool(), QLatin1String("QObject"));
+ case MetaObject:
+ return QXmlName(namePool(), QLatin1String("metaObject"));
+ case QObjectClassName:
+ case MetaObjectClassName:
+ return QXmlName(namePool(), QLatin1String("className"));
+ case QObjectProperty:
+ return QXmlName(namePool(), toMetaProperty(n).name());
+ case MetaObjects:
+ return QXmlName(namePool(), QLatin1String("metaObjects"));
+ case MetaObjectSuperClass:
+ return QXmlName(namePool(), QLatin1String("superClass"));
+ }
+
+ Q_ASSERT(false);
+ return QXmlName();
+}
+
+QVariant QObjectXmlModel::typedValue(const QXmlNodeModelIndex &n) const
+{
+ switch (toNodeType(n))
+ {
+ case QObjectProperty:
+ {
+ const QVariant &candidate = toMetaProperty(n).read(asQObject(n));
+ if (isTypeSupported(candidate.type()))
+ return candidate;
+ else
+ return QVariant();
+ }
+
+ case MetaObjectClassName:
+ return QVariant(static_cast<QMetaObject*>(n.internalPointer())->className());
+
+ case MetaObjectSuperClass:
+ {
+ const QMetaObject *const superClass = static_cast<QMetaObject*>(n.internalPointer())->superClass();
+ if (superClass)
+ return QVariant(superClass->className());
+ else
+ return QVariant();
+ }
+
+ case QObjectClassName:
+ return QVariant(asQObject(n)->metaObject()->className());
+
+ default:
+ return QVariant();
+ }
+}
+
+/*!
+ Returns \c true if QVariants of type \a type can be used
+ in QtXmlPatterns, otherwise \c false.
+ */
+bool QObjectXmlModel::isTypeSupported(QVariant::Type type)
+{
+ /* See data/qatomicvalue.cpp too. */
+ switch (type)
+ {
+ /* Fallthrough all these. */
+ case QVariant::Char:
+ case QVariant::String:
+ case QVariant::Url:
+ case QVariant::Bool:
+ case QVariant::ByteArray:
+ case QVariant::Int:
+ case QVariant::LongLong:
+ case QVariant::ULongLong:
+ case QVariant::Date:
+ case QVariant::DateTime:
+ case QVariant::Time:
+ case QVariant::Double:
+ return true;
+ default:
+ return false;
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.h b/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.h
new file mode 100644
index 0000000..2c2b468
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.h
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef Patternist_QObjectNodeModel_H
+#define Patternist_QObjectNodeModel_H
+
+#include <QSimpleXmlNodeModel>
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+class QObject;
+class PropertyToAtomicValue;
+
+/**
+ * @short Delegates QtCore's QObject into Patternist's QAbstractXmlNodeModel.
+ * known as pre/post numbering.
+ *
+ * QObjectXmlModel sets the toggle on QXmlNodeModelIndex to @c true, if it
+ * represents a property of the QObject. That is, if the QXmlNodeModelIndex is
+ * an attribute.
+ *
+ * @author Frans Englich <fenglich@trolltech.com>
+ */
+class QObjectXmlModel : public QSimpleXmlNodeModel
+{
+ public:
+ QObjectXmlModel(QObject *const object, const QXmlNamePool &np);
+
+ QXmlNodeModelIndex root() const;
+
+//! [0]
+ virtual QXmlNodeModelIndex::DocumentOrder compareOrder(const QXmlNodeModelIndex &n1, const QXmlNodeModelIndex &n2) const;
+ virtual QXmlName name(const QXmlNodeModelIndex &n) const;
+ virtual QUrl documentUri(const QXmlNodeModelIndex &n) const;
+ virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &n) const;
+ virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &n) const;
+ virtual QVariant typedValue(const QXmlNodeModelIndex &n) const;
+ virtual QVector<QXmlNodeModelIndex> attributes(const QXmlNodeModelIndex&) const;
+ virtual QXmlNodeModelIndex nextFromSimpleAxis(SimpleAxis, const QXmlNodeModelIndex&) const;
+//! [0]
+
+ private:
+ /**
+ * The highest three bits are used to signify whether the node index
+ * is an artificial node.
+ *
+ * @short if QXmlNodeModelIndex::additionalData() has the
+ * QObjectPropery flag set, then the QXmlNodeModelIndex is an
+ * attribute of the QObject element, and the remaining bits form
+ * an offset to the QObject property that the QXmlNodeModelIndex
+ * refers to.
+ *
+ */
+//! [3]
+ enum QObjectNodeType
+ {
+ IsQObject = 0,
+ QObjectProperty = 1 << 26,
+ MetaObjects = 2 << 26,
+ MetaObject = 3 << 26,
+ MetaObjectClassName = 4 << 26,
+ MetaObjectSuperClass = 5 << 26,
+ QObjectClassName = 6 << 26
+ };
+//! [3]
+
+//! [1]
+ typedef QVector<const QMetaObject *> AllMetaObjects;
+//! [1]
+ AllMetaObjects allMetaObjects() const;
+
+ static QObjectNodeType toNodeType(const QXmlNodeModelIndex &n);
+ static bool isTypeSupported(QVariant::Type type);
+ static inline QObject *asQObject(const QXmlNodeModelIndex &n);
+ static inline bool isProperty(const QXmlNodeModelIndex n);
+ static inline QMetaProperty toMetaProperty(const QXmlNodeModelIndex &n);
+ /**
+ * Returns the ancestors of @p n. Does therefore not include
+ * @p n.
+ */
+ inline QXmlNodeModelIndex::List ancestors(const QXmlNodeModelIndex n) const;
+ QXmlNodeModelIndex qObjectSibling(const int pos,
+ const QXmlNodeModelIndex &n) const;
+ QXmlNodeModelIndex metaObjectSibling(const int pos,
+ const QXmlNodeModelIndex &n) const;
+
+//! [2]
+ const QUrl m_baseURI;
+ QObject *const m_root;
+//! [4]
+ const AllMetaObjects m_allMetaObjects;
+//! [4]
+//! [2]
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
diff --git a/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.pro b/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.pro
new file mode 100644
index 0000000..39f0106
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel.pro
@@ -0,0 +1,13 @@
+
+FORMS += forms/mainwindow.ui
+QT += xmlpatterns webkit
+SOURCES += qobjectxmlmodel.cpp main.cpp mainwindow.cpp ../shared/xmlsyntaxhighlighter.cpp
+HEADERS += qobjectxmlmodel.h mainwindow.h ../shared/xmlsyntaxhighlighter.h
+RESOURCES = queries.qrc
+INCLUDEPATH += ../shared/
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/qobjectxmlmodel
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro *.xq *.html
+sources.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/qobjectxmlmodel
+INSTALLS += target sources
diff --git a/examples/xmlpatterns/qobjectxmlmodel/queries.qrc b/examples/xmlpatterns/qobjectxmlmodel/queries.qrc
new file mode 100644
index 0000000..ec8cc6b
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/queries.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC>
+ <RCC version="1.0">
+<qresource>
+ <file>queries/wholeTree.xq</file>
+ <file>queries/statisticsInHTML.xq</file>
+</qresource>
+</RCC>
diff --git a/examples/xmlpatterns/qobjectxmlmodel/queries/statisticsInHTML.xq b/examples/xmlpatterns/qobjectxmlmodel/queries/statisticsInHTML.xq
new file mode 100644
index 0000000..14a7a14
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/queries/statisticsInHTML.xq
@@ -0,0 +1,58 @@
+<html>
+ <head>
+ <title></title>
+ </head>
+ <body>
+ <p>In total the tree has {count($root//QObject)} QObject instances.</p>
+ <p>Order by occurrence, the QObjects are:</p>
+
+ <ol>
+ {
+ for $i in $root/preceding-sibling::metaObjects/metaObject
+ let $count := count($root//QObject[@className eq $i/@className])
+ stable order by $count descending
+ return if($count > 1)
+ then <li>{string($i/@className), $count} occurrences</li>
+ else ()
+ }
+ </ol>
+
+ <h1>Properties</h1>
+ {
+ (: For each QObject, we create a table listing
+ : the properties of that object. :)
+ for $object in $root//QObject
+ return (<h2>{let $name := string($object/@objectName)
+ return if(string-length($name))
+ then $name
+ else "[no name]",
+ '(', string($object/@className), ')'}</h2>,
+ <table border="1">
+ <thead>
+ <tr>
+ <td>Property Name</td>
+ <td>Value</td>
+ </tr>
+ </thead>
+ <tbody>
+ {
+ $object/@*/<tr>
+ <td>
+ {
+ name()
+ }
+ </td>
+ <td>
+ {
+ if(data(.))
+ then string(.)
+ else "N/A"
+ }
+ </td>
+ </tr>
+ }
+ </tbody>
+ </table>)
+ }
+ </body>
+</html>
diff --git a/examples/xmlpatterns/qobjectxmlmodel/queries/wholeTree.xq b/examples/xmlpatterns/qobjectxmlmodel/queries/wholeTree.xq
new file mode 100644
index 0000000..253cd43
--- /dev/null
+++ b/examples/xmlpatterns/qobjectxmlmodel/queries/wholeTree.xq
@@ -0,0 +1,3 @@
+<!-- This is the QObject tree for this application, rendered as XML. -->,
+$root/preceding-sibling::metaObjects,
+$root
diff --git a/examples/xmlpatterns/recipes/files/allRecipes.xq b/examples/xmlpatterns/recipes/files/allRecipes.xq
new file mode 100644
index 0000000..6888c31
--- /dev/null
+++ b/examples/xmlpatterns/recipes/files/allRecipes.xq
@@ -0,0 +1,4 @@
+(: Select all recipes. :)
+declare variable $inputDocument external;
+
+doc($inputDocument)/cookbook/recipe/<p>{string(title)}</p>
diff --git a/examples/xmlpatterns/recipes/files/cookbook.xml b/examples/xmlpatterns/recipes/files/cookbook.xml
new file mode 100644
index 0000000..3b6f621
--- /dev/null
+++ b/examples/xmlpatterns/recipes/files/cookbook.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<cookbook>
+ <recipe xml:id="MushroomSoup">
+ <title>Quick and Easy Mushroom Soup</title>
+ <ingredient name="Fresh mushrooms"
+ quantity="7"
+ unit="pieces"/>
+ <ingredient name="Garlic"
+ quantity="1"
+ unit="cloves"/>
+ <ingredient name="Olive oil"
+ quantity="2"
+ unit="tablespoons"/>
+ <ingredient name="Milk"
+ quantity="200"
+ unit="milliliters"/>
+ <ingredient name="Water"
+ quantity="200"
+ unit="milliliters"/>
+ <ingredient name="Cream"
+ quantity="100"
+ unit="milliliters"/>
+ <ingredient name="Vegetable soup cube"
+ quantity="1/2"
+ unit="cubes"/>
+ <ingredient name="Ground black pepper"
+ quantity="1/2"
+ unit="teaspoons"/>
+ <ingredient name="Dried parsley"
+ quantity="1"
+ unit="teaspoons"/>
+ <time quantity="20"
+ unit="minutes"/>
+ <method>
+ <step>1. Slice mushrooms and garlic.</step>
+ <step>2. Fry mushroom slices and garlic with olive oil.</step>
+ <step>3. Once mushrooms are cooked, add milk, cream water. Stir.</step>
+ <step>4. Add vegetable soup cube.</step>
+ <step>5. Reduce heat, add pepper and parsley.</step>
+ <step>6. Turn off the stove before the mixture boils.</step>
+ <step>7. Blend the mixture.</step>
+ </method>
+ </recipe>
+ <recipe xml:id="CheeseOnToast">
+ <title>Cheese on Toast</title>
+ <ingredient name="Bread"
+ quantity="2"
+ unit="slices"/>
+ <ingredient name="Cheese"
+ quantity="2"
+ unit="slices"/>
+ <time quantity="3"
+ unit="minutes"/>
+ <method>
+ <step>1. Slice the bread and cheese.</step>
+ <step>2. Grill one side of each slice of bread.</step>
+ <step>3. Turn over the bread and place a slice of cheese on each piece.</step>
+ <step>4. Grill until the cheese has started to melt.</step>
+ <step>5. Serve and enjoy!</step>
+ </method>
+ </recipe>
+</cookbook>
diff --git a/examples/xmlpatterns/recipes/files/liquidIngredientsInSoup.xq b/examples/xmlpatterns/recipes/files/liquidIngredientsInSoup.xq
new file mode 100644
index 0000000..3baecd8
--- /dev/null
+++ b/examples/xmlpatterns/recipes/files/liquidIngredientsInSoup.xq
@@ -0,0 +1,5 @@
+(: All liquid ingredients form Mushroom Soup. :)
+declare variable $inputDocument external;
+
+doc($inputDocument)/cookbook/recipe[@xml:id = "MushroomSoup"]/ingredient[@unit = "milliliters"]/
+<p>{@name, @quantity, @unit}</p>
diff --git a/examples/xmlpatterns/recipes/files/mushroomSoup.xq b/examples/xmlpatterns/recipes/files/mushroomSoup.xq
new file mode 100644
index 0000000..b1fee34
--- /dev/null
+++ b/examples/xmlpatterns/recipes/files/mushroomSoup.xq
@@ -0,0 +1,5 @@
+(: All ingredients for Mushroom Soup. :)
+declare variable $inputDocument external;
+
+doc($inputDocument)/cookbook/recipe[@xml:id = "MushroomSoup"]/ingredient/
+<p>{@name, @quantity}</p>
diff --git a/examples/xmlpatterns/recipes/files/preparationLessThan30.xq b/examples/xmlpatterns/recipes/files/preparationLessThan30.xq
new file mode 100644
index 0000000..d74a4eb
--- /dev/null
+++ b/examples/xmlpatterns/recipes/files/preparationLessThan30.xq
@@ -0,0 +1,9 @@
+(: All recipes taking 10 minutes or less to prepare. :)
+declare variable $inputDocument external;
+
+doc($inputDocument)/cookbook/recipe/time[@unit = "minutes" and xs:integer(@quantity) <= 10]/
+<p>
+ {
+ concat(../title, ' (', @quantity, ' ', @unit, ')')
+ }
+</p>
diff --git a/examples/xmlpatterns/recipes/files/preparationTimes.xq b/examples/xmlpatterns/recipes/files/preparationTimes.xq
new file mode 100644
index 0000000..cb4217f
--- /dev/null
+++ b/examples/xmlpatterns/recipes/files/preparationTimes.xq
@@ -0,0 +1,5 @@
+(: All recipes with preparation times. :)
+declare variable $inputDocument external;
+
+doc($inputDocument)/cookbook/recipe/
+<recipe title="{title}" time="{time/@quantity} {time/@unit}"/>
diff --git a/examples/xmlpatterns/recipes/forms/querywidget.ui b/examples/xmlpatterns/recipes/forms/querywidget.ui
new file mode 100644
index 0000000..fb2ab64
--- /dev/null
+++ b/examples/xmlpatterns/recipes/forms/querywidget.ui
@@ -0,0 +1,151 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QueryWidget</class>
+ <widget class="QMainWindow" name="QueryWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>570</width>
+ <height>531</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Recipes XQuery Example</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QVBoxLayout">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QGroupBox" name="inputGroupBox">
+ <property name="minimumSize">
+ <size>
+ <width>550</width>
+ <height>120</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Input Document</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <layout class="QVBoxLayout" name="_2">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTextEdit" name="inputTextEdit">
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="queryGroupBox">
+ <property name="minimumSize">
+ <size>
+ <width>550</width>
+ <height>120</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Select your query:</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_5">
+ <item>
+ <widget class="QComboBox" name="defaultQueries"/>
+ </item>
+ <item>
+ <widget class="QTextEdit" name="queryTextEdit">
+ <property name="minimumSize">
+ <size>
+ <width>400</width>
+ <height>60</height>
+ </size>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="acceptRichText">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="outputGroupBox">
+ <property name="minimumSize">
+ <size>
+ <width>550</width>
+ <height>120</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Output Document</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_6">
+ <item>
+ <layout class="QVBoxLayout" name="_3">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTextEdit" name="outputTextEdit">
+ <property name="minimumSize">
+ <size>
+ <width>500</width>
+ <height>80</height>
+ </size>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="acceptRichText">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>570</width>
+ <height>26</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QStatusBar" name="statusbar"/>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/examples/xmlpatterns/recipes/main.cpp b/examples/xmlpatterns/recipes/main.cpp
new file mode 100644
index 0000000..ee0698f
--- /dev/null
+++ b/examples/xmlpatterns/recipes/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include "querymainwindow.h"
+
+//! [0]
+int main(int argc, char* argv[])
+{
+ Q_INIT_RESOURCE(recipes);
+ QApplication app(argc, argv);
+ QueryMainWindow* const queryWindow = new QueryMainWindow;
+ queryWindow->show();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/xmlpatterns/recipes/querymainwindow.cpp b/examples/xmlpatterns/recipes/querymainwindow.cpp
new file mode 100644
index 0000000..0438ab9
--- /dev/null
+++ b/examples/xmlpatterns/recipes/querymainwindow.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtXmlPatterns>
+
+#include "querymainwindow.h"
+#include "xmlsyntaxhighlighter.h"
+
+//! [0]
+QueryMainWindow::QueryMainWindow() : ui_defaultQueries(0)
+{
+ setupUi(this);
+
+ new XmlSyntaxHighlighter(qFindChild<QTextEdit*>(this, "inputTextEdit")->document());
+ new XmlSyntaxHighlighter(qFindChild<QTextEdit*>(this, "outputTextEdit")->document());
+
+ ui_defaultQueries = qFindChild<QComboBox*>(this, "defaultQueries");
+ QMetaObject::connectSlotsByName(this);
+ connect(ui_defaultQueries, SIGNAL(currentIndexChanged(int)), SLOT(displayQuery(int)));
+
+ loadInputFile();
+ const QStringList queries(QDir(":/files/", "*.xq").entryList());
+ int len = queries.count();
+ for(int i = 0; i < len; ++i)
+ ui_defaultQueries->addItem(queries.at(i));
+}
+//! [0]
+
+
+//! [1]
+void QueryMainWindow::displayQuery(int index)
+{
+ QFile queryFile(QString(":files/") + ui_defaultQueries->itemText(index));
+ queryFile.open(QIODevice::ReadOnly);
+ const QString query(QString::fromLatin1(queryFile.readAll()));
+ qFindChild<QTextEdit*>(this, "queryTextEdit")->setPlainText(query);
+
+ evaluate(query);
+}
+//! [1]
+
+
+void QueryMainWindow::loadInputFile()
+{
+ QFile forView;
+ forView.setFileName(":/files/cookbook.xml");
+ if (!forView.open(QIODevice::ReadOnly)) {
+ QMessageBox::information(this,
+ tr("Unable to open file"), forView.errorString());
+ return;
+ }
+
+ QTextStream in(&forView);
+ QString inputDocument = in.readAll();
+ qFindChild<QTextEdit*>(this, "inputTextEdit")->setPlainText(inputDocument);
+}
+
+
+//! [2]
+void QueryMainWindow::evaluate(const QString &str)
+{
+ QFile sourceDocument;
+ sourceDocument.setFileName(":/files/cookbook.xml");
+ sourceDocument.open(QIODevice::ReadOnly);
+
+ QByteArray outArray;
+ QBuffer buffer(&outArray);
+ buffer.open(QIODevice::ReadWrite);
+
+ QXmlQuery query;
+ query.bindVariable("inputDocument", &sourceDocument);
+ query.setQuery(str);
+ if (!query.isValid())
+ return;
+
+ QXmlFormatter formatter(query, &buffer);
+ if (!query.evaluateTo(&formatter))
+ return;
+
+ buffer.close();
+ qFindChild<QTextEdit*>(this, "outputTextEdit")->setPlainText(QString::fromUtf8(outArray.constData()));
+
+}
+//! [2]
+
diff --git a/examples/xmlpatterns/recipes/querymainwindow.h b/examples/xmlpatterns/recipes/querymainwindow.h
new file mode 100644
index 0000000..2c85932
--- /dev/null
+++ b/examples/xmlpatterns/recipes/querymainwindow.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QUERYMAINWINDOW_H
+#define QUERYMAINWINDOW_H
+
+#include <QMainWindow>
+
+#include "ui_querywidget.h"
+
+QT_BEGIN_NAMESPACE
+class QComboBox;
+QT_END_NAMESPACE
+
+//! [0]
+class QueryMainWindow : public QMainWindow,
+ private Ui::QueryWidget
+{
+ Q_OBJECT
+
+ public:
+ QueryMainWindow();
+
+ public slots:
+ void displayQuery(int index);
+
+ private:
+ QComboBox* ui_defaultQueries;
+
+ void evaluate(const QString &str);
+ void loadInputFile();
+};
+//! [0]
+#endif
diff --git a/examples/xmlpatterns/recipes/recipes.pro b/examples/xmlpatterns/recipes/recipes.pro
new file mode 100644
index 0000000..cee7b6d
--- /dev/null
+++ b/examples/xmlpatterns/recipes/recipes.pro
@@ -0,0 +1,13 @@
+QT += xmlpatterns
+FORMS += forms/querywidget.ui
+HEADERS = querymainwindow.h ../shared/xmlsyntaxhighlighter.h
+RESOURCES = recipes.qrc
+SOURCES = main.cpp querymainwindow.cpp ../shared/xmlsyntaxhighlighter.cpp
+INCLUDEPATH += ../shared/
+
+target.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/recipes
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.xq *.html forms files
+sources.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/recipes
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/xmlpatterns/recipes/recipes.qrc b/examples/xmlpatterns/recipes/recipes.qrc
new file mode 100644
index 0000000..2f375ee
--- /dev/null
+++ b/examples/xmlpatterns/recipes/recipes.qrc
@@ -0,0 +1,11 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>forms/querywidget.ui</file>
+ <file>files/cookbook.xml</file>
+ <file>files/allRecipes.xq</file>
+ <file>files/liquidIngredientsInSoup.xq</file>
+ <file>files/mushroomSoup.xq</file>
+ <file>files/preparationLessThan30.xq</file>
+ <file>files/preparationTimes.xq</file>
+</qresource>
+</RCC>
diff --git a/examples/xmlpatterns/shared/xmlsyntaxhighlighter.cpp b/examples/xmlpatterns/shared/xmlsyntaxhighlighter.cpp
new file mode 100644
index 0000000..c796f81
--- /dev/null
+++ b/examples/xmlpatterns/shared/xmlsyntaxhighlighter.cpp
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "xmlsyntaxhighlighter.h"
+
+XmlSyntaxHighlighter::XmlSyntaxHighlighter(QTextDocument *parent)
+ : QSyntaxHighlighter(parent)
+{
+ HighlightingRule rule;
+
+ // tag format
+ tagFormat.setForeground(Qt::darkBlue);
+ tagFormat.setFontWeight(QFont::Bold);
+ rule.pattern = QRegExp("(<[a-zA-Z:]+\\b|<\\?[a-zA-Z:]+\\b|\\?>|>|/>|</[a-zA-Z:]+>)");
+ rule.format = tagFormat;
+ highlightingRules.append(rule);
+
+ // attribute format
+ attributeFormat.setForeground(Qt::darkGreen);
+ rule.pattern = QRegExp("[a-zA-Z:]+=");
+ rule.format = attributeFormat;
+ highlightingRules.append(rule);
+
+ // attribute content format
+ attributeContentFormat.setForeground(Qt::red);
+ rule.pattern = QRegExp("(\"[^\"]*\"|'[^']*')");
+ rule.format = attributeContentFormat;
+ highlightingRules.append(rule);
+
+ commentFormat.setForeground(Qt::lightGray);
+ commentFormat.setFontItalic(true);
+
+ commentStartExpression = QRegExp("<!--");
+ commentEndExpression = QRegExp("-->");
+}
+
+void XmlSyntaxHighlighter::highlightBlock(const QString &text)
+{
+ foreach (const HighlightingRule &rule, highlightingRules) {
+ QRegExp expression(rule.pattern);
+ int index = text.indexOf(expression);
+ while (index >= 0) {
+ int length = expression.matchedLength();
+ setFormat(index, length, rule.format);
+ index = text.indexOf(expression, index + length);
+ }
+ }
+ setCurrentBlockState(0);
+
+ int startIndex = 0;
+ if (previousBlockState() != 1)
+ startIndex = text.indexOf(commentStartExpression);
+
+ while (startIndex >= 0) {
+ int endIndex = text.indexOf(commentEndExpression, startIndex);
+ int commentLength;
+ if (endIndex == -1) {
+ setCurrentBlockState(1);
+ commentLength = text.length() - startIndex;
+ } else {
+ commentLength = endIndex - startIndex
+ + commentEndExpression.matchedLength();
+ }
+ setFormat(startIndex, commentLength, commentFormat);
+ startIndex = text.indexOf(commentStartExpression,
+ startIndex + commentLength);
+ }
+}
diff --git a/examples/xmlpatterns/shared/xmlsyntaxhighlighter.h b/examples/xmlpatterns/shared/xmlsyntaxhighlighter.h
new file mode 100644
index 0000000..5fe9aa4
--- /dev/null
+++ b/examples/xmlpatterns/shared/xmlsyntaxhighlighter.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef XMLSYNTAXHIGHLIGHTER_H
+#define XMLSYNTAXHIGHLIGHTER_H
+
+#include <QtGui/QSyntaxHighlighter>
+
+class XmlSyntaxHighlighter : public QSyntaxHighlighter
+{
+ public:
+ XmlSyntaxHighlighter(QTextDocument *parent = 0);
+
+ protected:
+ virtual void highlightBlock(const QString &text);
+
+ private:
+ struct HighlightingRule
+ {
+ QRegExp pattern;
+ QTextCharFormat format;
+ };
+ QVector<HighlightingRule> highlightingRules;
+
+ QRegExp commentStartExpression;
+ QRegExp commentEndExpression;
+
+ QTextCharFormat tagFormat;
+ QTextCharFormat attributeFormat;
+ QTextCharFormat attributeContentFormat;
+ QTextCharFormat commentFormat;
+};
+
+#endif
diff --git a/examples/xmlpatterns/trafficinfo/main.cpp b/examples/xmlpatterns/trafficinfo/main.cpp
new file mode 100644
index 0000000..97b2bf7
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+
+#include <QtGui/QApplication>
+
+int main(int argc, char **argv)
+{
+ QApplication app(argc, argv);
+
+ MainWindow window;
+ window.show();
+
+ return app.exec();
+}
diff --git a/examples/xmlpatterns/trafficinfo/mainwindow.cpp b/examples/xmlpatterns/trafficinfo/mainwindow.cpp
new file mode 100644
index 0000000..c4ca731
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/mainwindow.cpp
@@ -0,0 +1,181 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mainwindow.h"
+#include "stationdialog.h"
+
+#include <QtCore/QSettings>
+#include <QtCore/QTimer>
+#include <QtGui/QAction>
+#include <QtGui/QApplication>
+#include <QtGui/QBitmap>
+#include <QtGui/QLinearGradient>
+#include <QtGui/QMouseEvent>
+#include <QtGui/QPainter>
+
+MainWindow::MainWindow()
+ : QWidget(0, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint)
+{
+ QAction *quitAction = new QAction(tr("E&xit"), this);
+ quitAction->setShortcut(tr("Ctrl+Q"));
+ connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
+
+ QAction *configAction = new QAction(tr("&Select station..."), this);
+ configAction->setShortcut(tr("Ctrl+C"));
+ connect(configAction, SIGNAL(triggered()), this, SLOT(configure()));
+
+ addAction(configAction);
+ addAction(quitAction);
+
+ setContextMenuPolicy(Qt::ActionsContextMenu);
+
+ setWindowTitle(tr("Traffic Info Oslo"));
+
+ QTimer *timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(updateTimeInformation()));
+ timer->start(1000*60);
+
+ const QSettings settings("Qt Software", "trafficinfo");
+ m_station = StationInformation(settings.value("stationId", "03012130").toString(),
+ settings.value("stationName", "Nydalen [T-bane] (OSL)").toString());
+ m_lines = settings.value("lines", QStringList()).toStringList();
+
+ updateTimeInformation();
+}
+
+MainWindow::~MainWindow()
+{
+ QSettings settings("Qt Software", "trafficinfo");
+ settings.setValue("stationId", m_station.id());
+ settings.setValue("stationName", m_station.name());
+ settings.setValue("lines", m_lines);
+}
+
+QSize MainWindow::sizeHint() const
+{
+ return QSize(300, 200);
+}
+
+void MainWindow::mouseMoveEvent(QMouseEvent *event)
+{
+ if (event->buttons() & Qt::LeftButton) {
+ move(event->globalPos() - m_dragPosition);
+ event->accept();
+ }
+}
+
+void MainWindow::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ m_dragPosition = event->globalPos() - frameGeometry().topLeft();
+ event->accept();
+ }
+}
+
+void MainWindow::paintEvent(QPaintEvent*)
+{
+ QLinearGradient gradient(QPoint(width()/2, 0), QPoint(width()/2, height()));
+ const QColor qtGreen(102, 176, 54);
+ gradient.setColorAt(0, qtGreen.dark());
+ gradient.setColorAt(0.5, qtGreen);
+ gradient.setColorAt(1, qtGreen.dark());
+
+ QPainter p(this);
+ p.fillRect(0, 0, width(), height(), gradient);
+
+ QFont headerFont("Sans Serif", 12, QFont::Bold);
+ QFont normalFont("Sans Serif", 9, QFont::Normal);
+
+ // draw it twice for shadow effect
+ p.setFont(headerFont);
+ QRect headerRect(1, 1, width(), 25);
+ p.setPen(Qt::black);
+ p.drawText(headerRect, Qt::AlignCenter, m_station.name());
+
+ headerRect.moveTopLeft(QPoint(0, 0));
+ p.setPen(Qt::white);
+ p.drawText(headerRect, Qt::AlignCenter, m_station.name());
+
+ p.setFont(normalFont);
+ int pos = 40;
+ for (int i = 0; i < m_times.count() && i < 9; ++i) {
+ p.setPen(Qt::black);
+ p.drawText(51, pos + 1, m_times.at(i).time());
+ p.drawText(101, pos + 1, m_times.at(i).direction());
+
+ p.setPen(Qt::white);
+ p.drawText(50, pos, m_times.at(i).time());
+ p.drawText(100, pos, m_times.at(i).direction());
+
+ pos += 18;
+ }
+}
+
+void MainWindow::resizeEvent(QResizeEvent*)
+{
+ QBitmap maskBitmap(width(), height());
+ maskBitmap.clear();
+
+ QPainter p(&maskBitmap);
+ p.setBrush(Qt::black);
+ p.drawRoundRect(0, 0, width(), height(), 20, 30);
+ p.end();
+
+ setMask(maskBitmap);
+}
+
+void MainWindow::updateTimeInformation()
+{
+ TimeQuery query;
+ m_times = query.query(m_station.id(), m_lines, QDateTime::currentDateTime());
+
+ update();
+}
+
+void MainWindow::configure()
+{
+ StationDialog dlg(m_station.name(), m_lines, this);
+ if (dlg.exec()) {
+ m_station = dlg.selectedStation();
+ m_lines = dlg.lineNumbers();
+ updateTimeInformation();
+ }
+}
diff --git a/examples/xmlpatterns/trafficinfo/mainwindow.h b/examples/xmlpatterns/trafficinfo/mainwindow.h
new file mode 100644
index 0000000..d48109d
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/mainwindow.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include "stationquery.h"
+#include "timequery.h"
+
+#include <QtGui/QWidget>
+
+class MainWindow : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ MainWindow();
+ ~MainWindow();
+
+ QSize sizeHint() const;
+
+ protected:
+ void mouseMoveEvent(QMouseEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event);
+ void resizeEvent(QResizeEvent *event);
+
+ private Q_SLOTS:
+ void updateTimeInformation();
+ void configure();
+
+ private:
+ QPoint m_dragPosition;
+ TimeInformation::List m_times;
+ StationInformation m_station;
+ QStringList m_lines;
+};
+
+#endif
diff --git a/examples/xmlpatterns/trafficinfo/station_example.wml b/examples/xmlpatterns/trafficinfo/station_example.wml
new file mode 100644
index 0000000..da7f82f
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/station_example.wml
@@ -0,0 +1,31 @@
+//! [0]
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
+<wml>
+<template>
+ <do type="prev" name="b" label="Tilbake"><prev/></do>
+ <do type="options" label="Nytt søk"><go href="velkommen.wml"/></do>
+</template>
+<card id="Liste" title="Trafikanten">
+<p>
+<small>
+Velg stoppsted: <br />
+
+ <a title="Velg" href="DateLink.asp?fra=05280320">Nydalen (Østre Toten) (Ø-T)</a><br />
+
+ <a title="Velg" href="DateLink.asp?fra=03012126">Nydalen st. (i Store ringvei) (OSL)</a><br />
+
+ <a title="Velg" href="DateLink.asp?fra=03012131">Nydalen T [buss] (OSL)</a><br />
+
+ <a title="Velg" href="DateLink.asp?fra=03012130">Nydalen [T-bane] (OSL)</a><br />
+
+ <a title="Velg" href="DateLink.asp?fra=03012125">Nydalen [tog] (OSL)</a><br />
+
+<br/>
+<a title="Nytt søk" href="Velkommen.wml">"Nytt søk"</a>
+<br/>
+</small>
+</p>
+</card>
+</wml>
+//! [0]
diff --git a/examples/xmlpatterns/trafficinfo/stationdialog.cpp b/examples/xmlpatterns/trafficinfo/stationdialog.cpp
new file mode 100644
index 0000000..9876bdb
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/stationdialog.cpp
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "stationdialog.h"
+#include "ui_stationdialog.h"
+
+#include <QtCore/QAbstractListModel>
+
+class StationModel : public QAbstractListModel
+{
+ public:
+ enum Role
+ {
+ StationIdRole = Qt::UserRole + 1,
+ StationNameRole
+ };
+
+ StationModel(QObject *parent = 0)
+ : QAbstractListModel(parent)
+ {
+ }
+
+ void setStations(const StationInformation::List &list)
+ {
+ m_stations = list;
+ layoutChanged();
+ }
+
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const
+ {
+ if (!parent.isValid())
+ return m_stations.count();
+ else
+ return 0;
+ }
+
+ virtual int columnCount(const QModelIndex &parent = QModelIndex()) const
+ {
+ if (!parent.isValid())
+ return 1;
+ else
+ return 0;
+ }
+
+ virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
+ {
+ if (!index.isValid())
+ return QVariant();
+
+ if (index.column() > 1 || index.row() >= m_stations.count())
+ return QVariant();
+
+ const StationInformation info = m_stations.at(index.row());
+ if (role == Qt::DisplayRole || role == StationNameRole)
+ return info.name();
+ else if (role == StationIdRole)
+ return info.id();
+
+ return QVariant();
+ }
+
+ private:
+ StationInformation::List m_stations;
+};
+
+StationDialog::StationDialog(const QString &name, const QStringList &lineNumbers, QWidget *parent)
+ : QDialog(parent)
+{
+ m_ui.setupUi(this);
+
+ connect(m_ui.m_searchButton, SIGNAL(clicked()), this, SLOT(searchStations()));
+
+ m_ui.m_searchButton->setDefault(true);
+ m_ui.m_input->setText(name);
+
+ m_model = new StationModel(this);
+ m_ui.m_view->setModel(m_model);
+
+ for (int i = 0; i < lineNumbers.count(); ++i) {
+ if (i == 0)
+ m_ui.m_line1->setText(lineNumbers.at(i));
+ else if (i == 1)
+ m_ui.m_line2->setText(lineNumbers.at(i));
+ else if (i == 2)
+ m_ui.m_line3->setText(lineNumbers.at(i));
+ else if (i == 3)
+ m_ui.m_line4->setText(lineNumbers.at(i));
+ }
+
+ searchStations();
+}
+
+StationInformation StationDialog::selectedStation() const
+{
+ const QModelIndex index = m_ui.m_view->currentIndex();
+
+ if (!index.isValid())
+ return StationInformation();
+
+ return StationInformation(index.data(StationModel::StationIdRole).toString(),
+ index.data(StationModel::StationNameRole).toString());
+}
+
+QStringList StationDialog::lineNumbers() const
+{
+ QStringList lines;
+
+ if (!m_ui.m_line1->text().simplified().isEmpty())
+ lines.append(m_ui.m_line1->text().simplified());
+ if (!m_ui.m_line2->text().simplified().isEmpty())
+ lines.append(m_ui.m_line2->text().simplified());
+ if (!m_ui.m_line3->text().simplified().isEmpty())
+ lines.append(m_ui.m_line3->text().simplified());
+ if (!m_ui.m_line4->text().simplified().isEmpty())
+ lines.append(m_ui.m_line4->text().simplified());
+
+ return lines;
+}
+
+void StationDialog::searchStations()
+{
+ StationQuery query;
+
+ m_model->setStations(query.query(m_ui.m_input->text()));
+ m_ui.m_view->keyboardSearch(m_ui.m_input->text());
+}
diff --git a/examples/xmlpatterns/trafficinfo/stationdialog.h b/examples/xmlpatterns/trafficinfo/stationdialog.h
new file mode 100644
index 0000000..5ac1635
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/stationdialog.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STATIONDIALOG_H
+#define STATIONDIALOG_H
+
+#include <QtGui/QDialog>
+
+#include "stationquery.h"
+#include "ui_stationdialog.h"
+
+class StationModel;
+
+class StationDialog : public QDialog
+{
+ Q_OBJECT
+
+ public:
+ StationDialog(const QString &id, const QStringList &lineNumbers, QWidget *parent);
+
+ StationInformation selectedStation() const;
+ QStringList lineNumbers() const;
+
+ private Q_SLOTS:
+ void searchStations();
+
+ private:
+ Ui_StationDialog m_ui;
+ StationModel *m_model;
+};
+
+#endif
diff --git a/examples/xmlpatterns/trafficinfo/stationdialog.ui b/examples/xmlpatterns/trafficinfo/stationdialog.ui
new file mode 100644
index 0000000..254dedb
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/stationdialog.ui
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>StationDialog</class>
+ <widget class="QDialog" name="StationDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>462</width>
+ <height>391</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Select Station</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QLineEdit" name="m_input"/>
+ </item>
+ <item row="0" column="1">
+ <widget class="QPushButton" name="m_searchButton">
+ <property name="text">
+ <string>Search</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="2">
+ <widget class="QListView" name="m_view"/>
+ </item>
+ <item row="2" column="0" colspan="2">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Lines:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="m_line1"/>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="m_line2"/>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="m_line3"/>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="m_line4"/>
+ </item>
+ </layout>
+ </item>
+ <item row="3" column="0" colspan="2">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>StationDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>228</x>
+ <y>373</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>StationDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>296</x>
+ <y>372</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/examples/xmlpatterns/trafficinfo/stationquery.cpp b/examples/xmlpatterns/trafficinfo/stationquery.cpp
new file mode 100644
index 0000000..ab42ad9
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/stationquery.cpp
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "stationquery.h"
+
+#include <QtCore/QStringList>
+#include <QtXmlPatterns/QXmlQuery>
+
+StationInformation::StationInformation()
+{
+}
+
+StationInformation::StationInformation(const QString &id, const QString &name)
+ : m_id(id), m_name(name)
+{
+}
+
+QString StationInformation::id() const
+{
+ return m_id;
+}
+
+QString StationInformation::name() const
+{
+ return m_name;
+}
+
+//! [0]
+StationInformation::List StationQuery::query(const QString &name)
+{
+ const QString stationIdQueryUrl = QString("doc(concat('http://wap.trafikanten.no/FromLink1.asp?fra=', $station))/wml/card/p/small/a[@title='Velg']/substring(@href,18)");
+ const QString stationNameQueryUrl = QString("doc(concat('http://wap.trafikanten.no/FromLink1.asp?fra=', $station))/wml/card/p/small/a[@title='Velg']/string()");
+
+ QStringList stationIds;
+ QStringList stationNames;
+
+ QXmlQuery query;
+
+ query.bindVariable("station", QVariant(QString::fromLatin1(QUrl::toPercentEncoding(name))));
+ query.setQuery(stationIdQueryUrl);
+ query.evaluateTo(&stationIds);
+
+ query.bindVariable("station", QVariant(QString::fromLatin1(QUrl::toPercentEncoding(name))));
+ query.setQuery(stationNameQueryUrl);
+ query.evaluateTo(&stationNames);
+
+ if (stationIds.count() != stationNames.count()) // something went wrong...
+ return StationInformation::List();
+
+ StationInformation::List information;
+ for (int i = 0; i < stationIds.count(); ++i)
+ information.append(StationInformation(stationIds.at(i), stationNames.at(i)));
+
+ return information;
+}
+//! [0]
diff --git a/examples/xmlpatterns/trafficinfo/stationquery.h b/examples/xmlpatterns/trafficinfo/stationquery.h
new file mode 100644
index 0000000..5cbf28a
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/stationquery.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef STATIONQUERY_H
+#define STATIONQUERY_H
+
+#include <QtCore/QList>
+#include <QtCore/QString>
+
+//! [0]
+class StationInformation
+{
+ public:
+ typedef QList<StationInformation> List;
+
+ StationInformation();
+ StationInformation(const QString &id, const QString &name);
+
+ QString id() const;
+ QString name() const;
+
+ private:
+ QString m_id;
+ QString m_name;
+};
+//! [0]
+
+//! [1]
+class StationQuery
+{
+ public:
+ static StationInformation::List query(const QString &name);
+};
+//! [1]
+
+#endif
diff --git a/examples/xmlpatterns/trafficinfo/time_example.wml b/examples/xmlpatterns/trafficinfo/time_example.wml
new file mode 100644
index 0000000..75e3408
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/time_example.wml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
+<wml>
+<template>
+ <do type="prev" name="b" label="Tilbake"><prev/></do>
+ <do type="options" name="n" label="Nytt søk"><go href="velkommen.wml"/></do>
+</template>
+<card id="Liste" title="Trafikanten">
+<p>
+<small>
+Fra Nydalen [T-bane]:<br />
+
+ <a href="Rute.asp?d=3011030&amp;t=21832&amp;l=4&amp;Start=1">13.00</a>
+ 4 Bergkrystallen [T-bane]<br />
+
+ <a href="Rute.asp?d=3012585&amp;t=22543&amp;l=6&amp;Start=1">13.05</a>
+ 6 Åsjordet<br />
+
+ <a href="Rute.asp?d=3011730&amp;t=22264&amp;l=5&amp;Start=1">13.09</a>
+ 5 Vestli [T-bane]<br />
+
+ <a href="Rute.asp?d=3012120&amp;t=22080&amp;l=5&amp;Start=1">13.13</a>
+ 5 Storo [T-bane]<br />
+
+ <a href="Rute.asp?d=3011030&amp;t=21831&amp;l=4&amp;Start=1">13.15</a>
+ 4 Bergkrystallen [T-bane]<br />
+
+ <a href="Rute.asp?d=3012585&amp;t=22542&amp;l=6&amp;Start=1">13.20</a>
+ 6 Åsjordet<br />
+
+ <a href="Rute.asp?d=3011730&amp;t=22263&amp;l=5&amp;Start=1">13.24</a>
+ 5 Vestli [T-bane]<br />
+
+ <a href="Rute.asp?d=3012120&amp;t=22079&amp;l=5&amp;Start=1">13.28</a>
+ 5 Storo [T-bane]<br />
+
+ <a href="Rute.asp?d=3011030&amp;t=21830&amp;l=4&amp;Start=1">13.30</a>
+ 4 Bergkrystallen [T-bane]<br />
+
+ <a href="Rute.asp?d=3012585&amp;t=22541&amp;l=6&amp;Start=1">13.35</a>
+ 6 Åsjordet<br />
+
+ <br />
+ <a title="Neste 10" href="F.asp?f=03012130&amp;t=13&amp;m=35&amp;d=14.11.2008&amp;Start=11">Neste 10 avganger</a>
+
+<br/>
+<a href="F.asp?f=03012130&amp;t=14&amp;d=14.11.2008&amp;Start=1">Neste timeintervall</a>
+<br/>
+<a href="F.asp?f=03012130&amp;t=12&amp;d=14.11.2008&amp;Start=1">Forrige timeintervall</a>
+<br/>
+<a href="Velkommen.wml">"Nytt søk"</a>
+<br/>
+</small>
+</p>
+</card>
+</wml>
diff --git a/examples/xmlpatterns/trafficinfo/timequery.cpp b/examples/xmlpatterns/trafficinfo/timequery.cpp
new file mode 100644
index 0000000..bd63560
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/timequery.cpp
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "timequery.h"
+
+#include <QtCore/QStringList>
+#include <QtXmlPatterns/QXmlQuery>
+
+TimeInformation::TimeInformation(const QString &time, const QString &direction)
+ : m_time(time), m_direction(direction)
+{
+}
+
+QString TimeInformation::time() const
+{
+ return m_time;
+}
+
+QString TimeInformation::direction() const
+{
+ return m_direction;
+}
+
+TimeInformation::List TimeQuery::query(const QString &stationId, const QStringList &lineNumbers, const QDateTime &dateTime)
+{
+ const TimeInformation::List information = queryInternal(stationId, dateTime);
+
+ TimeInformation::List filteredInformation;
+
+ if (!lineNumbers.isEmpty()) {
+ for (int i = 0; i < information.count(); ++i) {
+ const TimeInformation info = information.at(i);
+ for (int j = 0; j < lineNumbers.count(); ++j) {
+ if (info.direction().startsWith(QString("%1 ").arg(lineNumbers.at(j))))
+ filteredInformation.append(info);
+ }
+ }
+ } else {
+ filteredInformation = information;
+ }
+
+ return filteredInformation;
+}
+
+//! [1]
+TimeInformation::List TimeQuery::queryInternal(const QString &stationId, const QDateTime &dateTime)
+{
+ const QString timesQueryUrl = QString("doc('http://wap.trafikanten.no/F.asp?f=%1&amp;t=%2&amp;m=%3&amp;d=%4&amp;start=1')/wml/card/p/small/a[fn:starts-with(@href, 'Rute')]/string()")
+ .arg(stationId)
+ .arg(dateTime.time().hour())
+ .arg(dateTime.time().minute())
+ .arg(dateTime.toString("dd.MM.yyyy"));
+ const QString directionsQueryUrl = QString("doc('http://wap.trafikanten.no/F.asp?f=%1&amp;t=%2&amp;m=%3&amp;d=%4&amp;start=1')/wml/card/p/small/text()[matches(., '[0-9].*')]/string()")
+ .arg(stationId)
+ .arg(dateTime.time().hour())
+ .arg(dateTime.time().minute())
+ .arg(dateTime.toString("dd.MM.yyyy"));
+
+ QStringList times;
+ QStringList directions;
+
+ QXmlQuery query;
+ query.setQuery(timesQueryUrl);
+ query.evaluateTo(&times);
+
+ query.setQuery(directionsQueryUrl);
+ query.evaluateTo(&directions);
+
+ if (times.count() != directions.count()) // something went wrong...
+ return TimeInformation::List();
+
+ TimeInformation::List information;
+ for (int i = 0; i < times.count(); ++i)
+ information.append(TimeInformation(times.at(i).simplified(), directions.at(i).simplified()));
+
+ return information;
+}
+//! [1]
diff --git a/examples/xmlpatterns/trafficinfo/timequery.h b/examples/xmlpatterns/trafficinfo/timequery.h
new file mode 100644
index 0000000..f88e62c
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/timequery.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TIMEQUERY_H
+#define TIMEQUERY_H
+
+#include <QtCore/QDateTime>
+#include <QtCore/QList>
+#include <QtCore/QStringList>
+
+class TimeInformation
+{
+ public:
+ typedef QList<TimeInformation> List;
+
+ TimeInformation(const QString &time, const QString &direction);
+
+ QString time() const;
+ QString direction() const;
+
+ private:
+ QString m_time;
+ QString m_direction;
+};
+
+
+class TimeQuery
+{
+ public:
+ static TimeInformation::List query(const QString &stationId, const QStringList &lineNumbers, const QDateTime &dateTime);
+
+ private:
+ static TimeInformation::List queryInternal(const QString &stationId, const QDateTime &dateTime);
+};
+
+#endif
diff --git a/examples/xmlpatterns/trafficinfo/trafficinfo.pro b/examples/xmlpatterns/trafficinfo/trafficinfo.pro
new file mode 100644
index 0000000..52bcc19
--- /dev/null
+++ b/examples/xmlpatterns/trafficinfo/trafficinfo.pro
@@ -0,0 +1,9 @@
+QT += xmlpatterns
+HEADERS = mainwindow.h stationdialog.h stationquery.h timequery.h
+SOURCES = main.cpp mainwindow.cpp stationdialog.cpp stationquery.cpp timequery.cpp
+FORMS = stationdialog.ui
+
+target.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/trafficinfo
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/trafficinfo
+INSTALLS += target sources
diff --git a/examples/xmlpatterns/xmlpatterns.pro b/examples/xmlpatterns/xmlpatterns.pro
new file mode 100644
index 0000000..081abde
--- /dev/null
+++ b/examples/xmlpatterns/xmlpatterns.pro
@@ -0,0 +1,16 @@
+TEMPLATE = subdirs
+SUBDIRS = recipes \
+ trafficinfo \
+ xquery \
+ filetree
+
+# This example depends on QtWebkit as well.
+contains(QT_CONFIG, webkit):SUBDIRS += qobjectxmlmodel
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS xmlpatterns.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/xmlpatterns/xquery/globalVariables/globalVariables.pro b/examples/xmlpatterns/xquery/globalVariables/globalVariables.pro
new file mode 100644
index 0000000..0016c41
--- /dev/null
+++ b/examples/xmlpatterns/xquery/globalVariables/globalVariables.pro
@@ -0,0 +1,11 @@
+# We don't have any C++ files to build, so in order to trick qmake which
+# doesn't understand that, we use the subdirs template, but without specifying
+# any subdirs.
+TEMPLATE = subdirs
+
+target.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/xquery/globalVariables
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.cpp *.pro *.xq *.html globals.gccxml
+sources.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/xquery/globalVariables
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/xmlpatterns/xquery/globalVariables/globals.cpp b/examples/xmlpatterns/xquery/globalVariables/globals.cpp
new file mode 100644
index 0000000..7ecd9ed
--- /dev/null
+++ b/examples/xmlpatterns/xquery/globalVariables/globals.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+ 1. int mutablePrimitive1;
+ 2. int mutablePrimitive2;
+ 3. const int constPrimitive1 = 4;
+ 4. const int constPrimitive2 = 3;
+ 5.
+ 6. class ComplexClass
+ 7. {
+ 8. public:
+ 9. ComplexClass();
+10. ComplexClass(const ComplexClass &);
+11. ~ComplexClass();
+12. };
+13.
+14. ComplexClass mutableComplex1;
+15. ComplexClass mutableComplex2;
+16. const ComplexClass constComplex1;
+17. const ComplexClass constComplex2;
+18.
+19. int main()
+20. {
+22. int localVariable;
+23. localVariable = 0;
+24. return localVariable;
+25. }
+//! [0]
diff --git a/examples/xmlpatterns/xquery/globalVariables/globals.gccxml b/examples/xmlpatterns/xquery/globalVariables/globals.gccxml
new file mode 100644
index 0000000..81bcb22
--- /dev/null
+++ b/examples/xmlpatterns/xquery/globalVariables/globals.gccxml
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<GCC_XML>
+ <Namespace id="_1" name="::" members="_3 _4 _5 _6 _7 _8 _9 _10 _11 _12 _13 _14 _15 " mangled="_Z2::"/>
+ <Namespace id="_2" name="std" context="_1" members="" mangled="_Z3std"/>
+ <Function id="_3" name="_GLOBAL__D_globals.cppwVRo3a" returns="_16" context="_1" location="f0:14" file="f0" line="14" endline="14"/>
+ <Function id="_4" name="_GLOBAL__I_globals.cppwVRo3a" returns="_16" context="_1" location="f0:14" file="f0" line="14" endline="14"/>
+ <Function id="_5" name="__static_initialization_and_destruction_0" returns="_16" context="_1" mangled="_Z41__static_initialization_and_destruction_0ii" location="f0:23" file="f0" line="23" endline="14">
+ <Argument name="__initialize_p" type="_17"/>
+ <Argument name="__priority" type="_17"/>
+ </Function>
+ <Function id="_6" name="main" returns="_17" context="_1" location="f0:20" file="f0" line="20" endline="24"/>
+ <Variable id="_7" name="constComplex2" type="_11c" context="_1" location="f0:17" file="f0" line="17"/>
+ <Variable id="_8" name="constComplex1" type="_11c" context="_1" location="f0:16" file="f0" line="16"/>
+ <Variable id="_9" name="mutableComplex2" type="_11" context="_1" location="f0:15" file="f0" line="15"/>
+ <Variable id="_10" name="mutableComplex1" type="_11" context="_1" location="f0:14" file="f0" line="14"/>
+ <Class id="_11" name="ComplexClass" context="_1" mangled="12ComplexClass" location="f0:7" file="f0" line="7" members="_19 _20 _21 " bases=""/>
+ <Variable id="_12" name="constPrimitive2" type="_17c" init="3" context="_1" location="f0:4" file="f0" line="4"/>
+ <Variable id="_13" name="constPrimitive1" type="_17c" init="4" context="_1" location="f0:3" file="f0" line="3"/>
+ <Variable id="_14" name="mutablePrimitive2" type="_17" context="_1" location="f0:2" file="f0" line="2"/>
+ <Variable id="_15" name="mutablePrimitive1" type="_17" context="_1" location="f0:1" file="f0" line="1"/>
+ <FundamentalType id="_16" name="void"/>
+ <FundamentalType id="_17" name="int"/>
+ <CvQualifiedType id="_11c" type="_11" const="1"/>
+ <Constructor id="_19" name="ComplexClass" context="_11" mangled="_ZN12ComplexClassC1Ev *INTERNAL* " location="f0:9" file="f0" line="9" extern="1"/>
+ <Constructor id="_20" name="ComplexClass" context="_11" mangled="_ZN12ComplexClassC1ERKS_ *INTERNAL* " location="f0:10" file="f0" line="10" extern="1">
+ <Argument type="_23"/>
+ </Constructor>
+ <Destructor id="_21" name="ComplexClass" context="_11" mangled="_ZN12ComplexClassD1Ev *INTERNAL* " location="f0:11" file="f0" line="11" extern="1">
+ </Destructor>
+ <CvQualifiedType id="_17c" type="_17" const="1"/>
+ <ReferenceType id="_23" type="_11c"/>
+ <File id="f0" name="globals.cpp"/>
+</GCC_XML>
diff --git a/examples/xmlpatterns/xquery/globalVariables/globals.html b/examples/xmlpatterns/xquery/globalVariables/globals.html
new file mode 100644
index 0000000..d8affc8
--- /dev/null
+++ b/examples/xmlpatterns/xquery/globalVariables/globals.html
@@ -0,0 +1,40 @@
+<html xmlns="http://www.w3.org/1999/xhtml/" xml:lang="en" lang="en">
+ <head>
+ <title>Global variables report for globals.gccxml</title>
+ </head>
+ <style type="text/css">
+ .details
+ {
+ text-align: center;
+ font-size: 80%;
+ color: blue
+ }
+ .variableName
+ {
+ font-family: courier;
+ color: blue
+ }
+ </style>
+ <body>
+ <p class="details">Start report: 2008-12-16T13:43:49.65Z</p>
+ <p>Global variables with complex types:</p>
+ <ol>
+ <li>
+ <span class="variableName">mutableComplex1</span> in globals.cpp at line 14</li>
+ <li>
+ <span class="variableName">mutableComplex2</span> in globals.cpp at line 15</li>
+ <li>
+ <span class="variableName">constComplex1</span> in globals.cpp at line 16</li>
+ <li>
+ <span class="variableName">constComplex2</span> in globals.cpp at line 17</li>
+ </ol>
+ <p>Mutable global variables with primitives types:</p>
+ <ol>
+ <li>
+ <span class="variableName">mutablePrimitive1</span> in globals.cpp at line 1</li>
+ <li>
+ <span class="variableName">mutablePrimitive2</span> in globals.cpp at line 2</li>
+ </ol>
+ <p class="details">End report: 2008-12-16T13:43:49.65Z</p>
+ </body>
+</html>
diff --git a/examples/xmlpatterns/xquery/globalVariables/reportGlobals.xq b/examples/xmlpatterns/xquery/globalVariables/reportGlobals.xq
new file mode 100644
index 0000000..026679d
--- /dev/null
+++ b/examples/xmlpatterns/xquery/globalVariables/reportGlobals.xq
@@ -0,0 +1,110 @@
+(:
+ This XQuery loads a GCC-XML file and reports the locations of all
+ global variables in the original C++ source. To run the query,
+ use the command line:
+
+ xmlpatterns reportGlobals.xq -param fileToOpen=globals.gccxml -output globals.html
+
+ "fileToOpen=globals.gccxml" binds the file name "globals.gccxml"
+ to the variable "fileToOpen" declared and used below.
+:)
+
+declare variable $fileToOpen as xs:anyURI external;
+declare variable $inDoc as document-node() := doc($fileToOpen);
+
+(:
+ This function determines whether the typeId is a complex type,
+ e.g. QString. We only check whether it's a class. To be strictly
+ correct, we should check whether the class has a non-synthesized
+ constructor. We accept both mutable and const types.
+:)
+declare function local:isComplexType($typeID as xs:string) as xs:boolean
+{
+ exists($inDoc/GCC_XML/Class[@id = $typeID])
+ or
+ exists($inDoc/GCC_XML/Class[@id = $inDoc/GCC_XML/CvQualifiedType[@id = $typeID]/@type])
+};
+
+(:
+ This function determines whether the typeId is a primitive type.
+:)
+declare function local:isPrimitive($typeId as xs:string) as xs:boolean
+{
+ exists($inDoc/GCC_XML/FundamentalType[@id = $typeId])
+};
+
+(:
+ This function constructs a line for the report. The line contains
+ a variable name, the source file, and the line number.
+:)
+declare function local:location($block as element()) as xs:string
+{
+ concat($inDoc/GCC_XML/File[@id = $block/@file]/@name, " at line ", $block/@line)
+};
+
+(:
+ This function generates the report. Note that it is called once
+ in the <body> element of the <html> output.
+
+ It ignores const variables of simple types but reports all others.
+:)
+declare function local:report() as element()+
+{
+ let $complexVariables as element(Variable)* := $inDoc/GCC_XML/Variable[local:isComplexType(@type)]
+ return if (exists($complexVariables))
+ then (<p xmlns="http://www.w3.org/1999/xhtml/">Global variables with complex types:</p>,
+ <ol xmlns="http://www.w3.org/1999/xhtml/">
+ {
+ (: For each Variable in $complexVariables... :)
+ $complexVariables/<li><span class="variableName">{string(@name)}</span> in {local:location(.)}</li>
+ }
+ </ol>)
+ else <p xmlns="http://www.w3.org/1999/xhtml/">No complex global variables found.</p>
+
+ ,
+
+ let $primitiveVariables as element(Variable)+ := $inDoc/GCC_XML/Variable[local:isPrimitive(@type)]
+ return if (exists($primitiveVariables))
+ then (<p xmlns="http://www.w3.org/1999/xhtml/">Mutable global variables with primitives types:</p>,
+ <ol xmlns="http://www.w3.org/1999/xhtml/">
+ {
+ (: For each Variable in $complexVariables... :)
+ $primitiveVariables/<li><span class="variableName">{string(@name)}</span> in {local:location(.)}</li>
+ }
+ </ol>)
+ else <p xmlns="http://www.w3.org/1999/xhtml/">No mutable primitive global variables found.</p>
+};
+
+(:
+ This is where the <html> report is output. First
+ there is some style stuff, then the <body> element,
+ which contains the call to the \c{local:report()}
+ declared above.
+:)
+<html xmlns="http://www.w3.org/1999/xhtml/" xml:lang="en" lang="en">
+ <head>
+ <title>Global variables report for {$fileToOpen}</title>
+ </head>
+ <style type="text/css">
+ .details
+ {{
+ text-align: left;
+ font-size: 80%;
+ color: blue
+ }}
+ .variableName
+ {{
+ font-family: courier;
+ color: blue
+ }}
+ </style>
+
+ <body>
+ <p class="details">Start report: {current-dateTime()}</p>
+ {
+ local:report()
+ }
+ <p class="details">End report: {current-dateTime()}</p>
+ </body>
+
+</html>
diff --git a/examples/xmlpatterns/xquery/xquery.pro b/examples/xmlpatterns/xquery/xquery.pro
new file mode 100644
index 0000000..2a91188
--- /dev/null
+++ b/examples/xmlpatterns/xquery/xquery.pro
@@ -0,0 +1,10 @@
+TEMPLATE = subdirs
+SUBDIRS += globalVariables
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/xquery
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS xquery.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/xmlpatterns/xquery
+INSTALLS += target sources
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)