@@ -1,54 +1,56 | |||||
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 | import QtQuick 1.0 |
|
21 | import QtQuick 1.0 | |
22 | import QtCommercial.Chart 1.0 |
|
22 | import QtCommercial.Chart 1.0 | |
23 |
|
23 | |||
24 | Rectangle { |
|
24 | Rectangle { | |
25 | anchors.fill: parent |
|
25 | anchors.fill: parent | |
26 |
|
26 | |||
27 | ChartView { |
|
27 | ChartView { | |
28 | title: "Scatters" |
|
28 | title: "Scatters" | |
29 | anchors.fill: parent |
|
29 | anchors.fill: parent | |
30 | theme: ChartView.ChartThemeBlueCerulean |
|
30 | theme: ChartView.ChartThemeBlueCerulean | |
|
31 | axisX.max: 4 | |||
|
32 | axisY.max: 4 | |||
31 |
|
33 | |||
32 | ScatterSeries { |
|
34 | ScatterSeries { | |
33 | id: scatter1 |
|
35 | id: scatter1 | |
34 | name: "Scatter1" |
|
36 | name: "Scatter1" | |
35 | XyPoint { x: 1.5; y: 1.5 } |
|
37 | XyPoint { x: 1.5; y: 1.5 } | |
36 | XyPoint { x: 1.5; y: 1.6 } |
|
38 | XyPoint { x: 1.5; y: 1.6 } | |
37 | XyPoint { x: 1.57; y: 1.55 } |
|
39 | XyPoint { x: 1.57; y: 1.55 } | |
38 | XyPoint { x: 1.8; y: 1.8 } |
|
40 | XyPoint { x: 1.8; y: 1.8 } | |
39 | XyPoint { x: 1.9; y: 1.6 } |
|
41 | XyPoint { x: 1.9; y: 1.6 } | |
40 | XyPoint { x: 2.1; y: 1.3 } |
|
42 | XyPoint { x: 2.1; y: 1.3 } | |
41 | XyPoint { x: 2.5; y: 2.1 } |
|
43 | XyPoint { x: 2.5; y: 2.1 } | |
42 | } |
|
44 | } | |
43 |
|
45 | |||
44 | ScatterSeries { |
|
46 | ScatterSeries { | |
45 | name: "Scatter2" |
|
47 | name: "Scatter2" | |
46 | XyPoint { x: 2.0; y: 2.0 } |
|
48 | XyPoint { x: 2.0; y: 2.0 } | |
47 | XyPoint { x: 2.0; y: 2.1 } |
|
49 | XyPoint { x: 2.0; y: 2.1 } | |
48 | XyPoint { x: 2.07; y: 2.05 } |
|
50 | XyPoint { x: 2.07; y: 2.05 } | |
49 | XyPoint { x: 2.2; y: 2.9 } |
|
51 | XyPoint { x: 2.2; y: 2.9 } | |
50 | XyPoint { x: 2.4; y: 2.7 } |
|
52 | XyPoint { x: 2.4; y: 2.7 } | |
51 | XyPoint { x: 2.67; y: 2.65 } |
|
53 | XyPoint { x: 2.67; y: 2.65 } | |
52 | } |
|
54 | } | |
53 | } |
|
55 | } | |
54 | } |
|
56 | } |
@@ -1,102 +1,120 | |||||
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 | import QtQuick 1.0 |
|
21 | import QtQuick 1.0 | |
22 | import QtCommercial.Chart 1.0 |
|
22 | import QtCommercial.Chart 1.0 | |
23 | import QmlCustomModel 1.0 |
|
23 | import QmlCustomModel 1.0 | |
24 |
|
24 | |||
25 | Rectangle { |
|
25 | Rectangle { | |
26 | width: parent.width |
|
26 | width: parent.width | |
27 | height: parent.height |
|
27 | height: parent.height | |
28 |
|
28 | |||
29 | ChartView { |
|
29 | ChartView { | |
30 | id: chart |
|
30 | id: chart | |
31 | title: "Custom model example" |
|
31 | title: "Custom model example" | |
32 | anchors.fill: parent |
|
32 | anchors.fill: parent | |
33 | theme: ChartView.ChartThemeLight |
|
33 | theme: ChartView.ChartThemeLight | |
|
34 | axisX.max: 20 | |||
|
35 | axisY.max: 20 | |||
34 |
|
36 | |||
35 | // For dynamic data we use a custom data model derived from QAbstractiItemModel |
|
37 | // For dynamic data we use a custom data model derived from QAbstractiItemModel | |
36 | CustomModel { |
|
38 | CustomModel { | |
37 | id: customModel |
|
39 | id: customModel | |
38 |
CustomModelElement { values: [ |
|
40 | CustomModelElement { values: [index, "Manufacturer", 1, 2] } | |
39 |
CustomModelElement { values: [ |
|
41 | CustomModelElement { values: [1, "Volkswagen", 13.5, 12.5] } | |
40 |
CustomModelElement { values: [ |
|
42 | CustomModelElement { values: [2, "Toyota", 10.9, 9.9] } | |
41 |
CustomModelElement { values: [ |
|
43 | CustomModelElement { values: [3, "Ford", 8.6, 7.6] } | |
42 |
CustomModelElement { values: [ |
|
44 | CustomModelElement { values: [4, "Skoda", 8.2, 7.2] } | |
|
45 | CustomModelElement { values: [5, "Volvo", 6.8, 5.8] } | |||
43 | } |
|
46 | } | |
44 |
|
47 | |||
45 | LineSeries { |
|
48 | LineSeries { | |
46 |
name: " |
|
49 | name: "Volkswagen" | |
47 |
|
50 | HXYModelMapper { | ||
48 | // TODO: the new mapper api |
|
51 | model: customModel | |
49 | // VXYModelMapper { |
|
52 | xRow: 0 | |
50 |
|
|
53 | yRow: 1 | |
51 |
|
|
54 | first: 2 | |
52 | // yColumn: 1 |
|
55 | } | |
53 | // } |
|
|||
54 |
|
|
56 | } | |
55 |
|
57 | |||
|
58 | LineSeries { | |||
|
59 | name: "Toyota" | |||
|
60 | HXYModelMapper { | |||
|
61 | model: customModel | |||
|
62 | xRow: 0 | |||
|
63 | yRow: 2 | |||
|
64 | first: 2 | |||
|
65 | } | |||
|
66 | } | |||
56 |
|
67 | |||
57 | PieSeries { |
|
68 | PieSeries { | |
58 | id: pieSeries |
|
69 | id: pieSeries | |
59 | size: 0.4 |
|
70 | size: 0.4 | |
60 | horizontalPosition: 0.2 |
|
71 | horizontalPosition: 0.2 | |
61 | verticalPosition: 0.3 |
|
72 | verticalPosition: 0.3 | |
62 | } |
|
73 | } | |
63 |
|
74 | |||
64 | VPieModelMapper { |
|
75 | VPieModelMapper { | |
65 | series: pieSeries |
|
76 | series: pieSeries | |
66 | model: customModel |
|
77 | model: customModel | |
67 |
labelsColumn: |
|
78 | labelsColumn: 1 | |
68 |
valuesColumn: |
|
79 | valuesColumn: 2 | |
|
80 | first: 1 | |||
69 | } |
|
81 | } | |
70 |
|
82 | |||
71 |
|
|
83 | AreaSeries { | |
72 |
|
|
84 | name: "Ford" | |
73 |
|
|
85 | upperSeries: LineSeries { | |
74 | // lowerSeries: LineSeries {} |
|
86 | HXYModelMapper { | |
75 | // } |
|
87 | model: customModel | |
|
88 | xRow: 0 | |||
|
89 | yRow: 3 | |||
|
90 | first: 2 | |||
|
91 | } | |||
|
92 | } | |||
|
93 | } | |||
76 |
|
|
94 | ||
77 | // BarSeries { |
|
95 | // BarSeries { | |
78 | // model: customModel |
|
96 | // model: customModel | |
79 | // modelMapper.first: 0 |
|
97 | // modelMapper.first: 0 | |
80 | // } |
|
98 | // } | |
81 | } |
|
99 | } | |
82 |
|
100 | |||
83 |
|
101 | |||
84 | // TODO: you could also implement appending to your model, for example: |
|
102 | // TODO: you could also implement appending to your model, for example: | |
85 | // pieSeries.model.append(["Others", 52.0]); |
|
103 | // pieSeries.model.append(["Others", 52.0]); | |
86 |
|
104 | |||
87 | // TODO: show how to use data from a list model in a chart view |
|
105 | // TODO: show how to use data from a list model in a chart view | |
88 | // i.e. copy the data into a custom model |
|
106 | // i.e. copy the data into a custom model | |
89 | // ListModel { |
|
107 | // ListModel { | |
90 | // id: listModel |
|
108 | // id: listModel | |
91 | // ListElement { |
|
109 | // ListElement { | |
92 | // label: "Volkswagen" |
|
110 | // label: "Volkswagen" | |
93 | // value: 13.5 |
|
111 | // value: 13.5 | |
94 | // } |
|
112 | // } | |
95 | // ListElement { |
|
113 | // ListElement { | |
96 | // label: "Toyota" |
|
114 | // label: "Toyota" | |
97 | // value: 10.9 |
|
115 | // value: 10.9 | |
98 | // } |
|
116 | // } | |
99 | // // and so on... |
|
117 | // // and so on... | |
100 | // } |
|
118 | // } | |
101 |
|
119 | |||
102 | } |
|
120 | } |
@@ -1,250 +1,250 | |||||
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 "declarativechart.h" |
|
21 | #include "declarativechart.h" | |
22 | #include <QPainter> |
|
22 | #include <QPainter> | |
23 | #include "declarativelineseries.h" |
|
23 | #include "declarativelineseries.h" | |
24 | #include "declarativeareaseries.h" |
|
24 | #include "declarativeareaseries.h" | |
25 | #include "declarativebarseries.h" |
|
25 | #include "declarativebarseries.h" | |
26 | #include "declarativepieseries.h" |
|
26 | #include "declarativepieseries.h" | |
27 | #include "declarativesplineseries.h" |
|
27 | #include "declarativesplineseries.h" | |
28 | #include "declarativescatterseries.h" |
|
28 | #include "declarativescatterseries.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
32 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) | |
33 | : QDeclarativeItem(parent), |
|
33 | : QDeclarativeItem(parent), | |
34 | m_chart(new QChart(this)), |
|
34 | m_chart(new QChart(this)), | |
35 | m_legend(LegendTop) |
|
35 | m_legend(LegendTop) | |
36 | { |
|
36 | { | |
37 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
37 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
38 | m_chart->axisX()->setNiceNumbersEnabled(false); |
|
38 | // m_chart->axisX()->setNiceNumbersEnabled(false); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | DeclarativeChart::~DeclarativeChart() |
|
41 | DeclarativeChart::~DeclarativeChart() | |
42 | { |
|
42 | { | |
43 | delete m_chart; |
|
43 | delete m_chart; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
46 | void DeclarativeChart::childEvent(QChildEvent *event) | |
47 | { |
|
47 | { | |
48 | if (event->type() == QEvent::ChildAdded) { |
|
48 | if (event->type() == QEvent::ChildAdded) { | |
49 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
49 | if (qobject_cast<QAbstractSeries *>(event->child())) { | |
50 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
50 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); | |
51 | } |
|
51 | } | |
52 | } |
|
52 | } | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | void DeclarativeChart::componentComplete() |
|
55 | void DeclarativeChart::componentComplete() | |
56 | { |
|
56 | { | |
57 | // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max(); |
|
57 | // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max(); | |
58 | foreach(QObject *child, children()) { |
|
58 | foreach(QObject *child, children()) { | |
59 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
59 | if (qobject_cast<QAbstractSeries *>(child)) { | |
60 | // qDebug() << "DeclarativeChart::componentComplete(), add: " << child; |
|
60 | // qDebug() << "DeclarativeChart::componentComplete(), add: " << child; | |
61 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); |
|
61 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); | |
62 | } |
|
62 | } | |
63 | } |
|
63 | } | |
64 | // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max(); |
|
64 | // qDebug() << "DeclarativeChart::componentComplete(), maxX: " << axisX()->max(); | |
65 |
|
65 | |||
66 | QDeclarativeItem::componentComplete(); |
|
66 | QDeclarativeItem::componentComplete(); | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
69 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | |
70 | { |
|
70 | { | |
71 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
71 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); | |
72 | Q_UNUSED(oldGeometry) |
|
72 | Q_UNUSED(oldGeometry) | |
73 |
|
73 | |||
74 | if (newGeometry.isValid()) { |
|
74 | if (newGeometry.isValid()) { | |
75 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
75 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
76 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
76 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
77 | } |
|
77 | } | |
78 | } |
|
78 | } | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
81 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
82 | { |
|
82 | { | |
83 | Q_UNUSED(option) |
|
83 | Q_UNUSED(option) | |
84 | Q_UNUSED(widget) |
|
84 | Q_UNUSED(widget) | |
85 |
|
85 | |||
86 | // TODO: optimized? |
|
86 | // TODO: optimized? | |
87 | painter->setRenderHint(QPainter::Antialiasing, true); |
|
87 | painter->setRenderHint(QPainter::Antialiasing, true); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
90 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) | |
91 | { |
|
91 | { | |
92 | m_chart->setTheme((QChart::ChartTheme) theme); |
|
92 | m_chart->setTheme((QChart::ChartTheme) theme); | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
95 | DeclarativeChart::Theme DeclarativeChart::theme() | |
96 | { |
|
96 | { | |
97 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
97 | return (DeclarativeChart::Theme) m_chart->theme(); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
100 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) | |
101 | { |
|
101 | { | |
102 | m_chart->setAnimationOptions((QChart::AnimationOption) animations); |
|
102 | m_chart->setAnimationOptions((QChart::AnimationOption) animations); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
105 | DeclarativeChart::Animation DeclarativeChart::animationOptions() | |
106 | { |
|
106 | { | |
107 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
107 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) | |
108 | return DeclarativeChart::AllAnimations; |
|
108 | return DeclarativeChart::AllAnimations; | |
109 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
109 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) | |
110 | return DeclarativeChart::GridAxisAnimations; |
|
110 | return DeclarativeChart::GridAxisAnimations; | |
111 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
111 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) | |
112 | return DeclarativeChart::SeriesAnimations; |
|
112 | return DeclarativeChart::SeriesAnimations; | |
113 | else |
|
113 | else | |
114 | return DeclarativeChart::NoAnimation; |
|
114 | return DeclarativeChart::NoAnimation; | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void DeclarativeChart::setLegend(DeclarativeChart::Legend legend) |
|
117 | void DeclarativeChart::setLegend(DeclarativeChart::Legend legend) | |
118 | { |
|
118 | { | |
119 | if (legend != m_legend) { |
|
119 | if (legend != m_legend) { | |
120 | m_legend = legend; |
|
120 | m_legend = legend; | |
121 | switch (m_legend) { |
|
121 | switch (m_legend) { | |
122 | case LegendDisabled: |
|
122 | case LegendDisabled: | |
123 | m_chart->legend()->setVisible(false); |
|
123 | m_chart->legend()->setVisible(false); | |
124 | break; |
|
124 | break; | |
125 | case LegendTop: |
|
125 | case LegendTop: | |
126 | m_chart->legend()->setVisible(true); |
|
126 | m_chart->legend()->setVisible(true); | |
127 | m_chart->legend()->setAlignment(QLegend::AlignmentTop); |
|
127 | m_chart->legend()->setAlignment(QLegend::AlignmentTop); | |
128 | break; |
|
128 | break; | |
129 | case LegendBottom: |
|
129 | case LegendBottom: | |
130 | m_chart->legend()->setVisible(true); |
|
130 | m_chart->legend()->setVisible(true); | |
131 | m_chart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
131 | m_chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
132 | break; |
|
132 | break; | |
133 | case LegendLeft: |
|
133 | case LegendLeft: | |
134 | m_chart->legend()->setVisible(true); |
|
134 | m_chart->legend()->setVisible(true); | |
135 | m_chart->legend()->setAlignment(QLegend::AlignmentLeft); |
|
135 | m_chart->legend()->setAlignment(QLegend::AlignmentLeft); | |
136 | break; |
|
136 | break; | |
137 | case LegendRight: |
|
137 | case LegendRight: | |
138 | m_chart->legend()->setVisible(true); |
|
138 | m_chart->legend()->setVisible(true); | |
139 | m_chart->legend()->setAlignment(QLegend::AlignmentRight); |
|
139 | m_chart->legend()->setAlignment(QLegend::AlignmentRight); | |
140 | break; |
|
140 | break; | |
141 | default: |
|
141 | default: | |
142 | m_chart->legend()->setVisible(false); |
|
142 | m_chart->legend()->setVisible(false); | |
143 | break; |
|
143 | break; | |
144 | } |
|
144 | } | |
145 | } |
|
145 | } | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | DeclarativeChart::Legend DeclarativeChart::legend() |
|
148 | DeclarativeChart::Legend DeclarativeChart::legend() | |
149 | { |
|
149 | { | |
150 | return m_legend; |
|
150 | return m_legend; | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | QAxis *DeclarativeChart::axisX() |
|
153 | QAxis *DeclarativeChart::axisX() | |
154 | { |
|
154 | { | |
155 | return m_chart->axisX(); |
|
155 | return m_chart->axisX(); | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | QAxis *DeclarativeChart::axisY() |
|
158 | QAxis *DeclarativeChart::axisY() | |
159 | { |
|
159 | { | |
160 | return m_chart->axisY(); |
|
160 | return m_chart->axisY(); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | QVariantList DeclarativeChart::axisXLabels() |
|
163 | QVariantList DeclarativeChart::axisXLabels() | |
164 | { |
|
164 | { | |
165 | QVariantList labels; |
|
165 | QVariantList labels; | |
166 | foreach (qreal value, m_chart->axisX()->categories()->values()) { |
|
166 | foreach (qreal value, m_chart->axisX()->categories()->values()) { | |
167 | labels.append(value); |
|
167 | labels.append(value); | |
168 | labels.append(m_chart->axisX()->categories()->label(value)); |
|
168 | labels.append(m_chart->axisX()->categories()->label(value)); | |
169 | } |
|
169 | } | |
170 | return labels; |
|
170 | return labels; | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void DeclarativeChart::setAxisXLabels(QVariantList list) |
|
173 | void DeclarativeChart::setAxisXLabels(QVariantList list) | |
174 | { |
|
174 | { | |
175 | QVariant value(QVariant::Invalid); |
|
175 | QVariant value(QVariant::Invalid); | |
176 | foreach (QVariant element, list) { |
|
176 | foreach (QVariant element, list) { | |
177 | if (value.isValid() && element.type() == QVariant::String) { |
|
177 | if (value.isValid() && element.type() == QVariant::String) { | |
178 | m_chart->axisX()->categories()->insert(value.toDouble(), element.toString()); |
|
178 | m_chart->axisX()->categories()->insert(value.toDouble(), element.toString()); | |
179 | value = QVariant(QVariant::Invalid); |
|
179 | value = QVariant(QVariant::Invalid); | |
180 | } else { |
|
180 | } else { | |
181 | if (element.canConvert(QVariant::Double)) |
|
181 | if (element.canConvert(QVariant::Double)) | |
182 | value = element; |
|
182 | value = element; | |
183 | } |
|
183 | } | |
184 | } |
|
184 | } | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | int DeclarativeChart::count() |
|
187 | int DeclarativeChart::count() | |
188 | { |
|
188 | { | |
189 | return m_chart->series().count(); |
|
189 | return m_chart->series().count(); | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | QAbstractSeries *DeclarativeChart::series(int index) |
|
192 | QAbstractSeries *DeclarativeChart::series(int index) | |
193 | { |
|
193 | { | |
194 | if (index < m_chart->series().count()) { |
|
194 | if (index < m_chart->series().count()) { | |
195 | return m_chart->series().at(index); |
|
195 | return m_chart->series().at(index); | |
196 | } |
|
196 | } | |
197 | return 0; |
|
197 | return 0; | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
200 | QAbstractSeries *DeclarativeChart::series(QString seriesName) | |
201 | { |
|
201 | { | |
202 | foreach(QAbstractSeries *series, m_chart->series()) { |
|
202 | foreach(QAbstractSeries *series, m_chart->series()) { | |
203 | if (series->name() == seriesName) |
|
203 | if (series->name() == seriesName) | |
204 | return series; |
|
204 | return series; | |
205 | } |
|
205 | } | |
206 | return 0; |
|
206 | return 0; | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
209 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) | |
210 | { |
|
210 | { | |
211 | QAbstractSeries *series = 0; |
|
211 | QAbstractSeries *series = 0; | |
212 | switch (type) { |
|
212 | switch (type) { | |
213 | case DeclarativeChart::SeriesTypeLine: |
|
213 | case DeclarativeChart::SeriesTypeLine: | |
214 | series = new DeclarativeLineSeries(); |
|
214 | series = new DeclarativeLineSeries(); | |
215 | break; |
|
215 | break; | |
216 | case DeclarativeChart::SeriesTypeArea: |
|
216 | case DeclarativeChart::SeriesTypeArea: | |
217 | series = new DeclarativeAreaSeries(); |
|
217 | series = new DeclarativeAreaSeries(); | |
218 | break; |
|
218 | break; | |
219 | case DeclarativeChart::SeriesTypeBar: |
|
219 | case DeclarativeChart::SeriesTypeBar: | |
220 | series = new DeclarativeBarSeries(); |
|
220 | series = new DeclarativeBarSeries(); | |
221 | break; |
|
221 | break; | |
222 | case DeclarativeChart::SeriesTypeStackedBar: |
|
222 | case DeclarativeChart::SeriesTypeStackedBar: | |
223 | // TODO |
|
223 | // TODO | |
224 | break; |
|
224 | break; | |
225 | case DeclarativeChart::SeriesTypePercentBar: |
|
225 | case DeclarativeChart::SeriesTypePercentBar: | |
226 | // TODO |
|
226 | // TODO | |
227 | break; |
|
227 | break; | |
228 | case DeclarativeChart::SeriesTypeGroupedBar: |
|
228 | case DeclarativeChart::SeriesTypeGroupedBar: | |
229 | series = new DeclarativeGroupedBarSeries(); |
|
229 | series = new DeclarativeGroupedBarSeries(); | |
230 | break; |
|
230 | break; | |
231 | case DeclarativeChart::SeriesTypePie: |
|
231 | case DeclarativeChart::SeriesTypePie: | |
232 | series = new DeclarativePieSeries(); |
|
232 | series = new DeclarativePieSeries(); | |
233 | break; |
|
233 | break; | |
234 | case DeclarativeChart::SeriesTypeScatter: |
|
234 | case DeclarativeChart::SeriesTypeScatter: | |
235 | series = new DeclarativeScatterSeries(); |
|
235 | series = new DeclarativeScatterSeries(); | |
236 | break; |
|
236 | break; | |
237 | case DeclarativeChart::SeriesTypeSpline: |
|
237 | case DeclarativeChart::SeriesTypeSpline: | |
238 | series = new DeclarativeSplineSeries(); |
|
238 | series = new DeclarativeSplineSeries(); | |
239 | break; |
|
239 | break; | |
240 | default: |
|
240 | default: | |
241 | qWarning() << "Illegal series type"; |
|
241 | qWarning() << "Illegal series type"; | |
242 | } |
|
242 | } | |
243 | series->setName(name); |
|
243 | series->setName(name); | |
244 | m_chart->addSeries(series); |
|
244 | m_chart->addSeries(series); | |
245 | return series; |
|
245 | return series; | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | #include "moc_declarativechart.cpp" |
|
248 | #include "moc_declarativechart.cpp" | |
249 |
|
249 | |||
250 | QTCOMMERCIALCHART_END_NAMESPACE |
|
250 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,55 +1,61 | |||||
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 DECLARATIVELINESERIES_H |
|
21 | #ifndef DECLARATIVELINESERIES_H | |
22 | #define DECLARATIVELINESERIES_H |
|
22 | #define DECLARATIVELINESERIES_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qlineseries.h" |
|
25 | #include "qlineseries.h" | |
26 | #include "declarativexyseries.h" |
|
26 | #include "declarativexyseries.h" | |
27 | #include <QDeclarativeParserStatus> |
|
27 | #include <QDeclarativeParserStatus> | |
28 | #include <QDeclarativeListProperty> |
|
28 | #include <QDeclarativeListProperty> | |
|
29 | #include <QDeclarativeParserStatus> | |||
29 |
|
30 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
32 | |||
32 | class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries |
|
33 | class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries, public QDeclarativeParserStatus | |
33 | { |
|
34 | { | |
34 | Q_OBJECT |
|
35 | Q_OBJECT | |
|
36 | Q_INTERFACES(QDeclarativeParserStatus) | |||
35 | Q_PROPERTY(QColor color READ penColor WRITE setPenColor) |
|
37 | Q_PROPERTY(QColor color READ penColor WRITE setPenColor) | |
36 | Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren) |
|
38 | Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren) | |
37 | Q_CLASSINFO("DefaultProperty", "declarativeChildren") |
|
39 | Q_CLASSINFO("DefaultProperty", "declarativeChildren") | |
38 |
|
40 | |||
39 | public: |
|
41 | public: | |
40 | explicit DeclarativeLineSeries(QObject *parent = 0); |
|
42 | explicit DeclarativeLineSeries(QObject *parent = 0); | |
41 | QDeclarativeListProperty<QObject> declarativeChildren(); |
|
43 | QDeclarativeListProperty<QObject> declarativeChildren(); | |
42 |
|
44 | |||
|
45 | public: // from QDeclarativeParserStatus | |||
|
46 | void classBegin() { DeclarativeXySeries::classBegin(); } | |||
|
47 | void componentComplete() { DeclarativeXySeries::componentComplete(); } | |||
|
48 | ||||
43 | public: // from QLineSeries |
|
49 | public: // from QLineSeries | |
44 | Q_INVOKABLE void append(qreal x, qreal y) { QLineSeries::append(x, y); } |
|
50 | Q_INVOKABLE void append(qreal x, qreal y) { QLineSeries::append(x, y); } | |
45 | Q_INVOKABLE void remove(qreal x, qreal y) { QLineSeries::remove(x, y); } |
|
51 | Q_INVOKABLE void remove(qreal x, qreal y) { QLineSeries::remove(x, y); } | |
46 | Q_INVOKABLE void clear() { QLineSeries::removeAll(); } |
|
52 | Q_INVOKABLE void clear() { QLineSeries::removeAll(); } | |
47 | Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); } |
|
53 | Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); } | |
48 |
|
54 | |||
49 | public Q_SLOTS: |
|
55 | public Q_SLOTS: | |
50 | static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
56 | static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
51 | }; |
|
57 | }; | |
52 |
|
58 | |||
53 | QTCOMMERCIALCHART_END_NAMESPACE |
|
59 | QTCOMMERCIALCHART_END_NAMESPACE | |
54 |
|
60 | |||
55 | #endif // DECLARATIVELINESERIES_H |
|
61 | #endif // DECLARATIVELINESERIES_H |
@@ -1,57 +1,63 | |||||
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 DECLARATIVESCATTERSERIES_H |
|
21 | #ifndef DECLARATIVESCATTERSERIES_H | |
22 | #define DECLARATIVESCATTERSERIES_H |
|
22 | #define DECLARATIVESCATTERSERIES_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qscatterseries.h" |
|
25 | #include "qscatterseries.h" | |
26 | #include "declarativexyseries.h" |
|
26 | #include "declarativexyseries.h" | |
27 | #include <QDeclarativeListProperty> |
|
27 | #include <QDeclarativeListProperty> | |
|
28 | #include <QDeclarativeParserStatus> | |||
28 |
|
29 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
31 | |||
31 | class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries |
|
32 | class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries, public QDeclarativeParserStatus | |
32 | { |
|
33 | { | |
33 | Q_OBJECT |
|
34 | Q_OBJECT | |
|
35 | Q_INTERFACES(QDeclarativeParserStatus) | |||
34 | Q_PROPERTY(QColor color READ brushColor WRITE setBrushColor) |
|
36 | Q_PROPERTY(QColor color READ brushColor WRITE setBrushColor) | |
35 | Q_PROPERTY(QColor borderColor READ penColor WRITE setPenColor) |
|
37 | Q_PROPERTY(QColor borderColor READ penColor WRITE setPenColor) | |
36 | Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren) |
|
38 | Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren) | |
37 | Q_CLASSINFO("DefaultProperty", "declarativeChildren") |
|
39 | Q_CLASSINFO("DefaultProperty", "declarativeChildren") | |
38 |
|
40 | |||
39 | public: |
|
41 | public: | |
40 | explicit DeclarativeScatterSeries(QObject *parent = 0); |
|
42 | explicit DeclarativeScatterSeries(QObject *parent = 0); | |
41 | QDeclarativeListProperty<QObject> declarativeChildren(); |
|
43 | QDeclarativeListProperty<QObject> declarativeChildren(); | |
42 | QColor brushColor(); |
|
44 | QColor brushColor(); | |
43 | void setBrushColor(QColor color); |
|
45 | void setBrushColor(QColor color); | |
44 |
|
46 | |||
|
47 | public: // from QDeclarativeParserStatus | |||
|
48 | void classBegin() { DeclarativeXySeries::classBegin(); } | |||
|
49 | void componentComplete() { DeclarativeXySeries::componentComplete(); } | |||
|
50 | ||||
45 | public: // from QScatterSeries |
|
51 | public: // from QScatterSeries | |
46 | Q_INVOKABLE void append(qreal x, qreal y) { QScatterSeries::append(x, y); } |
|
52 | Q_INVOKABLE void append(qreal x, qreal y) { QScatterSeries::append(x, y); } | |
47 | Q_INVOKABLE void remove(qreal x, qreal y) { QScatterSeries::remove(x, y); } |
|
53 | Q_INVOKABLE void remove(qreal x, qreal y) { QScatterSeries::remove(x, y); } | |
48 | Q_INVOKABLE void clear() { QScatterSeries::removeAll(); } |
|
54 | Q_INVOKABLE void clear() { QScatterSeries::removeAll(); } | |
49 | Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); } |
|
55 | Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); } | |
50 |
|
56 | |||
51 | public Q_SLOTS: |
|
57 | public Q_SLOTS: | |
52 | static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
58 | static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
53 | }; |
|
59 | }; | |
54 |
|
60 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
61 | QTCOMMERCIALCHART_END_NAMESPACE | |
56 |
|
62 | |||
57 | #endif // DECLARATIVESCATTERSERIES_H |
|
63 | #endif // DECLARATIVESCATTERSERIES_H |
@@ -1,55 +1,61 | |||||
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 DECLARATIVESPLINESERIES_H |
|
21 | #ifndef DECLARATIVESPLINESERIES_H | |
22 | #define DECLARATIVESPLINESERIES_H |
|
22 | #define DECLARATIVESPLINESERIES_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qsplineseries.h" |
|
25 | #include "qsplineseries.h" | |
26 | #include "declarativexyseries.h" |
|
26 | #include "declarativexyseries.h" | |
27 | #include <QDeclarativeParserStatus> |
|
27 | #include <QDeclarativeParserStatus> | |
28 | #include <QDeclarativeListProperty> |
|
28 | #include <QDeclarativeListProperty> | |
|
29 | #include <QDeclarativeParserStatus> | |||
29 |
|
30 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
32 | |||
32 | class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries |
|
33 | class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries, public QDeclarativeParserStatus | |
33 | { |
|
34 | { | |
34 | Q_OBJECT |
|
35 | Q_OBJECT | |
|
36 | Q_INTERFACES(QDeclarativeParserStatus) | |||
35 | Q_PROPERTY(QColor color READ penColor WRITE setPenColor) |
|
37 | Q_PROPERTY(QColor color READ penColor WRITE setPenColor) | |
36 | Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren) |
|
38 | Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren) | |
37 | Q_CLASSINFO("DefaultProperty", "declarativeChildren") |
|
39 | Q_CLASSINFO("DefaultProperty", "declarativeChildren") | |
38 |
|
40 | |||
39 | public: |
|
41 | public: | |
40 | explicit DeclarativeSplineSeries(QObject *parent = 0); |
|
42 | explicit DeclarativeSplineSeries(QObject *parent = 0); | |
41 | QDeclarativeListProperty<QObject> declarativeChildren(); |
|
43 | QDeclarativeListProperty<QObject> declarativeChildren(); | |
42 |
|
44 | |||
|
45 | public: // from QDeclarativeParserStatus | |||
|
46 | void classBegin() { DeclarativeXySeries::classBegin(); } | |||
|
47 | void componentComplete() { DeclarativeXySeries::componentComplete(); } | |||
|
48 | ||||
43 | public: // from QSplineSeries |
|
49 | public: // from QSplineSeries | |
44 | Q_INVOKABLE void append(qreal x, qreal y) { QSplineSeries::append(x, y); } |
|
50 | Q_INVOKABLE void append(qreal x, qreal y) { QSplineSeries::append(x, y); } | |
45 | Q_INVOKABLE void remove(qreal x, qreal y) { QSplineSeries::remove(x, y); } |
|
51 | Q_INVOKABLE void remove(qreal x, qreal y) { QSplineSeries::remove(x, y); } | |
46 | Q_INVOKABLE void clear() { QSplineSeries::removeAll(); } |
|
52 | Q_INVOKABLE void clear() { QSplineSeries::removeAll(); } | |
47 | Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); } |
|
53 | Q_INVOKABLE DeclarativeXyPoint *at(int index) { return DeclarativeXySeries::at(index); } | |
48 |
|
54 | |||
49 | public Q_SLOTS: |
|
55 | public Q_SLOTS: | |
50 | static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
56 | static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
51 | }; |
|
57 | }; | |
52 |
|
58 | |||
53 | QTCOMMERCIALCHART_END_NAMESPACE |
|
59 | QTCOMMERCIALCHART_END_NAMESPACE | |
54 |
|
60 | |||
55 | #endif // DECLARATIVESPLINESERIES_H |
|
61 | #endif // DECLARATIVESPLINESERIES_H |
@@ -1,67 +1,91 | |||||
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 "DeclarativeXySeries.h" |
|
21 | //#include "DeclarativeXySeries.h" | |
22 | #include "declarativexyseries.h" |
|
22 | #include "declarativexyseries.h" | |
23 | #include "declarativechart.h" |
|
23 | #include "declarativechart.h" | |
24 | #include <QXYSeries> |
|
24 | #include <QXYSeries> | |
25 | #include <QXYModelMapper> |
|
25 | #include <QVXYModelMapper> | |
|
26 | #include <QHXYModelMapper> | |||
26 | #include <QDeclarativeListProperty> |
|
27 | #include <QDeclarativeListProperty> | |
27 |
|
28 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
30 | |||
30 | DeclarativeXySeries::DeclarativeXySeries() |
|
31 | DeclarativeXySeries::DeclarativeXySeries() | |
31 | { |
|
32 | { | |
32 | } |
|
33 | } | |
33 |
|
34 | |||
34 | DeclarativeXySeries::~DeclarativeXySeries() |
|
35 | DeclarativeXySeries::~DeclarativeXySeries() | |
35 | { |
|
36 | { | |
36 | } |
|
37 | } | |
37 |
|
38 | |||
|
39 | void DeclarativeXySeries::classBegin() | |||
|
40 | { | |||
|
41 | } | |||
|
42 | ||||
|
43 | void DeclarativeXySeries::componentComplete() | |||
|
44 | { | |||
|
45 | // All the inherited objects must be of type QXYSeries, so it is safe to cast | |||
|
46 | QXYSeries *series = reinterpret_cast<QXYSeries *>(this); | |||
|
47 | foreach(QObject *child, series->children()) { | |||
|
48 | if (qobject_cast<DeclarativeXyPoint *>(child)) { | |||
|
49 | // TODO: | |||
|
50 | // series->append(qobject_cast<DeclarativeXyPoint *>(child)); | |||
|
51 | } else if(qobject_cast<QVXYModelMapper *>(child)) { | |||
|
52 | QVXYModelMapper *mapper = qobject_cast<QVXYModelMapper *>(child); | |||
|
53 | mapper->setSeries(series); | |||
|
54 | } else if(qobject_cast<QHXYModelMapper *>(child)) { | |||
|
55 | QHXYModelMapper *mapper = qobject_cast<QHXYModelMapper *>(child); | |||
|
56 | mapper->setSeries(series); | |||
|
57 | } | |||
|
58 | } | |||
|
59 | } | |||
|
60 | ||||
|
61 | ||||
38 | QColor DeclarativeXySeries::penColor() |
|
62 | QColor DeclarativeXySeries::penColor() | |
39 | { |
|
63 | { | |
40 | // All the inherited objects must be of type QXYSeries, so it is safe to cast |
|
64 | // All the inherited objects must be of type QXYSeries, so it is safe to cast | |
41 | QXYSeries *series = reinterpret_cast<QXYSeries *>(this); |
|
65 | QXYSeries *series = reinterpret_cast<QXYSeries *>(this); | |
42 | return series->pen().color(); |
|
66 | return series->pen().color(); | |
43 | } |
|
67 | } | |
44 |
|
68 | |||
45 | void DeclarativeXySeries::setPenColor(QColor color) |
|
69 | void DeclarativeXySeries::setPenColor(QColor color) | |
46 | { |
|
70 | { | |
47 | QXYSeries *series = reinterpret_cast<QXYSeries *>(this); |
|
71 | QXYSeries *series = reinterpret_cast<QXYSeries *>(this); | |
48 | QPen pen = series->pen(); |
|
72 | QPen pen = series->pen(); | |
49 | pen.setColor(color); |
|
73 | pen.setColor(color); | |
50 | series->setPen(pen); |
|
74 | series->setPen(pen); | |
51 | } |
|
75 | } | |
52 |
|
76 | |||
53 | DeclarativeXyPoint *DeclarativeXySeries::at(int index) |
|
77 | DeclarativeXyPoint *DeclarativeXySeries::at(int index) | |
54 | { |
|
78 | { | |
55 | QXYSeries *series = reinterpret_cast<QXYSeries *>(this); |
|
79 | QXYSeries *series = reinterpret_cast<QXYSeries *>(this); | |
56 | if (index < series->count()) { |
|
80 | if (index < series->count()) { | |
57 | QPointF point = series->points().at(index); |
|
81 | QPointF point = series->points().at(index); | |
58 | DeclarativeXyPoint *xyPoint = new DeclarativeXyPoint(series); |
|
82 | DeclarativeXyPoint *xyPoint = new DeclarativeXyPoint(series); | |
59 | xyPoint->setX(point.x()); |
|
83 | xyPoint->setX(point.x()); | |
60 | xyPoint->setY(point.y()); |
|
84 | xyPoint->setY(point.y()); | |
61 | return xyPoint; |
|
85 | return xyPoint; | |
62 | } |
|
86 | } | |
63 | return 0; |
|
87 | return 0; | |
64 | } |
|
88 | } | |
65 |
|
89 | |||
66 |
|
90 | |||
67 | QTCOMMERCIALCHART_END_NAMESPACE |
|
91 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,47 +1,49 | |||||
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 DECLARATIVE_XY_SERIES_H |
|
21 | #ifndef DECLARATIVE_XY_SERIES_H | |
22 | #define DECLARATIVE_XY_SERIES_H |
|
22 | #define DECLARATIVE_XY_SERIES_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "declarativexypoint.h" |
|
25 | #include "declarativexypoint.h" | |
26 | #include <QColor> |
|
26 | #include <QColor> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | class QChart; |
|
30 | class QChart; | |
31 | class QAbstractSeries; |
|
31 | class QAbstractSeries; | |
32 |
|
32 | |||
33 | class DeclarativeXySeries |
|
33 | class DeclarativeXySeries | |
34 | { |
|
34 | { | |
35 | public: |
|
35 | public: | |
36 | explicit DeclarativeXySeries(); |
|
36 | explicit DeclarativeXySeries(); | |
37 | ~DeclarativeXySeries(); |
|
37 | ~DeclarativeXySeries(); | |
38 |
|
38 | |||
39 | public: |
|
39 | public: | |
|
40 | void classBegin(); | |||
|
41 | void componentComplete(); | |||
40 | QColor penColor(); |
|
42 | QColor penColor(); | |
41 | void setPenColor(QColor color); |
|
43 | void setPenColor(QColor color); | |
42 | DeclarativeXyPoint *at(int index); |
|
44 | DeclarativeXyPoint *at(int index); | |
43 | }; |
|
45 | }; | |
44 |
|
46 | |||
45 | QTCOMMERCIALCHART_END_NAMESPACE |
|
47 | QTCOMMERCIALCHART_END_NAMESPACE | |
46 |
|
48 | |||
47 | #endif // DECLARATIVE_XY_SERIES_H |
|
49 | #endif // DECLARATIVE_XY_SERIES_H |
@@ -1,88 +1,92 | |||||
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 <QtDeclarative/qdeclarativeextensionplugin.h> |
|
21 | #include <QtDeclarative/qdeclarativeextensionplugin.h> | |
22 | #include <QtDeclarative/qdeclarative.h> |
|
22 | #include <QtDeclarative/qdeclarative.h> | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 | #include "qaxiscategories.h" |
|
24 | #include "qaxiscategories.h" | |
25 | #include "declarativechart.h" |
|
25 | #include "declarativechart.h" | |
26 | #include "declarativexypoint.h" |
|
26 | #include "declarativexypoint.h" | |
27 | #include "declarativelineseries.h" |
|
27 | #include "declarativelineseries.h" | |
28 | #include "declarativesplineseries.h" |
|
28 | #include "declarativesplineseries.h" | |
29 | #include "declarativeareaseries.h" |
|
29 | #include "declarativeareaseries.h" | |
30 | #include "declarativescatterseries.h" |
|
30 | #include "declarativescatterseries.h" | |
31 | #include "declarativebarseries.h" |
|
31 | #include "declarativebarseries.h" | |
32 | #include "declarativepieseries.h" |
|
32 | #include "declarativepieseries.h" | |
|
33 | #include <QVXYModelMapper> | |||
|
34 | #include <QHXYModelMapper> | |||
33 | #include <QHPieModelMapper> |
|
35 | #include <QHPieModelMapper> | |
34 | #include <QVPieModelMapper> |
|
36 | #include <QVPieModelMapper> | |
35 | #include <QXYModelMapper> |
|
|||
36 |
|
37 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
39 | |||
39 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin |
|
40 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin | |
40 | { |
|
41 | { | |
41 | Q_OBJECT |
|
42 | Q_OBJECT | |
42 | public: |
|
43 | public: | |
43 | virtual void registerTypes(const char *uri) |
|
44 | virtual void registerTypes(const char *uri) | |
44 | { |
|
45 | { | |
45 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
46 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); | |
46 |
|
47 | |||
47 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); |
|
48 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); | |
48 | qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint"); |
|
49 | qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint"); | |
49 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
50 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); | |
50 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); |
|
51 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); | |
51 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); |
|
52 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); | |
52 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); |
|
53 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); | |
53 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); |
|
54 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); | |
54 | qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries"); |
|
55 | qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries"); | |
55 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
56 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); | |
56 | qmlRegisterType<DeclarativePieSlice>(uri, 1, 0, "PieSlice"); |
|
57 | qmlRegisterType<DeclarativePieSlice>(uri, 1, 0, "PieSlice"); | |
57 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); |
|
58 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); | |
|
59 | qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper"); | |||
|
60 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); | |||
|
61 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); | |||
|
62 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); | |||
58 |
|
63 | |||
59 |
|
64 | |||
60 | qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries", |
|
65 | qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries", | |
61 | QLatin1String("Trying to create uncreatable: QScatterSeries.")); |
|
66 | QLatin1String("Trying to create uncreatable: QScatterSeries.")); | |
62 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", |
|
67 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", | |
63 | QLatin1String("Trying to create uncreatable: QPieSeries.")); |
|
68 | QLatin1String("Trying to create uncreatable: QPieSeries.")); | |
64 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", |
|
69 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", | |
65 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); |
|
70 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); | |
|
71 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", | |||
|
72 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); | |||
66 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
73 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", | |
67 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
74 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); | |
68 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); |
|
|||
69 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); |
|
|||
70 |
|
||||
71 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", |
|
75 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", | |
72 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); |
|
76 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); | |
73 | qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis", |
|
77 | qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis", | |
74 | QLatin1String("Trying to create uncreatable: Axis.")); |
|
78 | QLatin1String("Trying to create uncreatable: Axis.")); | |
75 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
79 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", | |
76 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
80 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); | |
77 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
81 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", | |
78 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
82 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); | |
79 | } |
|
83 | } | |
80 | }; |
|
84 | }; | |
81 |
|
85 | |||
82 | #include "plugin.moc" |
|
86 | #include "plugin.moc" | |
83 |
|
87 | |||
84 | QTCOMMERCIALCHART_END_NAMESPACE |
|
88 | QTCOMMERCIALCHART_END_NAMESPACE | |
85 |
|
89 | |||
86 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
90 | QTCOMMERCIALCHART_USE_NAMESPACE | |
87 |
|
91 | |||
88 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
|
92 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
@@ -1,414 +1,417 | |||||
1 | #include "qxymodelmapper.h" |
|
1 | #include "qxymodelmapper.h" | |
2 | #include "qxymodelmapper_p.h" |
|
2 | #include "qxymodelmapper_p.h" | |
3 | #include "qxyseries.h" |
|
3 | #include "qxyseries.h" | |
4 | #include <QAbstractItemModel> |
|
4 | #include <QAbstractItemModel> | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | QXYModelMapper::QXYModelMapper(QObject *parent): |
|
8 | QXYModelMapper::QXYModelMapper(QObject *parent): | |
9 | QObject(parent), |
|
9 | QObject(parent), | |
10 | d_ptr(new QXYModelMapperPrivate(this)) |
|
10 | d_ptr(new QXYModelMapperPrivate(this)) | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
14 | QAbstractItemModel* QXYModelMapper::model() const |
|
14 | QAbstractItemModel* QXYModelMapper::model() const | |
15 | { |
|
15 | { | |
16 | Q_D(const QXYModelMapper); |
|
16 | Q_D(const QXYModelMapper); | |
17 | return d->m_model; |
|
17 | return d->m_model; | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 | void QXYModelMapper::setModel(QAbstractItemModel *model) |
|
20 | void QXYModelMapper::setModel(QAbstractItemModel *model) | |
21 | { |
|
21 | { | |
22 | if (model == 0) |
|
22 | if (model == 0) | |
23 | return; |
|
23 | return; | |
24 |
|
24 | |||
25 | Q_D(QXYModelMapper); |
|
25 | Q_D(QXYModelMapper); | |
26 | if (d->m_model) { |
|
26 | if (d->m_model) { | |
27 | disconnect(d->m_model, 0, d, 0); |
|
27 | disconnect(d->m_model, 0, d, 0); | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | d->m_model = model; |
|
30 | d->m_model = model; | |
31 | d->initializeXYFromModel(); |
|
31 | d->initializeXYFromModel(); | |
32 | // connect signals from the model |
|
32 | // connect signals from the model | |
33 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
33 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
34 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
34 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
35 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
35 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
36 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
36 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
37 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
37 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | QXYSeries* QXYModelMapper::series() const |
|
40 | QXYSeries* QXYModelMapper::series() const | |
41 | { |
|
41 | { | |
42 | Q_D(const QXYModelMapper); |
|
42 | Q_D(const QXYModelMapper); | |
43 | return d->m_series; |
|
43 | return d->m_series; | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | void QXYModelMapper::setSeries(QXYSeries *series) |
|
46 | void QXYModelMapper::setSeries(QXYSeries *series) | |
47 | { |
|
47 | { | |
48 | Q_D(QXYModelMapper); |
|
48 | Q_D(QXYModelMapper); | |
49 | if (d->m_series) { |
|
49 | if (d->m_series) { | |
50 | disconnect(d->m_series, 0, d, 0); |
|
50 | disconnect(d->m_series, 0, d, 0); | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | if (series == 0) |
|
53 | if (series == 0) | |
54 | return; |
|
54 | return; | |
55 |
|
55 | |||
56 | d->m_series = series; |
|
56 | d->m_series = series; | |
57 | d->initializeXYFromModel(); |
|
57 | d->initializeXYFromModel(); | |
58 | // connect the signals from the series |
|
58 | // connect the signals from the series | |
59 | connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int))); |
|
59 | connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int))); | |
60 | connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int))); |
|
60 | connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int))); | |
61 | connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int))); |
|
61 | connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int))); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | int QXYModelMapper::first() const |
|
64 | int QXYModelMapper::first() const | |
65 | { |
|
65 | { | |
66 | Q_D(const QXYModelMapper); |
|
66 | Q_D(const QXYModelMapper); | |
67 | return d->m_first; |
|
67 | return d->m_first; | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void QXYModelMapper::setFirst(int first) |
|
70 | void QXYModelMapper::setFirst(int first) | |
71 | { |
|
71 | { | |
72 | Q_D(QXYModelMapper); |
|
72 | Q_D(QXYModelMapper); | |
73 | d->m_first = qMax(first, 0); |
|
73 | d->m_first = qMax(first, 0); | |
74 | d->initializeXYFromModel(); |
|
74 | d->initializeXYFromModel(); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | int QXYModelMapper::count() const |
|
77 | int QXYModelMapper::count() const | |
78 | { |
|
78 | { | |
79 | Q_D(const QXYModelMapper); |
|
79 | Q_D(const QXYModelMapper); | |
80 | return d->m_count; |
|
80 | return d->m_count; | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | void QXYModelMapper::setCount(int count) |
|
83 | void QXYModelMapper::setCount(int count) | |
84 | { |
|
84 | { | |
85 | Q_D(QXYModelMapper); |
|
85 | Q_D(QXYModelMapper); | |
86 | d->m_count = qMax(count, -1); |
|
86 | d->m_count = qMax(count, -1); | |
87 | d->initializeXYFromModel(); |
|
87 | d->initializeXYFromModel(); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | Qt::Orientation QXYModelMapper::orientation() const |
|
90 | Qt::Orientation QXYModelMapper::orientation() const | |
91 | { |
|
91 | { | |
92 | Q_D(const QXYModelMapper); |
|
92 | Q_D(const QXYModelMapper); | |
93 | return d->m_orientation; |
|
93 | return d->m_orientation; | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void QXYModelMapper::setOrientation(Qt::Orientation orientation) |
|
96 | void QXYModelMapper::setOrientation(Qt::Orientation orientation) | |
97 | { |
|
97 | { | |
98 | Q_D(QXYModelMapper); |
|
98 | Q_D(QXYModelMapper); | |
99 | d->m_orientation = orientation; |
|
99 | d->m_orientation = orientation; | |
100 | d->initializeXYFromModel(); |
|
100 | d->initializeXYFromModel(); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | int QXYModelMapper::xSection() const |
|
103 | int QXYModelMapper::xSection() const | |
104 | { |
|
104 | { | |
105 | Q_D(const QXYModelMapper); |
|
105 | Q_D(const QXYModelMapper); | |
106 | return d->m_xSection; |
|
106 | return d->m_xSection; | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void QXYModelMapper::setXSection(int xSection) |
|
109 | void QXYModelMapper::setXSection(int xSection) | |
110 | { |
|
110 | { | |
111 | Q_D(QXYModelMapper); |
|
111 | Q_D(QXYModelMapper); | |
112 | d->m_xSection = xSection; |
|
112 | d->m_xSection = xSection; | |
113 | d->initializeXYFromModel(); |
|
113 | d->initializeXYFromModel(); | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | int QXYModelMapper::ySection() const |
|
116 | int QXYModelMapper::ySection() const | |
117 | { |
|
117 | { | |
118 | Q_D(const QXYModelMapper); |
|
118 | Q_D(const QXYModelMapper); | |
119 | return d->m_ySection; |
|
119 | return d->m_ySection; | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | void QXYModelMapper::setYSection(int ySection) |
|
122 | void QXYModelMapper::setYSection(int ySection) | |
123 | { |
|
123 | { | |
124 | Q_D(QXYModelMapper); |
|
124 | Q_D(QXYModelMapper); | |
125 | d->m_ySection = ySection; |
|
125 | d->m_ySection = ySection; | |
126 | d->initializeXYFromModel(); |
|
126 | d->initializeXYFromModel(); | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 | void QXYModelMapper::reset() |
|
129 | void QXYModelMapper::reset() | |
130 | { |
|
130 | { | |
131 | Q_D(QXYModelMapper); |
|
131 | Q_D(QXYModelMapper); | |
132 | d->m_first = 0; |
|
132 | d->m_first = 0; | |
133 | d->m_count = -1; |
|
133 | d->m_count = -1; | |
134 | d->m_orientation = Qt::Vertical; |
|
134 | d->m_orientation = Qt::Vertical; | |
135 | d->m_xSection = -1; |
|
135 | d->m_xSection = -1; | |
136 | d->m_ySection = -1; |
|
136 | d->m_ySection = -1; | |
137 | d->initializeXYFromModel(); |
|
137 | d->initializeXYFromModel(); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
140 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
141 |
|
141 | |||
142 | QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) : |
|
142 | QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) : | |
143 | m_series(0), |
|
143 | m_series(0), | |
144 | m_model(0), |
|
144 | m_model(0), | |
145 | m_first(0), |
|
145 | m_first(0), | |
146 | m_count(-1), |
|
146 | m_count(-1), | |
147 | m_orientation(Qt::Vertical), |
|
147 | m_orientation(Qt::Vertical), | |
148 | m_xSection(-1), |
|
148 | m_xSection(-1), | |
149 | m_ySection(-1), |
|
149 | m_ySection(-1), | |
150 | m_seriesSignalsBlock(false), |
|
150 | m_seriesSignalsBlock(false), | |
151 | m_modelSignalsBlock(false), |
|
151 | m_modelSignalsBlock(false), | |
152 | q_ptr(q) |
|
152 | q_ptr(q) | |
153 | { |
|
153 | { | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void QXYModelMapperPrivate::blockModelSignals(bool block) |
|
156 | void QXYModelMapperPrivate::blockModelSignals(bool block) | |
157 | { |
|
157 | { | |
158 | m_modelSignalsBlock = block; |
|
158 | m_modelSignalsBlock = block; | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void QXYModelMapperPrivate::blockSeriesSignals(bool block) |
|
161 | void QXYModelMapperPrivate::blockSeriesSignals(bool block) | |
162 | { |
|
162 | { | |
163 | m_seriesSignalsBlock = block; |
|
163 | m_seriesSignalsBlock = block; | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | QModelIndex QXYModelMapperPrivate::xModelIndex(int xPos) |
|
166 | QModelIndex QXYModelMapperPrivate::xModelIndex(int xPos) | |
167 | { |
|
167 | { | |
168 | if (m_count != -1 && xPos >= m_count) |
|
168 | if (m_count != -1 && xPos >= m_count) | |
169 | return QModelIndex(); // invalid |
|
169 | return QModelIndex(); // invalid | |
170 |
|
170 | |||
171 | if (m_orientation == Qt::Vertical) |
|
171 | if (m_orientation == Qt::Vertical) | |
172 | return m_model->index(xPos + m_first, m_xSection); |
|
172 | return m_model->index(xPos + m_first, m_xSection); | |
173 | else |
|
173 | else | |
174 | return m_model->index(m_xSection, xPos + m_first); |
|
174 | return m_model->index(m_xSection, xPos + m_first); | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | QModelIndex QXYModelMapperPrivate::yModelIndex(int yPos) |
|
177 | QModelIndex QXYModelMapperPrivate::yModelIndex(int yPos) | |
178 | { |
|
178 | { | |
179 | if (m_count != -1 && yPos >= m_count) |
|
179 | if (m_count != -1 && yPos >= m_count) | |
180 | return QModelIndex(); // invalid |
|
180 | return QModelIndex(); // invalid | |
181 |
|
181 | |||
182 | if (m_orientation == Qt::Vertical) |
|
182 | if (m_orientation == Qt::Vertical) | |
183 | return m_model->index(yPos + m_first, m_ySection); |
|
183 | return m_model->index(yPos + m_first, m_ySection); | |
184 | else |
|
184 | else | |
185 | return m_model->index(m_ySection, yPos + m_first); |
|
185 | return m_model->index(m_ySection, yPos + m_first); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | void QXYModelMapperPrivate::handlePointAdded(int pointPos) |
|
188 | void QXYModelMapperPrivate::handlePointAdded(int pointPos) | |
189 | { |
|
189 | { | |
190 | if (m_seriesSignalsBlock) |
|
190 | if (m_seriesSignalsBlock) | |
191 | return; |
|
191 | return; | |
192 |
|
192 | |||
193 | if (m_count != -1) |
|
193 | if (m_count != -1) | |
194 | m_count += 1; |
|
194 | m_count += 1; | |
195 |
|
195 | |||
196 | blockModelSignals(); |
|
196 | blockModelSignals(); | |
197 | if (m_orientation == Qt::Vertical) |
|
197 | if (m_orientation == Qt::Vertical) | |
198 | m_model->insertRows(pointPos + m_first, 1); |
|
198 | m_model->insertRows(pointPos + m_first, 1); | |
199 | else |
|
199 | else | |
200 | m_model->insertColumns(pointPos + m_first, 1); |
|
200 | m_model->insertColumns(pointPos + m_first, 1); | |
201 |
|
201 | |||
202 | m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x()); |
|
202 | m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x()); | |
203 | m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y()); |
|
203 | m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y()); | |
204 | blockModelSignals(false); |
|
204 | blockModelSignals(false); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | void QXYModelMapperPrivate::handlePointRemoved(int pointPos) |
|
207 | void QXYModelMapperPrivate::handlePointRemoved(int pointPos) | |
208 | { |
|
208 | { | |
209 | if (m_seriesSignalsBlock) |
|
209 | if (m_seriesSignalsBlock) | |
210 | return; |
|
210 | return; | |
211 |
|
211 | |||
212 | if (m_count != -1) |
|
212 | if (m_count != -1) | |
213 | m_count -= 1; |
|
213 | m_count -= 1; | |
214 |
|
214 | |||
215 | blockModelSignals(); |
|
215 | blockModelSignals(); | |
216 | if (m_orientation == Qt::Vertical) |
|
216 | if (m_orientation == Qt::Vertical) | |
217 | m_model->removeRow(pointPos + m_first); |
|
217 | m_model->removeRow(pointPos + m_first); | |
218 | else |
|
218 | else | |
219 | m_model->removeColumn(pointPos + m_first); |
|
219 | m_model->removeColumn(pointPos + m_first); | |
220 | blockModelSignals(false); |
|
220 | blockModelSignals(false); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | void QXYModelMapperPrivate::handlePointReplaced(int pointPos) |
|
223 | void QXYModelMapperPrivate::handlePointReplaced(int pointPos) | |
224 | { |
|
224 | { | |
225 | if (m_seriesSignalsBlock) |
|
225 | if (m_seriesSignalsBlock) | |
226 | return; |
|
226 | return; | |
227 |
|
227 | |||
228 | blockModelSignals(); |
|
228 | blockModelSignals(); | |
229 | m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x()); |
|
229 | m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x()); | |
230 | m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y()); |
|
230 | m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y()); | |
231 | blockModelSignals(false); |
|
231 | blockModelSignals(false); | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
234 | void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
235 | { |
|
235 | { | |
|
236 | if (m_model == 0 || m_series == 0) | |||
|
237 | return; | |||
|
238 | ||||
236 | if (m_modelSignalsBlock) |
|
239 | if (m_modelSignalsBlock) | |
237 | return; |
|
240 | return; | |
238 |
|
241 | |||
239 | blockSeriesSignals(); |
|
242 | blockSeriesSignals(); | |
240 | QModelIndex index; |
|
243 | QModelIndex index; | |
241 | QPointF oldPoint; |
|
244 | QPointF oldPoint; | |
242 | QPointF newPoint; |
|
245 | QPointF newPoint; | |
243 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
246 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
244 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
247 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
245 | index = topLeft.sibling(row, column); |
|
248 | index = topLeft.sibling(row, column); | |
246 | if (m_orientation == Qt::Vertical && (index.column() == m_xSection|| index.column() == m_ySection)) { |
|
249 | if (m_orientation == Qt::Vertical && (index.column() == m_xSection|| index.column() == m_ySection)) { | |
247 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
250 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { | |
248 | oldPoint = m_series->points().at(index.row() - m_first); |
|
251 | oldPoint = m_series->points().at(index.row() - m_first); | |
249 | newPoint.setX(m_model->data(m_model->index(index.row(), m_xSection)).toReal()); |
|
252 | newPoint.setX(m_model->data(m_model->index(index.row(), m_xSection)).toReal()); | |
250 | newPoint.setY(m_model->data(m_model->index(index.row(), m_ySection)).toReal()); |
|
253 | newPoint.setY(m_model->data(m_model->index(index.row(), m_ySection)).toReal()); | |
251 | } |
|
254 | } | |
252 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) { |
|
255 | } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) { | |
253 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) { |
|
256 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) { | |
254 | oldPoint = m_series->points().at(index.column() - m_first); |
|
257 | oldPoint = m_series->points().at(index.column() - m_first); | |
255 | newPoint.setX(m_model->data(m_model->index(m_xSection, index.column())).toReal()); |
|
258 | newPoint.setX(m_model->data(m_model->index(m_xSection, index.column())).toReal()); | |
256 | newPoint.setY(m_model->data(m_model->index(m_ySection, index.column())).toReal()); |
|
259 | newPoint.setY(m_model->data(m_model->index(m_ySection, index.column())).toReal()); | |
257 | } |
|
260 | } | |
258 | } else { |
|
261 | } else { | |
259 | continue; |
|
262 | continue; | |
260 | } |
|
263 | } | |
261 | m_series->replace(oldPoint, newPoint); |
|
264 | m_series->replace(oldPoint, newPoint); | |
262 | } |
|
265 | } | |
263 | blockSeriesSignals(false); |
|
266 | blockSeriesSignals(false); | |
264 | } |
|
267 | } | |
265 | } |
|
268 | } | |
266 |
|
269 | |||
267 | void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
270 | void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
268 | { |
|
271 | { | |
269 | Q_UNUSED(parent); |
|
272 | Q_UNUSED(parent); | |
270 | if (m_modelSignalsBlock) |
|
273 | if (m_modelSignalsBlock) | |
271 | return; |
|
274 | return; | |
272 |
|
275 | |||
273 | blockSeriesSignals(); |
|
276 | blockSeriesSignals(); | |
274 | if (m_orientation == Qt::Vertical) |
|
277 | if (m_orientation == Qt::Vertical) | |
275 | insertData(start, end); |
|
278 | insertData(start, end); | |
276 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy |
|
279 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy | |
277 | initializeXYFromModel(); |
|
280 | initializeXYFromModel(); | |
278 | blockSeriesSignals(false); |
|
281 | blockSeriesSignals(false); | |
279 | } |
|
282 | } | |
280 |
|
283 | |||
281 | void QXYModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
284 | void QXYModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
282 | { |
|
285 | { | |
283 | Q_UNUSED(parent); |
|
286 | Q_UNUSED(parent); | |
284 | if (m_modelSignalsBlock) |
|
287 | if (m_modelSignalsBlock) | |
285 | return; |
|
288 | return; | |
286 |
|
289 | |||
287 | blockSeriesSignals(); |
|
290 | blockSeriesSignals(); | |
288 | if (m_orientation == Qt::Vertical) |
|
291 | if (m_orientation == Qt::Vertical) | |
289 | removeData(start, end); |
|
292 | removeData(start, end); | |
290 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy |
|
293 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy | |
291 | initializeXYFromModel(); |
|
294 | initializeXYFromModel(); | |
292 | blockSeriesSignals(false); |
|
295 | blockSeriesSignals(false); | |
293 | } |
|
296 | } | |
294 |
|
297 | |||
295 | void QXYModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
298 | void QXYModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
296 | { |
|
299 | { | |
297 | Q_UNUSED(parent); |
|
300 | Q_UNUSED(parent); | |
298 | if (m_modelSignalsBlock) |
|
301 | if (m_modelSignalsBlock) | |
299 | return; |
|
302 | return; | |
300 |
|
303 | |||
301 | blockSeriesSignals(); |
|
304 | blockSeriesSignals(); | |
302 | if (m_orientation == Qt::Horizontal) |
|
305 | if (m_orientation == Qt::Horizontal) | |
303 | insertData(start, end); |
|
306 | insertData(start, end); | |
304 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy |
|
307 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy | |
305 | initializeXYFromModel(); |
|
308 | initializeXYFromModel(); | |
306 | blockSeriesSignals(false); |
|
309 | blockSeriesSignals(false); | |
307 | } |
|
310 | } | |
308 |
|
311 | |||
309 | void QXYModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
312 | void QXYModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
310 | { |
|
313 | { | |
311 | Q_UNUSED(parent); |
|
314 | Q_UNUSED(parent); | |
312 | if (m_modelSignalsBlock) |
|
315 | if (m_modelSignalsBlock) | |
313 | return; |
|
316 | return; | |
314 |
|
317 | |||
315 | blockSeriesSignals(); |
|
318 | blockSeriesSignals(); | |
316 | if (m_orientation == Qt::Horizontal) |
|
319 | if (m_orientation == Qt::Horizontal) | |
317 | removeData(start, end); |
|
320 | removeData(start, end); | |
318 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy |
|
321 | else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy | |
319 | initializeXYFromModel(); |
|
322 | initializeXYFromModel(); | |
320 | blockSeriesSignals(false); |
|
323 | blockSeriesSignals(false); | |
321 | } |
|
324 | } | |
322 |
|
325 | |||
323 | void QXYModelMapperPrivate::insertData(int start, int end) |
|
326 | void QXYModelMapperPrivate::insertData(int start, int end) | |
324 | { |
|
327 | { | |
325 | if (m_model == 0 || m_series == 0) |
|
328 | if (m_model == 0 || m_series == 0) | |
326 | return; |
|
329 | return; | |
327 |
|
330 | |||
328 | if (m_count != -1 && start >= m_first + m_count) { |
|
331 | if (m_count != -1 && start >= m_first + m_count) { | |
329 | return; |
|
332 | return; | |
330 | } else { |
|
333 | } else { | |
331 | int addedCount = end - start + 1; |
|
334 | int addedCount = end - start + 1; | |
332 | if (m_count != -1 && addedCount > m_count) |
|
335 | if (m_count != -1 && addedCount > m_count) | |
333 | addedCount = m_count; |
|
336 | addedCount = m_count; | |
334 | int first = qMax(start, m_first); |
|
337 | int first = qMax(start, m_first); | |
335 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); |
|
338 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); | |
336 | for (int i = first; i <= last; i++) { |
|
339 | for (int i = first; i <= last; i++) { | |
337 | QPointF point; |
|
340 | QPointF point; | |
338 | point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble()); |
|
341 | point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble()); | |
339 | point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble()); |
|
342 | point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble()); | |
340 | m_series->insert(i - m_first, point); |
|
343 | m_series->insert(i - m_first, point); | |
341 | } |
|
344 | } | |
342 |
|
345 | |||
343 | // remove excess of slices (abouve m_count) |
|
346 | // remove excess of slices (abouve m_count) | |
344 | if (m_count != -1 && m_series->points().size() > m_count) |
|
347 | if (m_count != -1 && m_series->points().size() > m_count) | |
345 | for (int i = m_series->points().size() - 1; i >= m_count; i--) { |
|
348 | for (int i = m_series->points().size() - 1; i >= m_count; i--) { | |
346 | m_series->remove(m_series->points().at(i)); |
|
349 | m_series->remove(m_series->points().at(i)); | |
347 | } |
|
350 | } | |
348 | } |
|
351 | } | |
349 | } |
|
352 | } | |
350 |
|
353 | |||
351 | void QXYModelMapperPrivate::removeData(int start, int end) |
|
354 | void QXYModelMapperPrivate::removeData(int start, int end) | |
352 | { |
|
355 | { | |
353 | if (m_model == 0 || m_series == 0) |
|
356 | if (m_model == 0 || m_series == 0) | |
354 | return; |
|
357 | return; | |
355 |
|
358 | |||
356 | int removedCount = end - start + 1; |
|
359 | int removedCount = end - start + 1; | |
357 | if (m_count != -1 && start >= m_first + m_count) { |
|
360 | if (m_count != -1 && start >= m_first + m_count) { | |
358 | return; |
|
361 | return; | |
359 | } else { |
|
362 | } else { | |
360 | int toRemove = qMin(m_series->points().size(), removedCount); // first find how many items can actually be removed |
|
363 | int toRemove = qMin(m_series->points().size(), removedCount); // first find how many items can actually be removed | |
361 | int first = qMax(start, m_first); // get the index of the first item that will be removed. |
|
364 | int first = qMax(start, m_first); // get the index of the first item that will be removed. | |
362 | int last = qMin(first + toRemove - 1, m_series->points().size() + m_first - 1); // get the index of the last item that will be removed. |
|
365 | int last = qMin(first + toRemove - 1, m_series->points().size() + m_first - 1); // get the index of the last item that will be removed. | |
363 | for (int i = last; i >= first; i--) { |
|
366 | for (int i = last; i >= first; i--) { | |
364 | m_series->remove(m_series->points().at(i - m_first)); |
|
367 | m_series->remove(m_series->points().at(i - m_first)); | |
365 | } |
|
368 | } | |
366 |
|
369 | |||
367 | if (m_count != -1) { |
|
370 | if (m_count != -1) { | |
368 | int itemsAvailable; // check how many are available to be added |
|
371 | int itemsAvailable; // check how many are available to be added | |
369 | if (m_orientation == Qt::Vertical) |
|
372 | if (m_orientation == Qt::Vertical) | |
370 | itemsAvailable = m_model->rowCount() - m_first - m_series->points().size(); |
|
373 | itemsAvailable = m_model->rowCount() - m_first - m_series->points().size(); | |
371 | else |
|
374 | else | |
372 | itemsAvailable = m_model->columnCount() - m_first - m_series->points().size(); |
|
375 | itemsAvailable = m_model->columnCount() - m_first - m_series->points().size(); | |
373 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->points().size()); // add not more items than there is space left to be filled. |
|
376 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->points().size()); // add not more items than there is space left to be filled. | |
374 | int currentSize = m_series->points().size(); |
|
377 | int currentSize = m_series->points().size(); | |
375 | if (toBeAdded > 0) |
|
378 | if (toBeAdded > 0) | |
376 | for (int i = m_series->points().size(); i < currentSize + toBeAdded; i++) { |
|
379 | for (int i = m_series->points().size(); i < currentSize + toBeAdded; i++) { | |
377 | QPointF point; |
|
380 | QPointF point; | |
378 | point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble()); |
|
381 | point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble()); | |
379 | point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble()); |
|
382 | point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble()); | |
380 | m_series->insert(i, point); |
|
383 | m_series->insert(i, point); | |
381 | } |
|
384 | } | |
382 | } |
|
385 | } | |
383 | } |
|
386 | } | |
384 | } |
|
387 | } | |
385 |
|
388 | |||
386 | void QXYModelMapperPrivate::initializeXYFromModel() |
|
389 | void QXYModelMapperPrivate::initializeXYFromModel() | |
387 | { |
|
390 | { | |
388 | if (m_model == 0 || m_series == 0) |
|
391 | if (m_model == 0 || m_series == 0) | |
389 | return; |
|
392 | return; | |
390 |
|
393 | |||
391 | blockSeriesSignals(); |
|
394 | blockSeriesSignals(); | |
392 | // clear current content |
|
395 | // clear current content | |
393 | m_series->clear(); |
|
396 | m_series->clear(); | |
394 |
|
397 | |||
395 | // create the initial slices set |
|
398 | // create the initial slices set | |
396 | int pointPos = 0; |
|
399 | int pointPos = 0; | |
397 | QModelIndex xIndex = xModelIndex(pointPos); |
|
400 | QModelIndex xIndex = xModelIndex(pointPos); | |
398 | QModelIndex yIndex = yModelIndex(pointPos); |
|
401 | QModelIndex yIndex = yModelIndex(pointPos); | |
399 | while (xIndex.isValid() && yIndex.isValid()) { |
|
402 | while (xIndex.isValid() && yIndex.isValid()) { | |
400 | QPointF point; |
|
403 | QPointF point; | |
401 | point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble()); |
|
404 | point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble()); | |
402 | point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble()); |
|
405 | point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble()); | |
403 | m_series->append(point); |
|
406 | m_series->append(point); | |
404 | pointPos++; |
|
407 | pointPos++; | |
405 | xIndex = xModelIndex(pointPos); |
|
408 | xIndex = xModelIndex(pointPos); | |
406 | yIndex = yModelIndex(pointPos); |
|
409 | yIndex = yModelIndex(pointPos); | |
407 | } |
|
410 | } | |
408 | blockSeriesSignals(false); |
|
411 | blockSeriesSignals(false); | |
409 | } |
|
412 | } | |
410 |
|
413 | |||
411 | #include "moc_qxymodelmapper.cpp" |
|
414 | #include "moc_qxymodelmapper.cpp" | |
412 | #include "moc_qxymodelmapper_p.cpp" |
|
415 | #include "moc_qxymodelmapper_p.cpp" | |
413 |
|
416 | |||
414 | QTCOMMERCIALCHART_END_NAMESPACE |
|
417 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now