From 9f27bfb31acfba49a74a342d9249f24633a7ade2 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Fri, 13 Apr 2018 09:01:43 +0200 Subject: Make sure we can build with -no-feature-draganddrop We move QInternalMimeData to a separate file, because this class is used, even if draganddrop is disabled. From now on, include qinternalmimedata_p.h instead of qdnd_p.h for QInternalMimeData. Change-Id: I594e08e2e90d574dc445119091686b4b69e4731b Reviewed-by: Gatis Paeglis --- examples/network/torrent/mainwindow.cpp | 6 +++--- examples/widgets/graphicsview/graphicsview.pro | 2 +- examples/widgets/itemviews/itemviews.pro | 2 +- examples/widgets/widgets.pro | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/network/torrent/mainwindow.cpp b/examples/network/torrent/mainwindow.cpp index f80c2c6975..660472c05c 100644 --- a/examples/network/torrent/mainwindow.cpp +++ b/examples/network/torrent/mainwindow.cpp @@ -62,7 +62,7 @@ class TorrentView : public QTreeWidget public: TorrentView(QWidget *parent = 0); -#ifndef QT_NO_DRAGANDDROP +#if QT_CONFIG(draganddrop) signals: void fileDropped(const QString &fileName); @@ -702,12 +702,12 @@ void MainWindow::closeEvent(QCloseEvent *) TorrentView::TorrentView(QWidget *parent) : QTreeWidget(parent) { -#ifndef QT_NO_DRAGANDDROP +#if QT_CONFIG(draganddrop) setAcceptDrops(true); #endif } -#ifndef QT_NO_DRAGANDDROP +#if QT_CONFIG(draganddrop) void TorrentView::dragMoveEvent(QDragMoveEvent *event) { // Accept file actions with a '.torrent' extension. diff --git a/examples/widgets/graphicsview/graphicsview.pro b/examples/widgets/graphicsview/graphicsview.pro index 5a054fe6b2..b9bef70a0e 100644 --- a/examples/widgets/graphicsview/graphicsview.pro +++ b/examples/widgets/graphicsview/graphicsview.pro @@ -13,7 +13,7 @@ SUBDIRS = \ simpleanchorlayout \ weatheranchorlayout -contains(DEFINES, QT_NO_CURSOR)|contains(DEFINES, QT_NO_DRAGANDDROP): SUBDIRS -= dragdroprobot +contains(DEFINES, QT_NO_CURSOR)|!qtConfig(draganddrop): SUBDIRS -= dragdroprobot qtHaveModule(opengl):!qtConfig(opengles.):!qtConfig(dynamicgl) { SUBDIRS += boxes diff --git a/examples/widgets/itemviews/itemviews.pro b/examples/widgets/itemviews/itemviews.pro index 75307bd74e..b4a002c156 100644 --- a/examples/widgets/itemviews/itemviews.pro +++ b/examples/widgets/itemviews/itemviews.pro @@ -20,5 +20,5 @@ SUBDIRS = addressbook \ spreadsheet \ stardelegate \ storageview -contains(DEFINES, QT_NO_DRAGANDDROP): SUBDIRS -= puzzle +!qtConfig(draganddrop): SUBDIRS -= puzzle !qtHaveModule(xml): SUBDIRS -= simpledommodel diff --git a/examples/widgets/widgets.pro b/examples/widgets/widgets.pro index cef4936d32..f9d863b69e 100644 --- a/examples/widgets/widgets.pro +++ b/examples/widgets/widgets.pro @@ -26,5 +26,5 @@ qtHaveModule(gui):qtConfig(opengl): \ SUBDIRS += windowcontainer contains(DEFINES, QT_NO_CURSOR): SUBDIRS -= mainwindows -contains(DEFINES, QT_NO_DRAGANDDROP): SUBDIRS -= draganddrop +!qtConfig(draganddrop): SUBDIRS -= draganddrop mac:SUBDIRS += mac -- cgit v1.2.3 From 28738d2d8d6db6b0a771c3c6676450e7269e4f37 Mon Sep 17 00:00:00 2001 From: Nico Vertriest Date: Tue, 22 May 2018 12:23:54 +0200 Subject: Doc: Add formatting features to Notepad example - bold, italic, underline - About button Change-Id: I8ece7d2bfca0b148b681a2fccb4a439ce179848a Reviewed-by: Venugopal Shivashankar --- examples/widgets/tutorials/notepad/images/bold.png | Bin 0 -> 724 bytes .../widgets/tutorials/notepad/images/italic.png | Bin 0 -> 471 bytes .../widgets/tutorials/notepad/images/underline.png | Bin 0 -> 520 bytes examples/widgets/tutorials/notepad/notepad.cpp | 24 ++++ examples/widgets/tutorials/notepad/notepad.h | 10 +- examples/widgets/tutorials/notepad/notepad.qrc | 17 ++- examples/widgets/tutorials/notepad/notepad.ui | 153 +++++++++++++++++++-- 7 files changed, 182 insertions(+), 22 deletions(-) create mode 100644 examples/widgets/tutorials/notepad/images/bold.png create mode 100644 examples/widgets/tutorials/notepad/images/italic.png create mode 100644 examples/widgets/tutorials/notepad/images/underline.png (limited to 'examples') diff --git a/examples/widgets/tutorials/notepad/images/bold.png b/examples/widgets/tutorials/notepad/images/bold.png new file mode 100644 index 0000000000..fe737cdb76 Binary files /dev/null and b/examples/widgets/tutorials/notepad/images/bold.png differ diff --git a/examples/widgets/tutorials/notepad/images/italic.png b/examples/widgets/tutorials/notepad/images/italic.png new file mode 100644 index 0000000000..337aac23a9 Binary files /dev/null and b/examples/widgets/tutorials/notepad/images/italic.png differ diff --git a/examples/widgets/tutorials/notepad/images/underline.png b/examples/widgets/tutorials/notepad/images/underline.png new file mode 100644 index 0000000000..437c45b3b1 Binary files /dev/null and b/examples/widgets/tutorials/notepad/images/underline.png differ diff --git a/examples/widgets/tutorials/notepad/notepad.cpp b/examples/widgets/tutorials/notepad/notepad.cpp index 44d8597cb7..99a1a52c2b 100644 --- a/examples/widgets/tutorials/notepad/notepad.cpp +++ b/examples/widgets/tutorials/notepad/notepad.cpp @@ -191,3 +191,27 @@ void Notepad::on_actionFont_triggered() if (fontSelected) ui->textEdit->setFont(font); } + +void Notepad::on_actionUnderline_triggered() +{ + ui->textEdit->setFontUnderline(ui->actionUnderline->isChecked()); +} + +void Notepad::on_actionItalic_triggered() +{ + ui->textEdit->setFontItalic(ui->actionItalic->isChecked()); +} + +void Notepad::on_actionBold_triggered() +{ + ui->actionBold->isChecked() ? ui->textEdit->setFontWeight(QFont::Bold) : + ui->textEdit->setFontWeight(QFont::Normal); +} + +void Notepad::on_actionAbout_triggered() +{ + QMessageBox::about(this, tr("About MDI"), + tr("The Notepad example demonstrates how to code a basic " + "text editor using QtWidgets")); + +} diff --git a/examples/widgets/tutorials/notepad/notepad.h b/examples/widgets/tutorials/notepad/notepad.h index f688df45ac..288ab4e373 100644 --- a/examples/widgets/tutorials/notepad/notepad.h +++ b/examples/widgets/tutorials/notepad/notepad.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2018 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. @@ -103,6 +103,14 @@ private slots: void on_actionFont_triggered(); + void on_actionBold_triggered(); + + void on_actionUnderline_triggered(); + + void on_actionItalic_triggered(); + + void on_actionAbout_triggered(); + //! [6] private: Ui::Notepad *ui; diff --git a/examples/widgets/tutorials/notepad/notepad.qrc b/examples/widgets/tutorials/notepad/notepad.qrc index ec11679f13..8c0486bc39 100644 --- a/examples/widgets/tutorials/notepad/notepad.qrc +++ b/examples/widgets/tutorials/notepad/notepad.qrc @@ -1,12 +1,5 @@ - images/copy.png - images/create.png - images/cut.png - images/edit_redo.png - images/edit_undo.png - images/exit.png - images/font.png images/info.png images/new.png images/open.png @@ -15,5 +8,15 @@ images/print.png images/save.png images/save_as.png + images/exit.png + images/font.png + images/copy.png + images/create.png + images/cut.png + images/edit_redo.png + images/edit_undo.png + images/bold.png + images/italic.png + images/underline.png diff --git a/examples/widgets/tutorials/notepad/notepad.ui b/examples/widgets/tutorials/notepad/notepad.ui index d197a95fe7..4b2a6a0675 100644 --- a/examples/widgets/tutorials/notepad/notepad.ui +++ b/examples/widgets/tutorials/notepad/notepad.ui @@ -6,8 +6,8 @@ 0 0 - 524 - 300 + 800 + 400 @@ -25,7 +25,7 @@ 0 0 - 524 + 800 25 @@ -74,7 +74,13 @@ + + + + + + @@ -87,105 +93,224 @@ New + + New text document + + + Ctrl+N + - + :/images/open.png:/images/open.png Open + + Open file + + + Ctrl+O + - + :/images/save.png:/images/save.png Save + + Save file + + + Ctrl+S + - + :/images/save_as.png:/images/save_as.png Save as + + Save file as + + + Alt+S + - + :/images/print.png:/images/print.png Print + + Print file + + + Ctrl+P + - + :/images/exit.png:/images/exit.png Exit + + Exit notepad + + + - + :/images/copy.png:/images/copy.png Copy + + Ctrl+C + - + :/images/cut.png:/images/cut.png Cut + + Ctrl+X + - + :/images/paste.png:/images/paste.png Paste + + Ctrl+V + - + :/images/edit_undo.png:/images/edit_undo.png Undo + + Ctrl+Z + - + :/images/edit_redo.png:/images/edit_redo.png Redo + + Ctrl+Y + - + :/images/font.png:/images/font.png Font + + Ctrl+F + + + + + true + + + + :/images/italic.png:/images/italic.png + + + Italic + + + Italic font + + + Ctrl+I + + + + + true + + + + :/images/bold.png:/images/bold.png + + + actionBold + + + Bold + + + Ctrl+B + + + + + true + + + + :/images/underline.png:/images/underline.png + + + Underline + + + Underline + + + Ctrl+U + + + + + + :/images/info.png:/images/info.png + + + About + + + About Notepad + -- cgit v1.2.3 From 7b74b4fbec299c2c8a9956a01d73beda69aee0df Mon Sep 17 00:00:00 2001 From: Nico Vertriest Date: Thu, 19 Apr 2018 14:24:24 +0200 Subject: Doc: Update connect syntax Plugandpaint Example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-60635 Change-Id: I354a0886b22c63be57bd927308163abd3246be77 Reviewed-by: André Hartmann Reviewed-by: Paul Wicking Reviewed-by: Venugopal Shivashankar --- .../widgets/tools/plugandpaint/app/mainwindow.cpp | 28 +++++++++++----------- .../widgets/tools/plugandpaint/app/mainwindow.h | 4 +++- .../tools/plugandpaint/app/plugindialog.cpp | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) (limited to 'examples') diff --git a/examples/widgets/tools/plugandpaint/app/mainwindow.cpp b/examples/widgets/tools/plugandpaint/app/mainwindow.cpp index 12c65e9364..b2287ee072 100644 --- a/examples/widgets/tools/plugandpaint/app/mainwindow.cpp +++ b/examples/widgets/tools/plugandpaint/app/mainwindow.cpp @@ -85,7 +85,7 @@ MainWindow::MainWindow() : if (!brushActionGroup->actions().isEmpty()) brushActionGroup->actions().first()->trigger(); - QTimer::singleShot(500, this, SLOT(aboutPlugins())); + QTimer::singleShot(500, this, &MainWindow::aboutPlugins); } void MainWindow::open() @@ -189,32 +189,32 @@ void MainWindow::createActions() { openAct = new QAction(tr("&Open..."), this); openAct->setShortcuts(QKeySequence::Open); - connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + connect(openAct, &QAction::triggered, this, &MainWindow::open); saveAsAct = new QAction(tr("&Save As..."), this); saveAsAct->setShortcuts(QKeySequence::SaveAs); - connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); + connect(saveAsAct, &QAction::triggered, this, &MainWindow::saveAs); exitAct = new QAction(tr("E&xit"), this); exitAct->setShortcuts(QKeySequence::Quit); - connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + connect(exitAct, &QAction::triggered, this, &MainWindow::close); brushColorAct = new QAction(tr("&Brush Color..."), this); - connect(brushColorAct, SIGNAL(triggered()), this, SLOT(brushColor())); + connect(brushColorAct, &QAction::triggered, this, &MainWindow::brushColor); brushWidthAct = new QAction(tr("&Brush Width..."), this); - connect(brushWidthAct, SIGNAL(triggered()), this, SLOT(brushWidth())); + connect(brushWidthAct, &QAction::triggered, this, &MainWindow::brushWidth); brushActionGroup = new QActionGroup(this); aboutAct = new QAction(tr("&About"), this); - connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + connect(aboutAct, &QAction::triggered, this, &MainWindow::about); aboutQtAct = new QAction(tr("About &Qt"), this); - connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt); aboutPluginsAct = new QAction(tr("About &Plugins"), this); - connect(aboutPluginsAct, SIGNAL(triggered()), this, SLOT(aboutPlugins())); + connect(aboutPluginsAct, &QAction::triggered, this, &MainWindow::aboutPlugins); } void MainWindow::createMenus() @@ -289,26 +289,26 @@ void MainWindow::populateMenus(QObject *plugin) { BrushInterface *iBrush = qobject_cast(plugin); if (iBrush) - addToMenu(plugin, iBrush->brushes(), brushMenu, SLOT(changeBrush()), + addToMenu(plugin, iBrush->brushes(), brushMenu, &MainWindow::changeBrush, brushActionGroup); ShapeInterface *iShape = qobject_cast(plugin); if (iShape) - addToMenu(plugin, iShape->shapes(), shapesMenu, SLOT(insertShape())); + addToMenu(plugin, iShape->shapes(), shapesMenu, &MainWindow::insertShape); FilterInterface *iFilter = qobject_cast(plugin); if (iFilter) - addToMenu(plugin, iFilter->filters(), filterMenu, SLOT(applyFilter())); + addToMenu(plugin, iFilter->filters(), filterMenu, &MainWindow::applyFilter); } //! [10] void MainWindow::addToMenu(QObject *plugin, const QStringList &texts, - QMenu *menu, const char *member, + QMenu *menu, Member member, QActionGroup *actionGroup) { foreach (QString text, texts) { QAction *action = new QAction(text, plugin); - connect(action, SIGNAL(triggered()), this, member); + connect(action, &QAction::triggered, this, member); menu->addAction(action); if (actionGroup) { diff --git a/examples/widgets/tools/plugandpaint/app/mainwindow.h b/examples/widgets/tools/plugandpaint/app/mainwindow.h index 398759fecf..7d2c085c23 100644 --- a/examples/widgets/tools/plugandpaint/app/mainwindow.h +++ b/examples/widgets/tools/plugandpaint/app/mainwindow.h @@ -82,12 +82,14 @@ private slots: void aboutPlugins(); private: + typedef void (MainWindow::*Member)(); + void createActions(); void createMenus(); void loadPlugins(); void populateMenus(QObject *plugin); void addToMenu(QObject *plugin, const QStringList &texts, QMenu *menu, - const char *member, QActionGroup *actionGroup = 0); + Member member, QActionGroup *actionGroup = 0); PaintArea *paintArea; QScrollArea *scrollArea; diff --git a/examples/widgets/tools/plugandpaint/app/plugindialog.cpp b/examples/widgets/tools/plugandpaint/app/plugindialog.cpp index 00c2498bd5..43eb34f423 100644 --- a/examples/widgets/tools/plugandpaint/app/plugindialog.cpp +++ b/examples/widgets/tools/plugandpaint/app/plugindialog.cpp @@ -77,7 +77,7 @@ PluginDialog::PluginDialog(const QString &path, const QStringList &fileNames, okButton->setDefault(true); - connect(okButton, SIGNAL(clicked()), this, SLOT(close())); + connect(okButton, &QAbstractButton::clicked, this, &QWidget::close); QGridLayout *mainLayout = new QGridLayout; mainLayout->setColumnStretch(0, 1); -- cgit v1.2.3 From ce7cbcc3b64a1b0b6e5cf91d911d3ad10e7d6424 Mon Sep 17 00:00:00 2001 From: Paul Wicking Date: Tue, 5 Jun 2018 13:13:38 +0200 Subject: Doc: Clean up and modernize SQL example: Books MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Replace Qt4-style connects. * Reformat code to adhere to 80 column width. * Touch comments to make location and style consistent. * Rename a label in the UI form. Task-number: QTBUG-68652 Change-Id: Icc592f7b5a013d1806bc36c45057b35472b6efbb Reviewed-by: Topi Reiniö --- examples/sql/books/bookdelegate.cpp | 28 ++++--- examples/sql/books/bookwindow.cpp | 42 ++++++---- examples/sql/books/bookwindow.ui | 149 ++++++++++++++++++++---------------- 3 files changed, 126 insertions(+), 93 deletions(-) (limited to 'examples') diff --git a/examples/sql/books/bookdelegate.cpp b/examples/sql/books/bookdelegate.cpp index 6a42fd2db7..4115f80cf3 100644 --- a/examples/sql/books/bookdelegate.cpp +++ b/examples/sql/books/bookdelegate.cpp @@ -62,15 +62,21 @@ void BookDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, { if (index.column() != 5) { QStyleOptionViewItem opt = option; - opt.rect.adjust(0, 0, -1, -1); // since we draw the grid ourselves + // Since we draw the grid ourselves: + opt.rect.adjust(0, 0, -1, -1); QSqlRelationalDelegate::paint(painter, opt, index); } else { const QAbstractItemModel *model = index.model(); QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? - (option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive : QPalette::Disabled; + (option.state & QStyle::State_Active) ? + QPalette::Normal : + QPalette::Inactive : + QPalette::Disabled; if (option.state & QStyle::State_Selected) - painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight)); + painter->fillRect( + option.rect, + option.palette.color(cg, QPalette::Highlight)); int rating = model->data(index, Qt::DisplayRole).toInt(); int width = star.width(); @@ -81,7 +87,8 @@ void BookDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, painter->drawPixmap(x, y, star); x += width; } - drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves + // Since we draw the grid ourselves: + drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); } QPen pen = painter->pen(); @@ -96,8 +103,8 @@ QSize BookDelegate::sizeHint(const QStyleOptionViewItem &option, { if (index.column() == 5) return QSize(5 * star.width(), star.height()) + QSize(1, 1); - - return QSqlRelationalDelegate::sizeHint(option, index) + QSize(1, 1); // since we draw the grid ourselves + // Since we draw the grid ourselves: + return QSqlRelationalDelegate::sizeHint(option, index) + QSize(1, 1); } bool BookDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, @@ -112,19 +119,21 @@ bool BookDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, int stars = qBound(0, int(0.7 + qreal(mouseEvent->pos().x() - option.rect.x()) / star.width()), 5); model->setData(index, QVariant(stars)); - return false; //so that the selection can change + // So that the selection can change: + return false; } return true; } -QWidget *BookDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, +QWidget *BookDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem &option, const QModelIndex &index) const { if (index.column() != 4) return QSqlRelationalDelegate::createEditor(parent, option, index); - // for editing the year, return a spinbox with a range from -1000 to 2100. + // For editing the year, return a spinbox with a range from -1000 to 2100. QSpinBox *sb = new QSpinBox(parent); sb->setFrame(false); sb->setMaximum(2100); @@ -132,4 +141,3 @@ QWidget *BookDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem return sb; } - diff --git a/examples/sql/books/bookwindow.cpp b/examples/sql/books/bookwindow.cpp index 1428bc04b5..d85b438956 100644 --- a/examples/sql/books/bookwindow.cpp +++ b/examples/sql/books/bookwindow.cpp @@ -59,53 +59,61 @@ BookWindow::BookWindow() ui.setupUi(this); if (!QSqlDatabase::drivers().contains("QSQLITE")) - QMessageBox::critical(this, "Unable to load database", "This demo needs the SQLITE driver"); + QMessageBox::critical( + this, + "Unable to load database", + "This demo needs the SQLITE driver" + ); - // initialize the database + // Initialize the database: QSqlError err = initDb(); if (err.type() != QSqlError::NoError) { showError(err); return; } - // Create the data model + // Create the data model: model = new QSqlRelationalTableModel(ui.bookTable); model->setEditStrategy(QSqlTableModel::OnManualSubmit); model->setTable("books"); - // Remember the indexes of the columns + // Remember the indexes of the columns: authorIdx = model->fieldIndex("author"); genreIdx = model->fieldIndex("genre"); - // Set the relations to the other database tables + // Set the relations to the other database tables: model->setRelation(authorIdx, QSqlRelation("authors", "id", "name")); model->setRelation(genreIdx, QSqlRelation("genres", "id", "name")); - // Set the localized header captions + // Set the localized header captions: model->setHeaderData(authorIdx, Qt::Horizontal, tr("Author Name")); model->setHeaderData(genreIdx, Qt::Horizontal, tr("Genre")); - model->setHeaderData(model->fieldIndex("title"), Qt::Horizontal, tr("Title")); + model->setHeaderData(model->fieldIndex("title"), + Qt::Horizontal, tr("Title")); model->setHeaderData(model->fieldIndex("year"), Qt::Horizontal, tr("Year")); - model->setHeaderData(model->fieldIndex("rating"), Qt::Horizontal, tr("Rating")); + model->setHeaderData(model->fieldIndex("rating"), + Qt::Horizontal, tr("Rating")); - // Populate the model + // Populate the model: if (!model->select()) { showError(model->lastError()); return; } - // Set the model and hide the ID column + // Set the model and hide the ID column: ui.bookTable->setModel(model); ui.bookTable->setItemDelegate(new BookDelegate(ui.bookTable)); ui.bookTable->setColumnHidden(model->fieldIndex("id"), true); ui.bookTable->setSelectionMode(QAbstractItemView::SingleSelection); - // Initialize the Author combo box + // Initialize the Author combo box: ui.authorEdit->setModel(model->relationModel(authorIdx)); - ui.authorEdit->setModelColumn(model->relationModel(authorIdx)->fieldIndex("name")); + ui.authorEdit->setModelColumn( + model->relationModel(authorIdx)->fieldIndex("name")); ui.genreEdit->setModel(model->relationModel(genreIdx)); - ui.genreEdit->setModelColumn(model->relationModel(genreIdx)->fieldIndex("name")); + ui.genreEdit->setModelColumn( + model->relationModel(genreIdx)->fieldIndex("name")); QDataWidgetMapper *mapper = new QDataWidgetMapper(this); mapper->setModel(model); @@ -116,8 +124,11 @@ BookWindow::BookWindow() mapper->addMapping(ui.genreEdit, genreIdx); mapper->addMapping(ui.ratingEdit, model->fieldIndex("rating")); - connect(ui.bookTable->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), - mapper, SLOT(setCurrentModelIndex(QModelIndex))); + connect(ui.bookTable->selectionModel(), + &QItemSelectionModel::currentRowChanged, + mapper, + &QDataWidgetMapper::setCurrentModelIndex + ); ui.bookTable->setCurrentIndex(model->index(0, 0)); } @@ -127,4 +138,3 @@ void BookWindow::showError(const QSqlError &err) QMessageBox::critical(this, "Unable to initialize Database", "Error initializing database: " + err.text()); } - diff --git a/examples/sql/books/bookwindow.ui b/examples/sql/books/bookwindow.ui index 659d324564..c81a86cb2c 100644 --- a/examples/sql/books/bookwindow.ui +++ b/examples/sql/books/bookwindow.ui @@ -1,10 +1,8 @@ - - - - + + BookWindow - - + + 0 0 @@ -12,117 +10,135 @@ 420 - + Books - - - + + + + 6 + + 9 - - 6 + + 9 + + + 9 + + + 9 - - + + Books - - + + + 6 + + 9 - - 6 + + 9 + + + 9 + + + 9 - - + + QAbstractItemView::SelectRows - - + + Details - - - - - <b>Title:</b> + + + + + <b>Title:</b> - - - + + + true - - - - <b>Author: </b> + + + + <b>Author: </b> - - - - + + + + true - - - - - <b>Genre:</b> + + + + + <b>Genre:</b> - - - + + + true - - - - <b>Year:</b> + + + + <b>Year:</b> - - - - + + + + true - + - - 2100 - - + -1000 + + 2100 + - - - - <b>Rating:</b> + + + + <b>Rating:</b> - - - + + + 5 @@ -136,7 +152,6 @@ - bookTable titleEdit -- cgit v1.2.3 From fcbfa534fab7dc0e989382a664031a42ba35ee92 Mon Sep 17 00:00:00 2001 From: Paul Wicking Date: Tue, 5 Jun 2018 13:55:43 +0200 Subject: Doc: Clean up SQL example: Books (part 2) Improve readability, enforce consistent code formatting. Task-number: QTBUG-68652 Change-Id: I7bbe0b2baa6273e0133df84d7c3cc2aa6a0b6ff2 Reviewed-by: Venugopal Shivashankar --- examples/sql/books/bookdelegate.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/sql/books/bookdelegate.h b/examples/sql/books/bookdelegate.h index d07f2b9534..a7a76a1060 100644 --- a/examples/sql/books/bookdelegate.h +++ b/examples/sql/books/bookdelegate.h @@ -66,7 +66,8 @@ public: void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; - QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; + QSize sizeHint(const QStyleOptionViewItem &option, + const QModelIndex &index) const override; bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, -- cgit v1.2.3 From afdb675ada5b21216dd1bf017a6054cf508be0b9 Mon Sep 17 00:00:00 2001 From: Paul Wicking Date: Tue, 5 Jun 2018 14:04:04 +0200 Subject: Doc: Clean up SQL Example: Books - whitespace edition Remove whitespace for consistency. Task-number: QTBUG-68652 Change-Id: I1ca1f449db2352cb96c88535936f2c44392693cf Reviewed-by: Venugopal Shivashankar --- examples/sql/books/bookdelegate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/sql/books/bookdelegate.h b/examples/sql/books/bookdelegate.h index a7a76a1060..f1b4326992 100644 --- a/examples/sql/books/bookdelegate.h +++ b/examples/sql/books/bookdelegate.h @@ -74,7 +74,7 @@ public: const QModelIndex &index) override; QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const override; + const QModelIndex &index) const override; private: QPixmap star; -- cgit v1.2.3 From a14a943f9ac3d1e85514d7fb6688c84e624ac850 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Fri, 11 May 2018 16:31:51 +0200 Subject: Examples: Cleanup and modernize Plug&Paint * Use C++11 member init * Use auto where appropriate * Replace foreach with range-for * Replace last Qt4-style connects * Sort includes to common style * Fix some Clang warnings Task-number: QTBUG-60635 Change-Id: I61c98b34b954e416dd175b56ca589125217083de Reviewed-by: Venugopal Shivashankar Reviewed-by: Paul Wicking Reviewed-by: Richard Moe Gustavsen --- examples/widgets/tools/plugandpaint/app/main.cpp | 3 +- .../widgets/tools/plugandpaint/app/mainwindow.cpp | 55 +++++++++++----------- .../widgets/tools/plugandpaint/app/mainwindow.h | 34 ++++++------- .../widgets/tools/plugandpaint/app/paintarea.cpp | 9 +--- .../widgets/tools/plugandpaint/app/paintarea.h | 12 ++--- .../tools/plugandpaint/app/plugindialog.cpp | 29 ++++++------ .../widgets/tools/plugandpaint/app/plugindialog.h | 8 ++-- .../plugins/basictools/basictoolsplugin.cpp | 16 +++---- .../plugins/extrafilters/extrafiltersplugin.cpp | 24 +++++----- 9 files changed, 91 insertions(+), 99 deletions(-) (limited to 'examples') diff --git a/examples/widgets/tools/plugandpaint/app/main.cpp b/examples/widgets/tools/plugandpaint/app/main.cpp index f157957da5..f50fd86b97 100644 --- a/examples/widgets/tools/plugandpaint/app/main.cpp +++ b/examples/widgets/tools/plugandpaint/app/main.cpp @@ -50,8 +50,9 @@ //! [0] #include "mainwindow.h" -#include + #include +#include Q_IMPORT_PLUGIN(BasicToolsPlugin) diff --git a/examples/widgets/tools/plugandpaint/app/mainwindow.cpp b/examples/widgets/tools/plugandpaint/app/mainwindow.cpp index b2287ee072..ebe1150eea 100644 --- a/examples/widgets/tools/plugandpaint/app/mainwindow.cpp +++ b/examples/widgets/tools/plugandpaint/app/mainwindow.cpp @@ -54,19 +54,18 @@ #include "paintarea.h" #include "plugindialog.h" -#include -#include - -#include -#include -#include #include -#include -#include -#include +#include +#include #include +#include #include -#include +#include +#include +#include +#include +#include +#include MainWindow::MainWindow() : paintArea(new PaintArea), @@ -109,11 +108,10 @@ bool MainWindow::saveAs() const QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), initialPath); - if (fileName.isEmpty()) { + if (fileName.isEmpty()) return false; - } else { - return paintArea->saveImage(fileName, "png"); - } + + return paintArea->saveImage(fileName, "png"); } void MainWindow::brushColor() @@ -137,8 +135,8 @@ void MainWindow::brushWidth() //! [0] void MainWindow::changeBrush() { - QAction *action = qobject_cast(sender()); - BrushInterface *iBrush = qobject_cast(action->parent()); + auto action = qobject_cast(sender()); + auto iBrush = qobject_cast(action->parent()); const QString brush = action->text(); paintArea->setBrush(iBrush, brush); @@ -148,8 +146,8 @@ void MainWindow::changeBrush() //! [1] void MainWindow::insertShape() { - QAction *action = qobject_cast(sender()); - ShapeInterface *iShape = qobject_cast(action->parent()); + auto action = qobject_cast(sender()); + auto iShape = qobject_cast(action->parent()); const QPainterPath path = iShape->generateShape(action->text(), this); if (!path.isEmpty()) @@ -160,9 +158,8 @@ void MainWindow::insertShape() //! [2] void MainWindow::applyFilter() { - QAction *action = qobject_cast(sender()); - FilterInterface *iFilter = - qobject_cast(action->parent()); + auto action = qobject_cast(sender()); + auto iFilter = qobject_cast(action->parent()); const QImage image = iFilter->filterImage(action->text(), paintArea->image(), this); @@ -245,7 +242,8 @@ void MainWindow::createMenus() //! [4] void MainWindow::loadPlugins() { - foreach (QObject *plugin, QPluginLoader::staticInstances()) + const auto staticInstances = QPluginLoader::staticInstances(); + for (QObject *plugin : staticInstances) populateMenus(plugin); //! [4] //! [5] @@ -265,7 +263,8 @@ void MainWindow::loadPlugins() //! [5] //! [6] - foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { + const auto entryList = pluginsDir.entryList(QDir::Files); + for (const QString &fileName : entryList) { QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); QObject *plugin = loader.instance(); if (plugin) { @@ -287,16 +286,16 @@ void MainWindow::loadPlugins() //! [10] void MainWindow::populateMenus(QObject *plugin) { - BrushInterface *iBrush = qobject_cast(plugin); + auto iBrush = qobject_cast(plugin); if (iBrush) addToMenu(plugin, iBrush->brushes(), brushMenu, &MainWindow::changeBrush, brushActionGroup); - ShapeInterface *iShape = qobject_cast(plugin); + auto iShape = qobject_cast(plugin); if (iShape) addToMenu(plugin, iShape->shapes(), shapesMenu, &MainWindow::insertShape); - FilterInterface *iFilter = qobject_cast(plugin); + auto iFilter = qobject_cast(plugin); if (iFilter) addToMenu(plugin, iFilter->filters(), filterMenu, &MainWindow::applyFilter); } @@ -306,8 +305,8 @@ void MainWindow::addToMenu(QObject *plugin, const QStringList &texts, QMenu *menu, Member member, QActionGroup *actionGroup) { - foreach (QString text, texts) { - QAction *action = new QAction(text, plugin); + for (const QString &text : texts) { + auto action = new QAction(text, plugin); connect(action, &QAction::triggered, this, member); menu->addAction(action); diff --git a/examples/widgets/tools/plugandpaint/app/mainwindow.h b/examples/widgets/tools/plugandpaint/app/mainwindow.h index 7d2c085c23..2b54264893 100644 --- a/examples/widgets/tools/plugandpaint/app/mainwindow.h +++ b/examples/widgets/tools/plugandpaint/app/mainwindow.h @@ -89,27 +89,27 @@ private: void loadPlugins(); void populateMenus(QObject *plugin); void addToMenu(QObject *plugin, const QStringList &texts, QMenu *menu, - Member member, QActionGroup *actionGroup = 0); + Member member, QActionGroup *actionGroup = nullptr); - PaintArea *paintArea; - QScrollArea *scrollArea; + PaintArea *paintArea = nullptr; + QScrollArea *scrollArea = nullptr; QDir pluginsDir; QStringList pluginFileNames; - QMenu *fileMenu; - QMenu *brushMenu; - QMenu *shapesMenu; - QMenu *filterMenu; - QMenu *helpMenu; - QActionGroup *brushActionGroup; - QAction *openAct; - QAction *saveAsAct; - QAction *exitAct; - QAction *brushWidthAct; - QAction *brushColorAct; - QAction *aboutAct; - QAction *aboutQtAct; - QAction *aboutPluginsAct; + QMenu *fileMenu = nullptr; + QMenu *brushMenu = nullptr; + QMenu *shapesMenu = nullptr; + QMenu *filterMenu = nullptr; + QMenu *helpMenu = nullptr; + QActionGroup *brushActionGroup = nullptr; + QAction *openAct = nullptr; + QAction *saveAsAct = nullptr; + QAction *exitAct = nullptr; + QAction *brushWidthAct = nullptr; + QAction *brushColorAct = nullptr; + QAction *aboutAct = nullptr; + QAction *aboutQtAct = nullptr; + QAction *aboutPluginsAct = nullptr; }; #endif diff --git a/examples/widgets/tools/plugandpaint/app/paintarea.cpp b/examples/widgets/tools/plugandpaint/app/paintarea.cpp index 5d2170bfd4..4295e04cc0 100644 --- a/examples/widgets/tools/plugandpaint/app/paintarea.cpp +++ b/examples/widgets/tools/plugandpaint/app/paintarea.cpp @@ -52,16 +52,11 @@ #include "interfaces.h" #include "paintarea.h" -#include #include +#include PaintArea::PaintArea(QWidget *parent) : - QWidget(parent), - theImage(500, 400, QImage::Format_RGB32), - color(Qt::blue), - thickness(3), - brushInterface(0), - lastPos(-1, -1) + QWidget(parent) { setAttribute(Qt::WA_StaticContents); setAttribute(Qt::WA_NoBackground); diff --git a/examples/widgets/tools/plugandpaint/app/paintarea.h b/examples/widgets/tools/plugandpaint/app/paintarea.h index 1c8ee1ee1b..1d1e6006c8 100644 --- a/examples/widgets/tools/plugandpaint/app/paintarea.h +++ b/examples/widgets/tools/plugandpaint/app/paintarea.h @@ -63,7 +63,7 @@ class PaintArea : public QWidget Q_OBJECT public: - PaintArea(QWidget *parent = 0); + PaintArea(QWidget *parent = nullptr); bool openImage(const QString &fileName); bool saveImage(const QString &fileName, const char *fileFormat); @@ -87,13 +87,13 @@ protected: private: void setupPainter(QPainter &painter); - QImage theImage; - QColor color; - int thickness; + QImage theImage = {500, 400, QImage::Format_RGB32}; + QColor color = Qt::blue; + int thickness = 3; - BrushInterface *brushInterface; + BrushInterface *brushInterface = nullptr; QString brush; - QPoint lastPos; + QPoint lastPos = {-1, -1}; QPainterPath pendingPath; }; diff --git a/examples/widgets/tools/plugandpaint/app/plugindialog.cpp b/examples/widgets/tools/plugandpaint/app/plugindialog.cpp index 43eb34f423..af5828f67e 100644 --- a/examples/widgets/tools/plugandpaint/app/plugindialog.cpp +++ b/examples/widgets/tools/plugandpaint/app/plugindialog.cpp @@ -52,16 +52,15 @@ #include "interfaces.h" #include "plugindialog.h" -#include -#include #include - -#include #include +#include +#include +#include #include +#include #include #include -#include PluginDialog::PluginDialog(const QString &path, const QStringList &fileNames, QWidget *parent) : @@ -107,11 +106,12 @@ void PluginDialog::findPlugins(const QString &path, const QDir dir(path); - foreach (QObject *plugin, QPluginLoader::staticInstances()) + const auto staticInstances = QPluginLoader::staticInstances(); + for (QObject *plugin : staticInstances) populateTreeWidget(plugin, tr("%1 (Static Plugin)") .arg(plugin->metaObject()->className())); - foreach (QString fileName, fileNames) { + for (const QString &fileName : fileNames) { QPluginLoader loader(dir.absoluteFilePath(fileName)); QObject *plugin = loader.instance(); if (plugin) @@ -123,7 +123,7 @@ void PluginDialog::findPlugins(const QString &path, //! [1] void PluginDialog::populateTreeWidget(QObject *plugin, const QString &text) { - QTreeWidgetItem *pluginItem = new QTreeWidgetItem(treeWidget); + auto pluginItem = new QTreeWidgetItem(treeWidget); pluginItem->setText(0, text); treeWidget->setItemExpanded(pluginItem, true); @@ -132,16 +132,15 @@ void PluginDialog::populateTreeWidget(QObject *plugin, const QString &text) pluginItem->setFont(0, boldFont); if (plugin) { - BrushInterface *iBrush = qobject_cast(plugin); + auto iBrush = qobject_cast(plugin); if (iBrush) addItems(pluginItem, "BrushInterface", iBrush->brushes()); - ShapeInterface *iShape = qobject_cast(plugin); + auto iShape = qobject_cast(plugin); if (iShape) addItems(pluginItem, "ShapeInterface", iShape->shapes()); - FilterInterface *iFilter = - qobject_cast(plugin); + auto iFilter = qobject_cast(plugin); if (iFilter) addItems(pluginItem, "FilterInterface", iFilter->filters()); } @@ -152,14 +151,14 @@ void PluginDialog::addItems(QTreeWidgetItem *pluginItem, const char *interfaceName, const QStringList &features) { - QTreeWidgetItem *interfaceItem = new QTreeWidgetItem(pluginItem); + auto interfaceItem = new QTreeWidgetItem(pluginItem); interfaceItem->setText(0, interfaceName); interfaceItem->setIcon(0, interfaceIcon); - foreach (QString feature, features) { + for (QString feature : features) { if (feature.endsWith("...")) feature.chop(3); - QTreeWidgetItem *featureItem = new QTreeWidgetItem(interfaceItem); + auto featureItem = new QTreeWidgetItem(interfaceItem); featureItem->setText(0, feature); featureItem->setIcon(0, featureIcon); } diff --git a/examples/widgets/tools/plugandpaint/app/plugindialog.h b/examples/widgets/tools/plugandpaint/app/plugindialog.h index f8e5bcda24..b18b30e62c 100644 --- a/examples/widgets/tools/plugandpaint/app/plugindialog.h +++ b/examples/widgets/tools/plugandpaint/app/plugindialog.h @@ -68,7 +68,7 @@ class PluginDialog : public QDialog public: PluginDialog(const QString &path, const QStringList &fileNames, - QWidget *parent = 0); + QWidget *parent = nullptr); private: void findPlugins(const QString &path, const QStringList &fileNames); @@ -76,9 +76,9 @@ private: void addItems(QTreeWidgetItem *pluginItem, const char *interfaceName, const QStringList &features); - QLabel *label; - QTreeWidget *treeWidget; - QPushButton *okButton; + QLabel *label = nullptr; + QTreeWidget *treeWidget = nullptr; + QPushButton *okButton = nullptr; QIcon interfaceIcon; QIcon featureIcon; }; diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp index 92620ddd8c..3b465565ba 100644 --- a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp +++ b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp @@ -48,18 +48,17 @@ ** ****************************************************************************/ +#include "basictoolsplugin.h" + +#include #include -#include #include -#include "basictoolsplugin.h" - //! [0] QStringList BasicToolsPlugin::brushes() const { - return QStringList() << tr("Pencil") << tr("Air Brush") - << tr("Random Letters"); + return {tr("Pencil"), tr("Air Brush"), tr("Random Letters")}; } //! [0] @@ -132,7 +131,7 @@ QRect BasicToolsPlugin::mouseRelease(const QString & /* brush */, //! [5] QStringList BasicToolsPlugin::shapes() const { - return QStringList() << tr("Circle") << tr("Star") << tr("Text..."); + return {tr("Circle"), tr("Star"), tr("Text...")}; } //! [5] @@ -169,8 +168,7 @@ QPainterPath BasicToolsPlugin::generateShape(const QString &shape, //! [7] QStringList BasicToolsPlugin::filters() const { - return QStringList() << tr("Invert Pixels") << tr("Swap RGB") - << tr("Grayscale"); + return {tr("Invert Pixels"), tr("Swap RGB"), tr("Grayscale")}; } //! [7] @@ -187,7 +185,7 @@ QImage BasicToolsPlugin::filterImage(const QString &filter, const QImage &image, } else if (filter == tr("Grayscale")) { for (int y = 0; y < result.height(); ++y) { for (int x = 0; x < result.width(); ++x) { - int pixel = result.pixel(x, y); + QRgb pixel = result.pixel(x, y); int gray = qGray(pixel); int alpha = qAlpha(pixel); result.setPixel(x, y, qRgba(gray, gray, gray, alpha)); diff --git a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp b/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp index 8f59afa759..48717e34f6 100644 --- a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp +++ b/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp @@ -48,17 +48,17 @@ ** ****************************************************************************/ +#include "extrafiltersplugin.h" + #include #include #include -#include "extrafiltersplugin.h" - QStringList ExtraFiltersPlugin::filters() const { - return QStringList() << tr("Flip Horizontally") << tr("Flip Vertically") - << tr("Smudge...") << tr("Threshold..."); + return {tr("Flip Horizontally"), tr("Flip Vertically"), + tr("Smudge..."), tr("Threshold...")}; } QImage ExtraFiltersPlugin::filterImage(const QString &filter, @@ -70,14 +70,14 @@ QImage ExtraFiltersPlugin::filterImage(const QString &filter, if (filter == tr("Flip Horizontally")) { for (int y = 0; y < original.height(); ++y) { for (int x = 0; x < original.width(); ++x) { - int pixel = original.pixel(original.width() - x - 1, y); + QRgb pixel = original.pixel(original.width() - x - 1, y); result.setPixel(x, y, pixel); } } } else if (filter == tr("Flip Vertically")) { for (int y = 0; y < original.height(); ++y) { for (int x = 0; x < original.width(); ++x) { - int pixel = original.pixel(x, original.height() - y - 1); + QRgb pixel = original.pixel(x, original.height() - y - 1); result.setPixel(x, y, pixel); } } @@ -90,11 +90,11 @@ QImage ExtraFiltersPlugin::filterImage(const QString &filter, for (int i = 0; i < numIters; ++i) { for (int y = 1; y < original.height() - 1; ++y) { for (int x = 1; x < original.width() - 1; ++x) { - int p1 = original.pixel(x, y); - int p2 = original.pixel(x, y + 1); - int p3 = original.pixel(x, y - 1); - int p4 = original.pixel(x + 1, y); - int p5 = original.pixel(x - 1, y); + QRgb p1 = original.pixel(x, y); + QRgb p2 = original.pixel(x, y + 1); + QRgb p3 = original.pixel(x, y - 1); + QRgb p4 = original.pixel(x + 1, y); + QRgb p5 = original.pixel(x - 1, y); int red = (qRed(p1) + qRed(p2) + qRed(p3) + qRed(p4) + qRed(p5)) / 5; @@ -119,7 +119,7 @@ QImage ExtraFiltersPlugin::filterImage(const QString &filter, int factor = 256 / threshold; for (int y = 0; y < original.height(); ++y) { for (int x = 0; x < original.width(); ++x) { - int pixel = original.pixel(x, y); + QRgb pixel = original.pixel(x, y); result.setPixel(x, y, qRgba(qRed(pixel) / factor * factor, qGreen(pixel) / factor * factor, qBlue(pixel) / factor * factor, -- cgit v1.2.3