Port examples/widgets/itemviews to new connection syntax.

Rename some slots to avoid ugly casts.

Change-Id: I5d7b2c044ab6a725f7259e5e34f00c3d06fff050
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Friedemann Kleint 2015-07-31 13:53:29 +02:00
parent 7b72cc205c
commit af38340720
24 changed files with 157 additions and 154 deletions

View File

@ -72,8 +72,8 @@ AddDialog::AddDialog(QWidget *parent)
mainLayout->addLayout(gLayout); mainLayout->addLayout(gLayout);
setLayout(mainLayout); setLayout(mainLayout);
connect(okButton, SIGNAL(clicked()), this, SLOT(accept())); connect(okButton, &QAbstractButton::clicked, this, &QDialog::accept);
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); connect(cancelButton, &QAbstractButton::clicked, this, &QDialog::reject);
setWindowTitle(tr("Add a Contact")); setWindowTitle(tr("Add a Contact"));
} }

View File

@ -49,8 +49,8 @@ AddressWidget::AddressWidget(QWidget *parent)
{ {
table = new TableModel(this); table = new TableModel(this);
newAddressTab = new NewAddressTab(this); newAddressTab = new NewAddressTab(this);
connect(newAddressTab, SIGNAL(sendDetails(QString, QString)), connect(newAddressTab, &NewAddressTab::sendDetails,
this, SLOT(addEntry(QString, QString))); this, &AddressWidget::addEntry);
addTab(newAddressTab, "Address Book"); addTab(newAddressTab, "Address Book");
@ -59,7 +59,7 @@ AddressWidget::AddressWidget(QWidget *parent)
//! [0] //! [0]
//! [2] //! [2]
void AddressWidget::addEntry() void AddressWidget::showAddEntryDialog()
{ {
AddDialog aDialog; AddDialog aDialog;
@ -182,8 +182,8 @@ void AddressWidget::setupTabs()
tableView->setSortingEnabled(true); tableView->setSortingEnabled(true);
connect(tableView->selectionModel(), connect(tableView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)), &QItemSelectionModel::selectionChanged,
this, SIGNAL(selectionChanged(QItemSelection))); this, &AddressWidget::selectionChanged);
addTab(tableView, str); addTab(tableView, str);
} }

View File

@ -63,7 +63,7 @@ public:
void writeToFile(const QString &fileName); void writeToFile(const QString &fileName);
public slots: public slots:
void addEntry(); void showAddEntryDialog();
void addEntry(QString name, QString address); void addEntry(QString name, QString address);
void editEntry(); void editEntry();
void removeEntry(); void removeEntry();

View File

@ -61,40 +61,40 @@ void MainWindow::createMenus()
openAct = new QAction(tr("&Open..."), this); openAct = new QAction(tr("&Open..."), this);
fileMenu->addAction(openAct); fileMenu->addAction(openAct);
connect(openAct, SIGNAL(triggered()), this, SLOT(openFile())); connect(openAct, &QAction::triggered, this, &MainWindow::openFile);
//! [1a] //! [1a]
saveAct = new QAction(tr("&Save As..."), this); saveAct = new QAction(tr("&Save As..."), this);
fileMenu->addAction(saveAct); fileMenu->addAction(saveAct);
connect(saveAct, SIGNAL(triggered()), this, SLOT(saveFile())); connect(saveAct, &QAction::triggered, this, &MainWindow::saveFile);
fileMenu->addSeparator(); fileMenu->addSeparator();
exitAct = new QAction(tr("E&xit"), this); exitAct = new QAction(tr("E&xit"), this);
fileMenu->addAction(exitAct); fileMenu->addAction(exitAct);
connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); connect(exitAct, &QAction::triggered, this, &QWidget::close);
toolMenu = menuBar()->addMenu(tr("&Tools")); toolMenu = menuBar()->addMenu(tr("&Tools"));
addAct = new QAction(tr("&Add Entry..."), this); addAct = new QAction(tr("&Add Entry..."), this);
toolMenu->addAction(addAct); toolMenu->addAction(addAct);
connect(addAct, SIGNAL(triggered()), addressWidget, SLOT(addEntry())); connect(addAct, &QAction::triggered, addressWidget, &AddressWidget::showAddEntryDialog);
//! [1b] //! [1b]
editAct = new QAction(tr("&Edit Entry..."), this); editAct = new QAction(tr("&Edit Entry..."), this);
editAct->setEnabled(false); editAct->setEnabled(false);
toolMenu->addAction(editAct); toolMenu->addAction(editAct);
connect(editAct, SIGNAL(triggered()), addressWidget, SLOT(editEntry())); connect(editAct, &QAction::triggered, addressWidget, &AddressWidget::editEntry);
toolMenu->addSeparator(); toolMenu->addSeparator();
removeAct = new QAction(tr("&Remove Entry"), this); removeAct = new QAction(tr("&Remove Entry"), this);
removeAct->setEnabled(false); removeAct->setEnabled(false);
toolMenu->addAction(removeAct); toolMenu->addAction(removeAct);
connect(removeAct, SIGNAL(triggered()), addressWidget, SLOT(removeEntry())); connect(removeAct, &QAction::triggered, addressWidget, &AddressWidget::removeEntry);
connect(addressWidget, SIGNAL(selectionChanged(QItemSelection)), connect(addressWidget, &AddressWidget::selectionChanged,
this, SLOT(updateActions(QItemSelection))); this, &MainWindow::updateActions);
} }
//! [1b] //! [1b]

View File

@ -53,7 +53,7 @@ NewAddressTab::NewAddressTab(QWidget *parent)
addButton = new QPushButton(tr("Add")); addButton = new QPushButton(tr("Add"));
connect(addButton, SIGNAL(clicked()), this, SLOT(addEntry())); connect(addButton, &QAbstractButton::clicked, this, &NewAddressTab::addEntry);
mainLayout = new QVBoxLayout; mainLayout = new QVBoxLayout;
mainLayout->addWidget(descriptionLabel); mainLayout->addWidget(descriptionLabel);

View File

@ -77,16 +77,18 @@ Window::Window()
filterColumnLabel = new QLabel(tr("Filter &column:")); filterColumnLabel = new QLabel(tr("Filter &column:"));
filterColumnLabel->setBuddy(filterColumnComboBox); filterColumnLabel->setBuddy(filterColumnComboBox);
connect(filterPatternLineEdit, SIGNAL(textChanged(QString)), connect(filterPatternLineEdit, &QLineEdit::textChanged,
this, SLOT(filterRegExpChanged())); this, &Window::filterRegExpChanged);
connect(filterSyntaxComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(filterRegExpChanged())); typedef void (QComboBox::*QComboIntSignal)(int);
connect(filterColumnComboBox, SIGNAL(currentIndexChanged(int)), connect(filterSyntaxComboBox, static_cast<QComboIntSignal>(&QComboBox::currentIndexChanged),
this, SLOT(filterColumnChanged())); this, &Window::filterRegExpChanged);
connect(filterCaseSensitivityCheckBox, SIGNAL(toggled(bool)), connect(filterColumnComboBox, static_cast<QComboIntSignal>(&QComboBox::currentIndexChanged),
this, SLOT(filterRegExpChanged())); this, &Window::filterColumnChanged);
connect(sortCaseSensitivityCheckBox, SIGNAL(toggled(bool)), connect(filterCaseSensitivityCheckBox, &QAbstractButton::toggled,
this, SLOT(sortChanged())); this, &Window::filterRegExpChanged);
connect(sortCaseSensitivityCheckBox, &QAbstractButton::toggled,
this, &Window::sortChanged);
sourceGroupBox = new QGroupBox(tr("Original Model")); sourceGroupBox = new QGroupBox(tr("Original Model"));
proxyGroupBox = new QGroupBox(tr("Sorted/Filtered Model")); proxyGroupBox = new QGroupBox(tr("Sorted/Filtered Model"));

View File

@ -56,14 +56,14 @@ MainWindow::MainWindow()
setupModel(); setupModel();
setupViews(); setupViews();
connect(openAction, SIGNAL(triggered()), this, SLOT(openFile())); connect(openAction, &QAction::triggered, this, &MainWindow::openFile);
connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile())); connect(saveAction, &QAction::triggered, this, &MainWindow::saveFile);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
menuBar()->addMenu(fileMenu); menuBar()->addMenu(fileMenu);
statusBar(); statusBar();
openFile(":/Charts/qtdata.cht"); loadFile(":/Charts/qtdata.cht");
setWindowTitle(tr("Chart")); setWindowTitle(tr("Chart"));
resize(870, 550); resize(870, 550);
@ -99,17 +99,16 @@ void MainWindow::setupViews()
setCentralWidget(splitter); setCentralWidget(splitter);
} }
void MainWindow::openFile(const QString &path) void MainWindow::openFile()
{ {
QString fileName; const QString fileName =
if (path.isNull()) QFileDialog::getOpenFileName(this, tr("Choose a data file"), "", "*.cht");
fileName = QFileDialog::getOpenFileName(this, tr("Choose a data file"), "", "*.cht"); if (!fileName.isEmpty())
else loadFile(fileName);
fileName = path; }
if (fileName.isEmpty())
return;
void MainWindow::loadFile(const QString &fileName)
{
QFile file(fileName); QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) if (!file.open(QFile::ReadOnly | QFile::Text))
return; return;

View File

@ -57,12 +57,13 @@ public:
MainWindow(); MainWindow();
private slots: private slots:
void openFile(const QString &path = QString()); void openFile();
void saveFile(); void saveFile();
private: private:
void setupModel(); void setupModel();
void setupViews(); void setupViews();
void loadFile(const QString &path);
QAbstractItemModel *model; QAbstractItemModel *model;
QAbstractItemView *pieChart; QAbstractItemView *pieChart;

View File

@ -72,12 +72,12 @@ Window::Window(QWidget *parent)
//! [Set up the mapper] //! [Set up the mapper]
//! [Set up connections and layouts] //! [Set up connections and layouts]
connect(previousButton, SIGNAL(clicked()), connect(previousButton, &QAbstractButton::clicked,
mapper, SLOT(toPrevious())); mapper, &QDataWidgetMapper::toPrevious);
connect(nextButton, SIGNAL(clicked()), connect(nextButton, &QAbstractButton::clicked,
mapper, SLOT(toNext())); mapper, &QDataWidgetMapper::toNext);
connect(mapper, SIGNAL(currentIndexChanged(int)), connect(mapper, &QDataWidgetMapper::currentIndexChanged,
this, SLOT(updateButtons(int))); this, &Window::updateButtons);
QGridLayout *layout = new QGridLayout(); QGridLayout *layout = new QGridLayout();
layout->addWidget(nameLabel, 0, 0, 1, 1); layout->addWidget(nameLabel, 0, 0, 1, 1);

View File

@ -55,12 +55,12 @@ FilterWidget::FilterWidget(QWidget *parent)
, m_patternGroup(new QActionGroup(this)) , m_patternGroup(new QActionGroup(this))
{ {
setClearButtonEnabled(true); setClearButtonEnabled(true);
connect(this, SIGNAL(textChanged(QString)), this, SIGNAL(filterChanged())); connect(this, &QLineEdit::textChanged, this, &FilterWidget::filterChanged);
QMenu *menu = new QMenu(this); QMenu *menu = new QMenu(this);
m_caseSensitivityAction = menu->addAction(tr("Case Sensitive")); m_caseSensitivityAction = menu->addAction(tr("Case Sensitive"));
m_caseSensitivityAction->setCheckable(true); m_caseSensitivityAction->setCheckable(true);
connect(m_caseSensitivityAction, SIGNAL(toggled(bool)), this, SIGNAL(filterChanged())); connect(m_caseSensitivityAction, &QAction::toggled, this, &FilterWidget::filterChanged);
menu->addSeparator(); menu->addSeparator();
m_patternGroup->setExclusive(true); m_patternGroup->setExclusive(true);
@ -77,7 +77,7 @@ FilterWidget::FilterWidget(QWidget *parent)
patternAction->setCheckable(true); patternAction->setCheckable(true);
patternAction->setData(QVariant(int(QRegExp::Wildcard))); patternAction->setData(QVariant(int(QRegExp::Wildcard)));
m_patternGroup->addAction(patternAction); 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")); const QIcon icon = QIcon(QPixmap(":/images/find.png"));
QToolButton *optionsButton = new QToolButton; QToolButton *optionsButton = new QToolButton;

View File

@ -66,7 +66,7 @@ Window::Window()
//! [3] //! [3]
filterWidget = new FilterWidget; filterWidget = new FilterWidget;
filterWidget->setText("Grace|Sports"); 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 = new QLabel(tr("&Filter pattern:"));
filterPatternLabel->setBuddy(filterWidget); filterPatternLabel->setBuddy(filterWidget);
@ -81,13 +81,13 @@ Window::Window()
toLabel = new QLabel(tr("&To:")); toLabel = new QLabel(tr("&To:"));
toLabel->setBuddy(toDateEdit); toLabel->setBuddy(toDateEdit);
connect(filterWidget, SIGNAL(textChanged(QString)), connect(filterWidget, &QLineEdit::textChanged,
this, SLOT(textFilterChanged())); this, &Window::textFilterChanged);
connect(fromDateEdit, SIGNAL(dateChanged(QDate)), connect(fromDateEdit, &QDateTimeEdit::dateChanged,
this, SLOT(dateFilterChanged())); this, &Window::dateFilterChanged);
connect(toDateEdit, SIGNAL(dateChanged(QDate)), connect(toDateEdit, &QDateTimeEdit::dateChanged,
//! [3] //! [4] //! [3] //! [4]
this, SLOT(dateFilterChanged())); this, &Window::dateFilterChanged);
//! [4] //! [4]
//! [5] //! [5]

View File

@ -60,19 +60,17 @@ MainWindow::MainWindow(QWidget *parent)
for (int column = 0; column < model->columnCount(); ++column) for (int column = 0; column < model->columnCount(); ++column)
view->resizeColumnToContents(column); view->resizeColumnToContents(column);
connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(exitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
connect(view->selectionModel(), connect(view->selectionModel(), &QItemSelectionModel::selectionChanged,
SIGNAL(selectionChanged(const QItemSelection &, this, &MainWindow::updateActions);
const QItemSelection &)),
this, SLOT(updateActions()));
connect(actionsMenu, SIGNAL(aboutToShow()), this, SLOT(updateActions())); connect(actionsMenu, &QMenu::aboutToShow, this, &MainWindow::updateActions);
connect(insertRowAction, SIGNAL(triggered()), this, SLOT(insertRow())); connect(insertRowAction, &QAction::triggered, this, &MainWindow::insertRow);
connect(insertColumnAction, SIGNAL(triggered()), this, SLOT(insertColumn())); connect(insertColumnAction, &QAction::triggered, this, &MainWindow::insertColumn);
connect(removeRowAction, SIGNAL(triggered()), this, SLOT(removeRow())); connect(removeRowAction, &QAction::triggered, this, &MainWindow::removeRow);
connect(removeColumnAction, SIGNAL(triggered()), this, SLOT(removeColumn())); connect(removeColumnAction, &QAction::triggered, this, &MainWindow::removeColumn);
connect(insertChildAction, SIGNAL(triggered()), this, SLOT(insertChild())); connect(insertChildAction, &QAction::triggered, this, &MainWindow::insertChild);
updateActions(); updateActions();
} }
@ -102,13 +100,13 @@ void MainWindow::insertChild()
updateActions(); updateActions();
} }
bool MainWindow::insertColumn(const QModelIndex &parent) bool MainWindow::insertColumn()
{ {
QAbstractItemModel *model = view->model(); QAbstractItemModel *model = view->model();
int column = view->selectionModel()->currentIndex().column(); int column = view->selectionModel()->currentIndex().column();
// Insert a column in the parent item. // Insert a column in the parent item.
bool changed = model->insertColumn(column + 1, parent); bool changed = model->insertColumn(column + 1);
if (changed) if (changed)
model->setHeaderData(column + 1, Qt::Horizontal, QVariant("[No header]"), Qt::EditRole); 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(); QAbstractItemModel *model = view->model();
int column = view->selectionModel()->currentIndex().column(); int column = view->selectionModel()->currentIndex().column();
// Insert columns in each child of the parent item. // 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(); updateActions();
return changed; return changed;

View File

@ -58,9 +58,9 @@ public slots:
private slots: private slots:
void insertChild(); void insertChild();
bool insertColumn(const QModelIndex &parent = QModelIndex()); bool insertColumn();
void insertRow(); void insertRow();
bool removeColumn(const QModelIndex &parent = QModelIndex()); bool removeColumn();
void removeRow(); void removeRow();
}; };

View File

@ -59,12 +59,12 @@ Window::Window(QWidget *parent)
logViewer = new QTextBrowser; logViewer = new QTextBrowser;
logViewer->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); logViewer->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
connect(lineEdit, SIGNAL(textChanged(QString)), connect(lineEdit, &QLineEdit::textChanged,
model, SLOT(setDirPath(QString))); model, &FileListModel::setDirPath);
connect(lineEdit, SIGNAL(textChanged(QString)), connect(lineEdit, &QLineEdit::textChanged,
logViewer, SLOT(clear())); logViewer, &QTextEdit::clear);
connect(model, SIGNAL(numberPopulated(int)), connect(model, &FileListModel::numberPopulated,
this, SLOT(updateLog(int))); this, &Window::updateLog);
QGridLayout *layout = new QGridLayout; QGridLayout *layout = new QGridLayout;
layout->addWidget(label, 0, 0); layout->addWidget(label, 0, 0);

View File

@ -52,15 +52,15 @@ FreezeTableWidget::FreezeTableWidget(QAbstractItemModel * model)
init(); init();
//connect the headers and scrollbars of both tableviews together //connect the headers and scrollbars of both tableviews together
connect(horizontalHeader(),SIGNAL(sectionResized(int,int,int)), this, connect(horizontalHeader(),&QHeaderView::sectionResized, this,
SLOT(updateSectionWidth(int,int,int))); &FreezeTableWidget::updateSectionWidth);
connect(verticalHeader(),SIGNAL(sectionResized(int,int,int)), this, connect(verticalHeader(),&QHeaderView::sectionResized, this,
SLOT(updateSectionHeight(int,int,int))); &FreezeTableWidget::updateSectionHeight);
connect(frozenTableView->verticalScrollBar(), SIGNAL(valueChanged(int)), connect(frozenTableView->verticalScrollBar(), &QAbstractSlider::valueChanged,
verticalScrollBar(), SLOT(setValue(int))); verticalScrollBar(), &QAbstractSlider::setValue);
connect(verticalScrollBar(), SIGNAL(valueChanged(int)), connect(verticalScrollBar(), &QAbstractSlider::valueChanged,
frozenTableView->verticalScrollBar(), SLOT(setValue(int))); frozenTableView->verticalScrollBar(), &QAbstractSlider::setValue);
} }

View File

@ -98,15 +98,16 @@ MainWindow::MainWindow()
menuBar()->addSeparator(); menuBar()->addSeparator();
menuBar()->addMenu(helpMenu); menuBar()->addMenu(helpMenu);
connect(openAction, SIGNAL(triggered()), this, SLOT(chooseImage())); connect(openAction, &QAction::triggered, this, &MainWindow::chooseImage);
connect(printAction, SIGNAL(triggered()), this, SLOT(printImage())); connect(printAction, &QAction::triggered, this, &MainWindow::printImage);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAboutBox())); connect(aboutAction, &QAction::triggered, this, &MainWindow::showAboutBox);
//! [4] //! [4]
connect(pixelSizeSpinBox, SIGNAL(valueChanged(int)), typedef void (QSpinBox::*QSpinBoxIntSignal)(int);
delegate, SLOT(setPixelSize(int))); connect(pixelSizeSpinBox, static_cast<QSpinBoxIntSignal>(&QSpinBox::valueChanged),
connect(pixelSizeSpinBox, SIGNAL(valueChanged(int)), delegate, &PixelDelegate::setPixelSize);
this, SLOT(updateView())); connect(pixelSizeSpinBox, static_cast<QSpinBoxIntSignal>(&QSpinBox::valueChanged),
this, &MainWindow::updateView);
//! [4] //! [4]
QHBoxLayout *controlsLayout = new QHBoxLayout; QHBoxLayout *controlsLayout = new QHBoxLayout;

View File

@ -48,7 +48,7 @@ int main(int argc, char *argv[])
QApplication app(argc, argv); QApplication app(argc, argv);
MainWindow window; MainWindow window;
window.openImage(":/images/example.jpg"); window.loadImage(":/images/example.jpg");
window.show(); window.show();
return app.exec(); return app.exec();
} }

View File

@ -57,26 +57,27 @@ MainWindow::MainWindow(QWidget *parent)
setWindowTitle(tr("Puzzle")); setWindowTitle(tr("Puzzle"));
} }
void MainWindow::openImage(const QString &path) void MainWindow::openImage()
{ {
QString fileName = path; const QString fileName =
QFileDialog::getOpenFileName(this,
tr("Open Image"), QString(),
tr("Image Files (*.png *.jpg *.bmp)"));
if (!fileName.isEmpty())
loadImage(fileName);
}
if (fileName.isNull()) { void MainWindow::loadImage(const QString &fileName)
fileName = QFileDialog::getOpenFileName(this, {
tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); QPixmap newImage;
} if (!newImage.load(fileName)) {
QMessageBox::warning(this, tr("Open Image"),
if (!fileName.isEmpty()) { tr("The image file could not be loaded."),
QPixmap newImage; QMessageBox::Cancel);
if (!newImage.load(fileName)) { return;
QMessageBox::warning(this, tr("Open Image"),
tr("The image file could not be loaded."),
QMessageBox::Cancel);
return;
}
puzzleImage = newImage;
setupPuzzle();
} }
puzzleImage = newImage;
setupPuzzle();
} }
void MainWindow::setCompleted() void MainWindow::setCompleted()
@ -116,9 +117,9 @@ void MainWindow::setupMenus()
QAction *restartAction = gameMenu->addAction(tr("&Restart")); QAction *restartAction = gameMenu->addAction(tr("&Restart"));
connect(openAction, SIGNAL(triggered()), this, SLOT(openImage())); connect(openAction, &QAction::triggered, this, &MainWindow::openImage);
connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(exitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
connect(restartAction, SIGNAL(triggered()), this, SLOT(setupPuzzle())); connect(restartAction, &QAction::triggered, this, &MainWindow::setupPuzzle);
} }
void MainWindow::setupWidgets() void MainWindow::setupWidgets()
@ -141,8 +142,8 @@ void MainWindow::setupWidgets()
PiecesModel *model = new PiecesModel(puzzleWidget->pieceSize(), this); PiecesModel *model = new PiecesModel(puzzleWidget->pieceSize(), this);
piecesList->setModel(model); piecesList->setModel(model);
connect(puzzleWidget, SIGNAL(puzzleCompleted()), connect(puzzleWidget, &PuzzleWidget::puzzleCompleted,
this, SLOT(setCompleted()), Qt::QueuedConnection); this, &MainWindow::setCompleted, Qt::QueuedConnection);
frameLayout->addWidget(piecesList); frameLayout->addWidget(piecesList);
frameLayout->addWidget(puzzleWidget); frameLayout->addWidget(puzzleWidget);

View File

@ -58,7 +58,8 @@ public:
MainWindow(QWidget *parent = 0); MainWindow(QWidget *parent = 0);
public slots: public slots:
void openImage(const QString &path = QString()); void openImage();
void loadImage(const QString &path);
void setupPuzzle(); void setupPuzzle();
private slots: private slots:

View File

@ -49,8 +49,8 @@
MainWindow::MainWindow() : QMainWindow(), model(0) MainWindow::MainWindow() : QMainWindow(), model(0)
{ {
fileMenu = menuBar()->addMenu(tr("&File")); fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(tr("&Open..."), this, SLOT(openFile()), QKeySequence::Open); fileMenu->addAction(tr("&Open..."), this, &MainWindow::openFile, QKeySequence::Open);
fileMenu->addAction(tr("E&xit"), this, SLOT(close()), QKeySequence::Quit); fileMenu->addAction(tr("E&xit"), this, &QWidget::close, QKeySequence::Quit);
model = new DomModel(QDomDocument(), this); model = new DomModel(QDomDocument(), this);
view = new QTreeView(this); view = new QTreeView(this);

View File

@ -69,9 +69,9 @@ Window::Window(QWidget *parent)
mapper->addMapping(addressEdit, 1); mapper->addMapping(addressEdit, 1);
mapper->addMapping(ageSpinBox, 2); mapper->addMapping(ageSpinBox, 2);
connect(previousButton, SIGNAL(clicked()), mapper, SLOT(toPrevious())); connect(previousButton, &QAbstractButton::clicked, mapper, &QDataWidgetMapper::toPrevious);
connect(nextButton, SIGNAL(clicked()), mapper, SLOT(toNext())); connect(nextButton, &QAbstractButton::clicked, mapper, &QDataWidgetMapper::toNext);
connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(updateButtons(int))); connect(mapper, &QDataWidgetMapper::currentIndexChanged, this, &Window::updateButtons);
//! [Set up the mapper] //! [Set up the mapper]
//! [Set up the layout] //! [Set up the layout]

View File

@ -73,17 +73,17 @@ SpreadSheet::SpreadSheet(int rows, int cols, QWidget *parent)
setCentralWidget(table); setCentralWidget(table);
statusBar(); statusBar();
connect(table, SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)), connect(table, &QTableWidget::currentItemChanged,
this, SLOT(updateStatus(QTableWidgetItem*))); this, &SpreadSheet::updateStatus);
connect(table, SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)), connect(table, &QTableWidget::currentItemChanged,
this, SLOT(updateColor(QTableWidgetItem*))); this, &SpreadSheet::updateColor);
connect(table, SIGNAL(currentItemChanged(QTableWidgetItem*,QTableWidgetItem*)), connect(table, &QTableWidget::currentItemChanged,
this, SLOT(updateLineEdit(QTableWidgetItem*))); this, &SpreadSheet::updateLineEdit);
connect(table, SIGNAL(itemChanged(QTableWidgetItem*)), connect(table, &QTableWidget::itemChanged,
this, SLOT(updateStatus(QTableWidgetItem*))); this, &SpreadSheet::updateStatus);
connect(formulaInput, SIGNAL(returnPressed()), this, SLOT(returnPressed())); connect(formulaInput, &QLineEdit::returnPressed, this, &SpreadSheet::returnPressed);
connect(table, SIGNAL(itemChanged(QTableWidgetItem*)), connect(table, &QTableWidget::itemChanged,
this, SLOT(updateLineEdit(QTableWidgetItem*))); this, &SpreadSheet::updateLineEdit);
setWindowTitle(tr("Spreadsheet")); setWindowTitle(tr("Spreadsheet"));
} }
@ -91,43 +91,43 @@ SpreadSheet::SpreadSheet(int rows, int cols, QWidget *parent)
void SpreadSheet::createActions() void SpreadSheet::createActions()
{ {
cell_sumAction = new QAction(tr("Sum"), this); 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 = new QAction(tr("&Add"), this);
cell_addAction->setShortcut(Qt::CTRL | Qt::Key_Plus); 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 = new QAction(tr("&Subtract"), this);
cell_subAction->setShortcut(Qt::CTRL | Qt::Key_Minus); 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 = new QAction(tr("&Multiply"), this);
cell_mulAction->setShortcut(Qt::CTRL | Qt::Key_multiply); 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 = new QAction(tr("&Divide"), this);
cell_divAction->setShortcut(Qt::CTRL | Qt::Key_division); 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 = new QAction(tr("Font..."), this);
fontAction->setShortcut(Qt::CTRL | Qt::Key_F); 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); 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 = new QAction(tr("Clear"), this);
clearAction->setShortcut(Qt::Key_Delete); 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); 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); 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); 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 = new QAction(this);
firstSeparator->setSeparator(true); firstSeparator->setSeparator(true);
@ -309,11 +309,11 @@ bool SpreadSheet::runInputDialog(const QString &title,
outColInput.setCurrentIndex(outCol); outColInput.setCurrentIndex(outCol);
QPushButton cancelButton(tr("Cancel"), &addDialog); QPushButton cancelButton(tr("Cancel"), &addDialog);
connect(&cancelButton, SIGNAL(clicked()), &addDialog, SLOT(reject())); connect(&cancelButton, &QAbstractButton::clicked, &addDialog, &QDialog::reject);
QPushButton okButton(tr("OK"), &addDialog); QPushButton okButton(tr("OK"), &addDialog);
okButton.setDefault(true); okButton.setDefault(true);
connect(&okButton, SIGNAL(clicked()), &addDialog, SLOT(accept())); connect(&okButton, &QAbstractButton::clicked, &addDialog, &QDialog::accept);
QHBoxLayout *buttonsLayout = new QHBoxLayout; QHBoxLayout *buttonsLayout = new QHBoxLayout;
buttonsLayout->addStretch(1); buttonsLayout->addStretch(1);
@ -625,7 +625,7 @@ void SpreadSheet::print()
QPrintPreviewDialog dlg(&printer); QPrintPreviewDialog dlg(&printer);
PrintView view; PrintView view;
view.setModel(table->model()); view.setModel(table->model());
connect(&dlg, SIGNAL(paintRequested(QPrinter*)), &view, SLOT(print(QPrinter*))); connect(&dlg, &QPrintPreviewDialog::paintRequested, &view, &PrintView::print);
dlg.exec(); dlg.exec();
#endif #endif
} }

View File

@ -63,7 +63,7 @@ QWidget *SpreadSheetDelegate::createEditor(QWidget *parent,
QCompleter *autoComplete = new QCompleter(allStrings); QCompleter *autoComplete = new QCompleter(allStrings);
editor->setCompleter(autoComplete); editor->setCompleter(autoComplete);
connect(editor, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); connect(editor, &QLineEdit::editingFinished, this, &SpreadSheetDelegate::commitAndCloseEditor);
return editor; return editor;
} }

View File

@ -83,8 +83,8 @@ QWidget *StarDelegate::createEditor(QWidget *parent,
{ {
if (index.data().canConvert<StarRating>()) { if (index.data().canConvert<StarRating>()) {
StarEditor *editor = new StarEditor(parent); StarEditor *editor = new StarEditor(parent);
connect(editor, SIGNAL(editingFinished()), connect(editor, &StarEditor::editingFinished,
this, SLOT(commitAndCloseEditor())); this, &StarDelegate::commitAndCloseEditor);
return editor; return editor;
} else { } else {
return QStyledItemDelegate::createEditor(parent, option, index); return QStyledItemDelegate::createEditor(parent, option, index);