@@ -1,105 +1,146 | |||||
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: chartView | |
31 | title: "Top-5 car brand shares in Finland" |
|
31 | title: "Top-5 car brand shares in Finland" | |
32 | anchors.fill: parent |
|
32 | anchors.fill: parent | |
33 | theme: ChartView.ChartThemeLight |
|
33 | theme: ChartView.ChartThemeLight | |
34 | axisX.max: 10 |
|
34 | axisX.max: 10 | |
35 | axisX.min: 0 |
|
35 | axisX.min: 0 | |
36 | axisY.max: 20 |
|
36 | axisY.max: 20 | |
37 | axisY.min: 0 |
|
37 | axisY.min: 0 | |
38 | animationOptions: ChartView.SeriesAnimations |
|
38 | animationOptions: ChartView.SeriesAnimations | |
39 | axisXLabels: [0, "2007", 1, "2008", 2, "2009", 3, "2010", 4, "2011", 5, "2012"] |
|
39 | axisXLabels: [0, "2007", 1, "2008", 2, "2009", 3, "2010", 4, "2011", 5, "2012"] | |
40 |
|
40 | |||
41 | // For dynamic data we use a custom data model derived from QAbstractiItemModel |
|
41 | // For dynamic data we use a custom data model derived from QAbstractiItemModel | |
42 | CustomModel { |
|
42 | CustomModel { | |
43 | id: customModel |
|
43 | id: customModel | |
44 | CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] } |
|
44 | CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] } | |
45 | CustomModelElement { values: [1, "Volkswagen", 10.3, 12.0, 12.8, 13.0, 13.8] } |
|
45 | CustomModelElement { values: [1, "Volkswagen", 10.3, 12.0, 12.8, 13.0, 13.8] } | |
46 | CustomModelElement { values: [2, "Toyota", 13.8, 13.5, 16.2, 13.7, 10.7] } |
|
46 | CustomModelElement { values: [2, "Toyota", 13.8, 13.5, 16.2, 13.7, 10.7] } | |
47 | CustomModelElement { values: [3, "Ford", 6.4, 7.1, 8.9, 8.2, 8.6] } |
|
47 | CustomModelElement { values: [3, "Ford", 6.4, 7.1, 8.9, 8.2, 8.6] } | |
48 | CustomModelElement { values: [4, "Skoda", 4.7, 5.8, 6.9, 8.3, 8.2] } |
|
48 | CustomModelElement { values: [4, "Skoda", 4.7, 5.8, 6.9, 8.3, 8.2] } | |
49 | CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] } |
|
49 | CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] } | |
50 | CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] } |
|
50 | CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] } | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | BarSeries { |
|
53 | BarSeries { | |
54 | name: "Others" |
|
54 | name: "Others" | |
55 | barMargin: 0 |
|
55 | barMargin: 0 | |
|
56 | visible: false | |||
56 | HBarModelMapper { |
|
57 | HBarModelMapper { | |
57 | model: customModel |
|
58 | model: customModel | |
58 | firstBarSetRow: 6 |
|
59 | firstBarSetRow: 6 | |
59 | lastBarSetRow: 6 |
|
60 | lastBarSetRow: 6 | |
60 | first: 2 |
|
61 | first: 2 | |
61 | } |
|
62 | } | |
62 | } |
|
63 | } | |
63 |
|
64 | |||
64 | LineSeries { |
|
65 | LineSeries { | |
65 | id: lineSeries |
|
|||
66 | name: "Volkswagen" |
|
66 | name: "Volkswagen" | |
|
67 | visible: false | |||
67 | HXYModelMapper { |
|
68 | HXYModelMapper { | |
68 | id: lineSeriesMapper |
|
|||
69 | model: customModel |
|
69 | model: customModel | |
70 | xRow: 0 |
|
70 | xRow: 0 | |
71 | yRow: 1 |
|
71 | yRow: 1 | |
72 | first: 2 |
|
72 | first: 2 | |
73 | } |
|
73 | } | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
|
76 | LineSeries { | |||
|
77 | name: "Toyota" | |||
|
78 | visible: false | |||
|
79 | HXYModelMapper { | |||
|
80 | model: customModel | |||
|
81 | xRow: 0 | |||
|
82 | yRow: 2 | |||
|
83 | first: 2 | |||
|
84 | } | |||
|
85 | } | |||
|
86 | ||||
|
87 | LineSeries { | |||
|
88 | name: "Ford" | |||
|
89 | visible: false | |||
|
90 | HXYModelMapper { | |||
|
91 | model: customModel | |||
|
92 | xRow: 0 | |||
|
93 | yRow: 2 | |||
|
94 | first: 2 | |||
|
95 | } | |||
|
96 | } | |||
|
97 | ||||
|
98 | LineSeries { | |||
|
99 | name: "Skoda" | |||
|
100 | visible: false | |||
|
101 | HXYModelMapper { | |||
|
102 | model: customModel | |||
|
103 | xRow: 0 | |||
|
104 | yRow: 3 | |||
|
105 | first: 2 | |||
|
106 | } | |||
|
107 | } | |||
|
108 | ||||
|
109 | LineSeries { | |||
|
110 | name: "Volvo" | |||
|
111 | visible: false | |||
|
112 | HXYModelMapper { | |||
|
113 | model: customModel | |||
|
114 | xRow: 0 | |||
|
115 | yRow: 4 | |||
|
116 | first: 2 | |||
|
117 | } | |||
|
118 | } | |||
|
119 | ||||
76 | PieSeries { |
|
120 | PieSeries { | |
77 | id: pieSeries |
|
121 | id: pieSeries | |
78 | size: 0.4 |
|
122 | size: 0.4 | |
79 | horizontalPosition: 0.7 |
|
123 | horizontalPosition: 0.7 | |
80 | verticalPosition: 0.4 |
|
124 | verticalPosition: 0.4 | |
81 | onClicked: { |
|
125 | onClicked: { | |
82 | // Show the selection by exploding the slice |
|
126 | // Show the selection by exploding the slice | |
83 | for (var i = 0; i < pieSeries.count; i++) |
|
127 | slice.exploded = !slice.exploded; | |
84 | pieSeries.at(i).exploded = false; |
|
|||
85 | slice.exploded = true; |
|
|||
86 |
|
128 | |||
87 | // Update the line series to show the yearly data for this slice |
|
129 | // Update the line series to show the yearly data for this slice | |
88 | lineSeries.name = slice.label; |
|
130 | for (var i = 0; i < chartView.count; i++) { | |
89 | for (var j = 0; j < customModel.rowCount; j++) { |
|
131 | if (chartView.series(i).name == slice.label) { | |
90 | if (customModel.at(j, 1) == slice.label) { |
|
132 | chartView.series(i).visible = slice.exploded; | |
91 | lineSeriesMapper.yRow = j; |
|
|||
92 | } |
|
133 | } | |
93 | } |
|
134 | } | |
94 | } |
|
135 | } | |
95 | } |
|
136 | } | |
96 |
|
137 | |||
97 | VPieModelMapper { |
|
138 | VPieModelMapper { | |
98 | series: pieSeries |
|
139 | series: pieSeries | |
99 | model: customModel |
|
140 | model: customModel | |
100 | labelsColumn: 1 |
|
141 | labelsColumn: 1 | |
101 | valuesColumn: 2 |
|
142 | valuesColumn: 2 | |
102 | first: 1 |
|
143 | first: 1 | |
103 | } |
|
144 | } | |
104 | } |
|
145 | } | |
105 | } |
|
146 | } |
@@ -1,143 +1,146 | |||||
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 "areachartitem_p.h" |
|
21 | #include "areachartitem_p.h" | |
22 | #include "qareaseries.h" |
|
22 | #include "qareaseries.h" | |
23 | #include "qareaseries_p.h" |
|
23 | #include "qareaseries_p.h" | |
24 | #include "qlineseries.h" |
|
24 | #include "qlineseries.h" | |
25 | #include "chartpresenter_p.h" |
|
25 | #include "chartpresenter_p.h" | |
26 | #include <QPainter> |
|
26 | #include <QPainter> | |
27 | #include <QGraphicsSceneMouseEvent> |
|
27 | #include <QGraphicsSceneMouseEvent> | |
28 | #include <QDebug> |
|
28 | #include <QDebug> | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | //TODO: optimize : remove points which are not visible |
|
33 | //TODO: optimize : remove points which are not visible | |
34 |
|
34 | |||
35 | AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, ChartPresenter *presenter) |
|
35 | AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, ChartPresenter *presenter) | |
36 | : ChartItem(presenter), |
|
36 | : ChartItem(presenter), | |
37 | m_series(areaSeries), |
|
37 | m_series(areaSeries), | |
38 | m_upper(0), |
|
38 | m_upper(0), | |
39 | m_lower(0), |
|
39 | m_lower(0), | |
40 | m_pointsVisible(false) |
|
40 | m_pointsVisible(false) | |
41 | { |
|
41 | { | |
42 | setZValue(ChartPresenter::LineChartZValue); |
|
42 | setZValue(ChartPresenter::LineChartZValue); | |
43 | m_upper = new AreaBoundItem(this,m_series->upperSeries(),presenter); |
|
43 | m_upper = new AreaBoundItem(this,m_series->upperSeries(),presenter); | |
44 | if (m_series->lowerSeries()) |
|
44 | if (m_series->lowerSeries()) | |
45 | m_lower = new AreaBoundItem(this,m_series->lowerSeries(),presenter); |
|
45 | m_lower = new AreaBoundItem(this,m_series->lowerSeries(),presenter); | |
46 |
|
46 | |||
47 | QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
47 | QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); | |
|
48 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |||
48 | QObject::connect(this,SIGNAL(clicked(QPointF)),areaSeries,SIGNAL(clicked(QPointF))); |
|
49 | QObject::connect(this,SIGNAL(clicked(QPointF)),areaSeries,SIGNAL(clicked(QPointF))); | |
49 |
|
50 | |||
50 | handleUpdated(); |
|
51 | handleUpdated(); | |
51 | } |
|
52 | } | |
52 |
|
53 | |||
53 | AreaChartItem::~AreaChartItem() |
|
54 | AreaChartItem::~AreaChartItem() | |
54 | { |
|
55 | { | |
55 | delete m_upper; |
|
56 | delete m_upper; | |
56 | delete m_lower; |
|
57 | delete m_lower; | |
57 | } |
|
58 | } | |
58 |
|
59 | |||
59 | QRectF AreaChartItem::boundingRect() const |
|
60 | QRectF AreaChartItem::boundingRect() const | |
60 | { |
|
61 | { | |
61 | return m_rect; |
|
62 | return m_rect; | |
62 | } |
|
63 | } | |
63 |
|
64 | |||
64 | QPainterPath AreaChartItem::shape() const |
|
65 | QPainterPath AreaChartItem::shape() const | |
65 | { |
|
66 | { | |
66 | return m_path; |
|
67 | return m_path; | |
67 | } |
|
68 | } | |
68 |
|
69 | |||
69 | void AreaChartItem::updatePath() |
|
70 | void AreaChartItem::updatePath() | |
70 | { |
|
71 | { | |
71 | QPainterPath path; |
|
72 | QPainterPath path; | |
72 |
|
73 | |||
73 | path = m_upper->shape(); |
|
74 | path = m_upper->shape(); | |
74 |
|
75 | |||
75 | if (m_lower) { |
|
76 | if (m_lower) { | |
76 | path.connectPath(m_lower->shape().toReversed()); |
|
77 | path.connectPath(m_lower->shape().toReversed()); | |
77 | } else { |
|
78 | } else { | |
78 | QPointF first = path.pointAtPercent(0); |
|
79 | QPointF first = path.pointAtPercent(0); | |
79 | QPointF last = path.pointAtPercent(1); |
|
80 | QPointF last = path.pointAtPercent(1); | |
80 | path.lineTo(last.x(),m_clipRect.bottom()); |
|
81 | path.lineTo(last.x(),m_clipRect.bottom()); | |
81 | path.lineTo(first.x(),m_clipRect.bottom()); |
|
82 | path.lineTo(first.x(),m_clipRect.bottom()); | |
82 | } |
|
83 | } | |
83 | path.closeSubpath(); |
|
84 | path.closeSubpath(); | |
84 | prepareGeometryChange(); |
|
85 | prepareGeometryChange(); | |
85 | m_path = path; |
|
86 | m_path = path; | |
86 | m_rect = path.boundingRect(); |
|
87 | m_rect = path.boundingRect(); | |
87 | update(); |
|
88 | update(); | |
88 | } |
|
89 | } | |
89 |
|
90 | |||
90 | void AreaChartItem::handleUpdated() |
|
91 | void AreaChartItem::handleUpdated() | |
91 | { |
|
92 | { | |
92 | m_pointsVisible = m_series->pointsVisible(); |
|
93 | m_pointsVisible = m_series->pointsVisible(); | |
93 | m_linePen = m_series->pen(); |
|
94 | m_linePen = m_series->pen(); | |
94 | m_brush = m_series->brush(); |
|
95 | m_brush = m_series->brush(); | |
95 | m_pointPen = m_series->pen(); |
|
96 | m_pointPen = m_series->pen(); | |
96 | m_pointPen.setWidthF(2 * m_pointPen.width()); |
|
97 | m_pointPen.setWidthF(2 * m_pointPen.width()); | |
97 |
|
98 | |||
98 | update(); |
|
99 | update(); | |
99 | } |
|
100 | } | |
100 |
|
101 | |||
101 | void AreaChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
102 | void AreaChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
102 | { |
|
103 | { | |
103 | m_upper->handleDomainChanged(minX,maxX,minY,maxY); |
|
104 | m_upper->handleDomainChanged(minX,maxX,minY,maxY); | |
104 | if (m_lower) |
|
105 | if (m_lower) | |
105 | m_lower->handleDomainChanged(minX,maxX,minY,maxY); |
|
106 | m_lower->handleDomainChanged(minX,maxX,minY,maxY); | |
106 | } |
|
107 | } | |
107 |
|
108 | |||
108 | void AreaChartItem::handleGeometryChanged(const QRectF &rect) |
|
109 | void AreaChartItem::handleGeometryChanged(const QRectF &rect) | |
109 | { |
|
110 | { | |
110 | m_clipRect=rect.translated(-rect.topLeft()); |
|
111 | m_clipRect=rect.translated(-rect.topLeft()); | |
111 | setPos(rect.topLeft()); |
|
112 | setPos(rect.topLeft()); | |
112 | m_upper->handleGeometryChanged(rect); |
|
113 | m_upper->handleGeometryChanged(rect); | |
113 | if (m_lower) |
|
114 | if (m_lower) | |
114 | m_lower->handleGeometryChanged(rect); |
|
115 | m_lower->handleGeometryChanged(rect); | |
115 | } |
|
116 | } | |
116 |
|
117 | |||
117 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
118 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
118 | { |
|
119 | { | |
119 | Q_UNUSED(widget) |
|
120 | Q_UNUSED(widget) | |
120 | Q_UNUSED(option) |
|
121 | Q_UNUSED(option) | |
121 |
|
122 | |||
122 | painter->save(); |
|
123 | if (m_series->isVisible()) { | |
123 |
painter->s |
|
124 | painter->save(); | |
124 |
painter->set |
|
125 | painter->setPen(m_linePen); | |
125 | painter->setClipRect(m_clipRect); |
|
126 | painter->setBrush(m_brush); | |
126 | painter->drawPath(m_path); |
|
127 | painter->setClipRect(m_clipRect); | |
127 | if (m_pointsVisible) { |
|
128 | painter->drawPath(m_path); | |
128 | painter->setPen(m_pointPen); |
|
129 | if (m_pointsVisible) { | |
129 | painter->drawPoints(m_upper->geometryPoints()); |
|
130 | painter->setPen(m_pointPen); | |
130 | if (m_lower) |
|
131 | painter->drawPoints(m_upper->geometryPoints()); | |
131 | painter->drawPoints(m_lower->geometryPoints()); |
|
132 | if (m_lower) | |
|
133 | painter->drawPoints(m_lower->geometryPoints()); | |||
|
134 | } | |||
|
135 | painter->restore(); | |||
132 | } |
|
136 | } | |
133 | painter->restore(); |
|
|||
134 | } |
|
137 | } | |
135 |
|
138 | |||
136 | void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
139 | void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
137 | { |
|
140 | { | |
138 | emit clicked(m_upper->calculateDomainPoint(event->pos())); |
|
141 | emit clicked(m_upper->calculateDomainPoint(event->pos())); | |
139 | } |
|
142 | } | |
140 |
|
143 | |||
141 | #include "moc_areachartitem_p.cpp" |
|
144 | #include "moc_areachartitem_p.cpp" | |
142 |
|
145 | |||
143 | QTCOMMERCIALCHART_END_NAMESPACE |
|
146 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,211 +1,212 | |||||
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 "barchartitem_p.h" |
|
21 | #include "barchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include "qbarseries_p.h" |
|
26 | #include "qbarseries_p.h" | |
27 | #include "qchart.h" |
|
27 | #include "qchart.h" | |
28 | #include "chartpresenter_p.h" |
|
28 | #include "chartpresenter_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 | #include "chartdataset_p.h" |
|
30 | #include "chartdataset_p.h" | |
31 | #include <QPainter> |
|
31 | #include <QPainter> | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
35 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
36 | ChartItem(presenter), |
|
36 | ChartItem(presenter), | |
37 | m_series(series) |
|
37 | m_series(series) | |
38 | { |
|
38 | { | |
39 | setFlag(ItemClipsChildrenToShape); |
|
39 | setFlag(ItemClipsChildrenToShape); | |
40 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); |
|
40 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
41 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); |
|
41 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); | |
42 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); |
|
42 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); | |
|
43 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleLayoutChanged())); | |||
43 | setZValue(ChartPresenter::BarSeriesZValue); |
|
44 | setZValue(ChartPresenter::BarSeriesZValue); | |
44 | handleDataStructureChanged(); |
|
45 | handleDataStructureChanged(); | |
45 | } |
|
46 | } | |
46 |
|
47 | |||
47 | BarChartItem::~BarChartItem() |
|
48 | BarChartItem::~BarChartItem() | |
48 | { |
|
49 | { | |
49 | } |
|
50 | } | |
50 |
|
51 | |||
51 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
52 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
52 | { |
|
53 | { | |
53 | Q_UNUSED(painter); |
|
54 | Q_UNUSED(painter); | |
54 | Q_UNUSED(option); |
|
55 | Q_UNUSED(option); | |
55 | Q_UNUSED(widget); |
|
56 | Q_UNUSED(widget); | |
56 | } |
|
57 | } | |
57 |
|
58 | |||
58 | QRectF BarChartItem::boundingRect() const |
|
59 | QRectF BarChartItem::boundingRect() const | |
59 | { |
|
60 | { | |
60 | return m_rect; |
|
61 | return m_rect; | |
61 | } |
|
62 | } | |
62 |
|
63 | |||
63 | void BarChartItem::handleDataStructureChanged() |
|
64 | void BarChartItem::handleDataStructureChanged() | |
64 | { |
|
65 | { | |
65 | foreach(QGraphicsItem *item, childItems()) { |
|
66 | foreach(QGraphicsItem *item, childItems()) { | |
66 | delete item; |
|
67 | delete item; | |
67 | } |
|
68 | } | |
68 |
|
69 | |||
69 | m_bars.clear(); |
|
70 | m_bars.clear(); | |
70 | m_labels.clear(); |
|
71 | m_labels.clear(); | |
71 | m_layout.clear(); |
|
72 | m_layout.clear(); | |
72 |
|
73 | |||
73 | bool labelsVisible = m_series->isLabelsVisible(); |
|
74 | bool labelsVisible = m_series->isLabelsVisible(); | |
74 |
|
75 | |||
75 | // Create new graphic items for bars |
|
76 | // Create new graphic items for bars | |
76 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { |
|
77 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { | |
77 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
78 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
78 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
79 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
79 |
|
80 | |||
80 | // Bars |
|
81 | // Bars | |
81 | Bar *bar = new Bar(set,c,this); |
|
82 | Bar *bar = new Bar(set,c,this); | |
82 | m_bars.append(bar); |
|
83 | m_bars.append(bar); | |
83 | connect(bar, SIGNAL(clicked(QBarSet*,int)), m_series, SIGNAL(clicked(QBarSet*,int))); |
|
84 | connect(bar, SIGNAL(clicked(QBarSet*,int)), m_series, SIGNAL(clicked(QBarSet*,int))); | |
84 | connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); |
|
85 | connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); | |
85 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
86 | m_layout.append(QRectF(0, 0, 0, 0)); | |
86 |
|
87 | |||
87 | // Labels |
|
88 | // Labels | |
88 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); |
|
89 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); | |
89 | label->setVisible(labelsVisible); |
|
90 | label->setVisible(labelsVisible); | |
90 | m_labels.append(label); |
|
91 | m_labels.append(label); | |
91 | } |
|
92 | } | |
92 | } |
|
93 | } | |
93 |
|
94 | |||
94 | // TODO: Is this the right place to call it? |
|
95 | // TODO: Is this the right place to call it? | |
95 | // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
96 | // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
96 | handleLayoutChanged(); |
|
97 | handleLayoutChanged(); | |
97 | } |
|
98 | } | |
98 |
|
99 | |||
99 | QVector<QRectF> BarChartItem::calculateLayout() |
|
100 | QVector<QRectF> BarChartItem::calculateLayout() | |
100 | { |
|
101 | { | |
101 | QVector<QRectF> layout; |
|
102 | QVector<QRectF> layout; | |
102 |
|
103 | |||
103 | // Use temporary qreals for accuracy |
|
104 | // Use temporary qreals for accuracy | |
104 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
105 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
105 | qreal setCount = m_series->barsetCount(); |
|
106 | qreal setCount = m_series->barsetCount(); | |
106 | bool barsVisible = m_series->isVisible(); |
|
107 | bool barsVisible = m_series->isVisible(); | |
107 |
|
108 | |||
108 | // Domain: |
|
109 | // Domain: | |
109 | qreal width = geometry().width(); |
|
110 | qreal width = geometry().width(); | |
110 | qreal height = geometry().height(); |
|
111 | qreal height = geometry().height(); | |
111 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
112 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
112 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
113 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
113 | qreal scaleY = (height / rangeY); |
|
114 | qreal scaleY = (height / rangeY); | |
114 | qreal scaleX = (width / rangeX); |
|
115 | qreal scaleX = (width / rangeX); | |
115 | qreal barWidth = scaleX - scaleX * m_series->d_func()->barMargin(); |
|
116 | qreal barWidth = scaleX - scaleX * m_series->d_func()->barMargin(); | |
116 |
|
117 | |||
117 | int itemIndex(0); |
|
118 | int itemIndex(0); | |
118 | for (int category = 0; category < categoryCount; category++) { |
|
119 | for (int category = 0; category < categoryCount; category++) { | |
119 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
120 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); | |
120 | for (int set = 0; set < setCount; set++) { |
|
121 | for (int set = 0; set < setCount; set++) { | |
121 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
122 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
122 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; |
|
123 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
123 | qreal barHeight = barSet->at(category).y() * scaleY; |
|
124 | qreal barHeight = barSet->at(category).y() * scaleY; | |
124 |
|
125 | |||
125 | Bar* bar = m_bars.at(itemIndex); |
|
126 | Bar* bar = m_bars.at(itemIndex); | |
126 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
127 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
127 |
|
128 | |||
128 | layout.append(rect); |
|
129 | layout.append(rect); | |
129 | bar->setPen(barSet->pen()); |
|
130 | bar->setPen(barSet->pen()); | |
130 | bar->setBrush(barSet->brush()); |
|
131 | bar->setBrush(barSet->brush()); | |
131 | bar->setVisible(barsVisible); |
|
132 | bar->setVisible(barsVisible); | |
132 |
|
133 | |||
133 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
134 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
134 |
|
135 | |||
135 | if (!qFuzzyIsNull(barSet->at(category).y())) { |
|
136 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |
136 | label->setText(QString::number(barSet->at(category).y())); |
|
137 | label->setText(QString::number(barSet->at(category).y())); | |
137 | } else { |
|
138 | } else { | |
138 | label->setText(QString("")); |
|
139 | label->setText(QString("")); | |
139 | } |
|
140 | } | |
140 |
|
141 | |||
141 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
142 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
142 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
143 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
143 | label->setFont(barSet->labelFont()); |
|
144 | label->setFont(barSet->labelFont()); | |
144 | label->setBrush(barSet->labelBrush()); |
|
145 | label->setBrush(barSet->labelBrush()); | |
145 |
|
146 | |||
146 | itemIndex++; |
|
147 | itemIndex++; | |
147 | } |
|
148 | } | |
148 | } |
|
149 | } | |
149 |
|
150 | |||
150 | return layout; |
|
151 | return layout; | |
151 | } |
|
152 | } | |
152 |
|
153 | |||
153 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
154 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
154 | { |
|
155 | { | |
155 | if (animator()) { |
|
156 | if (animator()) { | |
156 | animator()->updateLayout(this, m_layout, layout); |
|
157 | animator()->updateLayout(this, m_layout, layout); | |
157 | } else { |
|
158 | } else { | |
158 | setLayout(layout); |
|
159 | setLayout(layout); | |
159 | } |
|
160 | } | |
160 | } |
|
161 | } | |
161 |
|
162 | |||
162 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
163 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
163 | { |
|
164 | { | |
164 | m_layout = layout; |
|
165 | m_layout = layout; | |
165 |
|
166 | |||
166 | for (int i=0; i < m_bars.count(); i++) { |
|
167 | for (int i=0; i < m_bars.count(); i++) { | |
167 | m_bars.at(i)->setRect(layout.at(i)); |
|
168 | m_bars.at(i)->setRect(layout.at(i)); | |
168 | } |
|
169 | } | |
169 |
|
170 | |||
170 | update(); |
|
171 | update(); | |
171 | } |
|
172 | } | |
172 | //handlers |
|
173 | //handlers | |
173 |
|
174 | |||
174 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
175 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
175 | { |
|
176 | { | |
176 | m_domainMinX = minX; |
|
177 | m_domainMinX = minX; | |
177 | m_domainMaxX = maxX; |
|
178 | m_domainMaxX = maxX; | |
178 | m_domainMinY = minY; |
|
179 | m_domainMinY = minY; | |
179 | m_domainMaxY = maxY; |
|
180 | m_domainMaxY = maxY; | |
180 | handleLayoutChanged(); |
|
181 | handleLayoutChanged(); | |
181 | } |
|
182 | } | |
182 |
|
183 | |||
183 | void BarChartItem::handleGeometryChanged(const QRectF &rect) |
|
184 | void BarChartItem::handleGeometryChanged(const QRectF &rect) | |
184 | { |
|
185 | { | |
185 | prepareGeometryChange(); |
|
186 | prepareGeometryChange(); | |
186 | m_rect = rect; |
|
187 | m_rect = rect; | |
187 | handleLayoutChanged(); |
|
188 | handleLayoutChanged(); | |
188 | } |
|
189 | } | |
189 |
|
190 | |||
190 | void BarChartItem::handleLayoutChanged() |
|
191 | void BarChartItem::handleLayoutChanged() | |
191 | { |
|
192 | { | |
192 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { |
|
193 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { | |
193 | // rect size zero. |
|
194 | // rect size zero. | |
194 | return; |
|
195 | return; | |
195 | } |
|
196 | } | |
196 | QVector<QRectF> layout = calculateLayout(); |
|
197 | QVector<QRectF> layout = calculateLayout(); | |
197 | applyLayout(layout); |
|
198 | applyLayout(layout); | |
198 | update(); |
|
199 | update(); | |
199 | } |
|
200 | } | |
200 |
|
201 | |||
201 | void BarChartItem::handleLabelsVisibleChanged(bool visible) |
|
202 | void BarChartItem::handleLabelsVisibleChanged(bool visible) | |
202 | { |
|
203 | { | |
203 | foreach (QGraphicsSimpleTextItem* label, m_labels) { |
|
204 | foreach (QGraphicsSimpleTextItem* label, m_labels) { | |
204 | label->setVisible(visible); |
|
205 | label->setVisible(visible); | |
205 | } |
|
206 | } | |
206 | update(); |
|
207 | update(); | |
207 | } |
|
208 | } | |
208 |
|
209 | |||
209 | #include "moc_barchartitem_p.cpp" |
|
210 | #include "moc_barchartitem_p.cpp" | |
210 |
|
211 | |||
211 | QTCOMMERCIALCHART_END_NAMESPACE |
|
212 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,561 +1,543 | |||||
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 "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \class QBarSeries |
|
34 | \class QBarSeries | |
35 | \brief part of QtCommercial chart API. |
|
35 | \brief part of QtCommercial chart API. | |
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
38 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
39 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
39 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
40 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
40 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
41 | shows the x-values. |
|
41 | shows the x-values. | |
42 |
|
42 | |||
43 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
43 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
44 | \image examples_barchart.png |
|
44 | \image examples_barchart.png | |
45 |
|
45 | |||
46 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
46 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \fn void QBarSeries::clicked(QBarSet *barset, int index) |
|
50 | \fn void QBarSeries::clicked(QBarSet *barset, int index) | |
51 |
|
51 | |||
52 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
52 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
53 | Clicked bar inside set is indexed by \a index |
|
53 | Clicked bar inside set is indexed by \a index | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
57 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) | |
58 |
|
58 | |||
59 | The signal is emitted if mouse is hovered on top of series. |
|
59 | The signal is emitted if mouse is hovered on top of series. | |
60 | Parameter \a barset is the pointer of barset, where hover happened. |
|
60 | Parameter \a barset is the pointer of barset, where hover happened. | |
61 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
61 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | Constructs empty QBarSeries. |
|
65 | Constructs empty QBarSeries. | |
66 | QBarSeries is QObject which is a child of a \a parent. |
|
66 | QBarSeries is QObject which is a child of a \a parent. | |
67 | */ |
|
67 | */ | |
68 | QBarSeries::QBarSeries(QObject *parent) : |
|
68 | QBarSeries::QBarSeries(QObject *parent) : | |
69 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) |
|
69 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) | |
70 | { |
|
70 | { | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | Destructs barseries and owned barsets. |
|
74 | Destructs barseries and owned barsets. | |
75 | */ |
|
75 | */ | |
76 | QBarSeries::~QBarSeries() |
|
76 | QBarSeries::~QBarSeries() | |
77 | { |
|
77 | { | |
78 | Q_D(QBarSeries); |
|
78 | Q_D(QBarSeries); | |
79 | if(d->m_dataset){ |
|
79 | if(d->m_dataset){ | |
80 | d->m_dataset->removeSeries(this); |
|
80 | d->m_dataset->removeSeries(this); | |
81 | } |
|
81 | } | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | \internal |
|
85 | \internal | |
86 | */ |
|
86 | */ | |
87 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
87 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : | |
88 | QAbstractSeries(d,parent) |
|
88 | QAbstractSeries(d,parent) | |
89 | { |
|
89 | { | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | /*! |
|
92 | /*! | |
93 | Returns the type of series. Derived classes override this. |
|
93 | Returns the type of series. Derived classes override this. | |
94 | */ |
|
94 | */ | |
95 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
95 | QAbstractSeries::SeriesType QBarSeries::type() const | |
96 | { |
|
96 | { | |
97 | return QAbstractSeries::SeriesTypeBar; |
|
97 | return QAbstractSeries::SeriesTypeBar; | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | Sets the margin around bars. Parameter \a margin is from 0 to 1 and represents |
|
101 | Sets the margin around bars. Parameter \a margin is from 0 to 1 and represents | |
102 | percentage of margin compared to bars |
|
102 | percentage of margin compared to bars | |
103 | */ |
|
103 | */ | |
104 | void QBarSeries::setBarMargin(qreal margin) |
|
104 | void QBarSeries::setBarMargin(qreal margin) | |
105 | { |
|
105 | { | |
106 | Q_D(QBarSeries); |
|
106 | Q_D(QBarSeries); | |
107 | d->setBarMargin(margin); |
|
107 | d->setBarMargin(margin); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | Returns the margin around bars |
|
111 | Returns the margin around bars | |
112 | */ |
|
112 | */ | |
113 | qreal QBarSeries::barMargin() const |
|
113 | qreal QBarSeries::barMargin() const | |
114 | { |
|
114 | { | |
115 | Q_D(const QBarSeries); |
|
115 | Q_D(const QBarSeries); | |
116 | return d->barMargin(); |
|
116 | return d->barMargin(); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
120 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
121 | Returns true, if appending succeeded. |
|
121 | Returns true, if appending succeeded. | |
122 |
|
122 | |||
123 | */ |
|
123 | */ | |
124 | bool QBarSeries::append(QBarSet *set) |
|
124 | bool QBarSeries::append(QBarSet *set) | |
125 | { |
|
125 | { | |
126 | Q_D(QBarSeries); |
|
126 | Q_D(QBarSeries); | |
127 | return d->append(set); |
|
127 | return d->append(set); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | /*! |
|
130 | /*! | |
131 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
131 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
132 | Returns true, if set was removed. |
|
132 | Returns true, if set was removed. | |
133 | */ |
|
133 | */ | |
134 | bool QBarSeries::remove(QBarSet *set) |
|
134 | bool QBarSeries::remove(QBarSet *set) | |
135 | { |
|
135 | { | |
136 | Q_D(QBarSeries); |
|
136 | Q_D(QBarSeries); | |
137 | return d->remove(set); |
|
137 | return d->remove(set); | |
138 | } |
|
138 | } | |
139 |
|
139 | |||
140 | /*! |
|
140 | /*! | |
141 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
141 | Adds a list of barsets to series. Takes ownership of \a sets. | |
142 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
142 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
143 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
143 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
144 | and function returns false. |
|
144 | and function returns false. | |
145 | */ |
|
145 | */ | |
146 | bool QBarSeries::append(QList<QBarSet* > sets) |
|
146 | bool QBarSeries::append(QList<QBarSet* > sets) | |
147 | { |
|
147 | { | |
148 | Q_D(QBarSeries); |
|
148 | Q_D(QBarSeries); | |
149 | return d->append(sets); |
|
149 | return d->append(sets); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. |
|
153 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. | |
154 | */ |
|
154 | */ | |
155 | bool QBarSeries::remove(QList<QBarSet* > sets) |
|
155 | bool QBarSeries::remove(QList<QBarSet* > sets) | |
156 | { |
|
156 | { | |
157 | Q_D(QBarSeries); |
|
157 | Q_D(QBarSeries); | |
158 | return d->remove(sets); |
|
158 | return d->remove(sets); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void QBarSeries::clear() |
|
161 | void QBarSeries::clear() | |
162 | { |
|
162 | { | |
163 | Q_D(QBarSeries); |
|
163 | Q_D(QBarSeries); | |
164 | d->m_barSets.clear(); |
|
164 | d->m_barSets.clear(); | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | /*! |
|
167 | /*! | |
168 | Returns number of sets in series. |
|
168 | Returns number of sets in series. | |
169 | */ |
|
169 | */ | |
170 | int QBarSeries::barsetCount() const |
|
170 | int QBarSeries::barsetCount() const | |
171 | { |
|
171 | { | |
172 | Q_D(const QBarSeries); |
|
172 | Q_D(const QBarSeries); | |
173 | return d->m_barSets.count(); |
|
173 | return d->m_barSets.count(); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | Returns a list of sets in series. Keeps ownership of sets. |
|
177 | Returns a list of sets in series. Keeps ownership of sets. | |
178 | */ |
|
178 | */ | |
179 | QList<QBarSet*> QBarSeries::barSets() const |
|
179 | QList<QBarSet*> QBarSeries::barSets() const | |
180 | { |
|
180 | { | |
181 | Q_D(const QBarSeries); |
|
181 | Q_D(const QBarSeries); | |
182 | return d->m_barSets; |
|
182 | return d->m_barSets; | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | Sets the visibility of series to \a visible |
|
|||
187 | */ |
|
|||
188 | void QBarSeries::setVisible(bool visible) |
|
|||
189 | { |
|
|||
190 | Q_D(QBarSeries); |
|
|||
191 | d->setVisible(visible); |
|
|||
192 | } |
|
|||
193 |
|
||||
194 | /*! |
|
|||
195 | Returns the visibility of series |
|
|||
196 | */ |
|
|||
197 | bool QBarSeries::isVisible() const |
|
|||
198 | { |
|
|||
199 | Q_D(const QBarSeries); |
|
|||
200 | return d->isVisible(); |
|
|||
201 | } |
|
|||
202 |
|
||||
203 | /*! |
|
|||
204 | Sets the visibility of labels in series to \a visible |
|
186 | Sets the visibility of labels in series to \a visible | |
205 | */ |
|
187 | */ | |
206 | void QBarSeries::setLabelsVisible(bool visible) |
|
188 | void QBarSeries::setLabelsVisible(bool visible) | |
207 | { |
|
189 | { | |
208 | Q_D(QBarSeries); |
|
190 | Q_D(QBarSeries); | |
209 | if (d->m_labelsVisible != visible) { |
|
191 | if (d->m_labelsVisible != visible) { | |
210 | d->m_labelsVisible = visible; |
|
192 | d->m_labelsVisible = visible; | |
211 | emit d->labelsVisibleChanged(visible); |
|
193 | emit d->labelsVisibleChanged(visible); | |
212 | } |
|
194 | } | |
213 | } |
|
195 | } | |
214 |
|
196 | |||
215 | /*! |
|
197 | /*! | |
216 | Returns the visibility of labels |
|
198 | Returns the visibility of labels | |
217 | */ |
|
199 | */ | |
218 | bool QBarSeries::isLabelsVisible() const |
|
200 | bool QBarSeries::isLabelsVisible() const | |
219 | { |
|
201 | { | |
220 | Q_D(const QBarSeries); |
|
202 | Q_D(const QBarSeries); | |
221 | return d->m_labelsVisible; |
|
203 | return d->m_labelsVisible; | |
222 | } |
|
204 | } | |
223 |
|
205 | |||
224 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
206 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
225 |
|
207 | |||
226 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : |
|
208 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : | |
227 | QAbstractSeriesPrivate(q), |
|
209 | QAbstractSeriesPrivate(q), | |
228 | m_barMargin(0.5), // Default value is 50% of category width |
|
210 | m_barMargin(0.5), // Default value is 50% of category width | |
229 | m_labelsVisible(false), |
|
211 | m_labelsVisible(false), | |
230 | m_visible(true) |
|
212 | m_visible(true) | |
231 | { |
|
213 | { | |
232 | } |
|
214 | } | |
233 |
|
215 | |||
234 | void QBarSeriesPrivate::setCategories(QStringList categories) |
|
216 | void QBarSeriesPrivate::setCategories(QStringList categories) | |
235 | { |
|
217 | { | |
236 | m_categories = categories; |
|
218 | m_categories = categories; | |
237 | } |
|
219 | } | |
238 |
|
220 | |||
239 | void QBarSeriesPrivate::insertCategory(int index, const QString category) |
|
221 | void QBarSeriesPrivate::insertCategory(int index, const QString category) | |
240 | { |
|
222 | { | |
241 | m_categories.insert(index, category); |
|
223 | m_categories.insert(index, category); | |
242 | emit categoriesUpdated(); |
|
224 | emit categoriesUpdated(); | |
243 | } |
|
225 | } | |
244 |
|
226 | |||
245 | void QBarSeriesPrivate::removeCategory(int index) |
|
227 | void QBarSeriesPrivate::removeCategory(int index) | |
246 | { |
|
228 | { | |
247 | m_categories.removeAt(index); |
|
229 | m_categories.removeAt(index); | |
248 | emit categoriesUpdated(); |
|
230 | emit categoriesUpdated(); | |
249 | } |
|
231 | } | |
250 |
|
232 | |||
251 | int QBarSeriesPrivate::categoryCount() const |
|
233 | int QBarSeriesPrivate::categoryCount() const | |
252 | { |
|
234 | { | |
253 | if (m_categories.count() > 0) { |
|
235 | if (m_categories.count() > 0) { | |
254 | return m_categories.count(); |
|
236 | return m_categories.count(); | |
255 | } |
|
237 | } | |
256 |
|
238 | |||
257 | // No categories defined. return count of longest set. |
|
239 | // No categories defined. return count of longest set. | |
258 | int count = 0; |
|
240 | int count = 0; | |
259 | for (int i=0; i<m_barSets.count(); i++) { |
|
241 | for (int i=0; i<m_barSets.count(); i++) { | |
260 | if (m_barSets.at(i)->count() > count) { |
|
242 | if (m_barSets.at(i)->count() > count) { | |
261 | count = m_barSets.at(i)->count(); |
|
243 | count = m_barSets.at(i)->count(); | |
262 | } |
|
244 | } | |
263 | } |
|
245 | } | |
264 |
|
246 | |||
265 | return count; |
|
247 | return count; | |
266 | } |
|
248 | } | |
267 |
|
249 | |||
268 | QStringList QBarSeriesPrivate::categories() const |
|
250 | QStringList QBarSeriesPrivate::categories() const | |
269 | { |
|
251 | { | |
270 | if (m_categories.count() > 0) { |
|
252 | if (m_categories.count() > 0) { | |
271 | return m_categories; |
|
253 | return m_categories; | |
272 | } |
|
254 | } | |
273 |
|
255 | |||
274 | // No categories defined. retun list of indices. |
|
256 | // No categories defined. retun list of indices. | |
275 | QStringList categories; |
|
257 | QStringList categories; | |
276 |
|
258 | |||
277 | int count = categoryCount(); |
|
259 | int count = categoryCount(); | |
278 | for (int i = 0; i < count; i++) { |
|
260 | for (int i = 0; i < count; i++) { | |
279 | categories.append(QString::number(i)); |
|
261 | categories.append(QString::number(i)); | |
280 | } |
|
262 | } | |
281 | return categories; |
|
263 | return categories; | |
282 | } |
|
264 | } | |
283 |
|
265 | |||
284 | void QBarSeriesPrivate::setBarMargin(qreal margin) |
|
266 | void QBarSeriesPrivate::setBarMargin(qreal margin) | |
285 | { |
|
267 | { | |
286 | if (margin > 1.0) { |
|
268 | if (margin > 1.0) { | |
287 | margin = 1.0; |
|
269 | margin = 1.0; | |
288 | } else if (margin < 0.0) { |
|
270 | } else if (margin < 0.0) { | |
289 | margin = 0.0; |
|
271 | margin = 0.0; | |
290 | } |
|
272 | } | |
291 |
|
273 | |||
292 | m_barMargin = margin; |
|
274 | m_barMargin = margin; | |
293 | emit updatedBars(); |
|
275 | emit updatedBars(); | |
294 | } |
|
276 | } | |
295 |
|
277 | |||
296 | qreal QBarSeriesPrivate::barMargin() const |
|
278 | qreal QBarSeriesPrivate::barMargin() const | |
297 | { |
|
279 | { | |
298 | return m_barMargin; |
|
280 | return m_barMargin; | |
299 | } |
|
281 | } | |
300 |
|
282 | |||
301 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
283 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
302 | { |
|
284 | { | |
303 | return m_barSets.at(index); |
|
285 | return m_barSets.at(index); | |
304 | } |
|
286 | } | |
305 |
|
287 | |||
306 | void QBarSeriesPrivate::setVisible(bool visible) |
|
288 | void QBarSeriesPrivate::setVisible(bool visible) | |
307 | { |
|
289 | { | |
308 | if (m_visible != visible) { |
|
290 | if (m_visible != visible) { | |
309 | m_visible = visible; |
|
291 | m_visible = visible; | |
310 | emit updatedBars(); |
|
292 | emit updatedBars(); | |
311 | } |
|
293 | } | |
312 | } |
|
294 | } | |
313 |
|
295 | |||
314 | bool QBarSeriesPrivate::isVisible() const |
|
296 | bool QBarSeriesPrivate::isVisible() const | |
315 | { |
|
297 | { | |
316 | return m_visible; |
|
298 | return m_visible; | |
317 | } |
|
299 | } | |
318 |
|
300 | |||
319 | QString QBarSeriesPrivate::categoryName(int category) |
|
301 | QString QBarSeriesPrivate::categoryName(int category) | |
320 | { |
|
302 | { | |
321 | if ((category >= 0) && (category < m_categories.count())) { |
|
303 | if ((category >= 0) && (category < m_categories.count())) { | |
322 | return m_categories.at(category); |
|
304 | return m_categories.at(category); | |
323 | } |
|
305 | } | |
324 |
|
306 | |||
325 | return QString::number(category); |
|
307 | return QString::number(category); | |
326 | } |
|
308 | } | |
327 |
|
309 | |||
328 | qreal QBarSeriesPrivate::min() |
|
310 | qreal QBarSeriesPrivate::min() | |
329 | { |
|
311 | { | |
330 | if (m_barSets.count() <= 0) { |
|
312 | if (m_barSets.count() <= 0) { | |
331 | return 0; |
|
313 | return 0; | |
332 | } |
|
314 | } | |
333 | qreal min = INT_MAX; |
|
315 | qreal min = INT_MAX; | |
334 |
|
316 | |||
335 | for (int i = 0; i < m_barSets.count(); i++) { |
|
317 | for (int i = 0; i < m_barSets.count(); i++) { | |
336 | int categoryCount = m_barSets.at(i)->count(); |
|
318 | int categoryCount = m_barSets.at(i)->count(); | |
337 | for (int j = 0; j < categoryCount; j++) { |
|
319 | for (int j = 0; j < categoryCount; j++) { | |
338 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
320 | qreal temp = m_barSets.at(i)->at(j).y(); | |
339 | if (temp < min) |
|
321 | if (temp < min) | |
340 | min = temp; |
|
322 | min = temp; | |
341 | } |
|
323 | } | |
342 | } |
|
324 | } | |
343 | return min; |
|
325 | return min; | |
344 | } |
|
326 | } | |
345 |
|
327 | |||
346 | qreal QBarSeriesPrivate::max() |
|
328 | qreal QBarSeriesPrivate::max() | |
347 | { |
|
329 | { | |
348 | if (m_barSets.count() <= 0) { |
|
330 | if (m_barSets.count() <= 0) { | |
349 | return 0; |
|
331 | return 0; | |
350 | } |
|
332 | } | |
351 | qreal max = INT_MIN; |
|
333 | qreal max = INT_MIN; | |
352 |
|
334 | |||
353 | for (int i = 0; i < m_barSets.count(); i++) { |
|
335 | for (int i = 0; i < m_barSets.count(); i++) { | |
354 | int categoryCount = m_barSets.at(i)->count(); |
|
336 | int categoryCount = m_barSets.at(i)->count(); | |
355 | for (int j = 0; j < categoryCount; j++) { |
|
337 | for (int j = 0; j < categoryCount; j++) { | |
356 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
338 | qreal temp = m_barSets.at(i)->at(j).y(); | |
357 | if (temp > max) |
|
339 | if (temp > max) | |
358 | max = temp; |
|
340 | max = temp; | |
359 | } |
|
341 | } | |
360 | } |
|
342 | } | |
361 |
|
343 | |||
362 | return max; |
|
344 | return max; | |
363 | } |
|
345 | } | |
364 |
|
346 | |||
365 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
347 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
366 | { |
|
348 | { | |
367 | if ((set < 0) || (set >= m_barSets.count())) { |
|
349 | if ((set < 0) || (set >= m_barSets.count())) { | |
368 | // No set, no value. |
|
350 | // No set, no value. | |
369 | return 0; |
|
351 | return 0; | |
370 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
352 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
371 | // No category, no value. |
|
353 | // No category, no value. | |
372 | return 0; |
|
354 | return 0; | |
373 | } |
|
355 | } | |
374 |
|
356 | |||
375 | return m_barSets.at(set)->at(category).y(); |
|
357 | return m_barSets.at(set)->at(category).y(); | |
376 | } |
|
358 | } | |
377 |
|
359 | |||
378 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
360 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
379 | { |
|
361 | { | |
380 | if ((set < 0) || (set >= m_barSets.count())) { |
|
362 | if ((set < 0) || (set >= m_barSets.count())) { | |
381 | // No set, no value. |
|
363 | // No set, no value. | |
382 | return 0; |
|
364 | return 0; | |
383 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
365 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
384 | // No category, no value. |
|
366 | // No category, no value. | |
385 | return 0; |
|
367 | return 0; | |
386 | } |
|
368 | } | |
387 |
|
369 | |||
388 | qreal value = m_barSets.at(set)->at(category).y(); |
|
370 | qreal value = m_barSets.at(set)->at(category).y(); | |
389 | qreal sum = categorySum(category); |
|
371 | qreal sum = categorySum(category); | |
390 | if ( qFuzzyIsNull(sum) ) { |
|
372 | if ( qFuzzyIsNull(sum) ) { | |
391 | return 0; |
|
373 | return 0; | |
392 | } |
|
374 | } | |
393 |
|
375 | |||
394 | return value / sum; |
|
376 | return value / sum; | |
395 | } |
|
377 | } | |
396 |
|
378 | |||
397 | qreal QBarSeriesPrivate::categorySum(int category) |
|
379 | qreal QBarSeriesPrivate::categorySum(int category) | |
398 | { |
|
380 | { | |
399 | qreal sum(0); |
|
381 | qreal sum(0); | |
400 | int count = m_barSets.count(); // Count sets |
|
382 | int count = m_barSets.count(); // Count sets | |
401 | for (int set = 0; set < count; set++) { |
|
383 | for (int set = 0; set < count; set++) { | |
402 | if (category < m_barSets.at(set)->count()) |
|
384 | if (category < m_barSets.at(set)->count()) | |
403 | sum += m_barSets.at(set)->at(category).y(); |
|
385 | sum += m_barSets.at(set)->at(category).y(); | |
404 | } |
|
386 | } | |
405 | return sum; |
|
387 | return sum; | |
406 | } |
|
388 | } | |
407 |
|
389 | |||
408 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
390 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
409 | { |
|
391 | { | |
410 | qreal sum(0); |
|
392 | qreal sum(0); | |
411 | int count = m_barSets.count(); // Count sets |
|
393 | int count = m_barSets.count(); // Count sets | |
412 | for (int set = 0; set < count; set++) { |
|
394 | for (int set = 0; set < count; set++) { | |
413 | if (category < m_barSets.at(set)->count()) |
|
395 | if (category < m_barSets.at(set)->count()) | |
414 | sum += qAbs(m_barSets.at(set)->at(category).y()); |
|
396 | sum += qAbs(m_barSets.at(set)->at(category).y()); | |
415 | } |
|
397 | } | |
416 | return sum; |
|
398 | return sum; | |
417 | } |
|
399 | } | |
418 |
|
400 | |||
419 | qreal QBarSeriesPrivate::maxCategorySum() |
|
401 | qreal QBarSeriesPrivate::maxCategorySum() | |
420 | { |
|
402 | { | |
421 | qreal max = INT_MIN; |
|
403 | qreal max = INT_MIN; | |
422 | int count = categoryCount(); |
|
404 | int count = categoryCount(); | |
423 | for (int i = 0; i < count; i++) { |
|
405 | for (int i = 0; i < count; i++) { | |
424 | qreal sum = categorySum(i); |
|
406 | qreal sum = categorySum(i); | |
425 | if (sum > max) |
|
407 | if (sum > max) | |
426 | max = sum; |
|
408 | max = sum; | |
427 | } |
|
409 | } | |
428 | return max; |
|
410 | return max; | |
429 | } |
|
411 | } | |
430 |
|
412 | |||
431 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
413 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
432 | { |
|
414 | { | |
433 | qreal minX(domain.minX()); |
|
415 | qreal minX(domain.minX()); | |
434 | qreal minY(domain.minY()); |
|
416 | qreal minY(domain.minY()); | |
435 | qreal maxX(domain.maxX()); |
|
417 | qreal maxX(domain.maxX()); | |
436 | qreal maxY(domain.maxY()); |
|
418 | qreal maxY(domain.maxY()); | |
437 | int tickXCount(domain.tickXCount()); |
|
419 | int tickXCount(domain.tickXCount()); | |
438 | int tickYCount(domain.tickYCount()); |
|
420 | int tickYCount(domain.tickYCount()); | |
439 |
|
421 | |||
440 | qreal x = categoryCount(); |
|
422 | qreal x = categoryCount(); | |
441 | qreal y = max(); |
|
423 | qreal y = max(); | |
442 | minX = qMin(minX, x) - 0.5; |
|
424 | minX = qMin(minX, x) - 0.5; | |
443 | minY = qMin(minY, y); |
|
425 | minY = qMin(minY, y); | |
444 | maxX = qMax(maxX, x) - 0.5; |
|
426 | maxX = qMax(maxX, x) - 0.5; | |
445 | maxY = qMax(maxY, y); |
|
427 | maxY = qMax(maxY, y); | |
446 | tickXCount = x+1; |
|
428 | tickXCount = x+1; | |
447 |
|
429 | |||
448 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
430 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
449 | } |
|
431 | } | |
450 |
|
432 | |||
451 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
433 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
452 | { |
|
434 | { | |
453 | Q_Q(QBarSeries); |
|
435 | Q_Q(QBarSeries); | |
454 |
|
436 | |||
455 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
437 | BarChartItem* bar = new BarChartItem(q,presenter); | |
456 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
438 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
457 | presenter->animator()->addAnimation(bar); |
|
439 | presenter->animator()->addAnimation(bar); | |
458 | } |
|
440 | } | |
459 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
441 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
460 | return bar; |
|
442 | return bar; | |
461 |
|
443 | |||
462 | } |
|
444 | } | |
463 |
|
445 | |||
464 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
446 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
465 | { |
|
447 | { | |
466 | Q_Q(QBarSeries); |
|
448 | Q_Q(QBarSeries); | |
467 | QList<LegendMarker*> markers; |
|
449 | QList<LegendMarker*> markers; | |
468 | foreach(QBarSet* set, q->barSets()) { |
|
450 | foreach(QBarSet* set, q->barSets()) { | |
469 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
451 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
470 | markers << marker; |
|
452 | markers << marker; | |
471 | } |
|
453 | } | |
472 |
|
454 | |||
473 | return markers; |
|
455 | return markers; | |
474 | } |
|
456 | } | |
475 |
|
457 | |||
476 | bool QBarSeriesPrivate::append(QBarSet *set) |
|
458 | bool QBarSeriesPrivate::append(QBarSet *set) | |
477 | { |
|
459 | { | |
478 | Q_Q(QBarSeries); |
|
460 | Q_Q(QBarSeries); | |
479 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
461 | if ((m_barSets.contains(set)) || (set == 0)) { | |
480 | // Fail if set is already in list or set is null. |
|
462 | // Fail if set is already in list or set is null. | |
481 | return false; |
|
463 | return false; | |
482 | } |
|
464 | } | |
483 | m_barSets.append(set); |
|
465 | m_barSets.append(set); | |
484 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
466 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
485 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
467 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
486 | if (m_dataset) { |
|
468 | if (m_dataset) { | |
487 | m_dataset->updateSeries(q); // this notifies legend |
|
469 | m_dataset->updateSeries(q); // this notifies legend | |
488 | } |
|
470 | } | |
489 | emit restructuredBars(); // this notifies barchartitem |
|
471 | emit restructuredBars(); // this notifies barchartitem | |
490 | return true; |
|
472 | return true; | |
491 | } |
|
473 | } | |
492 |
|
474 | |||
493 | bool QBarSeriesPrivate::remove(QBarSet *set) |
|
475 | bool QBarSeriesPrivate::remove(QBarSet *set) | |
494 | { |
|
476 | { | |
495 | Q_Q(QBarSeries); |
|
477 | Q_Q(QBarSeries); | |
496 | if (!m_barSets.contains(set)) { |
|
478 | if (!m_barSets.contains(set)) { | |
497 | // Fail if set is not in list |
|
479 | // Fail if set is not in list | |
498 | return false; |
|
480 | return false; | |
499 | } |
|
481 | } | |
500 | m_barSets.removeOne(set); |
|
482 | m_barSets.removeOne(set); | |
501 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
483 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
502 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
484 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
503 | if (m_dataset) { |
|
485 | if (m_dataset) { | |
504 | m_dataset->updateSeries(q); // this notifies legend |
|
486 | m_dataset->updateSeries(q); // this notifies legend | |
505 | } |
|
487 | } | |
506 | emit restructuredBars(); // this notifies barchartitem |
|
488 | emit restructuredBars(); // this notifies barchartitem | |
507 | return true; |
|
489 | return true; | |
508 | } |
|
490 | } | |
509 |
|
491 | |||
510 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
492 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) | |
511 | { |
|
493 | { | |
512 | Q_Q(QBarSeries); |
|
494 | Q_Q(QBarSeries); | |
513 | foreach (QBarSet* set, sets) { |
|
495 | foreach (QBarSet* set, sets) { | |
514 | if ((set == 0) || (m_barSets.contains(set))) { |
|
496 | if ((set == 0) || (m_barSets.contains(set))) { | |
515 | // Fail if any of the sets is null or is already appended. |
|
497 | // Fail if any of the sets is null or is already appended. | |
516 | return false; |
|
498 | return false; | |
517 | } |
|
499 | } | |
518 | if (sets.count(set) != 1) { |
|
500 | if (sets.count(set) != 1) { | |
519 | // Also fail if same set is more than once in given list. |
|
501 | // Also fail if same set is more than once in given list. | |
520 | return false; |
|
502 | return false; | |
521 | } |
|
503 | } | |
522 | } |
|
504 | } | |
523 |
|
505 | |||
524 | foreach (QBarSet* set, sets) { |
|
506 | foreach (QBarSet* set, sets) { | |
525 | m_barSets.append(set); |
|
507 | m_barSets.append(set); | |
526 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
508 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
527 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
509 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
528 | } |
|
510 | } | |
529 | if (m_dataset) { |
|
511 | if (m_dataset) { | |
530 | m_dataset->updateSeries(q); // this notifies legend |
|
512 | m_dataset->updateSeries(q); // this notifies legend | |
531 | } |
|
513 | } | |
532 | emit restructuredBars(); // this notifies barchartitem |
|
514 | emit restructuredBars(); // this notifies barchartitem | |
533 | return true; |
|
515 | return true; | |
534 | } |
|
516 | } | |
535 |
|
517 | |||
536 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
518 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
537 | { |
|
519 | { | |
538 | Q_Q(QBarSeries); |
|
520 | Q_Q(QBarSeries); | |
539 | bool setsRemoved = false; |
|
521 | bool setsRemoved = false; | |
540 | foreach (QBarSet* set, sets) { |
|
522 | foreach (QBarSet* set, sets) { | |
541 | if (m_barSets.contains(set)) { |
|
523 | if (m_barSets.contains(set)) { | |
542 | m_barSets.removeOne(set); |
|
524 | m_barSets.removeOne(set); | |
543 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
525 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
544 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
526 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
545 | setsRemoved = true; |
|
527 | setsRemoved = true; | |
546 | } |
|
528 | } | |
547 | } |
|
529 | } | |
548 |
|
530 | |||
549 | if (setsRemoved) { |
|
531 | if (setsRemoved) { | |
550 | if (m_dataset) { |
|
532 | if (m_dataset) { | |
551 | m_dataset->updateSeries(q); // this notifies legend |
|
533 | m_dataset->updateSeries(q); // this notifies legend | |
552 | } |
|
534 | } | |
553 | emit restructuredBars(); // this notifies barchartitem |
|
535 | emit restructuredBars(); // this notifies barchartitem | |
554 | } |
|
536 | } | |
555 | return setsRemoved; |
|
537 | return setsRemoved; | |
556 | } |
|
538 | } | |
557 |
|
539 | |||
558 | #include "moc_qbarseries.cpp" |
|
540 | #include "moc_qbarseries.cpp" | |
559 | #include "moc_qbarseries_p.cpp" |
|
541 | #include "moc_qbarseries_p.cpp" | |
560 |
|
542 | |||
561 | QTCOMMERCIALCHART_END_NAMESPACE |
|
543 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,80 +1,77 | |||||
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 BARSERIES_H |
|
21 | #ifndef BARSERIES_H | |
22 | #define BARSERIES_H |
|
22 | #define BARSERIES_H | |
23 |
|
23 | |||
24 | #include <qabstractseries.h> |
|
24 | #include <qabstractseries.h> | |
25 | #include <QStringList> |
|
25 | #include <QStringList> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class QBarSet; |
|
29 | class QBarSet; | |
30 | class QBarSeriesPrivate; |
|
30 | class QBarSeriesPrivate; | |
31 |
|
31 | |||
32 | // Container for series |
|
32 | // Container for series | |
33 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries |
|
33 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | Q_PROPERTY(qreal barMargin READ barMargin WRITE setBarMargin) |
|
36 | Q_PROPERTY(qreal barMargin READ barMargin WRITE setBarMargin) | |
37 |
Q_PROPERTY(int count READ barsetCount) |
|
37 | Q_PROPERTY(int count READ barsetCount) | |
38 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible) |
|
|||
39 | Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible) |
|
38 | Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible) | |
40 |
|
39 | |||
41 | public: |
|
40 | public: | |
42 | explicit QBarSeries(QObject *parent = 0); |
|
41 | explicit QBarSeries(QObject *parent = 0); | |
43 | virtual ~QBarSeries(); |
|
42 | virtual ~QBarSeries(); | |
44 |
|
43 | |||
45 | QAbstractSeries::SeriesType type() const; |
|
44 | QAbstractSeries::SeriesType type() const; | |
46 |
|
45 | |||
47 | void setBarMargin(qreal margin); |
|
46 | void setBarMargin(qreal margin); | |
48 | qreal barMargin() const; |
|
47 | qreal barMargin() const; | |
49 |
|
48 | |||
50 | bool append(QBarSet *set); |
|
49 | bool append(QBarSet *set); | |
51 | bool remove(QBarSet *set); |
|
50 | bool remove(QBarSet *set); | |
52 | bool append(QList<QBarSet* > sets); |
|
51 | bool append(QList<QBarSet* > sets); | |
53 | bool remove(QList<QBarSet* > sets); |
|
52 | bool remove(QList<QBarSet* > sets); | |
54 | int barsetCount() const; |
|
53 | int barsetCount() const; | |
55 | QList<QBarSet*> barSets() const; |
|
54 | QList<QBarSet*> barSets() const; | |
56 | void clear(); |
|
55 | void clear(); | |
57 |
|
56 | |||
58 | void setVisible(bool visible = true); |
|
|||
59 | bool isVisible() const; |
|
|||
60 | void setLabelsVisible(bool visible = true); |
|
57 | void setLabelsVisible(bool visible = true); | |
61 | bool isLabelsVisible() const; |
|
58 | bool isLabelsVisible() const; | |
62 |
|
59 | |||
63 | protected: |
|
60 | protected: | |
64 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); |
|
61 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); | |
65 |
|
62 | |||
66 | Q_SIGNALS: |
|
63 | Q_SIGNALS: | |
67 | void clicked(QBarSet *barset, int index); |
|
64 | void clicked(QBarSet *barset, int index); | |
68 | void hovered(QBarSet* barset, bool status); |
|
65 | void hovered(QBarSet* barset, bool status); | |
69 |
|
66 | |||
70 | protected: |
|
67 | protected: | |
71 | Q_DECLARE_PRIVATE(QBarSeries) |
|
68 | Q_DECLARE_PRIVATE(QBarSeries) | |
72 | friend class BarChartItem; |
|
69 | friend class BarChartItem; | |
73 | friend class PercentBarChartItem; |
|
70 | friend class PercentBarChartItem; | |
74 | friend class StackedBarChartItem; |
|
71 | friend class StackedBarChartItem; | |
75 | friend class GroupedBarChartItem; |
|
72 | friend class GroupedBarChartItem; | |
76 | }; |
|
73 | }; | |
77 |
|
74 | |||
78 | QTCOMMERCIALCHART_END_NAMESPACE |
|
75 | QTCOMMERCIALCHART_END_NAMESPACE | |
79 |
|
76 | |||
80 | #endif // BARSERIES_H |
|
77 | #endif // BARSERIES_H |
@@ -1,111 +1,114 | |||||
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 "linechartitem_p.h" |
|
21 | #include "linechartitem_p.h" | |
22 | #include "qlineseries.h" |
|
22 | #include "qlineseries.h" | |
23 | #include "qlineseries_p.h" |
|
23 | #include "qlineseries_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include <QPainter> |
|
25 | #include <QPainter> | |
26 | #include <QGraphicsSceneMouseEvent> |
|
26 | #include <QGraphicsSceneMouseEvent> | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | //TODO: optimize : remove points which are not visible |
|
31 | //TODO: optimize : remove points which are not visible | |
32 |
|
32 | |||
33 | LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter):XYChart(series,presenter), |
|
33 | LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter):XYChart(series,presenter), | |
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), |
|
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), | |
35 | m_series(series), |
|
35 | m_series(series), | |
36 | m_pointsVisible(false) |
|
36 | m_pointsVisible(false) | |
37 | { |
|
37 | { | |
38 | setZValue(ChartPresenter::LineChartZValue); |
|
38 | setZValue(ChartPresenter::LineChartZValue); | |
39 | QObject::connect(series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
39 | QObject::connect(series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); | |
|
40 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |||
40 | handleUpdated(); |
|
41 | handleUpdated(); | |
41 | } |
|
42 | } | |
42 |
|
43 | |||
43 | QRectF LineChartItem::boundingRect() const |
|
44 | QRectF LineChartItem::boundingRect() const | |
44 | { |
|
45 | { | |
45 | return m_rect; |
|
46 | return m_rect; | |
46 | } |
|
47 | } | |
47 |
|
48 | |||
48 | QPainterPath LineChartItem::shape() const |
|
49 | QPainterPath LineChartItem::shape() const | |
49 | { |
|
50 | { | |
50 | return m_path; |
|
51 | return m_path; | |
51 | } |
|
52 | } | |
52 |
|
53 | |||
53 | void LineChartItem::updateGeometry() |
|
54 | void LineChartItem::updateGeometry() | |
54 | { |
|
55 | { | |
55 | const QVector<QPointF>& points = geometryPoints(); |
|
56 | const QVector<QPointF>& points = geometryPoints(); | |
56 |
|
57 | |||
57 | if(points.size()==0) |
|
58 | if(points.size()==0) | |
58 | { |
|
59 | { | |
59 | prepareGeometryChange(); |
|
60 | prepareGeometryChange(); | |
60 | m_path = QPainterPath(); |
|
61 | m_path = QPainterPath(); | |
61 | m_rect = QRect(); |
|
62 | m_rect = QRect(); | |
62 | return; |
|
63 | return; | |
63 | } |
|
64 | } | |
64 |
|
65 | |||
65 | QPainterPath linePath(points.at(0)); |
|
66 | QPainterPath linePath(points.at(0)); | |
66 |
|
67 | |||
67 | for(int i=1; i< points.size();i++) { |
|
68 | for(int i=1; i< points.size();i++) { | |
68 | linePath.lineTo(points.at(i)); |
|
69 | linePath.lineTo(points.at(i)); | |
69 | } |
|
70 | } | |
70 |
|
71 | |||
71 | prepareGeometryChange(); |
|
72 | prepareGeometryChange(); | |
72 | m_path = linePath; |
|
73 | m_path = linePath; | |
73 | m_rect = linePath.boundingRect(); |
|
74 | m_rect = linePath.boundingRect(); | |
74 | setPos(origin()); |
|
75 | setPos(origin()); | |
75 | } |
|
76 | } | |
76 |
|
77 | |||
77 | void LineChartItem::handleUpdated() |
|
78 | void LineChartItem::handleUpdated() | |
78 | { |
|
79 | { | |
79 | m_pointsVisible = m_series->pointsVisible(); |
|
80 | m_pointsVisible = m_series->pointsVisible(); | |
80 | m_linePen = m_series->pen(); |
|
81 | m_linePen = m_series->pen(); | |
81 | m_pointPen = m_series->pen(); |
|
82 | m_pointPen = m_series->pen(); | |
82 | m_pointPen.setWidthF(2*m_pointPen.width()); |
|
83 | m_pointPen.setWidthF(2*m_pointPen.width()); | |
83 | update(); |
|
84 | update(); | |
84 | } |
|
85 | } | |
85 |
|
86 | |||
86 | //painter |
|
87 | //painter | |
87 |
|
88 | |||
88 | void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
89 | void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
89 | { |
|
90 | { | |
90 | Q_UNUSED(widget) |
|
91 | Q_UNUSED(widget) | |
91 | Q_UNUSED(option) |
|
92 | Q_UNUSED(option) | |
92 |
|
93 | |||
93 | painter->save(); |
|
94 | if (m_series->isVisible()) { | |
94 |
painter->s |
|
95 | painter->save(); | |
95 |
painter->set |
|
96 | painter->setPen(m_linePen); | |
96 | painter->drawPath(m_path); |
|
97 | painter->setClipRect(clipRect()); | |
97 | if(m_pointsVisible){ |
|
98 | painter->drawPath(m_path); | |
98 | painter->setPen(m_pointPen); |
|
99 | if(m_pointsVisible){ | |
99 | painter->drawPoints(geometryPoints()); |
|
100 | painter->setPen(m_pointPen); | |
|
101 | painter->drawPoints(geometryPoints()); | |||
|
102 | } | |||
|
103 | painter->restore(); | |||
100 | } |
|
104 | } | |
101 | painter->restore(); |
|
|||
102 | } |
|
105 | } | |
103 |
|
106 | |||
104 | void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
107 | void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
105 | { |
|
108 | { | |
106 | emit XYChart::clicked(calculateDomainPoint(event->pos())); |
|
109 | emit XYChart::clicked(calculateDomainPoint(event->pos())); | |
107 | } |
|
110 | } | |
108 |
|
111 | |||
109 | #include "moc_linechartitem_p.cpp" |
|
112 | #include "moc_linechartitem_p.cpp" | |
110 |
|
113 | |||
111 | QTCOMMERCIALCHART_END_NAMESPACE |
|
114 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,145 +1,165 | |||||
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 "qabstractseries.h" |
|
21 | #include "qabstractseries.h" | |
22 | #include "qabstractseries_p.h" |
|
22 | #include "qabstractseries_p.h" | |
23 | #include "chartdataset_p.h" |
|
23 | #include "chartdataset_p.h" | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \class QAbstractSeries |
|
28 | \class QAbstractSeries | |
29 | \brief Base class for all QtCommercial Chart series. |
|
29 | \brief Base class for all QtCommercial Chart series. | |
30 | \mainclass |
|
30 | \mainclass | |
31 |
|
31 | |||
32 | Usually you use the series type specific inherited classes instead of the base class. |
|
32 | Usually you use the series type specific inherited classes instead of the base class. | |
33 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries, |
|
33 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries, | |
34 | QPercentBarSeries, QPieSeries |
|
34 | QPercentBarSeries, QPieSeries | |
35 | */ |
|
35 | */ | |
36 |
|
36 | |||
37 | /*! |
|
37 | /*! | |
38 | \enum QAbstractSeries::SeriesType |
|
38 | \enum QAbstractSeries::SeriesType | |
39 |
|
39 | |||
40 | The type of the series object. |
|
40 | The type of the series object. | |
41 |
|
41 | |||
42 | \value SeriesTypeLine |
|
42 | \value SeriesTypeLine | |
43 | \value SeriesTypeArea |
|
43 | \value SeriesTypeArea | |
44 | \value SeriesTypeBar |
|
44 | \value SeriesTypeBar | |
45 | \value SeriesTypeStackedBar |
|
45 | \value SeriesTypeStackedBar | |
46 | \value SeriesTypePercentBar |
|
46 | \value SeriesTypePercentBar | |
47 | \value SeriesTypeGroupedBar |
|
47 | \value SeriesTypeGroupedBar | |
48 | \value SeriesTypePie |
|
48 | \value SeriesTypePie | |
49 | \value SeriesTypeScatter |
|
49 | \value SeriesTypeScatter | |
50 | \value SeriesTypeSpline |
|
50 | \value SeriesTypeSpline | |
51 | */ |
|
51 | */ | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | \fn QSeriesType QAbstractSeries::type() const |
|
54 | \fn QSeriesType QAbstractSeries::type() const | |
55 | \brief The type of the series. |
|
55 | \brief The type of the series. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \property QAbstractSeries::name |
|
59 | \property QAbstractSeries::name | |
60 | \brief name of the series property |
|
60 | \brief name of the series property | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \fn void QAbstractSeries::nameChanged() |
|
64 | \fn void QAbstractSeries::nameChanged() | |
65 |
|
65 | |||
66 | This signal is emitted when the series name changes. |
|
66 | This signal is emitted when the series name changes. | |
67 |
|
67 | |||
68 | \sa name |
|
68 | \sa name | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \fn void QAbstractSeries::setName(const QString& name) |
|
72 | \fn void QAbstractSeries::setName(const QString& name) | |
73 | \brief Sets a \a name for the series. |
|
73 | \brief Sets a \a name for the series. | |
74 |
|
74 | |||
75 | The name of a series is shown in the legend for QXYSeries. |
|
75 | The name of a series is shown in the legend for QXYSeries. | |
76 | \sa QChart::setTitle() |
|
76 | \sa QChart::setTitle() | |
77 | \sa QPieSlice::setLabel() |
|
77 | \sa QPieSlice::setLabel() | |
78 | \sa QBarSet::setName() |
|
78 | \sa QBarSet::setName() | |
79 | */ |
|
79 | */ | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | \internal |
|
82 | \internal | |
83 | \brief Constructs ChartSeries object with \a parent. |
|
83 | \brief Constructs ChartSeries object with \a parent. | |
84 | */ |
|
84 | */ | |
85 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : |
|
85 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : | |
86 | QObject(parent), |
|
86 | QObject(parent), | |
87 | d_ptr(&d) |
|
87 | d_ptr(&d) | |
88 | { |
|
88 | { | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | \brief Virtual destructor for the chart series. |
|
92 | \brief Virtual destructor for the chart series. | |
93 | */ |
|
93 | */ | |
94 | QAbstractSeries::~QAbstractSeries() |
|
94 | QAbstractSeries::~QAbstractSeries() | |
95 | { |
|
95 | { | |
96 | if(d_ptr->m_dataset) qFatal("Still binded series detected !"); |
|
96 | if(d_ptr->m_dataset) qFatal("Still binded series detected !"); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void QAbstractSeries::setName(const QString& name) |
|
99 | void QAbstractSeries::setName(const QString& name) | |
100 | { |
|
100 | { | |
101 | if (name != d_ptr->m_name) { |
|
101 | if (name != d_ptr->m_name) { | |
102 | d_ptr->m_name = name; |
|
102 | d_ptr->m_name = name; | |
103 | nameChanged(); |
|
103 | emit nameChanged(); | |
104 | } |
|
104 | } | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \brief Returns the name of the series. |
|
108 | \brief Returns the name of the series. | |
109 | \sa setName() |
|
109 | \sa setName() | |
110 | */ |
|
110 | */ | |
111 | QString QAbstractSeries::name() const |
|
111 | QString QAbstractSeries::name() const | |
112 | { |
|
112 | { | |
113 | return d_ptr->m_name; |
|
113 | return d_ptr->m_name; | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
|
117 | Sets the visibility of series to \a visible | |||
|
118 | */ | |||
|
119 | void QAbstractSeries::setVisible(bool visible) | |||
|
120 | { | |||
|
121 | if (visible != d_ptr->m_visible) { | |||
|
122 | d_ptr->m_visible = visible; | |||
|
123 | emit visibleChanged(); | |||
|
124 | } | |||
|
125 | } | |||
|
126 | ||||
|
127 | /*! | |||
|
128 | Returns the visibility of series | |||
|
129 | */ | |||
|
130 | bool QAbstractSeries::isVisible() const | |||
|
131 | { | |||
|
132 | return d_ptr->m_visible; | |||
|
133 | } | |||
|
134 | ||||
|
135 | /*! | |||
117 | \brief Returns the chart where series belongs to. |
|
136 | \brief Returns the chart where series belongs to. | |
118 |
|
137 | |||
119 | Set automatically when the series is added to the chart |
|
138 | Set automatically when the series is added to the chart | |
120 | and unset when the series is removed from the chart. |
|
139 | and unset when the series is removed from the chart. | |
121 | */ |
|
140 | */ | |
122 | QChart* QAbstractSeries::chart() const |
|
141 | QChart* QAbstractSeries::chart() const | |
123 | { |
|
142 | { | |
124 | return d_ptr->m_chart; |
|
143 | return d_ptr->m_chart; | |
125 | } |
|
144 | } | |
126 |
|
145 | |||
127 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
146 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
128 |
|
147 | |||
129 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): |
|
148 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): | |
130 | q_ptr(q), |
|
149 | q_ptr(q), | |
131 | m_chart(0), |
|
150 | m_chart(0), | |
132 | m_dataset(0) |
|
151 | m_dataset(0), | |
|
152 | m_visible(true) | |||
133 | { |
|
153 | { | |
134 | } |
|
154 | } | |
135 |
|
155 | |||
136 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() |
|
156 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() | |
137 | { |
|
157 | { | |
138 | } |
|
158 | } | |
139 |
|
159 | |||
140 | #include "moc_qabstractseries.cpp" |
|
160 | #include "moc_qabstractseries.cpp" | |
141 | #include "moc_qabstractseries_p.cpp" |
|
161 | #include "moc_qabstractseries_p.cpp" | |
142 |
|
162 | |||
143 | QTCOMMERCIALCHART_END_NAMESPACE |
|
163 | QTCOMMERCIALCHART_END_NAMESPACE | |
144 |
|
164 | |||
145 |
|
165 |
@@ -1,74 +1,78 | |||||
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 QABSTRACTSERIES_H |
|
21 | #ifndef QABSTRACTSERIES_H | |
22 | #define QABSTRACTSERIES_H |
|
22 | #define QABSTRACTSERIES_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QObject> |
|
25 | #include <QObject> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | class QAbstractSeriesPrivate; |
|
30 | class QAbstractSeriesPrivate; | |
31 | class QChart; |
|
31 | class QChart; | |
32 |
|
32 | |||
33 | class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject |
|
33 | class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
|
36 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) | |
|
37 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) | |||
37 | Q_ENUMS(SeriesType) |
|
38 | Q_ENUMS(SeriesType) | |
38 |
|
39 | |||
39 | public: |
|
40 | public: | |
40 | enum SeriesType { |
|
41 | enum SeriesType { | |
41 | SeriesTypeLine, |
|
42 | SeriesTypeLine, | |
42 | SeriesTypeArea, |
|
43 | SeriesTypeArea, | |
43 | SeriesTypeBar, |
|
44 | SeriesTypeBar, | |
44 | SeriesTypeStackedBar, |
|
45 | SeriesTypeStackedBar, | |
45 | SeriesTypePercentBar, |
|
46 | SeriesTypePercentBar, | |
46 | SeriesTypeGroupedBar, |
|
47 | SeriesTypeGroupedBar, | |
47 | SeriesTypePie, |
|
48 | SeriesTypePie, | |
48 | SeriesTypeScatter, |
|
49 | SeriesTypeScatter, | |
49 | SeriesTypeSpline |
|
50 | SeriesTypeSpline | |
50 | }; |
|
51 | }; | |
51 |
|
52 | |||
52 | protected: |
|
53 | protected: | |
53 | QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0); |
|
54 | QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0); | |
54 |
|
55 | |||
55 | public: |
|
56 | public: | |
56 | ~QAbstractSeries(); |
|
57 | ~QAbstractSeries(); | |
57 | virtual SeriesType type() const = 0; |
|
58 | virtual SeriesType type() const = 0; | |
58 | void setName(const QString& name); |
|
59 | void setName(const QString& name); | |
59 | QString name() const; |
|
60 | QString name() const; | |
|
61 | void setVisible(bool visible = true); | |||
|
62 | bool isVisible() const; | |||
60 | QChart* chart() const; |
|
63 | QChart* chart() const; | |
61 |
|
64 | |||
62 | Q_SIGNALS: |
|
65 | Q_SIGNALS: | |
63 | void nameChanged(); |
|
66 | void nameChanged(); | |
|
67 | void visibleChanged(); | |||
64 |
|
68 | |||
65 | protected: |
|
69 | protected: | |
66 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; |
|
70 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; | |
67 | friend class ChartDataSet; |
|
71 | friend class ChartDataSet; | |
68 | friend class ChartPresenter; |
|
72 | friend class ChartPresenter; | |
69 | friend class QLegendPrivate; |
|
73 | friend class QLegendPrivate; | |
70 | }; |
|
74 | }; | |
71 |
|
75 | |||
72 | QTCOMMERCIALCHART_END_NAMESPACE |
|
76 | QTCOMMERCIALCHART_END_NAMESPACE | |
73 |
|
77 | |||
74 | #endif |
|
78 | #endif |
@@ -1,67 +1,68 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QABSTRACTSERIES_P_H |
|
30 | #ifndef QABSTRACTSERIES_P_H | |
31 | #define QABSTRACTSERIES_P_H |
|
31 | #define QABSTRACTSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractseries.h" |
|
33 | #include "qabstractseries.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class Domain; |
|
37 | class Domain; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 | class Chart; |
|
39 | class Chart; | |
40 | class LegendMarker; |
|
40 | class LegendMarker; | |
41 | class QLegend; |
|
41 | class QLegend; | |
42 | class ChartDataSet; |
|
42 | class ChartDataSet; | |
43 |
|
43 | |||
44 | class QAbstractSeriesPrivate : public QObject |
|
44 | class QAbstractSeriesPrivate : public QObject | |
45 | { |
|
45 | { | |
46 | Q_OBJECT |
|
46 | Q_OBJECT | |
47 | public: |
|
47 | public: | |
48 | QAbstractSeriesPrivate(QAbstractSeries *q); |
|
48 | QAbstractSeriesPrivate(QAbstractSeries *q); | |
49 | ~QAbstractSeriesPrivate(); |
|
49 | ~QAbstractSeriesPrivate(); | |
50 |
|
50 | |||
51 | virtual void scaleDomain(Domain& domain) = 0; |
|
51 | virtual void scaleDomain(Domain& domain) = 0; | |
52 | virtual Chart* createGraphics(ChartPresenter* presenter) = 0; |
|
52 | virtual Chart* createGraphics(ChartPresenter* presenter) = 0; | |
53 | virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0; |
|
53 | virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0; | |
54 |
|
54 | |||
55 | protected: |
|
55 | protected: | |
56 | QAbstractSeries *q_ptr; |
|
56 | QAbstractSeries *q_ptr; | |
57 | QChart *m_chart; |
|
57 | QChart *m_chart; | |
58 | ChartDataSet *m_dataset; |
|
58 | ChartDataSet *m_dataset; | |
59 | QString m_name; |
|
59 | QString m_name; | |
|
60 | bool m_visible; | |||
60 |
|
61 | |||
61 | friend class QAbstractSeries; |
|
62 | friend class QAbstractSeries; | |
62 | friend class ChartDataSet; |
|
63 | friend class ChartDataSet; | |
63 | }; |
|
64 | }; | |
64 |
|
65 | |||
65 | QTCOMMERCIALCHART_END_NAMESPACE |
|
66 | QTCOMMERCIALCHART_END_NAMESPACE | |
66 |
|
67 | |||
67 | #endif |
|
68 | #endif |
@@ -1,200 +1,201 | |||||
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 "scatterchartitem_p.h" |
|
21 | #include "scatterchartitem_p.h" | |
22 | #include "qscatterseries.h" |
|
22 | #include "qscatterseries.h" | |
23 | #include "qscatterseries_p.h" |
|
23 | #include "qscatterseries_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include <QPainter> |
|
25 | #include <QPainter> | |
26 | #include <QGraphicsScene> |
|
26 | #include <QGraphicsScene> | |
27 | #include <QDebug> |
|
27 | #include <QDebug> | |
28 | #include <QGraphicsSceneMouseEvent> |
|
28 | #include <QGraphicsSceneMouseEvent> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) : |
|
32 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) : | |
33 | XYChart(series,presenter), |
|
33 | XYChart(series,presenter), | |
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), |
|
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), | |
35 | m_series(series), |
|
35 | m_series(series), | |
36 | m_items(this), |
|
36 | m_items(this), | |
37 | m_shape(QScatterSeries::MarkerShapeRectangle), |
|
37 | m_shape(QScatterSeries::MarkerShapeRectangle), | |
38 | m_size(15) |
|
38 | m_size(15) | |
39 | { |
|
39 | { | |
40 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated())); |
|
40 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated())); | |
|
41 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |||
41 |
|
42 | |||
42 | setZValue(ChartPresenter::ScatterSeriesZValue); |
|
43 | setZValue(ChartPresenter::ScatterSeriesZValue); | |
43 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
44 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
44 |
|
45 | |||
45 | handleUpdated(); |
|
46 | handleUpdated(); | |
46 |
|
47 | |||
47 | m_items.setHandlesChildEvents(false); |
|
48 | m_items.setHandlesChildEvents(false); | |
48 |
|
49 | |||
49 | // TODO: how to draw a drop shadow? |
|
50 | // TODO: how to draw a drop shadow? | |
50 | // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect(); |
|
51 | // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect(); | |
51 | // dropShadow->setOffset(2.0); |
|
52 | // dropShadow->setOffset(2.0); | |
52 | // dropShadow->setBlurRadius(2.0); |
|
53 | // dropShadow->setBlurRadius(2.0); | |
53 | // setGraphicsEffect(dropShadow); |
|
54 | // setGraphicsEffect(dropShadow); | |
54 | } |
|
55 | } | |
55 |
|
56 | |||
56 | QRectF ScatterChartItem::boundingRect() const |
|
57 | QRectF ScatterChartItem::boundingRect() const | |
57 | { |
|
58 | { | |
58 | return m_rect; |
|
59 | return m_rect; | |
59 | } |
|
60 | } | |
60 |
|
61 | |||
61 | void ScatterChartItem::createPoints(int count) |
|
62 | void ScatterChartItem::createPoints(int count) | |
62 | { |
|
63 | { | |
63 | for (int i = 0; i < count; ++i) { |
|
64 | for (int i = 0; i < count; ++i) { | |
64 |
|
65 | |||
65 | QGraphicsItem *item = 0; |
|
66 | QGraphicsItem *item = 0; | |
66 |
|
67 | |||
67 | switch (m_shape) { |
|
68 | switch (m_shape) { | |
68 | case QScatterSeries::MarkerShapeCircle: { |
|
69 | case QScatterSeries::MarkerShapeCircle: { | |
69 | QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size); |
|
70 | QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size); | |
70 | const QRectF& rect = i->boundingRect(); |
|
71 | const QRectF& rect = i->boundingRect(); | |
71 | i->setPos(-rect.width()/2,-rect.height()/2); |
|
72 | i->setPos(-rect.width()/2,-rect.height()/2); | |
72 | item = new Marker(i,this); |
|
73 | item = new Marker(i,this); | |
73 | break; |
|
74 | break; | |
74 | } |
|
75 | } | |
75 | case QScatterSeries::MarkerShapeRectangle: { |
|
76 | case QScatterSeries::MarkerShapeRectangle: { | |
76 | QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size); |
|
77 | QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size); | |
77 | i->setPos(-m_size/2,-m_size/2); |
|
78 | i->setPos(-m_size/2,-m_size/2); | |
78 | item = new Marker(i,this); |
|
79 | item = new Marker(i,this); | |
79 | break; |
|
80 | break; | |
80 | } |
|
81 | } | |
81 | default: |
|
82 | default: | |
82 | qWarning()<<"Unsupported marker type"; |
|
83 | qWarning()<<"Unsupported marker type"; | |
83 | break; |
|
84 | break; | |
84 |
|
85 | |||
85 | } |
|
86 | } | |
86 | m_items.addToGroup(item); |
|
87 | m_items.addToGroup(item); | |
87 | } |
|
88 | } | |
88 | } |
|
89 | } | |
89 |
|
90 | |||
90 | void ScatterChartItem::deletePoints(int count) |
|
91 | void ScatterChartItem::deletePoints(int count) | |
91 | { |
|
92 | { | |
92 | QList<QGraphicsItem *> items = m_items.childItems(); |
|
93 | QList<QGraphicsItem *> items = m_items.childItems(); | |
93 |
|
94 | |||
94 | for (int i = 0; i < count; ++i) { |
|
95 | for (int i = 0; i < count; ++i) { | |
95 | delete(items.takeLast()); |
|
96 | delete(items.takeLast()); | |
96 | } |
|
97 | } | |
97 | } |
|
98 | } | |
98 |
|
99 | |||
99 | void ScatterChartItem::markerSelected(Marker *marker) |
|
100 | void ScatterChartItem::markerSelected(Marker *marker) | |
100 | { |
|
101 | { | |
101 | emit XYChart::clicked(marker->point()); |
|
102 | emit XYChart::clicked(marker->point()); | |
102 | } |
|
103 | } | |
103 |
|
104 | |||
104 | void ScatterChartItem::updateGeometry() |
|
105 | void ScatterChartItem::updateGeometry() | |
105 | { |
|
106 | { | |
106 |
|
107 | |||
107 | const QVector<QPointF>& points = geometryPoints(); |
|
108 | const QVector<QPointF>& points = geometryPoints(); | |
108 |
|
109 | |||
109 | if(points.size()==0) |
|
110 | if(points.size()==0) | |
110 | { |
|
111 | { | |
111 | deletePoints(m_items.childItems().count()); |
|
112 | deletePoints(m_items.childItems().count()); | |
112 | return; |
|
113 | return; | |
113 | } |
|
114 | } | |
114 |
|
115 | |||
115 | int diff = m_items.childItems().size() - points.size(); |
|
116 | int diff = m_items.childItems().size() - points.size(); | |
116 |
|
117 | |||
117 | if(diff>0) { |
|
118 | if(diff>0) { | |
118 | deletePoints(diff); |
|
119 | deletePoints(diff); | |
119 | } |
|
120 | } | |
120 | else if(diff<0) { |
|
121 | else if(diff<0) { | |
121 | createPoints(-diff); |
|
122 | createPoints(-diff); | |
122 | } |
|
123 | } | |
123 |
|
124 | |||
124 | if(diff!=0) handleUpdated(); |
|
125 | if(diff!=0) handleUpdated(); | |
125 |
|
126 | |||
126 | QList<QGraphicsItem*> items = m_items.childItems(); |
|
127 | QList<QGraphicsItem*> items = m_items.childItems(); | |
127 |
|
128 | |||
128 | for (int i = 0; i < points.size(); i++) { |
|
129 | for (int i = 0; i < points.size(); i++) { | |
129 | Marker* item = static_cast<Marker*>(items.at(i)); |
|
130 | Marker* item = static_cast<Marker*>(items.at(i)); | |
130 | const QPointF& point = points.at(i); |
|
131 | const QPointF& point = points.at(i); | |
131 | const QRectF& rect = item->boundingRect(); |
|
132 | const QRectF& rect = item->boundingRect(); | |
132 | item->setPoint(point); |
|
133 | item->setPoint(point); | |
133 | item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2); |
|
134 | item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2); | |
134 | if(!clipRect().contains(point)) { |
|
135 | if(!clipRect().contains(point)) { | |
135 | item->setVisible(false); |
|
136 | item->setVisible(false); | |
136 | } |
|
137 | } | |
137 | else { |
|
138 | else { | |
138 | item->setVisible(true); |
|
139 | item->setVisible(true); | |
139 | } |
|
140 | } | |
140 | } |
|
141 | } | |
141 |
|
142 | |||
142 | prepareGeometryChange(); |
|
143 | prepareGeometryChange(); | |
143 | m_rect = clipRect(); |
|
144 | m_rect = clipRect(); | |
144 | setPos(origin()); |
|
145 | setPos(origin()); | |
145 | } |
|
146 | } | |
146 |
|
147 | |||
147 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
148 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
148 | { |
|
149 | { | |
149 | Q_UNUSED(painter) |
|
150 | Q_UNUSED(painter) | |
150 | Q_UNUSED(option) |
|
151 | Q_UNUSED(option) | |
151 | Q_UNUSED(widget) |
|
152 | Q_UNUSED(widget) | |
152 | } |
|
153 | } | |
153 |
|
154 | |||
154 | void ScatterChartItem::setPen(const QPen& pen) |
|
155 | void ScatterChartItem::setPen(const QPen& pen) | |
155 | { |
|
156 | { | |
156 | foreach(QGraphicsItem* item , m_items.childItems()) { |
|
157 | foreach(QGraphicsItem* item , m_items.childItems()) { | |
157 | static_cast<Marker*>(item)->setPen(pen); |
|
158 | static_cast<Marker*>(item)->setPen(pen); | |
158 | } |
|
159 | } | |
159 | } |
|
160 | } | |
160 |
|
161 | |||
161 | void ScatterChartItem::setBrush(const QBrush& brush) |
|
162 | void ScatterChartItem::setBrush(const QBrush& brush) | |
162 | { |
|
163 | { | |
163 | foreach(QGraphicsItem* item , m_items.childItems()) { |
|
164 | foreach(QGraphicsItem* item , m_items.childItems()) { | |
164 | static_cast<Marker*>(item)->setBrush(brush); |
|
165 | static_cast<Marker*>(item)->setBrush(brush); | |
165 | } |
|
166 | } | |
166 | } |
|
167 | } | |
167 |
|
168 | |||
168 | void ScatterChartItem::handleUpdated() |
|
169 | void ScatterChartItem::handleUpdated() | |
169 | { |
|
170 | { | |
170 | int count = m_items.childItems().count(); |
|
171 | int count = m_items.childItems().count(); | |
171 |
|
172 | |||
172 | if(count==0) return; |
|
173 | if(count==0) return; | |
173 |
|
174 | |||
174 | bool recreate = m_size != m_series->markerSize() || m_shape != m_series->markerShape(); |
|
175 | bool recreate = m_size != m_series->markerSize() || m_shape != m_series->markerShape(); | |
175 |
|
176 | |||
176 | m_size = m_series->markerSize(); |
|
177 | m_size = m_series->markerSize(); | |
177 | m_shape = m_series->markerShape(); |
|
178 | m_shape = m_series->markerShape(); | |
178 |
|
179 | |||
179 | if(recreate) { |
|
180 | if(recreate) { | |
180 | // TODO: optimize handleUpdate to recreate points only in case shape changed |
|
181 | // TODO: optimize handleUpdate to recreate points only in case shape changed | |
181 | deletePoints(count); |
|
182 | deletePoints(count); | |
182 | createPoints(count); |
|
183 | createPoints(count); | |
183 |
|
184 | |||
184 | // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points |
|
185 | // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points | |
185 | updateGeometry(); |
|
186 | updateGeometry(); | |
186 | } |
|
187 | } | |
187 |
|
188 | |||
188 | setPen(m_series->pen()); |
|
189 | setPen(m_series->pen()); | |
189 | setBrush(m_series->brush()); |
|
190 | setBrush(m_series->brush()); | |
190 | update(); |
|
191 | update(); | |
191 | } |
|
192 | } | |
192 |
|
193 | |||
193 | void ScatterChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
194 | void ScatterChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
194 | { |
|
195 | { | |
195 | emit XYChart::clicked(calculateDomainPoint(event->pos())); |
|
196 | emit XYChart::clicked(calculateDomainPoint(event->pos())); | |
196 | } |
|
197 | } | |
197 |
|
198 | |||
198 | #include "moc_scatterchartitem_p.cpp" |
|
199 | #include "moc_scatterchartitem_p.cpp" | |
199 |
|
200 | |||
200 | QTCOMMERCIALCHART_END_NAMESPACE |
|
201 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,168 +1,171 | |||||
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 "splinechartitem_p.h" |
|
21 | #include "splinechartitem_p.h" | |
22 | #include "qsplineseries_p.h" |
|
22 | #include "qsplineseries_p.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "chartanimator_p.h" |
|
24 | #include "chartanimator_p.h" | |
25 | #include <QPainter> |
|
25 | #include <QPainter> | |
26 | #include <QGraphicsSceneMouseEvent> |
|
26 | #include <QGraphicsSceneMouseEvent> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | SplineChartItem::SplineChartItem(QSplineSeries *series, ChartPresenter *presenter) : |
|
30 | SplineChartItem::SplineChartItem(QSplineSeries *series, ChartPresenter *presenter) : | |
31 | XYChart(series, presenter), |
|
31 | XYChart(series, presenter), | |
32 | QGraphicsItem(presenter ? presenter->rootItem() : 0), |
|
32 | QGraphicsItem(presenter ? presenter->rootItem() : 0), | |
33 | m_series(series), |
|
33 | m_series(series), | |
34 | m_pointsVisible(false), |
|
34 | m_pointsVisible(false), | |
35 | m_animation(0) |
|
35 | m_animation(0) | |
36 | { |
|
36 | { | |
37 | setZValue(ChartPresenter::LineChartZValue); |
|
37 | setZValue(ChartPresenter::LineChartZValue); | |
38 | QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
38 | QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); | |
|
39 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |||
39 | handleUpdated(); |
|
40 | handleUpdated(); | |
40 | } |
|
41 | } | |
41 |
|
42 | |||
42 | QRectF SplineChartItem::boundingRect() const |
|
43 | QRectF SplineChartItem::boundingRect() const | |
43 | { |
|
44 | { | |
44 | return m_rect; |
|
45 | return m_rect; | |
45 | } |
|
46 | } | |
46 |
|
47 | |||
47 | QPainterPath SplineChartItem::shape() const |
|
48 | QPainterPath SplineChartItem::shape() const | |
48 | { |
|
49 | { | |
49 | return m_path; |
|
50 | return m_path; | |
50 | } |
|
51 | } | |
51 |
|
52 | |||
52 | void SplineChartItem::setAnimation(SplineAnimation* animation) |
|
53 | void SplineChartItem::setAnimation(SplineAnimation* animation) | |
53 | { |
|
54 | { | |
54 | m_animation=animation; |
|
55 | m_animation=animation; | |
55 | XYChart::setAnimation(animation); |
|
56 | XYChart::setAnimation(animation); | |
56 | } |
|
57 | } | |
57 |
|
58 | |||
58 | void SplineChartItem::setControlGeometryPoints(QVector<QPointF>& points) |
|
59 | void SplineChartItem::setControlGeometryPoints(QVector<QPointF>& points) | |
59 | { |
|
60 | { | |
60 | m_controlPoints=points; |
|
61 | m_controlPoints=points; | |
61 | } |
|
62 | } | |
62 |
|
63 | |||
63 | QVector<QPointF> SplineChartItem::controlGeometryPoints() const |
|
64 | QVector<QPointF> SplineChartItem::controlGeometryPoints() const | |
64 | { |
|
65 | { | |
65 | return m_controlPoints; |
|
66 | return m_controlPoints; | |
66 | } |
|
67 | } | |
67 |
|
68 | |||
68 | void SplineChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index) |
|
69 | void SplineChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index) | |
69 | { |
|
70 | { | |
70 | QVector<QPointF> controlPoints; |
|
71 | QVector<QPointF> controlPoints; | |
71 |
|
72 | |||
72 | if(newPoints.count()>=2) { |
|
73 | if(newPoints.count()>=2) { | |
73 | controlPoints.resize(newPoints.count()*2-2); |
|
74 | controlPoints.resize(newPoints.count()*2-2); | |
74 | } |
|
75 | } | |
75 |
|
76 | |||
76 | for (int i = 0; i < newPoints.size() - 1; i++) { |
|
77 | for (int i = 0; i < newPoints.size() - 1; i++) { | |
77 | controlPoints[2*i] = calculateGeometryControlPoint(2 * i); |
|
78 | controlPoints[2*i] = calculateGeometryControlPoint(2 * i); | |
78 | controlPoints[2 * i + 1] = calculateGeometryControlPoint(2 * i + 1); |
|
79 | controlPoints[2 * i + 1] = calculateGeometryControlPoint(2 * i + 1); | |
79 | } |
|
80 | } | |
80 |
|
81 | |||
81 | if (controlPoints.count()<2) { |
|
82 | if (controlPoints.count()<2) { | |
82 | setGeometryPoints(newPoints); |
|
83 | setGeometryPoints(newPoints); | |
83 | setControlGeometryPoints(controlPoints); |
|
84 | setControlGeometryPoints(controlPoints); | |
84 | updateGeometry(); |
|
85 | updateGeometry(); | |
85 | return; |
|
86 | return; | |
86 | } |
|
87 | } | |
87 |
|
88 | |||
88 | if (m_animation) { |
|
89 | if (m_animation) { | |
89 | m_animation->setup(oldPoints,newPoints,m_controlPoints,controlPoints,index); |
|
90 | m_animation->setup(oldPoints,newPoints,m_controlPoints,controlPoints,index); | |
90 | setGeometryPoints(newPoints); |
|
91 | setGeometryPoints(newPoints); | |
91 | setDirty(false); |
|
92 | setDirty(false); | |
92 | presenter()->startAnimation(m_animation); |
|
93 | presenter()->startAnimation(m_animation); | |
93 | } |
|
94 | } | |
94 | else { |
|
95 | else { | |
95 | setGeometryPoints(newPoints); |
|
96 | setGeometryPoints(newPoints); | |
96 | setControlGeometryPoints(controlPoints); |
|
97 | setControlGeometryPoints(controlPoints); | |
97 | updateGeometry(); |
|
98 | updateGeometry(); | |
98 | } |
|
99 | } | |
99 | } |
|
100 | } | |
100 |
|
101 | |||
101 | QPointF SplineChartItem::calculateGeometryControlPoint(int index) const |
|
102 | QPointF SplineChartItem::calculateGeometryControlPoint(int index) const | |
102 | { |
|
103 | { | |
103 | return XYChart::calculateGeometryPoint(m_series->d_func()->controlPoint(index)); |
|
104 | return XYChart::calculateGeometryPoint(m_series->d_func()->controlPoint(index)); | |
104 | } |
|
105 | } | |
105 |
|
106 | |||
106 | void SplineChartItem::updateGeometry() |
|
107 | void SplineChartItem::updateGeometry() | |
107 | { |
|
108 | { | |
108 | const QVector<QPointF> &points = geometryPoints(); |
|
109 | const QVector<QPointF> &points = geometryPoints(); | |
109 | const QVector<QPointF> &controlPoints = controlGeometryPoints(); |
|
110 | const QVector<QPointF> &controlPoints = controlGeometryPoints(); | |
110 |
|
111 | |||
111 | if ((points.size()<2) || (controlPoints.size()<2)) { |
|
112 | if ((points.size()<2) || (controlPoints.size()<2)) { | |
112 | prepareGeometryChange(); |
|
113 | prepareGeometryChange(); | |
113 | m_path = QPainterPath(); |
|
114 | m_path = QPainterPath(); | |
114 | m_rect = QRect(); |
|
115 | m_rect = QRect(); | |
115 | return; |
|
116 | return; | |
116 | } |
|
117 | } | |
117 |
|
118 | |||
118 | Q_ASSERT(points.count()*2-2 == controlPoints.count()); |
|
119 | Q_ASSERT(points.count()*2-2 == controlPoints.count()); | |
119 |
|
120 | |||
120 | QPainterPath splinePath(points.at(0)); |
|
121 | QPainterPath splinePath(points.at(0)); | |
121 |
|
122 | |||
122 | for (int i = 0; i < points.size() - 1; i++) { |
|
123 | for (int i = 0; i < points.size() - 1; i++) { | |
123 | const QPointF& point = points.at(i + 1); |
|
124 | const QPointF& point = points.at(i + 1); | |
124 | splinePath.cubicTo(controlPoints[2*i],controlPoints[2 * i + 1],point); |
|
125 | splinePath.cubicTo(controlPoints[2*i],controlPoints[2 * i + 1],point); | |
125 | } |
|
126 | } | |
126 |
|
127 | |||
127 | prepareGeometryChange(); |
|
128 | prepareGeometryChange(); | |
128 | m_path = splinePath; |
|
129 | m_path = splinePath; | |
129 | m_rect = splinePath.boundingRect(); |
|
130 | m_rect = splinePath.boundingRect(); | |
130 | setPos(origin()); |
|
131 | setPos(origin()); | |
131 | } |
|
132 | } | |
132 |
|
133 | |||
133 | //handlers |
|
134 | //handlers | |
134 |
|
135 | |||
135 | void SplineChartItem::handleUpdated() |
|
136 | void SplineChartItem::handleUpdated() | |
136 | { |
|
137 | { | |
137 | m_pointsVisible = m_series->pointsVisible(); |
|
138 | m_pointsVisible = m_series->pointsVisible(); | |
138 | m_linePen = m_series->pen(); |
|
139 | m_linePen = m_series->pen(); | |
139 | m_pointPen = m_series->pen(); |
|
140 | m_pointPen = m_series->pen(); | |
140 | m_pointPen.setWidthF(2*m_pointPen.width()); |
|
141 | m_pointPen.setWidthF(2*m_pointPen.width()); | |
141 | update(); |
|
142 | update(); | |
142 | } |
|
143 | } | |
143 |
|
144 | |||
144 | //painter |
|
145 | //painter | |
145 |
|
146 | |||
146 | void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
147 | void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
147 | { |
|
148 | { | |
148 | Q_UNUSED(widget) |
|
149 | Q_UNUSED(widget) | |
149 | Q_UNUSED(option) |
|
150 | Q_UNUSED(option) | |
150 | painter->save(); |
|
151 | if (m_series->isVisible()) { | |
151 | painter->setClipRect(clipRect()); |
|
152 | painter->save(); | |
152 |
painter->set |
|
153 | painter->setClipRect(clipRect()); | |
153 | painter->drawPath(m_path); |
|
154 | painter->setPen(m_linePen); | |
154 | if (m_pointsVisible) { |
|
155 | painter->drawPath(m_path); | |
155 | painter->setPen(m_pointPen); |
|
156 | if (m_pointsVisible) { | |
156 |
painter-> |
|
157 | painter->setPen(m_pointPen); | |
|
158 | painter->drawPoints(geometryPoints()); | |||
|
159 | } | |||
|
160 | painter->restore(); | |||
157 | } |
|
161 | } | |
158 | painter->restore(); |
|
|||
159 | } |
|
162 | } | |
160 |
|
163 | |||
161 | void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
164 | void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
162 | { |
|
165 | { | |
163 | emit XYChart::clicked(calculateDomainPoint(event->pos())); |
|
166 | emit XYChart::clicked(calculateDomainPoint(event->pos())); | |
164 | } |
|
167 | } | |
165 |
|
168 | |||
166 | #include "moc_splinechartitem_p.cpp" |
|
169 | #include "moc_splinechartitem_p.cpp" | |
167 |
|
170 | |||
168 | QTCOMMERCIALCHART_END_NAMESPACE |
|
171 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,361 +1,361 | |||||
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 "qxyseries.h" |
|
21 | #include "qxyseries.h" | |
22 | #include "qxyseries_p.h" |
|
22 | #include "qxyseries_p.h" | |
23 | #include "domain_p.h" |
|
23 | #include "domain_p.h" | |
24 | #include "legendmarker_p.h" |
|
24 | #include "legendmarker_p.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \class QXYSeries |
|
29 | \class QXYSeries | |
30 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
30 | \brief The QXYSeries class is a base class for line, spline and scatter series. | |
31 | */ |
|
31 | */ | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \property QXYSeries::pointsVisible |
|
34 | \property QXYSeries::pointsVisible | |
35 |
|
35 | |||
36 | Controls if the data points are visible and should be drawn. |
|
36 | Controls if the data points are visible and should be drawn. | |
37 | */ |
|
37 | */ | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \property QXYSeries::count |
|
40 | \property QXYSeries::count | |
41 |
|
41 | |||
42 | Number of points in the series. |
|
42 | Number of points in the series. | |
43 | */ |
|
43 | */ | |
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | \fn QPen QXYSeries::pen() const |
|
46 | \fn QPen QXYSeries::pen() const | |
47 | \brief Returns pen used to draw points for series. |
|
47 | \brief Returns pen used to draw points for series. | |
48 | \sa setPen() |
|
48 | \sa setPen() | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | \fn QBrush QXYSeries::brush() const |
|
52 | \fn QBrush QXYSeries::brush() const | |
53 | \brief Returns brush used to draw points for series. |
|
53 | \brief Returns brush used to draw points for series. | |
54 | \sa setBrush() |
|
54 | \sa setBrush() | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \fn void QXYSeries::clicked(const QPointF& point) |
|
58 | \fn void QXYSeries::clicked(const QPointF& point) | |
59 | \brief Signal is emitted when user clicks the \a point on chart. |
|
59 | \brief Signal is emitted when user clicks the \a point on chart. | |
60 | */ |
|
60 | */ | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | \fn void QXYSeries::pointReplaced(int index) |
|
63 | \fn void QXYSeries::pointReplaced(int index) | |
64 | \brief Signal is emitted when user replaces a point at \a index. |
|
64 | \brief Signal is emitted when user replaces a point at \a index. | |
65 | \sa replace() |
|
65 | \sa replace() | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \fn void QXYSeries::pointAdded(int index) |
|
69 | \fn void QXYSeries::pointAdded(int index) | |
70 | \brief Signal is emitted when user adds a point at \a index. |
|
70 | \brief Signal is emitted when user adds a point at \a index. | |
71 | \sa append(), insert() |
|
71 | \sa append(), insert() | |
72 | */ |
|
72 | */ | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | \fn void QXYSeries::pointRemoved(int index) |
|
75 | \fn void QXYSeries::pointRemoved(int index) | |
76 | \brief Signal is emitted when user removes a point at \a index. |
|
76 | \brief Signal is emitted when user removes a point at \a index. | |
77 | \sa remove() |
|
77 | \sa remove() | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \fn void QXYSeriesPrivate::updated() |
|
81 | \fn void QXYSeriesPrivate::updated() | |
82 | \brief \internal |
|
82 | \brief \internal | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \internal |
|
86 | \internal | |
87 |
|
87 | |||
88 | Constructs empty series object which is a child of \a parent. |
|
88 | Constructs empty series object which is a child of \a parent. | |
89 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
89 | When series object is added to QChartView or QChart instance ownerships is transferred. | |
90 | */ |
|
90 | */ | |
91 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent) |
|
91 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent) | |
92 | { |
|
92 | { | |
93 |
|
||||
94 | } |
|
93 | } | |
|
94 | ||||
95 | /*! |
|
95 | /*! | |
96 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
96 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
97 | and are deleted when mentioned object are destroyed. |
|
97 | and are deleted when mentioned object are destroyed. | |
98 | */ |
|
98 | */ | |
99 | QXYSeries::~QXYSeries() |
|
99 | QXYSeries::~QXYSeries() | |
100 | { |
|
100 | { | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
104 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. | |
105 | */ |
|
105 | */ | |
106 | void QXYSeries::append(qreal x,qreal y) |
|
106 | void QXYSeries::append(qreal x,qreal y) | |
107 | { |
|
107 | { | |
108 | append(QPointF(x,y)); |
|
108 | append(QPointF(x,y)); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | /*! |
|
111 | /*! | |
112 | This is an overloaded function. |
|
112 | This is an overloaded function. | |
113 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
113 | Adds data \a point to the series. Points are connected with lines on the chart. | |
114 | */ |
|
114 | */ | |
115 | void QXYSeries::append(const QPointF &point) |
|
115 | void QXYSeries::append(const QPointF &point) | |
116 | { |
|
116 | { | |
117 | Q_D(QXYSeries); |
|
117 | Q_D(QXYSeries); | |
118 | d->m_points<<point; |
|
118 | d->m_points<<point; | |
119 | // emit d->pointAdded(d->m_points.count()-1); |
|
119 | // emit d->pointAdded(d->m_points.count()-1); | |
120 | emit pointAdded(d->m_points.count()-1); |
|
120 | emit pointAdded(d->m_points.count()-1); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | This is an overloaded function. |
|
124 | This is an overloaded function. | |
125 | Adds list of data \a points to the series. Points are connected with lines on the chart. |
|
125 | Adds list of data \a points to the series. Points are connected with lines on the chart. | |
126 | */ |
|
126 | */ | |
127 | void QXYSeries::append(const QList<QPointF> &points) |
|
127 | void QXYSeries::append(const QList<QPointF> &points) | |
128 | { |
|
128 | { | |
129 | foreach(const QPointF& point , points) { |
|
129 | foreach(const QPointF& point , points) { | |
130 | append(point); |
|
130 | append(point); | |
131 | } |
|
131 | } | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | Replaces data point \a oldX \a oldY with data point \a newX \a newY. |
|
135 | Replaces data point \a oldX \a oldY with data point \a newX \a newY. | |
136 | */ |
|
136 | */ | |
137 | void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY) |
|
137 | void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY) | |
138 | { |
|
138 | { | |
139 | replace(QPointF(oldX,oldY),QPointF(newX,newY)); |
|
139 | replace(QPointF(oldX,oldY),QPointF(newX,newY)); | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | Replaces \a oldPoint with \a newPoint. |
|
143 | Replaces \a oldPoint with \a newPoint. | |
144 | */ |
|
144 | */ | |
145 | void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint) |
|
145 | void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint) | |
146 | { |
|
146 | { | |
147 | Q_D(QXYSeries); |
|
147 | Q_D(QXYSeries); | |
148 | int index = d->m_points.indexOf(oldPoint); |
|
148 | int index = d->m_points.indexOf(oldPoint); | |
149 | if(index==-1) return; |
|
149 | if(index==-1) return; | |
150 | d->m_points[index] = newPoint; |
|
150 | d->m_points[index] = newPoint; | |
151 | // emit d->pointReplaced(index); |
|
151 | // emit d->pointReplaced(index); | |
152 | emit pointReplaced(index); |
|
152 | emit pointReplaced(index); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | Removes current \a x and \a y value. |
|
156 | Removes current \a x and \a y value. | |
157 | */ |
|
157 | */ | |
158 | void QXYSeries::remove(qreal x,qreal y) |
|
158 | void QXYSeries::remove(qreal x,qreal y) | |
159 | { |
|
159 | { | |
160 | remove(QPointF(x,y)); |
|
160 | remove(QPointF(x,y)); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | Removes current \a point x value. |
|
164 | Removes current \a point x value. | |
165 |
|
165 | |||
166 | Note: point y value is ignored. |
|
166 | Note: point y value is ignored. | |
167 | */ |
|
167 | */ | |
168 | void QXYSeries::remove(const QPointF &point) |
|
168 | void QXYSeries::remove(const QPointF &point) | |
169 | { |
|
169 | { | |
170 | Q_D(QXYSeries); |
|
170 | Q_D(QXYSeries); | |
171 | int index = d->m_points.indexOf(point); |
|
171 | int index = d->m_points.indexOf(point); | |
172 | if(index==-1) return; |
|
172 | if(index==-1) return; | |
173 | d->m_points.remove(index); |
|
173 | d->m_points.remove(index); | |
174 | // emit d->pointRemoved(index); |
|
174 | // emit d->pointRemoved(index); | |
175 | emit pointRemoved(index); |
|
175 | emit pointRemoved(index); | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | /*! |
|
178 | /*! | |
179 | Removes all data points from the series. |
|
179 | Removes all data points from the series. | |
180 | */ |
|
180 | */ | |
181 | void QXYSeries::removeAll() |
|
181 | void QXYSeries::removeAll() | |
182 | { |
|
182 | { | |
183 | Q_D(QXYSeries); |
|
183 | Q_D(QXYSeries); | |
184 | foreach(const QPointF& point, d->m_points) { |
|
184 | foreach(const QPointF& point, d->m_points) { | |
185 | remove(point); |
|
185 | remove(point); | |
186 | } |
|
186 | } | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | /*! |
|
189 | /*! | |
190 | Inserts a \a point in the series at \a index position. |
|
190 | Inserts a \a point in the series at \a index position. | |
191 | */ |
|
191 | */ | |
192 | void QXYSeries::insert(int index, const QPointF &point) |
|
192 | void QXYSeries::insert(int index, const QPointF &point) | |
193 | { |
|
193 | { | |
194 | Q_D(QXYSeries); |
|
194 | Q_D(QXYSeries); | |
195 | d->m_points.insert(index, point); |
|
195 | d->m_points.insert(index, point); | |
196 | // emit d->pointAdded(index); |
|
196 | // emit d->pointAdded(index); | |
197 | emit pointAdded(index); |
|
197 | emit pointAdded(index); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Removes all points from the series. |
|
201 | Removes all points from the series. | |
202 | */ |
|
202 | */ | |
203 | void QXYSeries::clear() |
|
203 | void QXYSeries::clear() | |
204 | { |
|
204 | { | |
205 | Q_D(QXYSeries); |
|
205 | Q_D(QXYSeries); | |
206 | for (int i = d->m_points.size() - 1; i >= 0; i--) |
|
206 | for (int i = d->m_points.size() - 1; i >= 0; i--) | |
207 | remove(d->m_points.at(i)); |
|
207 | remove(d->m_points.at(i)); | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | \internal \a pos |
|
211 | \internal \a pos | |
212 | */ |
|
212 | */ | |
213 | QList<QPointF> QXYSeries::points() const |
|
213 | QList<QPointF> QXYSeries::points() const | |
214 | { |
|
214 | { | |
215 | Q_D(const QXYSeries); |
|
215 | Q_D(const QXYSeries); | |
216 | return d->m_points.toList(); |
|
216 | return d->m_points.toList(); | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | Returns number of data points within series. |
|
220 | Returns number of data points within series. | |
221 | */ |
|
221 | */ | |
222 | int QXYSeries::count() const |
|
222 | int QXYSeries::count() const | |
223 | { |
|
223 | { | |
224 | Q_D(const QXYSeries); |
|
224 | Q_D(const QXYSeries); | |
225 | return d->m_points.count(); |
|
225 | return d->m_points.count(); | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 |
|
228 | |||
229 | /*! |
|
229 | /*! | |
230 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
230 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the | |
231 | pen from chart theme is used. |
|
231 | pen from chart theme is used. | |
232 | \sa QChart::setTheme() |
|
232 | \sa QChart::setTheme() | |
233 | */ |
|
233 | */ | |
234 | void QXYSeries::setPen(const QPen &pen) |
|
234 | void QXYSeries::setPen(const QPen &pen) | |
235 | { |
|
235 | { | |
236 | Q_D(QXYSeries); |
|
236 | Q_D(QXYSeries); | |
237 | if (d->m_pen!=pen) { |
|
237 | if (d->m_pen!=pen) { | |
238 | d->m_pen = pen; |
|
238 | d->m_pen = pen; | |
239 | emit d->updated(); |
|
239 | emit d->updated(); | |
240 | } |
|
240 | } | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | QPen QXYSeries::pen() const |
|
243 | QPen QXYSeries::pen() const | |
244 | { |
|
244 | { | |
245 | Q_D(const QXYSeries); |
|
245 | Q_D(const QXYSeries); | |
246 | return d->m_pen; |
|
246 | return d->m_pen; | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | /*! |
|
249 | /*! | |
250 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
250 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush | |
251 | from chart theme setting is used. |
|
251 | from chart theme setting is used. | |
252 | \sa QChart::setTheme() |
|
252 | \sa QChart::setTheme() | |
253 | */ |
|
253 | */ | |
254 | void QXYSeries::setBrush(const QBrush &brush) |
|
254 | void QXYSeries::setBrush(const QBrush &brush) | |
255 | { |
|
255 | { | |
256 | Q_D(QXYSeries); |
|
256 | Q_D(QXYSeries); | |
257 | if (d->m_brush!=brush) { |
|
257 | if (d->m_brush!=brush) { | |
258 | d->m_brush = brush; |
|
258 | d->m_brush = brush; | |
259 | emit d->updated(); |
|
259 | emit d->updated(); | |
260 | } |
|
260 | } | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | QBrush QXYSeries::brush() const |
|
263 | QBrush QXYSeries::brush() const | |
264 | { |
|
264 | { | |
265 | Q_D(const QXYSeries); |
|
265 | Q_D(const QXYSeries); | |
266 | return d->m_brush; |
|
266 | return d->m_brush; | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 |
|
269 | |||
270 | void QXYSeries::setPointsVisible(bool visible) |
|
270 | void QXYSeries::setPointsVisible(bool visible) | |
271 | { |
|
271 | { | |
272 | Q_D(QXYSeries); |
|
272 | Q_D(QXYSeries); | |
273 | if (d->m_pointsVisible != visible){ |
|
273 | if (d->m_pointsVisible != visible){ | |
274 | d->m_pointsVisible = visible; |
|
274 | d->m_pointsVisible = visible; | |
275 | emit d->updated(); |
|
275 | emit d->updated(); | |
276 | } |
|
276 | } | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | bool QXYSeries::pointsVisible() const |
|
279 | bool QXYSeries::pointsVisible() const | |
280 | { |
|
280 | { | |
281 | Q_D(const QXYSeries); |
|
281 | Q_D(const QXYSeries); | |
282 | return d->m_pointsVisible; |
|
282 | return d->m_pointsVisible; | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 |
|
285 | |||
286 | /*! |
|
286 | /*! | |
287 | Stream operator for adding a data \a point to the series. |
|
287 | Stream operator for adding a data \a point to the series. | |
288 | \sa append() |
|
288 | \sa append() | |
289 | */ |
|
289 | */ | |
290 | QXYSeries& QXYSeries::operator<< (const QPointF &point) |
|
290 | QXYSeries& QXYSeries::operator<< (const QPointF &point) | |
291 | { |
|
291 | { | |
292 | append(point); |
|
292 | append(point); | |
293 | return *this; |
|
293 | return *this; | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 |
|
296 | |||
297 | /*! |
|
297 | /*! | |
298 | Stream operator for adding a list of \a points to the series. |
|
298 | Stream operator for adding a list of \a points to the series. | |
299 | \sa append() |
|
299 | \sa append() | |
300 | */ |
|
300 | */ | |
301 |
|
301 | |||
302 | QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points) |
|
302 | QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points) | |
303 | { |
|
303 | { | |
304 | append(points); |
|
304 | append(points); | |
305 | return *this; |
|
305 | return *this; | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
308 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
309 |
|
309 | |||
310 |
|
310 | |||
311 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : |
|
311 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : | |
312 | QAbstractSeriesPrivate(q), |
|
312 | QAbstractSeriesPrivate(q), | |
313 | m_pointsVisible(false) |
|
313 | m_pointsVisible(false) | |
314 | { |
|
314 | { | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | void QXYSeriesPrivate::scaleDomain(Domain& domain) |
|
317 | void QXYSeriesPrivate::scaleDomain(Domain& domain) | |
318 | { |
|
318 | { | |
319 | qreal minX(domain.minX()); |
|
319 | qreal minX(domain.minX()); | |
320 | qreal minY(domain.minY()); |
|
320 | qreal minY(domain.minY()); | |
321 | qreal maxX(domain.maxX()); |
|
321 | qreal maxX(domain.maxX()); | |
322 | qreal maxY(domain.maxY()); |
|
322 | qreal maxY(domain.maxY()); | |
323 | int tickXCount(domain.tickXCount()); |
|
323 | int tickXCount(domain.tickXCount()); | |
324 | int tickYCount(domain.tickYCount()); |
|
324 | int tickYCount(domain.tickYCount()); | |
325 |
|
325 | |||
326 | Q_Q(QXYSeries); |
|
326 | Q_Q(QXYSeries); | |
327 |
|
327 | |||
328 | const QList<QPointF>& points = q->points(); |
|
328 | const QList<QPointF>& points = q->points(); | |
329 |
|
329 | |||
330 |
|
330 | |||
331 | if(points.isEmpty()){ |
|
331 | if(points.isEmpty()){ | |
332 | minX=0.0; |
|
332 | minX=0.0; | |
333 | minY=0.0; |
|
333 | minY=0.0; | |
334 | maxX=1.0; |
|
334 | maxX=1.0; | |
335 | maxY=1.0; |
|
335 | maxY=1.0; | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | for (int i = 0; i < points.count(); i++) |
|
338 | for (int i = 0; i < points.count(); i++) | |
339 | { |
|
339 | { | |
340 | qreal x = points[i].x(); |
|
340 | qreal x = points[i].x(); | |
341 | qreal y = points[i].y(); |
|
341 | qreal y = points[i].y(); | |
342 | minX = qMin(minX, x); |
|
342 | minX = qMin(minX, x); | |
343 | minY = qMin(minY, y); |
|
343 | minY = qMin(minY, y); | |
344 | maxX = qMax(maxX, x); |
|
344 | maxX = qMax(maxX, x); | |
345 | maxY = qMax(maxY, y); |
|
345 | maxY = qMax(maxY, y); | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
348 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) |
|
351 | QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) | |
352 | { |
|
352 | { | |
353 | Q_Q(QXYSeries); |
|
353 | Q_Q(QXYSeries); | |
354 | QList<LegendMarker*> list; |
|
354 | QList<LegendMarker*> list; | |
355 | return list << new XYLegendMarker(q,legend); |
|
355 | return list << new XYLegendMarker(q,legend); | |
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 | #include "moc_qxyseries.cpp" |
|
358 | #include "moc_qxyseries.cpp" | |
359 | #include "moc_qxyseries_p.cpp" |
|
359 | #include "moc_qxyseries_p.cpp" | |
360 |
|
360 | |||
361 | QTCOMMERCIALCHART_END_NAMESPACE |
|
361 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,410 +1,409 | |||||
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 <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qbarset.h> |
|
22 | #include <qbarset.h> | |
23 | #include <qgroupedbarseries.h> |
|
23 | #include <qgroupedbarseries.h> | |
24 | #include <qchartview.h> |
|
24 | #include <qchartview.h> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | QTCOMMERCIALCHART_USE_NAMESPACE | |
27 |
|
27 | |||
28 | class tst_QBarSet : public QObject |
|
28 | class tst_QBarSet : public QObject | |
29 | { |
|
29 | { | |
30 | Q_OBJECT |
|
30 | Q_OBJECT | |
31 |
|
31 | |||
32 | public slots: |
|
32 | public slots: | |
33 | void initTestCase(); |
|
33 | void initTestCase(); | |
34 | void cleanupTestCase(); |
|
34 | void cleanupTestCase(); | |
35 | void init(); |
|
35 | void init(); | |
36 | void cleanup(); |
|
36 | void cleanup(); | |
37 |
|
37 | |||
38 | private slots: |
|
38 | private slots: | |
39 | void qbarset_data(); |
|
39 | void qbarset_data(); | |
40 | void qbarset(); |
|
40 | void qbarset(); | |
41 | void name_data(); |
|
41 | void name_data(); | |
42 | void name(); |
|
42 | void name(); | |
43 | void append_data(); |
|
43 | void append_data(); | |
44 | void append(); |
|
44 | void append(); | |
45 | void appendOperator_data(); |
|
45 | void appendOperator_data(); | |
46 | void appendOperator(); |
|
46 | void appendOperator(); | |
47 | void insert_data(); |
|
47 | void insert_data(); | |
48 | void insert(); |
|
48 | void insert(); | |
49 | void remove_data(); |
|
49 | void remove_data(); | |
50 | void remove(); |
|
50 | void remove(); | |
51 | void replace_data(); |
|
51 | void replace_data(); | |
52 | void replace(); |
|
52 | void replace(); | |
53 | void at_data(); |
|
53 | void at_data(); | |
54 | void at(); |
|
54 | void at(); | |
55 | void atOperator_data(); |
|
55 | void atOperator_data(); | |
56 | void atOperator(); |
|
56 | void atOperator(); | |
57 | void count_data(); |
|
57 | void count_data(); | |
58 | void count(); |
|
58 | void count(); | |
59 | void sum_data(); |
|
59 | void sum_data(); | |
60 | void sum(); |
|
60 | void sum(); | |
61 | void customize(); |
|
61 | void customize(); | |
62 |
|
62 | |||
63 | private: |
|
63 | private: | |
64 | QBarSet* m_barset; |
|
64 | QBarSet* m_barset; | |
65 | }; |
|
65 | }; | |
66 |
|
66 | |||
67 | void tst_QBarSet::initTestCase() |
|
67 | void tst_QBarSet::initTestCase() | |
68 | { |
|
68 | { | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void tst_QBarSet::cleanupTestCase() |
|
71 | void tst_QBarSet::cleanupTestCase() | |
72 | { |
|
72 | { | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void tst_QBarSet::init() |
|
75 | void tst_QBarSet::init() | |
76 | { |
|
76 | { | |
77 | m_barset = new QBarSet(QString("Name")); |
|
77 | m_barset = new QBarSet(QString("Name")); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void tst_QBarSet::cleanup() |
|
80 | void tst_QBarSet::cleanup() | |
81 | { |
|
81 | { | |
82 | delete m_barset; |
|
82 | delete m_barset; | |
83 | m_barset = 0; |
|
83 | m_barset = 0; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | void tst_QBarSet::qbarset_data() |
|
86 | void tst_QBarSet::qbarset_data() | |
87 | { |
|
87 | { | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void tst_QBarSet::qbarset() |
|
90 | void tst_QBarSet::qbarset() | |
91 | { |
|
91 | { | |
92 | QBarSet barset(QString("Name")); |
|
92 | QBarSet barset(QString("Name")); | |
93 | QCOMPARE(barset.name(), QString("Name")); |
|
93 | QCOMPARE(barset.name(), QString("Name")); | |
94 | QCOMPARE(barset.count(), 0); |
|
94 | QCOMPARE(barset.count(), 0); | |
95 | QVERIFY(qFuzzyIsNull(barset.sum())); |
|
95 | QVERIFY(qFuzzyIsNull(barset.sum())); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void tst_QBarSet::name_data() |
|
98 | void tst_QBarSet::name_data() | |
99 | { |
|
99 | { | |
100 | QTest::addColumn<QString> ("name"); |
|
100 | QTest::addColumn<QString> ("name"); | |
101 | QTest::addColumn<QString> ("result"); |
|
101 | QTest::addColumn<QString> ("result"); | |
102 | QTest::newRow("name0") << QString("name0") << QString("name0"); |
|
102 | QTest::newRow("name0") << QString("name0") << QString("name0"); | |
103 | QTest::newRow("name1") << QString("name1") << QString("name1"); |
|
103 | QTest::newRow("name1") << QString("name1") << QString("name1"); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | void tst_QBarSet::name() |
|
106 | void tst_QBarSet::name() | |
107 | { |
|
107 | { | |
108 | QFETCH(QString, name); |
|
108 | QFETCH(QString, name); | |
109 | QFETCH(QString, result); |
|
109 | QFETCH(QString, result); | |
110 |
|
110 | |||
111 | m_barset->setName(name); |
|
111 | m_barset->setName(name); | |
112 | QCOMPARE(m_barset->name(), result); |
|
112 | QCOMPARE(m_barset->name(), result); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | void tst_QBarSet::append_data() |
|
115 | void tst_QBarSet::append_data() | |
116 | { |
|
116 | { | |
117 | QTest::addColumn<int> ("count"); |
|
117 | QTest::addColumn<int> ("count"); | |
118 | QTest::newRow("0") << 0; |
|
118 | QTest::newRow("0") << 0; | |
119 | QTest::newRow("5") << 5; |
|
119 | QTest::newRow("5") << 5; | |
120 | QTest::newRow("100") << 100; |
|
120 | QTest::newRow("100") << 100; | |
121 | QTest::newRow("1000") << 1000; |
|
121 | QTest::newRow("1000") << 1000; | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | void tst_QBarSet::append() |
|
124 | void tst_QBarSet::append() | |
125 | { |
|
125 | { | |
126 | QFETCH(int, count); |
|
126 | QFETCH(int, count); | |
127 |
|
127 | |||
128 | QCOMPARE(m_barset->count(), 0); |
|
128 | QCOMPARE(m_barset->count(), 0); | |
129 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
129 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
130 |
|
130 | |||
131 | qreal sum(0.0); |
|
131 | qreal sum(0.0); | |
132 | qreal value(0.0); |
|
132 | qreal value(0.0); | |
133 |
|
133 | |||
134 | for (int i=0; i<count; i++) { |
|
134 | for (int i=0; i<count; i++) { | |
135 | m_barset->append(value); |
|
135 | m_barset->append(value); | |
136 | QCOMPARE(m_barset->at(i).y(), value); |
|
136 | QCOMPARE(m_barset->at(i).y(), value); | |
137 | sum += value; |
|
137 | sum += value; | |
138 | value += 1.0; |
|
138 | value += 1.0; | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | QCOMPARE(m_barset->count(), count); |
|
141 | QCOMPARE(m_barset->count(), count); | |
142 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); |
|
142 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | void tst_QBarSet::appendOperator_data() |
|
145 | void tst_QBarSet::appendOperator_data() | |
146 | { |
|
146 | { | |
147 | append_data(); |
|
147 | append_data(); | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | void tst_QBarSet::appendOperator() |
|
150 | void tst_QBarSet::appendOperator() | |
151 | { |
|
151 | { | |
152 | QFETCH(int, count); |
|
152 | QFETCH(int, count); | |
153 |
|
153 | |||
154 | QCOMPARE(m_barset->count(), 0); |
|
154 | QCOMPARE(m_barset->count(), 0); | |
155 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
155 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
156 |
|
156 | |||
157 | qreal sum(0.0); |
|
157 | qreal sum(0.0); | |
158 | qreal value(0.0); |
|
158 | qreal value(0.0); | |
159 |
|
159 | |||
160 | for (int i=0; i<count; i++) { |
|
160 | for (int i=0; i<count; i++) { | |
161 | *m_barset << value; |
|
161 | *m_barset << value; | |
162 | QCOMPARE(m_barset->at(i).y(), value); |
|
162 | QCOMPARE(m_barset->at(i).y(), value); | |
163 | sum += value; |
|
163 | sum += value; | |
164 | value += 1.0; |
|
164 | value += 1.0; | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | QCOMPARE(m_barset->count(), count); |
|
167 | QCOMPARE(m_barset->count(), count); | |
168 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); |
|
168 | QVERIFY(qFuzzyCompare(m_barset->sum(), sum)); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | void tst_QBarSet::insert_data() |
|
171 | void tst_QBarSet::insert_data() | |
172 | { |
|
172 | { | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | void tst_QBarSet::insert() |
|
175 | void tst_QBarSet::insert() | |
176 | { |
|
176 | { | |
177 | QCOMPARE(m_barset->count(), 0); |
|
177 | QCOMPARE(m_barset->count(), 0); | |
178 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
178 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
179 |
|
179 | |||
180 | m_barset->insert(0, 1.0); // 1.0 |
|
180 | m_barset->insert(0, 1.0); // 1.0 | |
181 | QCOMPARE(m_barset->at(0).y(), 1.0); |
|
181 | QCOMPARE(m_barset->at(0).y(), 1.0); | |
182 | QCOMPARE(m_barset->count(), 1); |
|
182 | QCOMPARE(m_barset->count(), 1); | |
183 | QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0)); |
|
183 | QVERIFY(qFuzzyCompare(m_barset->sum(), 1.0)); | |
184 |
|
184 | |||
185 | m_barset->insert(0, 2.0); // 2.0 1.0 |
|
185 | m_barset->insert(0, 2.0); // 2.0 1.0 | |
186 | QCOMPARE(m_barset->at(0).y(), 2.0); |
|
186 | QCOMPARE(m_barset->at(0).y(), 2.0); | |
187 | QCOMPARE(m_barset->at(1).y(), 1.0); |
|
187 | QCOMPARE(m_barset->at(1).y(), 1.0); | |
188 | QCOMPARE(m_barset->count(), 2); |
|
188 | QCOMPARE(m_barset->count(), 2); | |
189 | QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0)); |
|
189 | QVERIFY(qFuzzyCompare(m_barset->sum(), 3.0)); | |
190 |
|
190 | |||
191 | m_barset->insert(1, 3.0); // 2.0 3.0 1.0 |
|
191 | m_barset->insert(1, 3.0); // 2.0 3.0 1.0 | |
192 | QCOMPARE(m_barset->at(1).y(), 3.0); |
|
192 | QCOMPARE(m_barset->at(1).y(), 3.0); | |
193 | QCOMPARE(m_barset->at(0).y(), 2.0); |
|
193 | QCOMPARE(m_barset->at(0).y(), 2.0); | |
194 | QCOMPARE(m_barset->at(2).y(), 1.0); |
|
194 | QCOMPARE(m_barset->at(2).y(), 1.0); | |
195 | QCOMPARE(m_barset->count(), 3); |
|
195 | QCOMPARE(m_barset->count(), 3); | |
196 | QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0)); |
|
196 | QVERIFY(qFuzzyCompare(m_barset->sum(), 6.0)); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | void tst_QBarSet::remove_data() |
|
199 | void tst_QBarSet::remove_data() | |
200 | { |
|
200 | { | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | void tst_QBarSet::remove() |
|
203 | void tst_QBarSet::remove() | |
204 | { |
|
204 | { | |
205 | QCOMPARE(m_barset->count(), 0); |
|
205 | QCOMPARE(m_barset->count(), 0); | |
206 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
206 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
207 |
|
207 | |||
208 | m_barset->append(1.0); |
|
208 | m_barset->append(1.0); | |
209 | m_barset->append(2.0); |
|
209 | m_barset->append(2.0); | |
210 | m_barset->append(3.0); |
|
210 | m_barset->append(3.0); | |
211 | m_barset->append(4.0); |
|
211 | m_barset->append(4.0); | |
212 |
|
212 | |||
213 | QCOMPARE(m_barset->count(), 4); |
|
213 | QCOMPARE(m_barset->count(), 4); | |
214 | QCOMPARE(m_barset->sum(), 10.0); |
|
214 | QCOMPARE(m_barset->sum(), 10.0); | |
215 |
|
215 | |||
216 | m_barset->remove(2); // 1.0 2.0 4.0 |
|
216 | m_barset->remove(2); // 1.0 2.0 4.0 | |
217 | QCOMPARE(m_barset->at(0).y(), 1.0); |
|
217 | QCOMPARE(m_barset->at(0).y(), 1.0); | |
218 | QCOMPARE(m_barset->at(1).y(), 2.0); |
|
218 | QCOMPARE(m_barset->at(1).y(), 2.0); | |
219 | QCOMPARE(m_barset->at(2).y(), 4.0); |
|
219 | QCOMPARE(m_barset->at(2).y(), 4.0); | |
220 | QCOMPARE(m_barset->count(), 3); |
|
220 | QCOMPARE(m_barset->count(), 3); | |
221 | QCOMPARE(m_barset->sum(), 7.0); |
|
221 | QCOMPARE(m_barset->sum(), 7.0); | |
222 |
|
222 | |||
223 | m_barset->remove(0); // 2.0 4.0 |
|
223 | m_barset->remove(0); // 2.0 4.0 | |
224 | QCOMPARE(m_barset->at(0).y(), 2.0); |
|
224 | QCOMPARE(m_barset->at(0).y(), 2.0); | |
225 | QCOMPARE(m_barset->at(1).y(), 4.0); |
|
225 | QCOMPARE(m_barset->at(1).y(), 4.0); | |
226 | QCOMPARE(m_barset->count(), 2); |
|
226 | QCOMPARE(m_barset->count(), 2); | |
227 | QCOMPARE(m_barset->sum(), 6.0); |
|
227 | QCOMPARE(m_barset->sum(), 6.0); | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | void tst_QBarSet::replace_data() |
|
230 | void tst_QBarSet::replace_data() | |
231 | { |
|
231 | { | |
232 |
|
232 | |||
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | void tst_QBarSet::replace() |
|
235 | void tst_QBarSet::replace() | |
236 | { |
|
236 | { | |
237 | QCOMPARE(m_barset->count(), 0); |
|
237 | QCOMPARE(m_barset->count(), 0); | |
238 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
238 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
239 |
|
239 | |||
240 | m_barset->append(1.0); |
|
240 | m_barset->append(1.0); | |
241 | m_barset->append(2.0); |
|
241 | m_barset->append(2.0); | |
242 | m_barset->append(3.0); |
|
242 | m_barset->append(3.0); | |
243 | m_barset->append(4.0); |
|
243 | m_barset->append(4.0); | |
244 |
|
244 | |||
245 | QCOMPARE(m_barset->count(), 4); |
|
245 | QCOMPARE(m_barset->count(), 4); | |
246 | QCOMPARE(m_barset->sum(), 10.0); |
|
246 | QCOMPARE(m_barset->sum(), 10.0); | |
247 |
|
247 | |||
248 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 |
|
248 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 | |
249 | QCOMPARE(m_barset->count(), 4); |
|
249 | QCOMPARE(m_barset->count(), 4); | |
250 | QCOMPARE(m_barset->sum(), 14.0); |
|
250 | QCOMPARE(m_barset->sum(), 14.0); | |
251 | QCOMPARE(m_barset->at(0).y(), 5.0); |
|
251 | QCOMPARE(m_barset->at(0).y(), 5.0); | |
252 |
|
252 | |||
253 | m_barset->replace(3, 6.0); |
|
253 | m_barset->replace(3, 6.0); | |
254 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
254 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
255 | QCOMPARE(m_barset->sum(), 16.0); |
|
255 | QCOMPARE(m_barset->sum(), 16.0); | |
256 | QCOMPARE(m_barset->at(0).y(), 5.0); |
|
256 | QCOMPARE(m_barset->at(0).y(), 5.0); | |
257 | QCOMPARE(m_barset->at(1).y(), 2.0); |
|
257 | QCOMPARE(m_barset->at(1).y(), 2.0); | |
258 | QCOMPARE(m_barset->at(2).y(), 3.0); |
|
258 | QCOMPARE(m_barset->at(2).y(), 3.0); | |
259 | QCOMPARE(m_barset->at(3).y(), 6.0); |
|
259 | QCOMPARE(m_barset->at(3).y(), 6.0); | |
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | void tst_QBarSet::at_data() |
|
262 | void tst_QBarSet::at_data() | |
263 | { |
|
263 | { | |
264 |
|
264 | |||
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | void tst_QBarSet::at() |
|
267 | void tst_QBarSet::at() | |
268 | { |
|
268 | { | |
269 | QCOMPARE(m_barset->count(), 0); |
|
269 | QCOMPARE(m_barset->count(), 0); | |
270 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
270 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
271 |
|
271 | |||
272 | m_barset->append(1.0); |
|
272 | m_barset->append(1.0); | |
273 | m_barset->append(2.0); |
|
273 | m_barset->append(2.0); | |
274 | m_barset->append(3.0); |
|
274 | m_barset->append(3.0); | |
275 | m_barset->append(4.0); |
|
275 | m_barset->append(4.0); | |
276 |
|
276 | |||
277 | QCOMPARE(m_barset->at(0).y(), 1.0); |
|
277 | QCOMPARE(m_barset->at(0).y(), 1.0); | |
278 | QCOMPARE(m_barset->at(1).y(), 2.0); |
|
278 | QCOMPARE(m_barset->at(1).y(), 2.0); | |
279 | QCOMPARE(m_barset->at(2).y(), 3.0); |
|
279 | QCOMPARE(m_barset->at(2).y(), 3.0); | |
280 | QCOMPARE(m_barset->at(3).y(), 4.0); |
|
280 | QCOMPARE(m_barset->at(3).y(), 4.0); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | void tst_QBarSet::atOperator_data() |
|
283 | void tst_QBarSet::atOperator_data() | |
284 | { |
|
284 | { | |
285 |
|
285 | |||
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | void tst_QBarSet::atOperator() |
|
288 | void tst_QBarSet::atOperator() | |
289 | { |
|
289 | { | |
290 | QCOMPARE(m_barset->count(), 0); |
|
290 | QCOMPARE(m_barset->count(), 0); | |
291 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
291 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
292 |
|
292 | |||
293 | m_barset->append(1.0); |
|
293 | m_barset->append(1.0); | |
294 | m_barset->append(2.0); |
|
294 | m_barset->append(2.0); | |
295 | m_barset->append(3.0); |
|
295 | m_barset->append(3.0); | |
296 | m_barset->append(4.0); |
|
296 | m_barset->append(4.0); | |
297 |
|
297 | |||
298 | QCOMPARE(m_barset->operator [](0).y(), 1.0); |
|
298 | QCOMPARE(m_barset->operator [](0).y(), 1.0); | |
299 | QCOMPARE(m_barset->operator [](1).y(), 2.0); |
|
299 | QCOMPARE(m_barset->operator [](1).y(), 2.0); | |
300 | QCOMPARE(m_barset->operator [](2).y(), 3.0); |
|
300 | QCOMPARE(m_barset->operator [](2).y(), 3.0); | |
301 | QCOMPARE(m_barset->operator [](3).y(), 4.0); |
|
301 | QCOMPARE(m_barset->operator [](3).y(), 4.0); | |
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | void tst_QBarSet::count_data() |
|
304 | void tst_QBarSet::count_data() | |
305 | { |
|
305 | { | |
306 |
|
306 | |||
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | void tst_QBarSet::count() |
|
309 | void tst_QBarSet::count() | |
310 | { |
|
310 | { | |
311 | QCOMPARE(m_barset->count(), 0); |
|
311 | QCOMPARE(m_barset->count(), 0); | |
312 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
312 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
313 |
|
313 | |||
314 | m_barset->append(1.0); |
|
314 | m_barset->append(1.0); | |
315 | QCOMPARE(m_barset->count(),1); |
|
315 | QCOMPARE(m_barset->count(),1); | |
316 | m_barset->append(2.0); |
|
316 | m_barset->append(2.0); | |
317 | QCOMPARE(m_barset->count(),2); |
|
317 | QCOMPARE(m_barset->count(),2); | |
318 | m_barset->append(3.0); |
|
318 | m_barset->append(3.0); | |
319 | QCOMPARE(m_barset->count(),3); |
|
319 | QCOMPARE(m_barset->count(),3); | |
320 | m_barset->append(4.0); |
|
320 | m_barset->append(4.0); | |
321 | QCOMPARE(m_barset->count(),4); |
|
321 | QCOMPARE(m_barset->count(),4); | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | void tst_QBarSet::sum_data() |
|
324 | void tst_QBarSet::sum_data() | |
325 | { |
|
325 | { | |
326 |
|
326 | |||
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | void tst_QBarSet::sum() |
|
329 | void tst_QBarSet::sum() | |
330 | { |
|
330 | { | |
331 | QCOMPARE(m_barset->count(), 0); |
|
331 | QCOMPARE(m_barset->count(), 0); | |
332 | QVERIFY(qFuzzyIsNull(m_barset->sum())); |
|
332 | QVERIFY(qFuzzyIsNull(m_barset->sum())); | |
333 |
|
333 | |||
334 | m_barset->append(1.0); |
|
334 | m_barset->append(1.0); | |
335 | QVERIFY(qFuzzyCompare(m_barset->sum(),1.0)); |
|
335 | QVERIFY(qFuzzyCompare(m_barset->sum(),1.0)); | |
336 | m_barset->append(2.0); |
|
336 | m_barset->append(2.0); | |
337 | QVERIFY(qFuzzyCompare(m_barset->sum(),3.0)); |
|
337 | QVERIFY(qFuzzyCompare(m_barset->sum(),3.0)); | |
338 | m_barset->append(3.0); |
|
338 | m_barset->append(3.0); | |
339 | QVERIFY(qFuzzyCompare(m_barset->sum(),6.0)); |
|
339 | QVERIFY(qFuzzyCompare(m_barset->sum(),6.0)); | |
340 | m_barset->append(4.0); |
|
340 | m_barset->append(4.0); | |
341 | QVERIFY(qFuzzyCompare(m_barset->sum(),10.0)); |
|
341 | QVERIFY(qFuzzyCompare(m_barset->sum(),10.0)); | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 | void tst_QBarSet::customize() |
|
344 | void tst_QBarSet::customize() | |
345 | { |
|
345 | { | |
346 | // Create sets |
|
346 | // Create sets | |
347 | QBarSet *set1 = new QBarSet("set1"); |
|
347 | QBarSet *set1 = new QBarSet("set1"); | |
348 | QBarSet *set2 = new QBarSet("set2"); |
|
348 | QBarSet *set2 = new QBarSet("set2"); | |
349 |
|
349 | |||
350 | // Append set1 to series |
|
350 | // Append set1 to series | |
351 | QGroupedBarSeries *series = new QGroupedBarSeries(); |
|
351 | QGroupedBarSeries *series = new QGroupedBarSeries(); | |
352 | bool success = series->append(set1); |
|
352 | bool success = series->append(set1); | |
353 | QVERIFY(success); |
|
353 | QVERIFY(success); | |
354 |
|
354 | |||
355 | // Add series to the chart |
|
355 | // Add series to the chart | |
356 | QChartView view(new QChart()); |
|
356 | QChartView view(new QChart()); | |
357 | view.resize(200, 200); |
|
357 | view.resize(200, 200); | |
358 | view.chart()->addSeries(series); |
|
358 | view.chart()->addSeries(series); | |
359 | view.show(); |
|
359 | view.show(); | |
360 | QTest::qWaitForWindowShown(&view); |
|
360 | QTest::qWaitForWindowShown(&view); | |
361 |
|
361 | |||
362 | // Test adding data to the sets |
|
362 | // Test adding data to the sets | |
363 | *set1 << 1 << 2 << 1 << 3; |
|
363 | *set1 << 1 << 2 << 1 << 3; | |
364 | *set2 << 2 << 1 << 3 << 1; |
|
364 | *set2 << 2 << 1 << 3 << 1; | |
365 |
|
365 | |||
366 | // Test pen |
|
366 | // Test pen | |
367 | QVERIFY(set1->pen() != QPen()); |
|
367 | QVERIFY(set1->pen() != QPen()); | |
368 | QVERIFY(set2->pen() == QPen()); |
|
368 | QVERIFY(set2->pen() == QPen()); | |
369 | QPen pen(QColor(128,128,128,128)); |
|
369 | QPen pen(QColor(128,128,128,128)); | |
370 | set1->setPen(pen); |
|
370 | set1->setPen(pen); | |
371 | QVERIFY(set1->pen() == pen); |
|
371 | QVERIFY(set1->pen() == pen); | |
372 | QVERIFY(set2->pen() == QPen()); |
|
372 | QVERIFY(set2->pen() == QPen()); | |
373 |
|
373 | |||
374 | // Test brush |
|
374 | // Test brush | |
375 | QVERIFY(set1->brush() != QBrush()); |
|
375 | QVERIFY(set1->brush() != QBrush()); | |
376 | QVERIFY(set2->brush() == QBrush()); |
|
376 | QVERIFY(set2->brush() == QBrush()); | |
377 | QBrush brush(QColor(128,128,128,128)); |
|
377 | QBrush brush(QColor(128,128,128,128)); | |
378 | set1->setBrush(brush); |
|
378 | set1->setBrush(brush); | |
379 | QVERIFY(set1->brush() == brush); |
|
379 | QVERIFY(set1->brush() == brush); | |
380 | QVERIFY(set2->brush() == QBrush()); |
|
380 | QVERIFY(set2->brush() == QBrush()); | |
381 |
|
381 | |||
382 | // Test label brush |
|
382 | // Test label brush | |
383 | QVERIFY(set1->labelBrush() != QBrush()); |
|
383 | QVERIFY(set1->labelBrush() != QBrush()); | |
384 | QVERIFY(set2->labelBrush() == QBrush()); |
|
384 | QVERIFY(set2->labelBrush() == QBrush()); | |
385 | set1->setLabelBrush(brush); |
|
385 | set1->setLabelBrush(brush); | |
386 | QVERIFY(set1->labelBrush() == brush); |
|
386 | QVERIFY(set1->labelBrush() == brush); | |
387 | QVERIFY(set2->labelBrush() == QBrush()); |
|
387 | QVERIFY(set2->labelBrush() == QBrush()); | |
388 |
|
388 | |||
389 | // Test label font |
|
389 | // Test label font | |
390 | // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the |
|
390 | // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the | |
391 | // same for the set added to the series (depending on the QChart's theme configuration) |
|
391 | // same for the set added to the series (depending on the QChart's theme configuration) | |
392 | QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont()); |
|
392 | QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont()); | |
393 | QVERIFY(set2->labelFont() == QFont()); |
|
393 | QVERIFY(set2->labelFont() == QFont()); | |
394 | QFont font; |
|
394 | QFont font; | |
395 | font.setBold(true); |
|
395 | font.setBold(true); | |
396 | font.setItalic(true); |
|
396 | font.setItalic(true); | |
397 | set1->setLabelFont(font); |
|
397 | set1->setLabelFont(font); | |
398 | QVERIFY(set1->labelFont() == font); |
|
398 | QVERIFY(set1->labelFont() == font); | |
399 | QVERIFY(set2->labelFont() == QFont()); |
|
399 | QVERIFY(set2->labelFont() == QFont()); | |
400 |
|
400 | |||
401 | // Test adding data to the sets |
|
401 | // Test adding data to the sets | |
402 | *set1 << 1 << 2 << 1 << 3; |
|
402 | *set1 << 1 << 2 << 1 << 3; | |
403 | *set2 << 2 << 1 << 3 << 1; |
|
403 | *set2 << 2 << 1 << 3 << 1; | |
404 | QTest::qWait(3000); |
|
|||
405 | } |
|
404 | } | |
406 |
|
405 | |||
407 | QTEST_MAIN(tst_QBarSet) |
|
406 | QTEST_MAIN(tst_QBarSet) | |
408 |
|
407 | |||
409 | #include "tst_qbarset.moc" |
|
408 | #include "tst_qbarset.moc" | |
410 |
|
409 |
@@ -1,350 +1,362 | |||||
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 "tst_qxyseries.h" |
|
21 | #include "tst_qxyseries.h" | |
22 |
|
22 | |||
23 | Q_DECLARE_METATYPE(QList<QPointF>) |
|
23 | Q_DECLARE_METATYPE(QList<QPointF>) | |
24 |
|
24 | |||
25 | void tst_QXYSeries::initTestCase() |
|
25 | void tst_QXYSeries::initTestCase() | |
26 | { |
|
26 | { | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | void tst_QXYSeries::cleanupTestCase() |
|
29 | void tst_QXYSeries::cleanupTestCase() | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | void tst_QXYSeries::init() |
|
33 | void tst_QXYSeries::init() | |
34 | { |
|
34 | { | |
35 | m_view = new QChartView(new QChart()); |
|
35 | m_view = new QChartView(new QChart()); | |
36 | m_chart = m_view->chart(); |
|
36 | m_chart = m_view->chart(); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | void tst_QXYSeries::cleanup() |
|
39 | void tst_QXYSeries::cleanup() | |
40 | { |
|
40 | { | |
41 | delete m_view; |
|
41 | delete m_view; | |
42 | m_view = 0; |
|
42 | m_view = 0; | |
43 | m_chart = 0; |
|
43 | m_chart = 0; | |
44 | m_series = 0; |
|
44 | m_series = 0; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void tst_QXYSeries::append_data() |
|
47 | void tst_QXYSeries::append_data() | |
48 | { |
|
48 | { | |
49 | QTest::addColumn< QList<QPointF> >("points"); |
|
49 | QTest::addColumn< QList<QPointF> >("points"); | |
50 | QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3)); |
|
50 | QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3)); | |
51 | QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3)); |
|
51 | QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3)); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 |
|
54 | |||
55 | void tst_QXYSeries::append_raw_data() |
|
55 | void tst_QXYSeries::append_raw_data() | |
56 | { |
|
56 | { | |
57 | append_data(); |
|
57 | append_data(); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void tst_QXYSeries::append_raw() |
|
60 | void tst_QXYSeries::append_raw() | |
61 | { |
|
61 | { | |
62 | QFETCH(QList<QPointF>, points); |
|
62 | QFETCH(QList<QPointF>, points); | |
63 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
63 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
64 | m_series->append(points); |
|
64 | m_series->append(points); | |
65 | TRY_COMPARE(spy0.count(), 0); |
|
65 | TRY_COMPARE(spy0.count(), 0); | |
66 | QCOMPARE(m_series->points(), points); |
|
66 | QCOMPARE(m_series->points(), points); | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void tst_QXYSeries::chart_append_data() |
|
69 | void tst_QXYSeries::chart_append_data() | |
70 | { |
|
70 | { | |
71 | append_data(); |
|
71 | append_data(); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | void tst_QXYSeries::chart_append() |
|
74 | void tst_QXYSeries::chart_append() | |
75 | { |
|
75 | { | |
76 | append_raw(); |
|
76 | append_raw(); | |
77 | m_chart->addSeries(m_series); |
|
77 | m_chart->addSeries(m_series); | |
78 | m_view->show(); |
|
78 | m_view->show(); | |
79 | QTest::qWaitForWindowShown(m_view); |
|
79 | QTest::qWaitForWindowShown(m_view); | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void tst_QXYSeries::append_chart_data() |
|
82 | void tst_QXYSeries::append_chart_data() | |
83 | { |
|
83 | { | |
84 | append_data(); |
|
84 | append_data(); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | void tst_QXYSeries::append_chart() |
|
87 | void tst_QXYSeries::append_chart() | |
88 | { |
|
88 | { | |
89 | m_view->show(); |
|
89 | m_view->show(); | |
90 | m_chart->addSeries(m_series); |
|
90 | m_chart->addSeries(m_series); | |
91 | QTest::qWaitForWindowShown(m_view); |
|
91 | QTest::qWaitForWindowShown(m_view); | |
92 | append_raw(); |
|
92 | append_raw(); | |
93 |
|
93 | |||
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void tst_QXYSeries::append_chart_animation_data() |
|
96 | void tst_QXYSeries::append_chart_animation_data() | |
97 | { |
|
97 | { | |
98 | append_data(); |
|
98 | append_data(); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | void tst_QXYSeries::append_chart_animation() |
|
101 | void tst_QXYSeries::append_chart_animation() | |
102 | { |
|
102 | { | |
103 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
103 | m_chart->setAnimationOptions(QChart::AllAnimations); | |
104 | append_chart(); |
|
104 | append_chart(); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void tst_QXYSeries::count_data() |
|
107 | void tst_QXYSeries::count_data() | |
108 | { |
|
108 | { | |
109 | QTest::addColumn<int>("count"); |
|
109 | QTest::addColumn<int>("count"); | |
110 | QTest::newRow("0") << 0; |
|
110 | QTest::newRow("0") << 0; | |
111 | QTest::newRow("5") << 5; |
|
111 | QTest::newRow("5") << 5; | |
112 | QTest::newRow("10") << 5; |
|
112 | QTest::newRow("10") << 5; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | void tst_QXYSeries::count_raw_data() |
|
115 | void tst_QXYSeries::count_raw_data() | |
116 | { |
|
116 | { | |
117 | count_data(); |
|
117 | count_data(); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | void tst_QXYSeries::count_raw() |
|
120 | void tst_QXYSeries::count_raw() | |
121 | { |
|
121 | { | |
122 | QFETCH(int, count); |
|
122 | QFETCH(int, count); | |
123 |
|
123 | |||
124 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
124 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
125 |
|
125 | |||
126 | for(int i=0 ; i< count; ++i) |
|
126 | for(int i=0 ; i< count; ++i) | |
127 | m_series->append(i,i); |
|
127 | m_series->append(i,i); | |
128 |
|
128 | |||
129 | TRY_COMPARE(spy0.count(), 0); |
|
129 | TRY_COMPARE(spy0.count(), 0); | |
130 | QCOMPARE(m_series->count(), count); |
|
130 | QCOMPARE(m_series->count(), count); | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | void tst_QXYSeries::remove_raw_data() |
|
133 | void tst_QXYSeries::remove_raw_data() | |
134 | { |
|
134 | { | |
135 | append_data(); |
|
135 | append_data(); | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | void tst_QXYSeries::remove_raw() |
|
138 | void tst_QXYSeries::remove_raw() | |
139 | { |
|
139 | { | |
140 | QFETCH(QList<QPointF>, points); |
|
140 | QFETCH(QList<QPointF>, points); | |
141 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
141 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
142 | m_series->append(points); |
|
142 | m_series->append(points); | |
143 | TRY_COMPARE(spy0.count(), 0); |
|
143 | TRY_COMPARE(spy0.count(), 0); | |
144 | QCOMPARE(m_series->points(), points); |
|
144 | QCOMPARE(m_series->points(), points); | |
145 |
|
145 | |||
146 | foreach(const QPointF& point,points) |
|
146 | foreach(const QPointF& point,points) | |
147 | m_series->remove(point); |
|
147 | m_series->remove(point); | |
148 |
|
148 | |||
149 | QCOMPARE(m_series->points().count(), 0); |
|
149 | QCOMPARE(m_series->points().count(), 0); | |
150 | TRY_COMPARE(spy0.count(), 0); |
|
150 | TRY_COMPARE(spy0.count(), 0); | |
151 |
|
151 | |||
152 | m_series->append(points); |
|
152 | m_series->append(points); | |
153 | QCOMPARE(m_series->points(), points); |
|
153 | QCOMPARE(m_series->points(), points); | |
154 |
|
154 | |||
155 | //reverse order |
|
155 | //reverse order | |
156 | for(int i = points.count()-1 ; i>=0; i--){ |
|
156 | for(int i = points.count()-1 ; i>=0; i--){ | |
157 | m_series->remove(points[i]); |
|
157 | m_series->remove(points[i]); | |
158 | } |
|
158 | } | |
159 | QCOMPARE(m_series->points().count(), 0); |
|
159 | QCOMPARE(m_series->points().count(), 0); | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | void tst_QXYSeries::remove_chart_data() |
|
162 | void tst_QXYSeries::remove_chart_data() | |
163 | { |
|
163 | { | |
164 | append_data(); |
|
164 | append_data(); | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | void tst_QXYSeries::remove_chart() |
|
167 | void tst_QXYSeries::remove_chart() | |
168 | { |
|
168 | { | |
169 | m_view->show(); |
|
169 | m_view->show(); | |
170 | m_chart->addSeries(m_series); |
|
170 | m_chart->addSeries(m_series); | |
171 | QTest::qWaitForWindowShown(m_view); |
|
171 | QTest::qWaitForWindowShown(m_view); | |
172 | remove_raw(); |
|
172 | remove_raw(); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | void tst_QXYSeries::remove_chart_animation_data() |
|
175 | void tst_QXYSeries::remove_chart_animation_data() | |
176 | { |
|
176 | { | |
177 | append_data(); |
|
177 | append_data(); | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | void tst_QXYSeries::remove_chart_animation() |
|
180 | void tst_QXYSeries::remove_chart_animation() | |
181 | { |
|
181 | { | |
182 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
182 | m_chart->setAnimationOptions(QChart::AllAnimations); | |
183 | remove_chart(); |
|
183 | remove_chart(); | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 |
|
186 | |||
187 | void tst_QXYSeries::removeAll_raw_data() |
|
187 | void tst_QXYSeries::removeAll_raw_data() | |
188 | { |
|
188 | { | |
189 | append_data(); |
|
189 | append_data(); | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | void tst_QXYSeries::removeAll_raw() |
|
192 | void tst_QXYSeries::removeAll_raw() | |
193 | { |
|
193 | { | |
194 | QFETCH(QList<QPointF>, points); |
|
194 | QFETCH(QList<QPointF>, points); | |
195 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
195 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
196 | m_series->append(points); |
|
196 | m_series->append(points); | |
197 | TRY_COMPARE(spy0.count(), 0); |
|
197 | TRY_COMPARE(spy0.count(), 0); | |
198 | QCOMPARE(m_series->points(), points); |
|
198 | QCOMPARE(m_series->points(), points); | |
199 | m_series->removeAll(); |
|
199 | m_series->removeAll(); | |
200 | TRY_COMPARE(spy0.count(), 0); |
|
200 | TRY_COMPARE(spy0.count(), 0); | |
201 | QCOMPARE(m_series->points().count(), 0); |
|
201 | QCOMPARE(m_series->points().count(), 0); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | void tst_QXYSeries::removeAll_chart_data() |
|
204 | void tst_QXYSeries::removeAll_chart_data() | |
205 | { |
|
205 | { | |
206 | append_data(); |
|
206 | append_data(); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | void tst_QXYSeries::removeAll_chart() |
|
209 | void tst_QXYSeries::removeAll_chart() | |
210 | { |
|
210 | { | |
211 | m_view->show(); |
|
211 | m_view->show(); | |
212 | m_chart->addSeries(m_series); |
|
212 | m_chart->addSeries(m_series); | |
213 | QTest::qWaitForWindowShown(m_view); |
|
213 | QTest::qWaitForWindowShown(m_view); | |
214 | removeAll_raw(); |
|
214 | removeAll_raw(); | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | void tst_QXYSeries::removeAll_chart_animation_data() |
|
217 | void tst_QXYSeries::removeAll_chart_animation_data() | |
218 | { |
|
218 | { | |
219 | append_data(); |
|
219 | append_data(); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | void tst_QXYSeries::removeAll_chart_animation() |
|
222 | void tst_QXYSeries::removeAll_chart_animation() | |
223 | { |
|
223 | { | |
224 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
224 | m_chart->setAnimationOptions(QChart::AllAnimations); | |
225 | removeAll_chart(); |
|
225 | removeAll_chart(); | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | void tst_QXYSeries::replace_raw_data() |
|
228 | void tst_QXYSeries::replace_raw_data() | |
229 | { |
|
229 | { | |
230 | append_data(); |
|
230 | append_data(); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | void tst_QXYSeries::replace_raw() |
|
233 | void tst_QXYSeries::replace_raw() | |
234 | { |
|
234 | { | |
235 | QFETCH(QList<QPointF>, points); |
|
235 | QFETCH(QList<QPointF>, points); | |
236 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
236 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
237 | m_series->append(points); |
|
237 | m_series->append(points); | |
238 | TRY_COMPARE(spy0.count(), 0); |
|
238 | TRY_COMPARE(spy0.count(), 0); | |
239 | QCOMPARE(m_series->points(), points); |
|
239 | QCOMPARE(m_series->points(), points); | |
240 |
|
240 | |||
241 | foreach(const QPointF& point,points) |
|
241 | foreach(const QPointF& point,points) | |
242 | m_series->replace(point.x(),point.y(),point.x(),0); |
|
242 | m_series->replace(point.x(),point.y(),point.x(),0); | |
243 |
|
243 | |||
244 | QList<QPointF> newPoints = m_series->points(); |
|
244 | QList<QPointF> newPoints = m_series->points(); | |
245 |
|
245 | |||
246 | QCOMPARE(newPoints.count(), points.count()); |
|
246 | QCOMPARE(newPoints.count(), points.count()); | |
247 |
|
247 | |||
248 | for(int i =0 ; i<points.count() ; ++i) { |
|
248 | for(int i =0 ; i<points.count() ; ++i) { | |
249 | QCOMPARE(points[i].x(), newPoints[i].x()); |
|
249 | QCOMPARE(points[i].x(), newPoints[i].x()); | |
250 | QCOMPARE(newPoints[i].y(), 0.0); |
|
250 | QCOMPARE(newPoints[i].y(), 0.0); | |
251 | } |
|
251 | } | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 |
|
254 | |||
255 | void tst_QXYSeries::replace_chart_data() |
|
255 | void tst_QXYSeries::replace_chart_data() | |
256 | { |
|
256 | { | |
257 | append_data(); |
|
257 | append_data(); | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 | void tst_QXYSeries::replace_chart() |
|
260 | void tst_QXYSeries::replace_chart() | |
261 | { |
|
261 | { | |
262 | m_view->show(); |
|
262 | m_view->show(); | |
263 | m_chart->addSeries(m_series); |
|
263 | m_chart->addSeries(m_series); | |
264 | QTest::qWaitForWindowShown(m_view); |
|
264 | QTest::qWaitForWindowShown(m_view); | |
265 | replace_raw(); |
|
265 | replace_raw(); | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | void tst_QXYSeries::replace_chart_animation_data() |
|
268 | void tst_QXYSeries::replace_chart_animation_data() | |
269 | { |
|
269 | { | |
270 | append_data(); |
|
270 | append_data(); | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | void tst_QXYSeries::replace_chart_animation() |
|
273 | void tst_QXYSeries::replace_chart_animation() | |
274 | { |
|
274 | { | |
275 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
275 | m_chart->setAnimationOptions(QChart::AllAnimations); | |
276 | replace_chart(); |
|
276 | replace_chart(); | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | void tst_QXYSeries::oper_data() |
|
279 | void tst_QXYSeries::oper_data() | |
280 | { |
|
280 | { | |
281 | append_data(); |
|
281 | append_data(); | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | void tst_QXYSeries::oper() |
|
284 | void tst_QXYSeries::oper() | |
285 | { |
|
285 | { | |
286 | QFETCH(QList<QPointF>, points); |
|
286 | QFETCH(QList<QPointF>, points); | |
287 |
|
287 | |||
288 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
288 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
289 |
|
289 | |||
290 | foreach(const QPointF& point,points) |
|
290 | foreach(const QPointF& point,points) | |
291 | { |
|
291 | { | |
292 | *m_series<<point; |
|
292 | *m_series<<point; | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | QCOMPARE(m_series->points(), points); |
|
295 | QCOMPARE(m_series->points(), points); | |
296 | TRY_COMPARE(spy0.count(), 0); |
|
296 | TRY_COMPARE(spy0.count(), 0); | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 |
|
299 | |||
300 | void tst_QXYSeries::pen_data() |
|
300 | void tst_QXYSeries::pen_data() | |
301 | { |
|
301 | { | |
302 | QTest::addColumn<QPen>("pen"); |
|
302 | QTest::addColumn<QPen>("pen"); | |
303 | QTest::newRow("null") << QPen(); |
|
303 | QTest::newRow("null") << QPen(); | |
304 | QTest::newRow("blue") << QPen(Qt::blue); |
|
304 | QTest::newRow("blue") << QPen(Qt::blue); | |
305 | QTest::newRow("black") << QPen(Qt::black); |
|
305 | QTest::newRow("black") << QPen(Qt::black); | |
306 | QTest::newRow("red") << QPen(Qt::red); |
|
306 | QTest::newRow("red") << QPen(Qt::red); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | void tst_QXYSeries::pen() |
|
309 | void tst_QXYSeries::pen() | |
310 | { |
|
310 | { | |
311 | QFETCH(QPen, pen); |
|
311 | QFETCH(QPen, pen); | |
312 |
|
312 | |||
313 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
313 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
314 | m_series->setPen(pen); |
|
314 | m_series->setPen(pen); | |
315 |
|
315 | |||
316 | TRY_COMPARE(spy0.count(), 0); |
|
316 | TRY_COMPARE(spy0.count(), 0); | |
317 | QCOMPARE(m_series->pen(), pen); |
|
317 | QCOMPARE(m_series->pen(), pen); | |
318 |
|
318 | |||
319 | m_chart->addSeries(m_series); |
|
319 | m_chart->addSeries(m_series); | |
320 |
|
320 | |||
321 | if (pen != QPen()) |
|
321 | if (pen != QPen()) | |
322 | QCOMPARE(m_series->pen(), pen); |
|
322 | QCOMPARE(m_series->pen(), pen); | |
323 |
|
323 | |||
324 | m_chart->setTheme(QChart::ChartThemeDark); |
|
324 | m_chart->setTheme(QChart::ChartThemeDark); | |
325 |
|
325 | |||
326 | // setting a theme will overwrite all customizations |
|
326 | // setting a theme will overwrite all customizations | |
327 | if (pen != QPen()) |
|
327 | if (pen != QPen()) | |
328 | QVERIFY(m_series->pen() != pen); |
|
328 | QVERIFY(m_series->pen() != pen); | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | void tst_QXYSeries::pointsVisible_data() |
|
331 | void tst_QXYSeries::pointsVisible_data() | |
332 | { |
|
332 | { | |
333 | QTest::addColumn<bool>("pointsVisible"); |
|
333 | QTest::addColumn<bool>("pointsVisible"); | |
334 | QTest::newRow("true") << true; |
|
334 | QTest::newRow("true") << true; | |
335 | QTest::newRow("false") << false; |
|
335 | QTest::newRow("false") << false; | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | void tst_QXYSeries::pointsVisible_raw_data() |
|
338 | void tst_QXYSeries::pointsVisible_raw_data() | |
339 | { |
|
339 | { | |
340 | pointsVisible_data(); |
|
340 | pointsVisible_data(); | |
341 | } |
|
341 | } | |
342 |
|
342 | |||
343 | void tst_QXYSeries::pointsVisible_raw() |
|
343 | void tst_QXYSeries::pointsVisible_raw() | |
344 | { |
|
344 | { | |
345 | QFETCH(bool, pointsVisible); |
|
345 | QFETCH(bool, pointsVisible); | |
346 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
346 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
347 | m_series->setPointsVisible(pointsVisible); |
|
347 | m_series->setPointsVisible(pointsVisible); | |
348 | TRY_COMPARE(spy0.count(), 0); |
|
348 | TRY_COMPARE(spy0.count(), 0); | |
349 | QCOMPARE(m_series->pointsVisible(), pointsVisible); |
|
349 | QCOMPARE(m_series->pointsVisible(), pointsVisible); | |
350 | } |
|
350 | } | |
|
351 | ||||
|
352 | void tst_QXYSeries::changedSignals() | |||
|
353 | { | |||
|
354 | QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged())); | |||
|
355 | ||||
|
356 | m_series->setVisible(false); | |||
|
357 | m_series->setVisible(false); | |||
|
358 | TRY_COMPARE(visibleSpy.count(), 1); | |||
|
359 | m_series->setVisible(true); | |||
|
360 | TRY_COMPARE(visibleSpy.count(), 2); | |||
|
361 | } | |||
|
362 |
@@ -1,88 +1,89 | |||||
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 TST_QXYSERIES_H |
|
21 | #ifndef TST_QXYSERIES_H | |
22 | #define TST_QXYSERIES_H |
|
22 | #define TST_QXYSERIES_H | |
23 |
|
23 | |||
24 | #include <QtTest/QtTest> |
|
24 | #include <QtTest/QtTest> | |
25 | #include <qxyseries.h> |
|
25 | #include <qxyseries.h> | |
26 | #include <qchartview.h> |
|
26 | #include <qchartview.h> | |
27 | #include <QStandardItemModel> |
|
27 | #include <QStandardItemModel> | |
28 | #include <tst_definitions.h> |
|
28 | #include <tst_definitions.h> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
30 | QTCOMMERCIALCHART_USE_NAMESPACE | |
31 |
|
31 | |||
32 | class tst_QXYSeries : public QObject |
|
32 | class tst_QXYSeries : public QObject | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 |
|
35 | |||
36 | public slots: |
|
36 | public slots: | |
37 | virtual void initTestCase(); |
|
37 | virtual void initTestCase(); | |
38 | virtual void cleanupTestCase(); |
|
38 | virtual void cleanupTestCase(); | |
39 | virtual void init(); |
|
39 | virtual void init(); | |
40 | virtual void cleanup(); |
|
40 | virtual void cleanup(); | |
41 |
|
41 | |||
42 | private slots: |
|
42 | private slots: | |
43 | void oper_data(); |
|
43 | void oper_data(); | |
44 | void oper(); |
|
44 | void oper(); | |
45 | void pen_data(); |
|
45 | void pen_data(); | |
46 | void pen(); |
|
46 | void pen(); | |
47 | void pointsVisible_raw_data(); |
|
47 | void pointsVisible_raw_data(); | |
48 | void pointsVisible_raw(); |
|
48 | void pointsVisible_raw(); | |
49 | void append_raw_data(); |
|
49 | void append_raw_data(); | |
50 | void append_raw(); |
|
50 | void append_raw(); | |
51 | void append_chart_data(); |
|
51 | void append_chart_data(); | |
52 | void append_chart(); |
|
52 | void append_chart(); | |
53 | void append_chart_animation_data(); |
|
53 | void append_chart_animation_data(); | |
54 | void append_chart_animation(); |
|
54 | void append_chart_animation(); | |
55 | void chart_append_data(); |
|
55 | void chart_append_data(); | |
56 | void chart_append(); |
|
56 | void chart_append(); | |
57 | void count_raw_data(); |
|
57 | void count_raw_data(); | |
58 | void count_raw(); |
|
58 | void count_raw(); | |
59 | void remove_raw_data(); |
|
59 | void remove_raw_data(); | |
60 | void remove_raw(); |
|
60 | void remove_raw(); | |
61 | void remove_chart_data(); |
|
61 | void remove_chart_data(); | |
62 | void remove_chart(); |
|
62 | void remove_chart(); | |
63 | void remove_chart_animation_data(); |
|
63 | void remove_chart_animation_data(); | |
64 | void remove_chart_animation(); |
|
64 | void remove_chart_animation(); | |
65 | void removeAll_raw_data(); |
|
65 | void removeAll_raw_data(); | |
66 | void removeAll_raw(); |
|
66 | void removeAll_raw(); | |
67 | void removeAll_chart_data(); |
|
67 | void removeAll_chart_data(); | |
68 | void removeAll_chart(); |
|
68 | void removeAll_chart(); | |
69 | void removeAll_chart_animation_data(); |
|
69 | void removeAll_chart_animation_data(); | |
70 | void removeAll_chart_animation(); |
|
70 | void removeAll_chart_animation(); | |
71 | void replace_raw_data(); |
|
71 | void replace_raw_data(); | |
72 | void replace_raw(); |
|
72 | void replace_raw(); | |
73 | void replace_chart_data(); |
|
73 | void replace_chart_data(); | |
74 | void replace_chart(); |
|
74 | void replace_chart(); | |
75 | void replace_chart_animation_data(); |
|
75 | void replace_chart_animation_data(); | |
76 | void replace_chart_animation(); |
|
76 | void replace_chart_animation(); | |
|
77 | void changedSignals(); | |||
77 | protected: |
|
78 | protected: | |
78 | void append_data(); |
|
79 | void append_data(); | |
79 | void count_data(); |
|
80 | void count_data(); | |
80 | void pointsVisible_data(); |
|
81 | void pointsVisible_data(); | |
81 |
|
82 | |||
82 | protected: |
|
83 | protected: | |
83 | QChartView* m_view; |
|
84 | QChartView* m_view; | |
84 | QChart* m_chart; |
|
85 | QChart* m_chart; | |
85 | QXYSeries* m_series; |
|
86 | QXYSeries* m_series; | |
86 | }; |
|
87 | }; | |
87 |
|
88 | |||
88 | #endif |
|
89 | #endif |
@@ -1,55 +1,59 | |||||
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 |
|
24 | |||
25 | Flow { |
|
25 | Flow { | |
26 | id: flow |
|
26 | id: flow | |
27 | spacing: 5 |
|
27 | spacing: 5 | |
28 | flow: Flow.TopToBottom |
|
28 | flow: Flow.TopToBottom | |
29 | property variant series |
|
29 | property variant series | |
30 |
|
30 | |||
31 | Button { |
|
31 | Button { | |
|
32 | text: "visible" | |||
|
33 | onClicked: series.visible = !series.visible; | |||
|
34 | } | |||
|
35 | Button { | |||
32 | text: "color" |
|
36 | text: "color" | |
33 | onClicked: series.color = main.nextColor(); |
|
37 | onClicked: series.color = main.nextColor(); | |
34 | } |
|
38 | } | |
35 | Button { |
|
39 | Button { | |
36 | text: "borderColor" |
|
40 | text: "borderColor" | |
37 | onClicked: series.borderColor = main.nextColor(); |
|
41 | onClicked: series.borderColor = main.nextColor(); | |
38 | } |
|
42 | } | |
39 | Button { |
|
43 | Button { | |
40 | text: "upper color" |
|
44 | text: "upper color" | |
41 | onClicked: series.upperSeries.color = main.nextColor(); |
|
45 | onClicked: series.upperSeries.color = main.nextColor(); | |
42 | } |
|
46 | } | |
43 | Button { |
|
47 | Button { | |
44 | text: "lower color" |
|
48 | text: "lower color" | |
45 | onClicked: series.lowerSeries.color = main.nextColor(); |
|
49 | onClicked: series.lowerSeries.color = main.nextColor(); | |
46 | } |
|
50 | } | |
47 | Button { |
|
51 | Button { | |
48 | text: "upper points visible" |
|
52 | text: "upper points visible" | |
49 | onClicked: series.upperSeries.pointsVisible = !series.pointsVisible; |
|
53 | onClicked: series.upperSeries.pointsVisible = !series.pointsVisible; | |
50 | } |
|
54 | } | |
51 | Button { |
|
55 | Button { | |
52 | text: "lower points visible" |
|
56 | text: "lower points visible" | |
53 | onClicked: series.lowerSeries.pointsVisible = !series.pointsVisible; |
|
57 | onClicked: series.lowerSeries.pointsVisible = !series.pointsVisible; | |
54 | } |
|
58 | } | |
55 | } |
|
59 | } |
@@ -1,66 +1,66 | |||||
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 | Flow { |
|
24 | Flow { | |
25 | id: flow |
|
25 | id: flow | |
26 | spacing: 5 |
|
26 | spacing: 5 | |
27 | flow: Flow.TopToBottom |
|
27 | flow: Flow.TopToBottom | |
28 | property variant series |
|
28 | property variant series | |
29 |
|
29 | |||
30 | Button { |
|
30 | Button { | |
31 | text: "set 1 color" |
|
|||
32 | onClicked: series.at(0).color = main.nextColor(); |
|
|||
33 | } |
|
|||
34 | Button { |
|
|||
35 | text: "set 1 border color" |
|
|||
36 | onClicked: series.at(0).borderColor = main.nextColor(); |
|
|||
37 | } |
|
|||
38 | Button { |
|
|||
39 | text: "set 1 label color" |
|
|||
40 | onClicked: series.at(0).labelColor = main.nextColor(); |
|
|||
41 | } |
|
|||
42 | Button { |
|
|||
43 | text: "visible" |
|
31 | text: "visible" | |
44 | onClicked: series.visible = !series.visible; |
|
32 | onClicked: series.visible = !series.visible; | |
45 | } |
|
33 | } | |
46 | Button { |
|
34 | Button { | |
47 | text: "labels visible" |
|
35 | text: "labels visible" | |
48 | onClicked: series.labelsVisible = !series.labelsVisible; |
|
36 | onClicked: series.labelsVisible = !series.labelsVisible; | |
49 | } |
|
37 | } | |
50 | Button { |
|
38 | Button { | |
51 | text: "bar margin +" |
|
39 | text: "bar margin +" | |
52 | onClicked: series.barMargin += 0.1; |
|
40 | onClicked: series.barMargin += 0.1; | |
53 | } |
|
41 | } | |
54 | Button { |
|
42 | Button { | |
55 | text: "bar margin -" |
|
43 | text: "bar margin -" | |
56 | onClicked: series.barMargin -= 0.1; |
|
44 | onClicked: series.barMargin -= 0.1; | |
57 | } |
|
45 | } | |
58 | Button { |
|
46 | Button { | |
|
47 | text: "set 1 color" | |||
|
48 | onClicked: series.at(0).color = main.nextColor(); | |||
|
49 | } | |||
|
50 | Button { | |||
|
51 | text: "set 1 border color" | |||
|
52 | onClicked: series.at(0).borderColor = main.nextColor(); | |||
|
53 | } | |||
|
54 | Button { | |||
|
55 | text: "set 1 label color" | |||
|
56 | onClicked: series.at(0).labelColor = main.nextColor(); | |||
|
57 | } | |||
|
58 | Button { | |||
59 | text: "set 1 font size +" |
|
59 | text: "set 1 font size +" | |
60 | onClicked: series.at(0).labelFont.pixelSize += 1; |
|
60 | onClicked: series.at(0).labelFont.pixelSize += 1; | |
61 | } |
|
61 | } | |
62 | Button { |
|
62 | Button { | |
63 | text: "set 1 font size -" |
|
63 | text: "set 1 font size -" | |
64 | onClicked: series.at(0).labelFont.pixelSize -= 1; |
|
64 | onClicked: series.at(0).labelFont.pixelSize -= 1; | |
65 | } |
|
65 | } | |
66 | } |
|
66 | } |
@@ -1,39 +1,43 | |||||
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 |
|
24 | |||
25 | Flow { |
|
25 | Flow { | |
26 | id: flow |
|
26 | id: flow | |
27 | spacing: 5 |
|
27 | spacing: 5 | |
28 | flow: Flow.TopToBottom |
|
28 | flow: Flow.TopToBottom | |
29 | property variant series |
|
29 | property variant series | |
30 |
|
30 | |||
31 | Button { |
|
31 | Button { | |
|
32 | text: "visible" | |||
|
33 | onClicked: series.visible = !series.visible; | |||
|
34 | } | |||
|
35 | Button { | |||
32 | text: "color" |
|
36 | text: "color" | |
33 | onClicked: series.color = main.nextColor(); |
|
37 | onClicked: series.color = main.nextColor(); | |
34 | } |
|
38 | } | |
35 | Button { |
|
39 | Button { | |
36 | text: "points visible" |
|
40 | text: "points visible" | |
37 | onClicked: series.pointsVisible = !series.pointsVisible |
|
41 | onClicked: series.pointsVisible = !series.pointsVisible | |
38 | } |
|
42 | } | |
39 | } |
|
43 | } |
@@ -1,114 +1,118 | |||||
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 | Flow { |
|
24 | Flow { | |
25 | id: flow |
|
25 | id: flow | |
26 | spacing: 5 |
|
26 | spacing: 5 | |
27 | flow: Flow.TopToBottom |
|
27 | flow: Flow.TopToBottom | |
28 | property variant series |
|
28 | property variant series | |
29 |
|
29 | |||
30 | Button { |
|
30 | Button { | |
|
31 | text: "visible" | |||
|
32 | onClicked: series.visible = !series.visible; | |||
|
33 | } | |||
|
34 | Button { | |||
|
35 | text: "series hpos +" | |||
|
36 | onClicked: series.horizontalPosition += 0.1; | |||
|
37 | } | |||
|
38 | Button { | |||
|
39 | text: "series hpos -" | |||
|
40 | onClicked: series.horizontalPosition -= 0.1; | |||
|
41 | } | |||
|
42 | Button { | |||
|
43 | text: "series vpos +" | |||
|
44 | onClicked: series.verticalPosition += 0.1; | |||
|
45 | } | |||
|
46 | Button { | |||
|
47 | text: "series vpos -" | |||
|
48 | onClicked: series.verticalPosition -= 0.1; | |||
|
49 | } | |||
|
50 | Button { | |||
|
51 | text: "series size +" | |||
|
52 | onClicked: series.size += 0.1; | |||
|
53 | } | |||
|
54 | Button { | |||
|
55 | text: "series size -" | |||
|
56 | onClicked: series.size -= 0.1; | |||
|
57 | } | |||
|
58 | Button { | |||
|
59 | text: "series start angle +" | |||
|
60 | onClicked: series.startAngle += 0.1; | |||
|
61 | } | |||
|
62 | Button { | |||
|
63 | text: "series start angle -" | |||
|
64 | onClicked: series.startAngle -= 0.1; | |||
|
65 | } | |||
|
66 | Button { | |||
|
67 | text: "series end angle +" | |||
|
68 | onClicked: series.endAngle += 0.1; | |||
|
69 | } | |||
|
70 | Button { | |||
|
71 | text: "series end angle -" | |||
|
72 | onClicked: series.endAngle -= 0.1; | |||
|
73 | } | |||
|
74 | Button { | |||
31 | text: "slice color" |
|
75 | text: "slice color" | |
32 | onClicked: series.at(0).color = main.nextColor(); |
|
76 | onClicked: series.at(0).color = main.nextColor(); | |
33 | } |
|
77 | } | |
34 | Button { |
|
78 | Button { | |
35 | text: "slice border color" |
|
79 | text: "slice border color" | |
36 | onClicked: series.at(0).borderColor = main.nextColor(); |
|
80 | onClicked: series.at(0).borderColor = main.nextColor(); | |
37 | } |
|
81 | } | |
38 | Button { |
|
82 | Button { | |
39 | text: "slice border width +" |
|
83 | text: "slice border width +" | |
40 | onClicked: series.at(0).borderWidth++; |
|
84 | onClicked: series.at(0).borderWidth++; | |
41 | } |
|
85 | } | |
42 | Button { |
|
86 | Button { | |
43 | text: "slice border width -" |
|
87 | text: "slice border width -" | |
44 | onClicked: series.at(0).borderWidth--; |
|
88 | onClicked: series.at(0).borderWidth--; | |
45 | } |
|
89 | } | |
46 | Button { |
|
90 | Button { | |
47 | text: "slice label visible" |
|
91 | text: "slice label visible" | |
48 | onClicked: series.at(0).labelVisible = !series.at(0).labelVisible; |
|
92 | onClicked: series.at(0).labelVisible = !series.at(0).labelVisible; | |
49 | } |
|
93 | } | |
50 | Button { |
|
94 | Button { | |
51 | text: "slice label arm len +" |
|
95 | text: "slice label arm len +" | |
52 | onClicked: series.at(0).labelArmLengthFactor += 0.1; |
|
96 | onClicked: series.at(0).labelArmLengthFactor += 0.1; | |
53 | } |
|
97 | } | |
54 | Button { |
|
98 | Button { | |
55 | text: "slice label arm len -" |
|
99 | text: "slice label arm len -" | |
56 | onClicked: series.at(0).labelArmLengthFactor -= 0.1; |
|
100 | onClicked: series.at(0).labelArmLengthFactor -= 0.1; | |
57 | } |
|
101 | } | |
58 | Button { |
|
102 | Button { | |
59 | text: "slice label color" |
|
103 | text: "slice label color" | |
60 | onClicked: series.at(0).labelColor = main.nextColor(); |
|
104 | onClicked: series.at(0).labelColor = main.nextColor(); | |
61 | } |
|
105 | } | |
62 | Button { |
|
106 | Button { | |
63 | text: "slice exploded" |
|
107 | text: "slice exploded" | |
64 | onClicked: series.at(0).exploded = !series.at(0).exploded; |
|
108 | onClicked: series.at(0).exploded = !series.at(0).exploded; | |
65 | } |
|
109 | } | |
66 | Button { |
|
110 | Button { | |
67 | text: "slice explode dist +" |
|
111 | text: "slice explode dist +" | |
68 | onClicked: series.at(0).explodeDistanceFactor += 0.1; |
|
112 | onClicked: series.at(0).explodeDistanceFactor += 0.1; | |
69 | } |
|
113 | } | |
70 | Button { |
|
114 | Button { | |
71 | text: "slice explode dist -" |
|
115 | text: "slice explode dist -" | |
72 | onClicked: series.at(0).explodeDistanceFactor -= 0.1; |
|
116 | onClicked: series.at(0).explodeDistanceFactor -= 0.1; | |
73 | } |
|
117 | } | |
74 | Button { |
|
|||
75 | text: "series hpos +" |
|
|||
76 | onClicked: series.horizontalPosition += 0.1; |
|
|||
77 | } |
|
|||
78 | Button { |
|
|||
79 | text: "series hpos -" |
|
|||
80 | onClicked: series.horizontalPosition -= 0.1; |
|
|||
81 | } |
|
|||
82 | Button { |
|
|||
83 | text: "series vpos +" |
|
|||
84 | onClicked: series.verticalPosition += 0.1; |
|
|||
85 | } |
|
|||
86 | Button { |
|
|||
87 | text: "series vpos -" |
|
|||
88 | onClicked: series.verticalPosition -= 0.1; |
|
|||
89 | } |
|
|||
90 | Button { |
|
|||
91 | text: "series size +" |
|
|||
92 | onClicked: series.size += 0.1; |
|
|||
93 | } |
|
|||
94 | Button { |
|
|||
95 | text: "series size -" |
|
|||
96 | onClicked: series.size -= 0.1; |
|
|||
97 | } |
|
|||
98 | Button { |
|
|||
99 | text: "series start angle +" |
|
|||
100 | onClicked: series.startAngle += 0.1; |
|
|||
101 | } |
|
|||
102 | Button { |
|
|||
103 | text: "series start angle -" |
|
|||
104 | onClicked: series.startAngle -= 0.1; |
|
|||
105 | } |
|
|||
106 | Button { |
|
|||
107 | text: "series end angle +" |
|
|||
108 | onClicked: series.endAngle += 0.1; |
|
|||
109 | } |
|
|||
110 | Button { |
|
|||
111 | text: "series end angle -" |
|
|||
112 | onClicked: series.endAngle -= 0.1; |
|
|||
113 | } |
|
|||
114 | } |
|
118 | } |
@@ -1,51 +1,55 | |||||
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 |
|
24 | |||
25 | Flow { |
|
25 | Flow { | |
26 | id: flow |
|
26 | id: flow | |
27 | spacing: 5 |
|
27 | spacing: 5 | |
28 | flow: Flow.TopToBottom |
|
28 | flow: Flow.TopToBottom | |
29 | property variant series |
|
29 | property variant series | |
30 |
|
30 | |||
31 | Button { |
|
31 | Button { | |
|
32 | text: "visible" | |||
|
33 | onClicked: series.visible = !series.visible; | |||
|
34 | } | |||
|
35 | Button { | |||
32 | text: "color" |
|
36 | text: "color" | |
33 | onClicked: series.color = main.nextColor(); |
|
37 | onClicked: series.color = main.nextColor(); | |
34 | } |
|
38 | } | |
35 | Button { |
|
39 | Button { | |
36 | text: "borderColor" |
|
40 | text: "borderColor" | |
37 | onClicked: series.borderColor = main.nextColor(); |
|
41 | onClicked: series.borderColor = main.nextColor(); | |
38 | } |
|
42 | } | |
39 | Button { |
|
43 | Button { | |
40 | text: "markerSize +" |
|
44 | text: "markerSize +" | |
41 | onClicked: series.markerSize += 1.0; |
|
45 | onClicked: series.markerSize += 1.0; | |
42 | } |
|
46 | } | |
43 | Button { |
|
47 | Button { | |
44 | text: "markerSize -" |
|
48 | text: "markerSize -" | |
45 | onClicked: series.markerSize -= 1.0; |
|
49 | onClicked: series.markerSize -= 1.0; | |
46 | } |
|
50 | } | |
47 | Button { |
|
51 | Button { | |
48 | text: "markerShape" |
|
52 | text: "markerShape" | |
49 | onClicked: series.markerShape = ((series.markerShape + 1) % 2); |
|
53 | onClicked: series.markerShape = ((series.markerShape + 1) % 2); | |
50 | } |
|
54 | } | |
51 | } |
|
55 | } |
General Comments 0
You need to be logged in to leave comments.
Login now