Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
torusgeometry_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef TORUSGEOMETRY_P_H
5#define TORUSGEOMETRY_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick3DHelpers/qtquick3dhelpersexports.h>
19#include <QQuick3DGeometry>
20#include <QQmlEngine>
21#include <QVector3D>
22
23#if QT_CONFIG(concurrent)
24#include <QFuture>
25#include <QFutureWatcher>
26#endif
27
29
30class Q_QUICK3DHELPERS_EXPORT TorusGeometry : public QQuick3DGeometry
31{
32 Q_OBJECT
33 Q_PROPERTY(int rings READ rings WRITE setRings NOTIFY ringsChanged FINAL)
34 Q_PROPERTY(int segments READ segments WRITE setSegments NOTIFY segmentsChanged FINAL)
35 Q_PROPERTY(float radius READ radius WRITE setRadius NOTIFY radiusChanged FINAL)
36 Q_PROPERTY(float tubeRadius READ tubeRadius WRITE setTubeRadius NOTIFY tubeRadiusChanged FINAL)
37 Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged)
38 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
39 QML_ELEMENT
40 QML_ADDED_IN_VERSION(6, 9)
41public:
42 enum Status { Null, Ready, Loading, Error };
43 Q_ENUM(Status)
44 explicit TorusGeometry(QQuick3DObject *parent = nullptr);
45 ~TorusGeometry() override;
46
47 int rings() const;
48 void setRings(int newRings);
49 int segments() const;
50 void setSegments(int newSegments);
51
52 float radius() const;
53 void setRadius(float newRadius);
54
55 float tubeRadius() const;
56 void setTubeRadius(float newTubeRadius);
57
58 bool asynchronous() const;
59 void setAsynchronous(bool newAsynchronous);
60
61 Status status() const;
62
63private Q_SLOTS:
64 void doUpdateGeometry();
65 void requestFinished();
66
67Q_SIGNALS:
68 void ringsChanged();
69 void segmentsChanged();
70 void radiusChanged();
71 void tubeRadiusChanged();
72 void asynchronousChanged();
73 void statusChanged();
74
75private:
76 struct GeometryData {
77 QByteArray vertexData;
78 QByteArray indexData;
79 QVector3D boundsMin;
80 QVector3D boundsMax;
81 };
82
83 void scheduleGeometryUpdate();
84 void updateGeometry(const GeometryData &geometryData);
85
86 static TorusGeometry::GeometryData generateTorusGeometry(int rings,
87 int segments,
88 float radius,
89 float tubeRadius);
90#if QT_CONFIG(concurrent)
91 static void generateTorusGeometryAsync(QPromise<TorusGeometry::GeometryData> &promise,
92 int rings,
93 int segments,
94 float radius,
95 float tubeRadius);
96#endif
97
98 int m_rings = 50;
99 int m_segments = 50;
100 float m_radius = 100.0f;
101 float m_tubeRadius = 10.0f;
102 bool m_asynchronous = true;
103 Status m_status = Null;
104#if QT_CONFIG(concurrent)
105 QFuture<GeometryData> m_geometryDataFuture;
106 QFutureWatcher<GeometryData> m_geometryDataWatcher;
107#endif
108 bool m_geometryUpdateRequested = false;
109 bool m_pendingAsyncUpdate = false;
110};
111
112QT_END_NAMESPACE
113
114#endif // TORUSGEOMETRY_P_H
const size_t UINT_SIZE
const size_t VEC3_SIZE
const size_t VEC2_SIZE
const size_t FLOAT_SIZE