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:
parent
7b72cc205c
commit
af38340720
@ -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"));
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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]
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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<QComboIntSignal>(&QComboBox::currentIndexChanged),
|
||||
this, &Window::filterRegExpChanged);
|
||||
connect(filterColumnComboBox, static_cast<QComboIntSignal>(&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"));
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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]
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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(horizontalHeader(),&QHeaderView::sectionResized, this,
|
||||
&FreezeTableWidget::updateSectionWidth);
|
||||
connect(verticalHeader(),&QHeaderView::sectionResized, this,
|
||||
&FreezeTableWidget::updateSectionHeight);
|
||||
|
||||
connect(frozenTableView->verticalScrollBar(), SIGNAL(valueChanged(int)),
|
||||
verticalScrollBar(), SLOT(setValue(int)));
|
||||
connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
|
||||
frozenTableView->verticalScrollBar(), SLOT(setValue(int)));
|
||||
connect(frozenTableView->verticalScrollBar(), &QAbstractSlider::valueChanged,
|
||||
verticalScrollBar(), &QAbstractSlider::setValue);
|
||||
connect(verticalScrollBar(), &QAbstractSlider::valueChanged,
|
||||
frozenTableView->verticalScrollBar(), &QAbstractSlider::setValue);
|
||||
|
||||
|
||||
}
|
||||
|
@ -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<QSpinBoxIntSignal>(&QSpinBox::valueChanged),
|
||||
delegate, &PixelDelegate::setPixelSize);
|
||||
connect(pixelSizeSpinBox, static_cast<QSpinBoxIntSignal>(&QSpinBox::valueChanged),
|
||||
this, &MainWindow::updateView);
|
||||
//! [4]
|
||||
|
||||
QHBoxLayout *controlsLayout = new QHBoxLayout;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -57,26 +57,27 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
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()) {
|
||||
fileName = QFileDialog::getOpenFileName(this,
|
||||
tr("Open Image"), "", tr("Image Files (*.png *.jpg *.bmp)"));
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -83,8 +83,8 @@ QWidget *StarDelegate::createEditor(QWidget *parent,
|
||||
{
|
||||
if (index.data().canConvert<StarRating>()) {
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user