@@ -1,7 +1,7 | |||
|
1 | 1 | #include "qchart.h" |
|
2 | 2 | #include "qchartseries.h" |
|
3 | 3 | #include "xylinechartitem_p.h" |
|
4 |
#include "xyplotd |
|
|
4 | #include "xyplotdomain_p.h" | |
|
5 | 5 | #include "axis_p.h" |
|
6 | 6 | #include "xygrid_p.h" |
|
7 | 7 | #include <QDebug> |
@@ -21,7 +21,7 m_plotDataIndex(0) | |||
|
21 | 21 | |
|
22 | 22 | |
|
23 | 23 | //TODO hardcoded values , to removed soon |
|
24 |
XYPlotD |
|
|
24 | XYPlotDomain* data = new XYPlotDomain(); | |
|
25 | 25 | data->m_minX = 0.0; |
|
26 | 26 | data->m_maxX = 100.0; |
|
27 | 27 | data->m_minY = 0.0; |
@@ -51,7 +51,7 void QChart::addSeries(QChartSeries* series) | |||
|
51 | 51 | { |
|
52 | 52 | case QChartSeries::LINE: |
|
53 | 53 | XYLineChartItem* item = new XYLineChartItem(reinterpret_cast<QXYChartSeries*>(series),this); |
|
54 |
item-> |
|
|
54 | item->updateXYPlotData(*m_plotDataList.at(0)); | |
|
55 | 55 | m_items<<item; |
|
56 | 56 | break; |
|
57 | 57 | } |
@@ -63,8 +63,9 void QChart::setSize(const QSizeF& size) { | |||
|
63 | 63 | m_rect.adjust(margin(),margin(),-margin(),-margin()); |
|
64 | 64 | m_grid->setPos(m_rect.topLeft()); |
|
65 | 65 | m_grid->setSize(m_rect.size()); |
|
66 | m_plotDataList.at(0)->m_viewportRect = m_rect; | |
|
66 | 67 | foreach(QGraphicsItem* item , m_items) |
|
67 |
reinterpret_cast<XYLineChartItem*>(item)-> |
|
|
68 | reinterpret_cast<XYLineChartItem*>(item)->updateXYPlotData(*m_plotDataList.at(0)); | |
|
68 | 69 | update(); |
|
69 | 70 | |
|
70 | 71 | } |
@@ -9,7 +9,7 QCHART_BEGIN_NAMESPACE | |||
|
9 | 9 | class Axis; |
|
10 | 10 | class XYGrid; |
|
11 | 11 | class QChartSeries; |
|
12 |
class XYPlotD |
|
|
12 | class XYPlotDomain; | |
|
13 | 13 | |
|
14 | 14 | class QCHART_EXPORT QChart : public QGraphicsItem |
|
15 | 15 | { |
@@ -34,7 +34,7 private: | |||
|
34 | 34 | Axis* m_axisX; |
|
35 | 35 | Axis* m_axisY; |
|
36 | 36 | XYGrid* m_grid; |
|
37 |
QList<XYPlotD |
|
|
37 | QList<XYPlotDomain*> m_plotDataList; | |
|
38 | 38 | QList<QGraphicsItem*> m_items; |
|
39 | 39 | int m_plotDataIndex; |
|
40 | 40 | int m_marginSize; |
@@ -9,14 +9,14 SOURCES += \ | |||
|
9 | 9 | xylinechart/qxychartseries.cpp \ |
|
10 | 10 | xylinechart/xylinechartitem.cpp \ |
|
11 | 11 | xylinechart/xygrid.cpp \ |
|
12 |
xylinechart/xyplotd |
|
|
12 | xylinechart/xyplotdomain.cpp \ | |
|
13 | 13 | qchart.cpp \ |
|
14 | 14 | axis.cpp \ |
|
15 | 15 | qchartwidget.cpp |
|
16 | 16 | |
|
17 | 17 | PRIVATE_HEADERS += \ |
|
18 | 18 | xylinechart/xylinechartitem_p.h \ |
|
19 |
xylinechart/xyplotd |
|
|
19 | xylinechart/xyplotdomain_p.h \ | |
|
20 | 20 | xylinechart/xygrid_p.h \ |
|
21 | 21 | axis_p.h |
|
22 | 22 |
@@ -18,7 +18,7 void XYGrid::setSize(const QSizeF& size) | |||
|
18 | 18 | m_rect.setSize(size.toSize()); |
|
19 | 19 | } |
|
20 | 20 | |
|
21 |
void XYGrid::setXYPlotData(const XYPlotD |
|
|
21 | void XYGrid::setXYPlotData(const XYPlotDomain& xyPlotData) | |
|
22 | 22 | { |
|
23 | 23 | m_xyPlotData = xyPlotData; |
|
24 | 24 | } |
@@ -2,7 +2,7 | |||
|
2 | 2 | #define XYGRID_H_ |
|
3 | 3 | |
|
4 | 4 | #include <qchartconfig.h> |
|
5 |
#include <xyplotd |
|
|
5 | #include <xyplotdomain_p.h> | |
|
6 | 6 | #include <QGraphicsItem> |
|
7 | 7 | |
|
8 | 8 | QCHART_BEGIN_NAMESPACE |
@@ -18,12 +18,12 public: | |||
|
18 | 18 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
19 | 19 | |
|
20 | 20 | //TODO: this is just temporary interface |
|
21 |
void setXYPlotData(const XYPlotD |
|
|
21 | void setXYPlotData(const XYPlotDomain& xyPlotData); | |
|
22 | 22 | void setSize(const QSizeF& rect); |
|
23 | 23 | |
|
24 | 24 | private: |
|
25 | 25 | QRectF m_rect; |
|
26 |
XYPlotD |
|
|
26 | XYPlotDomain m_xyPlotData; | |
|
27 | 27 | }; |
|
28 | 28 | |
|
29 | 29 | QCHART_END_NAMESPACE |
@@ -9,42 +9,22 | |||
|
9 | 9 | QCHART_BEGIN_NAMESPACE |
|
10 | 10 | |
|
11 | 11 | XYLineChartItem::XYLineChartItem(QXYChartSeries* series,QGraphicsItem *parent):QGraphicsItem(parent), |
|
12 |
m_series(series) |
|
|
13 | m_dirtyGeometry(true) | |
|
12 | m_series(series) | |
|
14 | 13 | { |
|
15 | 14 | |
|
16 | 15 | } |
|
17 | 16 | |
|
18 |
void XYLineChartItem:: |
|
|
17 | void XYLineChartItem::updateXYPlotData(const XYPlotDomain& data) | |
|
19 | 18 | { |
|
20 | m_rect = rect; | |
|
21 | m_dirtyGeometry = true; | |
|
22 | } | |
|
23 | ||
|
24 | void XYLineChartItem::setXYPlotData(const XYPlotData& data){ | |
|
25 | 19 | m_xyPlotData=data; |
|
26 | m_dirtyGeometry = true; | |
|
27 | } | |
|
28 | ||
|
29 | QRectF XYLineChartItem::boundingRect() const | |
|
30 | { | |
|
31 | return m_polyline.boundingRect(); | |
|
32 | } | |
|
33 | ||
|
34 | ||
|
35 | void XYLineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) | |
|
36 | { | |
|
37 | if(m_dirtyGeometry) { | |
|
38 | 20 | |
|
39 | m_dirtyGeometry=false; | |
|
40 | ||
|
41 | if (!m_rect.isValid()) | |
|
21 | if (!m_xyPlotData.m_viewportRect.isValid()) | |
|
42 | 22 |
|
|
43 | 23 | |
|
44 | painter->setClipRect(m_rect.adjusted(+1, +1, -1, -1)); | |
|
24 | const QRect& rect = m_xyPlotData.m_viewportRect; | |
|
45 | 25 | |
|
46 |
|
|
|
47 |
|
|
|
26 | const qreal deltaX = (rect.width()-1)/m_xyPlotData.spanX(); | |
|
27 | const qreal deltaY = (rect.height()-1)/m_xyPlotData.spanY(); | |
|
48 | 28 | |
|
49 | 29 |
|
|
50 | 30 |
|
@@ -52,15 +32,22 void XYLineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *o | |||
|
52 | 32 |
|
|
53 | 33 |
|
|
54 | 34 |
|
|
55 |
|
|
|
56 |
|
|
|
35 | qreal x = (dx * deltaX) + rect.left(); | |
|
36 | qreal y = - (dy * deltaY) + rect.bottom(); | |
|
57 | 37 |
|
|
58 | 38 |
|
|
59 | painter->setPen(m_series->color()); | |
|
60 | painter->drawPolyline(m_polyline); | |
|
39 | ||
|
40 | } | |
|
41 | ||
|
42 | QRectF XYLineChartItem::boundingRect() const | |
|
43 | { | |
|
44 | return m_polyline.boundingRect(); | |
|
61 | 45 | } |
|
62 | 46 | |
|
63 | painter->setClipRect(m_rect.adjusted(+1, +1, -1, -1)); | |
|
47 | ||
|
48 | void XYLineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget) | |
|
49 | { | |
|
50 | painter->setClipRect(m_xyPlotData.m_viewportRect.adjusted(+1, +1, -1, -1)); | |
|
64 | 51 | painter->setPen(m_series->color()); |
|
65 | 52 | painter->drawPolyline(m_polyline); |
|
66 | 53 |
@@ -3,7 +3,7 | |||
|
3 | 3 | |
|
4 | 4 | #include "qchartconfig.h" |
|
5 | 5 | #include "qchart.h" |
|
6 |
#include "xyplotd |
|
|
6 | #include "xyplotdomain_p.h" | |
|
7 | 7 | |
|
8 | 8 | QCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
@@ -20,16 +20,12 public: | |||
|
20 | 20 | virtual QRectF boundingRect() const; |
|
21 | 21 | virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
22 | 22 | |
|
23 | //TODO: this is just temporary interface | |
|
24 | void setChartSize(const QRectF& size); | |
|
25 | void setXYPlotData(const XYPlotData& data); | |
|
23 | void updateXYPlotData(const XYPlotDomain& data); | |
|
26 | 24 | |
|
27 | 25 | private: |
|
28 | QRectF m_rect; | |
|
29 | 26 | QPolygonF m_polyline; |
|
30 | 27 | QXYChartSeries* m_series; |
|
31 |
XYPlotD |
|
|
32 | bool m_dirtyGeometry; | |
|
28 | XYPlotDomain m_xyPlotData; | |
|
33 | 29 | }; |
|
34 | 30 | |
|
35 | 31 | QCHART_END_NAMESPACE |
@@ -1,24 +1,30 | |||
|
1 |
#include "xyplotd |
|
|
1 | #include "xyplotdomain_p.h" | |
|
2 | 2 | |
|
3 | 3 | QCHART_BEGIN_NAMESPACE |
|
4 | 4 | |
|
5 |
XYPlotD |
|
|
5 | XYPlotDomain::XYPlotDomain(): | |
|
6 | m_ticksX(0), | |
|
7 | m_ticksY(0), | |
|
8 | m_minX(0), | |
|
9 | m_maxX(0), | |
|
10 | m_minY(0), | |
|
11 | m_maxY(0) | |
|
6 | 12 | { |
|
7 | 13 | |
|
8 | 14 | } |
|
9 | 15 | |
|
10 |
XYPlotD |
|
|
16 | XYPlotDomain::~XYPlotDomain() | |
|
11 | 17 | { |
|
12 | 18 | // TODO Auto-generated destructor stub |
|
13 | 19 | } |
|
14 | 20 | |
|
15 |
qreal XYPlotD |
|
|
21 | qreal XYPlotDomain::spanX() const | |
|
16 | 22 | { |
|
17 | 23 | Q_ASSERT(m_maxX >= m_minX); |
|
18 | 24 | return m_maxX - m_minX; |
|
19 | 25 | } |
|
20 | 26 | |
|
21 |
qreal XYPlotD |
|
|
27 | qreal XYPlotDomain::spanY() const | |
|
22 | 28 | { |
|
23 | 29 | Q_ASSERT(m_maxY >= m_minY); |
|
24 | 30 | return m_maxY - m_minY; |
@@ -1,14 +1,14 | |||
|
1 |
#ifndef PLOT |
|
|
2 |
#define PLOT |
|
|
1 | #ifndef PLOTDOMAIN_H_ | |
|
2 | #define PLOTDOMAIN_H_ | |
|
3 | 3 | #include "qchartconfig.h" |
|
4 |
#include <Qt |
|
|
4 | #include <QRect> | |
|
5 | 5 | |
|
6 | 6 | QCHART_BEGIN_NAMESPACE |
|
7 | 7 | |
|
8 |
class XYPlotD |
|
|
8 | class XYPlotDomain { | |
|
9 | 9 | public: |
|
10 |
XYPlotD |
|
|
11 |
virtual ~XYPlotD |
|
|
10 | XYPlotDomain(); | |
|
11 | virtual ~XYPlotDomain(); | |
|
12 | 12 | |
|
13 | 13 | qreal spanX() const; |
|
14 | 14 | qreal spanY() const; |
@@ -22,8 +22,7 public: | |||
|
22 | 22 | qreal m_maxX; |
|
23 | 23 | qreal m_minY; |
|
24 | 24 | qreal m_maxY; |
|
25 | ||
|
26 | ||
|
25 | QRect m_viewportRect; | |
|
27 | 26 | }; |
|
28 | 27 | |
|
29 | 28 | QCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now