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