@@ -8,71 +8,105 | |||
|
8 | 8 | |
|
9 | 9 | QCHART_BEGIN_NAMESPACE |
|
10 | 10 | |
|
11 | class QChartPrivate | |
|
12 | { | |
|
13 | public: | |
|
14 | ||
|
15 | QChartPrivate(QChart* parent): | |
|
16 | m_axisX(new Axis(parent)), | |
|
17 | m_axisY(new Axis(parent)), | |
|
18 | m_grid(new XYGrid(parent)), | |
|
19 | m_plotDataIndex(0), | |
|
20 | m_marginSize(0){} | |
|
21 | ||
|
22 | Axis* m_axisX; | |
|
23 | Axis* m_axisY; | |
|
24 | XYGrid* m_grid; | |
|
25 | QRect m_rect; | |
|
26 | QList<const QChartSeries*> m_series; | |
|
27 | QList<XYPlotDomain> m_plotDataList; | |
|
28 | QList<QGraphicsItem*> m_items; | |
|
29 | int m_plotDataIndex; | |
|
30 | int m_marginSize; | |
|
31 | ||
|
32 | }; | |
|
33 | ||
|
34 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
35 | ||
|
11 | 36 | QChart::QChart(QGraphicsItem* parent):QGraphicsItem(parent), |
|
12 | m_marginSize(0), | |
|
13 | m_axisX(new Axis(this)), | |
|
14 | m_axisY(new Axis(this)), | |
|
15 | m_grid(new XYGrid(this)), | |
|
16 | m_plotDataIndex(0) | |
|
37 | d_ptr(new QChartPrivate(this)) | |
|
17 | 38 | { |
|
18 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
|
39 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
|
19 | 40 | // set axis |
|
20 | m_axisY->rotate(90); | |
|
21 | ||
|
41 | Q_D(QChart); | |
|
42 | d->m_axisY->rotate(90); | |
|
22 | 43 | |
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
44 | //TODO hardcoded values , to removed soon | |
|
45 | XYPlotDomain data; | |
|
46 | data.m_minX = 0.0; | |
|
47 | data.m_maxX = 100.0; | |
|
48 | data.m_minY = 0.0; | |
|
49 | data.m_maxY = 100.0; | |
|
50 | data.m_ticksX=4; | |
|
51 | data.m_ticksY=4; | |
|
31 | 52 | |
|
32 |
|
|
|
33 |
|
|
|
53 | d->m_plotDataList.clear(); | |
|
54 | d->m_plotDataList << data; | |
|
34 | 55 | |
|
35 |
|
|
|
36 |
|
|
|
56 | d->m_grid->setZValue(10); | |
|
57 | d->m_grid->setXYPlotData(d->m_plotDataList.at(0)); | |
|
37 | 58 | } |
|
38 | 59 | |
|
39 | 60 | QChart::~QChart(){} |
|
40 | 61 | |
|
41 | 62 | QRectF QChart::boundingRect() const |
|
42 | 63 | { |
|
43 | return m_rect; | |
|
64 | Q_D(const QChart); | |
|
65 | return d->m_rect; | |
|
44 | 66 | } |
|
45 | 67 | |
|
46 | 68 | void QChart::addSeries(QChartSeries* series) |
|
47 | 69 | { |
|
48 | m_series<<series; | |
|
70 | Q_D(QChart); | |
|
71 | d->m_series<<series; | |
|
49 | 72 | |
|
50 | 73 | switch(series->type()) |
|
51 | 74 | { |
|
52 | 75 | case QChartSeries::LINE: |
|
53 | 76 | XYLineChartItem* item = new XYLineChartItem(reinterpret_cast<QXYChartSeries*>(series),this); |
|
54 |
item->updateXYPlotData( |
|
|
55 | m_items<<item; | |
|
77 | item->updateXYPlotData(d->m_plotDataList.at(0)); | |
|
78 | d->m_items<<item; | |
|
56 | 79 | break; |
|
57 | 80 | } |
|
58 | 81 | } |
|
59 | 82 | |
|
60 |
void QChart::setSize(const QSizeF& size) |
|
|
83 | void QChart::setSize(const QSizeF& size) | |
|
84 | { | |
|
85 | Q_D(QChart); | |
|
61 | 86 | //TODO refactor to setGeometry |
|
62 | m_rect = QRect(QPoint(0,0),size.toSize()); | |
|
63 | m_rect.adjust(margin(),margin(),-margin(),-margin()); | |
|
64 | m_grid->setPos(m_rect.topLeft()); | |
|
65 | m_grid->setSize(m_rect.size()); | |
|
66 |
|
|
|
67 | foreach(QGraphicsItem* item , m_items) | |
|
68 |
reinterpret_cast<XYLineChartItem*>(item)->updateXYPlotData( |
|
|
87 | d->m_rect = QRect(QPoint(0,0),size.toSize()); | |
|
88 | d->m_rect.adjust(margin(),margin(),-margin(),-margin()); | |
|
89 | d->m_grid->setPos(d->m_rect.topLeft()); | |
|
90 | d->m_grid->setSize(d->m_rect.size()); | |
|
91 | d->m_plotDataList[0].m_viewportRect = d->m_rect; | |
|
92 | foreach(QGraphicsItem* item , d->m_items) | |
|
93 | reinterpret_cast<XYLineChartItem*>(item)->updateXYPlotData(d->m_plotDataList.at(0)); | |
|
69 | 94 | update(); |
|
70 | 95 | |
|
71 | 96 | } |
|
72 | 97 | |
|
98 | int QChart::margin() const | |
|
99 | { | |
|
100 | Q_D(const QChart); | |
|
101 | return d->m_marginSize; | |
|
102 | } | |
|
103 | ||
|
73 | 104 | void QChart::setMargin(int margin) |
|
74 | 105 | { |
|
75 | m_marginSize = margin; | |
|
106 | Q_D(QChart); | |
|
107 | d->m_marginSize = margin; | |
|
76 | 108 | } |
|
77 | 109 | |
|
110 | ||
|
111 | ||
|
78 | 112 | QCHART_END_NAMESPACE |
@@ -10,6 +10,7 class Axis; | |||
|
10 | 10 | class XYGrid; |
|
11 | 11 | class QChartSeries; |
|
12 | 12 | class XYPlotDomain; |
|
13 | class QChartPrivate; | |
|
13 | 14 | |
|
14 | 15 | class QCHART_EXPORT QChart : public QGraphicsItem |
|
15 | 16 | { |
@@ -26,18 +27,15 public: | |||
|
26 | 27 | |
|
27 | 28 | virtual void setSize(const QSizeF& rect); |
|
28 | 29 | void setMargin(int margin); |
|
29 |
int margin() const |
|
|
30 | int margin() const; | |
|
31 | ||
|
32 | protected: | |
|
33 | QChartPrivate * const d_ptr; | |
|
30 | 34 | |
|
31 | 35 | private: |
|
32 | QRect m_rect; | |
|
33 | QList<const QChartSeries*> m_series; | |
|
34 | Axis* m_axisX; | |
|
35 | Axis* m_axisY; | |
|
36 | XYGrid* m_grid; | |
|
37 | QList<XYPlotDomain*> m_plotDataList; | |
|
38 | QList<QGraphicsItem*> m_items; | |
|
39 | int m_plotDataIndex; | |
|
40 | int m_marginSize; | |
|
36 | Q_DISABLE_COPY(QChart) | |
|
37 | Q_DECLARE_PRIVATE(QChart) | |
|
38 | ||
|
41 | 39 | }; |
|
42 | 40 | |
|
43 | 41 | QCHART_END_NAMESPACE |
@@ -12,8 +12,7 public: | |||
|
12 | 12 | QChartWidgetPrivate(QChartWidget *parent) : |
|
13 | 13 | m_view(0), |
|
14 | 14 | m_scene(0), |
|
15 |
m_chart(0) |
|
|
16 | q_ptr( parent ) | |
|
15 | m_chart(0) | |
|
17 | 16 | { |
|
18 | 17 | m_scene = new QGraphicsScene(); |
|
19 | 18 | m_view = new QGraphicsView(parent); |
@@ -28,10 +27,10 public: | |||
|
28 | 27 | QGraphicsView *m_view; |
|
29 | 28 | QGraphicsScene *m_scene; |
|
30 | 29 | QChart* m_chart; |
|
31 | QChartWidget * const q_ptr; | |
|
32 | Q_DECLARE_PUBLIC(QChartWidget); | |
|
33 | 30 | }; |
|
34 | 31 | |
|
32 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
33 | ||
|
35 | 34 | QChartWidget::QChartWidget(QWidget *parent) : |
|
36 | 35 | QWidget(parent), |
|
37 | 36 | d_ptr(new QChartWidgetPrivate(this)) |
General Comments 0
You need to be logged in to leave comments.
Login now