@@ -13,6 +13,7 int main(int argc, char *argv[]) | |||||
13 | // Create chart widget |
|
13 | // Create chart widget | |
14 | QChartView *chartView = new QChartView(); |
|
14 | QChartView *chartView = new QChartView(); | |
15 |
|
15 | |||
|
16 | //! [1] | |||
16 | // Add scatter series with simple test data |
|
17 | // Add scatter series with simple test data | |
17 | QScatterSeries *scatter = new QScatterSeries(); |
|
18 | QScatterSeries *scatter = new QScatterSeries(); | |
18 | *scatter << QPointF(0.5, 5.0) |
|
19 | *scatter << QPointF(0.5, 5.0) | |
@@ -24,6 +25,7 int main(int argc, char *argv[]) | |||||
24 | << QPointF(2.5, 5.0); |
|
25 | << QPointF(2.5, 5.0); | |
25 | // Chart takes ownership |
|
26 | // Chart takes ownership | |
26 | chartView->addSeries(scatter); |
|
27 | chartView->addSeries(scatter); | |
|
28 | //! [1] | |||
27 |
|
29 | |||
28 | // Add another scatter series |
|
30 | // Add another scatter series | |
29 | // - more data with random component |
|
31 | // - more data with random component |
@@ -167,12 +167,12 void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, i | |||||
167 |
|
167 | |||
168 | QColor color = m_seriesColor.at(count % m_seriesColor.size()); |
|
168 | QColor color = m_seriesColor.at(count % m_seriesColor.size()); | |
169 | // TODO: define alpha in the theme? or in the series? |
|
169 | // TODO: define alpha in the theme? or in the series? | |
170 | color.setAlpha(120); |
|
170 | //color.setAlpha(120); | |
171 |
|
171 | |||
172 | QBrush brush(color, Qt::SolidPattern); |
|
172 | QBrush brush(color, Qt::SolidPattern); | |
173 | presenter->m_markerBrush = brush; |
|
173 | presenter->m_markerBrush = brush; | |
174 |
|
174 | |||
175 |
QPen pen(brush, |
|
175 | QPen pen(brush, 3); | |
176 | pen.setColor(color); |
|
176 | pen.setColor(color); | |
177 | presenter->m_markerPen = pen; |
|
177 | presenter->m_markerPen = pen; | |
178 | } |
|
178 | } |
@@ -66,7 +66,7 bool QPieSeries::setData(QList<qreal> data) | |||||
66 | { |
|
66 | { | |
67 | // TODO: remove this function |
|
67 | // TODO: remove this function | |
68 | QList<QPieSlice*> slices; |
|
68 | QList<QPieSlice*> slices; | |
69 |
foreach ( |
|
69 | foreach (qreal value, data) | |
70 | slices << new QPieSlice(value, QString::number(value)); |
|
70 | slices << new QPieSlice(value, QString::number(value)); | |
71 | set(slices); |
|
71 | set(slices); | |
72 | return true; |
|
72 | return true; |
@@ -33,6 +33,7 QScatterSeriesPrivate::QScatterSeriesPrivate() : | |||||
33 | \class QScatterSeries |
|
33 | \class QScatterSeries | |
34 | \brief QtCommercial Chart series API for showing scatter series. |
|
34 | \brief QtCommercial Chart series API for showing scatter series. | |
35 |
|
35 | |||
|
36 | \snippet ../../example/scatter/main.cpp 1 | |||
36 | Example on how to create a chart with scatter series: |
|
37 | Example on how to create a chart with scatter series: | |
37 | \code |
|
38 | \code | |
38 | #include <qchartglobal.h> |
|
39 | #include <qchartglobal.h> |
@@ -4,6 +4,7 | |||||
4 | #include <QPainter> |
|
4 | #include <QPainter> | |
5 | #include <QGraphicsScene> |
|
5 | #include <QGraphicsScene> | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
|
7 | #include <QTime> | |||
7 |
|
8 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
10 | |||
@@ -45,21 +46,61 void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem * | |||||
45 | { |
|
46 | { | |
46 | // TODO: Optimization: avoid setting on every paint method call? |
|
47 | // TODO: Optimization: avoid setting on every paint method call? | |
47 | // The custom settings in series override those defined by the theme |
|
48 | // The custom settings in series override those defined by the theme | |
48 | if (m_series->markerPen().color().isValid()) |
|
49 | int shape = m_series->markerShape(); | |
49 | painter->setPen(m_series->markerPen()); |
|
50 | ||
50 | else |
|
51 | painter->save(); | |
51 | painter->setPen(m_markerPen); |
|
52 | painter->setClipRect(m_boundingRect); | |
|
53 | ||||
|
54 | // Paint dropshadow | |||
|
55 | QPen dropShadowPen(QColor(0, 0, 0, 70)); | |||
|
56 | dropShadowPen.setWidth(3); | |||
|
57 | painter->setPen(dropShadowPen); | |||
|
58 | painter->setBrush(Qt::NoBrush); | |||
|
59 | painter->setRenderHint(QPainter::Antialiasing); | |||
|
60 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { | |||
|
61 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) | |||
|
62 | switch (shape) { | |||
|
63 | case QScatterSeries::MarkerShapeDefault: | |||
|
64 | // Fallthrough, defaults to circle | |||
|
65 | case QScatterSeries::MarkerShapeCircle: | |||
|
66 | painter->drawChord(m_scenex.at(i) + 2, m_sceney.at(i) + 2, 9, 9, 0, 5760); | |||
|
67 | break; | |||
|
68 | case QScatterSeries::MarkerShapePoint: | |||
|
69 | //painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); | |||
|
70 | break; | |||
|
71 | case QScatterSeries::MarkerShapeRectangle: | |||
|
72 | painter->drawRect(m_scenex.at(i) + 2, m_sceney.at(i) + 2, 8, 8); | |||
|
73 | break; | |||
|
74 | case QScatterSeries::MarkerShapeTiltedRectangle: { | |||
|
75 | // TODO: | |||
|
76 | static const QPointF points[4] = { | |||
|
77 | QPointF(-1.0 + m_scenex.at(i), 0.0 + m_sceney.at(i)), | |||
|
78 | QPointF(0.0 + m_scenex.at(i), 1.0 + m_sceney.at(i)), | |||
|
79 | QPointF(1.0 + m_scenex.at(i), 0.0 + m_sceney.at(i)), | |||
|
80 | QPointF(0.0 + m_scenex.at(i), -1.0 + m_sceney.at(i)) | |||
|
81 | }; | |||
|
82 | painter->drawPolygon(points, 4); | |||
|
83 | break; | |||
|
84 | } | |||
|
85 | default: | |||
|
86 | // TODO: implement the rest of the shapes | |||
|
87 | Q_ASSERT(false); | |||
|
88 | break; | |||
|
89 | } | |||
|
90 | } | |||
52 |
|
91 | |||
|
92 | // Paint the shape | |||
|
93 | QPen pen = m_markerPen; | |||
|
94 | if (m_series->markerPen().color().isValid()) | |||
|
95 | pen = m_series->markerPen(); | |||
53 | if (m_series->markerBrush().color().isValid()) |
|
96 | if (m_series->markerBrush().color().isValid()) | |
54 | painter->setBrush(m_series->markerBrush()); |
|
97 | painter->setBrush(m_series->markerBrush()); | |
55 | else |
|
98 | else | |
56 | painter->setBrush(m_markerBrush); |
|
99 | painter->setBrush(m_markerBrush); | |
57 |
|
100 | painter->setPen(pen); | ||
58 | int shape = m_series->markerShape(); |
|
101 | painter->setRenderHint(QPainter::Antialiasing, false); | |
59 |
|
||||
60 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { |
|
102 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { | |
61 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) |
|
103 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) | |
62 | // Paint a shape |
|
|||
63 | switch (shape) { |
|
104 | switch (shape) { | |
64 | case QScatterSeries::MarkerShapeDefault: |
|
105 | case QScatterSeries::MarkerShapeDefault: | |
65 | // Fallthrough, defaults to circle |
|
106 | // Fallthrough, defaults to circle | |
@@ -72,7 +113,7 void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem * | |||||
72 | case QScatterSeries::MarkerShapeRectangle: |
|
113 | case QScatterSeries::MarkerShapeRectangle: | |
73 | painter->drawRect(m_scenex.at(i), m_sceney.at(i), 9, 9); |
|
114 | painter->drawRect(m_scenex.at(i), m_sceney.at(i), 9, 9); | |
74 | break; |
|
115 | break; | |
75 | case QScatterSeries::MarkerShapeTiltedRectangle: |
|
116 | case QScatterSeries::MarkerShapeTiltedRectangle: { | |
76 | // TODO: |
|
117 | // TODO: | |
77 | static const QPointF points[4] = { |
|
118 | static const QPointF points[4] = { | |
78 | QPointF(-1.0 + m_scenex.at(i), 0.0 + m_sceney.at(i)), |
|
119 | QPointF(-1.0 + m_scenex.at(i), 0.0 + m_sceney.at(i)), | |
@@ -82,12 +123,15 void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem * | |||||
82 | }; |
|
123 | }; | |
83 | painter->drawPolygon(points, 4); |
|
124 | painter->drawPolygon(points, 4); | |
84 | break; |
|
125 | break; | |
|
126 | } | |||
85 | default: |
|
127 | default: | |
86 | // TODO: implement the rest of the shapes |
|
128 | // TODO: implement the rest of the shapes | |
87 | Q_ASSERT(false); |
|
129 | Q_ASSERT(false); | |
88 | break; |
|
130 | break; | |
89 | } |
|
131 | } | |
90 | } |
|
132 | } | |
|
133 | ||||
|
134 | painter->restore(); | |||
91 | } |
|
135 | } | |
92 |
|
136 | |||
93 | void ScatterPresenter::changeGeometry() |
|
137 | void ScatterPresenter::changeGeometry() |
@@ -1,42 +1,16 | |||||
1 | #include "dataseriedialog.h" |
|
1 | #include "dataseriedialog.h" | |
2 | #include <QDialogButtonBox> |
|
2 | #include <QDialogButtonBox> | |
3 | #include <QGridLayout> |
|
3 | #include <QGridLayout> | |
4 |
#include <QC |
|
4 | #include <QCheckbox> | |
5 | #include <QPushButton> |
|
5 | #include <QPushButton> | |
|
6 | #include <QGroupBox> | |||
|
7 | #include <QRadioButton> | |||
6 | #include <QLabel> |
|
8 | #include <QLabel> | |
7 | #include <QDebug> |
|
9 | #include <QDebug> | |
8 |
|
10 | |||
9 | DataSerieDialog::DataSerieDialog(QString defaultType, QWidget *parent) : |
|
11 | DataSerieDialog::DataSerieDialog(QString defaultType, QWidget *parent) : | |
10 | QDialog(parent) |
|
12 | QDialog(parent) | |
11 | { |
|
13 | { | |
12 | // Combo box for selecting the series type |
|
|||
13 | m_seriesTypeCombo = new QComboBox(this); |
|
|||
14 | m_seriesTypeCombo->addItem("Line"); |
|
|||
15 | m_seriesTypeCombo->addItem("Area"); |
|
|||
16 | m_seriesTypeCombo->addItem("Bar"); |
|
|||
17 | m_seriesTypeCombo->addItem("StackedBar"); |
|
|||
18 | m_seriesTypeCombo->addItem("PercentBar"); |
|
|||
19 | m_seriesTypeCombo->addItem("Pie"); |
|
|||
20 | m_seriesTypeCombo->addItem("Scatter"); |
|
|||
21 | m_seriesTypeCombo->addItem("Spline"); |
|
|||
22 |
|
||||
23 | // Allow pre-selection of a series type |
|
|||
24 | if (defaultType != "") { |
|
|||
25 | int index = m_seriesTypeCombo->findText(defaultType); |
|
|||
26 | if (index > 0) |
|
|||
27 | m_seriesTypeCombo->setCurrentIndex(index); |
|
|||
28 | } |
|
|||
29 |
|
||||
30 | // Combo box for selecting data for the new series |
|
|||
31 | m_testDataCombo = new QComboBox(this); |
|
|||
32 | m_testDataCombo->addItem("linear"); |
|
|||
33 | m_testDataCombo->addItem("linear, 1M"); |
|
|||
34 | m_testDataCombo->addItem("SIN"); |
|
|||
35 | m_testDataCombo->addItem("SIN + random"); |
|
|||
36 | m_testDataCombo->addItem("Table, 5 series"); |
|
|||
37 | m_testDataCombo->addItem("TODO From file..."); |
|
|||
38 | m_testDataCombo->addItem("TODO From URL..."); |
|
|||
39 |
|
||||
40 | QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal); |
|
14 | QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal); | |
41 | QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok); |
|
15 | QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok); | |
42 | connect(b, SIGNAL(clicked()), this, SLOT(accept())); |
|
16 | connect(b, SIGNAL(clicked()), this, SLOT(accept())); | |
@@ -44,22 +18,132 DataSerieDialog::DataSerieDialog(QString defaultType, QWidget *parent) : | |||||
44 | connect(b, SIGNAL(clicked()), this, SLOT(reject())); |
|
18 | connect(b, SIGNAL(clicked()), this, SLOT(reject())); | |
45 |
|
19 | |||
46 | QGridLayout *grid = new QGridLayout(); |
|
20 | QGridLayout *grid = new QGridLayout(); | |
47 | grid->addWidget(new QLabel("Series type:"), 0, 0); |
|
21 | ||
48 | grid->addWidget(m_seriesTypeCombo, 0, 1); |
|
22 | m_seriesTypeSelector = seriesTypeSelector(); | |
49 | grid->addWidget(new QLabel("Data:"), 1, 0); |
|
23 | m_columnCountSelector = columnCountSelector(); | |
50 | grid->addWidget(m_testDataCombo, 1, 1); |
|
24 | m_rowCountSelector = rowCountSelector(); | |
51 | grid->addWidget(addSeriesBox, 2, 1); |
|
25 | m_dataCharacteristicsSelector = dataCharacteristicsSelector(); | |
|
26 | ||||
|
27 | grid->addWidget(m_seriesTypeSelector, 0, 0); | |||
|
28 | grid->addWidget(m_columnCountSelector, 0, 1); | |||
|
29 | grid->addWidget(m_rowCountSelector, 1, 1); | |||
|
30 | grid->addWidget(m_dataCharacteristicsSelector, 1, 0); | |||
|
31 | m_labelsSelector = new QCheckBox("Labels defined"); | |||
|
32 | m_labelsSelector->setChecked(true); | |||
|
33 | grid->addWidget(m_labelsSelector, 2, 0); | |||
|
34 | grid->addWidget(addSeriesBox, 3, 1); | |||
52 |
|
35 | |||
53 | setLayout(grid); |
|
36 | setLayout(grid); | |
54 | } |
|
37 | } | |
55 |
|
38 | |||
|
39 | QGroupBox *DataSerieDialog::seriesTypeSelector() | |||
|
40 | { | |||
|
41 | QVBoxLayout *layout = new QVBoxLayout(); | |||
|
42 | ||||
|
43 | QRadioButton *line = new QRadioButton("&Line"); | |||
|
44 | QRadioButton *area = new QRadioButton("&Area"); | |||
|
45 | QRadioButton *pie = new QRadioButton("&Pie"); | |||
|
46 | QRadioButton *bar = new QRadioButton("&Bar"); | |||
|
47 | QRadioButton *scatter = new QRadioButton("&Scatter"); | |||
|
48 | QRadioButton *spline = new QRadioButton("Spl&ine"); | |||
|
49 | line->setChecked(true); | |||
|
50 | ||||
|
51 | layout->addWidget(line); | |||
|
52 | layout->addWidget(area); | |||
|
53 | layout->addWidget(pie); | |||
|
54 | layout->addWidget(bar); | |||
|
55 | layout->addWidget(scatter); | |||
|
56 | layout->addWidget(spline); | |||
|
57 | ||||
|
58 | QGroupBox *groupBox = new QGroupBox("Series type"); | |||
|
59 | groupBox->setLayout(layout); | |||
|
60 | ||||
|
61 | return groupBox; | |||
|
62 | } | |||
|
63 | ||||
|
64 | QGroupBox *DataSerieDialog::columnCountSelector() | |||
|
65 | { | |||
|
66 | QVBoxLayout *layout = new QVBoxLayout(); | |||
|
67 | ||||
|
68 | QRadioButton *radio = new QRadioButton("1"); | |||
|
69 | radio->setChecked(true); | |||
|
70 | layout->addWidget(radio); | |||
|
71 | layout->addWidget(new QRadioButton("2")); | |||
|
72 | layout->addWidget(new QRadioButton("3")); | |||
|
73 | layout->addWidget(new QRadioButton("5")); | |||
|
74 | layout->addWidget(new QRadioButton("10")); | |||
|
75 | layout->addWidget(new QRadioButton("100")); | |||
|
76 | ||||
|
77 | QGroupBox *groupBox = new QGroupBox("Column count"); | |||
|
78 | groupBox->setLayout(layout); | |||
|
79 | ||||
|
80 | return groupBox; | |||
|
81 | } | |||
|
82 | ||||
|
83 | QGroupBox *DataSerieDialog::rowCountSelector() | |||
|
84 | { | |||
|
85 | QVBoxLayout *layout = new QVBoxLayout(); | |||
|
86 | ||||
|
87 | layout->addWidget(new QRadioButton("1")); | |||
|
88 | QRadioButton *radio = new QRadioButton("10"); | |||
|
89 | radio->setChecked(true); | |||
|
90 | layout->addWidget(radio); | |||
|
91 | layout->addWidget(new QRadioButton("50")); | |||
|
92 | layout->addWidget(new QRadioButton("100")); | |||
|
93 | layout->addWidget(new QRadioButton("10000")); | |||
|
94 | layout->addWidget(new QRadioButton("1000000")); | |||
|
95 | ||||
|
96 | QGroupBox *groupBox = new QGroupBox("Row count"); | |||
|
97 | groupBox->setLayout(layout); | |||
|
98 | ||||
|
99 | return groupBox; | |||
|
100 | } | |||
|
101 | ||||
|
102 | QGroupBox *DataSerieDialog::dataCharacteristicsSelector() | |||
|
103 | { | |||
|
104 | QVBoxLayout *layout = new QVBoxLayout(); | |||
|
105 | ||||
|
106 | QRadioButton *radio1 = new QRadioButton("Linear"); | |||
|
107 | radio1->setChecked(true); | |||
|
108 | layout->addWidget(radio1); | |||
|
109 | layout->addWidget(new QRadioButton("Constant")); | |||
|
110 | layout->addWidget(new QRadioButton("Random")); | |||
|
111 | layout->addWidget(new QRadioButton("Sin")); | |||
|
112 | layout->addWidget(new QRadioButton("Sin + random")); | |||
|
113 | ||||
|
114 | QGroupBox *groupBox = new QGroupBox("Data Characteristics"); | |||
|
115 | groupBox->setLayout(layout); | |||
|
116 | ||||
|
117 | return groupBox; | |||
|
118 | } | |||
|
119 | ||||
56 | void DataSerieDialog::accept() |
|
120 | void DataSerieDialog::accept() | |
57 | { |
|
121 | { | |
58 | accepted(m_seriesTypeCombo->currentText(), m_testDataCombo->currentText()); |
|
122 | accepted(radioSelection(m_seriesTypeSelector), | |
|
123 | radioSelection(m_columnCountSelector).toInt(), | |||
|
124 | radioSelection(m_rowCountSelector).toInt(), | |||
|
125 | radioSelection(m_dataCharacteristicsSelector), | |||
|
126 | m_labelsSelector->isChecked()); | |||
59 | QDialog::accept(); |
|
127 | QDialog::accept(); | |
60 | } |
|
128 | } | |
61 | //void DataSerieDialog::addSeries(QAbstractButton *button) |
|
129 | ||
62 | //{ |
|
130 | QString DataSerieDialog::radioSelection(QGroupBox *groupBox) | |
63 | // addSeries(button->text().toAscii()); |
|
131 | { | |
64 | // accept(); |
|
132 | QString selection; | |
65 | //} |
|
133 | QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout()); | |
|
134 | Q_ASSERT(layout); | |||
|
135 | ||||
|
136 | for (int i(0); i < layout->count(); i++) { | |||
|
137 | QLayoutItem *item = layout->itemAt(i); | |||
|
138 | Q_ASSERT(item); | |||
|
139 | QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget()); | |||
|
140 | Q_ASSERT(radio); | |||
|
141 | if (radio->isChecked()) { | |||
|
142 | selection = radio->text(); | |||
|
143 | break; | |||
|
144 | } | |||
|
145 | } | |||
|
146 | ||||
|
147 | qDebug() << "radioSelection: " << selection; | |||
|
148 | return selection; | |||
|
149 | } |
@@ -3,7 +3,8 | |||||
3 |
|
3 | |||
4 | #include <QDialog> |
|
4 | #include <QDialog> | |
5 |
|
5 | |||
6 |
class Q |
|
6 | class QGroupBox; | |
|
7 | class QCheckBox; | |||
7 |
|
8 | |||
8 | class DataSerieDialog : public QDialog |
|
9 | class DataSerieDialog : public QDialog | |
9 | { |
|
10 | { | |
@@ -12,14 +13,22 public: | |||||
12 | explicit DataSerieDialog(QString defaultType, QWidget *parent = 0); |
|
13 | explicit DataSerieDialog(QString defaultType, QWidget *parent = 0); | |
13 |
|
14 | |||
14 | signals: |
|
15 | signals: | |
15 | void accepted(QString series, QString data); |
|
16 | void accepted(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsDefined); | |
16 |
|
17 | |||
17 | public slots: |
|
18 | public slots: | |
18 | void accept(); |
|
19 | void accept(); | |
19 |
|
20 | |||
20 | private: |
|
21 | private: | |
21 |
Q |
|
22 | QGroupBox *seriesTypeSelector(); | |
22 | QComboBox *m_testDataCombo; |
|
23 | QGroupBox *columnCountSelector(); | |
|
24 | QGroupBox *rowCountSelector(); | |||
|
25 | QGroupBox *dataCharacteristicsSelector(); | |||
|
26 | QString radioSelection(QGroupBox *groupBox); | |||
|
27 | QGroupBox *m_seriesTypeSelector; | |||
|
28 | QGroupBox *m_columnCountSelector; | |||
|
29 | QGroupBox *m_rowCountSelector; | |||
|
30 | QCheckBox *m_labelsSelector; | |||
|
31 | QGroupBox *m_dataCharacteristicsSelector; | |||
23 | }; |
|
32 | }; | |
24 |
|
33 | |||
25 | #endif // DATASERIEDIALOG_H |
|
34 | #endif // DATASERIEDIALOG_H |
@@ -63,9 +63,6 MainWidget::MainWidget(QWidget *parent) : | |||||
63 | // Add layouts and the chart widget to the main layout |
|
63 | // Add layouts and the chart widget to the main layout | |
64 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); |
|
64 | mainLayout->addWidget(m_chartWidget, 0, 1, 3, 1); | |
65 | setLayout(mainLayout); |
|
65 | setLayout(mainLayout); | |
66 |
|
||||
67 | // force an update to test data |
|
|||
68 | testDataChanged(0); |
|
|||
69 | } |
|
66 | } | |
70 |
|
67 | |||
71 | // Combo box for selecting the chart's background |
|
68 | // Combo box for selecting the chart's background | |
@@ -168,140 +165,91 void MainWidget::initPieControls() | |||||
168 | void MainWidget::addSeries() |
|
165 | void MainWidget::addSeries() | |
169 | { |
|
166 | { | |
170 | DataSerieDialog dialog(m_defaultSeriesName, this); |
|
167 | DataSerieDialog dialog(m_defaultSeriesName, this); | |
171 |
connect(&dialog, SIGNAL(accepted(QString, QString)), |
|
168 | connect(&dialog, SIGNAL(accepted(QString, int, int, QString, bool)), | |
|
169 | this, SLOT(addSeries(QString, int, int, QString, bool))); | |||
172 | dialog.exec(); |
|
170 | dialog.exec(); | |
173 | } |
|
171 | } | |
174 |
|
172 | |||
175 | void MainWidget::addSeries(QString series, QString data) |
|
173 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) | |
176 | { |
|
174 | { | |
177 | qDebug() << "addSeries: " << series << " data: " << data; |
|
175 | // TODO: dataCharacteristics | |
178 | m_defaultSeriesName = series; |
|
176 | QList<RealList> testData; | |
179 |
|
177 | for (int j(0); j < columnCount; j++) { | ||
180 | // TODO: a dedicated data class for storing x and y values |
|
178 | QList <qreal> newColumn; | |
181 | QList<qreal> x; |
|
179 | for (int i(0); i < rowCount; i++) { | |
182 | QList<qreal> y; |
|
180 | if (dataCharacteristics == "Sin") { | |
183 |
|
181 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | ||
184 | QBarSet *set0 = new QBarSet; |
|
182 | } else if (dataCharacteristics == "Sin + random") { | |
185 | QBarSet *set1 = new QBarSet; |
|
183 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
186 | QBarSet *set2 = new QBarSet; |
|
184 | } else if (dataCharacteristics == "Random") { | |
187 | QBarSet *set3 = new QBarSet; |
|
185 | newColumn.append(rand() % 5); | |
188 | QBarSet *set4 = new QBarSet; |
|
186 | } else if (dataCharacteristics == "Linear") { | |
189 |
|
187 | //newColumn.append(i * (j + 1.0)); | ||
190 | if (data == "linear") { |
|
188 | // TODO: temporary hack to make pie work; prevent zero values: | |
191 | for (int i = 0; i < 20; i++) { |
|
189 | newColumn.append(i * (j + 1.0) + 0.1); | |
192 | x.append(i); |
|
190 | } else { // "constant" | |
193 |
|
|
191 | newColumn.append((j + 1.0)); | |
194 | } |
|
192 | } | |
195 | } else if (data == "linear, 1M") { |
|
193 | } | |
196 | // 1 million data points from 0.0001 to 100 |
|
194 | testData.append(newColumn); | |
197 | // TODO: What is the requirement? Should we be able to show this kind of data with |
|
195 | } | |
198 | // reasonable performance, or can we expect the application developer to do "data mining" |
|
196 | return testData; | |
199 | // for us, so that the count of data points given to QtCommercial Chart is always |
|
|||
200 | // reasonable? |
|
|||
201 | for (qreal i = 0; i < 100; i += 0.0001) { |
|
|||
202 | x.append(i); |
|
|||
203 | y.append(20); |
|
|||
204 | } |
|
|||
205 | } else if (data == "SIN") { |
|
|||
206 | for (int i = 0; i < 100; i++) { |
|
|||
207 | x.append(i); |
|
|||
208 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
|||
209 | } |
|
|||
210 | } else if (data == "SIN + random") { |
|
|||
211 | for (qreal i = 0; i < 100; i += 0.1) { |
|
|||
212 | x.append(i + (rand() % 5)); |
|
|||
213 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
|||
214 | } |
|
|||
215 | } else if (data == "Table, 5 series"){ |
|
|||
216 | // Create some test data to chart |
|
|||
217 | *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; |
|
|||
218 | *set1 << 5 << 0 << 0 << 4 << 0 << 7 << 8 << 9 << 9 << 0 << 4 << 2; |
|
|||
219 | *set2 << 3 << 5 << 8 << 13 << 8 << 5 << 3 << 2 << 1 << 1 << 3 << 5; |
|
|||
220 | *set3 << 5 << 6 << 7 << 3 << 4 << 5 << 8 << 9 << 10 << 5 << 2 << 7; |
|
|||
221 | *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; |
|
|||
222 | } else { |
|
|||
223 | // TODO: check if data has a valid file name |
|
|||
224 | Q_ASSERT(false); |
|
|||
225 | } |
|
197 | } | |
226 |
|
198 | |||
227 | // TODO: color of the series |
|
199 | QStringList MainWidget::generateLabels(int count) | |
228 | QChartSeries *newSeries = 0; |
|
200 | { | |
229 | if (series == "Scatter") { |
|
201 | QStringList result; | |
230 | QScatterSeries *scatter = new QScatterSeries(); |
|
202 | for (int i(0); i < count; i++) | |
231 | for (int i(0); i < x.count() && i < y.count(); i++) |
|
203 | result.append("label" + QString::number(i)); | |
232 | (*scatter) << QPointF(x.at(i), y.at(i)); |
|
204 | return result; | |
233 | m_chartWidget->addSeries(scatter); |
|
205 | } | |
234 | } else if (series == "Pie") { |
|
206 | ||
235 | newSeries = new QPieSeries(); |
|
207 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) | |
236 | m_chartWidget->addSeries(newSeries); |
|
208 | { | |
237 | Q_ASSERT(newSeries->setData(y)); |
|
209 | qDebug() << "addSeries: " << seriesName | |
238 | } else if (series == "Line") { |
|
210 | << " columnCount: " << columnCount | |
239 | // TODO: adding data to an existing line series does not give any visuals for some reason |
|
211 | << " rowCount: " << rowCount | |
240 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); |
|
212 | << " dataCharacteristics: " << dataCharacteristics | |
241 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); |
|
213 | << " labels enabled: " << labelsEnabled; | |
242 | // lineSeries->setColor(Qt::blue); |
|
214 | m_defaultSeriesName = seriesName; | |
243 | // for (int i(0); i < x.count() && i < y.count(); i++) { |
|
215 | ||
244 | // lineSeries->add(x.at(i), y.at(i)); |
|
216 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); | |
245 | // } |
|
217 | ||
246 | //Q_ASSERT(newSeries->setData(x, y)); |
|
218 | // Line series and scatter series use similar data | |
247 | QLineChartSeries* series0 = new QLineChartSeries(); |
|
219 | if (seriesName.contains("line", Qt::CaseInsensitive)) { | |
248 |
for (int |
|
220 | for (int j(0); j < data.count(); j ++) { | |
249 | series0->add(x.at(i), y.at(i)); |
|
221 | QList<qreal> column = data.at(j); | |
250 | m_chartWidget->addSeries(series0); |
|
222 | QLineChartSeries *series = new QLineChartSeries(); | |
251 | newSeries = series0; |
|
223 | for (int i(0); i < column.count(); i++) { | |
252 | } else if (series == "Bar") { |
|
224 | series->add(i, column.at(i)); | |
253 | qDebug() << "Bar chart series"; |
|
225 | } | |
254 |
|
226 | m_chartWidget->addSeries(series); | ||
255 | QBarCategory *category = new QBarCategory; |
|
227 | setCurrentSeries(series); | |
256 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
228 | } | |
257 |
|
229 | } else if (seriesName.contains("scatter", Qt::CaseInsensitive)) { | ||
258 | QBarChartSeries* series0 = new QBarChartSeries(category, this); |
|
230 | for (int j(0); j < data.count(); j++) { | |
259 |
|
231 | QList<qreal> column = data.at(j); | ||
260 | series0->addBarSet(set0); |
|
232 | QScatterSeries *series = new QScatterSeries(); | |
261 | series0->addBarSet(set1); |
|
233 | for (int i(0); i < column.count(); i++) { | |
262 | series0->addBarSet(set2); |
|
234 | (*series) << QPointF(i, column.at(i)); | |
263 | series0->addBarSet(set3); |
|
235 | } | |
264 | series0->addBarSet(set4); |
|
236 | m_chartWidget->addSeries(series); | |
265 |
|
237 | setCurrentSeries(series); | ||
266 | m_chartWidget->addSeries(series0); |
|
238 | } | |
267 | newSeries = series0; |
|
239 | } else if (seriesName.contains("pie", Qt::CaseInsensitive)) { | |
268 | } else if (series == "StackedBar") { |
|
240 | QStringList labels = generateLabels(rowCount); | |
269 | qDebug() << "Stacked bar chart series"; |
|
241 | for (int j(0); j < data.count(); j++) { | |
270 |
|
242 | QPieSeries *series = new QPieSeries(); | ||
271 | QBarCategory *category = new QBarCategory; |
|
243 | QList<qreal> column = data.at(j); | |
272 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
244 | for (int i(0); i < column.count(); i++) { | |
273 |
|
245 | series->add(column.at(i), labels.at(i)); | ||
274 | QStackedBarChartSeries* series0 = new QStackedBarChartSeries(category, this); |
|
246 | } | |
275 |
|
247 | m_chartWidget->addSeries(series); | ||
276 | series0->addBarSet(set0); |
|
248 | setCurrentSeries(series); | |
277 | series0->addBarSet(set1); |
|
249 | } | |
278 | series0->addBarSet(set2); |
|
|||
279 | series0->addBarSet(set3); |
|
|||
280 | series0->addBarSet(set4); |
|
|||
281 |
|
||||
282 | m_chartWidget->addSeries(series0); |
|
|||
283 | newSeries = series0; |
|
|||
284 | } else if (series == "PercentBar") { |
|
|||
285 | qDebug() << "Percent bar chart series"; |
|
|||
286 |
|
||||
287 | QBarCategory *category = new QBarCategory; |
|
|||
288 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
|||
289 |
|
||||
290 | QPercentBarChartSeries* series0 = new QPercentBarChartSeries(category, this); |
|
|||
291 |
|
||||
292 | series0->addBarSet(set0); |
|
|||
293 | series0->addBarSet(set1); |
|
|||
294 | series0->addBarSet(set2); |
|
|||
295 | series0->addBarSet(set3); |
|
|||
296 | series0->addBarSet(set4); |
|
|||
297 |
|
||||
298 | m_chartWidget->addSeries(series0); |
|
|||
299 | newSeries = series0; |
|
|||
300 | } else { |
|
|||
301 | qDebug() << "Something weird going on in MainWidget::addSeries"; |
|
|||
302 | } |
|
250 | } | |
303 |
|
251 | |||
304 | setCurrentSeries(newSeries); |
|
252 | // TODO: bar and other... | |
305 | } |
|
253 | } | |
306 |
|
254 | |||
307 | void MainWidget::setCurrentSeries(QChartSeries *series) |
|
255 | void MainWidget::setCurrentSeries(QChartSeries *series) | |
@@ -331,42 +279,6 void MainWidget::setCurrentSeries(QChartSeries *series) | |||||
331 | } |
|
279 | } | |
332 | } |
|
280 | } | |
333 |
|
281 | |||
334 | void MainWidget::testDataChanged(int itemIndex) |
|
|||
335 | { |
|
|||
336 | qDebug() << "testDataChanged: " << itemIndex; |
|
|||
337 |
|
||||
338 | // switch (itemIndex) { |
|
|||
339 | // case 0: { |
|
|||
340 | // QList<QChartDataPoint> data; |
|
|||
341 | // for (int x = 0; x < 20; x++) { |
|
|||
342 | // data.append(QChartDataPoint() << x << x / 2); |
|
|||
343 | // } |
|
|||
344 | // m_chartWidget->setData(data); |
|
|||
345 | // break; |
|
|||
346 | // } |
|
|||
347 | // case 1: { |
|
|||
348 | // QList<QChartDataPoint> data; |
|
|||
349 | // for (int x = 0; x < 100; x++) { |
|
|||
350 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); |
|
|||
351 | // } |
|
|||
352 | // m_chartWidget->setData(data); |
|
|||
353 | // break; |
|
|||
354 | // } |
|
|||
355 | // case 2: { |
|
|||
356 | // QList<QChartDataPoint> data; |
|
|||
357 | // for (int x = 0; x < 1000; x++) { |
|
|||
358 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
|||
359 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
|||
360 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
|||
361 | // } |
|
|||
362 | // m_chartWidget->setData(data); |
|
|||
363 | // break; |
|
|||
364 | // } |
|
|||
365 | // default: |
|
|||
366 | // break; |
|
|||
367 | // } |
|
|||
368 | } |
|
|||
369 |
|
||||
370 | void MainWidget::backgroundChanged(int itemIndex) |
|
282 | void MainWidget::backgroundChanged(int itemIndex) | |
371 | { |
|
283 | { | |
372 | qDebug() << "backgroundChanged: " << itemIndex; |
|
284 | qDebug() << "backgroundChanged: " << itemIndex; |
@@ -11,6 +11,8 class QGridLayout; | |||||
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
12 | QTCOMMERCIALCHART_USE_NAMESPACE | |
13 |
|
13 | |||
|
14 | #define RealList QList<qreal> | |||
|
15 | ||||
14 | class MainWidget : public QWidget |
|
16 | class MainWidget : public QWidget | |
15 | { |
|
17 | { | |
16 | Q_OBJECT |
|
18 | Q_OBJECT | |
@@ -27,8 +29,7 private: | |||||
27 |
|
29 | |||
28 | private slots: |
|
30 | private slots: | |
29 | void addSeries(); |
|
31 | void addSeries(); | |
30 | void addSeries(QString series, QString data); |
|
32 | void addSeries(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled); | |
31 | void testDataChanged(int itemIndex); |
|
|||
32 | void backgroundChanged(int itemIndex); |
|
33 | void backgroundChanged(int itemIndex); | |
33 | void autoScaleChanged(int value); |
|
34 | void autoScaleChanged(int value); | |
34 | void xMinChanged(int value); |
|
35 | void xMinChanged(int value); | |
@@ -39,6 +40,8 private slots: | |||||
39 | void changeChartTheme(int themeIndex); |
|
40 | void changeChartTheme(int themeIndex); | |
40 | void setPieSizeFactor(double margin); |
|
41 | void setPieSizeFactor(double margin); | |
41 | void setPiePosition(int position); |
|
42 | void setPiePosition(int position); | |
|
43 | QList<RealList> generateTestData(int columnCount, int rowCount, QString dataCharacteristics); | |||
|
44 | QStringList generateLabels(int count); | |||
42 |
|
45 | |||
43 | private: |
|
46 | private: | |
44 | QChartView *m_chartWidget; |
|
47 | QChartView *m_chartWidget; |
General Comments 0
You need to be logged in to leave comments.
Login now