##// END OF EJS Templates
Scatter customization to QML api
Tero Ahola -
r1276:2661cb767b8b
parent child
Show More
@@ -1,92 +1,93
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 property int __activeIndex: 1
28 28 property real __intervalCoefficient: 0
29 29
30 30
31 31 ChartView {
32 32 id: chartView
33 33 anchors.fill: parent
34 34 title: "Wheel of fortune"
35 35 legend: ChartView.LegendDisabled
36 36
37 37 PieSeries {
38 38 id: wheelOfFortune
39 39 }
40 40
41 41 SplineSeries {
42 42 id: splineSeries
43 43 }
44 44
45 45 ScatterSeries {
46 46 id: scatterSeries
47 47 }
48 48 }
49 49
50 50
51 51 Component.onCompleted: {
52 52 __intervalCoefficient = Math.random() + 0.1;
53 53 console.log("__intervalCoefficient: " + __intervalCoefficient);
54 54
55 55 for (var i = 0; i < 20; i++)
56 56 wheelOfFortune.append("", 1);
57 57
58 58 var interval = 1;
59 59 for (var j = 0; interval < 800; j++) {
60 60 interval = __intervalCoefficient * j * j;
61 61 splineSeries.append(j, interval);
62 62 }
63 63 chartView.axisX.max = j;
64 64 chartView.axisY.max = 1000;
65 65 }
66 66
67 67 Timer {
68 68 triggeredOnStart: true
69 69 running: true
70 70 repeat: true
71 71 interval: 100
72 72 onTriggered: {
73 73 var index = __activeIndex % wheelOfFortune.count;
74 74 if (interval < 700) {
75 75 scatterSeries.clear();
76 76 wheelOfFortune.at(index).exploded = false;
77 77 __activeIndex++;
78 78 index = __activeIndex % wheelOfFortune.count;
79 79 wheelOfFortune.at(index).exploded = true;
80 80 interval = splineSeries.at(__activeIndex).y;
81 81 scatterSeries.append(__activeIndex, interval);
82 82 scatterSeries.color = Qt.tint(scatterSeries.color, "#05FF0000");
83 scatterSeries.markerSize += 0.5;
83 84 } else {
84 85 // Switch the colors of the slice and the border
85 86 wheelOfFortune.at(index).borderWidth = 2;
86 87 var borderColor = wheelOfFortune.at(index).borderColor;
87 88 wheelOfFortune.at(index).borderColor = wheelOfFortune.at(index).color;
88 89 wheelOfFortune.at(index).color = borderColor;
89 90 }
90 91 }
91 92 }
92 93 }
@@ -1,53 +1,52
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 #ifndef CUSTOMTABLEMODEL_H
22 22 #define CUSTOMTABLEMODEL_H
23 23
24 24 #include <QAbstractTableModel>
25 25 #include <QHash>
26 26
27 27 class CustomTableModel : public QAbstractTableModel
28 28 {
29 29 Q_OBJECT
30 30 Q_PROPERTY(int count READ rowCount)
31 31
32 32 public:
33 33 explicit CustomTableModel(QObject *parent = 0);
34 34
35 35 int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
36 36 int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
37 37 QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
38 38 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
39 39 bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
40 40 Qt::ItemFlags flags ( const QModelIndex & index ) const;
41 41 void insertColumn(int column, const QModelIndex &parent = QModelIndex());
42 42 void insertRow(int row, const QModelIndex &parent = QModelIndex());
43 /*Q_INVOKABLE*/ //bool removeRow(int row, const QModelIndex &parent = QModelIndex());
44 43 Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
45 44 Q_INVOKABLE bool removeRow (int row, const QModelIndex &parent = QModelIndex());
46 45
47 46 private:
48 47 QList<QVector<QVariant> * > m_data;
49 48 int m_columnCount;
50 49 int m_rowCount;
51 50 };
52 51
53 52 #endif // CUSTOMTABLEMODEL_H
@@ -1,36 +1,36
1 1 #include "chartview.h"
2 2 #include <QScatterSeries>
3 3
4 4 ChartView::ChartView(QWidget *parent) :
5 5 QChartView(new QChart(), parent)
6 6 {
7 7 //![1]
8 8 QScatterSeries *series0 = new QScatterSeries();
9 9 series0->setName("scatter1");
10 series0->setShape(QScatterSeries::MarkerShapeCircle);
11 series0->setSize(15.0);
10 series0->setMarkerShape(QScatterSeries::MarkerShapeCircle);
11 series0->setMarkerSize(15.0);
12 12
13 13 QScatterSeries *series1 = new QScatterSeries();
14 14 series1->setName("scatter2");
15 series1->setShape(QScatterSeries::MarkerShapeCircle);
16 series1->setSize(20.0);
15 series1->setMarkerShape(QScatterSeries::MarkerShapeCircle);
16 series1->setMarkerSize(20.0);
17 17 //![1]
18 18
19 19 //![2]
20 20 series0->append(0, 6);
21 21 series0->append(2, 4);
22 22 series0->append(3, 8);
23 23 series0->append(7, 4);
24 24 series0->append(10, 5);
25 25
26 26 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
27 27 //![2]
28 28
29 29 //![3]
30 30 setRenderHint(QPainter::Antialiasing);
31 31 chart()->addSeries(series0);
32 32 chart()->addSeries(series1);
33 33 chart()->setTitle("Simple scatterchart example");
34 34 chart()->setBackgroundDropShadowEnabled(false);
35 35 //![3]
36 36 }
@@ -1,85 +1,88
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 "qaxiscategories.h"
25 25 #include "declarativechart.h"
26 26 #include "declarativexypoint.h"
27 27 #include "declarativelineseries.h"
28 28 #include "declarativesplineseries.h"
29 29 #include "declarativeareaseries.h"
30 30 #include "declarativescatterseries.h"
31 31 #include "declarativebarseries.h"
32 32 #include "declarativepieseries.h"
33 33 #include <QHPieModelMapper>
34 34 #include <QVPieModelMapper>
35 35 #include <QXYModelMapper>
36 36
37 37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 38
39 39 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
40 40 {
41 41 Q_OBJECT
42 42 public:
43 43 virtual void registerTypes(const char *uri)
44 44 {
45 45 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
46 46
47 47 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
48 48 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
49 49 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
50 50 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
51 51 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
52 52 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
53 53 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
54 54 qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries");
55 55 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
56 56 qmlRegisterType<DeclarativePieSlice>(uri, 1, 0, "PieSlice");
57 57 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
58 58
59
60 qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries",
61 QLatin1String("Trying to create uncreatable: QScatterSeries."));
59 62 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries",
60 63 QLatin1String("Trying to create uncreatable: QPieSeries."));
61 64 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
62 65 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
63 66 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
64 67 QLatin1String("Trying to create uncreatable: PieModelMapper."));
65 68 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
66 69 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
67 70
68 71 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
69 72 QLatin1String("Trying to create uncreatable: AbstractSeries."));
70 73 qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis",
71 74 QLatin1String("Trying to create uncreatable: Axis."));
72 75 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
73 76 QLatin1String("Trying to create uncreatable: PieModelMapper."));
74 77 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
75 78 QLatin1String("Trying to create uncreatable: XYModelMapper."));
76 79 }
77 80 };
78 81
79 82 #include "plugin.moc"
80 83
81 84 QTCOMMERCIALCHART_END_NAMESPACE
82 85
83 86 QTCOMMERCIALCHART_USE_NAMESPACE
84 87
85 88 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,121 +1,123
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 "qlineseries.h"
22 22 #include "qlineseries_p.h"
23 23 #include "linechartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "chartanimator_p.h"
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 /*!
31 31 \class QLineSeries
32 32 \brief The QLineSeries class is used for making line charts.
33 33
34 34 \mainclass
35 35
36 36 A line chart is used to show information as a series of data points
37 37 connected by straight lines.
38 38
39 39 \image examples_linechart.png
40 40
41 41 Creating basic line chart is simple:
42 42 \code
43 43 QLineSeries* series = new QLineSeries();
44 44 series->append(0, 6);
45 45 series->append(2, 4);
46 46 ...
47 47 chart->addSeries(series);
48 48 \endcode
49 49 */
50 50
51 51 /*!
52 52 \fn virtual SeriesType QLineSeries::type() const
53 53 \brief Returns type of series.
54 54 \sa QAbstractSeries, SeriesType
55 55 */
56 56
57 57 /*!
58 58 Constructs empty series object which is a child of \a parent.
59 59 When series object is added to QChartView or QChart instance ownerships is transferred.
60 60 */
61 61 QLineSeries::QLineSeries(QObject *parent) : QXYSeries(*new QLineSeriesPrivate(this),parent)
62 62 {
63 63
64 64 }
65 65
66 66 /*!
67 67 \internal
68 68 */
69 69 QLineSeries::QLineSeries(QLineSeriesPrivate &d,QObject *parent) : QXYSeries (d,parent)
70 70 {
71 71
72 72 }
73 73 /*!
74 74 Destroys the object. Series added to QChartView or QChart instances are owned by those,
75 75 and are deleted when mentioned object are destroyed.
76 76 */
77 77 QLineSeries::~QLineSeries()
78 78 {
79 79 Q_D(QLineSeries);
80 80 if(d->m_dataset){
81 81 d->m_dataset->removeSeries(this);
82 82 }
83 83 }
84 84
85 85 QAbstractSeries::SeriesType QLineSeries::type() const
86 86 {
87 87 return QAbstractSeries::SeriesTypeLine;
88 88 }
89 89
90 90 /*
91 91 QDebug operator<< (QDebug debug, const QLineSeries series)
92 92 {
93 93 Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size());
94 94 int size = series.d_func()->m_x.size();
95 95 for (int i=0; i<size; i++) {
96 96 debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") ";
97 97 }
98 98 return debug.space();
99 99 }
100 100 */
101 101
102 102 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
103 103
104 104 QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries* q):QXYSeriesPrivate(q)
105 105 {
106 106
107 107 };
108 108
109 109 Chart* QLineSeriesPrivate::createGraphics(ChartPresenter* presenter)
110 110 {
111 111 Q_Q(QLineSeries);
112 112 LineChartItem* line = new LineChartItem(q,presenter);
113 113 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
114 114 line->setAnimator(presenter->animator());
115 115 line->setAnimation(new XYAnimation(line));
116 116 }
117 117 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
118 118 return line;
119 119 }
120 120
121 #include "moc_qlineseries.cpp"
122
121 123 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,52 +1,52
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 #ifndef QLINESERIES_H
22 22 #define QLINESERIES_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <qxyseries.h>
26 26 #include <QPen>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 class QLineSeriesPrivate;
31 31
32 32 class QTCOMMERCIALCHART_EXPORT QLineSeries : public QXYSeries
33 33 {
34 Q_OBJECT
35
34 36 public:
35 37 explicit QLineSeries(QObject *parent = 0);
36 38 ~QLineSeries();
37
38 39 QAbstractSeries::SeriesType type() const;
39 40
40 41 protected:
41 42 QLineSeries(QLineSeriesPrivate &d,QObject *parent = 0);
42 43
43 44 private:
44 45 Q_DECLARE_PRIVATE(QLineSeries)
45 46 Q_DISABLE_COPY(QLineSeries)
46 47 friend class LineChartItem;
47
48 48 };
49 49
50 50 QTCOMMERCIALCHART_END_NAMESPACE
51 51
52 52 #endif
@@ -1,155 +1,156
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 "qscatterseries.h"
22 22 #include "qscatterseries_p.h"
23 23 #include "scatterchartitem_p.h"
24 24 #include "chartdataset_p.h"
25 25 #include "charttheme_p.h"
26 26 #include "chartanimator_p.h"
27 27
28 28 /*!
29 29 \class QScatterSeries
30 30 \brief The QScatterSeries class is used for making scatter charts.
31 31
32 32 \mainclass
33 33
34 34 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
35 35 and the vertical axis.
36 36
37 37 \image examples_scatterchart.png
38 38
39 39 Creating basic scatter chart is simple:
40 40 \code
41 41 QScatterSeries* series = new QScatterSeries();
42 42 series->append(0, 6);
43 43 series->append(2, 4);
44 44 ...
45 45 chart->addSeries(series);
46 46 \endcode
47 47 */
48 48
49 49 /*!
50 50 \enum QScatterSeries::MarkerShape
51 51
52 52 This enum describes the shape used when rendering marker items.
53 53
54 54 \value MarkerShapeCircle
55 55 \value MarkerShapeRectangle
56 56 */
57 57
58 58 /*!
59 59 \fn QChartSeriesType QScatterSeries::type() const
60 60 \brief Returns QChartSeries::SeriesTypeScatter.
61 61 \sa QAbstractSeries, SeriesType
62 62 */
63 63
64 64 QTCOMMERCIALCHART_BEGIN_NAMESPACE
65 65
66 66 /*!
67 67 Constructs a series object which is a child of \a parent.
68 68 */
69 69 QScatterSeries::QScatterSeries(QObject *parent) : QXYSeries(*new QScatterSeriesPrivate(this),parent)
70 70 {
71 71 }
72 72
73 73 /*!
74 74 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
75 75 */
76 76 QScatterSeries::~QScatterSeries()
77 77 {
78 78 Q_D(QScatterSeries);
79 79 if(d->m_dataset) {
80 80 d->m_dataset->removeSeries(this);
81 81 }
82 82 }
83 83
84 84 QAbstractSeries::SeriesType QScatterSeries::type() const
85 85 {
86 86 return QAbstractSeries::SeriesTypeScatter;
87 87 }
88 88
89 89 /*!
90 90 Returns the shape used for drawing markers.
91 91 */
92 QScatterSeries::MarkerShape QScatterSeries::shape() const
92 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
93 93 {
94 94 Q_D(const QScatterSeries);
95 95 return d->m_shape;
96 96 }
97 97
98 98 /*!
99 99 Overrides the default shape of the marker items with a user defined \a shape. The default shape
100 100 is defined by chart theme setting.
101 101 */
102 void QScatterSeries::setShape(MarkerShape shape)
102 void QScatterSeries::setMarkerShape(MarkerShape shape)
103 103 {
104 104 Q_D(QScatterSeries);
105 105 if (d->m_shape != shape) {
106 106 d->m_shape = shape;
107 107 emit d->updated();
108 108 }
109 109 }
110 110
111 111 /*!
112 112 Returns the size of the marker items.
113 113 */
114 qreal QScatterSeries::size() const
114 qreal QScatterSeries::markerSize() const
115 115 {
116 116 Q_D(const QScatterSeries);
117 117 return d->m_size;
118 118 }
119 119
120 120 /*!
121 121 Set the \a size of the marker items. The default size is 15.
122 122 */
123 void QScatterSeries::setSize(qreal size)
123 void QScatterSeries::setMarkerSize(qreal size)
124 124 {
125 125 Q_D(QScatterSeries);
126 126
127 127 if (!qFuzzyIsNull(d->m_size - size)) {
128 128 d->m_size = size;
129 129 emit d->updated();
130 130 }
131 131 }
132 132
133 133 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
134 134
135 135 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q):QXYSeriesPrivate(q),
136 136 m_shape(QScatterSeries::MarkerShapeCircle),
137 137 m_size(15.0)
138 138 {
139 139
140 140 };
141 141
142 142 Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter)
143 143 {
144 144 Q_Q(QScatterSeries);
145 145 ScatterChartItem *scatter = new ScatterChartItem(q,presenter);
146 146 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
147 147 scatter->setAnimator(presenter->animator());
148 148 scatter->setAnimation(new XYAnimation(scatter));
149 149 }
150 150 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
151 151 return scatter;
152 152 }
153 153
154 #include "moc_qscatterseries.cpp"
154 155
155 156 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,60 +1,62
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 #ifndef QSCATTERSERIES_H
22 22 #define QSCATTERSERIES_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <qxyseries.h>
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28
29 29 class QScatterSeriesPrivate;
30 30
31 31 class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QXYSeries
32 32 {
33 Q_OBJECT
34 Q_PROPERTY(MarkerShape markerShape READ markerShape WRITE setMarkerShape)
35 Q_PROPERTY(qreal markerSize READ markerSize WRITE setMarkerSize)
36 Q_ENUMS(MarkerShape)
33 37
34 38 public:
35 39 enum MarkerShape {
36 40 MarkerShapeCircle,
37 41 MarkerShapeRectangle
38 42 };
39 43
40 44 public:
41 45 explicit QScatterSeries(QObject *parent = 0);
42 46 ~QScatterSeries();
43
44 47 QAbstractSeries::SeriesType type() const;
45
46 MarkerShape shape() const;
47 void setShape(MarkerShape shape);
48 qreal size() const;
49 void setSize(qreal size);
48 MarkerShape markerShape() const;
49 void setMarkerShape(MarkerShape shape);
50 qreal markerSize() const;
51 void setMarkerSize(qreal size);
50 52
51 53 private:
52 54 Q_DECLARE_PRIVATE(QScatterSeries)
53 55 Q_DISABLE_COPY(QScatterSeries)
54 56 friend class ScatterChartItem;
55 57
56 58 };
57 59
58 60 QTCOMMERCIALCHART_END_NAMESPACE
59 61
60 62 #endif // QSCATTERSERIES_H
@@ -1,198 +1,199
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 "qscatterseries_p.h"
24 24 #include "chartpresenter_p.h"
25 25 #include <QPainter>
26 26 #include <QGraphicsScene>
27 27 #include <QDebug>
28 28 #include <QGraphicsSceneMouseEvent>
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) :
33 33 XYChart(series,presenter),
34 34 QGraphicsItem(presenter ? presenter->rootItem() : 0),
35 35 m_series(series),
36 36 m_items(this),
37 37 m_shape(QScatterSeries::MarkerShapeRectangle),
38 38 m_size(15)
39 39 {
40 40 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated()));
41 41
42 42 setZValue(ChartPresenter::ScatterSeriesZValue);
43 43 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
44 44
45 45 handleUpdated();
46 46
47 47 m_items.setHandlesChildEvents(false);
48 48
49 49 // TODO: how to draw a drop shadow?
50 50 // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect();
51 51 // dropShadow->setOffset(2.0);
52 52 // dropShadow->setBlurRadius(2.0);
53 53 // setGraphicsEffect(dropShadow);
54 54 }
55 55
56 56 QRectF ScatterChartItem::boundingRect() const
57 57 {
58 58 return m_rect;
59 59 }
60 60
61 61 void ScatterChartItem::createPoints(int count)
62 62 {
63 63 for (int i = 0; i < count; ++i) {
64 64
65 65 QGraphicsItem *item = 0;
66 66
67 67 switch (m_shape) {
68 68 case QScatterSeries::MarkerShapeCircle: {
69 69 QGraphicsEllipseItem* i = new QGraphicsEllipseItem(0,0,m_size,m_size);
70 70 const QRectF& rect = i->boundingRect();
71 71 i->setPos(-rect.width()/2,-rect.height()/2);
72 72 item = new Marker(i,this);
73 73 break;
74 74 }
75 75 case QScatterSeries::MarkerShapeRectangle: {
76 76 QGraphicsRectItem* i = new QGraphicsRectItem(0,0,m_size,m_size);
77 77 i->setPos(-m_size/2,-m_size/2);
78 78 item = new Marker(i,this);
79 79 break;
80 80 }
81 81 default:
82 82 qWarning()<<"Unsupported marker type";
83 83 break;
84 84
85 85 }
86 86 m_items.addToGroup(item);
87 87 }
88 88 }
89 89
90 90 void ScatterChartItem::deletePoints(int count)
91 91 {
92 92 QList<QGraphicsItem *> items = m_items.childItems();
93 93
94 94 for (int i = 0; i < count; ++i) {
95 95 delete(items.takeLast());
96 96 }
97 97 }
98 98
99 99 void ScatterChartItem::markerSelected(Marker *marker)
100 100 {
101 101 emit XYChart::clicked(marker->point());
102 102 }
103 103
104 104 void ScatterChartItem::updateGeometry()
105 105 {
106 106
107 107 const QVector<QPointF>& points = geometryPoints();
108 108
109 109 if(points.size()==0)
110 110 {
111 111 deletePoints(m_items.childItems().count());
112 112 return;
113 113 }
114 114
115 115 int diff = m_items.childItems().size() - points.size();
116 116
117 117 if(diff>0) {
118 118 deletePoints(diff);
119 119 }
120 120 else if(diff<0) {
121 121 createPoints(-diff);
122 122 }
123 123
124 124 if(diff!=0) handleUpdated();
125 125
126 126 QList<QGraphicsItem*> items = m_items.childItems();
127 127
128 128 for (int i = 0; i < points.size(); i++) {
129 129 Marker* item = static_cast<Marker*>(items.at(i));
130 130 const QPointF& point = points.at(i);
131 131 const QRectF& rect = item->boundingRect();
132 132 item->setPoint(point);
133 133 item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2);
134 134 if(!clipRect().contains(point)) {
135 135 item->setVisible(false);
136 136 }
137 137 else {
138 138 item->setVisible(true);
139 139 }
140 140 }
141 141
142 142 prepareGeometryChange();
143 143 m_rect = clipRect();
144 144 setPos(origin());
145 145 }
146 146
147 147 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
148 148 {
149 149 Q_UNUSED(painter)
150 150 Q_UNUSED(option)
151 151 Q_UNUSED(widget)
152 152 }
153 153
154 154 void ScatterChartItem::setPen(const QPen& pen)
155 155 {
156 156 foreach(QGraphicsItem* item , m_items.childItems()) {
157 157 static_cast<Marker*>(item)->setPen(pen);
158 158 }
159 159 }
160 160
161 161 void ScatterChartItem::setBrush(const QBrush& brush)
162 162 {
163 163 foreach(QGraphicsItem* item , m_items.childItems()) {
164 164 static_cast<Marker*>(item)->setBrush(brush);
165 165 }
166 166 }
167 167
168 168 void ScatterChartItem::handleUpdated()
169 169 {
170
171 170 int count = m_items.childItems().count();
172 171
173 172 if(count==0) return;
174 173
175 bool recreate = m_size != m_series->size() || m_shape != m_series->shape();
176
177 //TODO: only rewrite on size change
174 bool recreate = m_size != m_series->markerSize() || m_shape != m_series->markerShape();
178 175
179 m_size = m_series->size();
180 m_shape = m_series->shape();
176 m_size = m_series->markerSize();
177 m_shape = m_series->markerShape();
181 178
182 179 if(recreate) {
180 // TODO: optimize handleUpdate to recreate points only in case shape changed
183 181 deletePoints(count);
184 182 createPoints(count);
183
184 // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points
185 updateGeometry();
185 186 }
186 187
187 188 setPen(m_series->pen());
188 189 setBrush(m_series->brush());
189 190 }
190 191
191 192 void ScatterChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
192 193 {
193 194 emit XYChart::clicked(calculateDomainPoint(event->pos()));
194 195 }
195 196
196 197 #include "moc_scatterchartitem_p.cpp"
197 198
198 199 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,51 +1,51
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 #ifndef QSPLINESERIES_H
22 22 #define QSPLINESERIES_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <qlineseries.h>
26 26 #include <QList>
27 27 #include <QPointF>
28 28 #include <QtGlobal>
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 class QSplineSeriesPrivate;
33 33
34 34 class QTCOMMERCIALCHART_EXPORT QSplineSeries : public QLineSeries
35 35 {
36 36 Q_OBJECT
37 public:
38 37
38 public:
39 39 explicit QSplineSeries(QObject *parent = 0);
40 40 ~QSplineSeries();
41 41 QAbstractSeries::SeriesType type() const;
42 42
43 43 private:
44 44 Q_DECLARE_PRIVATE(QSplineSeries)
45 45 Q_DISABLE_COPY(QSplineSeries)
46 46 friend class SplineChartItem;
47 47 };
48 48
49 49 QTCOMMERCIALCHART_END_NAMESPACE
50 50
51 51 #endif // QSPLINESERIES_H
@@ -1,189 +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 "dataseriedialog.h"
22 22 #include <QDialogButtonBox>
23 23 #include <QGridLayout>
24 24 #include <QCheckBox>
25 25 #include <QPushButton>
26 26 #include <QGroupBox>
27 27 #include <QRadioButton>
28 28 #include <QLabel>
29 29 #include <QDebug>
30 30
31 31 DataSerieDialog::DataSerieDialog(QWidget *parent) :
32 32 QDialog(parent)
33 33 {
34 34 QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal);
35 35 QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok);
36 36 connect(b, SIGNAL(clicked()), this, SLOT(accept()));
37 37 b = addSeriesBox->addButton(QDialogButtonBox::Cancel);
38 38 connect(b, SIGNAL(clicked()), this, SLOT(reject()));
39 39
40 40 QGridLayout *grid = new QGridLayout();
41 41
42 42 m_seriesTypeSelector = seriesTypeSelector();
43 43 m_columnCountSelector = columnCountSelector();
44 44 m_rowCountSelector = rowCountSelector();
45 45 m_dataCharacteristicsSelector = dataCharacteristicsSelector();
46 46
47 47 grid->addWidget(m_seriesTypeSelector, 0, 0);
48 48 grid->addWidget(m_columnCountSelector, 0, 1);
49 49 grid->addWidget(m_rowCountSelector, 1, 1);
50 50 grid->addWidget(m_dataCharacteristicsSelector, 1, 0);
51 51 m_labelsSelector = new QCheckBox("Labels defined");
52 52 m_labelsSelector->setChecked(true);
53 53 grid->addWidget(m_labelsSelector, 2, 0);
54 54 grid->addWidget(addSeriesBox, 3, 1);
55 55
56 56 setLayout(grid);
57 57 }
58 58
59 59 QGroupBox *DataSerieDialog::seriesTypeSelector()
60 60 {
61 61 QVBoxLayout *layout = new QVBoxLayout();
62 62
63 63 QRadioButton *line = new QRadioButton("Line");
64 64 line->setChecked(true);
65 65 layout->addWidget(line);
66 66 layout->addWidget(new QRadioButton("Area"));
67 67 layout->addWidget(new QRadioButton("Pie"));
68 68 layout->addWidget(new QRadioButton("Bar"));
69 69 layout->addWidget(new QRadioButton("Grouped bar"));
70 70 layout->addWidget(new QRadioButton("Stacked bar"));
71 71 layout->addWidget(new QRadioButton("Percent bar"));
72 72 layout->addWidget(new QRadioButton("Scatter"));
73 73 layout->addWidget(new QRadioButton("Spline"));
74 74
75 75 QGroupBox *groupBox = new QGroupBox("Series type");
76 76 groupBox->setLayout(layout);
77 77 selectRadio(groupBox, 0);
78 78
79 79 return groupBox;
80 80 }
81 81
82 82 QGroupBox *DataSerieDialog::columnCountSelector()
83 83 {
84 84 QVBoxLayout *layout = new QVBoxLayout();
85 85
86 86 QRadioButton *radio = new QRadioButton("1");
87 87 radio->setChecked(true);
88 88 layout->addWidget(radio);
89 89 layout->addWidget(new QRadioButton("2"));
90 90 layout->addWidget(new QRadioButton("3"));
91 91 layout->addWidget(new QRadioButton("4"));
92 92 layout->addWidget(new QRadioButton("5"));
93 93 layout->addWidget(new QRadioButton("8"));
94 94 layout->addWidget(new QRadioButton("10"));
95 95 layout->addWidget(new QRadioButton("100"));
96 96
97 97 QGroupBox *groupBox = new QGroupBox("Column count");
98 98 groupBox->setLayout(layout);
99 99 selectRadio(groupBox, 0);
100 100
101 101 return groupBox;
102 102 }
103 103
104 104 QGroupBox *DataSerieDialog::rowCountSelector()
105 105 {
106 106 QVBoxLayout *layout = new QVBoxLayout();
107 107
108 108 layout->addWidget(new QRadioButton("1"));
109 109 QRadioButton *radio = new QRadioButton("10");
110 110 radio->setChecked(true);
111 111 layout->addWidget(radio);
112 112 layout->addWidget(new QRadioButton("50"));
113 113 layout->addWidget(new QRadioButton("100"));
114 layout->addWidget(new QRadioButton("1000"));
114 115 layout->addWidget(new QRadioButton("10000"));
115 116 layout->addWidget(new QRadioButton("100000"));
116 117 layout->addWidget(new QRadioButton("1000000"));
117 118
118 119 QGroupBox *groupBox = new QGroupBox("Row count");
119 120 groupBox->setLayout(layout);
120 121 selectRadio(groupBox, 0);
121 122
122 123 return groupBox;
123 124 }
124 125
125 126 QGroupBox *DataSerieDialog::dataCharacteristicsSelector()
126 127 {
127 128 QVBoxLayout *layout = new QVBoxLayout();
128 129
129 130 layout->addWidget(new QRadioButton("Linear"));
130 131 layout->addWidget(new QRadioButton("Constant"));
131 132 layout->addWidget(new QRadioButton("Random"));
132 133 layout->addWidget(new QRadioButton("Sin"));
133 134 layout->addWidget(new QRadioButton("Sin + random"));
134 135
135 136 QGroupBox *groupBox = new QGroupBox("Data Characteristics");
136 137 groupBox->setLayout(layout);
137 138 selectRadio(groupBox, 0);
138 139
139 140 return groupBox;
140 141 }
141 142
142 143 void DataSerieDialog::accept()
143 144 {
144 145 accepted(radioSelection(m_seriesTypeSelector),
145 146 radioSelection(m_columnCountSelector).toInt(),
146 147 radioSelection(m_rowCountSelector).toInt(),
147 148 radioSelection(m_dataCharacteristicsSelector),
148 149 m_labelsSelector->isChecked());
149 150 QDialog::accept();
150 151 }
151 152
152 153 void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection)
153 154 {
154 155 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
155 156 Q_ASSERT(layout);
156 157 Q_ASSERT(layout->count());
157 158
158 159 QLayoutItem *item = 0;
159 160 if (defaultSelection == -1) {
160 161 item = layout->itemAt(0);
161 162 } else if (layout->count() > defaultSelection) {
162 163 item = layout->itemAt(defaultSelection);
163 164 }
164 165 Q_ASSERT(item);
165 166 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
166 167 Q_ASSERT(radio);
167 168 radio->setChecked(true);
168 169 }
169 170
170 171 QString DataSerieDialog::radioSelection(QGroupBox *groupBox)
171 172 {
172 173 QString selection;
173 174 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
174 175 Q_ASSERT(layout);
175 176
176 177 for (int i(0); i < layout->count(); i++) {
177 178 QLayoutItem *item = layout->itemAt(i);
178 179 Q_ASSERT(item);
179 180 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
180 181 Q_ASSERT(radio);
181 182 if (radio->isChecked()) {
182 183 selection = radio->text();
183 184 break;
184 185 }
185 186 }
186 187
187 188 qDebug() << "radioSelection: " << selection;
188 189 return selection;
189 190 }
General Comments 0
You need to be logged in to leave comments. Login now