##// END OF EJS Templates
Fixed spline's broken signals
Marek Rosa -
r1275:5883c94a00fe
parent child
Show More
@@ -1,221 +1,225
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 "qsplineseries.h"
21 #include "qsplineseries.h"
22 #include "qsplineseries_p.h"
22 #include "qsplineseries_p.h"
23 #include "splinechartitem_p.h"
23 #include "splinechartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 /*!
28 /*!
29 \class QSplineSeries
29 \class QSplineSeries
30 \brief Series type used to store data needed to draw a spline.
30 \brief Series type used to store data needed to draw a spline.
31
31
32 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
32 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
33 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
33 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
34
34
35 \image examples_splinechart.png
35 \image examples_splinechart.png
36
36
37 Creating basic spline chart is simple:
37 Creating basic spline chart is simple:
38 \code
38 \code
39 QSplineSeries* series = new QSplineSeries();
39 QSplineSeries* series = new QSplineSeries();
40 series->append(0, 6);
40 series->append(0, 6);
41 series->append(2, 4);
41 series->append(2, 4);
42 ...
42 ...
43 chart->addSeries(series);
43 chart->addSeries(series);
44 \endcode
44 \endcode
45 */
45 */
46
46
47 /*!
47 /*!
48 \fn QSeriesType QSplineSeries::type() const
48 \fn QSeriesType QSplineSeries::type() const
49 Returns the type of the series
49 Returns the type of the series
50 */
50 */
51
51
52 QTCOMMERCIALCHART_BEGIN_NAMESPACE
52 QTCOMMERCIALCHART_BEGIN_NAMESPACE
53
53
54 /*!
54 /*!
55 Constructs empty series object which is a child of \a parent.
55 Constructs empty series object which is a child of \a parent.
56 When series object is added to QChartView or QChart instance then the ownerships is transferred.
56 When series object is added to QChartView or QChart instance then the ownerships is transferred.
57 */
57 */
58
58
59 QSplineSeries::QSplineSeries(QObject *parent) :
59 QSplineSeries::QSplineSeries(QObject *parent) :
60 QLineSeries(*new QSplineSeriesPrivate(this),parent)
60 QLineSeries(*new QSplineSeriesPrivate(this),parent)
61 {
61 {
62 Q_D(QSplineSeries);
63 QObject::connect(this,SIGNAL(pointAdded(int)), d, SLOT(updateControlPoints()));
64 QObject::connect(this,SIGNAL(pointRemoved(int)), d, SLOT(updateControlPoints()));
65 QObject::connect(this,SIGNAL(pointReplaced(int)), d, SLOT(updateControlPoints()));
62 }
66 }
63
67
64 QSplineSeries::~QSplineSeries()
68 QSplineSeries::~QSplineSeries()
65 {
69 {
66 Q_D(QSplineSeries);
70 Q_D(QSplineSeries);
67 if(d->m_dataset){
71 if(d->m_dataset){
68 d->m_dataset->removeSeries(this);
72 d->m_dataset->removeSeries(this);
69 }
73 }
70 }
74 }
71
75
72 QAbstractSeries::SeriesType QSplineSeries::type() const
76 QAbstractSeries::SeriesType QSplineSeries::type() const
73 {
77 {
74 return QAbstractSeries::SeriesTypeSpline;
78 return QAbstractSeries::SeriesTypeSpline;
75 }
79 }
76
80
77 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
81 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
78
82
79 QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q)
83 QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries* q):QLineSeriesPrivate(q)
80 {
84 {
81 QObject::connect(this,SIGNAL(pointAdded(int)), this, SLOT(updateControlPoints()));
85 // QObject::connect(this,SIGNAL(pointAdded(int)), this, SLOT(updateControlPoints()));
82 QObject::connect(this,SIGNAL(pointRemoved(int)), this, SLOT(updateControlPoints()));
86 // QObject::connect(this,SIGNAL(pointRemoved(int)), this, SLOT(updateControlPoints()));
83 QObject::connect(this,SIGNAL(pointReplaced(int)), this, SLOT(updateControlPoints()));
87 // QObject::connect(this,SIGNAL(pointReplaced(int)), this, SLOT(updateControlPoints()));
84 };
88 };
85
89
86 /*!
90 /*!
87 Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points.
91 Calculates control points which are needed by QPainterPath.cubicTo function to draw the cubic Bezier cureve between two points.
88 */
92 */
89 void QSplineSeriesPrivate::calculateControlPoints()
93 void QSplineSeriesPrivate::calculateControlPoints()
90 {
94 {
91 Q_Q(QSplineSeries);
95 Q_Q(QSplineSeries);
92
96
93 const QList<QPointF>& points = q->points();
97 const QList<QPointF>& points = q->points();
94
98
95 int n = points.count() - 1;
99 int n = points.count() - 1;
96
100
97 if (n == 1)
101 if (n == 1)
98 {
102 {
99 //for n==1
103 //for n==1
100 m_controlPoints[0].setX((2 * points[0].x() + points[1].x()) / 3);
104 m_controlPoints[0].setX((2 * points[0].x() + points[1].x()) / 3);
101 m_controlPoints[0].setY((2 * points[0].y() + points[1].y()) / 3);
105 m_controlPoints[0].setY((2 * points[0].y() + points[1].y()) / 3);
102 m_controlPoints[1].setX(2 * m_controlPoints[0].x() - points[0].x());
106 m_controlPoints[1].setX(2 * m_controlPoints[0].x() - points[0].x());
103 m_controlPoints[1].setY(2 * m_controlPoints[0].y() - points[0].y());
107 m_controlPoints[1].setY(2 * m_controlPoints[0].y() - points[0].y());
104 return;
108 return;
105 }
109 }
106
110
107 // Calculate first Bezier control points
111 // Calculate first Bezier control points
108 // Right hand side vector
112 // Right hand side vector
109 // Set of equations for P0 to Pn points.
113 // Set of equations for P0 to Pn points.
110 //
114 //
111 // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
115 // | 2 1 0 0 ... 0 0 0 ... 0 0 0 | | P1_1 | | P0 + 2 * P1 |
112 // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
116 // | 1 4 1 0 ... 0 0 0 ... 0 0 0 | | P1_2 | | 4 * P1 + 2 * P2 |
113 // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
117 // | 0 1 4 1 ... 0 0 0 ... 0 0 0 | | P1_3 | | 4 * P2 + 2 * P3 |
114 // | . . . . . . . . . . . . | | ... | | ... |
118 // | . . . . . . . . . . . . | | ... | | ... |
115 // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
119 // | 0 0 0 0 ... 1 4 1 ... 0 0 0 | * | P1_i | = | 4 * P(i-1) + 2 * Pi |
116 // | . . . . . . . . . . . . | | ... | | ... |
120 // | . . . . . . . . . . . . | | ... | | ... |
117 // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
121 // | 0 0 0 0 0 0 0 0 ... 1 4 1 | | P1_(n-1)| | 4 * P(n-2) + 2 * P(n-1) |
118 // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
122 // | 0 0 0 0 0 0 0 0 ... 0 2 7 | | P1_n | | 8 * P(n-1) + Pn |
119 //
123 //
120 QVector<qreal> vector;
124 QVector<qreal> vector;
121 vector.resize(n);
125 vector.resize(n);
122
126
123 vector[0] = points[0].x() + 2 * points[1].x();
127 vector[0] = points[0].x() + 2 * points[1].x();
124
128
125
129
126 for (int i = 1; i < n - 1; ++i){
130 for (int i = 1; i < n - 1; ++i){
127 vector[i] = 4 * points[i].x() + 2 * points[i + 1].x();
131 vector[i] = 4 * points[i].x() + 2 * points[i + 1].x();
128 }
132 }
129
133
130 vector[n - 1] = (8 * points[n-1].x() + points[n].x()) / 2.0;
134 vector[n - 1] = (8 * points[n-1].x() + points[n].x()) / 2.0;
131
135
132 QVector<qreal> xControl = firstControlPoints(vector);
136 QVector<qreal> xControl = firstControlPoints(vector);
133
137
134 vector[0] = points[0].y() + 2 * points[1].y();
138 vector[0] = points[0].y() + 2 * points[1].y();
135
139
136 for (int i = 1; i < n - 1; ++i) {
140 for (int i = 1; i < n - 1; ++i) {
137 vector[i] = 4 * points[i].y() + 2 * points[i + 1].y();
141 vector[i] = 4 * points[i].y() + 2 * points[i + 1].y();
138 }
142 }
139
143
140 vector[n - 1] = (8 * points[n-1].y() + points[n].y()) / 2.0;
144 vector[n - 1] = (8 * points[n-1].y() + points[n].y()) / 2.0;
141
145
142 QVector<qreal> yControl = firstControlPoints(vector);
146 QVector<qreal> yControl = firstControlPoints(vector);
143
147
144 for (int i = 0,j =0; i < n; ++i, ++j) {
148 for (int i = 0,j =0; i < n; ++i, ++j) {
145
149
146 m_controlPoints[j].setX(xControl[i]);
150 m_controlPoints[j].setX(xControl[i]);
147 m_controlPoints[j].setY(yControl[i]);
151 m_controlPoints[j].setY(yControl[i]);
148
152
149 j++;
153 j++;
150
154
151 if (i < n - 1){
155 if (i < n - 1){
152 m_controlPoints[j].setX(2 * points[i+1].x() - xControl[i + 1]);
156 m_controlPoints[j].setX(2 * points[i+1].x() - xControl[i + 1]);
153 m_controlPoints[j].setY(2 * points[i+1].y() - yControl[i + 1]);
157 m_controlPoints[j].setY(2 * points[i+1].y() - yControl[i + 1]);
154 }else{
158 }else{
155 m_controlPoints[j].setX((points[n].x() + xControl[n - 1]) / 2);
159 m_controlPoints[j].setX((points[n].x() + xControl[n - 1]) / 2);
156 m_controlPoints[j].setY((points[n].y() + yControl[n - 1]) / 2);
160 m_controlPoints[j].setY((points[n].y() + yControl[n - 1]) / 2);
157 }
161 }
158 }
162 }
159 }
163 }
160
164
161 QVector<qreal> QSplineSeriesPrivate::firstControlPoints(const QVector<qreal>& vector)
165 QVector<qreal> QSplineSeriesPrivate::firstControlPoints(const QVector<qreal>& vector)
162 {
166 {
163 QVector<qreal> result;
167 QVector<qreal> result;
164
168
165 int count = vector.count();
169 int count = vector.count();
166 result.resize(count);
170 result.resize(count);
167 result[0] = vector[0] / 2.0;
171 result[0] = vector[0] / 2.0;
168
172
169 QVector<qreal> temp;
173 QVector<qreal> temp;
170 temp.resize(count);
174 temp.resize(count);
171 temp[0] = 0;
175 temp[0] = 0;
172
176
173 qreal b = 2.0;
177 qreal b = 2.0;
174
178
175 for (int i = 1; i < count; i++) {
179 for (int i = 1; i < count; i++) {
176 temp[i] = 1 / b;
180 temp[i] = 1 / b;
177 b = (i < count - 1 ? 4.0 : 3.5) - temp[i];
181 b = (i < count - 1 ? 4.0 : 3.5) - temp[i];
178 result[i]=(vector[i] - result[i - 1]) / b;
182 result[i]=(vector[i] - result[i - 1]) / b;
179 }
183 }
180 for (int i = 1; i < count; i++)
184 for (int i = 1; i < count; i++)
181 result[count - i - 1] -= temp[count - i] * result[count - i];
185 result[count - i - 1] -= temp[count - i] * result[count - i];
182
186
183 return result;
187 return result;
184 }
188 }
185
189
186 QPointF QSplineSeriesPrivate::controlPoint(int index) const
190 QPointF QSplineSeriesPrivate::controlPoint(int index) const
187 {
191 {
188 // Q_D(const QSplineSeries);
192 // Q_D(const QSplineSeries);
189 // return d->m_controlPoints[index];
193 // return d->m_controlPoints[index];
190 return m_controlPoints[index];
194 return m_controlPoints[index];
191 }
195 }
192
196
193 /*!
197 /*!
194 Updates the control points, besed on currently avaiable knots.
198 Updates the control points, besed on currently avaiable knots.
195 */
199 */
196 void QSplineSeriesPrivate::updateControlPoints()
200 void QSplineSeriesPrivate::updateControlPoints()
197 {
201 {
198 Q_Q(QSplineSeries);
202 Q_Q(QSplineSeries);
199 if (q->count() > 1) {
203 if (q->count() > 1) {
200 m_controlPoints.resize(2*q->count()-2);
204 m_controlPoints.resize(2*q->count()-2);
201 calculateControlPoints();
205 calculateControlPoints();
202 }
206 }
203 }
207 }
204
208
205 Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter)
209 Chart* QSplineSeriesPrivate::createGraphics(ChartPresenter* presenter)
206 {
210 {
207 Q_Q(QSplineSeries);
211 Q_Q(QSplineSeries);
208 SplineChartItem* spline = new SplineChartItem(q,presenter);
212 SplineChartItem* spline = new SplineChartItem(q,presenter);
209 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
213 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
210 spline->setAnimator(presenter->animator());
214 spline->setAnimator(presenter->animator());
211 spline->setAnimation(new SplineAnimation(spline));
215 spline->setAnimation(new SplineAnimation(spline));
212 }
216 }
213
217
214 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
218 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
215 return spline;
219 return spline;
216 }
220 }
217
221
218 #include "moc_qsplineseries.cpp"
222 #include "moc_qsplineseries.cpp"
219 #include "moc_qsplineseries_p.cpp"
223 #include "moc_qsplineseries_p.cpp"
220
224
221 QTCOMMERCIALCHART_END_NAMESPACE
225 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,539 +1,541
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "tablewidget.h"
21 #include "tablewidget.h"
22 #include <QGridLayout>
22 #include <QGridLayout>
23 #include <QTableView>
23 #include <QTableView>
24 #include <QChart>
24 #include <QChart>
25 #include <QStyledItemDelegate>
25 #include <QStyledItemDelegate>
26 #include <QLineSeries>
26 #include <QLineSeries>
27 #include <QSplineSeries>
27 #include <QSplineSeries>
28 #include <QScatterSeries>
28 #include <QScatterSeries>
29 #include <QVXYModelMapper>
29 #include <QVXYModelMapper>
30 #include "customtablemodel.h"
30 #include "customtablemodel.h"
31 #include <QPieSeries>
31 #include <QPieSeries>
32 #include <QVPieModelMapper>
32 #include <QVPieModelMapper>
33 #include <QPieSlice>
33 #include <QPieSlice>
34 #include <QAreaSeries>
34 #include <QAreaSeries>
35 #include <QBarSeries>
35 #include <QBarSeries>
36 #include <QGroupedBarSeries>
36 #include <QGroupedBarSeries>
37 #include <QBarSet>
37 #include <QBarSet>
38 #include <QBarModelMapper>
38 #include <QBarModelMapper>
39 #include <QPushButton>
39 #include <QPushButton>
40 #include <QRadioButton>
40 #include <QRadioButton>
41 #include <QLabel>
41 #include <QLabel>
42 #include <QSpinBox>
42 #include <QSpinBox>
43 #include <QTime>
43 #include <QTime>
44 #include <QHeaderView>
44 #include <QHeaderView>
45
45
46 TableWidget::TableWidget(QWidget *parent)
46 TableWidget::TableWidget(QWidget *parent)
47 : QWidget(parent)
47 : QWidget(parent)
48 // specialPie(0)
48 // specialPie(0)
49 {
49 {
50 setGeometry(1900, 100, 1000, 600);
50 setGeometry(1900, 100, 1000, 600);
51 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
51 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
52 // create simple model for storing data
52 // create simple model for storing data
53 // user's table data model
53 // user's table data model
54 m_model = new CustomTableModel;
54 m_model = new CustomTableModel;
55 m_tableView = new QTableView;
55 m_tableView = new QTableView;
56 m_tableView->setModel(m_model);
56 m_tableView->setModel(m_model);
57 // m_tableView->setMinimumHeight(300);
57 // m_tableView->setMinimumHeight(300);
58 m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
58 m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
59 m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
59 m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
60
60
61 m_chart = new QChart;
61 m_chart = new QChart;
62 m_chart->legend()->setVisible(true);
62 m_chart->legend()->setVisible(true);
63 m_chart->setAnimationOptions(QChart::SeriesAnimations);
63 m_chart->setAnimationOptions(QChart::SeriesAnimations);
64 m_chartView = new QChartView(m_chart);
64 m_chartView = new QChartView(m_chart);
65 m_chartView->setRenderHint(QPainter::Antialiasing);
65 m_chartView->setRenderHint(QPainter::Antialiasing);
66 m_chartView->setMinimumSize(640, 480);
66 m_chartView->setMinimumSize(640, 480);
67
67
68 // add, remove data buttons
68 // add, remove data buttons
69 QPushButton* addRowAboveButton = new QPushButton("Add row above");
69 QPushButton* addRowAboveButton = new QPushButton("Add row above");
70 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
70 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
71
71
72 QPushButton* addRowBelowButton = new QPushButton("Add row below");
72 QPushButton* addRowBelowButton = new QPushButton("Add row below");
73 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
73 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
74
74
75 QPushButton* removeRowButton = new QPushButton("Remove row");
75 QPushButton* removeRowButton = new QPushButton("Remove row");
76 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
76 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
77
77
78 QPushButton* addColumnRightButton = new QPushButton("Add column to the right");
78 QPushButton* addColumnRightButton = new QPushButton("Add column to the right");
79 connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight()));
79 connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight()));
80
80
81 QPushButton* removeColumnButton = new QPushButton("Remove column");
81 QPushButton* removeColumnButton = new QPushButton("Remove column");
82 connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn()));
82 connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn()));
83
83
84 QPushButton* specialPieButton = new QPushButton("Add slices using series API");
84 QPushButton* specialPieButton = new QPushButton("Add slices using series API");
85 connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie()));
85 connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie()));
86
86
87 QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API");
87 QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API");
88 connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2()));
88 connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2()));
89
89
90 QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API");
90 QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API");
91 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
91 connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3()));
92
92
93 QPushButton* xyTestButton = new QPushButton("Append XY point");
93 QPushButton* xyTestButton = new QPushButton("Append XY point");
94 connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY()));
94 connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY()));
95
95
96
96
97 QLabel *spinBoxLabel = new QLabel("Rows affected:");
97 QLabel *spinBoxLabel = new QLabel("Rows affected:");
98
98
99 // spin box for setting number of affected items (add, remove)
99 // spin box for setting number of affected items (add, remove)
100 m_linesCountSpinBox = new QSpinBox;
100 m_linesCountSpinBox = new QSpinBox;
101 m_linesCountSpinBox->setRange(1, 10);
101 m_linesCountSpinBox->setRange(1, 10);
102 m_linesCountSpinBox->setValue(1);
102 m_linesCountSpinBox->setValue(1);
103
103
104 // buttons layout
104 // buttons layout
105 QVBoxLayout* buttonsLayout = new QVBoxLayout;
105 QVBoxLayout* buttonsLayout = new QVBoxLayout;
106 buttonsLayout->addWidget(spinBoxLabel);
106 buttonsLayout->addWidget(spinBoxLabel);
107 buttonsLayout->addWidget(m_linesCountSpinBox);
107 buttonsLayout->addWidget(m_linesCountSpinBox);
108 // buttonsLayout->addWidget(addRowAboveButton);
108 // buttonsLayout->addWidget(addRowAboveButton);
109 buttonsLayout->addWidget(addRowBelowButton);
109 buttonsLayout->addWidget(addRowBelowButton);
110 buttonsLayout->addWidget(removeRowButton);
110 buttonsLayout->addWidget(removeRowButton);
111 // buttonsLayout->addWidget(addColumnRightButton);
111 // buttonsLayout->addWidget(addColumnRightButton);
112 // buttonsLayout->addWidget(removeColumnButton);
112 // buttonsLayout->addWidget(removeColumnButton);
113 buttonsLayout->addWidget(specialPieButton);
113 buttonsLayout->addWidget(specialPieButton);
114 buttonsLayout->addWidget(specialPieButton2);
114 buttonsLayout->addWidget(specialPieButton2);
115 buttonsLayout->addWidget(specialPieButton3);
115 buttonsLayout->addWidget(specialPieButton3);
116 buttonsLayout->addWidget(xyTestButton);
116 buttonsLayout->addWidget(xyTestButton);
117 buttonsLayout->addStretch();
117 buttonsLayout->addStretch();
118
118
119 // chart type radio buttons
119 // chart type radio buttons
120 m_lineRadioButton = new QRadioButton("Line");
120 m_lineRadioButton = new QRadioButton("Line");
121 m_splineRadioButton = new QRadioButton("Spline");
121 m_splineRadioButton = new QRadioButton("Spline");
122 m_scatterRadioButton = new QRadioButton("Scatter");
122 m_scatterRadioButton = new QRadioButton("Scatter");
123 m_pieRadioButton = new QRadioButton("Pie");
123 m_pieRadioButton = new QRadioButton("Pie");
124 m_areaRadioButton = new QRadioButton("Area");
124 m_areaRadioButton = new QRadioButton("Area");
125 m_barRadioButton = new QRadioButton("Bar");
125 m_barRadioButton = new QRadioButton("Bar");
126
126
127 connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
127 connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
128 connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
128 connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
129 connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
129 connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
130 connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
130 connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
131 connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
131 connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
132 connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
132 connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool)));
133 m_lineRadioButton->setChecked(true);
133 m_lineRadioButton->setChecked(true);
134
134
135 // radio buttons layout
135 // radio buttons layout
136 QVBoxLayout* radioLayout = new QVBoxLayout;
136 QVBoxLayout* radioLayout = new QVBoxLayout;
137 radioLayout->addWidget(m_lineRadioButton);
137 radioLayout->addWidget(m_lineRadioButton);
138 radioLayout->addWidget(m_splineRadioButton);
138 radioLayout->addWidget(m_splineRadioButton);
139 // radioLayout->addWidget(m_scatterRadioButton);
139 // radioLayout->addWidget(m_scatterRadioButton);
140 radioLayout->addWidget(m_pieRadioButton);
140 radioLayout->addWidget(m_pieRadioButton);
141 // radioLayout->addWidget(m_areaRadioButton);
141 // radioLayout->addWidget(m_areaRadioButton);
142 radioLayout->addWidget(m_barRadioButton);
142 radioLayout->addWidget(m_barRadioButton);
143 radioLayout->addStretch();
143 radioLayout->addStretch();
144
144
145 // create main layout
145 // create main layout
146 QGridLayout* mainLayout = new QGridLayout;
146 QGridLayout* mainLayout = new QGridLayout;
147 mainLayout->addLayout(buttonsLayout, 2, 0);
147 mainLayout->addLayout(buttonsLayout, 2, 0);
148 mainLayout->addLayout(radioLayout, 3, 0);
148 mainLayout->addLayout(radioLayout, 3, 0);
149 mainLayout->addWidget(m_tableView, 1, 0);
149 mainLayout->addWidget(m_tableView, 1, 0);
150 mainLayout->addWidget(m_chartView, 1, 1, 2, 1);
150 mainLayout->addWidget(m_chartView, 1, 1, 2, 1);
151 setLayout(mainLayout);
151 setLayout(mainLayout);
152 m_lineRadioButton->setFocus();
152 m_lineRadioButton->setFocus();
153 }
153 }
154
154
155 void TableWidget::addRowAbove()
155 void TableWidget::addRowAbove()
156 {
156 {
157 m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value());
157 m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value());
158
158
159 }
159 }
160
160
161 void TableWidget::addRowBelow()
161 void TableWidget::addRowBelow()
162 {
162 {
163 m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value());
163 m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value());
164
164
165 }
165 }
166
166
167 void TableWidget::removeRow()
167 void TableWidget::removeRow()
168 {
168 {
169 m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value()));
169 m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value()));
170 }
170 }
171
171
172 void TableWidget::addColumnRight()
172 void TableWidget::addColumnRight()
173 {
173 {
174 m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value());
174 m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value());
175 }
175 }
176
176
177 void TableWidget::removeColumn()
177 void TableWidget::removeColumn()
178 {
178 {
179 m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value()));
179 m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value()));
180 }
180 }
181
181
182 void TableWidget::updateChartType(bool toggle)
182 void TableWidget::updateChartType(bool toggle)
183 {
183 {
184 // this if is needed, so that the function is only called once.
184 // this if is needed, so that the function is only called once.
185 // For the radioButton that was enabled.
185 // For the radioButton that was enabled.
186 if (toggle) {
186 if (toggle) {
187 // specialPie = 0;
187 // specialPie = 0;
188 m_chart->removeAllSeries();
188 m_chart->removeAllSeries();
189 // m_chart->axisX()->setNiceNumbersEnabled(false);
189 // m_chart->axisX()->setNiceNumbersEnabled(false);
190 // m_chart->axisY()->setNiceNumbersEnabled(false);
190 // m_chart->axisY()->setNiceNumbersEnabled(false);
191
191
192 // renable axes of the chart (pie hides them)
192 // renable axes of the chart (pie hides them)
193 // x axis
193 // x axis
194 QAxis *axis = m_chart->axisX();
194 QAxis *axis = m_chart->axisX();
195 axis->setAxisVisible(true);
195 axis->setAxisVisible(true);
196 axis->setGridLineVisible(true);
196 axis->setGridLineVisible(true);
197 axis->setLabelsVisible(true);
197 axis->setLabelsVisible(true);
198
198
199 // y axis
199 // y axis
200 axis = m_chart->axisY();
200 axis = m_chart->axisY();
201 axis->setAxisVisible(true);
201 axis->setAxisVisible(true);
202 axis->setGridLineVisible(true);
202 axis->setGridLineVisible(true);
203 axis->setLabelsVisible(true);
203 axis->setLabelsVisible(true);
204
204
205 m_model->clearMapping();
205 m_model->clearMapping();
206
206
207 QString seriesColorHex = "#000000";
207 QString seriesColorHex = "#000000";
208 // QPen pen;
208 // QPen pen;
209 // pen.setWidth(2);
209 // pen.setWidth(2);
210
210
211 if (m_lineRadioButton->isChecked())
211 if (m_lineRadioButton->isChecked())
212 {
212 {
213 m_chart->setAnimationOptions(QChart::NoAnimation);
213 m_chart->setAnimationOptions(QChart::NoAnimation);
214
214
215 // series 1
215 // series 1
216 m_series = new QLineSeries(this);
216 m_series = new QLineSeries(this);
217
217
218 QVXYModelMapper *mapper = new QVXYModelMapper;
218 QVXYModelMapper *mapper = new QVXYModelMapper;
219 mapper->setModel(m_model);
219 mapper->setModel(m_model);
220 mapper->setSeries(m_series);
220 mapper->setSeries(m_series);
221 mapper->setXColumn(0);
221 mapper->setXColumn(0);
222 mapper->setYColumn(1);
222 mapper->setYColumn(1);
223 mapper->setFirst(3);
223 mapper->setFirst(3);
224 mapper->setCount(4);
224 mapper->setCount(4);
225
225
226 // m_series->setModelMapping(0,1, Qt::Vertical);
226 // m_series->setModelMapping(0,1, Qt::Vertical);
227 // m_series->setModelMappingRange(3, 4);
227 // m_series->setModelMappingRange(3, 4);
228 m_chart->addSeries(m_series);
228 m_chart->addSeries(m_series);
229 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
229 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
230 m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4));
230 m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4));
231
231
232 // // series 2
232 // // series 2
233 // m_series = new QLineSeries;
233 // m_series = new QLineSeries;
234 // m_series->setModel(m_model);
234 // m_series->setModel(m_model);
235
235
236 // mapper = new QXYModelMapper;
236 // mapper = new QXYModelMapper;
237 // mapper->setMapX(3);
237 // mapper->setMapX(3);
238 // mapper->setMapY(4);
238 // mapper->setMapY(4);
239 // // mapper->setFirst(3);
239 // // mapper->setFirst(3);
240 // // mapper->setCount(4);
240 // // mapper->setCount(4);
241 // m_series->setModelMapper(mapper);
241 // m_series->setModelMapper(mapper);
242 // // m_series->setModelMapping(2,3, Qt::Vertical);
242 // // m_series->setModelMapping(2,3, Qt::Vertical);
243 // m_chart->addSeries(m_series);
243 // m_chart->addSeries(m_series);
244 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
244 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
245 // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000));
245 // m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000));
246
246
247 // // series 3
247 // // series 3
248 // m_series = new QLineSeries;
248 // m_series = new QLineSeries;
249 // m_series->setModel(m_model);
249 // m_series->setModel(m_model);
250
250
251 // mapper = new QXYModelMapper;
251 // mapper = new QXYModelMapper;
252 // mapper->setMapX(5);
252 // mapper->setMapX(5);
253 // mapper->setMapY(6);
253 // mapper->setMapY(6);
254 // mapper->setFirst(2);
254 // mapper->setFirst(2);
255 // mapper->setCount(-1);
255 // mapper->setCount(-1);
256 // m_series->setModelMapper(mapper);
256 // m_series->setModelMapper(mapper);
257 // // m_series->setModelMapping(4,5, Qt::Vertical);
257 // // m_series->setModelMapping(4,5, Qt::Vertical);
258 // // m_series->setModelMappingRange(2, -1);
258 // // m_series->setModelMappingRange(2, -1);
259 // m_chart->addSeries(m_series);
259 // m_chart->addSeries(m_series);
260 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
260 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
261 // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000));
261 // m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000));
262 }
262 }
263 else if (m_splineRadioButton->isChecked())
263 else if (m_splineRadioButton->isChecked())
264 {
264 {
265 // m_chart->setAnimationOptions(QChart::NoAnimation);
265 m_chart->setAnimationOptions(QChart::NoAnimation);
266
266
267 // // series 1
267 // series 1
268 // m_series = new QSplineSeries;
268 m_series = new QSplineSeries;
269 // m_series->setModel(m_model);
269 // m_series->setModel(m_model);
270
270
271 // QXYModelMapper *mapper = new QXYModelMapper;
271 QVXYModelMapper *mapper = new QVXYModelMapper;
272 // mapper->setMapX(0);
272 mapper->setSeries(m_series);
273 // mapper->setMapY(1);
273 mapper->setModel(m_model);
274 // mapper->setFirst(0);
274 mapper->setXColumn(0);
275 // mapper->setCount(-1);
275 mapper->setYColumn(1);
276 mapper->setFirst(0);
277 mapper->setCount(-1);
276
278
277 // m_series->setModelMapper(mapper);
279 // m_series->setModelMapper(mapper);
278
280
279 // m_chart->addSeries(m_series);
281 m_chart->addSeries(m_series);
280 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
282 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
281 // m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000));
283 m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000));
282
284
283 // // series 2
285 // // series 2
284 // m_series = new QSplineSeries;
286 // m_series = new QSplineSeries;
285 // m_series->setModel(m_model);
287 // m_series->setModel(m_model);
286
288
287 // mapper = new QXYModelMapper;
289 // mapper = new QXYModelMapper;
288 // mapper->setMapX(2);
290 // mapper->setMapX(2);
289 // mapper->setMapY(3);
291 // mapper->setMapY(3);
290 // mapper->setFirst(2);
292 // mapper->setFirst(2);
291 // mapper->setCount(4);
293 // mapper->setCount(4);
292
294
293 // m_series->setModelMapper(mapper);
295 // m_series->setModelMapper(mapper);
294
296
295 // m_chart->addSeries(m_series);
297 // m_chart->addSeries(m_series);
296 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
298 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
297 // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4));
299 // m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4));
298
300
299 // // series 3
301 // // series 3
300 // m_series = new QSplineSeries;
302 // m_series = new QSplineSeries;
301 // m_series->setModel(m_model);
303 // m_series->setModel(m_model);
302
304
303 // mapper = new QXYModelMapper;
305 // mapper = new QXYModelMapper;
304 // mapper->setMapX(4);
306 // mapper->setMapX(4);
305 // mapper->setMapY(5);
307 // mapper->setMapY(5);
306 // mapper->setFirst(2);
308 // mapper->setFirst(2);
307 // mapper->setCount(-1);
309 // mapper->setCount(-1);
308
310
309 // m_series->setModelMapper(mapper);
311 // m_series->setModelMapper(mapper);
310
312
311 // m_chart->addSeries(m_series);
313 // m_chart->addSeries(m_series);
312 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
314 // seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
313 // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
315 // m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
314 }
316 }
315 // else if (m_scatterRadioButton->isChecked())
317 // else if (m_scatterRadioButton->isChecked())
316 // {
318 // {
317 // m_chart->setAnimationOptions(QChart::NoAnimation);
319 // m_chart->setAnimationOptions(QChart::NoAnimation);
318
320
319 // // series 1
321 // // series 1
320 // m_series = new QScatterSeries;
322 // m_series = new QScatterSeries;
321 // m_series->setModel(m_model);
323 // m_series->setModel(m_model);
322 // m_series->setModelMapping(0,1, Qt::Vertical);
324 // m_series->setModelMapping(0,1, Qt::Vertical);
323 // // m_series->setModelMappingRange(2, 0);
325 // // m_series->setModelMappingRange(2, 0);
324 // // series->setModelMapping(0,1, Qt::Horizontal);
326 // // series->setModelMapping(0,1, Qt::Horizontal);
325 // m_chart->addSeries(m_series);
327 // m_chart->addSeries(m_series);
326
328
327 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
329 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
328 // m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000));
330 // m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000));
329
331
330 // // series 2
332 // // series 2
331 // m_series = new QScatterSeries;
333 // m_series = new QScatterSeries;
332 // m_series->setModel(m_model);
334 // m_series->setModel(m_model);
333 // m_series->setModelMapping(2,3, Qt::Vertical);
335 // m_series->setModelMapping(2,3, Qt::Vertical);
334 // // m_series->setModelMappingRange(1, 6);
336 // // m_series->setModelMappingRange(1, 6);
335 // // series->setModelMapping(2,3, Qt::Horizontal);
337 // // series->setModelMapping(2,3, Qt::Horizontal);
336 // m_chart->addSeries(m_series);
338 // m_chart->addSeries(m_series);
337
339
338 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
340 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
339 // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6));
341 // m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6));
340
342
341 // // series 3
343 // // series 3
342 // m_series = new QScatterSeries;
344 // m_series = new QScatterSeries;
343 // m_series->setModel(m_model);
345 // m_series->setModel(m_model);
344 // m_series->setModelMapping(4,5, Qt::Vertical);
346 // m_series->setModelMapping(4,5, Qt::Vertical);
345 // // series->setModelMapping(4,5, Qt::Horizontal);
347 // // series->setModelMapping(4,5, Qt::Horizontal);
346 // m_chart->addSeries(m_series);
348 // m_chart->addSeries(m_series);
347 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
349 // seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
348 // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000));
350 // m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000));
349 // }
351 // }
350 else if (m_pieRadioButton->isChecked())
352 else if (m_pieRadioButton->isChecked())
351 {
353 {
352 m_chart->setAnimationOptions(QChart::SeriesAnimations);
354 m_chart->setAnimationOptions(QChart::SeriesAnimations);
353
355
354 // pie 1
356 // pie 1
355 m_pieSeries = new QPieSeries;
357 m_pieSeries = new QPieSeries;
356
358
357 m_pieMapper = new QVPieModelMapper;
359 m_pieMapper = new QVPieModelMapper;
358 m_pieMapper->setValuesColumn(1);
360 m_pieMapper->setValuesColumn(1);
359 m_pieMapper->setLabelsColumn(7);
361 m_pieMapper->setLabelsColumn(7);
360 m_pieMapper->setSeries(m_pieSeries);
362 m_pieMapper->setSeries(m_pieSeries);
361 m_pieMapper->setModel(m_model);
363 m_pieMapper->setModel(m_model);
362 m_pieMapper->setFirst(2);
364 m_pieMapper->setFirst(2);
363 // m_pieMapper->setCount(5);
365 // m_pieMapper->setCount(5);
364 // pieSeries->setModelMapper(mapper);
366 // pieSeries->setModelMapper(mapper);
365
367
366 m_pieSeries->setLabelsVisible(true);
368 m_pieSeries->setLabelsVisible(true);
367 m_pieSeries->setPieSize(0.35);
369 m_pieSeries->setPieSize(0.35);
368 m_pieSeries->setHorizontalPosition(0.25);
370 m_pieSeries->setHorizontalPosition(0.25);
369 m_pieSeries->setVerticalPosition(0.35);
371 m_pieSeries->setVerticalPosition(0.35);
370
372
371 m_chart->addSeries(m_pieSeries);
373 m_chart->addSeries(m_pieSeries);
372 seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
374 seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
373 m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50));
375 m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50));
374
376
375
377
376 // pieSeries->slices().at(0)->setValue(400);
378 // pieSeries->slices().at(0)->setValue(400);
377 // pieSeries->slices().at(0)->setLabel(QString("36"));
379 // pieSeries->slices().at(0)->setLabel(QString("36"));
378
380
379 // pie 2
381 // pie 2
380 m_pieSeries2 = new QPieSeries;
382 m_pieSeries2 = new QPieSeries;
381
383
382 m_pieMapper = new QVPieModelMapper;
384 m_pieMapper = new QVPieModelMapper;
383 m_pieMapper->setValuesColumn(0);
385 m_pieMapper->setValuesColumn(0);
384 m_pieMapper->setLabelsColumn(7);
386 m_pieMapper->setLabelsColumn(7);
385 m_pieMapper->setModel(m_model);
387 m_pieMapper->setModel(m_model);
386 m_pieMapper->setSeries(m_pieSeries2);
388 m_pieMapper->setSeries(m_pieSeries2);
387 m_pieMapper->setFirst(2);
389 m_pieMapper->setFirst(2);
388
390
389 m_pieSeries2->setLabelsVisible(true);
391 m_pieSeries2->setLabelsVisible(true);
390 m_pieSeries2->setPieSize(0.35);
392 m_pieSeries2->setPieSize(0.35);
391 m_pieSeries2->setHorizontalPosition(0.75);
393 m_pieSeries2->setHorizontalPosition(0.75);
392 m_pieSeries2->setVerticalPosition(0.65);
394 m_pieSeries2->setVerticalPosition(0.65);
393 m_chart->addSeries(m_pieSeries2);
395 m_chart->addSeries(m_pieSeries2);
394 seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
396 seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
395 m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000));
397 m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000));
396
398
397 // // pie 3
399 // // pie 3
398 // pieSeries = new QPieSeries;
400 // pieSeries = new QPieSeries;
399 // pieSeries->setModel(m_model);
401 // pieSeries->setModel(m_model);
400 // pieSeries->setModelMapping(2,2, Qt::Vertical);
402 // pieSeries->setModelMapping(2,2, Qt::Vertical);
401 // pieSeries->setLabelsVisible(true);
403 // pieSeries->setLabelsVisible(true);
402 // pieSeries->setPieSize(0.35);
404 // pieSeries->setPieSize(0.35);
403 // pieSeries->setHorizontalPosition(0.5);
405 // pieSeries->setHorizontalPosition(0.5);
404 // pieSeries->setVerticalPosition(0.75);
406 // pieSeries->setVerticalPosition(0.75);
405 // m_chart->addSeries(pieSeries);
407 // m_chart->addSeries(pieSeries);
406 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
408 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
407 // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
409 // m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000));
408
410
409 // // special pie
411 // // special pie
410 // specialPie = new QPieSeries;
412 // specialPie = new QPieSeries;
411 // specialPie->append(17, "1");
413 // specialPie->append(17, "1");
412 // specialPie->append(45, "2");
414 // specialPie->append(45, "2");
413 // specialPie->append(77, "3");
415 // specialPie->append(77, "3");
414 // specialPie->append(37, "4");
416 // specialPie->append(37, "4");
415 // specialPie->append(27, "5");
417 // specialPie->append(27, "5");
416 // specialPie->append(47, "6");
418 // specialPie->append(47, "6");
417 // specialPie->setPieSize(0.35);
419 // specialPie->setPieSize(0.35);
418 // specialPie->setHorizontalPosition(0.8);
420 // specialPie->setHorizontalPosition(0.8);
419 // specialPie->setVerticalPosition(0.75);
421 // specialPie->setVerticalPosition(0.75);
420 // specialPie->setLabelsVisible(true);
422 // specialPie->setLabelsVisible(true);
421 // m_chart->addSeries(specialPie);
423 // m_chart->addSeries(specialPie);
422 }
424 }
423 // else if (m_areaRadioButton->isChecked())
425 // else if (m_areaRadioButton->isChecked())
424 // {
426 // {
425 // m_chart->setAnimationOptions(QChart::NoAnimation);
427 // m_chart->setAnimationOptions(QChart::NoAnimation);
426
428
427 // QLineSeries* upperLineSeries = new QLineSeries;
429 // QLineSeries* upperLineSeries = new QLineSeries;
428 // upperLineSeries->setModel(m_model);
430 // upperLineSeries->setModel(m_model);
429 // upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
431 // upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
430 // // upperLineSeries->setModelMappingRange(1, 5);
432 // // upperLineSeries->setModelMappingRange(1, 5);
431 // QLineSeries* lowerLineSeries = new QLineSeries;
433 // QLineSeries* lowerLineSeries = new QLineSeries;
432 // lowerLineSeries->setModel(m_model);
434 // lowerLineSeries->setModel(m_model);
433 // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
435 // lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
434 // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
436 // QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
435 // m_chart->addSeries(areaSeries);
437 // m_chart->addSeries(areaSeries);
436 // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper();
438 // seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper();
437 // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5));
439 // m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5));
438 // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
440 // m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
439 // }
441 // }
440 else if (m_barRadioButton->isChecked())
442 else if (m_barRadioButton->isChecked())
441 {
443 {
442 // m_chart->setAnimationOptions(QChart::SeriesAnimations);
444 // m_chart->setAnimationOptions(QChart::SeriesAnimations);
443
445
444 // QGroupedBarSeries* barSeries = new QGroupedBarSeries();
446 // QGroupedBarSeries* barSeries = new QGroupedBarSeries();
445 // barSeries->setCategories(QStringList());
447 // barSeries->setCategories(QStringList());
446 // barSeries->setModel(m_model);
448 // barSeries->setModel(m_model);
447 // // barSeries->setModelMappingRange(2, 5);
449 // // barSeries->setModelMappingRange(2, 5);
448 //// barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
450 //// barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
449
451
450 // QBarModelMapper *mapper = new QBarModelMapper;
452 // QBarModelMapper *mapper = new QBarModelMapper;
451 // mapper->setMapCategories(5);
453 // mapper->setMapCategories(5);
452 // mapper->setMapBarBottom(2);
454 // mapper->setMapBarBottom(2);
453 // mapper->setMapBarTop(4);
455 // mapper->setMapBarTop(4);
454 // barSeries->setModelMapper(mapper);
456 // barSeries->setModelMapper(mapper);
455 // m_chart->addSeries(barSeries);
457 // m_chart->addSeries(barSeries);
456 // QList<QBarSet*> barsets = barSeries->barSets();
458 // QList<QBarSet*> barsets = barSeries->barSets();
457 // for (int i = 0; i < barsets.count(); i++) {
459 // for (int i = 0; i < barsets.count(); i++) {
458 // seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
460 // seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
459 // m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000));
461 // m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000));
460 // }
462 // }
461 }
463 }
462
464
463
465
464 if (!m_barRadioButton->isChecked()) {
466 if (!m_barRadioButton->isChecked()) {
465 m_chart->axisX()->setRange(0, 500);
467 m_chart->axisX()->setRange(0, 500);
466 m_chart->axisY()->setRange(0, 220);
468 m_chart->axisY()->setRange(0, 220);
467 }
469 }
468 m_chart->legend()->setVisible(true);
470 m_chart->legend()->setVisible(true);
469
471
470 // repaint table view colors
472 // repaint table view colors
471 m_tableView->repaint();
473 m_tableView->repaint();
472 m_tableView->setFocus();
474 m_tableView->setFocus();
473 }
475 }
474 }
476 }
475
477
476 void TableWidget::testPie()
478 void TableWidget::testPie()
477 {
479 {
478 // m_pieMapper->setCount(-1);
480 // m_pieMapper->setCount(-1);
479 QPieSlice *slice = new QPieSlice("Hehe", 145);
481 QPieSlice *slice = new QPieSlice("Hehe", 145);
480 slice->setLabelVisible();
482 slice->setLabelVisible();
481 m_pieSeries->append(slice);
483 m_pieSeries->append(slice);
482
484
483 slice = new QPieSlice("Hoho", 34);
485 slice = new QPieSlice("Hoho", 34);
484 slice->setLabelVisible();
486 slice->setLabelVisible();
485 m_pieSeries->append(slice);
487 m_pieSeries->append(slice);
486 // m_series->modelMapper()->setMapX(4);
488 // m_series->modelMapper()->setMapX(4);
487 // m_tableView->setColumnWidth(10, 250);
489 // m_tableView->setColumnWidth(10, 250);
488 // if (specialPie) {
490 // if (specialPie) {
489 // specialPie->remove(specialPie->slices().at(2));
491 // specialPie->remove(specialPie->slices().at(2));
490 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
492 // // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2));
491 // specialPie->append(4, "heloo");
493 // specialPie->append(4, "heloo");
492 // }
494 // }
493 }
495 }
494
496
495 void TableWidget::testPie2()
497 void TableWidget::testPie2()
496 {
498 {
497 QPieSlice *slice;
499 QPieSlice *slice;
498 if (m_pieSeries->count() > 0) {
500 if (m_pieSeries->count() > 0) {
499 slice = m_pieSeries->slices().last();
501 slice = m_pieSeries->slices().last();
500 m_pieSeries->remove(slice);
502 m_pieSeries->remove(slice);
501 }
503 }
502
504
503 if (m_pieSeries->count() > 0) {
505 if (m_pieSeries->count() > 0) {
504 slice = m_pieSeries->slices().first();
506 slice = m_pieSeries->slices().first();
505 m_pieSeries->remove(slice);
507 m_pieSeries->remove(slice);
506 }
508 }
507 }
509 }
508
510
509 void TableWidget::testPie3()
511 void TableWidget::testPie3()
510 {
512 {
511 QPieSlice *slice;
513 QPieSlice *slice;
512 if (m_pieSeries->count() > 0) {
514 if (m_pieSeries->count() > 0) {
513 slice = m_pieSeries->slices().last();
515 slice = m_pieSeries->slices().last();
514 slice->setLabel("Dalej");
516 slice->setLabel("Dalej");
515 slice->setValue(222);
517 slice->setValue(222);
516 }
518 }
517
519
518 if (m_pieSeries->count() > 0) {
520 if (m_pieSeries->count() > 0) {
519 slice = m_pieSeries->slices().first();
521 slice = m_pieSeries->slices().first();
520 slice->setLabel("Prawie");
522 slice->setLabel("Prawie");
521 slice->setValue(111);
523 slice->setValue(111);
522 }
524 }
523 }
525 }
524
526
525 void TableWidget::testXY()
527 void TableWidget::testXY()
526 {
528 {
527 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
529 // if (m_series->type() != QAbstractSeries::SeriesTypeLine) {
528 // m_series->append(QPointF(150, 75));
530 // m_series->append(QPointF(150, 75));
529 // }
531 // }
530
532
531 if (m_series->count() > 0) {
533 if (m_series->count() > 0) {
532 m_series->remove(m_series->points().last());
534 m_series->remove(m_series->points().last());
533 }
535 }
534 }
536 }
535
537
536 TableWidget::~TableWidget()
538 TableWidget::~TableWidget()
537 {
539 {
538
540
539 }
541 }
General Comments 0
You need to be logged in to leave comments. Login now