@@ -10,11 +10,9 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : | |||
|
10 | 10 | QDeclarativeItem(parent) |
|
11 | 11 | { |
|
12 | 12 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
13 | connect(this, SIGNAL(parentChanged()), | |
|
14 | this, SLOT(setParentForSeries())); | |
|
15 | 13 | } |
|
16 | 14 | |
|
17 |
void DeclarativeBarSeries:: |
|
|
15 | void DeclarativeBarSeries::componentComplete() | |
|
18 | 16 | { |
|
19 | 17 | if (!m_series) { |
|
20 | 18 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); |
@@ -23,9 +21,11 void DeclarativeBarSeries::setParentForSeries() | |||
|
23 | 21 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); |
|
24 | 22 | Q_ASSERT(chart); |
|
25 | 23 | |
|
26 | QStringList categories; | |
|
27 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
|
28 | m_series = new QBarSeries(categories); | |
|
24 | // QStringList categories; | |
|
25 | // categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
|
26 | // m_series = new QBarSeries(categories); | |
|
27 | // m_series = new QBarSeries(m_categories); | |
|
28 | m_series = new QBarSeries(m_categories); | |
|
29 | 29 | |
|
30 | 30 | // TODO: use data from model |
|
31 | 31 | QBarSet *set0 = new QBarSet("Bub"); |
@@ -45,6 +45,25 void DeclarativeBarSeries::setParentForSeries() | |||
|
45 | 45 | } |
|
46 | 46 | } |
|
47 | 47 | |
|
48 | void DeclarativeBarSeries::setBarCategories(QStringList categories) | |
|
49 | { | |
|
50 | m_categories = categories; | |
|
51 | if (m_series) { | |
|
52 | // Replace categories of the QBarSeries with the new categories | |
|
53 | for (int i(0); i < m_categories.count(); i++) { | |
|
54 | if (m_series->categories().at(i) != m_categories.at(i)) | |
|
55 | m_series->insertCategory(m_series->categoryCount(), m_categories.at(i)); | |
|
56 | } | |
|
57 | while (m_series->categoryCount() > m_categories.count()) | |
|
58 | m_series->removeCategory(m_series->categoryCount() - 1); | |
|
59 | } | |
|
60 | } | |
|
61 | ||
|
62 | QStringList DeclarativeBarSeries::barCategories() | |
|
63 | { | |
|
64 | return m_categories; | |
|
65 | } | |
|
66 | ||
|
48 | 67 | #include "moc_declarativebarseries.cpp" |
|
49 | 68 | |
|
50 | 69 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -12,20 +12,26 class QBarSeries; | |||
|
12 | 12 | class DeclarativeBarSeries : public QDeclarativeItem |
|
13 | 13 | { |
|
14 | 14 | Q_OBJECT |
|
15 | Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories) | |
|
15 | 16 | |
|
16 | 17 | public: |
|
17 | 18 | explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0); |
|
18 | 19 | |
|
20 | public: // from QDeclarativeParserStatus | |
|
21 | void componentComplete(); | |
|
22 | ||
|
23 | public: | |
|
24 | void setBarCategories(QStringList categories); | |
|
25 | QStringList barCategories(); | |
|
26 | ||
|
19 | 27 | signals: |
|
20 | 28 | |
|
21 | 29 | public slots: |
|
22 | 30 | |
|
23 | private slots: | |
|
24 | void setParentForSeries(); | |
|
25 | ||
|
26 | private: | |
|
31 | public: | |
|
27 | 32 | QChart *m_chart; |
|
28 | 33 | QBarSeries *m_series; |
|
34 | QStringList m_categories; | |
|
29 | 35 | }; |
|
30 | 36 | |
|
31 | 37 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -28,31 +28,31 void DeclarativeScatterSeries::componentComplete() | |||
|
28 | 28 | Q_ASSERT(m_chart); |
|
29 | 29 | |
|
30 | 30 | m_series = new QScatterSeries(); |
|
31 |
for (int i(0); i < m_ |
|
|
32 |
DeclarativeXyPoint *element = m_ |
|
|
31 | for (int i(0); i < m_points.count(); i++) { | |
|
32 | DeclarativeXyPoint *element = m_points.at(i); | |
|
33 | 33 | *m_series << QPointF(element->x(), element->y()); |
|
34 | 34 | } |
|
35 | 35 | m_chart->addSeries(m_series); |
|
36 | 36 | } |
|
37 | 37 | } |
|
38 | 38 | |
|
39 |
QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries:: |
|
|
39 | QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points() | |
|
40 | 40 | { |
|
41 | 41 | return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, |
|
42 |
&DeclarativeScatterSeries::append |
|
|
42 | &DeclarativeScatterSeries::appendPoints); | |
|
43 | 43 | } |
|
44 | 44 | |
|
45 |
void DeclarativeScatterSeries::append |
|
|
45 | void DeclarativeScatterSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, | |
|
46 | 46 | DeclarativeXyPoint *element) |
|
47 | 47 | { |
|
48 | 48 | DeclarativeScatterSeries *series = qobject_cast<DeclarativeScatterSeries *>(list->object); |
|
49 |
qDebug() << "append |
|
|
50 |
qDebug() << "append |
|
|
51 |
qDebug() << "append |
|
|
52 |
qDebug() << "append |
|
|
53 |
qDebug() << "append |
|
|
49 | qDebug() << "appendPoints: " << series; | |
|
50 | qDebug() << "appendPoints: " << element; | |
|
51 | qDebug() << "appendPoints: " << element->x(); | |
|
52 | qDebug() << "appendPoints: " << element->y(); | |
|
53 | qDebug() << "appendPoints: " << series->m_series; | |
|
54 | 54 | if (series) { |
|
55 |
series->m_ |
|
|
55 | series->m_points.append(element); | |
|
56 | 56 | if (series->m_series) |
|
57 | 57 | series->m_series->add(element->x(), element->y()); |
|
58 | 58 | } |
@@ -4,17 +4,16 | |||
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include "declarativexypoint.h" |
|
6 | 6 | #include <QDeclarativeItem> |
|
7 | #include <QDeclarativeParserStatus> | |
|
8 | 7 | |
|
9 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | 9 | |
|
11 | 10 | class QChart; |
|
12 | 11 | class QScatterSeries; |
|
13 | 12 | |
|
14 |
class DeclarativeScatterSeries : public QDeclarativeItem |
|
|
13 | class DeclarativeScatterSeries : public QDeclarativeItem | |
|
15 | 14 | { |
|
16 | 15 | Q_OBJECT |
|
17 |
Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> |
|
|
16 | Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points) | |
|
18 | 17 | |
|
19 | 18 | public: |
|
20 | 19 | explicit DeclarativeScatterSeries(QDeclarativeItem *parent = 0); |
@@ -24,12 +23,12 public: // from QDeclarativeParserStatus | |||
|
24 | 23 | void componentComplete(); |
|
25 | 24 | |
|
26 | 25 | public: |
|
27 |
QDeclarativeListProperty<DeclarativeXyPoint> |
|
|
26 | QDeclarativeListProperty<DeclarativeXyPoint> points(); | |
|
28 | 27 | |
|
29 | 28 | signals: |
|
30 | 29 | |
|
31 | 30 | public slots: |
|
32 |
static void append |
|
|
31 | static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list, | |
|
33 | 32 | DeclarativeXyPoint *element); |
|
34 | 33 | |
|
35 | 34 | private slots: |
@@ -37,7 +36,7 private slots: | |||
|
37 | 36 | public: |
|
38 | 37 | QChart *m_chart; // not owned |
|
39 | 38 | QScatterSeries *m_series; // not owned |
|
40 |
QList<DeclarativeXyPoint *> m_ |
|
|
39 | QList<DeclarativeXyPoint *> m_points; // not owned | |
|
41 | 40 | }; |
|
42 | 41 | |
|
43 | 42 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -35,6 +35,10 Rectangle { | |||
|
35 | 35 | theme: Chart.ThemeBlueCerulean |
|
36 | 36 | |
|
37 | 37 | BarSeries { |
|
38 | barCategories: [ "2008", "2009", "2010", "2011", "2012" ] | |
|
39 | // data: [ | |
|
40 | // BarSet { } | |
|
41 | // ] | |
|
38 | 42 | } |
|
39 | 43 | |
|
40 | 44 | // PieSeries { |
@@ -56,7 +60,7 Rectangle { | |||
|
56 | 60 | anchors.bottom: parent.bottom |
|
57 | 61 | anchors.left: parent.left |
|
58 | 62 | anchors.right: parent.right |
|
59 |
theme: Chart.Theme |
|
|
63 | theme: Chart.ThemeBrownSand | |
|
60 | 64 | |
|
61 | 65 | LineSeries { |
|
62 | 66 | data: [ |
@@ -67,34 +71,34 Rectangle { | |||
|
67 | 71 | ] |
|
68 | 72 | } |
|
69 | 73 | |
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
74 | ScatterSeries { | |
|
75 | id: scatter | |
|
76 | points: [ | |
|
77 | XyPoint { x: 1.1; y: 1.1 }, | |
|
78 | XyPoint { x: 1.1; y: 1.2 }, | |
|
79 | XyPoint { x: 1.17; y: 1.15 } | |
|
80 | ] | |
|
81 | } | |
|
82 | ScatterSeries { | |
|
83 | points: [ | |
|
84 | XyPoint { x: 1.5; y: 1.5 }, | |
|
85 | XyPoint { x: 1.5; y: 1.6 }, | |
|
86 | XyPoint { x: 1.57; y: 1.55 } | |
|
87 | ] | |
|
88 | } | |
|
89 | ScatterSeries { | |
|
90 | points: [ | |
|
91 | XyPoint { x: 2.0; y: 2.0 }, | |
|
92 | XyPoint { x: 2.0; y: 2.1 }, | |
|
93 | XyPoint { x: 2.07; y: 2.05 } | |
|
94 | ] | |
|
95 | } | |
|
96 | ScatterSeries { | |
|
97 | points: [ | |
|
98 | XyPoint { x: 2.6; y: 2.6 }, | |
|
99 | XyPoint { x: 2.6; y: 2.7 }, | |
|
100 | XyPoint { x: 2.67; y: 2.65 } | |
|
101 | ] | |
|
102 | } | |
|
99 | 103 |
|
|
100 | 104 | } |
General Comments 0
You need to be logged in to leave comments.
Login now