##// END OF EJS Templates
Added NOTIFY to XYModelMapper properties
Marek Rosa -
r1477:6fa77806900a
parent child
Show More
@@ -1,80 +1,98
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 "qhxymodelmapper.h"
21 #include "qhxymodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QHXYModelMapper
26 \class QHXYModelMapper
27 \brief part of QtCommercial chart API.
27 \brief part of QtCommercial chart API.
28 \mainclass
28 \mainclass
29
29
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
31 Horizontal model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
31 Horizontal model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
32 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
32 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
33 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
33 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
34 */
34 */
35
35
36 /*!
36 /*!
37 \property QHXYModelMapper::xRow
37 \property QHXYModelMapper::xRow
38 \brief Defines which row of the model is kept in sync with the x values of the QXYSeries
38 \brief Defines which row of the model is kept in sync with the x values of the QXYSeries
39 Default value is: -1 (invalid mapping)
39 Default value is: -1 (invalid mapping)
40 */
40 */
41
41
42 /*!
42 /*!
43 \property QHXYModelMapper::yRow
43 \property QHXYModelMapper::yRow
44 \brief Defines which row of the model is kept in sync with the y values of the QXYSeries
44 \brief Defines which row of the model is kept in sync with the y values of the QXYSeries
45
45
46 Default value is: -1 (invalid mapping)
46 Default value is: -1 (invalid mapping)
47 */
47 */
48
48
49 /*!
49 /*!
50 \fn void QHXYModelMapper::xRowChanged()
51
52 Emitted when the xRow has changed.
53 */
54
55 /*!
56 \fn void QHXYModelMapper::yRowChanged()
57
58 Emitted when the yRow has changed.
59 */
60
61 /*!
50 Constructs a mapper object which is a child of \a parent.
62 Constructs a mapper object which is a child of \a parent.
51 */
63 */
52 QHXYModelMapper::QHXYModelMapper(QObject *parent) :
64 QHXYModelMapper::QHXYModelMapper(QObject *parent) :
53 QXYModelMapper(parent)
65 QXYModelMapper(parent)
54 {
66 {
55 QXYModelMapper::setOrientation(Qt::Horizontal);
67 QXYModelMapper::setOrientation(Qt::Horizontal);
56 }
68 }
57
69
58 int QHXYModelMapper::xRow() const
70 int QHXYModelMapper::xRow() const
59 {
71 {
60 return QXYModelMapper::xSection();
72 return QXYModelMapper::xSection();
61 }
73 }
62
74
63 void QHXYModelMapper::setXRow(int xRow)
75 void QHXYModelMapper::setXRow(int xRow)
64 {
76 {
65 return QXYModelMapper::setXSection(xRow);
77 if (xRow != xSection()) {
78 return QXYModelMapper::setXSection(xRow);
79 emit xRowChanged();
80 }
66 }
81 }
67
82
68 int QHXYModelMapper::yRow() const
83 int QHXYModelMapper::yRow() const
69 {
84 {
70 return QXYModelMapper::ySection();
85 return QXYModelMapper::ySection();
71 }
86 }
72
87
73 void QHXYModelMapper::setYRow(int yRow)
88 void QHXYModelMapper::setYRow(int yRow)
74 {
89 {
75 return QXYModelMapper::setYSection(yRow);
90 if (yRow != ySection()) {
91 return QXYModelMapper::setYSection(yRow);
92 emit yRowChanged();
93 }
76 }
94 }
77
95
78 #include "moc_qhxymodelmapper.cpp"
96 #include "moc_qhxymodelmapper.cpp"
79
97
80 QTCOMMERCIALCHART_END_NAMESPACE
98 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,46 +1,50
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 QHXYMODELMAPPER_H
21 #ifndef QHXYMODELMAPPER_H
22 #define QHXYMODELMAPPER_H
22 #define QHXYMODELMAPPER_H
23
23
24 #include <QXYModelMapper>
24 #include <QXYModelMapper>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 class QTCOMMERCIALCHART_EXPORT QHXYModelMapper : public QXYModelMapper
28 class QTCOMMERCIALCHART_EXPORT QHXYModelMapper : public QXYModelMapper
29 {
29 {
30 Q_OBJECT
30 Q_OBJECT
31 Q_PROPERTY(int xRow READ xRow WRITE setXRow)
31 Q_PROPERTY(int xRow READ xRow WRITE setXRow NOTIFY xRowChanged)
32 Q_PROPERTY(int yRow READ yRow WRITE setYRow)
32 Q_PROPERTY(int yRow READ yRow WRITE setYRow NOTIFY yRowChanged)
33
33
34 public:
34 public:
35 explicit QHXYModelMapper(QObject *parent = 0);
35 explicit QHXYModelMapper(QObject *parent = 0);
36
36
37 int xRow() const;
37 int xRow() const;
38 void setXRow(int xRow);
38 void setXRow(int xRow);
39
39
40 int yRow() const;
40 int yRow() const;
41 void setYRow(int yRow);
41 void setYRow(int yRow);
42
43 Q_SIGNALS:
44 void xRowChanged();
45 void yRowChanged();
42 };
46 };
43
47
44 QTCOMMERCIALCHART_END_NAMESPACE
48 QTCOMMERCIALCHART_END_NAMESPACE
45
49
46 #endif // QHXYMODELMAPPER_H
50 #endif // QHXYMODELMAPPER_H
@@ -1,81 +1,99
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 "qvxymodelmapper.h"
21 #include "qvxymodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QVXYModelMapper
26 \class QVXYModelMapper
27 \brief part of QtCommercial chart API.
27 \brief part of QtCommercial chart API.
28 \mainclass
28 \mainclass
29
29
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
31 Vertical model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
31 Vertical model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
32 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
32 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
33 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
33 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
34 */
34 */
35
35
36 /*!
36 /*!
37 \property QVXYModelMapper::xColumn
37 \property QVXYModelMapper::xColumn
38 \brief Defines which column of the model is kept in sync with the x values of QXYSeries
38 \brief Defines which column of the model is kept in sync with the x values of QXYSeries
39
39
40 Default value is: -1 (invalid mapping)
40 Default value is: -1 (invalid mapping)
41 */
41 */
42
42
43 /*!
43 /*!
44 \property QVXYModelMapper::yColumn
44 \property QVXYModelMapper::yColumn
45 \brief Defines which column of the model is kept in sync with the y values of QXYSeries
45 \brief Defines which column of the model is kept in sync with the y values of QXYSeries
46
46
47 Default value is: -1 (invalid mapping)
47 Default value is: -1 (invalid mapping)
48 */
48 */
49
49
50 /*!
50 /*!
51 \fn void QVXYModelMapper::xColumnChanged()
52
53 Emitted when the xColumn has changed.
54 */
55
56 /*!
57 \fn void QVXYModelMapper::yColumnChanged()
58
59 Emitted when the yColumn has changed.
60 */
61
62 /*!
51 Constructs a mapper object which is a child of \a parent.
63 Constructs a mapper object which is a child of \a parent.
52 */
64 */
53 QVXYModelMapper::QVXYModelMapper(QObject *parent) :
65 QVXYModelMapper::QVXYModelMapper(QObject *parent) :
54 QXYModelMapper(parent)
66 QXYModelMapper(parent)
55 {
67 {
56 QXYModelMapper::setOrientation(Qt::Vertical);
68 QXYModelMapper::setOrientation(Qt::Vertical);
57 }
69 }
58
70
59 int QVXYModelMapper::xColumn() const
71 int QVXYModelMapper::xColumn() const
60 {
72 {
61 return QXYModelMapper::xSection();
73 return QXYModelMapper::xSection();
62 }
74 }
63
75
64 void QVXYModelMapper::setXColumn(int xColumn)
76 void QVXYModelMapper::setXColumn(int xColumn)
65 {
77 {
66 return QXYModelMapper::setXSection(xColumn);
78 if (xColumn != xSection()) {
79 return QXYModelMapper::setXSection(xColumn);
80 emit xColumnChanged();
81 }
67 }
82 }
68
83
69 int QVXYModelMapper::yColumn() const
84 int QVXYModelMapper::yColumn() const
70 {
85 {
71 return QXYModelMapper::ySection();
86 return QXYModelMapper::ySection();
72 }
87 }
73
88
74 void QVXYModelMapper::setYColumn(int yColumn)
89 void QVXYModelMapper::setYColumn(int yColumn)
75 {
90 {
76 return QXYModelMapper::setYSection(yColumn);
91 if (yColumn != ySection()) {
92 return QXYModelMapper::setYSection(yColumn);
93 emit yColumnChanged();
94 }
77 }
95 }
78
96
79 #include "moc_qvxymodelmapper.cpp"
97 #include "moc_qvxymodelmapper.cpp"
80
98
81 QTCOMMERCIALCHART_END_NAMESPACE
99 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,46 +1,50
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 QVXYMODELMAPPER_H
21 #ifndef QVXYMODELMAPPER_H
22 #define QVXYMODELMAPPER_H
22 #define QVXYMODELMAPPER_H
23
23
24 #include <QXYModelMapper>
24 #include <QXYModelMapper>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 class QTCOMMERCIALCHART_EXPORT QVXYModelMapper : public QXYModelMapper
28 class QTCOMMERCIALCHART_EXPORT QVXYModelMapper : public QXYModelMapper
29 {
29 {
30 Q_OBJECT
30 Q_OBJECT
31 Q_PROPERTY(int xColumn READ xColumn WRITE setXColumn)
31 Q_PROPERTY(int xColumn READ xColumn WRITE setXColumn NOTIFY xColumnChanged)
32 Q_PROPERTY(int yColumn READ yColumn WRITE setYColumn)
32 Q_PROPERTY(int yColumn READ yColumn WRITE setYColumn NOTIFY yColumnChanged)
33
33
34 public:
34 public:
35 explicit QVXYModelMapper(QObject *parent = 0);
35 explicit QVXYModelMapper(QObject *parent = 0);
36
36
37 int xColumn() const;
37 int xColumn() const;
38 void setXColumn(int xColumn);
38 void setXColumn(int xColumn);
39
39
40 int yColumn() const;
40 int yColumn() const;
41 void setYColumn(int yColumn);
41 void setYColumn(int yColumn);
42
43 Q_SIGNALS:
44 void xColumnChanged();
45 void yColumnChanged();
42 };
46 };
43
47
44 QTCOMMERCIALCHART_END_NAMESPACE
48 QTCOMMERCIALCHART_END_NAMESPACE
45
49
46 #endif // QVXYMODELMAPPER_H
50 #endif // QVXYMODELMAPPER_H
@@ -1,522 +1,558
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 "qxymodelmapper.h"
21 #include "qxymodelmapper.h"
22 #include "qxymodelmapper_p.h"
22 #include "qxymodelmapper_p.h"
23 #include "qxyseries.h"
23 #include "qxyseries.h"
24 #include <QAbstractItemModel>
24 #include <QAbstractItemModel>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QXYModelMapper
29 \class QXYModelMapper
30 \brief part of QtCommercial chart API.
30 \brief part of QtCommercial chart API.
31 \mainclass
31 \mainclass
32
32
33 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
33 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
34 The instance of this class cannot be created directly. QHXYModelMapper of QVXYModelMapper should be used instead. This class is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
34 The instance of this class cannot be created directly. QHXYModelMapper of QVXYModelMapper should be used instead. This class is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
35 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
35 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
36 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
36 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
37 */
37 */
38
38
39 /*!
39 /*!
40 \property QXYModelMapper::series
40 \property QXYModelMapper::series
41 \brief Defines the QPieSeries object that is used by the mapper.
41 \brief Defines the QPieSeries object that is used by the mapper.
42
42
43 All the data in the series is discarded when it is set to the mapper.
43 All the data in the series is discarded when it is set to the mapper.
44 When new series is specified the old series is disconnected (it preserves its data)
44 When new series is specified the old series is disconnected (it preserves its data)
45 */
45 */
46
46
47 /*!
47 /*!
48 \property QXYModelMapper::model
48 \property QXYModelMapper::model
49 \brief Defines the model that is used by the mapper.
49 \brief Defines the model that is used by the mapper.
50 */
50 */
51
51
52 /*!
52 /*!
53 \property QXYModelMapper::first
53 \property QXYModelMapper::first
54 \brief Defines which item of the model's row/column should be mapped as the first x/y pair
54 \brief Defines which item of the model's row/column should be mapped as the first x/y pair
55
55
56 Minimal and default value is: 0
56 Minimal and default value is: 0
57 */
57 */
58
58
59 /*!
59 /*!
60 \property QXYModelMapper::count
60 \property QXYModelMapper::count
61 \brief Defines the number of rows/columns of the model that are mapped as the data for QXYSeries
61 \brief Defines the number of rows/columns of the model that are mapped as the data for QXYSeries
62
62
63 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
63 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
64 */
64 */
65
65
66 /*!
66 /*!
67 \fn void QXYModelMapper::seriesReplaced()
68
69 Emitted when the series to which mapper is connected to has changed.
70 */
71
72 /*!
73 \fn void QXYModelMapper::modelReplaced()
74
75 Emitted when the model to which mapper is connected to has changed.
76 */
77
78 /*!
79 \fn void QXYModelMapper::firstChanged()
80
81 Emitted when the value for the first has changed.
82 */
83
84 /*!
85 \fn void QXYModelMapper::countChanged()
86
87 Emitted when the value for the count has changed.
88 */
89
90 /*!
67 Constructs a mapper object which is a child of \a parent.
91 Constructs a mapper object which is a child of \a parent.
68 */
92 */
69 QXYModelMapper::QXYModelMapper(QObject *parent):
93 QXYModelMapper::QXYModelMapper(QObject *parent):
70 QObject(parent),
94 QObject(parent),
71 d_ptr(new QXYModelMapperPrivate(this))
95 d_ptr(new QXYModelMapperPrivate(this))
72 {
96 {
73 }
97 }
74
98
75 QAbstractItemModel* QXYModelMapper::model() const
99 QAbstractItemModel* QXYModelMapper::model() const
76 {
100 {
77 Q_D(const QXYModelMapper);
101 Q_D(const QXYModelMapper);
78 return d->m_model;
102 return d->m_model;
79 }
103 }
80
104
81 void QXYModelMapper::setModel(QAbstractItemModel *model)
105 void QXYModelMapper::setModel(QAbstractItemModel *model)
82 {
106 {
83 if (model == 0)
107 if (model == 0)
84 return;
108 return;
85
109
86 Q_D(QXYModelMapper);
110 Q_D(QXYModelMapper);
87 if (d->m_model) {
111 if (d->m_model) {
88 disconnect(d->m_model, 0, d, 0);
112 disconnect(d->m_model, 0, d, 0);
89 }
113 }
90
114
91 d->m_model = model;
115 d->m_model = model;
92 d->initializeXYFromModel();
116 d->initializeXYFromModel();
93 // connect signals from the model
117 // connect signals from the model
94 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
118 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
95 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
119 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
96 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
120 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
97 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
121 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
98 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
122 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
123
124 emit modelReplaced();
99 }
125 }
100
126
101 QXYSeries* QXYModelMapper::series() const
127 QXYSeries* QXYModelMapper::series() const
102 {
128 {
103 Q_D(const QXYModelMapper);
129 Q_D(const QXYModelMapper);
104 return d->m_series;
130 return d->m_series;
105 }
131 }
106
132
107 void QXYModelMapper::setSeries(QXYSeries *series)
133 void QXYModelMapper::setSeries(QXYSeries *series)
108 {
134 {
109 Q_D(QXYModelMapper);
135 Q_D(QXYModelMapper);
110 if (d->m_series) {
136 if (d->m_series) {
111 disconnect(d->m_series, 0, d, 0);
137 disconnect(d->m_series, 0, d, 0);
112 }
138 }
113
139
114 if (series == 0)
140 if (series == 0)
115 return;
141 return;
116
142
117 d->m_series = series;
143 d->m_series = series;
118 d->initializeXYFromModel();
144 d->initializeXYFromModel();
119 // connect the signals from the series
145 // connect the signals from the series
120 connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
146 connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
121 connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
147 connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
122 connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
148 connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
149
150 emit seriesReplaced();
123 }
151 }
124
152
125 int QXYModelMapper::first() const
153 int QXYModelMapper::first() const
126 {
154 {
127 Q_D(const QXYModelMapper);
155 Q_D(const QXYModelMapper);
128 return d->m_first;
156 return d->m_first;
129 }
157 }
130
158
131 void QXYModelMapper::setFirst(int first)
159 void QXYModelMapper::setFirst(int first)
132 {
160 {
133 Q_D(QXYModelMapper);
161 Q_D(QXYModelMapper);
134 d->m_first = qMax(first, 0);
162 if (first != d->m_first) {
135 d->initializeXYFromModel();
163 d->m_first = qMax(first, 0);
164 d->initializeXYFromModel();
165
166 emit firstChanged();
167 }
136 }
168 }
137
169
138 int QXYModelMapper::count() const
170 int QXYModelMapper::count() const
139 {
171 {
140 Q_D(const QXYModelMapper);
172 Q_D(const QXYModelMapper);
141 return d->m_count;
173 return d->m_count;
142 }
174 }
143
175
144 void QXYModelMapper::setCount(int count)
176 void QXYModelMapper::setCount(int count)
145 {
177 {
146 Q_D(QXYModelMapper);
178 Q_D(QXYModelMapper);
147 d->m_count = qMax(count, -1);
179 if (count != d->m_count) {
148 d->initializeXYFromModel();
180 d->m_count = qMax(count, -1);
181 d->initializeXYFromModel();
182
183 emit countChanged();
184 }
149 }
185 }
150
186
151 /*!
187 /*!
152 Returns the orientation that is used when QXYModelMapper accesses the model.
188 Returns the orientation that is used when QXYModelMapper accesses the model.
153 This mean whether the consecutive x/y values of the QXYSeries are read from rows (Qt::Horizontal)
189 This mean whether the consecutive x/y values of the QXYSeries are read from rows (Qt::Horizontal)
154 or from columns (Qt::Vertical)
190 or from columns (Qt::Vertical)
155 */
191 */
156 Qt::Orientation QXYModelMapper::orientation() const
192 Qt::Orientation QXYModelMapper::orientation() const
157 {
193 {
158 Q_D(const QXYModelMapper);
194 Q_D(const QXYModelMapper);
159 return d->m_orientation;
195 return d->m_orientation;
160 }
196 }
161
197
162 /*!
198 /*!
163 Returns the \a orientation that is used when QXYModelMapper accesses the model.
199 Returns the \a orientation that is used when QXYModelMapper accesses the model.
164 This mean whether the consecutive x/y values of the QXYSeries are read from rows (Qt::Horizontal)
200 This mean whether the consecutive x/y values of the QXYSeries are read from rows (Qt::Horizontal)
165 or from columns (Qt::Vertical)
201 or from columns (Qt::Vertical)
166 */
202 */
167 void QXYModelMapper::setOrientation(Qt::Orientation orientation)
203 void QXYModelMapper::setOrientation(Qt::Orientation orientation)
168 {
204 {
169 Q_D(QXYModelMapper);
205 Q_D(QXYModelMapper);
170 d->m_orientation = orientation;
206 d->m_orientation = orientation;
171 d->initializeXYFromModel();
207 d->initializeXYFromModel();
172 }
208 }
173
209
174 /*!
210 /*!
175 Returns which section of the model is kept in sync with the x values of the QXYSeries
211 Returns which section of the model is kept in sync with the x values of the QXYSeries
176 */
212 */
177 int QXYModelMapper::xSection() const
213 int QXYModelMapper::xSection() const
178 {
214 {
179 Q_D(const QXYModelMapper);
215 Q_D(const QXYModelMapper);
180 return d->m_xSection;
216 return d->m_xSection;
181 }
217 }
182
218
183 /*!
219 /*!
184 Sets the model section that is kept in sync with the x values of the QXYSeries.
220 Sets the model section that is kept in sync with the x values of the QXYSeries.
185 Parameter \a xSection specifies the section of the model.
221 Parameter \a xSection specifies the section of the model.
186 */
222 */
187 void QXYModelMapper::setXSection(int xSection)
223 void QXYModelMapper::setXSection(int xSection)
188 {
224 {
189 Q_D(QXYModelMapper);
225 Q_D(QXYModelMapper);
190 d->m_xSection = qMax(-1, xSection);
226 d->m_xSection = qMax(-1, xSection);
191 d->initializeXYFromModel();
227 d->initializeXYFromModel();
192 }
228 }
193
229
194 /*!
230 /*!
195 Returns which section of the model is kept in sync with the y values of the QXYSeries
231 Returns which section of the model is kept in sync with the y values of the QXYSeries
196 */
232 */
197 int QXYModelMapper::ySection() const
233 int QXYModelMapper::ySection() const
198 {
234 {
199 Q_D(const QXYModelMapper);
235 Q_D(const QXYModelMapper);
200 return d->m_ySection;
236 return d->m_ySection;
201 }
237 }
202
238
203 /*!
239 /*!
204 Sets the model section that is kept in sync with the y values of the QXYSeries.
240 Sets the model section that is kept in sync with the y values of the QXYSeries.
205 Parameter \a ySection specifies the section of the model.
241 Parameter \a ySection specifies the section of the model.
206 */
242 */
207 void QXYModelMapper::setYSection(int ySection)
243 void QXYModelMapper::setYSection(int ySection)
208 {
244 {
209 Q_D(QXYModelMapper);
245 Q_D(QXYModelMapper);
210 d->m_ySection = qMax(-1, ySection);
246 d->m_ySection = qMax(-1, ySection);
211 d->initializeXYFromModel();
247 d->initializeXYFromModel();
212 }
248 }
213
249
214 /*!
250 /*!
215 Resets the QXYModelMapper to the default state.
251 Resets the QXYModelMapper to the default state.
216 first: 0; count: -1; xSection: -1; ySection: -1;
252 first: 0; count: -1; xSection: -1; ySection: -1;
217 */
253 */
218 void QXYModelMapper::reset()
254 void QXYModelMapper::reset()
219 {
255 {
220 Q_D(QXYModelMapper);
256 Q_D(QXYModelMapper);
221 d->m_first = 0;
257 d->m_first = 0;
222 d->m_count = -1;
258 d->m_count = -1;
223 d->m_orientation = Qt::Vertical;
259 d->m_orientation = Qt::Vertical;
224 d->m_xSection = -1;
260 d->m_xSection = -1;
225 d->m_ySection = -1;
261 d->m_ySection = -1;
226 d->initializeXYFromModel();
262 d->initializeXYFromModel();
227 }
263 }
228
264
229 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
265 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
230
266
231 QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) :
267 QXYModelMapperPrivate::QXYModelMapperPrivate(QXYModelMapper *q) :
232 m_series(0),
268 m_series(0),
233 m_model(0),
269 m_model(0),
234 m_first(0),
270 m_first(0),
235 m_count(-1),
271 m_count(-1),
236 m_orientation(Qt::Vertical),
272 m_orientation(Qt::Vertical),
237 m_xSection(-1),
273 m_xSection(-1),
238 m_ySection(-1),
274 m_ySection(-1),
239 m_seriesSignalsBlock(false),
275 m_seriesSignalsBlock(false),
240 m_modelSignalsBlock(false),
276 m_modelSignalsBlock(false),
241 q_ptr(q)
277 q_ptr(q)
242 {
278 {
243 }
279 }
244
280
245 void QXYModelMapperPrivate::blockModelSignals(bool block)
281 void QXYModelMapperPrivate::blockModelSignals(bool block)
246 {
282 {
247 m_modelSignalsBlock = block;
283 m_modelSignalsBlock = block;
248 }
284 }
249
285
250 void QXYModelMapperPrivate::blockSeriesSignals(bool block)
286 void QXYModelMapperPrivate::blockSeriesSignals(bool block)
251 {
287 {
252 m_seriesSignalsBlock = block;
288 m_seriesSignalsBlock = block;
253 }
289 }
254
290
255 QModelIndex QXYModelMapperPrivate::xModelIndex(int xPos)
291 QModelIndex QXYModelMapperPrivate::xModelIndex(int xPos)
256 {
292 {
257 if (m_count != -1 && xPos >= m_count)
293 if (m_count != -1 && xPos >= m_count)
258 return QModelIndex(); // invalid
294 return QModelIndex(); // invalid
259
295
260 if (m_orientation == Qt::Vertical)
296 if (m_orientation == Qt::Vertical)
261 return m_model->index(xPos + m_first, m_xSection);
297 return m_model->index(xPos + m_first, m_xSection);
262 else
298 else
263 return m_model->index(m_xSection, xPos + m_first);
299 return m_model->index(m_xSection, xPos + m_first);
264 }
300 }
265
301
266 QModelIndex QXYModelMapperPrivate::yModelIndex(int yPos)
302 QModelIndex QXYModelMapperPrivate::yModelIndex(int yPos)
267 {
303 {
268 if (m_count != -1 && yPos >= m_count)
304 if (m_count != -1 && yPos >= m_count)
269 return QModelIndex(); // invalid
305 return QModelIndex(); // invalid
270
306
271 if (m_orientation == Qt::Vertical)
307 if (m_orientation == Qt::Vertical)
272 return m_model->index(yPos + m_first, m_ySection);
308 return m_model->index(yPos + m_first, m_ySection);
273 else
309 else
274 return m_model->index(m_ySection, yPos + m_first);
310 return m_model->index(m_ySection, yPos + m_first);
275 }
311 }
276
312
277 void QXYModelMapperPrivate::handlePointAdded(int pointPos)
313 void QXYModelMapperPrivate::handlePointAdded(int pointPos)
278 {
314 {
279 if (m_seriesSignalsBlock)
315 if (m_seriesSignalsBlock)
280 return;
316 return;
281
317
282 if (m_count != -1)
318 if (m_count != -1)
283 m_count += 1;
319 m_count += 1;
284
320
285 blockModelSignals();
321 blockModelSignals();
286 if (m_orientation == Qt::Vertical)
322 if (m_orientation == Qt::Vertical)
287 m_model->insertRows(pointPos + m_first, 1);
323 m_model->insertRows(pointPos + m_first, 1);
288 else
324 else
289 m_model->insertColumns(pointPos + m_first, 1);
325 m_model->insertColumns(pointPos + m_first, 1);
290
326
291 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
327 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
292 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
328 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
293 blockModelSignals(false);
329 blockModelSignals(false);
294 }
330 }
295
331
296 void QXYModelMapperPrivate::handlePointRemoved(int pointPos)
332 void QXYModelMapperPrivate::handlePointRemoved(int pointPos)
297 {
333 {
298 if (m_seriesSignalsBlock)
334 if (m_seriesSignalsBlock)
299 return;
335 return;
300
336
301 if (m_count != -1)
337 if (m_count != -1)
302 m_count -= 1;
338 m_count -= 1;
303
339
304 blockModelSignals();
340 blockModelSignals();
305 if (m_orientation == Qt::Vertical)
341 if (m_orientation == Qt::Vertical)
306 m_model->removeRow(pointPos + m_first);
342 m_model->removeRow(pointPos + m_first);
307 else
343 else
308 m_model->removeColumn(pointPos + m_first);
344 m_model->removeColumn(pointPos + m_first);
309 blockModelSignals(false);
345 blockModelSignals(false);
310 }
346 }
311
347
312 void QXYModelMapperPrivate::handlePointReplaced(int pointPos)
348 void QXYModelMapperPrivate::handlePointReplaced(int pointPos)
313 {
349 {
314 if (m_seriesSignalsBlock)
350 if (m_seriesSignalsBlock)
315 return;
351 return;
316
352
317 blockModelSignals();
353 blockModelSignals();
318 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
354 m_model->setData(xModelIndex(pointPos), m_series->points().at(pointPos).x());
319 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
355 m_model->setData(yModelIndex(pointPos), m_series->points().at(pointPos).y());
320 blockModelSignals(false);
356 blockModelSignals(false);
321 }
357 }
322
358
323 void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
359 void QXYModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
324 {
360 {
325 if (m_model == 0 || m_series == 0)
361 if (m_model == 0 || m_series == 0)
326 return;
362 return;
327
363
328 if (m_modelSignalsBlock)
364 if (m_modelSignalsBlock)
329 return;
365 return;
330
366
331 blockSeriesSignals();
367 blockSeriesSignals();
332 QModelIndex index;
368 QModelIndex index;
333 QPointF oldPoint;
369 QPointF oldPoint;
334 QPointF newPoint;
370 QPointF newPoint;
335 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
371 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
336 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
372 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
337 index = topLeft.sibling(row, column);
373 index = topLeft.sibling(row, column);
338 if (m_orientation == Qt::Vertical && (index.column() == m_xSection || index.column() == m_ySection)) {
374 if (m_orientation == Qt::Vertical && (index.column() == m_xSection || index.column() == m_ySection)) {
339 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
375 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
340 QModelIndex xIndex = xModelIndex(index.row() - m_first);
376 QModelIndex xIndex = xModelIndex(index.row() - m_first);
341 QModelIndex yIndex = yModelIndex(index.row() - m_first);
377 QModelIndex yIndex = yModelIndex(index.row() - m_first);
342 if (xIndex.isValid() && yIndex.isValid()) {
378 if (xIndex.isValid() && yIndex.isValid()) {
343 oldPoint = m_series->points().at(index.row() - m_first);
379 oldPoint = m_series->points().at(index.row() - m_first);
344 newPoint.setX(m_model->data(xIndex).toReal());
380 newPoint.setX(m_model->data(xIndex).toReal());
345 newPoint.setY(m_model->data(yIndex).toReal());
381 newPoint.setY(m_model->data(yIndex).toReal());
346 }
382 }
347 }
383 }
348 } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) {
384 } else if (m_orientation == Qt::Horizontal && (index.row() == m_xSection || index.row() == m_ySection)) {
349 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
385 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) {
350 QModelIndex xIndex = xModelIndex(index.column() - m_first);
386 QModelIndex xIndex = xModelIndex(index.column() - m_first);
351 QModelIndex yIndex = yModelIndex(index.column() - m_first);
387 QModelIndex yIndex = yModelIndex(index.column() - m_first);
352 if (xIndex.isValid() && yIndex.isValid()) {
388 if (xIndex.isValid() && yIndex.isValid()) {
353 oldPoint = m_series->points().at(index.column() - m_first);
389 oldPoint = m_series->points().at(index.column() - m_first);
354 newPoint.setX(m_model->data(xIndex).toReal());
390 newPoint.setX(m_model->data(xIndex).toReal());
355 newPoint.setY(m_model->data(yIndex).toReal());
391 newPoint.setY(m_model->data(yIndex).toReal());
356 }
392 }
357 }
393 }
358 } else {
394 } else {
359 continue;
395 continue;
360 }
396 }
361 m_series->replace(oldPoint, newPoint);
397 m_series->replace(oldPoint, newPoint);
362 }
398 }
363 }
399 }
364 blockSeriesSignals(false);
400 blockSeriesSignals(false);
365 }
401 }
366
402
367 void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
403 void QXYModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
368 {
404 {
369 Q_UNUSED(parent);
405 Q_UNUSED(parent);
370 if (m_modelSignalsBlock)
406 if (m_modelSignalsBlock)
371 return;
407 return;
372
408
373 blockSeriesSignals();
409 blockSeriesSignals();
374 if (m_orientation == Qt::Vertical)
410 if (m_orientation == Qt::Vertical)
375 insertData(start, end);
411 insertData(start, end);
376 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
412 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
377 initializeXYFromModel();
413 initializeXYFromModel();
378 blockSeriesSignals(false);
414 blockSeriesSignals(false);
379 }
415 }
380
416
381 void QXYModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
417 void QXYModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
382 {
418 {
383 Q_UNUSED(parent);
419 Q_UNUSED(parent);
384 if (m_modelSignalsBlock)
420 if (m_modelSignalsBlock)
385 return;
421 return;
386
422
387 blockSeriesSignals();
423 blockSeriesSignals();
388 if (m_orientation == Qt::Vertical)
424 if (m_orientation == Qt::Vertical)
389 removeData(start, end);
425 removeData(start, end);
390 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
426 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
391 initializeXYFromModel();
427 initializeXYFromModel();
392 blockSeriesSignals(false);
428 blockSeriesSignals(false);
393 }
429 }
394
430
395 void QXYModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
431 void QXYModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
396 {
432 {
397 Q_UNUSED(parent);
433 Q_UNUSED(parent);
398 if (m_modelSignalsBlock)
434 if (m_modelSignalsBlock)
399 return;
435 return;
400
436
401 blockSeriesSignals();
437 blockSeriesSignals();
402 if (m_orientation == Qt::Horizontal)
438 if (m_orientation == Qt::Horizontal)
403 insertData(start, end);
439 insertData(start, end);
404 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
440 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
405 initializeXYFromModel();
441 initializeXYFromModel();
406 blockSeriesSignals(false);
442 blockSeriesSignals(false);
407 }
443 }
408
444
409 void QXYModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
445 void QXYModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
410 {
446 {
411 Q_UNUSED(parent);
447 Q_UNUSED(parent);
412 if (m_modelSignalsBlock)
448 if (m_modelSignalsBlock)
413 return;
449 return;
414
450
415 blockSeriesSignals();
451 blockSeriesSignals();
416 if (m_orientation == Qt::Horizontal)
452 if (m_orientation == Qt::Horizontal)
417 removeData(start, end);
453 removeData(start, end);
418 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
454 else if (start <= m_xSection || start <= m_ySection) // if the changes affect the map - reinitialize the xy
419 initializeXYFromModel();
455 initializeXYFromModel();
420 blockSeriesSignals(false);
456 blockSeriesSignals(false);
421 }
457 }
422
458
423 void QXYModelMapperPrivate::insertData(int start, int end)
459 void QXYModelMapperPrivate::insertData(int start, int end)
424 {
460 {
425 if (m_model == 0 || m_series == 0)
461 if (m_model == 0 || m_series == 0)
426 return;
462 return;
427
463
428 if (m_count != -1 && start >= m_first + m_count) {
464 if (m_count != -1 && start >= m_first + m_count) {
429 return;
465 return;
430 } else {
466 } else {
431 int addedCount = end - start + 1;
467 int addedCount = end - start + 1;
432 if (m_count != -1 && addedCount > m_count)
468 if (m_count != -1 && addedCount > m_count)
433 addedCount = m_count;
469 addedCount = m_count;
434 int first = qMax(start, m_first);
470 int first = qMax(start, m_first);
435 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
471 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
436 for (int i = first; i <= last; i++) {
472 for (int i = first; i <= last; i++) {
437 QPointF point;
473 QPointF point;
438 QModelIndex xIndex = xModelIndex(i - m_first);
474 QModelIndex xIndex = xModelIndex(i - m_first);
439 QModelIndex yIndex = yModelIndex(i - m_first);
475 QModelIndex yIndex = yModelIndex(i - m_first);
440 if (xIndex.isValid() && yIndex.isValid()) {
476 if (xIndex.isValid() && yIndex.isValid()) {
441 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
477 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
442 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
478 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
443 m_series->insert(i - m_first, point);
479 m_series->insert(i - m_first, point);
444 }
480 }
445 }
481 }
446
482
447 // remove excess of slices (abouve m_count)
483 // remove excess of slices (abouve m_count)
448 if (m_count != -1 && m_series->points().size() > m_count)
484 if (m_count != -1 && m_series->points().size() > m_count)
449 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
485 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
450 m_series->remove(m_series->points().at(i));
486 m_series->remove(m_series->points().at(i));
451 }
487 }
452 }
488 }
453 }
489 }
454
490
455 void QXYModelMapperPrivate::removeData(int start, int end)
491 void QXYModelMapperPrivate::removeData(int start, int end)
456 {
492 {
457 if (m_model == 0 || m_series == 0)
493 if (m_model == 0 || m_series == 0)
458 return;
494 return;
459
495
460 int removedCount = end - start + 1;
496 int removedCount = end - start + 1;
461 if (m_count != -1 && start >= m_first + m_count) {
497 if (m_count != -1 && start >= m_first + m_count) {
462 return;
498 return;
463 } else {
499 } else {
464 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
500 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
465 int first = qMax(start, m_first); // get the index of the first item that will be removed.
501 int first = qMax(start, m_first); // get the index of the first item that will be removed.
466 int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed.
502 int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed.
467 for (int i = last; i >= first; i--) {
503 for (int i = last; i >= first; i--) {
468 m_series->remove(m_series->points().at(i - m_first));
504 m_series->remove(m_series->points().at(i - m_first));
469 }
505 }
470
506
471 if (m_count != -1) {
507 if (m_count != -1) {
472 int itemsAvailable; // check how many are available to be added
508 int itemsAvailable; // check how many are available to be added
473 if (m_orientation == Qt::Vertical)
509 if (m_orientation == Qt::Vertical)
474 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
510 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
475 else
511 else
476 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
512 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
477 int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled.
513 int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled.
478 int currentSize = m_series->count();
514 int currentSize = m_series->count();
479 if (toBeAdded > 0)
515 if (toBeAdded > 0)
480 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
516 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
481 QPointF point;
517 QPointF point;
482 QModelIndex xIndex = xModelIndex(i);
518 QModelIndex xIndex = xModelIndex(i);
483 QModelIndex yIndex = yModelIndex(i);
519 QModelIndex yIndex = yModelIndex(i);
484 if (xIndex.isValid() && yIndex.isValid()) {
520 if (xIndex.isValid() && yIndex.isValid()) {
485 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
521 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
486 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
522 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
487 m_series->insert(i, point);
523 m_series->insert(i, point);
488 }
524 }
489 }
525 }
490 }
526 }
491 }
527 }
492 }
528 }
493
529
494 void QXYModelMapperPrivate::initializeXYFromModel()
530 void QXYModelMapperPrivate::initializeXYFromModel()
495 {
531 {
496 if (m_model == 0 || m_series == 0)
532 if (m_model == 0 || m_series == 0)
497 return;
533 return;
498
534
499 blockSeriesSignals();
535 blockSeriesSignals();
500 // clear current content
536 // clear current content
501 m_series->clear();
537 m_series->clear();
502
538
503 // create the initial slices set
539 // create the initial slices set
504 int pointPos = 0;
540 int pointPos = 0;
505 QModelIndex xIndex = xModelIndex(pointPos);
541 QModelIndex xIndex = xModelIndex(pointPos);
506 QModelIndex yIndex = yModelIndex(pointPos);
542 QModelIndex yIndex = yModelIndex(pointPos);
507 while (xIndex.isValid() && yIndex.isValid()) {
543 while (xIndex.isValid() && yIndex.isValid()) {
508 QPointF point;
544 QPointF point;
509 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
545 point.setX(m_model->data(xIndex, Qt::DisplayRole).toDouble());
510 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
546 point.setY(m_model->data(yIndex, Qt::DisplayRole).toDouble());
511 m_series->append(point);
547 m_series->append(point);
512 pointPos++;
548 pointPos++;
513 xIndex = xModelIndex(pointPos);
549 xIndex = xModelIndex(pointPos);
514 yIndex = yModelIndex(pointPos);
550 yIndex = yModelIndex(pointPos);
515 }
551 }
516 blockSeriesSignals(false);
552 blockSeriesSignals(false);
517 }
553 }
518
554
519 #include "moc_qxymodelmapper.cpp"
555 #include "moc_qxymodelmapper.cpp"
520 #include "moc_qxymodelmapper_p.cpp"
556 #include "moc_qxymodelmapper_p.cpp"
521
557
522 QTCOMMERCIALCHART_END_NAMESPACE
558 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,78 +1,84
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 QXYMODELMAPPER_H
21 #ifndef QXYMODELMAPPER_H
22 #define QXYMODELMAPPER_H
22 #define QXYMODELMAPPER_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include <QObject>
25 #include <QObject>
26
26
27 class QAbstractItemModel;
27 class QAbstractItemModel;
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QXYModelMapperPrivate;
31 class QXYModelMapperPrivate;
32 class QXYSeries;
32 class QXYSeries;
33
33
34 class QTCOMMERCIALCHART_EXPORT QXYModelMapper : public QObject
34 class QTCOMMERCIALCHART_EXPORT QXYModelMapper : public QObject
35 {
35 {
36 Q_OBJECT
36 Q_OBJECT
37 Q_PROPERTY(QXYSeries *series READ series WRITE setSeries)
37 Q_PROPERTY(QXYSeries *series READ series WRITE setSeries NOTIFY seriesReplaced)
38 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel)
38 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced)
39 Q_PROPERTY(int first READ first WRITE setFirst)
39 Q_PROPERTY(int first READ first WRITE setFirst NOTIFY firstChanged)
40 Q_PROPERTY(int count READ count WRITE setCount)
40 Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
41 Q_ENUMS(Qt::Orientation)
41 Q_ENUMS(Qt::Orientation)
42
42
43 protected:
43 protected:
44 explicit QXYModelMapper(QObject *parent = 0);
44 explicit QXYModelMapper(QObject *parent = 0);
45
45
46 public:
46 public:
47 QAbstractItemModel* model() const;
47 QAbstractItemModel* model() const;
48 void setModel(QAbstractItemModel *model);
48 void setModel(QAbstractItemModel *model);
49
49
50 QXYSeries* series() const;
50 QXYSeries* series() const;
51 void setSeries(QXYSeries *series);
51 void setSeries(QXYSeries *series);
52
52
53 int first() const;
53 int first() const;
54 void setFirst(int first);
54 void setFirst(int first);
55
55
56 int count() const;
56 int count() const;
57 void setCount(int count);
57 void setCount(int count);
58
58
59 void reset();
59 void reset();
60
60
61 protected:
61 protected:
62 Qt::Orientation orientation() const;
62 Qt::Orientation orientation() const;
63 void setOrientation(Qt::Orientation orientation);
63 void setOrientation(Qt::Orientation orientation);
64
64
65 int xSection() const;
65 int xSection() const;
66 void setXSection(int xSection);
66 void setXSection(int xSection);
67
67
68 int ySection() const;
68 int ySection() const;
69 void setYSection(int ySection);
69 void setYSection(int ySection);
70
70
71 Q_SIGNALS:
72 void seriesReplaced();
73 void modelReplaced();
74 void firstChanged();
75 void countChanged();
76
71 protected:
77 protected:
72 QXYModelMapperPrivate * const d_ptr;
78 QXYModelMapperPrivate * const d_ptr;
73 Q_DECLARE_PRIVATE(QXYModelMapper)
79 Q_DECLARE_PRIVATE(QXYModelMapper)
74 };
80 };
75
81
76 QTCOMMERCIALCHART_END_NAMESPACE
82 QTCOMMERCIALCHART_END_NAMESPACE
77
83
78 #endif // QXYMODELMAPPER_H
84 #endif // QXYMODELMAPPER_H
General Comments 0
You need to be logged in to leave comments. Login now