From e724fd4710cfd395b7d0a8cf160e79ec5ae9d685 Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Wed, 22 May 2013 10:52:56 +0200 Subject: 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 Reviewed-by: Jerome Pasion --- examples/sql/drilldown/drilldown.qrc | 17 ++++------ examples/sql/drilldown/imageitem.cpp | 2 +- examples/sql/drilldown/images/beijing.png | Bin 99093 -> 0 bytes examples/sql/drilldown/images/berlin.png | Bin 81944 -> 0 bytes examples/sql/drilldown/images/brisbane.png | Bin 57785 -> 0 bytes examples/sql/drilldown/images/munich.png | Bin 59769 -> 0 bytes examples/sql/drilldown/images/oslo.png | Bin 41781 -> 0 bytes examples/sql/drilldown/images/qt-creator.png | Bin 0 -> 46906 bytes examples/sql/drilldown/images/qt-logo.png | Bin 0 -> 45652 bytes examples/sql/drilldown/images/qt-project.png | Bin 0 -> 37795 bytes examples/sql/drilldown/images/qt-quick.png | Bin 0 -> 43238 bytes examples/sql/drilldown/images/redwood.png | Bin 39050 -> 0 bytes examples/sql/drilldown/informationwindow.cpp | 38 +++++++++------------- examples/sql/drilldown/informationwindow.h | 7 ++-- examples/sql/drilldown/logo.png | Bin 13378 -> 0 bytes examples/sql/drilldown/main.cpp | 2 +- examples/sql/drilldown/view.cpp | 47 ++++++++++++++------------- examples/sql/drilldown/view.h | 4 +-- 18 files changed, 53 insertions(+), 64 deletions(-) delete mode 100644 examples/sql/drilldown/images/beijing.png delete mode 100644 examples/sql/drilldown/images/berlin.png delete mode 100644 examples/sql/drilldown/images/brisbane.png delete mode 100644 examples/sql/drilldown/images/munich.png delete mode 100644 examples/sql/drilldown/images/oslo.png create mode 100644 examples/sql/drilldown/images/qt-creator.png create mode 100644 examples/sql/drilldown/images/qt-logo.png create mode 100644 examples/sql/drilldown/images/qt-project.png create mode 100644 examples/sql/drilldown/images/qt-quick.png delete mode 100644 examples/sql/drilldown/images/redwood.png delete mode 100644 examples/sql/drilldown/logo.png (limited to 'examples/sql/drilldown') diff --git a/examples/sql/drilldown/drilldown.qrc b/examples/sql/drilldown/drilldown.qrc index d2fb12295b..f24edbafe4 100644 --- a/examples/sql/drilldown/drilldown.qrc +++ b/examples/sql/drilldown/drilldown.qrc @@ -1,11 +1,8 @@ - - - images/oslo.png - images/brisbane.png - images/redwood.png - images/berlin.png - images/munich.png - images/beijing.png - logo.png - + + + images/qt-logo.png + images/qt-quick.png + images/qt-creator.png + images/qt-project.png + diff --git a/examples/sql/drilldown/imageitem.cpp b/examples/sql/drilldown/imageitem.cpp index 8ebd7fd890..f1e3872e1c 100644 --- a/examples/sql/drilldown/imageitem.cpp +++ b/examples/sql/drilldown/imageitem.cpp @@ -100,7 +100,7 @@ void ImageItem::setFrame(int frame) void ImageItem::adjust() { QMatrix matrix; - matrix.scale(150/ boundingRect().width(), 120/ boundingRect().height()); + matrix.scale(120/ boundingRect().width(), 120/ boundingRect().height()); setMatrix(matrix); } //! [4] diff --git a/examples/sql/drilldown/images/beijing.png b/examples/sql/drilldown/images/beijing.png deleted file mode 100644 index 45df148506..0000000000 Binary files a/examples/sql/drilldown/images/beijing.png and /dev/null differ diff --git a/examples/sql/drilldown/images/berlin.png b/examples/sql/drilldown/images/berlin.png deleted file mode 100644 index ead62f0421..0000000000 Binary files a/examples/sql/drilldown/images/berlin.png and /dev/null differ diff --git a/examples/sql/drilldown/images/brisbane.png b/examples/sql/drilldown/images/brisbane.png deleted file mode 100644 index 04fff57f9c..0000000000 Binary files a/examples/sql/drilldown/images/brisbane.png and /dev/null differ diff --git a/examples/sql/drilldown/images/munich.png b/examples/sql/drilldown/images/munich.png deleted file mode 100644 index 741eb77b8d..0000000000 Binary files a/examples/sql/drilldown/images/munich.png and /dev/null differ diff --git a/examples/sql/drilldown/images/oslo.png b/examples/sql/drilldown/images/oslo.png deleted file mode 100644 index 02fa25e5a0..0000000000 Binary files a/examples/sql/drilldown/images/oslo.png and /dev/null differ diff --git a/examples/sql/drilldown/images/qt-creator.png b/examples/sql/drilldown/images/qt-creator.png new file mode 100644 index 0000000000..fa0f6ed7ce Binary files /dev/null and b/examples/sql/drilldown/images/qt-creator.png differ diff --git a/examples/sql/drilldown/images/qt-logo.png b/examples/sql/drilldown/images/qt-logo.png new file mode 100644 index 0000000000..53bc39c38c Binary files /dev/null and b/examples/sql/drilldown/images/qt-logo.png differ diff --git a/examples/sql/drilldown/images/qt-project.png b/examples/sql/drilldown/images/qt-project.png new file mode 100644 index 0000000000..c34d3f099d Binary files /dev/null and b/examples/sql/drilldown/images/qt-project.png differ diff --git a/examples/sql/drilldown/images/qt-quick.png b/examples/sql/drilldown/images/qt-quick.png new file mode 100644 index 0000000000..f66127e8e7 Binary files /dev/null and b/examples/sql/drilldown/images/qt-quick.png differ diff --git a/examples/sql/drilldown/images/redwood.png b/examples/sql/drilldown/images/redwood.png deleted file mode 100644 index f39ac06578..0000000000 Binary files a/examples/sql/drilldown/images/redwood.png and /dev/null differ diff --git a/examples/sql/drilldown/informationwindow.cpp b/examples/sql/drilldown/informationwindow.cpp index 08c125e58a..d3930c6f0b 100644 --- a/examples/sql/drilldown/informationwindow.cpp +++ b/examples/sql/drilldown/informationwindow.cpp @@ -41,38 +41,35 @@ #include "informationwindow.h" //! [0] -InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *offices, +InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *items, QWidget *parent) : QDialog(parent) { //! [0] //! [1] - QLabel *locationLabel = new QLabel(tr("Location: ")); - QLabel *countryLabel = new QLabel(tr("Country: ")); + QLabel *itemLabel = new QLabel(tr("Item: ")); QLabel *descriptionLabel = new QLabel(tr("Description: ")); QLabel *imageFileLabel = new QLabel(tr("Image file: ")); createButtons(); - locationText = new QLabel; - countryText = new QLabel; + itemText = new QLabel; descriptionEditor = new QTextEdit; //! [1] //! [2] imageFileEditor = new QComboBox; - imageFileEditor->setModel(offices->relationModel(1)); - imageFileEditor->setModelColumn(offices->relationModel(1)->fieldIndex("file")); + imageFileEditor->setModel(items->relationModel(1)); + imageFileEditor->setModelColumn(items->relationModel(1)->fieldIndex("file")); //! [2] //! [3] mapper = new QDataWidgetMapper(this); - mapper->setModel(offices); + mapper->setModel(items); 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->addMapping(itemText, 2, "text"); + mapper->addMapping(descriptionEditor, 3); mapper->setCurrentIndex(id); //! [3] @@ -83,8 +80,7 @@ InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *offices, this, SLOT(enableButtons())); QFormLayout *formLayout = new QFormLayout; - formLayout->addRow(locationLabel, locationText); - formLayout->addRow(countryLabel, countryText); + formLayout->addRow(itemLabel, itemText); formLayout->addRow(imageFileLabel, imageFileEditor); formLayout->addRow(descriptionLabel, descriptionEditor); @@ -93,23 +89,19 @@ InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *offices, layout->addWidget(buttonBox); setLayout(layout); - locationId = id; + itemId = id; displayedImage = imageFileEditor->currentText(); - // Commented the following line. Now the window will look like dialog and the Qt will place the QDialogBox buttons to menu area in Symbian. - // Too bad that the revert button is missing, Should the Qt place the buttons under Option menu in the menu area?! - // If the Qt::Window flag was used, the background of window is white in symbian and the QLabels can't be regognized from the background. - - //setWindowFlags(Qt::Window); + setWindowFlags(Qt::Window); enableButtons(false); - setWindowTitle(tr("Office: %1").arg(locationText->text())); + setWindowTitle(itemText->text()); } //! [4] //! [5] int InformationWindow::id() { - return locationId; + return itemId; } //! [5] @@ -128,11 +120,11 @@ void InformationWindow::submit() if (displayedImage != newImage) { displayedImage = newImage; - emit imageChanged(locationId, newImage); + emit imageChanged(itemId, newImage); } mapper->submit(); - mapper->setCurrentIndex(locationId); + mapper->setCurrentIndex(itemId); enableButtons(false); } diff --git a/examples/sql/drilldown/informationwindow.h b/examples/sql/drilldown/informationwindow.h index e1bb9bc958..f039e120ca 100644 --- a/examples/sql/drilldown/informationwindow.h +++ b/examples/sql/drilldown/informationwindow.h @@ -50,7 +50,7 @@ class InformationWindow : public QDialog Q_OBJECT public: - InformationWindow(int id, QSqlRelationalTableModel *offices, + InformationWindow(int id, QSqlRelationalTableModel *items, QWidget *parent = 0); int id(); @@ -70,12 +70,11 @@ private slots: private: void createButtons(); - int locationId; + int itemId; QString displayedImage; QComboBox *imageFileEditor; - QLabel *locationText; - QLabel *countryText; + QLabel *itemText; QTextEdit *descriptionEditor; QPushButton *closeButton; diff --git a/examples/sql/drilldown/logo.png b/examples/sql/drilldown/logo.png deleted file mode 100644 index 4b1d235488..0000000000 Binary files a/examples/sql/drilldown/logo.png and /dev/null differ diff --git a/examples/sql/drilldown/main.cpp b/examples/sql/drilldown/main.cpp index 2ee32e446f..956cca9ef9 100644 --- a/examples/sql/drilldown/main.cpp +++ b/examples/sql/drilldown/main.cpp @@ -52,7 +52,7 @@ int main(int argc, char *argv[]) if (!createConnection()) return 1; - View view("offices", "images"); + View view("items", "images"); view.show(); #ifdef QT_KEYPAD_NAVIGATION QApplication::setNavigationMode(Qt::NavigationModeCursorAuto); 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))); diff --git a/examples/sql/drilldown/view.h b/examples/sql/drilldown/view.h index 21193b1960..c9fc040bb1 100644 --- a/examples/sql/drilldown/view.h +++ b/examples/sql/drilldown/view.h @@ -53,7 +53,7 @@ class View : public QGraphicsView Q_OBJECT public: - View(const QString &offices, const QString &images, QWidget *parent = 0); + View(const QString &items, const QString &images, QWidget *parent = 0); protected: void mouseReleaseEvent(QMouseEvent *event); @@ -73,7 +73,7 @@ private: QGraphicsScene *scene; QList informationWindows; //! [2] //! [3] - QSqlRelationalTableModel *officeTable; + QSqlRelationalTableModel *itemTable; }; //! [3] -- cgit v1.2.3