##// END OF EJS Templates
Refactored series creation with QChart
Tero Ahola -
r61:45d3de5e814a
parent child
Show More
@@ -1,166 +1,165
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartseries.h"
2 #include "qchartseries.h"
3 #include "qscatterseries.h"
3 #include "qscatterseries.h"
4 #include "qscatterseries_p.h"
4 #include "qscatterseries_p.h"
5 #include "qpieseries.h"
5 #include "qpieseries.h"
6 #include "qxychartseries.h"
6 #include "qxychartseries.h"
7
7
8 #include "barchartseries.h"
8 #include "barchartseries.h"
9 #include "bargroup.h"
9 #include "bargroup.h"
10
10
11 #include "xylinechartitem_p.h"
11 #include "xylinechartitem_p.h"
12 #include "xyplotdomain_p.h"
12 #include "xyplotdomain_p.h"
13 #include "axis_p.h"
13 #include "axis_p.h"
14 #include "xygrid_p.h"
14 #include "xygrid_p.h"
15 #include <QGraphicsScene>
15 #include <QGraphicsScene>
16 #include <QDebug>
16 #include <QDebug>
17
17
18 QTCOMMERCIALCHART_BEGIN_NAMESPACE
18 QTCOMMERCIALCHART_BEGIN_NAMESPACE
19
19
20 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
20 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent),
21 m_axisX(new Axis(this)),
21 m_axisX(new Axis(this)),
22 m_axisY(new Axis(this)),
22 m_axisY(new Axis(this)),
23 m_grid(new XYGrid(this)),
23 m_grid(new XYGrid(this)),
24 m_plotDataIndex(0),
24 m_plotDataIndex(0),
25 m_marginSize(0)
25 m_marginSize(0)
26 {
26 {
27 // setFlags(QGraphicsItem::ItemClipsChildrenToShape);
27 // setFlags(QGraphicsItem::ItemClipsChildrenToShape);
28 // set axis
28 // set axis
29 m_axisY->rotate(90);
29 m_axisY->rotate(90);
30 }
30 }
31
31
32 QChart::~QChart(){}
32 QChart::~QChart(){}
33
33
34 QRectF QChart::boundingRect() const
34 QRectF QChart::boundingRect() const
35 {
35 {
36 return m_rect;
36 return m_rect;
37 }
37 }
38
38
39 void QChart::addSeries(QChartSeries* series)
39 void QChart::addSeries(QChartSeries* series)
40 {
40 {
41 // TODO: we should check the series not already added
41 // TODO: we should check the series not already added
42
42
43 m_series<<series;
43 m_series<<series;
44
44
45 switch(series->type())
45 switch(series->type())
46 {
46 {
47 case QChartSeries::SeriesTypeLine: {
47 case QChartSeries::SeriesTypeLine: {
48
48
49 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
49 QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series);
50
50
51 XYPlotDomain domain;
51 XYPlotDomain domain;
52 //TODO "nice numbers algorithm"
52 //TODO "nice numbers algorithm"
53 domain.m_ticksX=4;
53 domain.m_ticksX=4;
54 domain.m_ticksY=4;
54 domain.m_ticksY=4;
55
55
56 for (int i = 0 ; i < xyseries->count() ; i++)
56 for (int i = 0 ; i < xyseries->count() ; i++)
57 {
57 {
58 qreal x = xyseries->x(i);
58 qreal x = xyseries->x(i);
59 qreal y = xyseries->y(i);
59 qreal y = xyseries->y(i);
60 domain.m_minX = qMin(domain.m_minX,x);
60 domain.m_minX = qMin(domain.m_minX,x);
61 domain.m_minY = qMin(domain.m_minY,y);
61 domain.m_minY = qMin(domain.m_minY,y);
62 domain.m_maxX = qMax(domain.m_maxX,x);
62 domain.m_maxX = qMax(domain.m_maxX,x);
63 domain.m_maxY = qMax(domain.m_maxY,y);
63 domain.m_maxY = qMax(domain.m_maxY,y);
64 }
64 }
65
65
66 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
66 XYLineChartItem* item = new XYLineChartItem(xyseries,this);
67 item->updateXYPlotDomain(domain);
67 item->updateXYPlotDomain(domain);
68 m_plotDomainList<<domain;
68 m_plotDomainList<<domain;
69 m_xyLineChartItems<<item;
69 m_xyLineChartItems<<item;
70 break;
70 break;
71 }
71 }
72 // TODO: Not tested:
72 // TODO: Not tested:
73 // case QChartSeries::SeriesTypeScatter: {
73 // case QChartSeries::SeriesTypeScatter: {
74 // QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series);
74 // QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series);
75 // if (scatter) {
75 // if (scatter) {
76 // scatter->d->setParentItem(this);
76 // scatter->d->setParentItem(this);
77 // scene()->addItem(scatter->d);
77 // scene()->addItem(scatter->d);
78 // }
78 // }
79 // break;
79 // break;
80 // }
80 // }
81
81
82 case QChartSeries::SeriesTypeBar: {
82 case QChartSeries::SeriesTypeBar: {
83
83
84 qDebug() << "barSeries added";
84 qDebug() << "barSeries added";
85 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
85 BarChartSeries* barSeries = static_cast<BarChartSeries*>(series);
86
86
87 // Who owns the series?
87 // Who owns the series?
88 BarGroup* group = new BarGroup(*barSeries, this);
88 BarGroup* group = new BarGroup(*barSeries, this);
89 scene()->addItem(group);
89 scene()->addItem(group);
90 m_BarGroupItems.append(group); // If we need to access group later
90 m_BarGroupItems.append(group); // If we need to access group later
91 break;
91 break;
92 }
92 }
93 }
93 }
94 }
94 }
95
95
96 QChartSeries* QChart::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type)
96 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type)
97 {
97 {
98 // TODO: support also other types; not only scatter and pie
98 // TODO: support also other types; not only scatter and pie
99 Q_ASSERT(type == QChartSeries::SeriesTypeScatter
100 || type == QChartSeries::SeriesTypePie);
101
99
102 switch (type) {
100 switch (type) {
103 case QChartSeries::SeriesTypeScatter: {
101 case QChartSeries::SeriesTypeScatter: {
104 QScatterSeries *scatterSeries = new QScatterSeries(x, y, this);
102 QScatterSeries *scatterSeries = new QScatterSeries(this);
105 connect(this, SIGNAL(sizeChanged(QRectF)),
103 connect(this, SIGNAL(sizeChanged(QRectF)),
106 scatterSeries, SLOT(chartSizeChanged(QRectF)));
104 scatterSeries, SLOT(chartSizeChanged(QRectF)));
107 scatterSeries->d->setParentItem(this);
105 scatterSeries->d->setParentItem(this);
108 return scatterSeries;
106 return scatterSeries;
109 }
107 }
110 case QChartSeries::SeriesTypePie: {
108 case QChartSeries::SeriesTypePie: {
111 // TODO: we now have also a list of y values as a parameter, it is ignored
109 // TODO: we now have also a list of y values as a parameter, it is ignored
112 // we should use a generic data class instead of list of x and y values
110 // we should use a generic data class instead of list of x and y values
113 QPieSeries *pieSeries = new QPieSeries(x, this);
111 QPieSeries *pieSeries = new QPieSeries(this);
114 connect(this, SIGNAL(sizeChanged(QRectF)),
112 connect(this, SIGNAL(sizeChanged(QRectF)),
115 pieSeries, SLOT(chartSizeChanged(QRectF)));
113 pieSeries, SLOT(chartSizeChanged(QRectF)));
116 return pieSeries;
114 return pieSeries;
117 }
115 }
118 default:
116 default:
117 Q_ASSERT(false);
119 break;
118 break;
120 }
119 }
121
120
122 return 0;
121 return 0;
123 }
122 }
124
123
125 void QChart::setSize(const QSizeF& size)
124 void QChart::setSize(const QSizeF& size)
126 {
125 {
127 m_rect = QRect(QPoint(0,0),size.toSize());
126 m_rect = QRect(QPoint(0,0),size.toSize());
128 m_rect.adjust(margin(),margin(), -margin(), -margin());
127 m_rect.adjust(margin(),margin(), -margin(), -margin());
129 m_grid->setPos(m_rect.topLeft());
128 m_grid->setPos(m_rect.topLeft());
130 m_grid->setSize(m_rect.size());
129 m_grid->setSize(m_rect.size());
131
130
132 // TODO: TTD for setting scale
131 // TODO: TTD for setting scale
133 //emit scaleChanged(100, 100);
132 //emit scaleChanged(100, 100);
134 // TODO: calculate the origo
133 // TODO: calculate the origo
135 // TODO: not sure if emitting a signal here is the best from performance point of view
134 // TODO: not sure if emitting a signal here is the best from performance point of view
136 emit sizeChanged(QRectF(0, 0, size.width(), size.height()));
135 emit sizeChanged(QRectF(0, 0, size.width(), size.height()));
137
136
138 for (int i(0); i < m_plotDomainList.size(); i++)
137 for (int i(0); i < m_plotDomainList.size(); i++)
139 m_plotDomainList[i].m_viewportRect = m_rect;
138 m_plotDomainList[i].m_viewportRect = m_rect;
140
139
141 // TODO: line chart items are updated separately as they don't support update
140 // TODO: line chart items are updated separately as they don't support update
142 // via sizeChanged signal
141 // via sizeChanged signal
143 foreach(XYLineChartItem* item ,m_xyLineChartItems)
142 foreach(XYLineChartItem* item ,m_xyLineChartItems)
144 item->updateXYPlotDomain(m_plotDomainList.at(m_plotDataIndex));
143 item->updateXYPlotDomain(m_plotDomainList.at(m_plotDataIndex));
145
144
146
145
147 if (m_plotDomainList.count())
146 if (m_plotDomainList.count())
148 m_grid->setXYPlotData(m_plotDomainList.at(m_plotDataIndex));
147 m_grid->setXYPlotData(m_plotDomainList.at(m_plotDataIndex));
149
148
150 update();
149 update();
151 }
150 }
152
151
153 int QChart::margin() const
152 int QChart::margin() const
154 {
153 {
155 return m_marginSize;
154 return m_marginSize;
156 }
155 }
157
156
158 void QChart::setMargin(int margin)
157 void QChart::setMargin(int margin)
159 {
158 {
160 m_marginSize = margin;
159 m_marginSize = margin;
161 }
160 }
162
161
163 #include "moc_qchart.cpp"
162 #include "moc_qchart.cpp"
164
163
165
164
166 QTCOMMERCIALCHART_END_NAMESPACE
165 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,67 +1,67
1 #ifndef CHART_H
1 #ifndef CHART_H
2 #define CHART_H
2 #define CHART_H
3
3
4 #include <qchartglobal.h>
4 #include <qchartglobal.h>
5 #include <qchartseries.h>
5 #include <qchartseries.h>
6 #include <QGraphicsObject>
6 #include <QGraphicsObject>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class Axis;
10 class Axis;
11 class XYGrid;
11 class XYGrid;
12 class QChartSeries;
12 class QChartSeries;
13 class XYPlotDomain;
13 class XYPlotDomain;
14 class XYLineChartItem;
14 class XYLineChartItem;
15 class BarGroup;
15 class BarGroup;
16
16
17 // TODO: We don't need to have QChart tied to QGraphicsItem:
17 // TODO: We don't need to have QChart tied to QGraphicsItem:
18 //class QTCOMMERCIALCHART_EXPORT QChart
18 //class QTCOMMERCIALCHART_EXPORT QChart
19 //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem {
19 //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem {
20 // public: QChartGraphicsItem(QChart &chart);
20 // public: QChartGraphicsItem(QChart &chart);
21
21
22 /*!
22 /*!
23 * TODO: define the responsibilities
23 * TODO: define the responsibilities
24 */
24 */
25 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsObject
25 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsObject
26 {
26 {
27 Q_OBJECT
27 Q_OBJECT
28 public:
28 public:
29 QChart(QGraphicsObject* parent = 0);
29 QChart(QGraphicsObject* parent = 0);
30 ~QChart();
30 ~QChart();
31
31
32 //from QGraphicsItem
32 //from QGraphicsItem
33 QRectF boundingRect() const;
33 QRectF boundingRect() const;
34 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
34 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){};
35
35
36 void addSeries(QChartSeries* series);
36 void addSeries(QChartSeries* series);
37 //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type);
37 //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type);
38 // TODO: who owns the series now? maybe owned by chart and returned a reference instead...
38 // TODO: who owns the series now? maybe owned by chart and returned a reference instead...
39 QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type);
39 QChartSeries* createSeries(QChartSeries::QChartSeriesType type);
40
40
41 virtual void setSize(const QSizeF& rect);
41 virtual void setSize(const QSizeF& rect);
42 void setMargin(int margin);
42 void setMargin(int margin);
43 int margin() const;
43 int margin() const;
44
44
45 signals:
45 signals:
46 void sizeChanged(QRectF rect);
46 void sizeChanged(QRectF rect);
47 void scaleChanged(qreal xscale, qreal yscale);
47 void scaleChanged(qreal xscale, qreal yscale);
48
48
49 private:
49 private:
50 Q_DISABLE_COPY(QChart)
50 Q_DISABLE_COPY(QChart)
51 Axis* m_axisX;
51 Axis* m_axisX;
52 Axis* m_axisY;
52 Axis* m_axisY;
53 XYGrid* m_grid;
53 XYGrid* m_grid;
54 QRect m_rect;
54 QRect m_rect;
55 QList<const QChartSeries*> m_series;
55 QList<const QChartSeries*> m_series;
56 QList<XYPlotDomain> m_plotDomainList;
56 QList<XYPlotDomain> m_plotDomainList;
57 QList<XYLineChartItem*> m_xyLineChartItems;
57 QList<XYLineChartItem*> m_xyLineChartItems;
58 QList<QGraphicsItem*> m_items;
58 QList<QGraphicsItem*> m_items;
59 int m_plotDataIndex;
59 int m_plotDataIndex;
60 int m_marginSize;
60 int m_marginSize;
61
61
62 QList<BarGroup*> m_BarGroupItems;
62 QList<BarGroup*> m_BarGroupItems;
63 };
63 };
64
64
65 QTCOMMERCIALCHART_END_NAMESPACE
65 QTCOMMERCIALCHART_END_NAMESPACE
66
66
67 #endif
67 #endif
@@ -1,38 +1,41
1 #ifndef QCHARTSERIES_H
1 #ifndef QCHARTSERIES_H
2 #define QCHARTSERIES_H
2 #define QCHARTSERIES_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include <QObject>
5 #include <QObject>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 class QTCOMMERCIALCHART_EXPORT QChartSeries : public QObject
9 class QTCOMMERCIALCHART_EXPORT QChartSeries : public QObject
10 {
10 {
11
11
12 public:
12 public:
13 enum QChartSeriesType {
13 enum QChartSeriesType {
14 SeriesTypeLine = 0,
14 SeriesTypeLine = 0,
15 // SeriesTypeArea,
15 // SeriesTypeArea,
16 SeriesTypeBar,
16 SeriesTypeBar,
17 SeriesTypePie,
17 SeriesTypePie,
18 SeriesTypeScatter
18 SeriesTypeScatter
19 // SeriesTypeSpline
19 // SeriesTypeSpline
20 };
20 };
21
21
22 protected:
22 protected:
23 QChartSeries(QObject *parent = 0):QObject(parent){};
23 QChartSeries(QObject *parent = 0):QObject(parent){};
24
24
25 public:
25 public:
26 virtual ~QChartSeries(){};
26 virtual ~QChartSeries(){};
27
27
28 //factory method
28 // Factory method
29 static QChartSeries* create(QObject* parent = 0 ){ return 0;}
29 static QChartSeries* create(QObject* parent = 0 ){ return 0;}
30 //pure virtual
30 // Pure virtual
31 virtual QChartSeriesType type() const = 0;
31 virtual QChartSeriesType type() const = 0;
32
32
33 virtual bool setData(QList<int> data) { return false; }
34 virtual bool setData(QList<qreal> data) { return false; }
35 virtual bool setData(QList<qreal> x, QList<qreal> y){ return false; }
33 };
36 };
34
37
35 QTCOMMERCIALCHART_END_NAMESPACE
38 QTCOMMERCIALCHART_END_NAMESPACE
36
39
37 #endif
40 #endif
38
41
@@ -1,81 +1,81
1 #include "qchartview.h"
1 #include "qchartview.h"
2 #include "qchart.h"
2 #include "qchart.h"
3 #include <QGraphicsView>
3 #include <QGraphicsView>
4 #include <QGraphicsScene>
4 #include <QGraphicsScene>
5 #include <QRubberBand>
5 #include <QRubberBand>
6 #include <QResizeEvent>
6 #include <QResizeEvent>
7 #include <QDebug>
7 #include <QDebug>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 QChartView::QChartView(QWidget *parent) :
11 QChartView::QChartView(QWidget *parent) :
12 QGraphicsView(parent),
12 QGraphicsView(parent),
13 m_scene(new QGraphicsScene()),
13 m_scene(new QGraphicsScene()),
14 m_chart(new QChart()),
14 m_chart(new QChart()),
15 m_rubberBand(0),
15 m_rubberBand(0),
16 m_showRubberBand(false)
16 m_showRubberBand(false)
17 {
17 {
18 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
18 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
19 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
19 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
20 setScene(m_scene);
20 setScene(m_scene);
21 m_chart->setMargin(50);
21 m_chart->setMargin(50);
22 m_scene->addItem(m_chart);
22 m_scene->addItem(m_chart);
23 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
23 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
24 }
24 }
25
25
26 QChartView::~QChartView()
26 QChartView::~QChartView()
27 {
27 {
28 }
28 }
29
29
30 void QChartView::resizeEvent(QResizeEvent *event)
30 void QChartView::resizeEvent(QResizeEvent *event)
31 {
31 {
32 m_scene->setSceneRect(0,0,size().width(),size().height());
32 m_scene->setSceneRect(0,0,size().width(),size().height());
33 m_chart->setSize(size());
33 m_chart->setSize(size());
34 QWidget::resizeEvent(event);
34 QWidget::resizeEvent(event);
35 }
35 }
36
36
37
37
38 void QChartView::addSeries(QChartSeries* series)
38 void QChartView::addSeries(QChartSeries* series)
39 {
39 {
40 m_chart->addSeries(series);
40 m_chart->addSeries(series);
41 }
41 }
42
42
43 QChartSeries* QChartView::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type)
43 QChartSeries* QChartView::createSeries(QChartSeries::QChartSeriesType type)
44 {
44 {
45
45
46 return m_chart->createSeries(x, y, type);
46 return m_chart->createSeries(type);
47 }
47 }
48
48
49 void QChartView::mousePressEvent(QMouseEvent *event)
49 void QChartView::mousePressEvent(QMouseEvent *event)
50 {
50 {
51 int margin = m_chart->margin();
51 int margin = m_chart->margin();
52
52
53 QRect rect(margin,margin,width()-2*margin,height()-2*margin);
53 QRect rect(margin,margin,width()-2*margin,height()-2*margin);
54
54
55 m_origin = event->pos();
55 m_origin = event->pos();
56
56
57 if (!rect.contains(m_origin)) return;
57 if (!rect.contains(m_origin)) return;
58
58
59 if (!m_rubberBand)
59 if (!m_rubberBand)
60 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
60 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
61 m_rubberBand->setGeometry(QRect(m_origin, QSize()));
61 m_rubberBand->setGeometry(QRect(m_origin, QSize()));
62 m_showRubberBand=true;
62 m_showRubberBand=true;
63 m_rubberBand->show();
63 m_rubberBand->show();
64
64
65 }
65 }
66
66
67 void QChartView::mouseMoveEvent(QMouseEvent *event)
67 void QChartView::mouseMoveEvent(QMouseEvent *event)
68 {
68 {
69 if(m_showRubberBand)
69 if(m_showRubberBand)
70 m_rubberBand->setGeometry(QRect(m_origin, event->pos()).normalized());
70 m_rubberBand->setGeometry(QRect(m_origin, event->pos()).normalized());
71 }
71 }
72
72
73 void QChartView::mouseReleaseEvent(QMouseEvent *event)
73 void QChartView::mouseReleaseEvent(QMouseEvent *event)
74 {
74 {
75 if(m_showRubberBand) {
75 if(m_showRubberBand) {
76 m_rubberBand->hide();
76 m_rubberBand->hide();
77 m_showRubberBand=false;
77 m_showRubberBand=false;
78 }
78 }
79 }
79 }
80
80
81 QTCOMMERCIALCHART_END_NAMESPACE
81 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,46 +1,46
1 #ifndef QCHARTWIDGET_H
1 #ifndef QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qchartseries.h"
5 #include "qchartseries.h"
6 #include <QGraphicsView>
6 #include <QGraphicsView>
7
7
8 class QGraphicsScene;
8 class QGraphicsScene;
9 class QRubberBand;
9 class QRubberBand;
10
10
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12
12
13 class QChart;
13 class QChart;
14
14
15 class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView
15 class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView
16 {
16 {
17 public:
17 public:
18 explicit QChartView(QWidget *parent = 0);
18 explicit QChartView(QWidget *parent = 0);
19 ~QChartView();
19 ~QChartView();
20
20
21 //implement from QWidget
21 //implement from QWidget
22 void resizeEvent(QResizeEvent *event);
22 void resizeEvent(QResizeEvent *event);
23
23
24 // TODO: addSeries and createSeries are optional solutions
25 void addSeries(QChartSeries* series);
24 void addSeries(QChartSeries* series);
26 QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type);
25 // Convenience function
26 QChartSeries* createSeries(QChartSeries::QChartSeriesType type);
27
27
28 protected:
28 protected:
29 void mouseMoveEvent (QMouseEvent *event);
29 void mouseMoveEvent (QMouseEvent *event);
30 void mousePressEvent (QMouseEvent *event);
30 void mousePressEvent (QMouseEvent *event);
31 void mouseReleaseEvent (QMouseEvent *event);
31 void mouseReleaseEvent (QMouseEvent *event);
32
32
33 private:
33 private:
34 QGraphicsScene *m_scene;
34 QGraphicsScene *m_scene;
35 QChart* m_chart;
35 QChart* m_chart;
36 QRubberBand *m_rubberBand;
36 QRubberBand *m_rubberBand;
37 QPoint m_origin;
37 QPoint m_origin;
38 bool m_showRubberBand;
38 bool m_showRubberBand;
39 Q_DISABLE_COPY(QChartView)
39 Q_DISABLE_COPY(QChartView)
40
40
41
41
42 };
42 };
43
43
44 QTCOMMERCIALCHART_END_NAMESPACE
44 QTCOMMERCIALCHART_END_NAMESPACE
45
45
46 #endif // QCHARTWIDGET_H
46 #endif // QCHARTWIDGET_H
@@ -1,51 +1,51
1 #include "qchartwidget.h"
1 #include "qchartwidget.h"
2 #include "qchartseries.h"
2 #include "qchartseries.h"
3 #include <QGraphicsView>
3 #include <QGraphicsView>
4 #include <QGraphicsScene>
4 #include <QGraphicsScene>
5 #include <QResizeEvent>
5 #include <QResizeEvent>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 QChartWidget::QChartWidget(QWidget *parent) :
9 QChartWidget::QChartWidget(QWidget *parent) :
10 QGraphicsView(parent)
10 QGraphicsView(parent)
11 {
11 {
12 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
12 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
13 m_scene = new QGraphicsScene();
13 m_scene = new QGraphicsScene();
14 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
14 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
15 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
15 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
16 setScene(m_scene);
16 setScene(m_scene);
17
17
18 m_chart = new QChart();
18 m_chart = new QChart();
19 m_scene->addItem(m_chart);
19 m_scene->addItem(m_chart);
20 show();
20 show();
21 }
21 }
22
22
23 QChartWidget::~QChartWidget()
23 QChartWidget::~QChartWidget()
24 {
24 {
25 }
25 }
26
26
27 void QChartWidget::resizeEvent(QResizeEvent *event)
27 void QChartWidget::resizeEvent(QResizeEvent *event)
28 {
28 {
29 m_scene->setSceneRect(0,0,size().width(),size().height());
29 m_scene->setSceneRect(0,0,size().width(),size().height());
30 m_chart->setSize(size());
30 m_chart->setSize(size());
31 QWidget::resizeEvent(event);
31 QWidget::resizeEvent(event);
32 }
32 }
33
33
34 QSize QChartWidget::sizeHint() const
34 QSize QChartWidget::sizeHint() const
35 {
35 {
36 // TODO: calculate size hint based on contents?
36 // TODO: calculate size hint based on contents?
37 return QSize(100, 100);
37 return QSize(100, 100);
38 }
38 }
39
39
40 void QChartWidget::addSeries(QChartSeries* series)
40 void QChartWidget::addSeries(QChartSeries* series)
41 {
41 {
42 m_chart->addSeries(series);
42 m_chart->addSeries(series);
43 }
43 }
44
44
45 QChartSeries* QChartWidget::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type)
45 QChartSeries* QChartWidget::createSeries(QChartSeries::QChartSeriesType type)
46 {
46 {
47 return m_chart->createSeries(x, y, type);
47 return m_chart->createSeries(type);
48 }
48 }
49 #include "moc_qchartwidget.cpp"
49 #include "moc_qchartwidget.cpp"
50
50
51 QTCOMMERCIALCHART_END_NAMESPACE
51 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,40 +1,40
1 #ifndef QCHARTWIDGET_H
1 #ifndef QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qchart.h"
5 #include "qchart.h"
6 #include <QGraphicsView>
6 #include <QGraphicsView>
7
7
8 class QGraphicsScene;
8 class QGraphicsScene;
9
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11
11
12 class QChartSeries;
12 class QChartSeries;
13 class QChartWidgetPrivate;
13 class QChartWidgetPrivate;
14
14
15 class QTCOMMERCIALCHART_EXPORT QChartWidget : public QGraphicsView
15 class QTCOMMERCIALCHART_EXPORT QChartWidget : public QGraphicsView
16 {
16 {
17 Q_OBJECT
17 Q_OBJECT
18 public:
18 public:
19 explicit QChartWidget(QWidget *parent = 0);
19 explicit QChartWidget(QWidget *parent = 0);
20 ~QChartWidget();
20 ~QChartWidget();
21
21
22 //implement from QWidget
22 //implement from QWidget
23 void resizeEvent(QResizeEvent *event);
23 void resizeEvent(QResizeEvent *event);
24 QSize sizeHint() const;
24 QSize sizeHint() const;
25
25
26 // TODO: addSeries and createSeries are optional solutions
26 // TODO: addSeries and createSeries are optional solutions
27 // TODO: currently createSeries assumes x, y value pairs. This isn't case with all charts. So is there another createSeries for other types (for example one list of ints)?
27 // TODO: currently createSeries assumes x, y value pairs. This isn't case with all charts. So is there another createSeries for other types (for example one list of ints)?
28 void addSeries(QChartSeries* series);
28 void addSeries(QChartSeries* series);
29 QChartSeries* createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type);
29 QChartSeries* createSeries(QChartSeries::QChartSeriesType type);
30
30
31 private:
31 private:
32 Q_DISABLE_COPY(QChartWidget)
32 Q_DISABLE_COPY(QChartWidget)
33 QGraphicsScene *m_scene;
33 QGraphicsScene *m_scene;
34 QChart* m_chart;
34 QChart* m_chart;
35
35
36 };
36 };
37
37
38 QTCOMMERCIALCHART_END_NAMESPACE
38 QTCOMMERCIALCHART_END_NAMESPACE
39
39
40 #endif // QCHARTWIDGET_H
40 #endif // QCHARTWIDGET_H
@@ -1,91 +1,97
1 #include "qpieseries.h"
1 #include "qpieseries.h"
2 #include "pieslice.h"
2 #include "pieslice.h"
3 #include <QGraphicsObject>
3 #include <QGraphicsObject>
4 #include <QDebug>
4 #include <QDebug>
5
5
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
7
8 QPieSeries::QPieSeries(QList<qreal> x, QGraphicsObject *parent) :
8 QPieSeries::QPieSeries(QGraphicsObject *parent) :
9 QChartSeries(parent),
9 QChartSeries(parent),
10 m_x(x),
11 m_sizeFactor(1.0)
10 m_sizeFactor(1.0)
12 {
11 {
12 }
13
14 QPieSeries::~QPieSeries()
15 {
16 while (m_slices.count())
17 delete m_slices.takeLast();
18 }
19
20 bool QPieSeries::setData(QList<qreal> data)
21 {
22 m_data = data;
23
13 // Create slices
24 // Create slices
14 qreal fullPie = 360;
25 qreal fullPie = 360;
15 qreal total = 0;
26 qreal total = 0;
16 foreach (qreal value, m_x)
27 foreach (qreal value, m_data)
17 total += value;
28 total += value;
18
29
19 QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent);
30 QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent());
20 Q_ASSERT(parentItem);
31 Q_ASSERT(parentItem);
21 m_chartSize = parentItem->boundingRect();
32 m_chartSize = parentItem->boundingRect();
22 qreal angle = 0;
33 qreal angle = 0;
23 // TODO: no need to create new slices in case size changed; we should re-use the existing ones
34 // TODO: no need to create new slices in case size changed; we should re-use the existing ones
24 foreach (qreal value, m_x) {
35 foreach (qreal value, m_data) {
25 qreal span = value / total * fullPie;
36 qreal span = value / total * fullPie;
26 PieSlice *slice = new PieSlice(randomColor(), angle, span, parentItem->boundingRect());
37 PieSlice *slice = new PieSlice(randomColor(), angle, span, parentItem->boundingRect());
27 slice->setParentItem(parentItem);
38 slice->setParentItem(parentItem);
28 m_slices.append(slice);
39 m_slices.append(slice);
29 angle += span;
40 angle += span;
30 }
41 }
31
42
32 resizeSlices(m_chartSize);
43 resizeSlices(m_chartSize);
33 }
44 return true;
34
35 QPieSeries::~QPieSeries()
36 {
37 while (m_slices.count())
38 delete m_slices.takeLast();
39 }
45 }
40
46
41 void QPieSeries::chartSizeChanged(QRectF chartRect)
47 void QPieSeries::chartSizeChanged(QRectF chartRect)
42 {
48 {
43 // TODO: allow user setting the size?
49 // TODO: allow user setting the size?
44 // TODO: allow user defining the margins?
50 // TODO: allow user defining the margins?
45 m_chartSize = chartRect;
51 m_chartSize = chartRect;
46 resizeSlices(m_chartSize);
52 resizeSlices(m_chartSize);
47 }
53 }
48
54
49 void QPieSeries::resizeSlices(QRectF rect)
55 void QPieSeries::resizeSlices(QRectF rect)
50 {
56 {
51 QRectF tempRect = rect;
57 QRectF tempRect = rect;
52 if (tempRect.width() < tempRect.height()) {
58 if (tempRect.width() < tempRect.height()) {
53 tempRect.setWidth(tempRect.width() * m_sizeFactor);
59 tempRect.setWidth(tempRect.width() * m_sizeFactor);
54 tempRect.setHeight(tempRect.width());
60 tempRect.setHeight(tempRect.width());
55 tempRect.moveCenter(rect.center());
61 tempRect.moveCenter(rect.center());
56 } else {
62 } else {
57 tempRect.setHeight(tempRect.height() * m_sizeFactor);
63 tempRect.setHeight(tempRect.height() * m_sizeFactor);
58 tempRect.setWidth(tempRect.height());
64 tempRect.setWidth(tempRect.height());
59 tempRect.moveCenter(rect.center());
65 tempRect.moveCenter(rect.center());
60 }
66 }
61
67
62 foreach (PieSlice *slice, m_slices)
68 foreach (PieSlice *slice, m_slices)
63 slice->m_rect = tempRect;
69 slice->m_rect = tempRect;
64 }
70 }
65
71
66 void QPieSeries::setSizeFactor(qreal factor)
72 void QPieSeries::setSizeFactor(qreal factor)
67 {
73 {
68 if (factor > 0.0)
74 if (factor > 0.0)
69 m_sizeFactor = factor;
75 m_sizeFactor = factor;
70 resizeSlices(m_chartSize);
76 resizeSlices(m_chartSize);
71
77
72 // Initiate update via the parent graphics item
78 // Initiate update via the parent graphics item
73 // TODO: potential issue: what if this function is called from the parent context?
79 // TODO: potential issue: what if this function is called from the parent context?
74 QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent());
80 QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent());
75 Q_ASSERT(parentItem);
81 Q_ASSERT(parentItem);
76 parentItem->update();
82 parentItem->update();
77 }
83 }
78
84
79 QColor QPieSeries::randomColor()
85 QColor QPieSeries::randomColor()
80 {
86 {
81 QColor c;
87 QColor c;
82 c.setRed(qrand() % 255);
88 c.setRed(qrand() % 255);
83 c.setGreen(qrand() % 255);
89 c.setGreen(qrand() % 255);
84 c.setBlue(qrand() % 255);
90 c.setBlue(qrand() % 255);
85 return c;
91 return c;
86 }
92 }
87
93
88
94
89 #include "moc_qpieseries.cpp"
95 #include "moc_qpieseries.cpp"
90
96
91 QTCOMMERCIALCHART_END_NAMESPACE
97 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,44 +1,45
1 #ifndef PIESERIES_H
1 #ifndef PIESERIES_H
2 #define PIESERIES_H
2 #define PIESERIES_H
3
3
4 #include "qchartseries.h"
4 #include "qchartseries.h"
5 #include <QObject>
5 #include <QObject>
6 #include <QRectF>
6 #include <QRectF>
7 #include <QColor>
7 #include <QColor>
8
8
9 class QGraphicsObject;
9 class QGraphicsObject;
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 class PieSlice;
11 class PieSlice;
12
12
13 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries
13 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries
14 {
14 {
15 Q_OBJECT
15 Q_OBJECT
16
16
17 public:
17 public:
18 // TODO: use a generic data class instead of x and y
18 // TODO: use a generic data class instead of x and y
19 QPieSeries(QList<qreal> x, QGraphicsObject *parent = 0);
19 QPieSeries(QGraphicsObject *parent = 0);
20 ~QPieSeries();
20 ~QPieSeries();
21 QColor randomColor();
21 QColor randomColor();
22 void setSizeFactor(qreal sizeFactor);
22 void setSizeFactor(qreal sizeFactor);
23 qreal sizeFactor() { return m_sizeFactor; }
23 qreal sizeFactor() { return m_sizeFactor; }
24
24
25 public: // from QChartSeries
25 public: // from QChartSeries
26 QChartSeriesType type() const { return QChartSeries::SeriesTypePie; }
26 QChartSeriesType type() const { return QChartSeries::SeriesTypePie; }
27 bool setData(QList<qreal> data);
27
28
28 public Q_SLOTS:
29 public Q_SLOTS:
29 void chartSizeChanged(QRectF rect);
30 void chartSizeChanged(QRectF rect);
30
31
31 private:
32 private:
32 void resizeSlices(QRectF rect);
33 void resizeSlices(QRectF rect);
33 //Q_DECLARE_PRIVATE(QPieSeries)
34 //Q_DECLARE_PRIVATE(QPieSeries)
34 Q_DISABLE_COPY(QPieSeries)
35 Q_DISABLE_COPY(QPieSeries)
35 // TODO: move the followin to internal impl
36 // TODO: move the followin to internal impl
36 QList<qreal> m_x;
37 QList<qreal> m_data;
37 QList<PieSlice*> m_slices;
38 QList<PieSlice*> m_slices;
38 QRectF m_chartSize;
39 QRectF m_chartSize;
39 qreal m_sizeFactor;
40 qreal m_sizeFactor;
40 };
41 };
41
42
42 QTCOMMERCIALCHART_END_NAMESPACE
43 QTCOMMERCIALCHART_END_NAMESPACE
43
44
44 #endif // PIESERIES_H
45 #endif // PIESERIES_H
@@ -1,88 +1,96
1 #include "qscatterseries.h"
1 #include "qscatterseries.h"
2 #include "qscatterseries_p.h"
2 #include "qscatterseries_p.h"
3 #include "qchart.h"
3 #include "qchart.h"
4 #include <QPainter>
4 #include <QPainter>
5 #include <QGraphicsScene>
5 #include <QGraphicsScene>
6 #include <QDebug>
6 #include <QDebug>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 //#define QSeriesData QList<qreal>
10 //#define QSeriesData QList<qreal>
11
11
12 QScatterSeriesPrivate::QScatterSeriesPrivate(QList<qreal> x, QList<qreal> y, QGraphicsItem *parent) :
12 QScatterSeriesPrivate::QScatterSeriesPrivate(QGraphicsItem *parent) :
13 QGraphicsItem(parent),
13 QGraphicsItem(parent),
14 m_x(x),
15 m_y(y),
16 m_scalex(100), // TODO: let the use define the scale (or autoscaled)
14 m_scalex(100), // TODO: let the use define the scale (or autoscaled)
17 m_scaley(100)
15 m_scaley(100)
18 {
16 {
19 resize(parent->boundingRect());
20 }
17 }
21
18
22 void QScatterSeriesPrivate::resize(QRectF rect)
19 void QScatterSeriesPrivate::resize(QRectF rect)
23 {
20 {
24 m_scenex.clear();
21 m_scenex.clear();
25 m_sceney.clear();
22 m_sceney.clear();
26
23
27 foreach(qreal x, m_x)
24 foreach(qreal x, m_x)
28 m_scenex.append(rect.left() + x * (rect.width() / m_scalex));
25 m_scenex.append(rect.left() + x * (rect.width() / m_scalex));
29
26
30 foreach(qreal y, m_y)
27 foreach(qreal y, m_y)
31 m_sceney.append(rect.bottom() - y * (rect.height() / m_scaley));
28 m_sceney.append(rect.bottom() - y * (rect.height() / m_scaley));
32 }
29 }
33
30
34 // TODO:
31 // TODO:
35 //void QScatterSeriesPrivate::setAxisScale(qreal xscale, qreal yscale)
32 //void QScatterSeriesPrivate::setAxisScale(qreal xscale, qreal yscale)
36
33
37 QRectF QScatterSeriesPrivate::boundingRect() const
34 QRectF QScatterSeriesPrivate::boundingRect() const
38 {
35 {
39 return QRectF(0, 0, 55, 100);
36 return QRectF(0, 0, 55, 100);
40 }
37 }
41
38
42 void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
39 void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
43 {
40 {
44 QPen pen = painter->pen();
41 QPen pen = painter->pen();
45 QBrush brush = pen.brush();
42 QBrush brush = pen.brush();
46 // TODO: The opacity should be user definable...
43 // TODO: The opacity should be user definable...
47 brush.setColor(QColor(255, 82, 0, 100));
44 brush.setColor(QColor(255, 82, 0, 100));
48 pen.setBrush(brush);
45 pen.setBrush(brush);
49 pen.setWidth(4);
46 pen.setWidth(4);
50 painter->setPen(pen);
47 painter->setPen(pen);
51
48
52 // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize
49 // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize
53 // event right after construction or maybe given a size during initialization
50 // event right after construction or maybe given a size during initialization
54 for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) {
51 for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) {
55 if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i))
52 if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i))
56 //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760);
53 //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760);
57 painter->drawPoint(m_scenex.at(i), m_sceney.at(i));
54 painter->drawPoint(m_scenex.at(i), m_sceney.at(i));
58 }
55 }
59 }
56 }
60
57
61 QScatterSeries::QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *parent) :
58 QScatterSeries::QScatterSeries(QObject *parent) :
62 QChartSeries(parent),
59 QChartSeries(parent),
63 d(new QScatterSeriesPrivate(x, y, qobject_cast<QGraphicsItem *> (parent)))
60 d(new QScatterSeriesPrivate(qobject_cast<QGraphicsItem *> (parent)))
64 {
61 {
65 }
62 }
66
63
64 bool QScatterSeries::setData(QList<qreal> x, QList<qreal> y)
65 {
66 // TODO: validate data
67 d->m_x = x;
68 d->m_y = y;
69 QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent());
70 Q_ASSERT(parentItem);
71 d->resize(parentItem->boundingRect());
72 return true;
73 }
74
67 void QScatterSeries::chartSizeChanged(QRectF rect)
75 void QScatterSeries::chartSizeChanged(QRectF rect)
68 {
76 {
69 // Recalculate scatter data point locations on the scene
77 // Recalculate scatter data point locations on the scene
70 // d->transform().reset();
78 // d->transform().reset();
71 // d->transform().translate();
79 // d->transform().translate();
72 d->resize(rect);
80 d->resize(rect);
73 }
81 }
74
82
75 // TODO:
83 // TODO:
76 //void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale)
84 //void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale)
77 //{
85 //{
78 // d->rescale(xscale, yscale);
86 // d->rescale(xscale, yscale);
79 //}
87 //}
80
88
81 QScatterSeries::~QScatterSeries()
89 QScatterSeries::~QScatterSeries()
82 {
90 {
83 delete d;
91 delete d;
84 }
92 }
85
93
86 #include "moc_qscatterseries.cpp"
94 #include "moc_qscatterseries.cpp"
87
95
88 QTCOMMERCIALCHART_END_NAMESPACE
96 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,34 +1,35
1 #ifndef QSCATTERSERIES_H
1 #ifndef QSCATTERSERIES_H
2 #define QSCATTERSERIES_H
2 #define QSCATTERSERIES_H
3
3
4 #include "qchartseries.h"
4 #include "qchartseries.h"
5 #include <QRectF>
5 #include <QRectF>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 class QScatterSeriesPrivate;
8 class QScatterSeriesPrivate;
9
9
10 class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries
10 class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries
11 {
11 {
12 Q_OBJECT
12 Q_OBJECT
13 public:
13 public:
14 //QScatterSeries(QSeriesData *data, QObject *chart);
14 //QScatterSeries(QSeriesData *data, QObject *chart);
15 QScatterSeries(QList<qreal> x, QList<qreal> y, QObject *parent = 0);
15 QScatterSeries(QObject *parent = 0);
16 ~QScatterSeries();
16 ~QScatterSeries();
17
17
18 public: // from QChartSeries
18 public: // from QChartSeries
19 QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; }
19 QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; }
20 bool setData(QList<qreal> x, QList<qreal> y);
20
21
21 public Q_SLOTS:
22 public Q_SLOTS:
22 void chartSizeChanged(QRectF rect);
23 void chartSizeChanged(QRectF rect);
23 //void chartScaleChanged(qreal xscale, qreal yscale);
24 //void chartScaleChanged(qreal xscale, qreal yscale);
24
25
25 private:
26 private:
26 Q_DECLARE_PRIVATE(QScatterSeries)
27 Q_DECLARE_PRIVATE(QScatterSeries)
27 Q_DISABLE_COPY(QScatterSeries)
28 Q_DISABLE_COPY(QScatterSeries)
28 friend class QChart;
29 friend class QChart;
29 QScatterSeriesPrivate *const d;
30 QScatterSeriesPrivate *const d;
30 };
31 };
31
32
32 QTCOMMERCIALCHART_END_NAMESPACE
33 QTCOMMERCIALCHART_END_NAMESPACE
33
34
34 #endif // QSCATTERSERIES_H
35 #endif // QSCATTERSERIES_H
@@ -1,33 +1,33
1 #ifndef QSCATTERSERIESPRIVATE_H
1 #ifndef QSCATTERSERIESPRIVATE_H
2 #define QSCATTERSERIESPRIVATE_H
2 #define QSCATTERSERIESPRIVATE_H
3
3
4 #include "qchartseries.h"
4 #include "qchartseries.h"
5 #include <QGraphicsItem>
5 #include <QGraphicsItem>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 /*!
9 /*!
10 * The PIMPL class of QScatterSeries.
10 * The PIMPL class of QScatterSeries.
11 */
11 */
12 class QScatterSeriesPrivate : public QGraphicsItem
12 class QScatterSeriesPrivate : public QGraphicsItem
13 {
13 {
14 public:
14 public:
15 QScatterSeriesPrivate(QList<qreal> x, QList<qreal> y, QGraphicsItem *parent);
15 QScatterSeriesPrivate(QGraphicsItem *parent);
16
16
17 public: // from QGraphicsItem
17 public: // from QGraphicsItem
18 void resize(QRectF rect);
18 void resize(QRectF rect);
19 QRectF boundingRect() const;
19 QRectF boundingRect() const;
20 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
20 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
21
21
22 // TODO: use the chart data class instead of list of x and y values?
22 // TODO: use the chart data class instead of list of x and y values?
23 QList<qreal> m_x;
23 QList<qreal> m_x;
24 QList<qreal> m_y;
24 QList<qreal> m_y;
25 qreal m_scalex;
25 qreal m_scalex;
26 qreal m_scaley;
26 qreal m_scaley;
27 QList<qreal> m_scenex;
27 QList<qreal> m_scenex;
28 QList<qreal> m_sceney;
28 QList<qreal> m_sceney;
29 };
29 };
30
30
31 QTCOMMERCIALCHART_END_NAMESPACE
31 QTCOMMERCIALCHART_END_NAMESPACE
32
32
33 #endif // QSCATTERSERIES_H
33 #endif // QSCATTERSERIES_H
@@ -1,271 +1,267
1 #include "mainwidget.h"
1 #include "mainwidget.h"
2 #include "dataseriedialog.h"
2 #include "dataseriedialog.h"
3 #include "qchartseries.h"
3 #include "qchartseries.h"
4 #include "qpieseries.h"
4 #include "qpieseries.h"
5 #include <qxychartseries.h>
5 #include <qxychartseries.h>
6 #include <QPushButton>
6 #include <QPushButton>
7 #include <QComboBox>
7 #include <QComboBox>
8 #include <QSpinBox>
8 #include <QSpinBox>
9 #include <QCheckBox>
9 #include <QCheckBox>
10 #include <QGridLayout>
10 #include <QGridLayout>
11 #include <QHBoxLayout>
11 #include <QHBoxLayout>
12 #include <QLabel>
12 #include <QLabel>
13 #include <QSpacerItem>
13 #include <QSpacerItem>
14 #include <QMessageBox>
14 #include <QMessageBox>
15 #include <cmath>
15 #include <cmath>
16 #include <QDebug>
16 #include <QDebug>
17
17
18 QTCOMMERCIALCHART_USE_NAMESPACE
18 QTCOMMERCIALCHART_USE_NAMESPACE
19
19
20 MainWidget::MainWidget(QWidget *parent) :
20 MainWidget::MainWidget(QWidget *parent) :
21 QWidget(parent)
21 QWidget(parent)
22 {
22 {
23 QPushButton *addSeriesButton = new QPushButton("Add series");
23 QPushButton *addSeriesButton = new QPushButton("Add series");
24 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
24 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
25
25
26 // Chart background
26 // Chart background
27 QComboBox *backgroundCombo = new QComboBox(this);
27 QComboBox *backgroundCombo = new QComboBox(this);
28 backgroundCombo->addItem("None");
28 backgroundCombo->addItem("None");
29 backgroundCombo->addItem("TODO Grid");
29 backgroundCombo->addItem("TODO Grid");
30 backgroundCombo->addItem("TODO Image");
30 backgroundCombo->addItem("TODO Image");
31 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
31 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
32 this, SLOT(backgroundChanged(int)));
32 this, SLOT(backgroundChanged(int)));
33
33
34 // Axis
34 // Axis
35 // TODO: multiple axes?
35 // TODO: multiple axes?
36 m_autoScaleCheck = new QCheckBox("Automatic scaling");
36 m_autoScaleCheck = new QCheckBox("Automatic scaling");
37 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
37 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
38 // Allow setting also non-sense values (like -2147483648 and 2147483647)
38 // Allow setting also non-sense values (like -2147483648 and 2147483647)
39 m_xMinSpin = new QSpinBox();
39 m_xMinSpin = new QSpinBox();
40 m_xMinSpin->setMinimum(INT_MIN);
40 m_xMinSpin->setMinimum(INT_MIN);
41 m_xMinSpin->setMaximum(INT_MAX);
41 m_xMinSpin->setMaximum(INT_MAX);
42 m_xMinSpin->setValue(0);
42 m_xMinSpin->setValue(0);
43 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
43 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
44 m_xMaxSpin = new QSpinBox();
44 m_xMaxSpin = new QSpinBox();
45 m_xMaxSpin->setMinimum(INT_MIN);
45 m_xMaxSpin->setMinimum(INT_MIN);
46 m_xMaxSpin->setMaximum(INT_MAX);
46 m_xMaxSpin->setMaximum(INT_MAX);
47 m_xMaxSpin->setValue(10);
47 m_xMaxSpin->setValue(10);
48 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
48 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
49 m_yMinSpin = new QSpinBox();
49 m_yMinSpin = new QSpinBox();
50 m_yMinSpin->setMinimum(INT_MIN);
50 m_yMinSpin->setMinimum(INT_MIN);
51 m_yMinSpin->setMaximum(INT_MAX);
51 m_yMinSpin->setMaximum(INT_MAX);
52 m_yMinSpin->setValue(0);
52 m_yMinSpin->setValue(0);
53 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
53 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
54 m_yMaxSpin = new QSpinBox();
54 m_yMaxSpin = new QSpinBox();
55 m_yMaxSpin->setMinimum(INT_MIN);
55 m_yMaxSpin->setMinimum(INT_MIN);
56 m_yMaxSpin->setMaximum(INT_MAX);
56 m_yMaxSpin->setMaximum(INT_MAX);
57 m_yMaxSpin->setValue(10);
57 m_yMaxSpin->setValue(10);
58 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
58 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
59
59
60 QGridLayout *grid = new QGridLayout();
60 QGridLayout *grid = new QGridLayout();
61 QGridLayout *mainLayout = new QGridLayout();
61 QGridLayout *mainLayout = new QGridLayout();
62 //grid->addWidget(new QLabel("Add series:"), 0, 0);
62 //grid->addWidget(new QLabel("Add series:"), 0, 0);
63 grid->addWidget(addSeriesButton, 0, 1);
63 grid->addWidget(addSeriesButton, 0, 1);
64 grid->addWidget(new QLabel("Background:"), 2, 0);
64 grid->addWidget(new QLabel("Background:"), 2, 0);
65 grid->addWidget(backgroundCombo, 2, 1);
65 grid->addWidget(backgroundCombo, 2, 1);
66 grid->addWidget(m_autoScaleCheck, 3, 0);
66 grid->addWidget(m_autoScaleCheck, 3, 0);
67 grid->addWidget(new QLabel("x min:"), 4, 0);
67 grid->addWidget(new QLabel("x min:"), 4, 0);
68 grid->addWidget(m_xMinSpin, 4, 1);
68 grid->addWidget(m_xMinSpin, 4, 1);
69 grid->addWidget(new QLabel("x max:"), 5, 0);
69 grid->addWidget(new QLabel("x max:"), 5, 0);
70 grid->addWidget(m_xMaxSpin, 5, 1);
70 grid->addWidget(m_xMaxSpin, 5, 1);
71 grid->addWidget(new QLabel("y min:"), 6, 0);
71 grid->addWidget(new QLabel("y min:"), 6, 0);
72 grid->addWidget(m_yMinSpin, 6, 1);
72 grid->addWidget(m_yMinSpin, 6, 1);
73 grid->addWidget(new QLabel("y max:"), 7, 0);
73 grid->addWidget(new QLabel("y max:"), 7, 0);
74 grid->addWidget(m_yMaxSpin, 7, 1);
74 grid->addWidget(m_yMaxSpin, 7, 1);
75 // add row with empty label to make all the other rows static
75 // add row with empty label to make all the other rows static
76 grid->addWidget(new QLabel(""), 8, 0);
76 grid->addWidget(new QLabel(""), 8, 0);
77 grid->setRowStretch(8, 1);
77 grid->setRowStretch(8, 1);
78
78
79 mainLayout->addLayout(grid, 0, 0);
79 mainLayout->addLayout(grid, 0, 0);
80
80
81 // Scatter specific settings
81 // Scatter specific settings
82 m_scatterLayout = new QGridLayout();
82 m_scatterLayout = new QGridLayout();
83 m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0);
83 m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0);
84 m_scatterLayout->setEnabled(false);
84 m_scatterLayout->setEnabled(false);
85
85
86 // Pie specific settings
86 // Pie specific settings
87 m_pieLayout = new QGridLayout();
87 m_pieLayout = new QGridLayout();
88 m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0);
88 m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0);
89 QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox();
89 QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox();
90 pieSizeSpin->setMinimum(LONG_MIN);
90 pieSizeSpin->setMinimum(LONG_MIN);
91 pieSizeSpin->setMaximum(LONG_MAX);
91 pieSizeSpin->setMaximum(LONG_MAX);
92 pieSizeSpin->setValue(1.0);
92 pieSizeSpin->setValue(1.0);
93 pieSizeSpin->setSingleStep(0.1);
93 pieSizeSpin->setSingleStep(0.1);
94 connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double)));
94 connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double)));
95 m_pieLayout->setEnabled(false);
95 m_pieLayout->setEnabled(false);
96 m_pieLayout->addWidget(pieSizeSpin, 0, 1);
96 m_pieLayout->addWidget(pieSizeSpin, 0, 1);
97
97
98 mainLayout->addLayout(m_scatterLayout, 1, 0);
98 mainLayout->addLayout(m_scatterLayout, 1, 0);
99 mainLayout->addLayout(m_pieLayout, 2, 0);
99 mainLayout->addLayout(m_pieLayout, 2, 0);
100
100
101 m_chartWidget = new QChartWidget(this);
101 m_chartWidget = new QChartWidget(this);
102 //m_chartWidget->setColor(Qt::red);
102 //m_chartWidget->setColor(Qt::red);
103 mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1);
103 mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1);
104 // hbox->setStretch(1, 1);
104 // hbox->setStretch(1, 1);
105
105
106 setLayout(mainLayout);
106 setLayout(mainLayout);
107
107
108 m_autoScaleCheck->setChecked(true);
108 m_autoScaleCheck->setChecked(true);
109 testDataChanged(0);
109 testDataChanged(0);
110 }
110 }
111
111
112 void MainWidget::addSeries()
112 void MainWidget::addSeries()
113 {
113 {
114 DataSerieDialog dialog(m_defaultSeriesName, this);
114 DataSerieDialog dialog(m_defaultSeriesName, this);
115 connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString)));
115 connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString)));
116 dialog.exec();
116 dialog.exec();
117 }
117 }
118
118
119 void MainWidget::addSeries(QString series, QString data)
119 void MainWidget::addSeries(QString series, QString data)
120 {
120 {
121 qDebug() << "addSeries: " << series << " data: " << data;
121 qDebug() << "addSeries: " << series << " data: " << data;
122 m_defaultSeriesName = series;
122 m_defaultSeriesName = series;
123 QChartSeries *newSeries = QXYChartSeries::create();
124
123
125 // TODO: a dedicated data class for storing x and y values
124 // TODO: a dedicated data class for storing x and y values
126 QList<qreal> x;
125 QList<qreal> x;
127 QList<qreal> y;
126 QList<qreal> y;
128
127
129 if (data == "linear") {
128 if (data == "linear") {
130 for (int i = 0; i < 20; i++) {
129 for (int i = 0; i < 20; i++) {
131 x.append(i);
130 x.append(i);
132 y.append(i);
131 y.append(i);
133 }
132 }
134 for (int i = 0; i < 20; i++)
135 ((QXYChartSeries *)newSeries)->add(i, i);
136 } else if (data == "linear, 1M") {
133 } else if (data == "linear, 1M") {
137 for (int i = 0; i < 10000; i++) {
134 for (int i = 0; i < 10000; i++) {
138 x.append(i);
135 x.append(i);
139 y.append(20);
136 y.append(20);
140 }
137 }
141 for (int i = 0; i < 1000000; i++)
142 ((QXYChartSeries *)newSeries)->add(i, 10);
143 } else if (data == "SIN") {
138 } else if (data == "SIN") {
144 for (int i = 0; i < 100; i++) {
139 for (int i = 0; i < 100; i++) {
145 x.append(i);
140 x.append(i);
146 y.append(abs(sin(3.14159265358979 / 50 * i) * 100));
141 y.append(abs(sin(3.14159265358979 / 50 * i) * 100));
147 }
142 }
148 for (int i = 0; i < 100; i++)
149 ((QXYChartSeries *)newSeries)->add(i, abs(sin(3.14159265358979 / 50 * i) * 100));
150 } else if (data == "SIN + random") {
143 } else if (data == "SIN + random") {
151 for (qreal i = 0; i < 100; i += 0.1) {
144 for (qreal i = 0; i < 100; i += 0.1) {
152 x.append(i + (rand() % 5));
145 x.append(i + (rand() % 5));
153 y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
146 y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
154 }
147 }
155 for (qreal i = 0; i < 100; i += 0.1)
156 ((QXYChartSeries *)newSeries)->add(i + (rand() % 5), abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
157 } else {
148 } else {
158 // TODO: check if data has a valid file name
149 // TODO: check if data has a valid file name
150 Q_ASSERT(false);
159 }
151 }
160
152
161 // TODO: color of the series
153 // TODO: color of the series
154 QChartSeries *newSeries = 0;
162 if (series == "Scatter") {
155 if (series == "Scatter") {
163 newSeries = m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypeScatter);
156 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter);
157 Q_ASSERT(newSeries->setData(x, y));
164 } else if (series == "Pie") {
158 } else if (series == "Pie") {
165 newSeries = m_chartWidget->createSeries(x, y, QChartSeries::SeriesTypePie);
159 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie);
160 Q_ASSERT(newSeries->setData(y));
166 } else if (series == "Line") {
161 } else if (series == "Line") {
167 m_chartWidget->addSeries(newSeries);
162 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie);
163 Q_ASSERT(newSeries->setData(x, y));
168 } else {
164 } else {
169 // TODO
165 // TODO
170 }
166 }
171
167
172 setCurrentSeries(newSeries);
168 setCurrentSeries(newSeries);
173 }
169 }
174
170
175 void MainWidget::setCurrentSeries(QChartSeries *series)
171 void MainWidget::setCurrentSeries(QChartSeries *series)
176 {
172 {
177 m_currentSeries = series;
173 m_currentSeries = series;
178 switch (m_currentSeries->type()) {
174 switch (m_currentSeries->type()) {
179 case QChartSeries::SeriesTypeLine:
175 case QChartSeries::SeriesTypeLine:
180 break;
176 break;
181 case QChartSeries::SeriesTypeScatter:
177 case QChartSeries::SeriesTypeScatter:
182 break;
178 break;
183 case QChartSeries::SeriesTypePie:
179 case QChartSeries::SeriesTypePie:
184 break;
180 break;
185 default:
181 default:
186 Q_ASSERT(false);
182 Q_ASSERT(false);
187 break;
183 break;
188 }
184 }
189 }
185 }
190
186
191 void MainWidget::testDataChanged(int itemIndex)
187 void MainWidget::testDataChanged(int itemIndex)
192 {
188 {
193 qDebug() << "testDataChanged: " << itemIndex;
189 qDebug() << "testDataChanged: " << itemIndex;
194
190
195 // switch (itemIndex) {
191 // switch (itemIndex) {
196 // case 0: {
192 // case 0: {
197 // QList<QChartDataPoint> data;
193 // QList<QChartDataPoint> data;
198 // for (int x = 0; x < 20; x++) {
194 // for (int x = 0; x < 20; x++) {
199 // data.append(QChartDataPoint() << x << x / 2);
195 // data.append(QChartDataPoint() << x << x / 2);
200 // }
196 // }
201 // m_chartWidget->setData(data);
197 // m_chartWidget->setData(data);
202 // break;
198 // break;
203 // }
199 // }
204 // case 1: {
200 // case 1: {
205 // QList<QChartDataPoint> data;
201 // QList<QChartDataPoint> data;
206 // for (int x = 0; x < 100; x++) {
202 // for (int x = 0; x < 100; x++) {
207 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100));
203 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100));
208 // }
204 // }
209 // m_chartWidget->setData(data);
205 // m_chartWidget->setData(data);
210 // break;
206 // break;
211 // }
207 // }
212 // case 2: {
208 // case 2: {
213 // QList<QChartDataPoint> data;
209 // QList<QChartDataPoint> data;
214 // for (int x = 0; x < 1000; x++) {
210 // for (int x = 0; x < 1000; x++) {
215 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
211 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
216 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
212 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
217 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
213 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
218 // }
214 // }
219 // m_chartWidget->setData(data);
215 // m_chartWidget->setData(data);
220 // break;
216 // break;
221 // }
217 // }
222 // default:
218 // default:
223 // break;
219 // break;
224 // }
220 // }
225 }
221 }
226
222
227 void MainWidget::backgroundChanged(int itemIndex)
223 void MainWidget::backgroundChanged(int itemIndex)
228 {
224 {
229 qDebug() << "backgroundChanged: " << itemIndex;
225 qDebug() << "backgroundChanged: " << itemIndex;
230 }
226 }
231
227
232 void MainWidget::autoScaleChanged(int value)
228 void MainWidget::autoScaleChanged(int value)
233 {
229 {
234 if (value) {
230 if (value) {
235 // TODO: enable auto scaling
231 // TODO: enable auto scaling
236 } else {
232 } else {
237 // TODO: set scaling manually (and disable auto scaling)
233 // TODO: set scaling manually (and disable auto scaling)
238 }
234 }
239
235
240 m_xMinSpin->setEnabled(!value);
236 m_xMinSpin->setEnabled(!value);
241 m_xMaxSpin->setEnabled(!value);
237 m_xMaxSpin->setEnabled(!value);
242 m_yMinSpin->setEnabled(!value);
238 m_yMinSpin->setEnabled(!value);
243 m_yMaxSpin->setEnabled(!value);
239 m_yMaxSpin->setEnabled(!value);
244 }
240 }
245
241
246 void MainWidget::xMinChanged(int value)
242 void MainWidget::xMinChanged(int value)
247 {
243 {
248 qDebug() << "xMinChanged: " << value;
244 qDebug() << "xMinChanged: " << value;
249 }
245 }
250
246
251 void MainWidget::xMaxChanged(int value)
247 void MainWidget::xMaxChanged(int value)
252 {
248 {
253 qDebug() << "xMaxChanged: " << value;
249 qDebug() << "xMaxChanged: " << value;
254 }
250 }
255
251
256 void MainWidget::yMinChanged(int value)
252 void MainWidget::yMinChanged(int value)
257 {
253 {
258 qDebug() << "yMinChanged: " << value;
254 qDebug() << "yMinChanged: " << value;
259 }
255 }
260
256
261 void MainWidget::yMaxChanged(int value)
257 void MainWidget::yMaxChanged(int value)
262 {
258 {
263 qDebug() << "yMaxChanged: " << value;
259 qDebug() << "yMaxChanged: " << value;
264 }
260 }
265
261
266 void MainWidget::setPieSizeFactor(double size)
262 void MainWidget::setPieSizeFactor(double size)
267 {
263 {
268 QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
264 QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
269 Q_ASSERT(pie);
265 Q_ASSERT(pie);
270 pie->setSizeFactor(qreal(size));
266 pie->setSizeFactor(qreal(size));
271 }
267 }
General Comments 0
You need to be logged in to leave comments. Login now