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