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