##// END OF EJS Templates
Bugfix for destruction of qlineseries
Michal Klocek -
r1069:c2064d29f258
parent child
Show More
@@ -1,116 +1,120
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 "qlineseries.h"
21 #include "qlineseries.h"
22 #include "qlineseries_p.h"
22 #include "qlineseries_p.h"
23 #include "linechartitem_p.h"
23 #include "linechartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 /*!
30 /*!
31 \class QLineSeries
31 \class QLineSeries
32 \brief The QLineSeries class is used for making line charts.
32 \brief The QLineSeries class is used for making line charts.
33
33
34 \mainclass
34 \mainclass
35
35
36 A line chart is used to show information as a series of data points
36 A line chart is used to show information as a series of data points
37 connected by straight lines.
37 connected by straight lines.
38
38
39 \image examples_linechart.png
39 \image examples_linechart.png
40
40
41 Creating basic line chart is simple:
41 Creating basic line chart is simple:
42 \code
42 \code
43 QLineSeries* series = new QLineSeries();
43 QLineSeries* series = new QLineSeries();
44 series->append(0, 6);
44 series->append(0, 6);
45 series->append(2, 4);
45 series->append(2, 4);
46 ...
46 ...
47 chart->addSeries(series);
47 chart->addSeries(series);
48 \endcode
48 \endcode
49 */
49 */
50
50
51 /*!
51 /*!
52 \fn virtual QSeriesType QLineSeries::type() const
52 \fn virtual QSeriesType QLineSeries::type() const
53 \brief Returns type of series.
53 \brief Returns type of series.
54 \sa QAbstractSeries, QSeriesType
54 \sa QAbstractSeries, QSeriesType
55 */
55 */
56
56
57 /*!
57 /*!
58 Constructs empty series object which is a child of \a parent.
58 Constructs empty series object which is a child of \a parent.
59 When series object is added to QChartView or QChart instance ownerships is transferred.
59 When series object is added to QChartView or QChart instance ownerships is transferred.
60 */
60 */
61 QLineSeries::QLineSeries(QObject *parent) : QXYSeries(*new QLineSeriesPrivate(this),parent)
61 QLineSeries::QLineSeries(QObject *parent) : QXYSeries(*new QLineSeriesPrivate(this),parent)
62 {
62 {
63
63
64 }
64 }
65
65
66 /*!
66 /*!
67 \internal
67 \internal
68 */
68 */
69 QLineSeries::QLineSeries(QLineSeriesPrivate &d,QObject *parent) : QXYSeries (d,parent)
69 QLineSeries::QLineSeries(QLineSeriesPrivate &d,QObject *parent) : QXYSeries (d,parent)
70 {
70 {
71
71
72 }
72 }
73 /*!
73 /*!
74 Destroys the object. Series added to QChartView or QChart instances are owned by those,
74 Destroys the object. Series added to QChartView or QChart instances are owned by those,
75 and are deleted when mentioned object are destroyed.
75 and are deleted when mentioned object are destroyed.
76 */
76 */
77 QLineSeries::~QLineSeries()
77 QLineSeries::~QLineSeries()
78 {
78 {
79 Q_D(QLineSeries);
80 if(d->m_dataset){
81 d->m_dataset->removeSeries(this);
82 }
79 }
83 }
80
84
81 QAbstractSeries::QSeriesType QLineSeries::type() const
85 QAbstractSeries::QSeriesType QLineSeries::type() const
82 {
86 {
83 return QAbstractSeries::SeriesTypeLine;
87 return QAbstractSeries::SeriesTypeLine;
84 }
88 }
85
89
86 /*
90 /*
87 QDebug operator<< (QDebug debug, const QLineSeries series)
91 QDebug operator<< (QDebug debug, const QLineSeries series)
88 {
92 {
89 Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size());
93 Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size());
90 int size = series.d_func()->m_x.size();
94 int size = series.d_func()->m_x.size();
91 for (int i=0; i<size; i++) {
95 for (int i=0; i<size; i++) {
92 debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") ";
96 debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") ";
93 }
97 }
94 return debug.space();
98 return debug.space();
95 }
99 }
96 */
100 */
97
101
98 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
102 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
99
103
100 QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries* q):QXYSeriesPrivate(q)
104 QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries* q):QXYSeriesPrivate(q)
101 {
105 {
102
106
103 };
107 };
104
108
105 Chart* QLineSeriesPrivate::createGraphics(ChartPresenter* presenter)
109 Chart* QLineSeriesPrivate::createGraphics(ChartPresenter* presenter)
106 {
110 {
107 Q_Q(QLineSeries);
111 Q_Q(QLineSeries);
108 LineChartItem* line = new LineChartItem(q,presenter);
112 LineChartItem* line = new LineChartItem(q,presenter);
109 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
113 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
110 presenter->animator()->addAnimation(line);
114 presenter->animator()->addAnimation(line);
111 }
115 }
112 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
116 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
113 return line;
117 return line;
114 }
118 }
115
119
116 QTCOMMERCIALCHART_END_NAMESPACE
120 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,158 +1,156
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 "qabstractseries.h"
21 #include "qabstractseries.h"
22 #include "qabstractseries_p.h"
22 #include "qabstractseries_p.h"
23 #include "chartdataset_p.h"
23 #include "chartdataset_p.h"
24
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
26
27 /*!
27 /*!
28 \class QAbstractSeries
28 \class QAbstractSeries
29 \brief Base class for all QtCommercial Chart series.
29 \brief Base class for all QtCommercial Chart series.
30 \mainclass
30 \mainclass
31
31
32 Usually you use the series type specific inherited classes instead of the base class.
32 Usually you use the series type specific inherited classes instead of the base class.
33 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries,
33 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries,
34 QPercentBarSeries, QPieSeries
34 QPercentBarSeries, QPieSeries
35 */
35 */
36
36
37 /*!
37 /*!
38 \enum QAbstractSeries::QSeriesType
38 \enum QAbstractSeries::QSeriesType
39
39
40 The type of the series object.
40 The type of the series object.
41
41
42 \value SeriesTypeLine
42 \value SeriesTypeLine
43 \value SeriesTypeArea
43 \value SeriesTypeArea
44 \value SeriesTypeBar
44 \value SeriesTypeBar
45 \value SeriesTypeStackedBar
45 \value SeriesTypeStackedBar
46 \value SeriesTypePercentBar
46 \value SeriesTypePercentBar
47 \value SeriesTypePie
47 \value SeriesTypePie
48 \value SeriesTypeScatter
48 \value SeriesTypeScatter
49 \value SeriesTypeSpline
49 \value SeriesTypeSpline
50 */
50 */
51
51
52 /*!
52 /*!
53 \fn QSeriesType QAbstractSeries::type() const
53 \fn QSeriesType QAbstractSeries::type() const
54 \brief The type of the series.
54 \brief The type of the series.
55 */
55 */
56
56
57 /*!
57 /*!
58 \fn bool QAbstractSeries::setModel(QAbstractItemModel *model)
58 \fn bool QAbstractSeries::setModel(QAbstractItemModel *model)
59 \brief Use the \a model to provide data for the series. The model overrides possible user data
59 \brief Use the \a model to provide data for the series. The model overrides possible user data
60 set with QChartSeries type specific data setters. For example if you call both
60 set with QChartSeries type specific data setters. For example if you call both
61 QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is
61 QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is
62 used by the series. Returns true if the model is valid for the series.
62 used by the series. Returns true if the model is valid for the series.
63 */
63 */
64
64
65 /*!
65 /*!
66 \property QAbstractSeries::name
66 \property QAbstractSeries::name
67 \brief name of the series property
67 \brief name of the series property
68 */
68 */
69
69
70 /*!
70 /*!
71 \fn void QAbstractSeries::setName(const QString& name)
71 \fn void QAbstractSeries::setName(const QString& name)
72 \brief Sets a \a name for the series.
72 \brief Sets a \a name for the series.
73
73
74 The name of a series is shown in the legend for QXYSeries.
74 The name of a series is shown in the legend for QXYSeries.
75 \sa QChart::setTitle()
75 \sa QChart::setTitle()
76 \sa QPieSlice::setLabel()
76 \sa QPieSlice::setLabel()
77 \sa QBarSet::setName()
77 \sa QBarSet::setName()
78 */
78 */
79
79
80 /*!
80 /*!
81 \internal
81 \internal
82 \brief Constructs ChartSeries object with \a parent.
82 \brief Constructs ChartSeries object with \a parent.
83 */
83 */
84 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
84 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
85 QObject(parent),
85 QObject(parent),
86 d_ptr(&d)
86 d_ptr(&d)
87 {
87 {
88 }
88 }
89
89
90 /*!
90 /*!
91 \brief Virtual destructor for the chart series.
91 \brief Virtual destructor for the chart series.
92 */
92 */
93 QAbstractSeries::~QAbstractSeries()
93 QAbstractSeries::~QAbstractSeries()
94 {
94 {
95 if(d_ptr->m_dataset){
95 if(d_ptr->m_dataset) qFatal("Still binded series detected !");
96 d_ptr->m_dataset->removeSeries(this);
97 }
98 }
96 }
99
97
100 /*!
98 /*!
101 \brief Returns the pointer to the model that is used as the series data source
99 \brief Returns the pointer to the model that is used as the series data source
102 */
100 */
103 QAbstractItemModel* QAbstractSeries::model() const
101 QAbstractItemModel* QAbstractSeries::model() const
104 {
102 {
105 return d_ptr->m_model;
103 return d_ptr->m_model;
106 }
104 }
107
105
108 int QAbstractSeries::mapFirst() const
106 int QAbstractSeries::mapFirst() const
109 {
107 {
110 return d_ptr->m_mapFirst;
108 return d_ptr->m_mapFirst;
111 }
109 }
112
110
113 int QAbstractSeries::mapCount() const
111 int QAbstractSeries::mapCount() const
114 {
112 {
115 return d_ptr->m_mapCount;
113 return d_ptr->m_mapCount;
116 }
114 }
117
115
118 int QAbstractSeries::mapOrientation() const
116 int QAbstractSeries::mapOrientation() const
119 {
117 {
120 return d_ptr->m_mapOrientation;
118 return d_ptr->m_mapOrientation;
121 }
119 }
122
120
123 void QAbstractSeries::setName(const QString& name)
121 void QAbstractSeries::setName(const QString& name)
124 {
122 {
125 d_ptr->m_name = name;
123 d_ptr->m_name = name;
126 }
124 }
127
125
128 /*!
126 /*!
129 \brief Returns the name of the series.
127 \brief Returns the name of the series.
130 \sa setName()
128 \sa setName()
131 */
129 */
132 QString QAbstractSeries::name() const
130 QString QAbstractSeries::name() const
133 {
131 {
134 return d_ptr->m_name;
132 return d_ptr->m_name;
135 }
133 }
136
134
137 ///////////////////////////////////////////////////////////////////////////////////////////////////
135 ///////////////////////////////////////////////////////////////////////////////////////////////////
138
136
139 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
137 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
140 q_ptr(q),
138 q_ptr(q),
141 m_model(0),
139 m_model(0),
142 m_dataset(0),
140 m_dataset(0),
143 m_mapFirst(0),
141 m_mapFirst(0),
144 m_mapCount(-1),
142 m_mapCount(-1),
145 m_mapOrientation(Qt::Vertical)
143 m_mapOrientation(Qt::Vertical)
146 {
144 {
147 }
145 }
148
146
149 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
147 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
150 {
148 {
151 }
149 }
152
150
153 #include "moc_qabstractseries.cpp"
151 #include "moc_qabstractseries.cpp"
154 #include "moc_qabstractseries_p.cpp"
152 #include "moc_qabstractseries_p.cpp"
155
153
156 QTCOMMERCIALCHART_END_NAMESPACE
154 QTCOMMERCIALCHART_END_NAMESPACE
157
155
158
156
General Comments 0
You need to be logged in to leave comments. Login now