@@ -1,285 +1,319 | |||||
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 "plotdomain_p.h" |
|
12 | #include "plotdomain_p.h" | |
13 | #include "axisitem_p.h" |
|
13 | #include "axisitem_p.h" | |
14 | #include <QGraphicsScene> |
|
14 | #include <QGraphicsScene> | |
15 | #include <QDebug> |
|
15 | #include <QDebug> | |
16 |
|
16 | |||
17 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
17 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
18 |
|
18 | |||
19 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), |
|
19 | QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), | |
20 | m_background(new QGraphicsRectItem(this)), |
|
20 | m_background(new QGraphicsRectItem(this)), | |
21 | m_title(new QGraphicsTextItem(this)), |
|
21 | m_title(new QGraphicsTextItem(this)), | |
22 | m_axisX(new AxisItem(AxisItem::X_AXIS,this)), |
|
22 | m_axisX(new AxisItem(AxisItem::X_AXIS,this)), | |
23 | m_axisY(new AxisItem(AxisItem::Y_AXIS,this)), |
|
23 | m_axisY(new AxisItem(AxisItem::Y_AXIS,this)), | |
24 | m_plotDataIndex(0), |
|
24 | m_plotDataIndex(0), | |
25 | m_marginSize(0) |
|
25 | m_marginSize(0) | |
26 | { |
|
26 | { | |
27 | // TODO: the default theme? |
|
27 | // TODO: the default theme? | |
28 | setTheme(QChart::ChartThemeVanilla); |
|
28 | setTheme(QChart::ChartThemeVanilla); | |
29 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
29 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
30 | PlotDomain domain; |
|
30 | PlotDomain domain; | |
31 | m_plotDomainList<<domain; |
|
31 | m_plotDomainList<<domain; | |
32 |
|
32 | |||
33 | m_chartItems<<m_axisX; |
|
33 | m_chartItems<<m_axisX; | |
34 | m_chartItems<<m_axisY; |
|
34 | m_chartItems<<m_axisY; | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | QChart::~QChart(){} |
|
37 | QChart::~QChart(){} | |
38 |
|
38 | |||
39 | QRectF QChart::boundingRect() const |
|
39 | QRectF QChart::boundingRect() const | |
40 | { |
|
40 | { | |
41 | return m_rect; |
|
41 | return m_rect; | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | void QChart::addSeries(QChartSeries* series) |
|
44 | void QChart::addSeries(QChartSeries* series) | |
45 | { |
|
45 | { | |
46 | // TODO: we should check the series not already added |
|
46 | // TODO: we should check the series not already added | |
47 |
|
47 | |||
48 |
m_ |
|
48 | m_chartSeries << series; | |
49 |
|
49 | |||
50 | switch(series->type()) |
|
50 | switch(series->type()) | |
51 | { |
|
51 | { | |
52 | case QChartSeries::SeriesTypeLine: { |
|
52 | case QChartSeries::SeriesTypeLine: { | |
53 |
|
53 | |||
54 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); |
|
54 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); | |
55 | // Use color defined by theme in case the series does not define a custom color |
|
55 | // Use color defined by theme in case the series does not define a custom color | |
56 | if (!xyseries->color().isValid() && m_themeColors.count()) |
|
56 | if (!xyseries->color().isValid() && m_themeColors.count()) | |
57 |
xyseries->setColor( |
|
57 | xyseries->setColor(nextColor()); | |
58 |
|
58 | |||
59 | m_plotDataIndex = 0 ; |
|
59 | m_plotDataIndex = 0 ; | |
60 | m_plotDomainList.resize(1); |
|
60 | m_plotDomainList.resize(1); | |
61 |
|
61 | |||
62 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; |
|
62 | PlotDomain& domain = m_plotDomainList[m_plotDataIndex]; | |
63 |
|
63 | |||
64 | for (int i = 0 ; i < xyseries->count() ; i++) |
|
64 | for (int i = 0 ; i < xyseries->count() ; i++) | |
65 | { |
|
65 | { | |
66 | qreal x = xyseries->x(i); |
|
66 | qreal x = xyseries->x(i); | |
67 | qreal y = xyseries->y(i); |
|
67 | qreal y = xyseries->y(i); | |
68 | domain.m_minX = qMin(domain.m_minX,x); |
|
68 | domain.m_minX = qMin(domain.m_minX,x); | |
69 | domain.m_minY = qMin(domain.m_minY,y); |
|
69 | domain.m_minY = qMin(domain.m_minY,y); | |
70 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
70 | domain.m_maxX = qMax(domain.m_maxX,x); | |
71 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
71 | domain.m_maxY = qMax(domain.m_maxY,y); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); |
|
74 | XYLineChartItem* item = new XYLineChartItem(xyseries,this); | |
75 |
|
||||
76 | m_chartItems<<item; |
|
75 | m_chartItems<<item; | |
77 |
|
76 | |||
78 | foreach(ChartItem* i ,m_chartItems) |
|
77 | foreach(ChartItem* i ,m_chartItems) | |
79 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); |
|
78 | i->setPlotDomain(m_plotDomainList.at(m_plotDataIndex)); | |
80 |
|
79 | |||
81 | break; |
|
80 | break; | |
82 | } |
|
81 | } | |
83 | case QChartSeries::SeriesTypeBar: { |
|
82 | case QChartSeries::SeriesTypeBar: { | |
84 |
|
83 | |||
85 | qDebug() << "barSeries added"; |
|
84 | qDebug() << "barSeries added"; | |
86 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
85 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); | |
87 | connect(this, SIGNAL(sizeChanged(QRectF)), |
|
86 | connect(this, SIGNAL(sizeChanged(QRectF)), | |
88 | barSeries, SLOT(chartSizeChanged(QRectF))); |
|
87 | barSeries, SLOT(chartSizeChanged(QRectF))); | |
89 |
|
88 | |||
90 | break; |
|
89 | break; | |
91 | } |
|
90 | } | |
92 | case QChartSeries::SeriesTypeScatter: { |
|
91 | case QChartSeries::SeriesTypeScatter: { | |
93 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
92 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
|
93 | scatterSeries->d->setParentItem(this); | |||
|
94 | // Set pre-defined colors in case the series has no colors defined | |||
|
95 | if (!scatterSeries->markerColor().isValid()) | |||
|
96 | scatterSeries->setMarkerColor(nextColor()); | |||
94 | connect(this, SIGNAL(sizeChanged(QRectF)), |
|
97 | connect(this, SIGNAL(sizeChanged(QRectF)), | |
95 | scatterSeries, SLOT(chartSizeChanged(QRectF))); |
|
98 | scatterSeries, SLOT(chartSizeChanged(QRectF))); | |
96 | scatterSeries->d->setParentItem(this); |
|
99 | // QColor nextColor = m_themeColors.takeFirst(); | |
97 | QColor nextColor = m_themeColors.takeFirst(); |
|
100 | // nextColor.setAlpha(150); // TODO: default opacity? | |
98 | nextColor.setAlpha(150); // TODO: default opacity? |
|
101 | // scatterSeries->setMarkerColor(nextColor); | |
99 | scatterSeries->setMarkerColor(nextColor); |
|
102 | break; | |
100 | } |
|
103 | } | |
101 | case QChartSeries::SeriesTypePie: { |
|
104 | case QChartSeries::SeriesTypePie: { | |
102 | // TODO: we now have also a list of y values as a parameter, it is ignored |
|
|||
103 | // we should use a generic data class instead of list of x and y values |
|
|||
104 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); |
|
105 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |
|
106 | for (int i(0); i < pieSeries->sliceCount(); i++) { | |||
|
107 | if (!pieSeries->sliceColor(i).isValid()) | |||
|
108 | pieSeries->setSliceColor(i, nextColor()); | |||
|
109 | } | |||
105 | connect(this, SIGNAL(sizeChanged(QRectF)), |
|
110 | connect(this, SIGNAL(sizeChanged(QRectF)), | |
106 | pieSeries, SLOT(chartSizeChanged(QRectF))); |
|
111 | pieSeries, SLOT(chartSizeChanged(QRectF))); | |
|
112 | ||||
|
113 | // Set pre-defined colors in case the series has no colors defined | |||
107 | // TODO: how to define the color for all the slices of a pie? |
|
114 | // TODO: how to define the color for all the slices of a pie? | |
|
115 | // for (int (i); i < pieSeries.sliceCount(); i++) | |||
|
116 | break; | |||
108 | } |
|
117 | } | |
109 | } |
|
118 | } | |
110 | } |
|
119 | } | |
111 |
|
120 | |||
112 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
121 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |
113 | { |
|
122 | { | |
114 | // TODO: support also other types; not only scatter and pie |
|
123 | // TODO: support also other types; not only scatter and pie | |
115 |
|
124 | |||
116 | QChartSeries *series(0); |
|
125 | QChartSeries *series(0); | |
117 |
|
126 | |||
118 | switch (type) { |
|
127 | switch (type) { | |
119 | case QChartSeries::SeriesTypeLine: { |
|
128 | case QChartSeries::SeriesTypeLine: { | |
120 | series = QXYChartSeries::create(); |
|
129 | series = QXYChartSeries::create(); | |
121 | break; |
|
130 | break; | |
122 | } |
|
131 | } | |
123 | case QChartSeries::SeriesTypeBar: { |
|
132 | case QChartSeries::SeriesTypeBar: { | |
124 | series = new BarChartSeries(this); |
|
133 | series = new BarChartSeries(this); | |
125 | break; |
|
134 | break; | |
126 | } |
|
135 | } | |
127 | case QChartSeries::SeriesTypeScatter: { |
|
136 | case QChartSeries::SeriesTypeScatter: { | |
128 | series = new QScatterSeries(this); |
|
137 | series = new QScatterSeries(this); | |
129 | break; |
|
138 | break; | |
130 | } |
|
139 | } | |
131 | case QChartSeries::SeriesTypePie: { |
|
140 | case QChartSeries::SeriesTypePie: { | |
132 | series = new QPieSeries(this); |
|
141 | series = new QPieSeries(this); | |
133 | break; |
|
142 | break; | |
134 | } |
|
143 | } | |
135 | default: |
|
144 | default: | |
136 | Q_ASSERT(false); |
|
145 | Q_ASSERT(false); | |
137 | break; |
|
146 | break; | |
138 | } |
|
147 | } | |
139 |
|
148 | |||
140 | addSeries(series); |
|
149 | addSeries(series); | |
141 | return series; |
|
150 | return series; | |
142 | } |
|
151 | } | |
143 |
|
152 | |||
144 | void QChart::setSize(const QSize& size) |
|
153 | void QChart::setSize(const QSize& size) | |
145 | { |
|
154 | { | |
146 | m_rect = QRect(QPoint(0,0),size); |
|
155 | m_rect = QRect(QPoint(0,0),size); | |
147 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
156 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
148 |
|
157 | |||
149 |
|
158 | |||
150 | //recalculate background gradient |
|
159 | //recalculate background gradient | |
151 | m_background->setRect(rect); |
|
160 | m_background->setRect(rect); | |
152 | m_backgroundGradient.setFinalStop(0,m_background->rect().height()); |
|
161 | m_backgroundGradient.setFinalStop(0,m_background->rect().height()); | |
153 | m_background->setBrush(m_backgroundGradient); |
|
162 | m_background->setBrush(m_backgroundGradient); | |
154 |
|
163 | |||
155 | //resize elements |
|
164 | //resize elements | |
156 | foreach (ChartItem* item ,m_chartItems) { |
|
165 | foreach (ChartItem* item ,m_chartItems) { | |
157 | item->setPos(rect.topLeft()); |
|
166 | item->setPos(rect.topLeft()); | |
158 | item->setSize(rect.size()); |
|
167 | item->setSize(rect.size()); | |
159 |
|
168 | |||
160 | } |
|
169 | } | |
161 | // TODO: TTD for setting scale |
|
170 | // TODO: TTD for setting scale | |
162 | //emit scaleChanged(100, 100); |
|
171 | //emit scaleChanged(100, 100); | |
163 | // TODO: calculate the origo |
|
172 | // TODO: calculate the origo | |
164 | // TODO: not sure if emitting a signal here is the best from performance point of view |
|
173 | // TODO: not sure if emitting a signal here is the best from performance point of view | |
165 | emit sizeChanged(QRectF(0, 0, size.width(), size.height())); |
|
174 | emit sizeChanged(QRectF(0, 0, size.width(), size.height())); | |
166 |
|
175 | |||
167 | update(); |
|
176 | update(); | |
168 | } |
|
177 | } | |
169 |
|
178 | |||
170 | void QChart::setBackgroundColor(const QColor& color) |
|
179 | void QChart::setBackgroundColor(const QColor& color) | |
171 | { |
|
180 | { | |
172 | m_backgroundGradient.setColorAt( 0.0, Qt::white); |
|
181 | m_backgroundGradient.setColorAt( 0.0, Qt::white); | |
173 | m_backgroundGradient.setColorAt( 1.0, color); |
|
182 | m_backgroundGradient.setColorAt( 1.0, color); | |
174 | m_background->setBrush(m_backgroundGradient); |
|
183 | m_background->setBrush(m_backgroundGradient); | |
175 | m_background->setPen(Qt::NoPen); |
|
184 | m_background->setPen(Qt::NoPen); | |
176 | m_background->update(); |
|
185 | m_background->update(); | |
177 | } |
|
186 | } | |
178 |
|
187 | |||
179 | void QChart::setTitle(const QString& title) |
|
188 | void QChart::setTitle(const QString& title) | |
180 | { |
|
189 | { | |
181 | m_title->setPlainText(title); |
|
190 | m_title->setPlainText(title); | |
182 | } |
|
191 | } | |
183 |
|
192 | |||
184 | int QChart::margin() const |
|
193 | int QChart::margin() const | |
185 | { |
|
194 | { | |
186 | return m_marginSize; |
|
195 | return m_marginSize; | |
187 | } |
|
196 | } | |
188 |
|
197 | |||
189 | void QChart::setMargin(int margin) |
|
198 | void QChart::setMargin(int margin) | |
190 | { |
|
199 | { | |
191 | m_marginSize = margin; |
|
200 | m_marginSize = margin; | |
192 | } |
|
201 | } | |
193 |
|
202 | |||
194 | void QChart::setTheme(QChart::ChartTheme theme) |
|
203 | void QChart::setTheme(QChart::ChartThemeId theme) | |
195 | { |
|
204 | { | |
|
205 | // if (theme != m_currentTheme) { | |||
|
206 | m_themeColors.clear(); | |||
|
207 | ||||
196 | // TODO: define color themes |
|
208 | // TODO: define color themes | |
197 | switch (theme) { |
|
209 | switch (theme) { | |
198 | case ChartThemeVanilla: |
|
210 | case QChart::ChartThemeVanilla: | |
199 |
m_themeColors.append(QColor(2 |
|
211 | m_themeColors.append(QColor(217, 197, 116)); | |
200 |
m_themeColors.append(QColor(2 |
|
212 | m_themeColors.append(QColor(214, 168, 150)); | |
201 |
m_themeColors.append(QColor( |
|
213 | m_themeColors.append(QColor(160, 160, 113)); | |
202 |
m_themeColors.append(QColor(1 |
|
214 | m_themeColors.append(QColor(210, 210, 52)); | |
203 |
m_themeColors.append(QColor( |
|
215 | m_themeColors.append(QColor(136, 114, 58)); | |
204 | break; |
|
216 | break; | |
205 | case ChartThemeIcy: |
|
217 | case QChart::ChartThemeIcy: | |
206 |
m_themeColors.append(QColor( |
|
218 | m_themeColors.append(QColor(0, 3, 165)); | |
207 |
m_themeColors.append(QColor( |
|
219 | m_themeColors.append(QColor(49, 52, 123)); | |
208 |
m_themeColors.append(QColor( |
|
220 | m_themeColors.append(QColor(71, 114, 187)); | |
209 |
m_themeColors.append(QColor( |
|
221 | m_themeColors.append(QColor(48, 97, 87)); | |
210 |
m_themeColors.append(QColor( |
|
222 | m_themeColors.append(QColor(19, 71, 90)); | |
|
223 | m_themeColors.append(QColor(110, 70, 228)); | |||
211 | break; |
|
224 | break; | |
212 | case ChartThemeGrayscale: |
|
225 | case QChart::ChartThemeGrayscale: | |
213 |
m_themeColors.append(QColor( |
|
226 | m_themeColors.append(QColor(0, 0, 0)); | |
214 |
m_themeColors.append(QColor( |
|
227 | m_themeColors.append(QColor(50, 50, 50)); | |
215 |
m_themeColors.append(QColor( |
|
228 | m_themeColors.append(QColor(100, 100, 100)); | |
216 |
m_themeColors.append(QColor(1 |
|
229 | m_themeColors.append(QColor(140, 140, 140)); | |
217 |
m_themeColors.append(QColor( |
|
230 | m_themeColors.append(QColor(180, 180, 180)); | |
218 | break; |
|
231 | break; | |
219 | default: |
|
232 | default: | |
220 | Q_ASSERT(false); |
|
233 | Q_ASSERT(false); | |
221 | break; |
|
234 | break; | |
222 | } |
|
235 | } | |
223 |
|
236 | |||
224 | // TODO: update coloring of different elements to match the selected theme |
|
237 | foreach(QChartSeries* series, m_chartSeries) { | |
|
238 | // TODO: other series interested on themes? | |||
|
239 | if (series->type() == QChartSeries::SeriesTypeLine) { | |||
|
240 | QXYChartSeries *lineseries = reinterpret_cast<QXYChartSeries *>(series); | |||
|
241 | lineseries->setColor(nextColor()); | |||
|
242 | } else if (series->type() == QChartSeries::SeriesTypeScatter) { | |||
|
243 | QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series); | |||
|
244 | scatter->setMarkerColor(nextColor()); | |||
|
245 | } else if (series->type() == QChartSeries::SeriesTypePie) { | |||
|
246 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |||
|
247 | for (int i(0); i < pieSeries->sliceCount(); i++) | |||
|
248 | pieSeries->setSliceColor(i, nextColor()); | |||
|
249 | } | |||
|
250 | } | |||
|
251 | update(); | |||
|
252 | } | |||
|
253 | ||||
|
254 | QColor QChart::nextColor() | |||
|
255 | { | |||
|
256 | QColor nextColor = m_themeColors.first(); | |||
|
257 | m_themeColors.move(0, m_themeColors.size() - 1); | |||
|
258 | return nextColor; | |||
225 | } |
|
259 | } | |
226 |
|
260 | |||
227 | void QChart::zoomInToRect(const QRect& rectangle) |
|
261 | void QChart::zoomInToRect(const QRect& rectangle) | |
228 | { |
|
262 | { | |
229 |
|
263 | |||
230 | if(!rectangle.isValid()) return; |
|
264 | if(!rectangle.isValid()) return; | |
231 |
|
265 | |||
232 | qreal margin = this->margin(); |
|
266 | qreal margin = this->margin(); | |
233 |
|
267 | |||
234 | QRect rect = rectangle.normalized(); |
|
268 | QRect rect = rectangle.normalized(); | |
235 | rect.translate(-margin, -margin); |
|
269 | rect.translate(-margin, -margin); | |
236 |
|
270 | |||
237 | PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex]; |
|
271 | PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex]; | |
238 | PlotDomain newDomain; |
|
272 | PlotDomain newDomain; | |
239 |
|
273 | |||
240 | qreal dx = oldDomain.spanX() / (m_rect.width() - 2 * margin); |
|
274 | qreal dx = oldDomain.spanX() / (m_rect.width() - 2 * margin); | |
241 | qreal dy = oldDomain.spanY() / (m_rect.height() - 2 * margin); |
|
275 | qreal dy = oldDomain.spanY() / (m_rect.height() - 2 * margin); | |
242 |
|
276 | |||
243 | newDomain.m_minX = oldDomain.m_minX + dx * rect.left(); |
|
277 | newDomain.m_minX = oldDomain.m_minX + dx * rect.left(); | |
244 | newDomain.m_maxX = oldDomain.m_minX + dx * rect.right(); |
|
278 | newDomain.m_maxX = oldDomain.m_minX + dx * rect.right(); | |
245 | newDomain.m_minY = oldDomain.m_maxY - dy * rect.bottom(); |
|
279 | newDomain.m_minY = oldDomain.m_maxY - dy * rect.bottom(); | |
246 | newDomain.m_maxY = oldDomain.m_maxY - dy * rect.top(); |
|
280 | newDomain.m_maxY = oldDomain.m_maxY - dy * rect.top(); | |
247 |
|
281 | |||
248 | m_plotDomainList.resize(m_plotDataIndex + 1); |
|
282 | m_plotDomainList.resize(m_plotDataIndex + 1); | |
249 | m_plotDomainList<<newDomain; |
|
283 | m_plotDomainList<<newDomain; | |
250 | m_plotDataIndex++; |
|
284 | m_plotDataIndex++; | |
251 |
|
285 | |||
252 | foreach (ChartItem* item ,m_chartItems) |
|
286 | foreach (ChartItem* item ,m_chartItems) | |
253 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
287 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
254 | update(); |
|
288 | update(); | |
255 | } |
|
289 | } | |
256 |
|
290 | |||
257 | void QChart::zoomIn() |
|
291 | void QChart::zoomIn() | |
258 | { |
|
292 | { | |
259 | if (m_plotDataIndex < m_plotDomainList.count() - 1) { |
|
293 | if (m_plotDataIndex < m_plotDomainList.count() - 1) { | |
260 | m_plotDataIndex++; |
|
294 | m_plotDataIndex++; | |
261 | foreach (ChartItem* item ,m_chartItems) |
|
295 | foreach (ChartItem* item ,m_chartItems) | |
262 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
296 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
263 | update(); |
|
297 | update(); | |
264 | }else{ |
|
298 | }else{ | |
265 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
299 | QRect rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
266 | rect.setWidth(rect.width()/2); |
|
300 | rect.setWidth(rect.width()/2); | |
267 | rect.setHeight(rect.height()/2); |
|
301 | rect.setHeight(rect.height()/2); | |
268 | rect.moveCenter(m_rect.center()); |
|
302 | rect.moveCenter(m_rect.center()); | |
269 | zoomInToRect(rect); |
|
303 | zoomInToRect(rect); | |
270 | } |
|
304 | } | |
271 | } |
|
305 | } | |
272 |
|
306 | |||
273 | void QChart::zoomOut() |
|
307 | void QChart::zoomOut() | |
274 | { |
|
308 | { | |
275 | if (m_plotDataIndex > 0) { |
|
309 | if (m_plotDataIndex > 0) { | |
276 | m_plotDataIndex--; |
|
310 | m_plotDataIndex--; | |
277 | foreach (ChartItem* item ,m_chartItems) |
|
311 | foreach (ChartItem* item ,m_chartItems) | |
278 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); |
|
312 | item->setPlotDomain(m_plotDomainList[m_plotDataIndex]); | |
279 | update(); |
|
313 | update(); | |
280 | } |
|
314 | } | |
281 | } |
|
315 | } | |
282 |
|
316 | |||
283 | #include "moc_qchart.cpp" |
|
317 | #include "moc_qchart.cpp" | |
284 |
|
318 | |||
285 | QTCOMMERCIALCHART_END_NAMESPACE |
|
319 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,91 +1,91 | |||||
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 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class AxisItem; |
|
11 | class AxisItem; | |
12 | class QChartSeries; |
|
12 | class QChartSeries; | |
13 | class PlotDomain; |
|
13 | class PlotDomain; | |
14 | class ChartItem; |
|
14 | class ChartItem; | |
15 | class BarGroup; |
|
15 | class BarGroup; | |
16 | class QChartAxis; |
|
16 | class QChartAxis; | |
17 |
|
17 | |||
18 | // TODO: We don't need to have QChart tied to QGraphicsItem: |
|
18 | // TODO: We don't need to have QChart tied to QGraphicsItem: | |
19 | //class QTCOMMERCIALCHART_EXPORT QChart |
|
19 | //class QTCOMMERCIALCHART_EXPORT QChart | |
20 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { |
|
20 | //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem { | |
21 | // public: QChartGraphicsItem(QChart &chart); |
|
21 | // public: QChartGraphicsItem(QChart &chart); | |
22 |
|
22 | |||
23 | /*! |
|
23 | /*! | |
24 | * TODO: define the responsibilities |
|
24 | * TODO: define the responsibilities | |
25 | */ |
|
25 | */ | |
26 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsObject |
|
26 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsObject | |
27 | { |
|
27 | { | |
28 | Q_OBJECT |
|
28 | Q_OBJECT | |
29 | public: |
|
29 | public: | |
30 | enum ChartTheme { |
|
30 | enum ChartThemeId { | |
31 | ChartThemeVanilla = 0, |
|
31 | ChartThemeVanilla = 0, | |
32 | ChartThemeIcy, |
|
32 | ChartThemeIcy, | |
33 | ChartThemeGrayscale |
|
33 | ChartThemeGrayscale | |
34 | }; |
|
34 | }; | |
35 |
|
35 | |||
36 | public: |
|
36 | public: | |
37 | QChart(QGraphicsObject* parent = 0); |
|
37 | QChart(QGraphicsObject* parent = 0); | |
38 | ~QChart(); |
|
38 | ~QChart(); | |
39 |
|
39 | |||
40 | //from QGraphicsItem |
|
40 | //from QGraphicsItem | |
41 | QRectF boundingRect() const; |
|
41 | QRectF boundingRect() const; | |
42 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){}; |
|
42 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){}; | |
43 |
|
43 | |||
44 | void addSeries(QChartSeries* series); |
|
44 | void addSeries(QChartSeries* series); | |
45 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); |
|
45 | //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type); | |
46 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... |
|
46 | // TODO: who owns the series now? maybe owned by chart and returned a reference instead... | |
47 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
47 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
48 |
|
48 | |||
49 | void setSize(const QSize& size); |
|
49 | void setSize(const QSize& size); | |
50 | void setMargin(int margin); |
|
50 | void setMargin(int margin); | |
51 | int margin() const; |
|
51 | int margin() const; | |
52 | void setTheme(QChart::ChartTheme theme); |
|
52 | void setTheme(QChart::ChartThemeId theme); | |
53 |
|
53 | |||
54 | void setTitle(const QString& title); |
|
54 | void setTitle(const QString& title); | |
55 | void setBackgroundColor(const QColor& color); |
|
55 | void setBackgroundColor(const QColor& color); | |
56 |
|
56 | |||
57 | void zoomInToRect(const QRect& rectangle); |
|
57 | void zoomInToRect(const QRect& rectangle); | |
58 | void zoomIn(); |
|
58 | void zoomIn(); | |
59 | void zoomOut(); |
|
59 | void zoomOut(); | |
60 |
|
60 | |||
61 | void setAxisX(QChartAxis* axis){}; |
|
61 | void setAxisX(QChartAxis* axis){}; | |
62 | void setAxisY(QChartAxis* axis){}; |
|
62 | void setAxisY(QChartAxis* axis){}; | |
63 | void setAxisY(QList<QChartAxis*> axis){}; |
|
63 | void setAxisY(QList<QChartAxis*> axis){}; | |
64 |
|
64 | |||
65 |
|
65 | |||
66 | signals: |
|
66 | signals: | |
67 | //TODO chage to const QSize& size |
|
67 | //TODO chage to const QSize& size | |
68 | void sizeChanged(QRectF rect); |
|
68 | void sizeChanged(QRectF rect); | |
69 | void scaleChanged(qreal xscale, qreal yscale); |
|
69 | void scaleChanged(qreal xscale, qreal yscale); | |
70 |
|
70 | |||
71 | private: |
|
71 | private: | |
|
72 | QColor nextColor(); | |||
|
73 | ||||
72 | Q_DISABLE_COPY(QChart) |
|
74 | Q_DISABLE_COPY(QChart) | |
73 | QGraphicsRectItem* m_background; |
|
75 | QGraphicsRectItem* m_background; | |
74 | QLinearGradient m_backgroundGradient; |
|
76 | QLinearGradient m_backgroundGradient; | |
75 | QGraphicsTextItem* m_title; |
|
77 | QGraphicsTextItem* m_title; | |
76 | AxisItem* m_axisX; |
|
78 | AxisItem* m_axisX; | |
77 | AxisItem* m_axisY; |
|
79 | AxisItem* m_axisY; | |
78 | QRect m_rect; |
|
80 | QRect m_rect; | |
79 |
QList< |
|
81 | QList<QChartSeries*> m_chartSeries; | |
80 | QVector<PlotDomain> m_plotDomainList; |
|
82 | QVector<PlotDomain> m_plotDomainList; | |
81 | QList<ChartItem*> m_chartItems; |
|
83 | QList<ChartItem*> m_chartItems; | |
82 | //TODO: remove |
|
|||
83 | QList<QGraphicsItem*> m_items; |
|
|||
84 | int m_plotDataIndex; |
|
84 | int m_plotDataIndex; | |
85 | int m_marginSize; |
|
85 | int m_marginSize; | |
86 | QList<QColor> m_themeColors; |
|
86 | QList<QColor> m_themeColors; | |
87 | }; |
|
87 | }; | |
88 |
|
88 | |||
89 | QTCOMMERCIALCHART_END_NAMESPACE |
|
89 | QTCOMMERCIALCHART_END_NAMESPACE | |
90 |
|
90 | |||
91 | #endif |
|
91 | #endif |
@@ -1,57 +1,57 | |||||
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(QChartSeries::QChartSeriesType type) |
|
45 | QChartSeries* QChartWidget::createSeries(QChartSeries::QChartSeriesType type) | |
46 | { |
|
46 | { | |
47 | return m_chart->createSeries(type); |
|
47 | return m_chart->createSeries(type); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | void QChartWidget::setTheme(QChart::ChartTheme theme) |
|
50 | void QChartWidget::setTheme(QChart::ChartThemeId theme) | |
51 | { |
|
51 | { | |
52 | m_chart->setTheme(theme); |
|
52 | m_chart->setTheme(theme); | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | #include "moc_qchartwidget.cpp" |
|
55 | #include "moc_qchartwidget.cpp" | |
56 |
|
56 | |||
57 | QTCOMMERCIALCHART_END_NAMESPACE |
|
57 | 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 "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(QChartSeries::QChartSeriesType type); |
|
29 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); | |
30 |
|
30 | |||
31 | /*! |
|
31 | /*! | |
32 | * Set color theme for the chart. Themes define harmonic colors for the graphical elements of |
|
32 | * Set color theme for the chart. Themes define harmonic colors for the graphical elements of | |
33 | * the chart. |
|
33 | * the chart. | |
34 | */ |
|
34 | */ | |
35 | void setTheme(QChart::ChartTheme theme); |
|
35 | void setTheme(QChart::ChartThemeId theme); | |
36 |
|
36 | |||
37 | private: |
|
37 | private: | |
38 | Q_DISABLE_COPY(QChartWidget) |
|
38 | Q_DISABLE_COPY(QChartWidget) | |
39 | QGraphicsScene *m_scene; |
|
39 | QGraphicsScene *m_scene; | |
40 | QChart* m_chart; |
|
40 | QChart* m_chart; | |
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,97 +1,106 | |||||
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(QGraphicsObject *parent) : |
|
8 | QPieSeries::QPieSeries(QGraphicsObject *parent) : | |
9 | QChartSeries(parent), |
|
9 | QChartSeries(parent), | |
10 | m_sizeFactor(1.0) |
|
10 | m_sizeFactor(1.0) | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
14 | QPieSeries::~QPieSeries() |
|
14 | QPieSeries::~QPieSeries() | |
15 | { |
|
15 | { | |
16 | while (m_slices.count()) |
|
16 | while (m_slices.count()) | |
17 | delete m_slices.takeLast(); |
|
17 | delete m_slices.takeLast(); | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 | bool QPieSeries::setData(QList<qreal> data) |
|
20 | bool QPieSeries::setData(QList<qreal> data) | |
21 | { |
|
21 | { | |
22 | m_data = data; |
|
22 | m_data = data; | |
23 |
|
23 | |||
24 | // Create slices |
|
24 | // Create slices | |
25 | qreal fullPie = 360; |
|
25 | qreal fullPie = 360; | |
26 | qreal total = 0; |
|
26 | qreal total = 0; | |
27 | foreach (qreal value, m_data) |
|
27 | foreach (qreal value, m_data) | |
28 | total += value; |
|
28 | total += value; | |
29 |
|
29 | |||
30 | QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent()); |
|
30 | QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent()); | |
31 | Q_ASSERT(parentItem); |
|
31 | Q_ASSERT(parentItem); | |
32 | m_chartSize = parentItem->boundingRect(); |
|
32 | m_chartSize = parentItem->boundingRect(); | |
33 | qreal angle = 0; |
|
33 | qreal angle = 0; | |
34 | // 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 | |
35 | foreach (qreal value, m_data) { |
|
35 | foreach (qreal value, m_data) { | |
36 | qreal span = value / total * fullPie; |
|
36 | qreal span = value / total * fullPie; | |
37 |
PieSlice *slice = new PieSlice( |
|
37 | PieSlice *slice = new PieSlice(QColor(), angle, span, parentItem->boundingRect()); | |
38 | slice->setParentItem(parentItem); |
|
38 | slice->setParentItem(parentItem); | |
39 | m_slices.append(slice); |
|
39 | m_slices.append(slice); | |
40 | angle += span; |
|
40 | angle += span; | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | resizeSlices(m_chartSize); |
|
43 | resizeSlices(m_chartSize); | |
44 | return true; |
|
44 | return true; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
|
47 | void QPieSeries::setSliceColor(int index, QColor color) | |||
|
48 | { | |||
|
49 | if (index >= 0 && index < m_slices.count()) | |||
|
50 | m_slices.at(index)->m_color = color; | |||
|
51 | } | |||
|
52 | ||||
|
53 | QColor QPieSeries::sliceColor(int index) | |||
|
54 | { | |||
|
55 | if (index >= 0 && index < m_slices.count()) | |||
|
56 | return m_slices.at(index)->m_color; | |||
|
57 | else | |||
|
58 | return QColor(); | |||
|
59 | } | |||
|
60 | ||||
|
61 | int QPieSeries::sliceCount() | |||
|
62 | { | |||
|
63 | return m_slices.count(); | |||
|
64 | } | |||
|
65 | ||||
47 | void QPieSeries::chartSizeChanged(QRectF chartRect) |
|
66 | void QPieSeries::chartSizeChanged(QRectF chartRect) | |
48 | { |
|
67 | { | |
49 | // TODO: allow user setting the size? |
|
68 | // TODO: allow user setting the size? | |
50 | // TODO: allow user defining the margins? |
|
69 | // TODO: allow user defining the margins? | |
51 | m_chartSize = chartRect; |
|
70 | m_chartSize = chartRect; | |
52 | resizeSlices(m_chartSize); |
|
71 | resizeSlices(m_chartSize); | |
53 | } |
|
72 | } | |
54 |
|
73 | |||
55 | void QPieSeries::resizeSlices(QRectF rect) |
|
74 | void QPieSeries::resizeSlices(QRectF rect) | |
56 | { |
|
75 | { | |
57 | QRectF tempRect = rect; |
|
76 | QRectF tempRect = rect; | |
58 | if (tempRect.width() < tempRect.height()) { |
|
77 | if (tempRect.width() < tempRect.height()) { | |
59 | tempRect.setWidth(tempRect.width() * m_sizeFactor); |
|
78 | tempRect.setWidth(tempRect.width() * m_sizeFactor); | |
60 | tempRect.setHeight(tempRect.width()); |
|
79 | tempRect.setHeight(tempRect.width()); | |
61 | tempRect.moveCenter(rect.center()); |
|
80 | tempRect.moveCenter(rect.center()); | |
62 | } else { |
|
81 | } else { | |
63 | tempRect.setHeight(tempRect.height() * m_sizeFactor); |
|
82 | tempRect.setHeight(tempRect.height() * m_sizeFactor); | |
64 | tempRect.setWidth(tempRect.height()); |
|
83 | tempRect.setWidth(tempRect.height()); | |
65 | tempRect.moveCenter(rect.center()); |
|
84 | tempRect.moveCenter(rect.center()); | |
66 | } |
|
85 | } | |
67 |
|
86 | |||
68 | foreach (PieSlice *slice, m_slices) |
|
87 | foreach (PieSlice *slice, m_slices) | |
69 | slice->m_rect = tempRect; |
|
88 | slice->m_rect = tempRect; | |
70 | } |
|
89 | } | |
71 |
|
90 | |||
72 | void QPieSeries::setSizeFactor(qreal factor) |
|
91 | void QPieSeries::setSizeFactor(qreal factor) | |
73 | { |
|
92 | { | |
74 | if (factor > 0.0) |
|
93 | if (factor > 0.0) | |
75 | m_sizeFactor = factor; |
|
94 | m_sizeFactor = factor; | |
76 | resizeSlices(m_chartSize); |
|
95 | resizeSlices(m_chartSize); | |
77 |
|
96 | |||
78 | // Initiate update via the parent graphics item |
|
97 | // Initiate update via the parent graphics item | |
79 | // TODO: potential issue: what if this function is called from the parent context? |
|
98 | // TODO: potential issue: what if this function is called from the parent context? | |
80 | QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent()); |
|
99 | QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent()); | |
81 | Q_ASSERT(parentItem); |
|
100 | Q_ASSERT(parentItem); | |
82 | parentItem->update(); |
|
101 | parentItem->update(); | |
83 | } |
|
102 | } | |
84 |
|
103 | |||
85 | QColor QPieSeries::randomColor() |
|
|||
86 | { |
|
|||
87 | QColor c; |
|
|||
88 | c.setRed(qrand() % 255); |
|
|||
89 | c.setGreen(qrand() % 255); |
|
|||
90 | c.setBlue(qrand() % 255); |
|
|||
91 | return c; |
|
|||
92 | } |
|
|||
93 |
|
||||
94 |
|
||||
95 | #include "moc_qpieseries.cpp" |
|
104 | #include "moc_qpieseries.cpp" | |
96 |
|
105 | |||
97 | QTCOMMERCIALCHART_END_NAMESPACE |
|
106 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,45 +1,50 | |||||
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(QGraphicsObject *parent = 0); |
|
19 | QPieSeries(QGraphicsObject *parent = 0); | |
20 | ~QPieSeries(); |
|
20 | ~QPieSeries(); | |
21 | QColor randomColor(); |
|
|||
22 | void setSizeFactor(qreal sizeFactor); |
|
21 | void setSizeFactor(qreal sizeFactor); | |
23 | qreal sizeFactor() { return m_sizeFactor; } |
|
22 | qreal sizeFactor() { return m_sizeFactor; } | |
24 |
|
23 | |||
25 | public: // from QChartSeries |
|
24 | public: // from QChartSeries | |
26 | QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } |
|
25 | QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } | |
27 | bool setData(QList<qreal> data); |
|
26 | bool setData(QList<qreal> data); | |
28 |
|
27 | |||
|
28 | public: | |||
|
29 | void setSliceColor(int index, QColor color); | |||
|
30 | QColor sliceColor(int index); | |||
|
31 | int sliceCount(); | |||
|
32 | ||||
29 | public Q_SLOTS: |
|
33 | public Q_SLOTS: | |
30 | void chartSizeChanged(QRectF rect); |
|
34 | void chartSizeChanged(QRectF rect); | |
31 |
|
35 | |||
32 | private: |
|
36 | private: | |
33 | void resizeSlices(QRectF rect); |
|
37 | void resizeSlices(QRectF rect); | |
34 | //Q_DECLARE_PRIVATE(QPieSeries) |
|
38 | //Q_DECLARE_PRIVATE(QPieSeries) | |
35 | Q_DISABLE_COPY(QPieSeries) |
|
39 | Q_DISABLE_COPY(QPieSeries) | |
|
40 | friend class QChart; | |||
36 | // TODO: move the followin to internal impl |
|
41 | // TODO: move the followin to internal impl | |
37 | QList<qreal> m_data; |
|
42 | QList<qreal> m_data; | |
38 | QList<PieSlice*> m_slices; |
|
43 | QList<PieSlice*> m_slices; | |
39 | QRectF m_chartSize; |
|
44 | QRectF m_chartSize; | |
40 | qreal m_sizeFactor; |
|
45 | qreal m_sizeFactor; | |
41 | }; |
|
46 | }; | |
42 |
|
47 | |||
43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
48 | QTCOMMERCIALCHART_END_NAMESPACE | |
44 |
|
49 | |||
45 | #endif // PIESERIES_H |
|
50 | #endif // PIESERIES_H |
@@ -1,103 +1,108 | |||||
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 | QGraphicsItem(parent), |
|
13 | QGraphicsItem(parent), | |
14 | 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) | |
15 | m_scaley(100), |
|
15 | m_scaley(100), | |
16 | m_markerColor(QColor()) |
|
16 | m_markerColor(QColor()) | |
17 | { |
|
17 | { | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 | void QScatterSeriesPrivate::resize(QRectF rect) |
|
20 | void QScatterSeriesPrivate::resize(QRectF rect) | |
21 | { |
|
21 | { | |
22 | m_scenex.clear(); |
|
22 | m_scenex.clear(); | |
23 | m_sceney.clear(); |
|
23 | m_sceney.clear(); | |
24 |
|
24 | |||
25 | foreach(qreal x, m_x) |
|
25 | foreach(qreal x, m_x) | |
26 | m_scenex.append(rect.left() + x * (rect.width() / m_scalex)); |
|
26 | m_scenex.append(rect.left() + x * (rect.width() / m_scalex)); | |
27 |
|
27 | |||
28 | foreach(qreal y, m_y) |
|
28 | foreach(qreal y, m_y) | |
29 | m_sceney.append(rect.bottom() - y * (rect.height() / m_scaley)); |
|
29 | m_sceney.append(rect.bottom() - y * (rect.height() / m_scaley)); | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | // TODO: |
|
32 | // TODO: | |
33 | //void QScatterSeriesPrivate::setAxisScale(qreal xscale, qreal yscale) |
|
33 | //void QScatterSeriesPrivate::setAxisScale(qreal xscale, qreal yscale) | |
34 |
|
34 | |||
35 | QRectF QScatterSeriesPrivate::boundingRect() const |
|
35 | QRectF QScatterSeriesPrivate::boundingRect() const | |
36 | { |
|
36 | { | |
37 | return QRectF(0, 0, 55, 100); |
|
37 | return QRectF(0, 0, 55, 100); | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
40 | void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
41 | { |
|
41 | { | |
42 | QPen pen = painter->pen(); |
|
42 | QPen pen = painter->pen(); | |
43 | QBrush brush = pen.brush(); |
|
43 | QBrush brush = pen.brush(); | |
44 | // TODO: The opacity should be user definable... |
|
44 | // TODO: The opacity should be user definable... | |
45 | //brush.setColor(QColor(255, 82, 0, 100)); |
|
45 | //brush.setColor(QColor(255, 82, 0, 100)); | |
46 | brush.setColor(m_markerColor); |
|
46 | brush.setColor(m_markerColor); | |
47 | pen.setBrush(brush); |
|
47 | pen.setBrush(brush); | |
48 | pen.setWidth(4); |
|
48 | pen.setWidth(4); | |
49 | painter->setPen(pen); |
|
49 | painter->setPen(pen); | |
50 |
|
50 | |||
51 | // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize |
|
51 | // TODO: m_scenex and m_sceny are left empty during construction -> we would need a resize | |
52 | // event right after construction or maybe given a size during initialization |
|
52 | // event right after construction or maybe given a size during initialization | |
53 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { |
|
53 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { | |
54 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) |
|
54 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) | |
55 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); |
|
55 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); | |
56 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); |
|
56 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); | |
57 | } |
|
57 | } | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | QScatterSeries::QScatterSeries(QObject *parent) : |
|
60 | QScatterSeries::QScatterSeries(QObject *parent) : | |
61 | QChartSeries(parent), |
|
61 | QChartSeries(parent), | |
62 | d(new QScatterSeriesPrivate(qobject_cast<QGraphicsItem *> (parent))) |
|
62 | d(new QScatterSeriesPrivate(qobject_cast<QGraphicsItem *> (parent))) | |
63 | { |
|
63 | { | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | bool QScatterSeries::setData(QList<qreal> x, QList<qreal> y) |
|
66 | bool QScatterSeries::setData(QList<qreal> x, QList<qreal> y) | |
67 | { |
|
67 | { | |
68 | // TODO: validate data |
|
68 | // TODO: validate data | |
69 | d->m_x = x; |
|
69 | d->m_x = x; | |
70 | d->m_y = y; |
|
70 | d->m_y = y; | |
71 | QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent()); |
|
71 | QGraphicsItem *parentItem = qobject_cast<QGraphicsItem *>(parent()); | |
72 | Q_ASSERT(parentItem); |
|
72 | Q_ASSERT(parentItem); | |
73 | d->resize(parentItem->boundingRect()); |
|
73 | d->resize(parentItem->boundingRect()); | |
74 | return true; |
|
74 | return true; | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void QScatterSeries::chartSizeChanged(QRectF rect) |
|
77 | void QScatterSeries::chartSizeChanged(QRectF rect) | |
78 | { |
|
78 | { | |
79 | // Recalculate scatter data point locations on the scene |
|
79 | // Recalculate scatter data point locations on the scene | |
80 | // d->transform().reset(); |
|
80 | // d->transform().reset(); | |
81 | // d->transform().translate(); |
|
81 | // d->transform().translate(); | |
82 | d->resize(rect); |
|
82 | d->resize(rect); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | void QScatterSeries::setMarkerColor(QColor color) |
|
85 | void QScatterSeries::setMarkerColor(QColor color) | |
86 | { |
|
86 | { | |
87 | d->m_markerColor = color; |
|
87 | d->m_markerColor = color; | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
|
90 | QColor QScatterSeries::markerColor() | |||
|
91 | { | |||
|
92 | return d->m_markerColor; | |||
|
93 | } | |||
|
94 | ||||
90 | // TODO: |
|
95 | // TODO: | |
91 | //void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale) |
|
96 | //void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale) | |
92 | //{ |
|
97 | //{ | |
93 | // d->rescale(xscale, yscale); |
|
98 | // d->rescale(xscale, yscale); | |
94 | //} |
|
99 | //} | |
95 |
|
100 | |||
96 | QScatterSeries::~QScatterSeries() |
|
101 | QScatterSeries::~QScatterSeries() | |
97 | { |
|
102 | { | |
98 | delete d; |
|
103 | delete d; | |
99 | } |
|
104 | } | |
100 |
|
105 | |||
101 | #include "moc_qscatterseries.cpp" |
|
106 | #include "moc_qscatterseries.cpp" | |
102 |
|
107 | |||
103 | QTCOMMERCIALCHART_END_NAMESPACE |
|
108 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,37 +1,38 | |||||
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 | #include <QColor> |
|
6 | #include <QColor> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 | class QScatterSeriesPrivate; |
|
9 | class QScatterSeriesPrivate; | |
10 |
|
10 | |||
11 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries |
|
11 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries | |
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
14 | public: |
|
14 | public: | |
15 | //QScatterSeries(QSeriesData *data, QObject *chart); |
|
15 | //QScatterSeries(QSeriesData *data, QObject *chart); | |
16 | QScatterSeries(QObject *parent = 0); |
|
16 | QScatterSeries(QObject *parent = 0); | |
17 | ~QScatterSeries(); |
|
17 | ~QScatterSeries(); | |
18 |
|
18 | |||
19 | public: // from QChartSeries |
|
19 | public: // from QChartSeries | |
20 | QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } |
|
20 | QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } | |
21 | bool setData(QList<qreal> x, QList<qreal> y); |
|
21 | bool setData(QList<qreal> x, QList<qreal> y); | |
22 |
|
22 | |||
23 | public Q_SLOTS: |
|
23 | public Q_SLOTS: | |
24 | void chartSizeChanged(QRectF rect); |
|
24 | void chartSizeChanged(QRectF rect); | |
25 | void setMarkerColor(QColor color); |
|
25 | void setMarkerColor(QColor color); | |
|
26 | QColor markerColor(); | |||
26 | //void chartScaleChanged(qreal xscale, qreal yscale); |
|
27 | //void chartScaleChanged(qreal xscale, qreal yscale); | |
27 |
|
28 | |||
28 | private: |
|
29 | private: | |
29 | Q_DECLARE_PRIVATE(QScatterSeries) |
|
30 | Q_DECLARE_PRIVATE(QScatterSeries) | |
30 | Q_DISABLE_COPY(QScatterSeries) |
|
31 | Q_DISABLE_COPY(QScatterSeries) | |
31 | friend class QChart; |
|
32 | friend class QChart; | |
32 | QScatterSeriesPrivate *const d; |
|
33 | QScatterSeriesPrivate *const d; | |
33 | }; |
|
34 | }; | |
34 |
|
35 | |||
35 | QTCOMMERCIALCHART_END_NAMESPACE |
|
36 | QTCOMMERCIALCHART_END_NAMESPACE | |
36 |
|
37 | |||
37 | #endif // QSCATTERSERIES_H |
|
38 | #endif // QSCATTERSERIES_H |
@@ -1,34 +1,35 | |||||
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(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 | public: | |||
22 | // TODO: use the chart data class instead of list of x and y values? |
|
23 | // TODO: use the chart data class instead of list of x and y values? | |
23 | QList<qreal> m_x; |
|
24 | QList<qreal> m_x; | |
24 | QList<qreal> m_y; |
|
25 | QList<qreal> m_y; | |
25 | qreal m_scalex; |
|
26 | qreal m_scalex; | |
26 | qreal m_scaley; |
|
27 | qreal m_scaley; | |
27 | QList<qreal> m_scenex; |
|
28 | QList<qreal> m_scenex; | |
28 | QList<qreal> m_sceney; |
|
29 | QList<qreal> m_sceney; | |
29 | QColor m_markerColor; |
|
30 | QColor m_markerColor; | |
30 | }; |
|
31 | }; | |
31 |
|
32 | |||
32 | QTCOMMERCIALCHART_END_NAMESPACE |
|
33 | QTCOMMERCIALCHART_END_NAMESPACE | |
33 |
|
34 | |||
34 | #endif // QSCATTERSERIES_H |
|
35 | #endif // QSCATTERSERIES_H |
@@ -1,314 +1,314 | |||||
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 |
|
18 | |||
19 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
19 | QTCOMMERCIALCHART_USE_NAMESPACE | |
20 |
|
20 | |||
21 | MainWidget::MainWidget(QWidget *parent) : |
|
21 | MainWidget::MainWidget(QWidget *parent) : | |
22 | QWidget(parent) |
|
22 | QWidget(parent) | |
23 | { |
|
23 | { | |
24 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
24 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
25 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
25 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
26 |
|
26 | |||
27 | // Chart background |
|
27 | // Chart background | |
28 | QComboBox *backgroundCombo = new QComboBox(this); |
|
28 | QComboBox *backgroundCombo = new QComboBox(this); | |
29 | backgroundCombo->addItem("None"); |
|
29 | backgroundCombo->addItem("None"); | |
30 | backgroundCombo->addItem("TODO Grid"); |
|
30 | backgroundCombo->addItem("TODO Grid"); | |
31 | backgroundCombo->addItem("TODO Image"); |
|
31 | backgroundCombo->addItem("TODO Image"); | |
32 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
32 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
33 | this, SLOT(backgroundChanged(int))); |
|
33 | this, SLOT(backgroundChanged(int))); | |
34 |
|
34 | |||
35 | // Axis |
|
35 | // Axis | |
36 | // TODO: multiple axes? |
|
36 | // TODO: multiple axes? | |
37 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
37 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
38 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
38 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
39 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
39 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
40 | m_xMinSpin = new QSpinBox(); |
|
40 | m_xMinSpin = new QSpinBox(); | |
41 | m_xMinSpin->setMinimum(INT_MIN); |
|
41 | m_xMinSpin->setMinimum(INT_MIN); | |
42 | m_xMinSpin->setMaximum(INT_MAX); |
|
42 | m_xMinSpin->setMaximum(INT_MAX); | |
43 | m_xMinSpin->setValue(0); |
|
43 | m_xMinSpin->setValue(0); | |
44 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
44 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
45 | m_xMaxSpin = new QSpinBox(); |
|
45 | m_xMaxSpin = new QSpinBox(); | |
46 | m_xMaxSpin->setMinimum(INT_MIN); |
|
46 | m_xMaxSpin->setMinimum(INT_MIN); | |
47 | m_xMaxSpin->setMaximum(INT_MAX); |
|
47 | m_xMaxSpin->setMaximum(INT_MAX); | |
48 | m_xMaxSpin->setValue(10); |
|
48 | m_xMaxSpin->setValue(10); | |
49 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
49 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
50 | m_yMinSpin = new QSpinBox(); |
|
50 | m_yMinSpin = new QSpinBox(); | |
51 | m_yMinSpin->setMinimum(INT_MIN); |
|
51 | m_yMinSpin->setMinimum(INT_MIN); | |
52 | m_yMinSpin->setMaximum(INT_MAX); |
|
52 | m_yMinSpin->setMaximum(INT_MAX); | |
53 | m_yMinSpin->setValue(0); |
|
53 | m_yMinSpin->setValue(0); | |
54 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
54 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
55 | m_yMaxSpin = new QSpinBox(); |
|
55 | m_yMaxSpin = new QSpinBox(); | |
56 | m_yMaxSpin->setMinimum(INT_MIN); |
|
56 | m_yMaxSpin->setMinimum(INT_MIN); | |
57 | m_yMaxSpin->setMaximum(INT_MAX); |
|
57 | m_yMaxSpin->setMaximum(INT_MAX); | |
58 | m_yMaxSpin->setValue(10); |
|
58 | m_yMaxSpin->setValue(10); | |
59 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
59 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
60 |
|
60 | |||
61 | QComboBox *chartTheme = new QComboBox(); |
|
61 | QComboBox *chartTheme = new QComboBox(); | |
62 | chartTheme->addItem("Vanilla"); |
|
62 | chartTheme->addItem("Vanilla"); | |
63 | chartTheme->addItem("Icy"); |
|
63 | chartTheme->addItem("Icy"); | |
64 | chartTheme->addItem("Grayscale"); |
|
64 | chartTheme->addItem("Grayscale"); | |
65 | chartTheme->addItem("Tobedefined"); |
|
65 | chartTheme->addItem("Tobedefined"); | |
66 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
66 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
67 | this, SLOT(changeChartTheme(int))); |
|
67 | this, SLOT(changeChartTheme(int))); | |
68 |
|
68 | |||
69 | QGridLayout *grid = new QGridLayout(); |
|
69 | QGridLayout *grid = new QGridLayout(); | |
70 | QGridLayout *mainLayout = new QGridLayout(); |
|
70 | QGridLayout *mainLayout = new QGridLayout(); | |
71 | //grid->addWidget(new QLabel("Add series:"), 0, 0); |
|
71 | //grid->addWidget(new QLabel("Add series:"), 0, 0); | |
72 | grid->addWidget(addSeriesButton, 0, 1); |
|
72 | grid->addWidget(addSeriesButton, 0, 1); | |
73 | grid->addWidget(new QLabel("Background:"), 2, 0); |
|
73 | grid->addWidget(new QLabel("Background:"), 2, 0); | |
74 | grid->addWidget(backgroundCombo, 2, 1); |
|
74 | grid->addWidget(backgroundCombo, 2, 1); | |
75 | grid->addWidget(m_autoScaleCheck, 3, 0); |
|
75 | grid->addWidget(m_autoScaleCheck, 3, 0); | |
76 | grid->addWidget(new QLabel("x min:"), 4, 0); |
|
76 | grid->addWidget(new QLabel("x min:"), 4, 0); | |
77 | grid->addWidget(m_xMinSpin, 4, 1); |
|
77 | grid->addWidget(m_xMinSpin, 4, 1); | |
78 | grid->addWidget(new QLabel("x max:"), 5, 0); |
|
78 | grid->addWidget(new QLabel("x max:"), 5, 0); | |
79 | grid->addWidget(m_xMaxSpin, 5, 1); |
|
79 | grid->addWidget(m_xMaxSpin, 5, 1); | |
80 | grid->addWidget(new QLabel("y min:"), 6, 0); |
|
80 | grid->addWidget(new QLabel("y min:"), 6, 0); | |
81 | grid->addWidget(m_yMinSpin, 6, 1); |
|
81 | grid->addWidget(m_yMinSpin, 6, 1); | |
82 | grid->addWidget(new QLabel("y max:"), 7, 0); |
|
82 | grid->addWidget(new QLabel("y max:"), 7, 0); | |
83 | grid->addWidget(m_yMaxSpin, 7, 1); |
|
83 | grid->addWidget(m_yMaxSpin, 7, 1); | |
84 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
84 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
85 | grid->addWidget(chartTheme, 8, 1); |
|
85 | grid->addWidget(chartTheme, 8, 1); | |
86 | // add row with empty label to make all the other rows static |
|
86 | // add row with empty label to make all the other rows static | |
87 | grid->addWidget(new QLabel(""), 9, 0); |
|
87 | grid->addWidget(new QLabel(""), 9, 0); | |
88 | grid->setRowStretch(9, 1); |
|
88 | grid->setRowStretch(9, 1); | |
89 |
|
89 | |||
90 | mainLayout->addLayout(grid, 0, 0); |
|
90 | mainLayout->addLayout(grid, 0, 0); | |
91 |
|
91 | |||
92 | // Scatter specific settings |
|
92 | // Scatter specific settings | |
93 | m_scatterLayout = new QGridLayout(); |
|
93 | m_scatterLayout = new QGridLayout(); | |
94 | m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); |
|
94 | m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); | |
95 | m_scatterLayout->setEnabled(false); |
|
95 | m_scatterLayout->setEnabled(false); | |
96 |
|
96 | |||
97 | // Pie specific settings |
|
97 | // Pie specific settings | |
98 | m_pieLayout = new QGridLayout(); |
|
98 | m_pieLayout = new QGridLayout(); | |
99 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); |
|
99 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); | |
100 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); |
|
100 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); | |
101 | pieSizeSpin->setMinimum(LONG_MIN); |
|
101 | pieSizeSpin->setMinimum(LONG_MIN); | |
102 | pieSizeSpin->setMaximum(LONG_MAX); |
|
102 | pieSizeSpin->setMaximum(LONG_MAX); | |
103 | pieSizeSpin->setValue(1.0); |
|
103 | pieSizeSpin->setValue(1.0); | |
104 | pieSizeSpin->setSingleStep(0.1); |
|
104 | pieSizeSpin->setSingleStep(0.1); | |
105 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); |
|
105 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); | |
106 | m_pieLayout->setEnabled(false); |
|
106 | m_pieLayout->setEnabled(false); | |
107 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); |
|
107 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); | |
108 |
|
108 | |||
109 | mainLayout->addLayout(m_scatterLayout, 1, 0); |
|
109 | mainLayout->addLayout(m_scatterLayout, 1, 0); | |
110 | mainLayout->addLayout(m_pieLayout, 2, 0); |
|
110 | mainLayout->addLayout(m_pieLayout, 2, 0); | |
111 |
|
111 | |||
112 | m_chartWidget = new QChartWidget(this); |
|
112 | m_chartWidget = new QChartWidget(this); | |
113 | //m_chartWidget->setColor(Qt::red); |
|
113 | //m_chartWidget->setColor(Qt::red); | |
114 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); |
|
114 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); | |
115 | // hbox->setStretch(1, 1); |
|
115 | // hbox->setStretch(1, 1); | |
116 |
|
116 | |||
117 | setLayout(mainLayout); |
|
117 | setLayout(mainLayout); | |
118 |
|
118 | |||
119 | m_autoScaleCheck->setChecked(true); |
|
119 | m_autoScaleCheck->setChecked(true); | |
120 | testDataChanged(0); |
|
120 | testDataChanged(0); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | void MainWidget::addSeries() |
|
123 | void MainWidget::addSeries() | |
124 | { |
|
124 | { | |
125 | DataSerieDialog dialog(m_defaultSeriesName, this); |
|
125 | DataSerieDialog dialog(m_defaultSeriesName, this); | |
126 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); |
|
126 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); | |
127 | dialog.exec(); |
|
127 | dialog.exec(); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | void MainWidget::addSeries(QString series, QString data) |
|
130 | void MainWidget::addSeries(QString series, QString data) | |
131 | { |
|
131 | { | |
132 | qDebug() << "addSeries: " << series << " data: " << data; |
|
132 | qDebug() << "addSeries: " << series << " data: " << data; | |
133 | m_defaultSeriesName = series; |
|
133 | m_defaultSeriesName = series; | |
134 |
|
134 | |||
135 | // TODO: a dedicated data class for storing x and y values |
|
135 | // TODO: a dedicated data class for storing x and y values | |
136 | QList<qreal> x; |
|
136 | QList<qreal> x; | |
137 | QList<qreal> y; |
|
137 | QList<qreal> y; | |
138 |
|
138 | |||
139 | if (data == "linear") { |
|
139 | if (data == "linear") { | |
140 | for (int i = 0; i < 20; i++) { |
|
140 | for (int i = 0; i < 20; i++) { | |
141 | x.append(i); |
|
141 | x.append(i); | |
142 | y.append(i); |
|
142 | y.append(i); | |
143 | } |
|
143 | } | |
144 | } else if (data == "linear, 1M") { |
|
144 | } else if (data == "linear, 1M") { | |
145 | for (int i = 0; i < 10000; i++) { |
|
145 | for (int i = 0; i < 10000; i++) { | |
146 | x.append(i); |
|
146 | x.append(i); | |
147 | y.append(20); |
|
147 | y.append(20); | |
148 | } |
|
148 | } | |
149 | } else if (data == "SIN") { |
|
149 | } else if (data == "SIN") { | |
150 | for (int i = 0; i < 100; i++) { |
|
150 | for (int i = 0; i < 100; i++) { | |
151 | x.append(i); |
|
151 | x.append(i); | |
152 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
152 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
153 | } |
|
153 | } | |
154 | } else if (data == "SIN + random") { |
|
154 | } else if (data == "SIN + random") { | |
155 | for (qreal i = 0; i < 100; i += 0.1) { |
|
155 | for (qreal i = 0; i < 100; i += 0.1) { | |
156 | x.append(i + (rand() % 5)); |
|
156 | x.append(i + (rand() % 5)); | |
157 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
157 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
158 | } |
|
158 | } | |
159 | } else { |
|
159 | } else { | |
160 | // TODO: check if data has a valid file name |
|
160 | // TODO: check if data has a valid file name | |
161 | Q_ASSERT(false); |
|
161 | Q_ASSERT(false); | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | // TODO: color of the series |
|
164 | // TODO: color of the series | |
165 | QChartSeries *newSeries = 0; |
|
165 | QChartSeries *newSeries = 0; | |
166 | if (series == "Scatter") { |
|
166 | if (series == "Scatter") { | |
167 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter); |
|
167 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter); | |
168 | Q_ASSERT(newSeries->setData(x, y)); |
|
168 | Q_ASSERT(newSeries->setData(x, y)); | |
169 | } else if (series == "Pie") { |
|
169 | } else if (series == "Pie") { | |
170 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); |
|
170 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); | |
171 | Q_ASSERT(newSeries->setData(y)); |
|
171 | Q_ASSERT(newSeries->setData(y)); | |
172 | } else if (series == "Line") { |
|
172 | } else if (series == "Line") { | |
173 | // TODO: adding data to an existing line series does not give any visuals for some reason |
|
173 | // TODO: adding data to an existing line series does not give any visuals for some reason | |
174 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); |
|
174 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); | |
175 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); |
|
175 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); | |
176 | // lineSeries->setColor(Qt::blue); |
|
176 | // lineSeries->setColor(Qt::blue); | |
177 | // for (int i(0); i < x.count() && i < y.count(); i++) { |
|
177 | // for (int i(0); i < x.count() && i < y.count(); i++) { | |
178 | // lineSeries->add(x.at(i), y.at(i)); |
|
178 | // lineSeries->add(x.at(i), y.at(i)); | |
179 | // } |
|
179 | // } | |
180 | //Q_ASSERT(newSeries->setData(x, y)); |
|
180 | //Q_ASSERT(newSeries->setData(x, y)); | |
181 | QXYChartSeries* series0 = QXYChartSeries::create(); |
|
181 | QXYChartSeries* series0 = QXYChartSeries::create(); | |
182 | for (int i(0); i < x.count() && i < y.count(); i++) |
|
182 | for (int i(0); i < x.count() && i < y.count(); i++) | |
183 | series0->add(x.at(i), y.at(i)); |
|
183 | series0->add(x.at(i), y.at(i)); | |
184 | m_chartWidget->addSeries(series0); |
|
184 | m_chartWidget->addSeries(series0); | |
185 | newSeries = series0; |
|
185 | newSeries = series0; | |
186 | } else { |
|
186 | } else { | |
187 | // TODO |
|
187 | // TODO | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | // BarChart |
|
190 | // BarChart | |
191 | if (series == "Bar") { |
|
191 | if (series == "Bar") { | |
192 | // This is the another way of creating series. Should we create test cases for both ways, if we support them? |
|
192 | // This is the another way of creating series. Should we create test cases for both ways, if we support them? | |
193 | qDebug() << "Bar chart series"; |
|
193 | qDebug() << "Bar chart series"; | |
194 | newSeries = QChartSeries::create(QChartSeries::SeriesTypeBar, this); |
|
194 | newSeries = QChartSeries::create(QChartSeries::SeriesTypeBar, this); | |
195 | QList<int> barData; |
|
195 | QList<int> barData; | |
196 | barData << 1; |
|
196 | barData << 1; | |
197 | barData << 12; |
|
197 | barData << 12; | |
198 | barData << 5; |
|
198 | barData << 5; | |
199 | barData << 8; |
|
199 | barData << 8; | |
200 | barData << 17; |
|
200 | barData << 17; | |
201 | barData << 9; |
|
201 | barData << 9; | |
202 | newSeries->setData(barData); |
|
202 | newSeries->setData(barData); | |
203 | m_chartWidget->addSeries(newSeries); |
|
203 | m_chartWidget->addSeries(newSeries); | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | setCurrentSeries(newSeries); |
|
206 | setCurrentSeries(newSeries); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | void MainWidget::setCurrentSeries(QChartSeries *series) |
|
209 | void MainWidget::setCurrentSeries(QChartSeries *series) | |
210 | { |
|
210 | { | |
211 | m_currentSeries = series; |
|
211 | m_currentSeries = series; | |
212 | switch (m_currentSeries->type()) { |
|
212 | switch (m_currentSeries->type()) { | |
213 | case QChartSeries::SeriesTypeLine: |
|
213 | case QChartSeries::SeriesTypeLine: | |
214 | break; |
|
214 | break; | |
215 | case QChartSeries::SeriesTypeScatter: |
|
215 | case QChartSeries::SeriesTypeScatter: | |
216 | break; |
|
216 | break; | |
217 | case QChartSeries::SeriesTypePie: |
|
217 | case QChartSeries::SeriesTypePie: | |
218 | break; |
|
218 | break; | |
219 | case QChartSeries::SeriesTypeBar: |
|
219 | case QChartSeries::SeriesTypeBar: | |
220 | qDebug() << "setCurrentSeries (bar)"; |
|
220 | qDebug() << "setCurrentSeries (bar)"; | |
221 | break; |
|
221 | break; | |
222 | default: |
|
222 | default: | |
223 | Q_ASSERT(false); |
|
223 | Q_ASSERT(false); | |
224 | break; |
|
224 | break; | |
225 | } |
|
225 | } | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | void MainWidget::testDataChanged(int itemIndex) |
|
228 | void MainWidget::testDataChanged(int itemIndex) | |
229 | { |
|
229 | { | |
230 | qDebug() << "testDataChanged: " << itemIndex; |
|
230 | qDebug() << "testDataChanged: " << itemIndex; | |
231 |
|
231 | |||
232 | // switch (itemIndex) { |
|
232 | // switch (itemIndex) { | |
233 | // case 0: { |
|
233 | // case 0: { | |
234 | // QList<QChartDataPoint> data; |
|
234 | // QList<QChartDataPoint> data; | |
235 | // for (int x = 0; x < 20; x++) { |
|
235 | // for (int x = 0; x < 20; x++) { | |
236 | // data.append(QChartDataPoint() << x << x / 2); |
|
236 | // data.append(QChartDataPoint() << x << x / 2); | |
237 | // } |
|
237 | // } | |
238 | // m_chartWidget->setData(data); |
|
238 | // m_chartWidget->setData(data); | |
239 | // break; |
|
239 | // break; | |
240 | // } |
|
240 | // } | |
241 | // case 1: { |
|
241 | // case 1: { | |
242 | // QList<QChartDataPoint> data; |
|
242 | // QList<QChartDataPoint> data; | |
243 | // for (int x = 0; x < 100; x++) { |
|
243 | // for (int x = 0; x < 100; x++) { | |
244 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); |
|
244 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); | |
245 | // } |
|
245 | // } | |
246 | // m_chartWidget->setData(data); |
|
246 | // m_chartWidget->setData(data); | |
247 | // break; |
|
247 | // break; | |
248 | // } |
|
248 | // } | |
249 | // case 2: { |
|
249 | // case 2: { | |
250 | // QList<QChartDataPoint> data; |
|
250 | // QList<QChartDataPoint> data; | |
251 | // for (int x = 0; x < 1000; x++) { |
|
251 | // for (int x = 0; x < 1000; x++) { | |
252 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
252 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
253 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
253 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
254 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
254 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
255 | // } |
|
255 | // } | |
256 | // m_chartWidget->setData(data); |
|
256 | // m_chartWidget->setData(data); | |
257 | // break; |
|
257 | // break; | |
258 | // } |
|
258 | // } | |
259 | // default: |
|
259 | // default: | |
260 | // break; |
|
260 | // break; | |
261 | // } |
|
261 | // } | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | void MainWidget::backgroundChanged(int itemIndex) |
|
264 | void MainWidget::backgroundChanged(int itemIndex) | |
265 | { |
|
265 | { | |
266 | qDebug() << "backgroundChanged: " << itemIndex; |
|
266 | qDebug() << "backgroundChanged: " << itemIndex; | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | void MainWidget::autoScaleChanged(int value) |
|
269 | void MainWidget::autoScaleChanged(int value) | |
270 | { |
|
270 | { | |
271 | if (value) { |
|
271 | if (value) { | |
272 | // TODO: enable auto scaling |
|
272 | // TODO: enable auto scaling | |
273 | } else { |
|
273 | } else { | |
274 | // TODO: set scaling manually (and disable auto scaling) |
|
274 | // TODO: set scaling manually (and disable auto scaling) | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | m_xMinSpin->setEnabled(!value); |
|
277 | m_xMinSpin->setEnabled(!value); | |
278 | m_xMaxSpin->setEnabled(!value); |
|
278 | m_xMaxSpin->setEnabled(!value); | |
279 | m_yMinSpin->setEnabled(!value); |
|
279 | m_yMinSpin->setEnabled(!value); | |
280 | m_yMaxSpin->setEnabled(!value); |
|
280 | m_yMaxSpin->setEnabled(!value); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | void MainWidget::xMinChanged(int value) |
|
283 | void MainWidget::xMinChanged(int value) | |
284 | { |
|
284 | { | |
285 | qDebug() << "xMinChanged: " << value; |
|
285 | qDebug() << "xMinChanged: " << value; | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | void MainWidget::xMaxChanged(int value) |
|
288 | void MainWidget::xMaxChanged(int value) | |
289 | { |
|
289 | { | |
290 | qDebug() << "xMaxChanged: " << value; |
|
290 | qDebug() << "xMaxChanged: " << value; | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | void MainWidget::yMinChanged(int value) |
|
293 | void MainWidget::yMinChanged(int value) | |
294 | { |
|
294 | { | |
295 | qDebug() << "yMinChanged: " << value; |
|
295 | qDebug() << "yMinChanged: " << value; | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
298 | void MainWidget::yMaxChanged(int value) |
|
298 | void MainWidget::yMaxChanged(int value) | |
299 | { |
|
299 | { | |
300 | qDebug() << "yMaxChanged: " << value; |
|
300 | qDebug() << "yMaxChanged: " << value; | |
301 | } |
|
301 | } | |
302 |
|
302 | |||
303 | void MainWidget::changeChartTheme(int themeIndex) |
|
303 | void MainWidget::changeChartTheme(int themeIndex) | |
304 | { |
|
304 | { | |
305 | qDebug() << "changeChartTheme: " << themeIndex; |
|
305 | qDebug() << "changeChartTheme: " << themeIndex; | |
306 |
|
|
306 | m_chartWidget->setTheme((QChart::ChartThemeId) themeIndex); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | void MainWidget::setPieSizeFactor(double size) |
|
309 | void MainWidget::setPieSizeFactor(double size) | |
310 | { |
|
310 | { | |
311 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
311 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
312 |
|
|
312 | if (pie) | |
313 | pie->setSizeFactor(qreal(size)); |
|
313 | pie->setSizeFactor(qreal(size)); | |
314 | } |
|
314 | } |
General Comments 0
You need to be logged in to leave comments.
Login now