Re-implemented itemChange must always call QQuickItem::itemChange
authorShawn Rutledge <shawn.rutledge@digia.com>
Thu, 25 Apr 2013 09:16:40 +0000 (11:16 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 26 Apr 2013 10:57:03 +0000 (12:57 +0200)
Documentation for that fact, and the windowChanged signal.
Fix existing QQuickItem subclasses which didn't call
QQuickItem::itemChange.  Examples should rather connect to the
windowChanged() signal.

Change-Id: Ieddcdbe69f849ddb120b64be9c5e0a21393b0ed9
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
examples/quick/scenegraph/openglunderqml/squircle.cpp
examples/quick/scenegraph/openglunderqml/squircle.h
src/particles/qquickparticlepainter.cpp
src/quick/items/qquickitem.cpp

index d9f49c9..1f87412 100644 (file)
@@ -93,8 +93,8 @@
 
     For our paint function to be called, we need to connect to the
     window's signals. When Squircle object is populated into the
-    scene, the itemChange function is called with the change type \c
-    ItemSceneChange. We connect \l QQuickWindow::beforeRendering() to
+    scene, the windowChanged signal is emitted. In our handler,
+    we connect \l QQuickWindow::beforeRendering() to
     \c paint() to do the rendering, and \l
     QQuickWindow::beforeSynchronizing() to \c sync() to copy the state
     of the \c t property for the upcoming frame.
 
     We import the Squircle QML type with the name we registered in the
     \c main() function. We then instantiate it and create a running
-    NumberAnimation on the its \c t property.
+    NumberAnimation on its \c t property.
 
     \snippet scenegraph/openglunderqml/main.qml 2
 
index 84509fb..8ceb9c5 100644 (file)
@@ -51,6 +51,7 @@ Squircle::Squircle()
     , m_t(0)
     , m_thread_t(0)
 {
+    connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
 }
 //! [7]
 
@@ -66,17 +67,11 @@ void Squircle::setT(qreal t)
 }
 //! [8]
 
-
 //! [1]
-void Squircle::itemChange(ItemChange change, const ItemChangeData &)
+void Squircle::handleWindowChanged(QQuickWindow *win)
 {
-    // The ItemSceneChange event is sent when we are first attached to a window.
-    if (change == ItemSceneChange) {
-        QQuickWindow *win = window();
-        if (!win)
-            return;
+    if (win) {
 //! [1]
-
         // Connect the beforeRendering signal to our paint function.
         // Since this call is executed on the rendering thread it must be
         // a Qt::DirectConnection
index e292ca3..449e02b 100644 (file)
@@ -61,14 +61,14 @@ public:
 signals:
     void tChanged();
 
-protected:
-    void itemChange(ItemChange change, const ItemChangeData &);
-
 public slots:
     void paint();
     void cleanup();
     void sync();
 
+private slots:
+    void handleWindowChanged(QQuickWindow *win);
+
 private:
     QOpenGLShaderProgram *m_program;
 
index a84f4a6..694391a 100644 (file)
@@ -80,8 +80,8 @@ void QQuickParticlePainter::itemChange(ItemChange change, const ItemChangeData &
         m_window = data.window;
         if (m_window)
             connect(m_window, SIGNAL(sceneGraphInvalidated()), this, SLOT(sceneGraphInvalidated()), Qt::DirectConnection);
-
     }
+    QQuickItem::itemChange(change, data);
 }
 
 void QQuickParticlePainter::componentComplete()
index 44d11ac..111e74e 100644 (file)
@@ -2346,13 +2346,16 @@ void QQuickItem::stackAfter(const QQuickItem *sibling)
         QQuickItemPrivate::get(parentPrivate->childItems.at(ii))->siblingOrderChanged();
 }
 
+/*! \fn void QQuickItem::windowChanged(QQuickWindow *window)
+    This signal is emitted when the item's \a window changes.
+*/
+
 /*!
   Returns the window in which this item is rendered.
 
-  The item does not have a window until it has been assigned into a scene. To
-  get notification about this, reimplement the itemChange() function and
-  listen for the ItemSceneChange change. The itemChange() function is called
-  both when the item is entered into a scene and when it is removed from a scene.
+  The item does not have a window until it has been assigned into a scene. The
+  \l windowChanged signal provides a notification both when the item is entered
+  into a scene and when it is removed from a scene.
   */
 QQuickWindow *QQuickItem::window() const
 {
@@ -4457,6 +4460,13 @@ void QQuickItemPrivate::deliverDragEvent(QEvent *e)
 
     \a value contains extra information relating to the change, when
     applicable.
+
+    If you re-implement this method in a subclass, be sure to call
+    \code
+    QQuickItem::itemChange(change, value);
+    \endcode
+    typically at the end of your implementation, to ensure the
+    \l windowChanged signal will be emitted.
   */
 void QQuickItem::itemChange(ItemChange change, const ItemChangeData &value)
 {