Fix PaintedItem redraw bug
authorCharles Yin <charles.yin@nokia.com>
Thu, 27 Oct 2011 03:06:57 +0000 (13:06 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 28 Oct 2011 20:31:32 +0000 (22:31 +0200)
1) After QQuickItem::update() being called (means item's content is dirty),
   the paint() function should always been called, so the contentsDirty
   and geometryDirty flags are not needed.
2) Update the smile example to validate the above changes

Task-number:QTBUG-22250
Change-Id: I5a72f18e6982bdb3ba23e78a253c2876aca2e8cb
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Reviewed-by: Yoann Lopes <yoann.lopes@nokia.com>
examples/declarative/painteditem/smile/main.cpp
examples/declarative/painteditem/smile/smile.qml
src/declarative/items/qquickpainteditem.cpp
src/declarative/items/qquickpainteditem.h
src/declarative/items/qquickpainteditem_p.h
src/declarative/scenegraph/util/qsgpainternode.cpp
src/declarative/scenegraph/util/qsgpainternode_p.h

index 1f0b3a3..dc76e71 100644 (file)
 #include <QtDeclarative/qdeclarative.h>
 #include <QtDeclarative/qquickview.h>
 #include <QtDeclarative/qquickpainteditem.h>
-
 class MyPaintItem : public QQuickPaintedItem
 {
     Q_OBJECT
+    Q_PROPERTY(QString face READ face WRITE setFace NOTIFY faceChanged)
 public:
-    MyPaintItem() : QQuickPaintedItem()
+    MyPaintItem()
+      : QQuickPaintedItem()
+      , m_face(QLatin1String(":-)"))
     {
         setAntialiasing(true);
     }
-
+    QString face() const {return m_face;}
+    void setFace(const QString &face) {
+       if (m_face != face) {
+          m_face = face;
+          emit faceChanged();
+       }
+    }
     virtual void paint(QPainter *p)
     {
         QRectF rect(0, 0, width(), height());
@@ -62,8 +70,12 @@ public:
         p->drawEllipse(rect);
         p->setPen(Qt::black);
         p->setFont(QFont(QLatin1String("Times"), qRound(rect.height() / 2)));
-        p->drawText(rect, Qt::AlignCenter, QLatin1String(":-)"));
+        p->drawText(rect, Qt::AlignCenter, m_face);
     }
+signals:
+    void faceChanged();
+private:
+    QString m_face;
 };
 
 int main(int argc, char ** argv)
index bc4bd26..e09d9b1 100644 (file)
@@ -42,16 +42,91 @@ import QtQuick 2.0
 import MyModule 1.0
 
 Rectangle {
-    width: 480
-    height: 480
+    width: 500
+    height: 500
     gradient: Gradient {
         GradientStop { position: 0.0; color: "#00249a" }
         GradientStop { position: 0.7; color: "#ffd94f" }
         GradientStop { position: 1.0; color: "#ffa322" }
     }
     MyPaintItem {
-        anchors.fill: parent
+        renderTarget:PaintedItem.Image
+        clip:true
+        width:240
+        height:240
+        anchors.left : parent.left
+        anchors.top :parent.top
         anchors.margins: 10
         smooth: true
+        MouseArea {
+          anchors.fill:parent
+          onClicked: {
+           if (parent.face == ":-)")
+              parent.face = ":-(";
+           else
+              parent.face = ":-)";
+           parent.update()
+          }
+        }
     }
-}
+    MyPaintItem {
+        clip:true
+        renderTarget:PaintedItem.Image
+        width:240
+        height:240
+        anchors.right : parent.right
+        anchors.top :parent.top
+        anchors.margins: 10
+        smooth: true
+        MouseArea {
+          anchors.fill:parent
+          onClicked: {
+           if (parent.face == ":-)")
+              parent.face = ":-(";
+           else
+              parent.face = ":-)";
+           parent.update()
+          }
+        }
+    }
+    MyPaintItem {
+        clip:true
+        renderTarget:PaintedItem.Image
+        width:240
+        height:240
+        anchors.left : parent.left
+        anchors.bottom :parent.bottom
+        anchors.margins: 10
+        smooth: true
+        MouseArea {
+          anchors.fill:parent
+          onClicked: {
+           if (parent.face == ":-)")
+              parent.face = ":-(";
+           else
+              parent.face = ":-)";
+           parent.update()
+          }
+        }
+    }
+    MyPaintItem {
+        clip:true
+        renderTarget:PaintedItem.Image
+        width:240
+        height:240
+        anchors.right : parent.right
+        anchors.bottom :parent.bottom
+        anchors.margins: 10
+        smooth: true
+        MouseArea {
+          anchors.fill:parent
+          onClicked: {
+           if (parent.face == ":-)")
+              parent.face = ":-(";
+           else
+              parent.face = ":-)";
+           parent.update()
+          }
+        }
+    }
+}
\ No newline at end of file
index ac67f6a..4d96da2 100644 (file)
@@ -123,8 +123,6 @@ QQuickPaintedItemPrivate::QQuickPaintedItemPrivate()
     , fillColor(Qt::transparent)
     , renderTarget(QQuickPaintedItem::Image)
     , performanceHints(0)
-    , geometryDirty(false)
-    , contentsDirty(false)
     , opaquePainting(false)
     , antialiasing(false)
     , mipmap(false)
@@ -171,7 +169,6 @@ QQuickPaintedItem::~QQuickPaintedItem()
 void QQuickPaintedItem::update(const QRect &rect)
 {
     Q_D(QQuickPaintedItem);
-    d->contentsDirty = true;
 
     if (rect.isNull() && !d->dirtyRect.isNull())
         d->dirtyRect = contentsBoundingRect().toAlignedRect();
@@ -492,17 +489,6 @@ void QQuickPaintedItem::setRenderTarget(RenderTarget target)
 */
 
 /*!
-    This function is called after the item's geometry has changed.
-*/
-void QQuickPaintedItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
-{
-    Q_D(QQuickPaintedItem);
-    d->geometryDirty = true;
-    QQuickItem::geometryChanged(newGeometry, oldGeometry);
-}
-
-
-/*!
     This function is called when the Scene Graph node associated to the item needs to
     be updated.
 */
@@ -531,11 +517,9 @@ QSGNode *QQuickPaintedItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDat
     node->setOpaquePainting(d->opaquePainting);
     node->setFillColor(d->fillColor);
     node->setContentsScale(d->contentsScale);
-    node->setDirty(d->contentsDirty || d->geometryDirty, d->dirtyRect);
+    node->setDirty(d->dirtyRect);
     node->update();
 
-    d->contentsDirty = false;
-    d->geometryDirty = false;
     d->dirtyRect = QRect();
 
     return node;
index 1ddfa25..b2da9e6 100644 (file)
@@ -114,7 +114,6 @@ Q_SIGNALS:
 
 protected:
     QQuickPaintedItem(QQuickPaintedItemPrivate &dd, QQuickItem *parent = 0);
-    virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
 
 private:
index 00061d9..b847b0a 100644 (file)
@@ -61,8 +61,6 @@ public:
 
     QRect dirtyRect;
 
-    bool geometryDirty : 1;
-    bool contentsDirty : 1;
     bool opaquePainting: 1;
     bool antialiasing: 1;
     bool mipmap: 1;
index a89dd75..f3e5202 100644 (file)
@@ -378,9 +378,9 @@ void QSGPainterNode::setSize(const QSize &size)
     m_dirtyTexture = true;
 }
 
-void QSGPainterNode::setDirty(bool d, const QRect &dirtyRect)
+void QSGPainterNode::setDirty(const QRect &dirtyRect)
 {
-    m_dirtyContents = d;
+    m_dirtyContents = true;
     m_dirtyRect = dirtyRect;
 
     if (m_mipmapping)
index c838ed1..8e95107 100644 (file)
@@ -83,7 +83,7 @@ public:
     void setSize(const QSize &size);
     QSize size() const { return m_size; }
 
-    void setDirty(bool d, const QRect &dirtyRect = QRect());
+    void setDirty(const QRect &dirtyRect = QRect());
 
     void setOpaquePainting(bool opaque);
     bool opaquePainting() const { return m_opaquePainting; }