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