@@ -22,7 +22,7 | |||||
22 | #include "axisanimation_p.h" |
|
22 | #include "axisanimation_p.h" | |
23 | #include "xyanimation_p.h" |
|
23 | #include "xyanimation_p.h" | |
24 | #include "splineanimation_p.h" |
|
24 | #include "splineanimation_p.h" | |
25 |
#include "xychart |
|
25 | #include "xychart_p.h" | |
26 | #include "pieanimation_p.h" |
|
26 | #include "pieanimation_p.h" | |
27 | #include "baranimation_p.h" |
|
27 | #include "baranimation_p.h" | |
28 | #include "barchartitem_p.h" |
|
28 | #include "barchartitem_p.h" |
@@ -19,14 +19,14 | |||||
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "xyanimation_p.h" |
|
21 | #include "xyanimation_p.h" | |
22 |
#include "xychart |
|
22 | #include "xychart_p.h" | |
23 | #include <QDebug> |
|
23 | #include <QDebug> | |
24 |
|
24 | |||
25 | Q_DECLARE_METATYPE(QVector<QPointF>) |
|
25 | Q_DECLARE_METATYPE(QVector<QPointF>) | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 |
XYAnimation::XYAnimation(XYChart |
|
29 | XYAnimation::XYAnimation(XYChart *item):ChartAnimation(item), | |
30 | m_item(item), |
|
30 | m_item(item), | |
31 | m_dirty(false), |
|
31 | m_dirty(false), | |
32 | m_type(MoveDownAnimation) |
|
32 | m_type(MoveDownAnimation) |
@@ -26,13 +26,13 | |||||
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 |
class XYChart |
|
29 | class XYChart; | |
30 |
|
30 | |||
31 | class XYAnimation : public ChartAnimation |
|
31 | class XYAnimation : public ChartAnimation | |
32 | { |
|
32 | { | |
33 | public: |
|
33 | public: | |
34 | enum Animation { LineDrawAnimation, MoveDownAnimation, MoveUpAnimation }; |
|
34 | enum Animation { LineDrawAnimation, MoveDownAnimation, MoveUpAnimation }; | |
35 |
XYAnimation(XYChart |
|
35 | XYAnimation(XYChart *item); | |
36 | ~XYAnimation(); |
|
36 | ~XYAnimation(); | |
37 | void setValues(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index); |
|
37 | void setValues(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index); | |
38 | void setAnimationType(Animation type); |
|
38 | void setAnimationType(Animation type); | |
@@ -43,7 +43,7 protected: | |||||
43 | void updateCurrentValue (const QVariant &value ); |
|
43 | void updateCurrentValue (const QVariant &value ); | |
44 |
|
44 | |||
45 | private: |
|
45 | private: | |
46 |
XYChart |
|
46 | XYChart *m_item; | |
47 | QVector<QPointF> m_oldPoints; |
|
47 | QVector<QPointF> m_oldPoints; | |
48 | bool m_dirty; |
|
48 | bool m_dirty; | |
49 | Animation m_type; |
|
49 | Animation m_type; |
@@ -23,13 +23,15 | |||||
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 |
|
27 | |||
27 |
|
28 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
30 | |||
30 | //TODO: optimize : remove points which are not visible |
|
31 | //TODO: optimize : remove points which are not visible | |
31 |
|
32 | |||
32 |
LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter):XYChart |
|
33 | LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter):XYChart(series,presenter), | |
|
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), | |||
33 | m_series(series), |
|
35 | m_series(series), | |
34 | m_pointsVisible(false) |
|
36 | m_pointsVisible(false) | |
35 | { |
|
37 | { | |
@@ -67,6 +69,7 void LineChartItem::updateGeometry() | |||||
67 | prepareGeometryChange(); |
|
69 | prepareGeometryChange(); | |
68 | m_path = linePath; |
|
70 | m_path = linePath; | |
69 | m_rect = linePath.boundingRect(); |
|
71 | m_rect = linePath.boundingRect(); | |
|
72 | setPos(origin()); | |||
70 | } |
|
73 | } | |
71 |
|
74 | |||
72 | void LineChartItem::handleUpdated() |
|
75 | void LineChartItem::handleUpdated() | |
@@ -96,6 +99,11 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt | |||||
96 | painter->restore(); |
|
99 | painter->restore(); | |
97 | } |
|
100 | } | |
98 |
|
101 | |||
|
102 | void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |||
|
103 | { | |||
|
104 | emit XYChart::clicked(calculateDomainPoint(event->pos())); | |||
|
105 | } | |||
|
106 | ||||
99 | #include "moc_linechartitem_p.cpp" |
|
107 | #include "moc_linechartitem_p.cpp" | |
100 |
|
108 | |||
101 | QTCOMMERCIALCHART_END_NAMESPACE |
|
109 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -22,7 +22,7 | |||||
22 | #define LINECHARTITEM_H |
|
22 | #define LINECHARTITEM_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 |
#include "xychart |
|
25 | #include "xychart_p.h" | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
@@ -30,9 +30,10 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
30 | class QLineSeries; |
|
30 | class QLineSeries; | |
31 | class ChartPresenter; |
|
31 | class ChartPresenter; | |
32 |
|
32 | |||
33 | class LineChartItem : public XYChartItem |
|
33 | class LineChartItem : public XYChart , public QGraphicsItem | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
|
36 | Q_INTERFACES(QGraphicsItem) | |||
36 | public: |
|
37 | public: | |
37 | explicit LineChartItem(QLineSeries *series,ChartPresenter *presenter); |
|
38 | explicit LineChartItem(QLineSeries *series,ChartPresenter *presenter); | |
38 | ~LineChartItem() {}; |
|
39 | ~LineChartItem() {}; | |
@@ -46,6 +47,7 public Q_SLOTS: | |||||
46 | void handleUpdated(); |
|
47 | void handleUpdated(); | |
47 | protected: |
|
48 | protected: | |
48 | void updateGeometry(); |
|
49 | void updateGeometry(); | |
|
50 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |||
49 |
|
51 | |||
50 | private: |
|
52 | private: | |
51 | QLineSeries* m_series; |
|
53 | QLineSeries* m_series; |
@@ -1,22 +1,22 | |||||
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" | |
@@ -25,16 +25,17 | |||||
25 | #include <QPainter> |
|
25 | #include <QPainter> | |
26 | #include <QGraphicsScene> |
|
26 | #include <QGraphicsScene> | |
27 | #include <QDebug> |
|
27 | #include <QDebug> | |
|
28 | #include <QGraphicsSceneMouseEvent> | |||
28 |
|
29 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
31 | |||
31 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) : |
|
32 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) : | |
32 |
|
|
33 | XYChart(series,presenter), | |
33 | m_series(series), |
|
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), | |
34 | m_items(this), |
|
35 | m_series(series), | |
35 | m_shape(QScatterSeries::MarkerShapeRectangle), |
|
36 | m_items(this), | |
36 | m_size(15) |
|
37 | m_shape(QScatterSeries::MarkerShapeRectangle), | |
37 |
|
38 | m_size(15) | ||
38 | { |
|
39 | { | |
39 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated())); |
|
40 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated())); | |
40 |
|
41 | |||
@@ -52,7 +53,6 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *prese | |||||
52 | // setGraphicsEffect(dropShadow); |
|
53 | // setGraphicsEffect(dropShadow); | |
53 | } |
|
54 | } | |
54 |
|
55 | |||
55 |
|
||||
56 | QRectF ScatterChartItem::boundingRect() const |
|
56 | QRectF ScatterChartItem::boundingRect() const | |
57 | { |
|
57 | { | |
58 | return m_rect; |
|
58 | return m_rect; | |
@@ -65,22 +65,22 void ScatterChartItem::createPoints(int count) | |||||
65 | QGraphicsItem *item = 0; |
|
65 | QGraphicsItem *item = 0; | |
66 |
|
66 | |||
67 | switch (m_shape) { |
|
67 | switch (m_shape) { | |
68 |
|
|
68 | case QScatterSeries::MarkerShapeCircle: { | |
69 |
|
|
69 | QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size); | |
70 |
|
|
70 | const QRectF& rect = i->boundingRect(); | |
71 |
|
|
71 | i->setPos(-rect.width()/2,-rect.height()/2); | |
72 |
|
|
72 | item = new Marker(i,this); | |
73 |
|
|
73 | break; | |
74 |
|
|
74 | } | |
75 |
|
|
75 | case QScatterSeries::MarkerShapeRectangle: { | |
76 |
|
|
76 | QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size); | |
77 |
|
|
77 | i->setPos(-m_size/2,-m_size/2); | |
78 |
|
|
78 | item = new Marker(i,this); | |
79 |
|
|
79 | break; | |
80 |
|
|
80 | } | |
81 |
|
|
81 | default: | |
82 |
|
|
82 | qWarning()<<"Unsupported marker type"; | |
83 |
|
|
83 | break; | |
84 |
|
84 | |||
85 | } |
|
85 | } | |
86 | m_items.addToGroup(item); |
|
86 | m_items.addToGroup(item); | |
@@ -98,7 +98,7 void ScatterChartItem::deletePoints(int count) | |||||
98 |
|
98 | |||
99 | void ScatterChartItem::markerSelected(Marker *marker) |
|
99 | void ScatterChartItem::markerSelected(Marker *marker) | |
100 | { |
|
100 | { | |
101 |
emit XYChart |
|
101 | emit XYChart::clicked(marker->point()); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void ScatterChartItem::updateGeometry() |
|
104 | void ScatterChartItem::updateGeometry() | |
@@ -141,9 +141,9 void ScatterChartItem::updateGeometry() | |||||
141 |
|
141 | |||
142 | prepareGeometryChange(); |
|
142 | prepareGeometryChange(); | |
143 | m_rect = clipRect(); |
|
143 | m_rect = clipRect(); | |
|
144 | setPos(origin()); | |||
144 | } |
|
145 | } | |
145 |
|
146 | |||
146 |
|
||||
147 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
147 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
148 | { |
|
148 | { | |
149 | Q_UNUSED(painter) |
|
149 | Q_UNUSED(painter) | |
@@ -154,15 +154,15 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * | |||||
154 | void ScatterChartItem::setPen(const QPen& pen) |
|
154 | void ScatterChartItem::setPen(const QPen& pen) | |
155 | { |
|
155 | { | |
156 | foreach(QGraphicsItem* item , m_items.childItems()) { |
|
156 | foreach(QGraphicsItem* item , m_items.childItems()) { | |
157 |
|
|
157 | static_cast<Marker*>(item)->setPen(pen); | |
158 | } |
|
158 | } | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void ScatterChartItem::setBrush(const QBrush& brush) |
|
161 | void ScatterChartItem::setBrush(const QBrush& brush) | |
162 | { |
|
162 | { | |
163 | foreach(QGraphicsItem* item , m_items.childItems()) { |
|
163 | foreach(QGraphicsItem* item , m_items.childItems()) { | |
164 |
|
|
164 | static_cast<Marker*>(item)->setBrush(brush); | |
165 |
|
|
165 | } | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void ScatterChartItem::handleUpdated() |
|
168 | void ScatterChartItem::handleUpdated() | |
@@ -179,7 +179,7 void ScatterChartItem::handleUpdated() | |||||
179 | m_size = m_series->size(); |
|
179 | m_size = m_series->size(); | |
180 | m_shape = m_series->shape(); |
|
180 | m_shape = m_series->shape(); | |
181 |
|
181 | |||
182 | if(recreate){ |
|
182 | if(recreate) { | |
183 | deletePoints(count); |
|
183 | deletePoints(count); | |
184 | createPoints(count); |
|
184 | createPoints(count); | |
185 | } |
|
185 | } | |
@@ -188,6 +188,11 void ScatterChartItem::handleUpdated() | |||||
188 | setBrush(m_series->brush()); |
|
188 | setBrush(m_series->brush()); | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
|
191 | void ScatterChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |||
|
192 | { | |||
|
193 | emit XYChart::clicked(calculateDomainPoint(event->pos())); | |||
|
194 | } | |||
|
195 | ||||
191 | #include "moc_scatterchartitem_p.cpp" |
|
196 | #include "moc_scatterchartitem_p.cpp" | |
192 |
|
197 | |||
193 | QTCOMMERCIALCHART_END_NAMESPACE |
|
198 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -22,7 +22,7 | |||||
22 | #define SCATTERCHARTITEM_H |
|
22 | #define SCATTERCHARTITEM_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 |
#include "xychart |
|
25 | #include "xychart_p.h" | |
26 | #include <QGraphicsEllipseItem> |
|
26 | #include <QGraphicsEllipseItem> | |
27 | #include <QPen> |
|
27 | #include <QPen> | |
28 |
|
28 | |||
@@ -31,7 +31,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
31 | class QScatterSeries; |
|
31 | class QScatterSeries; | |
32 | class Marker; |
|
32 | class Marker; | |
33 |
|
33 | |||
34 | class ScatterChartItem : public XYChartItem |
|
34 | class ScatterChartItem : public XYChart, public QGraphicsItem | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 | public: |
|
37 | public: | |
@@ -56,6 +56,7 private: | |||||
56 |
|
56 | |||
57 | protected: |
|
57 | protected: | |
58 | void updateGeometry(); |
|
58 | void updateGeometry(); | |
|
59 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |||
59 |
|
60 | |||
60 | private: |
|
61 | private: | |
61 | QScatterSeries *m_series; |
|
62 | QScatterSeries *m_series; |
@@ -1,37 +1,38 | |||||
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 <QDebug> |
|
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 |
|
|
31 | XYChart(series, presenter), | |
32 | m_series(series), |
|
32 | QGraphicsItem(presenter ? presenter->rootItem() : 0), | |
33 | m_pointsVisible(false), |
|
33 | m_series(series), | |
34 | m_animation(0) |
|
34 | m_pointsVisible(false), | |
|
35 | m_animation(0) | |||
35 | { |
|
36 | { | |
36 | setZValue(ChartPresenter::LineChartZValue); |
|
37 | setZValue(ChartPresenter::LineChartZValue); | |
37 | QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
38 | QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); | |
@@ -51,7 +52,7 QPainterPath SplineChartItem::shape() const | |||||
51 | void SplineChartItem::setAnimation(SplineAnimation* animation) |
|
52 | void SplineChartItem::setAnimation(SplineAnimation* animation) | |
52 | { |
|
53 | { | |
53 | m_animation=animation; |
|
54 | m_animation=animation; | |
54 |
XYChart |
|
55 | XYChart::setAnimation(animation); | |
55 | } |
|
56 | } | |
56 |
|
57 | |||
57 | void SplineChartItem::setControlGeometryPoints(QVector<QPointF>& points) |
|
58 | void SplineChartItem::setControlGeometryPoints(QVector<QPointF>& points) | |
@@ -97,7 +98,7 void SplineChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> | |||||
97 |
|
98 | |||
98 | QPointF SplineChartItem::calculateGeometryControlPoint(int index) const |
|
99 | QPointF SplineChartItem::calculateGeometryControlPoint(int index) const | |
99 | { |
|
100 | { | |
100 |
return XYChart |
|
101 | return XYChart::calculateGeometryPoint(m_series->d_func()->controlPoint(index)); | |
101 | } |
|
102 | } | |
102 |
|
103 | |||
103 | void SplineChartItem::updateGeometry() |
|
104 | void SplineChartItem::updateGeometry() | |
@@ -122,6 +123,7 void SplineChartItem::updateGeometry() | |||||
122 | prepareGeometryChange(); |
|
123 | prepareGeometryChange(); | |
123 | m_path = splinePath; |
|
124 | m_path = splinePath; | |
124 | m_rect = splinePath.boundingRect(); |
|
125 | m_rect = splinePath.boundingRect(); | |
|
126 | setPos(origin()); | |||
125 | } |
|
127 | } | |
126 |
|
128 | |||
127 | //handlers |
|
129 | //handlers | |
@@ -152,7 +154,10 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o | |||||
152 | painter->restore(); |
|
154 | painter->restore(); | |
153 | } |
|
155 | } | |
154 |
|
156 | |||
155 |
|
157 | void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | ||
|
158 | { | |||
|
159 | emit XYChart::clicked(calculateDomainPoint(event->pos())); | |||
|
160 | } | |||
156 |
|
161 | |||
157 | #include "moc_splinechartitem_p.cpp" |
|
162 | #include "moc_splinechartitem_p.cpp" | |
158 |
|
163 |
@@ -22,14 +22,15 | |||||
22 | #define SPLINECHARTITEM_P_H |
|
22 | #define SPLINECHARTITEM_P_H | |
23 |
|
23 | |||
24 | #include "qsplineseries.h" |
|
24 | #include "qsplineseries.h" | |
25 |
#include "xychart |
|
25 | #include "xychart_p.h" | |
26 | #include "splineanimation_p.h" |
|
26 | #include "splineanimation_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | class SplineChartItem : public XYChartItem |
|
30 | class SplineChartItem : public XYChart, public QGraphicsItem | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
|
33 | Q_INTERFACES(QGraphicsItem) | |||
33 | public: |
|
34 | public: | |
34 | SplineChartItem(QSplineSeries *series, ChartPresenter *presenter); |
|
35 | SplineChartItem(QSplineSeries *series, ChartPresenter *presenter); | |
35 |
|
36 | |||
@@ -50,6 +51,7 public Q_SLOTS: | |||||
50 | protected: |
|
51 | protected: | |
51 | void updateGeometry(); |
|
52 | void updateGeometry(); | |
52 | void updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index); |
|
53 | void updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index); | |
|
54 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |||
53 |
|
55 | |||
54 | private: |
|
56 | private: | |
55 | QPointF calculateGeometryControlPoint(int index) const; |
|
57 | QPointF calculateGeometryControlPoint(int index) const; |
@@ -78,7 +78,7 private: | |||||
78 | Q_DECLARE_PRIVATE(QXYSeries); |
|
78 | Q_DECLARE_PRIVATE(QXYSeries); | |
79 | Q_DISABLE_COPY(QXYSeries); |
|
79 | Q_DISABLE_COPY(QXYSeries); | |
80 | friend class XYLegendMarker; |
|
80 | friend class XYLegendMarker; | |
81 |
friend class XYChart |
|
81 | friend class XYChart; | |
82 | }; |
|
82 | }; | |
83 |
|
83 | |||
84 | QTCOMMERCIALCHART_END_NAMESPACE |
|
84 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -18,22 +18,20 | |||||
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 |
#include "xychart |
|
21 | #include "xychart_p.h" | |
22 | #include "qxyseries.h" |
|
22 | #include "qxyseries.h" | |
23 | #include "qxyseries_p.h" |
|
23 | #include "qxyseries_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "chartanimator_p.h" |
|
25 | #include "chartanimator_p.h" | |
26 | #include <QPainter> |
|
26 | #include <QPainter> | |
27 | #include <QGraphicsSceneMouseEvent> |
|
|||
28 | #include <QAbstractItemModel> |
|
27 | #include <QAbstractItemModel> | |
29 | #include "qxymodelmapper.h" |
|
28 | #include "qxymodelmapper.h" | |
30 | #include <QDebug> |
|
|||
31 |
|
29 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
31 | |||
34 | //TODO: optimize : remove points which are not visible |
|
32 | //TODO: optimize : remove points which are not visible | |
35 |
|
33 | |||
36 |
XYChart |
|
34 | XYChart::XYChart(QXYSeries *series, ChartPresenter *presenter):Chart(presenter), | |
37 | m_minX(0), |
|
35 | m_minX(0), | |
38 | m_maxX(0), |
|
36 | m_maxX(0), | |
39 | m_minY(0), |
|
37 | m_minY(0), | |
@@ -50,22 +48,22 m_animation(0) | |||||
50 | QObject::connect(this,SIGNAL(clicked(QPointF)),series,SIGNAL(clicked(QPointF))); |
|
48 | QObject::connect(this,SIGNAL(clicked(QPointF)),series,SIGNAL(clicked(QPointF))); | |
51 | } |
|
49 | } | |
52 |
|
50 | |||
53 |
void XYChart |
|
51 | void XYChart::setGeometryPoints(QVector<QPointF>& points) | |
54 | { |
|
52 | { | |
55 | m_points = points; |
|
53 | m_points = points; | |
56 | } |
|
54 | } | |
57 |
|
55 | |||
58 |
void XYChart |
|
56 | void XYChart::setClipRect(const QRectF &rect) | |
59 | { |
|
57 | { | |
60 | m_clipRect = rect; |
|
58 | m_clipRect = rect; | |
61 | } |
|
59 | } | |
62 |
|
60 | |||
63 |
void XYChart |
|
61 | void XYChart::setAnimation(XYAnimation* animation) | |
64 | { |
|
62 | { | |
65 | m_animation=animation; |
|
63 | m_animation=animation; | |
66 | } |
|
64 | } | |
67 |
|
65 | |||
68 |
QPointF XYChart |
|
66 | QPointF XYChart::calculateGeometryPoint(const QPointF &point) const | |
69 | { |
|
67 | { | |
70 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); |
|
68 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
71 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); |
|
69 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
@@ -74,7 +72,7 QPointF XYChartItem::calculateGeometryPoint(const QPointF &point) const | |||||
74 | return QPointF(x,y); |
|
72 | return QPointF(x,y); | |
75 | } |
|
73 | } | |
76 |
|
74 | |||
77 |
QPointF XYChart |
|
75 | QPointF XYChart::calculateGeometryPoint(int index) const | |
78 | { |
|
76 | { | |
79 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); |
|
77 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
80 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); |
|
78 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
@@ -84,7 +82,7 QPointF XYChartItem::calculateGeometryPoint(int index) const | |||||
84 | return QPointF(x,y); |
|
82 | return QPointF(x,y); | |
85 | } |
|
83 | } | |
86 |
|
84 | |||
87 |
QVector<QPointF> XYChart |
|
85 | QVector<QPointF> XYChart::calculateGeometryPoints() const | |
88 | { |
|
86 | { | |
89 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); |
|
87 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
90 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); |
|
88 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
@@ -101,7 +99,7 QVector<QPointF> XYChartItem::calculateGeometryPoints() const | |||||
101 | return result; |
|
99 | return result; | |
102 | } |
|
100 | } | |
103 |
|
101 | |||
104 |
QPointF XYChart |
|
102 | QPointF XYChart::calculateDomainPoint(const QPointF &point) const | |
105 | { |
|
103 | { | |
106 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); |
|
104 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
107 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); |
|
105 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
@@ -110,7 +108,7 QPointF XYChartItem::calculateDomainPoint(const QPointF &point) const | |||||
110 | return QPointF(x,y); |
|
108 | return QPointF(x,y); | |
111 | } |
|
109 | } | |
112 |
|
110 | |||
113 |
void XYChart |
|
111 | void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index) | |
114 | { |
|
112 | { | |
115 | if (m_animation) { |
|
113 | if (m_animation) { | |
116 | m_animation->setValues(oldPoints, newPoints, index); |
|
114 | m_animation->setValues(oldPoints, newPoints, index); | |
@@ -122,13 +120,9 void XYChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &new | |||||
122 | } |
|
120 | } | |
123 | } |
|
121 | } | |
124 |
|
122 | |||
125 | void XYChartItem::updateGeometry() |
|
|||
126 | { |
|
|||
127 | update(); |
|
|||
128 | } |
|
|||
129 | //handlers |
|
123 | //handlers | |
130 |
|
124 | |||
131 |
void XYChart |
|
125 | void XYChart::handlePointAdded(int index) | |
132 | { |
|
126 | { | |
133 | if (m_series->model() == 0) { |
|
127 | if (m_series->model() == 0) { | |
134 | Q_ASSERT(index<m_series->count()); |
|
128 | Q_ASSERT(index<m_series->count()); | |
@@ -147,7 +141,7 void XYChartItem::handlePointAdded(int index) | |||||
147 | updateChart(m_points,points,index); |
|
141 | updateChart(m_points,points,index); | |
148 | } |
|
142 | } | |
149 |
|
143 | |||
150 |
void XYChart |
|
144 | void XYChart::handlePointsAdded(int start, int end) | |
151 | { |
|
145 | { | |
152 | if (m_series->model() == 0) { |
|
146 | if (m_series->model() == 0) { | |
153 | for (int i = start; i <= end; i++) |
|
147 | for (int i = start; i <= end; i++) | |
@@ -177,7 +171,7 void XYChartItem::handlePointsAdded(int start, int end) | |||||
177 | } |
|
171 | } | |
178 | } |
|
172 | } | |
179 |
|
173 | |||
180 |
void XYChart |
|
174 | void XYChart::handlePointRemoved(int index) | |
181 | { |
|
175 | { | |
182 | if (m_series->model() == 0) { |
|
176 | if (m_series->model() == 0) { | |
183 | Q_ASSERT(index<m_series->count() + 1); |
|
177 | Q_ASSERT(index<m_series->count() + 1); | |
@@ -193,7 +187,7 void XYChartItem::handlePointRemoved(int index) | |||||
193 | updateChart(m_points,points,index); |
|
187 | updateChart(m_points,points,index); | |
194 | } |
|
188 | } | |
195 |
|
189 | |||
196 |
void XYChart |
|
190 | void XYChart::handlePointsRemoved(int start, int end) | |
197 | { |
|
191 | { | |
198 | Q_UNUSED(start) |
|
192 | Q_UNUSED(start) | |
199 | Q_UNUSED(end) |
|
193 | Q_UNUSED(end) | |
@@ -244,7 +238,7 void XYChartItem::handlePointsRemoved(int start, int end) | |||||
244 |
|
238 | |||
245 | } |
|
239 | } | |
246 |
|
240 | |||
247 |
void XYChart |
|
241 | void XYChart::handlePointReplaced(int index) | |
248 | { |
|
242 | { | |
249 | Q_ASSERT(index<m_series->count()); |
|
243 | Q_ASSERT(index<m_series->count()); | |
250 | Q_ASSERT(index>=0); |
|
244 | Q_ASSERT(index>=0); | |
@@ -259,7 +253,7 void XYChartItem::handlePointReplaced(int index) | |||||
259 | updateChart(m_points,points,index); |
|
253 | updateChart(m_points,points,index); | |
260 | } |
|
254 | } | |
261 |
|
255 | |||
262 |
void XYChart |
|
256 | void XYChart::handleReinitialized() | |
263 | { |
|
257 | { | |
264 | QVector<QPointF> points = calculateGeometryPoints(); |
|
258 | QVector<QPointF> points = calculateGeometryPoints(); | |
265 |
|
259 | |||
@@ -270,7 +264,7 void XYChartItem::handleReinitialized() | |||||
270 | updateChart(m_points,points); |
|
264 | updateChart(m_points,points); | |
271 | } |
|
265 | } | |
272 |
|
266 | |||
273 |
void XYChart |
|
267 | void XYChart::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
274 | { |
|
268 | { | |
275 | m_minX=minX; |
|
269 | m_minX=minX; | |
276 | m_maxX=maxX; |
|
270 | m_maxX=maxX; | |
@@ -285,12 +279,12 void XYChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal | |||||
285 | updateChart(m_points,points); |
|
279 | updateChart(m_points,points); | |
286 | } |
|
280 | } | |
287 |
|
281 | |||
288 |
void XYChart |
|
282 | void XYChart::handleGeometryChanged(const QRectF &rect) | |
289 | { |
|
283 | { | |
290 | Q_ASSERT(rect.isValid()); |
|
284 | Q_ASSERT(rect.isValid()); | |
291 | m_size=rect.size(); |
|
285 | m_size=rect.size(); | |
292 | m_clipRect=rect.translated(-rect.topLeft()); |
|
286 | m_clipRect=rect.translated(-rect.topLeft()); | |
293 |
|
|
287 | m_origin=rect.topLeft(); | |
294 |
|
288 | |||
295 | if (isEmpty()) return; |
|
289 | if (isEmpty()) return; | |
296 | QVector<QPointF> points = calculateGeometryPoints(); |
|
290 | QVector<QPointF> points = calculateGeometryPoints(); | |
@@ -300,16 +294,11 void XYChartItem::handleGeometryChanged(const QRectF &rect) | |||||
300 | updateChart(m_points,points); |
|
294 | updateChart(m_points,points); | |
301 | } |
|
295 | } | |
302 |
|
296 | |||
303 |
bool XYChart |
|
297 | bool XYChart::isEmpty() | |
304 | { |
|
298 | { | |
305 | return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY) || m_series->points().isEmpty(); |
|
299 | return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY) || m_series->points().isEmpty(); | |
306 | } |
|
300 | } | |
307 |
|
301 | |||
308 | void XYChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
302 | #include "moc_xychart_p.cpp" | |
309 | { |
|
|||
310 | emit clicked(calculateDomainPoint(event->pos())); |
|
|||
311 | } |
|
|||
312 |
|
||||
313 | #include "moc_xychartitem_p.cpp" |
|
|||
314 |
|
303 | |||
315 | QTCOMMERCIALCHART_END_NAMESPACE |
|
304 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -2,12 +2,12 INCLUDEPATH += $$PWD | |||||
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 |
$$PWD/xychart |
|
5 | $$PWD/xychart.cpp \ | |
6 | $$PWD/qxyseries.cpp \ |
|
6 | $$PWD/qxyseries.cpp \ | |
7 | $$PWD/qxymodelmapper.cpp |
|
7 | $$PWD/qxymodelmapper.cpp | |
8 |
|
8 | |||
9 | PRIVATE_HEADERS += \ |
|
9 | PRIVATE_HEADERS += \ | |
10 |
$$PWD/xychart |
|
10 | $$PWD/xychart_p.h \ | |
11 | $$PWD/qxyseries_p.h |
|
11 | $$PWD/qxyseries_p.h | |
12 |
|
12 | |||
13 |
|
13 |
@@ -31,12 +31,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
31 | class ChartPresenter; |
|
31 | class ChartPresenter; | |
32 | class QXYSeries; |
|
32 | class QXYSeries; | |
33 |
|
33 | |||
34 |
class XYChart |
|
34 | class XYChart : public Chart | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 | public: |
|
37 | public: | |
38 |
explicit XYChart |
|
38 | explicit XYChart(QXYSeries *series, ChartPresenter *presenter); | |
39 |
~XYChart |
|
39 | ~XYChart(){}; | |
40 |
|
40 | |||
41 | void setGeometryPoints(QVector<QPointF>& points); |
|
41 | void setGeometryPoints(QVector<QPointF>& points); | |
42 | QVector<QPointF> geometryPoints() const { return m_points; } |
|
42 | QVector<QPointF> geometryPoints() const { return m_points; } | |
@@ -44,9 +44,12 public: | |||||
44 | void setClipRect(const QRectF &rect); |
|
44 | void setClipRect(const QRectF &rect); | |
45 | QRectF clipRect() const { return m_clipRect; } |
|
45 | QRectF clipRect() const { return m_clipRect; } | |
46 |
|
46 | |||
|
47 | QSizeF size() const { return m_size; } | |||
|
48 | QPointF origin() const { return m_origin; } | |||
|
49 | ||||
47 | void setAnimation(XYAnimation* animation); |
|
50 | void setAnimation(XYAnimation* animation); | |
48 | ChartAnimation* animation() const { return m_animation; } |
|
51 | ChartAnimation* animation() const { return m_animation; } | |
49 | virtual void updateGeometry(); |
|
52 | virtual void updateGeometry() = 0; | |
50 |
|
53 | |||
51 | public Q_SLOTS: |
|
54 | public Q_SLOTS: | |
52 | void handlePointAdded(int index); |
|
55 | void handlePointAdded(int index); | |
@@ -67,7 +70,6 protected: | |||||
67 | QPointF calculateGeometryPoint(int index) const; |
|
70 | QPointF calculateGeometryPoint(int index) const; | |
68 | QPointF calculateDomainPoint(const QPointF &point) const; |
|
71 | QPointF calculateDomainPoint(const QPointF &point) const; | |
69 | QVector<QPointF> calculateGeometryPoints() const; |
|
72 | QVector<QPointF> calculateGeometryPoints() const; | |
70 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
|||
71 |
|
73 | |||
72 | private: |
|
74 | private: | |
73 | inline bool isEmpty(); |
|
75 | inline bool isEmpty(); | |
@@ -79,6 +81,7 private: | |||||
79 | qreal m_maxY; |
|
81 | qreal m_maxY; | |
80 | QXYSeries* m_series; |
|
82 | QXYSeries* m_series; | |
81 | QSizeF m_size; |
|
83 | QSizeF m_size; | |
|
84 | QPointF m_origin; | |||
82 | QRectF m_clipRect; |
|
85 | QRectF m_clipRect; | |
83 | QVector<QPointF> m_points; |
|
86 | QVector<QPointF> m_points; | |
84 | XYAnimation* m_animation; |
|
87 | XYAnimation* m_animation; |
General Comments 0
You need to be logged in to leave comments.
Login now