VTK  9.1.0
QQuickVTKRenderItem.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: QQuickVTKRenderItem.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
129 #ifndef QQuickVTKRenderItem_h
130 #define QQuickVTKRenderItem_h
131 
132 // Qt includes
133 #include <QOpenGLFunctions> // For QOpenGLFunctions
134 #include <QQuickItem>
135 
136 // vtk includes
137 #include "QQuickVTKRenderWindow.h" // For QQuickVTKRenderWindow
138 #include "vtkNew.h" // For vtkNew
139 #include "vtkRenderer.h" // For vtkRenderer
140 
141 #include "vtkGUISupportQtQuickModule.h" // for export macro
142 
143 // Forward declarations
144 class QHoverEvent;
145 class QKeyEvent;
146 class QMouseEvent;
148 class vtkImageData;
149 
150 class VTKGUISUPPORTQTQUICK_EXPORT QQuickVTKRenderItem
151  : public QQuickItem
152  , protected QOpenGLFunctions
153 {
154  Q_OBJECT
155  typedef QQuickItem Superclass;
156 
157  Q_PROPERTY(QQuickVTKRenderWindow* renderWindow READ renderWindow WRITE setRenderWindow)
158 
159 public:
160  QQuickVTKRenderItem(QQuickItem* parent = nullptr);
161  ~QQuickVTKRenderItem() = default;
162 
164 
170 
175 
183 
185 
191 
193 
197  virtual void removeWidgetByName(QString name);
199 
200 public Q_SLOTS:
209  virtual void sync();
210 
217  virtual void init();
218 
227  virtual void paint();
228 
233  virtual void cleanup();
234 
235 protected Q_SLOTS:
236  virtual void handleWindowChanged(QQuickWindow* w);
237 
238 protected:
239  // Helper members
240  QQuickVTKRenderWindow* m_renderWindow = nullptr;
242 
243  QVector<QQuickVTKInteractiveWidget*> m_widgets;
244 
248  virtual void setViewport(const QRectF& rect);
249 
250  // Event handlers
251 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
252  void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) override;
253 #else
254  void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override;
255 #endif
256  bool event(QEvent* ev) override;
257 
258 private:
259  QQuickVTKRenderItem(const QQuickVTKRenderItem&) = delete;
260  void operator=(const QQuickVTKRenderItem) = delete;
261 };
262 
263 #endif // QQuickVTKRenderItem_h
QObject that manages a VTK interactive widget to ensure that it behaves as per the QtQuick threaded r...
QQuickItem subclass to render a VTK scene in a QtQuick/QML application.
QQuickVTKRenderWindow * renderWindow() const
Set/Get the render window for the item.
virtual void removeWidgetByName(QString name)
Get/Remove widgets from the view by their object name.
virtual void handleWindowChanged(QQuickWindow *w)
QQuickVTKRenderItem(QQuickItem *parent=nullptr)
virtual vtkSmartPointer< vtkImageData > captureScreenshot()
Capture a screenshot of the view.
virtual void init()
Initialize the graphics resources required for this render item.
virtual void sync()
This is the function called on the QtQuick render thread before the scenegraph state is synchronized.
virtual QQuickVTKInteractiveWidget * widgetByName(QString name) const
Get/Remove widgets from the view by their object name.
vtkNew< vtkRenderer > m_renderer
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
virtual void setRenderWindow(QQuickVTKRenderWindow *w)
Set/Get the render window for the item.
vtkRenderer * renderer() const
Get access to the renderer.
bool event(QEvent *ev) override
~QQuickVTKRenderItem()=default
QVector< QQuickVTKInteractiveWidget * > m_widgets
virtual void setViewport(const QRectF &rect)
Set the viewport for this item.
virtual void removeWidget(QQuickVTKInteractiveWidget *w)
Add/Remove widgets to/from the view.
virtual void cleanup()
This is the function called on the QtQuick render thread when the scenegraph is invalidated.
virtual void addWidget(QQuickVTKInteractiveWidget *w)
Add/Remove widgets to/from the view.
virtual void paint()
This is the function called on the QtQuick render thread right before the scenegraph is rendered.
QQuickItem subclass that manages the vtkRenderWindow and, in turn, the OpenGL context of the QML appl...
topologically and geometrically regular array of data
Definition: vtkImageData.h:48
abstract specification for renderers
Definition: vtkRenderer.h:73
@ name
Definition: vtkX3D.h:225