| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QTDATAVIS3D_QABSTRACT3DGRAPH_H |
| 5 | #define QTDATAVIS3D_QABSTRACT3DGRAPH_H |
| 6 | |
| 7 | #include <QtDataVisualization/qdatavisualizationglobal.h> |
| 8 | #include <QtDataVisualization/q3dtheme.h> |
| 9 | #include <QtDataVisualization/q3dscene.h> |
| 10 | #include <QtDataVisualization/qabstract3dinputhandler.h> |
| 11 | #include <QtGui/QWindow> |
| 12 | #include <QtGui/QOpenGLFunctions> |
| 13 | #include <QtCore/QLocale> |
| 14 | |
| 15 | QT_BEGIN_NAMESPACE |
| 16 | |
| 17 | class QAbstract3DGraphPrivate; |
| 18 | class QCustom3DItem; |
| 19 | class QAbstract3DAxis; |
| 20 | class QAbstract3DSeries; |
| 21 | |
| 22 | class Q_DATAVISUALIZATION_EXPORT QAbstract3DGraph : public QWindow, protected QOpenGLFunctions |
| 23 | { |
| 24 | Q_OBJECT |
| 25 | Q_FLAGS(SelectionFlag SelectionFlags) |
| 26 | Q_FLAGS(OptimizationHint OptimizationHints) |
| 27 | Q_PROPERTY(QAbstract3DInputHandler* activeInputHandler READ activeInputHandler WRITE setActiveInputHandler NOTIFY activeInputHandlerChanged) |
| 28 | Q_PROPERTY(Q3DTheme* activeTheme READ activeTheme WRITE setActiveTheme NOTIFY activeThemeChanged) |
| 29 | Q_PROPERTY(SelectionFlags selectionMode READ selectionMode WRITE setSelectionMode NOTIFY selectionModeChanged) |
| 30 | Q_PROPERTY(ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality NOTIFY shadowQualityChanged) |
| 31 | Q_PROPERTY(Q3DScene* scene READ scene) |
| 32 | Q_PROPERTY(bool measureFps READ measureFps WRITE setMeasureFps NOTIFY measureFpsChanged) |
| 33 | Q_PROPERTY(qreal currentFps READ currentFps NOTIFY currentFpsChanged) |
| 34 | Q_PROPERTY(bool orthoProjection READ isOrthoProjection WRITE setOrthoProjection NOTIFY orthoProjectionChanged) |
| 35 | Q_PROPERTY(ElementType selectedElement READ selectedElement NOTIFY selectedElementChanged) |
| 36 | Q_PROPERTY(qreal aspectRatio READ aspectRatio WRITE setAspectRatio NOTIFY aspectRatioChanged) |
| 37 | Q_PROPERTY(OptimizationHints optimizationHints READ optimizationHints WRITE setOptimizationHints NOTIFY optimizationHintsChanged) |
| 38 | Q_PROPERTY(bool polar READ isPolar WRITE setPolar NOTIFY polarChanged) |
| 39 | Q_PROPERTY(float radialLabelOffset READ radialLabelOffset WRITE setRadialLabelOffset NOTIFY radialLabelOffsetChanged) |
| 40 | Q_PROPERTY(qreal horizontalAspectRatio READ horizontalAspectRatio WRITE setHorizontalAspectRatio NOTIFY horizontalAspectRatioChanged) |
| 41 | Q_PROPERTY(bool reflection READ isReflection WRITE setReflection NOTIFY reflectionChanged) |
| 42 | Q_PROPERTY(qreal reflectivity READ reflectivity WRITE setReflectivity NOTIFY reflectivityChanged) |
| 43 | Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged) |
| 44 | Q_PROPERTY(QVector3D queriedGraphPosition READ queriedGraphPosition NOTIFY queriedGraphPositionChanged) |
| 45 | Q_PROPERTY(qreal margin READ margin WRITE setMargin NOTIFY marginChanged) |
| 46 | |
| 47 | protected: |
| 48 | explicit QAbstract3DGraph(QAbstract3DGraphPrivate *d, const QSurfaceFormat *format, |
| 49 | QWindow *parent = nullptr); |
| 50 | |
| 51 | public: |
| 52 | enum SelectionFlag { |
| 53 | SelectionNone = 0, |
| 54 | SelectionItem = 1, |
| 55 | SelectionRow = 2, |
| 56 | SelectionItemAndRow = SelectionItem | SelectionRow, |
| 57 | SelectionColumn = 4, |
| 58 | SelectionItemAndColumn = SelectionItem | SelectionColumn, |
| 59 | SelectionRowAndColumn = SelectionRow | SelectionColumn, |
| 60 | SelectionItemRowAndColumn = SelectionItem | SelectionRow | SelectionColumn, |
| 61 | SelectionSlice = 8, |
| 62 | SelectionMultiSeries = 16 |
| 63 | }; |
| 64 | Q_ENUM(SelectionFlag) |
| 65 | Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag) |
| 66 | |
| 67 | enum ShadowQuality { |
| 68 | ShadowQualityNone = 0, |
| 69 | ShadowQualityLow, |
| 70 | ShadowQualityMedium, |
| 71 | ShadowQualityHigh, |
| 72 | ShadowQualitySoftLow, |
| 73 | ShadowQualitySoftMedium, |
| 74 | ShadowQualitySoftHigh |
| 75 | }; |
| 76 | Q_ENUM(ShadowQuality) |
| 77 | |
| 78 | enum ElementType { |
| 79 | ElementNone = 0, |
| 80 | ElementSeries, |
| 81 | ElementAxisXLabel, |
| 82 | ElementAxisYLabel, |
| 83 | ElementAxisZLabel, |
| 84 | ElementCustomItem |
| 85 | }; |
| 86 | Q_ENUM(ElementType) |
| 87 | |
| 88 | enum OptimizationHint { |
| 89 | OptimizationDefault = 0, |
| 90 | OptimizationStatic = 1 |
| 91 | }; |
| 92 | Q_ENUM(OptimizationHint) |
| 93 | Q_DECLARE_FLAGS(OptimizationHints, OptimizationHint) |
| 94 | |
| 95 | public: |
| 96 | virtual ~QAbstract3DGraph(); |
| 97 | |
| 98 | void addInputHandler(QAbstract3DInputHandler *inputHandler); |
| 99 | void releaseInputHandler(QAbstract3DInputHandler *inputHandler); |
| 100 | void setActiveInputHandler(QAbstract3DInputHandler *inputHandler); |
| 101 | QAbstract3DInputHandler *activeInputHandler() const; |
| 102 | QList<QAbstract3DInputHandler *> inputHandlers() const; |
| 103 | |
| 104 | void addTheme(Q3DTheme *theme); |
| 105 | void releaseTheme(Q3DTheme *theme); |
| 106 | void setActiveTheme(Q3DTheme *theme); |
| 107 | Q3DTheme *activeTheme() const; |
| 108 | QList<Q3DTheme *> themes() const; |
| 109 | |
| 110 | void setSelectionMode(SelectionFlags mode); |
| 111 | SelectionFlags selectionMode() const; |
| 112 | |
| 113 | void setShadowQuality(ShadowQuality quality); |
| 114 | ShadowQuality shadowQuality() const; |
| 115 | virtual bool shadowsSupported() const; |
| 116 | |
| 117 | Q3DScene *scene() const; |
| 118 | |
| 119 | void clearSelection(); |
| 120 | |
| 121 | bool hasSeries(QAbstract3DSeries *series) const; |
| 122 | |
| 123 | int addCustomItem(QCustom3DItem *item); |
| 124 | void removeCustomItems(); |
| 125 | void removeCustomItem(QCustom3DItem *item); |
| 126 | void removeCustomItemAt(const QVector3D &position); |
| 127 | void releaseCustomItem(QCustom3DItem *item); |
| 128 | QList<QCustom3DItem *> customItems() const; |
| 129 | |
| 130 | int selectedLabelIndex() const; |
| 131 | QAbstract3DAxis *selectedAxis() const; |
| 132 | |
| 133 | int selectedCustomItemIndex() const; |
| 134 | QCustom3DItem *selectedCustomItem() const; |
| 135 | |
| 136 | QImage renderToImage(int msaaSamples = 0, const QSize &imageSize = QSize()); |
| 137 | |
| 138 | void setMeasureFps(bool enable); |
| 139 | bool measureFps() const; |
| 140 | qreal currentFps() const; |
| 141 | |
| 142 | void setOrthoProjection(bool enable); |
| 143 | bool isOrthoProjection() const; |
| 144 | |
| 145 | ElementType selectedElement() const; |
| 146 | |
| 147 | void setAspectRatio(qreal ratio); |
| 148 | qreal aspectRatio() const; |
| 149 | |
| 150 | void setOptimizationHints(OptimizationHints hints); |
| 151 | OptimizationHints optimizationHints() const; |
| 152 | |
| 153 | void setPolar(bool enable); |
| 154 | bool isPolar() const; |
| 155 | |
| 156 | void setRadialLabelOffset(float offset); |
| 157 | float radialLabelOffset() const; |
| 158 | |
| 159 | void setHorizontalAspectRatio(qreal ratio); |
| 160 | qreal horizontalAspectRatio() const; |
| 161 | |
| 162 | void setReflection(bool enable); |
| 163 | bool isReflection() const; |
| 164 | |
| 165 | void setReflectivity(qreal reflectivity); |
| 166 | qreal reflectivity() const; |
| 167 | |
| 168 | void setLocale(const QLocale &locale); |
| 169 | QLocale locale() const; |
| 170 | |
| 171 | QVector3D queriedGraphPosition() const; |
| 172 | |
| 173 | void setMargin(qreal margin); |
| 174 | qreal margin() const; |
| 175 | |
| 176 | bool hasContext() const; |
| 177 | |
| 178 | protected: |
| 179 | bool event(QEvent *event) override; |
| 180 | void resizeEvent(QResizeEvent *event) override; |
| 181 | void exposeEvent(QExposeEvent *event) override; |
| 182 | |
| 183 | void mouseDoubleClickEvent(QMouseEvent *event) override; |
| 184 | void touchEvent(QTouchEvent *event) override; |
| 185 | void mousePressEvent(QMouseEvent *event) override; |
| 186 | void mouseReleaseEvent(QMouseEvent *event) override; |
| 187 | void mouseMoveEvent(QMouseEvent *event) override; |
| 188 | #if QT_CONFIG(wheelevent) |
| 189 | void wheelEvent(QWheelEvent *event) override; |
| 190 | #endif |
| 191 | |
| 192 | Q_SIGNALS: |
| 193 | void activeInputHandlerChanged(QAbstract3DInputHandler *inputHandler); |
| 194 | void activeThemeChanged(Q3DTheme *theme); |
| 195 | void selectionModeChanged(QAbstract3DGraph::SelectionFlags mode); |
| 196 | void shadowQualityChanged(QAbstract3DGraph::ShadowQuality quality); |
| 197 | void selectedElementChanged(QAbstract3DGraph::ElementType type); |
| 198 | void measureFpsChanged(bool enabled); |
| 199 | void currentFpsChanged(qreal fps); |
| 200 | void orthoProjectionChanged(bool enabled); |
| 201 | void aspectRatioChanged(qreal ratio); |
| 202 | void optimizationHintsChanged(QAbstract3DGraph::OptimizationHints hints); |
| 203 | void polarChanged(bool enabled); |
| 204 | void radialLabelOffsetChanged(float offset); |
| 205 | void horizontalAspectRatioChanged(qreal ratio); |
| 206 | void reflectionChanged(bool enabled); |
| 207 | void reflectivityChanged(qreal reflectivity); |
| 208 | void localeChanged(const QLocale &locale); |
| 209 | void queriedGraphPositionChanged(const QVector3D &data); |
| 210 | void marginChanged(qreal margin); |
| 211 | |
| 212 | private: |
| 213 | Q_DISABLE_COPY(QAbstract3DGraph) |
| 214 | QScopedPointer<QAbstract3DGraphPrivate> d_ptr; |
| 215 | |
| 216 | friend class Q3DBars; |
| 217 | friend class Q3DScatter; |
| 218 | friend class Q3DSurface; |
| 219 | }; |
| 220 | Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstract3DGraph::SelectionFlags) |
| 221 | Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstract3DGraph::OptimizationHints) |
| 222 | |
| 223 | QT_END_NAMESPACE |
| 224 | |
| 225 | #endif |
| 226 | |