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>
@ -78,55 +78,38 @@ static bool createConnection()
|
||||
query.exec("insert into person values(104, 'Roberto', 'Robitaille')");
|
||||
query.exec("insert into person values(105, 'Maria', 'Papadopoulos')");
|
||||
|
||||
query.exec("create table offices (id int primary key,"
|
||||
query.exec("create table items (id int primary key,"
|
||||
"imagefile int,"
|
||||
"location varchar(20),"
|
||||
"country varchar(20),"
|
||||
"itemtype varchar(20),"
|
||||
"description varchar(100))");
|
||||
query.exec("insert into offices "
|
||||
"values(0, 0, 'Oslo', 'Norway',"
|
||||
"'Oslo is home to more than 500 000 citizens and has a "
|
||||
"lot to offer.It has been called \"The city with the big "
|
||||
"heart\" and this is a nickname we are happy to live up to.')");
|
||||
query.exec("insert into offices "
|
||||
"values(1, 1, 'Brisbane', 'Australia',"
|
||||
"'Brisbane is the capital of Queensland, the Sunshine State, "
|
||||
"where it is beautiful one day, perfect the next. "
|
||||
"Brisbane is Australia''s 3rd largest city, being home "
|
||||
"to almost 2 million people.')");
|
||||
query.exec("insert into offices "
|
||||
"values(2, 2, 'Redwood City', 'US',"
|
||||
"'You find Redwood City in the heart of the Bay Area "
|
||||
"just north of Silicon Valley. The largest nearby city is "
|
||||
"San Jose which is the third largest city in California "
|
||||
"and the 10th largest in the US.')");
|
||||
query.exec("insert into offices "
|
||||
"values(3, 3, 'Berlin', 'Germany',"
|
||||
"'Berlin, the capital of Germany is dynamic, cosmopolitan "
|
||||
"and creative, allowing for every kind of lifestyle. "
|
||||
"East meets West in the metropolis at the heart of a "
|
||||
"changing Europe.')");
|
||||
query.exec("insert into offices "
|
||||
"values(4, 4, 'Munich', 'Germany',"
|
||||
"'Several technology companies are represented in Munich, "
|
||||
"and the city is often called the \"Bavarian Silicon Valley\". "
|
||||
"The exciting city is also filled with culture, "
|
||||
"art and music. ')");
|
||||
query.exec("insert into offices "
|
||||
"values(5, 5, 'Beijing', 'China',"
|
||||
"'Beijing as a capital city has more than 3000 years of "
|
||||
"history. Today the city counts 12 million citizens, and "
|
||||
"is the political, economic and cultural centre of China.')");
|
||||
|
||||
query.exec("create table images (locationid int, file varchar(20))");
|
||||
query.exec("insert into images values(0, 'images/oslo.png')");
|
||||
query.exec("insert into images values(1, 'images/brisbane.png')");
|
||||
query.exec("insert into images values(2, 'images/redwood.png')");
|
||||
query.exec("insert into images values(3, 'images/berlin.png')");
|
||||
query.exec("insert into images values(4, 'images/munich.png')");
|
||||
query.exec("insert into images values(5, 'images/beijing.png')");
|
||||
|
||||
query.exec("insert into items "
|
||||
"values(0, 0, 'Qt',"
|
||||
"'Qt is a full development framework with tools designed to "
|
||||
"streamline the creation of stunning applications and "
|
||||
"amazing user interfaces for desktop, embedded and mobile "
|
||||
"platforms.')");
|
||||
query.exec("insert into items "
|
||||
"values(1, 1, 'Qt Quick',"
|
||||
"'Qt Quick is a collection of techniques designed to help "
|
||||
"developers create intuitive, modern-looking, and fluid "
|
||||
"user interfaces using a CSS & JavaScript like language.')");
|
||||
query.exec("insert into items "
|
||||
"values(2, 2, 'Qt Creator',"
|
||||
"'Qt Creator is a powerful cross-platform integrated "
|
||||
"development environment (IDE), including UI design tools "
|
||||
"and on-device debugging.')");
|
||||
query.exec("insert into items "
|
||||
"values(3, 3, 'Qt Project',"
|
||||
"'The Qt Project governs the open source development of Qt, "
|
||||
"allowing anyone wanting to contribute to join the effort "
|
||||
"through a meritocratic structure of approvers and "
|
||||
"maintainers.')");
|
||||
|
||||
query.exec("create table images (itemid int, file varchar(20))");
|
||||
query.exec("insert into images values(0, 'images/qt-logo.png')");
|
||||
query.exec("insert into images values(1, 'images/qt-quick.png')");
|
||||
query.exec("insert into images values(2, 'images/qt-creator.png')");
|
||||
query.exec("insert into images values(3, 'images/qt-project.png')");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Before Width: | Height: | Size: 125 KiB After Width: | Height: | Size: 52 KiB |
@ -37,20 +37,19 @@
|
||||
\image drilldown-example.png Screenshot of the Drill Down Example
|
||||
|
||||
When running the example application, a user can retrieve
|
||||
information about each of Nokia's Qt offices by clicking the
|
||||
corresponding image. The application pops up an information window
|
||||
displaying the data, and allows the users to alter the location
|
||||
description as well as the image. The main view will be updated
|
||||
when the users submit their changes.
|
||||
information about each item by clicking the corresponding image.
|
||||
The application pops up an information window displaying the data,
|
||||
and allows the users to alter the description as well as the image.
|
||||
The main view will be updated when the users submit their changes.
|
||||
|
||||
The example consists of three classes:
|
||||
|
||||
\list
|
||||
\li \c ImageItem is a custom graphics item class used to
|
||||
display the office images.
|
||||
display the images.
|
||||
|
||||
\li \c View is the main application widget allowing the user to
|
||||
browse through the various locations.
|
||||
browse through the various items.
|
||||
|
||||
\li \c InformationWindow displays the requested information,
|
||||
allowing the users to alter it and submit their changes to the
|
||||
@ -70,7 +69,7 @@
|
||||
\snippet drilldown/informationwindow.h 0
|
||||
|
||||
When we create an information window, we pass the associated
|
||||
location ID, a parent, and a pointer to the database, to the
|
||||
item ID, a parent, and a pointer to the database, to the
|
||||
constructor. We will use the database pointer to populate our
|
||||
window with data, while passing the parent parameter on to the
|
||||
base class. The ID is stored for future reference.
|
||||
@ -84,7 +83,7 @@
|
||||
|
||||
\snippet drilldown/informationwindow.h 1
|
||||
|
||||
Since we allow the users to alter some of the location data, we
|
||||
Since we allow the users to alter some of the data, we
|
||||
must provide functionality for reverting and submitting their
|
||||
changes. The \c enableButtons() slot is provided for convenience
|
||||
to enable and disable the various buttons when required.
|
||||
@ -93,15 +92,15 @@
|
||||
|
||||
The \c createButtons() function is also a convenience function,
|
||||
provided to simplify the constructor. As mentioned above we store
|
||||
the location ID for future reference. We also store the name of
|
||||
the item ID for future reference. We also store the name of
|
||||
the currently displayed image file to be able to determine when to
|
||||
emit the \c imageChanged() signal.
|
||||
|
||||
The information window uses the QLabel class to display the office
|
||||
location and the country. The associated image file is displayed
|
||||
using a QComboBox instance while the description is displayed using
|
||||
QTextEdit. In addition, the window has three buttons to control
|
||||
the data flow and whether the window is shown or not.
|
||||
The information window uses the QLabel class to display the name of
|
||||
an item. The associated image file is displayed using a QComboBox
|
||||
instance while the description is displayed using QTextEdit. In
|
||||
addition, the window has three buttons to control the data flow and
|
||||
whether the window is shown or not.
|
||||
|
||||
Finally, we declare a \e mapper. The QDataWidgetMapper class
|
||||
provides mapping between a section of a data model to widgets. We
|
||||
@ -110,7 +109,7 @@
|
||||
|
||||
\section1 InformationWindow Class Implementation
|
||||
|
||||
The constructor takes three arguments: a location ID, a database
|
||||
The constructor takes three arguments: an item ID, a database
|
||||
pointer and a parent widget. The database pointer is actually a
|
||||
pointer to a QSqlRelationalTableModel object providing an editable
|
||||
data model (with foreign key support) for our database table.
|
||||
@ -125,8 +124,8 @@
|
||||
|
||||
\snippet drilldown/informationwindow.cpp 2
|
||||
|
||||
In this example, the information about the offices are stored in a
|
||||
database table called "offices". When creating the model,
|
||||
In this example, information about the items are stored in a
|
||||
database table called "items". When creating the model,
|
||||
we will use a foreign key to establish a relation between this
|
||||
table and a second data base table, "images", containing the names
|
||||
of the available image files. We will get back to how this is done
|
||||
@ -140,7 +139,7 @@
|
||||
the foreign key (in this case the "imagefile" column number) as
|
||||
argument. We use QComboBox's \l {QComboBox::}{setModel()} function
|
||||
to make the combobox use the "images" model. And, since this model
|
||||
has two columns ("locationid" and "file"), we also specify which
|
||||
has two columns ("itemid" and "file"), we also specify which
|
||||
column we want to be visible using the QComboBox::setModelColumn()
|
||||
function.
|
||||
|
||||
@ -156,7 +155,7 @@
|
||||
section is a column in the model, otherwise it is a row. We call
|
||||
the \l {QDataWidgetMapper::}{setCurrentIndex()} function to
|
||||
initialize the widgets with the data associated with the given
|
||||
location ID. Every time the current index changes, all the widgets
|
||||
item ID. Every time the current index changes, all the widgets
|
||||
are updated with the contents from the model.
|
||||
|
||||
We also set the mapper's submit policy to
|
||||
@ -168,14 +167,14 @@
|
||||
view should use for its items. The QSqlRelationalDelegate class
|
||||
represents a delegate that unlike the default delegate, enables
|
||||
combobox functionality for fields that are foreign keys into other
|
||||
tables (like "imagefile" in our "trolltechoffices" table).
|
||||
tables (like "imagefile" in our "items" table).
|
||||
|
||||
\snippet drilldown/informationwindow.cpp 4
|
||||
|
||||
Finally, we connect the "something's changed" signals in the
|
||||
editors to our custom \c enableButtons() slot, enabling the users
|
||||
to either submit or revert their changes. We add all the widgets
|
||||
into a layout, store the location ID and the name of the displayed
|
||||
into a layout, store the item ID and the name of the displayed
|
||||
image file for future reference, and set the window title and
|
||||
initial size.
|
||||
|
||||
@ -189,7 +188,7 @@
|
||||
application exits (i.e., if the user closes the information
|
||||
window, it is only hidden). For this reason we do not want to
|
||||
create more than one \c InformationWindow object for each
|
||||
location, and we provide the public \c id() function to be able to
|
||||
item, and we provide the public \c id() function to be able to
|
||||
determine whether a window already exists for a given location
|
||||
when the user requests information about it.
|
||||
|
||||
@ -256,16 +255,15 @@
|
||||
{QDialogButtonBox::ButtonRole}{reject} role indicates that
|
||||
clicking the button causes the dialog to be rejected. On the other
|
||||
hand, since we only hide the information window, any changes that
|
||||
the user has made wil be preserved until the user expliclity
|
||||
revert or submit them.
|
||||
the user has made will be preserved until the user explicitly
|
||||
reverts or submits them.
|
||||
|
||||
\snippet drilldown/informationwindow.cpp 10
|
||||
|
||||
The \c enableButtons() slot is called to enable the buttons
|
||||
whenever the user changes the presented data. Likewise, when the
|
||||
data the user choose to submit the changes, the buttons are
|
||||
disabled to indicate that the current data is stored in the
|
||||
database.
|
||||
user chooses to submit the changes, the buttons are disabled to
|
||||
indicate that the current data is stored in the database.
|
||||
|
||||
This completes the \c InformationWindow class. Let's take a look
|
||||
at how we have used it in our example application.
|
||||
@ -280,19 +278,17 @@
|
||||
\snippet drilldown/view.h 1
|
||||
|
||||
The QGraphicsView class is part of the \l {Graphics View
|
||||
Framework} which we will use to display the images of Nokia's
|
||||
Qt offices. To be able to respond to user interaction;
|
||||
i.e., showing the
|
||||
appropriate information window whenever the user clicks one of the
|
||||
office images, we reimplement QGraphicsView's \l
|
||||
{QGraphicsView::}{mouseReleaseEvent()} function.
|
||||
Framework} which we will use to display the images. To be able to
|
||||
respond to user interaction by displaying the appropriate
|
||||
information window when the image is clicked, we reimplement
|
||||
QGraphicsView's \l{QGraphicsView::}{mouseReleaseEvent()} function.
|
||||
|
||||
Note that the constructor expects the names of two database
|
||||
tables: One containing the detailed information about the offices,
|
||||
tables: One containing the detailed information about the items,
|
||||
and another containing the names of the available image files. We
|
||||
also provide a private \c updateImage() slot to catch \c
|
||||
{InformationWindow}'s \c imageChanged() signal that is emitted
|
||||
whenever the user changes a location's image.
|
||||
whenever the user changes an image associated with the item.
|
||||
|
||||
\snippet drilldown/view.h 2
|
||||
|
||||
@ -303,20 +299,20 @@
|
||||
The \c findWindow() function, on the other hand, is frequently
|
||||
used. It is called from the \c showInformation() function to
|
||||
detemine whether a window is already created for the given
|
||||
location (whenever we create an \c InformationWindow object, we
|
||||
item (whenever we create an \c InformationWindow object, we
|
||||
store a reference to it in the \c informationWindows list). The
|
||||
latter function is in turn called from our custom \c
|
||||
mouseReleaseEvent() implementation.
|
||||
|
||||
\snippet drilldown/view.h 3
|
||||
|
||||
Finally we declare a QSqlRelationalTableModel pointer. As
|
||||
Finally, we declare a QSqlRelationalTableModel pointer. As
|
||||
previously mentioned, the QSqlRelationalTableModel class provides
|
||||
an editable data model with foreign key support. There are a
|
||||
couple of things you should keep in mind when using the
|
||||
QSqlRelationalTableModel class: The table must have a primary key
|
||||
declared and this key cannot contain a relation to another table,
|
||||
i.e., it cannot be a foreign key. Note also that if a relational
|
||||
that is, it cannot be a foreign key. Also note that if a relational
|
||||
table contains keys that refer to non-existent rows in the
|
||||
referenced table, the rows containing the invalid keys will not be
|
||||
exposed through the model. It is the user's or the database's
|
||||
@ -327,11 +323,11 @@
|
||||
Although the constructor requests the names of both the table
|
||||
containing office details as well as the table containing the
|
||||
names of the available image files, we only have to create a
|
||||
QSqlRelationalTableModel object for the office table:
|
||||
QSqlRelationalTableModel object for the "items" table:
|
||||
|
||||
\snippet drilldown/view.cpp 0
|
||||
|
||||
The reason is that once we have a model with the office details,
|
||||
The reason is that once we have a model with the item details,
|
||||
we can create a relation to the available image files using
|
||||
QSqlRelationalTableModel's \l
|
||||
{QSqlRelationalTableModel::}{setRelation()} function. This
|
||||
@ -348,20 +344,19 @@
|
||||
\snippet drilldown/view.cpp 1
|
||||
|
||||
Then we create the contents of our view, i.e., the scene and its
|
||||
items. The location labels are regular QGraphicsTextItem objects,
|
||||
and the "Qt" logo is represented by a QGraphicsPixmapItem
|
||||
object. The images, on the other hand, are instances of the \c
|
||||
ImageItem class (derived from QGraphicsPixmapItem). We will get
|
||||
back to this shortly when reviewing the \c addItems() function.
|
||||
items. The labels are regular QGraphicsTextItem objects, whereas
|
||||
the images are instances of the \c ImageItem class, derived from
|
||||
QGraphicsPixmapItem. We will get back to this shortly when reviewing
|
||||
the \c addItems() function.
|
||||
|
||||
Finally, we set the main application widget's size constraints and
|
||||
window title.
|
||||
|
||||
\snippet drilldown/view.cpp 3
|
||||
|
||||
The \c addItems() function is called only once, i.e., when
|
||||
creating the main application window. For each row in the database
|
||||
table, we first extract the corresponding record using the model's
|
||||
The \c addItems() function is called only once when creating the main
|
||||
application window. For each row in the database table, we first
|
||||
extract the corresponding record using the model's
|
||||
\l {QSqlRelationalTableModel::}{record()} function. The QSqlRecord
|
||||
class encapsulates both the functionality and characteristics of a
|
||||
database record, and supports adding and removing fields as well
|
||||
@ -394,7 +389,7 @@
|
||||
\snippet drilldown/view.cpp 6
|
||||
|
||||
The \c showInformation() function is given an \c ImageItem object
|
||||
as argument, and starts off by extracting the item's location
|
||||
as argument, and starts off by extracting the item's item
|
||||
ID. Then it determines if there already is created an information
|
||||
window for this location. If it is, and the window is visible, it
|
||||
ensures that the window is raised to the top of the widget stack
|
||||
@ -402,7 +397,7 @@
|
||||
{QWidget::}{show()} slot gives the same result.
|
||||
|
||||
If no window for the given location exists, we create one by
|
||||
passing the location ID, a pointer to the model, and our view as a
|
||||
passing the item ID, a pointer to the model, and our view as a
|
||||
parent, to the \c InformationWindow constructor. Note that we
|
||||
connect the information window's \c imageChanged() signal to \e
|
||||
this widget's \c updateImage() slot, before we give it a suitable
|
||||
@ -410,16 +405,16 @@
|
||||
|
||||
\snippet drilldown/view.cpp 7
|
||||
|
||||
The \c updateImage() slot takes a location ID and the name of an
|
||||
image files as arguments. It filters out the image items, and
|
||||
updates the one that correspond to the given location ID, with the
|
||||
The \c updateImage() slot takes an item ID and the name of an
|
||||
image file as arguments. It filters out the image items, and
|
||||
updates the one that correspond to the given item ID, with the
|
||||
provided image file.
|
||||
|
||||
\snippet drilldown/view.cpp 8
|
||||
|
||||
The \c findWindow() function simply searches through the list of
|
||||
existing windows, returning a pointer to the window that matches
|
||||
the given location ID, or 0 if the window doesn't exists.
|
||||
the given item ID, or 0 if the window doesn't exists.
|
||||
|
||||
Finally, let's take a quick look at our custom \c ImageItem class:
|
||||
|
||||
@ -442,7 +437,7 @@
|
||||
returning back to its original size when the cursor leaves its
|
||||
borders.
|
||||
|
||||
Finally, we store the location ID that this particular record is
|
||||
Finally, we store the item ID that this particular record is
|
||||
associated with as well as a z-value. In the \l {Graphics View
|
||||
Framework}, an item's z-value determines its position in the item
|
||||
stack. An item of high z-value will be drawn on top of an item
|
||||
@ -460,8 +455,8 @@
|
||||
\snippet drilldown/imageitem.cpp 0
|
||||
|
||||
Then we store the ID for future reference, and ensure that our
|
||||
item will accept hover events. Hover events are delivered when
|
||||
there is no current mouse grabber item. They are sent when the
|
||||
image item will accept hover events. Hover events are delivered
|
||||
when there is no current mouse grabber item. They are sent when the
|
||||
mouse cursor enters an item, when it moves around inside the item,
|
||||
and when the cursor leaves an item. As we mentioned earlier, none
|
||||
of the \l {Graphics View Framework}'s items accept hover
|
||||
@ -487,7 +482,7 @@
|
||||
\codeline
|
||||
\snippet drilldown/imageitem.cpp 2
|
||||
|
||||
Whenever the mouse cursor enters or leave the image item, the
|
||||
Whenever the mouse cursor enters or leaves the image item, the
|
||||
corresponding event handlers are triggered: We first set the time
|
||||
line's direction, making the item expand or shrink,
|
||||
respectively. Then we alter the item's z-value if it is not already
|
||||
@ -532,6 +527,6 @@
|
||||
size regardless of the size of the source image. The \c id()
|
||||
function is trivial, and is simply provided to be able to identify
|
||||
the item. In the \c updateItemPosition() slot we call the
|
||||
QGraphicsItem::setZValue() function, setting the elevation (i.e.,
|
||||
the position) of the item.
|
||||
QGraphicsItem::setZValue() function, setting the elevation of the
|
||||
item.
|
||||
*/
|
||||
|
@ -1,11 +1,8 @@
|
||||
<!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>
|
||||
<qresource prefix="/">
|
||||
<file>images/qt-logo.png</file>
|
||||
<file>images/qt-quick.png</file>
|
||||
<file>images/qt-creator.png</file>
|
||||
<file>images/qt-project.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -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]
|
||||
|
Before Width: | Height: | Size: 97 KiB |
Before Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 58 KiB |
Before Width: | Height: | Size: 41 KiB |
BIN
examples/sql/drilldown/images/qt-creator.png
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
examples/sql/drilldown/images/qt-logo.png
Normal file
After Width: | Height: | Size: 45 KiB |
BIN
examples/sql/drilldown/images/qt-project.png
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
examples/sql/drilldown/images/qt-quick.png
Normal file
After Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 38 KiB |
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
Before Width: | Height: | Size: 13 KiB |
@ -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);
|
||||
|
@ -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)));
|
||||
|
@ -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<InformationWindow *> informationWindows;
|
||||
//! [2] //! [3]
|
||||
QSqlRelationalTableModel *officeTable;
|
||||
QSqlRelationalTableModel *itemTable;
|
||||
};
|
||||
//! [3]
|
||||
|
||||
|