diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp | 29 | ||||
-rw-r--r-- | examples/corelib/threads/mandelbrot/renderthread.cpp | 27 | ||||
-rw-r--r-- | examples/corelib/threads/mandelbrot/renderthread.h | 6 | ||||
-rw-r--r-- | examples/opengl/paintedwindow/paintedwindow.cpp | 1 | ||||
-rw-r--r-- | examples/opengl/qopenglwindow/main.cpp | 1 | ||||
-rw-r--r-- | examples/qpa/qrasterwindow/main.cpp | 1 | ||||
-rw-r--r-- | examples/sql/doc/src/drilldown.qdoc | 3 | ||||
-rw-r--r-- | examples/sql/drilldown/imageitem.h | 3 | ||||
-rw-r--r-- | examples/widgets/painting/basicdrawing/renderarea.cpp | 1 | ||||
-rw-r--r-- | examples/widgets/widgets/styles/norwegianwoodstyle.cpp | 1 |
10 files changed, 40 insertions, 33 deletions
diff --git a/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp b/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp index 822791533b..420fd6186a 100644 --- a/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp +++ b/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp @@ -56,29 +56,28 @@ #include <math.h> //! [0] -const double DefaultCenterX = -0.637011f; -const double DefaultCenterY = -0.0395159f; -const double DefaultScale = 0.00403897f; +const double DefaultCenterX = -0.637011; +const double DefaultCenterY = -0.0395159; +const double DefaultScale = 0.00403897; -const double ZoomInFactor = 0.8f; +const double ZoomInFactor = 0.8; const double ZoomOutFactor = 1 / ZoomInFactor; const int ScrollStep = 20; //! [0] //! [1] -MandelbrotWidget::MandelbrotWidget(QWidget *parent) - : QWidget(parent) +MandelbrotWidget::MandelbrotWidget(QWidget *parent) : + QWidget(parent), + centerX(DefaultCenterX), + centerY(DefaultCenterY), + pixmapScale(DefaultScale), + curScale(DefaultScale) { - centerX = DefaultCenterX; - centerY = DefaultCenterY; - pixmapScale = DefaultScale; - curScale = DefaultScale; - connect(&thread, &RenderThread::renderedImage, this, &MandelbrotWidget::updatePixmap); setWindowTitle(tr("Mandelbrot")); -#ifndef QT_NO_CURSOR +#if QT_CONFIG(cursor) setCursor(Qt::CrossCursor); #endif resize(550, 400); @@ -102,7 +101,7 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */) //! [4] //! [5] - if (curScale == pixmapScale) { + if (qFuzzyCompare(curScale, pixmapScale)) { //! [5] //! [6] painter.drawPixmap(pixmapOffset, pixmap); //! [6] //! [7] @@ -176,8 +175,8 @@ void MandelbrotWidget::keyPressEvent(QKeyEvent *event) //! [12] void MandelbrotWidget::wheelEvent(QWheelEvent *event) { - int numDegrees = event->angleDelta().y() / 8; - double numSteps = numDegrees / 15.0f; + const int numDegrees = event->angleDelta().y() / 8; + const double numSteps = numDegrees / double(15); zoom(pow(ZoomInFactor, numSteps)); } //! [12] diff --git a/examples/corelib/threads/mandelbrot/renderthread.cpp b/examples/corelib/threads/mandelbrot/renderthread.cpp index eee44c7242..22ce81c32d 100644 --- a/examples/corelib/threads/mandelbrot/renderthread.cpp +++ b/examples/corelib/threads/mandelbrot/renderthread.cpp @@ -57,9 +57,6 @@ RenderThread::RenderThread(QObject *parent) : QThread(parent) { - restart = false; - abort = false; - for (int i = 0; i < ColormapSize; ++i) colormap[i] = rgbFromWaveLength(380.0 + (i * 400.0 / ColormapSize)); } @@ -102,10 +99,10 @@ void RenderThread::run() { forever { mutex.lock(); - QSize resultSize = this->resultSize; - double scaleFactor = this->scaleFactor; - double centerX = this->centerX; - double centerY = this->centerY; + const QSize resultSize = this->resultSize; + const double scaleFactor = this->scaleFactor; + const double centerX = this->centerX; + const double centerY = this->centerY; mutex.unlock(); //! [3] @@ -128,20 +125,20 @@ void RenderThread::run() if (abort) return; - uint *scanLine = + auto scanLine = reinterpret_cast<uint *>(image.scanLine(y + halfHeight)); - double ay = centerY + (y * scaleFactor); + const double ay = centerY + (y * scaleFactor); for (int x = -halfWidth; x < halfWidth; ++x) { - double ax = centerX + (x * scaleFactor); + const double ax = centerX + (x * scaleFactor); double a1 = ax; double b1 = ay; int numIterations = 0; do { ++numIterations; - double a2 = (a1 * a1) - (b1 * b1) + ax; - double b2 = (2 * a1 * b1) + ay; + const double a2 = (a1 * a1) - (b1 * b1) + ax; + const double b2 = (2 * a1 * b1) + ay; if ((a2 * a2) + (b2 * b2) > Limit) break; @@ -187,9 +184,9 @@ void RenderThread::run() //! [10] uint RenderThread::rgbFromWaveLength(double wave) { - double r = 0.0; - double g = 0.0; - double b = 0.0; + double r = 0; + double g = 0; + double b = 0; if (wave >= 380.0 && wave <= 440.0) { r = -1.0 * (wave - 440.0) / (440.0 - 380.0); diff --git a/examples/corelib/threads/mandelbrot/renderthread.h b/examples/corelib/threads/mandelbrot/renderthread.h index 4f0394d554..934cc17d74 100644 --- a/examples/corelib/threads/mandelbrot/renderthread.h +++ b/examples/corelib/threads/mandelbrot/renderthread.h @@ -78,7 +78,7 @@ protected: void run() override; private: - uint rgbFromWaveLength(double wave); + static uint rgbFromWaveLength(double wave); QMutex mutex; QWaitCondition condition; @@ -86,8 +86,8 @@ private: double centerY; double scaleFactor; QSize resultSize; - bool restart; - bool abort; + bool restart = false; + bool abort = false; enum { ColormapSize = 512 }; uint colormap[ColormapSize]; diff --git a/examples/opengl/paintedwindow/paintedwindow.cpp b/examples/opengl/paintedwindow/paintedwindow.cpp index 799431a765..94aa215288 100644 --- a/examples/opengl/paintedwindow/paintedwindow.cpp +++ b/examples/opengl/paintedwindow/paintedwindow.cpp @@ -54,6 +54,7 @@ #include <QOpenGLContext> #include <QOpenGLPaintDevice> #include <QPainter> +#include <QPainterPath> #include <QScreen> #include <QTimer> diff --git a/examples/opengl/qopenglwindow/main.cpp b/examples/opengl/qopenglwindow/main.cpp index 8932269ddf..7ce4dd0977 100644 --- a/examples/opengl/qopenglwindow/main.cpp +++ b/examples/opengl/qopenglwindow/main.cpp @@ -51,6 +51,7 @@ #include <QOpenGLWindow> #include <QScreen> #include <QPainter> +#include <QPainterPath> #include <QGuiApplication> #include <QMatrix4x4> #include <QStaticText> diff --git a/examples/qpa/qrasterwindow/main.cpp b/examples/qpa/qrasterwindow/main.cpp index 958da2205a..699c950c27 100644 --- a/examples/qpa/qrasterwindow/main.cpp +++ b/examples/qpa/qrasterwindow/main.cpp @@ -50,6 +50,7 @@ #include <QRasterWindow> #include <QPainter> +#include <QPainterPath> #include <QGuiApplication> #include <QMatrix4x4> #include <QTimer> diff --git a/examples/sql/doc/src/drilldown.qdoc b/examples/sql/doc/src/drilldown.qdoc index 8beb515a83..a7a9601c26 100644 --- a/examples/sql/doc/src/drilldown.qdoc +++ b/examples/sql/doc/src/drilldown.qdoc @@ -437,6 +437,9 @@ \snippet drilldown/imageitem.h 0 + We declare a \c Type enum value for our custom item and reimplement + \l{QGreaphicsItem::}{type()}. This is done so we can safely use + qgraphicsitem_cast(). In addition, we implement a public \c id() function to be able to identify the associated location and a public \c adjust() function that can be called to ensure that the image item is given the diff --git a/examples/sql/drilldown/imageitem.h b/examples/sql/drilldown/imageitem.h index abb9103c7e..324c847b12 100644 --- a/examples/sql/drilldown/imageitem.h +++ b/examples/sql/drilldown/imageitem.h @@ -60,8 +60,11 @@ class ImageItem : public QObject, public QGraphicsPixmapItem Q_OBJECT public: + enum { Type = UserType + 1 }; + ImageItem(int id, const QPixmap &pixmap, QGraphicsItem *parent = nullptr); + int type() const override { return Type; } void adjust(); int id() const; diff --git a/examples/widgets/painting/basicdrawing/renderarea.cpp b/examples/widgets/painting/basicdrawing/renderarea.cpp index a1437dea8f..09d610ee95 100644 --- a/examples/widgets/painting/basicdrawing/renderarea.cpp +++ b/examples/widgets/painting/basicdrawing/renderarea.cpp @@ -51,6 +51,7 @@ #include "renderarea.h" #include <QPainter> +#include <QPainterPath> //! [0] RenderArea::RenderArea(QWidget *parent) diff --git a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp index 31150cd994..34a63e0eea 100644 --- a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp +++ b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp @@ -52,6 +52,7 @@ #include <QComboBox> #include <QPainter> +#include <QPainterPath> #include <QPushButton> #include <QStyleFactory> |