@@ -28,7 +28,8 public: | |||
|
28 | 28 | XYGrid* m_grid; |
|
29 | 29 | QRect m_rect; |
|
30 | 30 | QList<const QChartSeries*> m_series; |
|
31 |
QList<XYPlotDomain> m_plotD |
|
|
31 | QList<XYPlotDomain> m_plotDomainList; | |
|
32 | QList<XYLineChartItem*> m_xyLineChartItems; | |
|
32 | 33 | QList<QGraphicsItem*> m_items; |
|
33 | 34 | int m_plotDataIndex; |
|
34 | 35 | int m_marginSize; |
@@ -44,21 +45,6 d_ptr(new QChartPrivate(this)) | |||
|
44 | 45 | // set axis |
|
45 | 46 | Q_D(QChart); |
|
46 | 47 | d->m_axisY->rotate(90); |
|
47 | ||
|
48 | //TODO hardcoded values , to removed soon | |
|
49 | XYPlotDomain data; | |
|
50 | data.m_minX = 0.0; | |
|
51 | data.m_maxX = 100.0; | |
|
52 | data.m_minY = 0.0; | |
|
53 | data.m_maxY = 100.0; | |
|
54 | data.m_ticksX=4; | |
|
55 | data.m_ticksY=4; | |
|
56 | ||
|
57 | d->m_plotDataList.clear(); | |
|
58 | d->m_plotDataList << data; | |
|
59 | ||
|
60 | d->m_grid->setZValue(10); | |
|
61 | d->m_grid->setXYPlotData(d->m_plotDataList.at(0)); | |
|
62 | 48 | } |
|
63 | 49 | |
|
64 | 50 | QChart::~QChart(){} |
@@ -78,9 +64,28 void QChart::addSeries(QChartSeries* series) | |||
|
78 | 64 | switch(series->type()) |
|
79 | 65 | { |
|
80 | 66 | case QChartSeries::SeriesTypeLine: { |
|
81 | XYLineChartItem* item = new XYLineChartItem(static_cast<QXYChartSeries*>(series),this); | |
|
82 | item->updateXYPlotData(d->m_plotDataList.at(0)); | |
|
83 | d->m_items<<item; | |
|
67 | ||
|
68 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); | |
|
69 | ||
|
70 | XYPlotDomain domain; | |
|
71 | //TODO "nice numbers algorithm" | |
|
72 | domain.m_ticksX=4; | |
|
73 | domain.m_ticksY=4; | |
|
74 | ||
|
75 | for (int i = 0 ; i < xyseries->count() ; i++) | |
|
76 | { | |
|
77 | qreal x = xyseries->x(i); | |
|
78 | qreal y = xyseries->y(i); | |
|
79 | domain.m_minX = qMin(domain.m_minX,x); | |
|
80 | domain.m_minY = qMin(domain.m_minY,y); | |
|
81 | domain.m_maxX = qMax(domain.m_maxX,x); | |
|
82 | domain.m_maxY = qMax(domain.m_maxY,y); | |
|
83 | } | |
|
84 | ||
|
85 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); | |
|
86 | item->updateXYPlotDomain(domain); | |
|
87 | d->m_plotDomainList<<domain; | |
|
88 | d->m_xyLineChartItems<<item; | |
|
84 | 89 | break; |
|
85 | 90 | } |
|
86 | 91 | case QChartSeries::SeriesTypeScatter: { |
@@ -114,16 +119,22 QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries: | |||
|
114 | 119 | void QChart::setSize(const QSizeF& size) |
|
115 | 120 | { |
|
116 | 121 | Q_D(QChart); |
|
117 | //TODO refactor to setGeometry | |
|
118 | 122 | d->m_rect = QRect(QPoint(0,0),size.toSize()); |
|
119 | 123 | d->m_rect.adjust(margin(),margin(),-margin(),-margin()); |
|
120 | 124 | d->m_grid->setPos(d->m_rect.topLeft()); |
|
121 | 125 | d->m_grid->setSize(d->m_rect.size()); |
|
122 | d->m_plotDataList[0].m_viewportRect = d->m_rect; | |
|
123 | 126 | // TODO: line chart items would need to be updated separately as they don't support update |
|
124 | 127 | // via paint method |
|
125 | foreach(QGraphicsItem* item , d->m_items) | |
|
126 | reinterpret_cast<XYLineChartItem*>(item)->updateXYPlotData(d->m_plotDataList.at(0)); | |
|
128 | for (int i =0; i< d->m_plotDomainList.size();i++) | |
|
129 | { | |
|
130 | d->m_plotDomainList[i].m_viewportRect = d->m_rect; | |
|
131 | ||
|
132 | } | |
|
133 | ||
|
134 | foreach(XYLineChartItem* item , d->m_xyLineChartItems) | |
|
135 | item->updateXYPlotDomain(d->m_plotDomainList.at(d->m_plotDataIndex)); | |
|
136 | ||
|
137 | d->m_grid->setXYPlotData(d->m_plotDomainList.at(d->m_plotDataIndex)); | |
|
127 | 138 | update(); |
|
128 | 139 | } |
|
129 | 140 |
@@ -14,7 +14,7 m_series(series) | |||
|
14 | 14 | |
|
15 | 15 | } |
|
16 | 16 | |
|
17 |
void XYLineChartItem::updateXYPlotD |
|
|
17 | void XYLineChartItem::updateXYPlotDomain(const XYPlotDomain& data) | |
|
18 | 18 | { |
|
19 | 19 | m_xyPlotData=data; |
|
20 | 20 |
@@ -20,7 +20,7 public: | |||
|
20 | 20 | virtual QRectF boundingRect() const; |
|
21 | 21 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
22 | 22 | |
|
23 |
void updateXYPlotD |
|
|
23 | void updateXYPlotDomain(const XYPlotDomain& data); | |
|
24 | 24 | |
|
25 | 25 | private: |
|
26 | 26 | QPolygonF m_polyline; |
General Comments 0
You need to be logged in to leave comments.
Login now