diff options
Diffstat (limited to 'examples/xmlpatterns/trafficinfo')
-rw-r--r-- | examples/xmlpatterns/trafficinfo/main.cpp | 54 | ||||
-rw-r--r-- | examples/xmlpatterns/trafficinfo/mainwindow.cpp | 181 | ||||
-rw-r--r-- | examples/xmlpatterns/trafficinfo/mainwindow.h | 77 | ||||
-rw-r--r-- | examples/xmlpatterns/trafficinfo/station_example.wml | 31 | ||||
-rw-r--r-- | examples/xmlpatterns/trafficinfo/stationdialog.cpp | 164 | ||||
-rw-r--r-- | examples/xmlpatterns/trafficinfo/stationdialog.h | 70 | ||||
-rw-r--r-- | examples/xmlpatterns/trafficinfo/stationdialog.ui | 104 | ||||
-rw-r--r-- | examples/xmlpatterns/trafficinfo/stationquery.cpp | 94 | ||||
-rw-r--r-- | examples/xmlpatterns/trafficinfo/stationquery.h | 74 | ||||
-rw-r--r-- | examples/xmlpatterns/trafficinfo/time_example.wml | 56 | ||||
-rw-r--r-- | examples/xmlpatterns/trafficinfo/timequery.cpp | 116 | ||||
-rw-r--r-- | examples/xmlpatterns/trafficinfo/timequery.h | 74 | ||||
-rw-r--r-- | examples/xmlpatterns/trafficinfo/trafficinfo.pro | 9 |
13 files changed, 1104 insertions, 0 deletions
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&t=21832&l=4&Start=1">13.00</a> + 4 Bergkrystallen [T-bane]<br /> + + <a href="Rute.asp?d=3012585&t=22543&l=6&Start=1">13.05</a> + 6 Åsjordet<br /> + + <a href="Rute.asp?d=3011730&t=22264&l=5&Start=1">13.09</a> + 5 Vestli [T-bane]<br /> + + <a href="Rute.asp?d=3012120&t=22080&l=5&Start=1">13.13</a> + 5 Storo [T-bane]<br /> + + <a href="Rute.asp?d=3011030&t=21831&l=4&Start=1">13.15</a> + 4 Bergkrystallen [T-bane]<br /> + + <a href="Rute.asp?d=3012585&t=22542&l=6&Start=1">13.20</a> + 6 Åsjordet<br /> + + <a href="Rute.asp?d=3011730&t=22263&l=5&Start=1">13.24</a> + 5 Vestli [T-bane]<br /> + + <a href="Rute.asp?d=3012120&t=22079&l=5&Start=1">13.28</a> + 5 Storo [T-bane]<br /> + + <a href="Rute.asp?d=3011030&t=21830&l=4&Start=1">13.30</a> + 4 Bergkrystallen [T-bane]<br /> + + <a href="Rute.asp?d=3012585&t=22541&l=6&Start=1">13.35</a> + 6 Åsjordet<br /> + + <br /> + <a title="Neste 10" href="F.asp?f=03012130&t=13&m=35&d=14.11.2008&Start=11">Neste 10 avganger</a> + +<br/> +<a href="F.asp?f=03012130&t=14&d=14.11.2008&Start=1">Neste timeintervall</a> +<br/> +<a href="F.asp?f=03012130&t=12&d=14.11.2008&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&t=%2&m=%3&d=%4&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&t=%2&m=%3&d=%4&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(×); + + 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 |