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