diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-02-03 19:55:51 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-02-05 16:54:53 +0000 |
commit | 3514aedbf36b96f6e03f88c9c7814b6ba50aac8f (patch) | |
tree | 12b217941ade632b464a365acf3dc6be7ce8509d /src/widgets/doc/snippets/code | |
parent | b76a923a8e81f5fabe6e48ed467e5326275fae4e (diff) | |
download | qtbase-3514aedbf36b96f6e03f88c9c7814b6ba50aac8f.tar.gz |
QtWidgets documentation: cleanup
Cleanup the QtWidgets documentation:
- use new signal/slot syntax
- use range-based for loop instead foreach
Change-Id: I621b1ddac108d3df676209241d93d9b4f04a25fe
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/widgets/doc/snippets/code')
3 files changed, 13 insertions, 9 deletions
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] |