diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2019-04-16 16:32:08 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2019-04-16 16:32:08 +0200 |
commit | 6630937e63ae5797487b86743a7733c8ae5cc42c (patch) | |
tree | 3d53dacf6430f9099e1fb20835881205de674961 /examples/widgets/tutorials | |
parent | 37ed6dae00640f9cc980ffda05347c12a7eb5d7e (diff) | |
parent | c7af193d2e49e9f10b86262e63d8d13abf72b5cf (diff) |
Merge commit 'dev' into 'wip/cmake-merge'
Change-Id: I176c40d031be26a1dd1cf08843e448a660598783
Diffstat (limited to 'examples/widgets/tutorials')
40 files changed, 308 insertions, 260 deletions
diff --git a/examples/widgets/tutorials/addressbook/part2/addressbook.cpp b/examples/widgets/tutorials/addressbook/part2/addressbook.cpp index 34fa5d2060..d5ee394abd 100644 --- a/examples/widgets/tutorials/addressbook/part2/addressbook.cpp +++ b/examples/widgets/tutorials/addressbook/part2/addressbook.cpp @@ -74,9 +74,12 @@ AddressBook::AddressBook(QWidget *parent) cancelButton->hide(); //! [pushbutton declaration] //! [connecting signals and slots] - connect(addButton, SIGNAL(clicked()), this, SLOT(addContact())); - connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact())); - connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); + connect(addButton, &QPushButton::clicked, + this, &AddressBook::addContact); + connect(submitButton, &QPushButton::clicked, + this, &AddressBook::submitContact); + connect(cancelButton, &QPushButton::clicked, + this, &AddressBook::cancel); //! [connecting signals and slots] //! [vertical layout] QVBoxLayout *buttonLayout1 = new QVBoxLayout; diff --git a/examples/widgets/tutorials/addressbook/part3/addressbook.cpp b/examples/widgets/tutorials/addressbook/part3/addressbook.cpp index caef83970a..b6d48f7a0d 100644 --- a/examples/widgets/tutorials/addressbook/part3/addressbook.cpp +++ b/examples/widgets/tutorials/addressbook/part3/addressbook.cpp @@ -74,13 +74,17 @@ AddressBook::AddressBook(QWidget *parent) previousButton = new QPushButton(tr("&Previous")); previousButton->setEnabled(false); //! [navigation pushbuttons] - - connect(addButton, SIGNAL(clicked()), this, SLOT(addContact())); - connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact())); - connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); + connect(addButton, &QPushButton::clicked, + this, &AddressBook::addContact); + connect(submitButton, &QPushButton::clicked, + this, &AddressBook::submitContact); + connect(cancelButton, &QPushButton::clicked, + this, &AddressBook::cancel); //! [connecting navigation signals] - connect(nextButton, SIGNAL(clicked()), this, SLOT(next())); - connect(previousButton, SIGNAL(clicked()), this, SLOT(previous())); + connect(nextButton, &QPushButton::clicked, + this, &AddressBook::next); + connect(previousButton, &QPushButton::clicked, + this, &AddressBook::previous); //! [connecting navigation signals] QVBoxLayout *buttonLayout1 = new QVBoxLayout; diff --git a/examples/widgets/tutorials/addressbook/part4/addressbook.cpp b/examples/widgets/tutorials/addressbook/part4/addressbook.cpp index 92f0776727..77ce216c07 100644 --- a/examples/widgets/tutorials/addressbook/part4/addressbook.cpp +++ b/examples/widgets/tutorials/addressbook/part4/addressbook.cpp @@ -79,15 +79,22 @@ AddressBook::AddressBook(QWidget *parent) previousButton = new QPushButton(tr("&Previous")); previousButton->setEnabled(false); - connect(addButton, SIGNAL(clicked()), this, SLOT(addContact())); - connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact())); + connect(addButton, &QPushButton::clicked, + this, &AddressBook::addContact); + connect(submitButton, &QPushButton::clicked, + this, &AddressBook::submitContact); //! [connecting edit and remove] - connect(editButton, SIGNAL(clicked()), this, SLOT(editContact())); - connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact())); + connect(editButton, &QPushButton::clicked, + this, &AddressBook::editContact); + connect(removeButton, &QPushButton::clicked, + this, &AddressBook::removeContact); //! [connecting edit and remove] - connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); - connect(nextButton, SIGNAL(clicked()), this, SLOT(next())); - connect(previousButton, SIGNAL(clicked()), this, SLOT(previous())); + connect(cancelButton, &QPushButton::clicked, + this, &AddressBook::cancel); + connect(nextButton, &QPushButton::clicked, + this, &AddressBook::next); + connect(previousButton, &QPushButton::clicked, + this, &AddressBook::previous); QVBoxLayout *buttonLayout1 = new QVBoxLayout; buttonLayout1->addWidget(addButton); diff --git a/examples/widgets/tutorials/addressbook/part5/addressbook.cpp b/examples/widgets/tutorials/addressbook/part5/addressbook.cpp index 6e09ec287d..5505a0e35c 100644 --- a/examples/widgets/tutorials/addressbook/part5/addressbook.cpp +++ b/examples/widgets/tutorials/addressbook/part5/addressbook.cpp @@ -86,16 +86,24 @@ AddressBook::AddressBook(QWidget *parent) dialog = new FindDialog(this); //! [instantiating FindDialog] - connect(addButton, SIGNAL(clicked()), this, SLOT(addContact())); - connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact())); - connect(editButton, SIGNAL(clicked()), this, SLOT(editContact())); - connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); - connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact())); + connect(addButton, &QPushButton::clicked, + this, &AddressBook::addContact); + connect(submitButton, &QPushButton::clicked, + this, &AddressBook::submitContact); + connect(editButton, &QPushButton::clicked, + this, &AddressBook::editContact); + connect(removeButton, &QPushButton::clicked, + this, &AddressBook::removeContact); + connect(cancelButton, &QPushButton::clicked, + this, &AddressBook::cancel); //! [signals and slots for find] - connect(findButton, SIGNAL(clicked()), this, SLOT(findContact())); + connect(findButton, &QPushButton::clicked, + this, &AddressBook::findContact); //! [signals and slots for find] - connect(nextButton, SIGNAL(clicked()), this, SLOT(next())); - connect(previousButton, SIGNAL(clicked()), this, SLOT(previous())); + connect(nextButton, &QPushButton::clicked, + this, &AddressBook::next); + connect(previousButton, &QPushButton::clicked, + this, &AddressBook::previous); QVBoxLayout *buttonLayout1 = new QVBoxLayout; buttonLayout1->addWidget(addButton); diff --git a/examples/widgets/tutorials/addressbook/part5/finddialog.cpp b/examples/widgets/tutorials/addressbook/part5/finddialog.cpp index b0d9a5e6e3..615b39d42f 100644 --- a/examples/widgets/tutorials/addressbook/part5/finddialog.cpp +++ b/examples/widgets/tutorials/addressbook/part5/finddialog.cpp @@ -68,8 +68,10 @@ FindDialog::FindDialog(QWidget *parent) setLayout(layout); setWindowTitle(tr("Find a Contact")); - connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked())); - connect(findButton, SIGNAL(clicked()), this, SLOT(accept())); + connect(findButton, &QPushButton::clicked, + this, &FindDialog::findClicked); + connect(findButton, &QPushButton::clicked, + this, &FindDialog::accept); } //! [constructor] //! [findClicked() function] diff --git a/examples/widgets/tutorials/addressbook/part6/addressbook.cpp b/examples/widgets/tutorials/addressbook/part6/addressbook.cpp index b2e361a45e..8e740cfffc 100644 --- a/examples/widgets/tutorials/addressbook/part6/addressbook.cpp +++ b/examples/widgets/tutorials/addressbook/part6/addressbook.cpp @@ -92,16 +92,26 @@ AddressBook::AddressBook(QWidget *parent) dialog = new FindDialog(this); - connect(addButton, SIGNAL(clicked()), this, SLOT(addContact())); - connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact())); - connect(editButton, SIGNAL(clicked()), this, SLOT(editContact())); - connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); - connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact())); - connect(findButton, SIGNAL(clicked()), this, SLOT(findContact())); - connect(nextButton, SIGNAL(clicked()), this, SLOT(next())); - connect(previousButton, SIGNAL(clicked()), this, SLOT(previous())); - connect(loadButton, SIGNAL(clicked()), this, SLOT(loadFromFile())); - connect(saveButton, SIGNAL(clicked()), this, SLOT(saveToFile())); + connect(addButton, &QPushButton::clicked, + this, &AddressBook::addContact); + connect(submitButton, &QPushButton::clicked, + this, &AddressBook::submitContact); + connect(editButton, &QPushButton::clicked, + this, &AddressBook::editContact); + connect(removeButton, &QPushButton::clicked, + this, &AddressBook::removeContact); + connect(cancelButton, &QPushButton::clicked, + this, &AddressBook::cancel); + connect(findButton, &QPushButton::clicked, + this, &AddressBook::findContact); + connect(nextButton, &QPushButton::clicked, + this, &AddressBook::next); + connect(previousButton, &QPushButton::clicked, + this, &AddressBook::previous); + connect(loadButton, &QPushButton::clicked, + this, &AddressBook::loadFromFile); + connect(saveButton, &QPushButton::clicked, + this, &AddressBook::saveToFile); QVBoxLayout *buttonLayout1 = new QVBoxLayout; buttonLayout1->addWidget(addButton); diff --git a/examples/widgets/tutorials/addressbook/part6/finddialog.cpp b/examples/widgets/tutorials/addressbook/part6/finddialog.cpp index 6a1e6b116f..c25cccd552 100644 --- a/examples/widgets/tutorials/addressbook/part6/finddialog.cpp +++ b/examples/widgets/tutorials/addressbook/part6/finddialog.cpp @@ -67,8 +67,10 @@ FindDialog::FindDialog(QWidget *parent) setLayout(layout); setWindowTitle(tr("Find a Contact")); - connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked())); - connect(findButton, SIGNAL(clicked()), this, SLOT(accept())); + connect(findButton, &QPushButton::clicked, + this, &FindDialog::findClicked); + connect(findButton, &QPushButton::clicked, + this, &FindDialog::accept); } void FindDialog::findClicked() diff --git a/examples/widgets/tutorials/addressbook/part7/addressbook.cpp b/examples/widgets/tutorials/addressbook/part7/addressbook.cpp index e946c873e3..717d0882af 100644 --- a/examples/widgets/tutorials/addressbook/part7/addressbook.cpp +++ b/examples/widgets/tutorials/addressbook/part7/addressbook.cpp @@ -92,17 +92,28 @@ AddressBook::AddressBook(QWidget *parent) dialog = new FindDialog(this); - connect(addButton, SIGNAL(clicked()), this, SLOT(addContact())); - connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact())); - connect(editButton, SIGNAL(clicked()), this, SLOT(editContact())); - connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); - connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact())); - connect(findButton, SIGNAL(clicked()), this, SLOT(findContact())); - connect(nextButton, SIGNAL(clicked()), this, SLOT(next())); - connect(previousButton, SIGNAL(clicked()), this, SLOT(previous())); - connect(loadButton, SIGNAL(clicked()), this, SLOT(loadFromFile())); - connect(saveButton, SIGNAL(clicked()), this, SLOT(saveToFile())); - connect(exportButton, SIGNAL(clicked()), this, SLOT(exportAsVCard())); + connect(addButton, &QPushButton::clicked, + this, &AddressBook::addContact); + connect(submitButton, &QPushButton::clicked, + this, &AddressBook::submitContact); + connect(editButton, &QPushButton::clicked, + this, &AddressBook::editContact); + connect(removeButton, &QPushButton::clicked, + this, &AddressBook::removeContact); + connect(cancelButton, &QPushButton::clicked, + this, &AddressBook::cancel); + connect(findButton, &QPushButton::clicked, + this, &AddressBook::findContact); + connect(nextButton, &QPushButton::clicked, + this, &AddressBook::next); + connect(previousButton, &QPushButton::clicked, + this, &AddressBook::previous); + connect(loadButton, &QPushButton::clicked, + this, &AddressBook::loadFromFile); + connect(saveButton, &QPushButton::clicked, + this, &AddressBook::saveToFile); + connect(exportButton, &QPushButton::clicked, + this, &AddressBook::exportAsVCard); QVBoxLayout *buttonLayout1 = new QVBoxLayout; buttonLayout1->addWidget(addButton); diff --git a/examples/widgets/tutorials/addressbook/part7/finddialog.cpp b/examples/widgets/tutorials/addressbook/part7/finddialog.cpp index 6a1e6b116f..c25cccd552 100644 --- a/examples/widgets/tutorials/addressbook/part7/finddialog.cpp +++ b/examples/widgets/tutorials/addressbook/part7/finddialog.cpp @@ -67,8 +67,10 @@ FindDialog::FindDialog(QWidget *parent) setLayout(layout); setWindowTitle(tr("Find a Contact")); - connect(findButton, SIGNAL(clicked()), this, SLOT(findClicked())); - connect(findButton, SIGNAL(clicked()), this, SLOT(accept())); + connect(findButton, &QPushButton::clicked, + this, &FindDialog::findClicked); + connect(findButton, &QPushButton::clicked, + this, &FindDialog::accept); } void FindDialog::findClicked() diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp index 90f5f1a6b3..8bf83859a0 100644 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp +++ b/examples/widgets/tutorials/gettingStarted/gsQt/part2/main.cpp @@ -57,7 +57,8 @@ int main(int argc, char *argv[]) QTextEdit *textEdit = new QTextEdit; QPushButton *quitButton = new QPushButton("&Quit"); - QObject::connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit())); + QObject::connect(quitButton, &QPushButton::clicked, + qApp, &QApplication::quit); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(textEdit); diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp index 0a60c1cf16..d4b43eb034 100644 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp +++ b/examples/widgets/tutorials/gettingStarted/gsQt/part3/main.cpp @@ -71,7 +71,8 @@ Notepad::Notepad() textEdit = new QTextEdit; quitButton = new QPushButton(tr("Quit")); - connect(quitButton, SIGNAL(clicked()), this, SLOT(quit())); + connect(quitButton, &QPushButton::clicked, + this, &Notepad::quit); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(textEdit); diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp index 6d9e96a3d4..8c5fbc70ca 100644 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp +++ b/examples/widgets/tutorials/gettingStarted/gsQt/part4/main.cpp @@ -73,14 +73,16 @@ private: Notepad::Notepad() { - loadAction = new QAction(tr("&Load"), this); saveAction = new QAction(tr("&Save"), this); exitAction = new QAction(tr("E&xit"), this); - connect(loadAction, SIGNAL(triggered()), this, SLOT(load())); - connect(saveAction, SIGNAL(triggered()), this, SLOT(save())); - connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(loadAction, &QAction::triggered, + this, &Notepad::load); + connect(saveAction, &QAction::triggered, + this, &Notepad::save); + connect(exitAction, &QAction::triggered, + qApp, &QApplication::quit); fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(loadAction); diff --git a/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp b/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp index b2b4a73874..cc3e1a261c 100644 --- a/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp +++ b/examples/widgets/tutorials/gettingStarted/gsQt/part5/main.cpp @@ -73,14 +73,16 @@ private: Notepad::Notepad() { - openAction = new QAction(tr("&Load"), this); saveAction = new QAction(tr("&Save"), this); exitAction = new QAction(tr("E&xit"), this); - connect(openAction, SIGNAL(triggered()), this, SLOT(open())); - connect(saveAction, SIGNAL(triggered()), this, SLOT(save())); - connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(openAction, &QAction::triggered, + this, &Notepad::open); + connect(saveAction, &QAction::triggered, + this, &Notepad::save); + connect(exitAction, &QAction::triggered, + qApp, &QApplication::quit); fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(openAction); diff --git a/examples/widgets/tutorials/gettingstartedqt.qdoc b/examples/widgets/tutorials/gettingstartedqt.qdoc index bbe1dd1a8d..32e8845c05 100644 --- a/examples/widgets/tutorials/gettingstartedqt.qdoc +++ b/examples/widgets/tutorials/gettingstartedqt.qdoc @@ -390,10 +390,10 @@ action concerned. When the QAction has been dragged to the toolbar, clicking the icon will launch the associated slot. - Complete the method \c on_actionNew_triggered(): + Complete the method \c newDocument(): \quotefromfile tutorials/notepad/notepad.cpp - \skipto on_actionNew_triggered() + \skipto newDocument() \printuntil } \c current_file is a global variable containing the file presently @@ -411,10 +411,10 @@ In \c notepad.ui, right click on \c actionOpen and select \c {Go to slot} - Complete method \c on_actionOpen_triggered(). + Complete method \c open(). \quotefromfile tutorials/notepad/notepad.cpp - \skipto on_actionOpen_triggered() + \skipto open() \printuntil file.close \printuntil } @@ -436,7 +436,7 @@ \l {Opening a file}, by right clicking on \c actionSave, and selecting \c {Go to Slot}. - \skipto Notepad::on_actionSave_triggered + \skipto Notepad::save \printuntil file.close \printuntil } @@ -449,7 +449,7 @@ \section2 Saving a file with \c {Save as} - \skipto Notepad::on_actionSave_as_triggered + \skipto Notepad::saveAs \printuntil file.close \printuntil } @@ -475,7 +475,7 @@ \section2 Select a Font - \skipto Notepad::on_actionFont_triggered + \skipto Notepad::selectFont \printuntil ui->textEdit->setFont \printline } diff --git a/examples/widgets/tutorials/modelview/1_readonly/main.cpp b/examples/widgets/tutorials/modelview/1_readonly/main.cpp index 80383f8c94..ea571d3699 100644 --- a/examples/widgets/tutorials/modelview/1_readonly/main.cpp +++ b/examples/widgets/tutorials/modelview/1_readonly/main.cpp @@ -50,16 +50,16 @@ //! [Quoting ModelView Tutorial] // main.cpp -#include <QtWidgets/QApplication> -#include <QtWidgets/QTableView> +#include <QApplication> +#include <QTableView> #include "mymodel.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); QTableView tableView; - MyModel myModel(0); - tableView.setModel( &myModel ); + MyModel myModel; + tableView.setModel(&myModel); tableView.show(); return a.exec(); } diff --git a/examples/widgets/tutorials/modelview/1_readonly/mymodel.cpp b/examples/widgets/tutorials/modelview/1_readonly/mymodel.cpp index 82ec53c665..2b36565bc6 100644 --- a/examples/widgets/tutorials/modelview/1_readonly/mymodel.cpp +++ b/examples/widgets/tutorials/modelview/1_readonly/mymodel.cpp @@ -53,7 +53,7 @@ #include "mymodel.h" MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) + : QAbstractTableModel(parent) { } @@ -70,11 +70,10 @@ int MyModel::columnCount(const QModelIndex & /*parent*/) const QVariant MyModel::data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) - { return QString("Row%1, Column%2") .arg(index.row() + 1) .arg(index.column() +1); - } + return QVariant(); } //! [Quoting ModelView Tutorial] diff --git a/examples/widgets/tutorials/modelview/1_readonly/mymodel.h b/examples/widgets/tutorials/modelview/1_readonly/mymodel.h index e675cc6bc2..8761322896 100644 --- a/examples/widgets/tutorials/modelview/1_readonly/mymodel.h +++ b/examples/widgets/tutorials/modelview/1_readonly/mymodel.h @@ -59,8 +59,8 @@ class MyModel : public QAbstractTableModel { Q_OBJECT public: - MyModel(QObject *parent); - int rowCount(const QModelIndex &parent = QModelIndex()) const override ; + MyModel(QObject *parent = nullptr); + int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; }; diff --git a/examples/widgets/tutorials/modelview/2_formatting/main.cpp b/examples/widgets/tutorials/modelview/2_formatting/main.cpp index 80383f8c94..ea571d3699 100644 --- a/examples/widgets/tutorials/modelview/2_formatting/main.cpp +++ b/examples/widgets/tutorials/modelview/2_formatting/main.cpp @@ -50,16 +50,16 @@ //! [Quoting ModelView Tutorial] // main.cpp -#include <QtWidgets/QApplication> -#include <QtWidgets/QTableView> +#include <QApplication> +#include <QTableView> #include "mymodel.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); QTableView tableView; - MyModel myModel(0); - tableView.setModel( &myModel ); + MyModel myModel; + tableView.setModel(&myModel); tableView.show(); return a.exec(); } diff --git a/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp b/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp index 9511648392..938597a34e 100644 --- a/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp +++ b/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp @@ -48,13 +48,14 @@ ** ****************************************************************************/ +#include "mymodel.h" + #include <QFont> #include <QBrush> -#include "mymodel.h" #include <QDebug> MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) + : QAbstractTableModel(parent) { } @@ -78,7 +79,7 @@ QVariant MyModel::data(const QModelIndex &index, int role) const qDebug() << QString("row %1, col%2, role %3") .arg(row).arg(col).arg(role); - switch(role){ + switch (role) { case Qt::DisplayRole: if (row == 0 && col == 1) return QString("<--left"); if (row == 1 && col == 1) return QString("right-->"); @@ -86,36 +87,25 @@ QVariant MyModel::data(const QModelIndex &index, int role) const return QString("Row%1, Column%2") .arg(row + 1) .arg(col +1); - break; case Qt::FontRole: - if (row == 0 && col == 0) //change font only for cell(0,0) - { + if (row == 0 && col == 0) { //change font only for cell(0,0) QFont boldFont; boldFont.setBold(true); return boldFont; } break; case Qt::BackgroundRole: - if (row == 1 && col == 2) //change background only for cell(1,2) - { - QBrush redBackground(Qt::red); - return redBackground; - } + return QBrush(Qt::red); break; case Qt::TextAlignmentRole: - if (row == 1 && col == 1) //change text alignment only for cell(1,1) - { return Qt::AlignRight + Qt::AlignVCenter; - } break; case Qt::CheckStateRole: - if (row == 1 && col == 0) //add a checkbox to cell(1,0) - { return Qt::Checked; - } + break; } return QVariant(); } diff --git a/examples/widgets/tutorials/modelview/2_formatting/mymodel.h b/examples/widgets/tutorials/modelview/2_formatting/mymodel.h index 9c12f98ba9..e8ae673f62 100644 --- a/examples/widgets/tutorials/modelview/2_formatting/mymodel.h +++ b/examples/widgets/tutorials/modelview/2_formatting/mymodel.h @@ -57,8 +57,8 @@ class MyModel : public QAbstractTableModel { Q_OBJECT public: - MyModel(QObject *parent); - int rowCount(const QModelIndex &parent = QModelIndex()) const override ; + MyModel(QObject *parent = nullptr); + int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; }; diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp b/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp index c03019a910..2330019f93 100644 --- a/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp +++ b/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp @@ -48,8 +48,8 @@ ** ****************************************************************************/ -#include <QtWidgets/QApplication> -#include <QtWidgets/QTableView> +#include <QApplication> +#include <QTableView> #include "mymodel.h" int main(int argc, char *argv[]) @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); QTableView tableView; MyModel myModel(0); - tableView.setModel( &myModel ); + tableView.setModel(&myModel); tableView.show(); return a.exec(); } diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp index e4580a0e01..f289d9abda 100644 --- a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp +++ b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp @@ -48,18 +48,17 @@ ** ****************************************************************************/ -#include <QBrush> -#include <QTime> #include "mymodel.h" +#include <QTime> + //! [quoting mymodel_a] MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) + : QAbstractTableModel(parent) + , timer(new QTimer(this)) { -// selectedCell = 0; - timer = new QTimer(this); timer->setInterval(1000); - connect(timer, SIGNAL(timeout()) , this, SLOT(timerHit())); + connect(timer, &QTimer::timeout , this, &MyModel::timerHit); timer->start(); } //! [quoting mymodel_a] @@ -82,13 +81,9 @@ QVariant MyModel::data(const QModelIndex &index, int role) const int row = index.row(); int col = index.column(); - if (role == Qt::DisplayRole) - { - if (row == 0 && col == 0) - { - return QTime::currentTime().toString(); - } - } + if (role == Qt::DisplayRole && row == 0 && col == 0) + return QTime::currentTime().toString(); + return QVariant(); } //! [quoting mymodel_QVariant ] @@ -99,6 +94,6 @@ void MyModel::timerHit() //we identify the top left cell QModelIndex topLeft = createIndex(0,0); //emit a signal to make the view reread identified data - emit dataChanged(topLeft, topLeft); + emit dataChanged(topLeft, topLeft, {Qt::DisplayRole}); } //! [quoting mymodel_b ] diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h index dfcf0f6239..2ef0e480c2 100644 --- a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h +++ b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h @@ -58,13 +58,12 @@ class MyModel : public QAbstractTableModel { Q_OBJECT public: - MyModel(QObject *parent); - int rowCount(const QModelIndex &parent = QModelIndex()) const override ; + MyModel(QObject *parent = nullptr); + int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - QTimer *timer; private: - int selectedCell; + QTimer *timer; private slots: void timerHit(); }; diff --git a/examples/widgets/tutorials/modelview/4_headers/main.cpp b/examples/widgets/tutorials/modelview/4_headers/main.cpp index 82d493345d..90a8c6e894 100644 --- a/examples/widgets/tutorials/modelview/4_headers/main.cpp +++ b/examples/widgets/tutorials/modelview/4_headers/main.cpp @@ -48,16 +48,16 @@ ** ****************************************************************************/ -#include <QtWidgets/QApplication> -#include <QtWidgets/QTableView> +#include <QApplication> +#include <QTableView> #include "mymodel.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); QTableView tableView; - MyModel myModel(0); - tableView.setModel( &myModel ); + MyModel myModel; + tableView.setModel(&myModel); tableView.show(); return a.exec(); -}
\ No newline at end of file +} diff --git a/examples/widgets/tutorials/modelview/4_headers/mymodel.cpp b/examples/widgets/tutorials/modelview/4_headers/mymodel.cpp index 35e3463b7f..0084475374 100644 --- a/examples/widgets/tutorials/modelview/4_headers/mymodel.cpp +++ b/examples/widgets/tutorials/modelview/4_headers/mymodel.cpp @@ -51,7 +51,7 @@ #include "mymodel.h" MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) + : QAbstractTableModel(parent) { } @@ -70,8 +70,7 @@ int MyModel::columnCount(const QModelIndex & /*parent*/) const //------------------------------------------------------- QVariant MyModel::data(const QModelIndex &index, int role) const { - if (role == Qt::DisplayRole) - { + if (role == Qt::DisplayRole) { return QString("Row%1, Column%2") .arg(index.row() + 1) .arg(index.column() +1); @@ -82,18 +81,14 @@ QVariant MyModel::data(const QModelIndex &index, int role) const //! [quoting mymodel_c] QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const { - if (role == Qt::DisplayRole) - { - if (orientation == Qt::Horizontal) { - switch (section) - { - case 0: - return QString("first"); - case 1: - return QString("second"); - case 2: - return QString("third"); - } + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { + switch (section) { + case 0: + return QString("first"); + case 1: + return QString("second"); + case 2: + return QString("third"); } } return QVariant(); diff --git a/examples/widgets/tutorials/modelview/4_headers/mymodel.h b/examples/widgets/tutorials/modelview/4_headers/mymodel.h index fb2d7aa940..6d8477dae2 100644 --- a/examples/widgets/tutorials/modelview/4_headers/mymodel.h +++ b/examples/widgets/tutorials/modelview/4_headers/mymodel.h @@ -57,8 +57,8 @@ class MyModel : public QAbstractTableModel { Q_OBJECT public: - MyModel(QObject *parent); - int rowCount(const QModelIndex &parent = QModelIndex()) const override ; + MyModel(QObject *parent = nullptr); + int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; diff --git a/examples/widgets/tutorials/modelview/5_edit/main.cpp b/examples/widgets/tutorials/modelview/5_edit/main.cpp index e1b46339b1..315875a627 100644 --- a/examples/widgets/tutorials/modelview/5_edit/main.cpp +++ b/examples/widgets/tutorials/modelview/5_edit/main.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include <QtWidgets/QApplication> +#include <QApplication> #include "mainwindow.h" int main(int argc, char *argv[]) diff --git a/examples/widgets/tutorials/modelview/5_edit/mainwindow.cpp b/examples/widgets/tutorials/modelview/5_edit/mainwindow.cpp index e0b6ea7b1f..d8dfc33212 100644 --- a/examples/widgets/tutorials/modelview/5_edit/mainwindow.cpp +++ b/examples/widgets/tutorials/modelview/5_edit/mainwindow.cpp @@ -48,23 +48,25 @@ ** ****************************************************************************/ -#include <QTableView> #include "mainwindow.h" #include "mymodel.h" +#include <QTableView> + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) + , tableView(new QTableView(this)) { - tableView = new QTableView(this); setCentralWidget(tableView); - QAbstractTableModel *myModel = new MyModel(this); + MyModel *myModel = new MyModel(this); tableView->setModel(myModel); //transfer changes to the model to the window title - connect(myModel, SIGNAL(editCompleted(const QString &)), this, SLOT(setWindowTitle(const QString &))); + connect(myModel, &MyModel::editCompleted, + this, &MainWindow::showWindowTitle); } -void MainWindow::showWindowTitle(const QString & title) +void MainWindow::showWindowTitle(const QString &title) { -setWindowTitle(title); + setWindowTitle(title); } diff --git a/examples/widgets/tutorials/modelview/5_edit/mainwindow.h b/examples/widgets/tutorials/modelview/5_edit/mainwindow.h index 7915b29cdf..104f06f82e 100644 --- a/examples/widgets/tutorials/modelview/5_edit/mainwindow.h +++ b/examples/widgets/tutorials/modelview/5_edit/mainwindow.h @@ -51,9 +51,9 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include <QtWidgets/QMainWindow> +#include <QMainWindow> -QT_BEGIN_NAMESPACE // QT_BEGIN_NAMESPACE / QT_END_NAMESPACE are not needed in Qt user code +QT_BEGIN_NAMESPACE class QTableView; //forward declaration QT_END_NAMESPACE @@ -64,9 +64,9 @@ class MainWindow : public QMainWindow private: QTableView *tableView; public: - MainWindow(QWidget *parent = 0); + MainWindow(QWidget *parent = nullptr); public slots: - void showWindowTitle(const QString & title); + void showWindowTitle(const QString &title); }; #endif // MAINWINDOW_H diff --git a/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp b/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp index fb2954baf2..eeca2ce0a0 100644 --- a/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp +++ b/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp @@ -48,12 +48,10 @@ ** ****************************************************************************/ - #include "mymodel.h" - MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) + : QAbstractTableModel(parent) { } @@ -72,33 +70,31 @@ int MyModel::columnCount(const QModelIndex & /*parent*/) const //----------------------------------------------------------------- QVariant MyModel::data(const QModelIndex &index, int role) const { - if (role == Qt::DisplayRole) - { - return m_gridData[index.row()][index.column()]; - } + if (role == Qt::DisplayRole && checkIndex(index)) + return m_gridData[index.row()][index.column()]; + return QVariant(); } //----------------------------------------------------------------- //! [quoting mymodel_e] -bool MyModel::setData(const QModelIndex & index, const QVariant & value, int role) +bool MyModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if (role == Qt::EditRole) - { + if (role == Qt::EditRole) { + if (!checkIndex(index)) + return false; //save value from editor to member m_gridData m_gridData[index.row()][index.column()] = value.toString(); //for presentation purposes only: build and emit a joined string QString result; - for (int row= 0; row < ROWS; row++) - { - for(int col= 0; col < COLS; col++) - { + for (int row = 0; row < ROWS; row++) { + for (int col= 0; col < COLS; col++) result += m_gridData[row][col] + ' '; - } } - emit editCompleted( result ); + emit editCompleted(result); + return true; } - return true; + return false; } //! [quoting mymodel_e] diff --git a/examples/widgets/tutorials/modelview/5_edit/mymodel.h b/examples/widgets/tutorials/modelview/5_edit/mymodel.h index dd0d4f5066..ce462351af 100644 --- a/examples/widgets/tutorials/modelview/5_edit/mymodel.h +++ b/examples/widgets/tutorials/modelview/5_edit/mymodel.h @@ -64,12 +64,12 @@ class MyModel : public QAbstractTableModel { Q_OBJECT public: - MyModel(QObject *parent); - int rowCount(const QModelIndex &parent = QModelIndex()) const override ; + MyModel(QObject *parent = nullptr); + int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override; - Qt::ItemFlags flags(const QModelIndex & index) const override ; + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; + Qt::ItemFlags flags(const QModelIndex &index) const override; private: QString m_gridData[ROWS][COLS]; //holds text entered into QTableView signals: diff --git a/examples/widgets/tutorials/modelview/6_treeview/main.cpp b/examples/widgets/tutorials/modelview/6_treeview/main.cpp index e1b46339b1..315875a627 100644 --- a/examples/widgets/tutorials/modelview/6_treeview/main.cpp +++ b/examples/widgets/tutorials/modelview/6_treeview/main.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include <QtWidgets/QApplication> +#include <QApplication> #include "mainwindow.h" int main(int argc, char *argv[]) diff --git a/examples/widgets/tutorials/modelview/6_treeview/mainwindow.cpp b/examples/widgets/tutorials/modelview/6_treeview/mainwindow.cpp index 1016afba07..ae4a343680 100644 --- a/examples/widgets/tutorials/modelview/6_treeview/mainwindow.cpp +++ b/examples/widgets/tutorials/modelview/6_treeview/mainwindow.cpp @@ -50,24 +50,25 @@ //! [Quoting ModelView Tutorial] // modelview.cpp +#include "mainwindow.h" + #include <QTreeView> #include <QStandardItemModel> #include <QStandardItem> -#include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) + , treeView(new QTreeView(this)) + , standardModel(new QStandardItemModel(this)) { - treeView = new QTreeView(this); setCentralWidget(treeView); - standardModel = new QStandardItemModel ; - QList<QStandardItem *> preparedRow =prepareRow("first", "second", "third"); + QList<QStandardItem *> preparedRow = prepareRow("first", "second", "third"); QStandardItem *item = standardModel->invisibleRootItem(); // adding a row to the invisible root item produces a root element item->appendRow(preparedRow); - QList<QStandardItem *> secondRow =prepareRow("111", "222", "333"); + QList<QStandardItem *> secondRow = prepareRow("111", "222", "333"); // adding a row to an item starts a subtree preparedRow.first()->appendRow(secondRow); @@ -76,13 +77,11 @@ MainWindow::MainWindow(QWidget *parent) } QList<QStandardItem *> MainWindow::prepareRow(const QString &first, - const QString &second, - const QString &third) + const QString &second, + const QString &third) const { - QList<QStandardItem *> rowItems; - rowItems << new QStandardItem(first); - rowItems << new QStandardItem(second); - rowItems << new QStandardItem(third); - return rowItems; + return {new QStandardItem(first), + new QStandardItem(second), + new QStandardItem(third)}; } //! [Quoting ModelView Tutorial] diff --git a/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h b/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h index d625d5991d..65d9c18658 100644 --- a/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h +++ b/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h @@ -51,9 +51,9 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include <QtWidgets/QMainWindow> +#include <QMainWindow> -QT_BEGIN_NAMESPACE // QT_BEGIN_NAMESPACE / QT_END_NAMESPACE are not needed in Qt user code +QT_BEGIN_NAMESPACE class QTreeView; //forward declarations class QStandardItemModel; class QStandardItem; @@ -66,11 +66,11 @@ class MainWindow : public QMainWindow private: QTreeView *treeView; QStandardItemModel *standardModel; - QList<QStandardItem *> prepareRow( const QString &first, - const QString &second, - const QString &third ); + QList<QStandardItem *> prepareRow(const QString &first, + const QString &second, + const QString &third) const; public: - MainWindow(QWidget *parent = 0); + MainWindow(QWidget *parent = nullptr); }; #endif // MAINWINDOW_H diff --git a/examples/widgets/tutorials/modelview/7_selections/main.cpp b/examples/widgets/tutorials/modelview/7_selections/main.cpp index e1b46339b1..315875a627 100644 --- a/examples/widgets/tutorials/modelview/7_selections/main.cpp +++ b/examples/widgets/tutorials/modelview/7_selections/main.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include <QtWidgets/QApplication> +#include <QApplication> #include "mainwindow.h" int main(int argc, char *argv[]) diff --git a/examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp b/examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp index 200751ee6d..2b10071a68 100644 --- a/examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp +++ b/examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp @@ -49,17 +49,18 @@ ****************************************************************************/ //! [quoting modelview_a] +#include "mainwindow.h" + #include <QTreeView> #include <QStandardItemModel> #include <QItemSelectionModel> -#include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) + , treeView(new QTreeView(this)) + , standardModel(new QStandardItemModel(this)) { - treeView = new QTreeView(this); setCentralWidget(treeView); - standardModel = new QStandardItemModel ; QStandardItem *rootNode = standardModel->invisibleRootItem(); @@ -88,9 +89,9 @@ MainWindow::MainWindow(QWidget *parent) treeView->expandAll(); //selection changes shall trigger a slot - QItemSelectionModel *selectionModel= treeView->selectionModel(); - connect(selectionModel, SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &)), - this, SLOT(selectionChangedSlot(const QItemSelection &, const QItemSelection &))); + QItemSelectionModel *selectionModel = treeView->selectionModel(); + connect(selectionModel, &QItemSelectionModel::selectionChanged, + this, &MainWindow::selectionChangedSlot); } //! [quoting modelview_a] @@ -103,10 +104,9 @@ void MainWindow::selectionChangedSlot(const QItemSelection & /*newSelection*/, c const QModelIndex index = treeView->selectionModel()->currentIndex(); QString selectedText = index.data(Qt::DisplayRole).toString(); //find out the hierarchy level of the selected item - int hierarchyLevel=1; + int hierarchyLevel = 1; QModelIndex seekRoot = index; - while(seekRoot.parent() != QModelIndex()) - { + while (seekRoot.parent() != QModelIndex()) { seekRoot = seekRoot.parent(); hierarchyLevel++; } diff --git a/examples/widgets/tutorials/modelview/7_selections/mainwindow.h b/examples/widgets/tutorials/modelview/7_selections/mainwindow.h index 13ca7dbc30..c9761dd3d9 100644 --- a/examples/widgets/tutorials/modelview/7_selections/mainwindow.h +++ b/examples/widgets/tutorials/modelview/7_selections/mainwindow.h @@ -51,9 +51,9 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include <QtWidgets/QMainWindow> +#include <QMainWindow> -QT_BEGIN_NAMESPACE // QT_BEGIN_NAMESPACE / QT_END_NAMESPACE are not needed in Qt user code +QT_BEGIN_NAMESPACE class QTreeView; //forward declarations class QStandardItemModel; class QItemSelection; @@ -67,7 +67,7 @@ private: QTreeView *treeView; QStandardItemModel *standardModel; private slots: - void selectionChangedSlot(const QItemSelection & newSelection, const QItemSelection & oldSelection); + void selectionChangedSlot(const QItemSelection &newSelection, const QItemSelection &oldSelection); public: MainWindow(QWidget *parent = 0); }; diff --git a/examples/widgets/tutorials/notepad/notepad.cpp b/examples/widgets/tutorials/notepad/notepad.cpp index d0e600e852..2ccd6501a1 100644 --- a/examples/widgets/tutorials/notepad/notepad.cpp +++ b/examples/widgets/tutorials/notepad/notepad.cpp @@ -74,6 +74,23 @@ Notepad::Notepad(QWidget *parent) : ui->setupUi(this); this->setCentralWidget(ui->textEdit); + connect(ui->actionNew, &QAction::triggered, this, &Notepad::newDocument); + connect(ui->actionOpen, &QAction::triggered, this, &Notepad::open); + connect(ui->actionSave, &QAction::triggered, this, &Notepad::save); + connect(ui->actionSave_as, &QAction::triggered, this, &Notepad::saveAs); + connect(ui->actionPrint, &QAction::triggered, this, &Notepad::print); + connect(ui->actionExit, &QAction::triggered, this, &Notepad::exit); + connect(ui->actionCopy, &QAction::triggered, this, &Notepad::copy); + connect(ui->actionCut, &QAction::triggered, this, &Notepad::cut); + connect(ui->actionPaste, &QAction::triggered, this, &Notepad::paste); + connect(ui->actionUndo, &QAction::triggered, this, &Notepad::undo); + connect(ui->actionRedo, &QAction::triggered, this, &Notepad::redo); + connect(ui->actionFont, &QAction::triggered, this, &Notepad::selectFont); + connect(ui->actionBold, &QAction::triggered, this, &Notepad::setFontBold); + connect(ui->actionUnderline, &QAction::triggered, this, &Notepad::setFontUnderline); + connect(ui->actionItalic, &QAction::triggered, this, &Notepad::setFontItalic); + connect(ui->actionAbout, &QAction::triggered, this, &Notepad::about); + // Disable menu actions for unavailable features #if !QT_CONFIG(printer) ui->actionPrint->setEnabled(false); @@ -91,13 +108,13 @@ Notepad::~Notepad() delete ui; } -void Notepad::on_actionNew_triggered() +void Notepad::newDocument() { currentFile.clear(); ui->textEdit->setText(QString()); } -void Notepad::on_actionOpen_triggered() +void Notepad::open() { QString fileName = QFileDialog::getOpenFileName(this, "Open the file"); QFile file(fileName); @@ -113,7 +130,7 @@ void Notepad::on_actionOpen_triggered() file.close(); } -void Notepad::on_actionSave_triggered() +void Notepad::save() { QString fileName; // If we don't have a filename from before, get one. @@ -135,7 +152,7 @@ void Notepad::on_actionSave_triggered() file.close(); } -void Notepad::on_actionSave_as_triggered() +void Notepad::saveAs() { QString fileName = QFileDialog::getSaveFileName(this, "Save as"); QFile file(fileName); @@ -152,7 +169,7 @@ void Notepad::on_actionSave_as_triggered() file.close(); } -void Notepad::on_actionPrint_triggered() +void Notepad::print() { #if QT_CONFIG(printer) QPrinter printDev; @@ -165,43 +182,43 @@ void Notepad::on_actionPrint_triggered() #endif // QT_CONFIG(printer) } -void Notepad::on_actionExit_triggered() +void Notepad::exit() { QCoreApplication::quit(); } -void Notepad::on_actionCopy_triggered() +void Notepad::copy() { #if QT_CONFIG(clipboard) ui->textEdit->copy(); #endif } -void Notepad::on_actionCut_triggered() +void Notepad::cut() { #if QT_CONFIG(clipboard) ui->textEdit->cut(); #endif } -void Notepad::on_actionPaste_triggered() +void Notepad::paste() { #if QT_CONFIG(clipboard) ui->textEdit->paste(); #endif } -void Notepad::on_actionUndo_triggered() +void Notepad::undo() { ui->textEdit->undo(); } -void Notepad::on_actionRedo_triggered() +void Notepad::redo() { ui->textEdit->redo(); } -void Notepad::on_actionFont_triggered() +void Notepad::selectFont() { bool fontSelected; QFont font = QFontDialog::getFont(&fontSelected, this); @@ -209,23 +226,23 @@ void Notepad::on_actionFont_triggered() ui->textEdit->setFont(font); } -void Notepad::on_actionUnderline_triggered() +void Notepad::setFontUnderline(bool underline) { - ui->textEdit->setFontUnderline(ui->actionUnderline->isChecked()); + ui->textEdit->setFontUnderline(underline); } -void Notepad::on_actionItalic_triggered() +void Notepad::setFontItalic(bool italic) { - ui->textEdit->setFontItalic(ui->actionItalic->isChecked()); + ui->textEdit->setFontItalic(italic); } -void Notepad::on_actionBold_triggered() +void Notepad::setFontBold(bool bold) { - ui->actionBold->isChecked() ? ui->textEdit->setFontWeight(QFont::Bold) : - ui->textEdit->setFontWeight(QFont::Normal); + bold ? ui->textEdit->setFontWeight(QFont::Bold) : + ui->textEdit->setFontWeight(QFont::Normal); } -void Notepad::on_actionAbout_triggered() +void Notepad::about() { QMessageBox::about(this, tr("About MDI"), tr("The <b>Notepad</b> example demonstrates how to code a basic " diff --git a/examples/widgets/tutorials/notepad/notepad.h b/examples/widgets/tutorials/notepad/notepad.h index 288ab4e373..9580ab8071 100644 --- a/examples/widgets/tutorials/notepad/notepad.h +++ b/examples/widgets/tutorials/notepad/notepad.h @@ -79,37 +79,37 @@ public: //! [5] private slots: - void on_actionNew_triggered(); + void newDocument(); - void on_actionOpen_triggered(); + void open(); - void on_actionSave_triggered(); + void save(); - void on_actionSave_as_triggered(); + void saveAs(); - void on_actionPrint_triggered(); + void print(); - void on_actionExit_triggered(); + void exit(); - void on_actionCopy_triggered(); + void copy(); - void on_actionCut_triggered(); + void cut(); - void on_actionPaste_triggered(); + void paste(); - void on_actionUndo_triggered(); + void undo(); - void on_actionRedo_triggered(); + void redo(); - void on_actionFont_triggered(); + void selectFont(); - void on_actionBold_triggered(); + void setFontBold(bool bold); - void on_actionUnderline_triggered(); + void setFontUnderline(bool underline); - void on_actionItalic_triggered(); + void setFontItalic(bool italic); - void on_actionAbout_triggered(); + void about(); //! [6] private: diff --git a/examples/widgets/tutorials/widgets/nestedlayouts/main.cpp b/examples/widgets/tutorials/widgets/nestedlayouts/main.cpp index 9acc74b469..8880dbe3d0 100644 --- a/examples/widgets/tutorials/widgets/nestedlayouts/main.cpp +++ b/examples/widgets/tutorials/widgets/nestedlayouts/main.cpp @@ -76,25 +76,26 @@ int main(int argc, char *argv[]) //! [set up the model] QStandardItemModel model; - model.setHorizontalHeaderLabels( - QStringList() << QApplication::translate("nestedlayouts", "Name") - << QApplication::translate("nestedlayouts", "Office")); + model.setHorizontalHeaderLabels({ QApplication::translate("nestedlayouts", "Name"), + QApplication::translate("nestedlayouts", "Office") }); - QList<QStringList> rows = QList<QStringList>() - << (QStringList() << "Verne Nilsen" << "123") - << (QStringList() << "Carlos Tang" << "77") - << (QStringList() << "Bronwyn Hawcroft" << "119") - << (QStringList() << "Alessandro Hanssen" << "32") - << (QStringList() << "Andrew John Bakken" << "54") - << (QStringList() << "Vanessa Weatherley" << "85") - << (QStringList() << "Rebecca Dickens" << "17") - << (QStringList() << "David Bradley" << "42") - << (QStringList() << "Knut Walters" << "25") - << (QStringList() << "Andrea Jones" << "34"); + const QStringList rows[] = { + QStringList{ QStringLiteral("Verne Nilsen"), QStringLiteral("123") }, + QStringList{ QStringLiteral("Carlos Tang"), QStringLiteral("77") }, + QStringList{ QStringLiteral("Bronwyn Hawcroft"), QStringLiteral("119") }, + QStringList{ QStringLiteral("Alessandro Hanssen"), QStringLiteral("32") }, + QStringList{ QStringLiteral("Andrew John Bakken"), QStringLiteral("54") }, + QStringList{ QStringLiteral("Vanessa Weatherley"), QStringLiteral("85") }, + QStringList{ QStringLiteral("Rebecca Dickens"), QStringLiteral("17") }, + QStringList{ QStringLiteral("David Bradley"), QStringLiteral("42") }, + QStringList{ QStringLiteral("Knut Walters"), QStringLiteral("25") }, + QStringList{ QStringLiteral("Andrea Jones"), QStringLiteral("34") } + }; - foreach (QStringList row, rows) { - QList<QStandardItem *> items; - foreach (QString text, row) + QList<QStandardItem *> items; + for (const QStringList &row : rows) { + items.clear(); + for (const QString &text : row) items.append(new QStandardItem(text)); model.appendRow(items); } |