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