| 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 Q3DBARSCONTROLLER_p_H |
| 15 | #define Q3DBARSCONTROLLER_p_H |
| 16 | |
| 17 | #include <private/datavisualizationglobal_p.h> |
| 18 | #include <private/abstract3dcontroller_p.h> |
| 19 | |
| 20 | QT_BEGIN_NAMESPACE |
| 21 | |
| 22 | class Bars3DRenderer; |
| 23 | class QBar3DSeries; |
| 24 | |
| 25 | struct Bars3DChangeBitField { |
| 26 | bool multiSeriesScalingChanged : 1; |
| 27 | bool barSpecsChanged : 1; |
| 28 | bool selectedBarChanged : 1; |
| 29 | bool rowsChanged : 1; |
| 30 | bool itemChanged : 1; |
| 31 | bool floorLevelChanged : 1; |
| 32 | bool barSeriesMarginChanged : 1; |
| 33 | |
| 34 | Bars3DChangeBitField() : |
| 35 | multiSeriesScalingChanged(true), |
| 36 | barSpecsChanged(true), |
| 37 | selectedBarChanged(true), |
| 38 | rowsChanged(false), |
| 39 | itemChanged(false), |
| 40 | floorLevelChanged(false), |
| 41 | barSeriesMarginChanged(false) |
| 42 | { |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | class Q_DATAVISUALIZATION_EXPORT Bars3DController : public Abstract3DController |
| 47 | { |
| 48 | Q_OBJECT |
| 49 | |
| 50 | public: |
| 51 | struct ChangeItem { |
| 52 | QBar3DSeries *series; |
| 53 | QPoint point; |
| 54 | }; |
| 55 | struct ChangeRow { |
| 56 | QBar3DSeries *series; |
| 57 | int row; |
| 58 | }; |
| 59 | |
| 60 | private: |
| 61 | Bars3DChangeBitField m_changeTracker; |
| 62 | QList<ChangeItem> m_changedItems; |
| 63 | QList<ChangeRow> m_changedRows; |
| 64 | |
| 65 | // Interaction |
| 66 | QPoint m_selectedBar; // Points to row & column in data window. |
| 67 | QBar3DSeries *m_selectedBarSeries; // Points to the series for which the bar is selected in |
| 68 | // single series selection cases. |
| 69 | QBar3DSeries *m_primarySeries; // Category axis labels are taken from the primary series |
| 70 | |
| 71 | // Look'n'feel |
| 72 | bool m_isMultiSeriesUniform; |
| 73 | bool m_isBarSpecRelative; |
| 74 | GLfloat m_barThicknessRatio; |
| 75 | QSizeF m_barSpacing; |
| 76 | float m_floorLevel; |
| 77 | QSizeF m_barSeriesMargin; |
| 78 | |
| 79 | // Rendering |
| 80 | Bars3DRenderer *m_renderer; |
| 81 | |
| 82 | public: |
| 83 | explicit Bars3DController(QRect rect, Q3DScene *scene = 0); |
| 84 | ~Bars3DController(); |
| 85 | |
| 86 | void initializeOpenGL() override; |
| 87 | void synchDataToRenderer() override; |
| 88 | |
| 89 | void setMultiSeriesScaling(bool uniform); |
| 90 | bool multiSeriesScaling() const; |
| 91 | |
| 92 | // bar thickness, spacing between bars, and is spacing relative to thickness or absolute |
| 93 | // y -component sets the thickness/spacing of z -direction |
| 94 | // With relative 0.0f means side-to-side, 1.0f = one thickness in between |
| 95 | void setBarSpecs(GLfloat thicknessRatio = 1.0f, |
| 96 | const QSizeF &spacing = QSizeF(1.0, 1.0), |
| 97 | bool relative = true); |
| 98 | void setBarSeriesMargin(const QSizeF &margin); |
| 99 | QSizeF barSeriesMargin(); |
| 100 | |
| 101 | GLfloat barThickness(); |
| 102 | QSizeF barSpacing(); |
| 103 | bool isBarSpecRelative(); |
| 104 | void setFloorLevel(float level); |
| 105 | float floorLevel() const; |
| 106 | |
| 107 | inline QBar3DSeries *selectedSeries() const { return m_selectedBarSeries; } |
| 108 | |
| 109 | void setSelectionMode(QAbstract3DGraph::SelectionFlags mode) override; |
| 110 | void setSelectedBar(const QPoint &position, QBar3DSeries *series, bool enterSlice); |
| 111 | void clearSelection() override; |
| 112 | |
| 113 | void handleAxisAutoAdjustRangeChangedInOrientation( |
| 114 | QAbstract3DAxis::AxisOrientation orientation, bool autoAdjust) override; |
| 115 | void handleSeriesVisibilityChangedBySender(QObject *sender) override; |
| 116 | void handlePendingClick() override; |
| 117 | |
| 118 | static QPoint invalidSelectionPosition(); |
| 119 | |
| 120 | void setAxisX(QAbstract3DAxis *axis) override; |
| 121 | void setAxisZ(QAbstract3DAxis *axis) override; |
| 122 | |
| 123 | virtual void setPrimarySeries(QBar3DSeries *series); |
| 124 | virtual QBar3DSeries *primarySeries() const; |
| 125 | void addSeries(QAbstract3DSeries *series) override; |
| 126 | void removeSeries(QAbstract3DSeries *series) override; |
| 127 | void insertSeries(int index, QAbstract3DSeries *series) override; |
| 128 | virtual QList<QBar3DSeries *> barSeriesList(); |
| 129 | |
| 130 | void handleAxisRangeChangedBySender(QObject *sender) override; |
| 131 | void adjustAxisRanges() override; |
| 132 | |
| 133 | public Q_SLOTS: |
| 134 | void handleArrayReset(); |
| 135 | void handleRowsAdded(int startIndex, int count); |
| 136 | void handleRowsChanged(int startIndex, int count); |
| 137 | void handleRowsRemoved(int startIndex, int count); |
| 138 | void handleRowsInserted(int startIndex, int count); |
| 139 | void handleItemChanged(int rowIndex, int columnIndex); |
| 140 | void handleDataRowLabelsChanged(); |
| 141 | void handleDataColumnLabelsChanged(); |
| 142 | void handleRowColorsChanged(); |
| 143 | |
| 144 | Q_SIGNALS: |
| 145 | void primarySeriesChanged(QBar3DSeries *series); |
| 146 | void selectedSeriesChanged(QBar3DSeries *series); |
| 147 | |
| 148 | protected: |
| 149 | QAbstract3DAxis *createDefaultAxis(QAbstract3DAxis::AxisOrientation orientation) override; |
| 150 | |
| 151 | private: |
| 152 | void adjustSelectionPosition(QPoint &pos, const QBar3DSeries *series); |
| 153 | |
| 154 | Q_DISABLE_COPY(Bars3DController) |
| 155 | }; |
| 156 | |
| 157 | QT_END_NAMESPACE |
| 158 | |
| 159 | #endif |
| 160 | |