diff options
Diffstat (limited to 'examples/widgets/graphicsview/boxes')
-rw-r--r-- | examples/widgets/graphicsview/boxes/glbuffers.cpp | 23 | ||||
-rw-r--r-- | examples/widgets/graphicsview/boxes/glbuffers.h | 37 | ||||
-rw-r--r-- | examples/widgets/graphicsview/boxes/gltrianglemesh.h | 3 | ||||
-rw-r--r-- | examples/widgets/graphicsview/boxes/main.cpp | 12 | ||||
-rw-r--r-- | examples/widgets/graphicsview/boxes/qtbox.cpp | 39 | ||||
-rw-r--r-- | examples/widgets/graphicsview/boxes/qtbox.h | 11 | ||||
-rw-r--r-- | examples/widgets/graphicsview/boxes/roundedbox.h | 12 | ||||
-rw-r--r-- | examples/widgets/graphicsview/boxes/scene.cpp | 78 | ||||
-rw-r--r-- | examples/widgets/graphicsview/boxes/scene.h | 23 | ||||
-rw-r--r-- | examples/widgets/graphicsview/boxes/trackball.cpp | 17 | ||||
-rw-r--r-- | examples/widgets/graphicsview/boxes/trackball.h | 25 |
11 files changed, 95 insertions, 185 deletions
diff --git a/examples/widgets/graphicsview/boxes/glbuffers.cpp b/examples/widgets/graphicsview/boxes/glbuffers.cpp index b52b26c4ef..91de336af3 100644 --- a/examples/widgets/graphicsview/boxes/glbuffers.cpp +++ b/examples/widgets/graphicsview/boxes/glbuffers.cpp @@ -49,8 +49,6 @@ ****************************************************************************/ #include "glbuffers.h" -#include <QtGui/qmatrix4x4.h> -#include <QtCore/qmath.h> void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) { @@ -65,7 +63,7 @@ void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zF // GLTexture // //============================================================================// -GLTexture::GLTexture() : m_texture(0), m_failed(false) +GLTexture::GLTexture() { glGenTextures(1, &m_texture); } @@ -83,7 +81,7 @@ GLTexture2D::GLTexture2D(int width, int height) { glBindTexture(GL_TEXTURE_2D, m_texture); glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, - GL_BGRA, GL_UNSIGNED_BYTE, 0); + GL_BGRA, GL_UNSIGNED_BYTE, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); @@ -95,7 +93,7 @@ GLTexture2D::GLTexture2D(int width, int height) } -GLTexture2D::GLTexture2D(const QString& fileName, int width, int height) +GLTexture2D::GLTexture2D(const QString &fileName, int width, int height) { // TODO: Add error handling. QImage image(fileName); @@ -162,7 +160,7 @@ GLTexture3D::GLTexture3D(int width, int height, int depth) glBindTexture(GL_TEXTURE_3D, m_texture); glTexImage3D(GL_TEXTURE_3D, 0, 4, width, height, depth, 0, - GL_BGRA, GL_UNSIGNED_BYTE, 0); + GL_BGRA, GL_UNSIGNED_BYTE, nullptr); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); @@ -206,7 +204,7 @@ GLTextureCube::GLTextureCube(int size) for (int i = 0; i < 6; ++i) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 4, size, size, 0, - GL_BGRA, GL_UNSIGNED_BYTE, 0); + GL_BGRA, GL_UNSIGNED_BYTE, nullptr); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); @@ -252,7 +250,7 @@ GLTextureCube::GLTextureCube(const QStringList &fileNames, int size) // Clear remaining faces. while (index < 6) { glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, 4, size, size, 0, - GL_BGRA, GL_UNSIGNED_BYTE, 0); + GL_BGRA, GL_UNSIGNED_BYTE, nullptr); ++index; } @@ -291,11 +289,8 @@ void GLTextureCube::unbind() //============================================================================// GLFrameBufferObject::GLFrameBufferObject(int width, int height) - : m_fbo(0) - , m_depthBuffer(0) - , m_width(width) + : m_width(width) , m_height(height) - , m_failed(false) { GLBUFFERS_ASSERT_OPENGL("GLFrameBufferObject::GLFrameBufferObject", glGenFramebuffersEXT && glGenRenderbuffersEXT && glBindRenderbufferEXT && glRenderbufferStorageEXT, return) @@ -373,7 +368,7 @@ void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face) return; } - static int perm[6][3] = { + static constexpr int perm[6][3] = { {2, 1, 0}, {2, 1, 0}, {0, 2, 1}, @@ -382,7 +377,7 @@ void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face) {0, 1, 2}, }; - static float signs[6][3] = { + static constexpr float signs[6][3] = { {-1.0f, -1.0f, -1.0f}, {+1.0f, -1.0f, +1.0f}, {+1.0f, +1.0f, -1.0f}, diff --git a/examples/widgets/graphicsview/boxes/glbuffers.h b/examples/widgets/graphicsview/boxes/glbuffers.h index e2363d561e..4318e8ac24 100644 --- a/examples/widgets/graphicsview/boxes/glbuffers.h +++ b/examples/widgets/graphicsview/boxes/glbuffers.h @@ -58,7 +58,7 @@ #include <QtOpenGL> #define BUFFER_OFFSET(i) ((char*)0 + (i)) -#define SIZE_OF_MEMBER(cls, member) sizeof(static_cast<cls *>(0)->member) +#define SIZE_OF_MEMBER(cls, member) sizeof(static_cast<cls *>(nullptr)->member) #define GLBUFFERS_ASSERT_OPENGL(prefix, assertion, returnStatement) \ if (m_failed || !(assertion)) { \ @@ -82,8 +82,8 @@ public: virtual void unbind() = 0; virtual bool failed() const {return m_failed;} protected: - GLuint m_texture; - bool m_failed; + GLuint m_texture = 0; + bool m_failed = false; }; class GLFrameBufferObject @@ -98,17 +98,17 @@ public: virtual bool failed() const {return m_failed;} protected: void setAsRenderTarget(bool state = true); - GLuint m_fbo; - GLuint m_depthBuffer; + GLuint m_fbo = 0; + GLuint m_depthBuffer = 0; int m_width, m_height; - bool m_failed; + bool m_failed = false; }; class GLTexture2D : public GLTexture { public: GLTexture2D(int width, int height); - explicit GLTexture2D(const QString& fileName, int width = 0, int height = 0); + explicit GLTexture2D(const QString &fileName, int width = 0, int height = 0); void load(int width, int height, QRgb *data); void bind() override; void unbind() override; @@ -197,11 +197,7 @@ template<class T> class GLVertexBuffer { public: - GLVertexBuffer(int length, const T *data = 0, int mode = GL_STATIC_DRAW) - : m_length(0) - , m_mode(mode) - , m_buffer(0) - , m_failed(false) + GLVertexBuffer(int length, const T *data = nullptr, int mode = GL_STATIC_DRAW) { GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::GLVertexBuffer", glGenBuffers && glBindBuffer && glBufferData, return) @@ -275,12 +271,12 @@ public: T *lock() { - GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::lock", glBindBuffer && glMapBuffer, return 0) + GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::lock", glBindBuffer && glMapBuffer, return nullptr) glBindBuffer(GL_ARRAY_BUFFER, m_buffer); //glBufferData(GL_ARRAY_BUFFER, m_length, NULL, m_mode); GLvoid* buffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); - m_failed = (buffer == 0); + m_failed = (buffer == nullptr); return reinterpret_cast<T *>(buffer); } @@ -298,16 +294,17 @@ public: } private: - int m_length, m_mode; - GLuint m_buffer; - bool m_failed; + int m_length = 0; + int m_mode = 0; + GLuint m_buffer = 0; + bool m_failed = false; }; template<class T> class GLIndexBuffer { public: - GLIndexBuffer(int length, const T *data = 0, int mode = GL_STATIC_DRAW) + GLIndexBuffer(int length, const T *data = nullptr, int mode = GL_STATIC_DRAW) : m_length(0) , m_mode(mode) , m_buffer(0) @@ -345,11 +342,11 @@ public: T *lock() { - GLBUFFERS_ASSERT_OPENGL("GLIndexBuffer::lock", glBindBuffer && glMapBuffer, return 0) + GLBUFFERS_ASSERT_OPENGL("GLIndexBuffer::lock", glBindBuffer && glMapBuffer, return nullptr) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_buffer); GLvoid* buffer = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_READ_WRITE); - m_failed = (buffer == 0); + m_failed = (buffer == nullptr); return reinterpret_cast<T *>(buffer); } diff --git a/examples/widgets/graphicsview/boxes/gltrianglemesh.h b/examples/widgets/graphicsview/boxes/gltrianglemesh.h index 716c4de62e..e5c4f51514 100644 --- a/examples/widgets/graphicsview/boxes/gltrianglemesh.h +++ b/examples/widgets/graphicsview/boxes/gltrianglemesh.h @@ -51,13 +51,12 @@ #ifndef GLTRIANGLEMESH_H #define GLTRIANGLEMESH_H -//#include <GL/glew.h> +#include "glbuffers.h" #include "glextensions.h" #include <QtWidgets> #include <QtOpenGL> -#include "glbuffers.h" template<class TVertex, class TIndex> class GLTriangleMesh diff --git a/examples/widgets/graphicsview/boxes/main.cpp b/examples/widgets/graphicsview/boxes/main.cpp index b7242d529b..2b3e6d3389 100644 --- a/examples/widgets/graphicsview/boxes/main.cpp +++ b/examples/widgets/graphicsview/boxes/main.cpp @@ -48,13 +48,11 @@ ** ****************************************************************************/ -//#include <GL/glew.h> #include "glextensions.h" - #include "scene.h" -#include <QtWidgets> #include <QGLWidget> +#include <QtWidgets> class GraphicsView : public QGraphicsView { @@ -114,7 +112,7 @@ int main(int argc, char **argv) QApplication app(argc, argv); if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_5) == 0) { - QMessageBox::critical(0, "OpenGL features missing", + QMessageBox::critical(nullptr, "OpenGL features missing", "OpenGL version 1.5 or higher is required to run this demo.\n" "The program will now exit."); return -1; @@ -125,7 +123,7 @@ int main(int argc, char **argv) widget->makeCurrent(); if (!necessaryExtensionsSupported()) { - QMessageBox::critical(0, "OpenGL features missing", + QMessageBox::critical(nullptr, "OpenGL features missing", "The OpenGL extensions required to run this demo are missing.\n" "The program will now exit."); delete widget; @@ -134,7 +132,7 @@ int main(int argc, char **argv) // Check if all the necessary functions are resolved. if (!getGLExtensionFunctions().resolve(widget->context())) { - QMessageBox::critical(0, "OpenGL features missing", + QMessageBox::critical(nullptr, "OpenGL features missing", "Failed to resolve OpenGL functions required to run this demo.\n" "The program will now exit."); delete widget; @@ -142,7 +140,7 @@ int main(int argc, char **argv) } // TODO: Make conditional for final release - QMessageBox::information(0, "For your information", + QMessageBox::information(nullptr, "For your information", "This demo can be GPU and CPU intensive and may\n" "work poorly or not at all on your system."); diff --git a/examples/widgets/graphicsview/boxes/qtbox.cpp b/examples/widgets/graphicsview/boxes/qtbox.cpp index 68d5c251f4..8713aac05d 100644 --- a/examples/widgets/graphicsview/boxes/qtbox.cpp +++ b/examples/widgets/graphicsview/boxes/qtbox.cpp @@ -50,28 +50,23 @@ #include "qtbox.h" -const qreal ROTATE_SPEED_X = 30.0 / 1000.0; -const qreal ROTATE_SPEED_Y = 20.0 / 1000.0; -const qreal ROTATE_SPEED_Z = 40.0 / 1000.0; -const int MAX_ITEM_SIZE = 512; -const int MIN_ITEM_SIZE = 16; +constexpr qreal ROTATE_SPEED_X = 30.0 / 1000.0; +constexpr qreal ROTATE_SPEED_Y = 20.0 / 1000.0; +constexpr qreal ROTATE_SPEED_Z = 40.0 / 1000.0; +constexpr int MAX_ITEM_SIZE = 512; +constexpr int MIN_ITEM_SIZE = 16; //============================================================================// // ItemBase // //============================================================================// -ItemBase::ItemBase(int size, int x, int y) : m_size(size), m_isResizing(false) +ItemBase::ItemBase(int size, int x, int y) : m_size(size), m_startTime(QTime::currentTime()) { setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsFocusable, true); setAcceptHoverEvents(true); setPos(x, y); - m_startTime = QTime::currentTime(); -} - -ItemBase::~ItemBase() -{ } QRectF ItemBase::boundingRect() const @@ -252,10 +247,7 @@ void ItemBase::wheelEvent(QGraphicsSceneWheelEvent *event) { prepareGeometryChange(); m_size = int(m_size * qExp(-event->delta() / 600.0)); - if (m_size > MAX_ITEM_SIZE) - m_size = MAX_ITEM_SIZE; - else if (m_size < MIN_ITEM_SIZE) - m_size = MIN_ITEM_SIZE; + m_size = qBound(MIN_ITEM_SIZE, m_size, MAX_ITEM_SIZE); } int ItemBase::type() const @@ -273,7 +265,7 @@ bool ItemBase::isInResizeArea(const QPointF &pos) // QtBox // //============================================================================// -QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y), m_texture(0) +QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y) { for (int i = 0; i < 8; ++i) { m_vertices[i].setX(i & 1 ? 0.5f : -0.5f); @@ -294,8 +286,7 @@ QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y), m_texture(0) QtBox::~QtBox() { - if (m_texture) - delete m_texture; + delete m_texture; } ItemBase *QtBox::createNew(int size, int x, int y) @@ -337,7 +328,7 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi glEnable(GL_COLOR_MATERIAL); glEnable(GL_NORMALIZE); - if(m_texture == 0) + if (m_texture == nullptr) m_texture = new GLTexture2D(":/res/boxes/qt-logo.jpg", 64, 64); m_texture->bind(); glEnable(GL_TEXTURE_2D); @@ -405,9 +396,8 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi //============================================================================// CircleItem::CircleItem(int size, int x, int y) : ItemBase(size, x, y) -{ - m_color = QColor::fromHsv(QRandomGenerator::global()->bounded(360), 255, 255); -} + , m_color(QColor::fromHsv(QRandomGenerator::global()->bounded(360), 255, 255)) +{} void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { @@ -455,9 +445,8 @@ ItemBase *CircleItem::createNew(int size, int x, int y) //============================================================================// SquareItem::SquareItem(int size, int x, int y) : ItemBase(size, x, y) -{ - m_image = QPixmap(":/res/boxes/square.jpg"); -} + , m_image(QPixmap(":/res/boxes/square.jpg")) +{} void SquareItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { diff --git a/examples/widgets/graphicsview/boxes/qtbox.h b/examples/widgets/graphicsview/boxes/qtbox.h index f8ee9bdb0a..84c8cb1d93 100644 --- a/examples/widgets/graphicsview/boxes/qtbox.h +++ b/examples/widgets/graphicsview/boxes/qtbox.h @@ -51,18 +51,17 @@ #ifndef QTBOX_H #define QTBOX_H -#include <QtWidgets> - -#include <QtGui/qvector3d.h> #include "glbuffers.h" +#include <QtWidgets> +#include <QVector3D> + class ItemBase : public QGraphicsItem { public: enum { Type = UserType + 1 }; ItemBase(int size, int x, int y); - virtual ~ItemBase(); QRectF boundingRect() const override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; protected: @@ -84,7 +83,7 @@ protected: int m_size; QTime m_startTime; - bool m_isResizing; + bool m_isResizing = false; }; class QtBox : public ItemBase @@ -99,7 +98,7 @@ private: QVector3D m_vertices[8]; QVector3D m_texCoords[4]; QVector3D m_normals[6]; - GLTexture *m_texture; + GLTexture *m_texture = nullptr; }; class CircleItem : public ItemBase diff --git a/examples/widgets/graphicsview/boxes/roundedbox.h b/examples/widgets/graphicsview/boxes/roundedbox.h index ebc2dbd36e..a1f15cd631 100644 --- a/examples/widgets/graphicsview/boxes/roundedbox.h +++ b/examples/widgets/graphicsview/boxes/roundedbox.h @@ -51,16 +51,12 @@ #ifndef ROUNDEDBOX_H #define ROUNDEDBOX_H -//#include <GL/glew.h> +#include "glbuffers.h" #include "glextensions.h" - -#include <QtWidgets> -#include <QtOpenGL> - #include "gltrianglemesh.h" -#include <QtGui/qvector3d.h> -#include <QtGui/qvector2d.h> -#include "glbuffers.h" + +#include <QVector2D> +#include <QVector3D> struct P3T2N3Vertex { diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp index a9995efa27..b344f65561 100644 --- a/examples/widgets/graphicsview/boxes/scene.cpp +++ b/examples/widgets/graphicsview/boxes/scene.cpp @@ -48,45 +48,15 @@ ** ****************************************************************************/ -#include <QDebug> #include "scene.h" -#include <QtCore/QRandomGenerator> -#include <QtGui/qmatrix4x4.h> -#include <QtGui/qvector3d.h> + +#include <QMatrix4x4> +#include <QRandomGenerator> +#include <QVector3D> #include <qmath.h> #include "3rdparty/fbm.h" -void checkGLErrors(const QString& prefix) -{ - switch (glGetError()) { - case GL_NO_ERROR: - //qDebug() << prefix << tr("No error."); - break; - case GL_INVALID_ENUM: - qDebug() << prefix << QObject::tr("Invalid enum."); - break; - case GL_INVALID_VALUE: - qDebug() << prefix << QObject::tr("Invalid value."); - break; - case GL_INVALID_OPERATION: - qDebug() << prefix << QObject::tr("Invalid operation."); - break; - case GL_STACK_OVERFLOW: - qDebug() << prefix << QObject::tr("Stack overflow."); - break; - case GL_STACK_UNDERFLOW: - qDebug() << prefix << QObject::tr("Stack underflow."); - break; - case GL_OUT_OF_MEMORY: - qDebug() << prefix << QObject::tr("Out of memory."); - break; - default: - qDebug() << prefix << QObject::tr("Unknown error."); - break; - } -} - //============================================================================// // ColorEdit // //============================================================================// @@ -126,7 +96,7 @@ void ColorEdit::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { QColor color(m_color); - QColorDialog dialog(color, 0); + QColorDialog dialog(color, nullptr); dialog.setOption(QColorDialog::ShowAlphaChannel, true); dialog.move(280, 120); if (dialog.exec() == QDialog::Rejected) @@ -179,17 +149,6 @@ void FloatEdit::editDone() //============================================================================// // TwoSidedGraphicsWidget // //============================================================================// - -TwoSidedGraphicsWidget::TwoSidedGraphicsWidget(QGraphicsScene *scene) - : QObject(scene) - , m_current(0) - , m_angle(0) - , m_delta(0) -{ - for (int i = 0; i < 2; ++i) - m_proxyWidgets[i] = 0; -} - void TwoSidedGraphicsWidget::setWidget(int index, QWidget *widget) { if (index < 0 || index >= 2) @@ -201,8 +160,7 @@ void TwoSidedGraphicsWidget::setWidget(int index, QWidget *widget) GraphicsWidget *proxy = new GraphicsWidget; proxy->setWidget(widget); - if (m_proxyWidgets[index]) - delete m_proxyWidgets[index]; + delete m_proxyWidgets[index]; m_proxyWidgets[index] = proxy; proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache); @@ -219,7 +177,7 @@ QWidget *TwoSidedGraphicsWidget::widget(int index) if (index < 0 || index >= 2) { qWarning("TwoSidedGraphicsWidget::widget: Index out of bounds, index == %d", index); - return 0; + return nullptr; } return m_proxyWidgets[index]->widget(); } @@ -289,7 +247,7 @@ void GraphicsWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *op //============================================================================// RenderOptionsDialog::RenderOptionsDialog() - : QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint) + : QDialog(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint) { setWindowOpacity(0.75); setWindowTitle(tr("Options (double click to flip)")); @@ -423,7 +381,7 @@ void RenderOptionsDialog::mouseDoubleClickEvent(QMouseEvent *event) //============================================================================// ItemDialog::ItemDialog() - : QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint) + : QDialog(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint) { setWindowTitle(tr("Items (double click to flip)")); setWindowOpacity(0.75); @@ -487,10 +445,10 @@ Scene::Scene(int width, int height, int maxTextureSize) , m_currentTexture(0) , m_dynamicCubemap(false) , m_updateAllCubemaps(true) - , m_box(0) - , m_vertexShader(0) - , m_environmentShader(0) - , m_environmentProgram(0) + , m_box(nullptr) + , m_vertexShader(nullptr) + , m_environmentShader(nullptr) + , m_environmentProgram(nullptr) { setSceneRect(0, 0, width, height); @@ -564,9 +522,8 @@ void Scene::initGL() const int NOISE_SIZE = 128; // for a different size, B and BM in fbm.c must also be changed m_noise = new GLTexture3D(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE); - QRgb *data = new QRgb[NOISE_SIZE * NOISE_SIZE * NOISE_SIZE]; - memset(data, 0, NOISE_SIZE * NOISE_SIZE * NOISE_SIZE * sizeof(QRgb)); - QRgb *p = data; + QVector<QRgb> data(NOISE_SIZE * NOISE_SIZE * NOISE_SIZE, QRgb(0)); + QRgb *p = data.data(); float pos[3]; for (int k = 0; k < NOISE_SIZE; ++k) { pos[2] = k * (0x20 / (float)NOISE_SIZE); @@ -581,8 +538,7 @@ void Scene::initGL() } } } - m_noise->load(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE, data); - delete[] data; + m_noise->load(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE, data.data()); m_mainCubemap = new GLRenderTargetCube(512); @@ -634,7 +590,7 @@ void Scene::initGL() m_renderOptions->addShader(file.baseName()); program->bind(); - m_cubemaps << ((program->uniformLocation("env") != -1) ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : 0); + m_cubemaps << ((program->uniformLocation("env") != -1) ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : nullptr); program->release(); } diff --git a/examples/widgets/graphicsview/boxes/scene.h b/examples/widgets/graphicsview/boxes/scene.h index ffff01358f..5d65dc71e2 100644 --- a/examples/widgets/graphicsview/boxes/scene.h +++ b/examples/widgets/graphicsview/boxes/scene.h @@ -51,17 +51,12 @@ #ifndef SCENE_H #define SCENE_H -//#include <GL/glew.h> +#include "glbuffers.h" #include "glextensions.h" - -#include <QtWidgets> -#include <QtOpenGL> - -#include "roundedbox.h" #include "gltrianglemesh.h" -#include "trackball.h" -#include "glbuffers.h" #include "qtbox.h" +#include "roundedbox.h" +#include "trackball.h" QT_BEGIN_NAMESPACE class QMatrix4x4; @@ -116,7 +111,7 @@ private: class GraphicsWidget : public QGraphicsProxyWidget { public: - GraphicsWidget() : QGraphicsProxyWidget(0, Qt::Window) {} + GraphicsWidget() : QGraphicsProxyWidget(nullptr, Qt::Window) {} protected: QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; void resizeEvent(QGraphicsSceneResizeEvent *event) override; @@ -127,7 +122,7 @@ class TwoSidedGraphicsWidget : public QObject { Q_OBJECT public: - TwoSidedGraphicsWidget(QGraphicsScene *scene); + using QObject::QObject; void setWidget(int index, QWidget *widget); QWidget *widget(int index); public slots: @@ -135,10 +130,10 @@ public slots: protected slots: void animateFlip(); private: - GraphicsWidget *m_proxyWidgets[2]; - int m_current; - int m_angle; // angle in degrees - int m_delta; + GraphicsWidget *m_proxyWidgets[2] = {nullptr, nullptr}; + int m_current = 0; + int m_angle = 0; // angle in degrees + int m_delta = 0; }; class RenderOptionsDialog : public QDialog diff --git a/examples/widgets/graphicsview/boxes/trackball.cpp b/examples/widgets/graphicsview/boxes/trackball.cpp index 794ce7ac37..b9dfc1fc7f 100644 --- a/examples/widgets/graphicsview/boxes/trackball.cpp +++ b/examples/widgets/graphicsview/boxes/trackball.cpp @@ -50,34 +50,21 @@ #include "trackball.h" #include "scene.h" -#include <qmath.h> -#include <cmath> //============================================================================// // TrackBall // //============================================================================// TrackBall::TrackBall(TrackMode mode) - : m_angularVelocity(0) - , m_paused(false) - , m_pressed(false) - , m_mode(mode) + : TrackBall(0, QVector3D(0, 1, 0), mode) { - m_axis = QVector3D(0, 1, 0); - m_rotation = QQuaternion(); - m_lastTime = QTime::currentTime(); } TrackBall::TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode) : m_axis(axis) , m_angularVelocity(angularVelocity) - , m_paused(false) - , m_pressed(false) , m_mode(mode) -{ - m_rotation = QQuaternion(); - m_lastTime = QTime::currentTime(); -} +{} void TrackBall::push(const QPointF& p, const QQuaternion &) { diff --git a/examples/widgets/graphicsview/boxes/trackball.h b/examples/widgets/graphicsview/boxes/trackball.h index e65080e089..af90e4d842 100644 --- a/examples/widgets/graphicsview/boxes/trackball.h +++ b/examples/widgets/graphicsview/boxes/trackball.h @@ -51,10 +51,9 @@ #ifndef TRACKBALL_H #define TRACKBALL_H -#include <QtWidgets> - -#include <QtGui/qvector3d.h> -#include <QtGui/qquaternion.h> +#include <QQuaternion> +#include <QTime> +#include <QVector3D> class TrackBall { @@ -65,24 +64,24 @@ public: Sphere, }; TrackBall(TrackMode mode = Sphere); - TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode = Sphere); + TrackBall(float angularVelocity, const QVector3D &axis, TrackMode mode = Sphere); // coordinates in [-1,1]x[-1,1] - void push(const QPointF& p, const QQuaternion &transformation); - void move(const QPointF& p, const QQuaternion &transformation); - void release(const QPointF& p, const QQuaternion &transformation); + void push(const QPointF &p, const QQuaternion &transformation); + void move(const QPointF &p, const QQuaternion &transformation); + void release(const QPointF &p, const QQuaternion &transformation); void start(); // starts clock void stop(); // stops clock QQuaternion rotation() const; private: QQuaternion m_rotation; - QVector3D m_axis; - float m_angularVelocity; + QVector3D m_axis = QVector3D(0, 1, 0); + float m_angularVelocity = 0; QPointF m_lastPos; - QTime m_lastTime; - bool m_paused; - bool m_pressed; + QTime m_lastTime = QTime::currentTime(); TrackMode m_mode; + bool m_paused = false; + bool m_pressed = false; }; #endif |