From af38340720aa26ce95ceae661e3fd1dfc2770195 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 31 Jul 2015 13:53:29 +0200 Subject: Port examples/widgets/itemviews to new connection syntax. Rename some slots to avoid ugly casts. Change-Id: I5d7b2c044ab6a725f7259e5e34f00c3d06fff050 Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../widgets/itemviews/addressbook/adddialog.cpp | 4 +- .../itemviews/addressbook/addresswidget.cpp | 10 ++--- .../widgets/itemviews/addressbook/addresswidget.h | 2 +- .../widgets/itemviews/addressbook/mainwindow.cpp | 16 +++---- .../itemviews/addressbook/newaddresstab.cpp | 2 +- .../itemviews/basicsortfiltermodel/window.cpp | 22 +++++----- examples/widgets/itemviews/chart/mainwindow.cpp | 25 ++++++----- examples/widgets/itemviews/chart/mainwindow.h | 3 +- .../widgets/itemviews/combowidgetmapper/window.cpp | 12 +++--- .../customsortfiltermodel/filterwidget.cpp | 6 +-- .../itemviews/customsortfiltermodel/window.cpp | 14 +++--- .../itemviews/editabletreemodel/mainwindow.cpp | 30 ++++++------- .../itemviews/editabletreemodel/mainwindow.h | 4 +- examples/widgets/itemviews/fetchmore/window.cpp | 12 +++--- .../itemviews/frozencolumn/freezetablewidget.cpp | 18 ++++---- .../widgets/itemviews/pixelator/mainwindow.cpp | 17 ++++---- examples/widgets/itemviews/puzzle/main.cpp | 2 +- examples/widgets/itemviews/puzzle/mainwindow.cpp | 45 +++++++++---------- examples/widgets/itemviews/puzzle/mainwindow.h | 3 +- .../itemviews/simpledommodel/mainwindow.cpp | 4 +- .../itemviews/simplewidgetmapper/window.cpp | 6 +-- .../widgets/itemviews/spreadsheet/spreadsheet.cpp | 50 +++++++++++----------- .../itemviews/spreadsheet/spreadsheetdelegate.cpp | 2 +- .../itemviews/stardelegate/stardelegate.cpp | 4 +- 24 files changed, 158 insertions(+), 155 deletions(-) (limited to 'examples/widgets') diff --git a/examples/widgets/itemviews/addressbook/adddialog.cpp b/examples/widgets/itemviews/addressbook/adddialog.cpp index de5c7eaf87..d153381b56 100644 --- a/examples/widgets/itemviews/addressbook/adddialog.cpp +++ b/examples/widgets/itemviews/addressbook/adddialog.cpp @@ -72,8 +72,8 @@ AddDialog::AddDialog(QWidget *parent) mainLayout->addLayout(gLayout); setLayout(mainLayout); - connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); - connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); + connect(okButton, &QAbstractButton::clicked, this, &QDialog::accept); + connect(cancelButton, &QAbstractButton::clicked, this, &QDialog::reject); setWindowTitle(tr("Add a Contact")); } diff --git a/examples/widgets/itemviews/addressbook/addresswidget.cpp b/examples/widgets/itemviews/addressbook/addresswidget.cpp index 20589a9417..792d626a4e 100644 --- a/examples/widgets/itemviews/addressbook/addresswidget.cpp +++ b/examples/widgets/itemviews/addressbook/addresswidget.cpp @@ -49,8 +49,8 @@ AddressWidget::AddressWidget(QWidget *parent) { table = new TableModel(this); newAddressTab = new NewAddressTab(this); - connect(newAddressTab, SIGNAL(sendDetails(QString, QString)), - this, SLOT(addEntry(QString, QString))); + connect(newAddressTab, &NewAddressTab::sendDetails, + this, &AddressWidget::addEntry); addTab(newAddressTab, "Address Book"); @@ -59,7 +59,7 @@ AddressWidget::AddressWidget(QWidget *parent) //! [0] //! [2] -void AddressWidget::addEntry() +void AddressWidget::showAddEntryDialog() { AddDialog aDialog; @@ -182,8 +182,8 @@ void AddressWidget::setupTabs() tableView->setSortingEnabled(true); connect(tableView->selectionModel(), - SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - this, SIGNAL(selectionChanged(QItemSelection))); + &QItemSelectionModel::selectionChanged, + this, &AddressWidget::selectionChanged); addTab(tableView, str); } diff --git a/examples/widgets/itemviews/addressbook/addresswidget.h b/examples/widgets/itemviews/addressbook/addresswidget.h index b990c47911..a2fc4bc03b 100644 --- a/examples/widgets/itemviews/addressbook/addresswidget.h +++ b/examples/widgets/itemviews/addressbook/addresswidget.h @@ -63,7 +63,7 @@ public: void writeToFile(const QString &fileName); public slots: - void addEntry(); + void showAddEntryDialog(); void addEntry(QString name, QString address); void editEntry(); void removeEntry(); diff --git a/examples/widgets/itemviews/addressbook/mainwindow.cpp b/examples/widgets/itemviews/addressbook/mainwindow.cpp index f729f43604..94b38ea2f6 100644 --- a/examples/widgets/itemviews/addressbook/mainwindow.cpp +++ b/examples/widgets/itemviews/addressbook/mainwindow.cpp @@ -61,40 +61,40 @@ void MainWindow::createMenus() openAct = new QAction(tr("&Open..."), this); fileMenu->addAction(openAct); - connect(openAct, SIGNAL(triggered()), this, SLOT(openFile())); + connect(openAct, &QAction::triggered, this, &MainWindow::openFile); //! [1a] saveAct = new QAction(tr("&Save As..."), this); fileMenu->addAction(saveAct); - connect(saveAct, SIGNAL(triggered()), this, SLOT(saveFile())); + connect(saveAct, &QAction::triggered, this, &MainWindow::saveFile); fileMenu->addSeparator(); exitAct = new QAction(tr("E&xit"), this); fileMenu->addAction(exitAct); - connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + connect(exitAct, &QAction::triggered, this, &QWidget::close); toolMenu = menuBar()->addMenu(tr("&Tools")); addAct = new QAction(tr("&Add Entry..."), this); toolMenu->addAction(addAct); - connect(addAct, SIGNAL(triggered()), addressWidget, SLOT(addEntry())); + connect(addAct, &QAction::triggered, addressWidget, &AddressWidget::showAddEntryDialog); //! [1b] editAct = new QAction(tr("&Edit Entry..."), this); editAct->setEnabled(false); toolMenu->addAction(editAct); - connect(editAct, SIGNAL(triggered()), addressWidget, SLOT(editEntry())); + connect(editAct, &QAction::triggered, addressWidget, &AddressWidget::editEntry); toolMenu->addSeparator(); removeAct = new QAction(tr("&Remove Entry"), this); removeAct->setEnabled(false); toolMenu->addAction(removeAct); - connect(removeAct, SIGNAL(triggered()), addressWidget, SLOT(removeEntry())); + connect(removeAct, &QAction::triggered, addressWidget, &AddressWidget::removeEntry); - connect(addressWidget, SIGNAL(selectionChanged(QItemSelection)), - this, SLOT(updateActions(QItemSelection))); + connect(addressWidget, &AddressWidget::selectionChanged, + this, &MainWindow::updateActions); } //! [1b] diff --git a/examples/widgets/itemviews/addressbook/newaddresstab.cpp b/examples/widgets/itemviews/addressbook/newaddresstab.cpp index 012a19991c..af66636995 100644 --- a/examples/widgets/itemviews/addressbook/newaddresstab.cpp +++ b/examples/widgets/itemviews/addressbook/newaddresstab.cpp @@ -53,7 +53,7 @@ NewAddressTab::NewAddressTab(QWidget *parent) addButton = new QPushButton(tr("Add")); - connect(addButton, SIGNAL(clicked()), this, SLOT(addEntry())); + connect(addButton, &QAbstractButton::clicked, this, &NewAddressTab::addEntry); mainLayout = new QVBoxLayout; mainLayout->addWidget(descriptionLabel); diff --git a/examples/widgets/itemviews/basicsortfiltermodel/window.cpp b/examples/widgets/itemviews/basicsortfiltermodel/window.cpp index b518460230..0f5a434bcc 100644 --- a/examples/widgets/itemviews/basicsortfiltermodel/window.cpp +++ b/examples/widgets/itemviews/basicsortfiltermodel/window.cpp @@ -77,16 +77,18 @@ Window::Window() filterColumnLabel = new QLabel(tr("Filter &column:")); filterColumnLabel->setBuddy(filterColumnComboBox); - connect(filterPatternLineEdit, SIGNAL(textChanged(QString)), - this, SLOT(filterRegExpChanged())); - connect(filterSyntaxComboBox, SIGNAL(currentIndexChanged(int)), - this, SLOT(filterRegExpChanged())); - connect(filterColumnComboBox, SIGNAL(currentIndexChanged(int)), - this, SLOT(filterColumnChanged())); - connect(filterCaseSensitivityCheckBox, SIGNAL(toggled(bool)), - this, SLOT(filterRegExpChanged())); - connect(sortCaseSensitivityCheckBox, SIGNAL(toggled(bool)), - this, SLOT(sortChanged())); + connect(filterPatternLineEdit, &QLineEdit::textChanged, + this, &Window::filterRegExpChanged); + + typedef void (QComboBox::*QComboIntSignal)(int); + connect(filterSyntaxComboBox, static_cast(&QComboBox::currentIndexChanged), + this, &Window::filterRegExpChanged); + connect(filterColumnComboBox, static_cast(&QComboBox::currentIndexChanged), + this, &Window::filterColumnChanged); + connect(filterCaseSensitivityCheckBox, &QAbstractButton::toggled, + this, &Window::filterRegExpChanged); + connect(sortCaseSensitivityCheckBox, &QAbstractButton::toggled, + this, &Window::sortChanged); sourceGroupBox = new QGroupBox(tr("Original Model")); proxyGroupBox = new QGroupBox(tr("Sorted/Filtered Model")); diff --git a/examples/widgets/itemviews/chart/mainwindow.cpp b/examples/widgets/itemviews/chart/mainwindow.cpp index 646b8a293a..9a3b372233 100644 --- a/examples/widgets/itemviews/chart/mainwindow.cpp +++ b/examples/widgets/itemviews/chart/mainwindow.cpp @@ -56,14 +56,14 @@ MainWindow::MainWindow() setupModel(); setupViews(); - connect(openAction, SIGNAL(triggered()), this, SLOT(openFile())); - connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile())); - connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(openAction, &QAction::triggered, this, &MainWindow::openFile); + connect(saveAction, &QAction::triggered, this, &MainWindow::saveFile); + connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit); menuBar()->addMenu(fileMenu); statusBar(); - openFile(":/Charts/qtdata.cht"); + loadFile(":/Charts/qtdata.cht"); setWindowTitle(tr("Chart")); resize(870, 550); @@ -99,17 +99,16 @@ void MainWindow::setupViews() setCentralWidget(splitter); } -void MainWindow::openFile(const QString &path) +void MainWindow::openFile() { - QString fileName; - if (path.isNull()) - fileName = QFileDialog::getOpenFileName(this, tr("Choose a data file"), "", "*.cht"); - else - fileName = path; - - if (fileName.isEmpty()) - return; + const QString fileName = + QFileDialog::getOpenFileName(this, tr("Choose a data file"), "", "*.cht"); + if (!fileName.isEmpty()) + loadFile(fileName); +} +void MainWindow::loadFile(const QString &fileName) +{ QFile file(fileName); if (!file.open(QFile::ReadOnly | QFile::Text)) return; diff --git a/examples/widgets/itemviews/chart/mainwindow.h b/examples/widgets/itemviews/chart/mainwindow.h index 2fc47bb75b..523ad70441 100644 --- a/examples/widgets/itemviews/chart/mainwindow.h +++ b/examples/widgets/itemviews/chart/mainwindow.h @@ -57,12 +57,13 @@ public: MainWindow(); private slots: - void openFile(const QString &path = QString()); + void openFile(); void saveFile(); private: void setupModel(); void setupViews(); + void loadFile(const QString &path); QAbstractItemModel *model; QAbstractItemView *pieChart; diff --git a/examples/widgets/itemviews/combowidgetmapper/window.cpp b/examples/widgets/itemviews/combowidgetmapper/window.cpp index d135ffb33f..3a6f649856 100644 --- a/examples/widgets/itemviews/combowidgetmapper/window.cpp +++ b/examples/widgets/itemviews/combowidgetmapper/window.cpp @@ -72,12 +72,12 @@ Window::Window(QWidget *parent) //! [Set up the mapper] //! [Set up connections and layouts] - connect(previousButton, SIGNAL(clicked()), - mapper, SLOT(toPrevious())); - connect(nextButton, SIGNAL(clicked()), - mapper, SLOT(toNext())); - connect(mapper, SIGNAL(currentIndexChanged(int)), - this, SLOT(updateButtons(int))); + connect(previousButton, &QAbstractButton::clicked, + mapper, &QDataWidgetMapper::toPrevious); + connect(nextButton, &QAbstractButton::clicked, + mapper, &QDataWidgetMapper::toNext); + connect(mapper, &QDataWidgetMapper::currentIndexChanged, + this, &Window::updateButtons); QGridLayout *layout = new QGridLayout(); layout->addWidget(nameLabel, 0, 0, 1, 1); diff --git a/examples/widgets/itemviews/customsortfiltermodel/filterwidget.cpp b/examples/widgets/itemviews/customsortfiltermodel/filterwidget.cpp index 6b5896f3c1..12019e606a 100644 --- a/examples/widgets/itemviews/customsortfiltermodel/filterwidget.cpp +++ b/examples/widgets/itemviews/customsortfiltermodel/filterwidget.cpp @@ -55,12 +55,12 @@ FilterWidget::FilterWidget(QWidget *parent) , m_patternGroup(new QActionGroup(this)) { setClearButtonEnabled(true); - connect(this, SIGNAL(textChanged(QString)), this, SIGNAL(filterChanged())); + connect(this, &QLineEdit::textChanged, this, &FilterWidget::filterChanged); QMenu *menu = new QMenu(this); m_caseSensitivityAction = menu->addAction(tr("Case Sensitive")); m_caseSensitivityAction->setCheckable(true); - connect(m_caseSensitivityAction, SIGNAL(toggled(bool)), this, SIGNAL(filterChanged())); + connect(m_caseSensitivityAction, &QAction::toggled, this, &FilterWidget::filterChanged); menu->addSeparator(); m_patternGroup->setExclusive(true); @@ -77,7 +77,7 @@ FilterWidget::FilterWidget(QWidget *parent) patternAction->setCheckable(true); patternAction->setData(QVariant(int(QRegExp::Wildcard))); m_patternGroup->addAction(patternAction); - connect(m_patternGroup, SIGNAL(triggered(QAction*)), this, SIGNAL(filterChanged())); + connect(m_patternGroup, &QActionGroup::triggered, this, &FilterWidget::filterChanged); const QIcon icon = QIcon(QPixmap(":/images/find.png")); QToolButton *optionsButton = new QToolButton; diff --git a/examples/widgets/itemviews/customsortfiltermodel/window.cpp b/examples/widgets/itemviews/customsortfiltermodel/window.cpp index 8653df2a61..ff07dfe79c 100644 --- a/examples/widgets/itemviews/customsortfiltermodel/window.cpp +++ b/examples/widgets/itemviews/customsortfiltermodel/window.cpp @@ -66,7 +66,7 @@ Window::Window() //! [3] filterWidget = new FilterWidget; filterWidget->setText("Grace|Sports"); - connect(filterWidget, SIGNAL(filterChanged()), this, SLOT(textFilterChanged())); + connect(filterWidget, &FilterWidget::filterChanged, this, &Window::textFilterChanged); filterPatternLabel = new QLabel(tr("&Filter pattern:")); filterPatternLabel->setBuddy(filterWidget); @@ -81,13 +81,13 @@ Window::Window() toLabel = new QLabel(tr("&To:")); toLabel->setBuddy(toDateEdit); - connect(filterWidget, SIGNAL(textChanged(QString)), - this, SLOT(textFilterChanged())); - connect(fromDateEdit, SIGNAL(dateChanged(QDate)), - this, SLOT(dateFilterChanged())); - connect(toDateEdit, SIGNAL(dateChanged(QDate)), + connect(filterWidget, &QLineEdit::textChanged, + this, &Window::textFilterChanged); + connect(fromDateEdit, &QDateTimeEdit::dateChanged, + this, &Window::dateFilterChanged); + connect(toDateEdit, &QDateTimeEdit::dateChanged, //! [3] //! [4] - this, SLOT(dateFilterChanged())); + this, &Window::dateFilterChanged); //! [4] //! [5] diff --git a/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp b/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp index c7abe59c77..f138e27095 100644 --- a/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp +++ b/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp @@ -60,19 +60,17 @@ MainWindow::MainWindow(QWidget *parent) for (int column = 0; column < model->columnCount(); ++column) view->resizeColumnToContents(column); - connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(exitAction, &QAction::triggered, qApp, &QCoreApplication::quit); - connect(view->selectionModel(), - SIGNAL(selectionChanged(const QItemSelection &, - const QItemSelection &)), - this, SLOT(updateActions())); + connect(view->selectionModel(), &QItemSelectionModel::selectionChanged, + this, &MainWindow::updateActions); - connect(actionsMenu, SIGNAL(aboutToShow()), this, SLOT(updateActions())); - connect(insertRowAction, SIGNAL(triggered()), this, SLOT(insertRow())); - connect(insertColumnAction, SIGNAL(triggered()), this, SLOT(insertColumn())); - connect(removeRowAction, SIGNAL(triggered()), this, SLOT(removeRow())); - connect(removeColumnAction, SIGNAL(triggered()), this, SLOT(removeColumn())); - connect(insertChildAction, SIGNAL(triggered()), this, SLOT(insertChild())); + connect(actionsMenu, &QMenu::aboutToShow, this, &MainWindow::updateActions); + connect(insertRowAction, &QAction::triggered, this, &MainWindow::insertRow); + connect(insertColumnAction, &QAction::triggered, this, &MainWindow::insertColumn); + connect(removeRowAction, &QAction::triggered, this, &MainWindow::removeRow); + connect(removeColumnAction, &QAction::triggered, this, &MainWindow::removeColumn); + connect(insertChildAction, &QAction::triggered, this, &MainWindow::insertChild); updateActions(); } @@ -102,13 +100,13 @@ void MainWindow::insertChild() updateActions(); } -bool MainWindow::insertColumn(const QModelIndex &parent) +bool MainWindow::insertColumn() { QAbstractItemModel *model = view->model(); int column = view->selectionModel()->currentIndex().column(); // Insert a column in the parent item. - bool changed = model->insertColumn(column + 1, parent); + bool changed = model->insertColumn(column + 1); if (changed) model->setHeaderData(column + 1, Qt::Horizontal, QVariant("[No header]"), Qt::EditRole); @@ -133,15 +131,15 @@ void MainWindow::insertRow() } } -bool MainWindow::removeColumn(const QModelIndex &parent) +bool MainWindow::removeColumn() { QAbstractItemModel *model = view->model(); int column = view->selectionModel()->currentIndex().column(); // Insert columns in each child of the parent item. - bool changed = model->removeColumn(column, parent); + bool changed = model->removeColumn(column); - if (!parent.isValid() && changed) + if (changed) updateActions(); return changed; diff --git a/examples/widgets/itemviews/editabletreemodel/mainwindow.h b/examples/widgets/itemviews/editabletreemodel/mainwindow.h index 4626ecbc2a..4c164f88c1 100644 --- a/examples/widgets/itemviews/editabletreemodel/mainwindow.h +++ b/examples/widgets/itemviews/editabletreemodel/mainwindow.h @@ -58,9 +58,9 @@ public slots: private slots: void insertChild(); - bool insertColumn(const QModelIndex &parent = QModelIndex()); + bool insertColumn(); void insertRow(); - bool removeColumn(const QModelIndex &parent = QModelIndex()); + bool removeColumn(); void removeRow(); }; diff --git a/examples/widgets/itemviews/fetchmore/window.cpp b/examples/widgets/itemviews/fetchmore/window.cpp index eefa09622d..aa4e0adc90 100644 --- a/examples/widgets/itemviews/fetchmore/window.cpp +++ b/examples/widgets/itemviews/fetchmore/window.cpp @@ -59,12 +59,12 @@ Window::Window(QWidget *parent) logViewer = new QTextBrowser; logViewer->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); - connect(lineEdit, SIGNAL(textChanged(QString)), - model, SLOT(setDirPath(QString))); - connect(lineEdit, SIGNAL(textChanged(QString)), - logViewer, SLOT(clear())); - connect(model, SIGNAL(numberPopulated(int)), - this, SLOT(updateLog(int))); + connect(lineEdit, &QLineEdit::textChanged, + model, &FileListModel::setDirPath); + connect(lineEdit, &QLineEdit::textChanged, + logViewer, &QTextEdit::clear); + connect(model, &FileListModel::numberPopulated, + this, &Window::updateLog); QGridLayout *layout = new QGridLayout; layout->addWidget(label, 0, 0); diff --git a/examples/widgets/itemviews/frozencolumn/freezetablewidget.cpp b/examples/widgets/itemviews/frozencolumn/freezetablewidget.cpp index 254786b16e..c2233abcc2 100644 --- a/examples/widgets/itemviews/frozencolumn/freezetablewidget.cpp +++ b/examples/widgets/itemviews/frozencolumn/freezetablewidget.cpp @@ -52,15 +52,15 @@ FreezeTableWidget::FreezeTableWidget(QAbstractItemModel * model) init(); //connect the headers and scrollbars of both tableviews together - connect(horizontalHeader(),SIGNAL(sectionResized(int,int,int)), this, - SLOT(updateSectionWidth(int,int,int))); - connect(verticalHeader(),SIGNAL(sectionResized(int,int,int)), this, - SLOT(updateSectionHeight(int,int,int))); - - connect(frozenTableView->verticalScrollBar(), SIGNAL(valueChanged(int)), - verticalScrollBar(), SLOT(setValue(int))); - connect(verticalScrollBar(), SIGNAL(valueChanged(int)), - frozenTableView->verticalScrollBar(), SLOT(setValue(int))); + connect(horizontalHeader(),&QHeaderView::sectionResized, this, + &FreezeTableWidget::updateSectionWidth); + connect(verticalHeader(),&QHeaderView::sectionResized, this, + &FreezeTableWidget::updateSectionHeight); + + connect(frozenTableView->verticalScrollBar(), &QAbstractSlider::valueChanged, + verticalScrollBar(), &QAbstractSlider::setValue); + connect(verticalScrollBar(), &QAbstractSlider::valueChanged, + frozenTableView->verticalScrollBar(), &QAbstractSlider::setValue); } diff --git a/examples/widgets/itemviews/pixelator/mainwindow.cpp b/examples/widgets/itemviews/pixelator/mainwindow.cpp index a05880225b..bab130a2b2 100644 --- a/examples/widgets/itemviews/pixelator/mainwindow.cpp +++ b/examples/widgets/itemviews/pixelator/mainwindow.cpp @@ -98,15 +98,16 @@ MainWindow::MainWindow() menuBar()->addSeparator(); menuBar()->addMenu(helpMenu); - connect(openAction, SIGNAL(triggered()), this, SLOT(chooseImage())); - connect(printAction, SIGNAL(triggered()), this, SLOT(printImage())); - connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); - connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAboutBox())); + connect(openAction, &QAction::triggered, this, &MainWindow::chooseImage); + connect(printAction, &QAction::triggered, this, &MainWindow::printImage); + connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit); + connect(aboutAction, &QAction::triggered, this, &MainWindow::showAboutBox); //! [4] - connect(pixelSizeSpinBox, SIGNAL(valueChanged(int)), - delegate, SLOT(setPixelSize(int))); - connect(pixelSizeSpinBox, SIGNAL(valueChanged(int)), - this, SLOT(updateView())); + typedef void (QSpinBox::*QSpinBoxIntSignal)(int); + connect(pixelSizeSpinBox, static_cast(&QSpinBox::valueChanged), + delegate, &PixelDelegate::setPixelSize); + connect(pixelSizeSpinBox, static_cast(&QSpinBox::valueChanged), + this, &MainWindow::updateView); //! [4] QHBoxLayout *controlsLayout = new QHBoxLayout; diff --git a/examples/widgets/itemviews/puzzle/main.cpp b/examples/widgets/itemviews/puzzle/main.cpp index 866c6f0d8b..a7980489a8 100644 --- a/examples/widgets/itemviews/puzzle/main.cpp +++ b/examples/widgets/itemviews/puzzle/main.cpp @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); MainWindow window; - window.openImage(":/images/example.jpg"); + window.loadImage(":/images/example.jpg"); window.show(); return app.exec(); } diff --git a/examples/widgets/itemviews/puzzle/mainwindow.cpp b/examples/widgets/itemviews/puzzle/mainwindow.cpp index 2e2a1d0ab5..5cd9a7f0df 100644 --- a/examples/widgets/itemviews/puzzle/mainwindow.cpp +++ b/examples/widgets/itemviews/puzzle/mainwindow.cpp @@ -57,26 +57,27 @@ MainWindow::MainWindow(QWidget *parent) setWindowTitle(tr("Puzzle")); } -void MainWindow::openImage(const QString &path) +void MainWindow::openImage() { - QString fileName = path; - - if (fileName.isNull()) { - fileName = QFileDialog::getOpenFileName(this, - tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); - } + const QString fileName = + QFileDialog::getOpenFileName(this, + tr("Open Image"), QString(), + tr("Image Files (*.png *.jpg *.bmp)")); + if (!fileName.isEmpty()) + loadImage(fileName); +} - if (!fileName.isEmpty()) { - QPixmap newImage; - if (!newImage.load(fileName)) { - QMessageBox::warning(this, tr("Open Image"), - tr("The image file could not be loaded."), - QMessageBox::Cancel); - return; - } - puzzleImage = newImage; - setupPuzzle(); +void MainWindow::loadImage(const QString &fileName) +{ + QPixmap newImage; + if (!newImage.load(fileName)) { + QMessageBox::warning(this, tr("Open Image"), + tr("The image file could not be loaded."), + QMessageBox::Cancel); + return; } + puzzleImage = newImage; + setupPuzzle(); } void MainWindow::setCompleted() @@ -116,9 +117,9 @@ void MainWindow::setupMenus() QAction *restartAction = gameMenu->addAction(tr("&Restart")); - connect(openAction, SIGNAL(triggered()), this, SLOT(openImage())); - connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); - connect(restartAction, SIGNAL(triggered()), this, SLOT(setupPuzzle())); + connect(openAction, &QAction::triggered, this, &MainWindow::openImage); + connect(exitAction, &QAction::triggered, qApp, &QCoreApplication::quit); + connect(restartAction, &QAction::triggered, this, &MainWindow::setupPuzzle); } void MainWindow::setupWidgets() @@ -141,8 +142,8 @@ void MainWindow::setupWidgets() PiecesModel *model = new PiecesModel(puzzleWidget->pieceSize(), this); piecesList->setModel(model); - connect(puzzleWidget, SIGNAL(puzzleCompleted()), - this, SLOT(setCompleted()), Qt::QueuedConnection); + connect(puzzleWidget, &PuzzleWidget::puzzleCompleted, + this, &MainWindow::setCompleted, Qt::QueuedConnection); frameLayout->addWidget(piecesList); frameLayout->addWidget(puzzleWidget); diff --git a/examples/widgets/itemviews/puzzle/mainwindow.h b/examples/widgets/itemviews/puzzle/mainwindow.h index 86daf0af2d..440dd46377 100644 --- a/examples/widgets/itemviews/puzzle/mainwindow.h +++ b/examples/widgets/itemviews/puzzle/mainwindow.h @@ -58,7 +58,8 @@ public: MainWindow(QWidget *parent = 0); public slots: - void openImage(const QString &path = QString()); + void openImage(); + void loadImage(const QString &path); void setupPuzzle(); private slots: diff --git a/examples/widgets/itemviews/simpledommodel/mainwindow.cpp b/examples/widgets/itemviews/simpledommodel/mainwindow.cpp index 4dc87dac1a..c11fb40a0e 100644 --- a/examples/widgets/itemviews/simpledommodel/mainwindow.cpp +++ b/examples/widgets/itemviews/simpledommodel/mainwindow.cpp @@ -49,8 +49,8 @@ MainWindow::MainWindow() : QMainWindow(), model(0) { fileMenu = menuBar()->addMenu(tr("&File")); - fileMenu->addAction(tr("&Open..."), this, SLOT(openFile()), QKeySequence::Open); - fileMenu->addAction(tr("E&xit"), this, SLOT(close()), QKeySequence::Quit); + fileMenu->addAction(tr("&Open..."), this, &MainWindow::openFile, QKeySequence::Open); + fileMenu->addAction(tr("E&xit"), this, &QWidget::close, QKeySequence::Quit); model = new DomModel(QDomDocument(), this); view = new QTreeView(this); diff --git a/examples/widgets/itemviews/simplewidgetmapper/window.cpp b/examples/widgets/itemviews/simplewidgetmapper/window.cpp index 9df004430b..0d99acc603 100644 --- a/examples/widgets/itemviews/simplewidgetmapper/window.cpp +++ b/examples/widgets/itemviews/simplewidgetmapper/window.cpp @@ -69,9 +69,9 @@ Window::Window(QWidget *parent) mapper->addMapping(addressEdit, 1); mapper->addMapping(ageSpinBox, 2); - connect(previousButton, SIGNAL(clicked()), mapper, SLOT(toPrevious())); - connect(nextButton, SIGNAL(clicked()), mapper, SLOT(toNext())); - connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(updateButtons(int))); + connect(previousButton, &QAbstractButton::clicked, mapper, &QDataWidgetMapper::toPrevious); + connect(nextButton, &QAbstractButton::clicked, mapper, &QDataWidgetMapper::toNext); + connect(mapper, &QDataWidgetMapper::currentIndexChanged, this, &Window::updateButtons); //! [Set up the mapper] //! [Set up the layout] diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp b/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp index 02e635b87a..41b51c1071 100644 --- a/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp +++ b/examples/widgets/itemviews/spreadsheet/spreadsheet.cpp @@ -73,17 +73,17 @@ SpreadSheet::SpreadSheet(int rows, int cols, QWidget *parent) setCentralWidget(table); statusBar(); - connect(table, SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)), - this, SLOT(updateStatus(QTableWidgetItem*))); - connect(table, SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)), - this, SLOT(updateColor(QTableWidgetItem*))); - connect(table, SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)), - this, SLOT(updateLineEdit(QTableWidgetItem*))); - connect(table, SIGNAL(itemChanged(QTableWidgetItem*)), - this, SLOT(updateStatus(QTableWidgetItem*))); - connect(formulaInput, SIGNAL(returnPressed()), this, SLOT(returnPressed())); - connect(table, SIGNAL(itemChanged(QTableWidgetItem*)), - this, SLOT(updateLineEdit(QTableWidgetItem*))); + connect(table, &QTableWidget::currentItemChanged, + this, &SpreadSheet::updateStatus); + connect(table, &QTableWidget::currentItemChanged, + this, &SpreadSheet::updateColor); + connect(table, &QTableWidget::currentItemChanged, + this, &SpreadSheet::updateLineEdit); + connect(table, &QTableWidget::itemChanged, + this, &SpreadSheet::updateStatus); + connect(formulaInput, &QLineEdit::returnPressed, this, &SpreadSheet::returnPressed); + connect(table, &QTableWidget::itemChanged, + this, &SpreadSheet::updateLineEdit); setWindowTitle(tr("Spreadsheet")); } @@ -91,43 +91,43 @@ SpreadSheet::SpreadSheet(int rows, int cols, QWidget *parent) void SpreadSheet::createActions() { cell_sumAction = new QAction(tr("Sum"), this); - connect(cell_sumAction, SIGNAL(triggered()), this, SLOT(actionSum())); + connect(cell_sumAction, &QAction::triggered, this, &SpreadSheet::actionSum); cell_addAction = new QAction(tr("&Add"), this); cell_addAction->setShortcut(Qt::CTRL | Qt::Key_Plus); - connect(cell_addAction, SIGNAL(triggered()), this, SLOT(actionAdd())); + connect(cell_addAction, &QAction::triggered, this, &SpreadSheet::actionAdd); cell_subAction = new QAction(tr("&Subtract"), this); cell_subAction->setShortcut(Qt::CTRL | Qt::Key_Minus); - connect(cell_subAction, SIGNAL(triggered()), this, SLOT(actionSubtract())); + connect(cell_subAction, &QAction::triggered, this, &SpreadSheet::actionSubtract); cell_mulAction = new QAction(tr("&Multiply"), this); cell_mulAction->setShortcut(Qt::CTRL | Qt::Key_multiply); - connect(cell_mulAction, SIGNAL(triggered()), this, SLOT(actionMultiply())); + connect(cell_mulAction, &QAction::triggered, this, &SpreadSheet::actionMultiply); cell_divAction = new QAction(tr("&Divide"), this); cell_divAction->setShortcut(Qt::CTRL | Qt::Key_division); - connect(cell_divAction, SIGNAL(triggered()), this, SLOT(actionDivide())); + connect(cell_divAction, &QAction::triggered, this, &SpreadSheet::actionDivide); fontAction = new QAction(tr("Font..."), this); fontAction->setShortcut(Qt::CTRL | Qt::Key_F); - connect(fontAction, SIGNAL(triggered()), this, SLOT(selectFont())); + connect(fontAction, &QAction::triggered, this, &SpreadSheet::selectFont); colorAction = new QAction(QPixmap(16, 16), tr("Background &Color..."), this); - connect(colorAction, SIGNAL(triggered()), this, SLOT(selectColor())); + connect(colorAction, &QAction::triggered, this, &SpreadSheet::selectColor); clearAction = new QAction(tr("Clear"), this); clearAction->setShortcut(Qt::Key_Delete); - connect(clearAction, SIGNAL(triggered()), this, SLOT(clear())); + connect(clearAction, &QAction::triggered, this, &SpreadSheet::clear); aboutSpreadSheet = new QAction(tr("About Spreadsheet"), this); - connect(aboutSpreadSheet, SIGNAL(triggered()), this, SLOT(showAbout())); + connect(aboutSpreadSheet, &QAction::triggered, this, &SpreadSheet::showAbout); exitAction = new QAction(tr("E&xit"), this); - connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(exitAction, &QAction::triggered, qApp, &QCoreApplication::quit); printAction = new QAction(tr("&Print"), this); - connect(printAction, SIGNAL(triggered()), this, SLOT(print())); + connect(printAction, &QAction::triggered, this, &SpreadSheet::print); firstSeparator = new QAction(this); firstSeparator->setSeparator(true); @@ -309,11 +309,11 @@ bool SpreadSheet::runInputDialog(const QString &title, outColInput.setCurrentIndex(outCol); QPushButton cancelButton(tr("Cancel"), &addDialog); - connect(&cancelButton, SIGNAL(clicked()), &addDialog, SLOT(reject())); + connect(&cancelButton, &QAbstractButton::clicked, &addDialog, &QDialog::reject); QPushButton okButton(tr("OK"), &addDialog); okButton.setDefault(true); - connect(&okButton, SIGNAL(clicked()), &addDialog, SLOT(accept())); + connect(&okButton, &QAbstractButton::clicked, &addDialog, &QDialog::accept); QHBoxLayout *buttonsLayout = new QHBoxLayout; buttonsLayout->addStretch(1); @@ -625,7 +625,7 @@ void SpreadSheet::print() QPrintPreviewDialog dlg(&printer); PrintView view; view.setModel(table->model()); - connect(&dlg, SIGNAL(paintRequested(QPrinter*)), &view, SLOT(print(QPrinter*))); + connect(&dlg, &QPrintPreviewDialog::paintRequested, &view, &PrintView::print); dlg.exec(); #endif } diff --git a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp index d056e3f8e4..a7404fe159 100644 --- a/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp +++ b/examples/widgets/itemviews/spreadsheet/spreadsheetdelegate.cpp @@ -63,7 +63,7 @@ QWidget *SpreadSheetDelegate::createEditor(QWidget *parent, QCompleter *autoComplete = new QCompleter(allStrings); editor->setCompleter(autoComplete); - connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); + connect(editor, &QLineEdit::editingFinished, this, &SpreadSheetDelegate::commitAndCloseEditor); return editor; } diff --git a/examples/widgets/itemviews/stardelegate/stardelegate.cpp b/examples/widgets/itemviews/stardelegate/stardelegate.cpp index 48f6eb543b..a9e8f71699 100644 --- a/examples/widgets/itemviews/stardelegate/stardelegate.cpp +++ b/examples/widgets/itemviews/stardelegate/stardelegate.cpp @@ -83,8 +83,8 @@ QWidget *StarDelegate::createEditor(QWidget *parent, { if (index.data().canConvert()) { StarEditor *editor = new StarEditor(parent); - connect(editor, SIGNAL(editingFinished()), - this, SLOT(commitAndCloseEditor())); + connect(editor, &StarEditor::editingFinished, + this, &StarDelegate::commitAndCloseEditor); return editor; } else { return QStyledItemDelegate::createEditor(parent, option, index); -- cgit v1.2.3