##// END OF EJS Templates
tuning theme colors
Tero Ahola -
r125:d693628c68fb
parent child
Show More
@@ -1,45 +1,45
1 1 #ifndef DECLARATIVECHART_H
2 2 #define DECLARATIVECHART_H
3 3
4 4 #include <QtCore/QtGlobal>
5 5 #include <QDeclarativeItem>
6 6 #include <qchart.h>
7 7
8 8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 9
10 10 class DeclarativeChart : public QDeclarativeItem
11 11 // TODO: for QTQUICK2: extend QQuickPainterItem instead
12 12 //class DeclarativeChart : public QQuickPaintedItem, public Chart
13 13 {
14 14 Q_OBJECT
15 15 Q_ENUMS(ChartTheme)
16 16 Q_PROPERTY(ChartTheme theme READ theme WRITE setTheme)
17 17
18 18 public:
19 19 enum ChartTheme {
20 20 ThemeInvalid = QChart::ChartThemeInvalid,
21 21 ThemeDefault,
22 22 ThemeVanilla,
23 23 ThemeIcy,
24 24 ThemeGrayscale,
25 //ThemeScientific,
25 ThemeScientific,
26 26 ThemeUnnamed1
27 27 };
28 28 DeclarativeChart(QDeclarativeItem *parent = 0);
29 29
30 30 public: // From QDeclarativeItem/QGraphicsItem
31 31 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
32 32
33 33 public:
34 34 void setTheme(ChartTheme theme) {m_chart->setTheme((QChart::ChartThemeId) theme);}
35 35 ChartTheme theme();
36 36
37 37 public:
38 38 // Extending QChart with DeclarativeChart is not possible because QObject does not support
39 39 // multi inheritance, so we now have a QChart as a member instead
40 40 QChart *m_chart;
41 41 };
42 42
43 43 QTCOMMERCIALCHART_END_NAMESPACE
44 44
45 45 #endif // DECLARATIVECHART_H
@@ -1,106 +1,112
1 1 #include "charttheme_p.h"
2 2 #include "qchart.h"
3 3
4 4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 5
6 6 void ChartThemeData::setTheme(int theme)
7 7 {
8 8 m_seriesThemes.clear();
9 9 m_seriesIndex = 0;
10 10 m_currentTheme = theme;
11 11
12 12 switch (theme) {
13 13 case QChart::ChartThemeDefault:
14 14 // line: solid, dashed, dotted
15 15 // line width: 1
16 16 // line color (and opacity)
17 17 // line shadow (on/off)
18 18 // marker shape: "x", "o", "."
19 19 // TODO: define the default theme based on the OS
20 20 m_seriesThemes.append(SeriesTheme(QRgb(0xff000000), 2));
21 21 m_seriesThemes.append(SeriesTheme(QRgb(0xff707070), 2));
22 22 m_gradientStartColor = QColor(QRgb(0xffffffff));
23 23 m_gradientEndColor = QColor(QRgb(0xffafafaf));
24 24 break;
25 25 case QChart::ChartThemeVanilla:
26 26 m_seriesThemes.append(SeriesTheme(QColor(217, 197, 116), 6));
27 27 m_seriesThemes.append(SeriesTheme(QColor(214, 168, 150), 4));
28 28 m_seriesThemes.append(SeriesTheme(QColor(160, 160, 113), 6));
29 29 m_seriesThemes.append(SeriesTheme(QColor(210, 210, 52), 4));
30 30 m_seriesThemes.append(SeriesTheme(QColor(136, 114, 58), 6));
31 31
32 32 m_gradientStartColor = QColor(QRgb(0xff9d844d));
33 33 m_gradientEndColor = QColor(QRgb(0xffafafaf));
34 34 break;
35 35 case QChart::ChartThemeIcy:
36 m_seriesThemes.append(SeriesTheme(QColor(0, 3, 165), 2));
37 m_seriesThemes.append(SeriesTheme(QColor(49, 52, 123), 2));
38 m_seriesThemes.append(SeriesTheme(QColor(71, 114, 187), 2));
39 m_seriesThemes.append(SeriesTheme(QColor(48, 97, 87), 2));
40 m_seriesThemes.append(SeriesTheme(QColor(19, 71, 90), 2));
41 m_seriesThemes.append(SeriesTheme(QColor(110, 70, 228), 2));
36 m_seriesThemes.append(SeriesTheme(QRgb(0xFF0D2673), 2));
37 m_seriesThemes.append(SeriesTheme(QRgb(0xFF2685BF), 2));
38 m_seriesThemes.append(SeriesTheme(QRgb(0xFF3DADD9), 3));
39 m_seriesThemes.append(SeriesTheme(QRgb(0xFF62C3D9), 2));
42 40
43 m_gradientStartColor = QColor(QRgb(0xffe4ffff));
44 m_gradientEndColor = QColor(QRgb(0xffe4ffff));
41 m_gradientStartColor = QColor(QRgb(0xffBDE3F2));
42 m_gradientEndColor = QColor(QRgb(0xffafafaf));
45 43 break;
46 44 case QChart::ChartThemeGrayscale:
47 m_seriesThemes.append(SeriesTheme(QColor(0, 0, 0), 2));
48 m_seriesThemes.append(SeriesTheme(QColor(50, 50, 50), 2));
49 m_seriesThemes.append(SeriesTheme(QColor(100, 100, 100), 2));
50 m_seriesThemes.append(SeriesTheme(QColor(140, 140, 140), 2));
51 m_seriesThemes.append(SeriesTheme(QColor(180, 180, 180), 2));
45 m_seriesThemes.append(SeriesTheme(QRgb(0xFF869299), 2));
46 m_seriesThemes.append(SeriesTheme(QRgb(0xFFA5BDCC), 2));
47 m_seriesThemes.append(SeriesTheme(QRgb(0xFFE8FFFC), 3));
48 m_seriesThemes.append(SeriesTheme(QRgb(0xFFCCC2C2), 2));
52 49
53 50 m_gradientStartColor = QColor(QRgb(0xffffffff));
54 51 m_gradientEndColor = QColor(QRgb(0xffafafaf));
55 52 break;
53 case QChart::ChartThemeScientific:
54 m_seriesThemes.append(SeriesTheme(QRgb(0xFF000000), 3));
55 m_seriesThemes.append(SeriesTheme(QRgb(0xFFFFAD00), 2));
56 m_seriesThemes.append(SeriesTheme(QRgb(0xFF596A75), 2));
57 m_seriesThemes.append(SeriesTheme(QRgb(0xFF474747), 2));
58
59 m_gradientStartColor = QColor(QRgb(0xffafafaf));
60 m_gradientEndColor = QColor(QRgb(0xffafafaf));
61 break;
56 62 case QChart::ChartThemeUnnamed1:
57 63 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2));
58 64 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2));
59 65 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2));
60 66 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2));
61 67 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2));
62 68
63 69 m_gradientStartColor = QColor(QRgb(0xfff3dc9e));
64 70 m_gradientEndColor = QColor(QRgb(0xffafafaf));
65 71 break;
66 72 default:
67 73 Q_ASSERT(false);
68 74 break;
69 75 }
70 76 }
71 77
72 78 ChartTheme::ChartTheme(QObject *parent) :
73 79 QObject(parent),
74 80 d(new ChartThemeData())
75 81 {
76 82 d->m_currentTheme = QChart::ChartThemeInvalid;
77 83 d->m_seriesIndex = 0;
78 84 }
79 85
80 86 void ChartTheme::setTheme(int theme)
81 87 {
82 88 if (theme != d->m_currentTheme) {
83 89 d->setTheme(theme);
84 90 foreach (ChartThemeObserver *o, d->m_observers)
85 91 o->themeChanged(this);
86 92 }
87 93 }
88 94
89 95 SeriesTheme ChartTheme::themeForSeries()
90 96 {
91 97 if (d->m_seriesThemes.count() == 0) {
92 98 return SeriesTheme();
93 99 } else {
94 100 // Get the next available theme for the series; if no more themes available start over
95 101 // beginning from the first theme in the list
96 102 SeriesTheme nextTheme =
97 103 d->m_seriesThemes[d->m_seriesIndex % d->m_seriesThemes.count()];
98 104 d->m_seriesIndex++;
99 105 return nextTheme;
100 106 }
101 107 }
102 108
103 109
104 110 #include "moc_charttheme_p.cpp"
105 111
106 112 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,103 +1,103
1 1 #ifndef CHART_H
2 2 #define CHART_H
3 3
4 4 #include <qchartglobal.h>
5 5 #include <qchartseries.h>
6 6 #include <QGraphicsWidget>
7 7 #include <QLinearGradient>
8 8 #include <QFont>
9 9
10 10 class QGraphicsSceneResizeEvent;
11 11
12 12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13 13
14 14 class AxisItem;
15 15 class QChartSeries;
16 16 class PlotDomain;
17 17 class BarGroup;
18 18 class QChartAxis;
19 19 class ChartTheme;
20 20 class ChartItem;
21 21
22 22 // TODO: We don't need to have QChart tied to QGraphicsItem:
23 23 //class QTCOMMERCIALCHART_EXPORT QChart
24 24 //class QTCOMMERCIALCHART_EXPORT QChartGraphicsItem : public QGraphicsItem {
25 25 // public: QChartGraphicsItem(QChart &chart);
26 26
27 27 /*!
28 28 * TODO: define the responsibilities
29 29 */
30 30 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
31 31 {
32 32 Q_OBJECT
33 33 public:
34 34 enum GradientOrientation {
35 35 HorizonatlGradientOrientation,
36 36 VerticalGradientOrientation
37 37 };
38 38 enum ChartThemeId {
39 39 ChartThemeInvalid = -1,
40 40 /*! The default theme follows the GUI style of the Operating System */
41 41 ChartThemeDefault,
42 42 ChartThemeVanilla,
43 43 ChartThemeIcy,
44 44 ChartThemeGrayscale,
45 //ChartThemeScientific,
45 ChartThemeScientific,
46 46 ChartThemeUnnamed1
47 47 };
48 48
49 49 public:
50 50 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
51 51 ~QChart();
52 52
53 53 void addSeries(QChartSeries* series);
54 54 //TODO: QChartSeries* createSeries(QSeriesData *data, QChartSeries::QChartSeriesType type);
55 55 // TODO: who owns the series now? maybe owned by chart and returned a reference instead...
56 56 QChartSeries* createSeries(QChartSeries::QChartSeriesType type);
57 57
58 58 void setMargin(int margin);
59 59 int margin() const;
60 60 void setTheme(QChart::ChartThemeId theme);
61 61 QChart::ChartThemeId theme();
62 62
63 63 void setTitle(const QString& title,const QFont& font = QFont());
64 64 void setBackground(const QColor& startColor, const QColor& endColor = Qt::white, GradientOrientation orientation = VerticalGradientOrientation);
65 65
66 66 void setChartBackgroundBrush(const QBrush& brush);
67 67 void setChartBackgroundPen(const QPen& pen);
68 68
69 69 void zoomInToRect(const QRectF& rectangle);
70 70 void zoomIn();
71 71 void zoomOut();
72 72 void zoomReset();
73 73
74 74 void setAxisX(const QChartAxis& axis);
75 75 void setAxisY(const QChartAxis& axis);
76 76 void setAxisY(const QList<QChartAxis>& axis);
77 77
78 78 protected:
79 79 void resizeEvent(QGraphicsSceneResizeEvent *event);
80 80
81 81 private:
82 82 void setAxis(AxisItem *item, const QChartAxis& axis);
83 83
84 84 private:
85 85 Q_DISABLE_COPY(QChart)
86 86 QGraphicsRectItem* m_backgroundItem;
87 87 QLinearGradient m_backgroundGradient;
88 88 GradientOrientation m_bacgroundOrinetation;
89 89 QGraphicsTextItem* m_titleItem;
90 90 AxisItem* m_axisXItem;
91 91 QList<AxisItem*> m_axisYItem;
92 92 QRectF m_rect;
93 93 QList<QChartSeries *> m_chartSeries;
94 94 QList<ChartItem *> m_chartItems;
95 95 QVector<PlotDomain> m_plotDomainList;
96 96 int m_plotDataIndex;
97 97 int m_marginSize;
98 98 ChartTheme *m_chartTheme;
99 99 };
100 100
101 101 QTCOMMERCIALCHART_END_NAMESPACE
102 102
103 103 #endif
@@ -1,379 +1,380
1 1 #include "mainwidget.h"
2 2 #include "dataseriedialog.h"
3 3 #include "qchartseries.h"
4 4 #include "qpieseries.h"
5 5 #include <qxychartseries.h>
6 6 #include <barchartseries.h>
7 7 #include <QPushButton>
8 8 #include <QComboBox>
9 9 #include <QSpinBox>
10 10 #include <QCheckBox>
11 11 #include <QGridLayout>
12 12 #include <QHBoxLayout>
13 13 #include <QLabel>
14 14 #include <QSpacerItem>
15 15 #include <QMessageBox>
16 16 #include <cmath>
17 17 #include <QDebug>
18 18 #include <QStandardItemModel>
19 19
20 20
21 21 QTCOMMERCIALCHART_USE_NAMESPACE
22 22
23 23 MainWidget::MainWidget(QWidget *parent) :
24 24 QWidget(parent)
25 25 {
26 26 m_chartWidget = new QChartWidget(this);
27 27
28 28 // Grid layout for the controls for configuring the chart widget
29 29 QGridLayout *grid = new QGridLayout();
30 30 QPushButton *addSeriesButton = new QPushButton("Add series");
31 31 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
32 32 grid->addWidget(addSeriesButton, 0, 1);
33 33 initBackroundCombo(grid);
34 34 initScaleControls(grid);
35 35 initThemeCombo(grid);
36 36 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
37 37 connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool)));
38 38 zoomCheckBox->setChecked(true);
39 39 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
40 40 // add row with empty label to make all the other rows static
41 41 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
42 42 grid->setRowStretch(grid->rowCount() - 1, 1);
43 43
44 44 // Another grid layout as a main layout
45 45 QGridLayout *mainLayout = new QGridLayout();
46 46 mainLayout->addLayout(grid, 0, 0);
47 47
48 48 // Init series type specific controls
49 49 initPieControls();
50 50 mainLayout->addLayout(m_pieLayout, 2, 0);
51 51 // Scatter series specific settings
52 52 // m_scatterLayout = new QGridLayout();
53 53 // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0);
54 54 // m_scatterLayout->setEnabled(false);
55 55 // mainLayout->addLayout(m_scatterLayout, 1, 0);
56 56
57 57 // Add layouts and the chart widget to the main layout
58 58 mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1);
59 59 setLayout(mainLayout);
60 60
61 61 // force an update to test data
62 62 testDataChanged(0);
63 63 }
64 64
65 65 // Combo box for selecting the chart's background
66 66 void MainWidget::initBackroundCombo(QGridLayout *grid)
67 67 {
68 68 QComboBox *backgroundCombo = new QComboBox(this);
69 69 backgroundCombo->addItem("Color");
70 70 backgroundCombo->addItem("Gradient");
71 71 backgroundCombo->addItem("Image");
72 72 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
73 73 this, SLOT(backgroundChanged(int)));
74 74
75 75 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
76 76 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
77 77 }
78 78
79 79 // Scale related controls (auto-scale vs. manual min-max values)
80 80 void MainWidget::initScaleControls(QGridLayout *grid)
81 81 {
82 82 m_autoScaleCheck = new QCheckBox("Automatic scaling");
83 83 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
84 84 // Allow setting also non-sense values (like -2147483648 and 2147483647)
85 85 m_xMinSpin = new QSpinBox();
86 86 m_xMinSpin->setMinimum(INT_MIN);
87 87 m_xMinSpin->setMaximum(INT_MAX);
88 88 m_xMinSpin->setValue(0);
89 89 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
90 90 m_xMaxSpin = new QSpinBox();
91 91 m_xMaxSpin->setMinimum(INT_MIN);
92 92 m_xMaxSpin->setMaximum(INT_MAX);
93 93 m_xMaxSpin->setValue(10);
94 94 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
95 95 m_yMinSpin = new QSpinBox();
96 96 m_yMinSpin->setMinimum(INT_MIN);
97 97 m_yMinSpin->setMaximum(INT_MAX);
98 98 m_yMinSpin->setValue(0);
99 99 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
100 100 m_yMaxSpin = new QSpinBox();
101 101 m_yMaxSpin->setMinimum(INT_MIN);
102 102 m_yMaxSpin->setMaximum(INT_MAX);
103 103 m_yMaxSpin->setValue(10);
104 104 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
105 105
106 106 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
107 107 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
108 108 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
109 109 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
110 110 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
111 111 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
112 112 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
113 113 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
114 114 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
115 115
116 116 m_autoScaleCheck->setChecked(true);
117 117 }
118 118
119 119 // Combo box for selecting theme
120 120 void MainWidget::initThemeCombo(QGridLayout *grid)
121 121 {
122 122 QComboBox *chartTheme = new QComboBox();
123 123 chartTheme->addItem("Default");
124 124 chartTheme->addItem("Vanilla");
125 125 chartTheme->addItem("Icy");
126 126 chartTheme->addItem("Grayscale");
127 chartTheme->addItem("Scientific");
127 128 chartTheme->addItem("Unnamed1");
128 129 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
129 130 this, SLOT(changeChartTheme(int)));
130 131 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
131 132 grid->addWidget(chartTheme, 8, 1);
132 133 }
133 134
134 135 void MainWidget::initPieControls()
135 136 {
136 137 // Pie series specific settings
137 138 // Pie size factory
138 139 QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox();
139 140 pieSizeSpin->setMinimum(LONG_MIN);
140 141 pieSizeSpin->setMaximum(LONG_MAX);
141 142 pieSizeSpin->setValue(1.0);
142 143 pieSizeSpin->setSingleStep(0.1);
143 144 connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double)));
144 145 // Pie position
145 146 QComboBox *piePosCombo = new QComboBox(this);
146 147 piePosCombo->addItem("Maximized");
147 148 piePosCombo->addItem("Top left");
148 149 piePosCombo->addItem("Top right");
149 150 piePosCombo->addItem("Bottom left");
150 151 piePosCombo->addItem("Bottom right");
151 152 connect(piePosCombo, SIGNAL(currentIndexChanged(int)),
152 153 this, SLOT(setPiePosition(int)));
153 154 m_pieLayout = new QGridLayout();
154 155 m_pieLayout->setEnabled(false);
155 156 m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0);
156 157 m_pieLayout->addWidget(pieSizeSpin, 0, 1);
157 158 m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0);
158 159 m_pieLayout->addWidget(piePosCombo, 1, 1);
159 160 }
160 161
161 162 void MainWidget::addSeries()
162 163 {
163 164 DataSerieDialog dialog(m_defaultSeriesName, this);
164 165 connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString)));
165 166 dialog.exec();
166 167 }
167 168
168 169 void MainWidget::addSeries(QString series, QString data)
169 170 {
170 171 qDebug() << "addSeries: " << series << " data: " << data;
171 172 m_defaultSeriesName = series;
172 173
173 174 // TODO: a dedicated data class for storing x and y values
174 175 QList<qreal> x;
175 176 QList<qreal> y;
176 177
177 178 if (data == "linear") {
178 179 for (int i = 0; i < 20; i++) {
179 180 x.append(i);
180 181 y.append(i);
181 182 }
182 183 } else if (data == "linear, 1M") {
183 184 // 1 million data points from 0.0001 to 100
184 185 // TODO: What is the requirement? Should we be able to show this kind of data with
185 186 // reasonable performance, or can we expect the application developer to do "data mining"
186 187 // for us, so that the count of data points given to QtCommercial Chart is always
187 188 // reasonable?
188 189 for (qreal i = 0; i < 100; i += 0.0001) {
189 190 x.append(i);
190 191 y.append(20);
191 192 }
192 193 } else if (data == "SIN") {
193 194 for (int i = 0; i < 100; i++) {
194 195 x.append(i);
195 196 y.append(abs(sin(3.14159265358979 / 50 * i) * 100));
196 197 }
197 198 } else if (data == "SIN + random") {
198 199 for (qreal i = 0; i < 100; i += 0.1) {
199 200 x.append(i + (rand() % 5));
200 201 y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
201 202 }
202 203 } else {
203 204 // TODO: check if data has a valid file name
204 205 Q_ASSERT(false);
205 206 }
206 207
207 208 // TODO: color of the series
208 209 QChartSeries *newSeries = 0;
209 210 if (series == "Scatter") {
210 211 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter);
211 212 Q_ASSERT(newSeries->setData(x, y));
212 213 } else if (series == "Pie") {
213 214 newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie);
214 215 Q_ASSERT(newSeries->setData(y));
215 216 } else if (series == "Line") {
216 217 // TODO: adding data to an existing line series does not give any visuals for some reason
217 218 // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine);
218 219 // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries);
219 220 // lineSeries->setColor(Qt::blue);
220 221 // for (int i(0); i < x.count() && i < y.count(); i++) {
221 222 // lineSeries->add(x.at(i), y.at(i));
222 223 // }
223 224 //Q_ASSERT(newSeries->setData(x, y));
224 225 QXYChartSeries* series0 = QXYChartSeries::create();
225 226 for (int i(0); i < x.count() && i < y.count(); i++)
226 227 series0->add(x.at(i), y.at(i));
227 228 m_chartWidget->addSeries(series0);
228 229 newSeries = series0;
229 230 } else {
230 231 // TODO
231 232 }
232 233
233 234 // BarChart
234 235 if (series == "Bar") {
235 236 // This is the another way of creating series. Should we create test cases for both ways, if we support them?
236 237 qDebug() << "Bar chart series";
237 238 newSeries = QChartSeries::create(QChartSeries::SeriesTypeBar, this);
238 239
239 240 // Create some test data to chart
240 241 QStandardItemModel dataModel(2,10,this);
241 242 QModelIndex index;
242 243 index = dataModel.index(0,0);
243 244 // Series 1, items 6 to 9 missing.
244 245 dataModel.setData(dataModel.index(0,0),1);
245 246 dataModel.setData(dataModel.index(0,1),12);
246 247 dataModel.setData(dataModel.index(0,2),5);
247 248 dataModel.setData(dataModel.index(0,3),8);
248 249 dataModel.setData(dataModel.index(0,4),17);
249 250 dataModel.setData(dataModel.index(0,5),9);
250 251
251 252 // Series 2, some other items missing
252 253 dataModel.setData(dataModel.index(1,0),5);
253 254 dataModel.setData(dataModel.index(1,3),4);
254 255 dataModel.setData(dataModel.index(1,5),7);
255 256 dataModel.setData(dataModel.index(1,6),8);
256 257 dataModel.setData(dataModel.index(1,8),9);
257 258 dataModel.setData(dataModel.index(1,9),9);
258 259
259 260 newSeries->setData(&dataModel);
260 261
261 262 m_chartWidget->addSeries(newSeries);
262 263 }
263 264
264 265 setCurrentSeries(newSeries);
265 266 }
266 267
267 268 void MainWidget::setCurrentSeries(QChartSeries *series)
268 269 {
269 270 m_currentSeries = series;
270 271 switch (m_currentSeries->type()) {
271 272 case QChartSeries::SeriesTypeLine:
272 273 break;
273 274 case QChartSeries::SeriesTypeScatter:
274 275 break;
275 276 case QChartSeries::SeriesTypePie:
276 277 break;
277 278 case QChartSeries::SeriesTypeBar:
278 279 qDebug() << "setCurrentSeries (bar)";
279 280 break;
280 281 default:
281 282 Q_ASSERT(false);
282 283 break;
283 284 }
284 285 }
285 286
286 287 void MainWidget::testDataChanged(int itemIndex)
287 288 {
288 289 qDebug() << "testDataChanged: " << itemIndex;
289 290
290 291 // switch (itemIndex) {
291 292 // case 0: {
292 293 // QList<QChartDataPoint> data;
293 294 // for (int x = 0; x < 20; x++) {
294 295 // data.append(QChartDataPoint() << x << x / 2);
295 296 // }
296 297 // m_chartWidget->setData(data);
297 298 // break;
298 299 // }
299 300 // case 1: {
300 301 // QList<QChartDataPoint> data;
301 302 // for (int x = 0; x < 100; x++) {
302 303 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100));
303 304 // }
304 305 // m_chartWidget->setData(data);
305 306 // break;
306 307 // }
307 308 // case 2: {
308 309 // QList<QChartDataPoint> data;
309 310 // for (int x = 0; x < 1000; x++) {
310 311 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
311 312 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
312 313 // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2));
313 314 // }
314 315 // m_chartWidget->setData(data);
315 316 // break;
316 317 // }
317 318 // default:
318 319 // break;
319 320 // }
320 321 }
321 322
322 323 void MainWidget::backgroundChanged(int itemIndex)
323 324 {
324 325 qDebug() << "backgroundChanged: " << itemIndex;
325 326 }
326 327
327 328 void MainWidget::autoScaleChanged(int value)
328 329 {
329 330 if (value) {
330 331 // TODO: enable auto scaling
331 332 } else {
332 333 // TODO: set scaling manually (and disable auto scaling)
333 334 }
334 335
335 336 m_xMinSpin->setEnabled(!value);
336 337 m_xMaxSpin->setEnabled(!value);
337 338 m_yMinSpin->setEnabled(!value);
338 339 m_yMaxSpin->setEnabled(!value);
339 340 }
340 341
341 342 void MainWidget::xMinChanged(int value)
342 343 {
343 344 qDebug() << "xMinChanged: " << value;
344 345 }
345 346
346 347 void MainWidget::xMaxChanged(int value)
347 348 {
348 349 qDebug() << "xMaxChanged: " << value;
349 350 }
350 351
351 352 void MainWidget::yMinChanged(int value)
352 353 {
353 354 qDebug() << "yMinChanged: " << value;
354 355 }
355 356
356 357 void MainWidget::yMaxChanged(int value)
357 358 {
358 359 qDebug() << "yMaxChanged: " << value;
359 360 }
360 361
361 362 void MainWidget::changeChartTheme(int themeIndex)
362 363 {
363 364 qDebug() << "changeChartTheme: " << themeIndex;
364 365 m_chartWidget->setTheme((QChart::ChartThemeId) themeIndex);
365 366 }
366 367
367 368 void MainWidget::setPieSizeFactor(double size)
368 369 {
369 370 QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
370 371 if (pie)
371 372 pie->setSizeFactor(qreal(size));
372 373 }
373 374
374 375 void MainWidget::setPiePosition(int position)
375 376 {
376 377 QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries);
377 378 if (pie)
378 379 pie->setPosition((QPieSeries::PiePosition) position);
379 380 }
@@ -1,76 +1,30
1 1 import QtQuick 1.0
2 2 import QtCommercial.Chart 1.0
3 3
4 4 Rectangle {
5 5 width: 360
6 6 height: 360
7 7 Text {
8 8 text: qsTr("Hello World")
9 9 anchors.centerIn: parent
10 10 }
11 11
12 // Component.onCompleted: {
13 // for (var i = 0.0; i < 100.0; i += 0.1) {
14 // var x = i + Math.random() * 5;
15 // var y = Math.abs(Math.sin(3.14159 / 50 * x) * 100) + (Math.random() * 5);
16 // myData.append({'x':x, 'y':y});
17 // }
18 // }
19
20 // ChartModel {
21 // id: chartData
22 // ChartElement {
23 // y: 1.2
24 // }
25 // ChartElement {
26 // x: 1.1
27 // y: 1.2
28 // }
29 // ChartElement {
30 // label: "February"
31 // y: 1.2
32 // }
33 // ChartElement {
34 // label: "January"
35 // x: 0.2
36 // y: 2.1
37 // }
38 // }
39
40 // Series {
41 // model: chartData
42 // seriesType: pie
43 // axis: Series.AxisSecondaryY
44 // }
45
46 ListModel {
47 id: myData
48 ListElement {
49 nnn: 55.2
50 mmm: 13.1
51 }
52 ListElement {
53 nnn: 15.3
54 mmm: 3.4
55 }
56 }
57
58 12 Chart {
59 13 anchors.fill: parent
60 14 theme: Chart.ThemeIcy
61 15
62 16 Series {
63 17 seriesType: Series.SeriesTypePie
64 18 }
65 19 Series {
66 20 seriesType: Series.SeriesTypeScatter
67 21 }
68 22 Series {
69 23 seriesType: Series.SeriesTypeLine
70 24 }
71 25 // TODO:
72 26 // Series {
73 27 // seriesType: Series.SeriesTypeBar
74 28 // }
75 29 }
76 30 }
General Comments 0
You need to be logged in to leave comments. Login now