##// END OF EJS Templates
Refactoring QML impl for series
Tero Ahola -
r846:accf902f8269
parent child
Show More
@@ -1,65 +1,66
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativechart.h"
21 #include "declarativechart.h"
22 #include <QPainter>
22 #include <QPainter>
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
26 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
27 : QDeclarativeItem(parent),
27 : QDeclarativeItem(parent),
28 m_chart(new QChart(this))
28 m_chart(new QChart(this))
29 {
29 {
30 m_chart->setAnimationOptions(QChart::SeriesAnimations);
30 setFlag(QGraphicsItem::ItemHasNoContents, false);
31 setFlag(QGraphicsItem::ItemHasNoContents, false);
31 }
32 }
32
33
33 DeclarativeChart::~DeclarativeChart()
34 DeclarativeChart::~DeclarativeChart()
34 {
35 {
35 delete m_chart;
36 delete m_chart;
36 }
37 }
37
38
38 QChart::ChartTheme DeclarativeChart::theme()
39 QChart::ChartTheme DeclarativeChart::theme()
39 {
40 {
40 return m_chart->theme();
41 return m_chart->theme();
41 }
42 }
42
43
43 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
44 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
44 {
45 {
45 Q_UNUSED(oldGeometry)
46 Q_UNUSED(oldGeometry)
46
47
47 if (newGeometry.isValid()) {
48 if (newGeometry.isValid()) {
48 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
49 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
49 m_chart->resize(newGeometry.width(), newGeometry.height());
50 m_chart->resize(newGeometry.width(), newGeometry.height());
50 }
51 }
51 }
52 }
52 }
53 }
53
54
54 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
55 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
55 {
56 {
56 Q_UNUSED(option)
57 Q_UNUSED(option)
57 Q_UNUSED(widget)
58 Q_UNUSED(widget)
58
59
59 // TODO: optimized?
60 // TODO: optimized?
60 painter->setRenderHint(QPainter::Antialiasing, true);
61 painter->setRenderHint(QPainter::Antialiasing, true);
61 }
62 }
62
63
63 #include "moc_declarativechart.cpp"
64 #include "moc_declarativechart.cpp"
64
65
65 QTCOMMERCIALCHART_END_NAMESPACE
66 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,51 +1,45
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativelineseries.h"
21 #include "declarativelineseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qlineseries.h"
24 #include "qlineseries.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
28 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
29 QLineSeries(parent)
29 QLineSeries(parent)
30 {
30 {
31 }
31 }
32
32
33 void DeclarativeLineSeries::componentComplete()
33 QSeries *DeclarativeLineSeries::series()
34 {
34 {
35 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
35 return this;
36
37 if (declarativeChart) {
38 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
39 Q_ASSERT(chart);
40 chart->addSeries(this);
41 }
42 }
36 }
43
37
44 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeLineSeries::points()
38 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeLineSeries::points()
45 {
39 {
46 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
40 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
47 }
41 }
48
42
49 #include "moc_declarativelineseries.cpp"
43 #include "moc_declarativelineseries.cpp"
50
44
51 QTCOMMERCIALCHART_END_NAMESPACE
45 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,46 +1,46
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVELINESERIES_H
21 #ifndef DECLARATIVELINESERIES_H
22 #define DECLARATIVELINESERIES_H
22 #define DECLARATIVELINESERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qlineseries.h"
25 #include "qlineseries.h"
26 #include "declarativexyseries.h"
26 #include "declarativexyseries.h"
27 #include <QDeclarativeParserStatus>
27 #include <QDeclarativeParserStatus>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries
31 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
35
35
36 public:
36 public:
37 explicit DeclarativeLineSeries(QObject *parent = 0);
37 explicit DeclarativeLineSeries(QObject *parent = 0);
38
38
39 public:
39 public:
40 void componentComplete();
40 QSeries *series();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 };
42 };
43
43
44 QTCOMMERCIALCHART_END_NAMESPACE
44 QTCOMMERCIALCHART_END_NAMESPACE
45
45
46 #endif // DECLARATIVELINESERIES_H
46 #endif // DECLARATIVELINESERIES_H
@@ -1,52 +1,45
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativescatterseries.h"
21 #include "declarativescatterseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qscatterseries.h"
24 #include "qscatterseries.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
28 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
29 QScatterSeries(parent)
29 QScatterSeries(parent)
30 {
30 {
31 }
31 }
32
32
33 void DeclarativeScatterSeries::componentComplete()
33 QSeries *DeclarativeScatterSeries::series()
34 {
34 {
35 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
35 return this;
36
37 if (declarativeChart) {
38 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
39 Q_ASSERT(chart);
40 qDebug() << "chart:" << chart;
41 chart->addSeries(this);
42 }
43 }
36 }
44
37
45 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points()
38 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points()
46 {
39 {
47 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
40 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
48 }
41 }
49
42
50 #include "moc_declarativescatterseries.cpp"
43 #include "moc_declarativescatterseries.cpp"
51
44
52 QTCOMMERCIALCHART_END_NAMESPACE
45 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,46 +1,46
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVESCATTERSERIES_H
21 #ifndef DECLARATIVESCATTERSERIES_H
22 #define DECLARATIVESCATTERSERIES_H
22 #define DECLARATIVESCATTERSERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qscatterseries.h"
25 #include "qscatterseries.h"
26 #include "declarativexyseries.h"
26 #include "declarativexyseries.h"
27 #include <QDeclarativeParserStatus>
27 #include <QDeclarativeParserStatus>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries
31 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
35
35
36 public:
36 public:
37 explicit DeclarativeScatterSeries(QObject *parent = 0);
37 explicit DeclarativeScatterSeries(QObject *parent = 0);
38
38
39 public:
39 public:
40 void componentComplete();
40 QSeries *series();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 };
42 };
43
43
44 QTCOMMERCIALCHART_END_NAMESPACE
44 QTCOMMERCIALCHART_END_NAMESPACE
45
45
46 #endif // DECLARATIVESCATTERSERIES_H
46 #endif // DECLARATIVESCATTERSERIES_H
@@ -1,50 +1,44
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativesplineseries.h"
21 #include "declarativesplineseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include "qchart.h"
23 #include "qchart.h"
24
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
26
27 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
27 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
28 QSplineSeries(parent)
28 QSplineSeries(parent)
29 {
29 {
30 }
30 }
31
31
32 void DeclarativeSplineSeries::componentComplete()
32 QSeries *DeclarativeSplineSeries::series()
33 {
33 {
34 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
34 return this;
35
36 if (declarativeChart) {
37 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
38 Q_ASSERT(chart);
39 chart->addSeries(this);
40 }
41 }
35 }
42
36
43 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeSplineSeries::points()
37 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeSplineSeries::points()
44 {
38 {
45 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
39 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
46 }
40 }
47
41
48 #include "moc_declarativesplineseries.cpp"
42 #include "moc_declarativesplineseries.cpp"
49
43
50 QTCOMMERCIALCHART_END_NAMESPACE
44 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,46 +1,46
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVESPLINESERIES_H
21 #ifndef DECLARATIVESPLINESERIES_H
22 #define DECLARATIVESPLINESERIES_H
22 #define DECLARATIVESPLINESERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qsplineseries.h"
25 #include "qsplineseries.h"
26 #include "declarativexyseries.h"
26 #include "declarativexyseries.h"
27 #include <QDeclarativeParserStatus>
27 #include <QDeclarativeParserStatus>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries
31 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
35
35
36 public:
36 public:
37 explicit DeclarativeSplineSeries(QObject *parent = 0);
37 explicit DeclarativeSplineSeries(QObject *parent = 0);
38
38
39 public:
39 public:
40 virtual void componentComplete();
40 QSeries *series();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
42 };
42 };
43
43
44 QTCOMMERCIALCHART_END_NAMESPACE
44 QTCOMMERCIALCHART_END_NAMESPACE
45
45
46 #endif // DECLARATIVESPLINESERIES_H
46 #endif // DECLARATIVESPLINESERIES_H
@@ -1,47 +1,63
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 //#include "DeclarativeXySeries.h"
21 //#include "DeclarativeXySeries.h"
22 #include "declarativexyseries.h"
22 #include "declarativexyseries.h"
23 #include "qxyseries.h"
23 #include "qxyseries.h"
24 #include "declarativechart.h"
25 #include <QObject>
24
26
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
28
27 DeclarativeXySeries::DeclarativeXySeries()
29 DeclarativeXySeries::DeclarativeXySeries()
28 {
30 {
29 }
31 }
30
32
31 DeclarativeXySeries::~DeclarativeXySeries()
33 DeclarativeXySeries::~DeclarativeXySeries()
32 {
34 {
33 }
35 }
34
36
35 void DeclarativeXySeries::classBegin()
37 void DeclarativeXySeries::classBegin()
36 {
38 {
37 }
39 }
38
40
41 void DeclarativeXySeries::componentComplete()
42 {
43 QSeries *thisObj = reinterpret_cast<QSeries *>(series());
44 // QSeries *thisObj = qobject_cast<QSeries *>(this);
45 // Q_ASSERT(thisObj);
46 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(thisObj->parent());
47
48 if (declarativeChart) {
49 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
50 Q_ASSERT(chart);
51 chart->addSeries(thisObj);
52 }
53 }
54
39 void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
55 void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
40 DeclarativeXyPoint *element)
56 DeclarativeXyPoint *element)
41 {
57 {
42 QXYSeries *series = qobject_cast<QXYSeries *>(list->object);
58 QXYSeries *series = qobject_cast<QXYSeries *>(list->object);
43 if (series)
59 if (series)
44 series->append(QPointF(element->x(), element->y()));
60 series->append(element->x(), element->y());
45 }
61 }
46
62
47 QTCOMMERCIALCHART_END_NAMESPACE
63 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,55 +1,57
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVE_XY_SERIES_H
21 #ifndef DECLARATIVE_XY_SERIES_H
22 #define DECLARATIVE_XY_SERIES_H
22 #define DECLARATIVE_XY_SERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "declarativexypoint.h"
25 #include "declarativexypoint.h"
26 #include <QDeclarativeParserStatus>
26 #include <QDeclarativeParserStatus>
27 #include <QDeclarativeListProperty>
27 #include <QDeclarativeListProperty>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QChart;
31 class QChart;
32 class QSeries;
32
33
33 class DeclarativeXySeries : public QDeclarativeParserStatus
34 class DeclarativeXySeries : public QDeclarativeParserStatus
34 {
35 {
35 Q_INTERFACES(QDeclarativeParserStatus)
36 Q_INTERFACES(QDeclarativeParserStatus)
36
37
37 public:
38 public:
38 explicit DeclarativeXySeries();
39 explicit DeclarativeXySeries();
39 ~DeclarativeXySeries();
40 ~DeclarativeXySeries();
40
41
41 public: // from QDeclarativeParserStatus
42 public: // from QDeclarativeParserStatus
42 virtual void classBegin();
43 virtual void classBegin();
43 virtual void componentComplete() = 0;
44 virtual void componentComplete();
44
45
45 public:
46 public:
47 virtual QSeries *series() = 0;
46 virtual QDeclarativeListProperty<DeclarativeXyPoint> points() = 0;
48 virtual QDeclarativeListProperty<DeclarativeXyPoint> points() = 0;
47
49
48 public Q_SLOTS:
50 public Q_SLOTS:
49 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
51 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
50 DeclarativeXyPoint *element);
52 DeclarativeXyPoint *element);
51 };
53 };
52
54
53 QTCOMMERCIALCHART_END_NAMESPACE
55 QTCOMMERCIALCHART_END_NAMESPACE
54
56
55 #endif // DECLARATIVE_XY_SERIES_H
57 #endif // DECLARATIVE_XY_SERIES_H
@@ -1,103 +1,104
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "linechartitem_p.h"
21 #include "linechartitem_p.h"
22 #include "qlineseries.h"
22 #include "qlineseries.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include <QPainter>
24 #include <QPainter>
25
25
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 //TODO: optimize : remove points which are not visible
29 //TODO: optimize : remove points which are not visible
30
30
31 LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter):XYChartItem(series,presenter),
31 LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter):XYChartItem(series,presenter),
32 m_series(series),
32 m_series(series),
33 m_pointsVisible(false)
33 m_pointsVisible(false)
34 {
34 {
35 setZValue(ChartPresenter::LineChartZValue);
35 setZValue(ChartPresenter::LineChartZValue);
36 QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated()));
36 QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated()));
37 handleUpdated();
37 handleUpdated();
38 }
38 }
39
39
40 QRectF LineChartItem::boundingRect() const
40 QRectF LineChartItem::boundingRect() const
41 {
41 {
42 return m_rect;
42 return m_rect;
43 }
43 }
44
44
45 QPainterPath LineChartItem::shape() const
45 QPainterPath LineChartItem::shape() const
46 {
46 {
47 return m_path;
47 return m_path;
48 }
48 }
49
49
50 void LineChartItem::setLayout(QVector<QPointF>& points)
50 void LineChartItem::setLayout(QVector<QPointF>& points)
51 {
51 {
52 // qDebug() << "line: " << points.count();
53
52 if(points.size()==0)
54 if(points.size()==0)
53 {
55 {
54 XYChartItem::setLayout(points);
56 XYChartItem::setLayout(points);
55 return;
57 return;
56 }
58 }
57
59
58 QList<QGraphicsItem*> items = m_items.childItems();
60 QList<QGraphicsItem*> items = m_items.childItems();
59
61
60 QPainterPath linePath(points.at(0));
62 QPainterPath linePath(points.at(0));
61
63
62 for(int i=1; i< points.size();i++) {
64 for(int i=1; i< points.size();i++) {
63 linePath.lineTo(points.at(i));
65 linePath.lineTo(points.at(i));
64 }
66 }
65
67
66 prepareGeometryChange();
68 prepareGeometryChange();
67 m_path = linePath;
69 m_path = linePath;
68 m_rect = linePath.boundingRect();
70 m_rect = linePath.boundingRect();
69
71
70 XYChartItem::setLayout(points);
72 XYChartItem::setLayout(points);
71
72 }
73 }
73
74
74 void LineChartItem::handleUpdated()
75 void LineChartItem::handleUpdated()
75 {
76 {
76 m_pointsVisible = m_series->pointsVisible();
77 m_pointsVisible = m_series->pointsVisible();
77 m_linePen = m_series->pen();
78 m_linePen = m_series->pen();
78 m_pointPen = m_series->pen();
79 m_pointPen = m_series->pen();
79 m_pointPen.setWidthF(2*m_pointPen.width());
80 m_pointPen.setWidthF(2*m_pointPen.width());
80 update();
81 update();
81 }
82 }
82
83
83 //painter
84 //painter
84
85
85 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
86 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
86 {
87 {
87 Q_UNUSED(widget)
88 Q_UNUSED(widget)
88 Q_UNUSED(option)
89 Q_UNUSED(option)
89
90
90 painter->save();
91 painter->save();
91 painter->setPen(m_linePen);
92 painter->setPen(m_linePen);
92 painter->setClipRect(clipRect());
93 painter->setClipRect(clipRect());
93 painter->drawPath(m_path);
94 painter->drawPath(m_path);
94 if(m_pointsVisible){
95 if(m_pointsVisible){
95 painter->setPen(m_pointPen);
96 painter->setPen(m_pointPen);
96 painter->drawPoints(points());
97 painter->drawPoints(points());
97 }
98 }
98 painter->restore();
99 painter->restore();
99 }
100 }
100
101
101 #include "moc_linechartitem_p.cpp"
102 #include "moc_linechartitem_p.cpp"
102
103
103 QTCOMMERCIALCHART_END_NAMESPACE
104 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,190 +1,193
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "scatterchartitem_p.h"
21 #include "scatterchartitem_p.h"
22 #include "qscatterseries.h"
22 #include "qscatterseries.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include <QPainter>
24 #include <QPainter>
25 #include <QGraphicsScene>
25 #include <QGraphicsScene>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) :
29 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) :
30 XYChartItem(series,presenter),
30 XYChartItem(series,presenter),
31 m_series(series),
31 m_series(series),
32 m_items(this),
32 m_items(this),
33 m_shape(QScatterSeries::MarkerShapeRectangle),
33 m_shape(QScatterSeries::MarkerShapeRectangle),
34 m_size(15)
34 m_size(15)
35
35
36 {
36 {
37 QObject::connect(m_series,SIGNAL(updated()), this, SLOT(handleUpdated()));
37 QObject::connect(m_series,SIGNAL(updated()), this, SLOT(handleUpdated()));
38
38
39 setZValue(ChartPresenter::ScatterSeriesZValue);
39 setZValue(ChartPresenter::ScatterSeriesZValue);
40 setFlags(QGraphicsItem::ItemHasNoContents);
40 setFlags(QGraphicsItem::ItemHasNoContents);
41 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
41 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
42
42
43 handleUpdated();
43 handleUpdated();
44
44
45 m_items.setHandlesChildEvents(false);
45 m_items.setHandlesChildEvents(false);
46
46
47 // TODO: how to draw a drop shadow?
47 // TODO: how to draw a drop shadow?
48 // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
48 // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
49 // dropShadow->setOffset(2.0);
49 // dropShadow->setOffset(2.0);
50 // dropShadow->setBlurRadius(2.0);
50 // dropShadow->setBlurRadius(2.0);
51 // setGraphicsEffect(dropShadow);
51 // setGraphicsEffect(dropShadow);
52 }
52 }
53
53
54
54
55 QRectF ScatterChartItem::boundingRect() const
55 QRectF ScatterChartItem::boundingRect() const
56 {
56 {
57 return m_rect;
57 return m_rect;
58 }
58 }
59
59
60 void ScatterChartItem::createPoints(int count)
60 void ScatterChartItem::createPoints(int count)
61 {
61 {
62 for (int i = 0; i < count; ++i) {
62 for (int i = 0; i < count; ++i) {
63
63
64 QGraphicsItem *item = 0;
64 QGraphicsItem *item = 0;
65
65
66 switch (m_shape) {
66 switch (m_shape) {
67 case QScatterSeries::MarkerShapeCircle:{
67 case QScatterSeries::MarkerShapeCircle:{
68 QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size);
68 QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size);
69 const QRectF& rect = i->boundingRect();
69 const QRectF& rect = i->boundingRect();
70 i->setPos(-rect.width()/2,-rect.height()/2);
70 i->setPos(-rect.width()/2,-rect.height()/2);
71 item = new Marker(i,this);
71 item = new Marker(i,this);
72 break;
72 break;
73 }
73 }
74 case QScatterSeries::MarkerShapeRectangle:{
74 case QScatterSeries::MarkerShapeRectangle:{
75 QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size);
75 QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size);
76 i->setPos(-m_size/2,-m_size/2);
76 i->setPos(-m_size/2,-m_size/2);
77 item = new Marker(i,this);
77 item = new Marker(i,this);
78 break;
78 break;
79 }
79 }
80 default:
80 default:
81 qWarning()<<"Unsupported marker type";
81 qWarning()<<"Unsupported marker type";
82 break;
82 break;
83
83
84 }
84 }
85 m_items.addToGroup(item);
85 m_items.addToGroup(item);
86 }
86 }
87 }
87 }
88
88
89 void ScatterChartItem::deletePoints(int count)
89 void ScatterChartItem::deletePoints(int count)
90 {
90 {
91 QList<QGraphicsItem *> items = m_items.childItems();
91 QList<QGraphicsItem *> items = m_items.childItems();
92
92
93 for (int i = 0; i < count; ++i) {
93 for (int i = 0; i < count; ++i) {
94 delete(items.takeLast());
94 delete(items.takeLast());
95 }
95 }
96 }
96 }
97
97
98 void ScatterChartItem::markerSelected(Marker *marker)
98 void ScatterChartItem::markerSelected(Marker *marker)
99 {
99 {
100 emit XYChartItem::clicked(QPointF(m_series->x(marker->index()), m_series->y(marker->index())));
100 emit XYChartItem::clicked(QPointF(m_series->x(marker->index()), m_series->y(marker->index())));
101 }
101 }
102
102
103 void ScatterChartItem::setLayout(QVector<QPointF>& points)
103 void ScatterChartItem::setLayout(QVector<QPointF>& points)
104 {
104 {
105 // qDebug() << "scatter: " << points.count();
105 if(points.size()==0)
106 if(points.size()==0)
106 {
107 {
107 XYChartItem::setLayout(points);
108 XYChartItem::setLayout(points);
108 return;
109 return;
109 }
110 }
110
111
111 int diff = XYChartItem::points().size() - points.size();
112 int diff = XYChartItem::points().size() - points.size();
112
113
113 if(diff>0) {
114 if(diff>0) {
114 deletePoints(diff);
115 deletePoints(diff);
115 }
116 }
116 else if(diff<0) {
117 else if(diff<0) {
117 createPoints(-diff);
118 createPoints(-diff);
118 }
119 }
119
120
120 if(diff!=0) handleUpdated();
121 if(diff!=0) handleUpdated();
121
122
122 QList<QGraphicsItem*> items = m_items.childItems();
123 QList<QGraphicsItem*> items = m_items.childItems();
124 // qDebug() << "items count" << items.count();
123
125
124 for(int i=0; i< points.size();i++) {
126 for (int i = 0; i < points.size() && i < items.count(); i++) {
127 Q_ASSERT(i < items.count());
125 Marker* item = static_cast<Marker*>(items.at(i));
128 Marker* item = static_cast<Marker*>(items.at(i));
126 const QPointF& point = points.at(i);
129 const QPointF& point = points.at(i);
127 const QRectF& rect = item->boundingRect();
130 const QRectF& rect = item->boundingRect();
128 item->setIndex(i);
131 item->setIndex(i);
129 item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2);
132 item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2);
130 if(!clipRect().contains(point)) {
133 if(!clipRect().contains(point)) {
131 item->setVisible(false);
134 item->setVisible(false);
132 }
135 }
133 else {
136 else {
134 item->setVisible(true);
137 item->setVisible(true);
135 }
138 }
136 }
139 }
137
140
138 prepareGeometryChange();
141 prepareGeometryChange();
139 m_rect = clipRect();
142 m_rect = clipRect();
140 XYChartItem::setLayout(points);
143 XYChartItem::setLayout(points);
141 }
144 }
142
145
143
146
144 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
147 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
145 {
148 {
146 Q_UNUSED(painter)
149 Q_UNUSED(painter)
147 Q_UNUSED(option)
150 Q_UNUSED(option)
148 Q_UNUSED(widget)
151 Q_UNUSED(widget)
149 }
152 }
150
153
151 void ScatterChartItem::setPen(const QPen& pen)
154 void ScatterChartItem::setPen(const QPen& pen)
152 {
155 {
153 foreach(QGraphicsItem* item , m_items.childItems()) {
156 foreach(QGraphicsItem* item , m_items.childItems()) {
154 static_cast<Marker*>(item)->setPen(pen);
157 static_cast<Marker*>(item)->setPen(pen);
155 }
158 }
156 }
159 }
157
160
158 void ScatterChartItem::setBrush(const QBrush& brush)
161 void ScatterChartItem::setBrush(const QBrush& brush)
159 {
162 {
160 foreach(QGraphicsItem* item , m_items.childItems()) {
163 foreach(QGraphicsItem* item , m_items.childItems()) {
161 static_cast<Marker*>(item)->setBrush(brush);
164 static_cast<Marker*>(item)->setBrush(brush);
162 }
165 }
163 }
166 }
164
167
165 void ScatterChartItem::handleUpdated()
168 void ScatterChartItem::handleUpdated()
166 {
169 {
167
170
168 int count = m_items.childItems().count();
171 int count = m_items.childItems().count();
169
172
170 if(count==0) return;
173 if(count==0) return;
171
174
172 bool recreate = m_size != m_series->size() || m_shape != m_series->shape();
175 bool recreate = m_size != m_series->size() || m_shape != m_series->shape();
173
176
174 //TODO: only rewrite on size change
177 //TODO: only rewrite on size change
175
178
176 m_size = m_series->size();
179 m_size = m_series->size();
177 m_shape = m_series->shape();
180 m_shape = m_series->shape();
178
181
179 if(recreate){
182 if(recreate){
180 deletePoints(count);
183 deletePoints(count);
181 createPoints(count);
184 createPoints(count);
182 }
185 }
183
186
184 setPen(m_series->pen());
187 setPen(m_series->pen());
185 setBrush(m_series->brush());
188 setBrush(m_series->brush());
186 }
189 }
187
190
188 #include "moc_scatterchartitem_p.cpp"
191 #include "moc_scatterchartitem_p.cpp"
189
192
190 QTCOMMERCIALCHART_END_NAMESPACE
193 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,123 +1,123
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 Rectangle {
24 Rectangle {
25 width: parent.width
25 width: parent.width
26 height: parent.height
26 height: parent.height
27
27
28 // Another option for QML data api:
28 // Another option for QML data api:
29 // ListModel {
29 // ListModel {
30 // id: listModelForPie
30 // id: listModelForPie
31 // // PieDataElement
31 // // PieDataElement
32 // ListElement {
32 // ListElement {
33 // label: "Apple"
33 // label: "Apple"
34 // value: 4.3
34 // value: 4.3
35 // }
35 // }
36 // ListElement {
36 // ListElement {
37 // label: "Blackberry"
37 // label: "Blackberry"
38 // value: 15.1
38 // value: 15.1
39 // }
39 // }
40 // }
40 // }
41
41
42 Component.onCompleted: {
42 Component.onCompleted: {
43 // console.log("model:" + myModel.item(0));
43 // console.log("model:" + myModel.item(0));
44 // myModel.insert(1, {"time":1.4; "speed":41.1 });
44 // myModel.insert(1, {"time":1.4; "speed":41.1 });
45 // scatter.appendData();
45 // scatter.appendData();
46 // chart1.theme = Chart.ThemeHighContrast;
46 // chart1.theme = Chart.ThemeHighContrast;
47 // chart2.theme = Chart.ThemeHighContrast;
47 // chart2.theme = Chart.ThemeHighContrast;
48 }
48 }
49
49
50
50
51 Chart {
51 Chart {
52 id: chart1
52 id: chart1
53 anchors.top: parent.top
53 anchors.top: parent.top
54 anchors.left: parent.left
54 anchors.left: parent.left
55 anchors.right: parent.right
55 anchors.right: parent.right
56 height: parent.height / 2
56 height: parent.height / 2
57 theme: Chart.ChartThemeBlueCerulean
57 theme: Chart.ChartThemeBlueCerulean
58
58
59 BarSeries {
59 BarSeries {
60 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
60 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
61 }
61 }
62
62
63 PieSeries {
63 PieSeries {
64 slices: [
64 slices: [
65 PieSlice { label: "Volkswagen"; value: 13.5 },
65 PieSlice { label: "Volkswagen"; value: 13.5 },
66 PieSlice { label: "Toyota"; value: 10.9 },
66 PieSlice { label: "Toyota"; value: 10.9 },
67 PieSlice { label: "Ford"; value: 8.6 },
67 PieSlice { label: "Ford"; value: 8.6 },
68 PieSlice { label: "Skoda"; value: 8.2 },
68 PieSlice { label: "Skoda"; value: 8.2 },
69 PieSlice { label: "Volvo"; value: 6.8 },
69 PieSlice { label: "Volvo"; value: 6.8 },
70 PieSlice { label: "Others"; value: 52.0 }
70 PieSlice { label: "Others"; value: 52.0 }
71 ]
71 ]
72 }
72 }
73 }
73 }
74
74
75
75
76 Chart {
76 Chart {
77 id: chart2
77 id: chart2
78 anchors.top: chart1.bottom
78 anchors.top: chart1.bottom
79 anchors.bottom: parent.bottom
79 anchors.bottom: parent.bottom
80 anchors.left: parent.left
80 anchors.left: parent.left
81 anchors.right: parent.right
81 anchors.right: parent.right
82 theme: Chart.ChartThemeHighContrast
82 theme: Chart.ChartThemeHighContrast
83
83
84 LineSeries {
84 LineSeries {
85 points: [
85 points: [
86 XyPoint { x: 0.0; y: 0.0 },
86 XyPoint { x: 0.0; y: 0.0 },
87 XyPoint { x: 1.1; y: 2.1 },
87 XyPoint { x: 1.1; y: 2.1 },
88 XyPoint { x: 2.9; y: 4.9 },
88 XyPoint { x: 2.9; y: 4.9 },
89 XyPoint { x: 3.2; y: 3.0 }
89 XyPoint { x: 3.2; y: 3.0 }
90 ]
90 ]
91 }
91 }
92
92
93 SplineSeries {
93 // SplineSeries {
94 points: [
94 // points: [
95 XyPoint { x: 0.0; y: 0.3 },
95 // XyPoint { x: 0.0; y: 0.3 },
96 XyPoint { x: 1.1; y: 3.2 },
96 // XyPoint { x: 1.1; y: 3.2 },
97 XyPoint { x: 4.17; y: 3.15 }
97 // XyPoint { x: 4.17; y: 3.15 }
98 ]
98 // ]
99 }
99 // }
100
100
101 ScatterSeries {
101 ScatterSeries {
102 points: [
102 points: [
103 XyPoint { x: 1.5; y: 1.5 },
103 XyPoint { x: 1.5; y: 1.5 },
104 XyPoint { x: 1.5; y: 1.6 },
104 XyPoint { x: 1.5; y: 1.6 },
105 XyPoint { x: 1.57; y: 1.55 }
105 XyPoint { x: 1.57; y: 1.55 }
106 ]
106 ]
107 }
107 }
108 ScatterSeries {
108 // ScatterSeries {
109 points: [
109 // points: [
110 XyPoint { x: 2.0; y: 2.0 },
110 // XyPoint { x: 2.0; y: 2.0 },
111 XyPoint { x: 2.0; y: 2.1 },
111 // XyPoint { x: 2.0; y: 2.1 },
112 XyPoint { x: 2.07; y: 2.05 }
112 // XyPoint { x: 2.07; y: 2.05 }
113 ]
113 // ]
114 }
114 // }
115 ScatterSeries {
115 // ScatterSeries {
116 points: [
116 // points: [
117 XyPoint { x: 2.6; y: 2.6 },
117 // XyPoint { x: 2.6; y: 2.6 },
118 XyPoint { x: 2.6; y: 2.7 },
118 // XyPoint { x: 2.6; y: 2.7 },
119 XyPoint { x: 2.67; y: 2.65 }
119 // XyPoint { x: 2.67; y: 2.65 }
120 ]
120 // ]
121 }
121 // }
122 }
122 }
123 }
123 }
General Comments 0
You need to be logged in to leave comments. Login now