diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2018-07-25 08:40:07 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2018-07-30 09:44:05 +0000 |
commit | 12a08ee8eaa27be7dc500b1c15348e8f692949dc (patch) | |
tree | 4b5b331f0fa96caf1f0c7eeb822b633934e6114e | |
parent | 4e11d09fdef369af130c86a81df599ee3273ac7d (diff) |
QQuickIconImage: prevent color from being applied twice
QQuickIconImage::componentComplete() calls
QQuickIconImagePrivate::updateIcon(), which loads the icon's image via
QQuickImageBase::load(). That eventually calls
QQuickImageBase::requestFinished(), which calls
QQuickIconImage::pixmapChange(). That then calls
QQuickIconImagePrivate::updateFillMode(), which can in turn cause
QQuickIconImage::pixmapChange() to be called again, causing recursion.
This recursion resulted in icon.color being applied twice.
We already have a recursion check in place in
QQuickIconImagePrivate::updateFillMode(), so we can reuse that in
QQuickIconImage::pixmapChange() to know whether or not we should apply
the color to the image.
Task-number: QTBUG-69506
Change-Id: I5cd9edaa524c7ceb9c41c53a9efefcc4c647e246
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r-- | src/quickcontrols2/qquickiconimage.cpp | 3 | ||||
-rw-r--r-- | tests/auto/qquickiconimage/data/translucentColors.qml | 67 | ||||
-rw-r--r-- | tests/auto/qquickiconimage/tst_qquickiconimage.cpp | 33 |
3 files changed, 101 insertions, 2 deletions
diff --git a/src/quickcontrols2/qquickiconimage.cpp b/src/quickcontrols2/qquickiconimage.cpp index c8357647..d86afd7f 100644 --- a/src/quickcontrols2/qquickiconimage.cpp +++ b/src/quickcontrols2/qquickiconimage.cpp @@ -198,7 +198,8 @@ void QQuickIconImage::pixmapChange() QQuickImage::pixmapChange(); d->updateFillMode(); - if (d->color.alpha() > 0) { + // Don't apply the color if we're recursing (updateFillMode() can cause us to recurse). + if (!d->updatingFillMode && d->color.alpha() > 0) { QImage image = d->pix.image(); if (!image.isNull()) { QPainter painter(&image); diff --git a/tests/auto/qquickiconimage/data/translucentColors.qml b/tests/auto/qquickiconimage/data/translucentColors.qml new file mode 100644 index 00000000..49178d76 --- /dev/null +++ b/tests/auto/qquickiconimage/data/translucentColors.qml @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.10 +import QtQuick.Controls 2.3 +import QtQuick.Controls.impl 2.3 + +ApplicationWindow { + width: 500 + height: 500 + visible: true + + IconImage { + width: Math.min(250, parent.width) + height: Math.min(250, parent.height) + source: "qrc:/icons/testtheme/22x22/actions/color-test-original.png" + sourceSize: Qt.size(250, 0) + color: Qt.rgba(0, 0, 0, 0.5) + } +} diff --git a/tests/auto/qquickiconimage/tst_qquickiconimage.cpp b/tests/auto/qquickiconimage/tst_qquickiconimage.cpp index 1dab0784..bc24c4fb 100644 --- a/tests/auto/qquickiconimage/tst_qquickiconimage.cpp +++ b/tests/auto/qquickiconimage/tst_qquickiconimage.cpp @@ -1,4 +1,4 @@ -/**************************************************************************** +/**************************************************************************** ** ** Copyright (C) 2017 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ @@ -30,6 +30,7 @@ #include <QtTest/qsignalspy.h> #include <QtCore/qmath.h> +#include <QtQml/qqmlapplicationengine.h> #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcomponent.h> #include <QtQml/qqmlfileselector.h> @@ -69,6 +70,7 @@ private slots: void color(); void fileSelectors(); void imageProvider(); + void translucentColors(); private: void setTheme(); @@ -528,6 +530,35 @@ void tst_qquickiconimage::imageProvider() QCOMPARE(image.pixelColor(image.width() / 2, image.height() / 2), QColor(Qt::red)); } +/* + QQuickIconImage::componentComplete() calls QQuickIconImagePrivate::updateIcon(), + which loads the icon's image via QQuickImageBase::load(). That eventually calls + QQuickImageBase::requestFinished(), which calls QQuickIconImage::pixmapChange(). + That then calls QQuickIconImagePrivate::updateFillMode(), which can in turn + cause QQuickIconImage::pixmapChange() to be called again, causing recursion. + + This was a problem because it resulted in icon.color being applied twice. + + This test checks that that doesn't happen. +*/ +void tst_qquickiconimage::translucentColors() +{ + if (QGuiApplication::platformName() == QLatin1String("offscreen")) + QSKIP("grabToImage() doesn't work on the \"offscreen\" platform plugin (QTBUG-63185)"); + + // Doesn't reproduce with QQuickView. + QQmlApplicationEngine engine; + engine.load(testFileUrl("translucentColors.qml")); + QQuickWindow *window = qobject_cast<QQuickWindow*>(engine.rootObjects().first()); + + QQuickIconImage *iconImage = qobject_cast<QQuickIconImage*>(window->findChild<QQuickIconImage*>()); + QVERIFY(iconImage); + + const QImage image = grabItemToImage(iconImage); + QVERIFY(!image.isNull()); + QCOMPARE(image.pixelColor(image.width() / 2, image.height() / 2), QColor::fromRgba(0x80000000)); +} + int main(int argc, char *argv[]) { QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); |