From f3ecda32e0f7bd21b44e7737d2939dcce2c26517 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Wed, 11 Dec 2019 14:50:40 +0100 Subject: Move QOpenGLPaintEngine and related classes from QtGui to QtOpenGL Also moves the openglwindow test to the opengl folder, as it makes use of these classes. Task-number: QTBUG-74409 Change-Id: Id9f0013cedcc8bd1e87122c005641d7298525045 Reviewed-by: Laszlo Agocs --- examples/gui/gui.pro | 2 - examples/gui/openglwindow/main.cpp | 177 --------------------- examples/gui/openglwindow/openglwindow.cpp | 161 ------------------- examples/gui/openglwindow/openglwindow.h | 91 ----------- examples/gui/openglwindow/openglwindow.pri | 3 - examples/gui/openglwindow/openglwindow.pro | 7 - examples/opengl/opengl.pro | 1 + examples/opengl/openglwindow/main.cpp | 177 +++++++++++++++++++++ examples/opengl/openglwindow/openglwindow.cpp | 161 +++++++++++++++++++ examples/opengl/openglwindow/openglwindow.h | 91 +++++++++++ examples/opengl/openglwindow/openglwindow.pri | 4 + examples/opengl/openglwindow/openglwindow.pro | 7 + examples/opengl/paintedwindow/paintedwindow.pro | 2 + examples/widgets/painting/shared/arthurwidgets.cpp | 2 +- .../widgets/windowcontainer/windowcontainer.cpp | 2 +- .../widgets/windowcontainer/windowcontainer.pro | 2 +- 16 files changed, 446 insertions(+), 444 deletions(-) delete mode 100644 examples/gui/openglwindow/main.cpp delete mode 100644 examples/gui/openglwindow/openglwindow.cpp delete mode 100644 examples/gui/openglwindow/openglwindow.h delete mode 100644 examples/gui/openglwindow/openglwindow.pri delete mode 100644 examples/gui/openglwindow/openglwindow.pro create mode 100644 examples/opengl/openglwindow/main.cpp create mode 100644 examples/opengl/openglwindow/openglwindow.cpp create mode 100644 examples/opengl/openglwindow/openglwindow.h create mode 100644 examples/opengl/openglwindow/openglwindow.pri create mode 100644 examples/opengl/openglwindow/openglwindow.pro (limited to 'examples') diff --git a/examples/gui/gui.pro b/examples/gui/gui.pro index b8080c2075..275adc804d 100644 --- a/examples/gui/gui.pro +++ b/examples/gui/gui.pro @@ -6,5 +6,3 @@ CONFIG += no_docs_target SUBDIRS += analogclock SUBDIRS += rasterwindow -qtHaveModule(gui):qtConfig(opengl): \ - SUBDIRS += openglwindow diff --git a/examples/gui/openglwindow/main.cpp b/examples/gui/openglwindow/main.cpp deleted file mode 100644 index 03a6ece06f..0000000000 --- a/examples/gui/openglwindow/main.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "openglwindow.h" - -#include -#include -#include -#include -#include - - -//! [1] -class TriangleWindow : public OpenGLWindow -{ -public: - using OpenGLWindow::OpenGLWindow; - - void initialize() override; - void render() override; - -private: - GLint m_posAttr = 0; - GLint m_colAttr = 0; - GLint m_matrixUniform = 0; - - QOpenGLShaderProgram *m_program = nullptr; - int m_frame = 0; -}; -//! [1] - -//! [2] -int main(int argc, char **argv) -{ - QGuiApplication app(argc, argv); - - QSurfaceFormat format; - format.setSamples(16); - - TriangleWindow window; - window.setFormat(format); - window.resize(640, 480); - window.show(); - - window.setAnimating(true); - - return app.exec(); -} -//! [2] - - -//! [3] -static const char *vertexShaderSource = - "attribute highp vec4 posAttr;\n" - "attribute lowp vec4 colAttr;\n" - "varying lowp vec4 col;\n" - "uniform highp mat4 matrix;\n" - "void main() {\n" - " col = colAttr;\n" - " gl_Position = matrix * posAttr;\n" - "}\n"; - -static const char *fragmentShaderSource = - "varying lowp vec4 col;\n" - "void main() {\n" - " gl_FragColor = col;\n" - "}\n"; -//! [3] - -//! [4] -void TriangleWindow::initialize() -{ - m_program = new QOpenGLShaderProgram(this); - m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource); - m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource); - m_program->link(); - m_posAttr = m_program->attributeLocation("posAttr"); - Q_ASSERT(m_posAttr != -1); - m_colAttr = m_program->attributeLocation("colAttr"); - Q_ASSERT(m_colAttr != -1); - m_matrixUniform = m_program->uniformLocation("matrix"); - Q_ASSERT(m_matrixUniform != -1); -} -//! [4] - -//! [5] -void TriangleWindow::render() -{ - const qreal retinaScale = devicePixelRatio(); - glViewport(0, 0, width() * retinaScale, height() * retinaScale); - - glClear(GL_COLOR_BUFFER_BIT); - - m_program->bind(); - - QMatrix4x4 matrix; - 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); - - m_program->setUniformValue(m_matrixUniform, matrix); - - static const GLfloat vertices[] = { - 0.0f, 0.707f, - -0.5f, -0.5f, - 0.5f, -0.5f - }; - - static const GLfloat colors[] = { - 1.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 1.0f - }; - - glVertexAttribPointer(m_posAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices); - glVertexAttribPointer(m_colAttr, 3, GL_FLOAT, GL_FALSE, 0, colors); - - glEnableVertexAttribArray(m_posAttr); - glEnableVertexAttribArray(m_colAttr); - - glDrawArrays(GL_TRIANGLES, 0, 3); - - glDisableVertexAttribArray(m_colAttr); - glDisableVertexAttribArray(m_posAttr); - - m_program->release(); - - ++m_frame; -} -//! [5] diff --git a/examples/gui/openglwindow/openglwindow.cpp b/examples/gui/openglwindow/openglwindow.cpp deleted file mode 100644 index bac887dca0..0000000000 --- a/examples/gui/openglwindow/openglwindow.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "openglwindow.h" - -#include -#include -#include - -//! [1] -OpenGLWindow::OpenGLWindow(QWindow *parent) - : QWindow(parent) -{ - setSurfaceType(QWindow::OpenGLSurface); -} -//! [1] - -OpenGLWindow::~OpenGLWindow() -{ - delete m_device; -} -//! [2] -void OpenGLWindow::render(QPainter *painter) -{ - Q_UNUSED(painter); -} - -void OpenGLWindow::initialize() -{ -} - -void OpenGLWindow::render() -{ - if (!m_device) - m_device = new QOpenGLPaintDevice; - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - - m_device->setSize(size() * devicePixelRatio()); - m_device->setDevicePixelRatio(devicePixelRatio()); - - QPainter painter(m_device); - render(&painter); -} -//! [2] - -//! [3] -void OpenGLWindow::renderLater() -{ - requestUpdate(); -} - -bool OpenGLWindow::event(QEvent *event) -{ - switch (event->type()) { - case QEvent::UpdateRequest: - renderNow(); - return true; - default: - return QWindow::event(event); - } -} - -void OpenGLWindow::exposeEvent(QExposeEvent *event) -{ - Q_UNUSED(event); - - if (isExposed()) - renderNow(); -} -//! [3] - -//! [4] -void OpenGLWindow::renderNow() -{ - if (!isExposed()) - return; - - bool needsInitialize = false; - - if (!m_context) { - m_context = new QOpenGLContext(this); - m_context->setFormat(requestedFormat()); - m_context->create(); - - needsInitialize = true; - } - - m_context->makeCurrent(this); - - if (needsInitialize) { - initializeOpenGLFunctions(); - initialize(); - } - - render(); - - m_context->swapBuffers(this); - - if (m_animating) - renderLater(); -} -//! [4] - -//! [5] -void OpenGLWindow::setAnimating(bool animating) -{ - m_animating = animating; - - if (animating) - renderLater(); -} -//! [5] - diff --git a/examples/gui/openglwindow/openglwindow.h b/examples/gui/openglwindow/openglwindow.h deleted file mode 100644 index 8db943ddde..0000000000 --- a/examples/gui/openglwindow/openglwindow.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -QT_BEGIN_NAMESPACE -class QPainter; -class QOpenGLContext; -class QOpenGLPaintDevice; -QT_END_NAMESPACE - -//! [1] -class OpenGLWindow : public QWindow, protected QOpenGLFunctions -{ - Q_OBJECT -public: - explicit OpenGLWindow(QWindow *parent = nullptr); - ~OpenGLWindow(); - - virtual void render(QPainter *painter); - virtual void render(); - - virtual void initialize(); - - void setAnimating(bool animating); - -public slots: - void renderLater(); - void renderNow(); - -protected: - bool event(QEvent *event) override; - - void exposeEvent(QExposeEvent *event) override; - -private: - bool m_animating = false; - - QOpenGLContext *m_context = nullptr; - QOpenGLPaintDevice *m_device = nullptr; -}; -//! [1] - diff --git a/examples/gui/openglwindow/openglwindow.pri b/examples/gui/openglwindow/openglwindow.pri deleted file mode 100644 index 45b0b0cd29..0000000000 --- a/examples/gui/openglwindow/openglwindow.pri +++ /dev/null @@ -1,3 +0,0 @@ -INCLUDEPATH += $$PWD -SOURCES += $$PWD/openglwindow.cpp -HEADERS += $$PWD/openglwindow.h diff --git a/examples/gui/openglwindow/openglwindow.pro b/examples/gui/openglwindow/openglwindow.pro deleted file mode 100644 index 93f18f3d3f..0000000000 --- a/examples/gui/openglwindow/openglwindow.pro +++ /dev/null @@ -1,7 +0,0 @@ -include(openglwindow.pri) - -SOURCES += \ - main.cpp - -target.path = $$[QT_INSTALL_EXAMPLES]/gui/openglwindow -INSTALLS += target diff --git a/examples/opengl/opengl.pro b/examples/opengl/opengl.pro index 89b3e1d86e..74c39a1e27 100644 --- a/examples/opengl/opengl.pro +++ b/examples/opengl/opengl.pro @@ -2,6 +2,7 @@ TEMPLATE = subdirs SUBDIRS = hellowindow \ paintedwindow \ + openglwindow \ qopenglwindow qtHaveModule(widgets) { diff --git a/examples/opengl/openglwindow/main.cpp b/examples/opengl/openglwindow/main.cpp new file mode 100644 index 0000000000..03a6ece06f --- /dev/null +++ b/examples/opengl/openglwindow/main.cpp @@ -0,0 +1,177 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "openglwindow.h" + +#include +#include +#include +#include +#include + + +//! [1] +class TriangleWindow : public OpenGLWindow +{ +public: + using OpenGLWindow::OpenGLWindow; + + void initialize() override; + void render() override; + +private: + GLint m_posAttr = 0; + GLint m_colAttr = 0; + GLint m_matrixUniform = 0; + + QOpenGLShaderProgram *m_program = nullptr; + int m_frame = 0; +}; +//! [1] + +//! [2] +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + + QSurfaceFormat format; + format.setSamples(16); + + TriangleWindow window; + window.setFormat(format); + window.resize(640, 480); + window.show(); + + window.setAnimating(true); + + return app.exec(); +} +//! [2] + + +//! [3] +static const char *vertexShaderSource = + "attribute highp vec4 posAttr;\n" + "attribute lowp vec4 colAttr;\n" + "varying lowp vec4 col;\n" + "uniform highp mat4 matrix;\n" + "void main() {\n" + " col = colAttr;\n" + " gl_Position = matrix * posAttr;\n" + "}\n"; + +static const char *fragmentShaderSource = + "varying lowp vec4 col;\n" + "void main() {\n" + " gl_FragColor = col;\n" + "}\n"; +//! [3] + +//! [4] +void TriangleWindow::initialize() +{ + m_program = new QOpenGLShaderProgram(this); + m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource); + m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource); + m_program->link(); + m_posAttr = m_program->attributeLocation("posAttr"); + Q_ASSERT(m_posAttr != -1); + m_colAttr = m_program->attributeLocation("colAttr"); + Q_ASSERT(m_colAttr != -1); + m_matrixUniform = m_program->uniformLocation("matrix"); + Q_ASSERT(m_matrixUniform != -1); +} +//! [4] + +//! [5] +void TriangleWindow::render() +{ + const qreal retinaScale = devicePixelRatio(); + glViewport(0, 0, width() * retinaScale, height() * retinaScale); + + glClear(GL_COLOR_BUFFER_BIT); + + m_program->bind(); + + QMatrix4x4 matrix; + 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); + + m_program->setUniformValue(m_matrixUniform, matrix); + + static const GLfloat vertices[] = { + 0.0f, 0.707f, + -0.5f, -0.5f, + 0.5f, -0.5f + }; + + static const GLfloat colors[] = { + 1.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f + }; + + glVertexAttribPointer(m_posAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices); + glVertexAttribPointer(m_colAttr, 3, GL_FLOAT, GL_FALSE, 0, colors); + + glEnableVertexAttribArray(m_posAttr); + glEnableVertexAttribArray(m_colAttr); + + glDrawArrays(GL_TRIANGLES, 0, 3); + + glDisableVertexAttribArray(m_colAttr); + glDisableVertexAttribArray(m_posAttr); + + m_program->release(); + + ++m_frame; +} +//! [5] diff --git a/examples/opengl/openglwindow/openglwindow.cpp b/examples/opengl/openglwindow/openglwindow.cpp new file mode 100644 index 0000000000..bac887dca0 --- /dev/null +++ b/examples/opengl/openglwindow/openglwindow.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "openglwindow.h" + +#include +#include +#include + +//! [1] +OpenGLWindow::OpenGLWindow(QWindow *parent) + : QWindow(parent) +{ + setSurfaceType(QWindow::OpenGLSurface); +} +//! [1] + +OpenGLWindow::~OpenGLWindow() +{ + delete m_device; +} +//! [2] +void OpenGLWindow::render(QPainter *painter) +{ + Q_UNUSED(painter); +} + +void OpenGLWindow::initialize() +{ +} + +void OpenGLWindow::render() +{ + if (!m_device) + m_device = new QOpenGLPaintDevice; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + + m_device->setSize(size() * devicePixelRatio()); + m_device->setDevicePixelRatio(devicePixelRatio()); + + QPainter painter(m_device); + render(&painter); +} +//! [2] + +//! [3] +void OpenGLWindow::renderLater() +{ + requestUpdate(); +} + +bool OpenGLWindow::event(QEvent *event) +{ + switch (event->type()) { + case QEvent::UpdateRequest: + renderNow(); + return true; + default: + return QWindow::event(event); + } +} + +void OpenGLWindow::exposeEvent(QExposeEvent *event) +{ + Q_UNUSED(event); + + if (isExposed()) + renderNow(); +} +//! [3] + +//! [4] +void OpenGLWindow::renderNow() +{ + if (!isExposed()) + return; + + bool needsInitialize = false; + + if (!m_context) { + m_context = new QOpenGLContext(this); + m_context->setFormat(requestedFormat()); + m_context->create(); + + needsInitialize = true; + } + + m_context->makeCurrent(this); + + if (needsInitialize) { + initializeOpenGLFunctions(); + initialize(); + } + + render(); + + m_context->swapBuffers(this); + + if (m_animating) + renderLater(); +} +//! [4] + +//! [5] +void OpenGLWindow::setAnimating(bool animating) +{ + m_animating = animating; + + if (animating) + renderLater(); +} +//! [5] + diff --git a/examples/opengl/openglwindow/openglwindow.h b/examples/opengl/openglwindow/openglwindow.h new file mode 100644 index 0000000000..8db943ddde --- /dev/null +++ b/examples/opengl/openglwindow/openglwindow.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +QT_BEGIN_NAMESPACE +class QPainter; +class QOpenGLContext; +class QOpenGLPaintDevice; +QT_END_NAMESPACE + +//! [1] +class OpenGLWindow : public QWindow, protected QOpenGLFunctions +{ + Q_OBJECT +public: + explicit OpenGLWindow(QWindow *parent = nullptr); + ~OpenGLWindow(); + + virtual void render(QPainter *painter); + virtual void render(); + + virtual void initialize(); + + void setAnimating(bool animating); + +public slots: + void renderLater(); + void renderNow(); + +protected: + bool event(QEvent *event) override; + + void exposeEvent(QExposeEvent *event) override; + +private: + bool m_animating = false; + + QOpenGLContext *m_context = nullptr; + QOpenGLPaintDevice *m_device = nullptr; +}; +//! [1] + diff --git a/examples/opengl/openglwindow/openglwindow.pri b/examples/opengl/openglwindow/openglwindow.pri new file mode 100644 index 0000000000..30320df3b7 --- /dev/null +++ b/examples/opengl/openglwindow/openglwindow.pri @@ -0,0 +1,4 @@ +QT += opengl +INCLUDEPATH += $$PWD +SOURCES += $$PWD/openglwindow.cpp +HEADERS += $$PWD/openglwindow.h diff --git a/examples/opengl/openglwindow/openglwindow.pro b/examples/opengl/openglwindow/openglwindow.pro new file mode 100644 index 0000000000..8b1ae71c14 --- /dev/null +++ b/examples/opengl/openglwindow/openglwindow.pro @@ -0,0 +1,7 @@ +include(openglwindow.pri) + +SOURCES += \ + main.cpp + +target.path = $$[QT_INSTALL_EXAMPLES]/opengl/openglwindow +INSTALLS += target diff --git a/examples/opengl/paintedwindow/paintedwindow.pro b/examples/opengl/paintedwindow/paintedwindow.pro index 1846aa4049..569eebe674 100644 --- a/examples/opengl/paintedwindow/paintedwindow.pro +++ b/examples/opengl/paintedwindow/paintedwindow.pro @@ -1,3 +1,5 @@ +QT += opengl + HEADERS += paintedwindow.h SOURCES += paintedwindow.cpp main.cpp diff --git a/examples/widgets/painting/shared/arthurwidgets.cpp b/examples/widgets/painting/shared/arthurwidgets.cpp index c7c851270b..e24130e464 100644 --- a/examples/widgets/painting/shared/arthurwidgets.cpp +++ b/examples/widgets/painting/shared/arthurwidgets.cpp @@ -62,8 +62,8 @@ #include #include #include -#include #if QT_CONFIG(opengl) +#include #include #endif diff --git a/examples/widgets/windowcontainer/windowcontainer.cpp b/examples/widgets/windowcontainer/windowcontainer.cpp index b920c85420..f7c146e2a9 100644 --- a/examples/widgets/windowcontainer/windowcontainer.cpp +++ b/examples/widgets/windowcontainer/windowcontainer.cpp @@ -60,7 +60,7 @@ #include -// Making use of the class from the opengl example in gui. +// Making use of the class from the openglwindow example class Window : public OpenGLWindow { Q_OBJECT diff --git a/examples/widgets/windowcontainer/windowcontainer.pro b/examples/widgets/windowcontainer/windowcontainer.pro index 9ac7e4a5ab..664ac938a2 100644 --- a/examples/widgets/windowcontainer/windowcontainer.pro +++ b/examples/widgets/windowcontainer/windowcontainer.pro @@ -6,4 +6,4 @@ QT += widgets target.path = $$[QT_INSTALL_EXAMPLES]/widgets/windowcontainer INSTALLS += target -include(../../gui/openglwindow/openglwindow.pri) +include(../../opengl/openglwindow/openglwindow.pri) -- cgit v1.2.3 From 73d1476fb1397948a4d806bd921fce372bd8d63b Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 2 Dec 2019 17:54:48 +0100 Subject: Replace most use of QVariant::type and occurrences of QVariant::Type I made a clazy automated check that replaced the use of QVariant::Type by the equivalent in QMetaType. This has been deprecated since Qt 5.0, but many uses were not yet removed. In addition, there was some manual changes to fix the compilation errors. Adapted the Private API of QDateTimeParser and QMimeDataPrivate and adjust QDateTimeEdit and QSpinBox. QVariant(QVariant::Invalid) in qstylesheet made no sense. But note that in QVariant::save, we actually wanted to use the non-user type. In the SQL module, many changes were actually reverted because the API still expects QVarient::Type. Change-Id: I98c368490e4ee465ed3a3b63bda8b8eaa50ea67e Reviewed-by: Lars Knoll --- .../serialization/convert/cborconverter.cpp | 4 +- .../serialization/convert/datastreamconverter.cpp | 6 +- .../serialization/convert/textconverter.cpp | 6 +- .../corelib/serialization/convert/xmlconverter.cpp | 20 ++-- examples/network/torrent/trackerclient.cpp | 2 +- .../itemviews/coloreditorfactory/window.cpp | 2 +- .../mysortfilterproxymodel.cpp | 2 +- .../widgets/tools/settingseditor/settingstree.cpp | 2 +- .../tools/settingseditor/variantdelegate.cpp | 132 ++++++++++----------- .../widgets/tools/settingseditor/variantdelegate.h | 2 +- 10 files changed, 89 insertions(+), 89 deletions(-) (limited to 'examples') diff --git a/examples/corelib/serialization/convert/cborconverter.cpp b/examples/corelib/serialization/convert/cborconverter.cpp index 60410ed26a..77df367e50 100644 --- a/examples/corelib/serialization/convert/cborconverter.cpp +++ b/examples/corelib/serialization/convert/cborconverter.cpp @@ -134,7 +134,7 @@ static QVariant convertCborValue(const QCborValue &value) enum TrimFloatingPoint { Double, Float, Float16 }; static QCborValue convertFromVariant(const QVariant &v, TrimFloatingPoint fpTrimming) { - if (v.userType() == QVariant::List) { + if (v.userType() == QMetaType::QVariantList) { const QVariantList list = v.toList(); QCborArray array; for (const QVariant &v : list) @@ -152,7 +152,7 @@ static QCborValue convertFromVariant(const QVariant &v, TrimFloatingPoint fpTrim return map; } - if (v.userType() == QVariant::Double && fpTrimming != Double) { + if (v.userType() == QMetaType::Double && fpTrimming != Double) { float f = float(v.toDouble()); if (fpTrimming == Float16) return float(qfloat16(f)); diff --git a/examples/corelib/serialization/convert/datastreamconverter.cpp b/examples/corelib/serialization/convert/datastreamconverter.cpp index 7e9f5e1bdc..6f0ca41ff5 100644 --- a/examples/corelib/serialization/convert/datastreamconverter.cpp +++ b/examples/corelib/serialization/convert/datastreamconverter.cpp @@ -96,8 +96,8 @@ static QString dumpVariant(const QVariant &v, const QString &indent = QLatin1Str QString indented = indent + QLatin1String(" "); int type = v.userType(); - if (type == qMetaTypeId() || type == QVariant::Map) { - const auto map = (type == QVariant::Map) ? + if (type == qMetaTypeId() || type == QMetaType::QVariantMap) { + const auto map = (type == QMetaType::QVariantMap) ? VariantOrderedMap(v.toMap()) : qvariant_cast(v); result = QLatin1String("Map {"); @@ -109,7 +109,7 @@ static QString dumpVariant(const QVariant &v, const QString &indent = QLatin1Str } result.chop(1); // remove comma result += indent + QLatin1String("},"); - } else if (type == QVariant::List) { + } else if (type == QMetaType::QVariantList) { const QVariantList list = v.toList(); result = QLatin1String("List ["); diff --git a/examples/corelib/serialization/convert/textconverter.cpp b/examples/corelib/serialization/convert/textconverter.cpp index 7aed08f96c..ae03b9a334 100644 --- a/examples/corelib/serialization/convert/textconverter.cpp +++ b/examples/corelib/serialization/convert/textconverter.cpp @@ -56,21 +56,21 @@ static void dumpVariant(QTextStream &out, const QVariant &v) { switch (v.userType()) { - case QVariant::List: { + case QMetaType::QVariantList: { const QVariantList list = v.toList(); for (const QVariant &item : list) dumpVariant(out, item); break; } - case QVariant::String: { + case QMetaType::QString: { const QStringList list = v.toStringList(); for (const QString &s : list) out << s << Qt::endl; break; } - case QVariant::Map: { + case QMetaType::QVariantMap: { const QVariantMap map = v.toMap(); for (auto it = map.begin(); it != map.end(); ++it) { out << it.key() << " => "; diff --git a/examples/corelib/serialization/convert/xmlconverter.cpp b/examples/corelib/serialization/convert/xmlconverter.cpp index d9e724dfe1..42cb10100a 100644 --- a/examples/corelib/serialization/convert/xmlconverter.cpp +++ b/examples/corelib/serialization/convert/xmlconverter.cpp @@ -284,18 +284,18 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options ba.resize(n); result = ba; } else { - int id = QVariant::Invalid; + int id = QMetaType::UnknownType; if (type == QLatin1String("datetime")) - id = QVariant::DateTime; + id = QMetaType::QDateTime; else if (type == QLatin1String("url")) - id = QVariant::Url; + id = QMetaType::QUrl; else if (type == QLatin1String("uuid")) - id = QVariant::Uuid; + id = QMetaType::QUuid; else if (type == QLatin1String("regex")) - id = QVariant::RegularExpression; + id = QMetaType::QRegularExpression; else id = QMetaType::type(type.toLatin1()); - if (id == QVariant::Invalid) { + if (id == QMetaType::UnknownType) { fprintf(stderr, "%lld:%lld: Invalid XML: unknown type '%s'.\n", xml.lineNumber(), xml.columnNumber(), qPrintable(type.toString())); exit(EXIT_FAILURE); @@ -327,14 +327,14 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options static void variantToXml(QXmlStreamWriter &xml, const QVariant &v) { int type = v.userType(); - if (type == QVariant::List) { + if (type == QMetaType::QVariantList) { QVariantList list = v.toList(); xml.writeStartElement("list"); for (const QVariant &v : list) variantToXml(xml, v); xml.writeEndElement(); - } else if (type == QVariant::Map || type == qMetaTypeId()) { - const VariantOrderedMap map = (type == QVariant::Map) ? + } else if (type == QMetaType::QVariantMap || type == qMetaTypeId()) { + const VariantOrderedMap map = (type == QMetaType::QVariantMap) ? VariantOrderedMap(v.toMap()) : qvariant_cast(v); @@ -433,7 +433,7 @@ static void variantToXml(QXmlStreamWriter &xml, const QVariant &v) // does this convert to string? const char *typeName = v.typeName(); QVariant copy = v; - if (copy.convert(QVariant::String)) { + if (copy.convert(QMetaType::QString)) { xml.writeAttribute(typeString, QString::fromLatin1(typeName)); xml.writeCharacters(copy.toString()); } else { diff --git a/examples/network/torrent/trackerclient.cpp b/examples/network/torrent/trackerclient.cpp index 540ab31557..a50a49fd64 100644 --- a/examples/network/torrent/trackerclient.cpp +++ b/examples/network/torrent/trackerclient.cpp @@ -209,7 +209,7 @@ void TrackerClient::httpRequestDone(QNetworkReply *reply) // store it peers.clear(); QVariant peerEntry = dict.value("peers"); - if (peerEntry.type() == QVariant::List) { + if (peerEntry.userType() == QMetaType::QVariantList) { QList peerTmp = peerEntry.toList(); for (int i = 0; i < peerTmp.size(); ++i) { TorrentPeer tmp; diff --git a/examples/widgets/itemviews/coloreditorfactory/window.cpp b/examples/widgets/itemviews/coloreditorfactory/window.cpp index e4a9379d8f..25e196a80c 100644 --- a/examples/widgets/itemviews/coloreditorfactory/window.cpp +++ b/examples/widgets/itemviews/coloreditorfactory/window.cpp @@ -61,7 +61,7 @@ Window::Window() QItemEditorCreatorBase *colorListCreator = new QStandardItemEditorCreator(); - factory->registerEditor(QVariant::Color, colorListCreator); + factory->registerEditor(QMetaType::QColor, colorListCreator); QItemEditorFactory::setDefaultFactory(factory); diff --git a/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp index 4753d04d9b..b0b4017e62 100644 --- a/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp +++ b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp @@ -98,7 +98,7 @@ bool MySortFilterProxyModel::lessThan(const QModelIndex &left, //! [4] //! [6] - if (leftData.type() == QVariant::DateTime) { + if (leftData.userType() == QMetaType::QDateTime) { return leftData.toDateTime() < rightData.toDateTime(); } else { static const QRegularExpression emailPattern("[\\w\\.]*@[\\w\\.]*"); diff --git a/examples/widgets/tools/settingseditor/settingstree.cpp b/examples/widgets/tools/settingseditor/settingstree.cpp index 49d299bf72..9132368e4a 100644 --- a/examples/widgets/tools/settingseditor/settingstree.cpp +++ b/examples/widgets/tools/settingseditor/settingstree.cpp @@ -208,7 +208,7 @@ void SettingsTree::updateChildItems(QTreeWidgetItem *parent) } QVariant value = settings->value(key); - if (value.type() == QVariant::Invalid) { + if (value.userType() == QMetaType::UnknownType) { child->setText(1, "Invalid"); } else { child->setText(1, value.typeName()); diff --git a/examples/widgets/tools/settingseditor/variantdelegate.cpp b/examples/widgets/tools/settingseditor/variantdelegate.cpp index 9772fe8a41..eb822f0dc2 100644 --- a/examples/widgets/tools/settingseditor/variantdelegate.cpp +++ b/examples/widgets/tools/settingseditor/variantdelegate.cpp @@ -81,7 +81,7 @@ void VariantDelegate::paint(QPainter *painter, { if (index.column() == 2) { QVariant value = index.model()->data(index, Qt::UserRole); - if (!isSupportedType(value.type())) { + if (!isSupportedType(value.userType())) { QStyleOptionViewItem myOption = option; myOption.state &= ~QStyle::State_Enabled; QStyledItemDelegate::paint(painter, myOption, index); @@ -100,7 +100,7 @@ QWidget *VariantDelegate::createEditor(QWidget *parent, return nullptr; QVariant originalValue = index.model()->data(index, Qt::UserRole); - if (!isSupportedType(originalValue.type())) + if (!isSupportedType(originalValue.userType())) return nullptr; QLineEdit *lineEdit = new QLineEdit(parent); @@ -108,46 +108,46 @@ QWidget *VariantDelegate::createEditor(QWidget *parent, QRegularExpression regExp; - switch (originalValue.type()) { - case QVariant::Bool: + switch (originalValue.userType()) { + case QMetaType::Bool: regExp = boolExp; break; - case QVariant::ByteArray: + case QMetaType::QByteArray: regExp = byteArrayExp; break; - case QVariant::Char: + case QMetaType::QChar: regExp = charExp; break; - case QVariant::Color: + case QMetaType::QColor: regExp = colorExp; break; - case QVariant::Date: + case QMetaType::QDate: regExp = dateExp; break; - case QVariant::DateTime: + case QMetaType::QDateTime: regExp = dateTimeExp; break; - case QVariant::Double: + case QMetaType::Double: regExp = doubleExp; break; - case QVariant::Int: - case QVariant::LongLong: + case QMetaType::Int: + case QMetaType::LongLong: regExp = signedIntegerExp; break; - case QVariant::Point: + case QMetaType::QPoint: regExp = pointExp; break; - case QVariant::Rect: + case QMetaType::QRect: regExp = rectExp; break; - case QVariant::Size: + case QMetaType::QSize: regExp = sizeExp; break; - case QVariant::Time: + case QMetaType::QTime: regExp = timeExp; break; - case QVariant::UInt: - case QVariant::ULongLong: + case QMetaType::UInt: + case QMetaType::ULongLong: regExp = unsignedIntegerExp; break; default: @@ -189,18 +189,18 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, QVariant value; QRegularExpressionMatch match; - switch (originalValue.type()) { - case QVariant::Char: + switch (originalValue.userType()) { + case QMetaType::QChar: value = text.at(0); break; - case QVariant::Color: + case QMetaType::QColor: match = colorExp.match(text); value = QColor(qMin(match.captured(1).toInt(), 255), qMin(match.captured(2).toInt(), 255), qMin(match.captured(3).toInt(), 255), qMin(match.captured(4).toInt(), 255)); break; - case QVariant::Date: + case QMetaType::QDate: { QDate date = QDate::fromString(text, Qt::ISODate); if (!date.isValid()) @@ -208,7 +208,7 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, value = date; } break; - case QVariant::DateTime: + case QMetaType::QDateTime: { QDateTime dateTime = QDateTime::fromString(text, Qt::ISODate); if (!dateTime.isValid()) @@ -216,23 +216,23 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, value = dateTime; } break; - case QVariant::Point: + case QMetaType::QPoint: match = pointExp.match(text); value = QPoint(match.captured(1).toInt(), match.captured(2).toInt()); break; - case QVariant::Rect: + case QMetaType::QRect: match = rectExp.match(text); value = QRect(match.captured(1).toInt(), match.captured(2).toInt(), match.captured(3).toInt(), match.captured(4).toInt()); break; - case QVariant::Size: + case QMetaType::QSize: match = sizeExp.match(text); value = QSize(match.captured(1).toInt(), match.captured(2).toInt()); break; - case QVariant::StringList: + case QMetaType::QStringList: value = text.split(','); break; - case QVariant::Time: + case QMetaType::QTime: { QTime time = QTime::fromString(text, Qt::ISODate); if (!time.isValid()) @@ -242,33 +242,33 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, break; default: value = text; - value.convert(originalValue.type()); + value.convert(originalValue.userType()); } model->setData(index, displayText(value), Qt::DisplayRole); model->setData(index, value, Qt::UserRole); } -bool VariantDelegate::isSupportedType(QVariant::Type type) +bool VariantDelegate::isSupportedType(int type) { switch (type) { - case QVariant::Bool: - case QVariant::ByteArray: - case QVariant::Char: - case QVariant::Color: - case QVariant::Date: - case QVariant::DateTime: - case QVariant::Double: - case QVariant::Int: - case QVariant::LongLong: - case QVariant::Point: - case QVariant::Rect: - case QVariant::Size: - case QVariant::String: - case QVariant::StringList: - case QVariant::Time: - case QVariant::UInt: - case QVariant::ULongLong: + case QMetaType::Bool: + case QMetaType::QByteArray: + case QMetaType::QChar: + case QMetaType::QColor: + case QMetaType::QDate: + case QMetaType::QDateTime: + case QMetaType::Double: + case QMetaType::Int: + case QMetaType::LongLong: + case QMetaType::QPoint: + case QMetaType::QRect: + case QMetaType::QSize: + case QMetaType::QString: + case QMetaType::QStringList: + case QMetaType::QTime: + case QMetaType::UInt: + case QMetaType::ULongLong: return true; default: return false; @@ -277,50 +277,50 @@ bool VariantDelegate::isSupportedType(QVariant::Type type) QString VariantDelegate::displayText(const QVariant &value) { - switch (value.type()) { - case QVariant::Bool: - case QVariant::ByteArray: - case QVariant::Char: - case QVariant::Double: - case QVariant::Int: - case QVariant::LongLong: - case QVariant::String: - case QVariant::UInt: - case QVariant::ULongLong: + switch (value.userType()) { + case QMetaType::Bool: + case QMetaType::QByteArray: + case QMetaType::QChar: + case QMetaType::Double: + case QMetaType::Int: + case QMetaType::LongLong: + case QMetaType::QString: + case QMetaType::UInt: + case QMetaType::ULongLong: return value.toString(); - case QVariant::Color: + case QMetaType::QColor: { QColor color = qvariant_cast(value); return QString("(%1,%2,%3,%4)") .arg(color.red()).arg(color.green()) .arg(color.blue()).arg(color.alpha()); } - case QVariant::Date: + case QMetaType::QDate: return value.toDate().toString(Qt::ISODate); - case QVariant::DateTime: + case QMetaType::QDateTime: return value.toDateTime().toString(Qt::ISODate); - case QVariant::Invalid: + case QMetaType::UnknownType: return ""; - case QVariant::Point: + case QMetaType::QPoint: { QPoint point = value.toPoint(); return QString("(%1,%2)").arg(point.x()).arg(point.y()); } - case QVariant::Rect: + case QMetaType::QRect: { QRect rect = value.toRect(); return QString("(%1,%2,%3,%4)") .arg(rect.x()).arg(rect.y()) .arg(rect.width()).arg(rect.height()); } - case QVariant::Size: + case QMetaType::QSize: { QSize size = value.toSize(); return QString("(%1,%2)").arg(size.width()).arg(size.height()); } - case QVariant::StringList: + case QMetaType::QStringList: return value.toStringList().join(','); - case QVariant::Time: + case QMetaType::QTime: return value.toTime().toString(Qt::ISODate); default: break; diff --git a/examples/widgets/tools/settingseditor/variantdelegate.h b/examples/widgets/tools/settingseditor/variantdelegate.h index 68f21fa3f6..96e44fd181 100644 --- a/examples/widgets/tools/settingseditor/variantdelegate.h +++ b/examples/widgets/tools/settingseditor/variantdelegate.h @@ -69,7 +69,7 @@ public: void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; - static bool isSupportedType(QVariant::Type type); + static bool isSupportedType(int type); static QString displayText(const QVariant &value); private: -- cgit v1.2.3 From 39396409656b12940ffe9b715f13e23ac4290eca Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 23 Jan 2020 15:48:15 +0100 Subject: Fix some qdoc-warnings src/corelib/tools/qmap.cpp:1199: (qdoc) warning: Can't link to 'QMultiMap::unite()' src/gui/kernel/qevent.cpp:949: (qdoc) warning: Unknown command '\see' src/gui/painting/qpaintengine_raster.cpp:344: (qdoc) warning: clang found diagnostics parsing \fn Type QRasterPaintEngine::type() const error: unknown type name 'Type' src/gui/doc/src/qtgui.qdoc:45: (qdoc) warning: Can't link to 'Build with CMake' examples/widgets/doc/src/gallery.qdoc:28: (qdoc) warning: Cannot find file 'widgets/gallery/gallery.pro' or 'widgets/gallery/gallery.pyproject' src/widgets/kernel/qwidget.cpp:5950: (qdoc) warning: Can't link to 'setFilePath' src/widgets/kernel/qshortcut.cpp:542: (qdoc) warning: No such parameter 'context' in QShortcut::QShortcut() Change-Id: I2395af854efebef719d4762da466f69f7c5aab9e Reviewed-by: Paul Wicking --- examples/widgets/doc/src/gallery.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/widgets/doc/src/gallery.qdoc b/examples/widgets/doc/src/gallery.qdoc index a262374ce6..455099ddce 100644 --- a/examples/widgets/doc/src/gallery.qdoc +++ b/examples/widgets/doc/src/gallery.qdoc @@ -26,7 +26,7 @@ ****************************************************************************/ /*! - \example widgets/gallery + \example gallery \title Widgets Gallery Example \ingroup examples-widgets \brief The Widgets Gallery example shows widgets relevant for designing UIs. -- cgit v1.2.3 From 582311d1224cb196d8149bdfd8f178d5239c6b28 Mon Sep 17 00:00:00 2001 From: Sze Howe Koh Date: Mon, 27 Jan 2020 17:11:51 +0800 Subject: Doc: Replace some usages of 0/zero/null with \nullptr Change-Id: Ibe7de11fc6fc41477c35e7d653c6a911855deabb Reviewed-by: Paul Wicking --- examples/sql/doc/src/drilldown.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/sql/doc/src/drilldown.qdoc b/examples/sql/doc/src/drilldown.qdoc index 7a8aa2037a..8beb515a83 100644 --- a/examples/sql/doc/src/drilldown.qdoc +++ b/examples/sql/doc/src/drilldown.qdoc @@ -425,7 +425,7 @@ The \c findWindow() function simply searches through the list of existing windows, returning a pointer to the window that matches - the given item ID, or 0 if the window doesn't exists. + the given item ID, or \nullptr if the window doesn't exists. Finally, let's take a quick look at our custom \c ImageItem class: -- cgit v1.2.3 From 4bb897a3841f0f79150787e29fe122e1410bc119 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 10 Jan 2020 10:08:37 +0100 Subject: Deprecate all methods that use QMatrix Don't use QMatrix in implementation classes anymore. Task-number: QTBUG-46653 Fixes: QTBUG-81627 Change-Id: I4806c1302e42645dc6a608062c8d9c336ae8629b Reviewed-by: Leena Miettinen Reviewed-by: Laszlo Agocs Reviewed-by: Lars Knoll --- examples/widgets/graphicsview/chip/view.cpp | 4 ++-- examples/widgets/graphicsview/diagramscene/mainwindow.cpp | 4 ++-- examples/widgets/painting/affine/xform.cpp | 4 ++-- examples/widgets/painting/deform/pathdeform.cpp | 2 +- examples/widgets/painting/pathstroke/pathstroke.cpp | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'examples') diff --git a/examples/widgets/graphicsview/chip/view.cpp b/examples/widgets/graphicsview/chip/view.cpp index 21998dc2df..86da5b138f 100644 --- a/examples/widgets/graphicsview/chip/view.cpp +++ b/examples/widgets/graphicsview/chip/view.cpp @@ -234,11 +234,11 @@ void View::setupMatrix() { qreal scale = qPow(qreal(2), (zoomSlider->value() - 250) / qreal(50)); - QMatrix matrix; + QTransform matrix; matrix.scale(scale, scale); matrix.rotate(rotateSlider->value()); - graphicsView->setMatrix(matrix); + graphicsView->setTransform(matrix); setResetButtonEnabled(); } diff --git a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp index 3327d4d5df..04ff42e3eb 100644 --- a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp +++ b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp @@ -231,8 +231,8 @@ void MainWindow::fontSizeChanged(const QString &) void MainWindow::sceneScaleChanged(const QString &scale) { double newScale = scale.left(scale.indexOf(tr("%"))).toDouble() / 100.0; - QMatrix oldMatrix = view->matrix(); - view->resetMatrix(); + QTransform oldMatrix = view->transform(); + view->resetTransform(); view->translate(oldMatrix.dx(), oldMatrix.dy()); view->scale(newScale, newScale); } diff --git a/examples/widgets/painting/affine/xform.cpp b/examples/widgets/painting/affine/xform.cpp index 50acf0f814..4e7cb91ce1 100644 --- a/examples/widgets/painting/affine/xform.cpp +++ b/examples/widgets/painting/affine/xform.cpp @@ -223,7 +223,7 @@ void XFormView::setRotation(qreal r) m_rotation = r; QPointF center(pts->points().at(0)); - QMatrix m; + QTransform m; m.translate(center.x(), center.y()); m.rotate(m_rotation - old_rot); m.translate(-center.x(), -center.y()); @@ -236,7 +236,7 @@ void XFormView::timerEvent(QTimerEvent *e) { if (e->timerId() == timer.timerId()) { QPointF center(pts->points().at(0)); - QMatrix m; + QTransform m; m.translate(center.x(), center.y()); m.rotate(0.2); m.translate(-center.x(), -center.y()); diff --git a/examples/widgets/painting/deform/pathdeform.cpp b/examples/widgets/painting/deform/pathdeform.cpp index d5c8746247..961d5e5e99 100644 --- a/examples/widgets/painting/deform/pathdeform.cpp +++ b/examples/widgets/painting/deform/pathdeform.cpp @@ -374,7 +374,7 @@ void PathDeformRenderer::setText(const QString &text) } for (int i=0; i Date: Sat, 25 Jan 2020 20:43:13 +0100 Subject: QButtonGroup: deprecate overloaded signals Deprecate the overloaded signals buttonClicked/buttonPressed/buttonReleased/buttonToggled taking an int to avoid to need to use QOverload<> when connecting the signal. The id of a button in a button group can be easily fetched with QButtonGroup::id(). Task-number: QTBUG-80906 Change-Id: Idaaab54bbcb25cba543fc99f305b9f4743ee3ed8 Reviewed-by: Sze Howe Koh Reviewed-by: Richard Moe Gustavsen --- examples/widgets/animation/easing/window.cpp | 7 ++++--- examples/widgets/animation/easing/window.h | 2 +- examples/widgets/graphicsview/diagramscene/mainwindow.cpp | 13 +++++++------ examples/widgets/graphicsview/diagramscene/mainwindow.h | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) (limited to 'examples') diff --git a/examples/widgets/animation/easing/window.cpp b/examples/widgets/animation/easing/window.cpp index d1d6348361..378af07535 100644 --- a/examples/widgets/animation/easing/window.cpp +++ b/examples/widgets/animation/easing/window.cpp @@ -67,7 +67,7 @@ Window::Window(QWidget *parent) connect(m_ui.easingCurvePicker, &QListWidget::currentRowChanged, this, &Window::curveChanged); - connect(m_ui.buttonGroup, QOverload::of(&QButtonGroup::buttonClicked), + connect(m_ui.buttonGroup, QOverload::of(&QButtonGroup::buttonClicked), this, &Window::pathChanged); connect(m_ui.periodSpinBox, QOverload::of(&QDoubleSpinBox::valueChanged), this, &Window::periodChanged); @@ -180,9 +180,10 @@ void Window::curveChanged(int row) m_ui.overshootSpinBox->setEnabled(curveType >= QEasingCurve::InBack && curveType <= QEasingCurve::OutInBack); } -void Window::pathChanged(int index) +void Window::pathChanged(QAbstractButton *button) { - m_anim->setPathType((Animation::PathType)index); + const int index = m_ui.buttonGroup->id(button); + m_anim->setPathType(Animation::PathType(index)); } void Window::periodChanged(double value) diff --git a/examples/widgets/animation/easing/window.h b/examples/widgets/animation/easing/window.h index 541377a981..0c49dd6e8a 100644 --- a/examples/widgets/animation/easing/window.h +++ b/examples/widgets/animation/easing/window.h @@ -69,7 +69,7 @@ public: Window(QWidget *parent = nullptr); private slots: void curveChanged(int row); - void pathChanged(int index); + void pathChanged(QAbstractButton *button); void periodChanged(double); void amplitudeChanged(double); void overshootChanged(double); diff --git a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp index 04ff42e3eb..58b959dd10 100644 --- a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp +++ b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp @@ -113,13 +113,14 @@ void MainWindow::backgroundButtonGroupClicked(QAbstractButton *button) //! [1] //! [2] -void MainWindow::buttonGroupClicked(int id) +void MainWindow::buttonGroupClicked(QAbstractButton *button) { const QList buttons = buttonGroup->buttons(); - for (QAbstractButton *button : buttons) { - if (buttonGroup->button(id) != button) + for (QAbstractButton *myButton : buttons) { + if (myButton != button) button->setChecked(false); } + const int id = buttonGroup->id(button); if (id == InsertTextButton) { scene->setMode(DiagramScene::InsertText); } else { @@ -154,7 +155,7 @@ void MainWindow::deleteItem() //! [3] //! [4] -void MainWindow::pointerGroupClicked(int) +void MainWindow::pointerGroupClicked() { scene->setMode(DiagramScene::Mode(pointerTypeGroup->checkedId())); } @@ -334,7 +335,7 @@ void MainWindow::createToolBox() { buttonGroup = new QButtonGroup(this); buttonGroup->setExclusive(false); - connect(buttonGroup, QOverload::of(&QButtonGroup::buttonClicked), + connect(buttonGroup, QOverload::of(&QButtonGroup::buttonClicked), this, &MainWindow::buttonGroupClicked); QGridLayout *layout = new QGridLayout; layout->addWidget(createCellWidget(tr("Conditional"), DiagramItem::Conditional), 0, 0); @@ -528,7 +529,7 @@ void MainWindow::createToolbars() pointerTypeGroup = new QButtonGroup(this); pointerTypeGroup->addButton(pointerButton, int(DiagramScene::MoveItem)); pointerTypeGroup->addButton(linePointerButton, int(DiagramScene::InsertLine)); - connect(pointerTypeGroup, QOverload::of(&QButtonGroup::buttonClicked), + connect(pointerTypeGroup, QOverload::of(&QButtonGroup::buttonClicked), this, &MainWindow::pointerGroupClicked); sceneScaleCombo = new QComboBox; diff --git a/examples/widgets/graphicsview/diagramscene/mainwindow.h b/examples/widgets/graphicsview/diagramscene/mainwindow.h index e04224fbc7..9fcd1884ca 100644 --- a/examples/widgets/graphicsview/diagramscene/mainwindow.h +++ b/examples/widgets/graphicsview/diagramscene/mainwindow.h @@ -82,9 +82,9 @@ public: private slots: void backgroundButtonGroupClicked(QAbstractButton *button); - void buttonGroupClicked(int id); + void buttonGroupClicked(QAbstractButton *button); void deleteItem(); - void pointerGroupClicked(int id); + void pointerGroupClicked(); void bringToFront(); void sendToBack(); void itemInserted(DiagramItem *item); -- cgit v1.2.3