: QQuickItem(*(new QQuickCanvasItemPrivate), parent)
{
setFlag(ItemHasContents);
- connect(this, SIGNAL(sceneGraphInvalidated()), this, SLOT(invalidateSG()));
}
QQuickCanvasItem::~QQuickCanvasItem()
}
}
-void QQuickCanvasItem::invalidateSG()
+void QQuickCanvasItem::invalidateSceneGraph()
{
Q_D(QQuickCanvasItem);
d->context->deleteLater();
private Q_SLOTS:
void sceneGraphInitialized();
void checkAnimationCallbacks();
- void invalidateSG();
+ void invalidateSceneGraph();
protected:
void componentComplete();
QQuickItem(*new QQuickFramebufferObjectPrivate, parent)
{
setFlag(ItemHasContents);
- connect(this, SIGNAL(sceneGraphInvalidated()), this, SLOT(invalidateSG()));
}
/*!
d->node = 0;
}
-void QQuickFramebufferObject::invalidateSG()
+void QQuickFramebufferObject::invalidateSceneGraph()
{
Q_D(QQuickFramebufferObject);
d->node = 0;
void textureFollowsItemSizeChanged(bool);
private Q_SLOTS:
- void invalidateSG();
+ void invalidateSceneGraph();
};
QT_END_NAMESPACE
QQuickImage::QQuickImage(QQuickItem *parent)
: QQuickImageBase(*(new QQuickImagePrivate), parent)
{
- connect(this, SIGNAL(sceneGraphInvalidated()), this, SLOT(invalidateSG()));
}
QQuickImage::QQuickImage(QQuickImagePrivate &dd, QQuickItem *parent)
: QQuickImageBase(dd, parent)
{
- connect(this, SIGNAL(sceneGraphInvalidated()), this, SLOT(invalidateSG()));
}
QQuickImage::~QQuickImage()
return d->provider;
}
-void QQuickImage::invalidateSG()
+void QQuickImage::invalidateSceneGraph()
{
Q_D(QQuickImage);
delete d->provider;
Q_REVISION(1) void mipmapChanged(bool);
private Q_SLOTS:
- void invalidateSG();
+ void invalidateSceneGraph();
protected:
QQuickImage(QQuickImagePrivate &dd, QQuickItem *parent);
\list
\li The scene graph is invalidated; This can happen, for instance,
- if the window is hidden using QQuickWindow::hide(). The signal
- QQuickItem::sceneGraphInvalidated() is emitted on the rendering
- thread and the GUI thread is blocked for the duration of this
- call. Graphics resources can be deleted directly when this signal
- is connected to using a Qt::DirectConnection.
+ if the window is hidden using QQuickWindow::hide(). If the item
+ class implements a \c slot named \c invalidateSceneGraph(), this
+ slot will be called on the rendering thread while the GUI thread
+ is blocked. This is equivalent to connecting to
+ QQuickWindow::sceneGraphInvalidated(). The OpenGL context of this
+ item's window will be bound when this slot is called. The only
+ exception is if the native OpenGL has been destroyed outside Qt's
+ control, for instance through \c EGL_CONTEXT_LOST.
\li The item is removed from the scene; If an item is taken out of
the scene, for instance because it's parent was set to \c null or
Q_ASSERT(window == 0);
window = c;
- if (q->flags() & QQuickItem::ItemHasContents) {
- QObject::connect(window, SIGNAL(sceneGraphInvalidated()), q, SIGNAL(sceneGraphInvalidated()), Qt::DirectConnection);
- QObject::connect(window, SIGNAL(sceneGraphInitialized()), q, SIGNAL(sceneGraphInitialized()), Qt::DirectConnection);
- }
-
if (polishScheduled)
QQuickWindowPrivate::get(window)->itemsToPolish.insert(q);
if (--windowRefCount > 0)
return; // There are still other references, so don't set window to null yet.
- if (q->flags() & QQuickItem::ItemHasContents) {
- QObject::disconnect(window, SIGNAL(sceneGraphInvalidated()), q, SIGNAL(sceneGraphInvalidated()));
- QObject::disconnect(window, SIGNAL(sceneGraphInitialized()), q, SIGNAL(sceneGraphInitialized()));
- }
-
q->releaseResources();
removeFromDirtyList();
QQuickWindowPrivate *c = QQuickWindowPrivate::get(window);
if (int(flags & ItemClipsChildrenToShape) != int(d->flags & ItemClipsChildrenToShape))
d->dirty(QQuickItemPrivate::Clip);
- if (window() && (flags & ItemHasContents) ^ (d->flags & ItemHasContents)) {
- if (flags & ItemHasContents) {
- connect(window(), SIGNAL(sceneGraphInvalidated()), this, SIGNAL(sceneGraphInvalidated()), Qt::DirectConnection);
- connect(window(), SIGNAL(sceneGraphInitialized()), this, SIGNAL(sceneGraphInitialized()), Qt::DirectConnection);
- } else {
- disconnect(window(), SIGNAL(sceneGraphInvalidated()), this, SIGNAL(sceneGraphInvalidated()));
- disconnect(window(), SIGNAL(sceneGraphInitialized()), this, SIGNAL(sceneGraphInitialized()));
- }
- }
-
d->flags = flags;
}
/*!
- \fn void QQuickItem::sceneGraphInvalidated()
-
- This signal is emitted when the scene graph is invalidated for
- items that have the ItemHasContents flag set.
-
- QSGNode instances will be cleaned up by the scene graph
- automatically. An application will only need to react to this signal
- to clean up resources that are stored and managed outside the
- QSGNode structure returned from updatePaintNode().
-
- When the scene graph is using a dedicated render thread, this
- signal will be emitted on the scene graph's render thread. The
- GUI thread is blocked for the duration of this call. Connections
- should for this reason be made using Qt::DirectConnection.
-
- The OpenGL context of this item's window will be bound when this
- signal is emitted. The only exception is if the native OpenGL has
- been destroyed outside Qt's control, for instance through
- EGL_CONTEXT_LOST.
-
- \since 5.4
- \since QtQuick 2.4
-
- \sa QQuickWindow::sceneGraphInvalidated(), {Graphics Resource Handling}
- */
-
-/*!
- \fn void QQuickItem::sceneGraphInitialized()
-
- This signal is emitted when the scene graph is initialized for
- items that have the ItemHasContents flag set.
-
- When the scene graph is using a dedicated render thread, this
- function will be called on the scene graph's render thread. The
- GUI thread is blocked for the duration of this call. Connections
- should for this reason be made using Qt::DirectConnection.
-
- The OpenGL context of this item's window will be bound when
- this signal is emitted.
-
- \since 5.4
- \since QtQuick 2.4
-
- \sa QQuickWindow::sceneGraphInitialized()
- */
-
-/*!
\qmlproperty real QtQuick::Item::x
\qmlproperty real QtQuick::Item::y
\qmlproperty real QtQuick::Item::width
void implicitWidthChanged();
void implicitHeightChanged();
- Q_REVISION(2) void sceneGraphInvalidated();
- Q_REVISION(2) void sceneGraphInitialized();
-
protected:
virtual bool event(QEvent *);
: QQuickItem(*(new QQuickPaintedItemPrivate), parent)
{
setFlag(ItemHasContents);
- connect(this, SIGNAL(sceneGraphInvalidated()), this, SLOT(invalidateSG()));
}
/*!
: QQuickItem(dd, parent)
{
setFlag(ItemHasContents);
- connect(this, SIGNAL(sceneGraphInvalidated()), this, SLOT(invalidateSG()));
}
/*!
d->node = 0; // Managed by the scene graph, just clear the pointer.
}
-void QQuickPaintedItem::invalidateSG()
+void QQuickPaintedItem::invalidateSceneGraph()
{
Q_D(QQuickPaintedItem);
delete d->textureProvider;
void releaseResources() Q_DECL_OVERRIDE;
private Q_SLOTS:
- void invalidateSG();
+ void invalidateSceneGraph();
private:
Q_DISABLE_COPY(QQuickPaintedItem)
, m_grab(true)
{
setFlag(ItemHasContents);
- connect(this, SIGNAL(sceneGraphInvalidated()), this, SLOT(invalidateSG()));
}
QQuickShaderEffectSource::~QQuickShaderEffectSource()
return node;
}
-void QQuickShaderEffectSource::invalidateSG()
+void QQuickShaderEffectSource::invalidateSceneGraph()
{
if (m_texture)
delete m_texture;
private Q_SLOTS:
void sourceItemDestroyed(QObject *item);
- void invalidateSG();
+ void invalidateSceneGraph();
protected:
virtual void releaseResources();
p->dirty(QQuickItemPrivate::Window);
}
+ // Qt 6: Make invalidateSceneGraph a virtual member of QQuickItem
+ if (p->flags & QQuickItem::ItemHasContents) {
+ const QMetaObject *mo = item->metaObject();
+ int index = mo->indexOfSlot("invalidateSceneGraph()");
+ if (index >= 0) {
+ const QMetaMethod &method = mo->method(index);
+ // Skip functions named invalidateSceneGraph() in QML items.
+ if (strstr(method.enclosingMetaObject()->className(), "_QML_") == 0)
+ method.invoke(item, Qt::DirectConnection);
+ }
+ }
+
for (int ii = 0; ii < p->childItems.count(); ++ii)
cleanupNodesOnShutdown(p->childItems.at(ii));
}
void visualParentOwnership();
void visualParentOwnershipWindow();
- void testSGInitializeAndInvalidate();
+ void testSGInvalidate();
void objectChildTransform();
}
}
-void tst_qquickitem::testSGInitializeAndInvalidate()
+class InvalidatedItem : public QQuickItem {
+ Q_OBJECT
+signals:
+ void invalidated();
+public slots:
+ void invalidateSceneGraph() { emit invalidated(); }
+};
+
+void tst_qquickitem::testSGInvalidate()
{
for (int i=0; i<2; ++i) {
QScopedPointer<QQuickView> view(new QQuickView());
- QQuickItem *item = new QQuickItem();
+ InvalidatedItem *item = new InvalidatedItem();
- int expected;
+ int expected = 0;
if (i == 0) {
// First iteration, item has contents and should get signals
expected = 1;
item->setFlag(QQuickItem::ItemHasContents, true);
} else {
// Second iteration, item does not have content and will not get signals
- expected = 0;
}
- QSignalSpy initializeSpy(item, SIGNAL(sceneGraphInitialized()));
- QSignalSpy invalidateSpy(item, SIGNAL(sceneGraphInvalidated()));
+ QSignalSpy invalidateSpy(item, SIGNAL(invalidated()));
item->setParentItem(view->contentItem());
view->show();
QVERIFY(QTest::qWaitForWindowExposed(view.data()));
- QCOMPARE(initializeSpy.size(), expected);
delete view.take();
QCOMPARE(invalidateSpy.size(), expected);