summaryrefslogtreecommitdiffstats
path: root/examples/sql/drilldown/view.cpp
diff options
context:
space:
mode:
authorTopi Reinio <topi.reinio@digia.com>2013-05-22 10:52:56 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-22 13:48:53 +0200
commite724fd4710cfd395b7d0a8cf160e79ec5ae9d685 (patch)
tree8279c866fb910a79416bbcfd762c36aafd5ce736 /examples/sql/drilldown/view.cpp
parentf9b3b02360f5b2352cfe26494fb07c7f2f3b7832 (diff)
Doc: Updated content for Drill Down example
QtWidgets/Drill Down example uses images and information about Nokia's old office locations as content. This change updates the example to use concepts related to Qt instead. In addition, - Documentation, screenshot updated accordingly - Corrected aspect ratio when scaling image items in the scene - Added a gray background with a slight gradient - Removed Symbian-specific code remnant Task-number: QTBUG-31075 Change-Id: Id8abfbf7f4033f74172477570f8f28390854101c Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
Diffstat (limited to 'examples/sql/drilldown/view.cpp')
-rw-r--r--examples/sql/drilldown/view.cpp47
1 files changed, 24 insertions, 23 deletions
diff --git a/examples/sql/drilldown/view.cpp b/examples/sql/drilldown/view.cpp
index d80a800e62..a64252cbd2 100644
--- a/examples/sql/drilldown/view.cpp
+++ b/examples/sql/drilldown/view.cpp
@@ -43,61 +43,62 @@
#include "view.h"
//! [0]
-View::View(const QString &offices, const QString &images, QWidget *parent)
+View::View(const QString &items, const QString &images, QWidget *parent)
: QGraphicsView(parent)
{
- officeTable = new QSqlRelationalTableModel(this);
- officeTable->setTable(offices);
- officeTable->setRelation(1, QSqlRelation(images, "locationid", "file"));
- officeTable->select();
+ itemTable = new QSqlRelationalTableModel(this);
+ itemTable->setTable(items);
+ itemTable->setRelation(1, QSqlRelation(images, "itemid", "file"));
+ itemTable->select();
//! [0]
//! [1]
scene = new QGraphicsScene(this);
- scene->setSceneRect(0, 0, 465, 615);
+ scene->setSceneRect(0, 0, 465, 365);
setScene(scene);
addItems();
- QGraphicsPixmapItem *logo = scene->addPixmap(QPixmap(":/logo.png"));
- logo->setPos(30, 515);
+ setMinimumSize(470, 370);
+ setMaximumSize(470, 370);
- setMinimumSize(470, 620);
- setMaximumSize(470, 620);
-
- setWindowTitle(tr("Offices World Wide"));
+ QLinearGradient gradient(QPointF(0, 0), QPointF(0, 370));
+ gradient.setColorAt(0, QColor("#868482"));
+ gradient.setColorAt(1, QColor("#5d5b59"));
+ setBackgroundBrush(gradient);
}
//! [1]
//! [3]
void View::addItems()
{
- int officeCount = officeTable->rowCount();
+ int itemCount = itemTable->rowCount();
int imageOffset = 150;
int leftMargin = 70;
int topMargin = 40;
- for (int i = 0; i < officeCount; i++) {
+ for (int i = 0; i < itemCount; i++) {
ImageItem *image;
QGraphicsTextItem *label;
- QSqlRecord record = officeTable->record(i);
+ QSqlRecord record = itemTable->record(i);
int id = record.value("id").toInt();
QString file = record.value("file").toString();
- QString location = record.value("location").toString();
+ QString item = record.value("itemtype").toString();
- int columnOffset = ((i / 3) * 37);
- int x = ((i / 3) * imageOffset) + leftMargin + columnOffset;
- int y = ((i % 3) * imageOffset) + topMargin;
+ int columnOffset = ((i % 2) * 37);
+ int x = ((i % 2) * imageOffset) + leftMargin + columnOffset;
+ int y = ((i / 2) * 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 = scene->addText(item);
+ label->setDefaultTextColor(QColor("#d7d6d5"));
+ QPointF labelOffset((120 - label->boundingRect().width()) / 2, 120.0);
label->setPos(QPointF(x, y) + labelOffset);
}
}
@@ -118,7 +119,7 @@ void View::mouseReleaseEvent(QMouseEvent *event)
void View::showInformation(ImageItem *image)
{
int id = image->id();
- if (id < 0 || id >= officeTable->rowCount())
+ if (id < 0 || id >= itemTable->rowCount())
return;
InformationWindow *window = findWindow(id);
@@ -129,7 +130,7 @@ void View::showInformation(ImageItem *image)
window->show();
} else {
InformationWindow *window;
- window = new InformationWindow(id, officeTable, this);
+ window = new InformationWindow(id, itemTable, this);
connect(window, SIGNAL(imageChanged(int,QString)),
this, SLOT(updateImage(int,QString)));