VTK  9.7.1
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)
75  return {};
76  }
78 
80 
96  virtual void destroyingVTK(vtkRenderWindow* renderWindow, vtkUserData userData)
97  {
98  Q_UNUSED(renderWindow);
99  Q_UNUSED(userData);
100  }
102 
104 
123  void dispatch_async(std::function<void(vtkRenderWindow* renderWindow, vtkUserData userData)> f);
125 
135  void scheduleRender();
136 
137 public Q_SLOTS: // NOLINT(readability-redundant-access-specifiers)
139 
163  Q_INVOKABLE void pinchHandlerRotate(const QPointF& position, double delta);
164  Q_INVOKABLE void pinchHandlerScale(const QPointF& position, double delta);
165  Q_INVOKABLE void pinchHandlerTranslate(const QPointF& position, const QVector2D& delta);
167 
168 protected:
169  bool event(QEvent*) override;
170 
171  QSGNode* updatePaintNode(QSGNode*, UpdatePaintNodeData*) override;
172  bool isTextureProvider() const override;
173  QSGTextureProvider* textureProvider() const override;
174  void releaseResources() override;
175 
176 private Q_SLOTS:
177  void invalidateSceneGraph();
178 
179 private: // NOLINT(readability-redundant-access-specifiers)
180  Q_DISABLE_COPY(QQuickVTKItem)
181  Q_DECLARE_PRIVATE_D(_d_ptr, QQuickVTKItem)
182  QScopedPointer<QQuickVTKItemPrivate> _d_ptr;
183 };
184 
185 VTK_ABI_NAMESPACE_END
186 #endif // QQuickVTKItem_h
virtual void destroyingVTK(vtkRenderWindow *renderWindow, vtkUserData userData)
At any moment the QML SceneGraph can decide to delete the underlying QSGNode.
Definition: QQuickVTKItem.h:96
abstract base class for most VTK objects
Definition: vtkObject.h:52
virtual vtkUserData initializeVTK(vtkRenderWindow *renderWindow)
This is where the VTK initialization should be done including creating a pipeline and attaching it to...
Definition: QQuickVTKItem.h:72
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:23
create a window for renderers to draw into
QQuickItem that manages a VTK rendering in the QML scenegraph.
Definition: QQuickVTKItem.h:26