@@ -1,87 +1,98 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativecategoryaxis.h" |
|
22 | 22 | #include <QDebug> |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | /*! |
|
27 | 27 | \qmlclass CategoryRange |
|
28 | 28 | \brief With CategoryRange you can define a range used by a CategoryAxis. |
|
29 | 29 | \sa CategoryAxis |
|
30 | 30 | */ |
|
31 | 31 | |
|
32 | 32 | DeclarativeCategoryRange::DeclarativeCategoryRange(QObject *parent) : |
|
33 | 33 | QObject(parent), |
|
34 | 34 | m_endValue(0), |
|
35 | 35 | m_label(QString()) |
|
36 | 36 | { |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | DeclarativeCategoryAxis::DeclarativeCategoryAxis(QObject *parent) : |
|
40 | 40 | QCategoryAxis(parent) |
|
41 | 41 | { |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | void DeclarativeCategoryAxis::classBegin() |
|
45 | 45 | { |
|
46 | 46 | } |
|
47 | 47 | |
|
48 | 48 | void DeclarativeCategoryAxis::componentComplete() |
|
49 | 49 | { |
|
50 | QList<QPair<QString, qreal> > ranges; | |
|
50 | 51 | foreach(QObject *child, children()) { |
|
51 | 52 | if (qobject_cast<DeclarativeCategoryRange *>(child)) { |
|
52 | 53 | DeclarativeCategoryRange *range = qobject_cast<DeclarativeCategoryRange *>(child); |
|
53 | append(range->label(), range->endValue()); | |
|
54 | ranges.append(QPair<QString, qreal>(range->label(), range->endValue())); | |
|
54 | 55 | } |
|
55 | 56 | } |
|
57 | ||
|
58 | // Sort and append the range objects according to end value | |
|
59 | qSort(ranges.begin(), ranges.end(), endValueLessThan); | |
|
60 | for (int i(0); i < ranges.count(); i++) | |
|
61 | append(ranges.at(i).first, ranges.at(i).second); | |
|
62 | } | |
|
63 | ||
|
64 | bool DeclarativeCategoryAxis::endValueLessThan(const QPair<QString, qreal> &value1, const QPair<QString, qreal> &value2) | |
|
65 | { | |
|
66 | return value1.second < value2.second; | |
|
56 | 67 | } |
|
57 | 68 | |
|
58 | 69 | QDeclarativeListProperty<QObject> DeclarativeCategoryAxis::axisChildren() |
|
59 | 70 | { |
|
60 | 71 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeCategoryAxis::appendAxisChildren); |
|
61 | 72 | } |
|
62 | 73 | |
|
63 | 74 | void DeclarativeCategoryAxis::append(const QString &label, qreal categoryEndValue) |
|
64 | 75 | { |
|
65 | 76 | QCategoryAxis::append(label, categoryEndValue); |
|
66 | 77 | } |
|
67 | 78 | |
|
68 | 79 | void DeclarativeCategoryAxis::remove(const QString &label) |
|
69 | 80 | { |
|
70 | 81 | QCategoryAxis::remove(label); |
|
71 | 82 | } |
|
72 | 83 | |
|
73 | 84 | void DeclarativeCategoryAxis::replace(const QString& oldLabel, const QString& newLabel) |
|
74 | 85 | { |
|
75 | 86 | QCategoryAxis::replaceLabel(oldLabel, newLabel); |
|
76 | 87 | } |
|
77 | 88 | |
|
78 | 89 | void DeclarativeCategoryAxis::appendAxisChildren(QDeclarativeListProperty<QObject> *list, QObject *element) |
|
79 | 90 | { |
|
80 | 91 | // Empty implementation; the children are parsed in componentComplete instead |
|
81 | 92 | Q_UNUSED(list) |
|
82 | 93 | Q_UNUSED(element) |
|
83 | 94 | } |
|
84 | 95 | |
|
85 | 96 | #include "moc_declarativecategoryaxis.cpp" |
|
86 | 97 | |
|
87 | 98 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,77 +1,80 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVECATEGORYAXIS_H |
|
22 | 22 | #define DECLARATIVECATEGORYAXIS_H |
|
23 | 23 | |
|
24 | 24 | #include "qcategoryaxis.h" |
|
25 | 25 | #ifdef QT5_QUICK_1 |
|
26 | 26 | #include <QtQuick1/QDeclarativeListProperty> |
|
27 | 27 | #include <QtQuick1/QDeclarativeParserStatus> |
|
28 | 28 | #else |
|
29 | 29 | #include <QtDeclarative/QDeclarativeListProperty> |
|
30 | 30 | #include <QtDeclarative/QDeclarativeParserStatus> |
|
31 | 31 | #endif |
|
32 | 32 | |
|
33 | 33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 34 | |
|
35 | 35 | class DeclarativeCategoryRange : public QObject |
|
36 | 36 | { |
|
37 | 37 | Q_OBJECT |
|
38 | 38 | Q_PROPERTY(qreal endValue READ endValue WRITE setEndValue) |
|
39 | 39 | Q_PROPERTY(QString label READ label WRITE setLabel) |
|
40 | 40 | |
|
41 | 41 | public: |
|
42 | 42 | explicit DeclarativeCategoryRange(QObject *parent = 0); |
|
43 | 43 | qreal endValue() { return m_endValue; } |
|
44 | 44 | void setEndValue(qreal endValue) { m_endValue = endValue; } |
|
45 | 45 | QString label() { return m_label; } |
|
46 | 46 | void setLabel(QString label) { m_label = label; } |
|
47 | 47 | |
|
48 | 48 | private: |
|
49 | 49 | qreal m_endValue; |
|
50 | 50 | QString m_label; |
|
51 | 51 | }; |
|
52 | 52 | |
|
53 | 53 | class DeclarativeCategoryAxis : public QCategoryAxis, public QDeclarativeParserStatus |
|
54 | 54 | { |
|
55 | 55 | Q_OBJECT |
|
56 | 56 | Q_INTERFACES(QDeclarativeParserStatus) |
|
57 | 57 | Q_PROPERTY(QDeclarativeListProperty<QObject> axisChildren READ axisChildren) |
|
58 | 58 | Q_CLASSINFO("DefaultProperty", "axisChildren") |
|
59 | 59 | |
|
60 | 60 | public: |
|
61 | 61 | explicit DeclarativeCategoryAxis(QObject *parent = 0); |
|
62 | 62 | QDeclarativeListProperty<QObject> axisChildren(); |
|
63 | 63 | |
|
64 | 64 | public: // from QDeclarativeParserStatus |
|
65 | 65 | void classBegin(); |
|
66 | 66 | void componentComplete(); |
|
67 | 67 | |
|
68 | 68 | public Q_SLOTS: |
|
69 | 69 | Q_INVOKABLE void append(const QString &label, qreal categoryEndValue); |
|
70 | 70 | Q_INVOKABLE void remove(const QString &label); |
|
71 | 71 | Q_INVOKABLE void replace(const QString& oldLabel, const QString& newLabel); |
|
72 | 72 | static void appendAxisChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
73 | ||
|
74 | private: | |
|
75 | static bool endValueLessThan(const QPair<QString, qreal> &value1, const QPair<QString, qreal> &value2); | |
|
73 | 76 | }; |
|
74 | 77 | |
|
75 | 78 | QTCOMMERCIALCHART_END_NAMESPACE |
|
76 | 79 | |
|
77 | 80 | #endif // DECLARATIVECATEGORYAXIS_H |
General Comments 0
You need to be logged in to leave comments.
Login now