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