summaryrefslogtreecommitdiffstats
path: root/examples/xmlpatterns/recipes
diff options
context:
space:
mode:
Diffstat (limited to 'examples/xmlpatterns/recipes')
-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.cpp53
-rw-r--r--examples/xmlpatterns/recipes/querymainwindow.cpp123
-rw-r--r--examples/xmlpatterns/recipes/querymainwindow.h71
-rw-r--r--examples/xmlpatterns/recipes/recipes.pro16
-rw-r--r--examples/xmlpatterns/recipes/recipes.qrc10
12 files changed, 514 insertions, 0 deletions
diff --git a/examples/xmlpatterns/recipes/files/allRecipes.xq b/examples/xmlpatterns/recipes/files/allRecipes.xq
new file mode 100644
index 00000000..6888c310
--- /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 00000000..3b6f621f
--- /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 00000000..3baecd8d
--- /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 00000000..b1fee349
--- /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 00000000..d74a4eb9
--- /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 00000000..cb4217ff
--- /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 00000000..fb2ab642
--- /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 00000000..cf679f5a
--- /dev/null
+++ b/examples/xmlpatterns/recipes/main.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $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 00000000..95a86699
--- /dev/null
+++ b/examples/xmlpatterns/recipes/querymainwindow.cpp
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtXmlPatterns>
+
+#include "querymainwindow.h"
+#include "xmlsyntaxhighlighter.h"
+
+//! [0]
+QueryMainWindow::QueryMainWindow() : ui_defaultQueries(0)
+{
+ setupUi(this);
+
+ new XmlSyntaxHighlighter(findChild<QTextEdit*>("inputTextEdit")->document());
+ new XmlSyntaxHighlighter(findChild<QTextEdit*>("outputTextEdit")->document());
+
+ ui_defaultQueries = findChild<QComboBox*>("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()));
+ findChild<QTextEdit*>("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();
+ findChild<QTextEdit*>("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();
+ findChild<QTextEdit*>("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 00000000..675b0476
--- /dev/null
+++ b/examples/xmlpatterns/recipes/querymainwindow.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $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 00000000..4c10227b
--- /dev/null
+++ b/examples/xmlpatterns/recipes/recipes.pro
@@ -0,0 +1,16 @@
+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]/qtxmlpatterns/xmlpatterns/recipes
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.xq *.html forms files
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtxmlpatterns/xmlpatterns/recipes
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000D7C5
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/xmlpatterns/recipes/recipes.qrc b/examples/xmlpatterns/recipes/recipes.qrc
new file mode 100644
index 00000000..65b6615c
--- /dev/null
+++ b/examples/xmlpatterns/recipes/recipes.qrc
@@ -0,0 +1,10 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <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>