1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | // W A R N I N G |
5 | // ------------- |
6 | // |
7 | // This file is not part of the Qt Chart API. It exists purely as an |
8 | // implementation detail. This header file may change from version to |
9 | // version without notice, or even be removed. |
10 | // |
11 | // We mean it. |
12 | |
13 | #ifndef DECLARATIVECATEGORYAXIS_H |
14 | #define DECLARATIVECATEGORYAXIS_H |
15 | |
16 | #include <QtQml/qqmlregistration.h> |
17 | #include <QtCharts/QCategoryAxis> |
18 | #include <private/declarativechartglobal_p.h> |
19 | |
20 | #include <QtQml/QQmlListProperty> |
21 | #include <QtQml/QQmlParserStatus> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | class Q_CHARTSQML_PRIVATE_EXPORT DeclarativeCategoryRange : public QObject |
26 | { |
27 | Q_OBJECT |
28 | Q_PROPERTY(qreal endValue READ endValue WRITE setEndValue) |
29 | Q_PROPERTY(QString label READ label WRITE setLabel) |
30 | QML_NAMED_ELEMENT(CategoryRange) |
31 | QML_ADDED_IN_VERSION(1, 1) |
32 | QML_EXTRA_VERSION(2, 0) |
33 | |
34 | public: |
35 | explicit DeclarativeCategoryRange(QObject *parent = 0); |
36 | qreal endValue() { return m_endValue; } |
37 | void setEndValue(qreal endValue) { m_endValue = endValue; } |
38 | QString label() { return m_label; } |
39 | void setLabel(const QString &label); |
40 | |
41 | private: |
42 | qreal m_endValue; |
43 | QString m_label; |
44 | }; |
45 | |
46 | class DeclarativeCategoryAxis : public QCategoryAxis, public QQmlParserStatus |
47 | { |
48 | Q_OBJECT |
49 | Q_INTERFACES(QQmlParserStatus) |
50 | Q_PROPERTY(QQmlListProperty<QObject> axisChildren READ axisChildren) |
51 | Q_CLASSINFO("DefaultProperty" , "axisChildren" ) |
52 | Q_PROPERTY(AxisLabelsPosition labelsPosition READ labelsPosition WRITE setLabelsPosition NOTIFY labelsPositionChanged REVISION(2, 1)) |
53 | Q_ENUMS(AxisLabelsPosition) |
54 | QML_NAMED_ELEMENT(CategoryAxis) |
55 | QML_ADDED_IN_VERSION(1, 1) |
56 | QML_EXTRA_VERSION(2, 0) |
57 | |
58 | public: |
59 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api |
60 | enum AxisLabelsPosition { |
61 | AxisLabelsPositionCenter = 0x0, |
62 | AxisLabelsPositionOnValue = 0x1 |
63 | }; |
64 | |
65 | explicit DeclarativeCategoryAxis(QObject *parent = 0); |
66 | QQmlListProperty<QObject> axisChildren(); |
67 | |
68 | |
69 | public: // from QDeclarativeParserStatus |
70 | void classBegin() override; |
71 | void componentComplete() override; |
72 | |
73 | public: |
74 | AxisLabelsPosition labelsPosition() const; |
75 | void setLabelsPosition(AxisLabelsPosition position); |
76 | |
77 | Q_SIGNALS: |
78 | Q_REVISION(2, 1) void labelsPositionChanged(AxisLabelsPosition position); |
79 | |
80 | public Q_SLOTS: |
81 | Q_INVOKABLE void append(const QString &label, qreal categoryEndValue); |
82 | Q_INVOKABLE void remove(const QString &label); |
83 | Q_INVOKABLE void replace(const QString &oldLabel, const QString &newLabel); |
84 | static void appendAxisChildren(QQmlListProperty<QObject> *list, QObject *element); |
85 | |
86 | private: |
87 | static bool endValueLessThan(const QPair<QString, qreal> &value1, const QPair<QString, qreal> &value2); |
88 | |
89 | private: |
90 | AxisLabelsPosition m_labelsPosition; |
91 | }; |
92 | |
93 | QT_END_NAMESPACE |
94 | |
95 | #endif // DECLARATIVECATEGORYAXIS_H |
96 | |