From f1dd6addda908185f497d299d706b88977dea858 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 2 Oct 2019 12:19:11 +0200 Subject: Make QTextBlockFormat::MarkerType an enum class This came up during API review. Change-Id: I9198e1eb96db0c21e46a226a032919bb62d3ca66 Reviewed-by: Giuseppe D'Angelo --- examples/widgets/richtext/textedit/textedit.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'examples') diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp index 996bb8e0a4..85fb83ab89 100644 --- a/examples/widgets/richtext/textedit/textedit.cpp +++ b/examples/widgets/richtext/textedit/textedit.cpp @@ -640,7 +640,7 @@ void TextEdit::textStyle(int styleIndex) { QTextCursor cursor = textEdit->textCursor(); QTextListFormat::Style style = QTextListFormat::ListStyleUndefined; - QTextBlockFormat::MarkerType marker = QTextBlockFormat::NoMarker; + QTextBlockFormat::MarkerType marker = QTextBlockFormat::MarkerType::NoMarker; switch (styleIndex) { case 1: @@ -657,14 +657,14 @@ void TextEdit::textStyle(int styleIndex) style = cursor.currentList()->format().style(); else style = QTextListFormat::ListDisc; - marker = QTextBlockFormat::Unchecked; + marker = QTextBlockFormat::MarkerType::Unchecked; break; case 5: if (cursor.currentList()) style = cursor.currentList()->format().style(); else style = QTextListFormat::ListDisc; - marker = QTextBlockFormat::Checked; + marker = QTextBlockFormat::MarkerType::Checked; break; case 6: style = QTextListFormat::ListDecimal; @@ -823,14 +823,14 @@ void TextEdit::cursorPositionChanged() break; } switch (textEdit->textCursor().block().blockFormat().marker()) { - case QTextBlockFormat::NoMarker: + case QTextBlockFormat::MarkerType::NoMarker: actionToggleCheckState->setChecked(false); break; - case QTextBlockFormat::Unchecked: + case QTextBlockFormat::MarkerType::Unchecked: comboStyle->setCurrentIndex(4); actionToggleCheckState->setChecked(false); break; - case QTextBlockFormat::Checked: + case QTextBlockFormat::MarkerType::Checked: comboStyle->setCurrentIndex(5); actionToggleCheckState->setChecked(true); break; -- cgit v1.2.3 From 4af00753fad57989a6ae366cc3dbfc56d88508f4 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 6 Sep 2019 23:24:56 +0200 Subject: Cleanup QtWidgets examples Cleanup QtWidgets examples: - use nullptr (clang-tidy) - use member-initialization - adjust the style - fix includes Change-Id: Ic5448606aacc525ea60b615a69227017aa2b821a Reviewed-by: Paul Wicking --- .../widgets/dialogs/classwizard/classwizard.cpp | 4 +- examples/widgets/dialogs/classwizard/classwizard.h | 12 +-- examples/widgets/dialogs/extension/finddialog.h | 2 +- examples/widgets/dialogs/findfiles/window.h | 2 +- .../widgets/dialogs/licensewizard/licensewizard.h | 12 +-- examples/widgets/dialogs/standarddialogs/dialog.h | 2 +- examples/widgets/dialogs/tabdialog/tabdialog.h | 8 +- examples/widgets/effects/blurpicker/blurpicker.h | 2 +- examples/widgets/effects/fademessage/fademessage.h | 2 +- .../widgets/gestures/imagegestures/imagewidget.cpp | 28 +++---- .../widgets/gestures/imagegestures/imagewidget.h | 10 +-- examples/widgets/gestures/imagegestures/main.cpp | 2 +- .../widgets/gestures/imagegestures/mainwidget.cpp | 2 +- .../widgets/gestures/imagegestures/mainwidget.h | 4 +- .../widgets/graphicsview/collidingmice/mouse.cpp | 5 +- examples/widgets/itemviews/frozencolumn/main.cpp | 2 +- examples/widgets/itemviews/interview/model.cpp | 4 +- examples/widgets/itemviews/stardelegate/main.cpp | 9 ++- examples/widgets/painting/deform/pathdeform.cpp | 2 +- examples/widgets/painting/fontsampler/mainwindow.h | 2 +- examples/widgets/painting/gradients/gradients.cpp | 28 +++---- examples/widgets/painting/gradients/gradients.h | 2 +- examples/widgets/painting/gradients/main.cpp | 4 +- .../widgets/painting/painterpaths/renderarea.h | 2 +- .../widgets/painting/pathstroke/pathstroke.cpp | 87 +++++++++++++--------- examples/widgets/painting/pathstroke/pathstroke.h | 2 +- examples/widgets/painting/shared/arthurstyle.h | 2 +- examples/widgets/painting/shared/arthurwidgets.cpp | 4 +- .../widgets/painting/shared/fbopaintdevice.cpp | 6 +- examples/widgets/painting/shared/fbopaintdevice.h | 4 +- examples/widgets/painting/shared/hoverpoints.cpp | 4 +- .../widgets/painting/transformations/renderarea.h | 2 +- examples/widgets/scroller/graphicsview/main.cpp | 2 +- .../widgets/statemachine/eventtransitions/main.cpp | 9 ++- examples/widgets/statemachine/factorial/main.cpp | 9 +-- .../widgets/statemachine/trafficlight/main.cpp | 14 +++- examples/widgets/touch/fingerpaint/scribblearea.h | 2 +- examples/widgets/touch/pinchzoom/graphicsview.cpp | 6 +- examples/widgets/touch/pinchzoom/graphicsview.h | 4 +- examples/widgets/touch/pinchzoom/main.cpp | 7 +- examples/widgets/touch/pinchzoom/mouse.cpp | 10 +-- examples/widgets/touch/pinchzoom/mouse.h | 6 +- .../tutorials/addressbook/part1/addressbook.h | 2 +- .../tutorials/addressbook/part2/addressbook.h | 2 +- .../tutorials/addressbook/part3/addressbook.h | 2 +- .../tutorials/addressbook/part4/addressbook.h | 2 +- .../tutorials/addressbook/part5/addressbook.h | 2 +- .../tutorials/addressbook/part5/finddialog.h | 2 +- .../tutorials/addressbook/part6/addressbook.h | 2 +- .../tutorials/addressbook/part6/finddialog.h | 2 +- .../tutorials/addressbook/part7/addressbook.h | 2 +- .../tutorials/addressbook/part7/finddialog.h | 2 +- .../tutorials/modelview/3_changingmodel/main.cpp | 2 +- .../tutorials/modelview/7_selections/mainwindow.h | 2 +- examples/widgets/tutorials/notepad/notepad.h | 2 +- .../widgets/windowcontainer/windowcontainer.cpp | 53 +++++++------ 56 files changed, 216 insertions(+), 195 deletions(-) (limited to 'examples') diff --git a/examples/widgets/dialogs/classwizard/classwizard.cpp b/examples/widgets/dialogs/classwizard/classwizard.cpp index 81adf85b0d..8421289eab 100644 --- a/examples/widgets/dialogs/classwizard/classwizard.cpp +++ b/examples/widgets/dialogs/classwizard/classwizard.cpp @@ -118,9 +118,9 @@ void ClassWizard::accept() block += "public:\n"; if (field("qobjectCtor").toBool()) { - block += " " + className + "(QObject *parent = 0);\n"; + block += " " + className + "(QObject *parent = nullptr);\n"; } else if (field("qwidgetCtor").toBool()) { - block += " " + className + "(QWidget *parent = 0);\n"; + block += " " + className + "(QWidget *parent = nullptr);\n"; } else if (field("defaultCtor").toBool()) { block += " " + className + "();\n"; if (field("copyCtor").toBool()) { diff --git a/examples/widgets/dialogs/classwizard/classwizard.h b/examples/widgets/dialogs/classwizard/classwizard.h index fee0f6df66..0c386f0553 100644 --- a/examples/widgets/dialogs/classwizard/classwizard.h +++ b/examples/widgets/dialogs/classwizard/classwizard.h @@ -67,7 +67,7 @@ class ClassWizard : public QWizard Q_OBJECT public: - ClassWizard(QWidget *parent = 0); + ClassWizard(QWidget *parent = nullptr); void accept() override; }; @@ -79,7 +79,7 @@ class IntroPage : public QWizardPage Q_OBJECT public: - IntroPage(QWidget *parent = 0); + IntroPage(QWidget *parent = nullptr); private: QLabel *label; @@ -92,7 +92,7 @@ class ClassInfoPage : public QWizardPage Q_OBJECT public: - ClassInfoPage(QWidget *parent = 0); + ClassInfoPage(QWidget *parent = nullptr); private: QLabel *classNameLabel; @@ -114,7 +114,7 @@ class CodeStylePage : public QWizardPage Q_OBJECT public: - CodeStylePage(QWidget *parent = 0); + CodeStylePage(QWidget *parent = nullptr); protected: void initializePage() override; @@ -135,7 +135,7 @@ class OutputFilesPage : public QWizardPage Q_OBJECT public: - OutputFilesPage(QWidget *parent = 0); + OutputFilesPage(QWidget *parent = nullptr); protected: void initializePage() override; @@ -154,7 +154,7 @@ class ConclusionPage : public QWizardPage Q_OBJECT public: - ConclusionPage(QWidget *parent = 0); + ConclusionPage(QWidget *parent = nullptr); protected: void initializePage() override; diff --git a/examples/widgets/dialogs/extension/finddialog.h b/examples/widgets/dialogs/extension/finddialog.h index 858e1c929b..9b4b5b5f3d 100644 --- a/examples/widgets/dialogs/extension/finddialog.h +++ b/examples/widgets/dialogs/extension/finddialog.h @@ -68,7 +68,7 @@ class FindDialog : public QDialog Q_OBJECT public: - FindDialog(QWidget *parent = 0); + FindDialog(QWidget *parent = nullptr); private: QLabel *label; diff --git a/examples/widgets/dialogs/findfiles/window.h b/examples/widgets/dialogs/findfiles/window.h index 949df704bb..b74ba5e70c 100644 --- a/examples/widgets/dialogs/findfiles/window.h +++ b/examples/widgets/dialogs/findfiles/window.h @@ -68,7 +68,7 @@ class Window : public QWidget Q_OBJECT public: - Window(QWidget *parent = 0); + Window(QWidget *parent = nullptr); private slots: void browse(); diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.h b/examples/widgets/dialogs/licensewizard/licensewizard.h index c7709d88b3..e2890e484f 100644 --- a/examples/widgets/dialogs/licensewizard/licensewizard.h +++ b/examples/widgets/dialogs/licensewizard/licensewizard.h @@ -72,7 +72,7 @@ public: Page_Conclusion }; //! [2] - LicenseWizard(QWidget *parent = 0); + LicenseWizard(QWidget *parent = nullptr); private slots: void showHelp(); @@ -86,7 +86,7 @@ class IntroPage : public QWizardPage Q_OBJECT public: - IntroPage(QWidget *parent = 0); + IntroPage(QWidget *parent = nullptr); int nextId() const override; @@ -103,7 +103,7 @@ class EvaluatePage : public QWizardPage Q_OBJECT public: - EvaluatePage(QWidget *parent = 0); + EvaluatePage(QWidget *parent = nullptr); int nextId() const override; @@ -120,7 +120,7 @@ class RegisterPage : public QWizardPage Q_OBJECT public: - RegisterPage(QWidget *parent = 0); + RegisterPage(QWidget *parent = nullptr); int nextId() const override; @@ -136,7 +136,7 @@ class DetailsPage : public QWizardPage Q_OBJECT public: - DetailsPage(QWidget *parent = 0); + DetailsPage(QWidget *parent = nullptr); int nextId() const override; @@ -155,7 +155,7 @@ class ConclusionPage : public QWizardPage Q_OBJECT public: - ConclusionPage(QWidget *parent = 0); + ConclusionPage(QWidget *parent = nullptr); void initializePage() override; int nextId() const override; diff --git a/examples/widgets/dialogs/standarddialogs/dialog.h b/examples/widgets/dialogs/standarddialogs/dialog.h index 0d1c8d3e54..6d9cbdc07a 100644 --- a/examples/widgets/dialogs/standarddialogs/dialog.h +++ b/examples/widgets/dialogs/standarddialogs/dialog.h @@ -66,7 +66,7 @@ class Dialog : public QWidget Q_OBJECT public: - Dialog(QWidget *parent = 0); + Dialog(QWidget *parent = nullptr); private slots: void setInteger(); diff --git a/examples/widgets/dialogs/tabdialog/tabdialog.h b/examples/widgets/dialogs/tabdialog/tabdialog.h index 2db47c9ddd..b7c6c5b8da 100644 --- a/examples/widgets/dialogs/tabdialog/tabdialog.h +++ b/examples/widgets/dialogs/tabdialog/tabdialog.h @@ -65,7 +65,7 @@ class GeneralTab : public QWidget Q_OBJECT public: - explicit GeneralTab(const QFileInfo &fileInfo, QWidget *parent = 0); + explicit GeneralTab(const QFileInfo &fileInfo, QWidget *parent = nullptr); }; //! [0] @@ -76,7 +76,7 @@ class PermissionsTab : public QWidget Q_OBJECT public: - explicit PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = 0); + explicit PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = nullptr); }; //! [1] @@ -87,7 +87,7 @@ class ApplicationsTab : public QWidget Q_OBJECT public: - explicit ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = 0); + explicit ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = nullptr); }; //! [2] @@ -98,7 +98,7 @@ class TabDialog : public QDialog Q_OBJECT public: - explicit TabDialog(const QString &fileName, QWidget *parent = 0); + explicit TabDialog(const QString &fileName, QWidget *parent = nullptr); private: QTabWidget *tabWidget; diff --git a/examples/widgets/effects/blurpicker/blurpicker.h b/examples/widgets/effects/blurpicker/blurpicker.h index 3f444419a8..dc7fc4dabb 100644 --- a/examples/widgets/effects/blurpicker/blurpicker.h +++ b/examples/widgets/effects/blurpicker/blurpicker.h @@ -63,7 +63,7 @@ class BlurPicker: public QGraphicsView Q_PROPERTY(qreal index READ index WRITE setIndex) public: - BlurPicker(QWidget *parent = 0); + BlurPicker(QWidget *parent = nullptr); qreal index() const; void setIndex(qreal); diff --git a/examples/widgets/effects/fademessage/fademessage.h b/examples/widgets/effects/fademessage/fademessage.h index d17a1616ce..4d84c4ed21 100644 --- a/examples/widgets/effects/fademessage/fademessage.h +++ b/examples/widgets/effects/fademessage/fademessage.h @@ -62,7 +62,7 @@ class FadeMessage: public QGraphicsView Q_OBJECT public: - FadeMessage(QWidget *parent = 0); + FadeMessage(QWidget *parent = nullptr); private: void setupScene(); diff --git a/examples/widgets/gestures/imagegestures/imagewidget.cpp b/examples/widgets/gestures/imagegestures/imagewidget.cpp index 0a6b963559..fb5351f949 100644 --- a/examples/widgets/gestures/imagegestures/imagewidget.cpp +++ b/examples/widgets/gestures/imagegestures/imagewidget.cpp @@ -50,26 +50,23 @@ #include "imagewidget.h" -#include +#include +#include +#include +#include Q_LOGGING_CATEGORY(lcExample, "qt.examples.imagegestures") //! [constructor] ImageWidget::ImageWidget(QWidget *parent) - : QWidget(parent), - position(0), - horizontalOffset(0), - verticalOffset(0), - rotationAngle(0), - scaleFactor(1), - currentStepScaleFactor(1) - + : QWidget(parent), position(0), horizontalOffset(0), verticalOffset(0) + , rotationAngle(0), scaleFactor(1), currentStepScaleFactor(1) { - setMinimumSize(QSize(100,100)); + setMinimumSize(QSize(100, 100)); } //! [constructor] -void ImageWidget::grabGestures(const QList &gestures) +void ImageWidget::grabGestures(const QVector &gestures) { //! [enable gestures] for (Qt::GestureType gesture : gestures) @@ -96,11 +93,11 @@ void ImageWidget::paintEvent(QPaintEvent*) const qreal wh = height(); const qreal ww = width(); - p.translate(ww/2, wh/2); + p.translate(ww / 2, wh / 2); p.translate(horizontalOffset, verticalOffset); p.rotate(rotationAngle); p.scale(currentStepScaleFactor * scaleFactor, currentStepScaleFactor * scaleFactor); - p.translate(-iw/2, -ih/2); + p.translate(-iw / 2, -ih / 2); p.drawImage(0, 0, currentImage); } //! [paint method] @@ -198,8 +195,7 @@ void ImageWidget::openDirectory(const QString &path) { this->path = path; QDir dir(path); - QStringList nameFilters; - nameFilters << "*.jpg" << "*.png"; + const QStringList nameFilters{"*.jpg", "*.png"}; files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name); position = 0; @@ -207,7 +203,7 @@ void ImageWidget::openDirectory(const QString &path) update(); } -QImage ImageWidget::loadImage(const QString &fileName) +QImage ImageWidget::loadImage(const QString &fileName) const { QImageReader reader(fileName); reader.setAutoTransform(true); diff --git a/examples/widgets/gestures/imagegestures/imagewidget.h b/examples/widgets/gestures/imagegestures/imagewidget.h index 5e92541067..ae5eb7bc2b 100644 --- a/examples/widgets/gestures/imagegestures/imagewidget.h +++ b/examples/widgets/gestures/imagegestures/imagewidget.h @@ -51,9 +51,9 @@ #ifndef IMAGEWIDGET_H #define IMAGEWIDGET_H -#include #include -#include +#include +#include QT_BEGIN_NAMESPACE class QGestureEvent; @@ -70,9 +70,9 @@ class ImageWidget : public QWidget Q_OBJECT public: - ImageWidget(QWidget *parent = 0); + ImageWidget(QWidget *parent = nullptr); void openDirectory(const QString &path); - void grabGestures(const QList &gestures); + void grabGestures(const QVector &gestures); protected: bool event(QEvent *event) override; @@ -87,7 +87,7 @@ private: void swipeTriggered(QSwipeGesture*); //! [class definition begin] - QImage loadImage(const QString &fileName); + QImage loadImage(const QString &fileName) const; void loadImage(); void goNextImage(); void goPrevImage(); diff --git a/examples/widgets/gestures/imagegestures/main.cpp b/examples/widgets/gestures/imagegestures/main.cpp index ecd7462bd3..4f8d4ec15e 100644 --- a/examples/widgets/gestures/imagegestures/main.cpp +++ b/examples/widgets/gestures/imagegestures/main.cpp @@ -102,7 +102,7 @@ int main(int argc, char *argv[]) return -1; } - QList gestures; + QVector gestures; if (!commandLineParser.isSet(disablePanOption)) gestures << Qt::PanGesture; if (!commandLineParser.isSet(disablePinchOption)) diff --git a/examples/widgets/gestures/imagegestures/mainwidget.cpp b/examples/widgets/gestures/imagegestures/mainwidget.cpp index c4e63e9e7d..d1c786a93a 100644 --- a/examples/widgets/gestures/imagegestures/mainwidget.cpp +++ b/examples/widgets/gestures/imagegestures/mainwidget.cpp @@ -72,7 +72,7 @@ void MainWidget::openDirectory(const QString &path) imageWidget->openDirectory(path); } -void MainWidget::grabGestures(const QList &gestures) +void MainWidget::grabGestures(const QVector &gestures) { imageWidget->grabGestures(gestures); } diff --git a/examples/widgets/gestures/imagegestures/mainwidget.h b/examples/widgets/gestures/imagegestures/mainwidget.h index f3763ffffc..1600597251 100644 --- a/examples/widgets/gestures/imagegestures/mainwidget.h +++ b/examples/widgets/gestures/imagegestures/mainwidget.h @@ -60,8 +60,8 @@ class MainWidget : public QMainWindow Q_OBJECT public: - MainWidget(QWidget *parent = 0); - void grabGestures(const QList &gestures); + MainWidget(QWidget *parent = nullptr); + void grabGestures(const QVector &gestures); public slots: void openDirectory(const QString &path); diff --git a/examples/widgets/graphicsview/collidingmice/mouse.cpp b/examples/widgets/graphicsview/collidingmice/mouse.cpp index 556e58d19b..8375092c39 100644 --- a/examples/widgets/graphicsview/collidingmice/mouse.cpp +++ b/examples/widgets/graphicsview/collidingmice/mouse.cpp @@ -69,8 +69,9 @@ static qreal normalizeAngle(qreal angle) } //! [0] -Mouse::Mouse() - : color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)) +Mouse::Mouse() : color(QRandomGenerator::global()->bounded(256), + QRandomGenerator::global()->bounded(256), + QRandomGenerator::global()->bounded(256)) { setRotation(QRandomGenerator::global()->bounded(360 * 16)); } diff --git a/examples/widgets/itemviews/frozencolumn/main.cpp b/examples/widgets/itemviews/frozencolumn/main.cpp index 6f2b4a8d71..2965617ba1 100644 --- a/examples/widgets/itemviews/frozencolumn/main.cpp +++ b/examples/widgets/itemviews/frozencolumn/main.cpp @@ -71,7 +71,7 @@ int main(int argc, char* argv[]) model->setHorizontalHeaderLabels(list); int row = 0; - QStandardItem *newItem = 0; + QStandardItem *newItem = nullptr; while (!stream.atEnd()) { line = stream.readLine(); if (!line.startsWith('#') && line.contains(',')) { diff --git a/examples/widgets/itemviews/interview/model.cpp b/examples/widgets/itemviews/interview/model.cpp index feaf8bb98c..519164999d 100644 --- a/examples/widgets/itemviews/interview/model.cpp +++ b/examples/widgets/itemviews/interview/model.cpp @@ -132,7 +132,7 @@ bool Model::hasChildren(const QModelIndex &parent) const Qt::ItemFlags Model::flags(const QModelIndex &index) const { if (!index.isValid()) - return 0; + return {}; return Qt::ItemIsDragEnabled|QAbstractItemModel::flags(index); } @@ -146,7 +146,7 @@ Model::Node *Model::node(int row, Node *parent) const Model::Node *Model::parent(Node *child) const { - return child ? child->parent : 0; + return child ? child->parent : nullptr; } int Model::row(Node *node) const diff --git a/examples/widgets/itemviews/stardelegate/main.cpp b/examples/widgets/itemviews/stardelegate/main.cpp index 452976bba0..5ca85a6151 100644 --- a/examples/widgets/itemviews/stardelegate/main.cpp +++ b/examples/widgets/itemviews/stardelegate/main.cpp @@ -48,7 +48,8 @@ ** ****************************************************************************/ -#include +#include +#include #include "stardelegate.h" #include "stareditor.h" @@ -57,7 +58,7 @@ //! [0] void populateTableWidget(QTableWidget *tableWidget) { - static const struct { + static constexpr struct { const char *title; const char *genre; const char *artist; @@ -70,12 +71,12 @@ void populateTableWidget(QTableWidget *tableWidget) { "Sex Bomb", "Pop", "Tom Jones", 3 }, { "Barbie Girl", "Pop", "Aqua", 5 }, //! [2] - { 0, 0, 0, 0 } + { nullptr, nullptr, nullptr, 0 } //! [2] //! [3] }; //! [3] //! [4] - for (int row = 0; staticData[row].title != 0; ++row) { + for (int row = 0; staticData[row].title != nullptr; ++row) { QTableWidgetItem *item0 = new QTableWidgetItem(staticData[row].title); QTableWidgetItem *item1 = new QTableWidgetItem(staticData[row].genre); QTableWidgetItem *item2 = new QTableWidgetItem(staticData[row].artist); diff --git a/examples/widgets/painting/deform/pathdeform.cpp b/examples/widgets/painting/deform/pathdeform.cpp index 64e81f8cab..d5c8746247 100644 --- a/examples/widgets/painting/deform/pathdeform.cpp +++ b/examples/widgets/painting/deform/pathdeform.cpp @@ -262,7 +262,7 @@ PathDeformWidget::PathDeformWidget(QWidget *parent, bool smallScreen) QHBoxLayout *mainLayout = new QHBoxLayout(this); mainLayout->addWidget(m_renderer); - m_controls = new PathDeformControls(0, m_renderer, smallScreen); + m_controls = new PathDeformControls(nullptr, m_renderer, smallScreen); m_controls->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); if (!smallScreen) diff --git a/examples/widgets/painting/fontsampler/mainwindow.h b/examples/widgets/painting/fontsampler/mainwindow.h index ffb2839ffa..34e54440d4 100644 --- a/examples/widgets/painting/fontsampler/mainwindow.h +++ b/examples/widgets/painting/fontsampler/mainwindow.h @@ -70,7 +70,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindowBase Q_OBJECT public: - MainWindow(QWidget *parent = 0); + MainWindow(QWidget *parent = nullptr); public slots: void on_clearAction_triggered(); diff --git a/examples/widgets/painting/gradients/gradients.cpp b/examples/widgets/painting/gradients/gradients.cpp index a4528ce06f..d62ae93a15 100644 --- a/examples/widgets/painting/gradients/gradients.cpp +++ b/examples/widgets/painting/gradients/gradients.cpp @@ -102,9 +102,9 @@ uint ShadeWidget::colorAt(int x) generateShade(); QPolygonF pts = m_hoverPoints->points(); - for (int i=1; i < pts.size(); ++i) { - if (pts.at(i-1).x() <= x && pts.at(i).x() >= x) { - QLineF l(pts.at(i-1), pts.at(i)); + for (int i = 1; i < pts.size(); ++i) { + if (pts.at(i - 1).x() <= x && pts.at(i).x() >= x) { + QLineF l(pts.at(i - 1), pts.at(i)); l.setLength(l.length() * ((x - l.x1()) / l.dx())); return m_shade.pixel(qRound(qMin(l.x2(), (qreal(m_shade.width() - 1)))), qRound(qMin(l.y2(), qreal(m_shade.height() - 1)))); @@ -118,9 +118,9 @@ void ShadeWidget::setGradientStops(const QGradientStops &stops) if (m_shade_type == ARGBShade) { m_alpha_gradient = QLinearGradient(0, 0, width(), 0); - for (int i=0; icolorAt(int(x))) >> 16, - (0x0000ff00 & m_green_shade->colorAt(int(x))) >> 8, - (0x000000ff & m_blue_shade->colorAt(int(x))), - (0xff000000 & m_alpha_shade->colorAt(int(x))) >> 24); + QColor color((0x00ff0000 & m_red_shade->colorAt(x)) >> 16, + (0x0000ff00 & m_green_shade->colorAt(x)) >> 8, + (0x000000ff & m_blue_shade->colorAt(x)), + (0xff000000 & m_alpha_shade->colorAt(x)) >> 24); if (x / w > 1) return; @@ -568,8 +568,8 @@ void GradientRenderer::paint(QPainter *p) g = QConicalGradient(pts.at(0), angle); } - for (int i = 0; i < m_stops.size(); ++i) - g.setColorAt(m_stops.at(i).first, m_stops.at(i).second); + for (const auto &stop : qAsConst(m_stops)) + g.setColorAt(stop.first, stop.second); g.setSpread(m_spread); diff --git a/examples/widgets/painting/gradients/gradients.h b/examples/widgets/painting/gradients/gradients.h index c6525d18f8..45ef5d0f93 100644 --- a/examples/widgets/painting/gradients/gradients.h +++ b/examples/widgets/painting/gradients/gradients.h @@ -157,7 +157,7 @@ class GradientWidget : public QWidget Q_OBJECT public: - GradientWidget(QWidget *parent); + GradientWidget(QWidget *parent = nullptr); public slots: void setDefault1() { setDefault(1); } diff --git a/examples/widgets/painting/gradients/main.cpp b/examples/widgets/painting/gradients/main.cpp index 539d67e40e..0ddf7a4579 100644 --- a/examples/widgets/painting/gradients/main.cpp +++ b/examples/widgets/painting/gradients/main.cpp @@ -58,8 +58,8 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); - GradientWidget gradientWidget(0); - QStyle *arthurStyle = new ArthurStyle(); + GradientWidget gradientWidget; + QStyle *arthurStyle = new ArthurStyle; gradientWidget.setStyle(arthurStyle); const QList widgets = gradientWidget.findChildren(); for (QWidget *w : widgets) { diff --git a/examples/widgets/painting/painterpaths/renderarea.h b/examples/widgets/painting/painterpaths/renderarea.h index 5f0874b772..4b3ea5a397 100644 --- a/examples/widgets/painting/painterpaths/renderarea.h +++ b/examples/widgets/painting/painterpaths/renderarea.h @@ -60,7 +60,7 @@ class RenderArea : public QWidget Q_OBJECT public: - explicit RenderArea(const QPainterPath &path, QWidget *parent = 0); + explicit RenderArea(const QPainterPath &path, QWidget *parent = nullptr); QSize minimumSizeHint() const override; QSize sizeHint() const override; diff --git a/examples/widgets/painting/pathstroke/pathstroke.cpp b/examples/widgets/painting/pathstroke/pathstroke.cpp index e4009f0b1a..a850ce2672 100644 --- a/examples/widgets/painting/pathstroke/pathstroke.cpp +++ b/examples/widgets/painting/pathstroke/pathstroke.cpp @@ -48,11 +48,9 @@ ** ****************************************************************************/ +#include "pathstroke.h" #include "arthurstyle.h" #include "arthurwidgets.h" -#include "pathstroke.h" - -#include extern void draw_round_rect(QPainter *p, const QRect &bounds, int radius); @@ -164,24 +162,39 @@ void PathStrokeControls::createCommonControls(QWidget* parent) // Connections - connect(flatCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setFlatCap); - connect(squareCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSquareCap); - connect(roundCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setRoundCap); - - connect(bevelJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setBevelJoin); - connect(miterJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setMiterJoin); - connect(svgMiterJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSvgMiterJoin); - connect(roundJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setRoundJoin); - - connect(curveMode, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setCurveMode); - connect(lineMode, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setLineMode); - - connect(solidLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSolidLine); - connect(dashLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashLine); - connect(dotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDotLine); - connect(dashDotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashDotLine); - connect(dashDotDotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashDotDotLine); - connect(customDashLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setCustomDashLine); + connect(flatCap, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setFlatCap); + connect(squareCap, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setSquareCap); + connect(roundCap, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setRoundCap); + + connect(bevelJoin, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setBevelJoin); + connect(miterJoin, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setMiterJoin); + connect(svgMiterJoin, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setSvgMiterJoin); + connect(roundJoin, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setRoundJoin); + + connect(curveMode, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setCurveMode); + connect(lineMode, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setLineMode); + + connect(solidLine, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setSolidLine); + connect(dashLine, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setDashLine); + connect(dotLine, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setDotLine); + connect(dashDotLine, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setDashDotLine); + connect(dashDotDotLine, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setDashDotDotLine); + connect(customDashLine, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setCustomDashLine); // Set the defaults: flatCap->setChecked(true); @@ -247,15 +260,20 @@ void PathStrokeControls::layoutForDesktop() // Set up connections - connect(animated, &QAbstractButton::toggled, m_renderer, &PathStrokeRenderer::setAnimation); + connect(animated, &QAbstractButton::toggled, + m_renderer, &PathStrokeRenderer::setAnimation); - connect(penWidth, &QAbstractSlider::valueChanged, m_renderer, &PathStrokeRenderer::setPenWidth); + connect(penWidth, &QAbstractSlider::valueChanged, + m_renderer, &PathStrokeRenderer::setPenWidth); - connect(showSourceButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::showSource); + connect(showSourceButton, &QAbstractButton::clicked, + m_renderer, &ArthurFrame::showSource); #if QT_CONFIG(opengl) - connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL); + connect(enableOpenGLButton, &QAbstractButton::clicked, + m_renderer, &ArthurFrame::enableOpenGL); #endif - connect(whatsThisButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::setDescriptionEnabled); + connect(whatsThisButton, &QAbstractButton::clicked, + m_renderer, &ArthurFrame::setDescriptionEnabled); connect(m_renderer, &ArthurFrame::descriptionEnabledChanged, whatsThisButton, &QAbstractButton::setChecked); @@ -296,11 +314,11 @@ void PathStrokeControls::layoutForSmallScreens() #endif // Layouts: - QHBoxLayout *penWidthLayout = new QHBoxLayout(0); + QHBoxLayout *penWidthLayout = new QHBoxLayout; penWidthLayout->addWidget(penWidthLabel, 0, Qt::AlignRight); penWidthLayout->addWidget(penWidth); - QVBoxLayout *leftLayout = new QVBoxLayout(0); + QVBoxLayout *leftLayout = new QVBoxLayout; leftLayout->addWidget(m_capGroup); leftLayout->addWidget(m_joinGroup); #if QT_CONFIG(opengl) @@ -308,7 +326,7 @@ void PathStrokeControls::layoutForSmallScreens() #endif leftLayout->addLayout(penWidthLayout); - QVBoxLayout *rightLayout = new QVBoxLayout(0); + QVBoxLayout *rightLayout = new QVBoxLayout; rightLayout->addWidget(m_styleGroup); rightLayout->addWidget(m_pathModeGroup); @@ -356,7 +374,7 @@ PathStrokeWidget::PathStrokeWidget(bool smallScreen) // Widget construction and property setting m_renderer = new PathStrokeRenderer(this, smallScreen); - m_controls = new PathStrokeControls(0, m_renderer, smallScreen); + m_controls = new PathStrokeControls(nullptr, m_renderer, smallScreen); // Layouting QHBoxLayout *viewLayout = new QHBoxLayout(this); @@ -383,10 +401,10 @@ void PathStrokeWidget::hideControls() m_controls->hide(); } -void PathStrokeWidget::setStyle( QStyle * style ) +void PathStrokeWidget::setStyle(QStyle *style) { QWidget::setStyle(style); - if (m_controls != 0) + if (m_controls != nullptr) { m_controls->setStyle(style); @@ -516,7 +534,7 @@ void PathStrokeRenderer::updatePoints() qreal bottom = height() - pad; Q_ASSERT(m_points.size() == m_vectors.size()); - for (int i=0; ipos(), m_points.at(i)).length(); if ((distance < 0 && d < 8 * m_pointSize) || d < distance) { distance = d; @@ -673,7 +691,6 @@ bool PathStrokeRenderer::event(QEvent *e) m_fingerPointMapping.clear(); setAnimation(m_wasAnimated); return true; - break; default: break; } diff --git a/examples/widgets/painting/pathstroke/pathstroke.h b/examples/widgets/painting/pathstroke/pathstroke.h index 7bc7e09003..b559ed2ba0 100644 --- a/examples/widgets/painting/pathstroke/pathstroke.h +++ b/examples/widgets/painting/pathstroke/pathstroke.h @@ -169,7 +169,7 @@ class PathStrokeWidget : public QWidget public: PathStrokeWidget(bool smallScreen); - void setStyle ( QStyle * style ); + void setStyle(QStyle *style); private: PathStrokeRenderer *m_renderer; diff --git a/examples/widgets/painting/shared/arthurstyle.h b/examples/widgets/painting/shared/arthurstyle.h index 8ea8354bab..64c888b636 100644 --- a/examples/widgets/painting/shared/arthurstyle.h +++ b/examples/widgets/painting/shared/arthurstyle.h @@ -63,7 +63,7 @@ public: void drawHoverRect(QPainter *painter, const QRect &rect) const; void drawPrimitive(PrimitiveElement element, const QStyleOption *option, - QPainter *painter, const QWidget *widget = 0) const override; + QPainter *painter, const QWidget *widget = nullptr) const override; void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override; void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, diff --git a/examples/widgets/painting/shared/arthurwidgets.cpp b/examples/widgets/painting/shared/arthurwidgets.cpp index 285be99d20..40d712c9e3 100644 --- a/examples/widgets/painting/shared/arthurwidgets.cpp +++ b/examples/widgets/painting/shared/arthurwidgets.cpp @@ -136,7 +136,7 @@ void ArthurFrame::createGlWindow() void ArthurFrame::paintEvent(QPaintEvent *e) { - static QImage *static_image = 0; + static QImage *static_image = nullptr; QPainter painter; @@ -376,7 +376,7 @@ void ArthurFrame::showSource() const QString html = QStringLiteral("
") + contents + QStringLiteral("
"); - QTextBrowser *sourceViewer = new QTextBrowser(0); + QTextBrowser *sourceViewer = new QTextBrowser; sourceViewer->setWindowTitle(tr("Source: %1").arg(m_sourceFileName.midRef(5))); sourceViewer->setParent(this, Qt::Dialog); sourceViewer->setAttribute(Qt::WA_DeleteOnClose); diff --git a/examples/widgets/painting/shared/fbopaintdevice.cpp b/examples/widgets/painting/shared/fbopaintdevice.cpp index 8207090cc8..9368293218 100644 --- a/examples/widgets/painting/shared/fbopaintdevice.cpp +++ b/examples/widgets/painting/shared/fbopaintdevice.cpp @@ -53,7 +53,7 @@ #include #include -QFboPaintDevice::QFboPaintDevice(const QSize& size, bool flipped, bool clearOnInit, +QFboPaintDevice::QFboPaintDevice(const QSize &size, bool flipped, bool clearOnInit, QOpenGLFramebufferObject::Attachment attachment) : QOpenGLPaintDevice(size) { @@ -97,8 +97,8 @@ GLuint QFboPaintDevice::takeTexture() QImage QFboPaintDevice::toImage() const { - QOpenGLContext* currentContext = QOpenGLContext::currentContext(); - QSurface* currentSurface = currentContext ? currentContext->surface() : 0; + QOpenGLContext *currentContext = QOpenGLContext::currentContext(); + QSurface *currentSurface = currentContext ? currentContext->surface() : nullptr; context()->makeCurrent(m_surface); diff --git a/examples/widgets/painting/shared/fbopaintdevice.h b/examples/widgets/painting/shared/fbopaintdevice.h index 78451af895..a42bcc756d 100644 --- a/examples/widgets/painting/shared/fbopaintdevice.h +++ b/examples/widgets/painting/shared/fbopaintdevice.h @@ -60,7 +60,7 @@ class QFboPaintDevice : public QOpenGLPaintDevice { public: - QFboPaintDevice(const QSize&, bool flipped = false, bool clearOnInit = true, + QFboPaintDevice(const QSize &size, bool flipped = false, bool clearOnInit = true, QOpenGLFramebufferObject::Attachment = QOpenGLFramebufferObject::CombinedDepthStencil); ~QFboPaintDevice(); @@ -83,7 +83,7 @@ public: private: QOpenGLFramebufferObject *m_framebufferObject; - QSurface* m_surface; + QSurface *m_surface; }; #endif // QT_NO_OPENGL diff --git a/examples/widgets/painting/shared/hoverpoints.cpp b/examples/widgets/painting/shared/hoverpoints.cpp index 2032fb5a2c..2bf3963e9e 100644 --- a/examples/widgets/painting/shared/hoverpoints.cpp +++ b/examples/widgets/painting/shared/hoverpoints.cpp @@ -262,8 +262,8 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event) case QEvent::Paint: { QWidget *that_widget = m_widget; - m_widget = 0; - QApplication::sendEvent(object, event); + m_widget = nullptr; + QCoreApplication::sendEvent(object, event); m_widget = that_widget; paintPoints(); return true; diff --git a/examples/widgets/painting/transformations/renderarea.h b/examples/widgets/painting/transformations/renderarea.h index 140be27b2b..d4be7cefa4 100644 --- a/examples/widgets/painting/transformations/renderarea.h +++ b/examples/widgets/painting/transformations/renderarea.h @@ -70,7 +70,7 @@ class RenderArea : public QWidget Q_OBJECT public: - RenderArea(QWidget *parent = 0); + RenderArea(QWidget *parent = nullptr); void setOperations(const QList &operations); void setShape(const QPainterPath &shape); diff --git a/examples/widgets/scroller/graphicsview/main.cpp b/examples/widgets/scroller/graphicsview/main.cpp index d6b2956d50..178c431e6c 100644 --- a/examples/widgets/scroller/graphicsview/main.cpp +++ b/examples/widgets/scroller/graphicsview/main.cpp @@ -64,7 +64,7 @@ class RectObject : public QGraphicsObject public: - RectObject(const QString &text, qreal x, qreal y, qreal width, qreal height, QBrush brush, QGraphicsItem *parent = 0) + RectObject(const QString &text, qreal x, qreal y, qreal width, qreal height, QBrush brush, QGraphicsItem *parent = nullptr) : QGraphicsObject(parent) , m_text(text) , m_rect(x, y, width, height) diff --git a/examples/widgets/statemachine/eventtransitions/main.cpp b/examples/widgets/statemachine/eventtransitions/main.cpp index 2de8e5daa3..fe9518092f 100644 --- a/examples/widgets/statemachine/eventtransitions/main.cpp +++ b/examples/widgets/statemachine/eventtransitions/main.cpp @@ -48,13 +48,18 @@ ** ****************************************************************************/ -#include +#include +#include +#include +#include +#include +#include //! [0] class Window : public QWidget { public: - Window(QWidget *parent = 0) + Window(QWidget *parent = nullptr) : QWidget(parent) { QPushButton *button = new QPushButton(this); diff --git a/examples/widgets/statemachine/factorial/main.cpp b/examples/widgets/statemachine/factorial/main.cpp index e9431596fe..e6cbdcae29 100644 --- a/examples/widgets/statemachine/factorial/main.cpp +++ b/examples/widgets/statemachine/factorial/main.cpp @@ -57,10 +57,7 @@ class Factorial : public QObject Q_PROPERTY(int x READ x WRITE setX) Q_PROPERTY(int fac READ fac WRITE setFac) public: - Factorial(QObject *parent = 0) - : QObject(parent), m_x(-1), m_fac(1) - { - } + using QObject::QObject; int x() const { @@ -89,8 +86,8 @@ Q_SIGNALS: void xChanged(int value); private: - int m_x; - int m_fac; + int m_x = -1; + int m_fac = 1; }; //! [0] diff --git a/examples/widgets/statemachine/trafficlight/main.cpp b/examples/widgets/statemachine/trafficlight/main.cpp index a12d2f10d1..dd8bddcb37 100644 --- a/examples/widgets/statemachine/trafficlight/main.cpp +++ b/examples/widgets/statemachine/trafficlight/main.cpp @@ -48,7 +48,13 @@ ** ****************************************************************************/ -#include +#include +#include +#include +#include +#include +#include +#include //! [0] class LightWidget : public QWidget @@ -56,7 +62,7 @@ class LightWidget : public QWidget Q_OBJECT Q_PROPERTY(bool on READ isOn WRITE setOn) public: - LightWidget(const QColor &color, QWidget *parent = 0) + LightWidget(const QColor &color, QWidget *parent = nullptr) : QWidget(parent), m_color(color), m_on(false) {} bool isOn() const @@ -94,7 +100,7 @@ private: class TrafficLightWidget : public QWidget { public: - TrafficLightWidget(QWidget *parent = 0) + TrafficLightWidget(QWidget *parent = nullptr) : QWidget(parent) { QVBoxLayout *vbox = new QVBoxLayout(this); @@ -125,7 +131,7 @@ private: //! [1] //! [2] -QState *createLightState(LightWidget *light, int duration, QState *parent = 0) +QState *createLightState(LightWidget *light, int duration, QState *parent = nullptr) { QState *lightState = new QState(parent); QTimer *timer = new QTimer(lightState); diff --git a/examples/widgets/touch/fingerpaint/scribblearea.h b/examples/widgets/touch/fingerpaint/scribblearea.h index 5138e3a1ab..fcdde53cc4 100644 --- a/examples/widgets/touch/fingerpaint/scribblearea.h +++ b/examples/widgets/touch/fingerpaint/scribblearea.h @@ -62,7 +62,7 @@ class ScribbleArea : public QWidget Q_OBJECT public: - ScribbleArea(QWidget *parent = 0); + ScribbleArea(QWidget *parent = nullptr); bool openImage(const QString &fileName); bool saveImage(const QString &fileName, const char *fileFormat); diff --git a/examples/widgets/touch/pinchzoom/graphicsview.cpp b/examples/widgets/touch/pinchzoom/graphicsview.cpp index 54e134aea2..6412f350a7 100644 --- a/examples/widgets/touch/pinchzoom/graphicsview.cpp +++ b/examples/widgets/touch/pinchzoom/graphicsview.cpp @@ -54,7 +54,7 @@ #include GraphicsView::GraphicsView(QGraphicsScene *scene, QWidget *parent) - : QGraphicsView(scene, parent), totalScaleFactor(1) + : QGraphicsView(scene, parent) { viewport()->setAttribute(Qt::WA_AcceptTouchEvents); setDragMode(ScrollHandDrag); @@ -83,8 +83,8 @@ bool GraphicsView::viewportEvent(QEvent *event) totalScaleFactor *= currentScaleFactor; currentScaleFactor = 1; } - setTransform(QTransform().scale(totalScaleFactor * currentScaleFactor, - totalScaleFactor * currentScaleFactor)); + setTransform(QTransform::fromScale(totalScaleFactor * currentScaleFactor, + totalScaleFactor * currentScaleFactor)); } return true; } diff --git a/examples/widgets/touch/pinchzoom/graphicsview.h b/examples/widgets/touch/pinchzoom/graphicsview.h index d4e2e32d36..c0faeba444 100644 --- a/examples/widgets/touch/pinchzoom/graphicsview.h +++ b/examples/widgets/touch/pinchzoom/graphicsview.h @@ -56,10 +56,10 @@ class GraphicsView : public QGraphicsView Q_OBJECT public: - GraphicsView(QGraphicsScene *scene = 0, QWidget *parent = 0); + GraphicsView(QGraphicsScene *scene = nullptr, QWidget *parent = nullptr); bool viewportEvent(QEvent *event) override; private: - qreal totalScaleFactor; + qreal totalScaleFactor = 1; }; diff --git a/examples/widgets/touch/pinchzoom/main.cpp b/examples/widgets/touch/pinchzoom/main.cpp index 938432600f..2c2ba39a26 100644 --- a/examples/widgets/touch/pinchzoom/main.cpp +++ b/examples/widgets/touch/pinchzoom/main.cpp @@ -51,11 +51,10 @@ #include "graphicsview.h" #include "mouse.h" -#include +#include +#include -#include - -static const int MouseCount = 7; +static constexpr int MouseCount = 7; //! [0] int main(int argc, char **argv) diff --git a/examples/widgets/touch/pinchzoom/mouse.cpp b/examples/widgets/touch/pinchzoom/mouse.cpp index 1dfd7d749c..8456a0214d 100644 --- a/examples/widgets/touch/pinchzoom/mouse.cpp +++ b/examples/widgets/touch/pinchzoom/mouse.cpp @@ -56,8 +56,8 @@ #include #include -const qreal Pi = M_PI; -const qreal TwoPi = 2 * M_PI; +constexpr qreal Pi = M_PI; +constexpr qreal TwoPi = 2 * M_PI; static qreal normalizeAngle(qreal angle) { @@ -69,9 +69,9 @@ static qreal normalizeAngle(qreal angle) } //! [0] -Mouse::Mouse() - : angle(0), speed(0), mouseEyeDirection(0), - color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)) +Mouse::Mouse() : color(QRandomGenerator::global()->bounded(256), + QRandomGenerator::global()->bounded(256), + QRandomGenerator::global()->bounded(256)) { setTransform(QTransform().rotate(QRandomGenerator::global()->bounded(360 * 16)), true); startTimer(1000 / 33); diff --git a/examples/widgets/touch/pinchzoom/mouse.h b/examples/widgets/touch/pinchzoom/mouse.h index 870bfcd6c0..8ac110821e 100644 --- a/examples/widgets/touch/pinchzoom/mouse.h +++ b/examples/widgets/touch/pinchzoom/mouse.h @@ -70,9 +70,9 @@ protected: void timerEvent(QTimerEvent *event) override; private: - qreal angle; - qreal speed; - qreal mouseEyeDirection; + qreal angle = 0; + qreal speed = 0; + qreal mouseEyeDirection = 0; QColor color; }; //! [0] diff --git a/examples/widgets/tutorials/addressbook/part1/addressbook.h b/examples/widgets/tutorials/addressbook/part1/addressbook.h index 1d575e1260..4c2b456a41 100644 --- a/examples/widgets/tutorials/addressbook/part1/addressbook.h +++ b/examples/widgets/tutorials/addressbook/part1/addressbook.h @@ -65,7 +65,7 @@ class AddressBook : public QWidget Q_OBJECT public: - AddressBook(QWidget *parent = 0); + AddressBook(QWidget *parent = nullptr); private: QLineEdit *nameLine; diff --git a/examples/widgets/tutorials/addressbook/part2/addressbook.h b/examples/widgets/tutorials/addressbook/part2/addressbook.h index 7b1714b443..e690d14244 100644 --- a/examples/widgets/tutorials/addressbook/part2/addressbook.h +++ b/examples/widgets/tutorials/addressbook/part2/addressbook.h @@ -66,7 +66,7 @@ class AddressBook : public QWidget Q_OBJECT public: - AddressBook(QWidget *parent = 0); + AddressBook(QWidget *parent = nullptr); //! [slots] public slots: diff --git a/examples/widgets/tutorials/addressbook/part3/addressbook.h b/examples/widgets/tutorials/addressbook/part3/addressbook.h index 746a58a32a..f4a8aaa976 100644 --- a/examples/widgets/tutorials/addressbook/part3/addressbook.h +++ b/examples/widgets/tutorials/addressbook/part3/addressbook.h @@ -66,7 +66,7 @@ class AddressBook : public QWidget Q_OBJECT public: - AddressBook(QWidget *parent = 0); + AddressBook(QWidget *parent = nullptr); public slots: void addContact(); diff --git a/examples/widgets/tutorials/addressbook/part4/addressbook.h b/examples/widgets/tutorials/addressbook/part4/addressbook.h index a8d4d9fe1d..307df1eb15 100644 --- a/examples/widgets/tutorials/addressbook/part4/addressbook.h +++ b/examples/widgets/tutorials/addressbook/part4/addressbook.h @@ -66,7 +66,7 @@ class AddressBook : public QWidget Q_OBJECT public: - AddressBook(QWidget *parent = 0); + AddressBook(QWidget *parent = nullptr); //! [Mode enum] enum Mode { NavigationMode, AddingMode, EditingMode }; //! [Mode enum] diff --git a/examples/widgets/tutorials/addressbook/part5/addressbook.h b/examples/widgets/tutorials/addressbook/part5/addressbook.h index b60929a50c..9dd7ed1d89 100644 --- a/examples/widgets/tutorials/addressbook/part5/addressbook.h +++ b/examples/widgets/tutorials/addressbook/part5/addressbook.h @@ -69,7 +69,7 @@ class AddressBook : public QWidget Q_OBJECT public: - AddressBook(QWidget *parent = 0); + AddressBook(QWidget *parent = nullptr); enum Mode { NavigationMode, AddingMode, EditingMode }; public slots: diff --git a/examples/widgets/tutorials/addressbook/part5/finddialog.h b/examples/widgets/tutorials/addressbook/part5/finddialog.h index 0fca6be81b..8e63eeee79 100644 --- a/examples/widgets/tutorials/addressbook/part5/finddialog.h +++ b/examples/widgets/tutorials/addressbook/part5/finddialog.h @@ -63,7 +63,7 @@ class FindDialog : public QDialog Q_OBJECT public: - FindDialog(QWidget *parent = 0); + FindDialog(QWidget *parent = nullptr); QString getFindText(); public slots: diff --git a/examples/widgets/tutorials/addressbook/part6/addressbook.h b/examples/widgets/tutorials/addressbook/part6/addressbook.h index 8d328310f7..fca62c52b7 100644 --- a/examples/widgets/tutorials/addressbook/part6/addressbook.h +++ b/examples/widgets/tutorials/addressbook/part6/addressbook.h @@ -68,7 +68,7 @@ class AddressBook : public QWidget Q_OBJECT public: - AddressBook(QWidget *parent = 0); + AddressBook(QWidget *parent = nullptr); enum Mode { NavigationMode, AddingMode, EditingMode }; public slots: diff --git a/examples/widgets/tutorials/addressbook/part6/finddialog.h b/examples/widgets/tutorials/addressbook/part6/finddialog.h index 527e0254e9..46f8047a56 100644 --- a/examples/widgets/tutorials/addressbook/part6/finddialog.h +++ b/examples/widgets/tutorials/addressbook/part6/finddialog.h @@ -63,7 +63,7 @@ class FindDialog : public QDialog Q_OBJECT public: - FindDialog(QWidget *parent = 0); + FindDialog(QWidget *parent = nullptr); QString getFindText(); public slots: diff --git a/examples/widgets/tutorials/addressbook/part7/addressbook.h b/examples/widgets/tutorials/addressbook/part7/addressbook.h index 0f109b2ef1..47a0f3c062 100644 --- a/examples/widgets/tutorials/addressbook/part7/addressbook.h +++ b/examples/widgets/tutorials/addressbook/part7/addressbook.h @@ -68,7 +68,7 @@ class AddressBook : public QWidget Q_OBJECT public: - AddressBook(QWidget *parent = 0); + AddressBook(QWidget *parent = nullptr); enum Mode { NavigationMode, AddingMode, EditingMode }; public slots: diff --git a/examples/widgets/tutorials/addressbook/part7/finddialog.h b/examples/widgets/tutorials/addressbook/part7/finddialog.h index 527e0254e9..46f8047a56 100644 --- a/examples/widgets/tutorials/addressbook/part7/finddialog.h +++ b/examples/widgets/tutorials/addressbook/part7/finddialog.h @@ -63,7 +63,7 @@ class FindDialog : public QDialog Q_OBJECT public: - FindDialog(QWidget *parent = 0); + FindDialog(QWidget *parent = nullptr); QString getFindText(); public slots: diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp b/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp index 2330019f93..90a8c6e894 100644 --- a/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp +++ b/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); QTableView tableView; - MyModel myModel(0); + MyModel myModel; tableView.setModel(&myModel); tableView.show(); return a.exec(); diff --git a/examples/widgets/tutorials/modelview/7_selections/mainwindow.h b/examples/widgets/tutorials/modelview/7_selections/mainwindow.h index c9761dd3d9..74906c831d 100644 --- a/examples/widgets/tutorials/modelview/7_selections/mainwindow.h +++ b/examples/widgets/tutorials/modelview/7_selections/mainwindow.h @@ -69,7 +69,7 @@ private: private slots: void selectionChangedSlot(const QItemSelection &newSelection, const QItemSelection &oldSelection); public: - MainWindow(QWidget *parent = 0); + MainWindow(QWidget *parent = nullptr); }; #endif // MAINWINDOW_H diff --git a/examples/widgets/tutorials/notepad/notepad.h b/examples/widgets/tutorials/notepad/notepad.h index 9580ab8071..5e44dfeedc 100644 --- a/examples/widgets/tutorials/notepad/notepad.h +++ b/examples/widgets/tutorials/notepad/notepad.h @@ -72,7 +72,7 @@ class Notepad : public QMainWindow //! [4] public: - explicit Notepad(QWidget *parent = 0); + explicit Notepad(QWidget *parent = nullptr); //! [4] //! [5] ~Notepad(); diff --git a/examples/widgets/windowcontainer/windowcontainer.cpp b/examples/widgets/windowcontainer/windowcontainer.cpp index 9f2124c4e1..b920c85420 100644 --- a/examples/widgets/windowcontainer/windowcontainer.cpp +++ b/examples/widgets/windowcontainer/windowcontainer.cpp @@ -50,16 +50,14 @@ #include "openglwindow.h" -#include -#include -#include -#include - #include -#include +#include #include +#include #include - +#include +#include +#include // Making use of the class from the opengl example in gui. @@ -67,13 +65,10 @@ class Window : public OpenGLWindow { Q_OBJECT public: - Window() - : m_mouseDown(false) - , m_focus(false) - { - } + using OpenGLWindow::OpenGLWindow; - void render(QPainter *p) override { + void render(QPainter *p) override + { QLinearGradient g(0, 0, 0, height()); g.setColorAt(0, QColor("lightsteelblue")); g.setColorAt(1, Qt::black); @@ -93,15 +88,15 @@ public: p->restore(); } - if (m_focus) { + if (m_focus) p->drawText(20, height() - 20, QLatin1String("Window has focus!")); - } p->setRenderHint(QPainter::Antialiasing); p->drawPolyline(m_polygon); } - void mousePressEvent(QMouseEvent *e) override { + void mousePressEvent(QMouseEvent *e) override + { if (!m_mouseDown) { m_mouseDown = true; m_polygon.clear(); @@ -110,14 +105,16 @@ public: } } - void mouseMoveEvent(QMouseEvent *e) override { + void mouseMoveEvent(QMouseEvent *e) override + { if (m_mouseDown) { m_polygon.append(e->pos()); renderLater(); } } - void mouseReleaseEvent(QMouseEvent *e) override { + void mouseReleaseEvent(QMouseEvent *e) override + { if (m_mouseDown) { m_mouseDown = false; m_polygon.append(e->pos()); @@ -125,33 +122,35 @@ public: } } - void focusInEvent(QFocusEvent *) override { + void focusInEvent(QFocusEvent *) override + { m_focus = true; renderLater(); } - void focusOutEvent(QFocusEvent *) override { + void focusOutEvent(QFocusEvent *) override + { m_focus = false; m_polygon.clear(); renderLater(); } - void keyPressEvent(QKeyEvent *e) override { + void keyPressEvent(QKeyEvent *e) override + { m_key = e->text(); renderLater(); } - void keyReleaseEvent(QKeyEvent *) override { + void keyReleaseEvent(QKeyEvent *) override + { m_key = QString(); renderLater(); } private: QPolygon m_polygon; - bool m_mouseDown; - - bool m_focus; - QString m_key; + bool m_mouseDown = false; + bool m_focus = false; }; @@ -162,7 +161,7 @@ int main(int argc, char *argv[]) QWidget *widget = new QWidget; QHBoxLayout *layout = new QHBoxLayout(widget); - Window *window = new Window(); + Window *window = new Window; QWidget *container = QWidget::createWindowContainer(window); container->setMinimumSize(300, 300); -- cgit v1.2.3