diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-09-13 20:43:09 +0200 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2019-09-30 22:16:27 +0200 |
commit | b0042601ed8056c9ed6056c26f71dfa9fbc951ce (patch) | |
tree | 9288bbda958a9e0755d3179de0fe5325d9bd7898 /examples/gui/openglwindow | |
parent | fbda189e081e6c7abf82334c0ac71b16ec2c37dd (diff) |
Cleanup QtOpenGL examples
Cleanup the OpenGL examples
- use nullptr (clang-tidy)
- use member-initialization
- avoid redundant checks for != nullptr when deleting a pointer
Change-Id: I3e4702690ed79e71c3e952d51ceef83b907b45b7
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'examples/gui/openglwindow')
-rw-r--r-- | examples/gui/openglwindow/main.cpp | 30 | ||||
-rw-r--r-- | examples/gui/openglwindow/openglwindow.cpp | 11 | ||||
-rw-r--r-- | examples/gui/openglwindow/openglwindow.h | 12 |
3 files changed, 21 insertions, 32 deletions
diff --git a/examples/gui/openglwindow/main.cpp b/examples/gui/openglwindow/main.cpp index 90c93f0d37..d1e5d3871e 100644 --- a/examples/gui/openglwindow/main.cpp +++ b/examples/gui/openglwindow/main.cpp @@ -50,36 +50,30 @@ #include "openglwindow.h" -#include <QtGui/QGuiApplication> -#include <QtGui/QMatrix4x4> -#include <QtGui/QOpenGLShaderProgram> -#include <QtGui/QScreen> +#include <QGuiApplication> +#include <QMatrix4x4> +#include <QOpenGLShaderProgram> +#include <QScreen> +#include <QtMath> -#include <QtCore/qmath.h> //! [1] class TriangleWindow : public OpenGLWindow { public: - TriangleWindow(); + using OpenGLWindow::OpenGLWindow; void initialize() override; void render() override; private: - GLuint m_posAttr; - GLuint m_colAttr; - GLuint m_matrixUniform; + GLuint m_posAttr = 0; + GLuint m_colAttr = 0; + GLuint m_matrixUniform = 0; - QOpenGLShaderProgram *m_program; - int m_frame; + QOpenGLShaderProgram *m_program = nullptr; + int m_frame = 0; }; - -TriangleWindow::TriangleWindow() - : m_program(0) - , m_frame(0) -{ -} //! [1] //! [2] @@ -144,7 +138,7 @@ void TriangleWindow::render() m_program->bind(); QMatrix4x4 matrix; - matrix.perspective(60.0f, 4.0f/3.0f, 0.1f, 100.0f); + matrix.perspective(60.0f, 4.0f / 3.0f, 0.1f, 100.0f); matrix.translate(0, 0, -2); matrix.rotate(100.0f * m_frame / screen()->refreshRate(), 0, 1, 0); diff --git a/examples/gui/openglwindow/openglwindow.cpp b/examples/gui/openglwindow/openglwindow.cpp index a0c85006bd..bac887dca0 100644 --- a/examples/gui/openglwindow/openglwindow.cpp +++ b/examples/gui/openglwindow/openglwindow.cpp @@ -50,18 +50,13 @@ #include "openglwindow.h" -#include <QtCore/QCoreApplication> - -#include <QtGui/QOpenGLContext> -#include <QtGui/QOpenGLPaintDevice> -#include <QtGui/QPainter> +#include <QOpenGLContext> +#include <QOpenGLPaintDevice> +#include <QPainter> //! [1] OpenGLWindow::OpenGLWindow(QWindow *parent) : QWindow(parent) - , m_animating(false) - , m_context(0) - , m_device(0) { setSurfaceType(QWindow::OpenGLSurface); } diff --git a/examples/gui/openglwindow/openglwindow.h b/examples/gui/openglwindow/openglwindow.h index 6e6c1d7449..8db943ddde 100644 --- a/examples/gui/openglwindow/openglwindow.h +++ b/examples/gui/openglwindow/openglwindow.h @@ -48,8 +48,8 @@ ** ****************************************************************************/ -#include <QtGui/QWindow> -#include <QtGui/QOpenGLFunctions> +#include <QWindow> +#include <QOpenGLFunctions> QT_BEGIN_NAMESPACE class QPainter; @@ -62,7 +62,7 @@ class OpenGLWindow : public QWindow, protected QOpenGLFunctions { Q_OBJECT public: - explicit OpenGLWindow(QWindow *parent = 0); + explicit OpenGLWindow(QWindow *parent = nullptr); ~OpenGLWindow(); virtual void render(QPainter *painter); @@ -82,10 +82,10 @@ protected: void exposeEvent(QExposeEvent *event) override; private: - bool m_animating; + bool m_animating = false; - QOpenGLContext *m_context; - QOpenGLPaintDevice *m_device; + QOpenGLContext *m_context = nullptr; + QOpenGLPaintDevice *m_device = nullptr; }; //! [1] |