##// END OF EJS Templates
XYSeries model with limits working.
Marek Rosa -
r833:16b8c9450c47
parent child
Show More
@@ -1,29 +1,29
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 SUBDIRS += \
2 SUBDIRS += \
3 areachart \
3 areachart \
4 barchart \
4 barchart \
5 #chartview \
5 #chartview \
6 customchart \
6 customchart \
7 #dynamiclinechart \
7 #dynamiclinechart \
8 #ekgchart \
8 #ekgchart \
9 linechart \
9 linechart \
10 #multichart \
10 #multichart \
11 percentbarchart \
11 percentbarchart \
12 piechart \
12 piechart \
13 piechartdrilldown \
13 piechartdrilldown \
14 #presenterchart \
14 #presenterchart \
15 scatterchart \
15 scatterchart \
16 scatterinteractions \
16 scatterinteractions \
17 splinechart \
17 splinechart \
18 stackedbarchart \
18 stackedbarchart \
19 stackedbarchartdrilldown \
19 stackedbarchartdrilldown \
20 #tablemodelchart \
20 tablemodelchart \
21 zoomlinechart
21 zoomlinechart
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
@@ -1,255 +1,258
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
24
25 CustomTableModel::CustomTableModel(QObject *parent) :
25 CustomTableModel::CustomTableModel(QObject *parent) :
26 QAbstractTableModel(parent)
26 QAbstractTableModel(parent)
27 {
27 {
28 // m_points.append(QPointF(10, 50));
28 // m_points.append(QPointF(10, 50));
29 // m_labels.append("Apples");
29 // m_labels.append("Apples");
30 // m_points.append(QPointF(60, 70));
30 // m_points.append(QPointF(60, 70));
31 // m_labels.append("Oranges");
31 // m_labels.append("Oranges");
32 // m_points.append(QPointF(110, 50));
32 // m_points.append(QPointF(110, 50));
33 // m_labels.append("Bananas");
33 // m_labels.append("Bananas");
34 // m_points.append(QPointF(140, 40));
34 // m_points.append(QPointF(140, 40));
35 // m_labels.append("Lemons");
35 // m_labels.append("Lemons");
36 // m_points.append(QPointF(200, 150));
36 // m_points.append(QPointF(200, 150));
37 // m_labels.append("Plums");
37 // m_labels.append("Plums");
38 // m_points.append(QPointF(225, 75));
38 // m_points.append(QPointF(225, 75));
39 // m_labels.append("Pearls");
39 // m_labels.append("Pearls");
40
40
41 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
41 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
42
42
43 // m_data
43 // m_data
44 for (int i = 0; i < 6; i++)
44 for (int i = 0; i < 6; i++)
45 {
45 {
46 QVector<qreal>* dataVec = new QVector<qreal>(6);
46 QVector<qreal>* dataVec = new QVector<qreal>(6);
47 QVector<QColor>* colorVec = new QVector<QColor>(6);
47 QVector<QColor>* colorVec = new QVector<QColor>(6);
48 for (int k = 0; k < dataVec->size(); k++)
48 for (int k = 0; k < dataVec->size(); k++)
49 {
49 {
50 if (k%2 == 0)
50 if (k%2 == 0)
51 dataVec->replace(k, i * 50 + qrand()%20);
51 dataVec->replace(k, i * 50 + qrand()%20);
52 else
52 else
53 dataVec->replace(k, qrand()%100);
53 dataVec->replace(k, qrand()%100);
54 colorVec->replace(k, QColor(Qt::white));
54 colorVec->replace(k, QColor(Qt::white));
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 m_rowsColors.append(colorVec);
58 m_rowsColors.append(colorVec);
59 }
59 }
60 }
60 }
61
61
62 int CustomTableModel::rowCount(const QModelIndex & parent) const
62 int CustomTableModel::rowCount(const QModelIndex & parent) const
63 {
63 {
64 Q_UNUSED(parent)
64 Q_UNUSED(parent)
65 // return m_points.count();
65 // return m_points.count();
66 return m_data.count();
66 return m_data.count();
67 }
67 }
68
68
69 int CustomTableModel::columnCount(const QModelIndex & parent) const
69 int CustomTableModel::columnCount(const QModelIndex & parent) const
70 {
70 {
71 Q_UNUSED(parent)
71 Q_UNUSED(parent)
72 // return 3;
72 // return 3;
73 return 6;
73 return 6;
74 }
74 }
75
75
76 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const
76 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const
77 {
77 {
78 if (role != Qt::DisplayRole)
78 if (role != Qt::DisplayRole)
79 return QVariant();
79 return QVariant();
80
80
81 if (orientation == Qt::Horizontal)
81 if (orientation == Qt::Horizontal)
82 {
82 {
83 switch(section)
83 switch(section)
84 {
84 {
85 // case 0:
85 // case 0:
86 // return "x";
86 // return "x";
87 // case 1:
87 // case 1:
88 // return "y";
88 // return "y";
89 // case 2:
89 // case 2:
90 case 6:
90 case 6:
91 return "Fruit";
91 return "Fruit";
92 default:
92 default:
93 if (section%2 == 0)
93 if (section%2 == 0)
94 return "x";
94 return "x";
95 else
95 else
96 return "y";
96 return "y";
97 // return "What?";
97 // return "What?";
98 }
98 }
99 }
99 }
100 else
100 else
101 return QString("%1").arg(section + 1);
101 return QString("%1").arg(section /*+ 1*/);
102 }
102 }
103
103
104 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
104 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
105 {
105 {
106 if (role == Qt::DisplayRole)
106 if (role == Qt::DisplayRole)
107 {
107 {
108 switch(index.column())
108 switch(index.column())
109 {
109 {
110 // case 0:
110 // case 0:
111 // return m_points[index.row()].x();
111 // return m_points[index.row()].x();
112 // case 1:
112 // case 1:
113 // return m_points[index.row()].y();
113 // return m_points[index.row()].y();
114 // case 2:
114 // case 2:
115 case 6:
115 case 6:
116 return m_labels[index.row()];
116 return m_labels[index.row()];
117 default:
117 default:
118 return m_data[index.row()]->at(index.column());
118 return m_data[index.row()]->at(index.column());
119 break;
119 break;
120 }
120 }
121 }
121 }
122 else if (role == Qt::EditRole)
122 else if (role == Qt::EditRole)
123 {
123 {
124 switch(index.column())
124 switch(index.column())
125 {
125 {
126 // case 0:
126 // case 0:
127 // return m_points[index.row()].x();
127 // return m_points[index.row()].x();
128 // case 1:
128 // case 1:
129 // return m_points[index.row()].y();
129 // return m_points[index.row()].y();
130 // case 2:
130 // case 2:
131 case 6:
131 case 6:
132 return m_labels[index.row()];
132 return m_labels[index.row()];
133 default:
133 default:
134 return m_data[index.row()]->at(index.column());
134 return m_data[index.row()]->at(index.column());
135 break;
135 break;
136 }
136 }
137 }
137 }
138 else if (role == Qt::BackgroundRole)
138 else if (role == Qt::BackgroundRole)
139 {
139 {
140 return m_rowsColors[index.row()]->at(index.column());
140 return m_rowsColors[index.row()]->at(index.column());
141 }
141 }
142 return QVariant();
142 return QVariant();
143 }
143 }
144
144
145 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & value, int role)
145 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & value, int role)
146 {
146 {
147 if (index.isValid() && role == Qt::EditRole)
147 if (index.isValid() && role == Qt::EditRole)
148 {
148 {
149 switch(index.column())
149 switch(index.column())
150 {
150 {
151 // case 0:
151 // case 0:
152 // m_points[index.row()].setX(value.toDouble());
152 // m_points[index.row()].setX(value.toDouble());
153 // break;
153 // break;
154 // case 1:
154 // case 1:
155 // m_points[index.row()].setY(value.toDouble());
155 // m_points[index.row()].setY(value.toDouble());
156 // break;
156 // break;
157 // case 2:
157 // case 2:
158 case 6:
158 case 6:
159 m_labels.replace(index.row(), value.toString());
159 m_labels.replace(index.row(), value.toString());
160 break;
160 break;
161 default:
161 default:
162 m_data[index.row()]->replace(index.column(), value.toDouble());
162 m_data[index.row()]->replace(index.column(), value.toDouble());
163 break;
163 break;
164 // return false;
164 // return false;
165 }
165 }
166 emit dataChanged(index, index);
166 emit dataChanged(index, index);
167 return true;
167 return true;
168 }
168 }
169 else if (role == Qt::BackgroundRole)
169 else if (role == Qt::BackgroundRole)
170 {
170 {
171 m_rowsColors[index.row()]->replace(index.column(), value.value<QColor>());
171 m_rowsColors[index.row()]->replace(index.column(), value.value<QColor>());
172 return true;
172 return true;
173 }
173 }
174 return false;
174 return false;
175 }
175 }
176
176
177 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const
177 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const
178 {
178 {
179 // if (!index.isValid())
179 // if (!index.isValid())
180 // return Qt::ItemIsEnabled;
180 // return Qt::ItemIsEnabled;
181 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
181 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
182 }
182 }
183
183
184 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent)
184 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent)
185 {
185 {
186 Q_UNUSED(parent)
186 Q_UNUSED(parent)
187
187
188 if (row < 0)
188 if (row < 0)
189 row = 0;
189 row = 0;
190 beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1);
190 beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1);
191 for (int i = row; i < row + count; i++)
191 for (int i = row; i < row + count; i++)
192 {
192 {
193 // m_points.insert(row, QPointF(10,20));
193 // m_points.insert(row, QPointF(10,20));
194 QVector<qreal>* dataVec = new QVector<qreal>(6);
194 QVector<qreal>* dataVec = new QVector<qreal>(6);
195 QVector<QColor>* colorVec = new QVector<QColor>(6);
195 QVector<QColor>* colorVec = new QVector<QColor>(6);
196 for (int k = 0; k < dataVec->size(); k++)
196 for (int k = 0; k < dataVec->size(); k++)
197 {
197 {
198 if (k%2 == 0)
198 if (k%2 == 0)
199 // dataVec->replace(k, i * 50 + qrand()%20);
199 // dataVec->replace(k, i * 50 + qrand()%20);
200 {
200 {
201 int difference = 0;
201 int difference = 0;
202 if (i < m_data.size())
202 if (i < m_data.size())
203 {
203 {
204 if (i - 1 >= 0)
204 if (i - 1 >= 0)
205 {
205 {
206 difference = (int)((qAbs(m_data[i]->at(k) - m_data[row - 1]->at(k)))/count);
206 if (row > 0)
207 difference = (int)((qAbs(m_data[i]->at(k) - m_data[row - 1]->at(k)))/count);
208 else
209 difference = (int)((qAbs(m_data[i]->at(k)/count)));
207 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%qMax(1, difference));
210 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%qMax(1, difference));
208 }
211 }
209 else
212 else
210 dataVec->replace(k, qrand()%40 + 10);
213 dataVec->replace(k, qrand()%40 + 10);
211 }
214 }
212 else
215 else
213 {
216 {
214 if (i - 1 >= 0)
217 if (i - 1 >= 0)
215 {
218 {
216 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%40 + 10);
219 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%40 + 10);
217 }
220 }
218 else
221 else
219 {
222 {
220 dataVec->replace(k, qrand()%40 + 10);
223 dataVec->replace(k, qrand()%40 + 10);
221 }
224 }
222 }
225 }
223 }
226 }
224 else
227 else
225 dataVec->replace(k, qrand()%100);
228 dataVec->replace(k, qrand()%100);
226 colorVec->replace(k, QColor(Qt::white));
229 colorVec->replace(k, QColor(Qt::white));
227 }
230 }
228 m_data.insert(i, dataVec);
231 m_data.insert(i, dataVec);
229 m_labels.insert(i,(QString("Row: %1").arg(i + 1)));
232 m_labels.insert(i,(QString("Row: %1").arg(i + 1)));
230 m_rowsColors.insert(i, colorVec);
233 m_rowsColors.insert(i, colorVec);
231 }
234 }
232 endInsertRows();
235 endInsertRows();
233 return true;
236 return true;
234 }
237 }
235
238
236 bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & parent)
239 bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & parent)
237 {
240 {
238 if (row > this->rowCount() - 1)
241 if (row > this->rowCount() - 1)
239 return false;
242 return false;
240 if (row < 0)
243 if (row < 0)
241 row = 0;
244 row = 0;
242 if (row + count > rowCount())
245 if (row + count > rowCount())
243 return false;
246 return false;
244 beginRemoveRows(parent, row, row + count - 1);
247 beginRemoveRows(parent, row, row + count - 1);
245 for (int i = row; i < row + count; i++)
248 for (int i = row; i < row + count; i++)
246 {
249 {
247 // m_points.removeAt(row);
250 // m_points.removeAt(row);
248 QVector<qreal>* item = m_data.at(row);
251 QVector<qreal>* item = m_data.at(row);
249 m_data.removeAt(row);
252 m_data.removeAt(row);
250 delete item;
253 delete item;
251 m_labels.removeAt(row);
254 m_labels.removeAt(row);
252 }
255 }
253 endRemoveRows();
256 endRemoveRows();
254 return true;
257 return true;
255 }
258 }
@@ -1,307 +1,309
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 <QStyledItemDelegate>
24 #include <QStyledItemDelegate>
25 #include "qlineseries.h"
25 #include "qlineseries.h"
26 #include "qsplineseries.h"
26 #include "qsplineseries.h"
27 #include "qscatterseries.h"
27 #include "qscatterseries.h"
28 #include "customtablemodel.h"
28 #include "customtablemodel.h"
29 #include "qpieseries.h"
29 #include "qpieseries.h"
30 #include "qareaseries.h"
30 #include "qareaseries.h"
31 #include "qbarseries.h"
31 #include "qbarseries.h"
32 #include <QPushButton>
32 #include <QPushButton>
33 #include <QRadioButton>
33 #include <QRadioButton>
34 #include <QSpinBox>
34 #include <QSpinBox>
35 #include <QTime>
35 #include <QTime>
36
36
37 TableWidget::TableWidget(QWidget *parent)
37 TableWidget::TableWidget(QWidget *parent)
38 : QWidget(parent)
38 : QWidget(parent)
39 {
39 {
40 setGeometry(100, 100, 1000, 600);
40 setGeometry(100, 100, 1000, 600);
41 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
41 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
42 // create simple model for storing data
42 // create simple model for storing data
43 // user's table data model
43 // user's table data model
44 m_model = new CustomTableModel;
44 m_model = new CustomTableModel;
45 tableView = new QTableView;
45 m_tableView = new QTableView;
46 tableView->setModel(m_model);
46 m_tableView->setModel(m_model);
47 tableView->setMinimumHeight(240);
47 m_tableView->setMinimumHeight(240);
48 // tableView->setMinimumSize(340, 480);
48 // tableView->setMinimumSize(340, 480);
49 // tableView->setItemDelegate(new QStyledItemDelegate);
49 // tableView->setItemDelegate(new QStyledItemDelegate);
50 chartView = new QChartView(this);
50 m_chart = new QChart;
51 chartView->setRenderHint(QPainter::Antialiasing);
51 m_chartView = new QChartView(m_chart);
52 chartView->setMinimumSize(640, 480);
52 m_chartView->setRenderHint(QPainter::Antialiasing);
53 m_chartView->setMinimumSize(640, 480);
53
54
54 // create
55 // create
55 // QLineSeries* series = new QLineSeries;
56 // QLineSeries* series = new QLineSeries;
56 // QSplineSeries* series = new QSplineSeries;
57 // QSplineSeries* series = new QSplineSeries;
57 // QScatterSeries* series = new QScatterSeries;
58 // QScatterSeries* series = new QScatterSeries;
58 // series->setModel(m_model);
59 // series->setModel(m_model);
59 // series->setModelMapping(0,1, Qt::Vertical);
60 // series->setModelMapping(0,1, Qt::Vertical);
60
61
61 // QPieSeries* pieSeries = new QPieSeries;
62 // QPieSeries* pieSeries = new QPieSeries;
62 // pieSeries->setModel(model);
63 // pieSeries->setModel(model);
63 // pieSeries
64 // pieSeries
64
65
65 // chartView->addSeries(series);
66 // chartView->addSeries(series);
66
67
67 // add, remove data buttons
68 // add, remove data buttons
68 QPushButton* addRowAboveButton = new QPushButton("Add row above");
69 QPushButton* addRowAboveButton = new QPushButton("Add row above");
69 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
70 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
70
71
71 QPushButton* addRowBelowButton = new QPushButton("Add row below");
72 QPushButton* addRowBelowButton = new QPushButton("Add row below");
72 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
73 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
73
74
74 QPushButton* removeRowButton = new QPushButton("Remove row");
75 QPushButton* removeRowButton = new QPushButton("Remove row");
75 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
76 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
76
77
77 linesCountSpinBox = new QSpinBox;
78 m_linesCountSpinBox = new QSpinBox;
78 linesCountSpinBox->setRange(1, 10);
79 m_linesCountSpinBox->setRange(1, 10);
79 linesCountSpinBox->setValue(1);
80 m_linesCountSpinBox->setValue(1);
80
81
81 // buttons layout
82 // buttons layout
82 QVBoxLayout* buttonsLayout = new QVBoxLayout;
83 QVBoxLayout* buttonsLayout = new QVBoxLayout;
83 buttonsLayout->addWidget(linesCountSpinBox);
84 buttonsLayout->addWidget(m_linesCountSpinBox);
84 buttonsLayout->addWidget(addRowAboveButton);
85 buttonsLayout->addWidget(addRowAboveButton);
85 buttonsLayout->addWidget(addRowBelowButton);
86 buttonsLayout->addWidget(addRowBelowButton);
86 buttonsLayout->addWidget(removeRowButton);
87 buttonsLayout->addWidget(removeRowButton);
87 buttonsLayout->addStretch();
88 buttonsLayout->addStretch();
88
89
89 // chart type radio buttons
90 // chart type radio buttons
90 lineRadioButton = new QRadioButton("Line");
91 m_lineRadioButton = new QRadioButton("Line");
91 splineRadioButton = new QRadioButton("Spline");
92 m_splineRadioButton = new QRadioButton("Spline");
92 scatterRadioButton = new QRadioButton("Scatter");
93 m_scatterRadioButton = new QRadioButton("Scatter");
93 pieRadioButton = new QRadioButton("Pie");
94 m_pieRadioButton = new QRadioButton("Pie");
94 areaRadioButton = new QRadioButton("Area");
95 m_areaRadioButton = new QRadioButton("Area");
95 barRadioButton = new QRadioButton("Bar");
96 m_barRadioButton = new QRadioButton("Bar");
96
97
97 connect(lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
98 connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
98 connect(splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
99 connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
99 connect(scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
100 connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
100 connect(pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
101 connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
101 connect(areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
102 connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
102 connect(barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
103 connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
103 lineRadioButton->setChecked(true);
104 m_lineRadioButton->setChecked(true);
104
105
105 // radio buttons layout
106 // radio buttons layout
106 QVBoxLayout* radioLayout = new QVBoxLayout;
107 QVBoxLayout* radioLayout = new QVBoxLayout;
107 radioLayout->addWidget(lineRadioButton);
108 radioLayout->addWidget(m_lineRadioButton);
108 radioLayout->addWidget(splineRadioButton);
109 radioLayout->addWidget(m_splineRadioButton);
109 radioLayout->addWidget(scatterRadioButton);
110 radioLayout->addWidget(m_scatterRadioButton);
110 radioLayout->addWidget(pieRadioButton);
111 radioLayout->addWidget(m_pieRadioButton);
111 radioLayout->addWidget(areaRadioButton);
112 radioLayout->addWidget(m_areaRadioButton);
112 radioLayout->addWidget(barRadioButton);
113 radioLayout->addWidget(m_barRadioButton);
113 radioLayout->addStretch();
114 radioLayout->addStretch();
114
115
115 // create main layout
116 // create main layout
116 QGridLayout* mainLayout = new QGridLayout;
117 QGridLayout* mainLayout = new QGridLayout;
117 mainLayout->addLayout(buttonsLayout, 1, 0);
118 mainLayout->addLayout(buttonsLayout, 1, 1);
118 mainLayout->addLayout(radioLayout, 2, 0);
119 mainLayout->addLayout(radioLayout, 2, 1);
119 mainLayout->addWidget(tableView, 1, 1);
120 mainLayout->addWidget(m_tableView, 1, 0);
120 mainLayout->addWidget(chartView, 2, 1);
121 mainLayout->addWidget(m_chartView, 2, 0);
121 setLayout(mainLayout);
122 setLayout(mainLayout);
122 lineRadioButton->setFocus();
123 m_lineRadioButton->setFocus();
123 }
124 }
124
125
125 void TableWidget::addRowAbove()
126 void TableWidget::addRowAbove()
126 {
127 {
127 // m_model->insertRow(m_model->rowCount());
128 // m_model->insertRow(m_model->rowCount());
128 // m_model->insertRow(tableView->currentIndex().row());
129 // m_model->insertRow(tableView->currentIndex().row());
129 m_model->insertRows(tableView->currentIndex().row(), linesCountSpinBox->value());
130 m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value());
130
131
131 }
132 }
132
133
133 void TableWidget::addRowBelow()
134 void TableWidget::addRowBelow()
134 {
135 {
135 // m_model->insertRow(m_model->rowCount());
136 // m_model->insertRow(m_model->rowCount());
136 // m_model->insertRow(tableView->currentIndex().row() + 1);
137 // m_model->insertRow(tableView->currentIndex().row() + 1);
137 m_model->insertRows(tableView->currentIndex().row() + 1, linesCountSpinBox->value());
138 m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value());
138
139
139 }
140 }
140
141
141 void TableWidget::removeRow()
142 void TableWidget::removeRow()
142 {
143 {
143 // m_model->removeRow(m_model->rowCount() - 1);
144 // m_model->removeRow(m_model->rowCount() - 1);
144 // m_model->removeRow(tableView->currentIndex().row());
145 // m_model->removeRow(tableView->currentIndex().row());
145 m_model->removeRows(tableView->currentIndex().row(), qMin(m_model->rowCount() - tableView->currentIndex().row(), linesCountSpinBox->value()));
146 m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value()));
146 }
147 }
147
148
148 void TableWidget::updateChartType()
149 void TableWidget::updateChartType()
149 {
150 {
150 chartView->removeAllSeries();
151 m_chart->removeAllSeries();
151
152
152 if (lineRadioButton->isChecked())
153 if (m_lineRadioButton->isChecked())
153 {
154 {
154 QPen pen;
155 QPen pen;
155 pen.setWidth(2);
156 pen.setWidth(2);
156
157
157 QColor seriesColor("#8FBC8F");
158 QColor seriesColor("#8FBC8F");
158
159
159 // series 1
160 // series 1
160 series = new QLineSeries;
161 m_series = new QLineSeries;
161 series->setModel(m_model);
162 m_series->setModel(m_model);
162 series->setModelMapping(0,1, Qt::Vertical);
163 m_series->setModelMapping(0,1, Qt::Vertical);
163 series->setModelMappingShift(1, 4);
164 m_series->setModelMappingShift(3, 3);
164 // series->setModelMapping(0,1, Qt::Horizontal);
165 // series->setModelMapping(0,1, Qt::Horizontal);
165
166
166 pen.setColor(seriesColor);
167 pen.setColor(seriesColor);
167 series->setPen(pen);
168 m_series->setPen(pen);
168 chartView->addSeries(series);
169 m_chart->addSeries(m_series);
169 for (int i = 1; i <=4; i++)
170 for (int i = 1; i <=4; i++)
170 {
171 {
171 m_model->setData(m_model->index(i, 0), seriesColor , Qt::BackgroundRole);
172 m_model->setData(m_model->index(i, 0), seriesColor , Qt::BackgroundRole);
172 m_model->setData(m_model->index(i, 1), seriesColor , Qt::BackgroundRole);
173 m_model->setData(m_model->index(i, 1), seriesColor , Qt::BackgroundRole);
173 }
174 }
174 // tableView->setsetStyleSheet("QTableView { border: 2px solid red }");
175 // tableView->setsetStyleSheet("QTableView { border: 2px solid red }");
175
176
176 seriesColor = QColor("#1E90FF");
177 seriesColor = QColor("#1E90FF");
177
178
178 // series 2
179 // series 2
179 series = new QLineSeries;
180 m_series = new QLineSeries;
180 series->setModel(m_model);
181 m_series->setModel(m_model);
181 series->setModelMapping(2,3, Qt::Vertical);
182 m_series->setModelMapping(2,3, Qt::Vertical);
182 // series->setModelMapping(2,3, Qt::Horizontal);
183 // series->setModelMapping(2,3, Qt::Horizontal);
183 pen.setColor(seriesColor);
184 pen.setColor(seriesColor);
184 series->setPen(pen);
185 m_series->setPen(pen);
185 chartView->addSeries(series);
186 // m_chart->addSeries(m_series);
186
187
187 chartView->axisX()->setRange(0, 500);
188 m_chart->axisX()->setRange(0, 500);
189 m_chart->axisY()->setRange(0, 120);
188
190
189 for (int i = 0; i < m_model->rowCount(); i++)
191 for (int i = 0; i < m_model->rowCount(); i++)
190 {
192 {
191 m_model->setData(m_model->index(i, 2), seriesColor , Qt::BackgroundRole);
193 m_model->setData(m_model->index(i, 2), seriesColor , Qt::BackgroundRole);
192 m_model->setData(m_model->index(i, 3), seriesColor , Qt::BackgroundRole);
194 m_model->setData(m_model->index(i, 3), seriesColor , Qt::BackgroundRole);
193 }
195 }
194 // // series 3
196 // // series 3
195 // series = new QLineSeries;
197 // series = new QLineSeries;
196 // series->setModel(m_model);
198 // series->setModel(m_model);
197 // series->setModelMapping(4,5, Qt::Vertical);
199 // series->setModelMapping(4,5, Qt::Vertical);
198 //// series->setModelMapping(4,5, Qt::Horizontal);
200 //// series->setModelMapping(4,5, Qt::Horizontal);
199 // chartView->addSeries(series);
201 // chartView->addSeries(series);
200 }
202 }
201 else if (splineRadioButton->isChecked())
203 else if (m_splineRadioButton->isChecked())
202 {
204 {
203 // series 1
205 // series 1
204 series = new QSplineSeries;
206 m_series = new QSplineSeries;
205 series->setModel(m_model);
207 m_series->setModel(m_model);
206 series->setModelMapping(0,1, Qt::Vertical);
208 m_series->setModelMapping(0,1, Qt::Vertical);
207 series->setModelMappingShift(1, 4);
209 m_series->setModelMappingShift(1, 4);
208 // series->setModelMapping(0,1, Qt::Horizontal);
210 // series->setModelMapping(0,1, Qt::Horizontal);
209 chartView->addSeries(series);
211 m_chart->addSeries(m_series);
210
212
211 // series 2
213 // series 2
212 series = new QSplineSeries;
214 m_series = new QSplineSeries;
213 series->setModel(m_model);
215 m_series->setModel(m_model);
214 series->setModelMapping(2,3, Qt::Vertical);
216 m_series->setModelMapping(2,3, Qt::Vertical);
215 series->setModelMappingShift(0, 0);
217 m_series->setModelMappingShift(0, 0);
216 // series->setModelMapping(2,3, Qt::Horizontal);
218 // series->setModelMapping(2,3, Qt::Horizontal);
217 chartView->addSeries(series);
219 m_chart->addSeries(m_series);
218
220
219 // series 3
221 // series 3
220 series = new QSplineSeries;
222 m_series = new QSplineSeries;
221 series->setModel(m_model);
223 m_series->setModel(m_model);
222 series->setModelMapping(4,5, Qt::Vertical);
224 m_series->setModelMapping(4,5, Qt::Vertical);
223 series->setModelMappingShift(0, 0);
225 m_series->setModelMappingShift(0, 0);
224 // series->setModelMapping(4,5, Qt::Horizontal);
226 // series->setModelMapping(4,5, Qt::Horizontal);
225 chartView->addSeries(series);
227 m_chart->addSeries(m_series);
226 }
228 }
227 else if (scatterRadioButton->isChecked())
229 else if (m_scatterRadioButton->isChecked())
228 {
230 {
229 // series 1
231 // series 1
230 series = new QScatterSeries;
232 m_series = new QScatterSeries;
231 series->setModel(m_model);
233 m_series->setModel(m_model);
232 series->setModelMapping(0,1, Qt::Vertical);
234 m_series->setModelMapping(0,1, Qt::Vertical);
233 // series->setModelMapping(0,1, Qt::Horizontal);
235 // series->setModelMapping(0,1, Qt::Horizontal);
234 chartView->addSeries(series);
236 m_chart->addSeries(m_series);
235
237
236 // series 2
238 // series 2
237 series = new QScatterSeries;
239 m_series = new QScatterSeries;
238 series->setModel(m_model);
240 m_series->setModel(m_model);
239 series->setModelMapping(2,3, Qt::Vertical);
241 m_series->setModelMapping(2,3, Qt::Vertical);
240 // series->setModelMapping(2,3, Qt::Horizontal);
242 // series->setModelMapping(2,3, Qt::Horizontal);
241 chartView->addSeries(series);
243 m_chart->addSeries(m_series);
242
244
243 // series 3
245 // series 3
244 series = new QScatterSeries;
246 m_series = new QScatterSeries;
245 series->setModel(m_model);
247 m_series->setModel(m_model);
246 series->setModelMapping(4,5, Qt::Vertical);
248 m_series->setModelMapping(4,5, Qt::Vertical);
247 // series->setModelMapping(4,5, Qt::Horizontal);
249 // series->setModelMapping(4,5, Qt::Horizontal);
248 chartView->addSeries(series);
250 m_chart->addSeries(m_series);
249 }
251 }
250 else if (pieRadioButton->isChecked())
252 else if (m_pieRadioButton->isChecked())
251 {
253 {
252 // pie 1
254 // pie 1
253 QPieSeries* pieSeries = new QPieSeries;
255 QPieSeries* pieSeries = new QPieSeries;
254 pieSeries->setModel(m_model);
256 pieSeries->setModel(m_model);
255 pieSeries->setModelMapping(0,0, Qt::Vertical);
257 pieSeries->setModelMapping(0,0, Qt::Vertical);
256 pieSeries->setLabelsVisible(true);
258 pieSeries->setLabelsVisible(true);
257 pieSeries->setPieSize(0.4);
259 pieSeries->setPieSize(0.4);
258 pieSeries->setPiePosition(0.2, 0.35);
260 pieSeries->setPiePosition(0.2, 0.35);
259 chartView->addSeries(pieSeries);
261 m_chart->addSeries(pieSeries);
260
262
261 // pie 2
263 // pie 2
262 pieSeries = new QPieSeries;
264 pieSeries = new QPieSeries;
263 pieSeries->setModel(m_model);
265 pieSeries->setModel(m_model);
264 pieSeries->setModelMapping(1,1, Qt::Vertical);
266 pieSeries->setModelMapping(1,1, Qt::Vertical);
265 pieSeries->setLabelsVisible(true);
267 pieSeries->setLabelsVisible(true);
266 pieSeries->setPieSize(0.4);
268 pieSeries->setPieSize(0.4);
267 pieSeries->setPiePosition(0.8, 0.35);
269 pieSeries->setPiePosition(0.8, 0.35);
268 chartView->addSeries(pieSeries);
270 m_chart->addSeries(pieSeries);
269
271
270 // pie 3
272 // pie 3
271 pieSeries = new QPieSeries;
273 pieSeries = new QPieSeries;
272 pieSeries->setModel(m_model);
274 pieSeries->setModel(m_model);
273 pieSeries->setModelMapping(2,2, Qt::Vertical);
275 pieSeries->setModelMapping(2,2, Qt::Vertical);
274 pieSeries->setLabelsVisible(true);
276 pieSeries->setLabelsVisible(true);
275 pieSeries->setPieSize(0.4);
277 pieSeries->setPieSize(0.4);
276 pieSeries->setPiePosition(0.5, 0.65);
278 pieSeries->setPiePosition(0.5, 0.65);
277 chartView->addSeries(pieSeries);
279 m_chart->addSeries(pieSeries);
278 }
280 }
279 else if (areaRadioButton->isChecked())
281 else if (m_areaRadioButton->isChecked())
280 {
282 {
281 QLineSeries* upperLineSeries = new QLineSeries;
283 QLineSeries* upperLineSeries = new QLineSeries;
282 upperLineSeries->setModel(m_model);
284 upperLineSeries->setModel(m_model);
283 upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
285 upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
284 QLineSeries* lowerLineSeries = new QLineSeries;
286 QLineSeries* lowerLineSeries = new QLineSeries;
285 lowerLineSeries->setModel(m_model);
287 lowerLineSeries->setModel(m_model);
286 lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
288 lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
287 QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
289 QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
288 chartView->addSeries(areaSeries);
290 m_chart->addSeries(areaSeries);
289 }
291 }
290 else if (barRadioButton->isChecked())
292 else if (m_barRadioButton->isChecked())
291 {
293 {
292 QBarSeries* barSeries = new QBarSeries(QStringList());
294 QBarSeries* barSeries = new QBarSeries(QStringList());
293 barSeries->setModel(m_model);
295 barSeries->setModel(m_model);
294 barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
296 barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
295 barSeries->setToolTipEnabled(true);
297 barSeries->setToolTipEnabled(true);
296 chartView->addSeries(barSeries);
298 m_chart->addSeries(barSeries);
297 }
299 }
298
300
299 // series->setModel(m_model);
301 // series->setModel(m_model);
300 // series->setModelMapping(0,1, Qt::Vertical);
302 // series->setModelMapping(0,1, Qt::Vertical);
301 // chartView->addSeries(series);
303 // chartView->addSeries(series);
302 }
304 }
303
305
304 TableWidget::~TableWidget()
306 TableWidget::~TableWidget()
305 {
307 {
306
308
307 }
309 }
@@ -1,65 +1,66
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef TABLEWIDGET_H
21 #ifndef TABLEWIDGET_H
22 #define TABLEWIDGET_H
22 #define TABLEWIDGET_H
23
23
24 #include <QtGui/QWidget>
24 #include <QtGui/QWidget>
25 #include "qchartview.h"
25 #include "qchartview.h"
26 #include "qxyseries.h"
26 #include "qxyseries.h"
27
27
28 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
29
29
30 class CustomTableModel;
30 class CustomTableModel;
31 class QTableView;
31 class QTableView;
32 class QRadioButton;
32 class QRadioButton;
33 class QSpinBox;
33 class QSpinBox;
34 //class QSeries;
34 //class QSeries;
35
35
36 class TableWidget : public QWidget
36 class TableWidget : public QWidget
37 {
37 {
38 Q_OBJECT
38 Q_OBJECT
39
39
40 public:
40 public:
41 TableWidget(QWidget *parent = 0);
41 TableWidget(QWidget *parent = 0);
42 ~TableWidget();
42 ~TableWidget();
43
43
44
44
45 public slots:
45 public slots:
46 void addRowAbove();
46 void addRowAbove();
47 void addRowBelow();
47 void addRowBelow();
48 void removeRow();
48 void removeRow();
49 void updateChartType();
49 void updateChartType();
50
50
51 private:
51 private:
52 QChartView* chartView;
52 QChartView* m_chartView;
53 QXYSeries* series;
53 QChart* m_chart;
54 QXYSeries* m_series;
54 CustomTableModel* m_model;
55 CustomTableModel* m_model;
55 QTableView* tableView;
56 QTableView* m_tableView;
56 QRadioButton* lineRadioButton;
57 QRadioButton* m_lineRadioButton;
57 QRadioButton* splineRadioButton;
58 QRadioButton* m_splineRadioButton;
58 QRadioButton* scatterRadioButton;
59 QRadioButton* m_scatterRadioButton;
59 QRadioButton* pieRadioButton;
60 QRadioButton* m_pieRadioButton;
60 QRadioButton* areaRadioButton;
61 QRadioButton* m_areaRadioButton;
61 QRadioButton* barRadioButton;
62 QRadioButton* m_barRadioButton;
62 QSpinBox* linesCountSpinBox;
63 QSpinBox* m_linesCountSpinBox;
63 };
64 };
64
65
65 #endif // TABLEWIDGET_H
66 #endif // TABLEWIDGET_H
@@ -1,510 +1,516
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 "qxyseries.h"
21 #include "qxyseries.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QXYSeries
26 \class QXYSeries
27 \brief The QXYSeries class is a base class for line, spline and scatter series.
27 \brief The QXYSeries class is a base class for line, spline and scatter series.
28 */
28 */
29
29
30 /*!
30 /*!
31 \fn QPen QXYSeries::pen() const
31 \fn QPen QXYSeries::pen() const
32 \brief Returns pen used to draw points for series.
32 \brief Returns pen used to draw points for series.
33 \sa setPen()
33 \sa setPen()
34 */
34 */
35
35
36 /*!
36 /*!
37 \fn QBrush QXYSeries::brush() const
37 \fn QBrush QXYSeries::brush() const
38 \brief Returns brush used to draw points for series.
38 \brief Returns brush used to draw points for series.
39 \sa setBrush()
39 \sa setBrush()
40 */
40 */
41
41
42 /*!
42 /*!
43 \fn void QXYSeries::clicked(const QPointF& point)
43 \fn void QXYSeries::clicked(const QPointF& point)
44 \brief Signal is emitted when user clicks the \a point on chart.
44 \brief Signal is emitted when user clicks the \a point on chart.
45 */
45 */
46
46
47 /*!
47 /*!
48 \fn void QXYSeries::pointReplaced(int index)
48 \fn void QXYSeries::pointReplaced(int index)
49 \brief \internal \a index
49 \brief \internal \a index
50 */
50 */
51
51
52 /*!
52 /*!
53 \fn void QXYSeries::pointAdded(int index)
53 \fn void QXYSeries::pointAdded(int index)
54 \brief \internal \a index
54 \brief \internal \a index
55 */
55 */
56
56
57 /*!
57 /*!
58 \fn void QXYSeries::pointRemoved(int index)
58 \fn void QXYSeries::pointRemoved(int index)
59 \brief \internal \a index
59 \brief \internal \a index
60 */
60 */
61
61
62 /*!
62 /*!
63 \fn void QXYSeries::updated()
63 \fn void QXYSeries::updated()
64 \brief \internal
64 \brief \internal
65 */
65 */
66
66
67 /*!
67 /*!
68 Constructs empty series object which is a child of \a parent.
68 Constructs empty series object which is a child of \a parent.
69 When series object is added to QChartView or QChart instance ownerships is transfered.
69 When series object is added to QChartView or QChart instance ownerships is transfered.
70 */
70 */
71 QXYSeries::QXYSeries(QObject *parent):QSeries(parent)
71 QXYSeries::QXYSeries(QObject *parent):QSeries(parent)
72 {
72 {
73 m_mapX = -1;
73 m_mapX = -1;
74 m_mapY = -1;
74 m_mapY = -1;
75 m_mapFirst = 0;
75 m_mapFirst = 0;
76 m_mapCount = 0;
76 m_mapCount = 0;
77 m_mapLimited = false;
77 m_mapLimited = false;
78 m_mapOrientation = Qt::Vertical;
78 m_mapOrientation = Qt::Vertical;
79 // m_mapYOrientation = Qt::Vertical;
79 // m_mapYOrientation = Qt::Vertical;
80 }
80 }
81 /*!
81 /*!
82 Destroys the object. Series added to QChartView or QChart instances are owned by those,
82 Destroys the object. Series added to QChartView or QChart instances are owned by those,
83 and are deleted when mentioned object are destroyed.
83 and are deleted when mentioned object are destroyed.
84 */
84 */
85 QXYSeries::~QXYSeries()
85 QXYSeries::~QXYSeries()
86 {
86 {
87 }
87 }
88
88
89 /*!
89 /*!
90 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
90 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
91 */
91 */
92 void QXYSeries::append(qreal x,qreal y)
92 void QXYSeries::append(qreal x,qreal y)
93 {
93 {
94 Q_ASSERT(m_x.size() == m_y.size());
94 Q_ASSERT(m_x.size() == m_y.size());
95 m_x<<x;
95 m_x<<x;
96 m_y<<y;
96 m_y<<y;
97 emit pointAdded(m_x.size()-1);
97 emit pointAdded(m_x.size()-1);
98 }
98 }
99
99
100 /*!
100 /*!
101 This is an overloaded function.
101 This is an overloaded function.
102 Adds data \a point to the series. Points are connected with lines on the chart.
102 Adds data \a point to the series. Points are connected with lines on the chart.
103 */
103 */
104 void QXYSeries::append(const QPointF &point)
104 void QXYSeries::append(const QPointF &point)
105 {
105 {
106 append(point.x(),point.y());
106 append(point.x(),point.y());
107 }
107 }
108
108
109 /*!
109 /*!
110 This is an overloaded function.
110 This is an overloaded function.
111 Adds list of data \a points to the series. Points are connected with lines on the chart.
111 Adds list of data \a points to the series. Points are connected with lines on the chart.
112 */
112 */
113 void QXYSeries::append(const QList<QPointF> points)
113 void QXYSeries::append(const QList<QPointF> points)
114 {
114 {
115 foreach(const QPointF& point , points) {
115 foreach(const QPointF& point , points) {
116 append(point.x(),point.y());
116 append(point.x(),point.y());
117 }
117 }
118 }
118 }
119
119
120 /*!
120 /*!
121 Modifies \a y value for given \a x a value.
121 Modifies \a y value for given \a x a value.
122 */
122 */
123 void QXYSeries::replace(qreal x,qreal y)
123 void QXYSeries::replace(qreal x,qreal y)
124 {
124 {
125 int index = m_x.indexOf(x);
125 int index = m_x.indexOf(x);
126 m_x[index] = x;
126 m_x[index] = x;
127 m_y[index] = y;
127 m_y[index] = y;
128 emit pointReplaced(index);
128 emit pointReplaced(index);
129 }
129 }
130
130
131 /*!
131 /*!
132 This is an overloaded function.
132 This is an overloaded function.
133 Replaces current y value of for given \a point x value with \a point y value.
133 Replaces current y value of for given \a point x value with \a point y value.
134 */
134 */
135 void QXYSeries::replace(const QPointF &point)
135 void QXYSeries::replace(const QPointF &point)
136 {
136 {
137 replace(point.x(),point.y());
137 replace(point.x(),point.y());
138 }
138 }
139
139
140 /*!
140 /*!
141 Removes first \a x value and related y value.
141 Removes first \a x value and related y value.
142 */
142 */
143 void QXYSeries::remove(qreal x)
143 void QXYSeries::remove(qreal x)
144 {
144 {
145 int index = m_x.indexOf(x);
145 int index = m_x.indexOf(x);
146
146
147 if (index == -1) return;
147 if (index == -1) return;
148
148
149 m_x.remove(index);
149 m_x.remove(index);
150 m_y.remove(index);
150 m_y.remove(index);
151
151
152 emit pointRemoved(index);
152 emit pointRemoved(index);
153 }
153 }
154
154
155 /*!
155 /*!
156 Removes current \a x and \a y value.
156 Removes current \a x and \a y value.
157 */
157 */
158 void QXYSeries::remove(qreal x,qreal y)
158 void QXYSeries::remove(qreal x,qreal y)
159 {
159 {
160 int index =-1;
160 int index =-1;
161 do {
161 do {
162 index = m_x.indexOf(x,index+1);
162 index = m_x.indexOf(x,index+1);
163 } while (index !=-1 && m_y.at(index)!=y);
163 } while (index !=-1 && m_y.at(index)!=y);
164
164
165 if (index==-1) return;
165 if (index==-1) return;
166
166
167 m_x.remove(index);
167 m_x.remove(index);
168 m_y.remove(index);
168 m_y.remove(index);
169 emit pointRemoved(index);
169 emit pointRemoved(index);
170 }
170 }
171
171
172 /*!
172 /*!
173 Removes current \a point x value. Note \a point y value is ignored.
173 Removes current \a point x value. Note \a point y value is ignored.
174 */
174 */
175 void QXYSeries::remove(const QPointF &point)
175 void QXYSeries::remove(const QPointF &point)
176 {
176 {
177 remove(point.x(),point.y());
177 remove(point.x(),point.y());
178 }
178 }
179
179
180 /*!
180 /*!
181 Removes all data points from the series.
181 Removes all data points from the series.
182 */
182 */
183 void QXYSeries::removeAll()
183 void QXYSeries::removeAll()
184 {
184 {
185 m_x.clear();
185 m_x.clear();
186 m_y.clear();
186 m_y.clear();
187 }
187 }
188
188
189 /*!
189 /*!
190 \internal \a pos
190 \internal \a pos
191 */
191 */
192 qreal QXYSeries::x(int pos) const
192 qreal QXYSeries::x(int pos) const
193 {
193 {
194 if (m_model) {
194 if (m_model) {
195 if (m_mapOrientation == Qt::Vertical)
195 if (m_mapOrientation == Qt::Vertical)
196 // consecutive data is read from model's column
196 // consecutive data is read from model's column
197 return m_model->data(m_model->index(pos + m_mapFirst, m_mapX), Qt::DisplayRole).toDouble();
197 return m_model->data(m_model->index(pos + m_mapFirst, m_mapX), Qt::DisplayRole).toDouble();
198 else
198 else
199 // consecutive data is read from model's row
199 // consecutive data is read from model's row
200 return m_model->data(m_model->index(m_mapX, pos + m_mapFirst), Qt::DisplayRole).toDouble();
200 return m_model->data(m_model->index(m_mapX, pos + m_mapFirst), Qt::DisplayRole).toDouble();
201 } else {
201 } else {
202 // model is not specified, return the data from series' internal data store
202 // model is not specified, return the data from series' internal data store
203 return m_x.at(pos);
203 return m_x.at(pos);
204 }
204 }
205 }
205 }
206
206
207 /*!
207 /*!
208 \internal \a pos
208 \internal \a pos
209 */
209 */
210 qreal QXYSeries::y(int pos) const
210 qreal QXYSeries::y(int pos) const
211 {
211 {
212 if (m_model) {
212 if (m_model) {
213 if (m_mapOrientation == Qt::Vertical)
213 if (m_mapOrientation == Qt::Vertical)
214 // consecutive data is read from model's column
214 // consecutive data is read from model's column
215 return m_model->data(m_model->index(pos + m_mapFirst, m_mapY), Qt::DisplayRole).toDouble();
215 return m_model->data(m_model->index(pos + m_mapFirst, m_mapY), Qt::DisplayRole).toDouble();
216 else
216 else
217 // consecutive data is read from model's row
217 // consecutive data is read from model's row
218 return m_model->data(m_model->index(m_mapY, pos + m_mapFirst), Qt::DisplayRole).toDouble();
218 return m_model->data(m_model->index(m_mapY, pos + m_mapFirst), Qt::DisplayRole).toDouble();
219 } else {
219 } else {
220 // model is not specified, return the data from series' internal data store
220 // model is not specified, return the data from series' internal data store
221 return m_y.at(pos);
221 return m_y.at(pos);
222 }
222 }
223 }
223 }
224
224
225 /*!
225 /*!
226 Returns number of data points within series.
226 Returns number of data points within series.
227 */
227 */
228 int QXYSeries::count() const
228 int QXYSeries::count() const
229 {
229 {
230 Q_ASSERT(m_x.size() == m_y.size());
230 Q_ASSERT(m_x.size() == m_y.size());
231
231
232 if (m_model) {
232 if (m_model) {
233 if (m_mapOrientation == Qt::Vertical) {
233 if (m_mapOrientation == Qt::Vertical) {
234 // data is in a column. Return the number of mapped items if the model's column have enough items
234 // data is in a column. Return the number of mapped items if the model's column have enough items
235 // or the number of items that can be mapped
235 // or the number of items that can be mapped
236 if (m_mapLimited)
236 if (m_mapLimited)
237 return qMin(m_mapCount, qMax(m_model->rowCount() - m_mapFirst, 0));
237 return qMin(m_mapCount, qMax(m_model->rowCount() - m_mapFirst, 0));
238 else
238 else
239 return qMax(m_model->rowCount() - m_mapFirst, 0);
239 return qMax(m_model->rowCount() - m_mapFirst, 0);
240 } else {
240 } else {
241 // data is in a row. Return the number of mapped items if the model's row have enough items
241 // data is in a row. Return the number of mapped items if the model's row have enough items
242 // or the number of items that can be mapped
242 // or the number of items that can be mapped
243 if (m_mapLimited)
243 if (m_mapLimited)
244 return qMin(m_mapCount, qMax(m_model->columnCount() - m_mapFirst, 0));
244 return qMin(m_mapCount, qMax(m_model->columnCount() - m_mapFirst, 0));
245 else
245 else
246 return qMax(m_model->columnCount() - m_mapFirst, 0);
246 return qMax(m_model->columnCount() - m_mapFirst, 0);
247 }
247 }
248 }
248 }
249
249
250 // model is not specified, return the number of points in the series internal data store
250 // model is not specified, return the number of points in the series internal data store
251 return m_x.size();
251 return m_x.size();
252 }
252 }
253
253
254 /*!
254 /*!
255 Returns the data points of the series.
255 Returns the data points of the series.
256 */
256 */
257 QList<QPointF> QXYSeries::data()
257 QList<QPointF> QXYSeries::data()
258 {
258 {
259 QList<QPointF> data;
259 QList<QPointF> data;
260 for (int i(0); i < m_x.count() && i < m_y.count(); i++)
260 for (int i(0); i < m_x.count() && i < m_y.count(); i++)
261 data.append(QPointF(m_x.at(i), m_y.at(i)));
261 data.append(QPointF(m_x.at(i), m_y.at(i)));
262 return data;
262 return data;
263 }
263 }
264
264
265
265
266 /*!
266 /*!
267 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
267 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
268 pen from chart theme is used.
268 pen from chart theme is used.
269 \sa QChart::setChartTheme()
269 \sa QChart::setChartTheme()
270 */
270 */
271 void QXYSeries::setPen(const QPen &pen)
271 void QXYSeries::setPen(const QPen &pen)
272 {
272 {
273 if (pen != m_pen) {
273 if (pen != m_pen) {
274 m_pen = pen;
274 m_pen = pen;
275 emit updated();
275 emit updated();
276 }
276 }
277 }
277 }
278
278
279 /*!
279 /*!
280 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
280 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
281 from chart theme setting is used.
281 from chart theme setting is used.
282 \sa QChart::setChartTheme()
282 \sa QChart::setChartTheme()
283 */
283 */
284
284
285 void QXYSeries::setBrush(const QBrush &brush)
285 void QXYSeries::setBrush(const QBrush &brush)
286 {
286 {
287 if (brush != m_brush) {
287 if (brush != m_brush) {
288 m_brush = brush;
288 m_brush = brush;
289 emit updated();
289 emit updated();
290 }
290 }
291 }
291 }
292
292
293
293
294 /*!
294 /*!
295 Stream operator for adding a data \a point to the series.
295 Stream operator for adding a data \a point to the series.
296 \sa append()
296 \sa append()
297 */
297 */
298
298
299 QXYSeries& QXYSeries::operator<< (const QPointF &point)
299 QXYSeries& QXYSeries::operator<< (const QPointF &point)
300 {
300 {
301 append(point);
301 append(point);
302 return *this;
302 return *this;
303 }
303 }
304
304
305
305
306 /*!
306 /*!
307 Stream operator for adding a list of \a points to the series.
307 Stream operator for adding a list of \a points to the series.
308 \sa append()
308 \sa append()
309 */
309 */
310
310
311 QXYSeries& QXYSeries::operator<< (const QList<QPointF> points)
311 QXYSeries& QXYSeries::operator<< (const QList<QPointF> points)
312 {
312 {
313 append(points);
313 append(points);
314 return *this;
314 return *this;
315 }
315 }
316
316
317
317
318 void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
318 void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
319 {
319 {
320 Q_UNUSED(bottomRight)
320 Q_UNUSED(bottomRight)
321
321
322 if (m_mapOrientation == Qt::Vertical) {
322 if (m_mapOrientation == Qt::Vertical) {
323 if (topLeft.row() >= m_mapFirst && (!m_mapLimited || topLeft.row() < m_mapFirst + m_mapCount))
323 if (topLeft.row() >= m_mapFirst && (!m_mapLimited || topLeft.row() < m_mapFirst + m_mapCount))
324 emit pointReplaced(topLeft.row() - m_mapFirst);
324 emit pointReplaced(topLeft.row() - m_mapFirst);
325 } else {
325 } else {
326 if (topLeft.column() >= m_mapFirst && (!m_mapLimited || topLeft.column() < m_mapFirst + m_mapCount))
326 if (topLeft.column() >= m_mapFirst && (!m_mapLimited || topLeft.column() < m_mapFirst + m_mapCount))
327 emit pointReplaced(topLeft.column() - m_mapFirst);
327 emit pointReplaced(topLeft.column() - m_mapFirst);
328 }
328 }
329 }
329 }
330
330
331 void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end)
331 void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end)
332 {
332 {
333 Q_UNUSED(parent)
333 Q_UNUSED(parent)
334 // Q_UNUSED(end)
334 // Q_UNUSED(end)
335
335
336 if (m_mapLimited) {
336 if (m_mapLimited) {
337 if (start >= m_mapFirst + m_mapCount) {
337 if (start >= m_mapFirst + m_mapCount) {
338 // the added data is below mapped area
338 // the added data is below mapped area
339 // therefore it has no relevance
339 // therefore it has no relevance
340 return;
340 return;
341 } else {
341 } else {
342 // the added data is in the mapped area or before it and update is needed
342 // the added data is in the mapped area or before it and update is needed
343
343
344 // check how many mapped items there is currently (before new items are added)
344 // check how many mapped items there is currently (before new items are added)
345 // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem
345 // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem
346 // internal storage before new ones can be added
346 // internal storage before new ones can be added
347
347
348 int itemsToRemove = qMin(count() - (start - m_mapFirst), end - start + 1);
348 int itemsToRemove = qMin(count() - qMax(start - m_mapFirst, 0), end - start + 1);
349 if (m_mapCount == count()) {
349 if (m_mapCount == count()) {
350 for (int i = 0; i < itemsToRemove; i++)
350 for (int i = 0; i < itemsToRemove; i++)
351 emit pointRemoved(count() - 1 - i);
351 emit pointRemoved(qMin(end, count()) - i);
352 }
352 }
353 }
353 }
354 } else {
354 } else {
355 // map is not limited (it includes all the items starting from m_mapFirst till the end of model)
355 // map is not limited (it includes all the items starting from m_mapFirst till the end of model)
356 // nothing to do
356 // nothing to do
357 // emit pointAdded(qMax(start - m_mapFirst, 0));
357 // emit pointAdded(qMax(start - m_mapFirst, 0));
358 }
358 }
359 }
359 }
360
360
361 void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end)
361 void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end)
362 {
362 {
363 Q_UNUSED(parent)
363 Q_UNUSED(parent)
364 // Q_UNUSED(end)
364 // Q_UNUSED(end)
365
365
366 if (m_mapLimited) {
366 if (m_mapLimited) {
367 if (start >= m_mapFirst + m_mapCount) {
367 if (start >= m_mapFirst + m_mapCount) {
368 // the added data is below mapped area
368 // the added data is below mapped area
369 // therefore it has no relevance
369 // therefore it has no relevance
370 return;
370 return;
371 } else {
371 } else {
372 // the added data is in the mapped area or before it
372 // the added data is in the mapped area or before it
373 // update needed
373 // update needed
374 if (count() > 0) {
374 if (count() > 0) {
375 for (int i = 0; i < qMin(m_mapCount - (start - m_mapFirst), end - start + 1); i++)
375 int toBeAdded = qMin(m_mapCount - (start - m_mapFirst), end - start + 1);
376 emit pointAdded(qMax(start + i - m_mapFirst, 0));
376 for (int i = 0; i < toBeAdded; i++)
377 if (start + i >= m_mapFirst)
378 emit pointAdded(start + i);
377 }
379 }
378 }
380 }
379 } else {
381 } else {
380 // map is not limited (it included all the items starting from m_mapFirst till the end of model)
382 // map is not limited (it included all the items starting from m_mapFirst till the end of model)
381 for (int i = 0; i < end - start + 1; i++)
383 for (int i = 0; i < end - start + 1; i++)
382 emit pointAdded(qMax(start + i - m_mapFirst, 0));
384 emit pointAdded(start + i);
383 }
385 }
384 }
386 }
385
387
386 void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end)
388 void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end)
387 {
389 {
388 Q_UNUSED(parent)
390 Q_UNUSED(parent)
389 // Q_UNUSED(end)
391 // Q_UNUSED(end)
390
392
391 if (m_mapLimited) {
393 if (m_mapLimited) {
392 if (start >= m_mapFirst + m_mapCount) {
394 if (start >= m_mapFirst + m_mapCount) {
393 // the removed data is below mapped area
395 // the removed data is below mapped area
394 // therefore it has no relevance
396 // therefore it has no relevance
395 return;
397 return;
396 } else {
398 } else {
397 // the removed data is in the mapped area or before it
399 // the removed data is in the mapped area or before it
398 // update needed
400 // update needed
399
401
400 // check how many items need to be removed from the xychartitem storage
402 // check how many items need to be removed from the xychartitem storage
401 // the number equals the number of items that are removed and that lay before
403 // the number equals the number of items that are removed and that lay before
402 // or in the mapped area. Items that lay beyond the map do not count
404 // or in the mapped area. Items that lay beyond the map do not count
403 // the max is the current number of items in storage (count())
405 // the max is the current number of items in storage (count())
404 int itemsToRemove = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1);
406 int itemsToRemove = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1);
405 for (int i = 0; i < itemsToRemove; i++)
407 for (int i = 0; i < itemsToRemove; i++)
406 emit pointRemoved(qMax(start - m_mapFirst, 0));
408 emit pointRemoved(start);
407 }
409 }
408 } else {
410 } else {
409 // map is not limited (it included all the items starting from m_mapFirst till the end of model)
411 // map is not limited (it included all the items starting from m_mapFirst till the end of model)
410 for (int i = 0; i < end - start + 1; i++)
412 for (int i = 0; i < end - start + 1; i++)
411 emit pointRemoved(qMax(start - m_mapFirst, 0));
413 emit pointRemoved(start);
412 }
414 }
413 }
415 }
414
416
415 void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end)
417 void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end)
416 {
418 {
417 Q_UNUSED(parent)
419 Q_UNUSED(parent)
418 Q_UNUSED(end)
420 Q_UNUSED(end)
419
421
420 // how many items there were before data was removed
422 // how many items there were before data was removed
421 // int oldCount = count() - 1;
423 // int oldCount = count() - 1;
422
424
423 if (m_mapLimited) {
425 if (m_mapLimited) {
424 if (start >= m_mapFirst + m_mapCount) {
426 if (start >= m_mapFirst + m_mapCount) {
425 // the removed data is below mapped area
427 // the removed data is below mapped area
426 // therefore it has no relevance
428 // therefore it has no relevance
427 return;
429 return;
428 } else {
430 } else {
429 // if the current items count in the whole model is bigger than the index of the last item
431 // if the current items count in the whole model is bigger than the index of the last item
430 // that was removed than it means there are some extra items available
432 // that was removed than it means there are some extra items available
433
434 int removedItemsCount = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1);
431 int extraItemsAvailable = 0;
435 int extraItemsAvailable = 0;
432 if (m_mapOrientation == Qt::Vertical) {
436 if (m_mapOrientation == Qt::Vertical) {
433 extraItemsAvailable = qMax(m_model->rowCount() - end, 0);
437 // int temp1 = m_model->rowCount();
438 // int temp2 = (end - start + 1);
439 // int temp3 = qMax(end + 1, m_mapFirst + m_mapCount);
440 extraItemsAvailable = qMax(m_model->rowCount() + (end - start + 1) - qMax(end + 1, m_mapFirst + m_mapCount), 0);
434 } else {
441 } else {
435 extraItemsAvailable = qMax(m_model->columnCount() - end, 0);
442 extraItemsAvailable = qMax(m_model->columnCount() + (end - start + 1) - qMax(end + 1, m_mapFirst + m_mapCount), 0);
436 }
443 }
437
444
438 // if there are excess items available (below the mapped area) use them to repopulate mapped area
445 // if there are excess items available (below the mapped area) use them to repopulate mapped area
439 int removedItemsCount = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - qMax(start, m_mapFirst) + 1);
440 int toBeAdded = qMin(extraItemsAvailable, removedItemsCount);
446 int toBeAdded = qMin(extraItemsAvailable, removedItemsCount);
441 for (int k = 0; k < toBeAdded; k++)
447 for (int k = 0; k < toBeAdded; k++)
442 emit pointAdded(qMax(start - m_mapFirst, m_mapFirst) + k);
448 emit pointAdded(m_mapFirst + m_mapCount - removedItemsCount + k);
443 }
449 }
444 } else {
450 } else {
445 // data was removed from XYSeries interal storage. Nothing more to do
451 // data was removed from XYSeries interal storage. Nothing more to do
446 }
452 }
447 }
453 }
448
454
449 bool QXYSeries::setModel(QAbstractItemModel *model) {
455 bool QXYSeries::setModel(QAbstractItemModel *model) {
450
456
451 // disconnect signals from old model
457 // disconnect signals from old model
452 if (m_model) {
458 if (m_model) {
453 disconnect(m_model, 0, this, 0);
459 disconnect(m_model, 0, this, 0);
454 m_mapX = -1;
460 m_mapX = -1;
455 m_mapY = -1;
461 m_mapY = -1;
456 m_mapFirst = 0;
462 m_mapFirst = 0;
457 m_mapCount = 0;
463 m_mapCount = 0;
458 m_mapLimited = false;
464 m_mapLimited = false;
459 m_mapOrientation = Qt::Vertical;
465 m_mapOrientation = Qt::Vertical;
460 }
466 }
461
467
462 // set new model
468 // set new model
463 if (model) {
469 if (model) {
464 m_model = model;
470 m_model = model;
465 return true;
471 return true;
466 } else {
472 } else {
467 m_model = 0;
473 m_model = 0;
468 return false;
474 return false;
469 }
475 }
470 }
476 }
471
477
472 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
478 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
473 {
479 {
474 if (m_model == 0)
480 if (m_model == 0)
475 return;
481 return;
476 m_mapX = modelX;
482 m_mapX = modelX;
477 m_mapY = modelY;
483 m_mapY = modelY;
478 m_mapFirst = 0;
484 m_mapFirst = 0;
479 m_mapOrientation = orientation;
485 m_mapOrientation = orientation;
480 if (m_mapOrientation == Qt::Vertical) {
486 if (m_mapOrientation == Qt::Vertical) {
481 // m_mapCount = m_model->rowCount();
487 // m_mapCount = m_model->rowCount();
482 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
488 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
483 connect(m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int)));
489 connect(m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int)));
484 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
490 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
485 connect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int)));
491 connect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int)));
486 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
492 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
487 } else {
493 } else {
488 // m_mapCount = m_model->columnCount();
494 // m_mapCount = m_model->columnCount();
489 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
495 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
490 connect(m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int)));
496 connect(m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int)));
491 connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
497 connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
492 connect(m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int)));
498 connect(m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int)));
493 connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
499 connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
494 }
500 }
495 }
501 }
496
502
497 void QXYSeries::setModelMappingShift(int first, int count)
503 void QXYSeries::setModelMappingShift(int first, int count)
498 {
504 {
499 m_mapFirst = first;
505 m_mapFirst = first;
500 if (count == 0) {
506 if (count == 0) {
501 m_mapLimited = false;
507 m_mapLimited = false;
502 } else {
508 } else {
503 m_mapCount = count;
509 m_mapCount = count;
504 m_mapLimited = true;
510 m_mapLimited = true;
505 }
511 }
506 }
512 }
507
513
508 #include "moc_qxyseries.cpp"
514 #include "moc_qxyseries.cpp"
509
515
510 QTCOMMERCIALCHART_END_NAMESPACE
516 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,100 +1,101
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QXYSERIES_H_
21 #ifndef QXYSERIES_H_
22 #define QXYSERIES_H_
22 #define QXYSERIES_H_
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <qseries.h>
25 #include <qseries.h>
26 #include <QPen>
26 #include <QPen>
27 #include <QBrush>
27 #include <QBrush>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QSeries
31 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QSeries
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 protected:
34 protected:
35 QXYSeries(QObject *parent = 0);
35 QXYSeries(QObject *parent = 0);
36 virtual ~QXYSeries();
36 virtual ~QXYSeries();
37
37
38 public:
38 public:
39 void append(qreal x, qreal y);
39 void append(qreal x, qreal y);
40 void append(const QPointF &point);
40 void append(const QPointF &point);
41 void append(const QList<QPointF> points);
41 void append(const QList<QPointF> points);
42 void replace(qreal x,qreal y);
42 void replace(qreal x,qreal y);
43 void replace(const QPointF &point);
43 void replace(const QPointF &point);
44 void remove(qreal x);
44 void remove(qreal x);
45 void remove(qreal x, qreal y);
45 void remove(qreal x, qreal y);
46 void remove(const QPointF &point);
46 void remove(const QPointF &point);
47 void removeAll();
47 void removeAll();
48
48
49 int count() const;
49 int count() const;
50 qreal x(int pos) const;
50 qreal x(int pos) const;
51 qreal y(int pos) const;
51 qreal y(int pos) const;
52 QList<QPointF> data();
52 QList<QPointF> data();
53
53
54 QXYSeries& operator << (const QPointF &point);
54 QXYSeries& operator << (const QPointF &point);
55 QXYSeries& operator << (const QList<QPointF> points);
55 QXYSeries& operator << (const QList<QPointF> points);
56
56
57 void setPen(const QPen &pen);
57 void setPen(const QPen &pen);
58 QPen pen() const {return m_pen;}
58 QPen pen() const {return m_pen;}
59 void setBrush(const QBrush &brush);
59 void setBrush(const QBrush &brush);
60 QBrush brush() const {return m_brush;}
60 QBrush brush() const {return m_brush;}
61
61
62 bool setModel(QAbstractItemModel *model);
62 bool setModel(QAbstractItemModel *model);
63 QAbstractItemModel* model() const { return m_model; }
63 QAbstractItemModel* model() const { return m_model; }
64
64
65 virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
65 virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
66 virtual void setModelMappingShift(int first, int count = 0);
66 virtual void setModelMappingShift(int first, int count = 0);
67 int mapFirst() const { return m_mapFirst; }
67
68
68 private Q_SLOTS:
69 private Q_SLOTS:
69 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
70 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
70 void modelDataAboutToBeAdded(QModelIndex parent, int start, int end);
71 void modelDataAboutToBeAdded(QModelIndex parent, int start, int end);
71 void modelDataAdded(QModelIndex parent, int start, int end);
72 void modelDataAdded(QModelIndex parent, int start, int end);
72 void modelDataAboutToBeRemoved(QModelIndex parent, int start, int end);
73 void modelDataAboutToBeRemoved(QModelIndex parent, int start, int end);
73 void modelDataRemoved(QModelIndex parent, int start, int end);
74 void modelDataRemoved(QModelIndex parent, int start, int end);
74
75
75 Q_SIGNALS:
76 Q_SIGNALS:
76 void clicked(const QPointF &point);
77 void clicked(const QPointF &point);
77 void updated();
78 void updated();
78 void pointReplaced(int index);
79 void pointReplaced(int index);
79 void pointRemoved(int index);
80 void pointRemoved(int index);
80 void pointAdded(int index);
81 void pointAdded(int index);
81
82
82 protected:
83 protected:
83 QVector<qreal> m_x;
84 QVector<qreal> m_x;
84 QVector<qreal> m_y;
85 QVector<qreal> m_y;
85
86
86 QPen m_pen;
87 QPen m_pen;
87 QBrush m_brush;
88 QBrush m_brush;
88
89
89 int m_mapX;
90 int m_mapX;
90 int m_mapY;
91 int m_mapY;
91 int m_mapFirst;
92 int m_mapFirst;
92 int m_mapCount;
93 int m_mapCount;
93 bool m_mapLimited;
94 bool m_mapLimited;
94 Qt::Orientation m_mapOrientation;
95 Qt::Orientation m_mapOrientation;
95 int tempItemsRemoved;
96 int tempItemsRemoved;
96 };
97 };
97
98
98 QTCOMMERCIALCHART_END_NAMESPACE
99 QTCOMMERCIALCHART_END_NAMESPACE
99
100
100 #endif
101 #endif
@@ -1,176 +1,195
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 "xychartitem_p.h"
21 #include "xychartitem_p.h"
22 #include "qxyseries.h"
22 #include "qxyseries.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
24 #include "chartanimator_p.h"
25 #include <QPainter>
25 #include <QPainter>
26 #include <QGraphicsSceneMouseEvent>
26 #include <QGraphicsSceneMouseEvent>
27
27
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 //TODO: optimize : remove points which are not visible
31 //TODO: optimize : remove points which are not visible
32
32
33 XYChartItem::XYChartItem(QXYSeries *series, ChartPresenter *presenter):ChartItem(presenter),
33 XYChartItem::XYChartItem(QXYSeries *series, ChartPresenter *presenter):ChartItem(presenter),
34 m_minX(0),
34 m_minX(0),
35 m_maxX(0),
35 m_maxX(0),
36 m_minY(0),
36 m_minY(0),
37 m_maxY(0),
37 m_maxY(0),
38 m_series(series)
38 m_series(series)
39 {
39 {
40 connect(series,SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int)));
40 connect(series,SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int)));
41 connect(series,SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int)));
41 connect(series,SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int)));
42 connect(series,SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int)));
42 connect(series,SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int)));
43 connect(this,SIGNAL(clicked(const QPointF&)),series,SIGNAL(clicked(const QPointF&)));
43 connect(this,SIGNAL(clicked(const QPointF&)),series,SIGNAL(clicked(const QPointF&)));
44 }
44 }
45
45
46 QPointF XYChartItem::calculateGeometryPoint(const QPointF &point) const
46 QPointF XYChartItem::calculateGeometryPoint(const QPointF &point) const
47 {
47 {
48 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
48 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
49 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
49 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
50 qreal x = (point.x() - m_minX)* deltaX;
50 qreal x = (point.x() - m_minX)* deltaX;
51 qreal y = (point.y() - m_minY)*-deltaY + m_size.height();
51 qreal y = (point.y() - m_minY)*-deltaY + m_size.height();
52 return QPointF(x,y);
52 return QPointF(x,y);
53 }
53 }
54
54
55
55
56 QPointF XYChartItem::calculateGeometryPoint(int index) const
56 QPointF XYChartItem::calculateGeometryPoint(int index) const
57 {
57 {
58 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
58 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
59 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
59 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
60 qreal x = (m_series->x(index) - m_minX)* deltaX;
60 qreal x = (m_series->x(index) - m_minX)* deltaX;
61 qreal y = (m_series->y(index) - m_minY)*-deltaY + m_size.height();
61 qreal y = (m_series->y(index) - m_minY)*-deltaY + m_size.height();
62 return QPointF(x,y);
62 return QPointF(x,y);
63 }
63 }
64
64
65 QVector<QPointF> XYChartItem::calculateGeometryPoints() const
65 QVector<QPointF> XYChartItem::calculateGeometryPoints() const
66 {
66 {
67 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
67 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
68 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
68 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
69
69
70 QVector<QPointF> points;
70 QVector<QPointF> points;
71 points.reserve(m_series->count());
71 points.reserve(m_series->count());
72 for (int i = 0; i < m_series->count(); ++i) {
72 for (int i = 0; i < m_series->count(); ++i) {
73 qreal x = (m_series->x(i) - m_minX)* deltaX;
73 qreal x = (m_series->x(i) - m_minX)* deltaX;
74 qreal y = (m_series->y(i) - m_minY)*-deltaY + m_size.height();
74 qreal y = (m_series->y(i) - m_minY)*-deltaY + m_size.height();
75 points << QPointF(x,y);
75 points << QPointF(x,y);
76 }
76 }
77 return points;
77 return points;
78 }
78 }
79
79
80 QPointF XYChartItem::calculateDomainPoint(const QPointF &point) const
80 QPointF XYChartItem::calculateDomainPoint(const QPointF &point) const
81 {
81 {
82 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
82 const qreal deltaX = m_size.width()/(m_maxX-m_minX);
83 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
83 const qreal deltaY = m_size.height()/(m_maxY-m_minY);
84 qreal x = point.x()/deltaX +m_minX;
84 qreal x = point.x()/deltaX +m_minX;
85 qreal y = (point.y()-m_size.height())/(-deltaY)+ m_minY;
85 qreal y = (point.y()-m_size.height())/(-deltaY)+ m_minY;
86 return QPointF(x,y);
86 return QPointF(x,y);
87 }
87 }
88
88
89 void XYChartItem::updateLayout(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index)
89 void XYChartItem::updateLayout(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index)
90 {
90 {
91 if (animator()) {
91 if (animator()) {
92 animator()->updateLayout(this,oldPoints,newPoints,index);
92 animator()->updateLayout(this,oldPoints,newPoints,index);
93 } else {
93 } else {
94 setLayout(newPoints);
94 setLayout(newPoints);
95 }
95 }
96 }
96 }
97
97
98 void XYChartItem::setLayout(QVector<QPointF> &points)
98 void XYChartItem::setLayout(QVector<QPointF> &points)
99 {
99 {
100 m_points = points;
100 m_points = points;
101 update();
101 update();
102 }
102 }
103
103
104 //handlers
104 //handlers
105
105
106 void XYChartItem::handlePointAdded(int index)
106 void XYChartItem::handlePointAdded(int index)
107 {
107 {
108 Q_ASSERT(index<m_series->count());
109 Q_ASSERT(index>=0);
110 QPointF point = calculateGeometryPoint(index);
111 QVector<QPointF> points = m_points;
108 QVector<QPointF> points = m_points;
112 points.insert(index,point);
109 QPointF point;
113 updateLayout(m_points,points,index);
110 if (m_series->model()) {
111 point = calculateGeometryPoint(index - m_series->mapFirst());
112 points.insert(index - m_series->mapFirst(), point);
113 updateLayout(m_points, points, index - m_series->mapFirst());
114 }
115 else {
116 // this checks do not work correctly if model is set
117 Q_ASSERT(index<m_series->count());
118 Q_ASSERT(index>=0);
119 point = calculateGeometryPoint(index);
120 points.insert(index, point);
121 updateLayout(m_points, points, index);
122 }
114 update();
123 update();
115 }
124 }
116 void XYChartItem::handlePointRemoved(int index)
125 void XYChartItem::handlePointRemoved(int index)
117 {
126 {
118 Q_ASSERT(index<m_series->count() + 1);
119 Q_ASSERT(index>=0);
120 QVector<QPointF> points = m_points;
127 QVector<QPointF> points = m_points;
121 points.remove(index);
128 if (m_series->model()) {
122 updateLayout(m_points,points,index);
129 if (index < m_series->mapFirst())
130 points.remove(0);
131 else
132 points.remove(index - m_series->mapFirst());
133 updateLayout(m_points, points, index - m_series->mapFirst());
134 }
135 else {
136 // this checks do not work correctly if model is set
137 Q_ASSERT(index<m_series->count() + 1);
138 Q_ASSERT(index>=0);
139 points.remove(index);
140 updateLayout(m_points, points, index);
141 }
123 update();
142 update();
124 }
143 }
125
144
126 void XYChartItem::handlePointReplaced(int index)
145 void XYChartItem::handlePointReplaced(int index)
127 {
146 {
128 Q_ASSERT(index<m_series->count());
147 Q_ASSERT(index<m_series->count());
129 Q_ASSERT(index>=0);
148 Q_ASSERT(index>=0);
130 QPointF point = calculateGeometryPoint(index);
149 QPointF point = calculateGeometryPoint(index);
131 QVector<QPointF> points = m_points;
150 QVector<QPointF> points = m_points;
132 points.replace(index,point);
151 points.replace(index,point);
133 updateLayout(m_points,points,index);
152 updateLayout(m_points,points,index);
134 update();
153 update();
135 }
154 }
136
155
137 void XYChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
156 void XYChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
138 {
157 {
139 m_minX=minX;
158 m_minX=minX;
140 m_maxX=maxX;
159 m_maxX=maxX;
141 m_minY=minY;
160 m_minY=minY;
142 m_maxY=maxY;
161 m_maxY=maxY;
143
162
144 if (isEmpty()) return;
163 if (isEmpty()) return;
145 QVector<QPointF> points = calculateGeometryPoints();
164 QVector<QPointF> points = calculateGeometryPoints();
146 updateLayout(m_points,points);
165 updateLayout(m_points,points);
147 update();
166 update();
148 }
167 }
149
168
150 void XYChartItem::handleGeometryChanged(const QRectF &rect)
169 void XYChartItem::handleGeometryChanged(const QRectF &rect)
151 {
170 {
152 Q_ASSERT(rect.isValid());
171 Q_ASSERT(rect.isValid());
153 m_size=rect.size();
172 m_size=rect.size();
154 m_clipRect=rect.translated(-rect.topLeft());
173 m_clipRect=rect.translated(-rect.topLeft());
155 setPos(rect.topLeft());
174 setPos(rect.topLeft());
156
175
157 if (isEmpty()) return;
176 if (isEmpty()) return;
158 QVector<QPointF> points = calculateGeometryPoints();
177 QVector<QPointF> points = calculateGeometryPoints();
159 updateLayout(m_points,points);
178 updateLayout(m_points,points);
160 update();
179 update();
161 }
180 }
162
181
163
182
164 bool XYChartItem::isEmpty()
183 bool XYChartItem::isEmpty()
165 {
184 {
166 return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY);
185 return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY);
167 }
186 }
168
187
169 void XYChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
188 void XYChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
170 {
189 {
171 emit clicked(calculateDomainPoint(event->pos()));
190 emit clicked(calculateDomainPoint(event->pos()));
172 }
191 }
173
192
174 #include "moc_xychartitem_p.cpp"
193 #include "moc_xychartitem_p.cpp"
175
194
176 QTCOMMERCIALCHART_END_NAMESPACE
195 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now