##// END OF EJS Templates
Removes PIMPL for now...
Michal Klocek -
r53:c6b7296833b8
parent child
Show More
@@ -13,52 +13,30
13
13
14 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14 QTCOMMERCIALCHART_BEGIN_NAMESPACE
15
15
16 class QChartPrivate
17 {
18 public:
19
20 QChartPrivate(QChart* parent):
21 m_axisX(new Axis(parent)),
22 m_axisY(new Axis(parent)),
23 m_grid(new XYGrid(parent)),
24 m_plotDataIndex(0),
25 m_marginSize(0){}
26
27 Axis* m_axisX;
28 Axis* m_axisY;
29 XYGrid* m_grid;
30 QRect m_rect;
31 QList<const QChartSeries*> m_series;
32 QList<XYPlotDomain> m_plotDomainList;
33 QList<XYLineChartItem*> m_xyLineChartItems;
34 QList<QGraphicsItem*> m_items;
35 int m_plotDataIndex;
36 int m_marginSize;
37
38 };
39
40 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
41
42 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
16 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
43 d(new QChartPrivate(this))
17 m_axisX(new Axis(this)),
18 m_axisY(new Axis(this)),
19 m_grid(new XYGrid(this)),
20 m_plotDataIndex(0),
21 m_marginSize(0)
44 {
22 {
45 // setFlags(QGraphicsItem::ItemClipsChildrenToShape);
23 // setFlags(QGraphicsItem::ItemClipsChildrenToShape);
46 // set axis
24 // set axis
47 d->m_axisY->rotate(90);
25 m_axisY->rotate(90);
48 }
26 }
49
27
50 QChart::~QChart(){}
28 QChart::~QChart(){}
51
29
52 QRectF QChart::boundingRect() const
30 QRectF QChart::boundingRect() const
53 {
31 {
54 return d->m_rect;
32 return m_rect;
55 }
33 }
56
34
57 void QChart::addSeries(QChartSeries* series)
35 void QChart::addSeries(QChartSeries* series)
58 {
36 {
59 // TODO: we should check the series not already added
37 // TODO: we should check the series not already added
60
38
61 d->m_series<<series;
39 m_series<<series;
62
40
63 switch(series->type())
41 switch(series->type())
64 {
42 {
@@ -83,8 +61,8 void QChart::addSeries(QChartSeries* series)
83
61
84 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
62 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
85 item->updateXYPlotDomain(domain);
63 item->updateXYPlotDomain(domain);
86 d->m_plotDomainList<<domain;
64 m_plotDomainList<<domain;
87 d->m_xyLineChartItems<<item;
65 m_xyLineChartItems<<item;
88 break;
66 break;
89 }
67 }
90 // TODO: Not tested:
68 // TODO: Not tested:
@@ -130,10 +108,10 QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries:
130
108
131 void QChart::setSize(const QSizeF& size)
109 void QChart::setSize(const QSizeF& size)
132 {
110 {
133 d->m_rect = QRect(QPoint(0,0),size.toSize());
111 m_rect = QRect(QPoint(0,0),size.toSize());
134 d->m_rect.adjust(margin(),margin(), -margin(), -margin());
112 m_rect.adjust(margin(),margin(), -margin(), -margin());
135 d->m_grid->setPos(d->m_rect.topLeft());
113 m_grid->setPos(m_rect.topLeft());
136 d->m_grid->setSize(d->m_rect.size());
114 m_grid->setSize(m_rect.size());
137
115
138 // TODO: calculate the scale
116 // TODO: calculate the scale
139 // TODO: calculate the origo
117 // TODO: calculate the origo
@@ -142,27 +120,29 void QChart::setSize(const QSizeF& size)
142 const qreal yscale = size.height() / 100;
120 const qreal yscale = size.height() / 100;
143 emit sizeChanged(QRectF(0, 0, size.width(), size.height()), xscale, yscale);
121 emit sizeChanged(QRectF(0, 0, size.width(), size.height()), xscale, yscale);
144
122
145 for (int i(0); i < d->m_plotDomainList.size(); i++)
123 for (int i(0); i < m_plotDomainList.size(); i++)
146 d->m_plotDomainList[i].m_viewportRect = d->m_rect;
124 m_plotDomainList[i].m_viewportRect = m_rect;
147
125
148 // TODO: line chart items are updated separately as they don't support update
126 // TODO: line chart items are updated separately as they don't support update
149 // via sizeChanged signal
127 // via sizeChanged signal
150 foreach(XYLineChartItem* item , d->m_xyLineChartItems)
128 foreach(XYLineChartItem* item ,m_xyLineChartItems)
151 item->updateXYPlotDomain(d->m_plotDomainList.at(d->m_plotDataIndex));
129 item->updateXYPlotDomain(m_plotDomainList.at(m_plotDataIndex));
130
131
132 if (m_plotDomainList.count())
133 m_grid->setXYPlotData(m_plotDomainList.at(m_plotDataIndex));
152
134
153 if (d->m_plotDomainList.count())
154 d->m_grid->setXYPlotData(d->m_plotDomainList.at(d->m_plotDataIndex));
155 update();
135 update();
156 }
136 }
157
137
158 int QChart::margin() const
138 int QChart::margin() const
159 {
139 {
160 return d->m_marginSize;
140 return m_marginSize;
161 }
141 }
162
142
163 void QChart::setMargin(int margin)
143 void QChart::setMargin(int margin)
164 {
144 {
165 d->m_marginSize = margin;
145 m_marginSize = margin;
166 }
146 }
167
147
168 #include "moc_qchart.cpp"
148 #include "moc_qchart.cpp"
@@ -11,7 +11,7 class Axis;
11 class XYGrid;
11 class XYGrid;
12 class QChartSeries;
12 class QChartSeries;
13 class XYPlotDomain;
13 class XYPlotDomain;
14 class QChartPrivate;
14 class XYLineChartItem;
15
15
16 // TODO: We don't need to have QChart tied to QGraphicsItem:
16 // TODO: We don't need to have QChart tied to QGraphicsItem:
17 //class QTCOMMERCIALCHART_EXPORT QChart
17 //class QTCOMMERCIALCHART_EXPORT QChart
@@ -45,9 +45,17 signals:
45 void sizeChanged(QRectF rect, qreal xscale, qreal yscale);
45 void sizeChanged(QRectF rect, qreal xscale, qreal yscale);
46
46
47 private:
47 private:
48 // Q_DECLARE_PRIVATE(QChart)
49 Q_DISABLE_COPY(QChart)
48 Q_DISABLE_COPY(QChart)
50 QChartPrivate *d;
49 Axis* m_axisX;
50 Axis* m_axisY;
51 XYGrid* m_grid;
52 QRect m_rect;
53 QList<const QChartSeries*> m_series;
54 QList<XYPlotDomain> m_plotDomainList;
55 QList<XYLineChartItem*> m_xyLineChartItems;
56 QList<QGraphicsItem*> m_items;
57 int m_plotDataIndex;
58 int m_marginSize;
51 };
59 };
52
60
53 QTCOMMERCIALCHART_END_NAMESPACE
61 QTCOMMERCIALCHART_END_NAMESPACE
@@ -6,52 +6,28
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 class QChartWidgetPrivate
9 QChartWidget::QChartWidget(QWidget *parent) :
10 {
10 QWidget(parent)
11 public:
12 QChartWidgetPrivate(QChartWidget *parent) :
13 m_view(0),
14 m_scene(0),
15 m_chart(0)
16 {
11 {
12 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
17 m_scene = new QGraphicsScene();
13 m_scene = new QGraphicsScene();
18 m_view = new QGraphicsView(parent);
14 m_view = new QGraphicsView(parent);
19 m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
15 m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
20 m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
21 m_view->setScene(m_scene);
16 m_view->setScene(m_scene);
22 m_chart = new QChart();
17 m_chart = new QChart();
23 m_scene->addItem(m_chart);
18 m_scene->addItem(m_chart);
24 m_view->show();
19 m_view->show();
25 }
20 }
26
21
27 ~QChartWidgetPrivate() {
28 }
29
30 QGraphicsView *m_view;
31 QGraphicsScene *m_scene;
32 QChart* m_chart;
33 };
34
35 ///////////////////////////////////////////////////////////////////////////////////////////////////
36
37 QChartWidget::QChartWidget(QWidget *parent) :
38 QWidget(parent),
39 d_ptr(new QChartWidgetPrivate(this))
40 {
41 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
42 }
43
44 QChartWidget::~QChartWidget()
22 QChartWidget::~QChartWidget()
45 {
23 {
46 delete d_ptr;
47 }
24 }
48
25
49 void QChartWidget::resizeEvent(QResizeEvent *event)
26 void QChartWidget::resizeEvent(QResizeEvent *event)
50 {
27 {
51 Q_D(QChartWidget);
28 m_view->resize(size().width(),size().height());
52 d->m_view->resize(size().width(),size().height());
29 m_scene->setSceneRect(0,0,size().width(),size().height());
53 d->m_scene->setSceneRect(0,0,size().width(),size().height());
30 m_chart->setSize(size());
54 d->m_chart->setSize(size());
55 QWidget::resizeEvent(event);
31 QWidget::resizeEvent(event);
56 }
32 }
57
33
@@ -63,14 +39,12 QSize QChartWidget::sizeHint() const
63
39
64 void QChartWidget::addSeries(QChartSeries* series)
40 void QChartWidget::addSeries(QChartSeries* series)
65 {
41 {
66 Q_D(QChartWidget);
42 m_chart->addSeries(series);
67 d->m_chart->addSeries(series);
68 }
43 }
69
44
70 QChartSeries* QChartWidget::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type)
45 QChartSeries* QChartWidget::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type)
71 {
46 {
72 Q_D(QChartWidget);
47 return m_chart->createSeries(x, y, type);
73 return d->m_chart->createSeries(x, y, type);
74 }
48 }
75 #include "moc_qchartwidget.cpp"
49 #include "moc_qchartwidget.cpp"
76
50
@@ -5,6 +5,9
5 #include "qchart.h"
5 #include "qchart.h"
6 #include <QWidget>
6 #include <QWidget>
7
7
8 class QGraphicsView;
9 class QGraphicsScene;
10
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
12
10 class QChartSeries;
13 class QChartSeries;
@@ -24,12 +27,12 public:
24 // TODO: addSeries and createSeries are optional solutions
27 // TODO: addSeries and createSeries are optional solutions
25 void addSeries(QChartSeries* series);
28 void addSeries(QChartSeries* series);
26 QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type);
29 QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type);
27 protected:
28 QChartWidgetPrivate * const d_ptr;
29
30
30 private:
31 private:
31 Q_DISABLE_COPY(QChartWidget)
32 Q_DISABLE_COPY(QChartWidget)
32 Q_DECLARE_PRIVATE(QChartWidget)
33 QGraphicsView *m_view;
34 QGraphicsScene *m_scene;
35 QChart* m_chart;
33
36
34 };
37 };
35
38
General Comments 0
You need to be logged in to leave comments. Login now