| 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 Charts 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 | //  W A R N I N G | 
| 31 | //  ------------- | 
| 32 | // | 
| 33 | // This file is not part of the Qt Chart API.  It exists purely as an | 
| 34 | // implementation detail.  This header file may change from version to | 
| 35 | // version without notice, or even be removed. | 
| 36 | // | 
| 37 | // We mean it. | 
| 38 |  | 
| 39 | #ifndef CHARTAXISELEMENT_H | 
| 40 | #define CHARTAXISELEMENT_H | 
| 41 |  | 
| 42 | #include <QtCharts/QChartGlobal> | 
| 43 | #include <QtCharts/private/qchartglobal_p.h> | 
| 44 | #include <private/chartelement_p.h> | 
| 45 | #include <private/axisanimation_p.h> | 
| 46 | #include <private/datetimeaxislabel_p.h> | 
| 47 | #include <private/valueaxislabel_p.h> | 
| 48 | #include <QtWidgets/QGraphicsItem> | 
| 49 | #include <QtWidgets/QGraphicsLayoutItem> | 
| 50 | #include <QtCharts/qdatetimeaxis.h> | 
| 51 | #include <QtCharts/QValueAxis> | 
| 52 | #include <QtGui/QFont> | 
| 53 |  | 
| 54 | QT_CHARTS_BEGIN_NAMESPACE | 
| 55 |  | 
| 56 | class ChartPresenter; | 
| 57 | class QAbstractAxis; | 
| 58 |  | 
| 59 | class Q_CHARTS_PRIVATE_EXPORT ChartAxisElement : public ChartElement, public QGraphicsLayoutItem | 
| 60 | { | 
| 61 |     Q_OBJECT | 
| 62 |  | 
| 63 |     using QGraphicsLayoutItem::setGeometry; | 
| 64 | public: | 
| 65 |     ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis = false); | 
| 66 |     ~ChartAxisElement(); | 
| 67 |  | 
| 68 |     virtual QRectF gridGeometry() const = 0; | 
| 69 |     virtual void setGeometry(const QRectF &axis, const QRectF &grid) = 0; | 
| 70 |     virtual bool isEmpty() = 0; | 
| 71 |  | 
| 72 |     void setAnimation(AxisAnimation *animation) { m_animation = animation; } | 
| 73 |     AxisAnimation *animation() const { return m_animation; } | 
| 74 |  | 
| 75 |     QAbstractAxis *axis() const { return m_axis; } | 
| 76 |     void setLayout(QVector<qreal> &layout) { m_layout = layout; } | 
| 77 |     QVector<qreal> &layout() { return m_layout; } // Modifiable reference | 
| 78 |     void setDynamicMinorTickLayout(const QVector<qreal> &layout) { m_dynamicMinorTickLayout = layout; } | 
| 79 |     QVector<qreal> &dynamicMinorTicklayout() { return m_dynamicMinorTickLayout; } // Modifiable reference | 
| 80 |     inline qreal labelPadding() const { return qreal(4.0); } | 
| 81 |     inline qreal titlePadding() const { return qreal(2.0); } | 
| 82 |     void setLabels(const QStringList &labels) { m_labelsList = labels; } | 
| 83 |     QStringList labels() const { return m_labelsList; } | 
| 84 |  | 
| 85 |     qreal min() const; | 
| 86 |     qreal max() const; | 
| 87 |  | 
| 88 |     qreal tickInterval() const; | 
| 89 |     qreal tickAnchor() const; | 
| 90 |  | 
| 91 |     QRectF axisGeometry() const { return m_axisRect; } | 
| 92 |     void setAxisGeometry(const QRectF &axisGeometry) { m_axisRect = axisGeometry; } | 
| 93 |  | 
| 94 |     void axisSelected(); | 
| 95 |  | 
| 96 |     //this flag indicates that axis is used to show intervals it means labels are in between ticks | 
| 97 |     bool intervalAxis() const { return m_intervalAxis; } | 
| 98 |  | 
| 99 |     QStringList createValueLabels(qreal max, qreal min, int ticks, | 
| 100 |                                   qreal tickInterval, qreal tickAnchor, | 
| 101 |                                   QValueAxis::TickType tickType, const QString &format) const; | 
| 102 |     QStringList createLogValueLabels(qreal min, qreal max, qreal base, int ticks, | 
| 103 |                                      const QString &format) const; | 
| 104 |     QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format) const; | 
| 105 |  | 
| 106 |     // from QGraphicsLayoutItem | 
| 107 |     QRectF boundingRect() const | 
| 108 |     { | 
| 109 |         return QRectF(); | 
| 110 |     } | 
| 111 |  | 
| 112 |     // from QGraphicsLayoutItem | 
| 113 |     void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) | 
| 114 |     { | 
| 115 |     } | 
| 116 |  | 
| 117 |     bool labelsEditable() const; | 
| 118 |     void setLabelsEditable(bool labelsEditable); | 
| 119 |  | 
| 120 | protected: | 
| 121 |     virtual QVector<qreal> calculateLayout() const = 0; | 
| 122 |     virtual void updateLayout(QVector<qreal> &layout) = 0; | 
| 123 |  | 
| 124 |     QList<QGraphicsItem *> gridItems() { return m_grid->childItems(); } | 
| 125 |     QList<QGraphicsItem *> minorGridItems() { return m_minorGrid->childItems(); } | 
| 126 |     QList<QGraphicsItem *> labelItems() { return m_labels->childItems(); } | 
| 127 |     QList<QGraphicsItem *> shadeItems() { return m_shades->childItems(); } | 
| 128 |     QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems(); } | 
| 129 |     QList<QGraphicsItem *> minorArrowItems() { return m_minorArrow->childItems(); } | 
| 130 |     QGraphicsTextItem *titleItem() const { return m_title.data(); } | 
| 131 |     QGraphicsItemGroup *gridGroup() { return m_grid.data(); } | 
| 132 |     QGraphicsItemGroup *minorGridGroup() { return m_minorGrid.data(); } | 
| 133 |     QGraphicsItemGroup *labelGroup() { return m_labels.data(); } | 
| 134 |     QGraphicsItemGroup *shadeGroup() { return m_shades.data(); } | 
| 135 |     QGraphicsItemGroup *arrowGroup() { return m_arrow.data(); } | 
| 136 |     QGraphicsItemGroup *minorArrowGroup() { return m_minorArrow.data(); } | 
| 137 |  | 
| 138 | public Q_SLOTS: | 
| 139 |     void handleVisibleChanged(bool visible); | 
| 140 |     void handleArrowVisibleChanged(bool visible); | 
| 141 |     void handleGridVisibleChanged(bool visible); | 
| 142 |     void handleLabelsVisibleChanged(bool visible); | 
| 143 |     void handleShadesVisibleChanged(bool visible); | 
| 144 |     void handleLabelsAngleChanged(int angle); | 
| 145 |     virtual void handleShadesBrushChanged(const QBrush &brush) = 0; | 
| 146 |     virtual void handleShadesPenChanged(const QPen &pen) = 0; | 
| 147 |     virtual void handleArrowPenChanged(const QPen &pen) = 0; | 
| 148 |     virtual void handleGridPenChanged(const QPen &pen) = 0; | 
| 149 |     virtual void handleMinorArrowPenChanged(const QPen &pen) = 0; | 
| 150 |     virtual void handleMinorGridPenChanged(const QPen &pen) = 0; | 
| 151 |     virtual void handleMinorGridLineColorChanged(const QColor &color) = 0; | 
| 152 |     virtual void handleGridLineColorChanged(const QColor &color) = 0; | 
| 153 |     void handleLabelsBrushChanged(const QBrush &brush); | 
| 154 |     void handleLabelsFontChanged(const QFont &font); | 
| 155 |     void handleTitleBrushChanged(const QBrush &brush); | 
| 156 |     void handleTitleFontChanged(const QFont &font); | 
| 157 |     void handleTitleTextChanged(const QString &title); | 
| 158 |     void handleTitleVisibleChanged(bool visible); | 
| 159 |     void handleRangeChanged(qreal min, qreal max); | 
| 160 |     void handleReverseChanged(bool reverse); | 
| 161 |     void handleMinorArrowVisibleChanged(bool visible); | 
| 162 |     void handleMinorGridVisibleChanged(bool visible); | 
| 163 |     void handleLabelsPositionChanged(); | 
| 164 |     void valueLabelEdited(qreal oldValue, qreal newValue); | 
| 165 |     void dateTimeLabelEdited(const QDateTime &oldTime, const QDateTime &newTime); | 
| 166 |  | 
| 167 | Q_SIGNALS: | 
| 168 |     void clicked(); | 
| 169 |  | 
| 170 | private: | 
| 171 |     void connectSlots(); | 
| 172 |     QString formatLabel(const QString &formatSpec, const QByteArray &array, | 
| 173 |                         qreal value, int precision, const QString &preStr, | 
| 174 |                         const QString &postStr) const; | 
| 175 |  | 
| 176 |     QAbstractAxis *m_axis; | 
| 177 |     AxisAnimation *m_animation; | 
| 178 |     QVector<qreal> m_layout; | 
| 179 |     QVector<qreal> m_dynamicMinorTickLayout; | 
| 180 |     QStringList m_labelsList; | 
| 181 |     QRectF m_axisRect; | 
| 182 |     QScopedPointer<QGraphicsItemGroup> m_grid; | 
| 183 |     QScopedPointer<QGraphicsItemGroup> m_arrow; | 
| 184 |     QScopedPointer<QGraphicsItemGroup> m_minorGrid; | 
| 185 |     QScopedPointer<QGraphicsItemGroup> m_minorArrow; | 
| 186 |     QScopedPointer<QGraphicsItemGroup> m_shades; | 
| 187 |     QScopedPointer<QGraphicsItemGroup> m_labels; | 
| 188 |     QScopedPointer<QGraphicsTextItem> m_title; | 
| 189 |     bool m_intervalAxis; | 
| 190 |     bool m_labelsEditable = false; | 
| 191 | }; | 
| 192 |  | 
| 193 | QT_CHARTS_END_NAMESPACE | 
| 194 |  | 
| 195 | #endif /* CHARTAXISELEMENT_H */ | 
| 196 |  |