diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2024-01-13 00:00:41 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2024-01-14 09:32:04 +0100 |
commit | 8bfebaa22f66d2cc32d6147611bcbaea3a85188c (patch) | |
tree | a16e191d3449dff288badb64b45cb517658bc2a4 /examples | |
parent | 27dd17890060313d684b72c871be9da7eb2b74fe (diff) |
SQL examples: code cleanup
Misc code cleanup for the sql examples:
- don't include global Qt headers but only needed ones
- use proper tr() where possible
- pass parameters by const ref
- style fixes
Change-Id: I4fd4293948918b9d7b373b6d1e8eeecf6f25a622
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/sql/books/bookdelegate.cpp | 22 | ||||
-rw-r--r-- | examples/sql/books/bookdelegate.h | 3 | ||||
-rw-r--r-- | examples/sql/books/bookwindow.cpp | 27 | ||||
-rw-r--r-- | examples/sql/books/bookwindow.h | 11 | ||||
-rw-r--r-- | examples/sql/books/initdb.h | 4 | ||||
-rw-r--r-- | examples/sql/books/main.cpp | 2 | ||||
-rw-r--r-- | examples/sql/cachedtable/tableeditor.cpp | 11 | ||||
-rw-r--r-- | examples/sql/cachedtable/tableeditor.h | 8 | ||||
-rw-r--r-- | examples/sql/masterdetail/dialog.cpp | 39 | ||||
-rw-r--r-- | examples/sql/masterdetail/dialog.h | 27 | ||||
-rw-r--r-- | examples/sql/masterdetail/main.cpp | 2 | ||||
-rw-r--r-- | examples/sql/masterdetail/mainwindow.cpp | 59 | ||||
-rw-r--r-- | examples/sql/masterdetail/mainwindow.h | 29 | ||||
-rw-r--r-- | examples/sql/querymodel/customsqlmodel.cpp | 4 | ||||
-rw-r--r-- | examples/sql/querymodel/editablesqlmodel.cpp | 12 | ||||
-rw-r--r-- | examples/sql/querymodel/main.cpp | 2 | ||||
-rw-r--r-- | examples/sql/sqlwidgetmapper/window.cpp | 15 | ||||
-rw-r--r-- | examples/sql/sqlwidgetmapper/window.h | 22 | ||||
-rw-r--r-- | examples/sql/tablemodel/tablemodel.cpp | 2 |
19 files changed, 172 insertions, 129 deletions
diff --git a/examples/sql/books/bookdelegate.cpp b/examples/sql/books/bookdelegate.cpp index 6aac70b860..ead9f9e7db 100644 --- a/examples/sql/books/bookdelegate.cpp +++ b/examples/sql/books/bookdelegate.cpp @@ -3,14 +3,13 @@ #include "bookdelegate.h" -#include <QtWidgets> +#include <QMouseEvent> +#include <QPainter> +#include <QSpinBox> -BookDelegate::BookDelegate(QObject *parent) - : QSqlRelationalDelegate(parent) -{} - -void BookDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const +void BookDelegate::paint(QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const { if (index.column() != 5) { QSqlRelationalDelegate::paint(painter, option, index); @@ -38,18 +37,17 @@ void BookDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, QIcon starFilledIcon(QStringLiteral(":images/star-filled.svg")); for (int i = 0; i < 5; ++i) { - if (i < rating) { + if (i < rating) starFilledIcon.paint(painter, QRect(x, y, width, height)); - } else { + else starIcon.paint(painter, QRect(x, y, width, height)); - } x += width; } } } QSize BookDelegate::sizeHint(const QStyleOptionViewItem &option, - const QModelIndex &index) const + const QModelIndex &index) const { if (index.column() == 5) return QSize(5 * iconDimension, iconDimension) + QSize(cellPadding, cellPadding); @@ -66,7 +64,7 @@ bool BookDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, if (event->type() == QEvent::MouseButtonPress) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); - int stars = qBound(0, int(0.7 + qreal(mouseEvent->position().toPoint().x() + int stars = qBound(0, int(0.7 + qreal(mouseEvent->position().x() - option.rect.x()) / iconDimension), 5); model->setData(index, QVariant(stars)); // So that the selection can change: diff --git a/examples/sql/books/bookdelegate.h b/examples/sql/books/bookdelegate.h index 5ddb635515..b36cb371ac 100644 --- a/examples/sql/books/bookdelegate.h +++ b/examples/sql/books/bookdelegate.h @@ -5,7 +5,6 @@ #define BOOKDELEGATE_H #include <QModelIndex> -#include <QPixmap> #include <QSize> #include <QSqlRelationalDelegate> @@ -14,7 +13,7 @@ QT_FORWARD_DECLARE_CLASS(QPainter) class BookDelegate : public QSqlRelationalDelegate { public: - BookDelegate(QObject *parent); + using QSqlRelationalDelegate::QSqlRelationalDelegate; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; diff --git a/examples/sql/books/bookwindow.cpp b/examples/sql/books/bookwindow.cpp index 8b34bd7a77..6de2d5e80a 100644 --- a/examples/sql/books/bookwindow.cpp +++ b/examples/sql/books/bookwindow.cpp @@ -5,16 +5,27 @@ #include "bookdelegate.h" #include "initdb.h" -#include <QtSql> +#include <QApplication> +#include <QComboBox> +#include <QDataWidgetMapper> +#include <QGridLayout> +#include <QHeaderView> +#include <QLabel> +#include <QLineEdit> +#include <QMenu> +#include <QMenuBar> +#include <QMessageBox> +#include <QPainter> +#include <QScrollBar> +#include <QSpinBox> +#include <QSqlDatabase> +#include <QTableView> BookWindow::BookWindow() { if (!QSqlDatabase::drivers().contains("QSQLITE")) - QMessageBox::critical( - this, - "Unable to load database", - "This demo needs the SQLITE driver" - ); + QMessageBox::critical(this, tr("Unable to load database"), + tr("This demo needs the SQLITE driver")); // Initialize the database: QSqlError err = initDb(); @@ -50,8 +61,8 @@ BookWindow::BookWindow() void BookWindow::showError(const QSqlError &err) { - QMessageBox::critical(this, "Unable to initialize Database", - "Error initializing database: " + err.text()); + QMessageBox::critical(this, tr("Unable to initialize Database"), + tr("Error initializing database: %1").arg(err.text())); } void BookWindow::createLayout() diff --git a/examples/sql/books/bookwindow.h b/examples/sql/books/bookwindow.h index 03d83e219d..46d3570df1 100644 --- a/examples/sql/books/bookwindow.h +++ b/examples/sql/books/bookwindow.h @@ -4,8 +4,15 @@ #ifndef BOOKWINDOW_H #define BOOKWINDOW_H -#include <QtWidgets> -#include <QtSql> +#include <QMainWindow> +QT_FORWARD_DECLARE_CLASS(QComboBox) +QT_FORWARD_DECLARE_CLASS(QGridLayout) +QT_FORWARD_DECLARE_CLASS(QLabel) +QT_FORWARD_DECLARE_CLASS(QLineEdit) +QT_FORWARD_DECLARE_CLASS(QSpinBox) +QT_FORWARD_DECLARE_CLASS(QSqlError) +QT_FORWARD_DECLARE_CLASS(QSqlRelationalTableModel) +QT_FORWARD_DECLARE_CLASS(QTableView) class BookWindow: public QMainWindow { diff --git a/examples/sql/books/initdb.h b/examples/sql/books/initdb.h index 38fc9aeb71..9de8845a2f 100644 --- a/examples/sql/books/initdb.h +++ b/examples/sql/books/initdb.h @@ -4,7 +4,9 @@ #ifndef INITDB_H #define INITDB_H -#include <QtSql> +#include <QDate> +#include <QSqlError> +#include <QSqlQuery> void addBook(QSqlQuery &q, const QString &title, int year, const QVariant &authorId, const QVariant &genreId, int rating) diff --git a/examples/sql/books/main.cpp b/examples/sql/books/main.cpp index e65ac93642..76a05f1c39 100644 --- a/examples/sql/books/main.cpp +++ b/examples/sql/books/main.cpp @@ -3,7 +3,7 @@ #include "bookwindow.h" -#include <QtWidgets> +#include <QApplication> int main(int argc, char * argv[]) { diff --git a/examples/sql/cachedtable/tableeditor.cpp b/examples/sql/cachedtable/tableeditor.cpp index 97b3fa0d96..b92e256438 100644 --- a/examples/sql/cachedtable/tableeditor.cpp +++ b/examples/sql/cachedtable/tableeditor.cpp @@ -1,11 +1,16 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -#include <QtWidgets> -#include <QtSql> - #include "tableeditor.h" +#include <QDialogButtonBox> +#include <QHBoxLayout> +#include <QMessageBox> +#include <QPushButton> +#include <QSqlError> +#include <QSqlTableModel> +#include <QTableView> + //! [0] TableEditor::TableEditor(const QString &tableName, QWidget *parent) : QWidget(parent) diff --git a/examples/sql/cachedtable/tableeditor.h b/examples/sql/cachedtable/tableeditor.h index dfa50a8934..8c3c56b397 100644 --- a/examples/sql/cachedtable/tableeditor.h +++ b/examples/sql/cachedtable/tableeditor.h @@ -6,11 +6,9 @@ #include <QDialog> -QT_BEGIN_NAMESPACE -class QDialogButtonBox; -class QPushButton; -class QSqlTableModel; -QT_END_NAMESPACE +QT_FORWARD_DECLARE_CLASS(QDialogButtonBox) +QT_FORWARD_DECLARE_CLASS(QPushButton) +QT_FORWARD_DECLARE_CLASS(QSqlTableModel) //! [0] class TableEditor : public QWidget diff --git a/examples/sql/masterdetail/dialog.cpp b/examples/sql/masterdetail/dialog.cpp index 19e941af30..0b8ed8a75b 100644 --- a/examples/sql/masterdetail/dialog.cpp +++ b/examples/sql/masterdetail/dialog.cpp @@ -3,10 +3,23 @@ #include "dialog.h" -int uniqueAlbumId; -int uniqueArtistId; - -Dialog::Dialog(QSqlRelationalTableModel *albums, QDomDocument details, +#include <QDialogButtonBox> +#include <QDate> +#include <QDomDocument> +#include <QGroupBox> +#include <QLabel> +#include <QLineEdit> +#include <QMessageBox> +#include <QPushButton> +#include <QSpinBox> +#include <QSqlField> +#include <QSqlRelationalTableModel> +#include <QSqlRecord> +#include <QVBoxLayout> + +int Dialog::s_artistId = 0; +int Dialog::s_albumId = 0; +Dialog::Dialog(QSqlRelationalTableModel *albums, const QDomDocument &details, QFile *output, QWidget *parent) : QDialog(parent) { @@ -25,6 +38,12 @@ Dialog::Dialog(QSqlRelationalTableModel *albums, QDomDocument details, setWindowTitle(tr("Add Album")); } +void Dialog::setInitialAlbumAndArtistId(int albumId, int artistId) +{ + s_albumId = albumId; + s_artistId = artistId; +} + void Dialog::submit() { QString artist = artistEditor->text(); @@ -145,7 +164,7 @@ void Dialog::addTracks(int albumId, const QStringList &tracks) */ } -void Dialog::increaseAlbumCount(QModelIndex artistIndex) +void Dialog::increaseAlbumCount(const QModelIndex &artistIndex) { QSqlTableModel *artistModel = model->relationModel(2); @@ -219,7 +238,7 @@ QDialogButtonBox *Dialog::createButtons() return buttonBox; } -QModelIndex Dialog::indexOfArtist(const QString &artist) +QModelIndex Dialog::indexOfArtist(const QString &artist) const { QSqlTableModel *artistModel = model->relationModel(2); @@ -234,12 +253,12 @@ QModelIndex Dialog::indexOfArtist(const QString &artist) int Dialog::generateArtistId() { - uniqueArtistId += 1; - return uniqueArtistId; + s_artistId += 1; + return s_artistId; } int Dialog::generateAlbumId() { - uniqueAlbumId += 1; - return uniqueAlbumId; + s_albumId += 1; + return s_albumId; } diff --git a/examples/sql/masterdetail/dialog.h b/examples/sql/masterdetail/dialog.h index 0c5a728ebb..2a4f5a0b8e 100644 --- a/examples/sql/masterdetail/dialog.h +++ b/examples/sql/masterdetail/dialog.h @@ -4,17 +4,25 @@ #ifndef DIALOG_H #define DIALOG_H -#include <QtWidgets> -#include <QtSql> -#include <QtXml> +#include <QDialog> +#include <QDomDocument> + +QT_FORWARD_DECLARE_CLASS(QDialogButtonBox) +QT_FORWARD_DECLARE_CLASS(QFile) +QT_FORWARD_DECLARE_CLASS(QGroupBox) +QT_FORWARD_DECLARE_CLASS(QLineEdit) +QT_FORWARD_DECLARE_CLASS(QModelIndex) +QT_FORWARD_DECLARE_CLASS(QSpinBox) +QT_FORWARD_DECLARE_CLASS(QSqlRelationalTableModel) class Dialog : public QDialog { Q_OBJECT public: - Dialog(QSqlRelationalTableModel *albums, QDomDocument details, + Dialog(QSqlRelationalTableModel *albums, const QDomDocument &details, QFile *output, QWidget *parent = nullptr); + static void setInitialAlbumAndArtistId(int albumId, int artistId); private slots: void revert(); @@ -27,10 +35,8 @@ private: QDialogButtonBox *createButtons(); QGroupBox *createInputWidgets(); int findArtistId(const QString &artist); - static int generateAlbumId(); - static int generateArtistId(); - void increaseAlbumCount(QModelIndex artistIndex); - QModelIndex indexOfArtist(const QString &artist); + void increaseAlbumCount(const QModelIndex &artistIndex); + QModelIndex indexOfArtist(const QString &artist) const; QSqlRelationalTableModel *model; QDomDocument albumDetails; @@ -40,6 +46,11 @@ private: QLineEdit *titleEditor; QSpinBox *yearEditor; QLineEdit *tracksEditor; + + static int generateAlbumId(); + static int generateArtistId(); + static int s_artistId; + static int s_albumId; }; #endif diff --git a/examples/sql/masterdetail/main.cpp b/examples/sql/masterdetail/main.cpp index e99d8e8645..50d99cf24e 100644 --- a/examples/sql/masterdetail/main.cpp +++ b/examples/sql/masterdetail/main.cpp @@ -7,8 +7,6 @@ #include <QApplication> #include <QFile> -#include <stdlib.h> - int main(int argc, char *argv[]) { QApplication app(argc, argv); diff --git a/examples/sql/masterdetail/mainwindow.cpp b/examples/sql/masterdetail/mainwindow.cpp index d720db1033..020a149b22 100644 --- a/examples/sql/masterdetail/mainwindow.cpp +++ b/examples/sql/masterdetail/mainwindow.cpp @@ -4,12 +4,20 @@ #include "mainwindow.h" #include "dialog.h" -#include <QtWidgets> -#include <QtSql> -#include <QtXml> - -extern int uniqueAlbumId; -extern int uniqueArtistId; +#include <QApplication> +#include <QComboBox> +#include <QHeaderView> +#include <QFile> +#include <QGridLayout> +#include <QGroupBox> +#include <QLabel> +#include <QListWidget> +#include <QMenu> +#include <QMenuBar> +#include <QMessageBox> +#include <QSqlRecord> +#include <QSqlRelationalTableModel> +#include <QTableView> MainWindow::MainWindow(const QString &artistTable, const QString &albumTable, QFile *albumDetails, QWidget *parent) @@ -28,13 +36,12 @@ MainWindow::MainWindow(const QString &artistTable, const QString &albumTable, QGroupBox *details = createDetailsGroupBox(); artistView->setCurrentIndex(0); - uniqueAlbumId = model->rowCount(); - uniqueArtistId = artistView->count(); + Dialog::setInitialAlbumAndArtistId(model->rowCount(), artistView->count()); connect(model, &QSqlRelationalTableModel::rowsInserted, - this, &MainWindow::updateHeader); + this, &MainWindow::adjustHeader); connect(model, &QSqlRelationalTableModel::rowsRemoved, - this, &MainWindow::updateHeader); + this, &MainWindow::adjustHeader); QGridLayout *layout = new QGridLayout; layout->addWidget(artists, 0, 0); @@ -67,7 +74,7 @@ void MainWindow::changeArtist(int row) } } -void MainWindow::showArtistProfile(QModelIndex index) +void MainWindow::showArtistProfile(const QModelIndex &index) { QSqlRecord record = model->relationModel(2)->record(index.row()); @@ -84,7 +91,7 @@ void MainWindow::showArtistProfile(QModelIndex index) imageLabel->hide(); } -void MainWindow::showAlbumDetails(QModelIndex index) +void MainWindow::showAlbumDetails(const QModelIndex &index) { QSqlRecord record = model->record(index.row()); @@ -113,14 +120,11 @@ void MainWindow::getTrackList(QDomNode album) { trackList->clear(); - QDomNodeList tracks = album.childNodes(); - QDomNode track; - QString trackNumber; - + const QDomNodeList tracks = album.childNodes(); for (int i = 0; i < tracks.count(); ++i) { - track = tracks.item(i); - trackNumber = track.toElement().attribute("number"); + const QDomNode track = tracks.item(i); + const QString trackNumber = track.toElement().attribute("number"); QListWidgetItem *item = new QListWidgetItem(trackList); item->setText(trackNumber + ": " + track.toElement().text()); @@ -132,7 +136,7 @@ void MainWindow::addAlbum() Dialog *dialog = new Dialog(model, albumData, file, this); int accepted = dialog->exec(); - if (accepted == 1) { + if (accepted == QDialog::Accepted) { int lastRow = model->rowCount() - 1; albumView->selectRow(lastRow); albumView->scrollToBottom(); @@ -142,10 +146,10 @@ void MainWindow::addAlbum() void MainWindow::deleteAlbum() { - QModelIndexList selection = albumView->selectionModel()->selectedRows(0); + const QModelIndexList selection = albumView->selectionModel()->selectedRows(0); if (!selection.empty()) { - QModelIndex idIndex = selection.at(0); + const QModelIndex &idIndex = selection.at(0); int id = idIndex.data().toInt(); QString title = idIndex.sibling(idIndex.row(), 1).data().toString(); QString artist = idIndex.sibling(idIndex.row(), 2).data().toString(); @@ -172,9 +176,7 @@ void MainWindow::deleteAlbum() void MainWindow::removeAlbumFromFile(int id) { - QDomNodeList albums = albumData.elementsByTagName("album"); - for (int i = 0; i < albums.count(); ++i) { QDomNode node = albums.item(i); if (node.toElement().attribute("id").toInt() == id) { @@ -197,12 +199,12 @@ void MainWindow::removeAlbumFromFile(int id) */ } -void MainWindow::removeAlbumFromDatabase(QModelIndex index) +void MainWindow::removeAlbumFromDatabase(const QModelIndex &index) { model->removeRow(index.row()); } -void MainWindow::decreaseAlbumCount(QModelIndex artistIndex) +void MainWindow::decreaseAlbumCount(const QModelIndex &artistIndex) { int row = artistIndex.row(); QModelIndex albumCountIndex = artistIndex.sibling(row, 2); @@ -358,7 +360,7 @@ void MainWindow::showImageLabel() imageLabel->show(); } -QModelIndex MainWindow::indexOfArtist(const QString &artist) +QModelIndex MainWindow::indexOfArtist(const QString &artist) const { QSqlTableModel *artistModel = model->relationModel(2); @@ -370,11 +372,6 @@ QModelIndex MainWindow::indexOfArtist(const QString &artist) return QModelIndex(); } -void MainWindow::updateHeader(QModelIndex, int, int) -{ - adjustHeader(); -} - void MainWindow::adjustHeader() { albumView->hideColumn(0); diff --git a/examples/sql/masterdetail/mainwindow.h b/examples/sql/masterdetail/mainwindow.h index a5f9e70648..cc2a5c9f59 100644 --- a/examples/sql/masterdetail/mainwindow.h +++ b/examples/sql/masterdetail/mainwindow.h @@ -8,15 +8,13 @@ #include <QMainWindow> #include <QModelIndex> -QT_BEGIN_NAMESPACE -class QComboBox; -class QFile; -class QGroupBox; -class QLabel; -class QListWidget; -class QSqlRelationalTableModel; -class QTableView; -QT_END_NAMESPACE +QT_FORWARD_DECLARE_CLASS(QComboBox) +QT_FORWARD_DECLARE_CLASS(QFile) +QT_FORWARD_DECLARE_CLASS(QGroupBox) +QT_FORWARD_DECLARE_CLASS(QLabel) +QT_FORWARD_DECLARE_CLASS(QListWidget) +QT_FORWARD_DECLARE_CLASS(QSqlRelationalTableModel) +QT_FORWARD_DECLARE_CLASS(QTableView) class MainWindow : public QMainWindow { @@ -31,21 +29,20 @@ private slots: void addAlbum(); void changeArtist(int row); void deleteAlbum(); - void showAlbumDetails(QModelIndex index); - void showArtistProfile(QModelIndex index); - void updateHeader(QModelIndex, int, int); + void showAlbumDetails(const QModelIndex &index); + void showArtistProfile(const QModelIndex &index); + void adjustHeader(); private: - void adjustHeader(); QGroupBox *createAlbumGroupBox(); QGroupBox *createArtistGroupBox(); QGroupBox *createDetailsGroupBox(); void createMenuBar(); - void decreaseAlbumCount(QModelIndex artistIndex); + void decreaseAlbumCount(const QModelIndex &artistIndex); void getTrackList(QDomNode album); - QModelIndex indexOfArtist(const QString &artist); + QModelIndex indexOfArtist(const QString &artist) const; void readAlbumData(); - void removeAlbumFromDatabase(QModelIndex album); + void removeAlbumFromDatabase(const QModelIndex &album); void removeAlbumFromFile(int id); void showImageLabel(); diff --git a/examples/sql/querymodel/customsqlmodel.cpp b/examples/sql/querymodel/customsqlmodel.cpp index 9063911218..e87be12f09 100644 --- a/examples/sql/querymodel/customsqlmodel.cpp +++ b/examples/sql/querymodel/customsqlmodel.cpp @@ -1,10 +1,10 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -#include <QtWidgets> - #include "customsqlmodel.h" +#include <QColor> + CustomSqlModel::CustomSqlModel(QObject *parent) : QSqlQueryModel(parent) { diff --git a/examples/sql/querymodel/editablesqlmodel.cpp b/examples/sql/querymodel/editablesqlmodel.cpp index b7cb930020..dc91666c06 100644 --- a/examples/sql/querymodel/editablesqlmodel.cpp +++ b/examples/sql/querymodel/editablesqlmodel.cpp @@ -1,18 +1,17 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -#include <QtSql> - #include "editablesqlmodel.h" +#include <QSqlQuery> + EditableSqlModel::EditableSqlModel(QObject *parent) : QSqlQueryModel(parent) { } //! [0] -Qt::ItemFlags EditableSqlModel::flags( - const QModelIndex &index) const +Qt::ItemFlags EditableSqlModel::flags(const QModelIndex &index) const { Qt::ItemFlags flags = QSqlQueryModel::flags(index); if (index.column() == 1 || index.column() == 2) @@ -33,11 +32,10 @@ bool EditableSqlModel::setData(const QModelIndex &index, const QVariant &value, clear(); bool ok; - if (index.column() == 1) { + if (index.column() == 1) ok = setFirstName(id, value.toString()); - } else { + else ok = setLastName(id, value.toString()); - } refresh(); return ok; } diff --git a/examples/sql/querymodel/main.cpp b/examples/sql/querymodel/main.cpp index 8c5af768e3..a4680f7fe8 100644 --- a/examples/sql/querymodel/main.cpp +++ b/examples/sql/querymodel/main.cpp @@ -8,8 +8,6 @@ #include <QApplication> #include <QTableView> -#include <stdlib.h> - void initializeModel(QSqlQueryModel *model) { model->setQuery("select * from person"); diff --git a/examples/sql/sqlwidgetmapper/window.cpp b/examples/sql/sqlwidgetmapper/window.cpp index fee3bc78dd..cd44174f84 100644 --- a/examples/sql/sqlwidgetmapper/window.cpp +++ b/examples/sql/sqlwidgetmapper/window.cpp @@ -1,11 +1,20 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -#include <QtWidgets> -#include <QtSql> - #include "window.h" +#include <QComboBox> +#include <QDataWidgetMapper> +#include <QGridLayout> +#include <QLabel> +#include <QLineEdit> +#include <QMessageBox> +#include <QPushButton> +#include <QSqlQuery> +#include <QSqlRelationalDelegate> +#include <QSqlTableModel> +#include <QTextEdit> + //! [Set up widgets] Window::Window(QWidget *parent) : QWidget(parent) diff --git a/examples/sql/sqlwidgetmapper/window.h b/examples/sql/sqlwidgetmapper/window.h index c3b01155af..9af9628b90 100644 --- a/examples/sql/sqlwidgetmapper/window.h +++ b/examples/sql/sqlwidgetmapper/window.h @@ -6,18 +6,16 @@ #include <QWidget> -QT_BEGIN_NAMESPACE -class QComboBox; -class QDataWidgetMapper; -class QItemSelectionModel; -class QLabel; -class QLineEdit; -class QPushButton; -class QSqlRelationalTableModel; -class QStandardItemModel; -class QStringListModel; -class QTextEdit; -QT_END_NAMESPACE +QT_FORWARD_DECLARE_CLASS(QComboBox) +QT_FORWARD_DECLARE_CLASS(QDataWidgetMapper) +QT_FORWARD_DECLARE_CLASS(QItemSelectionModel) +QT_FORWARD_DECLARE_CLASS(QLabel) +QT_FORWARD_DECLARE_CLASS(QLineEdit) +QT_FORWARD_DECLARE_CLASS(QPushButton) +QT_FORWARD_DECLARE_CLASS(QSqlRelationalTableModel) +QT_FORWARD_DECLARE_CLASS(QStandardItemModel) +QT_FORWARD_DECLARE_CLASS(QStringListModel) +QT_FORWARD_DECLARE_CLASS(QTextEdit) //! [Window definition] class Window : public QWidget diff --git a/examples/sql/tablemodel/tablemodel.cpp b/examples/sql/tablemodel/tablemodel.cpp index ae0aa17719..04c114dc63 100644 --- a/examples/sql/tablemodel/tablemodel.cpp +++ b/examples/sql/tablemodel/tablemodel.cpp @@ -6,8 +6,6 @@ #include <QSqlTableModel> #include <QTableView> -#include <stdlib.h> - void initializeModel(QSqlTableModel *model) { model->setTable("person"); |