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
144class QHoverEvent;
145class QKeyEvent;
146class QMouseEvent;
148class vtkImageData;
149
150class 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
159public:
160 QQuickVTKRenderItem(QQuickItem* parent = nullptr);
162
164
170
175
183
185
191
193
196 virtual QQuickVTKInteractiveWidget* widgetByName(QString name) const;
197 virtual void removeWidgetByName(QString name);
199
200public Q_SLOTS:
209 virtual void sync();
210
217 virtual void init();
218
227 virtual void paint();
228
233 virtual void cleanup();
234
235protected Q_SLOTS:
236 virtual void handleWindowChanged(QQuickWindow* w);
237
238protected:
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
258private:
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.
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 QQuickVTKInteractiveWidget * widgetByName(QString name) const
Get/Remove widgets from the view by their object name.
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.
vtkNew< vtkRenderer > m_renderer
QQuickVTKRenderWindow * renderWindow() const
Set/Get the render window for the item.
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
virtual void setRenderWindow(QQuickVTKRenderWindow *w)
Set/Get the render window for the item.
bool event(QEvent *ev) override
~QQuickVTKRenderItem()=default
virtual vtkSmartPointer< vtkImageData > captureScreenshot()
Capture a screenshot of the view.
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.
vtkRenderer * renderer() const
Get access to the renderer.
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:157
Allocate and hold a VTK object.
Definition: vtkNew.h:165
abstract specification for renderers
Definition: vtkRenderer.h:182
Hold a reference to a vtkObjectBase instance.