diff options
Diffstat (limited to 'src/widgets/doc/snippets')
22 files changed, 124 insertions, 175 deletions
diff --git a/src/widgets/doc/snippets/code/doc_src_examples_dropsite.qdoc b/src/widgets/doc/snippets/code/doc_src_examples_dropsite.qdoc deleted file mode 100644 index a91933cdce..0000000000 --- a/src/widgets/doc/snippets/code/doc_src_examples_dropsite.qdoc +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -//! [0] -\code -foreach(variable, container) -\endcode -//! [0] diff --git a/src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc b/src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc index 9af04f6b4c..098eaf4717 100644 --- a/src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc +++ b/src/widgets/doc/snippets/code/doc_src_stylesheet.qdoc @@ -514,13 +514,15 @@ QLabel { border-width: 1px 2px 3px 4px } /* 1px 2px 3px 4px */ //! [84] -QLabel { border-color: red } /* opaque red */ -QLabel { border-color: #FF0000 } /* opaque red */ -QLabel { border-color: rgba(255, 0, 0, 75%) } /* 75% opaque red */ -QLabel { border-color: rgb(255, 0, 0) } /* opaque red */ -QLabel { border-color: rgb(100%, 0%, 0%) } /* opaque red */ -QLabel { border-color: hsv(60, 255, 255) } /* opaque yellow */ -QLabel { border-color: hsva(240, 255, 255, 75%) } /* 75% blue */ +QLabel { border-color: red } /* opaque red */ +QLabel { border-color: #FF0000 } /* opaque red */ +QLabel { border-color: rgba(255, 0, 0, 75%) } /* 75% opaque red */ +QLabel { border-color: rgb(255, 0, 0) } /* opaque red */ +QLabel { border-color: rgb(100%, 0%, 0%) } /* opaque red */ +QLabel { border-color: hsv(60, 100%, 100%) } /* opaque yellow */ +QLabel { border-color: hsva(240, 255, 255, 75%) } /* 75% blue */ +QLabel { border-color: hsl(60, 100%, 50%) } /* opaque yellow */ +QLabel { border-color: hsla(240, 255, 50%, 75%) } /* 75% blue */ //! [84] diff --git a/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp b/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp index 06cca37111..1e9daf824b 100644 --- a/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp +++ b/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp @@ -144,3 +144,14 @@ dialog.exec(); //! [14] "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)" //! [14] + +//! [14] +auto fileOpenCompleted = [](const QSting &fileName, const QByteArray &fileContent) { + if (fileName.isEmpty()) { + // No file was selected + } else { + // Use fileName and fileContent + } +} +QFileDialog::getOpenFileContent("Images (*.png *.xpm *.jpg)", fileContentReady); +//! [14] diff --git a/src/widgets/doc/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp b/src/widgets/doc/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp index 4dad563660..cc1568cb9d 100644 --- a/src/widgets/doc/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp +++ b/src/widgets/doc/snippets/code/src_gui_itemviews_qdatawidgetmapper.cpp @@ -59,7 +59,7 @@ mapper->toFirst(); //! [1] -QDataWidgetMapper *mapper = new QDataWidgetMapper(); +QDataWidgetMapper *mapper = new QDataWidgetMapper; mapper->setModel(myModel); mapper->addMapping(nameLineEdit, 0); mapper->addMapping(ageSpinBox, 1); @@ -67,7 +67,7 @@ mapper->addMapping(ageSpinBox, 1); //! [2] -QDataWidgetMapper *mapper = new QDataWidgetMapper(); -connect(myTableView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), - mapper, SLOT(setCurrentModelIndex(QModelIndex))); +QDataWidgetMapper *mapper = new QDataWidgetMapper; +connect(myTableView->selectionModel(), &QItemSelectionModel::currentRowChanged, + mapper, &QDataWidgetMapper::setCurrentModelIndex); //! [2] diff --git a/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp b/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp index a907a0421f..0a70c1d32a 100644 --- a/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp +++ b/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp @@ -100,7 +100,8 @@ QSize MyWidget::sizeHint() const //! [4] void showAllHiddenTopLevelWidgets() { - foreach (QWidget *widget, QApplication::topLevelWidgets()) { + const QWidgetList topLevelWidgets = QApplication::topLevelWidgets(); + for (QWidget *widget : topLevelWidgets) { if (widget->isHidden()) widget->show(); } @@ -111,7 +112,8 @@ void showAllHiddenTopLevelWidgets() //! [5] void updateAllWidgets() { - foreach (QWidget *widget, QApplication::allWidgets()) + const QWidgetList allWidgets = QApplication::allWidgets(); + for (QWidget *widget : allWidgets) widget->update(); } //! [5] @@ -171,13 +173,15 @@ appname -session id //! [10] -foreach (const QString &command, mySession.restartCommand()) +const QStringList commands = mySession.restartCommand(); +for (const QString &command : commands) do_something(command); //! [10] //! [11] -foreach (const QString &command, mySession.discardCommand()) +const QStringList commands = mySession.discardCommand(); +for (const QString &command : commands) do_something(command); //! [11] diff --git a/src/widgets/doc/snippets/code/src_gui_widgets_qmenu.cpp b/src/widgets/doc/snippets/code/src_gui_widgets_qmenu.cpp index 4b1c4cd645..da3fd28056 100644 --- a/src/widgets/doc/snippets/code/src_gui_widgets_qmenu.cpp +++ b/src/widgets/doc/snippets/code/src_gui_widgets_qmenu.cpp @@ -81,7 +81,7 @@ exec(e->globalPos()); //! [6] QMenu menu; QAction *at = actions[0]; // Assumes actions is not empty -foreach (QAction *a, actions) +for (QAction *a : qAsConst(actions)) menu.addAction(a); menu.exec(pos, at); //! [6] diff --git a/src/widgets/doc/snippets/dialogs/dialogs.cpp b/src/widgets/doc/snippets/dialogs/dialogs.cpp index cca3ac8d75..7fa793c70f 100644 --- a/src/widgets/doc/snippets/dialogs/dialogs.cpp +++ b/src/widgets/doc/snippets/dialogs/dialogs.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include <QtGui> +#include <QtWidgets> typedef QDialog WordCountDialog; typedef QDialog FindDialog; @@ -76,7 +76,8 @@ void EditorWindow::find() { if (!findDialog) { findDialog = new FindDialog(this); - connect(findDialog, SIGNAL(findNext()), this, SLOT(findNext())); + connect(findDialog, &FindDialog::findNext, + this, &EditorWindow::findNext); } findDialog->show(); @@ -249,9 +250,9 @@ Operation::Operation(QObject *parent) : QObject(parent), steps(0) { pd = new QProgressDialog("Operation in progress.", "Cancel", 0, 100); - connect(pd, SIGNAL(canceled()), this, SLOT(cancel())); + connect(pd, &QProgressDialog::canceled, this, &Operation::cancel); t = new QTimer(this); - connect(t, SIGNAL(timeout()), this, SLOT(perform())); + connect(t, &QTimer::timeout, this, &Operation::perform); t->start(0); } //! [4] //! [5] diff --git a/src/widgets/doc/snippets/dockwidgets/mainwindow.cpp b/src/widgets/doc/snippets/dockwidgets/mainwindow.cpp index f6959cc12b..53f91589bf 100644 --- a/src/widgets/doc/snippets/dockwidgets/mainwindow.cpp +++ b/src/widgets/doc/snippets/dockwidgets/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include <QtGui> +#include <QtWidgets> #include "mainwindow.h" @@ -63,8 +63,8 @@ MainWindow::MainWindow(QWidget *parent) textBrowser = new QTextBrowser(this); - connect(headingList, SIGNAL(itemClicked(QListWidgetItem*)), - this, SLOT(updateText(QListWidgetItem*))); + connect(headingList, &QListWidget::itemClicked, + this, &MainWindow::updateText); updateText(headingList->item(0)); headingList->setCurrentRow(0); @@ -119,7 +119,7 @@ void MainWindow::setupMenus() QAction *exitAct = new QAction(tr("E&xit"), this); exitAct->setShortcut(tr("Ctrl+Q")); exitAct->setStatusTip(tr("Exit the application")); - connect(exitAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); + connect(exitAct, &QAction::triggered, qApp, &QApplication::closeAllWindows); QMenu *fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(exitAct); diff --git a/src/widgets/doc/snippets/mdiareasnippets.cpp b/src/widgets/doc/snippets/mdiareasnippets.cpp index b9d6f05daf..dec7aaa1e7 100644 --- a/src/widgets/doc/snippets/mdiareasnippets.cpp +++ b/src/widgets/doc/snippets/mdiareasnippets.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include <QtGui> +#include <QtWidgets> void mainWindowExample() { @@ -95,7 +95,7 @@ int main(int argv, char **args) QAction *act = new QAction(qApp); act->setShortcut(Qt::ALT + Qt::Key_S); act->setShortcutContext( Qt::ApplicationShortcut ); - QObject::connect(act, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + QObject::connect(act, &QAction::triggered, qApp, &QApplication::aboutQt); QWidget widget5; widget5.show(); diff --git a/src/widgets/doc/snippets/qlistview-dnd/mainwindow.cpp b/src/widgets/doc/snippets/qlistview-dnd/mainwindow.cpp index c2af9c4cf1..45f1eb7aa3 100644 --- a/src/widgets/doc/snippets/qlistview-dnd/mainwindow.cpp +++ b/src/widgets/doc/snippets/qlistview-dnd/mainwindow.cpp @@ -73,7 +73,8 @@ listView->setDropIndicatorShown(true); this->listView = listView; - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(quitAction, &QAction::triggered, + this, &QWidget::close); setupListItems(); diff --git a/src/widgets/doc/snippets/qlistview-dnd/model.cpp b/src/widgets/doc/snippets/qlistview-dnd/model.cpp index 710bbb2964..6835479e7a 100644 --- a/src/widgets/doc/snippets/qlistview-dnd/model.cpp +++ b/src/widgets/doc/snippets/qlistview-dnd/model.cpp @@ -54,7 +54,7 @@ A simple model that uses a QStringList as its data source. */ -#include <QtGui> +#include <QtWidgets> #include "model.h" @@ -121,7 +121,7 @@ bool DragDropListModel::dropMimeData(const QMimeData *data, //! [6] insertRows(beginRow, rows, QModelIndex()); - foreach (const QString &text, newItems) { + for (const QString &text : qAsConst(newItems)) { QModelIndex idx = index(beginRow, 0, QModelIndex()); setData(idx, text); beginRow++; @@ -146,12 +146,12 @@ Qt::ItemFlags DragDropListModel::flags(const QModelIndex &index) const //! [8] QMimeData *DragDropListModel::mimeData(const QModelIndexList &indexes) const { - QMimeData *mimeData = new QMimeData(); + QMimeData *mimeData = new QMimeData; QByteArray encodedData; QDataStream stream(&encodedData, QIODevice::WriteOnly); - foreach (const QModelIndex &index, indexes) { + for (const QModelIndex &index : indexes) { if (index.isValid()) { QString text = data(index, Qt::DisplayRole).toString(); stream << text; diff --git a/src/widgets/doc/snippets/qlistwidget-dnd/mainwindow.cpp b/src/widgets/doc/snippets/qlistwidget-dnd/mainwindow.cpp index 1153250b17..70df2b112e 100644 --- a/src/widgets/doc/snippets/qlistwidget-dnd/mainwindow.cpp +++ b/src/widgets/doc/snippets/qlistwidget-dnd/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include <QtGui> +#include <QtWidgets> #include "mainwindow.h" @@ -74,7 +74,7 @@ listWidget->setDragDropMode(QAbstractItemView::InternalMove); this->listWidget = listWidget; - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); + connect(quitAction, &QAction::triggered, this, &QWidget::close); setupListItems(); diff --git a/src/widgets/doc/snippets/qlistwidget-using/mainwindow.cpp b/src/widgets/doc/snippets/qlistwidget-using/mainwindow.cpp index ff69fd2efd..13b20bb856 100644 --- a/src/widgets/doc/snippets/qlistwidget-using/mainwindow.cpp +++ b/src/widgets/doc/snippets/qlistwidget-using/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include <QtGui> +#include <QtWidgets> #include "mainwindow.h" @@ -77,14 +77,13 @@ MainWindow::MainWindow() listWidget = new QListWidget(this); listWidget->setSelectionMode(QAbstractItemView::SingleSelection); - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - connect(ascendingAction, SIGNAL(triggered()), this, SLOT(sortAscending())); - connect(descendingAction, SIGNAL(triggered()), this, SLOT(sortDescending())); - connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem())); - connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem())); - connect(listWidget, - SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(updateMenus(QListWidgetItem*))); + connect(quitAction, &QAction::triggered, this, &QWidget::close); + connect(ascendingAction, &QAction::triggered, this, &MainWindow::sortAscending); + connect(descendingAction, &QAction::triggered, this, &MainWindow::sortDescending); + connect(insertAction, &QAction::triggered, this, &MainWindow::insertItem); + connect(removeAction, &QAction::triggered, this, &MainWindow::removeItem); + connect(listWidget, &QListWidget::currentItemChanged, + this, &MainWindow::updateMenus); setupListItems(); updateMenus(listWidget->currentItem()); diff --git a/src/widgets/doc/snippets/qsortfilterproxymodel/main.cpp b/src/widgets/doc/snippets/qsortfilterproxymodel/main.cpp index a6284bd578..2d4b1023f1 100644 --- a/src/widgets/doc/snippets/qsortfilterproxymodel/main.cpp +++ b/src/widgets/doc/snippets/qsortfilterproxymodel/main.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include <QtGui> +#include <QtWidgets> int main(int argc, char *argv[]) { @@ -74,9 +74,8 @@ int main(int argc, char *argv[]) filteredView->setWindowTitle("Filtered view onto a string list model"); QLineEdit *patternEditor = new QLineEdit; - QObject:: - connect(patternEditor, SIGNAL(textChanged(QString)), - filterModel, SLOT(setFilterRegExp(QString))); + QObject::connect(patternEditor, &QLineEdit::textChanged, + filterModel, &QSortFilterProxyModel::setFilterWildcard); QVBoxLayout *layout = new QVBoxLayout(window); layout->addWidget(filteredView); diff --git a/src/widgets/doc/snippets/qstackedlayout/main.cpp b/src/widgets/doc/snippets/qstackedlayout/main.cpp index 765608848c..9c61939dee 100644 --- a/src/widgets/doc/snippets/qstackedlayout/main.cpp +++ b/src/widgets/doc/snippets/qstackedlayout/main.cpp @@ -48,13 +48,12 @@ ** ****************************************************************************/ -#include <QtGui> -#include <QApplication> +#include <QtWidgets> class Widget : public QWidget { public: - Widget(QWidget *parent = 0); + Widget(QWidget *parent = nullptr); }; Widget::Widget(QWidget *parent) @@ -75,8 +74,8 @@ Widget::Widget(QWidget *parent) pageComboBox->addItem(tr("Page 1")); pageComboBox->addItem(tr("Page 2")); pageComboBox->addItem(tr("Page 3")); - connect(pageComboBox, SIGNAL(activated(int)), - stackedLayout, SLOT(setCurrentIndex(int))); + connect(pageComboBox, QOverload<int>::of(&QComboBox::activated), + stackedLayout, &QStackedLayout::setCurrentIndex); //! [1] //! [2] diff --git a/src/widgets/doc/snippets/qstackedwidget/main.cpp b/src/widgets/doc/snippets/qstackedwidget/main.cpp index a6c9c7afe3..077c281830 100644 --- a/src/widgets/doc/snippets/qstackedwidget/main.cpp +++ b/src/widgets/doc/snippets/qstackedwidget/main.cpp @@ -48,8 +48,7 @@ ** ****************************************************************************/ -#include <QtGui> -#include <QApplication> +#include <QtWidgets> class Widget : public QWidget { @@ -75,8 +74,8 @@ Widget::Widget(QWidget *parent) pageComboBox->addItem(tr("Page 1")); pageComboBox->addItem(tr("Page 2")); pageComboBox->addItem(tr("Page 3")); - connect(pageComboBox, SIGNAL(activated(int)), - stackedWidget, SLOT(setCurrentIndex(int))); + connect(pageComboBox, QOverload<int>::of(&QComboBox::activated), + stackedWidget, &QStackedWidget::setCurrentIndex); //! [1] //! [2] QVBoxLayout *layout = new QVBoxLayout; diff --git a/src/widgets/doc/snippets/qtablewidget-resizing/mainwindow.cpp b/src/widgets/doc/snippets/qtablewidget-resizing/mainwindow.cpp index 95113153e1..d2c50336f6 100644 --- a/src/widgets/doc/snippets/qtablewidget-resizing/mainwindow.cpp +++ b/src/widgets/doc/snippets/qtablewidget-resizing/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include <QtGui> +#include <QtWidgets> #include "mainwindow.h" @@ -72,9 +72,9 @@ MainWindow::MainWindow() //! [0] tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - connect(tableWidthAction, SIGNAL(triggered()), this, SLOT(changeWidth())); - connect(tableHeightAction, SIGNAL(triggered()), this, SLOT(changeHeight())); + connect(quitAction, &QAction::triggered, this, &QWidget::close); + connect(tableWidthAction, &QAction::triggered, this, &MainWindow::changeWidth); + connect(tableHeightAction, &QAction::triggered, this, &MainWindow::changeHeight); setupTableItems(); diff --git a/src/widgets/doc/snippets/qtablewidget-using/mainwindow.cpp b/src/widgets/doc/snippets/qtablewidget-using/mainwindow.cpp index 15b9457dd5..47b63b2b3f 100644 --- a/src/widgets/doc/snippets/qtablewidget-using/mainwindow.cpp +++ b/src/widgets/doc/snippets/qtablewidget-using/mainwindow.cpp @@ -48,8 +48,8 @@ ** ****************************************************************************/ -#include <QtGui> -#include "math.h" +#include <QtWidgets> +#include <math.h> #include "mainwindow.h" @@ -89,9 +89,9 @@ MainWindow::MainWindow() tableWidget->setHorizontalHeaderItem(1, squaresHeaderItem); tableWidget->setHorizontalHeaderItem(2, cubesHeaderItem); - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - connect(sumItemsAction, SIGNAL(triggered()), this, SLOT(sumItems())); - connect(averageItemsAction, SIGNAL(triggered()), this, SLOT(averageItems())); + connect(quitAction, &QAction::triggered, this, &QWidget::close); + connect(sumItemsAction, &QAction::triggered, this, &MainWindow::sumItems); + connect(averageItemsAction, &QAction::triggered, this, &MainWindow::averageItems); setupTableItems(); @@ -119,12 +119,11 @@ void MainWindow::setupTableItems() void MainWindow::averageItems() { - QList<QTableWidgetItem *> selected = tableWidget->selectedItems(); - QTableWidgetItem *item; + const QList<QTableWidgetItem *> selected = tableWidget->selectedItems(); int number = 0; double total = 0; - foreach (item, selected) { + for (QTableWidgetItem *item : selected) { bool ok; double value = item->text().toDouble(&ok); @@ -140,12 +139,11 @@ void MainWindow::averageItems() void MainWindow::sumItems() { //! [4] - QList<QTableWidgetItem *> selected = tableWidget->selectedItems(); - QTableWidgetItem *item; + const QList<QTableWidgetItem *> selected = tableWidget->selectedItems(); int number = 0; double total = 0; - foreach (item, selected) { + for (QTableWidgetItem *item : selected) { bool ok; double value = item->text().toDouble(&ok); diff --git a/src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp b/src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp index ee7e028a13..b9e258cb03 100644 --- a/src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp +++ b/src/widgets/doc/snippets/qtreewidget-using/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include <QtGui> +#include <QtWidgets> #include "mainwindow.h" @@ -90,16 +90,15 @@ MainWindow::MainWindow() treeWidget->setHeaderLabels(headers); //! [2] - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - connect(ascendingAction, SIGNAL(triggered()), this, SLOT(sortAscending())); - connect(autoSortAction, SIGNAL(triggered()), this, SLOT(updateSortItems())); - connect(descendingAction, SIGNAL(triggered()), this, SLOT(sortDescending())); - connect(findItemsAction, SIGNAL(triggered()), this, SLOT(findItems())); - connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem())); - connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem())); - connect(treeWidget, - SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), - this, SLOT(updateMenus(QTreeWidgetItem*))); + connect(quitAction, &QAction::triggered, this, &QWidget::close); + connect(ascendingAction, &QAction::triggered, this, &MainWindow::sortAscending); + connect(autoSortAction, &QAction::triggered, this, &MainWindow::updateSortItems); + connect(descendingAction, &QAction::triggered, this, &MainWindow::sortDescending); + connect(findItemsAction, &QAction::triggered, this, &MainWindow::findItems); + connect(insertAction, &QAction::triggered, this, &MainWindow::insertItem); + connect(removeAction, &QAction::triggered, this, &MainWindow::removeItem); + connect(treeWidget, &QTreeWidget::currentItemChanged, + this, &MainWindow::updateMenus); setupTreeItems(); updateMenus(treeWidget->currentItem()); @@ -150,18 +149,16 @@ void MainWindow::findItems() if (itemText.isEmpty()) return; -//! [6] - QTreeWidgetItem *item; -//! [6] - foreach (item, treeWidget->selectedItems()) - treeWidget->setItemSelected(item, false); + const QList<QTreeWidgetItem *> items = treeWidget->selectedItems(); + for (QTreeWidgetItem *item : items) + item->setSelected(false); //! [7] - QList<QTreeWidgetItem *> found = treeWidget->findItems( + const QList<QTreeWidgetItem *> found = treeWidget->findItems( itemText, Qt::MatchWildcard); - foreach (item, found) { - treeWidget->setItemSelected(item, true); + for (QTreeWidgetItem *item : found) { + item->setSelected(true); // Show the item->text(0) for each item. } //! [7] diff --git a/src/widgets/doc/snippets/qtreewidgetitemiterator-using/mainwindow.cpp b/src/widgets/doc/snippets/qtreewidgetitemiterator-using/mainwindow.cpp index 5f1f606185..bfe099bbb4 100644 --- a/src/widgets/doc/snippets/qtreewidgetitemiterator-using/mainwindow.cpp +++ b/src/widgets/doc/snippets/qtreewidgetitemiterator-using/mainwindow.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include <QtGui> +#include <QtWidgets> #include "mainwindow.h" @@ -85,16 +85,15 @@ MainWindow::MainWindow() headers << tr("Subject") << tr("Default"); treeWidget->setHeaderLabels(headers); - connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); - connect(ascendingAction, SIGNAL(triggered()), this, SLOT(sortAscending())); - connect(autoSortAction, SIGNAL(triggered()), this, SLOT(updateSortItems())); - connect(descendingAction, SIGNAL(triggered()), this, SLOT(sortDescending())); - connect(findItemsAction, SIGNAL(triggered()), this, SLOT(findItems())); - connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem())); - connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem())); - connect(treeWidget, - SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), - this, SLOT(updateMenus(QTreeWidgetItem*))); + connect(quitAction, &QAction::triggered, this, &QWidget::close); + connect(ascendingAction, &QAction::triggered, this, &MainWindow::sortAscending); + connect(autoSortAction, &QAction::triggered, this, &MainWindow::updateSortItems); + connect(descendingAction, &QAction::triggered, this, &MainWindow::sortDescending); + connect(findItemsAction, &QAction::triggered, this, &MainWindow::findItems); + connect(insertAction, &QAction::triggered, this, &MainWindow::insertItem); + connect(removeAction, &QAction::triggered, this, &MainWindow::removeItem); + connect(treeWidget, &QTreeWidget::currentItemChanged, + this, &MainWindow::updateMenus); setupTreeItems(); updateMenus(treeWidget->currentItem()); diff --git a/src/widgets/doc/snippets/reading-selections/window.cpp b/src/widgets/doc/snippets/reading-selections/window.cpp index 08805fe4b3..045d66a199 100644 --- a/src/widgets/doc/snippets/reading-selections/window.cpp +++ b/src/widgets/doc/snippets/reading-selections/window.cpp @@ -81,9 +81,9 @@ MainWindow::MainWindow(QWidget *parent) QAction *selectAllAction = actionMenu->addAction(tr("&Select All")); menuBar()->addMenu(actionMenu); - connect(fillAction, SIGNAL(triggered()), this, SLOT(fillSelection())); - connect(clearAction, SIGNAL(triggered()), this, SLOT(clearSelection())); - connect(selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll())); + connect(fillAction, &QAction::triggered, this, &MainWindow::fillSelection); + connect(clearAction, &QAction::triggered, this, &MainWindow::clearSelection); + connect(selectAllAction, &QAction::triggered, this, &MainWindow::selectAll); selectionModel = table->selectionModel(); @@ -94,10 +94,9 @@ MainWindow::MainWindow(QWidget *parent) void MainWindow::fillSelection() { //! [0] - QModelIndexList indexes = selectionModel->selectedIndexes(); - QModelIndex index; + const QModelIndexList indexes = selectionModel->selectedIndexes(); - foreach(index, indexes) { + for (const QModelIndex &index : indexes) { QString text = QString("(%1,%2)").arg(index.row()).arg(index.column()); model->setData(index, text); } @@ -106,11 +105,10 @@ void MainWindow::fillSelection() void MainWindow::clearSelection() { - QModelIndexList indexes = selectionModel->selectedIndexes(); - QModelIndex index; + const QModelIndexList indexes = selectionModel->selectedIndexes(); - foreach(index, indexes) - model->setData(index, ""); + for (const QModelIndex &index : indexes) + model->setData(index, QString()); } void MainWindow::selectAll() diff --git a/src/widgets/doc/snippets/updating-selections/window.cpp b/src/widgets/doc/snippets/updating-selections/window.cpp index 0bdcf8a64d..26e9b56ae4 100644 --- a/src/widgets/doc/snippets/updating-selections/window.cpp +++ b/src/widgets/doc/snippets/updating-selections/window.cpp @@ -74,12 +74,10 @@ MainWindow::MainWindow(QWidget *parent) table->setModel(model); selectionModel = table->selectionModel(); - connect(selectionModel, - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - this, SLOT(updateSelection(QItemSelection,QItemSelection))); - connect(selectionModel, - SIGNAL(currentChanged(QModelIndex,QModelIndex)), - this, SLOT(changeCurrent(QModelIndex,QModelIndex))); + connect(selectionModel, &QItemSelectionModel::selectionChanged, + this, &MainWindow::updateSelection); + connect(selectionModel, &QItemSelectionModel::currentChanged, + this, &MainWindow::changeCurrent); statusBar(); setCentralWidget(table); @@ -89,10 +87,9 @@ MainWindow::MainWindow(QWidget *parent) void MainWindow::updateSelection(const QItemSelection &selected, const QItemSelection &deselected) { - QModelIndex index; QModelIndexList items = selected.indexes(); - foreach (index, items) { + for (const QModelIndex &index : qAsConst(items)) { QString text = QString("(%1,%2)").arg(index.row()).arg(index.column()); model->setData(index, text); //! [0] //! [1] @@ -102,8 +99,8 @@ void MainWindow::updateSelection(const QItemSelection &selected, //! [2] items = deselected.indexes(); - foreach (index, items) - model->setData(index, ""); + for (const QModelIndex &index : qAsConst(items)) { + model->setData(index, QString()); } //! [2] |