@@ -18,14 +18,9 int main(int argc, char *argv[]) | |||||
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; |
@@ -1,5 +1,6 | |||||
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> | |
@@ -54,13 +55,11 void DeclarativeSeries::initSeries() | |||||
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: |
@@ -21,30 +21,17 QScatterSeries::~QScatterSeries() | |||||
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() | |
@@ -52,17 +39,14 QList<QPointF> QScatterSeries::data() | |||||
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" |
@@ -18,21 +18,28 public: | |||||
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) |
@@ -3,6 +3,7 | |||||
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 | |||
@@ -15,9 +16,8 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 |
@@ -60,10 +60,7 void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem * | |||||
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)); |
@@ -2,6 +2,7 | |||||
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> | |
@@ -227,7 +228,10 void MainWidget::addSeries(QString series, QString data) | |||||
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)); |
@@ -9,6 +9,69 Rectangle { | |||||
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 | |
@@ -33,6 +96,14 Rectangle { | |||||
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 { |
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