VTK  9.3.0
QQuickVTKItem.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright (c) John Stone
3 // SPDX-License-Identifier: BSD-3-Clause
8 #ifndef QQuickVTKItem_h
9 #define QQuickVTKItem_h
10 
11 #include <QtQuick/QQuickItem>
12 
13 #include <QtCore/QScopedPointer>
14 
15 #include <functional>
16 
17 #include "vtkGUISupportQtQuickModule.h" // for export macro
18 #include "vtkSmartPointer.h"
19 
20 VTK_ABI_NAMESPACE_BEGIN
21 
22 class vtkRenderWindow;
23 class vtkObject;
24 
25 class QQuickVTKItemPrivate;
26 class VTKGUISUPPORTQTQUICK_EXPORT QQuickVTKItem : public QQuickItem
27 {
28  Q_OBJECT
29 
30 public:
31  explicit QQuickVTKItem(QQuickItem* parent = nullptr);
32  ~QQuickVTKItem() override;
33 
35 
43  static void setGraphicsApi();
44 
46 
72  virtual vtkUserData initializeVTK(vtkRenderWindow* renderWindow)
73  {
74  Q_UNUSED(renderWindow) return {};
75  }
77 
79 
95  virtual void destroyingVTK(vtkRenderWindow* renderWindow, vtkUserData userData)
96  {
97  Q_UNUSED(renderWindow);
98  Q_UNUSED(userData);
99  }
101 
103 
122  void dispatch_async(std::function<void(vtkRenderWindow* renderWindow, vtkUserData userData)> f);
124 
125 protected:
127 
128  bool event(QEvent*) override;
129 
130  QSGNode* updatePaintNode(QSGNode*, UpdatePaintNodeData*) override;
131  bool isTextureProvider() const override;
132  QSGTextureProvider* textureProvider() const override;
133  void releaseResources() override;
134 
135 private Q_SLOTS:
136  void invalidateSceneGraph();
137 
138 private: // NOLINT(readability-redundant-access-specifiers)
139  Q_DISABLE_COPY(QQuickVTKItem)
140  Q_DECLARE_PRIVATE_D(_d_ptr, QQuickVTKItem)
141  QScopedPointer<QQuickVTKItemPrivate> _d_ptr;
142 };
143 
144 VTK_ABI_NAMESPACE_END
145 #endif // QQuickVTKItem_h
QQuickItem that manages a VTK rendering in the QML scenegraph.
Definition: QQuickVTKItem.h:27
QQuickVTKItem(QQuickItem *parent=nullptr)
QSGTextureProvider * textureProvider() const override
bool isTextureProvider() const override
void scheduleRender()
virtual vtkUserData initializeVTK(vtkRenderWindow *renderWindow)
This is where the VTK initializiation should be done including creating a pipeline and attaching it t...
Definition: QQuickVTKItem.h:72
void releaseResources() override
~QQuickVTKItem() override
void dispatch_async(std::function< void(vtkRenderWindow *renderWindow, vtkUserData userData)> f)
This is the function that enqueues an async command that will be executed just before VTK renders.
bool event(QEvent *) override
virtual void destroyingVTK(vtkRenderWindow *renderWindow, vtkUserData userData)
At any moment the QML SceneGraph can decide to delete the underlying QSGNode.
Definition: QQuickVTKItem.h:95
QSGNode * updatePaintNode(QSGNode *, UpdatePaintNodeData *) override
static void setGraphicsApi()
Set up the graphics surface format and api.
abstract base class for most VTK objects
Definition: vtkObject.h:61
create a window for renderers to draw into
Hold a reference to a vtkObjectBase instance.
@ function
Definition: vtkX3D.h:249