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