Sort gradient stops for the convenience of the scenegraph
authorAlan Alpert <alan.alpert@nokia.com>
Wed, 27 Apr 2011 00:46:24 +0000 (10:46 +1000)
committerAlan Alpert <alan.alpert@nokia.com>
Wed, 27 Apr 2011 23:53:26 +0000 (09:53 +1000)
The scenegraph gradients require sorted graident stops, whereas QML does
not. Gradient stops are now sorted at the point they are passed into the
scenegraph.

Change-Id: I499dd00dc78e60dfc2053f2ee3691e61e0cf2a5d
Task-number: QTBUG-18494
Reviewed-by: Martin Jones
(cherry picked from commit 8cbd68b29224eed19f6ca6ec8186766c69a35c83)

src/declarative/items/qsgrectangle.cpp

index 247d633..cba6527 100644 (file)
@@ -267,8 +267,12 @@ QSGNode *QSGRectangle::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *da
     QGradientStops stops;
     if (d->gradient) {
         QList<QSGGradientStop *> qxstops = d->gradient->m_stops;
-        for (int i = 0; i < qxstops.size(); ++i)
-            stops.append(QGradientStop(qxstops.at(i)->position(), qxstops.at(i)->color()));
+        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()));
+        }
     }
     rectangle->setGradientStops(stops);