VTK  9.3.0
QQuickVTKRenderItem.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
117#ifndef QQuickVTKRenderItem_h
118#define QQuickVTKRenderItem_h
119
120// Qt includes
121#include <QOpenGLFunctions> // For QOpenGLFunctions
122#include <QQuickItem>
123
124// vtk includes
125#include "QQuickVTKRenderWindow.h" // For QQuickVTKRenderWindow
126#include "vtkDeprecation.h"
127#include "vtkNew.h" // For vtkNew
128#include "vtkRenderer.h" // For vtkRenderer
129
130#include "vtkGUISupportQtQuickModule.h" // for export macro
131
132// Qt Forward declarations
133class QHoverEvent;
134class QKeyEvent;
135class QMouseEvent;
136
137VTK_ABI_NAMESPACE_BEGIN
138// VTK Forward declarations
140class vtkImageData;
141
143 "Use QQuickVTKItem instead") VTKGUISUPPORTQTQUICK_EXPORT QQuickVTKRenderItem
144 : public QQuickItem
145 , protected QOpenGLFunctions
146{
147 Q_OBJECT
148 typedef QQuickItem Superclass;
149
150 Q_PROPERTY(QQuickVTKRenderWindow* renderWindow READ renderWindow WRITE setRenderWindow)
151
152public:
153 QQuickVTKRenderItem(QQuickItem* parent = nullptr);
154 ~QQuickVTKRenderItem() override = default;
155
157
163
168
176
178
184
186
189 virtual QQuickVTKInteractiveWidget* widgetByName(QString name) const;
190 virtual void removeWidgetByName(QString name);
192
193public Q_SLOTS: // NOLINT(readability-redundant-access-specifiers)
202 virtual void sync();
203
210 virtual void init();
211
220 virtual void paint();
221
226 virtual void cleanup();
227
228protected Q_SLOTS:
229 virtual void handleWindowChanged(QQuickWindow* w);
230
231protected: // NOLINT(readability-redundant-access-specifiers)
232 // Helper members
233 QQuickVTKRenderWindow* m_renderWindow = nullptr;
235
236 QVector<QQuickVTKInteractiveWidget*> m_widgets;
237
241 virtual void setViewport(const QRectF& rect);
242
243 // Event handlers
244#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
245 void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) override;
246#else
247 void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override;
248#endif
249 bool event(QEvent* ev) override;
250
251private:
253 void operator=(const QQuickVTKRenderItem) = delete;
254};
255
256VTK_ABI_NAMESPACE_END
257#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
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.
~QQuickVTKRenderItem() override=default
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
Allocate and hold a VTK object.
Definition vtkNew.h:51
abstract specification for renderers
Definition vtkRenderer.h:59
Hold a reference to a vtkObjectBase instance.
#define VTK_DEPRECATED_IN_9_3_0(reason)