Expose Qt Quick gradient conversion code privately.
authorMitch Curtis <mitch.curtis@digia.com>
Fri, 7 Feb 2014 11:45:15 +0000 (12:45 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 12 Feb 2014 09:34:50 +0000 (10:34 +0100)
Rectangle is currently the only item that supports gradients, but other
items have been introduced (within Qt Quick Enterprise Controls) which
need QQuickGradient => QLinearGradient conversion, and it doesn't make
sense to duplicate the gradient stop conversion code.

The QQuickGradient and QQuickGradientStop classes need to be privately
exported so that modules that use private Qt API can use the classes
with quick-private.

Change-Id: I8b130ff5384d9481d3f29510b3de61f7d8f775e2
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
src/quick/items/qquickrectangle.cpp
src/quick/items/qquickrectangle_p.h
tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp

index 48f79a2..e50f772 100644 (file)
@@ -255,6 +255,18 @@ QQmlListProperty<QQuickGradientStop> QQuickGradient::stops()
     return QQmlListProperty<QQuickGradientStop>(this, m_stops);
 }
 
+QGradientStops QQuickGradient::gradientStops() const
+{
+    QGradientStops stops;
+    for (int i = 0; i < m_stops.size(); ++i){
+        int j = 0;
+        while (j < stops.size() && stops.at(j).first < m_stops[i]->position())
+            j++;
+        stops.insert(j, QGradientStop(m_stops.at(i)->position(), m_stops.at(i)->color()));
+    }
+    return stops;
+}
+
 void QQuickGradient::doUpdate()
 {
     emit updated();
@@ -480,13 +492,7 @@ QSGNode *QQuickRectangle::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData
 
     QGradientStops stops;
     if (d->gradient) {
-        QList<QQuickGradientStop *> qxstops = d->gradient->m_stops;
-        for (int i = 0; i < qxstops.size(); ++i){
-            int j = 0;
-            while (j < stops.size() && stops.at(j).first < qxstops[i]->position())
-                j++;
-            stops.insert(j, QGradientStop(qxstops.at(i)->position(), qxstops.at(i)->color()));
-        }
+        stops = d->gradient->gradientStops();
     }
     rectangle->setGradientStops(stops);
 
index 009512a..09b530c 100644 (file)
@@ -81,7 +81,7 @@ private:
     bool m_valid : 1;
 };
 
-class Q_AUTOTEST_EXPORT QQuickGradientStop : public QObject
+class Q_QUICK_PRIVATE_EXPORT QQuickGradientStop : public QObject
 {
     Q_OBJECT
 
@@ -105,7 +105,7 @@ private:
     QColor m_color;
 };
 
-class Q_AUTOTEST_EXPORT QQuickGradient : public QObject
+class Q_QUICK_PRIVATE_EXPORT QQuickGradient : public QObject
 {
     Q_OBJECT
 
@@ -118,6 +118,8 @@ public:
 
     QQmlListProperty<QQuickGradientStop> stops();
 
+    QGradientStops gradientStops() const;
+
 Q_SIGNALS:
     void updated();
 
index 204a3ff..5657ec4 100644 (file)
@@ -79,6 +79,13 @@ void tst_qquickrectangle::gradient()
     QCOMPARE(stops.at(&stops, 1)->position(), 1.0);
     QCOMPARE(stops.at(&stops, 1)->color(), QColor("white"));
 
+    QGradientStops gradientStops = grad->gradientStops();
+    QCOMPARE(gradientStops.count(), 2);
+    QCOMPARE(gradientStops.at(0).first, 0.0);
+    QCOMPARE(gradientStops.at(0).second, QColor("gray"));
+    QCOMPARE(gradientStops.at(1).first, 1.0);
+    QCOMPARE(gradientStops.at(1).second, QColor("white"));
+
     QMetaObject::invokeMethod(rect, "resetGradient");
 
     grad = rect->gradient();