@@ -1,506 +1,458 | |||||
1 | #include "qbarmodelmapper.h" |
|
1 | #include "qbarmodelmapper.h" | |
2 | #include "qbarmodelmapper_p.h" |
|
2 | #include "qbarmodelmapper_p.h" | |
3 | #include "qbarseries.h" |
|
3 | #include "qbarseries.h" | |
4 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
5 | #include "qchart.h" |
|
5 | #include "qchart.h" | |
6 | #include "qaxis.h" |
|
6 | #include "qaxis.h" | |
7 | #include <QAbstractItemModel> |
|
7 | #include <QAbstractItemModel> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | /*! |
|
11 | /*! | |
12 | \property QBarModelMapper::series |
|
12 | \property QBarModelMapper::series | |
13 | \brief Defines the QPieSeries object that is used by the mapper. |
|
13 | \brief Defines the QPieSeries object that is used by the mapper. | |
14 |
|
14 | |||
15 | All the data in the series in the series is discarded when it is set to the mapper. |
|
15 | All the data in the series in the series is discarded when it is set to the mapper. | |
16 | When new series is specified the old series is disconnected (it preserves its data) |
|
16 | When new series is specified the old series is disconnected (it preserves its data) | |
17 | */ |
|
17 | */ | |
18 |
|
18 | |||
19 | /*! |
|
19 | /*! | |
20 | \property QBarModelMapper::model |
|
20 | \property QBarModelMapper::model | |
21 | \brief Defines the model that is used by the mapper. |
|
21 | \brief Defines the model that is used by the mapper. | |
22 | */ |
|
22 | */ | |
23 |
|
23 | |||
24 | /*! |
|
24 | /*! | |
25 | \property QBarModelMapper::first |
|
25 | \property QBarModelMapper::first | |
26 | \brief Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series. |
|
26 | \brief Defines which item of the model's row/column should be mapped as the value of the first QBarSet in the series. | |
27 |
|
27 | |||
28 | Minimal and default value is: 0 |
|
28 | Minimal and default value is: 0 | |
29 | */ |
|
29 | */ | |
30 |
|
30 | |||
31 | /*! |
|
31 | /*! | |
32 | \property QBarModelMapper::count |
|
32 | \property QBarModelMapper::count | |
33 | \brief Defines the number of rows/columns of the model that are mapped as the data for QBarSeries |
|
33 | \brief Defines the number of rows/columns of the model that are mapped as the data for QBarSeries | |
34 |
|
34 | |||
35 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
35 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \class QBarModelMapper |
|
39 | \class QBarModelMapper | |
40 | \brief part of QtCommercial chart API. |
|
40 | \brief part of QtCommercial chart API. | |
41 | \mainclass |
|
41 | \mainclass | |
42 |
|
42 | |||
43 | The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead. This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object. |
|
43 | The instance of this class cannot be created directly. QHBarModelMapper of QVBarModelMapper should be used instead. This class is used to create a connection between QBarSeries and QAbstractItemModel derived model object. | |
44 | Curently it is NOT possible to use both QAbstractItemModel and QXYSeries model API. |
|
44 | Curently it is NOT possible to use both QAbstractItemModel and QXYSeries model API. | |
45 | When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used. |
|
45 | When the series is set to the mapper the QBarSeries and QBarSet API that affect the data (append, setValue, remove) should not be used. | |
46 | The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets. |
|
46 | The model and the QBarSeries won't be kept in sync. Model API should be used to insert,remove,modify BarSets. | |
47 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
47 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | Constructs a mapper object which is a child of \a parent. |
|
51 | Constructs a mapper object which is a child of \a parent. | |
52 | */ |
|
52 | */ | |
53 | QBarModelMapper::QBarModelMapper(QObject *parent) : |
|
53 | QBarModelMapper::QBarModelMapper(QObject *parent) : | |
54 | QObject(parent), |
|
54 | QObject(parent), | |
55 | d_ptr(new QBarModelMapperPrivate(this)) |
|
55 | d_ptr(new QBarModelMapperPrivate(this)) | |
56 | { |
|
56 | { | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | QAbstractItemModel* QBarModelMapper::model() const |
|
59 | QAbstractItemModel* QBarModelMapper::model() const | |
60 | { |
|
60 | { | |
61 | Q_D(const QBarModelMapper); |
|
61 | Q_D(const QBarModelMapper); | |
62 | return d->m_model; |
|
62 | return d->m_model; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | void QBarModelMapper::setModel(QAbstractItemModel *model) |
|
65 | void QBarModelMapper::setModel(QAbstractItemModel *model) | |
66 | { |
|
66 | { | |
67 | if (model == 0) |
|
67 | if (model == 0) | |
68 | return; |
|
68 | return; | |
69 |
|
69 | |||
70 | Q_D(QBarModelMapper); |
|
70 | Q_D(QBarModelMapper); | |
71 | if (d->m_model) { |
|
71 | if (d->m_model) { | |
72 | disconnect(d->m_model, 0, d, 0); |
|
72 | disconnect(d->m_model, 0, d, 0); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | d->m_model = model; |
|
75 | d->m_model = model; | |
76 | d->initializeBarFromModel(); |
|
76 | d->initializeBarFromModel(); | |
77 | // connect signals from the model |
|
77 | // connect signals from the model | |
78 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
78 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
79 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
79 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
80 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
80 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
81 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
81 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
82 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
82 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | QBarSeries* QBarModelMapper::series() const |
|
85 | QBarSeries* QBarModelMapper::series() const | |
86 | { |
|
86 | { | |
87 | Q_D(const QBarModelMapper); |
|
87 | Q_D(const QBarModelMapper); | |
88 | return d->m_series; |
|
88 | return d->m_series; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | void QBarModelMapper::setSeries(QBarSeries *series) |
|
91 | void QBarModelMapper::setSeries(QBarSeries *series) | |
92 | { |
|
92 | { | |
93 | Q_D(QBarModelMapper); |
|
93 | Q_D(QBarModelMapper); | |
94 | if (d->m_series) { |
|
94 | if (d->m_series) { | |
95 | disconnect(d->m_series, 0, d, 0); |
|
95 | disconnect(d->m_series, 0, d, 0); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | if (series == 0) |
|
98 | if (series == 0) | |
99 | return; |
|
99 | return; | |
100 |
|
100 | |||
101 | d->m_series = series; |
|
101 | d->m_series = series; | |
102 | d->initializeBarFromModel(); |
|
102 | d->initializeBarFromModel(); | |
103 | // connect the signals from the series |
|
103 | // connect the signals from the series | |
104 | // connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int))); |
|
104 | // connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int))); | |
105 | // connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int))); |
|
105 | // connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int))); | |
106 | // connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int))); |
|
106 | // connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int))); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | int QBarModelMapper::first() const |
|
109 | int QBarModelMapper::first() const | |
110 | { |
|
110 | { | |
111 | Q_D(const QBarModelMapper); |
|
111 | Q_D(const QBarModelMapper); | |
112 | return d->m_first; |
|
112 | return d->m_first; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | void QBarModelMapper::setFirst(int first) |
|
115 | void QBarModelMapper::setFirst(int first) | |
116 | { |
|
116 | { | |
117 | Q_D(QBarModelMapper); |
|
117 | Q_D(QBarModelMapper); | |
118 | d->m_first = qMax(first, 0); |
|
118 | d->m_first = qMax(first, 0); | |
119 | d->initializeBarFromModel(); |
|
119 | d->initializeBarFromModel(); | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | int QBarModelMapper::count() const |
|
122 | int QBarModelMapper::count() const | |
123 | { |
|
123 | { | |
124 | Q_D(const QBarModelMapper); |
|
124 | Q_D(const QBarModelMapper); | |
125 | return d->m_count; |
|
125 | return d->m_count; | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | void QBarModelMapper::setCount(int count) |
|
128 | void QBarModelMapper::setCount(int count) | |
129 | { |
|
129 | { | |
130 | Q_D(QBarModelMapper); |
|
130 | Q_D(QBarModelMapper); | |
131 | d->m_count = qMax(count, -1); |
|
131 | d->m_count = qMax(count, -1); | |
132 | d->initializeBarFromModel(); |
|
132 | d->initializeBarFromModel(); | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | /*! |
|
135 | /*! | |
136 | Returns the orientation that is used when QBarModelMapper accesses the model. |
|
136 | Returns the orientation that is used when QBarModelMapper accesses the model. | |
137 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) |
|
137 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) | |
138 | or from columns (Qt::Vertical) |
|
138 | or from columns (Qt::Vertical) | |
139 | */ |
|
139 | */ | |
140 | Qt::Orientation QBarModelMapper::orientation() const |
|
140 | Qt::Orientation QBarModelMapper::orientation() const | |
141 | { |
|
141 | { | |
142 | Q_D(const QBarModelMapper); |
|
142 | Q_D(const QBarModelMapper); | |
143 | return d->m_orientation; |
|
143 | return d->m_orientation; | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | /*! |
|
146 | /*! | |
147 | Returns the \a orientation that is used when QBarModelMapper accesses the model. |
|
147 | Returns the \a orientation that is used when QBarModelMapper accesses the model. | |
148 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) |
|
148 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) | |
149 | or from columns (Qt::Vertical) |
|
149 | or from columns (Qt::Vertical) | |
150 | */ |
|
150 | */ | |
151 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) |
|
151 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) | |
152 | { |
|
152 | { | |
153 | Q_D(QBarModelMapper); |
|
153 | Q_D(QBarModelMapper); | |
154 | d->m_orientation = orientation; |
|
154 | d->m_orientation = orientation; | |
155 | d->initializeBarFromModel(); |
|
155 | d->initializeBarFromModel(); | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | /*! |
|
158 | /*! | |
159 | Returns which section of the model is used as the data source for the first bar set |
|
159 | Returns which section of the model is used as the data source for the first bar set | |
160 | */ |
|
160 | */ | |
161 | int QBarModelMapper::firstBarSetSection() const |
|
161 | int QBarModelMapper::firstBarSetSection() const | |
162 | { |
|
162 | { | |
163 | Q_D(const QBarModelMapper); |
|
163 | Q_D(const QBarModelMapper); | |
164 | return d->m_firstBarSetSection; |
|
164 | return d->m_firstBarSetSection; | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | /*! |
|
167 | /*! | |
168 | Sets the model section that is used as the data source for the first bar set |
|
168 | Sets the model section that is used as the data source for the first bar set | |
169 | Parameter \a firstBarSetSection specifies the section of the model. |
|
169 | Parameter \a firstBarSetSection specifies the section of the model. | |
170 | */ |
|
170 | */ | |
171 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) |
|
171 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) | |
172 | { |
|
172 | { | |
173 | Q_D(QBarModelMapper); |
|
173 | Q_D(QBarModelMapper); | |
174 | d->m_firstBarSetSection = firstBarSetSection; |
|
174 | d->m_firstBarSetSection = firstBarSetSection; | |
175 | d->initializeBarFromModel(); |
|
175 | d->initializeBarFromModel(); | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | /*! |
|
178 | /*! | |
179 | Returns which section of the model is used as the data source for the last bar set |
|
179 | Returns which section of the model is used as the data source for the last bar set | |
180 | */ |
|
180 | */ | |
181 | int QBarModelMapper::lastBarSetSection() const |
|
181 | int QBarModelMapper::lastBarSetSection() const | |
182 | { |
|
182 | { | |
183 | Q_D(const QBarModelMapper); |
|
183 | Q_D(const QBarModelMapper); | |
184 | return d->m_lastBarSetSection; |
|
184 | return d->m_lastBarSetSection; | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | /*! |
|
187 | /*! | |
188 | Sets the model section that is used as the data source for the last bar set |
|
188 | Sets the model section that is used as the data source for the last bar set | |
189 | Parameter \a lastBarSetSection specifies the section of the model. |
|
189 | Parameter \a lastBarSetSection specifies the section of the model. | |
190 | */ |
|
190 | */ | |
191 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) |
|
191 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) | |
192 | { |
|
192 | { | |
193 | Q_D(QBarModelMapper); |
|
193 | Q_D(QBarModelMapper); | |
194 | d->m_lastBarSetSection = lastBarSetSection; |
|
194 | d->m_lastBarSetSection = lastBarSetSection; | |
195 | d->initializeBarFromModel(); |
|
195 | d->initializeBarFromModel(); | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | Returns which section of the model is used as the data source for the x axis categories. |
|
|||
200 | */ |
|
|||
201 | int QBarModelMapper::categoriesSection() const |
|
|||
202 | { |
|
|||
203 | Q_D(const QBarModelMapper); |
|
|||
204 | return d->m_categoriesSection; |
|
|||
205 | } |
|
|||
206 |
|
||||
207 | /*! |
|
|||
208 | Sets the model section that is used as the data source for the x axis categories. |
|
|||
209 | Parameter \a categoriesSection specifies the section of the model. |
|
|||
210 | */ |
|
|||
211 | void QBarModelMapper::setCategoriesSection(int categoriesSection) |
|
|||
212 | { |
|
|||
213 | Q_D(QBarModelMapper); |
|
|||
214 | d->m_categoriesSection = categoriesSection; |
|
|||
215 | d->initializeBarFromModel(); |
|
|||
216 | } |
|
|||
217 |
|
||||
218 | /*! |
|
|||
219 | Resets the QBarModelMapper to the default state. |
|
199 | Resets the QBarModelMapper to the default state. | |
220 | first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1 |
|
200 | first: 0; count: -1; firstBarSetSection: -1; lastBarSetSection: -1; categoriesSection: -1 | |
221 | */ |
|
201 | */ | |
222 | void QBarModelMapper::reset() |
|
202 | void QBarModelMapper::reset() | |
223 | { |
|
203 | { | |
224 | Q_D(QBarModelMapper); |
|
204 | Q_D(QBarModelMapper); | |
225 | d->m_first = 0; |
|
205 | d->m_first = 0; | |
226 | d->m_count = -1; |
|
206 | d->m_count = -1; | |
227 | d->m_firstBarSetSection = -1; |
|
207 | d->m_firstBarSetSection = -1; | |
228 | d->m_lastBarSetSection = -1; |
|
208 | d->m_lastBarSetSection = -1; | |
229 | d->m_categoriesSection = -1; |
|
|||
230 | d->initializeBarFromModel(); |
|
209 | d->initializeBarFromModel(); | |
231 | } |
|
210 | } | |
232 |
|
211 | |||
233 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
212 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
234 |
|
213 | |||
235 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : |
|
214 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : | |
236 | m_series(0), |
|
215 | m_series(0), | |
237 | m_model(0), |
|
216 | m_model(0), | |
238 | m_first(0), |
|
217 | m_first(0), | |
239 | m_count(-1), |
|
218 | m_count(-1), | |
240 | m_orientation(Qt::Vertical), |
|
219 | m_orientation(Qt::Vertical), | |
241 | m_firstBarSetSection(-1), |
|
220 | m_firstBarSetSection(-1), | |
242 | m_lastBarSetSection(-1), |
|
221 | m_lastBarSetSection(-1), | |
243 | m_categoriesSection(-1), |
|
|||
244 | m_seriesSignalsBlock(false), |
|
222 | m_seriesSignalsBlock(false), | |
245 | m_modelSignalsBlock(false), |
|
223 | m_modelSignalsBlock(false), | |
246 | q_ptr(q) |
|
224 | q_ptr(q) | |
247 | { |
|
225 | { | |
248 | } |
|
226 | } | |
249 |
|
227 | |||
250 | void QBarModelMapperPrivate::blockModelSignals(bool block) |
|
228 | void QBarModelMapperPrivate::blockModelSignals(bool block) | |
251 | { |
|
229 | { | |
252 | m_modelSignalsBlock = block; |
|
230 | m_modelSignalsBlock = block; | |
253 | } |
|
231 | } | |
254 |
|
232 | |||
255 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) |
|
233 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) | |
256 | { |
|
234 | { | |
257 | m_seriesSignalsBlock = block; |
|
235 | m_seriesSignalsBlock = block; | |
258 | } |
|
236 | } | |
259 |
|
237 | |||
260 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) |
|
238 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) | |
261 | { |
|
239 | { | |
262 | if (!index.isValid()) |
|
240 | if (!index.isValid()) | |
263 | return 0; |
|
241 | return 0; | |
264 |
|
242 | |||
265 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { |
|
243 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { | |
266 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
244 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { | |
267 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) |
|
245 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) | |
268 | return m_series->barSets().at(index.column() - m_firstBarSetSection); |
|
246 | return m_series->barSets().at(index.column() - m_firstBarSetSection); | |
269 | // else |
|
247 | // else | |
270 | // return 0; |
|
248 | // return 0; | |
271 | } |
|
249 | } | |
272 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { |
|
250 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { | |
273 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) |
|
251 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) | |
274 | return m_series->barSets().at(index.row() - m_firstBarSetSection); |
|
252 | return m_series->barSets().at(index.row() - m_firstBarSetSection); | |
275 | } |
|
253 | } | |
276 | return 0; // This part of model has not been mapped to any slice |
|
254 | return 0; // This part of model has not been mapped to any slice | |
277 | } |
|
255 | } | |
278 |
|
256 | |||
279 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) |
|
257 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) | |
280 | { |
|
258 | { | |
281 | if (m_count != -1 && posInBar >= m_count) |
|
259 | if (m_count != -1 && posInBar >= m_count) | |
282 | return QModelIndex(); // invalid |
|
260 | return QModelIndex(); // invalid | |
283 |
|
261 | |||
284 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) |
|
262 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) | |
285 | return QModelIndex(); // invalid |
|
263 | return QModelIndex(); // invalid | |
286 |
|
264 | |||
287 | if (m_orientation == Qt::Vertical) |
|
265 | if (m_orientation == Qt::Vertical) | |
288 | return m_model->index(posInBar + m_first, barSection); |
|
266 | return m_model->index(posInBar + m_first, barSection); | |
289 | else |
|
267 | else | |
290 | return m_model->index(barSection, posInBar + m_first); |
|
268 | return m_model->index(barSection, posInBar + m_first); | |
291 | } |
|
269 | } | |
292 |
|
270 | |||
293 | QModelIndex QBarModelMapperPrivate::categoriesModelIndex(int posInCategories) |
|
|||
294 | { |
|
|||
295 | if (m_count != -1 && posInCategories >= m_count) |
|
|||
296 | return QModelIndex(); // invalid |
|
|||
297 |
|
||||
298 | if (m_orientation == Qt::Vertical) |
|
|||
299 | return m_model->index(posInCategories + m_first, m_categoriesSection); |
|
|||
300 | else |
|
|||
301 | return m_model->index(m_categoriesSection, posInCategories + m_first); |
|
|||
302 | } |
|
|||
303 |
|
||||
304 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
271 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
305 | { |
|
272 | { | |
306 | Q_UNUSED(topLeft) |
|
273 | Q_UNUSED(topLeft) | |
307 | Q_UNUSED(bottomRight) |
|
274 | Q_UNUSED(bottomRight) | |
308 |
|
275 | |||
309 | if (m_model == 0 || m_series == 0) |
|
276 | if (m_model == 0 || m_series == 0) | |
310 | return; |
|
277 | return; | |
311 |
|
278 | |||
312 | if (m_modelSignalsBlock) |
|
279 | if (m_modelSignalsBlock) | |
313 | return; |
|
280 | return; | |
314 |
|
281 | |||
315 | blockSeriesSignals(); |
|
282 | blockSeriesSignals(); | |
316 | QModelIndex index; |
|
283 | QModelIndex index; | |
317 | // QPointF oldPoint; |
|
|||
318 | // QPointF newPoint; |
|
|||
319 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
284 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
320 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
285 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
321 | index = topLeft.sibling(row, column); |
|
286 | index = topLeft.sibling(row, column); | |
322 | QBarSet* bar = barSet(index); |
|
287 | QBarSet* bar = barSet(index); | |
323 | if (bar) { |
|
288 | if (bar) { | |
324 | if (m_orientation == Qt::Vertical) |
|
289 | if (m_orientation == Qt::Vertical) | |
325 | bar->replace(row - m_first, m_model->data(index).toReal()); |
|
290 | bar->replace(row - m_first, m_model->data(index).toReal()); | |
326 | else |
|
291 | else | |
327 | bar->replace(column - m_first, m_model->data(index).toReal()); |
|
292 | bar->replace(column - m_first, m_model->data(index).toReal()); | |
328 | } |
|
293 | } | |
329 | } |
|
294 | } | |
330 | } |
|
295 | } | |
331 | blockSeriesSignals(false); |
|
296 | blockSeriesSignals(false); | |
332 | } |
|
297 | } | |
333 |
|
298 | |||
334 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
299 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
335 | { |
|
300 | { | |
336 | Q_UNUSED(parent); |
|
301 | Q_UNUSED(parent); | |
337 | Q_UNUSED(end) |
|
302 | Q_UNUSED(end) | |
338 | if (m_modelSignalsBlock) |
|
303 | if (m_modelSignalsBlock) | |
339 | return; |
|
304 | return; | |
340 |
|
305 | |||
341 | blockSeriesSignals(); |
|
306 | blockSeriesSignals(); | |
342 | if (m_orientation == Qt::Vertical) |
|
307 | if (m_orientation == Qt::Vertical) | |
343 | // insertData(start, end); |
|
308 | // insertData(start, end); | |
344 | initializeBarFromModel(); |
|
309 | initializeBarFromModel(); | |
345 |
else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection |
|
310 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
346 | initializeBarFromModel(); |
|
311 | initializeBarFromModel(); | |
347 | blockSeriesSignals(false); |
|
312 | blockSeriesSignals(false); | |
348 | } |
|
313 | } | |
349 |
|
314 | |||
350 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
315 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
351 | { |
|
316 | { | |
352 | Q_UNUSED(parent); |
|
317 | Q_UNUSED(parent); | |
353 | Q_UNUSED(end) |
|
318 | Q_UNUSED(end) | |
354 | if (m_modelSignalsBlock) |
|
319 | if (m_modelSignalsBlock) | |
355 | return; |
|
320 | return; | |
356 |
|
321 | |||
357 | blockSeriesSignals(); |
|
322 | blockSeriesSignals(); | |
358 | if (m_orientation == Qt::Vertical) |
|
323 | if (m_orientation == Qt::Vertical) | |
359 | // removeData(start, end); |
|
324 | // removeData(start, end); | |
360 | initializeBarFromModel(); |
|
325 | initializeBarFromModel(); | |
361 |
else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection |
|
326 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
362 | initializeBarFromModel(); |
|
327 | initializeBarFromModel(); | |
363 | blockSeriesSignals(false); |
|
328 | blockSeriesSignals(false); | |
364 | } |
|
329 | } | |
365 |
|
330 | |||
366 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
331 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
367 | { |
|
332 | { | |
368 | Q_UNUSED(parent); |
|
333 | Q_UNUSED(parent); | |
369 | Q_UNUSED(end) |
|
334 | Q_UNUSED(end) | |
370 | if (m_modelSignalsBlock) |
|
335 | if (m_modelSignalsBlock) | |
371 | return; |
|
336 | return; | |
372 |
|
337 | |||
373 | blockSeriesSignals(); |
|
338 | blockSeriesSignals(); | |
374 | if (m_orientation == Qt::Horizontal) |
|
339 | if (m_orientation == Qt::Horizontal) | |
375 | // insertData(start, end); |
|
340 | // insertData(start, end); | |
376 | initializeBarFromModel(); |
|
341 | initializeBarFromModel(); | |
377 |
else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection |
|
342 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
378 | initializeBarFromModel(); |
|
343 | initializeBarFromModel(); | |
379 | blockSeriesSignals(false); |
|
344 | blockSeriesSignals(false); | |
380 | } |
|
345 | } | |
381 |
|
346 | |||
382 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
347 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
383 | { |
|
348 | { | |
384 | Q_UNUSED(parent); |
|
349 | Q_UNUSED(parent); | |
385 | Q_UNUSED(end) |
|
350 | Q_UNUSED(end) | |
386 | if (m_modelSignalsBlock) |
|
351 | if (m_modelSignalsBlock) | |
387 | return; |
|
352 | return; | |
388 |
|
353 | |||
389 | blockSeriesSignals(); |
|
354 | blockSeriesSignals(); | |
390 | if (m_orientation == Qt::Horizontal) |
|
355 | if (m_orientation == Qt::Horizontal) | |
391 | // removeData(start, end); |
|
356 | // removeData(start, end); | |
392 | initializeBarFromModel(); |
|
357 | initializeBarFromModel(); | |
393 |
else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection |
|
358 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
394 | initializeBarFromModel(); |
|
359 | initializeBarFromModel(); | |
395 | blockSeriesSignals(false); |
|
360 | blockSeriesSignals(false); | |
396 | } |
|
361 | } | |
397 |
|
362 | |||
398 | void QBarModelMapperPrivate::insertData(int start, int end) |
|
363 | void QBarModelMapperPrivate::insertData(int start, int end) | |
399 | { |
|
364 | { | |
400 | Q_UNUSED(end) |
|
365 | Q_UNUSED(end) | |
401 | if (m_model == 0 || m_series == 0) |
|
366 | if (m_model == 0 || m_series == 0) | |
402 | return; |
|
367 | return; | |
403 |
|
368 | |||
404 | if (m_count != -1 && start >= m_first + m_count) { |
|
369 | if (m_count != -1 && start >= m_first + m_count) { | |
405 | return; |
|
370 | return; | |
406 | } /*else { |
|
371 | } /*else { | |
407 | int addedCount = end - start + 1; |
|
372 | int addedCount = end - start + 1; | |
408 | if (m_count != -1 && addedCount > m_count) |
|
373 | if (m_count != -1 && addedCount > m_count) | |
409 | addedCount = m_count; |
|
374 | addedCount = m_count; | |
410 | int first = qMax(start, m_first); |
|
375 | int first = qMax(start, m_first); | |
411 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); |
|
376 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); | |
412 | for (int k = 0; k < m_series->barSets().count(); k++) { |
|
377 | for (int k = 0; k < m_series->barSets().count(); k++) { | |
413 | for (int i = first; i <= last; i++) { |
|
378 | for (int i = first; i <= last; i++) { | |
414 | QBar point; |
|
379 | QBar point; | |
415 | point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble()); |
|
380 | point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble()); | |
416 | point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble()); |
|
381 | point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble()); | |
417 | m_series->insert(i - m_first, point); |
|
382 | m_series->insert(i - m_first, point); | |
418 | } |
|
383 | } | |
419 | >>>>>>> Stashed changes |
|
384 | >>>>>>> Stashed changes | |
420 | } |
|
385 | } | |
421 |
|
386 | |||
422 | // remove excess of slices (abouve m_count) |
|
387 | // remove excess of slices (abouve m_count) | |
423 | if (m_count != -1 && m_series->points().size() > m_count) |
|
388 | if (m_count != -1 && m_series->points().size() > m_count) | |
424 | for (int i = m_series->points().size() - 1; i >= m_count; i--) { |
|
389 | for (int i = m_series->points().size() - 1; i >= m_count; i--) { | |
425 | m_series->remove(m_series->points().at(i)); |
|
390 | m_series->remove(m_series->points().at(i)); | |
426 | } |
|
391 | } | |
427 | }*/ |
|
392 | }*/ | |
428 | } |
|
393 | } | |
429 |
|
394 | |||
430 | void QBarModelMapperPrivate::removeData(int start, int end) |
|
395 | void QBarModelMapperPrivate::removeData(int start, int end) | |
431 | { |
|
396 | { | |
432 | Q_UNUSED(end) |
|
397 | Q_UNUSED(end) | |
433 | if (m_model == 0 || m_series == 0) |
|
398 | if (m_model == 0 || m_series == 0) | |
434 | return; |
|
399 | return; | |
435 |
|
400 | |||
436 | // int removedCount = end - start + 1; |
|
401 | // int removedCount = end - start + 1; | |
437 | if (m_count != -1 && start >= m_first + m_count) { |
|
402 | if (m_count != -1 && start >= m_first + m_count) { | |
438 | return; |
|
403 | return; | |
439 | } /*else { |
|
404 | } /*else { | |
440 | int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed |
|
405 | int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed | |
441 | int first = qMax(start, m_first); // get the index of the first item that will be removed. |
|
406 | int first = qMax(start, m_first); // get the index of the first item that will be removed. | |
442 | int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed. |
|
407 | int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed. | |
443 | for (int i = last; i >= first; i--) { |
|
408 | for (int i = last; i >= first; i--) { | |
444 | m_series->remove(m_series->points().at(i - m_first)); |
|
409 | m_series->remove(m_series->points().at(i - m_first)); | |
445 | } |
|
410 | } | |
446 |
|
411 | |||
447 | if (m_count != -1) { |
|
412 | if (m_count != -1) { | |
448 | int itemsAvailable; // check how many are available to be added |
|
413 | int itemsAvailable; // check how many are available to be added | |
449 | if (m_orientation == Qt::Vertical) |
|
414 | if (m_orientation == Qt::Vertical) | |
450 | itemsAvailable = m_model->rowCount() - m_first - m_series->count(); |
|
415 | itemsAvailable = m_model->rowCount() - m_first - m_series->count(); | |
451 | else |
|
416 | else | |
452 | itemsAvailable = m_model->columnCount() - m_first - m_series->count(); |
|
417 | itemsAvailable = m_model->columnCount() - m_first - m_series->count(); | |
453 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled. |
|
418 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled. | |
454 | int currentSize = m_series->count(); |
|
419 | int currentSize = m_series->count(); | |
455 | if (toBeAdded > 0) |
|
420 | if (toBeAdded > 0) | |
456 | for (int i = m_series->count(); i < currentSize + toBeAdded; i++) { |
|
421 | for (int i = m_series->count(); i < currentSize + toBeAdded; i++) { | |
457 | QPointF point; |
|
422 | QPointF point; | |
458 | point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble()); |
|
423 | point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble()); | |
459 | point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble()); |
|
424 | point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble()); | |
460 | m_series->insert(i, point); |
|
425 | m_series->insert(i, point); | |
461 | } |
|
426 | } | |
462 | } |
|
427 | } | |
463 | }*/ |
|
428 | }*/ | |
464 | } |
|
429 | } | |
465 |
|
430 | |||
466 | void QBarModelMapperPrivate::initializeBarFromModel() |
|
431 | void QBarModelMapperPrivate::initializeBarFromModel() | |
467 | { |
|
432 | { | |
468 | if (m_model == 0 || m_series == 0) |
|
433 | if (m_model == 0 || m_series == 0) | |
469 | return; |
|
434 | return; | |
470 |
|
435 | |||
471 | blockSeriesSignals(); |
|
436 | blockSeriesSignals(); | |
472 | // clear current content |
|
437 | // clear current content | |
473 | m_series->clear(); |
|
438 | m_series->clear(); | |
474 |
|
439 | |||
475 | // create the initial bar sets |
|
440 | // create the initial bar sets | |
476 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { |
|
441 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { | |
477 | int posInBar = 0; |
|
442 | int posInBar = 0; | |
478 | QModelIndex barIndex = barModelIndex(i, posInBar); |
|
443 | QModelIndex barIndex = barModelIndex(i, posInBar); | |
479 | QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString()); |
|
444 | QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString()); | |
480 | // QModelIndex yIndex = yModelIndex(pointPos); |
|
|||
481 | while (barIndex.isValid()) { |
|
445 | while (barIndex.isValid()) { | |
482 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); |
|
446 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); | |
483 | posInBar++; |
|
447 | posInBar++; | |
484 | barIndex = barModelIndex(i, posInBar); |
|
448 | barIndex = barModelIndex(i, posInBar); | |
485 | } |
|
449 | } | |
486 | m_series->append(barSet); |
|
450 | m_series->append(barSet); | |
487 | } |
|
451 | } | |
488 |
|
||||
489 | if (m_series->chart() && m_categoriesSection != -1) { |
|
|||
490 | int posInCategories = 0; |
|
|||
491 | QStringList categories; |
|
|||
492 | QModelIndex categoriesIndex = categoriesModelIndex(posInCategories); |
|
|||
493 | while (categoriesIndex.isValid()) { |
|
|||
494 | categories.append(m_model->data(categoriesIndex, Qt::DisplayRole).toString()); |
|
|||
495 | posInCategories++; |
|
|||
496 | categoriesIndex = categoriesModelIndex(posInCategories); |
|
|||
497 | } |
|
|||
498 | m_series->chart()->axisX()->categories()->insert(categories); |
|
|||
499 | } |
|
|||
500 | blockSeriesSignals(false); |
|
452 | blockSeriesSignals(false); | |
501 | } |
|
453 | } | |
502 |
|
454 | |||
503 | #include "moc_qbarmodelmapper.cpp" |
|
455 | #include "moc_qbarmodelmapper.cpp" | |
504 | #include "moc_qbarmodelmapper_p.cpp" |
|
456 | #include "moc_qbarmodelmapper_p.cpp" | |
505 |
|
457 | |||
506 | QTCOMMERCIALCHART_END_NAMESPACE |
|
458 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,62 +1,59 | |||||
1 | #ifndef QBARMODELMAPPER_H |
|
1 | #ifndef QBARMODELMAPPER_H | |
2 | #define QBARMODELMAPPER_H |
|
2 | #define QBARMODELMAPPER_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 |
|
6 | |||
7 | class QAbstractItemModel; |
|
7 | class QAbstractItemModel; | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class QBarModelMapperPrivate; |
|
11 | class QBarModelMapperPrivate; | |
12 | class QBarSeries; |
|
12 | class QBarSeries; | |
13 | class QChart; |
|
13 | class QChart; | |
14 |
|
14 | |||
15 | class QTCOMMERCIALCHART_EXPORT QBarModelMapper : public QObject |
|
15 | class QTCOMMERCIALCHART_EXPORT QBarModelMapper : public QObject | |
16 | { |
|
16 | { | |
17 | Q_OBJECT |
|
17 | Q_OBJECT | |
18 | Q_PROPERTY(QBarSeries *series READ series WRITE setSeries) |
|
18 | Q_PROPERTY(QBarSeries *series READ series WRITE setSeries) | |
19 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel) |
|
19 | Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel) | |
20 | Q_PROPERTY(int first READ first WRITE setFirst) |
|
20 | Q_PROPERTY(int first READ first WRITE setFirst) | |
21 | Q_PROPERTY(int count READ count WRITE setCount) |
|
21 | Q_PROPERTY(int count READ count WRITE setCount) | |
22 | Q_ENUMS(Qt::Orientation) |
|
22 | Q_ENUMS(Qt::Orientation) | |
23 |
|
23 | |||
24 | protected: |
|
24 | protected: | |
25 | explicit QBarModelMapper(QObject *parent = 0); |
|
25 | explicit QBarModelMapper(QObject *parent = 0); | |
26 |
|
26 | |||
27 | public: |
|
27 | public: | |
28 | QAbstractItemModel* model() const; |
|
28 | QAbstractItemModel* model() const; | |
29 | void setModel(QAbstractItemModel *model); |
|
29 | void setModel(QAbstractItemModel *model); | |
30 |
|
30 | |||
31 | QBarSeries* series() const; |
|
31 | QBarSeries* series() const; | |
32 | void setSeries(QBarSeries *series); |
|
32 | void setSeries(QBarSeries *series); | |
33 |
|
33 | |||
34 | int first() const; |
|
34 | int first() const; | |
35 | void setFirst(int first); |
|
35 | void setFirst(int first); | |
36 |
|
36 | |||
37 | int count() const; |
|
37 | int count() const; | |
38 | void setCount(int count); |
|
38 | void setCount(int count); | |
39 |
|
39 | |||
40 | void reset(); |
|
40 | void reset(); | |
41 |
|
41 | |||
42 | protected: |
|
42 | protected: | |
43 | int firstBarSetSection() const; |
|
43 | int firstBarSetSection() const; | |
44 | void setFirstBarSetSection(int firstBarSetSection); |
|
44 | void setFirstBarSetSection(int firstBarSetSection); | |
45 |
|
45 | |||
46 | int lastBarSetSection() const; |
|
46 | int lastBarSetSection() const; | |
47 | void setLastBarSetSection(int lastBarSetSection); |
|
47 | void setLastBarSetSection(int lastBarSetSection); | |
48 |
|
48 | |||
49 | int categoriesSection() const; |
|
|||
50 | void setCategoriesSection(int categoriesSection); |
|
|||
51 |
|
||||
52 | Qt::Orientation orientation() const; |
|
49 | Qt::Orientation orientation() const; | |
53 | void setOrientation(Qt::Orientation orientation); |
|
50 | void setOrientation(Qt::Orientation orientation); | |
54 |
|
51 | |||
55 | protected: |
|
52 | protected: | |
56 | QBarModelMapperPrivate * const d_ptr; |
|
53 | QBarModelMapperPrivate * const d_ptr; | |
57 | Q_DECLARE_PRIVATE(QBarModelMapper) |
|
54 | Q_DECLARE_PRIVATE(QBarModelMapper) | |
58 | }; |
|
55 | }; | |
59 |
|
56 | |||
60 | QTCOMMERCIALCHART_END_NAMESPACE |
|
57 | QTCOMMERCIALCHART_END_NAMESPACE | |
61 |
|
58 | |||
62 | #endif // QBARMODELMAPPER_H |
|
59 | #endif // QBARMODELMAPPER_H |
@@ -1,63 +1,61 | |||||
1 | #ifndef QBARMODELMAPPER_P_H |
|
1 | #ifndef QBARMODELMAPPER_P_H | |
2 | #define QBARMODELMAPPER_P_H |
|
2 | #define QBARMODELMAPPER_P_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include "qbarmodelmapper.h" |
|
6 | #include "qbarmodelmapper.h" | |
7 |
|
7 | |||
8 | class QModelIndex; |
|
8 | class QModelIndex; | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | class QBarSet; |
|
12 | class QBarSet; | |
13 |
|
13 | |||
14 | class QBarModelMapperPrivate : public QObject |
|
14 | class QBarModelMapperPrivate : public QObject | |
15 | { |
|
15 | { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 | public: |
|
17 | public: | |
18 | explicit QBarModelMapperPrivate(QBarModelMapper *q); |
|
18 | explicit QBarModelMapperPrivate(QBarModelMapper *q); | |
19 |
|
19 | |||
20 | public Q_SLOTS: |
|
20 | public Q_SLOTS: | |
21 | // for the model |
|
21 | // for the model | |
22 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
22 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
23 | void modelRowsAdded(QModelIndex parent, int start, int end); |
|
23 | void modelRowsAdded(QModelIndex parent, int start, int end); | |
24 | void modelRowsRemoved(QModelIndex parent, int start, int end); |
|
24 | void modelRowsRemoved(QModelIndex parent, int start, int end); | |
25 | void modelColumnsAdded(QModelIndex parent, int start, int end); |
|
25 | void modelColumnsAdded(QModelIndex parent, int start, int end); | |
26 | void modelColumnsRemoved(QModelIndex parent, int start, int end); |
|
26 | void modelColumnsRemoved(QModelIndex parent, int start, int end); | |
27 |
|
27 | |||
28 | // // for the series |
|
28 | // // for the series | |
29 | // void handlePointAdded(int pointPos); |
|
29 | // void handlePointAdded(int pointPos); | |
30 | // void handlePointRemoved(int pointPos); |
|
30 | // void handlePointRemoved(int pointPos); | |
31 | // void handlePointReplaced(int pointPos); |
|
31 | // void handlePointReplaced(int pointPos); | |
32 |
|
32 | |||
33 | void initializeBarFromModel(); |
|
33 | void initializeBarFromModel(); | |
34 |
|
34 | |||
35 | private: |
|
35 | private: | |
36 | QBarSet* barSet(QModelIndex index); |
|
36 | QBarSet* barSet(QModelIndex index); | |
37 | QModelIndex barModelIndex(int barSection, int posInBar); |
|
37 | QModelIndex barModelIndex(int barSection, int posInBar); | |
38 | QModelIndex categoriesModelIndex(int posInCategories); |
|
|||
39 | void insertData(int start, int end); |
|
38 | void insertData(int start, int end); | |
40 | void removeData(int start, int end); |
|
39 | void removeData(int start, int end); | |
41 | void blockModelSignals(bool block = true); |
|
40 | void blockModelSignals(bool block = true); | |
42 | void blockSeriesSignals(bool block = true); |
|
41 | void blockSeriesSignals(bool block = true); | |
43 |
|
42 | |||
44 | private: |
|
43 | private: | |
45 | QBarSeries *m_series; |
|
44 | QBarSeries *m_series; | |
46 | QAbstractItemModel *m_model; |
|
45 | QAbstractItemModel *m_model; | |
47 | int m_first; |
|
46 | int m_first; | |
48 | int m_count; |
|
47 | int m_count; | |
49 | Qt::Orientation m_orientation; |
|
48 | Qt::Orientation m_orientation; | |
50 | int m_firstBarSetSection; |
|
49 | int m_firstBarSetSection; | |
51 | int m_lastBarSetSection; |
|
50 | int m_lastBarSetSection; | |
52 | int m_categoriesSection; |
|
|||
53 | bool m_seriesSignalsBlock; |
|
51 | bool m_seriesSignalsBlock; | |
54 | bool m_modelSignalsBlock; |
|
52 | bool m_modelSignalsBlock; | |
55 |
|
53 | |||
56 | private: |
|
54 | private: | |
57 | QBarModelMapper *q_ptr; |
|
55 | QBarModelMapper *q_ptr; | |
58 | Q_DECLARE_PUBLIC(QBarModelMapper) |
|
56 | Q_DECLARE_PUBLIC(QBarModelMapper) | |
59 | }; |
|
57 | }; | |
60 |
|
58 | |||
61 | QTCOMMERCIALCHART_END_NAMESPACE |
|
59 | QTCOMMERCIALCHART_END_NAMESPACE | |
62 |
|
60 | |||
63 | #endif // QBARMODELMAPPER_P_H |
|
61 | #endif // QBARMODELMAPPER_P_H |
@@ -1,75 +1,58 | |||||
1 | #include "qhbarmodelmapper.h" |
|
1 | #include "qhbarmodelmapper.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | /*! |
|
5 | /*! | |
6 | \class QHBarModelMapper |
|
6 | \class QHBarModelMapper | |
7 | \brief part of QtCommercial chart API. |
|
7 | \brief part of QtCommercial chart API. | |
8 | \mainclass |
|
8 | \mainclass | |
9 |
|
9 | |||
10 | Nothing here yet |
|
10 | Nothing here yet | |
11 | */ |
|
11 | */ | |
12 |
|
12 | |||
13 | /*! |
|
13 | /*! | |
14 | \property QHBarModelMapper::firstBarSetRow |
|
14 | \property QHBarModelMapper::firstBarSetRow | |
15 | \brief Defines which column of the model is used as the data source for the first bar set |
|
15 | \brief Defines which column of the model is used as the data source for the first bar set | |
16 |
|
16 | |||
17 | Default value is: -1 (invalid mapping) |
|
17 | Default value is: -1 (invalid mapping) | |
18 | */ |
|
18 | */ | |
19 |
|
19 | |||
20 | /*! |
|
20 | /*! | |
21 | \property QHBarModelMapper::lastBarSetRow |
|
21 | \property QHBarModelMapper::lastBarSetRow | |
22 | \brief Defines which column of the model is used as the data source for the last bar set |
|
22 | \brief Defines which column of the model is used as the data source for the last bar set | |
23 |
|
23 | |||
24 | Default value is: -1 (invalid mapping) |
|
24 | Default value is: -1 (invalid mapping) | |
25 | */ |
|
25 | */ | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \property QHBarModelMapper::categoriesRow |
|
|||
29 | \brief Defines which row of the model is used as the data source for the x axis categories |
|
|||
30 |
|
||||
31 | Default value is: -1 (invalid mapping) |
|
|||
32 | */ |
|
|||
33 |
|
||||
34 | /*! |
|
|||
35 | Constructs a mapper object which is a child of \a parent. |
|
28 | Constructs a mapper object which is a child of \a parent. | |
36 | */ |
|
29 | */ | |
37 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : |
|
30 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : | |
38 | QBarModelMapper(parent) |
|
31 | QBarModelMapper(parent) | |
39 | { |
|
32 | { | |
40 | QBarModelMapper::setOrientation(Qt::Horizontal); |
|
33 | QBarModelMapper::setOrientation(Qt::Horizontal); | |
41 | } |
|
34 | } | |
42 |
|
35 | |||
43 | int QHBarModelMapper::firstBarSetRow() const |
|
36 | int QHBarModelMapper::firstBarSetRow() const | |
44 | { |
|
37 | { | |
45 | return QBarModelMapper::firstBarSetSection(); |
|
38 | return QBarModelMapper::firstBarSetSection(); | |
46 | } |
|
39 | } | |
47 |
|
40 | |||
48 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) |
|
41 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) | |
49 | { |
|
42 | { | |
50 | return QBarModelMapper::setFirstBarSetSection(firstBarSetRow); |
|
43 | return QBarModelMapper::setFirstBarSetSection(firstBarSetRow); | |
51 | } |
|
44 | } | |
52 |
|
45 | |||
53 | int QHBarModelMapper::lastBarSetRow() const |
|
46 | int QHBarModelMapper::lastBarSetRow() const | |
54 | { |
|
47 | { | |
55 | return QBarModelMapper::lastBarSetSection(); |
|
48 | return QBarModelMapper::lastBarSetSection(); | |
56 | } |
|
49 | } | |
57 |
|
50 | |||
58 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) |
|
51 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) | |
59 | { |
|
52 | { | |
60 | return QBarModelMapper::setLastBarSetSection(lastBarSetRow); |
|
53 | return QBarModelMapper::setLastBarSetSection(lastBarSetRow); | |
61 | } |
|
54 | } | |
62 |
|
55 | |||
63 | int QHBarModelMapper::categoriesRow() const |
|
|||
64 | { |
|
|||
65 | return QBarModelMapper::categoriesSection(); |
|
|||
66 | } |
|
|||
67 |
|
||||
68 | void QHBarModelMapper::setCategoriesRow(int categoriesRow) |
|
|||
69 | { |
|
|||
70 | return QBarModelMapper::setCategoriesSection(categoriesRow); |
|
|||
71 | } |
|
|||
72 |
|
||||
73 | #include "moc_qhbarmodelmapper.cpp" |
|
56 | #include "moc_qhbarmodelmapper.cpp" | |
74 |
|
57 | |||
75 | QTCOMMERCIALCHART_END_NAMESPACE |
|
58 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,31 +1,26 | |||||
1 | #ifndef QHBARMODELMAPPER_H |
|
1 | #ifndef QHBARMODELMAPPER_H | |
2 | #define QHBARMODELMAPPER_H |
|
2 | #define QHBARMODELMAPPER_H | |
3 |
|
3 | |||
4 | #include <QBarModelMapper> |
|
4 | #include <QBarModelMapper> | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper |
|
8 | class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper | |
9 | { |
|
9 | { | |
10 | Q_OBJECT |
|
10 | Q_OBJECT | |
11 | Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow) |
|
11 | Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow) | |
12 | Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow) |
|
12 | Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow) | |
13 | Q_PROPERTY(int categoriesRow READ categoriesRow WRITE setCategoriesRow) |
|
|||
14 |
|
13 | |||
15 | public: |
|
14 | public: | |
16 | explicit QHBarModelMapper(QObject *parent = 0); |
|
15 | explicit QHBarModelMapper(QObject *parent = 0); | |
17 |
|
16 | |||
18 | int firstBarSetRow() const; |
|
17 | int firstBarSetRow() const; | |
19 | void setFirstBarSetRow(int firstBarSetRow); |
|
18 | void setFirstBarSetRow(int firstBarSetRow); | |
20 |
|
19 | |||
21 | int lastBarSetRow() const; |
|
20 | int lastBarSetRow() const; | |
22 | void setLastBarSetRow(int lastBarSetRow); |
|
21 | void setLastBarSetRow(int lastBarSetRow); | |
23 |
|
||||
24 | int categoriesRow() const; |
|
|||
25 | void setCategoriesRow(int categoriesRow); |
|
|||
26 |
|
||||
27 | }; |
|
22 | }; | |
28 |
|
23 | |||
29 | QTCOMMERCIALCHART_END_NAMESPACE |
|
24 | QTCOMMERCIALCHART_END_NAMESPACE | |
30 |
|
25 | |||
31 | #endif // QHBARMODELMAPPER_H |
|
26 | #endif // QHBARMODELMAPPER_H |
@@ -1,75 +1,58 | |||||
1 | #include "qvbarmodelmapper.h" |
|
1 | #include "qvbarmodelmapper.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | /*! |
|
5 | /*! | |
6 | \class QVBarModelMapper |
|
6 | \class QVBarModelMapper | |
7 | \brief part of QtCommercial chart API. |
|
7 | \brief part of QtCommercial chart API. | |
8 | \mainclass |
|
8 | \mainclass | |
9 |
|
9 | |||
10 | Nothing here yet |
|
10 | Nothing here yet | |
11 | */ |
|
11 | */ | |
12 |
|
12 | |||
13 | /*! |
|
13 | /*! | |
14 | \property QVBarModelMapper::firstBarSetColumn |
|
14 | \property QVBarModelMapper::firstBarSetColumn | |
15 | \brief Defines which column of the model is used as the data source for the first bar set |
|
15 | \brief Defines which column of the model is used as the data source for the first bar set | |
16 |
|
16 | |||
17 | Default value is: -1 (invalid mapping) |
|
17 | Default value is: -1 (invalid mapping) | |
18 | */ |
|
18 | */ | |
19 |
|
19 | |||
20 | /*! |
|
20 | /*! | |
21 | \property QVBarModelMapper::lastBarSetColumn |
|
21 | \property QVBarModelMapper::lastBarSetColumn | |
22 | \brief Defines which column of the model is used as the data source for the last bar set |
|
22 | \brief Defines which column of the model is used as the data source for the last bar set | |
23 |
|
23 | |||
24 | Default value is: -1 (invalid mapping) |
|
24 | Default value is: -1 (invalid mapping) | |
25 | */ |
|
25 | */ | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \property QVBarModelMapper::categoriesColumn |
|
|||
29 | \brief Defines which column of the model is used as the data source for the x axis categories |
|
|||
30 |
|
||||
31 | Default value is: -1 (invalid mapping) |
|
|||
32 | */ |
|
|||
33 |
|
||||
34 | /*! |
|
|||
35 | Constructs a mapper object which is a child of \a parent. |
|
28 | Constructs a mapper object which is a child of \a parent. | |
36 | */ |
|
29 | */ | |
37 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : |
|
30 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : | |
38 | QBarModelMapper(parent) |
|
31 | QBarModelMapper(parent) | |
39 | { |
|
32 | { | |
40 | QBarModelMapper::setOrientation(Qt::Vertical); |
|
33 | QBarModelMapper::setOrientation(Qt::Vertical); | |
41 | } |
|
34 | } | |
42 |
|
35 | |||
43 | int QVBarModelMapper::firstBarSetColumn() const |
|
36 | int QVBarModelMapper::firstBarSetColumn() const | |
44 | { |
|
37 | { | |
45 | return QBarModelMapper::firstBarSetSection(); |
|
38 | return QBarModelMapper::firstBarSetSection(); | |
46 | } |
|
39 | } | |
47 |
|
40 | |||
48 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) |
|
41 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) | |
49 | { |
|
42 | { | |
50 | return QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); |
|
43 | return QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); | |
51 | } |
|
44 | } | |
52 |
|
45 | |||
53 | int QVBarModelMapper::lastBarSetColumn() const |
|
46 | int QVBarModelMapper::lastBarSetColumn() const | |
54 | { |
|
47 | { | |
55 | return QBarModelMapper::lastBarSetSection(); |
|
48 | return QBarModelMapper::lastBarSetSection(); | |
56 | } |
|
49 | } | |
57 |
|
50 | |||
58 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) |
|
51 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) | |
59 | { |
|
52 | { | |
60 | return QBarModelMapper::setLastBarSetSection(lastBarSetColumn); |
|
53 | return QBarModelMapper::setLastBarSetSection(lastBarSetColumn); | |
61 | } |
|
54 | } | |
62 |
|
55 | |||
63 | int QVBarModelMapper::categoriesColumn() const |
|
|||
64 | { |
|
|||
65 | return QBarModelMapper::categoriesSection(); |
|
|||
66 | } |
|
|||
67 |
|
||||
68 | void QVBarModelMapper::setCategoriesColumn(int categoriesColumn) |
|
|||
69 | { |
|
|||
70 | return QBarModelMapper::setCategoriesSection(categoriesColumn); |
|
|||
71 | } |
|
|||
72 |
|
||||
73 | #include "moc_qvbarmodelmapper.cpp" |
|
56 | #include "moc_qvbarmodelmapper.cpp" | |
74 |
|
57 | |||
75 | QTCOMMERCIALCHART_END_NAMESPACE |
|
58 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,31 +1,26 | |||||
1 | #ifndef QVBARMODELMAPPER_H |
|
1 | #ifndef QVBARMODELMAPPER_H | |
2 | #define QVBARMODELMAPPER_H |
|
2 | #define QVBARMODELMAPPER_H | |
3 |
|
3 | |||
4 | #include <QBarModelMapper> |
|
4 | #include <QBarModelMapper> | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper |
|
8 | class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper | |
9 | { |
|
9 | { | |
10 | Q_OBJECT |
|
10 | Q_OBJECT | |
11 | Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn) |
|
11 | Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn) | |
12 | Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn) |
|
12 | Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn) | |
13 | Q_PROPERTY(int categoriesColumn READ categoriesColumn WRITE setCategoriesColumn) |
|
|||
14 |
|
13 | |||
15 | public: |
|
14 | public: | |
16 | explicit QVBarModelMapper(QObject *parent = 0); |
|
15 | explicit QVBarModelMapper(QObject *parent = 0); | |
17 |
|
16 | |||
18 | int firstBarSetColumn() const; |
|
17 | int firstBarSetColumn() const; | |
19 | void setFirstBarSetColumn(int firstBarSetColumn); |
|
18 | void setFirstBarSetColumn(int firstBarSetColumn); | |
20 |
|
19 | |||
21 | int lastBarSetColumn() const; |
|
20 | int lastBarSetColumn() const; | |
22 | void setLastBarSetColumn(int lastBarSetColumn); |
|
21 | void setLastBarSetColumn(int lastBarSetColumn); | |
23 |
|
||||
24 | int categoriesColumn() const; |
|
|||
25 | void setCategoriesColumn(int categoriesColumn); |
|
|||
26 |
|
||||
27 | }; |
|
22 | }; | |
28 |
|
23 | |||
29 | QTCOMMERCIALCHART_END_NAMESPACE |
|
24 | QTCOMMERCIALCHART_END_NAMESPACE | |
30 |
|
25 | |||
31 | #endif // QVBARMODELMAPPER_H |
|
26 | #endif // QVBARMODELMAPPER_H |
@@ -1,586 +1,585 | |||||
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 "tablewidget.h" |
|
21 | #include "tablewidget.h" | |
22 | #include <QGridLayout> |
|
22 | #include <QGridLayout> | |
23 | #include <QTableView> |
|
23 | #include <QTableView> | |
24 | #include <QChart> |
|
24 | #include <QChart> | |
25 | #include <QStyledItemDelegate> |
|
25 | #include <QStyledItemDelegate> | |
26 | #include <QLineSeries> |
|
26 | #include <QLineSeries> | |
27 | #include <QSplineSeries> |
|
27 | #include <QSplineSeries> | |
28 | #include <QScatterSeries> |
|
28 | #include <QScatterSeries> | |
29 | #include <QVXYModelMapper> |
|
29 | #include <QVXYModelMapper> | |
30 | #include <QHXYModelMapper> |
|
30 | #include <QHXYModelMapper> | |
31 | #include "customtablemodel.h" |
|
31 | #include "customtablemodel.h" | |
32 | #include <QPieSeries> |
|
32 | #include <QPieSeries> | |
33 | #include <QVPieModelMapper> |
|
33 | #include <QVPieModelMapper> | |
34 | #include <QPieSlice> |
|
34 | #include <QPieSlice> | |
35 | #include <QAreaSeries> |
|
35 | #include <QAreaSeries> | |
36 | #include <QBarSeries> |
|
36 | #include <QBarSeries> | |
37 | #include <QGroupedBarSeries> |
|
37 | #include <QGroupedBarSeries> | |
38 | #include <QBarSet> |
|
38 | #include <QBarSet> | |
39 | #include <QVBarModelMapper> |
|
39 | #include <QVBarModelMapper> | |
40 | #include <QPushButton> |
|
40 | #include <QPushButton> | |
41 | #include <QRadioButton> |
|
41 | #include <QRadioButton> | |
42 | #include <QLabel> |
|
42 | #include <QLabel> | |
43 | #include <QSpinBox> |
|
43 | #include <QSpinBox> | |
44 | #include <QTime> |
|
44 | #include <QTime> | |
45 | #include <QHeaderView> |
|
45 | #include <QHeaderView> | |
46 |
|
46 | |||
47 | TableWidget::TableWidget(QWidget *parent) |
|
47 | TableWidget::TableWidget(QWidget *parent) | |
48 | : QWidget(parent), |
|
48 | : QWidget(parent), | |
49 | m_series(0), |
|
49 | m_series(0), | |
50 | m_mapper(0), |
|
50 | m_mapper(0), | |
51 | m_model(0), |
|
51 | m_model(0), | |
52 | m_pieMapper(0), |
|
52 | m_pieMapper(0), | |
53 | m_pieMapper2(0) |
|
53 | m_pieMapper2(0) | |
54 | // specialPie(0) |
|
54 | // specialPie(0) | |
55 | { |
|
55 | { | |
56 | setGeometry(1900, 100, 1000, 600); |
|
56 | setGeometry(1900, 100, 1000, 600); | |
57 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
57 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
58 | // create simple model for storing data |
|
58 | // create simple model for storing data | |
59 | // user's table data model |
|
59 | // user's table data model | |
60 | m_model = new CustomTableModel; |
|
60 | m_model = new CustomTableModel; | |
61 | m_tableView = new QTableView; |
|
61 | m_tableView = new QTableView; | |
62 | m_tableView->setModel(m_model); |
|
62 | m_tableView->setModel(m_model); | |
63 | // m_tableView->setMinimumHeight(300); |
|
63 | // m_tableView->setMinimumHeight(300); | |
64 | m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
64 | m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | |
65 | m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
65 | m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); | |
66 |
|
66 | |||
67 | m_chart = new QChart; |
|
67 | m_chart = new QChart; | |
68 | m_chart->legend()->setVisible(true); |
|
68 | m_chart->legend()->setVisible(true); | |
69 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
69 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
70 | m_chartView = new QChartView(m_chart); |
|
70 | m_chartView = new QChartView(m_chart); | |
71 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
71 | m_chartView->setRenderHint(QPainter::Antialiasing); | |
72 | m_chartView->setMinimumSize(640, 480); |
|
72 | m_chartView->setMinimumSize(640, 480); | |
73 |
|
73 | |||
74 | // add, remove data buttons |
|
74 | // add, remove data buttons | |
75 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); |
|
75 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); | |
76 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); |
|
76 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); | |
77 |
|
77 | |||
78 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); |
|
78 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); | |
79 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); |
|
79 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); | |
80 |
|
80 | |||
81 | QPushButton* removeRowButton = new QPushButton("Remove row"); |
|
81 | QPushButton* removeRowButton = new QPushButton("Remove row"); | |
82 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); |
|
82 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); | |
83 |
|
83 | |||
84 | QPushButton* addColumnRightButton = new QPushButton("Add column to the right"); |
|
84 | QPushButton* addColumnRightButton = new QPushButton("Add column to the right"); | |
85 | connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight())); |
|
85 | connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight())); | |
86 |
|
86 | |||
87 | QPushButton* removeColumnButton = new QPushButton("Remove column"); |
|
87 | QPushButton* removeColumnButton = new QPushButton("Remove column"); | |
88 | connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn())); |
|
88 | connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn())); | |
89 |
|
89 | |||
90 | QPushButton* specialPieButton = new QPushButton("Add slices using series API"); |
|
90 | QPushButton* specialPieButton = new QPushButton("Add slices using series API"); | |
91 | connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie())); |
|
91 | connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie())); | |
92 |
|
92 | |||
93 | QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API"); |
|
93 | QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API"); | |
94 | connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2())); |
|
94 | connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2())); | |
95 |
|
95 | |||
96 | QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API"); |
|
96 | QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API"); | |
97 | connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3())); |
|
97 | connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3())); | |
98 |
|
98 | |||
99 | QPushButton* xyTestButton = new QPushButton("Append XY point"); |
|
99 | QPushButton* xyTestButton = new QPushButton("Append XY point"); | |
100 | connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY())); |
|
100 | connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY())); | |
101 |
|
101 | |||
102 |
|
102 | |||
103 | QLabel *spinBoxLabel = new QLabel("Rows affected:"); |
|
103 | QLabel *spinBoxLabel = new QLabel("Rows affected:"); | |
104 |
|
104 | |||
105 | // spin box for setting number of affected items (add, remove) |
|
105 | // spin box for setting number of affected items (add, remove) | |
106 | m_linesCountSpinBox = new QSpinBox; |
|
106 | m_linesCountSpinBox = new QSpinBox; | |
107 | m_linesCountSpinBox->setRange(1, 10); |
|
107 | m_linesCountSpinBox->setRange(1, 10); | |
108 | m_linesCountSpinBox->setValue(1); |
|
108 | m_linesCountSpinBox->setValue(1); | |
109 |
|
109 | |||
110 | // buttons layout |
|
110 | // buttons layout | |
111 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
111 | QVBoxLayout* buttonsLayout = new QVBoxLayout; | |
112 | buttonsLayout->addWidget(spinBoxLabel); |
|
112 | buttonsLayout->addWidget(spinBoxLabel); | |
113 | buttonsLayout->addWidget(m_linesCountSpinBox); |
|
113 | buttonsLayout->addWidget(m_linesCountSpinBox); | |
114 | // buttonsLayout->addWidget(addRowAboveButton); |
|
114 | // buttonsLayout->addWidget(addRowAboveButton); | |
115 | buttonsLayout->addWidget(addRowBelowButton); |
|
115 | buttonsLayout->addWidget(addRowBelowButton); | |
116 | buttonsLayout->addWidget(removeRowButton); |
|
116 | buttonsLayout->addWidget(removeRowButton); | |
117 | // buttonsLayout->addWidget(addColumnRightButton); |
|
117 | // buttonsLayout->addWidget(addColumnRightButton); | |
118 | // buttonsLayout->addWidget(removeColumnButton); |
|
118 | // buttonsLayout->addWidget(removeColumnButton); | |
119 | buttonsLayout->addWidget(specialPieButton); |
|
119 | buttonsLayout->addWidget(specialPieButton); | |
120 | buttonsLayout->addWidget(specialPieButton2); |
|
120 | buttonsLayout->addWidget(specialPieButton2); | |
121 | buttonsLayout->addWidget(specialPieButton3); |
|
121 | buttonsLayout->addWidget(specialPieButton3); | |
122 | buttonsLayout->addWidget(xyTestButton); |
|
122 | buttonsLayout->addWidget(xyTestButton); | |
123 | buttonsLayout->addStretch(); |
|
123 | buttonsLayout->addStretch(); | |
124 |
|
124 | |||
125 | // chart type radio buttons |
|
125 | // chart type radio buttons | |
126 | m_lineRadioButton = new QRadioButton("Line"); |
|
126 | m_lineRadioButton = new QRadioButton("Line"); | |
127 | m_splineRadioButton = new QRadioButton("Spline"); |
|
127 | m_splineRadioButton = new QRadioButton("Spline"); | |
128 | m_scatterRadioButton = new QRadioButton("Scatter"); |
|
128 | m_scatterRadioButton = new QRadioButton("Scatter"); | |
129 | m_pieRadioButton = new QRadioButton("Pie"); |
|
129 | m_pieRadioButton = new QRadioButton("Pie"); | |
130 | m_areaRadioButton = new QRadioButton("Area"); |
|
130 | m_areaRadioButton = new QRadioButton("Area"); | |
131 | m_barRadioButton = new QRadioButton("Bar"); |
|
131 | m_barRadioButton = new QRadioButton("Bar"); | |
132 |
|
132 | |||
133 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
133 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
134 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
134 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
135 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
135 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
136 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
136 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
137 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
137 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
138 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); |
|
138 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | |
139 | m_barRadioButton->setChecked(true); |
|
139 | m_barRadioButton->setChecked(true); | |
140 |
|
140 | |||
141 | // radio buttons layout |
|
141 | // radio buttons layout | |
142 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
142 | QVBoxLayout* radioLayout = new QVBoxLayout; | |
143 | radioLayout->addWidget(m_lineRadioButton); |
|
143 | radioLayout->addWidget(m_lineRadioButton); | |
144 | radioLayout->addWidget(m_splineRadioButton); |
|
144 | radioLayout->addWidget(m_splineRadioButton); | |
145 | radioLayout->addWidget(m_scatterRadioButton); |
|
145 | radioLayout->addWidget(m_scatterRadioButton); | |
146 | radioLayout->addWidget(m_pieRadioButton); |
|
146 | radioLayout->addWidget(m_pieRadioButton); | |
147 | // radioLayout->addWidget(m_areaRadioButton); |
|
147 | // radioLayout->addWidget(m_areaRadioButton); | |
148 | radioLayout->addWidget(m_barRadioButton); |
|
148 | radioLayout->addWidget(m_barRadioButton); | |
149 | radioLayout->addStretch(); |
|
149 | radioLayout->addStretch(); | |
150 |
|
150 | |||
151 | // create main layout |
|
151 | // create main layout | |
152 | QGridLayout* mainLayout = new QGridLayout; |
|
152 | QGridLayout* mainLayout = new QGridLayout; | |
153 | mainLayout->addLayout(buttonsLayout, 2, 0); |
|
153 | mainLayout->addLayout(buttonsLayout, 2, 0); | |
154 | mainLayout->addLayout(radioLayout, 3, 0); |
|
154 | mainLayout->addLayout(radioLayout, 3, 0); | |
155 | mainLayout->addWidget(m_tableView, 1, 0); |
|
155 | mainLayout->addWidget(m_tableView, 1, 0); | |
156 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); |
|
156 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); | |
157 | setLayout(mainLayout); |
|
157 | setLayout(mainLayout); | |
158 | m_lineRadioButton->setFocus(); |
|
158 | m_lineRadioButton->setFocus(); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void TableWidget::addRowAbove() |
|
161 | void TableWidget::addRowAbove() | |
162 | { |
|
162 | { | |
163 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); |
|
163 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); | |
164 |
|
164 | |||
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | void TableWidget::addRowBelow() |
|
167 | void TableWidget::addRowBelow() | |
168 | { |
|
168 | { | |
169 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); |
|
169 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); | |
170 |
|
170 | |||
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void TableWidget::removeRow() |
|
173 | void TableWidget::removeRow() | |
174 | { |
|
174 | { | |
175 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); |
|
175 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | void TableWidget::addColumnRight() |
|
178 | void TableWidget::addColumnRight() | |
179 | { |
|
179 | { | |
180 | m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value()); |
|
180 | m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value()); | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | void TableWidget::removeColumn() |
|
183 | void TableWidget::removeColumn() | |
184 | { |
|
184 | { | |
185 | m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value())); |
|
185 | m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value())); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | void TableWidget::updateChartType(bool toggle) |
|
188 | void TableWidget::updateChartType(bool toggle) | |
189 | { |
|
189 | { | |
190 | // this if is needed, so that the function is only called once. |
|
190 | // this if is needed, so that the function is only called once. | |
191 | // For the radioButton that was enabled. |
|
191 | // For the radioButton that was enabled. | |
192 | if (toggle) { |
|
192 | if (toggle) { | |
193 | // specialPie = 0; |
|
193 | // specialPie = 0; | |
194 | m_chart->removeAllSeries(); |
|
194 | m_chart->removeAllSeries(); | |
195 | m_series = 0; |
|
195 | m_series = 0; | |
196 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
|
196 | // m_chart->axisX()->setNiceNumbersEnabled(false); | |
197 | // m_chart->axisY()->setNiceNumbersEnabled(false); |
|
197 | // m_chart->axisY()->setNiceNumbersEnabled(false); | |
198 | if (m_mapper) { |
|
198 | if (m_mapper) { | |
199 | m_mapper->deleteLater(); |
|
199 | m_mapper->deleteLater(); | |
200 | m_mapper = 0; |
|
200 | m_mapper = 0; | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | if (m_pieMapper) { |
|
203 | if (m_pieMapper) { | |
204 | m_pieMapper->deleteLater(); |
|
204 | m_pieMapper->deleteLater(); | |
205 | m_pieMapper = 0; |
|
205 | m_pieMapper = 0; | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | if (m_pieMapper2) { |
|
208 | if (m_pieMapper2) { | |
209 | m_pieMapper2->deleteLater(); |
|
209 | m_pieMapper2->deleteLater(); | |
210 | m_pieMapper2 = 0; |
|
210 | m_pieMapper2 = 0; | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | // if (m_series) { |
|
213 | // if (m_series) { | |
214 | // delete m_series; |
|
214 | // delete m_series; | |
215 | // m_series = 0; |
|
215 | // m_series = 0; | |
216 | // } |
|
216 | // } | |
217 |
|
217 | |||
218 | // renable axes of the chart (pie hides them) |
|
218 | // renable axes of the chart (pie hides them) | |
219 | // x axis |
|
219 | // x axis | |
220 | QAxis *axis = m_chart->axisX(); |
|
220 | QAxis *axis = m_chart->axisX(); | |
221 | axis->setAxisVisible(true); |
|
221 | axis->setAxisVisible(true); | |
222 | axis->setGridLineVisible(true); |
|
222 | axis->setGridLineVisible(true); | |
223 | axis->setLabelsVisible(true); |
|
223 | axis->setLabelsVisible(true); | |
224 |
|
224 | |||
225 | // y axis |
|
225 | // y axis | |
226 | axis = m_chart->axisY(); |
|
226 | axis = m_chart->axisY(); | |
227 | axis->setAxisVisible(true); |
|
227 | axis->setAxisVisible(true); | |
228 | axis->setGridLineVisible(true); |
|
228 | axis->setGridLineVisible(true); | |
229 | axis->setLabelsVisible(true); |
|
229 | axis->setLabelsVisible(true); | |
230 |
|
230 | |||
231 | m_model->clearMapping(); |
|
231 | m_model->clearMapping(); | |
232 |
|
232 | |||
233 | QString seriesColorHex = "#000000"; |
|
233 | QString seriesColorHex = "#000000"; | |
234 | // QPen pen; |
|
234 | // QPen pen; | |
235 | // pen.setWidth(2); |
|
235 | // pen.setWidth(2); | |
236 |
|
236 | |||
237 | if (m_lineRadioButton->isChecked()) |
|
237 | if (m_lineRadioButton->isChecked()) | |
238 | { |
|
238 | { | |
239 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
239 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
240 |
|
240 | |||
241 | // series 1 |
|
241 | // series 1 | |
242 | m_series = new QLineSeries; |
|
242 | m_series = new QLineSeries; | |
243 |
|
243 | |||
244 | // m_mapper = new QHXYModelMapper; |
|
244 | // m_mapper = new QHXYModelMapper; | |
245 | // m_mapper->setModel(m_model); |
|
245 | // m_mapper->setModel(m_model); | |
246 | // m_mapper->setSeries(m_series); |
|
246 | // m_mapper->setSeries(m_series); | |
247 | // m_mapper->setXRow(0); |
|
247 | // m_mapper->setXRow(0); | |
248 | // m_mapper->setYRow(1); |
|
248 | // m_mapper->setYRow(1); | |
249 | // m_mapper->setFirst(3); |
|
249 | // m_mapper->setFirst(3); | |
250 | // m_mapper->setCount(4); |
|
250 | // m_mapper->setCount(4); | |
251 |
|
251 | |||
252 | m_mapper = new QVXYModelMapper; |
|
252 | m_mapper = new QVXYModelMapper; | |
253 | m_mapper->setModel(m_model); |
|
253 | m_mapper->setModel(m_model); | |
254 | m_mapper->setSeries(m_series); |
|
254 | m_mapper->setSeries(m_series); | |
255 | m_mapper->setXColumn(0); |
|
255 | m_mapper->setXColumn(0); | |
256 | m_mapper->setYColumn(1); |
|
256 | m_mapper->setYColumn(1); | |
257 | m_mapper->setFirst(3); |
|
257 | m_mapper->setFirst(3); | |
258 | // m_mapper->setCount(4); |
|
258 | // m_mapper->setCount(4); | |
259 |
|
259 | |||
260 | // m_series->setModelMapping(0,1, Qt::Vertical); |
|
260 | // m_series->setModelMapping(0,1, Qt::Vertical); | |
261 | // m_series->setModelMappingRange(3, 4); |
|
261 | // m_series->setModelMappingRange(3, 4); | |
262 | m_chart->addSeries(m_series); |
|
262 | m_chart->addSeries(m_series); | |
263 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
263 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
264 | m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); |
|
264 | m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); | |
265 |
|
265 | |||
266 | // // series 2 |
|
266 | // // series 2 | |
267 | // m_series = new QLineSeries; |
|
267 | // m_series = new QLineSeries; | |
268 | // m_series->setModel(m_model); |
|
268 | // m_series->setModel(m_model); | |
269 |
|
269 | |||
270 | // mapper = new QXYModelMapper; |
|
270 | // mapper = new QXYModelMapper; | |
271 | // mapper->setMapX(3); |
|
271 | // mapper->setMapX(3); | |
272 | // mapper->setMapY(4); |
|
272 | // mapper->setMapY(4); | |
273 | // // mapper->setFirst(3); |
|
273 | // // mapper->setFirst(3); | |
274 | // // mapper->setCount(4); |
|
274 | // // mapper->setCount(4); | |
275 | // m_series->setModelMapper(mapper); |
|
275 | // m_series->setModelMapper(mapper); | |
276 | // // m_series->setModelMapping(2,3, Qt::Vertical); |
|
276 | // // m_series->setModelMapping(2,3, Qt::Vertical); | |
277 | // m_chart->addSeries(m_series); |
|
277 | // m_chart->addSeries(m_series); | |
278 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
278 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
279 | // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000)); |
|
279 | // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000)); | |
280 |
|
280 | |||
281 | // // series 3 |
|
281 | // // series 3 | |
282 | // m_series = new QLineSeries; |
|
282 | // m_series = new QLineSeries; | |
283 | // m_series->setModel(m_model); |
|
283 | // m_series->setModel(m_model); | |
284 |
|
284 | |||
285 | // mapper = new QXYModelMapper; |
|
285 | // mapper = new QXYModelMapper; | |
286 | // mapper->setMapX(5); |
|
286 | // mapper->setMapX(5); | |
287 | // mapper->setMapY(6); |
|
287 | // mapper->setMapY(6); | |
288 | // mapper->setFirst(2); |
|
288 | // mapper->setFirst(2); | |
289 | // mapper->setCount(-1); |
|
289 | // mapper->setCount(-1); | |
290 | // m_series->setModelMapper(mapper); |
|
290 | // m_series->setModelMapper(mapper); | |
291 | // // m_series->setModelMapping(4,5, Qt::Vertical); |
|
291 | // // m_series->setModelMapping(4,5, Qt::Vertical); | |
292 | // // m_series->setModelMappingRange(2, -1); |
|
292 | // // m_series->setModelMappingRange(2, -1); | |
293 | // m_chart->addSeries(m_series); |
|
293 | // m_chart->addSeries(m_series); | |
294 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
294 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
295 | // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000)); |
|
295 | // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000)); | |
296 | } |
|
296 | } | |
297 | else if (m_splineRadioButton->isChecked()) |
|
297 | else if (m_splineRadioButton->isChecked()) | |
298 | { |
|
298 | { | |
299 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
299 | m_chart->setAnimationOptions(QChart::NoAnimation); | |
300 |
|
300 | |||
301 | // series 1 |
|
301 | // series 1 | |
302 | m_series = new QSplineSeries; |
|
302 | m_series = new QSplineSeries; | |
303 | // m_series->setModel(m_model); |
|
303 | // m_series->setModel(m_model); | |
304 |
|
304 | |||
305 | // m_mapper = new QVXYModelMapper; |
|
305 | // m_mapper = new QVXYModelMapper; | |
306 | // m_mapper->setSeries(m_series); |
|
306 | // m_mapper->setSeries(m_series); | |
307 | // m_mapper->setModel(m_model); |
|
307 | // m_mapper->setModel(m_model); | |
308 | // m_mapper->setXColumn(0); |
|
308 | // m_mapper->setXColumn(0); | |
309 | // m_mapper->setYColumn(1); |
|
309 | // m_mapper->setYColumn(1); | |
310 | // m_mapper->setFirst(0); |
|
310 | // m_mapper->setFirst(0); | |
311 | // m_mapper->setCount(-1); |
|
311 | // m_mapper->setCount(-1); | |
312 |
|
312 | |||
313 | // m_series->setModelMapper(mapper); |
|
313 | // m_series->setModelMapper(mapper); | |
314 |
|
314 | |||
315 | m_chart->addSeries(m_series); |
|
315 | m_chart->addSeries(m_series); | |
316 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
316 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
317 | m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); |
|
317 | m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); | |
318 |
|
318 | |||
319 | // // series 2 |
|
319 | // // series 2 | |
320 | // m_series = new QSplineSeries; |
|
320 | // m_series = new QSplineSeries; | |
321 | // m_series->setModel(m_model); |
|
321 | // m_series->setModel(m_model); | |
322 |
|
322 | |||
323 | // mapper = new QXYModelMapper; |
|
323 | // mapper = new QXYModelMapper; | |
324 | // mapper->setMapX(2); |
|
324 | // mapper->setMapX(2); | |
325 | // mapper->setMapY(3); |
|
325 | // mapper->setMapY(3); | |
326 | // mapper->setFirst(2); |
|
326 | // mapper->setFirst(2); | |
327 | // mapper->setCount(4); |
|
327 | // mapper->setCount(4); | |
328 |
|
328 | |||
329 | // m_series->setModelMapper(mapper); |
|
329 | // m_series->setModelMapper(mapper); | |
330 |
|
330 | |||
331 | // m_chart->addSeries(m_series); |
|
331 | // m_chart->addSeries(m_series); | |
332 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
332 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
333 | // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); |
|
333 | // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); | |
334 |
|
334 | |||
335 | // // series 3 |
|
335 | // // series 3 | |
336 | // m_series = new QSplineSeries; |
|
336 | // m_series = new QSplineSeries; | |
337 | // m_series->setModel(m_model); |
|
337 | // m_series->setModel(m_model); | |
338 |
|
338 | |||
339 | // mapper = new QXYModelMapper; |
|
339 | // mapper = new QXYModelMapper; | |
340 | // mapper->setMapX(4); |
|
340 | // mapper->setMapX(4); | |
341 | // mapper->setMapY(5); |
|
341 | // mapper->setMapY(5); | |
342 | // mapper->setFirst(2); |
|
342 | // mapper->setFirst(2); | |
343 | // mapper->setCount(-1); |
|
343 | // mapper->setCount(-1); | |
344 |
|
344 | |||
345 | // m_series->setModelMapper(mapper); |
|
345 | // m_series->setModelMapper(mapper); | |
346 |
|
346 | |||
347 | // m_chart->addSeries(m_series); |
|
347 | // m_chart->addSeries(m_series); | |
348 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); |
|
348 | // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
349 | // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); |
|
349 | // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
350 | } else if (m_scatterRadioButton->isChecked()) |
|
350 | } else if (m_scatterRadioButton->isChecked()) | |
351 | { |
|
351 | { | |
352 | m_chart->setAnimationOptions(QChart::NoAnimation); |
|
352 | m_chart->setAnimationOptions(QChart::NoAnimation); | |
353 |
|
353 | |||
354 | // series 1 |
|
354 | // series 1 | |
355 | m_series = new QScatterSeries; |
|
355 | m_series = new QScatterSeries; | |
356 |
|
356 | |||
357 | // m_mapper = new QVXYModelMapper; |
|
357 | // m_mapper = new QVXYModelMapper; | |
358 | // m_mapper->setSeries(m_series); |
|
358 | // m_mapper->setSeries(m_series); | |
359 | // m_mapper->setModel(m_model); |
|
359 | // m_mapper->setModel(m_model); | |
360 | // m_mapper->setXColumn(0); |
|
360 | // m_mapper->setXColumn(0); | |
361 | // m_mapper->setYColumn(1); |
|
361 | // m_mapper->setYColumn(1); | |
362 | // m_mapper->setFirst(0); |
|
362 | // m_mapper->setFirst(0); | |
363 | // m_mapper->setCount(-1); |
|
363 | // m_mapper->setCount(-1); | |
364 |
|
364 | |||
365 | m_chart->addSeries(m_series); |
|
365 | m_chart->addSeries(m_series); | |
366 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
366 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
367 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); |
|
367 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); | |
368 |
|
368 | |||
369 | // // series 2 |
|
369 | // // series 2 | |
370 | // m_series = new QScatterSeries; |
|
370 | // m_series = new QScatterSeries; | |
371 | // m_series->setModel(m_model); |
|
371 | // m_series->setModel(m_model); | |
372 | // m_series->setModelMapping(2,3, Qt::Vertical); |
|
372 | // m_series->setModelMapping(2,3, Qt::Vertical); | |
373 | // // m_series->setModelMappingRange(1, 6); |
|
373 | // // m_series->setModelMappingRange(1, 6); | |
374 | // // series->setModelMapping(2,3, Qt::Horizontal); |
|
374 | // // series->setModelMapping(2,3, Qt::Horizontal); | |
375 | // m_chart->addSeries(m_series); |
|
375 | // m_chart->addSeries(m_series); | |
376 |
|
376 | |||
377 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
377 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
378 | // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); |
|
378 | // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); | |
379 |
|
379 | |||
380 | // // series 3 |
|
380 | // // series 3 | |
381 | // m_series = new QScatterSeries; |
|
381 | // m_series = new QScatterSeries; | |
382 | // m_series->setModel(m_model); |
|
382 | // m_series->setModel(m_model); | |
383 | // m_series->setModelMapping(4,5, Qt::Vertical); |
|
383 | // m_series->setModelMapping(4,5, Qt::Vertical); | |
384 | // // series->setModelMapping(4,5, Qt::Horizontal); |
|
384 | // // series->setModelMapping(4,5, Qt::Horizontal); | |
385 | // m_chart->addSeries(m_series); |
|
385 | // m_chart->addSeries(m_series); | |
386 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); |
|
386 | // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |
387 | // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); |
|
387 | // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); | |
388 | } else if (m_pieRadioButton->isChecked()) { |
|
388 | } else if (m_pieRadioButton->isChecked()) { | |
389 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
389 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
390 |
|
390 | |||
391 | // pie 1 |
|
391 | // pie 1 | |
392 | m_pieSeries = new QPieSeries; |
|
392 | m_pieSeries = new QPieSeries; | |
393 |
|
393 | |||
394 | m_pieMapper = new QVPieModelMapper; |
|
394 | m_pieMapper = new QVPieModelMapper; | |
395 | m_pieMapper->setValuesColumn(1); |
|
395 | m_pieMapper->setValuesColumn(1); | |
396 | m_pieMapper->setLabelsColumn(7); |
|
396 | m_pieMapper->setLabelsColumn(7); | |
397 | m_pieMapper->setSeries(m_pieSeries); |
|
397 | m_pieMapper->setSeries(m_pieSeries); | |
398 | m_pieMapper->setModel(m_model); |
|
398 | m_pieMapper->setModel(m_model); | |
399 | m_pieMapper->setFirst(2); |
|
399 | m_pieMapper->setFirst(2); | |
400 | // m_pieMapper->setCount(5); |
|
400 | // m_pieMapper->setCount(5); | |
401 | // pieSeries->setModelMapper(mapper); |
|
401 | // pieSeries->setModelMapper(mapper); | |
402 |
|
402 | |||
403 | m_pieSeries->setLabelsVisible(true); |
|
403 | m_pieSeries->setLabelsVisible(true); | |
404 | m_pieSeries->setPieSize(0.35); |
|
404 | m_pieSeries->setPieSize(0.35); | |
405 | m_pieSeries->setHorizontalPosition(0.25); |
|
405 | m_pieSeries->setHorizontalPosition(0.25); | |
406 | m_pieSeries->setVerticalPosition(0.35); |
|
406 | m_pieSeries->setVerticalPosition(0.35); | |
407 |
|
407 | |||
408 | m_chart->addSeries(m_pieSeries); |
|
408 | m_chart->addSeries(m_pieSeries); | |
409 | seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
409 | seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
410 | m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50)); |
|
410 | m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50)); | |
411 |
|
411 | |||
412 |
|
412 | |||
413 | // pieSeries->slices().at(0)->setValue(400); |
|
413 | // pieSeries->slices().at(0)->setValue(400); | |
414 | // pieSeries->slices().at(0)->setLabel(QString("36")); |
|
414 | // pieSeries->slices().at(0)->setLabel(QString("36")); | |
415 |
|
415 | |||
416 | // pie 2 |
|
416 | // pie 2 | |
417 | m_pieSeries2 = new QPieSeries; |
|
417 | m_pieSeries2 = new QPieSeries; | |
418 |
|
418 | |||
419 | m_pieMapper2 = new QVPieModelMapper; |
|
419 | m_pieMapper2 = new QVPieModelMapper; | |
420 | m_pieMapper2->setValuesColumn(0); |
|
420 | m_pieMapper2->setValuesColumn(0); | |
421 | m_pieMapper2->setLabelsColumn(7); |
|
421 | m_pieMapper2->setLabelsColumn(7); | |
422 | m_pieMapper2->setModel(m_model); |
|
422 | m_pieMapper2->setModel(m_model); | |
423 | m_pieMapper2->setSeries(m_pieSeries2); |
|
423 | m_pieMapper2->setSeries(m_pieSeries2); | |
424 | m_pieMapper2->setFirst(2); |
|
424 | m_pieMapper2->setFirst(2); | |
425 |
|
425 | |||
426 | m_pieSeries2->setLabelsVisible(true); |
|
426 | m_pieSeries2->setLabelsVisible(true); | |
427 | m_pieSeries2->setPieSize(0.35); |
|
427 | m_pieSeries2->setPieSize(0.35); | |
428 | m_pieSeries2->setHorizontalPosition(0.75); |
|
428 | m_pieSeries2->setHorizontalPosition(0.75); | |
429 | m_pieSeries2->setVerticalPosition(0.65); |
|
429 | m_pieSeries2->setVerticalPosition(0.65); | |
430 | m_chart->addSeries(m_pieSeries2); |
|
430 | m_chart->addSeries(m_pieSeries2); | |
431 | seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
431 | seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
432 | m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000)); |
|
432 | m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000)); | |
433 |
|
433 | |||
434 | // // pie 3 |
|
434 | // // pie 3 | |
435 | // pieSeries = new QPieSeries; |
|
435 | // pieSeries = new QPieSeries; | |
436 | // pieSeries->setModel(m_model); |
|
436 | // pieSeries->setModel(m_model); | |
437 | // pieSeries->setModelMapping(2,2, Qt::Vertical); |
|
437 | // pieSeries->setModelMapping(2,2, Qt::Vertical); | |
438 | // pieSeries->setLabelsVisible(true); |
|
438 | // pieSeries->setLabelsVisible(true); | |
439 | // pieSeries->setPieSize(0.35); |
|
439 | // pieSeries->setPieSize(0.35); | |
440 | // pieSeries->setHorizontalPosition(0.5); |
|
440 | // pieSeries->setHorizontalPosition(0.5); | |
441 | // pieSeries->setVerticalPosition(0.75); |
|
441 | // pieSeries->setVerticalPosition(0.75); | |
442 | // m_chart->addSeries(pieSeries); |
|
442 | // m_chart->addSeries(pieSeries); | |
443 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); |
|
443 | // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |
444 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); |
|
444 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); | |
445 |
|
445 | |||
446 | // // special pie |
|
446 | // // special pie | |
447 | // specialPie = new QPieSeries; |
|
447 | // specialPie = new QPieSeries; | |
448 | // specialPie->append(17, "1"); |
|
448 | // specialPie->append(17, "1"); | |
449 | // specialPie->append(45, "2"); |
|
449 | // specialPie->append(45, "2"); | |
450 | // specialPie->append(77, "3"); |
|
450 | // specialPie->append(77, "3"); | |
451 | // specialPie->append(37, "4"); |
|
451 | // specialPie->append(37, "4"); | |
452 | // specialPie->append(27, "5"); |
|
452 | // specialPie->append(27, "5"); | |
453 | // specialPie->append(47, "6"); |
|
453 | // specialPie->append(47, "6"); | |
454 | // specialPie->setPieSize(0.35); |
|
454 | // specialPie->setPieSize(0.35); | |
455 | // specialPie->setHorizontalPosition(0.8); |
|
455 | // specialPie->setHorizontalPosition(0.8); | |
456 | // specialPie->setVerticalPosition(0.75); |
|
456 | // specialPie->setVerticalPosition(0.75); | |
457 | // specialPie->setLabelsVisible(true); |
|
457 | // specialPie->setLabelsVisible(true); | |
458 | // m_chart->addSeries(specialPie); |
|
458 | // m_chart->addSeries(specialPie); | |
459 | } |
|
459 | } | |
460 | // else if (m_areaRadioButton->isChecked()) |
|
460 | // else if (m_areaRadioButton->isChecked()) | |
461 | // { |
|
461 | // { | |
462 | // m_chart->setAnimationOptions(QChart::NoAnimation); |
|
462 | // m_chart->setAnimationOptions(QChart::NoAnimation); | |
463 |
|
463 | |||
464 | // QLineSeries* upperLineSeries = new QLineSeries; |
|
464 | // QLineSeries* upperLineSeries = new QLineSeries; | |
465 | // upperLineSeries->setModel(m_model); |
|
465 | // upperLineSeries->setModel(m_model); | |
466 | // upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
466 | // upperLineSeries->setModelMapping(0, 1, Qt::Vertical); | |
467 | // // upperLineSeries->setModelMappingRange(1, 5); |
|
467 | // // upperLineSeries->setModelMappingRange(1, 5); | |
468 | // QLineSeries* lowerLineSeries = new QLineSeries; |
|
468 | // QLineSeries* lowerLineSeries = new QLineSeries; | |
469 | // lowerLineSeries->setModel(m_model); |
|
469 | // lowerLineSeries->setModel(m_model); | |
470 | // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
|
470 | // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); | |
471 | // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); |
|
471 | // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); | |
472 | // m_chart->addSeries(areaSeries); |
|
472 | // m_chart->addSeries(areaSeries); | |
473 | // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); |
|
473 | // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); | |
474 | // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); |
|
474 | // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); | |
475 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); |
|
475 | // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
476 | // } |
|
476 | // } | |
477 | else if (m_barRadioButton->isChecked()) |
|
477 | else if (m_barRadioButton->isChecked()) | |
478 | { |
|
478 | { | |
479 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
479 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | |
480 |
|
480 | |||
481 | QGroupedBarSeries* barSeries = new QGroupedBarSeries(); |
|
481 | QGroupedBarSeries* barSeries = new QGroupedBarSeries(); | |
482 | // barSeries->setCategories(QStringList()); |
|
|||
483 | // barSeries->setModel(m_model); |
|
|||
484 | // barSeries->setModelMappingRange(2, 5); |
|
|||
485 | // barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
|||
486 |
|
||||
487 |
|
482 | |||
488 | int first = 3; |
|
483 | int first = 3; | |
489 | int count = 6; |
|
484 | int count = 6; | |
490 | QVBarModelMapper *mapper = new QVBarModelMapper; |
|
485 | QVBarModelMapper *mapper = new QVBarModelMapper; | |
491 | mapper->setCategoriesColumn(5); |
|
|||
492 | mapper->setFirstBarSetColumn(2); |
|
486 | mapper->setFirstBarSetColumn(2); | |
493 | mapper->setLastBarSetColumn(4); |
|
487 | mapper->setLastBarSetColumn(4); | |
494 | mapper->setFirst(first); |
|
488 | mapper->setFirst(first); | |
495 | mapper->setCount(count); |
|
489 | mapper->setCount(count); | |
496 | mapper->setSeries(barSeries); |
|
490 | mapper->setSeries(barSeries); | |
497 | mapper->setModel(m_model); |
|
491 | mapper->setModel(m_model); | |
498 | // barSeries->setModelMapper(mapper); |
|
492 | // barSeries->setModelMapper(mapper); | |
499 | m_chart->addSeries(barSeries); |
|
493 | m_chart->addSeries(barSeries); | |
500 |
|
494 | |||
|
495 | QStringList categories; | |||
|
496 | categories << "June" << "July" << "August" << "September" << "October" << "November"; | |||
|
497 | ||||
|
498 | m_chart->axisX()->categories()->insert(categories); | |||
|
499 | ||||
501 | QList<QBarSet*> barsets = barSeries->barSets(); |
|
500 | QList<QBarSet*> barsets = barSeries->barSets(); | |
502 | for (int i = 0; i < barsets.count(); i++) { |
|
501 | for (int i = 0; i < barsets.count(); i++) { | |
503 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); |
|
502 | seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); | |
504 | m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count())); |
|
503 | m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count())); | |
505 | } |
|
504 | } | |
506 |
|
505 | |||
507 |
|
506 | |||
508 | } |
|
507 | } | |
509 |
|
508 | |||
510 |
|
509 | |||
511 | if (!m_barRadioButton->isChecked()) { |
|
510 | if (!m_barRadioButton->isChecked()) { | |
512 | // m_chart->axisX()->setRange(0, 500); |
|
511 | // m_chart->axisX()->setRange(0, 500); | |
513 | // m_chart->axisY()->setRange(0, 220); |
|
512 | // m_chart->axisY()->setRange(0, 220); | |
514 | } |
|
513 | } | |
515 | m_chart->legend()->setVisible(true); |
|
514 | m_chart->legend()->setVisible(true); | |
516 |
|
515 | |||
517 | // repaint table view colors |
|
516 | // repaint table view colors | |
518 | m_tableView->repaint(); |
|
517 | m_tableView->repaint(); | |
519 | m_tableView->setFocus(); |
|
518 | m_tableView->setFocus(); | |
520 | } |
|
519 | } | |
521 | } |
|
520 | } | |
522 |
|
521 | |||
523 | void TableWidget::testPie() |
|
522 | void TableWidget::testPie() | |
524 | { |
|
523 | { | |
525 | // m_pieMapper->setCount(-1); |
|
524 | // m_pieMapper->setCount(-1); | |
526 | QPieSlice *slice = new QPieSlice("Hehe", 145); |
|
525 | QPieSlice *slice = new QPieSlice("Hehe", 145); | |
527 | slice->setLabelVisible(); |
|
526 | slice->setLabelVisible(); | |
528 | m_pieSeries->append(slice); |
|
527 | m_pieSeries->append(slice); | |
529 |
|
528 | |||
530 | slice = new QPieSlice("Hoho", 34); |
|
529 | slice = new QPieSlice("Hoho", 34); | |
531 | slice->setLabelVisible(); |
|
530 | slice->setLabelVisible(); | |
532 | m_pieSeries->append(slice); |
|
531 | m_pieSeries->append(slice); | |
533 | // m_series->modelMapper()->setMapX(4); |
|
532 | // m_series->modelMapper()->setMapX(4); | |
534 | // m_tableView->setColumnWidth(10, 250); |
|
533 | // m_tableView->setColumnWidth(10, 250); | |
535 | // if (specialPie) { |
|
534 | // if (specialPie) { | |
536 | // specialPie->remove(specialPie->slices().at(2)); |
|
535 | // specialPie->remove(specialPie->slices().at(2)); | |
537 | // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); |
|
536 | // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); | |
538 | // specialPie->append(4, "heloo"); |
|
537 | // specialPie->append(4, "heloo"); | |
539 | // } |
|
538 | // } | |
540 | } |
|
539 | } | |
541 |
|
540 | |||
542 | void TableWidget::testPie2() |
|
541 | void TableWidget::testPie2() | |
543 | { |
|
542 | { | |
544 | QPieSlice *slice; |
|
543 | QPieSlice *slice; | |
545 | if (m_pieSeries->count() > 0) { |
|
544 | if (m_pieSeries->count() > 0) { | |
546 | slice = m_pieSeries->slices().last(); |
|
545 | slice = m_pieSeries->slices().last(); | |
547 | m_pieSeries->remove(slice); |
|
546 | m_pieSeries->remove(slice); | |
548 | } |
|
547 | } | |
549 |
|
548 | |||
550 | if (m_pieSeries->count() > 0) { |
|
549 | if (m_pieSeries->count() > 0) { | |
551 | slice = m_pieSeries->slices().first(); |
|
550 | slice = m_pieSeries->slices().first(); | |
552 | m_pieSeries->remove(slice); |
|
551 | m_pieSeries->remove(slice); | |
553 | } |
|
552 | } | |
554 | } |
|
553 | } | |
555 |
|
554 | |||
556 | void TableWidget::testPie3() |
|
555 | void TableWidget::testPie3() | |
557 | { |
|
556 | { | |
558 | QPieSlice *slice; |
|
557 | QPieSlice *slice; | |
559 | if (m_pieSeries->count() > 0) { |
|
558 | if (m_pieSeries->count() > 0) { | |
560 | slice = m_pieSeries->slices().last(); |
|
559 | slice = m_pieSeries->slices().last(); | |
561 | slice->setLabel("Dalej"); |
|
560 | slice->setLabel("Dalej"); | |
562 | slice->setValue(222); |
|
561 | slice->setValue(222); | |
563 | } |
|
562 | } | |
564 |
|
563 | |||
565 | if (m_pieSeries->count() > 0) { |
|
564 | if (m_pieSeries->count() > 0) { | |
566 | slice = m_pieSeries->slices().first(); |
|
565 | slice = m_pieSeries->slices().first(); | |
567 | slice->setLabel("Prawie"); |
|
566 | slice->setLabel("Prawie"); | |
568 | slice->setValue(111); |
|
567 | slice->setValue(111); | |
569 | } |
|
568 | } | |
570 | } |
|
569 | } | |
571 |
|
570 | |||
572 | void TableWidget::testXY() |
|
571 | void TableWidget::testXY() | |
573 | { |
|
572 | { | |
574 | // if (m_series->type() != QAbstractSeries::SeriesTypeLine) { |
|
573 | // if (m_series->type() != QAbstractSeries::SeriesTypeLine) { | |
575 | // m_series->append(QPointF(150, 75)); |
|
574 | // m_series->append(QPointF(150, 75)); | |
576 | // } |
|
575 | // } | |
577 |
|
576 | |||
578 | if (m_series->count() > 0) { |
|
577 | if (m_series->count() > 0) { | |
579 | m_series->remove(m_series->points().last()); |
|
578 | m_series->remove(m_series->points().last()); | |
580 | } |
|
579 | } | |
581 | } |
|
580 | } | |
582 |
|
581 | |||
583 | TableWidget::~TableWidget() |
|
582 | TableWidget::~TableWidget() | |
584 | { |
|
583 | { | |
585 |
|
584 | |||
586 | } |
|
585 | } |
General Comments 0
You need to be logged in to leave comments.
Login now