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 DECLARATIVECATEGORYAXIS_H |
40 | #define DECLARATIVECATEGORYAXIS_H |
41 | |
42 | #include <QtCharts/QCategoryAxis> |
43 | #include <private/declarativechartglobal_p.h> |
44 | |
45 | #include <QtQml/QQmlListProperty> |
46 | #include <QtQml/QQmlParserStatus> |
47 | |
48 | QT_CHARTS_BEGIN_NAMESPACE |
49 | |
50 | class Q_QMLCHARTS_PRIVATE_EXPORT DeclarativeCategoryRange : public QObject |
51 | { |
52 | Q_OBJECT |
53 | Q_PROPERTY(qreal endValue READ endValue WRITE setEndValue) |
54 | Q_PROPERTY(QString label READ label WRITE setLabel) |
55 | |
56 | public: |
57 | explicit DeclarativeCategoryRange(QObject *parent = 0); |
58 | qreal endValue() { return m_endValue; } |
59 | void setEndValue(qreal endValue) { m_endValue = endValue; } |
60 | QString label() { return m_label; } |
61 | void setLabel(const QString &label); |
62 | |
63 | private: |
64 | qreal m_endValue; |
65 | QString m_label; |
66 | }; |
67 | |
68 | class DeclarativeCategoryAxis : public QCategoryAxis, public QQmlParserStatus |
69 | { |
70 | Q_OBJECT |
71 | Q_INTERFACES(QQmlParserStatus) |
72 | Q_PROPERTY(QQmlListProperty<QObject> axisChildren READ axisChildren) |
73 | Q_CLASSINFO("DefaultProperty" , "axisChildren" ) |
74 | Q_PROPERTY(AxisLabelsPosition labelsPosition READ labelsPosition WRITE setLabelsPosition NOTIFY labelsPositionChanged REVISION 1) |
75 | Q_ENUMS(AxisLabelsPosition) |
76 | |
77 | public: |
78 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api |
79 | enum AxisLabelsPosition { |
80 | AxisLabelsPositionCenter = 0x0, |
81 | AxisLabelsPositionOnValue = 0x1 |
82 | }; |
83 | |
84 | explicit DeclarativeCategoryAxis(QObject *parent = 0); |
85 | QQmlListProperty<QObject> axisChildren(); |
86 | |
87 | |
88 | public: // from QDeclarativeParserStatus |
89 | void classBegin(); |
90 | void componentComplete(); |
91 | |
92 | public: |
93 | AxisLabelsPosition labelsPosition() const; |
94 | void setLabelsPosition(AxisLabelsPosition position); |
95 | |
96 | Q_SIGNALS: |
97 | Q_REVISION(1) void labelsPositionChanged(AxisLabelsPosition position); |
98 | |
99 | public Q_SLOTS: |
100 | Q_INVOKABLE void append(const QString &label, qreal categoryEndValue); |
101 | Q_INVOKABLE void remove(const QString &label); |
102 | Q_INVOKABLE void replace(const QString &oldLabel, const QString &newLabel); |
103 | static void appendAxisChildren(QQmlListProperty<QObject> *list, QObject *element); |
104 | |
105 | private: |
106 | static bool endValueLessThan(const QPair<QString, qreal> &value1, const QPair<QString, qreal> &value2); |
107 | |
108 | private: |
109 | AxisLabelsPosition m_labelsPosition; |
110 | }; |
111 | |
112 | QT_CHARTS_END_NAMESPACE |
113 | |
114 | #endif // DECLARATIVECATEGORYAXIS_H |
115 | |