@@ -24,6 +24,8 QChart::QChart(QGraphicsObject* parent) : QGraphicsObject(parent), | |||||
24 |
|
|
24 | m_plotDataIndex(0), | |
25 |
|
|
25 | m_marginSize(0) | |
26 | { |
|
26 | { | |
|
27 | // TODO: the default theme? | |||
|
28 | setTheme(QChart::ChartThemeVanilla); | |||
27 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
29 | // setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
28 | // set axis |
|
30 | // set axis | |
29 | m_axisY->rotate(90); |
|
31 | m_axisY->rotate(90); | |
@@ -47,6 +49,9 void QChart::addSeries(QChartSeries* series) | |||||
47 | case QChartSeries::SeriesTypeLine: { |
|
49 | case QChartSeries::SeriesTypeLine: { | |
48 |
|
50 | |||
49 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); |
|
51 | QXYChartSeries* xyseries = static_cast<QXYChartSeries*>(series); | |
|
52 | // Use color defined by theme in case the series does not define a custom color | |||
|
53 | if (!xyseries->color().isValid() && m_themeColors.count()) | |||
|
54 | xyseries->setColor(m_themeColors.takeFirst()); | |||
50 |
|
55 | |||
51 | XYPlotDomain domain; |
|
56 | XYPlotDomain domain; | |
52 | //TODO "nice numbers algorithm" |
|
57 | //TODO "nice numbers algorithm" | |
@@ -69,16 +74,6 void QChart::addSeries(QChartSeries* series) | |||||
69 | m_xyLineChartItems<<item; |
|
74 | m_xyLineChartItems<<item; | |
70 | break; |
|
75 | break; | |
71 | } |
|
76 | } | |
72 | // TODO: Not tested: |
|
|||
73 | // case QChartSeries::SeriesTypeScatter: { |
|
|||
74 | // QScatterSeries *scatter = qobject_cast<QScatterSeries *>(series); |
|
|||
75 | // if (scatter) { |
|
|||
76 | // scatter->d->setParentItem(this); |
|
|||
77 | // scene()->addItem(scatter->d); |
|
|||
78 | // } |
|
|||
79 | // break; |
|
|||
80 | // } |
|
|||
81 |
|
||||
82 | case QChartSeries::SeriesTypeBar: { |
|
77 | case QChartSeries::SeriesTypeBar: { | |
83 |
|
78 | |||
84 | qDebug() << "barSeries added"; |
|
79 | qDebug() << "barSeries added"; | |
@@ -90,6 +85,23 void QChart::addSeries(QChartSeries* series) | |||||
90 | m_BarGroupItems.append(group); // If we need to access group later |
|
85 | m_BarGroupItems.append(group); // If we need to access group later | |
91 | break; |
|
86 | break; | |
92 | } |
|
87 | } | |
|
88 | case QChartSeries::SeriesTypeScatter: { | |||
|
89 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |||
|
90 | connect(this, SIGNAL(sizeChanged(QRectF)), | |||
|
91 | scatterSeries, SLOT(chartSizeChanged(QRectF))); | |||
|
92 | scatterSeries->d->setParentItem(this); | |||
|
93 | QColor nextColor = m_themeColors.takeFirst(); | |||
|
94 | nextColor.setAlpha(150); // TODO: default opacity? | |||
|
95 | scatterSeries->setMarkerColor(nextColor); | |||
|
96 | } | |||
|
97 | case QChartSeries::SeriesTypePie: { | |||
|
98 | // TODO: we now have also a list of y values as a parameter, it is ignored | |||
|
99 | // we should use a generic data class instead of list of x and y values | |||
|
100 | QPieSeries *pieSeries = qobject_cast<QPieSeries *>(series); | |||
|
101 | connect(this, SIGNAL(sizeChanged(QRectF)), | |||
|
102 | pieSeries, SLOT(chartSizeChanged(QRectF))); | |||
|
103 | // TODO: how to define the color for all the slices of a pie? | |||
|
104 | } | |||
93 | } |
|
105 | } | |
94 | } |
|
106 | } | |
95 |
|
107 | |||
@@ -97,28 +109,32 QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) | |||||
97 | { |
|
109 | { | |
98 | // TODO: support also other types; not only scatter and pie |
|
110 | // TODO: support also other types; not only scatter and pie | |
99 |
|
111 | |||
|
112 | QChartSeries *series(0); | |||
|
113 | ||||
100 | switch (type) { |
|
114 | switch (type) { | |
|
115 | case QChartSeries::SeriesTypeLine: { | |||
|
116 | series = QXYChartSeries::create(); | |||
|
117 | break; | |||
|
118 | } | |||
|
119 | case QChartSeries::SeriesTypeBar: { | |||
|
120 | series = new BarChartSeries(this); | |||
|
121 | break; | |||
|
122 | } | |||
101 | case QChartSeries::SeriesTypeScatter: { |
|
123 | case QChartSeries::SeriesTypeScatter: { | |
102 |
|
|
124 | series = new QScatterSeries(this); | |
103 | connect(this, SIGNAL(sizeChanged(QRectF)), |
|
125 | break; | |
104 | scatterSeries, SLOT(chartSizeChanged(QRectF))); |
|
|||
105 | scatterSeries->d->setParentItem(this); |
|
|||
106 | return scatterSeries; |
|
|||
107 | } |
|
126 | } | |
108 | case QChartSeries::SeriesTypePie: { |
|
127 | case QChartSeries::SeriesTypePie: { | |
109 | // TODO: we now have also a list of y values as a parameter, it is ignored |
|
128 | series = new QPieSeries(this); | |
110 | // we should use a generic data class instead of list of x and y values |
|
129 | break; | |
111 | QPieSeries *pieSeries = new QPieSeries(this); |
|
|||
112 | connect(this, SIGNAL(sizeChanged(QRectF)), |
|
|||
113 | pieSeries, SLOT(chartSizeChanged(QRectF))); |
|
|||
114 | return pieSeries; |
|
|||
115 | } |
|
130 | } | |
116 | default: |
|
131 | default: | |
117 | Q_ASSERT(false); |
|
132 | Q_ASSERT(false); | |
118 | break; |
|
133 | break; | |
119 | } |
|
134 | } | |
120 |
|
135 | |||
121 | return 0; |
|
136 | addSeries(series); | |
|
137 | return series; | |||
122 | } |
|
138 | } | |
123 |
|
139 | |||
124 | void QChart::setSize(const QSizeF& size) |
|
140 | void QChart::setSize(const QSizeF& size) | |
@@ -159,7 +175,39 void QChart::setMargin(int margin) | |||||
159 | m_marginSize = margin; |
|
175 | m_marginSize = margin; | |
160 | } |
|
176 | } | |
161 |
|
177 | |||
162 | #include "moc_qchart.cpp" |
|
178 | void QChart::setTheme(QChart::ChartTheme theme) | |
|
179 | { | |||
|
180 | // TODO: define color themes | |||
|
181 | switch (theme) { | |||
|
182 | case ChartThemeVanilla: | |||
|
183 | m_themeColors.append(QColor(255, 238, 174)); | |||
|
184 | m_themeColors.append(QColor(228, 228, 160)); | |||
|
185 | m_themeColors.append(QColor(228, 179, 160)); | |||
|
186 | m_themeColors.append(QColor(180, 151, 18)); | |||
|
187 | m_themeColors.append(QColor(252, 252, 37)); | |||
|
188 | break; | |||
|
189 | case ChartThemeIcy: | |||
|
190 | m_themeColors.append(QColor(255, 238, 174)); | |||
|
191 | m_themeColors.append(QColor(228, 228, 160)); | |||
|
192 | m_themeColors.append(QColor(228, 179, 160)); | |||
|
193 | m_themeColors.append(QColor(180, 151, 18)); | |||
|
194 | m_themeColors.append(QColor(252, 252, 37)); | |||
|
195 | break; | |||
|
196 | case ChartThemeGrayscale: | |||
|
197 | m_themeColors.append(QColor(255, 238, 174)); | |||
|
198 | m_themeColors.append(QColor(228, 228, 160)); | |||
|
199 | m_themeColors.append(QColor(228, 179, 160)); | |||
|
200 | m_themeColors.append(QColor(180, 151, 18)); | |||
|
201 | m_themeColors.append(QColor(252, 252, 37)); | |||
|
202 | break; | |||
|
203 | default: | |||
|
204 | Q_ASSERT(false); | |||
|
205 | break; | |||
|
206 | } | |||
163 |
|
207 | |||
|
208 | // TODO: update coloring of different elements to match the selected theme | |||
|
209 | } | |||
|
210 | ||||
|
211 | #include "moc_qchart.cpp" | |||
164 |
|
212 | |||
165 | QTCOMMERCIALCHART_END_NAMESPACE |
|
213 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -26,6 +26,13 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsObject | |||||
26 | { |
|
26 | { | |
27 | Q_OBJECT |
|
27 | Q_OBJECT | |
28 | public: |
|
28 | public: | |
|
29 | enum ChartTheme { | |||
|
30 | ChartThemeVanilla = 0, | |||
|
31 | ChartThemeIcy, | |||
|
32 | ChartThemeGrayscale | |||
|
33 | }; | |||
|
34 | ||||
|
35 | public: | |||
29 | QChart(QGraphicsObject* parent = 0); |
|
36 | QChart(QGraphicsObject* parent = 0); | |
30 | ~QChart(); |
|
37 | ~QChart(); | |
31 |
|
38 | |||
@@ -41,6 +48,7 public: | |||||
41 | virtual void setSize(const QSizeF& rect); |
|
48 | virtual void setSize(const QSizeF& rect); | |
42 | void setMargin(int margin); |
|
49 | void setMargin(int margin); | |
43 | int margin() const; |
|
50 | int margin() const; | |
|
51 | void setTheme(QChart::ChartTheme theme); | |||
44 |
|
52 | |||
45 | signals: |
|
53 | signals: | |
46 | void sizeChanged(QRectF rect); |
|
54 | void sizeChanged(QRectF rect); | |
@@ -58,6 +66,7 private: | |||||
58 | QList<QGraphicsItem*> m_items; |
|
66 | QList<QGraphicsItem*> m_items; | |
59 | int m_plotDataIndex; |
|
67 | int m_plotDataIndex; | |
60 | int m_marginSize; |
|
68 | int m_marginSize; | |
|
69 | QList<QColor> m_themeColors; | |||
61 |
|
70 | |||
62 | QList<BarGroup*> m_BarGroupItems; |
|
71 | QList<BarGroup*> m_BarGroupItems; | |
63 | }; |
|
72 | }; |
@@ -46,6 +46,12 QChartSeries* QChartWidget::createSeries(QChartSeries::QChartSeriesType type) | |||||
46 | { |
|
46 | { | |
47 | return m_chart->createSeries(type); |
|
47 | return m_chart->createSeries(type); | |
48 | } |
|
48 | } | |
|
49 | ||||
|
50 | void QChartWidget::setTheme(QChart::ChartTheme theme) | |||
|
51 | { | |||
|
52 | m_chart->setTheme(theme); | |||
|
53 | } | |||
|
54 | ||||
49 | #include "moc_qchartwidget.cpp" |
|
55 | #include "moc_qchartwidget.cpp" | |
50 |
|
56 | |||
51 | QTCOMMERCIALCHART_END_NAMESPACE |
|
57 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -28,6 +28,12 public: | |||||
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 | /*! | |||
|
32 | * Set color theme for the chart. Themes define harmonic colors for the graphical elements of | |||
|
33 | * the chart. | |||
|
34 | */ | |||
|
35 | void setTheme(QChart::ChartTheme theme); | |||
|
36 | ||||
31 | private: |
|
37 | private: | |
32 | Q_DISABLE_COPY(QChartWidget) |
|
38 | Q_DISABLE_COPY(QChartWidget) | |
33 | QGraphicsScene *m_scene; |
|
39 | QGraphicsScene *m_scene; |
@@ -12,7 +12,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
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 | { |
|
17 | { | |
17 | } |
|
18 | } | |
18 |
|
19 | |||
@@ -41,7 +42,8 void QScatterSeriesPrivate::paint(QPainter *painter, const QStyleOptionGraphicsI | |||||
41 | QPen pen = painter->pen(); |
|
42 | QPen pen = painter->pen(); | |
42 | QBrush brush = pen.brush(); |
|
43 | QBrush brush = pen.brush(); | |
43 | // TODO: The opacity should be user definable... |
|
44 | // TODO: The opacity should be user definable... | |
44 | brush.setColor(QColor(255, 82, 0, 100)); |
|
45 | //brush.setColor(QColor(255, 82, 0, 100)); | |
|
46 | brush.setColor(m_markerColor); | |||
45 | pen.setBrush(brush); |
|
47 | pen.setBrush(brush); | |
46 | pen.setWidth(4); |
|
48 | pen.setWidth(4); | |
47 | painter->setPen(pen); |
|
49 | painter->setPen(pen); | |
@@ -80,6 +82,11 void QScatterSeries::chartSizeChanged(QRectF rect) | |||||
80 | d->resize(rect); |
|
82 | d->resize(rect); | |
81 | } |
|
83 | } | |
82 |
|
84 | |||
|
85 | void QScatterSeries::setMarkerColor(QColor color) | |||
|
86 | { | |||
|
87 | d->m_markerColor = color; | |||
|
88 | } | |||
|
89 | ||||
83 | // TODO: |
|
90 | // TODO: | |
84 | //void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale) |
|
91 | //void QScatterSeries::chartScaleChanged(qreal xscale, qreal yscale) | |
85 | //{ |
|
92 | //{ |
@@ -3,6 +3,7 | |||||
3 |
|
3 | |||
4 | #include "qchartseries.h" |
|
4 | #include "qchartseries.h" | |
5 | #include <QRectF> |
|
5 | #include <QRectF> | |
|
6 | #include <QColor> | |||
6 |
|
7 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 | class QScatterSeriesPrivate; |
|
9 | class QScatterSeriesPrivate; | |
@@ -21,6 +22,7 public: // from QChartSeries | |||||
21 |
|
22 | |||
22 | public Q_SLOTS: |
|
23 | public Q_SLOTS: | |
23 | void chartSizeChanged(QRectF rect); |
|
24 | void chartSizeChanged(QRectF rect); | |
|
25 | void setMarkerColor(QColor color); | |||
24 | //void chartScaleChanged(qreal xscale, qreal yscale); |
|
26 | //void chartScaleChanged(qreal xscale, qreal yscale); | |
25 |
|
27 | |||
26 | private: |
|
28 | private: |
@@ -26,6 +26,7 public: // from QGraphicsItem | |||||
26 | qreal m_scaley; |
|
26 | qreal m_scaley; | |
27 | QList<qreal> m_scenex; |
|
27 | QList<qreal> m_scenex; | |
28 | QList<qreal> m_sceney; |
|
28 | QList<qreal> m_sceney; | |
|
29 | QColor m_markerColor; | |||
29 | }; |
|
30 | }; | |
30 |
|
31 | |||
31 | QTCOMMERCIALCHART_END_NAMESPACE |
|
32 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -3,7 +3,7 | |||||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | QXYChartSeries::QXYChartSeries(QObject* parent):QChartSeries(parent), |
|
5 | QXYChartSeries::QXYChartSeries(QObject* parent):QChartSeries(parent), | |
6 |
m_color( |
|
6 | m_color() | |
7 | { |
|
7 | { | |
8 | } |
|
8 | } | |
9 |
|
9 |
@@ -58,6 +58,14 MainWidget::MainWidget(QWidget *parent) : | |||||
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(); | |||
|
62 | chartTheme->addItem("Vanilla"); | |||
|
63 | chartTheme->addItem("Icy"); | |||
|
64 | chartTheme->addItem("Grayscale"); | |||
|
65 | chartTheme->addItem("Tobedefined"); | |||
|
66 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |||
|
67 | this, SLOT(changeChartTheme(int))); | |||
|
68 | ||||
61 | QGridLayout *grid = new QGridLayout(); |
|
69 | QGridLayout *grid = new QGridLayout(); | |
62 | QGridLayout *mainLayout = new QGridLayout(); |
|
70 | QGridLayout *mainLayout = new QGridLayout(); | |
63 | //grid->addWidget(new QLabel("Add series:"), 0, 0); |
|
71 | //grid->addWidget(new QLabel("Add series:"), 0, 0); | |
@@ -73,9 +81,11 MainWidget::MainWidget(QWidget *parent) : | |||||
73 | grid->addWidget(m_yMinSpin, 6, 1); |
|
81 | grid->addWidget(m_yMinSpin, 6, 1); | |
74 | grid->addWidget(new QLabel("y max:"), 7, 0); |
|
82 | grid->addWidget(new QLabel("y max:"), 7, 0); | |
75 | grid->addWidget(m_yMaxSpin, 7, 1); |
|
83 | grid->addWidget(m_yMaxSpin, 7, 1); | |
|
84 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |||
|
85 | grid->addWidget(chartTheme, 8, 1); | |||
76 | // 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 | |
77 |
grid->addWidget(new QLabel(""), |
|
87 | grid->addWidget(new QLabel(""), 9, 0); | |
78 |
grid->setRowStretch( |
|
88 | grid->setRowStretch(9, 1); | |
79 |
|
89 | |||
80 | mainLayout->addLayout(grid, 0, 0); |
|
90 | mainLayout->addLayout(grid, 0, 0); | |
81 |
|
91 | |||
@@ -160,8 +170,19 void MainWidget::addSeries(QString series, QString data) | |||||
160 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); |
|
170 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); | |
161 | Q_ASSERT(newSeries->setData(y)); |
|
171 | Q_ASSERT(newSeries->setData(y)); | |
162 | } else if (series == "Line") { |
|
172 | } else if (series == "Line") { | |
163 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); |
|
173 | // TODO: adding data to an existing line series does not give any visuals for some reason | |
164 | Q_ASSERT(newSeries->setData(x, y)); |
|
174 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); | |
|
175 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); | |||
|
176 | // lineSeries->setColor(Qt::blue); | |||
|
177 | // for (int i(0); i < x.count() && i < y.count(); i++) { | |||
|
178 | // lineSeries->add(x.at(i), y.at(i)); | |||
|
179 | // } | |||
|
180 | //Q_ASSERT(newSeries->setData(x, y)); | |||
|
181 | QXYChartSeries* series0 = QXYChartSeries::create(); | |||
|
182 | for (int i(0); i < x.count() && i < y.count(); i++) | |||
|
183 | series0->add(x.at(i), y.at(i)); | |||
|
184 | m_chartWidget->addSeries(series0); | |||
|
185 | newSeries = series0; | |||
165 | } else { |
|
186 | } else { | |
166 | // TODO |
|
187 | // TODO | |
167 | } |
|
188 | } | |
@@ -279,6 +300,12 void MainWidget::yMaxChanged(int value) | |||||
279 | qDebug() << "yMaxChanged: " << value; |
|
300 | qDebug() << "yMaxChanged: " << value; | |
280 | } |
|
301 | } | |
281 |
|
302 | |||
|
303 | void MainWidget::changeChartTheme(int themeIndex) | |||
|
304 | { | |||
|
305 | qDebug() << "changeChartTheme: " << themeIndex; | |||
|
306 | m_chartWidget->setTheme((QChart::ChartTheme) themeIndex); | |||
|
307 | } | |||
|
308 | ||||
282 | void MainWidget::setPieSizeFactor(double size) |
|
309 | void MainWidget::setPieSizeFactor(double size) | |
283 | { |
|
310 | { | |
284 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
311 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
@@ -30,6 +30,7 private slots: | |||||
30 | void yMinChanged(int value); |
|
30 | void yMinChanged(int value); | |
31 | void yMaxChanged(int value); |
|
31 | void yMaxChanged(int value); | |
32 | void setCurrentSeries(QChartSeries *series); |
|
32 | void setCurrentSeries(QChartSeries *series); | |
|
33 | void changeChartTheme(int themeIndex); | |||
33 | void setPieSizeFactor(double margin); |
|
34 | void setPieSizeFactor(double margin); | |
34 |
|
35 | |||
35 | private: |
|
36 | private: |
General Comments 0
You need to be logged in to leave comments.
Login now