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