@@ -1,32 +1,33 | |||||
1 | #include <QtGui/QApplication> |
|
1 | #include <QtGui/QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <cmath> |
|
3 | #include <cmath> | |
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qchartview.h> |
|
5 | #include <qchartview.h> | |
6 | #include <qscatterseries.h> |
|
6 | #include <qscatterseries.h> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
8 | QTCOMMERCIALCHART_USE_NAMESPACE | |
9 |
|
9 | |||
10 | int main(int argc, char *argv[]) |
|
10 | int main(int argc, char *argv[]) | |
11 | { |
|
11 | { | |
12 | QApplication a(argc, argv); |
|
12 | QApplication a(argc, argv); | |
13 |
|
13 | |||
14 | // Create widget and scatter series |
|
14 | // Create widget and scatter series | |
15 | QChartView *chartWidget = new QChartView(); |
|
15 | QChartView *chartWidget = new QChartView(); | |
16 | QScatterSeries *scatter = |
|
16 | QScatterSeries *scatter = new QScatterSeries(); | |
17 | qobject_cast<QScatterSeries *>(chartWidget->createSeries(QChartSeries::SeriesTypeScatter)); |
|
|||
18 | Q_ASSERT(scatter); |
|
|||
19 |
|
17 | |||
20 | // Add test data to the series |
|
18 | // Add test data to the series | |
21 | for (qreal i(0.0); i < 20; i += 0.5) |
|
19 | for (qreal i(0.0); i < 20; i += 0.5) | |
22 |
scatter |
|
20 | (*scatter) << QPointF(i + (qreal)(rand() % 100) / 100.0, | |
23 |
|
|
21 | i + (qreal)(rand() % 100) / 100.0); | |
|
22 | ||||
|
23 | // Add series to the chart widget | |||
|
24 | chartWidget->addSeries(scatter); | |||
24 |
|
25 | |||
25 | // Use the chart widget as the central widget |
|
26 | // Use the chart widget as the central widget | |
26 | QMainWindow w; |
|
27 | QMainWindow w; | |
27 | w.resize(640, 480); |
|
28 | w.resize(640, 480); | |
28 | w.setCentralWidget(chartWidget); |
|
29 | w.setCentralWidget(chartWidget); | |
29 | w.show(); |
|
30 | w.show(); | |
30 |
|
31 | |||
31 | return a.exec(); |
|
32 | return a.exec(); | |
32 | } |
|
33 | } |
@@ -1,95 +1,100 | |||||
1 | #include "declarativeseries.h" |
|
1 | #include "declarativeseries.h" | |
2 | #include "declarativechart.h" |
|
2 | #include "declarativechart.h" | |
3 | #include <qscatterseries.h> |
|
3 | #include <qscatterseries.h> | |
4 | #include <qlinechartseries.h> |
|
4 | #include <qlinechartseries.h> | |
5 | #include <cmath> |
|
5 | #include <cmath> | |
6 | #include <QDebug> |
|
6 | #include <QDebug> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | DeclarativeSeries::DeclarativeSeries(QDeclarativeItem *parent) : |
|
10 | DeclarativeSeries::DeclarativeSeries(QDeclarativeItem *parent) : | |
11 | QDeclarativeItem(parent), |
|
11 | QDeclarativeItem(parent), | |
12 | m_seriesType(SeriesTypeInvalid), // TODO: default type? |
|
12 | m_seriesType(SeriesTypeInvalid), // TODO: default type? | |
13 | m_chart(0), |
|
13 | m_chart(0), | |
14 | m_series(0) |
|
14 | m_series(0) | |
15 | { |
|
15 | { | |
16 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
16 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
17 | connect(this, SIGNAL(parentChanged()), |
|
17 | connect(this, SIGNAL(parentChanged()), | |
18 | this, SLOT(setParentForSeries())); |
|
18 | this, SLOT(setParentForSeries())); | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | void DeclarativeSeries::setSeriesType(SeriesType type) |
|
21 | void DeclarativeSeries::setSeriesType(SeriesType type) | |
22 | { |
|
22 | { | |
23 | if (!m_series || type != m_seriesType) { |
|
23 | if (!m_series || type != m_seriesType) { | |
24 | m_seriesType = type; |
|
24 | m_seriesType = type; | |
25 | initSeries(); |
|
25 | initSeries(); | |
|
26 | } else { | |||
|
27 | m_seriesType = type; | |||
26 | } |
|
28 | } | |
27 | } |
|
29 | } | |
28 |
|
30 | |||
29 | void DeclarativeSeries::setParentForSeries() |
|
31 | void DeclarativeSeries::setParentForSeries() | |
30 | { |
|
32 | { | |
31 |
i |
|
33 | if (!m_series) | |
|
34 | initSeries(); | |||
|
35 | else if (m_series->type() != m_seriesType) | |||
|
36 | initSeries(); | |||
32 | } |
|
37 | } | |
33 |
|
38 | |||
34 | void DeclarativeSeries::initSeries() |
|
39 | void DeclarativeSeries::initSeries() | |
35 | { |
|
40 | { | |
36 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); |
|
41 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); | |
37 |
|
42 | |||
38 | if (declarativeChart && m_seriesType != SeriesTypeInvalid) { |
|
43 | if (declarativeChart && m_seriesType != SeriesTypeInvalid) { | |
39 | delete m_series; |
|
44 | delete m_series; | |
40 | m_series = 0; |
|
45 | m_series = 0; | |
41 |
|
46 | |||
42 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); |
|
47 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); | |
43 | qDebug() << "creating series for chart: " << chart; |
|
48 | qDebug() << "creating series for chart: " << chart; | |
44 | Q_ASSERT(chart); |
|
49 | Q_ASSERT(chart); | |
45 |
|
50 | |||
46 | switch (m_seriesType) { |
|
51 | switch (m_seriesType) { | |
47 | case SeriesTypeLine: { |
|
52 | case SeriesTypeLine: { | |
48 | m_series = new QLineChartSeries(this); |
|
53 | m_series = new QLineChartSeries(this); | |
49 | for (qreal i(0.0); i < 100.0; i += 1.0) |
|
54 | for (qreal i(0.0); i < 100.0; i += 1.0) | |
50 | ((QLineChartSeries *)m_series)->add(i, i); |
|
55 | ((QLineChartSeries *)m_series)->add(i, i); | |
51 | chart->addSeries(m_series); |
|
56 | chart->addSeries(m_series); | |
52 | break; |
|
57 | break; | |
53 | } |
|
58 | } | |
54 | case SeriesTypeBar: |
|
59 | case SeriesTypeBar: | |
55 | // fallthrough; bar and scatter use the same test data |
|
60 | // fallthrough; bar and scatter use the same test data | |
56 | case SeriesTypeScatter: { |
|
61 | case SeriesTypeScatter: { | |
57 | m_series = chart->createSeries((QChartSeries::QChartSeriesType) m_seriesType); |
|
62 | m_series = chart->createSeries((QChartSeries::QChartSeriesType) m_seriesType); | |
58 | QScatterSeries *scatter = qobject_cast<QScatterSeries *>(m_series); |
|
63 | QScatterSeries *scatter = qobject_cast<QScatterSeries *>(m_series); | |
59 | Q_ASSERT(scatter); |
|
64 | Q_ASSERT(scatter); | |
60 | for (qreal i = 0; i < 100; i += 0.1) |
|
65 | for (qreal i = 0; i < 100; i += 0.1) | |
61 | scatter->addData(QPointF(i + (rand() % 5), |
|
66 | scatter->addData(QPointF(i + (rand() % 5), | |
62 | abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5))); |
|
67 | abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5))); | |
63 | break; |
|
68 | break; | |
64 | } |
|
69 | } | |
65 | case SeriesTypeStackedBar: |
|
70 | case SeriesTypeStackedBar: | |
66 | break; |
|
71 | break; | |
67 | case SeriesTypePercentBar: |
|
72 | case SeriesTypePercentBar: | |
68 | break; |
|
73 | break; | |
69 | case SeriesTypePie: { |
|
74 | case SeriesTypePie: { | |
70 | m_series = chart->createSeries((QChartSeries::QChartSeriesType) m_seriesType); |
|
75 | m_series = chart->createSeries((QChartSeries::QChartSeriesType) m_seriesType); | |
71 | QList<qreal> data; |
|
76 | QList<qreal> data; | |
72 | data << 1.0; |
|
77 | data << 1.0; | |
73 | data << 12.0; |
|
78 | data << 12.0; | |
74 | data << 4.0; |
|
79 | data << 4.0; | |
75 | Q_ASSERT(m_series->setData(data)); |
|
80 | Q_ASSERT(m_series->setData(data)); | |
76 | break; |
|
81 | break; | |
77 | } |
|
82 | } | |
78 | default: |
|
83 | default: | |
79 | break; |
|
84 | break; | |
80 | } |
|
85 | } | |
81 | } |
|
86 | } | |
82 | } |
|
87 | } | |
83 |
|
88 | |||
84 | QVariant DeclarativeSeries::itemChange(GraphicsItemChange change, |
|
89 | QVariant DeclarativeSeries::itemChange(GraphicsItemChange change, | |
85 | const QVariant &value) |
|
90 | const QVariant &value) | |
86 | { |
|
91 | { | |
87 | // For debugging purposes only: |
|
92 | // For debugging purposes only: | |
88 | // qDebug() << QString::number(change) << " : " << value.toString(); |
|
93 | // qDebug() << QString::number(change) << " : " << value.toString(); | |
89 | return QGraphicsItem::itemChange(change, value); |
|
94 | return QGraphicsItem::itemChange(change, value); | |
90 | } |
|
95 | } | |
91 |
|
96 | |||
92 |
|
97 | |||
93 | #include "moc_declarativeseries.cpp" |
|
98 | #include "moc_declarativeseries.cpp" | |
94 |
|
99 | |||
95 | QTCOMMERCIALCHART_END_NAMESPACE |
|
100 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,54 +1,59 | |||||
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 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | QScatterSeriesPrivate::QScatterSeriesPrivate() : |
|
7 | QScatterSeriesPrivate::QScatterSeriesPrivate() : | |
8 | m_data(QList<QPointF>()) |
|
8 | m_data(QList<QPointF>()) | |
9 | { |
|
9 | { | |
10 | } |
|
10 | } | |
11 |
|
11 | |||
12 | QScatterSeries::QScatterSeries(QObject *parent) : |
|
12 | QScatterSeries::QScatterSeries(QObject *parent) : | |
13 | QChartSeries(parent), |
|
13 | QChartSeries(parent), | |
14 | d(new QScatterSeriesPrivate()) |
|
14 | d(new QScatterSeriesPrivate()) | |
15 | { |
|
15 | { | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | QScatterSeries::~QScatterSeries() |
|
18 | QScatterSeries::~QScatterSeries() | |
19 | { |
|
19 | { | |
20 | delete d; |
|
20 | delete d; | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | // TODO: change to list of QPointFs? |
|
23 | void QScatterSeries::addData(QPointF value) | |
24 | //bool QScatterSeries::setData(QList<qreal> xlist, QList<qreal> ylist) |
|
|||
25 | void QScatterSeries::setData(QList<QPointF> data) |
|
|||
26 | { |
|
24 | { | |
27 |
d->m_data |
|
25 | d->m_data.append(value); | |
|
26 | emit changed(); | |||
|
27 | } | |||
|
28 | ||||
|
29 | QScatterSeries& QScatterSeries::operator << (const QPointF &value) | |||
|
30 | { | |||
|
31 | d->m_data.append(value); | |||
28 | emit changed(); |
|
32 | emit changed(); | |
|
33 | return *this; | |||
29 | } |
|
34 | } | |
30 |
|
35 | |||
31 |
void QScatterSeries:: |
|
36 | void QScatterSeries::setData(QList<QPointF> data) | |
32 | { |
|
37 | { | |
33 |
d->m_data |
|
38 | d->m_data = data; | |
34 | emit changed(); |
|
39 | emit changed(); | |
35 | } |
|
40 | } | |
36 |
|
41 | |||
37 | QList<QPointF> QScatterSeries::data() |
|
42 | QList<QPointF> QScatterSeries::data() | |
38 | { |
|
43 | { | |
39 | return d->m_data; |
|
44 | return d->m_data; | |
40 | } |
|
45 | } | |
41 |
|
46 | |||
42 | void QScatterSeries::setMarkerPen(QPen pen) |
|
47 | void QScatterSeries::setMarkerPen(QPen pen) | |
43 | { |
|
48 | { | |
44 | d->m_markerPen = pen; |
|
49 | d->m_markerPen = pen; | |
45 | } |
|
50 | } | |
46 |
|
51 | |||
47 | QPen QScatterSeries::markerPen() |
|
52 | QPen QScatterSeries::markerPen() | |
48 | { |
|
53 | { | |
49 | return d->m_markerPen; |
|
54 | return d->m_markerPen; | |
50 | } |
|
55 | } | |
51 |
|
56 | |||
52 | #include "moc_qscatterseries.cpp" |
|
57 | #include "moc_qscatterseries.cpp" | |
53 |
|
58 | |||
54 | QTCOMMERCIALCHART_END_NAMESPACE |
|
59 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,51 +1,52 | |||||
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 |
|
21 | |||
22 | public: |
|
22 | public: | |
23 |
// TODO: the name of the function? addPoint? addData? add |
|
23 | // TODO: the name of the function? addPoint? addData? addValue? | |
24 |
void addData(QPointF |
|
24 | void addData(QPointF value); | |
|
25 | QScatterSeries& operator << (const QPointF &value); | |||
25 |
|
26 | |||
26 | void setData(QList<QPointF> data); |
|
27 | void setData(QList<QPointF> data); | |
27 |
|
28 | |||
28 | QList<QPointF> data(); |
|
29 | QList<QPointF> data(); | |
29 |
|
30 | |||
30 | //TODO? void insertData(int index, QPointF data); |
|
31 | //TODO? void insertData(int index, QPointF data); | |
31 |
|
32 | |||
32 | void setMarkerPen(QPen pen); |
|
33 | void setMarkerPen(QPen pen); | |
33 | QPen markerPen(); |
|
34 | QPen markerPen(); | |
34 | // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot |
|
35 | // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot | |
35 | //void setMarkerShape(MarkerShape shape); |
|
36 | //void setMarkerShape(MarkerShape shape); | |
36 |
|
37 | |||
37 | Q_SIGNALS: |
|
38 | Q_SIGNALS: | |
38 | // TODO: move to PIMPL? |
|
39 | // TODO: move to PIMPL? | |
39 | // TODO: more finegrained signaling for performance reasons |
|
40 | // TODO: more finegrained signaling for performance reasons | |
40 | void changed(); |
|
41 | void changed(); | |
41 |
|
42 | |||
42 | //public Q_SLOTS: |
|
43 | //public Q_SLOTS: | |
43 | private: |
|
44 | private: | |
44 | Q_DECLARE_PRIVATE(QScatterSeries) |
|
45 | Q_DECLARE_PRIVATE(QScatterSeries) | |
45 | Q_DISABLE_COPY(QScatterSeries) |
|
46 | Q_DISABLE_COPY(QScatterSeries) | |
46 | QScatterSeriesPrivate *const d; |
|
47 | QScatterSeriesPrivate *const d; | |
47 | }; |
|
48 | }; | |
48 |
|
49 | |||
49 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |
50 |
|
51 | |||
51 | #endif // QSCATTERSERIES_H |
|
52 | #endif // QSCATTERSERIES_H |
@@ -1,429 +1,430 | |||||
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 "qscatterseries.h" |
|
5 | #include "qscatterseries.h" | |
6 | #include <qlinechartseries.h> |
|
6 | #include <qlinechartseries.h> | |
7 | #include <qbarset.h> |
|
7 | #include <qbarset.h> | |
8 | #include <qbarcategory.h> |
|
8 | #include <qbarcategory.h> | |
9 | #include <barchartseries.h> |
|
9 | #include <barchartseries.h> | |
10 | #include <stackedbarchartseries.h> |
|
10 | #include <stackedbarchartseries.h> | |
11 | #include <percentbarchartseries.h> |
|
11 | #include <percentbarchartseries.h> | |
12 | #include <QPushButton> |
|
12 | #include <QPushButton> | |
13 | #include <QComboBox> |
|
13 | #include <QComboBox> | |
14 | #include <QSpinBox> |
|
14 | #include <QSpinBox> | |
15 | #include <QCheckBox> |
|
15 | #include <QCheckBox> | |
16 | #include <QGridLayout> |
|
16 | #include <QGridLayout> | |
17 | #include <QHBoxLayout> |
|
17 | #include <QHBoxLayout> | |
18 | #include <QLabel> |
|
18 | #include <QLabel> | |
19 | #include <QSpacerItem> |
|
19 | #include <QSpacerItem> | |
20 | #include <QMessageBox> |
|
20 | #include <QMessageBox> | |
21 | #include <cmath> |
|
21 | #include <cmath> | |
22 | #include <QDebug> |
|
22 | #include <QDebug> | |
23 | #include <QStandardItemModel> |
|
23 | #include <QStandardItemModel> | |
24 |
|
24 | |||
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | QTCOMMERCIALCHART_USE_NAMESPACE | |
27 |
|
27 | |||
28 | MainWidget::MainWidget(QWidget *parent) : |
|
28 | MainWidget::MainWidget(QWidget *parent) : | |
29 | QWidget(parent) |
|
29 | QWidget(parent) | |
30 | { |
|
30 | { | |
31 | m_chartWidget = new QChartView(this); |
|
31 | m_chartWidget = new QChartView(this); | |
32 | m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand); |
|
32 | m_chartWidget->setRubberBandPolicy(QChartView::HorizonalRubberBand); | |
33 |
|
33 | |||
34 | // Grid layout for the controls for configuring the chart widget |
|
34 | // Grid layout for the controls for configuring the chart widget | |
35 | QGridLayout *grid = new QGridLayout(); |
|
35 | QGridLayout *grid = new QGridLayout(); | |
36 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
36 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
37 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
37 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
38 | grid->addWidget(addSeriesButton, 0, 1); |
|
38 | grid->addWidget(addSeriesButton, 0, 1); | |
39 | initBackroundCombo(grid); |
|
39 | initBackroundCombo(grid); | |
40 | initScaleControls(grid); |
|
40 | initScaleControls(grid); | |
41 | initThemeCombo(grid); |
|
41 | initThemeCombo(grid); | |
42 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
42 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
43 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); |
|
43 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartWidget, SLOT(setZoomEnabled(bool))); | |
44 | zoomCheckBox->setChecked(true); |
|
44 | zoomCheckBox->setChecked(true); | |
45 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
45 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
46 | // add row with empty label to make all the other rows static |
|
46 | // add row with empty label to make all the other rows static | |
47 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
47 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
48 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
48 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
49 |
|
49 | |||
50 | // Another grid layout as a main layout |
|
50 | // Another grid layout as a main layout | |
51 | QGridLayout *mainLayout = new QGridLayout(); |
|
51 | QGridLayout *mainLayout = new QGridLayout(); | |
52 | mainLayout->addLayout(grid, 0, 0); |
|
52 | mainLayout->addLayout(grid, 0, 0); | |
53 |
|
53 | |||
54 | // Init series type specific controls |
|
54 | // Init series type specific controls | |
55 | initPieControls(); |
|
55 | initPieControls(); | |
56 | mainLayout->addLayout(m_pieLayout, 2, 0); |
|
56 | mainLayout->addLayout(m_pieLayout, 2, 0); | |
57 | // Scatter series specific settings |
|
57 | // Scatter series specific settings | |
58 | // m_scatterLayout = new QGridLayout(); |
|
58 | // m_scatterLayout = new QGridLayout(); | |
59 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); |
|
59 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); | |
60 | // m_scatterLayout->setEnabled(false); |
|
60 | // m_scatterLayout->setEnabled(false); | |
61 | // mainLayout->addLayout(m_scatterLayout, 1, 0); |
|
61 | // mainLayout->addLayout(m_scatterLayout, 1, 0); | |
62 |
|
62 | |||
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 |
|
66 | |||
67 | // force an update to test data |
|
67 | // force an update to test data | |
68 | testDataChanged(0); |
|
68 | testDataChanged(0); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | // Combo box for selecting the chart's background |
|
71 | // Combo box for selecting the chart's background | |
72 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
72 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
73 | { |
|
73 | { | |
74 | QComboBox *backgroundCombo = new QComboBox(this); |
|
74 | QComboBox *backgroundCombo = new QComboBox(this); | |
75 | backgroundCombo->addItem("Color"); |
|
75 | backgroundCombo->addItem("Color"); | |
76 | backgroundCombo->addItem("Gradient"); |
|
76 | backgroundCombo->addItem("Gradient"); | |
77 | backgroundCombo->addItem("Image"); |
|
77 | backgroundCombo->addItem("Image"); | |
78 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
78 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
79 | this, SLOT(backgroundChanged(int))); |
|
79 | this, SLOT(backgroundChanged(int))); | |
80 |
|
80 | |||
81 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
81 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
82 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
82 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | // Scale related controls (auto-scale vs. manual min-max values) |
|
85 | // Scale related controls (auto-scale vs. manual min-max values) | |
86 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
86 | void MainWidget::initScaleControls(QGridLayout *grid) | |
87 | { |
|
87 | { | |
88 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
88 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
89 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
89 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
90 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
90 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
91 | m_xMinSpin = new QSpinBox(); |
|
91 | m_xMinSpin = new QSpinBox(); | |
92 | m_xMinSpin->setMinimum(INT_MIN); |
|
92 | m_xMinSpin->setMinimum(INT_MIN); | |
93 | m_xMinSpin->setMaximum(INT_MAX); |
|
93 | m_xMinSpin->setMaximum(INT_MAX); | |
94 | m_xMinSpin->setValue(0); |
|
94 | m_xMinSpin->setValue(0); | |
95 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
95 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
96 | m_xMaxSpin = new QSpinBox(); |
|
96 | m_xMaxSpin = new QSpinBox(); | |
97 | m_xMaxSpin->setMinimum(INT_MIN); |
|
97 | m_xMaxSpin->setMinimum(INT_MIN); | |
98 | m_xMaxSpin->setMaximum(INT_MAX); |
|
98 | m_xMaxSpin->setMaximum(INT_MAX); | |
99 | m_xMaxSpin->setValue(10); |
|
99 | m_xMaxSpin->setValue(10); | |
100 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
100 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
101 | m_yMinSpin = new QSpinBox(); |
|
101 | m_yMinSpin = new QSpinBox(); | |
102 | m_yMinSpin->setMinimum(INT_MIN); |
|
102 | m_yMinSpin->setMinimum(INT_MIN); | |
103 | m_yMinSpin->setMaximum(INT_MAX); |
|
103 | m_yMinSpin->setMaximum(INT_MAX); | |
104 | m_yMinSpin->setValue(0); |
|
104 | m_yMinSpin->setValue(0); | |
105 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
105 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
106 | m_yMaxSpin = new QSpinBox(); |
|
106 | m_yMaxSpin = new QSpinBox(); | |
107 | m_yMaxSpin->setMinimum(INT_MIN); |
|
107 | m_yMaxSpin->setMinimum(INT_MIN); | |
108 | m_yMaxSpin->setMaximum(INT_MAX); |
|
108 | m_yMaxSpin->setMaximum(INT_MAX); | |
109 | m_yMaxSpin->setValue(10); |
|
109 | m_yMaxSpin->setValue(10); | |
110 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
110 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
111 |
|
111 | |||
112 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
112 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
113 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
113 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
114 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
114 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
115 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
115 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
116 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
116 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
117 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
117 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
118 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
118 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
119 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
119 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
120 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
120 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
121 |
|
121 | |||
122 | m_autoScaleCheck->setChecked(true); |
|
122 | m_autoScaleCheck->setChecked(true); | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | // Combo box for selecting theme |
|
125 | // Combo box for selecting theme | |
126 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
126 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
127 | { |
|
127 | { | |
128 | QComboBox *chartTheme = new QComboBox(); |
|
128 | QComboBox *chartTheme = new QComboBox(); | |
129 | chartTheme->addItem("Default"); |
|
129 | chartTheme->addItem("Default"); | |
130 | chartTheme->addItem("Vanilla"); |
|
130 | chartTheme->addItem("Vanilla"); | |
131 | chartTheme->addItem("Icy"); |
|
131 | chartTheme->addItem("Icy"); | |
132 | chartTheme->addItem("Grayscale"); |
|
132 | chartTheme->addItem("Grayscale"); | |
133 | chartTheme->addItem("Scientific"); |
|
133 | chartTheme->addItem("Scientific"); | |
134 | chartTheme->addItem("Unnamed1"); |
|
134 | chartTheme->addItem("Unnamed1"); | |
135 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
135 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
136 | this, SLOT(changeChartTheme(int))); |
|
136 | this, SLOT(changeChartTheme(int))); | |
137 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
137 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
138 | grid->addWidget(chartTheme, 8, 1); |
|
138 | grid->addWidget(chartTheme, 8, 1); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void MainWidget::initPieControls() |
|
141 | void MainWidget::initPieControls() | |
142 | { |
|
142 | { | |
143 | // Pie series specific settings |
|
143 | // Pie series specific settings | |
144 | // Pie size factory |
|
144 | // Pie size factory | |
145 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); |
|
145 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); | |
146 | pieSizeSpin->setMinimum(LONG_MIN); |
|
146 | pieSizeSpin->setMinimum(LONG_MIN); | |
147 | pieSizeSpin->setMaximum(LONG_MAX); |
|
147 | pieSizeSpin->setMaximum(LONG_MAX); | |
148 | pieSizeSpin->setValue(1.0); |
|
148 | pieSizeSpin->setValue(1.0); | |
149 | pieSizeSpin->setSingleStep(0.1); |
|
149 | pieSizeSpin->setSingleStep(0.1); | |
150 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); |
|
150 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); | |
151 | // Pie position |
|
151 | // Pie position | |
152 | QComboBox *piePosCombo = new QComboBox(this); |
|
152 | QComboBox *piePosCombo = new QComboBox(this); | |
153 | piePosCombo->addItem("Maximized"); |
|
153 | piePosCombo->addItem("Maximized"); | |
154 | piePosCombo->addItem("Top left"); |
|
154 | piePosCombo->addItem("Top left"); | |
155 | piePosCombo->addItem("Top right"); |
|
155 | piePosCombo->addItem("Top right"); | |
156 | piePosCombo->addItem("Bottom left"); |
|
156 | piePosCombo->addItem("Bottom left"); | |
157 | piePosCombo->addItem("Bottom right"); |
|
157 | piePosCombo->addItem("Bottom right"); | |
158 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), |
|
158 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), | |
159 | this, SLOT(setPiePosition(int))); |
|
159 | this, SLOT(setPiePosition(int))); | |
160 | m_pieLayout = new QGridLayout(); |
|
160 | m_pieLayout = new QGridLayout(); | |
161 | m_pieLayout->setEnabled(false); |
|
161 | m_pieLayout->setEnabled(false); | |
162 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); |
|
162 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); | |
163 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); |
|
163 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); | |
164 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); |
|
164 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); | |
165 | m_pieLayout->addWidget(piePosCombo, 1, 1); |
|
165 | m_pieLayout->addWidget(piePosCombo, 1, 1); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void MainWidget::addSeries() |
|
168 | void MainWidget::addSeries() | |
169 | { |
|
169 | { | |
170 | DataSerieDialog dialog(m_defaultSeriesName, this); |
|
170 | DataSerieDialog dialog(m_defaultSeriesName, this); | |
171 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); |
|
171 | connect(&dialog, SIGNAL(accepted(QString, QString)), this, SLOT(addSeries(QString, QString))); | |
172 | dialog.exec(); |
|
172 | dialog.exec(); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | void MainWidget::addSeries(QString series, QString data) |
|
175 | void MainWidget::addSeries(QString series, QString data) | |
176 | { |
|
176 | { | |
177 | qDebug() << "addSeries: " << series << " data: " << data; |
|
177 | qDebug() << "addSeries: " << series << " data: " << data; | |
178 | m_defaultSeriesName = series; |
|
178 | m_defaultSeriesName = series; | |
179 |
|
179 | |||
180 | // TODO: a dedicated data class for storing x and y values |
|
180 | // TODO: a dedicated data class for storing x and y values | |
181 | QList<qreal> x; |
|
181 | QList<qreal> x; | |
182 | QList<qreal> y; |
|
182 | QList<qreal> y; | |
183 |
|
183 | |||
184 | QBarSet *set0 = new QBarSet; |
|
184 | QBarSet *set0 = new QBarSet; | |
185 | QBarSet *set1 = new QBarSet; |
|
185 | QBarSet *set1 = new QBarSet; | |
186 | QBarSet *set2 = new QBarSet; |
|
186 | QBarSet *set2 = new QBarSet; | |
187 | QBarSet *set3 = new QBarSet; |
|
187 | QBarSet *set3 = new QBarSet; | |
188 | QBarSet *set4 = new QBarSet; |
|
188 | QBarSet *set4 = new QBarSet; | |
189 |
|
189 | |||
190 | if (data == "linear") { |
|
190 | if (data == "linear") { | |
191 | for (int i = 0; i < 20; i++) { |
|
191 | for (int i = 0; i < 20; i++) { | |
192 | x.append(i); |
|
192 | x.append(i); | |
193 | y.append(i); |
|
193 | y.append(i); | |
194 | } |
|
194 | } | |
195 | } else if (data == "linear, 1M") { |
|
195 | } else if (data == "linear, 1M") { | |
196 | // 1 million data points from 0.0001 to 100 |
|
196 | // 1 million data points from 0.0001 to 100 | |
197 | // TODO: What is the requirement? Should we be able to show this kind of data with |
|
197 | // TODO: What is the requirement? Should we be able to show this kind of data with | |
198 | // reasonable performance, or can we expect the application developer to do "data mining" |
|
198 | // reasonable performance, or can we expect the application developer to do "data mining" | |
199 | // for us, so that the count of data points given to QtCommercial Chart is always |
|
199 | // for us, so that the count of data points given to QtCommercial Chart is always | |
200 | // reasonable? |
|
200 | // reasonable? | |
201 | for (qreal i = 0; i < 100; i += 0.0001) { |
|
201 | for (qreal i = 0; i < 100; i += 0.0001) { | |
202 | x.append(i); |
|
202 | x.append(i); | |
203 | y.append(20); |
|
203 | y.append(20); | |
204 | } |
|
204 | } | |
205 | } else if (data == "SIN") { |
|
205 | } else if (data == "SIN") { | |
206 | for (int i = 0; i < 100; i++) { |
|
206 | for (int i = 0; i < 100; i++) { | |
207 | x.append(i); |
|
207 | x.append(i); | |
208 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
208 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
209 | } |
|
209 | } | |
210 | } else if (data == "SIN + random") { |
|
210 | } else if (data == "SIN + random") { | |
211 | for (qreal i = 0; i < 100; i += 0.1) { |
|
211 | for (qreal i = 0; i < 100; i += 0.1) { | |
212 | x.append(i + (rand() % 5)); |
|
212 | x.append(i + (rand() % 5)); | |
213 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
213 | y.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
214 | } |
|
214 | } | |
215 | } else if (data == "Table, 5 series"){ |
|
215 | } else if (data == "Table, 5 series"){ | |
216 | // Create some test data to chart |
|
216 | // Create some test data to chart | |
217 | *set0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12; |
|
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; |
|
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; |
|
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; |
|
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; |
|
221 | *set4 << 9 << 7 << 5 << 3 << 1 << 2 << 4 << 6 << 8 << 10 << 1 << 6; | |
222 | } else { |
|
222 | } else { | |
223 | // TODO: check if data has a valid file name |
|
223 | // TODO: check if data has a valid file name | |
224 | Q_ASSERT(false); |
|
224 | Q_ASSERT(false); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | // TODO: color of the series |
|
227 | // TODO: color of the series | |
228 | QChartSeries *newSeries = 0; |
|
228 | QChartSeries *newSeries = 0; | |
229 | if (series == "Scatter") { |
|
229 | if (series == "Scatter") { | |
230 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeScatter); |
|
230 | QScatterSeries *scatter = new QScatterSeries(); | |
231 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(newSeries); |
|
|||
232 | Q_ASSERT(scatterSeries); |
|
|||
233 | for (int i(0); i < x.count() && i < y.count(); i++) |
|
231 | for (int i(0); i < x.count() && i < y.count(); i++) | |
234 |
|
|
232 | (*scatter) << QPointF(x.at(i), y.at(i)); | |
|
233 | m_chartWidget->addSeries(scatter); | |||
235 | } else if (series == "Pie") { |
|
234 | } else if (series == "Pie") { | |
236 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); |
|
235 | newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypePie); | |
237 | Q_ASSERT(newSeries->setData(y)); |
|
236 | Q_ASSERT(newSeries->setData(y)); | |
238 | } else if (series == "Line") { |
|
237 | } else if (series == "Line") { | |
239 | // TODO: adding data to an existing line series does not give any visuals for some reason |
|
238 | // TODO: adding data to an existing line series does not give any visuals for some reason | |
240 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); |
|
239 | // newSeries = m_chartWidget->createSeries(QChartSeries::SeriesTypeLine); | |
241 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); |
|
240 | // QXYChartSeries *lineSeries = static_cast<QXYChartSeries *>(newSeries); | |
242 | // lineSeries->setColor(Qt::blue); |
|
241 | // lineSeries->setColor(Qt::blue); | |
243 | // for (int i(0); i < x.count() && i < y.count(); i++) { |
|
242 | // for (int i(0); i < x.count() && i < y.count(); i++) { | |
244 | // lineSeries->add(x.at(i), y.at(i)); |
|
243 | // lineSeries->add(x.at(i), y.at(i)); | |
245 | // } |
|
244 | // } | |
246 | //Q_ASSERT(newSeries->setData(x, y)); |
|
245 | //Q_ASSERT(newSeries->setData(x, y)); | |
247 | QLineChartSeries* series0 = new QLineChartSeries(); |
|
246 | QLineChartSeries* series0 = new QLineChartSeries(); | |
248 | for (int i(0); i < x.count() && i < y.count(); i++) |
|
247 | for (int i(0); i < x.count() && i < y.count(); i++) | |
249 | series0->add(x.at(i), y.at(i)); |
|
248 | series0->add(x.at(i), y.at(i)); | |
250 | m_chartWidget->addSeries(series0); |
|
249 | m_chartWidget->addSeries(series0); | |
251 | newSeries = series0; |
|
250 | newSeries = series0; | |
252 | } else if (series == "Bar") { |
|
251 | } else if (series == "Bar") { | |
253 | qDebug() << "Bar chart series"; |
|
252 | qDebug() << "Bar chart series"; | |
254 |
|
253 | |||
255 | QBarCategory *category = new QBarCategory; |
|
254 | QBarCategory *category = new QBarCategory; | |
256 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
255 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
257 |
|
256 | |||
258 | BarChartSeries* series0 = new BarChartSeries(category, this); |
|
257 | BarChartSeries* series0 = new BarChartSeries(category, this); | |
259 |
|
258 | |||
260 | series0->addBarSet(set0); |
|
259 | series0->addBarSet(set0); | |
261 | series0->addBarSet(set1); |
|
260 | series0->addBarSet(set1); | |
262 | series0->addBarSet(set2); |
|
261 | series0->addBarSet(set2); | |
263 | series0->addBarSet(set3); |
|
262 | series0->addBarSet(set3); | |
264 | series0->addBarSet(set4); |
|
263 | series0->addBarSet(set4); | |
265 |
|
264 | |||
266 | m_chartWidget->addSeries(series0); |
|
265 | m_chartWidget->addSeries(series0); | |
267 | newSeries = series0; |
|
266 | newSeries = series0; | |
268 | } else if (series == "StackedBar") { |
|
267 | } else if (series == "StackedBar") { | |
269 | qDebug() << "Stacked bar chart series"; |
|
268 | qDebug() << "Stacked bar chart series"; | |
270 |
|
269 | |||
271 | QBarCategory *category = new QBarCategory; |
|
270 | QBarCategory *category = new QBarCategory; | |
272 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
271 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
273 |
|
272 | |||
274 | StackedBarChartSeries* series0 = new StackedBarChartSeries(category, this); |
|
273 | StackedBarChartSeries* series0 = new StackedBarChartSeries(category, this); | |
275 |
|
274 | |||
276 | series0->addBarSet(set0); |
|
275 | series0->addBarSet(set0); | |
277 | series0->addBarSet(set1); |
|
276 | series0->addBarSet(set1); | |
278 | series0->addBarSet(set2); |
|
277 | series0->addBarSet(set2); | |
279 | series0->addBarSet(set3); |
|
278 | series0->addBarSet(set3); | |
280 | series0->addBarSet(set4); |
|
279 | series0->addBarSet(set4); | |
281 |
|
280 | |||
282 | m_chartWidget->addSeries(series0); |
|
281 | m_chartWidget->addSeries(series0); | |
283 | newSeries = series0; |
|
282 | newSeries = series0; | |
284 | } else if (series == "PercentBar") { |
|
283 | } else if (series == "PercentBar") { | |
285 | qDebug() << "Percent bar chart series"; |
|
284 | qDebug() << "Percent bar chart series"; | |
286 |
|
285 | |||
287 | QBarCategory *category = new QBarCategory; |
|
286 | QBarCategory *category = new QBarCategory; | |
288 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; |
|
287 | *category << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "June" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; | |
289 |
|
288 | |||
290 | PercentBarChartSeries* series0 = new PercentBarChartSeries(category, this); |
|
289 | PercentBarChartSeries* series0 = new PercentBarChartSeries(category, this); | |
291 |
|
290 | |||
292 | series0->addBarSet(set0); |
|
291 | series0->addBarSet(set0); | |
293 | series0->addBarSet(set1); |
|
292 | series0->addBarSet(set1); | |
294 | series0->addBarSet(set2); |
|
293 | series0->addBarSet(set2); | |
295 | series0->addBarSet(set3); |
|
294 | series0->addBarSet(set3); | |
296 | series0->addBarSet(set4); |
|
295 | series0->addBarSet(set4); | |
297 |
|
296 | |||
298 | m_chartWidget->addSeries(series0); |
|
297 | m_chartWidget->addSeries(series0); | |
299 | newSeries = series0; |
|
298 | newSeries = series0; | |
300 | } else { |
|
299 | } else { | |
301 | qDebug() << "Something weird going on in MainWidget::addSeries"; |
|
300 | qDebug() << "Something weird going on in MainWidget::addSeries"; | |
302 | } |
|
301 | } | |
303 |
|
302 | |||
304 | setCurrentSeries(newSeries); |
|
303 | setCurrentSeries(newSeries); | |
305 | } |
|
304 | } | |
306 |
|
305 | |||
307 | void MainWidget::setCurrentSeries(QChartSeries *series) |
|
306 | void MainWidget::setCurrentSeries(QChartSeries *series) | |
308 | { |
|
307 | { | |
309 | m_currentSeries = series; |
|
308 | if (series) { | |
310 | switch (m_currentSeries->type()) { |
|
309 | m_currentSeries = series; | |
311 | case QChartSeries::SeriesTypeLine: |
|
310 | switch (m_currentSeries->type()) { | |
312 | break; |
|
311 | case QChartSeries::SeriesTypeLine: | |
313 | case QChartSeries::SeriesTypeScatter: |
|
312 | break; | |
314 | break; |
|
313 | case QChartSeries::SeriesTypeScatter: | |
315 | case QChartSeries::SeriesTypePie: |
|
314 | break; | |
316 | break; |
|
315 | case QChartSeries::SeriesTypePie: | |
317 | case QChartSeries::SeriesTypeBar: |
|
316 | break; | |
318 | qDebug() << "setCurrentSeries (bar)"; |
|
317 | case QChartSeries::SeriesTypeBar: | |
319 | break; |
|
318 | qDebug() << "setCurrentSeries (bar)"; | |
320 | case QChartSeries::SeriesTypeStackedBar: |
|
319 | break; | |
321 | qDebug() << "setCurrentSeries (Stackedbar)"; |
|
320 | case QChartSeries::SeriesTypeStackedBar: | |
322 | break; |
|
321 | qDebug() << "setCurrentSeries (Stackedbar)"; | |
323 | case QChartSeries::SeriesTypePercentBar: |
|
322 | break; | |
324 | qDebug() << "setCurrentSeries (Percentbar)"; |
|
323 | case QChartSeries::SeriesTypePercentBar: | |
325 | break; |
|
324 | qDebug() << "setCurrentSeries (Percentbar)"; | |
326 | default: |
|
325 | break; | |
327 | Q_ASSERT(false); |
|
326 | default: | |
328 | break; |
|
327 | Q_ASSERT(false); | |
|
328 | break; | |||
|
329 | } | |||
329 | } |
|
330 | } | |
330 | } |
|
331 | } | |
331 |
|
332 | |||
332 | void MainWidget::testDataChanged(int itemIndex) |
|
333 | void MainWidget::testDataChanged(int itemIndex) | |
333 | { |
|
334 | { | |
334 | qDebug() << "testDataChanged: " << itemIndex; |
|
335 | qDebug() << "testDataChanged: " << itemIndex; | |
335 |
|
336 | |||
336 | // switch (itemIndex) { |
|
337 | // switch (itemIndex) { | |
337 | // case 0: { |
|
338 | // case 0: { | |
338 | // QList<QChartDataPoint> data; |
|
339 | // QList<QChartDataPoint> data; | |
339 | // for (int x = 0; x < 20; x++) { |
|
340 | // for (int x = 0; x < 20; x++) { | |
340 | // data.append(QChartDataPoint() << x << x / 2); |
|
341 | // data.append(QChartDataPoint() << x << x / 2); | |
341 | // } |
|
342 | // } | |
342 | // m_chartWidget->setData(data); |
|
343 | // m_chartWidget->setData(data); | |
343 | // break; |
|
344 | // break; | |
344 | // } |
|
345 | // } | |
345 | // case 1: { |
|
346 | // case 1: { | |
346 | // QList<QChartDataPoint> data; |
|
347 | // QList<QChartDataPoint> data; | |
347 | // for (int x = 0; x < 100; x++) { |
|
348 | // for (int x = 0; x < 100; x++) { | |
348 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); |
|
349 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); | |
349 | // } |
|
350 | // } | |
350 | // m_chartWidget->setData(data); |
|
351 | // m_chartWidget->setData(data); | |
351 | // break; |
|
352 | // break; | |
352 | // } |
|
353 | // } | |
353 | // case 2: { |
|
354 | // case 2: { | |
354 | // QList<QChartDataPoint> data; |
|
355 | // QList<QChartDataPoint> data; | |
355 | // for (int x = 0; x < 1000; x++) { |
|
356 | // for (int x = 0; x < 1000; x++) { | |
356 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
357 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
357 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); |
|
358 | // data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
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)); | |
359 | // } |
|
360 | // } | |
360 | // m_chartWidget->setData(data); |
|
361 | // m_chartWidget->setData(data); | |
361 | // break; |
|
362 | // break; | |
362 | // } |
|
363 | // } | |
363 | // default: |
|
364 | // default: | |
364 | // break; |
|
365 | // break; | |
365 | // } |
|
366 | // } | |
366 | } |
|
367 | } | |
367 |
|
368 | |||
368 | void MainWidget::backgroundChanged(int itemIndex) |
|
369 | void MainWidget::backgroundChanged(int itemIndex) | |
369 | { |
|
370 | { | |
370 | qDebug() << "backgroundChanged: " << itemIndex; |
|
371 | qDebug() << "backgroundChanged: " << itemIndex; | |
371 | } |
|
372 | } | |
372 |
|
373 | |||
373 | void MainWidget::autoScaleChanged(int value) |
|
374 | void MainWidget::autoScaleChanged(int value) | |
374 | { |
|
375 | { | |
375 | if (value) { |
|
376 | if (value) { | |
376 | // TODO: enable auto scaling |
|
377 | // TODO: enable auto scaling | |
377 | } else { |
|
378 | } else { | |
378 | // TODO: set scaling manually (and disable auto scaling) |
|
379 | // TODO: set scaling manually (and disable auto scaling) | |
379 | } |
|
380 | } | |
380 |
|
381 | |||
381 | m_xMinSpin->setEnabled(!value); |
|
382 | m_xMinSpin->setEnabled(!value); | |
382 | m_xMaxSpin->setEnabled(!value); |
|
383 | m_xMaxSpin->setEnabled(!value); | |
383 | m_yMinSpin->setEnabled(!value); |
|
384 | m_yMinSpin->setEnabled(!value); | |
384 | m_yMaxSpin->setEnabled(!value); |
|
385 | m_yMaxSpin->setEnabled(!value); | |
385 | } |
|
386 | } | |
386 |
|
387 | |||
387 | void MainWidget::xMinChanged(int value) |
|
388 | void MainWidget::xMinChanged(int value) | |
388 | { |
|
389 | { | |
389 | qDebug() << "xMinChanged: " << value; |
|
390 | qDebug() << "xMinChanged: " << value; | |
390 | } |
|
391 | } | |
391 |
|
392 | |||
392 | void MainWidget::xMaxChanged(int value) |
|
393 | void MainWidget::xMaxChanged(int value) | |
393 | { |
|
394 | { | |
394 | qDebug() << "xMaxChanged: " << value; |
|
395 | qDebug() << "xMaxChanged: " << value; | |
395 | } |
|
396 | } | |
396 |
|
397 | |||
397 | void MainWidget::yMinChanged(int value) |
|
398 | void MainWidget::yMinChanged(int value) | |
398 | { |
|
399 | { | |
399 | qDebug() << "yMinChanged: " << value; |
|
400 | qDebug() << "yMinChanged: " << value; | |
400 | } |
|
401 | } | |
401 |
|
402 | |||
402 | void MainWidget::yMaxChanged(int value) |
|
403 | void MainWidget::yMaxChanged(int value) | |
403 | { |
|
404 | { | |
404 | qDebug() << "yMaxChanged: " << value; |
|
405 | qDebug() << "yMaxChanged: " << value; | |
405 | } |
|
406 | } | |
406 |
|
407 | |||
407 | void MainWidget::changeChartTheme(int themeIndex) |
|
408 | void MainWidget::changeChartTheme(int themeIndex) | |
408 | { |
|
409 | { | |
409 | qDebug() << "changeChartTheme: " << themeIndex; |
|
410 | qDebug() << "changeChartTheme: " << themeIndex; | |
410 | m_chartWidget->setChartTheme((QChart::ChartTheme) themeIndex); |
|
411 | m_chartWidget->setChartTheme((QChart::ChartTheme) themeIndex); | |
411 | //TODO: remove this hack. This is just to make it so that theme change is seen immediately. |
|
412 | //TODO: remove this hack. This is just to make it so that theme change is seen immediately. | |
412 | QSize s = size(); |
|
413 | QSize s = size(); | |
413 | s.setWidth(s.width()+1); |
|
414 | s.setWidth(s.width()+1); | |
414 | resize(s); |
|
415 | resize(s); | |
415 | } |
|
416 | } | |
416 |
|
417 | |||
417 | void MainWidget::setPieSizeFactor(double size) |
|
418 | void MainWidget::setPieSizeFactor(double size) | |
418 | { |
|
419 | { | |
419 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
420 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
420 | if (pie) |
|
421 | if (pie) | |
421 | pie->setSizeFactor(qreal(size)); |
|
422 | pie->setSizeFactor(qreal(size)); | |
422 | } |
|
423 | } | |
423 |
|
424 | |||
424 | void MainWidget::setPiePosition(int position) |
|
425 | void MainWidget::setPiePosition(int position) | |
425 | { |
|
426 | { | |
426 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); |
|
427 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
427 | if (pie) |
|
428 | if (pie) | |
428 | pie->setPosition((QPieSeries::PiePosition) position); |
|
429 | pie->setPosition((QPieSeries::PiePosition) position); | |
429 | } |
|
430 | } |
General Comments 0
You need to be logged in to leave comments.
Login now