##// END OF EJS Templates
Updated API Classes page in docs
Marek Rosa -
r1368:eebcdd02f0a9
parent child
Show More
@@ -1,94 +1,104
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 Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However
6 Charts API is build on top of Qt Graphics View Framework. Charts can be displayed as QGraphicsWidget using QChart class. However
7 there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget.
7 there is also convenience class QChartView which is QWidget based. These lets quickly use QCharts as normal Qt widget.
8 The API supports following chart types:
8 The API supports following chart types:
9
9
10 \list
10 \list
11 \o area
11 \o area
12 \o line
12 \o line
13 \o bar
13 \o grouped bar
14 \o percent bar
14 \o percent bar
15 \o pie
15 \o pie
16 \o scatter
16 \o scatter
17 \o spline
17 \o spline
18 \o stacked bar
18 \o stacked bar
19 \endlist
19 \endlist
20
20
21
21
22 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.
22 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.
23 \code
23 \code
24 QLineSeries* series = new QLineSeries();
24 QLineSeries* series = new QLineSeries();
25 series->add(0, 6);
25 series->add(0, 6);
26 series->add(2, 4);
26 series->add(2, 4);
27 ...
27 ...
28 chart->addSeries(series);
28 chartView->chart()->addSeries(series);
29 \endcode
29 \endcode
30
30
31 \raw HTML
31 \raw HTML
32 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
32 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
33 <tr>
33 <tr>
34 <th class="titleheader" width="33%">
34 <th class="titleheader" width="25%">
35 List of classes
35 Common
36 </th>
36 </th>
37 </tr>
37 <th class="titleheader" width="25%">
38 <tr>
38 XY type
39 <td valign="top">
39 </th>
40 <ul>
40 <th class="titleheader" width="25%">
41 <li><a href="qareaseries.html">QAreaSeries</a></li>
41 Pie type
42 <li><a href="qbarseries.html">QBarSeries</a></li>
42 </th>
43 <li><a href="qbarset.html">QBarSet</a></li>
43 <th class="titleheader" width="25%">
44 <li><a href="qchart.html">QChart</a></li>
44 Bar type
45 <li><a href="qaxis.html">QAxis</a></li>
45 </th>
46 <li><a href="qchartview.html">QChartView</a></li>
46 <th class="titleheader" width="25%">
47 <li><a href="qlineseries.html">QLineSeries</a></li>
47 Other files
48 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
49 <li><a href="qpieseries.html">QPieSeries</a></li>
50 <li><a href="qpieslice.html">QPieSlice</a></li>
51 <li><a href="qscatterseries.html">QScatterSeries</a></li>
52 <li><a href="qabstractseries.html">QAbstractSeries</a></li>
53 <li><a href="qsplineseries.html">QSplineSeries</a></li>
54 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
55 <li><a href="qxyseries.html">QXYSeries</a></li>
56 <li><a href="qlegend.html">QLegend</a></li>
57 <li><a href="qpiemodelmapper.html">QPieModelMapper</a></li>
58 <ul>
59 <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li>
60 <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li>
61 </ul>
62 <li><a href="qbarmodelmapper.html">QBarModelMapper</a></li>
63 <ul>
64 <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li>
65 <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li>
66 </ul>
67 <li><a href="qxymodelmapper.html">QXYModelMapper</a></li>
68 <ul>
69 <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li>
70 <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li>
71 </ul>
72 </ul>
73 </td>
74 </tr>
75 </table>
76
77 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
78 <tr>
79 <th class="titleheader" width="33%">
80 Other files:
81 </th>
48 </th>
82 </tr>
49 </tr>
83 <tr>
50 <tr>
84 <td valign="top">
51 <td valign="top">
85 <ul>
52 <ul>
86 <li><a href="qchartglobal.html">QChartGlobal</a></li>
53 <li><a href="qchart.html">QChart</a></li>
87 </ul>
54 <li><a href="qaxis.html">QAxis</a></li>
88 </td>
55 <li><a href="qaxiscategories.html">QAxisCategories</a></li>
56 <li><a href="qchartview.html">QChartView</a></li>
57 <li><a href="qlegend.html">QLegend</a></li>
58 <li><a href="qabstractseries.html">QAbstractSeries</a></li>
59 <li><a href="qchartglobal.html">QChartGlobal</a></li>
60 </ul>
61 </td>
62 <td valign="top">
63 <ul>
64 <li><a href="qlineseries.html">QLineSeries</a></li>
65 <li><a href="qareaseries.html">QAreaSeries</a></li>
66 <li><a href="qscatterseries.html">QScatterSeries</a></li>
67 <li><a href="qsplineseries.html">QSplineSeries</a></li>
68 <li><a href="qxymodelmapper.html">QXYModelMapper</a></li>
69 <li><a href="qhxymodelmapper.html">QHXYModelMapper</a></li>
70 <li><a href="qvxymodelmapper.html">QVXYModelMapper</a></li>
71 </ul>
72 </td>
73 <td valign="top">
74 <ul>
75 <li><a href="qpieseries.html">QPieSeries</a></li>
76 <li><a href="qpieslice.html">QPieSlice</a></li>
77 <li><a href="qpiemodelmapper.html">QPieModelMapper</a></li>
78 <li><a href="qhpiemodelmapper.html">QHPieModelMapper</a></li>
79 <li><a href="qvpiemodelmapper.html">QVPieModelMapper</a></li>
80 </ul>
81 </td>
82 <td valign="top">
83 <ul>
84 <li><a href="qbarseries.html">QBarSeries</a></li>
85 <li><a href="qbarset.html">QBarSet</a></li>
86 <li><a href="qgroupedbarseries.html">QGroupedBarSeries</a></li>
87 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
88 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
89 <li><a href="qbarmodelmapper.html">QBarModelMapper</a></li>
90 <li><a href="qhbarmodelmapper.html">QHBarModelMapper</a></li>
91 <li><a href="qvbarmodelmapper.html">QVBarModelMapper</a></li>
92 </ul>
93 </td>
94 <td valign="top">
95 <ul>
96 <li><a href="qchartglobal.html">QChartGlobal</a></li>
97 </ul>
98 </td>
89 </tr>
99 </tr>
90 </table>
100 </table>
91
101
92 \endraw
102 \endraw
93
103
94 */
104 */
@@ -1,276 +1,276
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 "customtablemodel.h"
21 #include "customtablemodel.h"
22 #include <QVector>
22 #include <QVector>
23 #include <QTime>
23 #include <QTime>
24 #include <QRect>
24 #include <QRect>
25 #include <QColor>
25 #include <QColor>
26
26
27 CustomTableModel::CustomTableModel(QObject *parent) :
27 CustomTableModel::CustomTableModel(QObject *parent) :
28 QAbstractTableModel(parent)
28 QAbstractTableModel(parent)
29 {
29 {
30 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
30 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
31
31
32 m_columnCount = 7;
32 m_columnCount = 7;
33 m_rowCount = 29;
33 m_rowCount = 10;
34
34
35 m_labels.append("Apples");
35 m_labels.append("Apples");
36 m_labels.append("Oranges");
36 m_labels.append("Oranges");
37 m_labels.append("Pears");
37 m_labels.append("Pears");
38 m_labels.append("Peaches");
38 m_labels.append("Peaches");
39 m_labels.append("Coconuts");
39 m_labels.append("Coconuts");
40 m_labels.append("Bananas");
40 m_labels.append("Bananas");
41 m_labels.append("Kiwis");
41 m_labels.append("Kiwis");
42 m_labels.append("Grapes");
42 m_labels.append("Grapes");
43 m_labels.append("Plums");
43 m_labels.append("Plums");
44
44
45 // m_data
45 // m_data
46 for (int i = 0; i < m_rowCount; i++)
46 for (int i = 0; i < m_rowCount; i++)
47 {
47 {
48 QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount);
48 QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount);
49 for (int k = 0; k < dataVec->size(); k++)
49 for (int k = 0; k < dataVec->size(); k++)
50 {
50 {
51 if (k%2 == 0)
51 if (k%2 == 0)
52 dataVec->replace(k, i * 50 + qrand()%20);
52 dataVec->replace(k, i * 50 + qrand()%20);
53 else
53 else
54 dataVec->replace(k, qrand()%100);
54 dataVec->replace(k, qrand()%100);
55 }
55 }
56 m_data.append(dataVec);
56 m_data.append(dataVec);
57 // m_labels.append(QString("Row: %1").arg((i + 1)));
57 // m_labels.append(QString("Row: %1").arg((i + 1)));
58 }
58 }
59 }
59 }
60
60
61 int CustomTableModel::rowCount(const QModelIndex & parent) const
61 int CustomTableModel::rowCount(const QModelIndex & parent) const
62 {
62 {
63 Q_UNUSED(parent)
63 Q_UNUSED(parent)
64 return m_data.count();
64 return m_data.count();
65 }
65 }
66
66
67 int CustomTableModel::columnCount(const QModelIndex & parent) const
67 int CustomTableModel::columnCount(const QModelIndex & parent) const
68 {
68 {
69 Q_UNUSED(parent)
69 Q_UNUSED(parent)
70 return m_columnCount;// + 1;
70 return m_columnCount;// + 1;
71 }
71 }
72
72
73 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const
73 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const
74 {
74 {
75 if (role != Qt::DisplayRole)
75 if (role != Qt::DisplayRole)
76 return QVariant();
76 return QVariant();
77
77
78 if (orientation == Qt::Horizontal)
78 if (orientation == Qt::Horizontal)
79 {
79 {
80 switch(section)
80 switch(section)
81 {
81 {
82 case 7:
82 case 7:
83 return "Fruit";
83 return "Fruit";
84 case 1:
84 case 1:
85 return "Count";
85 return "Count";
86 case 2:
86 case 2:
87 return "Ordered";
87 return "Ordered";
88 default:
88 default:
89 if (section%2 == 0)
89 if (section%2 == 0)
90 return "x";
90 return "x";
91 else
91 else
92 return "y";
92 return "y";
93 }
93 }
94 }
94 }
95 else
95 else
96 return QString("%1").arg(section /*+ 1*/);
96 return QString("%1").arg(section /*+ 1*/);
97 }
97 }
98
98
99 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
99 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
100 {
100 {
101 if (role == Qt::DisplayRole)
101 if (role == Qt::DisplayRole)
102 {
102 {
103 switch(index.column())
103 switch(index.column())
104 {
104 {
105 // case 7:
105 // case 7:
106 // return m_labels[index.row()];
106 // return m_labels[index.row()];
107 default:
107 default:
108 return m_data[index.row()]->at(index.column());
108 return m_data[index.row()]->at(index.column());
109 break;
109 break;
110 }
110 }
111 }
111 }
112 else if (role == Qt::EditRole)
112 else if (role == Qt::EditRole)
113 {
113 {
114 switch(index.column())
114 switch(index.column())
115 {
115 {
116 // case 7:
116 // case 7:
117 // return m_labels[index.row()];
117 // return m_labels[index.row()];
118 default:
118 default:
119 return m_data[index.row()]->at(index.column());
119 return m_data[index.row()]->at(index.column());
120 break;
120 break;
121 }
121 }
122 }
122 }
123 else if (role == Qt::BackgroundRole)
123 else if (role == Qt::BackgroundRole)
124 {
124 {
125 QRect rect;
125 QRect rect;
126 foreach(rect, m_mapping)
126 foreach(rect, m_mapping)
127 if(rect.contains(index.column(), index.row()))
127 if(rect.contains(index.column(), index.row()))
128 return QColor(m_mapping.key(rect));
128 return QColor(m_mapping.key(rect));
129
129
130 // cell not mapped return white color
130 // cell not mapped return white color
131 return QColor(Qt::white);
131 return QColor(Qt::white);
132 }
132 }
133 return QVariant();
133 return QVariant();
134 }
134 }
135
135
136 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & value, int role)
136 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & value, int role)
137 {
137 {
138 if (index.isValid() && role == Qt::EditRole)
138 if (index.isValid() && role == Qt::EditRole)
139 {
139 {
140 switch(index.column())
140 switch(index.column())
141 {
141 {
142 case 7:
142 case 7:
143 m_labels.replace(index.row(), value.toString());
143 m_labels.replace(index.row(), value.toString());
144 break;
144 break;
145 default:
145 default:
146 m_data[index.row()]->replace(index.column(), value.toDouble());
146 m_data[index.row()]->replace(index.column(), value.toDouble());
147 break;
147 break;
148 }
148 }
149 emit dataChanged(index, index);
149 emit dataChanged(index, index);
150 return true;
150 return true;
151 }
151 }
152 return false;
152 return false;
153 }
153 }
154
154
155 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const
155 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const
156 {
156 {
157 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
157 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
158 }
158 }
159
159
160 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent)
160 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent)
161 {
161 {
162 Q_UNUSED(parent)
162 Q_UNUSED(parent)
163
163
164 if (row < 0)
164 if (row < 0)
165 row = 0;
165 row = 0;
166 beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1);
166 beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1);
167 for (int i = row; i < row + count; i++)
167 for (int i = row; i < row + count; i++)
168 {
168 {
169 // m_points.insert(row, QPointF(10,20));
169 // m_points.insert(row, QPointF(10,20));
170 QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount);
170 QVector<qreal>* dataVec = new QVector<qreal>(m_columnCount);
171 QVector<QColor>* colorVec = new QVector<QColor>(m_columnCount);
171 QVector<QColor>* colorVec = new QVector<QColor>(m_columnCount);
172 for (int k = 0; k < dataVec->size(); k++)
172 for (int k = 0; k < dataVec->size(); k++)
173 {
173 {
174 if (k%2 == 0)
174 if (k%2 == 0)
175 // dataVec->replace(k, i * 50 + qrand()%20);
175 // dataVec->replace(k, i * 50 + qrand()%20);
176 {
176 {
177 int difference = 0;
177 int difference = 0;
178 if (i < m_data.size())
178 if (i < m_data.size())
179 {
179 {
180 if (i - 1 >= 0)
180 if (i - 1 >= 0)
181 {
181 {
182 if (row > 0)
182 if (row > 0)
183 difference = (int)((qAbs(m_data[i]->at(k) - m_data[row - 1]->at(k)))/count);
183 difference = (int)((qAbs(m_data[i]->at(k) - m_data[row - 1]->at(k)))/count);
184 else
184 else
185 difference = (int)((qAbs(m_data[i]->at(k)/count)));
185 difference = (int)((qAbs(m_data[i]->at(k)/count)));
186 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%qMax(1, difference));
186 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%qMax(1, difference));
187 }
187 }
188 else
188 else
189 dataVec->replace(k, qrand()%40 + 10);
189 dataVec->replace(k, qrand()%40 + 10);
190 }
190 }
191 else
191 else
192 {
192 {
193 if (i - 1 >= 0)
193 if (i - 1 >= 0)
194 {
194 {
195 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%40 + 10);
195 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%40 + 10);
196 }
196 }
197 else
197 else
198 {
198 {
199 dataVec->replace(k, qrand()%40 + 10);
199 dataVec->replace(k, qrand()%40 + 10);
200 }
200 }
201 }
201 }
202 }
202 }
203 else
203 else
204 dataVec->replace(k, qrand()%100);
204 dataVec->replace(k, qrand()%100);
205 colorVec->replace(k, QColor(Qt::white));
205 colorVec->replace(k, QColor(Qt::white));
206 }
206 }
207 m_data.insert(i, dataVec);
207 m_data.insert(i, dataVec);
208 m_labels.insert(i,(QString("Row: %1").arg(i + 1)));
208 m_labels.insert(i,(QString("Row: %1").arg(i + 1)));
209 }
209 }
210 endInsertRows();
210 endInsertRows();
211 return true;
211 return true;
212 }
212 }
213
213
214 bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & parent)
214 bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & parent)
215 {
215 {
216 if (row > this->rowCount() - 1)
216 if (row > this->rowCount() - 1)
217 return false;
217 return false;
218 if (row < 0)
218 if (row < 0)
219 row = 0;
219 row = 0;
220 if (row + count > rowCount())
220 if (row + count > rowCount())
221 return false;
221 return false;
222 beginRemoveRows(parent, row, row + count - 1);
222 beginRemoveRows(parent, row, row + count - 1);
223 for (int i = row; i < row + count; i++)
223 for (int i = row; i < row + count; i++)
224 {
224 {
225 QVector<qreal>* item = m_data.at(row);
225 QVector<qreal>* item = m_data.at(row);
226 m_data.removeAt(row);
226 m_data.removeAt(row);
227 delete item;
227 delete item;
228 m_labels.removeAt(row);
228 m_labels.removeAt(row);
229 }
229 }
230 endRemoveRows();
230 endRemoveRows();
231 return true;
231 return true;
232 }
232 }
233
233
234 bool CustomTableModel::insertColumns ( int column, int count, const QModelIndex & parent)
234 bool CustomTableModel::insertColumns ( int column, int count, const QModelIndex & parent)
235 {
235 {
236 if (column < 0)
236 if (column < 0)
237 column = 0;
237 column = 0;
238 beginInsertColumns(parent, column, column + count - 1);
238 beginInsertColumns(parent, column, column + count - 1);
239 m_columnCount += count;
239 m_columnCount += count;
240 for (int i = column; i < column + count; i++)
240 for (int i = column; i < column + count; i++)
241 for (int k = 0; k < rowCount(); k++)
241 for (int k = 0; k < rowCount(); k++)
242 if (k - 1 >= 0) {
242 if (k - 1 >= 0) {
243 m_data[k]->insert(i, m_data[k - 1]->at(i) + qrand()%40 + 10);
243 m_data[k]->insert(i, m_data[k - 1]->at(i) + qrand()%40 + 10);
244 } else {
244 } else {
245 m_data[k]->insert(i, qrand()%40);
245 m_data[k]->insert(i, qrand()%40);
246 }
246 }
247 endInsertColumns();
247 endInsertColumns();
248 return true;
248 return true;
249 }
249 }
250
250
251 bool CustomTableModel::removeColumns ( int column, int count, const QModelIndex & parent)
251 bool CustomTableModel::removeColumns ( int column, int count, const QModelIndex & parent)
252 {
252 {
253 if (column > columnCount() - 1)
253 if (column > columnCount() - 1)
254 return false;
254 return false;
255 if (column < 0)
255 if (column < 0)
256 column = 0;
256 column = 0;
257 if (column + count > columnCount())
257 if (column + count > columnCount())
258 return false;
258 return false;
259 beginRemoveColumns(parent, column, column + count -1);
259 beginRemoveColumns(parent, column, column + count -1);
260 m_columnCount -= count;
260 m_columnCount -= count;
261 for (int i = column; i < column + count; i++)
261 for (int i = column; i < column + count; i++)
262 for (int k = 0; k < rowCount(); k++)
262 for (int k = 0; k < rowCount(); k++)
263 m_data[k]->remove(column);
263 m_data[k]->remove(column);
264 endRemoveColumns();
264 endRemoveColumns();
265 return true;
265 return true;
266 }
266 }
267
267
268 void CustomTableModel::addMapping(QString color, QRect area)
268 void CustomTableModel::addMapping(QString color, QRect area)
269 {
269 {
270 m_mapping.insertMulti(color, area);
270 m_mapping.insertMulti(color, area);
271 }
271 }
272
272
273 void CustomTableModel::addMapping(QString color, int left, int top, int right, int bottom)
273 void CustomTableModel::addMapping(QString color, int left, int top, int right, int bottom)
274 {
274 {
275 addMapping(color, QRect(QPoint(left, top), QPoint(right, bottom)));
275 addMapping(color, QRect(QPoint(left, top), QPoint(right, bottom)));
276 }
276 }
@@ -1,590 +1,611
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 m_barSeries(0),
54 m_barSeries(0),
55 m_barMapper(0)
55 m_barMapper(0)
56 // specialPie(0)
56 // specialPie(0)
57 {
57 {
58 setGeometry(1900, 100, 1000, 600);
58 setGeometry(1900, 100, 1000, 600);
59 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
59 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
60 // create simple model for storing data
60 // create simple model for storing data
61 // user's table data model
61 // user's table data model
62 m_model = new CustomTableModel;
62 m_model = new CustomTableModel;
63 m_tableView = new QTableView;
63 m_tableView = new QTableView;
64 m_tableView->setModel(m_model);
64 m_tableView->setModel(m_model);
65 // m_tableView->setMinimumHeight(300);
65 // m_tableView->setMinimumHeight(300);
66 m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
66 m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
67 m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
67 m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
68
68
69 m_chart = new QChart;
69 m_chart = new QChart;
70 m_chart->legend()->setVisible(true);
70 m_chart->legend()->setVisible(true);
71 m_chart->setAnimationOptions(QChart::SeriesAnimations);
71 m_chart->setAnimationOptions(QChart::SeriesAnimations);
72 m_chartView = new QChartView(m_chart);
72 m_chartView = new QChartView(m_chart);
73 m_chartView->setRenderHint(QPainter::Antialiasing);
73 m_chartView->setRenderHint(QPainter::Antialiasing);
74 m_chartView->setMinimumSize(640, 480);
74 m_chartView->setMinimumSize(640, 480);
75
75
76 // add, remove data buttons
76 // add, remove data buttons
77 QPushButton* addRowAboveButton = new QPushButton("Add row above");
77 QPushButton* addRowAboveButton = new QPushButton("Add row above");
78 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
78 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
79
79
80 QPushButton* addRowBelowButton = new QPushButton("Add row below");
80 QPushButton* addRowBelowButton = new QPushButton("Add row below");
81 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
81 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
82
82
83 QPushButton* removeRowButton = new QPushButton("Remove row");
83 QPushButton* removeRowButton = new QPushButton("Remove row");
84 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
84 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
85
85
86 QPushButton* addColumnRightButton = new QPushButton("Add column to the right");
86 QPushButton* addColumnRightButton = new QPushButton("Add column to the right");
87 connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight()));
87 connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight()));
88
88
89 QPushButton* removeColumnButton = new QPushButton("Remove column");
89 QPushButton* removeColumnButton = new QPushButton("Remove column");
90 connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn()));
90 connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn()));
91
91
92 QPushButton* specialPieButton = new QPushButton("Add slices using series API");
92 QPushButton* specialPieButton = new QPushButton("Add slices using series API");
93 connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie()));
93 connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie()));
94
94
95 QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API");
95 QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API");
96 connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2()));
96 connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2()));
97
97
98 QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API");
98 QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API");
99 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
99 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
100
100
101 QPushButton* xyTestButton = new QPushButton("Append XY point");
101 QPushButton* xyTestButton = new QPushButton("Append XY point");
102 connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY()));
102 connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY()));
103
103
104
104
105 QLabel *spinBoxLabel = new QLabel("Rows affected:");
105 QLabel *spinBoxLabel = new QLabel("Rows affected:");
106
106
107 // spin box for setting number of affected items (add, remove)
107 // spin box for setting number of affected items (add, remove)
108 m_linesCountSpinBox = new QSpinBox;
108 m_linesCountSpinBox = new QSpinBox;
109 m_linesCountSpinBox->setRange(1, 10);
109 m_linesCountSpinBox->setRange(1, 10);
110 m_linesCountSpinBox->setValue(1);
110 m_linesCountSpinBox->setValue(1);
111
111
112 // buttons layout
112 // buttons layout
113 QVBoxLayout* buttonsLayout = new QVBoxLayout;
113 QVBoxLayout* buttonsLayout = new QVBoxLayout;
114 buttonsLayout->addWidget(spinBoxLabel);
114 buttonsLayout->addWidget(spinBoxLabel);
115 buttonsLayout->addWidget(m_linesCountSpinBox);
115 buttonsLayout->addWidget(m_linesCountSpinBox);
116 // buttonsLayout->addWidget(addRowAboveButton);
116 // buttonsLayout->addWidget(addRowAboveButton);
117 buttonsLayout->addWidget(addRowBelowButton);
117 buttonsLayout->addWidget(addRowBelowButton);
118 buttonsLayout->addWidget(removeRowButton);
118 buttonsLayout->addWidget(removeRowButton);
119 // buttonsLayout->addWidget(addColumnRightButton);
119 // buttonsLayout->addWidget(addColumnRightButton);
120 // buttonsLayout->addWidget(removeColumnButton);
120 // buttonsLayout->addWidget(removeColumnButton);
121 buttonsLayout->addWidget(specialPieButton);
121 buttonsLayout->addWidget(specialPieButton);
122 buttonsLayout->addWidget(specialPieButton2);
122 buttonsLayout->addWidget(specialPieButton2);
123 buttonsLayout->addWidget(specialPieButton3);
123 buttonsLayout->addWidget(specialPieButton3);
124 buttonsLayout->addWidget(xyTestButton);
124 buttonsLayout->addWidget(xyTestButton);
125 buttonsLayout->addStretch();
125 buttonsLayout->addStretch();
126
126
127 // chart type radio buttons
127 // chart type radio buttons
128 m_lineRadioButton = new QRadioButton("Line");
128 m_lineRadioButton = new QRadioButton("Line");
129 m_splineRadioButton = new QRadioButton("Spline");
129 m_splineRadioButton = new QRadioButton("Spline");
130 m_scatterRadioButton = new QRadioButton("Scatter");
130 m_scatterRadioButton = new QRadioButton("Scatter");
131 m_pieRadioButton = new QRadioButton("Pie");
131 m_pieRadioButton = new QRadioButton("Pie");
132 m_areaRadioButton = new QRadioButton("Area");
132 m_areaRadioButton = new QRadioButton("Area");
133 m_barRadioButton = new QRadioButton("Bar");
133 m_barRadioButton = new QRadioButton("Bar");
134
134
135 connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
135 connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
136 connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
136 connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
137 connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
137 connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
138 connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
138 connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
139 connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
139 connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
140 connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
140 connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
141 m_barRadioButton->setChecked(true);
141 m_barRadioButton->setChecked(true);
142
142
143 // radio buttons layout
143 // radio buttons layout
144 QVBoxLayout* radioLayout = new QVBoxLayout;
144 QVBoxLayout* radioLayout = new QVBoxLayout;
145 radioLayout->addWidget(m_lineRadioButton);
145 radioLayout->addWidget(m_lineRadioButton);
146 radioLayout->addWidget(m_splineRadioButton);
146 radioLayout->addWidget(m_splineRadioButton);
147 radioLayout->addWidget(m_scatterRadioButton);
147 radioLayout->addWidget(m_scatterRadioButton);
148 radioLayout->addWidget(m_pieRadioButton);
148 radioLayout->addWidget(m_pieRadioButton);
149 // radioLayout->addWidget(m_areaRadioButton);
149 // radioLayout->addWidget(m_areaRadioButton);
150 radioLayout->addWidget(m_barRadioButton);
150 radioLayout->addWidget(m_barRadioButton);
151 radioLayout->addStretch();
151 radioLayout->addStretch();
152
152
153 // create main layout
153 // create main layout
154 QGridLayout* mainLayout = new QGridLayout;
154 QGridLayout* mainLayout = new QGridLayout;
155 mainLayout->addLayout(buttonsLayout, 2, 0);
155 mainLayout->addLayout(buttonsLayout, 2, 0);
156 mainLayout->addLayout(radioLayout, 3, 0);
156 mainLayout->addLayout(radioLayout, 3, 0);
157 mainLayout->addWidget(m_tableView, 1, 0);
157 mainLayout->addWidget(m_tableView, 1, 0);
158 mainLayout->addWidget(m_chartView, 1, 1, 2, 1);
158 mainLayout->addWidget(m_chartView, 1, 1, 2, 1);
159 setLayout(mainLayout);
159 setLayout(mainLayout);
160 m_lineRadioButton->setFocus();
160 m_lineRadioButton->setFocus();
161 }
161 }
162
162
163 void TableWidget::addRowAbove()
163 void TableWidget::addRowAbove()
164 {
164 {
165 m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value());
165 m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value());
166
166
167 }
167 }
168
168
169 void TableWidget::addRowBelow()
169 void TableWidget::addRowBelow()
170 {
170 {
171 m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value());
171 m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value());
172
172
173 }
173 }
174
174
175 void TableWidget::removeRow()
175 void TableWidget::removeRow()
176 {
176 {
177 m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value()));
177 m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value()));
178 }
178 }
179
179
180 void TableWidget::addColumnRight()
180 void TableWidget::addColumnRight()
181 {
181 {
182 m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value());
182 m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value());
183 }
183 }
184
184
185 void TableWidget::removeColumn()
185 void TableWidget::removeColumn()
186 {
186 {
187 m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value()));
187 m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value()));
188 }
188 }
189
189
190 void TableWidget::updateChartType(bool toggle)
190 void TableWidget::updateChartType(bool toggle)
191 {
191 {
192 // this if is needed, so that the function is only called once.
192 // this if is needed, so that the function is only called once.
193 // For the radioButton that was enabled.
193 // For the radioButton that was enabled.
194 if (toggle) {
194 if (toggle) {
195 // specialPie = 0;
195 // specialPie = 0;
196 m_chart->removeAllSeries();
196 m_chart->removeAllSeries();
197 m_series = 0;
197 m_series = 0;
198 // m_chart->axisX()->setNiceNumbersEnabled(false);
198 // m_chart->axisX()->setNiceNumbersEnabled(false);
199 // m_chart->axisY()->setNiceNumbersEnabled(false);
199 // m_chart->axisY()->setNiceNumbersEnabled(false);
200 if (m_mapper) {
200 if (m_mapper) {
201 m_mapper->deleteLater();
201 m_mapper->deleteLater();
202 m_mapper = 0;
202 m_mapper = 0;
203 }
203 }
204
204
205 if (m_pieMapper) {
205 if (m_pieMapper) {
206 m_pieMapper->deleteLater();
206 m_pieMapper->deleteLater();
207 m_pieMapper = 0;
207 m_pieMapper = 0;
208 }
208 }
209
209
210 if (m_pieMapper2) {
210 if (m_pieMapper2) {
211 m_pieMapper2->deleteLater();
211 m_pieMapper2->deleteLater();
212 m_pieMapper2 = 0;
212 m_pieMapper2 = 0;
213 }
213 }
214
214
215 // if (m_series) {
215 // if (m_series) {
216 // delete m_series;
216 // delete m_series;
217 // m_series = 0;
217 // m_series = 0;
218 // }
218 // }
219
219
220 // renable axes of the chart (pie hides them)
220 // renable axes of the chart (pie hides them)
221 // x axis
221 // x axis
222 QAxis *axis = m_chart->axisX();
222 QAxis *axis = m_chart->axisX();
223 axis->setAxisVisible(true);
223 axis->setAxisVisible(true);
224 axis->setGridLineVisible(true);
224 axis->setGridLineVisible(true);
225 axis->setLabelsVisible(true);
225 axis->setLabelsVisible(true);
226
226
227 // y axis
227 // y axis
228 axis = m_chart->axisY();
228 axis = m_chart->axisY();
229 axis->setAxisVisible(true);
229 axis->setAxisVisible(true);
230 axis->setGridLineVisible(true);
230 axis->setGridLineVisible(true);
231 axis->setLabelsVisible(true);
231 axis->setLabelsVisible(true);
232
232
233 m_model->clearMapping();
233 m_model->clearMapping();
234
234
235 QString seriesColorHex = "#000000";
235 QString seriesColorHex = "#000000";
236 // QPen pen;
236 // QPen pen;
237 // pen.setWidth(2);
237 // pen.setWidth(2);
238
238
239 if (m_lineRadioButton->isChecked())
239 if (m_lineRadioButton->isChecked())
240 {
240 {
241 // m_chart->setAnimationOptions(QChart::NoAnimation);
241 // m_chart->setAnimationOptions(QChart::NoAnimation);
242
242
243 // series 1
243 // series 1
244 m_series = new QLineSeries;
244 m_series = new QLineSeries;
245
245
246 // m_mapper = new QHXYModelMapper;
246 // m_mapper = new QHXYModelMapper;
247 // m_mapper->setModel(m_model);
247 // m_mapper->setModel(m_model);
248 // m_mapper->setSeries(m_series);
248 // m_mapper->setSeries(m_series);
249 // m_mapper->setXRow(0);
249 // m_mapper->setXRow(0);
250 // m_mapper->setYRow(1);
250 // m_mapper->setYRow(1);
251 // m_mapper->setFirst(3);
251 // m_mapper->setFirst(3);
252 // m_mapper->setCount(4);
252 // m_mapper->setCount(4);
253
253
254 QAxisCategories* xCategories = m_chart->axisX()->categories();
255 xCategories->insert(50, "Jeden");
256 xCategories->insert(100, "Dwa");
257 xCategories->insert(150, "Trzy");
258 xCategories->insert(200, "Cztery");
259 xCategories->insert(250, "Piec");
260 xCategories->insert(300, "szesc");
261
254 m_mapper = new QVXYModelMapper;
262 m_mapper = new QVXYModelMapper;
255 m_mapper->setModel(m_model);
263 m_mapper->setModel(m_model);
256 m_mapper->setSeries(m_series);
264 m_mapper->setSeries(m_series);
257 m_mapper->setXColumn(0);
265 m_mapper->setXColumn(0);
258 m_mapper->setYColumn(1);
266 m_mapper->setYColumn(1);
259 m_mapper->setFirst(3);
267 m_mapper->setFirst(3);
260 // m_mapper->setCount(4);
268 // m_mapper->setCount(4);
261
269
262 // m_series->setModelMapping(0,1, Qt::Vertical);
270 // m_series->setModelMapping(0,1, Qt::Vertical);
263 // m_series->setModelMappingRange(3, 4);
271 // m_series->setModelMappingRange(3, 4);
264 m_chart->addSeries(m_series);
272 m_chart->addSeries(m_series);
265 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
273 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
266 m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4));
274 m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4));
267
275
268 // // series 2
276 // // series 2
269 // m_series = new QLineSeries;
277 // m_series = new QLineSeries;
270 // m_series->setModel(m_model);
278 // m_series->setModel(m_model);
271
279
272 // mapper = new QXYModelMapper;
280 // mapper = new QXYModelMapper;
273 // mapper->setMapX(3);
281 // mapper->setMapX(3);
274 // mapper->setMapY(4);
282 // mapper->setMapY(4);
275 // // mapper->setFirst(3);
283 // // mapper->setFirst(3);
276 // // mapper->setCount(4);
284 // // mapper->setCount(4);
277 // m_series->setModelMapper(mapper);
285 // m_series->setModelMapper(mapper);
278 // // m_series->setModelMapping(2,3, Qt::Vertical);
286 // // m_series->setModelMapping(2,3, Qt::Vertical);
279 // m_chart->addSeries(m_series);
287 // m_chart->addSeries(m_series);
280 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
288 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
281 // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000));
289 // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000));
282
290
283 // // series 3
291 // // series 3
284 // m_series = new QLineSeries;
292 // m_series = new QLineSeries;
285 // m_series->setModel(m_model);
293 // m_series->setModel(m_model);
286
294
287 // mapper = new QXYModelMapper;
295 // mapper = new QXYModelMapper;
288 // mapper->setMapX(5);
296 // mapper->setMapX(5);
289 // mapper->setMapY(6);
297 // mapper->setMapY(6);
290 // mapper->setFirst(2);
298 // mapper->setFirst(2);
291 // mapper->setCount(-1);
299 // mapper->setCount(-1);
292 // m_series->setModelMapper(mapper);
300 // m_series->setModelMapper(mapper);
293 // // m_series->setModelMapping(4,5, Qt::Vertical);
301 // // m_series->setModelMapping(4,5, Qt::Vertical);
294 // // m_series->setModelMappingRange(2, -1);
302 // // m_series->setModelMappingRange(2, -1);
295 // m_chart->addSeries(m_series);
303 // m_chart->addSeries(m_series);
296 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
304 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
297 // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000));
305 // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000));
298 }
306 }
299 else if (m_splineRadioButton->isChecked())
307 else if (m_splineRadioButton->isChecked())
300 {
308 {
301 m_chart->setAnimationOptions(QChart::NoAnimation);
309 m_chart->setAnimationOptions(QChart::NoAnimation);
302
310
303 // series 1
311 // series 1
304 m_series = new QSplineSeries;
312 m_series = new QSplineSeries;
305 // m_series->setModel(m_model);
313 // m_series->setModel(m_model);
306
314
307 // m_mapper = new QVXYModelMapper;
315 // m_mapper = new QVXYModelMapper;
308 // m_mapper->setSeries(m_series);
316 // m_mapper->setSeries(m_series);
309 // m_mapper->setModel(m_model);
317 // m_mapper->setModel(m_model);
310 // m_mapper->setXColumn(0);
318 // m_mapper->setXColumn(0);
311 // m_mapper->setYColumn(1);
319 // m_mapper->setYColumn(1);
312 // m_mapper->setFirst(0);
320 // m_mapper->setFirst(0);
313 // m_mapper->setCount(-1);
321 // m_mapper->setCount(-1);
314
322
315 // m_series->setModelMapper(mapper);
323 // m_series->setModelMapper(mapper);
316
324
317 m_chart->addSeries(m_series);
325 m_chart->addSeries(m_series);
318 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
326 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
319 m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000));
327 m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000));
320
328
321 // // series 2
329 // // series 2
322 // m_series = new QSplineSeries;
330 // m_series = new QSplineSeries;
323 // m_series->setModel(m_model);
331 // m_series->setModel(m_model);
324
332
325 // mapper = new QXYModelMapper;
333 // mapper = new QXYModelMapper;
326 // mapper->setMapX(2);
334 // mapper->setMapX(2);
327 // mapper->setMapY(3);
335 // mapper->setMapY(3);
328 // mapper->setFirst(2);
336 // mapper->setFirst(2);
329 // mapper->setCount(4);
337 // mapper->setCount(4);
330
338
331 // m_series->setModelMapper(mapper);
339 // m_series->setModelMapper(mapper);
332
340
333 // m_chart->addSeries(m_series);
341 // m_chart->addSeries(m_series);
334 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
342 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
335 // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4));
343 // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4));
336
344
337 // // series 3
345 // // series 3
338 // m_series = new QSplineSeries;
346 // m_series = new QSplineSeries;
339 // m_series->setModel(m_model);
347 // m_series->setModel(m_model);
340
348
341 // mapper = new QXYModelMapper;
349 // mapper = new QXYModelMapper;
342 // mapper->setMapX(4);
350 // mapper->setMapX(4);
343 // mapper->setMapY(5);
351 // mapper->setMapY(5);
344 // mapper->setFirst(2);
352 // mapper->setFirst(2);
345 // mapper->setCount(-1);
353 // mapper->setCount(-1);
346
354
347 // m_series->setModelMapper(mapper);
355 // m_series->setModelMapper(mapper);
348
356
349 // m_chart->addSeries(m_series);
357 // m_chart->addSeries(m_series);
350 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
358 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
351 // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
359 // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
352 } else if (m_scatterRadioButton->isChecked())
360 } else if (m_scatterRadioButton->isChecked())
353 {
361 {
354 m_chart->setAnimationOptions(QChart::NoAnimation);
362 m_chart->setAnimationOptions(QChart::NoAnimation);
355
363
356 // series 1
364 // series 1
357 m_series = new QScatterSeries;
365 m_series = new QScatterSeries;
358
366
359 // m_mapper = new QVXYModelMapper;
367 // m_mapper = new QVXYModelMapper;
360 // m_mapper->setSeries(m_series);
368 // m_mapper->setSeries(m_series);
361 // m_mapper->setModel(m_model);
369 // m_mapper->setModel(m_model);
362 // m_mapper->setXColumn(0);
370 // m_mapper->setXColumn(0);
363 // m_mapper->setYColumn(1);
371 // m_mapper->setYColumn(1);
364 // m_mapper->setFirst(0);
372 // m_mapper->setFirst(0);
365 // m_mapper->setCount(-1);
373 // m_mapper->setCount(-1);
366
374
367 m_chart->addSeries(m_series);
375 m_chart->addSeries(m_series);
368 seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
376 seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
369 m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000));
377 m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000));
370
378
371 // // series 2
379 // // series 2
372 // m_series = new QScatterSeries;
380 // m_series = new QScatterSeries;
373 // m_series->setModel(m_model);
381 // m_series->setModel(m_model);
374 // m_series->setModelMapping(2,3, Qt::Vertical);
382 // m_series->setModelMapping(2,3, Qt::Vertical);
375 // // m_series->setModelMappingRange(1, 6);
383 // // m_series->setModelMappingRange(1, 6);
376 // // series->setModelMapping(2,3, Qt::Horizontal);
384 // // series->setModelMapping(2,3, Qt::Horizontal);
377 // m_chart->addSeries(m_series);
385 // m_chart->addSeries(m_series);
378
386
379 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
387 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
380 // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6));
388 // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6));
381
389
382 // // series 3
390 // // series 3
383 // m_series = new QScatterSeries;
391 // m_series = new QScatterSeries;
384 // m_series->setModel(m_model);
392 // m_series->setModel(m_model);
385 // m_series->setModelMapping(4,5, Qt::Vertical);
393 // m_series->setModelMapping(4,5, Qt::Vertical);
386 // // series->setModelMapping(4,5, Qt::Horizontal);
394 // // series->setModelMapping(4,5, Qt::Horizontal);
387 // m_chart->addSeries(m_series);
395 // m_chart->addSeries(m_series);
388 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
396 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
389 // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000));
397 // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000));
390 } else if (m_pieRadioButton->isChecked()) {
398 } else if (m_pieRadioButton->isChecked()) {
391 m_chart->setAnimationOptions(QChart::SeriesAnimations);
399 m_chart->setAnimationOptions(QChart::SeriesAnimations);
392
400
393 // pie 1
401 // pie 1
394 m_pieSeries = new QPieSeries;
402 m_pieSeries = new QPieSeries;
395
403
396 m_pieMapper = new QVPieModelMapper;
404 m_pieMapper = new QVPieModelMapper;
397 m_pieMapper->setValuesColumn(1);
405 m_pieMapper->setValuesColumn(1);
398 m_pieMapper->setLabelsColumn(7);
406 m_pieMapper->setLabelsColumn(7);
399 m_pieMapper->setSeries(m_pieSeries);
407 m_pieMapper->setSeries(m_pieSeries);
400 m_pieMapper->setModel(m_model);
408 m_pieMapper->setModel(m_model);
401 m_pieMapper->setFirst(2);
409 m_pieMapper->setFirst(2);
402 // m_pieMapper->setCount(5);
410 // m_pieMapper->setCount(5);
403 // pieSeries->setModelMapper(mapper);
411 // pieSeries->setModelMapper(mapper);
404
412
405 m_pieSeries->setLabelsVisible(true);
413 m_pieSeries->setLabelsVisible(true);
406 m_pieSeries->setPieSize(0.35);
414 m_pieSeries->setPieSize(0.35);
407 m_pieSeries->setHorizontalPosition(0.25);
415 m_pieSeries->setHorizontalPosition(0.25);
408 m_pieSeries->setVerticalPosition(0.35);
416 m_pieSeries->setVerticalPosition(0.35);
409
417
410 m_chart->addSeries(m_pieSeries);
418 m_chart->addSeries(m_pieSeries);
411 seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
419 seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
412 m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50));
420 m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50));
413
421
414
422
415 // pieSeries->slices().at(0)->setValue(400);
423 // pieSeries->slices().at(0)->setValue(400);
416 // pieSeries->slices().at(0)->setLabel(QString("36"));
424 // pieSeries->slices().at(0)->setLabel(QString("36"));
417
425
418 // pie 2
426 // pie 2
419 m_pieSeries2 = new QPieSeries;
427 m_pieSeries2 = new QPieSeries;
420
428
421 m_pieMapper2 = new QVPieModelMapper;
429 m_pieMapper2 = new QVPieModelMapper;
422 m_pieMapper2->setValuesColumn(0);
430 m_pieMapper2->setValuesColumn(0);
423 m_pieMapper2->setLabelsColumn(7);
431 m_pieMapper2->setLabelsColumn(7);
424 m_pieMapper2->setModel(m_model);
432 m_pieMapper2->setModel(m_model);
425 m_pieMapper2->setSeries(m_pieSeries2);
433 m_pieMapper2->setSeries(m_pieSeries2);
426 m_pieMapper2->setFirst(2);
434 m_pieMapper2->setFirst(2);
427
435
428 m_pieSeries2->setLabelsVisible(true);
436 m_pieSeries2->setLabelsVisible(true);
429 m_pieSeries2->setPieSize(0.35);
437 m_pieSeries2->setPieSize(0.35);
430 m_pieSeries2->setHorizontalPosition(0.75);
438 m_pieSeries2->setHorizontalPosition(0.75);
431 m_pieSeries2->setVerticalPosition(0.65);
439 m_pieSeries2->setVerticalPosition(0.65);
432 m_chart->addSeries(m_pieSeries2);
440 m_chart->addSeries(m_pieSeries2);
433 seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
441 seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
434 m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000));
442 m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000));
435
443
436 // // pie 3
444 // // pie 3
437 // pieSeries = new QPieSeries;
445 // pieSeries = new QPieSeries;
438 // pieSeries->setModel(m_model);
446 // pieSeries->setModel(m_model);
439 // pieSeries->setModelMapping(2,2, Qt::Vertical);
447 // pieSeries->setModelMapping(2,2, Qt::Vertical);
440 // pieSeries->setLabelsVisible(true);
448 // pieSeries->setLabelsVisible(true);
441 // pieSeries->setPieSize(0.35);
449 // pieSeries->setPieSize(0.35);
442 // pieSeries->setHorizontalPosition(0.5);
450 // pieSeries->setHorizontalPosition(0.5);
443 // pieSeries->setVerticalPosition(0.75);
451 // pieSeries->setVerticalPosition(0.75);
444 // m_chart->addSeries(pieSeries);
452 // m_chart->addSeries(pieSeries);
445 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
453 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
446 // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
454 // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
447
455
448 // // special pie
456 // // special pie
449 // specialPie = new QPieSeries;
457 // specialPie = new QPieSeries;
450 // specialPie->append(17, "1");
458 // specialPie->append(17, "1");
451 // specialPie->append(45, "2");
459 // specialPie->append(45, "2");
452 // specialPie->append(77, "3");
460 // specialPie->append(77, "3");
453 // specialPie->append(37, "4");
461 // specialPie->append(37, "4");
454 // specialPie->append(27, "5");
462 // specialPie->append(27, "5");
455 // specialPie->append(47, "6");
463 // specialPie->append(47, "6");
456 // specialPie->setPieSize(0.35);
464 // specialPie->setPieSize(0.35);
457 // specialPie->setHorizontalPosition(0.8);
465 // specialPie->setHorizontalPosition(0.8);
458 // specialPie->setVerticalPosition(0.75);
466 // specialPie->setVerticalPosition(0.75);
459 // specialPie->setLabelsVisible(true);
467 // specialPie->setLabelsVisible(true);
460 // m_chart->addSeries(specialPie);
468 // m_chart->addSeries(specialPie);
461 }
469 }
462 // else if (m_areaRadioButton->isChecked())
470 // else if (m_areaRadioButton->isChecked())
463 // {
471 // {
464 // m_chart->setAnimationOptions(QChart::NoAnimation);
472 // m_chart->setAnimationOptions(QChart::NoAnimation);
465
473
466 // QLineSeries* upperLineSeries = new QLineSeries;
474 // QLineSeries* upperLineSeries = new QLineSeries;
467 // upperLineSeries->setModel(m_model);
475 // upperLineSeries->setModel(m_model);
468 // upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
476 // upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
469 // // upperLineSeries->setModelMappingRange(1, 5);
477 // // upperLineSeries->setModelMappingRange(1, 5);
470 // QLineSeries* lowerLineSeries = new QLineSeries;
478 // QLineSeries* lowerLineSeries = new QLineSeries;
471 // lowerLineSeries->setModel(m_model);
479 // lowerLineSeries->setModel(m_model);
472 // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
480 // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
473 // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
481 // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
474 // m_chart->addSeries(areaSeries);
482 // m_chart->addSeries(areaSeries);
475 // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper();
483 // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper();
476 // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5));
484 // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5));
477 // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
485 // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
478 // }
486 // }
479 else if (m_barRadioButton->isChecked())
487 else if (m_barRadioButton->isChecked())
480 {
488 {
481 // m_chart->setAnimationOptions(QChart::SeriesAnimations);
489 // m_chart->setAnimationOptions(QChart::SeriesAnimations);
482 m_chart->setAnimationOptions(QChart::NoAnimation);
490 m_chart->setAnimationOptions(QChart::NoAnimation);
483
491
484 m_barSeries = new QGroupedBarSeries();
492 m_barSeries = new QGroupedBarSeries();
485
493
494 // QAxisCategories* xCategories = m_chart->axisX()->categories();
495 // xCategories->insert(0, "Jeden");
496 // xCategories->insert(1, "Dwa");
497 // xCategories->insert(2, "Trzy");
498 // xCategories->insert(3, "Cztery");
499 // xCategories->insert(4, "Piec");
500 // xCategories->insert(5, "szesc");
501
502 QStringList categories;
503 categories << "June" << "July" << "August" << "September" << "October" << "November";
504
505 m_chart->axisX()->categories()->insert(categories);
506
486 int first = 3;
507 int first = 3;
487 int count = 6;
508 int count = 6;
488 m_barMapper = new QVBarModelMapper;
509 m_barMapper = new QVBarModelMapper;
489 m_barMapper->setFirstBarSetColumn(2);
510 m_barMapper->setFirstBarSetColumn(2);
490 m_barMapper->setLastBarSetColumn(4);
511 m_barMapper->setLastBarSetColumn(4);
491 m_barMapper->setFirst(first);
512 m_barMapper->setFirst(first);
492 m_barMapper->setCount(count);
513 m_barMapper->setCount(count);
493 m_barMapper->setSeries(m_barSeries);
514 m_barMapper->setSeries(m_barSeries);
494 m_barMapper->setModel(m_model);
515 m_barMapper->setModel(m_model);
495 // barSeries->setModelMapper(mapper);
516 // barSeries->setModelMapper(mapper);
496 m_chart->addSeries(m_barSeries);
517 m_chart->addSeries(m_barSeries);
497
518
498 QStringList categories;
519 // QStringList categories;
499 categories << "June" << "July" << "August" << "September" << "October" << "November";
520 // categories << "June" << "July" << "August" << "September" << "October" << "November";
500
521
501 m_chart->axisX()->categories()->insert(categories);
522 // m_chart->axisX()->categories()->insert(categories);
502
523
503 QList<QBarSet*> barsets = m_barSeries->barSets();
524 QList<QBarSet*> barsets = m_barSeries->barSets();
504 for (int i = 0; i < barsets.count(); i++) {
525 for (int i = 0; i < barsets.count(); i++) {
505 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
526 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
506 m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count()));
527 m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count()));
507 }
528 }
508
529
509
530
510 }
531 }
511
532
512
533
513 if (!m_barRadioButton->isChecked()) {
534 if (!m_barRadioButton->isChecked()) {
514 // m_chart->axisX()->setRange(0, 500);
535 // m_chart->axisX()->setRange(0, 500);
515 // m_chart->axisY()->setRange(0, 220);
536 // m_chart->axisY()->setRange(0, 220);
516 }
537 }
517 m_chart->legend()->setVisible(true);
538 m_chart->legend()->setVisible(true);
518
539
519 // repaint table view colors
540 // repaint table view colors
520 m_tableView->repaint();
541 m_tableView->repaint();
521 m_tableView->setFocus();
542 m_tableView->setFocus();
522 }
543 }
523 }
544 }
524
545
525 void TableWidget::testPie()
546 void TableWidget::testPie()
526 {
547 {
527 // m_pieMapper->setCount(-1);
548 // m_pieMapper->setCount(-1);
528 QPieSlice *slice = new QPieSlice("Hehe", 145);
549 QPieSlice *slice = new QPieSlice("Hehe", 145);
529 slice->setLabelVisible();
550 slice->setLabelVisible();
530 m_pieSeries->append(slice);
551 m_pieSeries->append(slice);
531
552
532 slice = new QPieSlice("Hoho", 34);
553 slice = new QPieSlice("Hoho", 34);
533 slice->setLabelVisible();
554 slice->setLabelVisible();
534 m_pieSeries->append(slice);
555 m_pieSeries->append(slice);
535 // m_series->modelMapper()->setMapX(4);
556 // m_series->modelMapper()->setMapX(4);
536 // m_tableView->setColumnWidth(10, 250);
557 // m_tableView->setColumnWidth(10, 250);
537 // if (specialPie) {
558 // if (specialPie) {
538 // specialPie->remove(specialPie->slices().at(2));
559 // specialPie->remove(specialPie->slices().at(2));
539 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
560 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
540 // specialPie->append(4, "heloo");
561 // specialPie->append(4, "heloo");
541 // }
562 // }
542 }
563 }
543
564
544 void TableWidget::testPie2()
565 void TableWidget::testPie2()
545 {
566 {
546 QPieSlice *slice;
567 QPieSlice *slice;
547 if (m_pieSeries->count() > 0) {
568 if (m_pieSeries->count() > 0) {
548 slice = m_pieSeries->slices().last();
569 slice = m_pieSeries->slices().last();
549 m_pieSeries->remove(slice);
570 m_pieSeries->remove(slice);
550 }
571 }
551
572
552 if (m_pieSeries->count() > 0) {
573 if (m_pieSeries->count() > 0) {
553 slice = m_pieSeries->slices().first();
574 slice = m_pieSeries->slices().first();
554 m_pieSeries->remove(slice);
575 m_pieSeries->remove(slice);
555 }
576 }
556 }
577 }
557
578
558 void TableWidget::testPie3()
579 void TableWidget::testPie3()
559 {
580 {
560 QPieSlice *slice;
581 QPieSlice *slice;
561 if (m_pieSeries->count() > 0) {
582 if (m_pieSeries->count() > 0) {
562 slice = m_pieSeries->slices().last();
583 slice = m_pieSeries->slices().last();
563 slice->setLabel("Dalej");
584 slice->setLabel("Dalej");
564 slice->setValue(222);
585 slice->setValue(222);
565 }
586 }
566
587
567 if (m_pieSeries->count() > 0) {
588 if (m_pieSeries->count() > 0) {
568 slice = m_pieSeries->slices().first();
589 slice = m_pieSeries->slices().first();
569 slice->setLabel("Prawie");
590 slice->setLabel("Prawie");
570 slice->setValue(111);
591 slice->setValue(111);
571 }
592 }
572 }
593 }
573
594
574 void TableWidget::testXY()
595 void TableWidget::testXY()
575 {
596 {
576 if (m_barMapper)
597 if (m_barMapper)
577 m_barMapper->setLastBarSetColumn(m_barMapper->lastBarSetColumn() + 1);
598 m_barMapper->setLastBarSetColumn(m_barMapper->lastBarSetColumn() + 1);
578 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
599 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
579 // m_series->append(QPointF(150, 75));
600 // m_series->append(QPointF(150, 75));
580 // }
601 // }
581
602
582 // if (m_series->count() > 0) {
603 // if (m_series->count() > 0) {
583 // m_series->remove(m_series->points().last());
604 // m_series->remove(m_series->points().last());
584 // }
605 // }
585 }
606 }
586
607
587 TableWidget::~TableWidget()
608 TableWidget::~TableWidget()
588 {
609 {
589
610
590 }
611 }
General Comments 0
You need to be logged in to leave comments. Login now