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 --- 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 +++--- 6 files changed, 17 insertions(+), 18 deletions(-) (limited to 'examples/widgets/touch') 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] -- cgit v1.2.3