@@ -1,412 +1,402 | |||||
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 "qpieseries_p.h" |
|
6 | #include "qpieseries_p.h" | |
7 | #include "qxychartseries.h" |
|
7 | #include "qxychartseries.h" | |
8 | #include "qchartaxis.h" |
|
8 | #include "qchartaxis.h" | |
9 | #include "barchartseries.h" |
|
9 | #include "barchartseries.h" | |
10 | #include "bargroup.h" |
|
10 | #include "bargroup.h" | |
11 | #include "stackedbarchartseries.h" |
|
11 | #include "stackedbarchartseries.h" | |
12 | #include "stackedbargroup.h" |
|
12 | #include "stackedbargroup.h" | |
13 | #include "percentbarchartseries.h" |
|
13 | #include "percentbarchartseries.h" | |
14 | #include "percentbargroup.h" |
|
14 | #include "percentbargroup.h" | |
15 | #include "charttheme_p.h" |
|
15 | #include "charttheme_p.h" | |
16 | #include "chartitem_p.h" |
|
16 | #include "chartitem_p.h" | |
17 |
|
17 | |||
18 | #include "xylinechartitem_p.h" |
|
18 | #include "xylinechartitem_p.h" | |
19 | #include "plotdomain_p.h" |
|
19 | #include "plotdomain_p.h" | |
20 | #include "axisitem_p.h" |
|
20 | #include "axisitem_p.h" | |
21 | #include <QGraphicsScene> |
|
21 | #include <QGraphicsScene> | |
22 | #include <QDebug> |
|
22 | #include <QDebug> | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), |
|
26 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), | |
27 | m_backgroundItem(0), |
|
27 | m_backgroundItem(0), | |
28 | m_titleItem(0), |
|
28 | m_titleItem(0), | |
29 | m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)), |
|
29 | m_axisXItem(new AxisItem(AxisItem::X_AXIS, this)), | |
30 | m_plotDataIndex(0), |
|
30 | m_plotDataIndex(0), | |
31 | m_marginSize(0), |
|
31 | m_marginSize(0), | |
32 | m_chartTheme(new ChartTheme(this)) |
|
32 | m_chartTheme(new ChartTheme(this)) | |
33 | { |
|
33 | { | |
34 | // TODO: the default theme? |
|
34 | // TODO: the default theme? | |
35 | setTheme(QChart::ChartThemeDefault); |
|
35 | setTheme(QChart::ChartThemeDefault); | |
36 |
|
36 | |||
37 | PlotDomain domain; |
|
37 | PlotDomain domain; | |
38 | m_plotDomainList << domain; |
|
38 | m_plotDomainList << domain; | |
39 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); |
|
39 | m_axisYItem << new AxisItem(AxisItem::Y_AXIS,this); | |
40 | m_chartItems << m_axisXItem; |
|
40 | m_chartItems << m_axisXItem; | |
41 | m_chartItems << m_axisYItem.at(0); |
|
41 | m_chartItems << m_axisYItem.at(0); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | QChart::~QChart(){} |
|
44 | QChart::~QChart(){} | |
45 |
|
45 | |||
46 | QRectF QChart::boundingRect() const |
|
46 | QRectF QChart::boundingRect() const | |
47 | { |
|
47 | { | |
48 | return m_rect; |
|
48 | return m_rect; | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void QChart::addSeries(QChartSeries* series) |
|
51 | void QChart::addSeries(QChartSeries* series) | |
52 | { |
|
52 | { | |
53 | // TODO: we should check the series not already added |
|
53 | // TODO: we should check the series not already added | |
54 |
|
54 | |||
55 | m_chartSeries << series; |
|
55 | m_chartSeries << series; | |
56 |
|
56 | |||
|
57 | m_plotDataIndex = 0 ; | |||
|
58 | m_plotDomainList.resize(1); | |||
|
59 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; | |||
|
60 | ||||
57 | switch(series->type()) |
|
61 | switch(series->type()) | |
58 | { |
|
62 | { | |
59 | case QChartSeries::SeriesTypeLine: { |
|
63 | case QChartSeries::SeriesTypeLine: { | |
60 |
|
64 | |||
61 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); |
|
65 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); | |
62 | m_plotDataIndex = 0 ; |
|
|||
63 | m_plotDomainList.resize(1); |
|
|||
64 |
|
||||
65 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; |
|
|||
66 |
|
66 | |||
67 | for (int i = 0 ; i < xyseries->count() ; i++) { |
|
67 | for (int i = 0 ; i < xyseries->count() ; i++) { | |
68 | qreal x = xyseries->x(i); |
|
68 | qreal x = xyseries->x(i); | |
69 | qreal y = xyseries->y(i); |
|
69 | qreal y = xyseries->y(i); | |
70 | domain.m_minX = qMin(domain.m_minX,x); |
|
70 | domain.m_minX = qMin(domain.m_minX,x); | |
71 | domain.m_minY = qMin(domain.m_minY,y); |
|
71 | domain.m_minY = qMin(domain.m_minY,y); | |
72 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
72 | domain.m_maxX = qMax(domain.m_maxX,x); | |
73 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
73 | domain.m_maxY = qMax(domain.m_maxY,y); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); |
|
76 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); | |
77 |
|
77 | |||
78 | m_chartItems << item; |
|
78 | m_chartItems << item; | |
79 | // TODO: |
|
79 | // TODO: | |
80 | //m_chartTheme->addObserver(xyseries); |
|
80 | //m_chartTheme->addObserver(xyseries); | |
81 |
|
81 | |||
82 | break; |
|
82 | break; | |
83 | } |
|
83 | } | |
84 | case QChartSeries::SeriesTypeBar: { |
|
84 | case QChartSeries::SeriesTypeBar: { | |
85 |
|
85 | |||
86 | qDebug() << "barSeries added"; |
|
86 | qDebug() << "barSeries added"; | |
87 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
87 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
88 | BarGroup* barGroup = new BarGroup(*barSeries,this); |
|
88 | BarGroup* barGroup = new BarGroup(*barSeries,this); | |
89 |
|
89 | |||
90 | // Add some fugly colors for 5 fist series... |
|
90 | // Add some fugly colors for 5 fist series... | |
91 | barGroup->addColor(QColor(255,0,0,128)); |
|
91 | barGroup->addColor(QColor(255,0,0,128)); | |
92 | barGroup->addColor(QColor(255,255,0,128)); |
|
92 | barGroup->addColor(QColor(255,255,0,128)); | |
93 | barGroup->addColor(QColor(0,255,0,128)); |
|
93 | barGroup->addColor(QColor(0,255,0,128)); | |
94 | barGroup->addColor(QColor(0,0,255,128)); |
|
94 | barGroup->addColor(QColor(0,0,255,128)); | |
95 | barGroup->addColor(QColor(255,128,0,128)); |
|
95 | barGroup->addColor(QColor(255,128,0,128)); | |
96 |
|
96 | |||
97 | m_chartItems << barGroup; |
|
97 | m_chartItems << barGroup; | |
98 | childItems().append(barGroup); |
|
98 | childItems().append(barGroup); | |
99 |
|
99 | |||
100 | // TODO: setting of domain should this be somewhere else. |
|
|||
101 | m_plotDataIndex = 0 ; |
|
|||
102 | m_plotDomainList.resize(1); |
|
|||
103 |
|
||||
104 | qreal x = barSeries->countColumns(); |
|
100 | qreal x = barSeries->countColumns(); | |
105 | qreal y = barSeries->max(); |
|
101 | qreal y = barSeries->max(); | |
106 |
|
||||
107 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; |
|
|||
108 |
|
||||
109 | domain.m_minX = qMin(domain.m_minX,x); |
|
102 | domain.m_minX = qMin(domain.m_minX,x); | |
110 | domain.m_minY = qMin(domain.m_minY,y); |
|
103 | domain.m_minY = qMin(domain.m_minY,y); | |
111 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
104 | domain.m_maxX = qMax(domain.m_maxX,x); | |
112 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
105 | domain.m_maxY = qMax(domain.m_maxY,y); | |
113 | break; |
|
106 | break; | |
114 | } |
|
107 | } | |
115 | case QChartSeries::SeriesTypeStackedBar: { |
|
108 | case QChartSeries::SeriesTypeStackedBar: { | |
116 |
|
109 | |||
117 | qDebug() << "barSeries added"; |
|
110 | qDebug() << "barSeries added"; | |
118 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
111 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); | |
119 | StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this); |
|
112 | StackedBarGroup* stackedBarGroup = new StackedBarGroup(*stackedBarSeries,this); | |
120 |
|
113 | |||
121 | // Add some fugly colors for 5 fist series... |
|
114 | // Add some fugly colors for 5 fist series... | |
122 | stackedBarGroup->addColor(QColor(255,0,0,128)); |
|
115 | stackedBarGroup->addColor(QColor(255,0,0,128)); | |
123 | stackedBarGroup->addColor(QColor(255,255,0,128)); |
|
116 | stackedBarGroup->addColor(QColor(255,255,0,128)); | |
124 | stackedBarGroup->addColor(QColor(0,255,0,128)); |
|
117 | stackedBarGroup->addColor(QColor(0,255,0,128)); | |
125 | stackedBarGroup->addColor(QColor(0,0,255,128)); |
|
118 | stackedBarGroup->addColor(QColor(0,0,255,128)); | |
126 | stackedBarGroup->addColor(QColor(255,128,0,128)); |
|
119 | stackedBarGroup->addColor(QColor(255,128,0,128)); | |
127 |
|
120 | |||
128 | m_chartItems << stackedBarGroup; |
|
121 | m_chartItems << stackedBarGroup; | |
129 | childItems().append(stackedBarGroup); |
|
122 | childItems().append(stackedBarGroup); | |
130 |
|
123 | |||
131 | // TODO: setting of domain should this be somewhere else. |
|
|||
132 | m_plotDataIndex = 0 ; |
|
|||
133 | m_plotDomainList.resize(1); |
|
|||
134 |
|
||||
135 | qreal x = stackedBarSeries->countColumns(); |
|
124 | qreal x = stackedBarSeries->countColumns(); | |
136 | qreal y = stackedBarSeries->maxColumnSum(); |
|
125 | qreal y = stackedBarSeries->maxColumnSum(); | |
137 |
|
||||
138 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; |
|
|||
139 |
|
||||
140 | domain.m_minX = qMin(domain.m_minX,x); |
|
126 | domain.m_minX = qMin(domain.m_minX,x); | |
141 | domain.m_minY = qMin(domain.m_minY,y); |
|
127 | domain.m_minY = qMin(domain.m_minY,y); | |
142 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
128 | domain.m_maxX = qMax(domain.m_maxX,x); | |
143 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
129 | domain.m_maxY = qMax(domain.m_maxY,y); | |
144 | break; |
|
130 | break; | |
145 | } |
|
131 | } | |
146 | case QChartSeries::SeriesTypePercentBar: { |
|
132 | case QChartSeries::SeriesTypePercentBar: { | |
147 |
|
133 | |||
148 | qDebug() << "barSeries added"; |
|
134 | qDebug() << "barSeries added"; | |
149 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
135 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); | |
150 | PercentBarGroup* percentBarGroup = new PercentBarGroup(*percentBarSeries,this); |
|
136 | PercentBarGroup* percentBarGroup = new PercentBarGroup(*percentBarSeries,this); | |
151 |
|
137 | |||
152 | // Add some fugly colors for 5 fist series... |
|
138 | // Add some fugly colors for 5 fist series... | |
153 | percentBarGroup->addColor(QColor(255,0,0,128)); |
|
139 | percentBarGroup->addColor(QColor(255,0,0,128)); | |
154 | percentBarGroup->addColor(QColor(255,255,0,128)); |
|
140 | percentBarGroup->addColor(QColor(255,255,0,128)); | |
155 | percentBarGroup->addColor(QColor(0,255,0,128)); |
|
141 | percentBarGroup->addColor(QColor(0,255,0,128)); | |
156 | percentBarGroup->addColor(QColor(0,0,255,128)); |
|
142 | percentBarGroup->addColor(QColor(0,0,255,128)); | |
157 | percentBarGroup->addColor(QColor(255,128,0,128)); |
|
143 | percentBarGroup->addColor(QColor(255,128,0,128)); | |
158 |
|
144 | |||
159 | m_chartItems << percentBarGroup; |
|
145 | m_chartItems << percentBarGroup; | |
160 | childItems().append(percentBarGroup); |
|
146 | childItems().append(percentBarGroup); | |
161 |
|
147 | |||
162 | // TODO: setting of domain should this be somewhere else. |
|
|||
163 | m_plotDataIndex = 0 ; |
|
|||
164 | m_plotDomainList.resize(1); |
|
|||
165 |
|
||||
166 | qreal x = percentBarSeries->countColumns(); |
|
148 | qreal x = percentBarSeries->countColumns(); | |
167 |
|
||||
168 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; |
|
|||
169 |
|
||||
170 | domain.m_minX = qMin(domain.m_minX,x); |
|
149 | domain.m_minX = qMin(domain.m_minX,x); | |
171 | domain.m_minY = 0; |
|
150 | domain.m_minY = 0; | |
172 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
151 | domain.m_maxX = qMax(domain.m_maxX,x); | |
173 | domain.m_maxY = 100; |
|
152 | domain.m_maxY = 100; | |
174 | break; |
|
153 | break; | |
175 | } |
|
154 | } | |
176 | case QChartSeries::SeriesTypeScatter: { |
|
155 | case QChartSeries::SeriesTypeScatter: { | |
177 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
156 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
178 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); |
|
157 | scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); | |
179 | scatterSeries->d->setParentItem(this); |
|
158 | scatterSeries->d->setParentItem(this); | |
|
159 | scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |||
180 | m_chartItems << scatterSeries->d; |
|
160 | m_chartItems << scatterSeries->d; | |
181 | m_chartTheme->addObserver(scatterSeries->d); |
|
161 | m_chartTheme->addObserver(scatterSeries->d); | |
|
162 | ||||
|
163 | foreach (qreal x, scatterSeries->d->m_x) { | |||
|
164 | domain.m_minX = qMin(domain.m_minX, x); | |||
|
165 | domain.m_maxX = qMax(domain.m_maxX, x); | |||
|
166 | } | |||
|
167 | foreach (qreal y, scatterSeries->d->m_y) { | |||
|
168 | domain.m_minY = qMin(domain.m_minY, y); | |||
|
169 | domain.m_maxY = qMax(domain.m_maxY, y); | |||
|
170 | } | |||
|
171 | ||||
182 | break; |
|
172 | break; | |
183 | } |
|
173 | } | |
184 | case QChartSeries::SeriesTypePie: { |
|
174 | case QChartSeries::SeriesTypePie: { | |
185 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
175 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
186 | pieSeries->d->setParentItem(this); |
|
176 | pieSeries->d->setParentItem(this); | |
187 | m_chartItems << pieSeries->d; |
|
177 | m_chartItems << pieSeries->d; | |
188 | pieSeries->d->m_chartTheme = m_chartTheme; |
|
178 | pieSeries->d->m_chartTheme = m_chartTheme; | |
189 | m_chartTheme->addObserver(pieSeries->d); |
|
179 | m_chartTheme->addObserver(pieSeries->d); | |
190 | break; |
|
180 | break; | |
191 | } |
|
181 | } | |
192 | } |
|
182 | } | |
193 |
|
183 | |||
194 | // Update all the items to match the new visible area of the chart |
|
184 | // Update all the items to match the new visible area of the chart | |
195 | foreach(ChartItem* i, m_chartItems) |
|
185 | foreach(ChartItem* i, m_chartItems) | |
196 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); |
|
186 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); | |
197 | } |
|
187 | } | |
198 |
|
188 | |||
199 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
189 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
200 | { |
|
190 | { | |
201 | // TODO: support also other types; not only scatter and pie |
|
191 | // TODO: support also other types; not only scatter and pie | |
202 |
|
192 | |||
203 | QChartSeries *series(0); |
|
193 | QChartSeries *series(0); | |
204 |
|
194 | |||
205 | switch (type) { |
|
195 | switch (type) { | |
206 | case QChartSeries::SeriesTypeLine: { |
|
196 | case QChartSeries::SeriesTypeLine: { | |
207 | series = QXYChartSeries::create(); |
|
197 | series = QXYChartSeries::create(); | |
208 | break; |
|
198 | break; | |
209 | } |
|
199 | } | |
210 | case QChartSeries::SeriesTypeBar: { |
|
200 | case QChartSeries::SeriesTypeBar: { | |
211 | series = new BarChartSeries(this); |
|
201 | series = new BarChartSeries(this); | |
212 | break; |
|
202 | break; | |
213 | } |
|
203 | } | |
214 | case QChartSeries::SeriesTypeStackedBar: { |
|
204 | case QChartSeries::SeriesTypeStackedBar: { | |
215 | series = new StackedBarChartSeries(this); |
|
205 | series = new StackedBarChartSeries(this); | |
216 | break; |
|
206 | break; | |
217 | } |
|
207 | } | |
218 | case QChartSeries::SeriesTypePercentBar: { |
|
208 | case QChartSeries::SeriesTypePercentBar: { | |
219 | series = new PercentBarChartSeries(this); |
|
209 | series = new PercentBarChartSeries(this); | |
220 | break; |
|
210 | break; | |
221 | } |
|
211 | } | |
222 | case QChartSeries::SeriesTypeScatter: { |
|
212 | case QChartSeries::SeriesTypeScatter: { | |
223 | series = new QScatterSeries(this); |
|
213 | series = new QScatterSeries(this); | |
224 | break; |
|
214 | break; | |
225 | } |
|
215 | } | |
226 | case QChartSeries::SeriesTypePie: { |
|
216 | case QChartSeries::SeriesTypePie: { | |
227 | series = new QPieSeries(this); |
|
217 | series = new QPieSeries(this); | |
228 | break; |
|
218 | break; | |
229 | } |
|
219 | } | |
230 | default: |
|
220 | default: | |
231 | Q_ASSERT(false); |
|
221 | Q_ASSERT(false); | |
232 | break; |
|
222 | break; | |
233 | } |
|
223 | } | |
234 |
|
224 | |||
235 | addSeries(series); |
|
225 | addSeries(series); | |
236 | return series; |
|
226 | return series; | |
237 | } |
|
227 | } | |
238 |
|
228 | |||
239 | void QChart::setSize(const QSize& size) |
|
229 | void QChart::setSize(const QSize& size) | |
240 | { |
|
230 | { | |
241 | m_rect = QRect(QPoint(0,0),size); |
|
231 | m_rect = QRect(QPoint(0,0),size); | |
242 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
232 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
243 |
|
233 | |||
244 | // recalculate title position |
|
234 | // recalculate title position | |
245 | if (m_titleItem) { |
|
235 | if (m_titleItem) { | |
246 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
236 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
247 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
237 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
248 | } |
|
238 | } | |
249 |
|
239 | |||
250 | //recalculate background gradient |
|
240 | //recalculate background gradient | |
251 | if (m_backgroundItem) { |
|
241 | if (m_backgroundItem) { | |
252 | m_backgroundItem->setRect(rect); |
|
242 | m_backgroundItem->setRect(rect); | |
253 | if (m_bacgroundOrinetation == HorizonatlGradientOrientation) |
|
243 | if (m_bacgroundOrinetation == HorizonatlGradientOrientation) | |
254 | m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(), 0); |
|
244 | m_backgroundGradient.setFinalStop(m_backgroundItem->rect().width(), 0); | |
255 | else |
|
245 | else | |
256 | m_backgroundGradient.setFinalStop(0, m_backgroundItem->rect().height()); |
|
246 | m_backgroundGradient.setFinalStop(0, m_backgroundItem->rect().height()); | |
257 | m_backgroundItem->setBrush(m_backgroundGradient); |
|
247 | m_backgroundItem->setBrush(m_backgroundGradient); | |
258 | } |
|
248 | } | |
259 |
|
249 | |||
260 | // resize and reposition childs |
|
250 | // resize and reposition childs | |
261 | foreach (ChartItem *item, m_chartItems) { |
|
251 | foreach (ChartItem *item, m_chartItems) { | |
262 | item->setPos(rect.topLeft()); |
|
252 | item->setPos(rect.topLeft()); | |
263 | item->setSize(rect.size()); |
|
253 | item->setSize(rect.size()); | |
264 | } |
|
254 | } | |
265 |
|
255 | |||
266 | update(); |
|
256 | update(); | |
267 | } |
|
257 | } | |
268 |
|
258 | |||
269 | void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation) |
|
259 | void QChart::setBackground(const QColor& startColor, const QColor& endColor, GradientOrientation orientation) | |
270 | { |
|
260 | { | |
271 |
|
261 | |||
272 | if(!m_backgroundItem){ |
|
262 | if(!m_backgroundItem){ | |
273 | m_backgroundItem = new QGraphicsRectItem(this); |
|
263 | m_backgroundItem = new QGraphicsRectItem(this); | |
274 | m_backgroundItem->setZValue(-1); |
|
264 | m_backgroundItem->setZValue(-1); | |
275 | } |
|
265 | } | |
276 |
|
266 | |||
277 | m_bacgroundOrinetation = orientation; |
|
267 | m_bacgroundOrinetation = orientation; | |
278 | m_backgroundGradient.setColorAt(0.0, startColor); |
|
268 | m_backgroundGradient.setColorAt(0.0, startColor); | |
279 | m_backgroundGradient.setColorAt(1.0, endColor); |
|
269 | m_backgroundGradient.setColorAt(1.0, endColor); | |
280 | m_backgroundGradient.setStart(0,0); |
|
270 | m_backgroundGradient.setStart(0,0); | |
281 |
|
271 | |||
282 | if(orientation == VerticalGradientOrientation){ |
|
272 | if(orientation == VerticalGradientOrientation){ | |
283 | m_backgroundGradient.setFinalStop(0,m_rect.height()); |
|
273 | m_backgroundGradient.setFinalStop(0,m_rect.height()); | |
284 | }else{ |
|
274 | }else{ | |
285 | m_backgroundGradient.setFinalStop(m_rect.width(),0); |
|
275 | m_backgroundGradient.setFinalStop(m_rect.width(),0); | |
286 | } |
|
276 | } | |
287 |
|
277 | |||
288 | m_backgroundItem->setBrush(m_backgroundGradient); |
|
278 | m_backgroundItem->setBrush(m_backgroundGradient); | |
289 | m_backgroundItem->setPen(Qt::NoPen); |
|
279 | m_backgroundItem->setPen(Qt::NoPen); | |
290 | m_backgroundItem->update(); |
|
280 | m_backgroundItem->update(); | |
291 | } |
|
281 | } | |
292 |
|
282 | |||
293 | void QChart::setTitle(const QString& title,const QFont& font) |
|
283 | void QChart::setTitle(const QString& title,const QFont& font) | |
294 | { |
|
284 | { | |
295 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
285 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); | |
296 | m_titleItem->setPlainText(title); |
|
286 | m_titleItem->setPlainText(title); | |
297 | m_titleItem->setFont(font); |
|
287 | m_titleItem->setFont(font); | |
298 | } |
|
288 | } | |
299 |
|
289 | |||
300 | int QChart::margin() const |
|
290 | int QChart::margin() const | |
301 | { |
|
291 | { | |
302 | return m_marginSize; |
|
292 | return m_marginSize; | |
303 | } |
|
293 | } | |
304 |
|
294 | |||
305 | void QChart::setMargin(int margin) |
|
295 | void QChart::setMargin(int margin) | |
306 | { |
|
296 | { | |
307 | m_marginSize = margin; |
|
297 | m_marginSize = margin; | |
308 | } |
|
298 | } | |
309 |
|
299 | |||
310 | void QChart::setTheme(QChart::ChartThemeId theme) |
|
300 | void QChart::setTheme(QChart::ChartThemeId theme) | |
311 | { |
|
301 | { | |
312 | m_chartTheme->setTheme(theme); |
|
302 | m_chartTheme->setTheme(theme); | |
313 | setBackground(m_chartTheme->d->m_gradientStartColor, |
|
303 | setBackground(m_chartTheme->d->m_gradientStartColor, | |
314 | m_chartTheme->d->m_gradientEndColor, |
|
304 | m_chartTheme->d->m_gradientEndColor, | |
315 | m_bacgroundOrinetation); |
|
305 | m_bacgroundOrinetation); | |
316 |
|
306 | |||
317 | // TODO: Move the controlling of the series presentations into private implementation of the |
|
307 | // TODO: Move the controlling of the series presentations into private implementation of the | |
318 | // series instead of QChart controlling themes for each |
|
308 | // series instead of QChart controlling themes for each | |
319 | // In other words, the following should be used when creating xy series: |
|
309 | // In other words, the following should be used when creating xy series: | |
320 | // m_chartTheme->addObserver(xyseries) |
|
310 | // m_chartTheme->addObserver(xyseries) | |
321 | foreach (QChartSeries *series, m_chartSeries) { |
|
311 | foreach (QChartSeries *series, m_chartSeries) { | |
322 | if (series->type() == QChartSeries::SeriesTypeLine) { |
|
312 | if (series->type() == QChartSeries::SeriesTypeLine) { | |
323 | QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series); |
|
313 | QXYChartSeries *xyseries = static_cast<QXYChartSeries *>(series); | |
324 | SeriesTheme seriesTheme = m_chartTheme->themeForSeries(); |
|
314 | SeriesTheme seriesTheme = m_chartTheme->themeForSeries(); | |
325 | xyseries->setPen(seriesTheme.linePen); |
|
315 | xyseries->setPen(seriesTheme.linePen); | |
326 | } |
|
316 | } | |
327 | } |
|
317 | } | |
328 |
|
318 | |||
329 | update(); |
|
319 | update(); | |
330 | } |
|
320 | } | |
331 |
|
321 | |||
332 | void QChart::zoomInToRect(const QRect& rectangle) |
|
322 | void QChart::zoomInToRect(const QRect& rectangle) | |
333 | { |
|
323 | { | |
334 |
|
324 | |||
335 | if(!rectangle.isValid()) return; |
|
325 | if(!rectangle.isValid()) return; | |
336 |
|
326 | |||
337 | qreal margin = this->margin(); |
|
327 | qreal margin = this->margin(); | |
338 |
|
328 | |||
339 | QRect rect = rectangle.normalized(); |
|
329 | QRect rect = rectangle.normalized(); | |
340 | rect.translate(-margin, -margin); |
|
330 | rect.translate(-margin, -margin); | |
341 |
|
331 | |||
342 | PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex]; |
|
332 | PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex]; | |
343 |
|
333 | |||
344 | PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin); |
|
334 | PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin); | |
345 |
|
335 | |||
346 | m_plotDomainList.resize(m_plotDataIndex + 1); |
|
336 | m_plotDomainList.resize(m_plotDataIndex + 1); | |
347 | m_plotDomainList<<domain; |
|
337 | m_plotDomainList<<domain; | |
348 | m_plotDataIndex++; |
|
338 | m_plotDataIndex++; | |
349 |
|
339 | |||
350 | foreach (ChartItem* item, m_chartItems) |
|
340 | foreach (ChartItem* item, m_chartItems) | |
351 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
341 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
352 | update(); |
|
342 | update(); | |
353 | } |
|
343 | } | |
354 |
|
344 | |||
355 | void QChart::zoomIn() |
|
345 | void QChart::zoomIn() | |
356 | { |
|
346 | { | |
357 | if (m_plotDataIndex < m_plotDomainList.count() - 1) { |
|
347 | if (m_plotDataIndex < m_plotDomainList.count() - 1) { | |
358 | m_plotDataIndex++; |
|
348 | m_plotDataIndex++; | |
359 | foreach (ChartItem* item, m_chartItems) |
|
349 | foreach (ChartItem* item, m_chartItems) | |
360 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
350 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
361 | update(); |
|
351 | update(); | |
362 | } else { |
|
352 | } else { | |
363 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
353 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
364 | rect.setWidth(rect.width()/2); |
|
354 | rect.setWidth(rect.width()/2); | |
365 | rect.setHeight(rect.height()/2); |
|
355 | rect.setHeight(rect.height()/2); | |
366 | rect.moveCenter(m_rect.center()); |
|
356 | rect.moveCenter(m_rect.center()); | |
367 | zoomInToRect(rect); |
|
357 | zoomInToRect(rect); | |
368 | } |
|
358 | } | |
369 | } |
|
359 | } | |
370 |
|
360 | |||
371 | void QChart::zoomOut() |
|
361 | void QChart::zoomOut() | |
372 | { |
|
362 | { | |
373 | if (m_plotDataIndex > 0) { |
|
363 | if (m_plotDataIndex > 0) { | |
374 | m_plotDataIndex--; |
|
364 | m_plotDataIndex--; | |
375 | foreach (ChartItem* item, m_chartItems) |
|
365 | foreach (ChartItem* item, m_chartItems) | |
376 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
366 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
377 | update(); |
|
367 | update(); | |
378 | } |
|
368 | } | |
379 | } |
|
369 | } | |
380 |
|
370 | |||
381 | void QChart::zoomReset() |
|
371 | void QChart::zoomReset() | |
382 | { |
|
372 | { | |
383 | if (m_plotDataIndex > 0) { |
|
373 | if (m_plotDataIndex > 0) { | |
384 | m_plotDataIndex = 0; |
|
374 | m_plotDataIndex = 0; | |
385 | foreach (ChartItem* item, m_chartItems) |
|
375 | foreach (ChartItem* item, m_chartItems) | |
386 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
376 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
387 | update(); |
|
377 | update(); | |
388 | } |
|
378 | } | |
389 | } |
|
379 | } | |
390 |
|
380 | |||
391 | void QChart::setAxisX(const QChartAxis& axis) |
|
381 | void QChart::setAxisX(const QChartAxis& axis) | |
392 | { |
|
382 | { | |
393 | setAxis(m_axisXItem,axis); |
|
383 | setAxis(m_axisXItem,axis); | |
394 | } |
|
384 | } | |
395 | void QChart::setAxisY(const QChartAxis& axis) |
|
385 | void QChart::setAxisY(const QChartAxis& axis) | |
396 | { |
|
386 | { | |
397 | setAxis(m_axisYItem.at(0),axis); |
|
387 | setAxis(m_axisYItem.at(0),axis); | |
398 | } |
|
388 | } | |
399 |
|
389 | |||
400 | void QChart::setAxisY(const QList<QChartAxis>& axis) |
|
390 | void QChart::setAxisY(const QList<QChartAxis>& axis) | |
401 | { |
|
391 | { | |
402 | //TODO not implemented |
|
392 | //TODO not implemented | |
403 | } |
|
393 | } | |
404 |
|
394 | |||
405 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) |
|
395 | void QChart::setAxis(AxisItem *item, const QChartAxis& axis) | |
406 | { |
|
396 | { | |
407 | item->setVisible(axis.isAxisVisible()); |
|
397 | item->setVisible(axis.isAxisVisible()); | |
408 | } |
|
398 | } | |
409 |
|
399 | |||
410 | #include "moc_qchart.cpp" |
|
400 | #include "moc_qchart.cpp" | |
411 |
|
401 | |||
412 | QTCOMMERCIALCHART_END_NAMESPACE |
|
402 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,100 +1,102 | |||||
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 | m_rubberBand(QRubberBand::Rectangle, this), |
|
11 | m_rubberBand(QRubberBand::Rectangle, this), | |
12 | m_originX(0) |
|
12 | m_originX(0) | |
13 | { |
|
13 | { | |
14 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
14 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
15 | m_scene = new QGraphicsScene(); |
|
15 | m_scene = new QGraphicsScene(); | |
16 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
16 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
17 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
17 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
18 | setScene(m_scene); |
|
18 | setScene(m_scene); | |
19 |
|
19 | |||
20 | m_chart = new QChart(); |
|
20 | m_chart = new QChart(); | |
|
21 | // TODO: currently setting the margins explicitly is required, if you wish to have axis labels visible | |||
|
22 | m_chart->setMargin(25); | |||
21 | m_scene->addItem(m_chart); |
|
23 | m_scene->addItem(m_chart); | |
22 | m_rubberBand.setEnabled(true); // TODO: should zoom be enabled by default? |
|
24 | m_rubberBand.setEnabled(true); // TODO: should zoom be enabled by default? | |
23 | show(); |
|
25 | show(); | |
24 | } |
|
26 | } | |
25 |
|
27 | |||
26 | QChartWidget::~QChartWidget() |
|
28 | QChartWidget::~QChartWidget() | |
27 | { |
|
29 | { | |
28 | } |
|
30 | } | |
29 |
|
31 | |||
30 | void QChartWidget::resizeEvent(QResizeEvent *event) |
|
32 | void QChartWidget::resizeEvent(QResizeEvent *event) | |
31 | { |
|
33 | { | |
32 | m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
34 | m_scene->setSceneRect(0,0,size().width(),size().height()); | |
33 | m_chart->setSize(size()); |
|
35 | m_chart->setSize(size()); | |
34 | QWidget::resizeEvent(event); |
|
36 | QWidget::resizeEvent(event); | |
35 | } |
|
37 | } | |
36 |
|
38 | |||
37 | QSize QChartWidget::sizeHint() const |
|
39 | QSize QChartWidget::sizeHint() const | |
38 | { |
|
40 | { | |
39 | // TODO: calculate size hint based on contents? |
|
41 | // TODO: calculate size hint based on contents? | |
40 | return QSize(100, 100); |
|
42 | return QSize(100, 100); | |
41 | } |
|
43 | } | |
42 |
|
44 | |||
43 | void QChartWidget::mousePressEvent(QMouseEvent *event) |
|
45 | void QChartWidget::mousePressEvent(QMouseEvent *event) | |
44 | { |
|
46 | { | |
45 | if(m_rubberBand.isEnabled() && event->button() == Qt::LeftButton) { |
|
47 | if(m_rubberBand.isEnabled() && event->button() == Qt::LeftButton) { | |
46 | int margin = m_chart->margin(); |
|
48 | int margin = m_chart->margin(); | |
47 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
49 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); | |
48 |
|
50 | |||
49 | if (rect.contains(event->pos())) { |
|
51 | if (rect.contains(event->pos())) { | |
50 | m_originX = event->pos().x(); |
|
52 | m_originX = event->pos().x(); | |
51 | m_rubberBand.setGeometry(QRect(m_originX, 0, 0, height())); |
|
53 | m_rubberBand.setGeometry(QRect(m_originX, 0, 0, height())); | |
52 | m_rubberBand.show(); |
|
54 | m_rubberBand.show(); | |
53 | event->accept(); |
|
55 | event->accept(); | |
54 | } |
|
56 | } | |
55 | } |
|
57 | } | |
56 | } |
|
58 | } | |
57 |
|
59 | |||
58 | void QChartWidget::mouseMoveEvent(QMouseEvent *event) |
|
60 | void QChartWidget::mouseMoveEvent(QMouseEvent *event) | |
59 | { |
|
61 | { | |
60 | if(m_rubberBand.isVisible()) |
|
62 | if(m_rubberBand.isVisible()) | |
61 | m_rubberBand.setGeometry(QRect(m_originX, 0, |
|
63 | m_rubberBand.setGeometry(QRect(m_originX, 0, | |
62 | event->pos().x() - m_originX, height()).normalized()); |
|
64 | event->pos().x() - m_originX, height()).normalized()); | |
63 | } |
|
65 | } | |
64 |
|
66 | |||
65 | void QChartWidget::mouseReleaseEvent(QMouseEvent *event) |
|
67 | void QChartWidget::mouseReleaseEvent(QMouseEvent *event) | |
66 | { |
|
68 | { | |
67 | if (event->button() == Qt::LeftButton && m_rubberBand.isVisible()) { |
|
69 | if (event->button() == Qt::LeftButton && m_rubberBand.isVisible()) { | |
68 | m_rubberBand.hide(); |
|
70 | m_rubberBand.hide(); | |
69 | QRect rect = m_rubberBand.geometry(); |
|
71 | QRect rect = m_rubberBand.geometry(); | |
70 | m_chart->zoomInToRect(rect); |
|
72 | m_chart->zoomInToRect(rect); | |
71 | event->accept(); |
|
73 | event->accept(); | |
72 | } |
|
74 | } | |
73 |
|
75 | |||
74 | if(event->button()==Qt::RightButton) |
|
76 | if(event->button()==Qt::RightButton) | |
75 | m_chart->zoomReset(); |
|
77 | m_chart->zoomReset(); | |
76 | } |
|
78 | } | |
77 |
|
79 | |||
78 | void QChartWidget::addSeries(QChartSeries* series) |
|
80 | void QChartWidget::addSeries(QChartSeries* series) | |
79 | { |
|
81 | { | |
80 | m_chart->addSeries(series); |
|
82 | m_chart->addSeries(series); | |
81 | } |
|
83 | } | |
82 |
|
84 | |||
83 | QChartSeries* QChartWidget::createSeries(QChartSeries::QChartSeriesType type) |
|
85 | QChartSeries* QChartWidget::createSeries(QChartSeries::QChartSeriesType type) | |
84 | { |
|
86 | { | |
85 | return m_chart->createSeries(type); |
|
87 | return m_chart->createSeries(type); | |
86 | } |
|
88 | } | |
87 |
|
89 | |||
88 | void QChartWidget::setTheme(QChart::ChartThemeId theme) |
|
90 | void QChartWidget::setTheme(QChart::ChartThemeId theme) | |
89 | { |
|
91 | { | |
90 | m_chart->setTheme(theme); |
|
92 | m_chart->setTheme(theme); | |
91 | } |
|
93 | } | |
92 |
|
94 | |||
93 | void QChartWidget::setZoomEnabled(bool enabled) |
|
95 | void QChartWidget::setZoomEnabled(bool enabled) | |
94 | { |
|
96 | { | |
95 | m_rubberBand.setEnabled(enabled); |
|
97 | m_rubberBand.setEnabled(enabled); | |
96 | } |
|
98 | } | |
97 |
|
99 | |||
98 | #include "moc_qchartwidget.cpp" |
|
100 | #include "moc_qchartwidget.cpp" | |
99 |
|
101 | |||
100 | QTCOMMERCIALCHART_END_NAMESPACE |
|
102 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,125 +1,140 | |||||
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(QGraphicsItem *parent) : |
|
12 | QScatterSeriesPrivate::QScatterSeriesPrivate(QGraphicsItem *parent) : | |
13 | ChartItem(parent), |
|
13 | ChartItem(parent), | |
14 | m_markerColor(QColor()), |
|
14 | m_markerColor(QColor()), | |
15 | m_visibleChartArea() |
|
15 | m_visibleChartArea(), | |
|
16 | m_boundingRect() | |||
16 | { |
|
17 | { | |
|
18 | if (parent) | |||
|
19 | m_boundingRect = parent->boundingRect(); | |||
17 | } |
|
20 | } | |
18 |
|
21 | |||
19 |
void QScatterSeriesPrivate:: |
|
22 | void QScatterSeriesPrivate::changeGeometry() | |
20 | { |
|
23 | { | |
21 | qreal scalex = rect.width() / m_visibleChartArea.spanX(); |
|
24 | if (m_boundingRect.isValid()) { | |
22 | qreal scaley = rect.height() / m_visibleChartArea.spanY(); |
|
25 | prepareGeometryChange(); | |
23 |
|
26 | qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); | ||
|
27 | qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); | |||
24 | m_scenex.clear(); |
|
28 | m_scenex.clear(); | |
25 | m_sceney.clear(); |
|
29 | m_sceney.clear(); | |
26 |
|
30 | |||
27 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing |
|
31 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing | |
28 | foreach(qreal x, m_x) |
|
32 | foreach(qreal x, m_x) | |
29 |
m_scenex.append( |
|
33 | m_scenex.append(m_boundingRect.left() + x * scalex - m_visibleChartArea.m_minX * scalex); | |
30 |
|
34 | |||
31 | foreach(qreal y, m_y) |
|
35 | foreach(qreal y, m_y) | |
32 |
m_sceney.append( |
|
36 | m_sceney.append(m_boundingRect.bottom() - y * scaley + m_visibleChartArea.m_minY * scaley); | |
|
37 | } | |||
33 | } |
|
38 | } | |
34 |
|
39 | |||
35 | void QScatterSeriesPrivate::setSize(const QSize &size) |
|
40 | void QScatterSeriesPrivate::setSize(const QSize &size) | |
36 | { |
|
41 | { | |
37 | QGraphicsItem *parent = this->parentItem(); |
|
42 | // m_boundingRect = QRectF(pos().x(), pos().y(), size.width(), size.height()); | |
38 | if (parent) |
|
43 | m_boundingRect = QRectF(0, 0, size.width(), size.height()); | |
39 | resize(QRectF(parent->pos(), size)); |
|
44 | changeGeometry(); | |
40 | } |
|
45 | } | |
41 |
|
46 | |||
42 | void QScatterSeriesPrivate::themeChanged(ChartTheme *theme) |
|
47 | void QScatterSeriesPrivate::themeChanged(ChartTheme *theme) | |
43 | { |
|
48 | { | |
44 | m_theme = theme->themeForSeries(); |
|
49 | m_theme = theme->themeForSeries(); | |
45 | } |
|
50 | } | |
46 |
|
51 | |||
47 | void QScatterSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain) |
|
52 | void QScatterSeriesPrivate::setPlotDomain(const PlotDomain& plotDomain) | |
48 | { |
|
53 | { | |
49 | m_visibleChartArea = plotDomain; |
|
54 | m_visibleChartArea = plotDomain; | |
50 | resize(parentItem()->boundingRect()); |
|
55 | changeGeometry(); | |
51 | } |
|
56 | } | |
52 |
|
57 | |||
53 | QRectF QScatterSeriesPrivate::boundingRect() const |
|
58 | QRectF QScatterSeriesPrivate::boundingRect() const | |
54 | { |
|
59 | { | |
55 | return QRectF(0, 0, 55, 100); |
|
60 | return m_boundingRect; | |
56 | } |
|
61 | } | |
57 |
|
62 | |||
58 | void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) |
|
63 | void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) | |
59 | { |
|
64 | { | |
60 | // TODO: The opacity should be user definable? |
|
65 | // TODO: The opacity should be user definable? | |
61 | //brush.setColor(QColor(255, 82, 0, 100)); |
|
66 | //brush.setColor(QColor(255, 82, 0, 100)); | |
62 | if (m_markerColor.isValid()) { |
|
67 | if (m_markerColor.isValid()) { | |
63 | QPen pen = painter->pen(); |
|
68 | QPen pen = painter->pen(); | |
64 | QBrush brush = pen.brush(); |
|
69 | QBrush brush = pen.brush(); | |
65 | brush.setColor(m_markerColor); |
|
70 | brush.setColor(m_markerColor); | |
66 | pen.setBrush(brush); |
|
71 | pen.setBrush(brush); | |
67 | pen.setWidth(4); |
|
72 | pen.setWidth(4); | |
68 | painter->setPen(pen); |
|
73 | painter->setPen(pen); | |
69 | } |
|
74 | } | |
70 | else |
|
75 | else | |
71 | painter->setPen(m_theme.markerPen); |
|
76 | painter->setPen(m_theme.markerPen); | |
72 | // brush.setColor(m_theme..lineColor); |
|
77 | // brush.setColor(m_theme..lineColor); | |
73 |
|
78 | |||
74 | // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize |
|
79 | // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize | |
75 | // event right after construction or maybe given a size during initialization |
|
80 | // event right after construction or maybe given a size during initialization | |
76 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { |
|
81 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { | |
77 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) |
|
82 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) | |
78 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); |
|
83 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); | |
79 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); |
|
84 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); | |
80 | } |
|
85 | } | |
81 | } |
|
86 | } | |
82 |
|
87 | |||
83 | QScatterSeries::QScatterSeries(QObject *parent) : |
|
88 | QScatterSeries::QScatterSeries(QObject *parent) : | |
84 | QChartSeries(parent), |
|
89 | QChartSeries(parent), | |
85 | d(new QScatterSeriesPrivate(qobject_cast<QGraphicsItem *> (parent))) |
|
90 | d(new QScatterSeriesPrivate(qobject_cast<QGraphicsItem *> (parent))) | |
86 | { |
|
91 | { | |
87 | } |
|
92 | } | |
88 |
|
93 | |||
89 | bool QScatterSeries::setData(QList<qreal> x, QList<qreal> y) |
|
94 | bool QScatterSeries::setData(QList<qreal> xlist, QList<qreal> ylist) | |
90 | { |
|
95 | { | |
91 | // TODO: validate data |
|
96 | // TODO: validate data | |
92 | d->m_x = x; |
|
97 | d->m_x = xlist; | |
93 | d->m_y = y; |
|
98 | d->m_y = ylist; | |
94 | QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent()); |
|
99 | ||
95 | Q_ASSERT(parentItem); |
|
100 | // TODO: the following updates the visible chart area setting of the series, we would instead | |
96 | // d->setPos(parentItem->pos()); |
|
101 | // need to update the _chart's_ visible area... this would require a callback or | |
97 | // d->setSize(parentItem->boundingRect().size().toSize()); |
|
102 | // similar to the parenting QChart object... | |
98 | d->resize(parentItem->boundingRect()); |
|
103 | foreach (qreal x, d->m_x) { | |
|
104 | d->m_visibleChartArea.m_minX = qMin(d->m_visibleChartArea.m_minX, x); | |||
|
105 | d->m_visibleChartArea.m_maxX = qMax(d->m_visibleChartArea.m_maxX, x); | |||
|
106 | } | |||
|
107 | foreach (qreal y, d->m_y) { | |||
|
108 | d->m_visibleChartArea.m_minY = qMin(d->m_visibleChartArea.m_minY, y); | |||
|
109 | d->m_visibleChartArea.m_maxY = qMax(d->m_visibleChartArea.m_maxY, y); | |||
|
110 | } | |||
|
111 | ||||
|
112 | d->changeGeometry(); | |||
|
113 | ||||
99 | return true; |
|
114 | return true; | |
100 | } |
|
115 | } | |
101 |
|
116 | |||
102 | void QScatterSeries::setMarkerColor(QColor color) |
|
117 | void QScatterSeries::setMarkerColor(QColor color) | |
103 | { |
|
118 | { | |
104 | d->m_markerColor = color; |
|
119 | d->m_markerColor = color; | |
105 | } |
|
120 | } | |
106 |
|
121 | |||
107 | QColor QScatterSeries::markerColor() |
|
122 | QColor QScatterSeries::markerColor() | |
108 | { |
|
123 | { | |
109 | return d->m_markerColor; |
|
124 | return d->m_markerColor; | |
110 | } |
|
125 | } | |
111 |
|
126 | |||
112 | // TODO: |
|
127 | // TODO: | |
113 | //void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale) |
|
128 | //void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale) | |
114 | //{ |
|
129 | //{ | |
115 | // d->rescale(xscale, yscale); |
|
130 | // d->rescale(xscale, yscale); | |
116 | //} |
|
131 | //} | |
117 |
|
132 | |||
118 | QScatterSeries::~QScatterSeries() |
|
133 | QScatterSeries::~QScatterSeries() | |
119 | { |
|
134 | { | |
120 | delete d; |
|
135 | delete d; | |
121 | } |
|
136 | } | |
122 |
|
137 | |||
123 | #include "moc_qscatterseries.cpp" |
|
138 | #include "moc_qscatterseries.cpp" | |
124 |
|
139 | |||
125 | QTCOMMERCIALCHART_END_NAMESPACE |
|
140 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,48 +1,47 | |||||
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 "charttheme_p.h" |
|
5 | #include "charttheme_p.h" | |
6 | #include "chartitem_p.h" |
|
6 | #include "chartitem_p.h" | |
7 | #include "plotdomain_p.h" |
|
7 | #include "plotdomain_p.h" | |
8 | #include <QGraphicsItem> |
|
8 | #include <QGraphicsItem> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | /*! |
|
12 | /*! | |
13 | * The PIMPL class of QScatterSeries. |
|
13 | * The PIMPL class of QScatterSeries. | |
14 | */ |
|
14 | */ | |
15 | class QScatterSeriesPrivate : public ChartItem, public ChartThemeObserver |
|
15 | class QScatterSeriesPrivate : public ChartItem, public ChartThemeObserver | |
16 | { |
|
16 | { | |
17 | public: |
|
17 | public: | |
18 | QScatterSeriesPrivate(QGraphicsItem *parent); |
|
18 | QScatterSeriesPrivate(QGraphicsItem *parent); | |
19 |
|
19 | |||
20 | public: // from ChartObjectInterface |
|
20 | public: // from ChartObjectInterface | |
21 | void setSize(const QSize &size); |
|
21 | void setSize(const QSize &size); | |
22 | void setPlotDomain(const PlotDomain& data); |
|
22 | void setPlotDomain(const PlotDomain& data); | |
23 |
|
23 | |||
24 | public: // from ChartThemeObserver |
|
24 | public: // from ChartThemeObserver | |
25 | void themeChanged(ChartTheme *theme); |
|
25 | void themeChanged(ChartTheme *theme); | |
26 |
|
26 | |||
27 | public: // from QGraphicsItem |
|
27 | public: // from QGraphicsItem | |
28 | QRectF boundingRect() const; |
|
28 | QRectF boundingRect() const; | |
29 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
29 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
30 |
|
30 | |||
31 | public: |
|
31 | public: | |
32 | void resize(QRectF rect); // TODO: replace with setSize |
|
32 | void changeGeometry(); | |
33 |
|
33 | |||
|
34 | QRectF m_boundingRect; | |||
34 | // TODO: use the chart data class instead of list of x and y values? |
|
35 | // TODO: use the chart data class instead of list of x and y values? | |
35 | QList<qreal> m_x; |
|
36 | QList<qreal> m_x; | |
36 | QList<qreal> m_y; |
|
37 | QList<qreal> m_y; | |
37 | qreal m_scalex; |
|
|||
38 | qreal m_scaley; |
|
|||
39 | QList<qreal> m_scenex; |
|
38 | QList<qreal> m_scenex; | |
40 | QList<qreal> m_sceney; |
|
39 | QList<qreal> m_sceney; | |
41 | QColor m_markerColor; |
|
40 | QColor m_markerColor; | |
42 | SeriesTheme m_theme; |
|
41 | SeriesTheme m_theme; | |
43 | PlotDomain m_visibleChartArea; |
|
42 | PlotDomain m_visibleChartArea; | |
44 | }; |
|
43 | }; | |
45 |
|
44 | |||
46 | QTCOMMERCIALCHART_END_NAMESPACE |
|
45 | QTCOMMERCIALCHART_END_NAMESPACE | |
47 |
|
46 | |||
48 | #endif // QSCATTERSERIESPRIVATE_H |
|
47 | #endif // QSCATTERSERIESPRIVATE_H |
@@ -1,377 +1,379 | |||||
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 <barchartseries.h> |
|
6 | #include <barchartseries.h> | |
7 | #include <QPushButton> |
|
7 | #include <QPushButton> | |
8 | #include <QComboBox> |
|
8 | #include <QComboBox> | |
9 | #include <QSpinBox> |
|
9 | #include <QSpinBox> | |
10 | #include <QCheckBox> |
|
10 | #include <QCheckBox> | |
11 | #include <QGridLayout> |
|
11 | #include <QGridLayout> | |
12 | #include <QHBoxLayout> |
|
12 | #include <QHBoxLayout> | |
13 | #include <QLabel> |
|
13 | #include <QLabel> | |
14 | #include <QSpacerItem> |
|
14 | #include <QSpacerItem> | |
15 | #include <QMessageBox> |
|
15 | #include <QMessageBox> | |
16 | #include <cmath> |
|
16 | #include <cmath> | |
17 | #include <QDebug> |
|
17 | #include <QDebug> | |
18 | #include <QStandardItemModel> |
|
18 | #include <QStandardItemModel> | |
19 |
|
19 | |||
20 |
|
20 | |||
21 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
21 | QTCOMMERCIALCHART_USE_NAMESPACE | |
22 |
|
22 | |||
23 | MainWidget::MainWidget(QWidget *parent) : |
|
23 | MainWidget::MainWidget(QWidget *parent) : | |
24 | QWidget(parent) |
|
24 | QWidget(parent) | |
25 | { |
|
25 | { | |
26 | m_chartWidget = new QChartWidget(this); |
|
26 | m_chartWidget = new QChartWidget(this); | |
27 |
|
27 | |||
28 |
// Grid |
|
28 | // Grid layout for the controls for configuring the chart widget | |
29 | QGridLayout *grid = new QGridLayout(); |
|
29 | QGridLayout *grid = new QGridLayout(); | |
30 | QGridLayout *mainLayout = new QGridLayout(); |
|
|||
31 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
30 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
32 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
31 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
33 | grid->addWidget(addSeriesButton, 0, 1); |
|
32 | grid->addWidget(addSeriesButton, 0, 1); | |
34 | initBackroundCombo(grid); |
|
33 | initBackroundCombo(grid); | |
35 | initScaleControls(grid); |
|
34 | initScaleControls(grid); | |
36 | initThemeCombo(grid); |
|
35 | initThemeCombo(grid); | |
37 |
QCheckBox *zoomCheckBox = new QCheckBox("Zoom |
|
36 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
38 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); |
|
37 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); | |
39 | zoomCheckBox->setChecked(true); |
|
38 | zoomCheckBox->setChecked(true); | |
40 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
39 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
41 | // add row with empty label to make all the other rows static |
|
40 | // add row with empty label to make all the other rows static | |
42 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
41 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
43 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
42 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
|
43 | ||||
|
44 | // Another grid layout as a main layout | |||
|
45 | QGridLayout *mainLayout = new QGridLayout(); | |||
44 | mainLayout->addLayout(grid, 0, 0); |
|
46 | mainLayout->addLayout(grid, 0, 0); | |
45 |
|
47 | |||
46 | // Init series type specific controls |
|
48 | // Init series type specific controls | |
47 | initPieControls(); |
|
49 | initPieControls(); | |
48 | mainLayout->addLayout(m_pieLayout, 2, 0); |
|
50 | mainLayout->addLayout(m_pieLayout, 2, 0); | |
49 | // Scatter series specific settings |
|
51 | // Scatter series specific settings | |
50 | // m_scatterLayout = new QGridLayout(); |
|
52 | // m_scatterLayout = new QGridLayout(); | |
51 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); |
|
53 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); | |
52 | // m_scatterLayout->setEnabled(false); |
|
54 | // m_scatterLayout->setEnabled(false); | |
53 | // mainLayout->addLayout(m_scatterLayout, 1, 0); |
|
55 | // mainLayout->addLayout(m_scatterLayout, 1, 0); | |
54 |
|
56 | |||
55 | // Add layouts and the chart widget to the main layout |
|
57 | // Add layouts and the chart widget to the main layout | |
56 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); |
|
58 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); | |
57 | setLayout(mainLayout); |
|
59 | setLayout(mainLayout); | |
58 |
|
60 | |||
59 | // force an update to test data |
|
61 | // force an update to test data | |
60 | testDataChanged(0); |
|
62 | testDataChanged(0); | |
61 | } |
|
63 | } | |
62 |
|
64 | |||
63 | // Combo box for selecting the chart's background |
|
65 | // Combo box for selecting the chart's background | |
64 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
66 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
65 | { |
|
67 | { | |
66 | QComboBox *backgroundCombo = new QComboBox(this); |
|
68 | QComboBox *backgroundCombo = new QComboBox(this); | |
67 | backgroundCombo->addItem("Color"); |
|
69 | backgroundCombo->addItem("Color"); | |
68 | backgroundCombo->addItem("Gradient"); |
|
70 | backgroundCombo->addItem("Gradient"); | |
69 | backgroundCombo->addItem("Image"); |
|
71 | backgroundCombo->addItem("Image"); | |
70 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
72 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
71 | this, SLOT(backgroundChanged(int))); |
|
73 | this, SLOT(backgroundChanged(int))); | |
72 |
|
74 | |||
73 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
75 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
74 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
76 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
75 | } |
|
77 | } | |
76 |
|
78 | |||
77 | // Scale related controls (auto-scale vs. manual min-max values) |
|
79 | // Scale related controls (auto-scale vs. manual min-max values) | |
78 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
80 | void MainWidget::initScaleControls(QGridLayout *grid) | |
79 | { |
|
81 | { | |
80 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
82 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
81 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
83 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
82 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
84 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
83 | m_xMinSpin = new QSpinBox(); |
|
85 | m_xMinSpin = new QSpinBox(); | |
84 | m_xMinSpin->setMinimum(INT_MIN); |
|
86 | m_xMinSpin->setMinimum(INT_MIN); | |
85 | m_xMinSpin->setMaximum(INT_MAX); |
|
87 | m_xMinSpin->setMaximum(INT_MAX); | |
86 | m_xMinSpin->setValue(0); |
|
88 | m_xMinSpin->setValue(0); | |
87 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
89 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
88 | m_xMaxSpin = new QSpinBox(); |
|
90 | m_xMaxSpin = new QSpinBox(); | |
89 | m_xMaxSpin->setMinimum(INT_MIN); |
|
91 | m_xMaxSpin->setMinimum(INT_MIN); | |
90 | m_xMaxSpin->setMaximum(INT_MAX); |
|
92 | m_xMaxSpin->setMaximum(INT_MAX); | |
91 | m_xMaxSpin->setValue(10); |
|
93 | m_xMaxSpin->setValue(10); | |
92 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
94 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
93 | m_yMinSpin = new QSpinBox(); |
|
95 | m_yMinSpin = new QSpinBox(); | |
94 | m_yMinSpin->setMinimum(INT_MIN); |
|
96 | m_yMinSpin->setMinimum(INT_MIN); | |
95 | m_yMinSpin->setMaximum(INT_MAX); |
|
97 | m_yMinSpin->setMaximum(INT_MAX); | |
96 | m_yMinSpin->setValue(0); |
|
98 | m_yMinSpin->setValue(0); | |
97 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
99 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
98 | m_yMaxSpin = new QSpinBox(); |
|
100 | m_yMaxSpin = new QSpinBox(); | |
99 | m_yMaxSpin->setMinimum(INT_MIN); |
|
101 | m_yMaxSpin->setMinimum(INT_MIN); | |
100 | m_yMaxSpin->setMaximum(INT_MAX); |
|
102 | m_yMaxSpin->setMaximum(INT_MAX); | |
101 | m_yMaxSpin->setValue(10); |
|
103 | m_yMaxSpin->setValue(10); | |
102 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
104 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
103 |
|
105 | |||
104 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
106 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
105 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
107 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
106 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
108 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
107 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
109 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
108 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
110 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
109 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
111 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
110 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
112 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
111 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
113 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
112 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
114 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
113 |
|
115 | |||
114 | m_autoScaleCheck->setChecked(true); |
|
116 | m_autoScaleCheck->setChecked(true); | |
115 | } |
|
117 | } | |
116 |
|
118 | |||
117 | // Combo box for selecting theme |
|
119 | // Combo box for selecting theme | |
118 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
120 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
119 | { |
|
121 | { | |
120 | QComboBox *chartTheme = new QComboBox(); |
|
122 | QComboBox *chartTheme = new QComboBox(); | |
121 | chartTheme->addItem("Default"); |
|
123 | chartTheme->addItem("Default"); | |
122 | chartTheme->addItem("Vanilla"); |
|
124 | chartTheme->addItem("Vanilla"); | |
123 | chartTheme->addItem("Icy"); |
|
125 | chartTheme->addItem("Icy"); | |
124 | chartTheme->addItem("Grayscale"); |
|
126 | chartTheme->addItem("Grayscale"); | |
125 | chartTheme->addItem("Unnamed1"); |
|
127 | chartTheme->addItem("Unnamed1"); | |
126 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
128 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
127 | this, SLOT(changeChartTheme(int))); |
|
129 | this, SLOT(changeChartTheme(int))); | |
128 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
130 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
129 | grid->addWidget(chartTheme, 8, 1); |
|
131 | grid->addWidget(chartTheme, 8, 1); | |
130 | } |
|
132 | } | |
131 |
|
133 | |||
132 | void MainWidget::initPieControls() |
|
134 | void MainWidget::initPieControls() | |
133 | { |
|
135 | { | |
134 | // Pie series specific settings |
|
136 | // Pie series specific settings | |
135 | // Pie size factory |
|
137 | // Pie size factory | |
136 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); |
|
138 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); | |
137 | pieSizeSpin->setMinimum(LONG_MIN); |
|
139 | pieSizeSpin->setMinimum(LONG_MIN); | |
138 | pieSizeSpin->setMaximum(LONG_MAX); |
|
140 | pieSizeSpin->setMaximum(LONG_MAX); | |
139 | pieSizeSpin->setValue(1.0); |
|
141 | pieSizeSpin->setValue(1.0); | |
140 | pieSizeSpin->setSingleStep(0.1); |
|
142 | pieSizeSpin->setSingleStep(0.1); | |
141 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); |
|
143 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); | |
142 | // Pie position |
|
144 | // Pie position | |
143 | QComboBox *piePosCombo = new QComboBox(this); |
|
145 | QComboBox *piePosCombo = new QComboBox(this); | |
144 | piePosCombo->addItem("Maximized"); |
|
146 | piePosCombo->addItem("Maximized"); | |
145 | piePosCombo->addItem("Top left"); |
|
147 | piePosCombo->addItem("Top left"); | |
146 | piePosCombo->addItem("Top right"); |
|
148 | piePosCombo->addItem("Top right"); | |
147 | piePosCombo->addItem("Bottom left"); |
|
149 | piePosCombo->addItem("Bottom left"); | |
148 | piePosCombo->addItem("Bottom right"); |
|
150 | piePosCombo->addItem("Bottom right"); | |
149 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), |
|
151 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), | |
150 | this, SLOT(setPiePosition(int))); |
|
152 | this, SLOT(setPiePosition(int))); | |
151 | m_pieLayout = new QGridLayout(); |
|
153 | m_pieLayout = new QGridLayout(); | |
152 | m_pieLayout->setEnabled(false); |
|
154 | m_pieLayout->setEnabled(false); | |
153 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); |
|
155 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); | |
154 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); |
|
156 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); | |
155 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); |
|
157 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); | |
156 | m_pieLayout->addWidget(piePosCombo, 1, 1); |
|
158 | m_pieLayout->addWidget(piePosCombo, 1, 1); | |
157 | } |
|
159 | } | |
158 |
|
160 | |||
159 | void MainWidget::addSeries() |
|
161 | void MainWidget::addSeries() | |
160 | { |
|
162 | { | |
161 | DataSerieDialog dialog(m_defaultSeriesName, this); |
|
163 | DataSerieDialog dialog(m_defaultSeriesName, this); | |
162 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); |
|
164 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); | |
163 | dialog.exec(); |
|
165 | dialog.exec(); | |
164 | } |
|
166 | } | |
165 |
|
167 | |||
166 | void MainWidget::addSeries(QString series, QString data) |
|
168 | void MainWidget::addSeries(QString series, QString data) | |
167 | { |
|
169 | { | |
168 | qDebug() << "addSeries: " << series << " data: " << data; |
|
170 | qDebug() << "addSeries: " << series << " data: " << data; | |
169 | m_defaultSeriesName = series; |
|
171 | m_defaultSeriesName = series; | |
170 |
|
172 | |||
171 | // TODO: a dedicated data class for storing x and y values |
|
173 | // TODO: a dedicated data class for storing x and y values | |
172 | QList<qreal> x; |
|
174 | QList<qreal> x; | |
173 | QList<qreal> y; |
|
175 | QList<qreal> y; | |
174 |
|
176 | |||
175 | if (data == "linear") { |
|
177 | if (data == "linear") { | |
176 | for (int i = 0; i < 20; i++) { |
|
178 | for (int i = 0; i < 20; i++) { | |
177 | x.append(i); |
|
179 | x.append(i); | |
178 | y.append(i); |
|
180 | y.append(i); | |
179 | } |
|
181 | } | |
180 | } else if (data == "linear, 1M") { |
|
182 | } else if (data == "linear, 1M") { | |
181 | // 1 million data points from 0.0001 to 100 |
|
183 | // 1 million data points from 0.0001 to 100 | |
182 | // TODO: What is the requirement? Should we be able to show this kind of data with |
|
184 | // TODO: What is the requirement? Should we be able to show this kind of data with | |
183 | // reasonable performance, or can we expect the application developer to do "data mining" |
|
185 | // reasonable performance, or can we expect the application developer to do "data mining" | |
184 | // for us, so that the count of data points given to QtCommercial Chart is always |
|
186 | // for us, so that the count of data points given to QtCommercial Chart is always | |
185 | // reasonable? |
|
187 | // reasonable? | |
186 | for (qreal i = 0; i < 100; i += 0.0001) { |
|
188 | for (qreal i = 0; i < 100; i += 0.0001) { | |
187 | x.append(i); |
|
189 | x.append(i); | |
188 | y.append(20); |
|
190 | y.append(20); | |
189 | } |
|
191 | } | |
190 | } else if (data == "SIN") { |
|
192 | } else if (data == "SIN") { | |
191 | for (int i = 0; i < 100; i++) { |
|
193 | for (int i = 0; i < 100; i++) { | |
192 | x.append(i); |
|
194 | x.append(i); | |
193 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
195 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
194 | } |
|
196 | } | |
195 | } else if (data == "SIN + random") { |
|
197 | } else if (data == "SIN + random") { | |
196 | for (qreal i = 0; i < 100; i += 0.1) { |
|
198 | for (qreal i = 0; i < 100; i += 0.1) { | |
197 | x.append(i + (rand() % 5)); |
|
199 | x.append(i + (rand() % 5)); | |
198 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
200 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
199 | } |
|
201 | } | |
200 | } else { |
|
202 | } else { | |
201 | // TODO: check if data has a valid file name |
|
203 | // TODO: check if data has a valid file name | |
202 | Q_ASSERT(false); |
|
204 | Q_ASSERT(false); | |
203 | } |
|
205 | } | |
204 |
|
206 | |||
205 | // TODO: color of the series |
|
207 | // TODO: color of the series | |
206 | QChartSeries *newSeries = 0; |
|
208 | QChartSeries *newSeries = 0; | |
207 | if (series == "Scatter") { |
|
209 | if (series == "Scatter") { | |
208 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter); |
|
210 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter); | |
209 | Q_ASSERT(newSeries->setData(x, y)); |
|
211 | Q_ASSERT(newSeries->setData(x, y)); | |
210 | } else if (series == "Pie") { |
|
212 | } else if (series == "Pie") { | |
211 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); |
|
213 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); | |
212 | Q_ASSERT(newSeries->setData(y)); |
|
214 | Q_ASSERT(newSeries->setData(y)); | |
213 | } else if (series == "Line") { |
|
215 | } else if (series == "Line") { | |
214 | // TODO: adding data to an existing line series does not give any visuals for some reason |
|
216 | // TODO: adding data to an existing line series does not give any visuals for some reason | |
215 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); |
|
217 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); | |
216 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); |
|
218 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); | |
217 | // lineSeries->setColor(Qt::blue); |
|
219 | // lineSeries->setColor(Qt::blue); | |
218 | // for (int i(0); i < x.count() && i < y.count(); i++) { |
|
220 | // for (int i(0); i < x.count() && i < y.count(); i++) { | |
219 | // lineSeries->add(x.at(i), y.at(i)); |
|
221 | // lineSeries->add(x.at(i), y.at(i)); | |
220 | // } |
|
222 | // } | |
221 | //Q_ASSERT(newSeries->setData(x, y)); |
|
223 | //Q_ASSERT(newSeries->setData(x, y)); | |
222 | QXYChartSeries* series0 = QXYChartSeries::create(); |
|
224 | QXYChartSeries* series0 = QXYChartSeries::create(); | |
223 | for (int i(0); i < x.count() && i < y.count(); i++) |
|
225 | for (int i(0); i < x.count() && i < y.count(); i++) | |
224 | series0->add(x.at(i), y.at(i)); |
|
226 | series0->add(x.at(i), y.at(i)); | |
225 | m_chartWidget->addSeries(series0); |
|
227 | m_chartWidget->addSeries(series0); | |
226 | newSeries = series0; |
|
228 | newSeries = series0; | |
227 | } else { |
|
229 | } else { | |
228 | // TODO |
|
230 | // TODO | |
229 | } |
|
231 | } | |
230 |
|
232 | |||
231 | // BarChart |
|
233 | // BarChart | |
232 | if (series == "Bar") { |
|
234 | if (series == "Bar") { | |
233 | // This is the another way of creating series. Should we create test cases for both ways, if we support them? |
|
235 | // This is the another way of creating series. Should we create test cases for both ways, if we support them? | |
234 | qDebug() << "Bar chart series"; |
|
236 | qDebug() << "Bar chart series"; | |
235 | newSeries = QChartSeries::create(QChartSeries::SeriesTypeBar, this); |
|
237 | newSeries = QChartSeries::create(QChartSeries::SeriesTypeBar, this); | |
236 |
|
238 | |||
237 | // Create some test data to chart |
|
239 | // Create some test data to chart | |
238 | QStandardItemModel dataModel(2,10,this); |
|
240 | QStandardItemModel dataModel(2,10,this); | |
239 | QModelIndex index; |
|
241 | QModelIndex index; | |
240 | index = dataModel.index(0,0); |
|
242 | index = dataModel.index(0,0); | |
241 | // Series 1, items 6 to 9 missing. |
|
243 | // Series 1, items 6 to 9 missing. | |
242 | dataModel.setData(dataModel.index(0,0),1); |
|
244 | dataModel.setData(dataModel.index(0,0),1); | |
243 | dataModel.setData(dataModel.index(0,1),12); |
|
245 | dataModel.setData(dataModel.index(0,1),12); | |
244 | dataModel.setData(dataModel.index(0,2),5); |
|
246 | dataModel.setData(dataModel.index(0,2),5); | |
245 | dataModel.setData(dataModel.index(0,3),8); |
|
247 | dataModel.setData(dataModel.index(0,3),8); | |
246 | dataModel.setData(dataModel.index(0,4),17); |
|
248 | dataModel.setData(dataModel.index(0,4),17); | |
247 | dataModel.setData(dataModel.index(0,5),9); |
|
249 | dataModel.setData(dataModel.index(0,5),9); | |
248 |
|
250 | |||
249 | // Series 2, some other items missing |
|
251 | // Series 2, some other items missing | |
250 | dataModel.setData(dataModel.index(1,0),5); |
|
252 | dataModel.setData(dataModel.index(1,0),5); | |
251 | dataModel.setData(dataModel.index(1,3),4); |
|
253 | dataModel.setData(dataModel.index(1,3),4); | |
252 | dataModel.setData(dataModel.index(1,5),7); |
|
254 | dataModel.setData(dataModel.index(1,5),7); | |
253 | dataModel.setData(dataModel.index(1,6),8); |
|
255 | dataModel.setData(dataModel.index(1,6),8); | |
254 | dataModel.setData(dataModel.index(1,8),9); |
|
256 | dataModel.setData(dataModel.index(1,8),9); | |
255 | dataModel.setData(dataModel.index(1,9),9); |
|
257 | dataModel.setData(dataModel.index(1,9),9); | |
256 |
|
258 | |||
257 | newSeries->setData(&dataModel); |
|
259 | newSeries->setData(&dataModel); | |
258 |
|
260 | |||
259 | m_chartWidget->addSeries(newSeries); |
|
261 | m_chartWidget->addSeries(newSeries); | |
260 | } |
|
262 | } | |
261 |
|
263 | |||
262 | setCurrentSeries(newSeries); |
|
264 | setCurrentSeries(newSeries); | |
263 | } |
|
265 | } | |
264 |
|
266 | |||
265 | void MainWidget::setCurrentSeries(QChartSeries *series) |
|
267 | void MainWidget::setCurrentSeries(QChartSeries *series) | |
266 | { |
|
268 | { | |
267 | m_currentSeries = series; |
|
269 | m_currentSeries = series; | |
268 | switch (m_currentSeries->type()) { |
|
270 | switch (m_currentSeries->type()) { | |
269 | case QChartSeries::SeriesTypeLine: |
|
271 | case QChartSeries::SeriesTypeLine: | |
270 | break; |
|
272 | break; | |
271 | case QChartSeries::SeriesTypeScatter: |
|
273 | case QChartSeries::SeriesTypeScatter: | |
272 | break; |
|
274 | break; | |
273 | case QChartSeries::SeriesTypePie: |
|
275 | case QChartSeries::SeriesTypePie: | |
274 | break; |
|
276 | break; | |
275 | case QChartSeries::SeriesTypeBar: |
|
277 | case QChartSeries::SeriesTypeBar: | |
276 | qDebug() << "setCurrentSeries (bar)"; |
|
278 | qDebug() << "setCurrentSeries (bar)"; | |
277 | break; |
|
279 | break; | |
278 | default: |
|
280 | default: | |
279 | Q_ASSERT(false); |
|
281 | Q_ASSERT(false); | |
280 | break; |
|
282 | break; | |
281 | } |
|
283 | } | |
282 | } |
|
284 | } | |
283 |
|
285 | |||
284 | void MainWidget::testDataChanged(int itemIndex) |
|
286 | void MainWidget::testDataChanged(int itemIndex) | |
285 | { |
|
287 | { | |
286 | qDebug() << "testDataChanged: " << itemIndex; |
|
288 | qDebug() << "testDataChanged: " << itemIndex; | |
287 |
|
289 | |||
288 | // switch (itemIndex) { |
|
290 | // switch (itemIndex) { | |
289 | // case 0: { |
|
291 | // case 0: { | |
290 | // QList<QChartDataPoint> data; |
|
292 | // QList<QChartDataPoint> data; | |
291 | // for (int x = 0; x < 20; x++) { |
|
293 | // for (int x = 0; x < 20; x++) { | |
292 | // data.append(QChartDataPoint() << x << x / 2); |
|
294 | // data.append(QChartDataPoint() << x << x / 2); | |
293 | // } |
|
295 | // } | |
294 | // m_chartWidget->setData(data); |
|
296 | // m_chartWidget->setData(data); | |
295 | // break; |
|
297 | // break; | |
296 | // } |
|
298 | // } | |
297 | // case 1: { |
|
299 | // case 1: { | |
298 | // QList<QChartDataPoint> data; |
|
300 | // QList<QChartDataPoint> data; | |
299 | // for (int x = 0; x < 100; x++) { |
|
301 | // for (int x = 0; x < 100; x++) { | |
300 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); |
|
302 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); | |
301 | // } |
|
303 | // } | |
302 | // m_chartWidget->setData(data); |
|
304 | // m_chartWidget->setData(data); | |
303 | // break; |
|
305 | // break; | |
304 | // } |
|
306 | // } | |
305 | // case 2: { |
|
307 | // case 2: { | |
306 | // QList<QChartDataPoint> data; |
|
308 | // QList<QChartDataPoint> data; | |
307 | // for (int x = 0; x < 1000; x++) { |
|
309 | // for (int x = 0; x < 1000; x++) { | |
308 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
310 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
309 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
311 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
310 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
312 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
311 | // } |
|
313 | // } | |
312 | // m_chartWidget->setData(data); |
|
314 | // m_chartWidget->setData(data); | |
313 | // break; |
|
315 | // break; | |
314 | // } |
|
316 | // } | |
315 | // default: |
|
317 | // default: | |
316 | // break; |
|
318 | // break; | |
317 | // } |
|
319 | // } | |
318 | } |
|
320 | } | |
319 |
|
321 | |||
320 | void MainWidget::backgroundChanged(int itemIndex) |
|
322 | void MainWidget::backgroundChanged(int itemIndex) | |
321 | { |
|
323 | { | |
322 | qDebug() << "backgroundChanged: " << itemIndex; |
|
324 | qDebug() << "backgroundChanged: " << itemIndex; | |
323 | } |
|
325 | } | |
324 |
|
326 | |||
325 | void MainWidget::autoScaleChanged(int value) |
|
327 | void MainWidget::autoScaleChanged(int value) | |
326 | { |
|
328 | { | |
327 | if (value) { |
|
329 | if (value) { | |
328 | // TODO: enable auto scaling |
|
330 | // TODO: enable auto scaling | |
329 | } else { |
|
331 | } else { | |
330 | // TODO: set scaling manually (and disable auto scaling) |
|
332 | // TODO: set scaling manually (and disable auto scaling) | |
331 | } |
|
333 | } | |
332 |
|
334 | |||
333 | m_xMinSpin->setEnabled(!value); |
|
335 | m_xMinSpin->setEnabled(!value); | |
334 | m_xMaxSpin->setEnabled(!value); |
|
336 | m_xMaxSpin->setEnabled(!value); | |
335 | m_yMinSpin->setEnabled(!value); |
|
337 | m_yMinSpin->setEnabled(!value); | |
336 | m_yMaxSpin->setEnabled(!value); |
|
338 | m_yMaxSpin->setEnabled(!value); | |
337 | } |
|
339 | } | |
338 |
|
340 | |||
339 | void MainWidget::xMinChanged(int value) |
|
341 | void MainWidget::xMinChanged(int value) | |
340 | { |
|
342 | { | |
341 | qDebug() << "xMinChanged: " << value; |
|
343 | qDebug() << "xMinChanged: " << value; | |
342 | } |
|
344 | } | |
343 |
|
345 | |||
344 | void MainWidget::xMaxChanged(int value) |
|
346 | void MainWidget::xMaxChanged(int value) | |
345 | { |
|
347 | { | |
346 | qDebug() << "xMaxChanged: " << value; |
|
348 | qDebug() << "xMaxChanged: " << value; | |
347 | } |
|
349 | } | |
348 |
|
350 | |||
349 | void MainWidget::yMinChanged(int value) |
|
351 | void MainWidget::yMinChanged(int value) | |
350 | { |
|
352 | { | |
351 | qDebug() << "yMinChanged: " << value; |
|
353 | qDebug() << "yMinChanged: " << value; | |
352 | } |
|
354 | } | |
353 |
|
355 | |||
354 | void MainWidget::yMaxChanged(int value) |
|
356 | void MainWidget::yMaxChanged(int value) | |
355 | { |
|
357 | { | |
356 | qDebug() << "yMaxChanged: " << value; |
|
358 | qDebug() << "yMaxChanged: " << value; | |
357 | } |
|
359 | } | |
358 |
|
360 | |||
359 | void MainWidget::changeChartTheme(int themeIndex) |
|
361 | void MainWidget::changeChartTheme(int themeIndex) | |
360 | { |
|
362 | { | |
361 | qDebug() << "changeChartTheme: " << themeIndex; |
|
363 | qDebug() << "changeChartTheme: " << themeIndex; | |
362 | m_chartWidget->setTheme((QChart::ChartThemeId) themeIndex); |
|
364 | m_chartWidget->setTheme((QChart::ChartThemeId) themeIndex); | |
363 | } |
|
365 | } | |
364 |
|
366 | |||
365 | void MainWidget::setPieSizeFactor(double size) |
|
367 | void MainWidget::setPieSizeFactor(double size) | |
366 | { |
|
368 | { | |
367 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
369 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
368 | if (pie) |
|
370 | if (pie) | |
369 | pie->setSizeFactor(qreal(size)); |
|
371 | pie->setSizeFactor(qreal(size)); | |
370 | } |
|
372 | } | |
371 |
|
373 | |||
372 | void MainWidget::setPiePosition(int position) |
|
374 | void MainWidget::setPiePosition(int position) | |
373 | { |
|
375 | { | |
374 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
376 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
375 | if (pie) |
|
377 | if (pie) | |
376 | pie->setPosition((QPieSeries::PiePosition) position); |
|
378 | pie->setPosition((QPieSeries::PiePosition) position); | |
377 | } |
|
379 | } |
General Comments 0
You need to be logged in to leave comments.
Login now