##// END OF EJS Templates
Adds cliping and proper zoom handling for line chart
Michal Klocek -
r150:19743dc8af25
parent child
Show More
@@ -1,202 +1,207
1 #include "linechartitem_p.h"
1 #include "linechartitem_p.h"
2 #include "qlinechartseries.h"
2 #include "qlinechartseries.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include <QPainter>
4 #include <QPainter>
5
5
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 //TODO: optimazie : remove points which are not visible
10
9 LineChartItem::LineChartItem(ChartPresenter* presenter, QLineChartSeries* series,QGraphicsItem *parent):ChartItem(parent),
11 LineChartItem::LineChartItem(ChartPresenter* presenter, QLineChartSeries* series,QGraphicsItem *parent):ChartItem(parent),
10 m_presenter(presenter),
12 m_presenter(presenter),
11 m_series(series),
13 m_series(series),
12 m_dirtyData(false),
14 m_dirtyData(false),
13 m_dirtyGeometry(false),
15 m_dirtyGeometry(false),
14 m_dirtyDomain(false)
16 m_dirtyDomain(false)
15 {
17 {
16 }
18 }
17
19
18 QRectF LineChartItem::boundingRect() const
20 QRectF LineChartItem::boundingRect() const
19 {
21 {
20 return m_rect;
22 return m_rect;
21 }
23 }
22
24
23 QPainterPath LineChartItem::shape() const
25 QPainterPath LineChartItem::shape() const
24 {
26 {
25 return m_path;
27 return m_path;
26 }
28 }
27
29
28
30
29 void LineChartItem::addPoints(const QVector<QPointF>& points)
31 void LineChartItem::addPoints(const QVector<QPointF>& points)
30 {
32 {
31 m_data = points;
33 m_data = points;
32 for(int i=0; i<m_data.size();i++){
34 for(int i=0; i<m_data.size();i++){
33 const QPointF& point =m_data[i];
35 const QPointF& point =m_data[i];
34 QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this);
36 QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this);
35 item->setPos(point.x()-1,point.y()-1);
37 item->setPos(point.x()-1,point.y()-1);;
38 if(!m_clipRect.contains(point)) item->setVisible(false);
36 m_points << item;
39 m_points << item;
37 }
40 }
38 }
41 }
39
42
40 void LineChartItem::addPoint(const QPointF& point)
43 void LineChartItem::addPoint(const QPointF& point)
41 {
44 {
42 m_data << point;
45 m_data << point;
43 QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this);
46 QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3,this);
47 m_clipRect.contains(point);
44 item->setPos(point.x()-1,point.y()-1);
48 item->setPos(point.x()-1,point.y()-1);
49 if(!m_clipRect.contains(point)) item->setVisible(false);
45 m_points << item;
50 m_points << item;
46 }
51 }
47
52
48 void LineChartItem::removePoint(const QPointF& point)
53 void LineChartItem::removePoint(const QPointF& point)
49 {
54 {
50 Q_ASSERT(m_data.count() == m_points.count());
55 Q_ASSERT(m_data.count() == m_points.count());
51 int index = m_data.lastIndexOf(point,0);
56 int index = m_data.lastIndexOf(point,0);
52 m_data.remove(index);
57 m_data.remove(index);
53 delete(m_points.takeAt(index));
58 delete(m_points.takeAt(index));
54 }
59 }
55
60
56 void LineChartItem::setPoint(const QPointF& oldPoint,const QPointF& newPoint)
61 void LineChartItem::setPoint(const QPointF& oldPoint,const QPointF& newPoint)
57 {
62 {
58 Q_ASSERT(m_data.count() == m_points.count());
63 Q_ASSERT(m_data.count() == m_points.count());
59 int index = m_data.lastIndexOf(oldPoint,0);
64 int index = m_data.lastIndexOf(oldPoint,0);
60
65
61 if(index > -1){
66 if(index > -1){
62 m_data.replace(index,newPoint);
67 m_data.replace(index,newPoint);
63 QGraphicsItem* item = m_points.at(index);
68 QGraphicsItem* item = m_points.at(index);
64 item->setPos(newPoint.x()-1,newPoint.y()-1);
69 item->setPos(newPoint.x()-1,newPoint.y()-1);
65 }
70 }
66 }
71 }
67
72
68 void LineChartItem::setPoint(int index,const QPointF& point)
73 void LineChartItem::setPoint(int index,const QPointF& point)
69 {
74 {
70 Q_ASSERT(m_data.count() == m_points.count());
75 Q_ASSERT(m_data.count() == m_points.count());
71 Q_ASSERT(index>=0);
76 Q_ASSERT(index>=0);
72
77
73 m_data.replace(index,point);
78 m_data.replace(index,point);
74 QGraphicsItem* item = m_points.at(index);
79 QGraphicsItem* item = m_points.at(index);
75 item->setPos(point.x()-1,point.y()-1);
80 item->setPos(point.x()-1,point.y()-1);
76 }
81 }
77
82
78 void LineChartItem::clear()
83 void LineChartItem::clear()
79 {
84 {
80 qDeleteAll(m_points);
85 qDeleteAll(m_points);
81 m_points.clear();
86 m_points.clear();
82 m_hash.clear();
87 m_hash.clear();
83 m_path = QPainterPath();
88 m_path = QPainterPath();
84 m_rect = QRect();
89 m_rect = QRect();
85 m_data.clear();
90 m_data.clear();
86 }
91 }
87
92
88 void LineChartItem::clearView()
93 void LineChartItem::clearView()
89 {
94 {
90 qDeleteAll(m_points);
95 qDeleteAll(m_points);
91 m_points.clear();
96 m_points.clear();
92 m_path = QPainterPath();
97 m_path = QPainterPath();
93 m_rect = QRect();
98 m_rect = QRect();
94 m_data.clear();
99 m_data.clear();
95 }
100 }
96
101
97 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
102 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
98 {
103 {
99 Q_UNUSED(widget);
104 Q_UNUSED(widget);
100 Q_UNUSED(option);
105 Q_UNUSED(option);
101 painter->setPen(m_pen);
106 painter->setPen(m_pen);
107 painter->setClipRect(m_clipRect);
102 painter->drawPath(m_path);
108 painter->drawPath(m_path);
103 }
109 }
104
110
105 void LineChartItem::calculatePoint(QPointF& point, int index, const QLineChartSeries* series,const QSizeF& size, const Domain& domain) const
111 void LineChartItem::calculatePoint(QPointF& point, int index, const QLineChartSeries* series,const QSizeF& size, const Domain& domain) const
106 {
112 {
107 const qreal deltaX = size.width()/domain.spanX();
113 const qreal deltaX = size.width()/domain.spanX();
108 const qreal deltaY = size.height()/domain.spanY();
114 const qreal deltaY = size.height()/domain.spanY();
109 qreal x = (series->x(index) - domain.m_minX)* deltaX;
115 qreal x = (series->x(index) - domain.m_minX)* deltaX;
110 qreal y = (series->y(index) - domain.m_minY)*-deltaY + size.height();
116 qreal y = (series->y(index) - domain.m_minY)*-deltaY + size.height();
111 point.setX(x);
117 point.setX(x);
112 point.setY(y);
118 point.setY(y);
113 }
119 }
114
120
115
121
116 void LineChartItem::calculatePoints(QVector<QPointF>& points, QHash<int,int>& hash,const QLineChartSeries* series,const QSizeF& size, const Domain& domain) const
122 void LineChartItem::calculatePoints(QVector<QPointF>& points, QHash<int,int>& hash,const QLineChartSeries* series,const QSizeF& size, const Domain& domain) const
117 {
123 {
118 const qreal deltaX = size.width()/domain.spanX();
124 const qreal deltaX = size.width()/domain.spanX();
119 const qreal deltaY = size.height()/domain.spanY();
125 const qreal deltaY = size.height()/domain.spanY();
120
126
121 for (int i = 0; i < series->count(); ++i) {
127 for (int i = 0; i < series->count(); ++i) {
122 qreal x = (series->x(i) - domain.m_minX)* deltaX;
128 qreal x = (series->x(i) - domain.m_minX)* deltaX;
123 if(x<0 || x > size.width()) continue;
124 qreal y = (series->y(i) - domain.m_minY)*-deltaY + size.height();
129 qreal y = (series->y(i) - domain.m_minY)*-deltaY + size.height();
125 if(y<0 || y > size.height()) continue;
126 hash[i] = points.size();
130 hash[i] = points.size();
127 points << QPointF(x,y);
131 points << QPointF(x,y);
128 }
132 }
129 }
133 }
130
134
131 void LineChartItem::updateDomain()
135 void LineChartItem::updateDomain()
132 {
136 {
133 clear();
137 clear();
138 prepareGeometryChange();
134 calculatePoints(m_data,m_hash,m_series,m_size, m_domain);
139 calculatePoints(m_data,m_hash,m_series,m_size, m_domain);
135 addPoints(m_data);
140 addPoints(m_data);
136 }
141 }
137
142
138 void LineChartItem::updateData()
143 void LineChartItem::updateData()
139 {
144 {
140 //for now the same
145 //for now the same
141 updateDomain();
146 updateDomain();
142 }
147 }
143
148
144 void LineChartItem::updateGeometry()
149 void LineChartItem::updateGeometry()
145 {
150 {
146
151
147 if(m_data.size()==0) return;
152 if(m_data.size()==0) return;
148
153
149 prepareGeometryChange();
154 prepareGeometryChange();
150 QPainterPath path;
155 QPainterPath path;
151 const QPointF& point = m_data.at(0);
156 const QPointF& point = m_data.at(0);
152 path.moveTo(point);
157 path.moveTo(point);
153
158
154 foreach( const QPointF& point , m_data) {
159 foreach( const QPointF& point , m_data) {
155 path.lineTo(point);
160 path.lineTo(point);
156 }
161 }
157
162
158 m_path = path;
163 m_path = path;
159 m_rect = path.boundingRect();
164 m_rect = path.boundingRect();
160 }
165 }
161
166
162 void LineChartItem::setPen(const QPen& pen)
167 void LineChartItem::setPen(const QPen& pen)
163 {
168 {
164 m_pen = pen;
169 m_pen = pen;
165 }
170 }
166
171
167 //handlers
172 //handlers
168
173
169 void LineChartItem::handleModelChanged(int index)
174 void LineChartItem::handleModelChanged(int index)
170 {
175 {
171 Q_ASSERT(index<m_series->count());
176 Q_ASSERT(index<m_series->count());
172 if(m_hash.contains(index)){
177 if(m_hash.contains(index)){
173 int i = m_hash.value(index);
178 int i = m_hash.value(index);
174 QPointF point;
179 QPointF point;
175 calculatePoint(point,index,m_series,m_size,m_domain);
180 calculatePoint(point,index,m_series,m_size,m_domain);
176 setPoint(i,point);
181 setPoint(i,point);
177 }
182 }
178 update();
183 update();
179 }
184 }
180
185
181 void LineChartItem::handleDomainChanged(const Domain& domain)
186 void LineChartItem::handleDomainChanged(const Domain& domain)
182 {
187 {
183 m_domain = domain;
188 m_domain = domain;
184 updateDomain();
189 updateDomain();
185 update();
190 update();
186 }
191 }
187
192
188 void LineChartItem::handleGeometryChanged(const QRectF& rect)
193 void LineChartItem::handleGeometryChanged(const QRectF& rect)
189 {
194 {
190 Q_ASSERT(rect.isValid());
195 Q_ASSERT(rect.isValid());
191
192 m_size=rect.size();
196 m_size=rect.size();
197 m_clipRect=rect.translated(-rect.topLeft());
193 updateDomain();
198 updateDomain();
194 updateGeometry();
199 updateGeometry();
195 setPos(rect.topLeft());
200 setPos(rect.topLeft());
196 update();
201 update();
197 }
202 }
198
203
199
204
200 #include "moc_linechartitem_p.cpp"
205 #include "moc_linechartitem_p.cpp"
201
206
202 QTCOMMERCIALCHART_END_NAMESPACE
207 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,72 +1,73
1 #ifndef LINECHARTITEM_H
1 #ifndef LINECHARTITEM_H
2 #define LINECHARTITEM_H
2 #define LINECHARTITEM_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "chartitem_p.h"
5 #include "chartitem_p.h"
6 #include <QPen>
6 #include <QPen>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class ChartPresenter;
10 class ChartPresenter;
11 class QLineChartSeries;
11 class QLineChartSeries;
12 class LineChartAnimationItem;
12 class LineChartAnimationItem;
13
13
14 class LineChartItem : public QObject , public ChartItem
14 class LineChartItem : public QObject , public ChartItem
15 {
15 {
16 Q_OBJECT
16 Q_OBJECT
17 public:
17 public:
18 LineChartItem(ChartPresenter* presenter, QLineChartSeries* series,QGraphicsItem *parent = 0);
18 LineChartItem(ChartPresenter* presenter, QLineChartSeries* series,QGraphicsItem *parent = 0);
19 ~ LineChartItem(){};
19 ~ LineChartItem(){};
20
20
21 //from QGraphicsItem
21 //from QGraphicsItem
22 QRectF boundingRect() const;
22 QRectF boundingRect() const;
23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
24 QPainterPath shape() const;
24 QPainterPath shape() const;
25
25
26 void setPen(const QPen& pen);
26 void setPen(const QPen& pen);
27 const Domain& domain() const { return m_domain;}
27 const Domain& domain() const { return m_domain;}
28
28
29 virtual void addPoint(const QPointF& );
29 virtual void addPoint(const QPointF& );
30 virtual void addPoints(const QVector<QPointF>& points);
30 virtual void addPoints(const QVector<QPointF>& points);
31 virtual void removePoint(const QPointF& point);
31 virtual void removePoint(const QPointF& point);
32 virtual void setPoint(const QPointF& oldPoint, const QPointF& newPoint);
32 virtual void setPoint(const QPointF& oldPoint, const QPointF& newPoint);
33 virtual void setPoint(int index,const QPointF& point);
33 virtual void setPoint(int index,const QPointF& point);
34 void clear();
34 void clear();
35 void clearView();
35 void clearView();
36 int count() const { return m_data.size();}
36 int count() const { return m_data.size();}
37
37
38 const QVector<QPointF>& points(){ return m_data;}
38 const QVector<QPointF>& points(){ return m_data;}
39
39
40 protected:
40 protected:
41 virtual void updateGeometry();
41 virtual void updateGeometry();
42 virtual void updateData();
42 virtual void updateData();
43 virtual void updateDomain();
43 virtual void updateDomain();
44 //refactor
44 //refactor
45 void calculatePoint(QPointF& point, int index, const QLineChartSeries* series,const QSizeF& size, const Domain& domain) const;
45 void calculatePoint(QPointF& point, int index, const QLineChartSeries* series,const QSizeF& size, const Domain& domain) const;
46 void calculatePoints(QVector<QPointF>& points,QHash<int,int>& hash,const QLineChartSeries* series, const QSizeF& size, const Domain& domain) const;
46 void calculatePoints(QVector<QPointF>& points,QHash<int,int>& hash,const QLineChartSeries* series, const QSizeF& size, const Domain& domain) const;
47
47
48 protected slots:
48 protected slots:
49 void handleModelChanged(int index);
49 void handleModelChanged(int index);
50 void handleDomainChanged(const Domain& domain);
50 void handleDomainChanged(const Domain& domain);
51 void handleGeometryChanged(const QRectF& size);
51 void handleGeometryChanged(const QRectF& size);
52
52
53 private:
53 private:
54 ChartPresenter* m_presenter;
54 ChartPresenter* m_presenter;
55 QPainterPath m_path;
55 QPainterPath m_path;
56 QSizeF m_size;
56 QSizeF m_size;
57 QRectF m_rect;
57 QRectF m_rect;
58 QRectF m_clipRect;
58 Domain m_domain;
59 Domain m_domain;
59 QList<QGraphicsItem*> m_points;
60 QList<QGraphicsItem*> m_points;
60 QVector<QPointF> m_data;
61 QVector<QPointF> m_data;
61 QHash<int,int> m_hash;
62 QHash<int,int> m_hash;
62 QLineChartSeries* m_series;
63 QLineChartSeries* m_series;
63 QPen m_pen;
64 QPen m_pen;
64 bool m_dirtyData;
65 bool m_dirtyData;
65 bool m_dirtyGeometry;
66 bool m_dirtyGeometry;
66 bool m_dirtyDomain;
67 bool m_dirtyDomain;
67
68
68 };
69 };
69
70
70 QTCOMMERCIALCHART_END_NAMESPACE
71 QTCOMMERCIALCHART_END_NAMESPACE
71
72
72 #endif
73 #endif
@@ -1,190 +1,190
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qscatterseries.h"
2 #include "qscatterseries.h"
3 #include "qscatterseries_p.h"
3 #include "qscatterseries_p.h"
4 #include "qpieseries.h"
4 #include "qpieseries.h"
5 #include "qchartaxis.h"
5 #include "qchartaxis.h"
6 #include "chartpresenter_p.h"
6 #include "chartpresenter_p.h"
7 #include "chartdataset_p.h"
7 #include "chartdataset_p.h"
8
8
9 //series
9 //series
10 #include "barchartseries.h"
10 #include "barchartseries.h"
11 #include "stackedbarchartseries.h"
11 #include "stackedbarchartseries.h"
12 #include "percentbarchartseries.h"
12 #include "percentbarchartseries.h"
13 #include "qlinechartseries.h"
13 #include "qlinechartseries.h"
14
14
15 #include <QGraphicsScene>
15 #include <QGraphicsScene>
16 #include <QGraphicsSceneResizeEvent>
16 #include <QGraphicsSceneResizeEvent>
17 #include <QDebug>
17 #include <QDebug>
18
18
19 QTCOMMERCIALCHART_BEGIN_NAMESPACE
19 QTCOMMERCIALCHART_BEGIN_NAMESPACE
20
20
21 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
21 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
22 m_backgroundItem(0),
22 m_backgroundItem(0),
23 m_titleItem(0),
23 m_titleItem(0),
24 m_dataset(new ChartDataSet(this)),
24 m_dataset(new ChartDataSet(this)),
25 m_presenter(new ChartPresenter(this,m_dataset))
25 m_presenter(new ChartPresenter(this,m_dataset))
26 {
26 {
27 }
27 }
28
28
29 QChart::~QChart() {}
29 QChart::~QChart() {}
30
30
31 void QChart::addSeries(QChartSeries* series)
31 void QChart::addSeries(QChartSeries* series)
32 {
32 {
33 m_dataset->addSeries(series);
33 m_dataset->addSeries(series);
34 }
34 }
35
35
36 //TODO on review, is it really needed ??
36 //TODO on review, is it really needed ??
37 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
37 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
38 {
38 {
39 // TODO: support also other types; not only scatter and pie
39 // TODO: support also other types; not only scatter and pie
40
40
41 QChartSeries *series(0);
41 QChartSeries *series(0);
42
42
43 switch (type) {
43 switch (type) {
44 case QChartSeries::SeriesTypeLine: {
44 case QChartSeries::SeriesTypeLine: {
45 series = QLineChartSeries::create();
45 series = QLineChartSeries::create();
46 break;
46 break;
47 }
47 }
48 case QChartSeries::SeriesTypeBar: {
48 case QChartSeries::SeriesTypeBar: {
49 series = new BarChartSeries(this);
49 series = new BarChartSeries(this);
50 break;
50 break;
51 }
51 }
52 case QChartSeries::SeriesTypeStackedBar: {
52 case QChartSeries::SeriesTypeStackedBar: {
53 series = new StackedBarChartSeries(this);
53 series = new StackedBarChartSeries(this);
54 break;
54 break;
55 }
55 }
56 case QChartSeries::SeriesTypePercentBar: {
56 case QChartSeries::SeriesTypePercentBar: {
57 series = new PercentBarChartSeries(this);
57 series = new PercentBarChartSeries(this);
58 break;
58 break;
59 }
59 }
60 case QChartSeries::SeriesTypeScatter: {
60 case QChartSeries::SeriesTypeScatter: {
61 series = new QScatterSeries(this);
61 series = new QScatterSeries(this);
62 break;
62 break;
63 }
63 }
64 case QChartSeries::SeriesTypePie: {
64 case QChartSeries::SeriesTypePie: {
65 series = new QPieSeries(this);
65 series = new QPieSeries(this);
66 break;
66 break;
67 }
67 }
68 default:
68 default:
69 Q_ASSERT(false);
69 Q_ASSERT(false);
70 break;
70 break;
71 }
71 }
72
72
73 addSeries(series);
73 addSeries(series);
74 return series;
74 return series;
75 }
75 }
76
76
77 void QChart::setChartBackgroundBrush(const QBrush& brush)
77 void QChart::setChartBackgroundBrush(const QBrush& brush)
78 {
78 {
79
79
80 if(!m_backgroundItem) {
80 if(!m_backgroundItem) {
81 m_backgroundItem = new QGraphicsRectItem(this);
81 m_backgroundItem = new QGraphicsRectItem(this);
82 m_backgroundItem->setZValue(-1);
82 m_backgroundItem->setZValue(-1);
83 }
83 }
84
84
85 m_backgroundItem->setBrush(brush);
85 m_backgroundItem->setBrush(brush);
86 m_backgroundItem->update();
86 m_backgroundItem->update();
87 }
87 }
88
88
89 void QChart::setChartBackgroundPen(const QPen& pen)
89 void QChart::setChartBackgroundPen(const QPen& pen)
90 {
90 {
91
91
92 if(!m_backgroundItem) {
92 if(!m_backgroundItem) {
93 m_backgroundItem = new QGraphicsRectItem(this);
93 m_backgroundItem = new QGraphicsRectItem(this);
94 m_backgroundItem->setZValue(-1);
94 m_backgroundItem->setZValue(-1);
95 }
95 }
96
96
97 m_backgroundItem->setPen(pen);
97 m_backgroundItem->setPen(pen);
98 m_backgroundItem->update();
98 m_backgroundItem->update();
99 }
99 }
100
100
101 void QChart::setTitle(const QString& title,const QFont& font)
101 void QChart::setTitle(const QString& title,const QFont& font)
102 {
102 {
103 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
103 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
104 m_titleItem->setPlainText(title);
104 m_titleItem->setPlainText(title);
105 m_titleItem->setFont(font);
105 m_titleItem->setFont(font);
106 }
106 }
107
107
108 int QChart::margin() const
108 int QChart::margin() const
109 {
109 {
110 return m_presenter->margin();
110 return m_presenter->margin();
111 }
111 }
112
112
113 void QChart::setMargin(int margin)
113 void QChart::setMargin(int margin)
114 {
114 {
115 m_presenter->setMargin(margin);
115 m_presenter->setMargin(margin);
116 }
116 }
117
117
118 void QChart::setTheme(QChart::ChartThemeId theme)
118 void QChart::setTheme(QChart::ChartThemeId theme)
119 {
119 {
120 m_presenter->setTheme(theme);
120 m_presenter->setTheme(theme);
121 }
121 }
122
122
123 QChart::ChartThemeId QChart::theme()
123 QChart::ChartThemeId QChart::theme()
124 {
124 {
125 return (QChart::ChartThemeId) m_presenter->theme();
125 return m_presenter->theme();
126 }
126 }
127
127
128 void QChart::zoomInToRect(const QRectF& rectangle)
128 void QChart::zoomInToRect(const QRectF& rectangle)
129 {
129 {
130 m_presenter->zoomInToRect(rectangle);
130 m_presenter->zoomInToRect(rectangle);
131 }
131 }
132
132
133 void QChart::zoomIn()
133 void QChart::zoomIn()
134 {
134 {
135 m_presenter->zoomIn();
135 m_presenter->zoomIn();
136 }
136 }
137
137
138 void QChart::zoomOut()
138 void QChart::zoomOut()
139 {
139 {
140 m_presenter->zoomOut();
140 m_presenter->zoomOut();
141 }
141 }
142
142
143 void QChart::zoomReset()
143 void QChart::zoomReset()
144 {
144 {
145 m_presenter->zoomReset();
145 m_presenter->zoomReset();
146 }
146 }
147
147
148 void QChart::setAxisX(const QChartAxis& axis)
148 void QChart::setAxisX(const QChartAxis& axis)
149 {
149 {
150
150
151 }
151 }
152 void QChart::setAxisY(const QChartAxis& axis)
152 void QChart::setAxisY(const QChartAxis& axis)
153 {
153 {
154
154
155 }
155 }
156
156
157 void QChart::setAxisY(const QList<QChartAxis>& axis)
157 void QChart::setAxisY(const QList<QChartAxis>& axis)
158 {
158 {
159 //TODO not implemented
159 //TODO not implemented
160 }
160 }
161
161
162 void QChart::setAxis(AxisItem *item, const QChartAxis& axis)
162 void QChart::setAxis(AxisItem *item, const QChartAxis& axis)
163 {
163 {
164
164
165 }
165 }
166
166
167 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
167 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
168 {
168 {
169
169
170 m_rect = QRectF(QPoint(0,0),event->newSize());
170 m_rect = QRectF(QPoint(0,0),event->newSize());
171 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
171 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
172
172
173 // recalculate title position
173 // recalculate title position
174 if (m_titleItem) {
174 if (m_titleItem) {
175 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
175 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
176 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
176 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
177 }
177 }
178
178
179 //recalculate background gradient
179 //recalculate background gradient
180 if (m_backgroundItem) {
180 if (m_backgroundItem) {
181 m_backgroundItem->setRect(rect);
181 m_backgroundItem->setRect(rect);
182 }
182 }
183
183
184 QGraphicsWidget::resizeEvent(event);
184 QGraphicsWidget::resizeEvent(event);
185 update();
185 update();
186 }
186 }
187
187
188 #include "moc_qchart.cpp"
188 #include "moc_qchart.cpp"
189
189
190 QTCOMMERCIALCHART_END_NAMESPACE
190 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now