SQL/drilldown example: add new icons and misc cleanup

Cleanup the drilldown example:
 - use icons with the current style
 - remove unneeded QOverload<>
 - remove some empty lines which don't look good in the documentation
 - use Q_SLOTS/Q_SIGNALS instead slots/signals

Fixes: QTBUG-113696
Change-Id: I62476a8989c0abd1f424d1425cb05489491e2153
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Christian Ehrlicher 2023-11-10 21:13:05 +01:00
parent 1ffd12a8dc
commit fa045a3ce7
12 changed files with 17 additions and 21 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -46,8 +46,8 @@
\snippet drilldown/informationwindow.h 0 \snippet drilldown/informationwindow.h 0
When we create an information window, we pass the associated When we create an information window, we pass the associated
item ID, a parent, and a pointer to the database, to the item ID, a pointer to the model, and a parent to the
constructor. We will use the database pointer to populate our constructor. We will use the model pointer to populate our
window with data, while passing the parent parameter on to the window with data, while passing the parent parameter on to the
base class. The ID is stored for future reference. base class. The ID is stored for future reference.

View File

@ -54,7 +54,7 @@ void ImageItem::setFrame(int frame)
QPointF center = boundingRect().center(); QPointF center = boundingRect().center();
setTransform(QTransform::fromTranslate(center.x(), center.y()), true); setTransform(QTransform::fromTranslate(center.x(), center.y()), true);
setTransform(QTransform::fromScale(1 + frame / 330.0, 1 + frame / 330.0), true); setTransform(QTransform::fromScale(1 + frame / 300.0, 1 + frame / 300.0), true);
setTransform(QTransform::fromTranslate(-center.x(), -center.y()), true); setTransform(QTransform::fromTranslate(-center.x(), -center.y()), true);
} }
//! [3] //! [3]
@ -62,8 +62,8 @@ void ImageItem::setFrame(int frame)
//! [4] //! [4]
void ImageItem::adjust() void ImageItem::adjust()
{ {
setTransform(QTransform::fromScale(120 / boundingRect().width(), setTransform(QTransform::fromScale(120.0 / boundingRect().width(),
120 / boundingRect().height())); 120.0 / boundingRect().height()));
} }
//! [4] //! [4]

View File

@ -11,7 +11,6 @@
class ImageItem : public QObject, public QGraphicsPixmapItem class ImageItem : public QObject, public QGraphicsPixmapItem
{ {
Q_OBJECT Q_OBJECT
public: public:
enum { Type = UserType + 1 }; enum { Type = UserType + 1 };
@ -25,7 +24,7 @@ protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
private slots: private Q_SLOTS:
void setFrame(int frame); void setFrame(int frame);
void updateItemPosition(); void updateItemPosition();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

@ -9,9 +9,9 @@ InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *items,
: QDialog(parent) : QDialog(parent)
{ {
//! [0] //! [1] //! [0] //! [1]
QLabel *itemLabel = new QLabel(tr("Item: ")); QLabel *itemLabel = new QLabel(tr("Item:"));
QLabel *descriptionLabel = new QLabel(tr("Description: ")); QLabel *descriptionLabel = new QLabel(tr("Description:"));
QLabel *imageFileLabel = new QLabel(tr("Image file: ")); QLabel *imageFileLabel = new QLabel(tr("Image file:"));
createButtons(); createButtons();
@ -37,8 +37,8 @@ InformationWindow::InformationWindow(int id, QSqlRelationalTableModel *items,
//! [3] //! [3]
//! [4] //! [4]
connect(descriptionEditor, &QTextEdit::textChanged, this, [this]() { enableButtons(); }); connect(descriptionEditor, &QTextEdit::textChanged, this, [this]() { enableButtons(true); });
connect(imageFileEditor, &QComboBox::currentIndexChanged, this, [this]() { enableButtons(); }); connect(imageFileEditor, &QComboBox::currentIndexChanged, this, [this]() { enableButtons(true); });
QFormLayout *formLayout = new QFormLayout; QFormLayout *formLayout = new QFormLayout;
formLayout->addRow(itemLabel, itemText); formLayout->addRow(itemLabel, itemText);

View File

@ -11,22 +11,20 @@
class InformationWindow : public QDialog class InformationWindow : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
InformationWindow(int id, QSqlRelationalTableModel *items, InformationWindow(int id, QSqlRelationalTableModel *items,
QWidget *parent = nullptr); QWidget *parent = nullptr);
int id() const; int id() const;
signals: Q_SIGNALS:
void imageChanged(int id, const QString &fileName); void imageChanged(int id, const QString &fileName);
//! [0] //! [0]
//! [1] //! [1]
private slots: private Q_SLOTS:
void revert(); void revert();
void submit(); void submit();
void enableButtons(bool enable = true); void enableButtons(bool enable);
//! [1] //! [1]
//! [2] //! [2]

View File

@ -87,8 +87,8 @@ void View::showInformation(ImageItem *image)
if (!window) { if (!window) {
window = new InformationWindow(id, itemTable, this); window = new InformationWindow(id, itemTable, this);
connect(window, QOverload<int,const QString &>::of(&InformationWindow::imageChanged), connect(window, &InformationWindow::imageChanged,
this, QOverload<int,const QString &>::of(&View::updateImage)); this, &View::updateImage);
window->move(pos() + QPoint(20, 40)); window->move(pos() + QPoint(20, 40));
window->show(); window->show();

View File

@ -14,7 +14,6 @@ class InformationWindow;
class View : public QGraphicsView class View : public QGraphicsView
{ {
Q_OBJECT Q_OBJECT
public: public:
View(const QString &items, const QString &images, QWidget *parent = nullptr); View(const QString &items, const QString &images, QWidget *parent = nullptr);
@ -23,7 +22,7 @@ protected:
//! [0] //! [0]
//! [1] //! [1]
private slots: private Q_SLOTS:
void updateImage(int id, const QString &fileName); void updateImage(int id, const QString &fileName);
//! [1] //! [1]