aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2012-07-03 15:04:19 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-03 07:27:22 +0200
commitf39c22ecec295d44eb1604e0a5dd5400093f0322 (patch)
tree836c1f2d9abe90bf6214e19301dd518a65201f8b
parente1b3ad7c831023c3e336414a16b69773adea4e26 (diff)
Allow resetting a Rectangle gradient.
If a gradient and a color are set on a rectangle, the gradient is used. This means that if you wish to override the gradient on a component with a color, you have to unset the gradient. Also remove the unused QQuickGradient::gradient() method. Task-number: QTBUG-23238 Change-Id: Ibd43cfe1bd4b867e4f6103f1d0dc0ed6176ab5c1 Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
-rw-r--r--src/quick/items/qquickrectangle.cpp24
-rw-r--r--src/quick/items/qquickrectangle_p.h6
-rw-r--r--tests/auto/quick/qquickrectangle/data/gradient.qml14
-rw-r--r--tests/auto/quick/qquickrectangle/qquickrectangle.pro12
-rw-r--r--tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp93
-rw-r--r--tests/auto/quick/quick.pro1
6 files changed, 128 insertions, 22 deletions
diff --git a/src/quick/items/qquickrectangle.cpp b/src/quick/items/qquickrectangle.cpp
index 3137ba93fd..608fd94ac1 100644
--- a/src/quick/items/qquickrectangle.cpp
+++ b/src/quick/items/qquickrectangle.cpp
@@ -240,13 +240,12 @@ void QQuickGradientStop::updateGradient()
To set the gradient stops, define them as children of the Gradient element.
*/
QQuickGradient::QQuickGradient(QObject *parent)
-: QObject(parent), m_gradient(0)
+: QObject(parent)
{
}
QQuickGradient::~QQuickGradient()
{
- delete m_gradient;
}
QQmlListProperty<QQuickGradientStop> QQuickGradient::stops()
@@ -254,24 +253,8 @@ QQmlListProperty<QQuickGradientStop> QQuickGradient::stops()
return QQmlListProperty<QQuickGradientStop>(this, m_stops);
}
-const QGradient *QQuickGradient::gradient() const
-{
- if (!m_gradient && !m_stops.isEmpty()) {
- m_gradient = new QLinearGradient(0,0,0,1.0);
- for (int i = 0; i < m_stops.count(); ++i) {
- const QQuickGradientStop *stop = m_stops.at(i);
- m_gradient->setCoordinateMode(QGradient::ObjectBoundingMode);
- m_gradient->setColorAt(stop->position(), stop->color());
- }
- }
-
- return m_gradient;
-}
-
void QQuickGradient::doUpdate()
{
- delete m_gradient;
- m_gradient = 0;
emit updated();
}
@@ -426,6 +409,11 @@ void QQuickRectangle::setGradient(QQuickGradient *gradient)
update();
}
+void QQuickRectangle::resetGradient()
+{
+ setGradient(0);
+}
+
/*!
\qmlproperty real QtQuick2::Rectangle::radius
This property holds the corner radius used to draw a rounded rectangle.
diff --git a/src/quick/items/qquickrectangle_p.h b/src/quick/items/qquickrectangle_p.h
index f077e7fbe2..0ac2ea6aaa 100644
--- a/src/quick/items/qquickrectangle_p.h
+++ b/src/quick/items/qquickrectangle_p.h
@@ -120,8 +120,6 @@ public:
QQmlListProperty<QQuickGradientStop> stops();
- const QGradient *gradient() const;
-
Q_SIGNALS:
void updated();
@@ -130,7 +128,6 @@ private:
private:
QList<QQuickGradientStop *> m_stops;
- mutable QGradient *m_gradient;
friend class QQuickRectangle;
friend class QQuickGradientStop;
};
@@ -141,7 +138,7 @@ class Q_AUTOTEST_EXPORT QQuickRectangle : public QQuickItem
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
- Q_PROPERTY(QQuickGradient *gradient READ gradient WRITE setGradient)
+ Q_PROPERTY(QQuickGradient *gradient READ gradient WRITE setGradient RESET resetGradient)
Q_PROPERTY(QQuickPen * border READ border CONSTANT)
Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged)
public:
@@ -154,6 +151,7 @@ public:
QQuickGradient *gradient() const;
void setGradient(QQuickGradient *gradient);
+ void resetGradient();
qreal radius() const;
void setRadius(qreal radius);
diff --git a/tests/auto/quick/qquickrectangle/data/gradient.qml b/tests/auto/quick/qquickrectangle/data/gradient.qml
new file mode 100644
index 0000000000..6d2a3c4646
--- /dev/null
+++ b/tests/auto/quick/qquickrectangle/data/gradient.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.0
+
+Rectangle {
+
+ function resetGradient() {
+ gradient = undefined
+ }
+
+ gradient: Gradient {
+ GradientStop { position: 0.0; color: "gray" }
+ GradientStop { position: 1.0; color: "white" }
+ }
+}
+
diff --git a/tests/auto/quick/qquickrectangle/qquickrectangle.pro b/tests/auto/quick/qquickrectangle/qquickrectangle.pro
new file mode 100644
index 0000000000..daefb5fe75
--- /dev/null
+++ b/tests/auto/quick/qquickrectangle/qquickrectangle.pro
@@ -0,0 +1,12 @@
+CONFIG += testcase
+TARGET = tst_qquickrectangle
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_qquickrectangle.cpp
+
+include (../../shared/util.pri)
+include (../shared/util.pri)
+
+TESTDATA = data/*
+
+QT += core-private gui-private qml-private quick-private testlib
diff --git a/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp b/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp
new file mode 100644
index 0000000000..dd667c2ab7
--- /dev/null
+++ b/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qtest.h>
+
+#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlcomponent.h>
+#include <private/qquickrectangle_p.h>
+
+#include "../../shared/util.h"
+
+class tst_qquickrectangle : public QQmlDataTest
+{
+ Q_OBJECT
+public:
+ tst_qquickrectangle();
+
+private slots:
+ void gradient();
+
+private:
+ QQmlEngine engine;
+};
+
+tst_qquickrectangle::tst_qquickrectangle()
+{
+}
+
+void tst_qquickrectangle::gradient()
+{
+ QQmlComponent component(&engine, testFileUrl("gradient.qml"));
+ QQuickRectangle *rect = qobject_cast<QQuickRectangle*>(component.create());
+ QVERIFY(rect);
+
+ QQuickGradient *grad = rect->gradient();
+ QVERIFY(grad);
+
+ QQmlListProperty<QQuickGradientStop> stops = grad->stops();
+ QCOMPARE(stops.count(&stops), 2);
+ QCOMPARE(stops.at(&stops, 0)->position(), 0.0);
+ QCOMPARE(stops.at(&stops, 0)->color(), QColor("gray"));
+ QCOMPARE(stops.at(&stops, 1)->position(), 1.0);
+ QCOMPARE(stops.at(&stops, 1)->color(), QColor("white"));
+
+ QMetaObject::invokeMethod(rect, "resetGradient");
+
+ grad = rect->gradient();
+ QVERIFY(!grad);
+
+ delete rect;
+}
+
+
+QTEST_MAIN(tst_qquickrectangle)
+
+#include "tst_qquickrectangle.moc"
diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro
index fd78da2746..aed2ae964e 100644
--- a/tests/auto/quick/quick.pro
+++ b/tests/auto/quick/quick.pro
@@ -60,6 +60,7 @@ QUICKTESTS = \
qquickpathview \
qquickpincharea \
qquickpositioners \
+ qquickrectangle \
qquickrepeater \
qquickshadereffect \
qquickspritesequence \