##// END OF EJS Templates
Added placeholders for mappers documentation
Marek Rosa -
r1331:c415cc6dbfb2
parent child
Show More
@@ -1,81 +1,87
1 /*!
1 /*!
2 \page classes.html
2 \page classes.html
3 \title QtCommercial Charts API
3 \title QtCommercial Charts API
4 \keyword All Classes
4 \keyword All Classes
5
5
6 \image class_diagram.png
6 \image class_diagram.png
7
7
8 Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However
8 Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However
9 there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget.
9 there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget.
10 The API supports following chart types:
10 The API supports following chart types:
11
11
12 \list
12 \list
13 \o area
13 \o area
14 \o line
14 \o line
15 \o bar
15 \o bar
16 \o percent bar
16 \o percent bar
17 \o pie
17 \o pie
18 \o scatter
18 \o scatter
19 \o spline
19 \o spline
20 \o stacked bar
20 \o stacked bar
21 \endlist
21 \endlist
22
22
23
23
24 Each chart type is represented by QSeries derived class. To create given chart type users have to use instace of releted sereis class and add it to QChart/QChartView instance.
24 Each chart type is represented by QSeries derived class. To create given chart type users have to use instace of releted sereis class and add it to QChart/QChartView instance.
25 \code
25 \code
26 QLineSeries* series = new QLineSeries();
26 QLineSeries* series = new QLineSeries();
27 series->add(0, 6);
27 series->add(0, 6);
28 series->add(2, 4);
28 series->add(2, 4);
29 ...
29 ...
30 chartView->addSeries(series);
30 chartView->addSeries(series);
31 \endcode
31 \endcode
32
32
33 \raw HTML
33 \raw HTML
34 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
34 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
35 <tr>
35 <tr>
36 <th class="titleheader" width="33%">
36 <th class="titleheader" width="33%">
37 List of classes
37 List of classes
38 </th>
38 </th>
39 </tr>
39 </tr>
40 <tr>
40 <tr>
41 <td valign="top">
41 <td valign="top">
42 <ul>
42 <ul>
43 <li><a href="qareaseries.html">QAreaSeries</a></li>
43 <li><a href="qareaseries.html">QAreaSeries</a></li>
44 <li><a href="qbarseries.html">QBarSeries</a></li>
44 <li><a href="qbarseries.html">QBarSeries</a></li>
45 <li><a href="qbarset.html">QBarSet</a></li>
45 <li><a href="qbarset.html">QBarSet</a></li>
46 <li><a href="qchart.html">QChart</a></li>
46 <li><a href="qchart.html">QChart</a></li>
47 <li><a href="qaxis.html">QAxis</a></li>
47 <li><a href="qaxis.html">QAxis</a></li>
48 <li><a href="qchartview.html">QChartView</a></li>
48 <li><a href="qchartview.html">QChartView</a></li>
49 <li><a href="qlineseries.html">QLineSeries</a></li>
49 <li><a href="qlineseries.html">QLineSeries</a></li>
50 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
50 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
51 <li><a href="qpieseries.html">QPieSeries</a></li>
51 <li><a href="qpieseries.html">QPieSeries</a></li>
52 <li><a href="qpieslice.html">QPieSlice</a></li>
52 <li><a href="qpieslice.html">QPieSlice</a></li>
53 <li><a href="qscatterseries.html">QScatterSeries</a></li>
53 <li><a href="qscatterseries.html">QScatterSeries</a></li>
54 <li><a href="qabstractseries.html">QAbstractSeries</a></li>
54 <li><a href="qabstractseries.html">QAbstractSeries</a></li>
55 <li><a href="qsplineseries.html">QSplineSeries</a></li>
55 <li><a href="qsplineseries.html">QSplineSeries</a></li>
56 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
56 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
57 <li><a href="qxyseries.html">QXYSeries</a></li>
57 <li><a href="qxyseries.html">QXYSeries</a></li>
58 <li><a href="qlegend.html">QLegend</a></li>
58 <li><a href="qlegend.html">QLegend</a></li>
59 <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li>
60 <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li>
61 <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li>
62 <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li>
63 <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li>
64 <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li>
59 </ul>
65 </ul>
60 </td>
66 </td>
61 </tr>
67 </tr>
62 </table>
68 </table>
63
69
64 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
70 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
65 <tr>
71 <tr>
66 <th class="titleheader" width="33%">
72 <th class="titleheader" width="33%">
67 Other files:
73 Other files:
68 </th>
74 </th>
69 </tr>
75 </tr>
70 <tr>
76 <tr>
71 <td valign="top">
77 <td valign="top">
72 <ul>
78 <ul>
73 <li><a href="qchartglobal.html">QChartGlobal</a></li>
79 <li><a href="qchartglobal.html">QChartGlobal</a></li>
74 </ul>
80 </ul>
75 </td>
81 </td>
76 </tr>
82 </tr>
77 </table>
83 </table>
78
84
79 \endraw
85 \endraw
80
86
81 */
87 */
@@ -1,424 +1,429
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"
6 #include "qaxis.h"
5 #include <QAbstractItemModel>
7 #include <QAbstractItemModel>
6
8
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
10
9 QBarModelMapper::QBarModelMapper(QObject *parent) :
11 QBarModelMapper::QBarModelMapper(QObject *parent) :
10 QObject(parent),
12 QObject(parent),
11 d_ptr(new QBarModelMapperPrivate(this))
13 d_ptr(new QBarModelMapperPrivate(this))
12 {
14 {
13 }
15 }
14
16
15 QAbstractItemModel* QBarModelMapper::model() const
17 QAbstractItemModel* QBarModelMapper::model() const
16 {
18 {
17 Q_D(const QBarModelMapper);
19 Q_D(const QBarModelMapper);
18 return d->m_model;
20 return d->m_model;
19 }
21 }
20
22
21 void QBarModelMapper::setModel(QAbstractItemModel *model)
23 void QBarModelMapper::setModel(QAbstractItemModel *model)
22 {
24 {
23 if (model == 0)
25 if (model == 0)
24 return;
26 return;
25
27
26 Q_D(QBarModelMapper);
28 Q_D(QBarModelMapper);
27 if (d->m_model) {
29 if (d->m_model) {
28 disconnect(d->m_model, 0, d, 0);
30 disconnect(d->m_model, 0, d, 0);
29 }
31 }
30
32
31 d->m_model = model;
33 d->m_model = model;
32 d->initializeBarFromModel();
34 d->initializeBarFromModel();
33 // connect signals from the model
35 // connect signals from the model
34 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
36 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
35 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
37 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
36 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
38 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
37 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
39 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
38 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
40 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
39 }
41 }
40
42
41 QBarSeries* QBarModelMapper::series() const
43 QBarSeries* QBarModelMapper::series() const
42 {
44 {
43 Q_D(const QBarModelMapper);
45 Q_D(const QBarModelMapper);
44 return d->m_series;
46 return d->m_series;
45 }
47 }
46
48
47 void QBarModelMapper::setSeries(QBarSeries *series)
49 void QBarModelMapper::setSeries(QBarSeries *series)
48 {
50 {
49 Q_D(QBarModelMapper);
51 Q_D(QBarModelMapper);
50 if (d->m_series) {
52 if (d->m_series) {
51 disconnect(d->m_series, 0, d, 0);
53 disconnect(d->m_series, 0, d, 0);
52 }
54 }
53
55
54 if (series == 0)
56 if (series == 0)
55 return;
57 return;
56
58
57 d->m_series = series;
59 d->m_series = series;
58 d->initializeBarFromModel();
60 d->initializeBarFromModel();
59 // connect the signals from the series
61 // connect the signals from the series
60 // connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
62 // connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int)));
61 // connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
63 // connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int)));
62 // connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
64 // connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int)));
63 }
65 }
64
66
65 int QBarModelMapper::first() const
67 int QBarModelMapper::first() const
66 {
68 {
67 Q_D(const QBarModelMapper);
69 Q_D(const QBarModelMapper);
68 return d->m_first;
70 return d->m_first;
69 }
71 }
70
72
71 void QBarModelMapper::setFirst(int first)
73 void QBarModelMapper::setFirst(int first)
72 {
74 {
73 Q_D(QBarModelMapper);
75 Q_D(QBarModelMapper);
74 d->m_first = qMax(first, 0);
76 d->m_first = qMax(first, 0);
75 d->initializeBarFromModel();
77 d->initializeBarFromModel();
76 }
78 }
77
79
78 int QBarModelMapper::count() const
80 int QBarModelMapper::count() const
79 {
81 {
80 Q_D(const QBarModelMapper);
82 Q_D(const QBarModelMapper);
81 return d->m_count;
83 return d->m_count;
82 }
84 }
83
85
84 void QBarModelMapper::setCount(int count)
86 void QBarModelMapper::setCount(int count)
85 {
87 {
86 Q_D(QBarModelMapper);
88 Q_D(QBarModelMapper);
87 d->m_count = qMax(count, -1);
89 d->m_count = qMax(count, -1);
88 d->initializeBarFromModel();
90 d->initializeBarFromModel();
89 }
91 }
90
92
91 Qt::Orientation QBarModelMapper::orientation() const
93 Qt::Orientation QBarModelMapper::orientation() const
92 {
94 {
93 Q_D(const QBarModelMapper);
95 Q_D(const QBarModelMapper);
94 return d->m_orientation;
96 return d->m_orientation;
95 }
97 }
96
98
97 void QBarModelMapper::setOrientation(Qt::Orientation orientation)
99 void QBarModelMapper::setOrientation(Qt::Orientation orientation)
98 {
100 {
99 Q_D(QBarModelMapper);
101 Q_D(QBarModelMapper);
100 d->m_orientation = orientation;
102 d->m_orientation = orientation;
101 d->initializeBarFromModel();
103 d->initializeBarFromModel();
102 }
104 }
103
105
104 int QBarModelMapper::firstBarSetSection() const
106 int QBarModelMapper::firstBarSetSection() const
105 {
107 {
106 Q_D(const QBarModelMapper);
108 Q_D(const QBarModelMapper);
107 return d->m_firstBarSetSection;
109 return d->m_firstBarSetSection;
108 }
110 }
109
111
110 void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection)
112 void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection)
111 {
113 {
112 Q_D(QBarModelMapper);
114 Q_D(QBarModelMapper);
113 d->m_firstBarSetSection = firstBarSetSection;
115 d->m_firstBarSetSection = firstBarSetSection;
114 d->initializeBarFromModel();
116 d->initializeBarFromModel();
115 }
117 }
116
118
117 int QBarModelMapper::lastBarSetSection() const
119 int QBarModelMapper::lastBarSetSection() const
118 {
120 {
119 Q_D(const QBarModelMapper);
121 Q_D(const QBarModelMapper);
120 return d->m_lastBarSetSection;
122 return d->m_lastBarSetSection;
121 }
123 }
122
124
123 void QBarModelMapper::setLastBarSetSection(int lastBarSetSection)
125 void QBarModelMapper::setLastBarSetSection(int lastBarSetSection)
124 {
126 {
125 Q_D(QBarModelMapper);
127 Q_D(QBarModelMapper);
126 d->m_lastBarSetSection = lastBarSetSection;
128 d->m_lastBarSetSection = lastBarSetSection;
127 d->initializeBarFromModel();
129 d->initializeBarFromModel();
128 }
130 }
129
131
130 int QBarModelMapper::categoriesSection() const
132 int QBarModelMapper::categoriesSection() const
131 {
133 {
132 Q_D(const QBarModelMapper);
134 Q_D(const QBarModelMapper);
133 return d->m_categoriesSection;
135 return d->m_categoriesSection;
134 }
136 }
135
137
136 void QBarModelMapper::setCategoriesSection(int categoriesSection)
138 void QBarModelMapper::setCategoriesSection(int categoriesSection)
137 {
139 {
138 Q_D(QBarModelMapper);
140 Q_D(QBarModelMapper);
139 d->m_categoriesSection = categoriesSection;
141 d->m_categoriesSection = categoriesSection;
140 d->initializeBarFromModel();
142 d->initializeBarFromModel();
141 }
143 }
142
144
143 void QBarModelMapper::reset()
145 void QBarModelMapper::reset()
144 {
146 {
145 Q_D(QBarModelMapper);
147 Q_D(QBarModelMapper);
146 d->m_first = 0;
148 d->m_first = 0;
147 d->m_count = -1;
149 d->m_count = -1;
148 d->m_orientation = Qt::Vertical;
149 d->m_firstBarSetSection = -1;
150 d->m_firstBarSetSection = -1;
150 d->m_lastBarSetSection = -1;
151 d->m_lastBarSetSection = -1;
151 d->m_categoriesSection = -1;
152 d->m_categoriesSection = -1;
152 d->initializeBarFromModel();
153 d->initializeBarFromModel();
153 }
154 }
154
155
155 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
156 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
156
157
157 QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
158 QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
158 m_series(0),
159 m_series(0),
159 m_model(0),
160 m_model(0),
160 m_first(0),
161 m_first(0),
161 m_count(-1),
162 m_count(-1),
162 m_orientation(Qt::Vertical),
163 m_orientation(Qt::Vertical),
163 m_firstBarSetSection(-1),
164 m_firstBarSetSection(-1),
164 m_lastBarSetSection(-1),
165 m_lastBarSetSection(-1),
165 m_categoriesSection(-1),
166 m_categoriesSection(-1),
166 m_seriesSignalsBlock(false),
167 m_seriesSignalsBlock(false),
167 m_modelSignalsBlock(false),
168 m_modelSignalsBlock(false),
168 q_ptr(q)
169 q_ptr(q)
169 {
170 {
170 }
171 }
171
172
172 void QBarModelMapperPrivate::blockModelSignals(bool block)
173 void QBarModelMapperPrivate::blockModelSignals(bool block)
173 {
174 {
174 m_modelSignalsBlock = block;
175 m_modelSignalsBlock = block;
175 }
176 }
176
177
177 void QBarModelMapperPrivate::blockSeriesSignals(bool block)
178 void QBarModelMapperPrivate::blockSeriesSignals(bool block)
178 {
179 {
179 m_seriesSignalsBlock = block;
180 m_seriesSignalsBlock = block;
180 }
181 }
181
182
182 QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index)
183 QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index)
183 {
184 {
184 if (!index.isValid())
185 if (!index.isValid())
185 return 0;
186 return 0;
186
187
187 if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) {
188 if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) {
188 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count))
189 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
189 return m_series->barSets().at(index.column() - m_firstBarSetSection);
190 // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
191 return m_series->barSets().at(index.column() - m_firstBarSetSection);
192 // else
193 // return 0;
194 }
190 } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) {
195 } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) {
191 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
196 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
192 return m_series->barSets().at(index.row() - m_firstBarSetSection);
197 return m_series->barSets().at(index.row() - m_firstBarSetSection);
193 }
198 }
194 return 0; // This part of model has not been mapped to any slice
199 return 0; // This part of model has not been mapped to any slice
195 }
200 }
196
201
197 QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
202 QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
198 {
203 {
199 if (m_count != -1 && posInBar >= m_count)
204 if (m_count != -1 && posInBar >= m_count)
200 return QModelIndex(); // invalid
205 return QModelIndex(); // invalid
201
206
202 if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection)
207 if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection)
203 return QModelIndex(); // invalid
208 return QModelIndex(); // invalid
204
209
205 if (m_orientation == Qt::Vertical)
210 if (m_orientation == Qt::Vertical)
206 return m_model->index(posInBar + m_first, barSection);
211 return m_model->index(posInBar + m_first, barSection);
207 else
212 else
208 return m_model->index(barSection, posInBar + m_first);
213 return m_model->index(barSection, posInBar + m_first);
209 }
214 }
210
215
211 QModelIndex QBarModelMapperPrivate::categoriesModelIndex(int posInCategories)
216 QModelIndex QBarModelMapperPrivate::categoriesModelIndex(int posInCategories)
212 {
217 {
213 if (m_count != -1 && posInCategories >= m_count)
218 if (m_count != -1 && posInCategories >= m_count)
214 return QModelIndex(); // invalid
219 return QModelIndex(); // invalid
215
220
216 if (m_orientation == Qt::Vertical)
221 if (m_orientation == Qt::Vertical)
217 return m_model->index(posInCategories + m_first, m_categoriesSection);
222 return m_model->index(posInCategories + m_first, m_categoriesSection);
218 else
223 else
219 return m_model->index(m_categoriesSection, posInCategories + m_first);
224 return m_model->index(m_categoriesSection, posInCategories + m_first);
220 }
225 }
221
226
222 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
227 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
223 {
228 {
224 Q_UNUSED(topLeft)
229 Q_UNUSED(topLeft)
225 Q_UNUSED(bottomRight)
230 Q_UNUSED(bottomRight)
226
231
227 if (m_model == 0 || m_series == 0)
232 if (m_model == 0 || m_series == 0)
228 return;
233 return;
229
234
230 if (m_modelSignalsBlock)
235 if (m_modelSignalsBlock)
231 return;
236 return;
232
237
233 blockSeriesSignals();
238 blockSeriesSignals();
234 QModelIndex index;
239 QModelIndex index;
235 // QPointF oldPoint;
240 // QPointF oldPoint;
236 // QPointF newPoint;
241 // QPointF newPoint;
237 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
242 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
238 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
243 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
239 index = topLeft.sibling(row, column);
244 index = topLeft.sibling(row, column);
240 QBarSet* bar = barSet(index);
245 QBarSet* bar = barSet(index);
241 if (bar) {
246 if (bar) {
242 if (m_orientation == Qt::Vertical)
247 if (m_orientation == Qt::Vertical)
243 bar->replace(row - m_first, m_model->data(index).toReal());
248 bar->replace(row - m_first, m_model->data(index).toReal());
244 else
249 else
245 bar->replace(column - m_first, m_model->data(index).toReal());
250 bar->replace(column - m_first, m_model->data(index).toReal());
246 }
251 }
247 }
252 }
248 }
253 }
249 blockSeriesSignals(false);
254 blockSeriesSignals(false);
250 }
255 }
251
256
252 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
257 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
253 {
258 {
254 Q_UNUSED(parent);
259 Q_UNUSED(parent);
255 Q_UNUSED(end)
260 Q_UNUSED(end)
256 if (m_modelSignalsBlock)
261 if (m_modelSignalsBlock)
257 return;
262 return;
258
263
259 blockSeriesSignals();
264 blockSeriesSignals();
260 if (m_orientation == Qt::Vertical)
265 if (m_orientation == Qt::Vertical)
261 // insertData(start, end);
266 // insertData(start, end);
262 initializeBarFromModel();
267 initializeBarFromModel();
263 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
268 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
264 initializeBarFromModel();
269 initializeBarFromModel();
265 blockSeriesSignals(false);
270 blockSeriesSignals(false);
266 }
271 }
267
272
268 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
273 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
269 {
274 {
270 Q_UNUSED(parent);
275 Q_UNUSED(parent);
271 Q_UNUSED(end)
276 Q_UNUSED(end)
272 if (m_modelSignalsBlock)
277 if (m_modelSignalsBlock)
273 return;
278 return;
274
279
275 blockSeriesSignals();
280 blockSeriesSignals();
276 if (m_orientation == Qt::Vertical)
281 if (m_orientation == Qt::Vertical)
277 // removeData(start, end);
282 // removeData(start, end);
278 initializeBarFromModel();
283 initializeBarFromModel();
279 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
284 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
280 initializeBarFromModel();
285 initializeBarFromModel();
281 blockSeriesSignals(false);
286 blockSeriesSignals(false);
282 }
287 }
283
288
284 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
289 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
285 {
290 {
286 Q_UNUSED(parent);
291 Q_UNUSED(parent);
287 Q_UNUSED(end)
292 Q_UNUSED(end)
288 if (m_modelSignalsBlock)
293 if (m_modelSignalsBlock)
289 return;
294 return;
290
295
291 blockSeriesSignals();
296 blockSeriesSignals();
292 if (m_orientation == Qt::Horizontal)
297 if (m_orientation == Qt::Horizontal)
293 // insertData(start, end);
298 // insertData(start, end);
294 initializeBarFromModel();
299 initializeBarFromModel();
295 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
300 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
296 initializeBarFromModel();
301 initializeBarFromModel();
297 blockSeriesSignals(false);
302 blockSeriesSignals(false);
298 }
303 }
299
304
300 void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
305 void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
301 {
306 {
302 Q_UNUSED(parent);
307 Q_UNUSED(parent);
303 Q_UNUSED(end)
308 Q_UNUSED(end)
304 if (m_modelSignalsBlock)
309 if (m_modelSignalsBlock)
305 return;
310 return;
306
311
307 blockSeriesSignals();
312 blockSeriesSignals();
308 if (m_orientation == Qt::Horizontal)
313 if (m_orientation == Qt::Horizontal)
309 // removeData(start, end);
314 // removeData(start, end);
310 initializeBarFromModel();
315 initializeBarFromModel();
311 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
316 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize
312 initializeBarFromModel();
317 initializeBarFromModel();
313 blockSeriesSignals(false);
318 blockSeriesSignals(false);
314 }
319 }
315
320
316 void QBarModelMapperPrivate::insertData(int start, int end)
321 void QBarModelMapperPrivate::insertData(int start, int end)
317 {
322 {
318 Q_UNUSED(end)
323 Q_UNUSED(end)
319 if (m_model == 0 || m_series == 0)
324 if (m_model == 0 || m_series == 0)
320 return;
325 return;
321
326
322 if (m_count != -1 && start >= m_first + m_count) {
327 if (m_count != -1 && start >= m_first + m_count) {
323 return;
328 return;
324 } /*else {
329 } /*else {
325 int addedCount = end - start + 1;
330 int addedCount = end - start + 1;
326 if (m_count != -1 && addedCount > m_count)
331 if (m_count != -1 && addedCount > m_count)
327 addedCount = m_count;
332 addedCount = m_count;
328 int first = qMax(start, m_first);
333 int first = qMax(start, m_first);
329 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
334 int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1);
330 for (int k = 0; k < m_series->barSets().count(); k++) {
335 for (int k = 0; k < m_series->barSets().count(); k++) {
331 for (int i = first; i <= last; i++) {
336 for (int i = first; i <= last; i++) {
332 QBar point;
337 QBar point;
333 point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble());
338 point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble());
334 point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble());
339 point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble());
335 m_series->insert(i - m_first, point);
340 m_series->insert(i - m_first, point);
336 }
341 }
342 >>>>>>> Stashed changes
337 }
343 }
338
344
339 // remove excess of slices (abouve m_count)
345 // remove excess of slices (abouve m_count)
340 if (m_count != -1 && m_series->points().size() > m_count)
346 if (m_count != -1 && m_series->points().size() > m_count)
341 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
347 for (int i = m_series->points().size() - 1; i >= m_count; i--) {
342 m_series->remove(m_series->points().at(i));
348 m_series->remove(m_series->points().at(i));
343 }
349 }
344 }*/
350 }*/
345 }
351 }
346
352
347 void QBarModelMapperPrivate::removeData(int start, int end)
353 void QBarModelMapperPrivate::removeData(int start, int end)
348 {
354 {
349 Q_UNUSED(end)
355 Q_UNUSED(end)
350 if (m_model == 0 || m_series == 0)
356 if (m_model == 0 || m_series == 0)
351 return;
357 return;
352
358
353 // int removedCount = end - start + 1;
359 // int removedCount = end - start + 1;
354 if (m_count != -1 && start >= m_first + m_count) {
360 if (m_count != -1 && start >= m_first + m_count) {
355 return;
361 return;
356 } /*else {
362 } /*else {
357 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
363 int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed
358 int first = qMax(start, m_first); // get the index of the first item that will be removed.
364 int first = qMax(start, m_first); // get the index of the first item that will be removed.
359 int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed.
365 int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed.
360 for (int i = last; i >= first; i--) {
366 for (int i = last; i >= first; i--) {
361 m_series->remove(m_series->points().at(i - m_first));
367 m_series->remove(m_series->points().at(i - m_first));
362 }
368 }
363
369
364 if (m_count != -1) {
370 if (m_count != -1) {
365 int itemsAvailable; // check how many are available to be added
371 int itemsAvailable; // check how many are available to be added
366 if (m_orientation == Qt::Vertical)
372 if (m_orientation == Qt::Vertical)
367 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
373 itemsAvailable = m_model->rowCount() - m_first - m_series->count();
368 else
374 else
369 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
375 itemsAvailable = m_model->columnCount() - m_first - m_series->count();
370 int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled.
376 int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled.
371 int currentSize = m_series->count();
377 int currentSize = m_series->count();
372 if (toBeAdded > 0)
378 if (toBeAdded > 0)
373 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
379 for (int i = m_series->count(); i < currentSize + toBeAdded; i++) {
374 QPointF point;
380 QPointF point;
375 point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble());
381 point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble());
376 point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble());
382 point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble());
377 m_series->insert(i, point);
383 m_series->insert(i, point);
378 }
384 }
379 }
385 }
380 }*/
386 }*/
381 }
387 }
382
388
383 void QBarModelMapperPrivate::initializeBarFromModel()
389 void QBarModelMapperPrivate::initializeBarFromModel()
384 {
390 {
385 if (m_model == 0 || m_series == 0)
391 if (m_model == 0 || m_series == 0)
386 return;
392 return;
387
393
388 blockSeriesSignals();
394 blockSeriesSignals();
389 // clear current content
395 // clear current content
390 m_series->clear();
396 m_series->clear();
391
397
392 // create the initial bar sets
398 // create the initial bar sets
393 for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
399 for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
394 int posInBar = 0;
400 int posInBar = 0;
395 QModelIndex barIndex = barModelIndex(i, posInBar);
401 QModelIndex barIndex = barModelIndex(i, posInBar);
396 QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString());
402 QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString());
397 // QModelIndex yIndex = yModelIndex(pointPos);
403 // QModelIndex yIndex = yModelIndex(pointPos);
398 while (barIndex.isValid()) {
404 while (barIndex.isValid()) {
399 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
405 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
400 posInBar++;
406 posInBar++;
401 barIndex = barModelIndex(i, posInBar);
407 barIndex = barModelIndex(i, posInBar);
402 }
408 }
403 m_series->append(barSet);
409 m_series->append(barSet);
404 }
410 }
405
411
406 if (m_categoriesSection != -1) {
412 if (m_series->chart() && m_categoriesSection != -1) {
407 int posInCategories = 0;
413 int posInCategories = 0;
408 QStringList categories;
414 QStringList categories;
409 QModelIndex categoriesIndex = categoriesModelIndex(posInCategories);
415 QModelIndex categoriesIndex = categoriesModelIndex(posInCategories);
410 while (categoriesIndex.isValid()) {
416 while (categoriesIndex.isValid()) {
411 categories.append(m_model->data(categoriesIndex, Qt::DisplayRole).toString());
417 categories.append(m_model->data(categoriesIndex, Qt::DisplayRole).toString());
412 posInCategories++;
418 posInCategories++;
413 categoriesIndex = categoriesModelIndex(posInCategories);
419 categoriesIndex = categoriesModelIndex(posInCategories);
414 }
420 }
415 // TODO: set the categories to axis
421 m_series->chart()->axisX()->categories()->insert(categories);
416 // m_series->setCategories(categories);
417 }
422 }
418 blockSeriesSignals(false);
423 blockSeriesSignals(false);
419 }
424 }
420
425
421 #include "moc_qbarmodelmapper.cpp"
426 #include "moc_qbarmodelmapper.cpp"
422 #include "moc_qbarmodelmapper_p.cpp"
427 #include "moc_qbarmodelmapper_p.cpp"
423
428
424 QTCOMMERCIALCHART_END_NAMESPACE
429 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,64 +1,65
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
14
14 class QTCOMMERCIALCHART_EXPORT QBarModelMapper : public QObject
15 class QTCOMMERCIALCHART_EXPORT QBarModelMapper : public QObject
15 {
16 {
16 Q_OBJECT
17 Q_OBJECT
17 Q_PROPERTY(QBarSeries *series READ series WRITE setSeries)
18 Q_PROPERTY(QBarSeries *series READ series WRITE setSeries)
18 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel)
19 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel)
19 Q_PROPERTY(int first READ first WRITE setFirst)
20 Q_PROPERTY(int first READ first WRITE setFirst)
20 Q_PROPERTY(int count READ count WRITE setCount)
21 Q_PROPERTY(int count READ count WRITE setCount)
21 Q_ENUMS(Qt::Orientation)
22 Q_ENUMS(Qt::Orientation)
22
23
23 protected:
24 protected:
24 explicit QBarModelMapper(QObject *parent = 0);
25 explicit QBarModelMapper(QObject *parent = 0);
25
26
26 public:
27 public:
27 QAbstractItemModel* model() const;
28 QAbstractItemModel* model() const;
28 void setModel(QAbstractItemModel *model);
29 void setModel(QAbstractItemModel *model);
29
30
30 QBarSeries* series() const;
31 QBarSeries* series() const;
31 void setSeries(QBarSeries *series);
32 void setSeries(QBarSeries *series);
32
33
33 int first() const;
34 int first() const;
34 void setFirst(int first);
35 void setFirst(int first);
35
36
36 int count() const;
37 int count() const;
37 void setCount(int count);
38 void setCount(int count);
38
39
40 void reset();
41
42 protected:
39 int firstBarSetSection() const;
43 int firstBarSetSection() const;
40 void setFirstBarSetSection(int firstBarSetSection);
44 void setFirstBarSetSection(int firstBarSetSection);
41
45
42 int lastBarSetSection() const;
46 int lastBarSetSection() const;
43 void setLastBarSetSection(int lastBarSetSection);
47 void setLastBarSetSection(int lastBarSetSection);
44
48
45 int categoriesSection() const;
49 int categoriesSection() const;
46 void setCategoriesSection(int categoriesSection);
50 void setCategoriesSection(int categoriesSection);
47
51
48 protected:
49 Qt::Orientation orientation() const;
52 Qt::Orientation orientation() const;
50 void setOrientation(Qt::Orientation orientation);
53 void setOrientation(Qt::Orientation orientation);
51
52 void reset();
53
54
54 Q_SIGNALS:
55 Q_SIGNALS:
55 void updated();
56 void updated();
56
57
57 protected:
58 protected:
58 QBarModelMapperPrivate * const d_ptr;
59 QBarModelMapperPrivate * const d_ptr;
59 Q_DECLARE_PRIVATE(QBarModelMapper)
60 Q_DECLARE_PRIVATE(QBarModelMapper)
60 };
61 };
61
62
62 QTCOMMERCIALCHART_END_NAMESPACE
63 QTCOMMERCIALCHART_END_NAMESPACE
63
64
64 #endif // QBARMODELMAPPER_H
65 #endif // QBARMODELMAPPER_H
@@ -1,43 +1,51
1 #include "qhbarmodelmapper.h"
1 #include "qhbarmodelmapper.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 /*!
6 \class QHBarModelMapper
7 \brief part of QtCommercial chart API.
8 \mainclass
9
10 Nothing here yet
11 */
12
5 QHBarModelMapper::QHBarModelMapper(QObject *parent) :
13 QHBarModelMapper::QHBarModelMapper(QObject *parent) :
6 QBarModelMapper(parent)
14 QBarModelMapper(parent)
7 {
15 {
8 QBarModelMapper::setOrientation(Qt::Horizontal);
16 QBarModelMapper::setOrientation(Qt::Horizontal);
9 }
17 }
10
18
11 int QHBarModelMapper::firstBarSetRow() const
19 int QHBarModelMapper::firstBarSetRow() const
12 {
20 {
13 return QBarModelMapper::firstBarSetSection();
21 return QBarModelMapper::firstBarSetSection();
14 }
22 }
15
23
16 void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow)
24 void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow)
17 {
25 {
18 return QBarModelMapper::setFirstBarSetSection(firstBarSetRow);
26 return QBarModelMapper::setFirstBarSetSection(firstBarSetRow);
19 }
27 }
20
28
21 int QHBarModelMapper::lastBarSetRow() const
29 int QHBarModelMapper::lastBarSetRow() const
22 {
30 {
23 return QBarModelMapper::lastBarSetSection();
31 return QBarModelMapper::lastBarSetSection();
24 }
32 }
25
33
26 void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow)
34 void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow)
27 {
35 {
28 return QBarModelMapper::setLastBarSetSection(lastBarSetRow);
36 return QBarModelMapper::setLastBarSetSection(lastBarSetRow);
29 }
37 }
30
38
31 int QHBarModelMapper::categoriesRow() const
39 int QHBarModelMapper::categoriesRow() const
32 {
40 {
33 return QBarModelMapper::categoriesSection();
41 return QBarModelMapper::categoriesSection();
34 }
42 }
35
43
36 void QHBarModelMapper::setCategoriesRow(int categoriesRow)
44 void QHBarModelMapper::setCategoriesRow(int categoriesRow)
37 {
45 {
38 return QBarModelMapper::setCategoriesSection(categoriesRow);
46 return QBarModelMapper::setCategoriesSection(categoriesRow);
39 }
47 }
40
48
41 #include "moc_qhbarmodelmapper.cpp"
49 #include "moc_qhbarmodelmapper.cpp"
42
50
43 QTCOMMERCIALCHART_END_NAMESPACE
51 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,43 +1,51
1 #include "qvbarmodelmapper.h"
1 #include "qvbarmodelmapper.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 /*!
6 \class QVBarModelMapper
7 \brief part of QtCommercial chart API.
8 \mainclass
9
10 Nothing here yet
11 */
12
5 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
13 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
6 QBarModelMapper(parent)
14 QBarModelMapper(parent)
7 {
15 {
8 QBarModelMapper::setOrientation(Qt::Vertical);
16 QBarModelMapper::setOrientation(Qt::Vertical);
9 }
17 }
10
18
11 int QVBarModelMapper::firstBarSetColumn() const
19 int QVBarModelMapper::firstBarSetColumn() const
12 {
20 {
13 return QBarModelMapper::firstBarSetSection();
21 return QBarModelMapper::firstBarSetSection();
14 }
22 }
15
23
16 void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn)
24 void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn)
17 {
25 {
18 return QBarModelMapper::setFirstBarSetSection(firstBarSetColumn);
26 return QBarModelMapper::setFirstBarSetSection(firstBarSetColumn);
19 }
27 }
20
28
21 int QVBarModelMapper::lastBarSetColumn() const
29 int QVBarModelMapper::lastBarSetColumn() const
22 {
30 {
23 return QBarModelMapper::lastBarSetSection();
31 return QBarModelMapper::lastBarSetSection();
24 }
32 }
25
33
26 void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn)
34 void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn)
27 {
35 {
28 return QBarModelMapper::setLastBarSetSection(lastBarSetColumn);
36 return QBarModelMapper::setLastBarSetSection(lastBarSetColumn);
29 }
37 }
30
38
31 int QVBarModelMapper::categoriesColumn() const
39 int QVBarModelMapper::categoriesColumn() const
32 {
40 {
33 return QBarModelMapper::categoriesSection();
41 return QBarModelMapper::categoriesSection();
34 }
42 }
35
43
36 void QVBarModelMapper::setCategoriesColumn(int categoriesColumn)
44 void QVBarModelMapper::setCategoriesColumn(int categoriesColumn)
37 {
45 {
38 return QBarModelMapper::setCategoriesSection(categoriesColumn);
46 return QBarModelMapper::setCategoriesSection(categoriesColumn);
39 }
47 }
40
48
41 #include "moc_qvbarmodelmapper.cpp"
49 #include "moc_qvbarmodelmapper.cpp"
42
50
43 QTCOMMERCIALCHART_END_NAMESPACE
51 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,53 +1,61
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 "qhpiemodelmapper.h"
21 #include "qhpiemodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
26 \class QHPieModelMapper
27 \brief part of QtCommercial chart API.
28 \mainclass
29
30 Nothing here yet
31 */
32
25 QHPieModelMapper::QHPieModelMapper(QObject *parent) :
33 QHPieModelMapper::QHPieModelMapper(QObject *parent) :
26 QPieModelMapper(parent)
34 QPieModelMapper(parent)
27 {
35 {
28 QPieModelMapper::setOrientation(Qt::Horizontal);
36 QPieModelMapper::setOrientation(Qt::Horizontal);
29 }
37 }
30
38
31 int QHPieModelMapper::valuesRow() const
39 int QHPieModelMapper::valuesRow() const
32 {
40 {
33 return QPieModelMapper::valuesSection();
41 return QPieModelMapper::valuesSection();
34 }
42 }
35
43
36 void QHPieModelMapper::setValuesRow(int valuesRow)
44 void QHPieModelMapper::setValuesRow(int valuesRow)
37 {
45 {
38 QPieModelMapper::setValuesSection(valuesRow);
46 QPieModelMapper::setValuesSection(valuesRow);
39 }
47 }
40
48
41 int QHPieModelMapper::labelsRow() const
49 int QHPieModelMapper::labelsRow() const
42 {
50 {
43 return QPieModelMapper::labelsSection();
51 return QPieModelMapper::labelsSection();
44 }
52 }
45
53
46 void QHPieModelMapper::setLabelsRow(int labelsRow)
54 void QHPieModelMapper::setLabelsRow(int labelsRow)
47 {
55 {
48 QPieModelMapper::setLabelsSection(labelsRow);
56 QPieModelMapper::setLabelsSection(labelsRow);
49 }
57 }
50
58
51 #include "moc_qhpiemodelmapper.cpp"
59 #include "moc_qhpiemodelmapper.cpp"
52
60
53 QTCOMMERCIALCHART_END_NAMESPACE
61 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,54 +1,62
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 "qpiemodelmapper_p.h"
21 #include "qpiemodelmapper_p.h"
22 #include "qvpiemodelmapper.h"
22 #include "qvpiemodelmapper.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
27 \class QVPieModelMapper
28 \brief part of QtCommercial chart API.
29 \mainclass
30
31 Nothing here yet
32 */
33
26 QVPieModelMapper::QVPieModelMapper(QObject *parent) :
34 QVPieModelMapper::QVPieModelMapper(QObject *parent) :
27 QPieModelMapper(parent)
35 QPieModelMapper(parent)
28 {
36 {
29 QPieModelMapper::setOrientation(Qt::Vertical);
37 QPieModelMapper::setOrientation(Qt::Vertical);
30 }
38 }
31
39
32 int QVPieModelMapper::valuesColumn() const
40 int QVPieModelMapper::valuesColumn() const
33 {
41 {
34 return QPieModelMapper::valuesSection();
42 return QPieModelMapper::valuesSection();
35 }
43 }
36
44
37 void QVPieModelMapper::setValuesColumn(int valuesColumn)
45 void QVPieModelMapper::setValuesColumn(int valuesColumn)
38 {
46 {
39 QPieModelMapper::setValuesSection(valuesColumn);
47 QPieModelMapper::setValuesSection(valuesColumn);
40 }
48 }
41
49
42 int QVPieModelMapper::labelsColumn() const
50 int QVPieModelMapper::labelsColumn() const
43 {
51 {
44 return QPieModelMapper::labelsSection();
52 return QPieModelMapper::labelsSection();
45 }
53 }
46
54
47 void QVPieModelMapper::setLabelsColumn(int labelsColumn)
55 void QVPieModelMapper::setLabelsColumn(int labelsColumn)
48 {
56 {
49 QPieModelMapper::setLabelsSection(labelsColumn);
57 QPieModelMapper::setLabelsSection(labelsColumn);
50 }
58 }
51
59
52 #include "moc_qvpiemodelmapper.cpp"
60 #include "moc_qvpiemodelmapper.cpp"
53
61
54 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,33 +1,41
1 #include "qhxymodelmapper.h"
1 #include "qhxymodelmapper.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 /*!
6 \class QHXYModelMapper
7 \brief part of QtCommercial chart API.
8 \mainclass
9
10 Nothing here yet
11 */
12
5 QHXYModelMapper::QHXYModelMapper(QObject *parent) :
13 QHXYModelMapper::QHXYModelMapper(QObject *parent) :
6 QXYModelMapper(parent)
14 QXYModelMapper(parent)
7 {
15 {
8 QXYModelMapper::setOrientation(Qt::Horizontal);
16 QXYModelMapper::setOrientation(Qt::Horizontal);
9 }
17 }
10
18
11 int QHXYModelMapper::xRow() const
19 int QHXYModelMapper::xRow() const
12 {
20 {
13 return QXYModelMapper::xSection();
21 return QXYModelMapper::xSection();
14 }
22 }
15
23
16 void QHXYModelMapper::setXRow(int xRow)
24 void QHXYModelMapper::setXRow(int xRow)
17 {
25 {
18 return QXYModelMapper::setXSection(xRow);
26 return QXYModelMapper::setXSection(xRow);
19 }
27 }
20
28
21 int QHXYModelMapper::yRow() const
29 int QHXYModelMapper::yRow() const
22 {
30 {
23 return QXYModelMapper::ySection();
31 return QXYModelMapper::ySection();
24 }
32 }
25
33
26 void QHXYModelMapper::setYRow(int yRow)
34 void QHXYModelMapper::setYRow(int yRow)
27 {
35 {
28 return QXYModelMapper::setYSection(yRow);
36 return QXYModelMapper::setYSection(yRow);
29 }
37 }
30
38
31 #include "moc_qhxymodelmapper.cpp"
39 #include "moc_qhxymodelmapper.cpp"
32
40
33 QTCOMMERCIALCHART_END_NAMESPACE
41 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,33 +1,41
1 #include "qvxymodelmapper.h"
1 #include "qvxymodelmapper.h"
2
2
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
4
5 /*!
6 \class QVXYModelMapper
7 \brief part of QtCommercial chart API.
8 \mainclass
9
10 Nothing here yet
11 */
12
5 QVXYModelMapper::QVXYModelMapper(QObject *parent) :
13 QVXYModelMapper::QVXYModelMapper(QObject *parent) :
6 QXYModelMapper(parent)
14 QXYModelMapper(parent)
7 {
15 {
8 QXYModelMapper::setOrientation(Qt::Vertical);
16 QXYModelMapper::setOrientation(Qt::Vertical);
9 }
17 }
10
18
11 int QVXYModelMapper::xColumn() const
19 int QVXYModelMapper::xColumn() const
12 {
20 {
13 return QXYModelMapper::xSection();
21 return QXYModelMapper::xSection();
14 }
22 }
15
23
16 void QVXYModelMapper::setXColumn(int xColumn)
24 void QVXYModelMapper::setXColumn(int xColumn)
17 {
25 {
18 return QXYModelMapper::setXSection(xColumn);
26 return QXYModelMapper::setXSection(xColumn);
19 }
27 }
20
28
21 int QVXYModelMapper::yColumn() const
29 int QVXYModelMapper::yColumn() const
22 {
30 {
23 return QXYModelMapper::ySection();
31 return QXYModelMapper::ySection();
24 }
32 }
25
33
26 void QVXYModelMapper::setYColumn(int yColumn)
34 void QVXYModelMapper::setYColumn(int yColumn)
27 {
35 {
28 return QXYModelMapper::setYSection(yColumn);
36 return QXYModelMapper::setYSection(yColumn);
29 }
37 }
30
38
31 #include "moc_qvxymodelmapper.cpp"
39 #include "moc_qvxymodelmapper.cpp"
32
40
33 QTCOMMERCIALCHART_END_NAMESPACE
41 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,582 +1,586
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_lineRadioButton->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());
482 // barSeries->setCategories(QStringList());
483 // barSeries->setModel(m_model);
483 // barSeries->setModel(m_model);
484 // barSeries->setModelMappingRange(2, 5);
484 // barSeries->setModelMappingRange(2, 5);
485 // barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
485 // barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
486
486
487
487 int first = 3;
488 int first = 3;
488 // int count = 4;
489 int count = 6;
489 QVBarModelMapper *mapper = new QVBarModelMapper;
490 QVBarModelMapper *mapper = new QVBarModelMapper;
490 mapper->setCategoriesSection(5);
491 mapper->setCategoriesColumn(5);
491 mapper->setFirstBarSetSection(2);
492 mapper->setFirstBarSetColumn(2);
492 mapper->setLastBarSetSection(4);
493 mapper->setLastBarSetColumn(4);
493 mapper->setFirst(first);
494 mapper->setFirst(first);
494 // mapper->setCount(count);
495 mapper->setCount(count);
495 mapper->setSeries(barSeries);
496 mapper->setSeries(barSeries);
496 mapper->setModel(m_model);
497 mapper->setModel(m_model);
497 // barSeries->setModelMapper(mapper);
498 // barSeries->setModelMapper(mapper);
498 m_chart->addSeries(barSeries);
499 m_chart->addSeries(barSeries);
500
499 QList<QBarSet*> barsets = barSeries->barSets();
501 QList<QBarSet*> barsets = barSeries->barSets();
500 for (int i = 0; i < barsets.count(); i++) {
502 for (int i = 0; i < barsets.count(); i++) {
501 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
503 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
502 m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count()));
504 m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count()));
503 }
505 }
506
507
504 }
508 }
505
509
506
510
507 if (!m_barRadioButton->isChecked()) {
511 if (!m_barRadioButton->isChecked()) {
508 // m_chart->axisX()->setRange(0, 500);
512 // m_chart->axisX()->setRange(0, 500);
509 // m_chart->axisY()->setRange(0, 220);
513 // m_chart->axisY()->setRange(0, 220);
510 }
514 }
511 m_chart->legend()->setVisible(true);
515 m_chart->legend()->setVisible(true);
512
516
513 // repaint table view colors
517 // repaint table view colors
514 m_tableView->repaint();
518 m_tableView->repaint();
515 m_tableView->setFocus();
519 m_tableView->setFocus();
516 }
520 }
517 }
521 }
518
522
519 void TableWidget::testPie()
523 void TableWidget::testPie()
520 {
524 {
521 // m_pieMapper->setCount(-1);
525 // m_pieMapper->setCount(-1);
522 QPieSlice *slice = new QPieSlice("Hehe", 145);
526 QPieSlice *slice = new QPieSlice("Hehe", 145);
523 slice->setLabelVisible();
527 slice->setLabelVisible();
524 m_pieSeries->append(slice);
528 m_pieSeries->append(slice);
525
529
526 slice = new QPieSlice("Hoho", 34);
530 slice = new QPieSlice("Hoho", 34);
527 slice->setLabelVisible();
531 slice->setLabelVisible();
528 m_pieSeries->append(slice);
532 m_pieSeries->append(slice);
529 // m_series->modelMapper()->setMapX(4);
533 // m_series->modelMapper()->setMapX(4);
530 // m_tableView->setColumnWidth(10, 250);
534 // m_tableView->setColumnWidth(10, 250);
531 // if (specialPie) {
535 // if (specialPie) {
532 // specialPie->remove(specialPie->slices().at(2));
536 // specialPie->remove(specialPie->slices().at(2));
533 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
537 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
534 // specialPie->append(4, "heloo");
538 // specialPie->append(4, "heloo");
535 // }
539 // }
536 }
540 }
537
541
538 void TableWidget::testPie2()
542 void TableWidget::testPie2()
539 {
543 {
540 QPieSlice *slice;
544 QPieSlice *slice;
541 if (m_pieSeries->count() > 0) {
545 if (m_pieSeries->count() > 0) {
542 slice = m_pieSeries->slices().last();
546 slice = m_pieSeries->slices().last();
543 m_pieSeries->remove(slice);
547 m_pieSeries->remove(slice);
544 }
548 }
545
549
546 if (m_pieSeries->count() > 0) {
550 if (m_pieSeries->count() > 0) {
547 slice = m_pieSeries->slices().first();
551 slice = m_pieSeries->slices().first();
548 m_pieSeries->remove(slice);
552 m_pieSeries->remove(slice);
549 }
553 }
550 }
554 }
551
555
552 void TableWidget::testPie3()
556 void TableWidget::testPie3()
553 {
557 {
554 QPieSlice *slice;
558 QPieSlice *slice;
555 if (m_pieSeries->count() > 0) {
559 if (m_pieSeries->count() > 0) {
556 slice = m_pieSeries->slices().last();
560 slice = m_pieSeries->slices().last();
557 slice->setLabel("Dalej");
561 slice->setLabel("Dalej");
558 slice->setValue(222);
562 slice->setValue(222);
559 }
563 }
560
564
561 if (m_pieSeries->count() > 0) {
565 if (m_pieSeries->count() > 0) {
562 slice = m_pieSeries->slices().first();
566 slice = m_pieSeries->slices().first();
563 slice->setLabel("Prawie");
567 slice->setLabel("Prawie");
564 slice->setValue(111);
568 slice->setValue(111);
565 }
569 }
566 }
570 }
567
571
568 void TableWidget::testXY()
572 void TableWidget::testXY()
569 {
573 {
570 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
574 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
571 // m_series->append(QPointF(150, 75));
575 // m_series->append(QPointF(150, 75));
572 // }
576 // }
573
577
574 if (m_series->count() > 0) {
578 if (m_series->count() > 0) {
575 m_series->remove(m_series->points().last());
579 m_series->remove(m_series->points().last());
576 }
580 }
577 }
581 }
578
582
579 TableWidget::~TableWidget()
583 TableWidget::~TableWidget()
580 {
584 {
581
585
582 }
586 }
General Comments 0
You need to be logged in to leave comments. Login now