summaryrefslogtreecommitdiffstats
path: root/examples/sql/drilldown
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit38be0d13830efd2d98281c645c3a60afe05ffece (patch)
tree6ea73f3ec77f7d153333779883e8120f82820abe /examples/sql/drilldown
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'examples/sql/drilldown')
-rw-r--r--examples/sql/drilldown/drilldown.pro21
-rw-r--r--examples/sql/drilldown/drilldown.qrc11
-rw-r--r--examples/sql/drilldown/imageitem.cpp123
-rw-r--r--examples/sql/drilldown/imageitem.h74
-rw-r--r--examples/sql/drilldown/images/beijing.pngbin0 -> 99093 bytes
-rw-r--r--examples/sql/drilldown/images/berlin.pngbin0 -> 81944 bytes
-rw-r--r--examples/sql/drilldown/images/brisbane.pngbin0 -> 57785 bytes
-rw-r--r--examples/sql/drilldown/images/munich.pngbin0 -> 59769 bytes
-rw-r--r--examples/sql/drilldown/images/oslo.pngbin0 -> 41781 bytes
-rw-r--r--examples/sql/drilldown/images/redwood.pngbin0 -> 39050 bytes
-rw-r--r--examples/sql/drilldown/informationwindow.cpp167
-rw-r--r--examples/sql/drilldown/informationwindow.h90
-rw-r--r--examples/sql/drilldown/logo.pngbin0 -> 13378 bytes
-rw-r--r--examples/sql/drilldown/main.cpp65
-rw-r--r--examples/sql/drilldown/view.cpp191
-rw-r--r--examples/sql/drilldown/view.h80
16 files changed, 822 insertions, 0 deletions
diff --git a/examples/sql/drilldown/drilldown.pro b/examples/sql/drilldown/drilldown.pro
new file mode 100644
index 0000000000..e3f05c2293
--- /dev/null
+++ b/examples/sql/drilldown/drilldown.pro
@@ -0,0 +1,21 @@
+HEADERS = ../connection.h \
+ imageitem.h \
+ informationwindow.h \
+ view.h
+RESOURCES = drilldown.qrc
+SOURCES = imageitem.cpp \
+ informationwindow.cpp \
+ main.cpp \
+ view.cpp
+QT += sql
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/drilldown
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS drilldown.pro *.png *.jpg images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/sql/drilldown
+INSTALLS += target sources
+
+symbian {
+ TARGET.UID3 = 0xA000C612
+ include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
+}
diff --git a/examples/sql/drilldown/drilldown.qrc b/examples/sql/drilldown/drilldown.qrc
new file mode 100644
index 0000000000..d2fb12295b
--- /dev/null
+++ b/examples/sql/drilldown/drilldown.qrc
@@ -0,0 +1,11 @@
+<!DOCTYPE RCC><RCC version="1.0">
+ <qresource>
+ <file>images/oslo.png</file>
+ <file>images/brisbane.png</file>
+ <file>images/redwood.png</file>
+ <file>images/berlin.png</file>
+ <file>images/munich.png</file>
+ <file>images/beijing.png</file>
+ <file>logo.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/sql/drilldown/imageitem.cpp b/examples/sql/drilldown/imageitem.cpp
new file mode 100644
index 0000000000..52dff716d5
--- /dev/null
+++ b/examples/sql/drilldown/imageitem.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 "imageitem.h"
+
+//! [0]
+ImageItem::ImageItem(int id, const QPixmap &pixmap, QGraphicsItem *parent,
+ QGraphicsScene *scene)
+ : QGraphicsPixmapItem(pixmap, parent, scene)
+{
+ recordId = id;
+ setAcceptsHoverEvents(true);
+
+ timeLine.setDuration(150);
+ timeLine.setFrameRange(0, 150);
+
+ connect(&timeLine, SIGNAL(frameChanged(int)), this, SLOT(setFrame(int)));
+ connect(&timeLine, SIGNAL(finished()), this, SLOT(updateItemPosition()));
+
+ adjust();
+}
+//! [0]
+
+//! [1]
+void ImageItem::hoverEnterEvent(QGraphicsSceneHoverEvent * /*event*/)
+{
+ timeLine.setDirection(QTimeLine::Forward);
+
+ if (z != 1.0) {
+ z = 1.0;
+ updateItemPosition();
+ }
+
+ if (timeLine.state() == QTimeLine::NotRunning)
+ timeLine.start();
+}
+//! [1]
+
+//! [2]
+void ImageItem::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
+{
+ timeLine.setDirection(QTimeLine::Backward);
+ if (z != 0.0)
+ z = 0.0;
+
+ if (timeLine.state() == QTimeLine::NotRunning)
+ timeLine.start();
+}
+//! [2]
+
+//! [3]
+void ImageItem::setFrame(int frame)
+{
+ adjust();
+ QPointF center = boundingRect().center();
+
+ translate(center.x(), center.y());
+ scale(1 + frame / 330.0, 1 + frame / 330.0);
+ translate(-center.x(), -center.y());
+}
+//! [3]
+
+//! [4]
+void ImageItem::adjust()
+{
+ QMatrix matrix;
+ matrix.scale(150/ boundingRect().width(), 120/ boundingRect().height());
+ setMatrix(matrix);
+}
+//! [4]
+
+//! [5]
+int ImageItem::id()
+{
+ return recordId;
+}
+//! [5]
+
+//! [6]
+void ImageItem::updateItemPosition()
+{
+ setZValue(z);
+}
+//! [6]
+
+
diff --git a/examples/sql/drilldown/imageitem.h b/examples/sql/drilldown/imageitem.h
new file mode 100644
index 0000000000..13d99c3846
--- /dev/null
+++ b/examples/sql/drilldown/imageitem.h
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** 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 IMAGEITEM_H
+#define IMAGEITEM_H
+
+#include <QtCore>
+#include <QtGui/QGraphicsPixmapItem>
+
+//! [0]
+class ImageItem : public QObject, public QGraphicsPixmapItem
+{
+ Q_OBJECT
+
+public:
+ ImageItem(int id, const QPixmap &pixmap, QGraphicsItem *parent = 0,
+ QGraphicsScene *scene = 0);
+
+ void adjust();
+ int id();
+
+protected:
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
+
+private slots:
+ void setFrame(int frame);
+ void updateItemPosition();
+
+private:
+ QTimeLine timeLine;
+ int recordId;
+ double z;
+};
+//! [0]
+
+#endif
diff --git a/examples/sql/drilldown/images/beijing.png b/examples/sql/drilldown/images/beijing.png
new file mode 100644
index 0000000000..45df148506
--- /dev/null
+++ b/examples/sql/drilldown/images/beijing.png
Binary files differ
diff --git a/examples/sql/drilldown/images/berlin.png b/examples/sql/drilldown/images/berlin.png
new file mode 100644
index 0000000000..ead62f0421
--- /dev/null
+++ b/examples/sql/drilldown/images/berlin.png
Binary files differ
diff --git a/examples/sql/drilldown/images/brisbane.png b/examples/sql/drilldown/images/brisbane.png
new file mode 100644
index 0000000000..04fff57f9c
--- /dev/null
+++ b/examples/sql/drilldown/images/brisbane.png
Binary files differ
diff --git a/examples/sql/drilldown/images/munich.png b/examples/sql/drilldown/images/munich.png
new file mode 100644
index 0000000000..741eb77b8d
--- /dev/null
+++ b/examples/sql/drilldown/images/munich.png
Binary files differ
diff --git a/examples/sql/drilldown/images/oslo.png b/examples/sql/drilldown/images/oslo.png
new file mode 100644
index 0000000000..02fa25e5a0
--- /dev/null
+++ b/examples/sql/drilldown/images/oslo.png
Binary files differ
diff --git a/examples/sql/drilldown/images/redwood.png b/examples/sql/drilldown/images/redwood.png
new file mode 100644
index 0000000000..f39ac06578
--- /dev/null
+++ b/examples/sql/drilldown/images/redwood.png
Binary files differ
diff --git a/examples/sql/drilldown/informationwindow.cpp b/examples/sql/drilldown/informationwindow.cpp
new file mode 100644
index 0000000000..3f43a5901f
--- /dev/null
+++ b/examples/sql/drilldown/informationwindow.cpp
@@ -0,0 +1,167 @@
+/****************************************************************************
+**
+** 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 "informationwindow.h"
+
+//! [0]
+InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *offices,
+ QWidget *parent)
+ : QDialog(parent)
+{
+//! [0] //! [1]
+ QLabel *locationLabel = new QLabel(tr("Location: "));
+ QLabel *countryLabel = new QLabel(tr("Country: "));
+ QLabel *descriptionLabel = new QLabel(tr("Description: "));
+ QLabel *imageFileLabel = new QLabel(tr("Image file: "));
+
+ createButtons();
+
+ locationText = new QLabel;
+ countryText = new QLabel;
+ descriptionEditor = new QTextEdit;
+//! [1]
+
+//! [2]
+ imageFileEditor = new QComboBox;
+ imageFileEditor->setModel(offices->relationModel(1));
+ imageFileEditor->setModelColumn(offices->relationModel(1)->fieldIndex("file"));
+//! [2]
+
+//! [3]
+ mapper = new QDataWidgetMapper(this);
+ mapper->setModel(offices);
+ mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
+ mapper->setItemDelegate(new QSqlRelationalDelegate(mapper));
+ mapper->addMapping(imageFileEditor, 1);
+ mapper->addMapping(locationText, 2, "text");
+ mapper->addMapping(countryText, 3, "text");
+ mapper->addMapping(descriptionEditor, 4);
+ mapper->setCurrentIndex(id);
+//! [3]
+
+//! [4]
+ connect(descriptionEditor, SIGNAL(textChanged()),
+ this, SLOT(enableButtons()));
+ connect(imageFileEditor, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(enableButtons()));
+
+ QFormLayout *formLayout = new QFormLayout;
+ formLayout->addRow(locationLabel, locationText);
+ formLayout->addRow(countryLabel, countryText);
+ formLayout->addRow(imageFileLabel, imageFileEditor);
+ formLayout->addRow(descriptionLabel, descriptionEditor);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ layout->addLayout(formLayout);
+ layout->addWidget(buttonBox);
+ setLayout(layout);
+
+ locationId = id;
+ displayedImage = imageFileEditor->currentText();
+
+ setWindowFlags(Qt::Window);
+ enableButtons(false);
+ setWindowTitle(tr("Office: %1").arg(locationText->text()));
+}
+//! [4]
+
+//! [5]
+int InformationWindow::id()
+{
+ return locationId;
+}
+//! [5]
+
+//! [6]
+void InformationWindow::revert()
+{
+ mapper->revert();
+ enableButtons(false);
+}
+//! [6]
+
+//! [7]
+void InformationWindow::submit()
+{
+ QString newImage(imageFileEditor->currentText());
+
+ if (displayedImage != newImage) {
+ displayedImage = newImage;
+ emit imageChanged(locationId, newImage);
+ }
+
+ mapper->submit();
+ mapper->setCurrentIndex(locationId);
+
+ enableButtons(false);
+}
+//! [7]
+
+//! [8]
+void InformationWindow::createButtons()
+{
+ closeButton = new QPushButton(tr("&Close"));
+ revertButton = new QPushButton(tr("&Revert"));
+ submitButton = new QPushButton(tr("&Submit"));
+
+ closeButton->setDefault(true);
+
+ connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
+ connect(revertButton, SIGNAL(clicked()), this, SLOT(revert()));
+ connect(submitButton, SIGNAL(clicked()), this, SLOT(submit()));
+//! [8]
+
+//! [9]
+ buttonBox = new QDialogButtonBox(this);
+ buttonBox->addButton(submitButton, QDialogButtonBox::AcceptRole);
+ buttonBox->addButton(revertButton, QDialogButtonBox::ResetRole);
+ buttonBox->addButton(closeButton, QDialogButtonBox::RejectRole);
+}
+//! [9]
+
+//! [10]
+void InformationWindow::enableButtons(bool enable)
+{
+ revertButton->setEnabled(enable);
+ submitButton->setEnabled(enable);
+}
+//! [10]
+
+
diff --git a/examples/sql/drilldown/informationwindow.h b/examples/sql/drilldown/informationwindow.h
new file mode 100644
index 0000000000..354823f152
--- /dev/null
+++ b/examples/sql/drilldown/informationwindow.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** 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 INFORMATIONWINDOW_H
+#define INFORMATIONWINDOW_H
+
+#include <QtGui>
+#include <QtSql>
+
+//! [0]
+class InformationWindow : public QDialog
+{
+ Q_OBJECT
+
+public:
+ InformationWindow(int id, QSqlRelationalTableModel *offices,
+ QWidget *parent = 0);
+
+ int id();
+
+signals:
+ void imageChanged(int id, const QString &fileName);
+//! [0]
+
+//! [1]
+private slots:
+ void revert();
+ void submit();
+ void enableButtons(bool enable = true);
+//! [1]
+
+//! [2]
+private:
+ void createButtons();
+
+ int locationId;
+ QString displayedImage;
+
+ QComboBox *imageFileEditor;
+ QLabel *locationText;
+ QLabel *countryText;
+ QTextEdit *descriptionEditor;
+
+ QPushButton *closeButton;
+ QPushButton *submitButton;
+ QPushButton *revertButton;
+ QDialogButtonBox *buttonBox;
+
+ QDataWidgetMapper *mapper;
+};
+//! [2]
+
+#endif
diff --git a/examples/sql/drilldown/logo.png b/examples/sql/drilldown/logo.png
new file mode 100644
index 0000000000..4b1d235488
--- /dev/null
+++ b/examples/sql/drilldown/logo.png
Binary files differ
diff --git a/examples/sql/drilldown/main.cpp b/examples/sql/drilldown/main.cpp
new file mode 100644
index 0000000000..e3c8fa7cce
--- /dev/null
+++ b/examples/sql/drilldown/main.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** 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 "../connection.h"
+#include "view.h"
+
+int main(int argc, char *argv[])
+{
+ Q_INIT_RESOURCE(drilldown);
+
+ QApplication app(argc, argv);
+
+ if (!createConnection())
+ return 1;
+
+ View view("offices", "images");
+#ifndef Q_OS_SYMBIAN
+ view.show();
+#else
+ view.showFullScreen();
+#endif
+#ifdef QT_KEYPAD_NAVIGATION
+ QApplication::setNavigationMode(Qt::NavigationModeCursorAuto);
+#endif
+ return app.exec();
+}
diff --git a/examples/sql/drilldown/view.cpp b/examples/sql/drilldown/view.cpp
new file mode 100644
index 0000000000..68fe06a8e2
--- /dev/null
+++ b/examples/sql/drilldown/view.cpp
@@ -0,0 +1,191 @@
+/****************************************************************************
+**
+** 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 "informationwindow.h"
+#include "imageitem.h"
+#include "view.h"
+
+//! [0]
+View::View(const QString &offices, const QString &images, QWidget *parent)
+ : QGraphicsView(parent)
+{
+ officeTable = new QSqlRelationalTableModel(this);
+ officeTable->setTable(offices);
+ officeTable->setRelation(1, QSqlRelation(images, "locationid", "file"));
+ officeTable->select();
+//! [0]
+
+//! [1]
+ scene = new QGraphicsScene(this);
+ scene->setSceneRect(0, 0, 465, 615);
+ setScene(scene);
+
+ addItems();
+
+ QGraphicsPixmapItem *logo = scene->addPixmap(QPixmap(":/logo.png"));
+ logo->setPos(30, 515);
+
+#ifndef Q_OS_SYMBIAN
+ setMinimumSize(470, 620);
+ setMaximumSize(470, 620);
+#else
+ setDragMode(QGraphicsView::ScrollHandDrag);
+#endif
+
+ setWindowTitle(tr("Offices World Wide"));
+}
+//! [1]
+
+//! [3]
+void View::addItems()
+{
+ int officeCount = officeTable->rowCount();
+
+ int imageOffset = 150;
+ int leftMargin = 70;
+ int topMargin = 40;
+
+ for (int i = 0; i < officeCount; i++) {
+ ImageItem *image;
+ QGraphicsTextItem *label;
+ QSqlRecord record = officeTable->record(i);
+
+ int id = record.value("id").toInt();
+ QString file = record.value("file").toString();
+ QString location = record.value("location").toString();
+
+ int columnOffset = ((i / 3) * 37);
+ int x = ((i / 3) * imageOffset) + leftMargin + columnOffset;
+ int y = ((i % 3) * imageOffset) + topMargin;
+
+ image = new ImageItem(id, QPixmap(":/" + file));
+ image->setData(0, i);
+ image->setPos(x, y);
+ scene->addItem(image);
+
+ label = scene->addText(location);
+ QPointF labelOffset((150 - label->boundingRect().width()) / 2, 120.0);
+ label->setPos(QPointF(x, y) + labelOffset);
+ }
+}
+//! [3]
+
+//! [5]
+void View::mouseReleaseEvent(QMouseEvent *event)
+{
+ if (QGraphicsItem *item = itemAt(event->pos())) {
+ if (ImageItem *image = qgraphicsitem_cast<ImageItem *>(item))
+ showInformation(image);
+ }
+ QGraphicsView::mouseReleaseEvent(event);
+}
+//! [5]
+
+//! [6]
+void View::showInformation(ImageItem *image)
+{
+ int id = image->id();
+ if (id < 0 || id >= officeTable->rowCount())
+ return;
+
+ InformationWindow *window = findWindow(id);
+ if (window && window->isVisible()) {
+ window->raise();
+ window->activateWindow();
+ } else if (window && !window->isVisible()) {
+#ifndef Q_OS_SYMBIAN
+ window->show();
+#else
+ window->showMaximized();
+#endif
+ } else {
+ InformationWindow *window;
+ window = new InformationWindow(id, officeTable, this);
+
+ connect(window, SIGNAL(imageChanged(int,QString)),
+ this, SLOT(updateImage(int,QString)));
+
+#ifndef Q_OS_SYMBIAN
+ window->move(pos() + QPoint(20, 40));
+ window->show();
+#else
+ window->showMaximized();
+#endif
+ informationWindows.append(window);
+ }
+}
+//! [6]
+
+//! [7]
+void View::updateImage(int id, const QString &fileName)
+{
+ QList<QGraphicsItem *> items = scene->items();
+
+ while(!items.empty()) {
+ QGraphicsItem *item = items.takeFirst();
+
+ if (ImageItem *image = qgraphicsitem_cast<ImageItem *>(item)) {
+ if (image->id() == id){
+ image->setPixmap(QPixmap(":/" +fileName));
+ image->adjust();
+ break;
+ }
+ }
+ }
+}
+//! [7]
+
+//! [8]
+InformationWindow* View::findWindow(int id)
+{
+ QList<InformationWindow*>::iterator i, beginning, end;
+
+ beginning = informationWindows.begin();
+ end = informationWindows.end();
+
+ for (i = beginning; i != end; ++i) {
+ InformationWindow *window = (*i);
+ if (window && (window->id() == id))
+ return window;
+ }
+ return 0;
+}
+//! [8]
+
diff --git a/examples/sql/drilldown/view.h b/examples/sql/drilldown/view.h
new file mode 100644
index 0000000000..3efe6bb8ce
--- /dev/null
+++ b/examples/sql/drilldown/view.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** 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 VIEW_H
+#define VIEW_H
+
+#include <QtGui>
+#include <QtSql>
+
+class ImageItem;
+class InformationWindow;
+
+//! [0]
+class View : public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ View(const QString &offices, const QString &images, QWidget *parent = 0);
+
+protected:
+ void mouseReleaseEvent(QMouseEvent *event);
+//! [0]
+
+//! [1]
+private slots:
+ void updateImage(int id, const QString &fileName);
+//! [1]
+
+//! [2]
+private:
+ void addItems();
+ InformationWindow* findWindow(int id);
+ void showInformation(ImageItem *image);
+
+ QGraphicsScene *scene;
+ QList<InformationWindow *> informationWindows;
+//! [2] //! [3]
+ QSqlRelationalTableModel *officeTable;
+};
+//! [3]
+
+#endif