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