| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | // |
| 5 | // W A R N I N G |
| 6 | // ------------- |
| 7 | // |
| 8 | // This file is not part of the QtDataVisualization API. It exists purely as an |
| 9 | // implementation detail. This header file may change from version to |
| 10 | // version without notice, or even be removed. |
| 11 | // |
| 12 | // We mean it. |
| 13 | |
| 14 | #ifndef ABSTRACT3DCONTROLLER_P_H |
| 15 | #define ABSTRACT3DCONTROLLER_P_H |
| 16 | |
| 17 | #include <private/datavisualizationglobal_p.h> |
| 18 | |
| 19 | #include "qabstract3daxis.h" |
| 20 | #include "drawer_p.h" |
| 21 | #include "qabstract3dinputhandler.h" |
| 22 | #include "qabstract3dgraph.h" |
| 23 | #include "q3dscene_p.h" |
| 24 | #include "qcustom3ditem.h" |
| 25 | #include <QtGui/QLinearGradient> |
| 26 | #include <QtCore/QElapsedTimer> |
| 27 | #include <QtCore/QLocale> |
| 28 | #include <QtCore/QMutex> |
| 29 | |
| 30 | QT_FORWARD_DECLARE_CLASS(QOpenGLFramebufferObject) |
| 31 | |
| 32 | QT_BEGIN_NAMESPACE |
| 33 | |
| 34 | class AbstractDeclarativeInterface; |
| 35 | class AbstractDeclarative; |
| 36 | class Abstract3DRenderer; |
| 37 | class QAbstract3DSeries; |
| 38 | class ThemeManager; |
| 39 | |
| 40 | struct Abstract3DChangeBitField { |
| 41 | bool themeChanged : 1; |
| 42 | bool shadowQualityChanged : 1; |
| 43 | bool selectionModeChanged : 1; |
| 44 | bool optimizationHintChanged : 1; |
| 45 | bool axisXTypeChanged : 1; |
| 46 | bool axisYTypeChanged : 1; |
| 47 | bool axisZTypeChanged : 1; |
| 48 | bool axisXTitleChanged : 1; |
| 49 | bool axisYTitleChanged : 1; |
| 50 | bool axisZTitleChanged : 1; |
| 51 | bool axisXLabelsChanged : 1; |
| 52 | bool axisYLabelsChanged : 1; |
| 53 | bool axisZLabelsChanged : 1; |
| 54 | bool axisXRangeChanged : 1; |
| 55 | bool axisYRangeChanged : 1; |
| 56 | bool axisZRangeChanged : 1; |
| 57 | bool axisXSegmentCountChanged : 1; |
| 58 | bool axisYSegmentCountChanged : 1; |
| 59 | bool axisZSegmentCountChanged : 1; |
| 60 | bool axisXSubSegmentCountChanged : 1; |
| 61 | bool axisYSubSegmentCountChanged : 1; |
| 62 | bool axisZSubSegmentCountChanged : 1; |
| 63 | bool axisXLabelFormatChanged : 1; |
| 64 | bool axisYLabelFormatChanged : 1; |
| 65 | bool axisZLabelFormatChanged : 1; |
| 66 | bool axisXReversedChanged : 1; |
| 67 | bool axisYReversedChanged : 1; |
| 68 | bool axisZReversedChanged : 1; |
| 69 | bool axisXFormatterChanged : 1; |
| 70 | bool axisYFormatterChanged : 1; |
| 71 | bool axisZFormatterChanged : 1; |
| 72 | bool projectionChanged : 1; |
| 73 | bool axisXLabelAutoRotationChanged : 1; |
| 74 | bool axisYLabelAutoRotationChanged : 1; |
| 75 | bool axisZLabelAutoRotationChanged : 1; |
| 76 | bool aspectRatioChanged : 1; |
| 77 | bool horizontalAspectRatioChanged : 1; |
| 78 | bool axisXTitleVisibilityChanged : 1; |
| 79 | bool axisYTitleVisibilityChanged : 1; |
| 80 | bool axisZTitleVisibilityChanged : 1; |
| 81 | bool axisXTitleFixedChanged : 1; |
| 82 | bool axisYTitleFixedChanged : 1; |
| 83 | bool axisZTitleFixedChanged : 1; |
| 84 | bool polarChanged : 1; |
| 85 | bool radialLabelOffsetChanged : 1; |
| 86 | bool reflectionChanged : 1; |
| 87 | bool reflectivityChanged : 1; |
| 88 | bool marginChanged : 1; |
| 89 | |
| 90 | Abstract3DChangeBitField() : |
| 91 | themeChanged(true), |
| 92 | shadowQualityChanged(true), |
| 93 | selectionModeChanged(true), |
| 94 | optimizationHintChanged(true), |
| 95 | axisXTypeChanged(true), |
| 96 | axisYTypeChanged(true), |
| 97 | axisZTypeChanged(true), |
| 98 | axisXTitleChanged(true), |
| 99 | axisYTitleChanged(true), |
| 100 | axisZTitleChanged(true), |
| 101 | axisXLabelsChanged(true), |
| 102 | axisYLabelsChanged(true), |
| 103 | axisZLabelsChanged(true), |
| 104 | axisXRangeChanged(true), |
| 105 | axisYRangeChanged(true), |
| 106 | axisZRangeChanged(true), |
| 107 | axisXSegmentCountChanged(true), |
| 108 | axisYSegmentCountChanged(true), |
| 109 | axisZSegmentCountChanged(true), |
| 110 | axisXSubSegmentCountChanged(true), |
| 111 | axisYSubSegmentCountChanged(true), |
| 112 | axisZSubSegmentCountChanged(true), |
| 113 | axisXLabelFormatChanged(true), |
| 114 | axisYLabelFormatChanged(true), |
| 115 | axisZLabelFormatChanged(true), |
| 116 | axisXReversedChanged(true), |
| 117 | axisYReversedChanged(true), |
| 118 | axisZReversedChanged(true), |
| 119 | axisXFormatterChanged(true), |
| 120 | axisYFormatterChanged(true), |
| 121 | axisZFormatterChanged(true), |
| 122 | projectionChanged(true), |
| 123 | axisXLabelAutoRotationChanged(true), |
| 124 | axisYLabelAutoRotationChanged(true), |
| 125 | axisZLabelAutoRotationChanged(true), |
| 126 | aspectRatioChanged(true), |
| 127 | horizontalAspectRatioChanged(true), |
| 128 | axisXTitleVisibilityChanged(true), |
| 129 | axisYTitleVisibilityChanged(true), |
| 130 | axisZTitleVisibilityChanged(true), |
| 131 | axisXTitleFixedChanged(true), |
| 132 | axisYTitleFixedChanged(true), |
| 133 | axisZTitleFixedChanged(true), |
| 134 | polarChanged(true), |
| 135 | radialLabelOffsetChanged(true), |
| 136 | reflectionChanged(true), |
| 137 | reflectivityChanged(true), |
| 138 | marginChanged(true) |
| 139 | { |
| 140 | } |
| 141 | }; |
| 142 | |
| 143 | class Q_DATAVISUALIZATION_EXPORT Abstract3DController : public QObject |
| 144 | { |
| 145 | Q_OBJECT |
| 146 | |
| 147 | public: |
| 148 | enum SelectionType { |
| 149 | SelectionNone = 0, |
| 150 | SelectionItem, |
| 151 | SelectionRow, |
| 152 | SelectionColumn |
| 153 | }; |
| 154 | |
| 155 | private: |
| 156 | Abstract3DChangeBitField m_changeTracker; |
| 157 | ThemeManager *m_themeManager; |
| 158 | QAbstract3DGraph::SelectionFlags m_selectionMode; |
| 159 | QAbstract3DGraph::ShadowQuality m_shadowQuality; |
| 160 | bool m_useOrthoProjection; |
| 161 | qreal m_aspectRatio; |
| 162 | qreal m_horizontalAspectRatio; |
| 163 | QAbstract3DGraph::OptimizationHints m_optimizationHints; |
| 164 | bool m_reflectionEnabled; |
| 165 | qreal m_reflectivity; |
| 166 | QLocale m_locale; |
| 167 | QVector3D m_queriedGraphPosition; |
| 168 | |
| 169 | protected: |
| 170 | Q3DScene *m_scene; |
| 171 | QList<QAbstract3DInputHandler *> m_inputHandlers; // List of all added input handlers |
| 172 | QAbstract3DInputHandler *m_activeInputHandler; |
| 173 | // Active axes |
| 174 | QAbstract3DAxis *m_axisX; |
| 175 | QAbstract3DAxis *m_axisY; |
| 176 | QAbstract3DAxis *m_axisZ; |
| 177 | |
| 178 | QList<QAbstract3DAxis *> m_axes; // List of all added axes |
| 179 | Abstract3DRenderer *m_renderer; |
| 180 | bool m_isDataDirty; |
| 181 | bool m_isCustomDataDirty; |
| 182 | bool m_isCustomItemDirty; |
| 183 | bool m_isSeriesVisualsDirty; |
| 184 | bool m_renderPending; |
| 185 | bool m_isPolar; |
| 186 | float m_radialLabelOffset; |
| 187 | |
| 188 | QList<QAbstract3DSeries *> m_seriesList; |
| 189 | |
| 190 | bool m_measureFps; |
| 191 | QElapsedTimer m_frameTimer; |
| 192 | int m_numFrames; |
| 193 | qreal m_currentFps; |
| 194 | |
| 195 | QList<QAbstract3DSeries *> m_changedSeriesList; |
| 196 | |
| 197 | QList<QCustom3DItem *> m_customItems; |
| 198 | |
| 199 | QAbstract3DGraph::ElementType m_clickedType; |
| 200 | int m_selectedLabelIndex; |
| 201 | int m_selectedCustomItemIndex; |
| 202 | qreal m_margin; |
| 203 | |
| 204 | QMutex m_renderMutex; |
| 205 | AbstractDeclarativeInterface *m_qml = nullptr; |
| 206 | |
| 207 | explicit Abstract3DController(QRect initialViewport, Q3DScene *scene, QObject *parent = 0); |
| 208 | |
| 209 | public: |
| 210 | virtual ~Abstract3DController(); |
| 211 | |
| 212 | inline bool isInitialized() { return (m_renderer != 0); } |
| 213 | virtual void synchDataToRenderer(); |
| 214 | virtual void render(const GLuint defaultFboHandle = 0); |
| 215 | virtual void initializeOpenGL() = 0; |
| 216 | void setRenderer(Abstract3DRenderer *renderer); |
| 217 | |
| 218 | virtual void addSeries(QAbstract3DSeries *series); |
| 219 | virtual void insertSeries(int index, QAbstract3DSeries *series); |
| 220 | virtual void removeSeries(QAbstract3DSeries *series); |
| 221 | virtual bool hasSeries(QAbstract3DSeries *series); |
| 222 | QList<QAbstract3DSeries *> seriesList(); |
| 223 | |
| 224 | virtual void setAxisX(QAbstract3DAxis *axis); |
| 225 | virtual QAbstract3DAxis *axisX() const; |
| 226 | virtual void setAxisY(QAbstract3DAxis *axis); |
| 227 | virtual QAbstract3DAxis *axisY() const; |
| 228 | virtual void setAxisZ(QAbstract3DAxis *axis); |
| 229 | virtual QAbstract3DAxis *axisZ() const; |
| 230 | virtual void addAxis(QAbstract3DAxis *axis); |
| 231 | virtual void releaseAxis(QAbstract3DAxis *axis); |
| 232 | virtual QList<QAbstract3DAxis *> axes() const; // Omits default axes |
| 233 | |
| 234 | virtual void addInputHandler(QAbstract3DInputHandler *inputHandler); |
| 235 | virtual void releaseInputHandler(QAbstract3DInputHandler *inputHandler); |
| 236 | virtual void setActiveInputHandler(QAbstract3DInputHandler *inputHandler); |
| 237 | virtual QAbstract3DInputHandler *activeInputHandler(); |
| 238 | virtual QList<QAbstract3DInputHandler *> inputHandlers() const; |
| 239 | |
| 240 | virtual void addTheme(Q3DTheme *theme); |
| 241 | virtual void releaseTheme(Q3DTheme *theme); |
| 242 | virtual void setActiveTheme(Q3DTheme *theme, bool force = true); |
| 243 | virtual Q3DTheme *activeTheme() const; |
| 244 | virtual QList<Q3DTheme *> themes() const; |
| 245 | |
| 246 | virtual void setSelectionMode(QAbstract3DGraph::SelectionFlags mode); |
| 247 | virtual QAbstract3DGraph::SelectionFlags selectionMode() const; |
| 248 | |
| 249 | virtual void setShadowQuality(QAbstract3DGraph::ShadowQuality quality); |
| 250 | virtual void doSetShadowQuality(QAbstract3DGraph::ShadowQuality quality); |
| 251 | virtual QAbstract3DGraph::ShadowQuality shadowQuality() const; |
| 252 | virtual bool shadowsSupported() const; |
| 253 | |
| 254 | void setOptimizationHints(QAbstract3DGraph::OptimizationHints hints); |
| 255 | QAbstract3DGraph::OptimizationHints optimizationHints() const; |
| 256 | |
| 257 | bool isSlicingActive() const; |
| 258 | void setSlicingActive(bool isSlicing); |
| 259 | |
| 260 | Q3DScene *scene(); |
| 261 | |
| 262 | void markDataDirty(); |
| 263 | void markSeriesVisualsDirty(); |
| 264 | |
| 265 | void requestRender(QOpenGLFramebufferObject *fbo); |
| 266 | |
| 267 | int addCustomItem(QCustom3DItem *item); |
| 268 | void deleteCustomItems(); |
| 269 | void deleteCustomItem(QCustom3DItem *item); |
| 270 | void deleteCustomItem(const QVector3D &position); |
| 271 | void releaseCustomItem(QCustom3DItem *item); |
| 272 | QList<QCustom3DItem *> customItems() const; |
| 273 | |
| 274 | int selectedLabelIndex() const; |
| 275 | QAbstract3DAxis *selectedAxis() const; |
| 276 | int selectedCustomItemIndex() const; |
| 277 | QCustom3DItem *selectedCustomItem() const; |
| 278 | |
| 279 | void setOrthoProjection(bool enable); |
| 280 | bool isOrthoProjection() const; |
| 281 | |
| 282 | void setMeasureFps(bool enable); |
| 283 | inline bool measureFps() const { return m_measureFps; } |
| 284 | inline qreal currentFps() const { return m_currentFps; } |
| 285 | |
| 286 | QAbstract3DGraph::ElementType selectedElement() const; |
| 287 | |
| 288 | void setAspectRatio(qreal ratio); |
| 289 | qreal aspectRatio(); |
| 290 | void setHorizontalAspectRatio(qreal ratio); |
| 291 | qreal horizontalAspectRatio() const; |
| 292 | |
| 293 | void setReflection(bool enable); |
| 294 | bool reflection() const; |
| 295 | void setReflectivity(qreal reflectivity); |
| 296 | qreal reflectivity() const; |
| 297 | |
| 298 | void setPolar(bool enable); |
| 299 | bool isPolar() const; |
| 300 | void setRadialLabelOffset(float offset); |
| 301 | float radialLabelOffset() const; |
| 302 | |
| 303 | void setLocale(const QLocale &locale); |
| 304 | QLocale locale() const; |
| 305 | |
| 306 | QVector3D queriedGraphPosition() const; |
| 307 | |
| 308 | void setMargin(qreal margin); |
| 309 | qreal margin() const; |
| 310 | |
| 311 | void emitNeedRender(); |
| 312 | |
| 313 | virtual void clearSelection() = 0; |
| 314 | |
| 315 | virtual void mouseDoubleClickEvent(QMouseEvent *event); |
| 316 | virtual void touchEvent(QTouchEvent *event); |
| 317 | virtual void mousePressEvent(QMouseEvent *event, const QPoint &mousePos); |
| 318 | virtual void mouseReleaseEvent(QMouseEvent *event, const QPoint &mousePos); |
| 319 | virtual void mouseMoveEvent(QMouseEvent *event, const QPoint &mousePos); |
| 320 | #if QT_CONFIG(wheelevent) |
| 321 | virtual void wheelEvent(QWheelEvent *event); |
| 322 | #endif |
| 323 | |
| 324 | virtual void handleAxisTitleChangedBySender(QObject *sender); |
| 325 | virtual void handleAxisLabelsChangedBySender(QObject *sender); |
| 326 | virtual void handleAxisRangeChangedBySender(QObject *sender); |
| 327 | virtual void handleAxisSegmentCountChangedBySender(QObject *sender); |
| 328 | virtual void handleAxisSubSegmentCountChangedBySender(QObject *sender); |
| 329 | virtual void handleAxisAutoAdjustRangeChangedInOrientation( |
| 330 | QAbstract3DAxis::AxisOrientation orientation, bool autoAdjust) = 0; |
| 331 | virtual void handleAxisLabelFormatChangedBySender(QObject *sender); |
| 332 | virtual void handleAxisReversedChangedBySender(QObject *sender); |
| 333 | virtual void handleAxisFormatterDirtyBySender(QObject *sender); |
| 334 | virtual void handleAxisLabelAutoRotationChangedBySender(QObject *sender); |
| 335 | virtual void handleAxisTitleVisibilityChangedBySender(QObject *sender); |
| 336 | virtual void handleAxisTitleFixedChangedBySender(QObject *sender); |
| 337 | virtual void handleSeriesVisibilityChangedBySender(QObject *sender); |
| 338 | virtual void handlePendingClick(); |
| 339 | virtual void handlePendingGraphPositionQuery(); |
| 340 | virtual void adjustAxisRanges() = 0; |
| 341 | |
| 342 | void markSeriesItemLabelsDirty(); |
| 343 | bool isOpenGLES() const; |
| 344 | |
| 345 | public Q_SLOTS: |
| 346 | void destroyRenderer(); |
| 347 | |
| 348 | void handleAxisTitleChanged(const QString &title); |
| 349 | void handleAxisLabelsChanged(); |
| 350 | void handleAxisRangeChanged(float min, float max); |
| 351 | void handleAxisSegmentCountChanged(int count); |
| 352 | void handleAxisSubSegmentCountChanged(int count); |
| 353 | void handleAxisAutoAdjustRangeChanged(bool autoAdjust); |
| 354 | void handleAxisLabelFormatChanged(const QString &format); |
| 355 | void handleAxisReversedChanged(bool enable); |
| 356 | void handleAxisFormatterDirty(); |
| 357 | void handleAxisLabelAutoRotationChanged(float angle); |
| 358 | void handleAxisTitleVisibilityChanged(bool visible); |
| 359 | void handleAxisTitleFixedChanged(bool fixed); |
| 360 | void handleInputViewChanged(QAbstract3DInputHandler::InputView view); |
| 361 | void handleInputPositionChanged(const QPoint &position); |
| 362 | void handleSeriesVisibilityChanged(bool visible); |
| 363 | |
| 364 | void handleThemeColorStyleChanged(Q3DTheme::ColorStyle style); |
| 365 | void handleThemeBaseColorsChanged(const QList<QColor> &color); |
| 366 | void handleThemeBaseGradientsChanged(const QList<QLinearGradient> &gradient); |
| 367 | void handleThemeSingleHighlightColorChanged(const QColor &color); |
| 368 | void handleThemeSingleHighlightGradientChanged(const QLinearGradient &gradient); |
| 369 | void handleThemeMultiHighlightColorChanged(const QColor &color); |
| 370 | void handleThemeMultiHighlightGradientChanged(const QLinearGradient &gradient); |
| 371 | void handleThemeTypeChanged(Q3DTheme::Theme theme); |
| 372 | |
| 373 | // Renderer callback handlers |
| 374 | void handleRequestShadowQuality(QAbstract3DGraph::ShadowQuality quality); |
| 375 | |
| 376 | void updateCustomItem(); |
| 377 | |
| 378 | Q_SIGNALS: |
| 379 | void shadowQualityChanged(QAbstract3DGraph::ShadowQuality quality); |
| 380 | void activeInputHandlerChanged(QAbstract3DInputHandler *inputHandler); |
| 381 | void activeThemeChanged(Q3DTheme *activeTheme); |
| 382 | void selectionModeChanged(QAbstract3DGraph::SelectionFlags mode); |
| 383 | void needRender(); |
| 384 | void axisXChanged(QAbstract3DAxis *axis); |
| 385 | void axisYChanged(QAbstract3DAxis *axis); |
| 386 | void axisZChanged(QAbstract3DAxis *axis); |
| 387 | void elementSelected(QAbstract3DGraph::ElementType type); |
| 388 | void measureFpsChanged(bool enabled); |
| 389 | void currentFpsChanged(qreal fps); |
| 390 | void orthoProjectionChanged(bool enabled); |
| 391 | void aspectRatioChanged(qreal ratio); |
| 392 | void horizontalAspectRatioChanged(qreal ratio); |
| 393 | void optimizationHintsChanged(QAbstract3DGraph::OptimizationHints hints); |
| 394 | void polarChanged(bool enabled); |
| 395 | void radialLabelOffsetChanged(float offset); |
| 396 | void reflectionChanged(bool enabled); |
| 397 | void reflectivityChanged(qreal reflectivity); |
| 398 | void localeChanged(const QLocale &locale); |
| 399 | void queriedGraphPositionChanged(const QVector3D &data); |
| 400 | void marginChanged(qreal margin); |
| 401 | |
| 402 | protected: |
| 403 | virtual QAbstract3DAxis *createDefaultAxis(QAbstract3DAxis::AxisOrientation orientation); |
| 404 | QValue3DAxis *createDefaultValueAxis(); |
| 405 | QCategory3DAxis *createDefaultCategoryAxis(); |
| 406 | virtual void startRecordingRemovesAndInserts(); |
| 407 | |
| 408 | private: |
| 409 | void setAxisHelper(QAbstract3DAxis::AxisOrientation orientation, QAbstract3DAxis *axis, |
| 410 | QAbstract3DAxis **axisPtr); |
| 411 | |
| 412 | friend class AbstractDeclarative; |
| 413 | friend class Bars3DController; |
| 414 | friend class QAbstract3DGraphPrivate; |
| 415 | }; |
| 416 | |
| 417 | QT_END_NAMESPACE |
| 418 | |
| 419 | #endif |
| 420 | |