summaryrefslogtreecommitdiffstats
path: root/examples/sql/drilldown
diff options
context:
space:
mode:
Diffstat (limited to 'examples/sql/drilldown')
-rw-r--r--examples/sql/drilldown/drilldown.pro20
-rw-r--r--examples/sql/drilldown/drilldown.qrc11
-rw-r--r--examples/sql/drilldown/imageitem.cpp124
-rw-r--r--examples/sql/drilldown/imageitem.h75
-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.cpp172
-rw-r--r--examples/sql/drilldown/informationwindow.h91
-rw-r--r--examples/sql/drilldown/logo.pngbin0 -> 13378 bytes
-rw-r--r--examples/sql/drilldown/main.cpp63
-rw-r--r--examples/sql/drilldown/view.cpp192
-rw-r--r--examples/sql/drilldown/view.h81
16 files changed, 829 insertions, 0 deletions
diff --git a/examples/sql/drilldown/drilldown.pro b/examples/sql/drilldown/drilldown.pro
new file mode 100644
index 0000000..7907bd2
--- /dev/null
+++ b/examples/sql/drilldown/drilldown.pro
@@ -0,0 +1,20 @@
+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]/sql/drilldown
+sources.files = $$SOURCES *.h $$RESOURCES $$FORMS drilldown.pro *.png *.jpg images
+sources.path = $$[QT_INSTALL_EXAMPLES]/sql/drilldown
+INSTALLS += target sources
+
+symbian:TARGET.UID3 = 0xA000C612
+
+include($$QT_SOURCE_TREE/examples/examplebase.pri)
diff --git a/examples/sql/drilldown/drilldown.qrc b/examples/sql/drilldown/drilldown.qrc
new file mode 100644
index 0000000..d2fb122
--- /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 0000000..620afed
--- /dev/null
+++ b/examples/sql/drilldown/imageitem.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 "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 0000000..20c7811
--- /dev/null
+++ b/examples/sql/drilldown/imageitem.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** 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 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 0000000..45df148
--- /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 0000000..ead62f0
--- /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 0000000..04fff57
--- /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 0000000..741eb77
--- /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 0000000..02fa25e
--- /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 0000000..f39ac06
--- /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 0000000..ea66b0b
--- /dev/null
+++ b/examples/sql/drilldown/informationwindow.cpp
@@ -0,0 +1,172 @@
+/****************************************************************************
+**
+** 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 "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()));
+
+ QGridLayout *layout = new QGridLayout;
+ layout->addWidget(locationLabel, 0, 0, Qt::AlignLeft | Qt::AlignTop);
+ layout->addWidget(countryLabel, 1, 0, Qt::AlignLeft | Qt::AlignTop);
+ layout->addWidget(imageFileLabel, 2, 0, Qt::AlignLeft | Qt::AlignTop);
+ layout->addWidget(descriptionLabel, 3, 0, Qt::AlignLeft | Qt::AlignTop);
+ layout->addWidget(locationText, 0, 1);
+ layout->addWidget(countryText, 1, 1);
+ layout->addWidget(imageFileEditor, 2, 1);
+ layout->addWidget(descriptionEditor, 3, 1);
+ layout->addWidget(buttonBox, 4, 0, 1, 2);
+ setLayout(layout);
+
+ locationId = id;
+ displayedImage = imageFileEditor->currentText();
+
+ setWindowFlags(Qt::Window);
+ enableButtons(false);
+ setWindowTitle(tr("Office: %1").arg(locationText->text()));
+#ifndef Q_OS_SYMBIAN
+ resize(320, sizeHint().height());
+#endif
+}
+//! [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;
+ buttonBox->addButton(submitButton, QDialogButtonBox::ResetRole);
+ 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 0000000..f28b47d
--- /dev/null
+++ b/examples/sql/drilldown/informationwindow.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** 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 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 0000000..4b1d235
--- /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 0000000..c340f5e
--- /dev/null
+++ b/examples/sql/drilldown/main.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** 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 "../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
+ return app.exec();
+}
diff --git a/examples/sql/drilldown/view.cpp b/examples/sql/drilldown/view.cpp
new file mode 100644
index 0000000..778767b
--- /dev/null
+++ b/examples/sql/drilldown/view.cpp
@@ -0,0 +1,192 @@
+/****************************************************************************
+**
+** 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 "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->showFullScreen();
+#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->showFullScreen();
+#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 0000000..37ddabb
--- /dev/null
+++ b/examples/sql/drilldown/view.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** 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 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