@@ -1,224 +1,224 | |||||
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 "mainwidget.h" |
|
21 | #include "mainwidget.h" | |
22 | #include <QChart> |
|
22 | #include <QChart> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QPushButton> |
|
24 | #include <QPushButton> | |
25 | #include <QLabel> |
|
25 | #include <QLabel> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 | #include <QBarSet> |
|
27 | #include <QBarSet> | |
28 | #include <QBarSeries> |
|
28 | #include <QBarSeries> | |
29 | #include <QLegend> |
|
29 | #include <QLegend> | |
30 | #include <QFormLayout> |
|
30 | #include <QFormLayout> | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
32 | QTCOMMERCIALCHART_USE_NAMESPACE | |
33 |
|
33 | |||
34 | MainWidget::MainWidget(QWidget *parent) : |
|
34 | MainWidget::MainWidget(QWidget *parent) : | |
35 | QWidget(parent) |
|
35 | QWidget(parent) | |
36 | { |
|
36 | { | |
37 | // Create buttons for ui |
|
37 | // Create buttons for ui | |
38 | m_buttonLayout = new QGridLayout(); |
|
38 | m_buttonLayout = new QGridLayout(); | |
39 | QPushButton *detachLegendButton = new QPushButton("detach legend"); |
|
39 | QPushButton *detachLegendButton = new QPushButton("detach legend"); | |
40 | connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(detachLegend())); |
|
40 | connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(detachLegend())); | |
41 | m_buttonLayout->addWidget(detachLegendButton, 0, 0); |
|
41 | m_buttonLayout->addWidget(detachLegendButton, 0, 0); | |
42 | QPushButton *attachLegendButton = new QPushButton("attach legend"); |
|
42 | QPushButton *attachLegendButton = new QPushButton("attach legend"); | |
43 | connect(attachLegendButton, SIGNAL(clicked()), this, SLOT(attachLegend())); |
|
43 | connect(attachLegendButton, SIGNAL(clicked()), this, SLOT(attachLegend())); | |
44 | m_buttonLayout->addWidget(attachLegendButton, 1, 0); |
|
44 | m_buttonLayout->addWidget(attachLegendButton, 1, 0); | |
45 |
|
45 | |||
46 | QPushButton *addSetButton = new QPushButton("add barset"); |
|
46 | QPushButton *addSetButton = new QPushButton("add barset"); | |
47 | connect(addSetButton, SIGNAL(clicked()), this, SLOT(addBarset())); |
|
47 | connect(addSetButton, SIGNAL(clicked()), this, SLOT(addBarset())); | |
48 | m_buttonLayout->addWidget(addSetButton, 2, 0); |
|
48 | m_buttonLayout->addWidget(addSetButton, 2, 0); | |
49 | QPushButton *removeBarsetButton = new QPushButton("remove barset"); |
|
49 | QPushButton *removeBarsetButton = new QPushButton("remove barset"); | |
50 | connect(removeBarsetButton, SIGNAL(clicked()), this, SLOT(removeBarset())); |
|
50 | connect(removeBarsetButton, SIGNAL(clicked()), this, SLOT(removeBarset())); | |
51 | m_buttonLayout->addWidget(removeBarsetButton, 3, 0); |
|
51 | m_buttonLayout->addWidget(removeBarsetButton, 3, 0); | |
52 |
|
52 | |||
53 | QPushButton *leftButton = new QPushButton("Align legend left"); |
|
53 | QPushButton *leftButton = new QPushButton("Align legend left"); | |
54 | connect(leftButton, SIGNAL(clicked()), this, SLOT(setLegendLeft())); |
|
54 | connect(leftButton, SIGNAL(clicked()), this, SLOT(setLegendLeft())); | |
55 | m_buttonLayout->addWidget(leftButton, 4, 0); |
|
55 | m_buttonLayout->addWidget(leftButton, 4, 0); | |
56 |
|
56 | |||
57 | QPushButton *rightButton = new QPushButton("Align legend right"); |
|
57 | QPushButton *rightButton = new QPushButton("Align legend right"); | |
58 | connect(rightButton, SIGNAL(clicked()), this, SLOT(setLegendRight())); |
|
58 | connect(rightButton, SIGNAL(clicked()), this, SLOT(setLegendRight())); | |
59 | m_buttonLayout->addWidget(rightButton, 5, 0); |
|
59 | m_buttonLayout->addWidget(rightButton, 5, 0); | |
60 |
|
60 | |||
61 | QPushButton *topButton = new QPushButton("Align legend top"); |
|
61 | QPushButton *topButton = new QPushButton("Align legend top"); | |
62 | connect(topButton, SIGNAL(clicked()), this, SLOT(setLegendTop())); |
|
62 | connect(topButton, SIGNAL(clicked()), this, SLOT(setLegendTop())); | |
63 | m_buttonLayout->addWidget(topButton, 6, 0); |
|
63 | m_buttonLayout->addWidget(topButton, 6, 0); | |
64 |
|
64 | |||
65 | QPushButton *bottomButton = new QPushButton("Align legend bottom"); |
|
65 | QPushButton *bottomButton = new QPushButton("Align legend bottom"); | |
66 | connect(bottomButton, SIGNAL(clicked()), this, SLOT(setLegendBottom())); |
|
66 | connect(bottomButton, SIGNAL(clicked()), this, SLOT(setLegendBottom())); | |
67 | m_buttonLayout->addWidget(bottomButton, 7, 0); |
|
67 | m_buttonLayout->addWidget(bottomButton, 7, 0); | |
68 |
|
68 | |||
69 | m_legendPosX = new QDoubleSpinBox(); |
|
69 | m_legendPosX = new QDoubleSpinBox(); | |
70 | m_legendPosY = new QDoubleSpinBox(); |
|
70 | m_legendPosY = new QDoubleSpinBox(); | |
71 | m_legendWidth = new QDoubleSpinBox(); |
|
71 | m_legendWidth = new QDoubleSpinBox(); | |
72 | m_legendHeight = new QDoubleSpinBox(); |
|
72 | m_legendHeight = new QDoubleSpinBox(); | |
73 |
|
73 | |||
74 | connect(m_legendPosX, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
74 | connect(m_legendPosX, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
75 | connect(m_legendPosY, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
75 | connect(m_legendPosY, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
76 | connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
76 | connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
77 | connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
77 | connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
78 |
|
78 | |||
79 | QFormLayout* legendLayout = new QFormLayout(); |
|
79 | QFormLayout* legendLayout = new QFormLayout(); | |
80 | legendLayout->addRow("Horizontal position", m_legendPosX); |
|
80 | legendLayout->addRow("Horizontal position", m_legendPosX); | |
81 | legendLayout->addRow("Vertical position", m_legendPosY); |
|
81 | legendLayout->addRow("Vertical position", m_legendPosY); | |
82 | legendLayout->addRow("Width", m_legendWidth); |
|
82 | legendLayout->addRow("Width", m_legendWidth); | |
83 | legendLayout->addRow("Height", m_legendHeight); |
|
83 | legendLayout->addRow("Height", m_legendHeight); | |
84 | m_legendSettings = new QGroupBox("Detached legend"); |
|
84 | m_legendSettings = new QGroupBox("Detached legend"); | |
85 | m_legendSettings->setLayout(legendLayout); |
|
85 | m_legendSettings->setLayout(legendLayout); | |
86 | m_buttonLayout->addWidget(m_legendSettings); |
|
86 | m_buttonLayout->addWidget(m_legendSettings); | |
87 | m_legendSettings->setVisible(false); |
|
87 | m_legendSettings->setVisible(false); | |
88 |
|
88 | |||
89 | // Create chart view with the chart |
|
89 | // Create chart view with the chart | |
90 | m_chart = new QChart(); |
|
90 | m_chart = new QChart(); | |
91 | m_chartView = new QChartView(m_chart, this); |
|
91 | m_chartView = new QChartView(m_chart, this); | |
92 |
|
92 | |||
93 | // Create layout for grid and detached legend |
|
93 | // Create layout for grid and detached legend | |
94 | m_mainLayout = new QGridLayout(); |
|
94 | m_mainLayout = new QGridLayout(); | |
95 | m_mainLayout->addLayout(m_buttonLayout, 0, 0); |
|
95 | m_mainLayout->addLayout(m_buttonLayout, 0, 0); | |
96 | m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
96 | m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
97 | setLayout(m_mainLayout); |
|
97 | setLayout(m_mainLayout); | |
98 |
|
98 | |||
99 | createSeries(); |
|
99 | createSeries(); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | void MainWidget::createSeries() |
|
102 | void MainWidget::createSeries() | |
103 | { |
|
103 | { | |
104 | m_series = new QBarSeries(); |
|
104 | m_series = new QBarSeries(); | |
105 | addBarset(); |
|
105 | addBarset(); | |
106 | addBarset(); |
|
106 | addBarset(); | |
107 | addBarset(); |
|
107 | addBarset(); | |
108 | addBarset(); |
|
108 | addBarset(); | |
109 |
|
109 | |||
110 | m_chart->addSeries(m_series); |
|
110 | m_chart->addSeries(m_series); | |
111 | m_chart->setTitle("Legend detach example"); |
|
111 | m_chart->setTitle("Legend detach example"); | |
112 | //![1] |
|
112 | //![1] | |
113 | m_chart->legend()->setVisible(true); |
|
113 | m_chart->legend()->setVisible(true); | |
114 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
114 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |
115 | //![1] |
|
115 | //![1] | |
116 |
|
116 | |||
117 | m_chart->axisY()->setNiceNumbersEnabled(true); |
|
117 | m_chart->axisY()->setNiceNumbersEnabled(true); | |
118 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
118 | m_chartView->setRenderHint(QPainter::Antialiasing); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | void MainWidget::showLegendSpinbox() |
|
121 | void MainWidget::showLegendSpinbox() | |
122 | { |
|
122 | { | |
123 | m_legendSettings->setVisible(true); |
|
123 | m_legendSettings->setVisible(true); | |
124 | QRectF chartViewRect = m_chartView->rect(); |
|
124 | QRectF chartViewRect = m_chartView->rect(); | |
125 | QRectF legendRect = m_chart->legend()->boundingRect(); |
|
125 | QRectF legendRect = m_chart->legend()->boundingRect(); | |
126 |
|
126 | |||
127 | m_legendPosX->setMinimum(0); |
|
127 | m_legendPosX->setMinimum(0); | |
128 | m_legendPosX->setMaximum(chartViewRect.width()); |
|
128 | m_legendPosX->setMaximum(chartViewRect.width()); | |
129 | m_legendPosX->setValue(150); |
|
129 | m_legendPosX->setValue(150); | |
130 |
|
130 | |||
131 | m_legendPosY->setMinimum(0); |
|
131 | m_legendPosY->setMinimum(0); | |
132 | m_legendPosY->setMaximum(chartViewRect.height()); |
|
132 | m_legendPosY->setMaximum(chartViewRect.height()); | |
133 | m_legendPosY->setValue(150); |
|
133 | m_legendPosY->setValue(150); | |
134 |
|
134 | |||
135 | m_legendWidth->setMinimum(0); |
|
135 | m_legendWidth->setMinimum(0); | |
136 | m_legendWidth->setMaximum(chartViewRect.width()); |
|
136 | m_legendWidth->setMaximum(chartViewRect.width()); | |
137 | m_legendWidth->setValue(150); |
|
137 | m_legendWidth->setValue(150); | |
138 |
|
138 | |||
139 | m_legendHeight->setMinimum(0); |
|
139 | m_legendHeight->setMinimum(0); | |
140 | m_legendHeight->setMaximum(chartViewRect.height()); |
|
140 | m_legendHeight->setMaximum(chartViewRect.height()); | |
141 | m_legendHeight->setValue(75); |
|
141 | m_legendHeight->setValue(75); | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | void MainWidget::hideLegendSpinbox() |
|
144 | void MainWidget::hideLegendSpinbox() | |
145 | { |
|
145 | { | |
146 | m_legendSettings->setVisible(false); |
|
146 | m_legendSettings->setVisible(false); | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 |
|
149 | |||
150 | void MainWidget::detachLegend() |
|
150 | void MainWidget::detachLegend() | |
151 | { |
|
151 | { | |
152 | //![2] |
|
152 | //![2] | |
153 | QLegend *legend = m_chart->legend(); |
|
153 | QLegend *legend = m_chart->legend(); | |
154 | legend->detachFromChart(); |
|
154 | legend->detachFromChart(); | |
155 |
|
155 | |||
156 | m_chart->legend()->setBackgroundVisible(true); |
|
156 | m_chart->legend()->setBackgroundVisible(true); | |
157 | m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128))); |
|
157 | m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128))); | |
158 | m_chart->legend()->setPen(QPen(QColor(192,192,192,192))); |
|
158 | m_chart->legend()->setPen(QPen(QColor(192,192,192,192))); | |
159 | //![2] |
|
159 | //![2] | |
160 |
|
160 | |||
161 | showLegendSpinbox(); |
|
161 | showLegendSpinbox(); | |
162 | updateLegendLayout(); |
|
162 | updateLegendLayout(); | |
163 | update(); |
|
163 | update(); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 |
|
166 | |||
167 | void MainWidget::attachLegend() |
|
167 | void MainWidget::attachLegend() | |
168 | { |
|
168 | { | |
169 | //![3] |
|
169 | //![3] | |
170 | QLegend *legend = m_chart->legend(); |
|
170 | QLegend *legend = m_chart->legend(); | |
171 | legend->attachToChart(); |
|
171 | legend->attachToChart(); | |
172 | m_chart->legend()->setBackgroundVisible(false); |
|
172 | m_chart->legend()->setBackgroundVisible(false); | |
173 | //![3] |
|
173 | //![3] | |
174 |
|
174 | |||
175 | hideLegendSpinbox(); |
|
175 | hideLegendSpinbox(); | |
176 | update(); |
|
176 | update(); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | void MainWidget::addBarset() |
|
179 | void MainWidget::addBarset() | |
180 | { |
|
180 | { | |
181 |
QBarSet *barSet = new QBarSet(QString("set ") + QString::number(m_series-> |
|
181 | QBarSet *barSet = new QBarSet(QString("set ") + QString::number(m_series->count())); | |
182 |
qreal delta = m_series-> |
|
182 | qreal delta = m_series->count() * 0.1; | |
183 | *barSet << QPointF(0.0 + delta, 1 + delta) << QPointF(1.0 + delta, 2 + delta) << QPointF(2.0 + delta, 3 + delta) << QPointF(3.0 + delta, 4 + delta); |
|
183 | *barSet << QPointF(0.0 + delta, 1 + delta) << QPointF(1.0 + delta, 2 + delta) << QPointF(2.0 + delta, 3 + delta) << QPointF(3.0 + delta, 4 + delta); | |
184 | m_series->append(barSet); |
|
184 | m_series->append(barSet); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | void MainWidget::removeBarset() |
|
187 | void MainWidget::removeBarset() | |
188 | { |
|
188 | { | |
189 | QList<QBarSet*> sets = m_series->barSets(); |
|
189 | QList<QBarSet*> sets = m_series->barSets(); | |
190 | if (sets.count() > 0) { |
|
190 | if (sets.count() > 0) { | |
191 | m_series->remove(sets.at(sets.count()-1)); |
|
191 | m_series->remove(sets.at(sets.count()-1)); | |
192 | } |
|
192 | } | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | void MainWidget::setLegendLeft() |
|
195 | void MainWidget::setLegendLeft() | |
196 | { |
|
196 | { | |
197 | m_chart->legend()->setAlignment(Qt::AlignLeft); |
|
197 | m_chart->legend()->setAlignment(Qt::AlignLeft); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | void MainWidget::setLegendRight() |
|
200 | void MainWidget::setLegendRight() | |
201 | { |
|
201 | { | |
202 | m_chart->legend()->setAlignment(Qt::AlignRight); |
|
202 | m_chart->legend()->setAlignment(Qt::AlignRight); | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | void MainWidget::setLegendTop() |
|
205 | void MainWidget::setLegendTop() | |
206 | { |
|
206 | { | |
207 | m_chart->legend()->setAlignment(Qt::AlignTop); |
|
207 | m_chart->legend()->setAlignment(Qt::AlignTop); | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | void MainWidget::setLegendBottom() |
|
210 | void MainWidget::setLegendBottom() | |
211 | { |
|
211 | { | |
212 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
212 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | void MainWidget::updateLegendLayout() |
|
215 | void MainWidget::updateLegendLayout() | |
216 | { |
|
216 | { | |
217 | //![4] |
|
217 | //![4] | |
218 | m_chart->legend()->setGeometry(m_legendPosX->value() |
|
218 | m_chart->legend()->setGeometry(m_legendPosX->value() | |
219 | ,m_legendPosY->value() |
|
219 | ,m_legendPosY->value() | |
220 | ,m_legendWidth->value() |
|
220 | ,m_legendWidth->value() | |
221 | ,m_legendHeight->value()); |
|
221 | ,m_legendHeight->value()); | |
222 | m_chart->legend()->update(); |
|
222 | m_chart->legend()->update(); | |
223 | //![4] |
|
223 | //![4] | |
224 | } |
|
224 | } |
@@ -1,614 +1,614 | |||||
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 <QtCore/QString> |
|
21 | #include <QtCore/QString> | |
22 | #include <QtTest/QtTest> |
|
22 | #include <QtTest/QtTest> | |
23 |
|
23 | |||
24 | #include <qchart.h> |
|
24 | #include <qchart.h> | |
25 | #include <qchartview.h> |
|
25 | #include <qchartview.h> | |
26 | #include <qgroupedbarseries.h> |
|
26 | #include <qgroupedbarseries.h> | |
27 | #include <qbarset.h> |
|
27 | #include <qbarset.h> | |
28 | #include <qvbarmodelmapper.h> |
|
28 | #include <qvbarmodelmapper.h> | |
29 | #include <qhbarmodelmapper.h> |
|
29 | #include <qhbarmodelmapper.h> | |
30 | #include <QStandardItemModel> |
|
30 | #include <QStandardItemModel> | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
32 | QTCOMMERCIALCHART_USE_NAMESPACE | |
33 |
|
33 | |||
34 | class tst_qbarmodelmapper : public QObject |
|
34 | class tst_qbarmodelmapper : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 |
|
37 | |||
38 | public: |
|
38 | public: | |
39 | tst_qbarmodelmapper(); |
|
39 | tst_qbarmodelmapper(); | |
40 | void createVerticalMapper(); |
|
40 | void createVerticalMapper(); | |
41 | void createHorizontalMapper(); |
|
41 | void createHorizontalMapper(); | |
42 |
|
42 | |||
43 | private Q_SLOTS: |
|
43 | private Q_SLOTS: | |
44 | void initTestCase(); |
|
44 | void initTestCase(); | |
45 | void cleanupTestCase(); |
|
45 | void cleanupTestCase(); | |
46 | void init(); |
|
46 | void init(); | |
47 | void cleanup(); |
|
47 | void cleanup(); | |
48 | void verticalMapper_data(); |
|
48 | void verticalMapper_data(); | |
49 | void verticalMapper(); |
|
49 | void verticalMapper(); | |
50 | void verticalMapperCustomMapping_data(); |
|
50 | void verticalMapperCustomMapping_data(); | |
51 | void verticalMapperCustomMapping(); |
|
51 | void verticalMapperCustomMapping(); | |
52 | void horizontalMapper_data(); |
|
52 | void horizontalMapper_data(); | |
53 | void horizontalMapper(); |
|
53 | void horizontalMapper(); | |
54 | void horizontalMapperCustomMapping_data(); |
|
54 | void horizontalMapperCustomMapping_data(); | |
55 | void horizontalMapperCustomMapping(); |
|
55 | void horizontalMapperCustomMapping(); | |
56 | void seriesUpdated(); |
|
56 | void seriesUpdated(); | |
57 | void verticalModelInsertRows(); |
|
57 | void verticalModelInsertRows(); | |
58 | void verticalModelRemoveRows(); |
|
58 | void verticalModelRemoveRows(); | |
59 | void verticalModelInsertColumns(); |
|
59 | void verticalModelInsertColumns(); | |
60 | void verticalModelRemoveColumns(); |
|
60 | void verticalModelRemoveColumns(); | |
61 | void horizontalModelInsertRows(); |
|
61 | void horizontalModelInsertRows(); | |
62 | void horizontalModelRemoveRows(); |
|
62 | void horizontalModelRemoveRows(); | |
63 | void horizontalModelInsertColumns(); |
|
63 | void horizontalModelInsertColumns(); | |
64 | void horizontalModelRemoveColumns(); |
|
64 | void horizontalModelRemoveColumns(); | |
65 | void modelUpdateCell(); |
|
65 | void modelUpdateCell(); | |
66 |
|
66 | |||
67 | private: |
|
67 | private: | |
68 | QStandardItemModel *m_model; |
|
68 | QStandardItemModel *m_model; | |
69 | int m_modelRowCount; |
|
69 | int m_modelRowCount; | |
70 | int m_modelColumnCount; |
|
70 | int m_modelColumnCount; | |
71 |
|
71 | |||
72 | QVBarModelMapper *m_vMapper; |
|
72 | QVBarModelMapper *m_vMapper; | |
73 | QHBarModelMapper *m_hMapper; |
|
73 | QHBarModelMapper *m_hMapper; | |
74 |
|
74 | |||
75 | QGroupedBarSeries *m_series; |
|
75 | QGroupedBarSeries *m_series; | |
76 | QChart *m_chart; |
|
76 | QChart *m_chart; | |
77 | }; |
|
77 | }; | |
78 |
|
78 | |||
79 | tst_qbarmodelmapper::tst_qbarmodelmapper(): |
|
79 | tst_qbarmodelmapper::tst_qbarmodelmapper(): | |
80 | m_model(0), |
|
80 | m_model(0), | |
81 | m_modelRowCount(10), |
|
81 | m_modelRowCount(10), | |
82 | m_modelColumnCount(8), |
|
82 | m_modelColumnCount(8), | |
83 | m_vMapper(0), |
|
83 | m_vMapper(0), | |
84 | m_hMapper(0), |
|
84 | m_hMapper(0), | |
85 | m_series(0), |
|
85 | m_series(0), | |
86 | m_chart(0) |
|
86 | m_chart(0) | |
87 | { |
|
87 | { | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void tst_qbarmodelmapper::createVerticalMapper() |
|
90 | void tst_qbarmodelmapper::createVerticalMapper() | |
91 | { |
|
91 | { | |
92 | m_vMapper = new QVBarModelMapper; |
|
92 | m_vMapper = new QVBarModelMapper; | |
93 | QVERIFY(m_vMapper->model() == 0); |
|
93 | QVERIFY(m_vMapper->model() == 0); | |
94 | m_vMapper->setFirstBarSetColumn(0); |
|
94 | m_vMapper->setFirstBarSetColumn(0); | |
95 | m_vMapper->setLastBarSetColumn(4); |
|
95 | m_vMapper->setLastBarSetColumn(4); | |
96 | m_vMapper->setModel(m_model); |
|
96 | m_vMapper->setModel(m_model); | |
97 | m_vMapper->setSeries(m_series); |
|
97 | m_vMapper->setSeries(m_series); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void tst_qbarmodelmapper::createHorizontalMapper() |
|
100 | void tst_qbarmodelmapper::createHorizontalMapper() | |
101 | { |
|
101 | { | |
102 | m_hMapper = new QHBarModelMapper; |
|
102 | m_hMapper = new QHBarModelMapper; | |
103 | QVERIFY(m_hMapper->model() == 0); |
|
103 | QVERIFY(m_hMapper->model() == 0); | |
104 | m_hMapper->setFirstBarSetRow(0); |
|
104 | m_hMapper->setFirstBarSetRow(0); | |
105 | m_hMapper->setLastBarSetRow(4); |
|
105 | m_hMapper->setLastBarSetRow(4); | |
106 | m_hMapper->setModel(m_model); |
|
106 | m_hMapper->setModel(m_model); | |
107 | m_hMapper->setSeries(m_series); |
|
107 | m_hMapper->setSeries(m_series); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void tst_qbarmodelmapper::init() |
|
110 | void tst_qbarmodelmapper::init() | |
111 | { |
|
111 | { | |
112 | m_series = new QGroupedBarSeries; |
|
112 | m_series = new QGroupedBarSeries; | |
113 | m_chart->addSeries(m_series); |
|
113 | m_chart->addSeries(m_series); | |
114 |
|
114 | |||
115 | m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this); |
|
115 | m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this); | |
116 | for (int row = 0; row < m_modelRowCount; ++row) { |
|
116 | for (int row = 0; row < m_modelRowCount; ++row) { | |
117 | for (int column = 0; column < m_modelColumnCount; column++) { |
|
117 | for (int column = 0; column < m_modelColumnCount; column++) { | |
118 | m_model->setData(m_model->index(row, column), row * column); |
|
118 | m_model->setData(m_model->index(row, column), row * column); | |
119 | } |
|
119 | } | |
120 | } |
|
120 | } | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | void tst_qbarmodelmapper::cleanup() |
|
123 | void tst_qbarmodelmapper::cleanup() | |
124 | { |
|
124 | { | |
125 | m_chart->removeSeries(m_series); |
|
125 | m_chart->removeSeries(m_series); | |
126 | delete m_series; |
|
126 | delete m_series; | |
127 | m_series = 0; |
|
127 | m_series = 0; | |
128 |
|
128 | |||
129 | m_model->clear(); |
|
129 | m_model->clear(); | |
130 | m_model->deleteLater(); |
|
130 | m_model->deleteLater(); | |
131 | m_model = 0; |
|
131 | m_model = 0; | |
132 |
|
132 | |||
133 | if (m_vMapper) { |
|
133 | if (m_vMapper) { | |
134 | m_vMapper->deleteLater(); |
|
134 | m_vMapper->deleteLater(); | |
135 | m_vMapper = 0; |
|
135 | m_vMapper = 0; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | if (m_hMapper) { |
|
138 | if (m_hMapper) { | |
139 | m_hMapper->deleteLater(); |
|
139 | m_hMapper->deleteLater(); | |
140 | m_hMapper = 0; |
|
140 | m_hMapper = 0; | |
141 | } |
|
141 | } | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | void tst_qbarmodelmapper::initTestCase() |
|
144 | void tst_qbarmodelmapper::initTestCase() | |
145 | { |
|
145 | { | |
146 | m_chart = new QChart; |
|
146 | m_chart = new QChart; | |
147 | QChartView *chartView = new QChartView(m_chart); |
|
147 | QChartView *chartView = new QChartView(m_chart); | |
148 | chartView->show(); |
|
148 | chartView->show(); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void tst_qbarmodelmapper::cleanupTestCase() |
|
151 | void tst_qbarmodelmapper::cleanupTestCase() | |
152 | { |
|
152 | { | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | void tst_qbarmodelmapper::verticalMapper_data() |
|
155 | void tst_qbarmodelmapper::verticalMapper_data() | |
156 | { |
|
156 | { | |
157 | QTest::addColumn<int>("firstBarSetColumn"); |
|
157 | QTest::addColumn<int>("firstBarSetColumn"); | |
158 | QTest::addColumn<int>("lastBarSetColumn"); |
|
158 | QTest::addColumn<int>("lastBarSetColumn"); | |
159 | QTest::addColumn<int>("expectedBarSetCount"); |
|
159 | QTest::addColumn<int>("expectedBarSetCount"); | |
160 | QTest::newRow("lastBarSetColumn greater than firstBarSetColumn") << 0 << 1 << 2; |
|
160 | QTest::newRow("lastBarSetColumn greater than firstBarSetColumn") << 0 << 1 << 2; | |
161 | QTest::newRow("lastBarSetColumn equal to firstBarSetColumn") << 1 << 1 << 1; |
|
161 | QTest::newRow("lastBarSetColumn equal to firstBarSetColumn") << 1 << 1 << 1; | |
162 | QTest::newRow("lastBarSetColumn lesser than firstBarSetColumn") << 1 << 0 << 0; |
|
162 | QTest::newRow("lastBarSetColumn lesser than firstBarSetColumn") << 1 << 0 << 0; | |
163 | QTest::newRow("invalid firstBarSetColumn and correct lastBarSetColumn") << -3 << 1 << 0; |
|
163 | QTest::newRow("invalid firstBarSetColumn and correct lastBarSetColumn") << -3 << 1 << 0; | |
164 | QTest::newRow("firstBarSetColumn beyond the size of model and correct lastBarSetColumn") << m_modelColumnCount << 1 << 0; |
|
164 | QTest::newRow("firstBarSetColumn beyond the size of model and correct lastBarSetColumn") << m_modelColumnCount << 1 << 0; | |
165 | QTest::newRow("firstBarSetColumn beyond the size of model and invalid lastBarSetColumn") << m_modelColumnCount << -1 << 0; |
|
165 | QTest::newRow("firstBarSetColumn beyond the size of model and invalid lastBarSetColumn") << m_modelColumnCount << -1 << 0; | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void tst_qbarmodelmapper::verticalMapper() |
|
168 | void tst_qbarmodelmapper::verticalMapper() | |
169 | { |
|
169 | { | |
170 | QFETCH(int, firstBarSetColumn); |
|
170 | QFETCH(int, firstBarSetColumn); | |
171 | QFETCH(int, lastBarSetColumn); |
|
171 | QFETCH(int, lastBarSetColumn); | |
172 | QFETCH(int, expectedBarSetCount); |
|
172 | QFETCH(int, expectedBarSetCount); | |
173 |
|
173 | |||
174 | m_series = new QGroupedBarSeries; |
|
174 | m_series = new QGroupedBarSeries; | |
175 |
|
175 | |||
176 | QVBarModelMapper *mapper = new QVBarModelMapper; |
|
176 | QVBarModelMapper *mapper = new QVBarModelMapper; | |
177 | mapper->setFirstBarSetColumn(firstBarSetColumn); |
|
177 | mapper->setFirstBarSetColumn(firstBarSetColumn); | |
178 | mapper->setLastBarSetColumn(lastBarSetColumn); |
|
178 | mapper->setLastBarSetColumn(lastBarSetColumn); | |
179 | mapper->setModel(m_model); |
|
179 | mapper->setModel(m_model); | |
180 | mapper->setSeries(m_series); |
|
180 | mapper->setSeries(m_series); | |
181 |
|
181 | |||
182 | m_chart->addSeries(m_series); |
|
182 | m_chart->addSeries(m_series); | |
183 |
|
183 | |||
184 |
QCOMPARE(m_series-> |
|
184 | QCOMPARE(m_series->count(), expectedBarSetCount); | |
185 | QCOMPARE(mapper->firstBarSetColumn(), qMax(-1, firstBarSetColumn)); |
|
185 | QCOMPARE(mapper->firstBarSetColumn(), qMax(-1, firstBarSetColumn)); | |
186 | QCOMPARE(mapper->lastBarSetColumn(), qMax(-1, lastBarSetColumn)); |
|
186 | QCOMPARE(mapper->lastBarSetColumn(), qMax(-1, lastBarSetColumn)); | |
187 |
|
187 | |||
188 | delete mapper; |
|
188 | delete mapper; | |
189 | mapper = 0; |
|
189 | mapper = 0; | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | void tst_qbarmodelmapper::verticalMapperCustomMapping_data() |
|
192 | void tst_qbarmodelmapper::verticalMapperCustomMapping_data() | |
193 | { |
|
193 | { | |
194 | QTest::addColumn<int>("first"); |
|
194 | QTest::addColumn<int>("first"); | |
195 | QTest::addColumn<int>("countLimit"); |
|
195 | QTest::addColumn<int>("countLimit"); | |
196 | QTest::addColumn<int>("expectedBarSetCount"); |
|
196 | QTest::addColumn<int>("expectedBarSetCount"); | |
197 | QTest::addColumn<int>("expectedCount"); |
|
197 | QTest::addColumn<int>("expectedCount"); | |
198 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelRowCount; |
|
198 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelRowCount; | |
199 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelRowCount - 3; |
|
199 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelRowCount - 3; | |
200 | QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelRowCount); |
|
200 | QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelRowCount); | |
201 | QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelRowCount - 3); |
|
201 | QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelRowCount - 3); | |
202 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0 << 0; |
|
202 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0 << 0; | |
203 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0 << 0; |
|
203 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0 << 0; | |
204 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << 2 << m_modelRowCount; |
|
204 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << 2 << m_modelRowCount; | |
205 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelRowCount; |
|
205 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelRowCount; | |
206 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelRowCount; |
|
206 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelRowCount; | |
207 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelRowCount; |
|
207 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelRowCount; | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | void tst_qbarmodelmapper::verticalMapperCustomMapping() |
|
210 | void tst_qbarmodelmapper::verticalMapperCustomMapping() | |
211 | { |
|
211 | { | |
212 | QFETCH(int, first); |
|
212 | QFETCH(int, first); | |
213 | QFETCH(int, countLimit); |
|
213 | QFETCH(int, countLimit); | |
214 | QFETCH(int, expectedBarSetCount); |
|
214 | QFETCH(int, expectedBarSetCount); | |
215 | QFETCH(int, expectedCount); |
|
215 | QFETCH(int, expectedCount); | |
216 |
|
216 | |||
217 | m_series = new QGroupedBarSeries; |
|
217 | m_series = new QGroupedBarSeries; | |
218 |
|
218 | |||
219 |
QCOMPARE(m_series-> |
|
219 | QCOMPARE(m_series->count(), 0); | |
220 |
|
220 | |||
221 | QVBarModelMapper *mapper = new QVBarModelMapper; |
|
221 | QVBarModelMapper *mapper = new QVBarModelMapper; | |
222 | mapper->setFirstBarSetColumn(0); |
|
222 | mapper->setFirstBarSetColumn(0); | |
223 | mapper->setLastBarSetColumn(1); |
|
223 | mapper->setLastBarSetColumn(1); | |
224 | mapper->setModel(m_model); |
|
224 | mapper->setModel(m_model); | |
225 | mapper->setSeries(m_series); |
|
225 | mapper->setSeries(m_series); | |
226 | mapper->setFirst(first); |
|
226 | mapper->setFirst(first); | |
227 | mapper->setCount(countLimit); |
|
227 | mapper->setCount(countLimit); | |
228 | m_chart->addSeries(m_series); |
|
228 | m_chart->addSeries(m_series); | |
229 |
|
229 | |||
230 |
QCOMPARE(m_series-> |
|
230 | QCOMPARE(m_series->count(), expectedBarSetCount); | |
231 |
|
231 | |||
232 | if (expectedBarSetCount > 0) |
|
232 | if (expectedBarSetCount > 0) | |
233 | QCOMPARE(m_series->barSets().first()->count(), expectedCount); |
|
233 | QCOMPARE(m_series->barSets().first()->count(), expectedCount); | |
234 |
|
234 | |||
235 | // change values column mapping to invalid |
|
235 | // change values column mapping to invalid | |
236 | mapper->setFirstBarSetColumn(-1); |
|
236 | mapper->setFirstBarSetColumn(-1); | |
237 | mapper->setLastBarSetColumn(1); |
|
237 | mapper->setLastBarSetColumn(1); | |
238 |
|
238 | |||
239 |
QCOMPARE(m_series-> |
|
239 | QCOMPARE(m_series->count(), 0); | |
240 |
|
240 | |||
241 | delete mapper; |
|
241 | delete mapper; | |
242 | mapper = 0; |
|
242 | mapper = 0; | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | void tst_qbarmodelmapper::horizontalMapper_data() |
|
245 | void tst_qbarmodelmapper::horizontalMapper_data() | |
246 | { |
|
246 | { | |
247 | QTest::addColumn<int>("firstBarSetRow"); |
|
247 | QTest::addColumn<int>("firstBarSetRow"); | |
248 | QTest::addColumn<int>("lastBarSetRow"); |
|
248 | QTest::addColumn<int>("lastBarSetRow"); | |
249 | QTest::addColumn<int>("expectedBarSetCount"); |
|
249 | QTest::addColumn<int>("expectedBarSetCount"); | |
250 | QTest::newRow("lastBarSetRow greater than firstBarSetRow") << 0 << 1 << 2; |
|
250 | QTest::newRow("lastBarSetRow greater than firstBarSetRow") << 0 << 1 << 2; | |
251 | QTest::newRow("lastBarSetRow equal to firstBarSetRow") << 1 << 1 << 1; |
|
251 | QTest::newRow("lastBarSetRow equal to firstBarSetRow") << 1 << 1 << 1; | |
252 | QTest::newRow("lastBarSetRow lesser than firstBarSetRow") << 1 << 0 << 0; |
|
252 | QTest::newRow("lastBarSetRow lesser than firstBarSetRow") << 1 << 0 << 0; | |
253 | QTest::newRow("invalid firstBarSetRow and correct lastBarSetRow") << -3 << 1 << 0; |
|
253 | QTest::newRow("invalid firstBarSetRow and correct lastBarSetRow") << -3 << 1 << 0; | |
254 | QTest::newRow("firstBarSetRow beyond the size of model and correct lastBarSetRow") << m_modelRowCount << 1 << 0; |
|
254 | QTest::newRow("firstBarSetRow beyond the size of model and correct lastBarSetRow") << m_modelRowCount << 1 << 0; | |
255 | QTest::newRow("firstBarSetRow beyond the size of model and invalid lastBarSetRow") << m_modelRowCount << -1 << 0; |
|
255 | QTest::newRow("firstBarSetRow beyond the size of model and invalid lastBarSetRow") << m_modelRowCount << -1 << 0; | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | void tst_qbarmodelmapper::horizontalMapper() |
|
258 | void tst_qbarmodelmapper::horizontalMapper() | |
259 | { |
|
259 | { | |
260 | QFETCH(int, firstBarSetRow); |
|
260 | QFETCH(int, firstBarSetRow); | |
261 | QFETCH(int, lastBarSetRow); |
|
261 | QFETCH(int, lastBarSetRow); | |
262 | QFETCH(int, expectedBarSetCount); |
|
262 | QFETCH(int, expectedBarSetCount); | |
263 |
|
263 | |||
264 | m_series = new QGroupedBarSeries; |
|
264 | m_series = new QGroupedBarSeries; | |
265 |
|
265 | |||
266 | QHBarModelMapper *mapper = new QHBarModelMapper; |
|
266 | QHBarModelMapper *mapper = new QHBarModelMapper; | |
267 | mapper->setFirstBarSetRow(firstBarSetRow); |
|
267 | mapper->setFirstBarSetRow(firstBarSetRow); | |
268 | mapper->setLastBarSetRow(lastBarSetRow); |
|
268 | mapper->setLastBarSetRow(lastBarSetRow); | |
269 | mapper->setModel(m_model); |
|
269 | mapper->setModel(m_model); | |
270 | mapper->setSeries(m_series); |
|
270 | mapper->setSeries(m_series); | |
271 |
|
271 | |||
272 | m_chart->addSeries(m_series); |
|
272 | m_chart->addSeries(m_series); | |
273 |
|
273 | |||
274 |
QCOMPARE(m_series-> |
|
274 | QCOMPARE(m_series->count(), expectedBarSetCount); | |
275 | QCOMPARE(mapper->firstBarSetRow(), qMax(-1, firstBarSetRow)); |
|
275 | QCOMPARE(mapper->firstBarSetRow(), qMax(-1, firstBarSetRow)); | |
276 | QCOMPARE(mapper->lastBarSetRow(), qMax(-1, lastBarSetRow)); |
|
276 | QCOMPARE(mapper->lastBarSetRow(), qMax(-1, lastBarSetRow)); | |
277 |
|
277 | |||
278 | delete mapper; |
|
278 | delete mapper; | |
279 | mapper = 0; |
|
279 | mapper = 0; | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | void tst_qbarmodelmapper::horizontalMapperCustomMapping_data() |
|
282 | void tst_qbarmodelmapper::horizontalMapperCustomMapping_data() | |
283 | { |
|
283 | { | |
284 | QTest::addColumn<int>("first"); |
|
284 | QTest::addColumn<int>("first"); | |
285 | QTest::addColumn<int>("countLimit"); |
|
285 | QTest::addColumn<int>("countLimit"); | |
286 | QTest::addColumn<int>("expectedBarSetCount"); |
|
286 | QTest::addColumn<int>("expectedBarSetCount"); | |
287 | QTest::addColumn<int>("expectedCount"); |
|
287 | QTest::addColumn<int>("expectedCount"); | |
288 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelColumnCount; |
|
288 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelColumnCount; | |
289 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelColumnCount - 3; |
|
289 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelColumnCount - 3; | |
290 | QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelColumnCount); |
|
290 | QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelColumnCount); | |
291 | QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelColumnCount - 3); |
|
291 | QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelColumnCount - 3); | |
292 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0 << 0; |
|
292 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0 << 0; | |
293 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0 << 0; |
|
293 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0 << 0; | |
294 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << 2 << m_modelColumnCount; |
|
294 | QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << 2 << m_modelColumnCount; | |
295 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelColumnCount; |
|
295 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelColumnCount; | |
296 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelColumnCount; |
|
296 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelColumnCount; | |
297 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelColumnCount; |
|
297 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelColumnCount; | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | void tst_qbarmodelmapper::horizontalMapperCustomMapping() |
|
300 | void tst_qbarmodelmapper::horizontalMapperCustomMapping() | |
301 | { |
|
301 | { | |
302 | QFETCH(int, first); |
|
302 | QFETCH(int, first); | |
303 | QFETCH(int, countLimit); |
|
303 | QFETCH(int, countLimit); | |
304 | QFETCH(int, expectedBarSetCount); |
|
304 | QFETCH(int, expectedBarSetCount); | |
305 | QFETCH(int, expectedCount); |
|
305 | QFETCH(int, expectedCount); | |
306 |
|
306 | |||
307 | m_series = new QGroupedBarSeries; |
|
307 | m_series = new QGroupedBarSeries; | |
308 |
|
308 | |||
309 |
QCOMPARE(m_series-> |
|
309 | QCOMPARE(m_series->count(), 0); | |
310 |
|
310 | |||
311 | QHBarModelMapper *mapper = new QHBarModelMapper; |
|
311 | QHBarModelMapper *mapper = new QHBarModelMapper; | |
312 | mapper->setFirstBarSetRow(0); |
|
312 | mapper->setFirstBarSetRow(0); | |
313 | mapper->setLastBarSetRow(1); |
|
313 | mapper->setLastBarSetRow(1); | |
314 | mapper->setModel(m_model); |
|
314 | mapper->setModel(m_model); | |
315 | mapper->setSeries(m_series); |
|
315 | mapper->setSeries(m_series); | |
316 | mapper->setFirst(first); |
|
316 | mapper->setFirst(first); | |
317 | mapper->setCount(countLimit); |
|
317 | mapper->setCount(countLimit); | |
318 | m_chart->addSeries(m_series); |
|
318 | m_chart->addSeries(m_series); | |
319 |
|
319 | |||
320 |
QCOMPARE(m_series-> |
|
320 | QCOMPARE(m_series->count(), expectedBarSetCount); | |
321 |
|
321 | |||
322 | if (expectedBarSetCount > 0) |
|
322 | if (expectedBarSetCount > 0) | |
323 | QCOMPARE(m_series->barSets().first()->count(), expectedCount); |
|
323 | QCOMPARE(m_series->barSets().first()->count(), expectedCount); | |
324 |
|
324 | |||
325 | // change values column mapping to invalid |
|
325 | // change values column mapping to invalid | |
326 | mapper->setFirstBarSetRow(-1); |
|
326 | mapper->setFirstBarSetRow(-1); | |
327 | mapper->setLastBarSetRow(1); |
|
327 | mapper->setLastBarSetRow(1); | |
328 |
|
328 | |||
329 |
QCOMPARE(m_series-> |
|
329 | QCOMPARE(m_series->count(), 0); | |
330 |
|
330 | |||
331 | delete mapper; |
|
331 | delete mapper; | |
332 | mapper = 0; |
|
332 | mapper = 0; | |
333 | } |
|
333 | } | |
334 |
|
334 | |||
335 | void tst_qbarmodelmapper::seriesUpdated() |
|
335 | void tst_qbarmodelmapper::seriesUpdated() | |
336 | { |
|
336 | { | |
337 | // setup the mapper |
|
337 | // setup the mapper | |
338 | createVerticalMapper(); |
|
338 | createVerticalMapper(); | |
339 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
339 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
340 | QCOMPARE(m_vMapper->count(), -1); |
|
340 | QCOMPARE(m_vMapper->count(), -1); | |
341 |
|
341 | |||
342 | m_series->barSets().first()->append(123); |
|
342 | m_series->barSets().first()->append(123); | |
343 | QCOMPARE(m_model->rowCount(), m_modelRowCount + 1); |
|
343 | QCOMPARE(m_model->rowCount(), m_modelRowCount + 1); | |
344 | QCOMPARE(m_vMapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model |
|
344 | QCOMPARE(m_vMapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model | |
345 |
|
345 | |||
346 | m_series->barSets().last()->remove(0, m_modelRowCount); |
|
346 | m_series->barSets().last()->remove(0, m_modelRowCount); | |
347 | QCOMPARE(m_model->rowCount(), 1); |
|
347 | QCOMPARE(m_model->rowCount(), 1); | |
348 | QCOMPARE(m_vMapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model |
|
348 | QCOMPARE(m_vMapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model | |
349 |
|
349 | |||
350 | m_series->barSets().first()->replace(0, 444.0); |
|
350 | m_series->barSets().first()->replace(0, 444.0); | |
351 | QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 444.0); |
|
351 | QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 444.0); | |
352 |
|
352 | |||
353 | m_series->barSets().first()->setLabel("Hello"); |
|
353 | m_series->barSets().first()->setLabel("Hello"); | |
354 | QCOMPARE(m_model->headerData(0, Qt::Horizontal).toString(), QString("Hello")); |
|
354 | QCOMPARE(m_model->headerData(0, Qt::Horizontal).toString(), QString("Hello")); | |
355 |
|
355 | |||
356 | QList<qreal> newValues; |
|
356 | QList<qreal> newValues; | |
357 | newValues << 15 << 27 << 35 << 49; |
|
357 | newValues << 15 << 27 << 35 << 49; | |
358 | m_series->barSets().first()->append(newValues); |
|
358 | m_series->barSets().first()->append(newValues); | |
359 | QCOMPARE(m_model->rowCount(), 1 + newValues.count()); |
|
359 | QCOMPARE(m_model->rowCount(), 1 + newValues.count()); | |
360 |
|
360 | |||
361 | QList<QBarSet* > newBarSets; |
|
361 | QList<QBarSet* > newBarSets; | |
362 | QBarSet* newBarSet_1 = new QBarSet("New_1"); |
|
362 | QBarSet* newBarSet_1 = new QBarSet("New_1"); | |
363 | newBarSet_1->append(101); |
|
363 | newBarSet_1->append(101); | |
364 | newBarSet_1->append(102); |
|
364 | newBarSet_1->append(102); | |
365 | newBarSet_1->append(103); |
|
365 | newBarSet_1->append(103); | |
366 | newBarSets.append(newBarSet_1); |
|
366 | newBarSets.append(newBarSet_1); | |
367 |
|
367 | |||
368 | QBarSet* newBarSet_2 = new QBarSet("New_1"); |
|
368 | QBarSet* newBarSet_2 = new QBarSet("New_1"); | |
369 | newBarSet_2->append(201); |
|
369 | newBarSet_2->append(201); | |
370 | newBarSet_2->append(202); |
|
370 | newBarSet_2->append(202); | |
371 | newBarSet_2->append(203); |
|
371 | newBarSet_2->append(203); | |
372 | newBarSets.append(newBarSet_2); |
|
372 | newBarSets.append(newBarSet_2); | |
373 |
|
373 | |||
374 | m_series->append(newBarSets); |
|
374 | m_series->append(newBarSets); | |
375 | QCOMPARE(m_model->columnCount(), m_modelColumnCount + newBarSets.count()); |
|
375 | QCOMPARE(m_model->columnCount(), m_modelColumnCount + newBarSets.count()); | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | void tst_qbarmodelmapper::verticalModelInsertRows() |
|
378 | void tst_qbarmodelmapper::verticalModelInsertRows() | |
379 | { |
|
379 | { | |
380 | // setup the mapper |
|
380 | // setup the mapper | |
381 | createVerticalMapper(); |
|
381 | createVerticalMapper(); | |
382 |
QCOMPARE(m_series-> |
|
382 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
383 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
383 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
384 | QVERIFY(m_vMapper->model() != 0); |
|
384 | QVERIFY(m_vMapper->model() != 0); | |
385 |
|
385 | |||
386 | int insertCount = 4; |
|
386 | int insertCount = 4; | |
387 | m_model->insertRows(3, insertCount); |
|
387 | m_model->insertRows(3, insertCount); | |
388 |
QCOMPARE(m_series-> |
|
388 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
389 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount); |
|
389 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount); | |
390 |
|
390 | |||
391 | int first = 3; |
|
391 | int first = 3; | |
392 | m_vMapper->setFirst(3); |
|
392 | m_vMapper->setFirst(3); | |
393 |
QCOMPARE(m_series-> |
|
393 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
394 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount - first); |
|
394 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount - first); | |
395 |
|
395 | |||
396 | m_model->insertRows(3, insertCount); |
|
396 | m_model->insertRows(3, insertCount); | |
397 |
QCOMPARE(m_series-> |
|
397 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
398 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 2 * insertCount - first); |
|
398 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 2 * insertCount - first); | |
399 |
|
399 | |||
400 | int countLimit = 6; |
|
400 | int countLimit = 6; | |
401 | m_vMapper->setCount(countLimit); |
|
401 | m_vMapper->setCount(countLimit); | |
402 |
QCOMPARE(m_series-> |
|
402 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
403 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); |
|
403 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); | |
404 |
|
404 | |||
405 | m_model->insertRows(3, insertCount); |
|
405 | m_model->insertRows(3, insertCount); | |
406 |
QCOMPARE(m_series-> |
|
406 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
407 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); |
|
407 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); | |
408 |
|
408 | |||
409 | m_vMapper->setFirst(0); |
|
409 | m_vMapper->setFirst(0); | |
410 |
QCOMPARE(m_series-> |
|
410 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
411 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); |
|
411 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); | |
412 |
|
412 | |||
413 | m_vMapper->setCount(-1); |
|
413 | m_vMapper->setCount(-1); | |
414 |
QCOMPARE(m_series-> |
|
414 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
415 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 3 * insertCount); |
|
415 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 3 * insertCount); | |
416 | } |
|
416 | } | |
417 |
|
417 | |||
418 | void tst_qbarmodelmapper::verticalModelRemoveRows() |
|
418 | void tst_qbarmodelmapper::verticalModelRemoveRows() | |
419 | { |
|
419 | { | |
420 | // setup the mapper |
|
420 | // setup the mapper | |
421 | createVerticalMapper(); |
|
421 | createVerticalMapper(); | |
422 |
QCOMPARE(m_series-> |
|
422 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
423 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
423 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
424 | QVERIFY(m_vMapper->model() != 0); |
|
424 | QVERIFY(m_vMapper->model() != 0); | |
425 |
|
425 | |||
426 | int removeCount = 2; |
|
426 | int removeCount = 2; | |
427 | m_model->removeRows(1, removeCount); |
|
427 | m_model->removeRows(1, removeCount); | |
428 |
QCOMPARE(m_series-> |
|
428 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
429 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount); |
|
429 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount); | |
430 |
|
430 | |||
431 | int first = 1; |
|
431 | int first = 1; | |
432 | m_vMapper->setFirst(first); |
|
432 | m_vMapper->setFirst(first); | |
433 |
QCOMPARE(m_series-> |
|
433 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
434 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount - first); |
|
434 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount - first); | |
435 |
|
435 | |||
436 | m_model->removeRows(1, removeCount); |
|
436 | m_model->removeRows(1, removeCount); | |
437 |
QCOMPARE(m_series-> |
|
437 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
438 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 2 * removeCount - first); |
|
438 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 2 * removeCount - first); | |
439 |
|
439 | |||
440 | int countLimit = 3; |
|
440 | int countLimit = 3; | |
441 | m_vMapper->setCount(countLimit); |
|
441 | m_vMapper->setCount(countLimit); | |
442 |
QCOMPARE(m_series-> |
|
442 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
443 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); |
|
443 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); | |
444 |
|
444 | |||
445 | m_model->removeRows(1, removeCount); |
|
445 | m_model->removeRows(1, removeCount); | |
446 |
QCOMPARE(m_series-> |
|
446 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
447 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); |
|
447 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); | |
448 |
|
448 | |||
449 | m_vMapper->setFirst(0); |
|
449 | m_vMapper->setFirst(0); | |
450 |
QCOMPARE(m_series-> |
|
450 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
451 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); |
|
451 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); | |
452 |
|
452 | |||
453 | m_vMapper->setCount(-1); |
|
453 | m_vMapper->setCount(-1); | |
454 |
QCOMPARE(m_series-> |
|
454 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
455 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 3 * removeCount); |
|
455 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 3 * removeCount); | |
456 | } |
|
456 | } | |
457 |
|
457 | |||
458 | void tst_qbarmodelmapper::verticalModelInsertColumns() |
|
458 | void tst_qbarmodelmapper::verticalModelInsertColumns() | |
459 | { |
|
459 | { | |
460 | // setup the mapper |
|
460 | // setup the mapper | |
461 | createVerticalMapper(); |
|
461 | createVerticalMapper(); | |
462 |
QCOMPARE(m_series-> |
|
462 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
463 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
463 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
464 | QVERIFY(m_vMapper->model() != 0); |
|
464 | QVERIFY(m_vMapper->model() != 0); | |
465 |
|
465 | |||
466 | int insertCount = 4; |
|
466 | int insertCount = 4; | |
467 | m_model->insertColumns(3, insertCount); |
|
467 | m_model->insertColumns(3, insertCount); | |
468 |
QCOMPARE(m_series-> |
|
468 | QCOMPARE(m_series->count(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1); | |
469 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
469 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
470 | } |
|
470 | } | |
471 |
|
471 | |||
472 | void tst_qbarmodelmapper::verticalModelRemoveColumns() |
|
472 | void tst_qbarmodelmapper::verticalModelRemoveColumns() | |
473 | { |
|
473 | { | |
474 | // setup the mapper |
|
474 | // setup the mapper | |
475 | createVerticalMapper(); |
|
475 | createVerticalMapper(); | |
476 |
QCOMPARE(m_series-> |
|
476 | QCOMPARE(m_series->count(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1)); | |
477 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
477 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
478 | QVERIFY(m_vMapper->model() != 0); |
|
478 | QVERIFY(m_vMapper->model() != 0); | |
479 |
|
479 | |||
480 | int removeCount = m_modelColumnCount - 2; |
|
480 | int removeCount = m_modelColumnCount - 2; | |
481 | m_model->removeColumns(0, removeCount); |
|
481 | m_model->removeColumns(0, removeCount); | |
482 |
QCOMPARE(m_series-> |
|
482 | QCOMPARE(m_series->count(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1)); | |
483 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); |
|
483 | QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount); | |
484 |
|
484 | |||
485 | // leave all the columns |
|
485 | // leave all the columns | |
486 | m_model->removeColumns(0, m_modelColumnCount - removeCount); |
|
486 | m_model->removeColumns(0, m_modelColumnCount - removeCount); | |
487 |
QCOMPARE(m_series-> |
|
487 | QCOMPARE(m_series->count(), 0); | |
488 | } |
|
488 | } | |
489 |
|
489 | |||
490 | void tst_qbarmodelmapper::horizontalModelInsertRows() |
|
490 | void tst_qbarmodelmapper::horizontalModelInsertRows() | |
491 | { |
|
491 | { | |
492 | // setup the mapper |
|
492 | // setup the mapper | |
493 | createHorizontalMapper(); |
|
493 | createHorizontalMapper(); | |
494 |
QCOMPARE(m_series-> |
|
494 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
495 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
495 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
496 | QVERIFY(m_hMapper->model() != 0); |
|
496 | QVERIFY(m_hMapper->model() != 0); | |
497 |
|
497 | |||
498 | int insertCount = 4; |
|
498 | int insertCount = 4; | |
499 | m_model->insertRows(3, insertCount); |
|
499 | m_model->insertRows(3, insertCount); | |
500 |
QCOMPARE(m_series-> |
|
500 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
501 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
501 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
502 | } |
|
502 | } | |
503 |
|
503 | |||
504 | void tst_qbarmodelmapper::horizontalModelRemoveRows() |
|
504 | void tst_qbarmodelmapper::horizontalModelRemoveRows() | |
505 | { |
|
505 | { | |
506 | // setup the mapper |
|
506 | // setup the mapper | |
507 | createHorizontalMapper(); |
|
507 | createHorizontalMapper(); | |
508 |
QCOMPARE(m_series-> |
|
508 | QCOMPARE(m_series->count(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1)); | |
509 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
509 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
510 | QVERIFY(m_hMapper->model() != 0); |
|
510 | QVERIFY(m_hMapper->model() != 0); | |
511 |
|
511 | |||
512 | int removeCount = m_modelRowCount - 2; |
|
512 | int removeCount = m_modelRowCount - 2; | |
513 | m_model->removeRows(0, removeCount); |
|
513 | m_model->removeRows(0, removeCount); | |
514 |
QCOMPARE(m_series-> |
|
514 | QCOMPARE(m_series->count(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1)); | |
515 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
515 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
516 |
|
516 | |||
517 | // leave all the columns |
|
517 | // leave all the columns | |
518 | m_model->removeRows(0, m_modelRowCount - removeCount); |
|
518 | m_model->removeRows(0, m_modelRowCount - removeCount); | |
519 |
QCOMPARE(m_series-> |
|
519 | QCOMPARE(m_series->count(), 0); | |
520 | } |
|
520 | } | |
521 |
|
521 | |||
522 | void tst_qbarmodelmapper::horizontalModelInsertColumns() |
|
522 | void tst_qbarmodelmapper::horizontalModelInsertColumns() | |
523 | { |
|
523 | { | |
524 | // setup the mapper |
|
524 | // setup the mapper | |
525 | createHorizontalMapper(); |
|
525 | createHorizontalMapper(); | |
526 |
QCOMPARE(m_series-> |
|
526 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
527 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
527 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
528 | QVERIFY(m_hMapper->model() != 0); |
|
528 | QVERIFY(m_hMapper->model() != 0); | |
529 |
|
529 | |||
530 | int insertCount = 4; |
|
530 | int insertCount = 4; | |
531 | m_model->insertColumns(3, insertCount); |
|
531 | m_model->insertColumns(3, insertCount); | |
532 |
QCOMPARE(m_series-> |
|
532 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
533 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount); |
|
533 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount); | |
534 |
|
534 | |||
535 | int first = 3; |
|
535 | int first = 3; | |
536 | m_hMapper->setFirst(3); |
|
536 | m_hMapper->setFirst(3); | |
537 |
QCOMPARE(m_series-> |
|
537 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
538 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount - first); |
|
538 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount - first); | |
539 |
|
539 | |||
540 | m_model->insertColumns(3, insertCount); |
|
540 | m_model->insertColumns(3, insertCount); | |
541 |
QCOMPARE(m_series-> |
|
541 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
542 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 2 * insertCount - first); |
|
542 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 2 * insertCount - first); | |
543 |
|
543 | |||
544 | int countLimit = 6; |
|
544 | int countLimit = 6; | |
545 | m_hMapper->setCount(countLimit); |
|
545 | m_hMapper->setCount(countLimit); | |
546 |
QCOMPARE(m_series-> |
|
546 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
547 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); |
|
547 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); | |
548 |
|
548 | |||
549 | m_model->insertColumns(3, insertCount); |
|
549 | m_model->insertColumns(3, insertCount); | |
550 |
QCOMPARE(m_series-> |
|
550 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
551 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); |
|
551 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); | |
552 |
|
552 | |||
553 | m_hMapper->setFirst(0); |
|
553 | m_hMapper->setFirst(0); | |
554 |
QCOMPARE(m_series-> |
|
554 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
555 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); |
|
555 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); | |
556 |
|
556 | |||
557 | m_hMapper->setCount(-1); |
|
557 | m_hMapper->setCount(-1); | |
558 |
QCOMPARE(m_series-> |
|
558 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
559 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 3 * insertCount); |
|
559 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 3 * insertCount); | |
560 | } |
|
560 | } | |
561 |
|
561 | |||
562 | void tst_qbarmodelmapper::horizontalModelRemoveColumns() |
|
562 | void tst_qbarmodelmapper::horizontalModelRemoveColumns() | |
563 | { |
|
563 | { | |
564 | // setup the mapper |
|
564 | // setup the mapper | |
565 | createHorizontalMapper(); |
|
565 | createHorizontalMapper(); | |
566 |
QCOMPARE(m_series-> |
|
566 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
567 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); |
|
567 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount); | |
568 | QVERIFY(m_hMapper->model() != 0); |
|
568 | QVERIFY(m_hMapper->model() != 0); | |
569 |
|
569 | |||
570 | int removeCount = 2; |
|
570 | int removeCount = 2; | |
571 | m_model->removeColumns(1, removeCount); |
|
571 | m_model->removeColumns(1, removeCount); | |
572 |
QCOMPARE(m_series-> |
|
572 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
573 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount); |
|
573 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount); | |
574 |
|
574 | |||
575 | int first = 1; |
|
575 | int first = 1; | |
576 | m_hMapper->setFirst(first); |
|
576 | m_hMapper->setFirst(first); | |
577 |
QCOMPARE(m_series-> |
|
577 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
578 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount - first); |
|
578 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount - first); | |
579 |
|
579 | |||
580 | m_model->removeColumns(1, removeCount); |
|
580 | m_model->removeColumns(1, removeCount); | |
581 |
QCOMPARE(m_series-> |
|
581 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
582 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 2 * removeCount - first); |
|
582 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 2 * removeCount - first); | |
583 |
|
583 | |||
584 | int countLimit = 3; |
|
584 | int countLimit = 3; | |
585 | m_hMapper->setCount(countLimit); |
|
585 | m_hMapper->setCount(countLimit); | |
586 |
QCOMPARE(m_series-> |
|
586 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
587 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); |
|
587 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); | |
588 |
|
588 | |||
589 | m_model->removeColumns(1, removeCount); |
|
589 | m_model->removeColumns(1, removeCount); | |
590 |
QCOMPARE(m_series-> |
|
590 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
591 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); |
|
591 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); | |
592 |
|
592 | |||
593 | m_hMapper->setFirst(0); |
|
593 | m_hMapper->setFirst(0); | |
594 |
QCOMPARE(m_series-> |
|
594 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
595 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); |
|
595 | QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); | |
596 |
|
596 | |||
597 | m_hMapper->setCount(-1); |
|
597 | m_hMapper->setCount(-1); | |
598 |
QCOMPARE(m_series-> |
|
598 | QCOMPARE(m_series->count(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1); | |
599 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 3 * removeCount); |
|
599 | QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 3 * removeCount); | |
600 | } |
|
600 | } | |
601 |
|
601 | |||
602 | void tst_qbarmodelmapper::modelUpdateCell() |
|
602 | void tst_qbarmodelmapper::modelUpdateCell() | |
603 | { |
|
603 | { | |
604 | // setup the mapper |
|
604 | // setup the mapper | |
605 | createVerticalMapper(); |
|
605 | createVerticalMapper(); | |
606 |
|
606 | |||
607 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); |
|
607 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); | |
608 | QCOMPARE(m_series->barSets().at(0)->at(1).y(), 44.0); |
|
608 | QCOMPARE(m_series->barSets().at(0)->at(1).y(), 44.0); | |
609 | QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); |
|
609 | QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); | |
610 | } |
|
610 | } | |
611 |
|
611 | |||
612 | QTEST_MAIN(tst_qbarmodelmapper) |
|
612 | QTEST_MAIN(tst_qbarmodelmapper) | |
613 |
|
613 | |||
614 | #include "tst_qbarmodelmapper.moc" |
|
614 | #include "tst_qbarmodelmapper.moc" |
@@ -1,508 +1,508 | |||||
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 <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qbarseries.h> |
|
22 | #include <qbarseries.h> | |
23 | #include <qbarset.h> |
|
23 | #include <qbarset.h> | |
24 | #include <qchartview.h> |
|
24 | #include <qchartview.h> | |
25 | #include <qchart.h> |
|
25 | #include <qchart.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |
28 |
|
28 | |||
29 | Q_DECLARE_METATYPE(QBarSet*) |
|
29 | Q_DECLARE_METATYPE(QBarSet*) | |
30 |
|
30 | |||
31 | class tst_QBarSeries : public QObject |
|
31 | class tst_QBarSeries : public QObject | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
|
34 | |||
35 | public slots: |
|
35 | public slots: | |
36 | void initTestCase(); |
|
36 | void initTestCase(); | |
37 | void cleanupTestCase(); |
|
37 | void cleanupTestCase(); | |
38 | void init(); |
|
38 | void init(); | |
39 | void cleanup(); |
|
39 | void cleanup(); | |
40 |
|
40 | |||
41 | private slots: |
|
41 | private slots: | |
42 | void qbarseries_data(); |
|
42 | void qbarseries_data(); | |
43 | void qbarseries(); |
|
43 | void qbarseries(); | |
44 | void type_data(); |
|
44 | void type_data(); | |
45 | void type(); |
|
45 | void type(); | |
46 | void append_data(); |
|
46 | void append_data(); | |
47 | void append(); |
|
47 | void append(); | |
48 | void remove_data(); |
|
48 | void remove_data(); | |
49 | void remove(); |
|
49 | void remove(); | |
50 | void appendList_data(); |
|
50 | void appendList_data(); | |
51 | void appendList(); |
|
51 | void appendList(); | |
52 |
void |
|
52 | void count_data(); | |
53 |
void |
|
53 | void count(); | |
54 | void barSets_data(); |
|
54 | void barSets_data(); | |
55 | void barSets(); |
|
55 | void barSets(); | |
56 | void setLabelsVisible_data(); |
|
56 | void setLabelsVisible_data(); | |
57 | void setLabelsVisible(); |
|
57 | void setLabelsVisible(); | |
58 | void mouseclicked_data(); |
|
58 | void mouseclicked_data(); | |
59 | void mouseclicked(); |
|
59 | void mouseclicked(); | |
60 | void mousehovered_data(); |
|
60 | void mousehovered_data(); | |
61 | void mousehovered(); |
|
61 | void mousehovered(); | |
62 | void clearWithAnimations(); |
|
62 | void clearWithAnimations(); | |
63 |
|
63 | |||
64 | private: |
|
64 | private: | |
65 | QBarSeries* m_barseries; |
|
65 | QBarSeries* m_barseries; | |
66 | QBarSeries* m_barseries_with_sets; |
|
66 | QBarSeries* m_barseries_with_sets; | |
67 |
|
67 | |||
68 | QList<QBarSet*> m_testSets; |
|
68 | QList<QBarSet*> m_testSets; | |
69 |
|
69 | |||
70 | }; |
|
70 | }; | |
71 |
|
71 | |||
72 | void tst_QBarSeries::initTestCase() |
|
72 | void tst_QBarSeries::initTestCase() | |
73 | { |
|
73 | { | |
74 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
74 | qRegisterMetaType<QBarSet*>("QBarSet*"); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void tst_QBarSeries::cleanupTestCase() |
|
77 | void tst_QBarSeries::cleanupTestCase() | |
78 | { |
|
78 | { | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | void tst_QBarSeries::init() |
|
81 | void tst_QBarSeries::init() | |
82 | { |
|
82 | { | |
83 | m_barseries = new QBarSeries(); |
|
83 | m_barseries = new QBarSeries(); | |
84 | m_barseries_with_sets = new QBarSeries(); |
|
84 | m_barseries_with_sets = new QBarSeries(); | |
85 |
|
85 | |||
86 | for (int i=0; i<5; i++) { |
|
86 | for (int i=0; i<5; i++) { | |
87 | m_testSets.append(new QBarSet("testset")); |
|
87 | m_testSets.append(new QBarSet("testset")); | |
88 | m_barseries_with_sets->append(m_testSets.at(i)); |
|
88 | m_barseries_with_sets->append(m_testSets.at(i)); | |
89 | } |
|
89 | } | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void tst_QBarSeries::cleanup() |
|
92 | void tst_QBarSeries::cleanup() | |
93 | { |
|
93 | { | |
94 | foreach(QBarSet* s, m_testSets) { |
|
94 | foreach(QBarSet* s, m_testSets) { | |
95 | m_barseries_with_sets->remove(s); |
|
95 | m_barseries_with_sets->remove(s); | |
96 | delete s; |
|
96 | delete s; | |
97 | } |
|
97 | } | |
98 | m_testSets.clear(); |
|
98 | m_testSets.clear(); | |
99 |
|
99 | |||
100 | delete m_barseries; |
|
100 | delete m_barseries; | |
101 | m_barseries = 0; |
|
101 | m_barseries = 0; | |
102 | delete m_barseries_with_sets; |
|
102 | delete m_barseries_with_sets; | |
103 | m_barseries_with_sets = 0; |
|
103 | m_barseries_with_sets = 0; | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | void tst_QBarSeries::qbarseries_data() |
|
106 | void tst_QBarSeries::qbarseries_data() | |
107 | { |
|
107 | { | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void tst_QBarSeries::qbarseries() |
|
110 | void tst_QBarSeries::qbarseries() | |
111 | { |
|
111 | { | |
112 | QBarSeries *barseries = new QBarSeries(); |
|
112 | QBarSeries *barseries = new QBarSeries(); | |
113 | QVERIFY(barseries != 0); |
|
113 | QVERIFY(barseries != 0); | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | void tst_QBarSeries::type_data() |
|
116 | void tst_QBarSeries::type_data() | |
117 | { |
|
117 | { | |
118 |
|
118 | |||
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | void tst_QBarSeries::type() |
|
121 | void tst_QBarSeries::type() | |
122 | { |
|
122 | { | |
123 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); |
|
123 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void tst_QBarSeries::append_data() |
|
126 | void tst_QBarSeries::append_data() | |
127 | { |
|
127 | { | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | void tst_QBarSeries::append() |
|
130 | void tst_QBarSeries::append() | |
131 | { |
|
131 | { | |
132 |
QVERIFY(m_barseries-> |
|
132 | QVERIFY(m_barseries->count() == 0); | |
133 |
|
133 | |||
134 | bool ret = false; |
|
134 | bool ret = false; | |
135 |
|
135 | |||
136 | // Try adding barset |
|
136 | // Try adding barset | |
137 | QBarSet *barset = new QBarSet("testset"); |
|
137 | QBarSet *barset = new QBarSet("testset"); | |
138 | ret = m_barseries->append(barset); |
|
138 | ret = m_barseries->append(barset); | |
139 |
|
139 | |||
140 | QVERIFY(ret == true); |
|
140 | QVERIFY(ret == true); | |
141 |
QVERIFY(m_barseries-> |
|
141 | QVERIFY(m_barseries->count() == 1); | |
142 |
|
142 | |||
143 | // Try adding another set |
|
143 | // Try adding another set | |
144 | QBarSet *barset2 = new QBarSet("testset2"); |
|
144 | QBarSet *barset2 = new QBarSet("testset2"); | |
145 | ret = m_barseries->append(barset2); |
|
145 | ret = m_barseries->append(barset2); | |
146 |
|
146 | |||
147 | QVERIFY(ret == true); |
|
147 | QVERIFY(ret == true); | |
148 |
QVERIFY(m_barseries-> |
|
148 | QVERIFY(m_barseries->count() == 2); | |
149 |
|
149 | |||
150 | // Try adding same set again |
|
150 | // Try adding same set again | |
151 | ret = m_barseries->append(barset2); |
|
151 | ret = m_barseries->append(barset2); | |
152 | QVERIFY(ret == false); |
|
152 | QVERIFY(ret == false); | |
153 |
QVERIFY(m_barseries-> |
|
153 | QVERIFY(m_barseries->count() == 2); | |
154 |
|
154 | |||
155 | // Try adding null set |
|
155 | // Try adding null set | |
156 | ret = m_barseries->append(0); |
|
156 | ret = m_barseries->append(0); | |
157 | QVERIFY(ret == false); |
|
157 | QVERIFY(ret == false); | |
158 |
QVERIFY(m_barseries-> |
|
158 | QVERIFY(m_barseries->count() == 2); | |
159 |
|
159 | |||
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | void tst_QBarSeries::remove_data() |
|
162 | void tst_QBarSeries::remove_data() | |
163 | { |
|
163 | { | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | void tst_QBarSeries::remove() |
|
166 | void tst_QBarSeries::remove() | |
167 | { |
|
167 | { | |
168 | int count = m_testSets.count(); |
|
168 | int count = m_testSets.count(); | |
169 |
QVERIFY(m_barseries_with_sets-> |
|
169 | QVERIFY(m_barseries_with_sets->count() == count); | |
170 |
|
170 | |||
171 | // Try to remove null pointer (should not remove, should not crash) |
|
171 | // Try to remove null pointer (should not remove, should not crash) | |
172 | bool ret = false; |
|
172 | bool ret = false; | |
173 | ret = m_barseries_with_sets->remove(0); |
|
173 | ret = m_barseries_with_sets->remove(0); | |
174 | QVERIFY(ret == false); |
|
174 | QVERIFY(ret == false); | |
175 |
QVERIFY(m_barseries_with_sets-> |
|
175 | QVERIFY(m_barseries_with_sets->count() == count); | |
176 |
|
176 | |||
177 | // Try to remove invalid pointer (should not remove, should not crash) |
|
177 | // Try to remove invalid pointer (should not remove, should not crash) | |
178 | ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) ); |
|
178 | ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) ); | |
179 | QVERIFY(ret == false); |
|
179 | QVERIFY(ret == false); | |
180 |
QVERIFY(m_barseries_with_sets-> |
|
180 | QVERIFY(m_barseries_with_sets->count() == count); | |
181 |
|
181 | |||
182 | // remove some sets |
|
182 | // remove some sets | |
183 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); |
|
183 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); | |
184 | QVERIFY(ret == true); |
|
184 | QVERIFY(ret == true); | |
185 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); |
|
185 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); | |
186 | QVERIFY(ret == true); |
|
186 | QVERIFY(ret == true); | |
187 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); |
|
187 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); | |
188 | QVERIFY(ret == true); |
|
188 | QVERIFY(ret == true); | |
189 |
|
189 | |||
190 |
QVERIFY(m_barseries_with_sets-> |
|
190 | QVERIFY(m_barseries_with_sets->count() == 2); | |
191 |
|
191 | |||
192 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); |
|
192 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); | |
193 |
|
193 | |||
194 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); |
|
194 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); | |
195 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); |
|
195 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); | |
196 |
|
196 | |||
197 | // Try removing all sets again (should be ok, even if some sets have already been removed) |
|
197 | // Try removing all sets again (should be ok, even if some sets have already been removed) | |
198 | ret = false; |
|
198 | ret = false; | |
199 | for (int i=0; i<count; i++) { |
|
199 | for (int i=0; i<count; i++) { | |
200 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); |
|
200 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | QVERIFY(ret == true); |
|
203 | QVERIFY(ret == true); | |
204 |
QVERIFY(m_barseries_with_sets-> |
|
204 | QVERIFY(m_barseries_with_sets->count() == 0); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | void tst_QBarSeries::appendList_data() |
|
207 | void tst_QBarSeries::appendList_data() | |
208 | { |
|
208 | { | |
209 |
|
209 | |||
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | void tst_QBarSeries::appendList() |
|
212 | void tst_QBarSeries::appendList() | |
213 | { |
|
213 | { | |
214 | int count = 5; |
|
214 | int count = 5; | |
215 |
QVERIFY(m_barseries-> |
|
215 | QVERIFY(m_barseries->count() == 0); | |
216 |
|
216 | |||
217 | QList<QBarSet*> sets; |
|
217 | QList<QBarSet*> sets; | |
218 | for (int i=0; i<count; i++) { |
|
218 | for (int i=0; i<count; i++) { | |
219 | sets.append(new QBarSet("testset")); |
|
219 | sets.append(new QBarSet("testset")); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | // Append new sets (should succeed, count should match the count of sets) |
|
222 | // Append new sets (should succeed, count should match the count of sets) | |
223 | bool ret = false; |
|
223 | bool ret = false; | |
224 | ret = m_barseries->append(sets); |
|
224 | ret = m_barseries->append(sets); | |
225 | QVERIFY(ret == true); |
|
225 | QVERIFY(ret == true); | |
226 |
QVERIFY(m_barseries-> |
|
226 | QVERIFY(m_barseries->count() == count); | |
227 |
|
227 | |||
228 | // Append same sets again (should fail, count should remain same) |
|
228 | // Append same sets again (should fail, count should remain same) | |
229 | ret = m_barseries->append(sets); |
|
229 | ret = m_barseries->append(sets); | |
230 | QVERIFY(ret == false); |
|
230 | QVERIFY(ret == false); | |
231 |
QVERIFY(m_barseries-> |
|
231 | QVERIFY(m_barseries->count() == count); | |
232 |
|
232 | |||
233 | // Try append empty list (should succeed, but count should remain same) |
|
233 | // Try append empty list (should succeed, but count should remain same) | |
234 | QList<QBarSet*> invalidList; |
|
234 | QList<QBarSet*> invalidList; | |
235 | ret = m_barseries->append(invalidList); |
|
235 | ret = m_barseries->append(invalidList); | |
236 | QVERIFY(ret == true); |
|
236 | QVERIFY(ret == true); | |
237 |
QVERIFY(m_barseries-> |
|
237 | QVERIFY(m_barseries->count() == count); | |
238 |
|
238 | |||
239 | // Try append list with one new and one existing set (should fail, count remains same) |
|
239 | // Try append list with one new and one existing set (should fail, count remains same) | |
240 | invalidList.append(new QBarSet("ok set")); |
|
240 | invalidList.append(new QBarSet("ok set")); | |
241 | invalidList.append(sets.at(0)); |
|
241 | invalidList.append(sets.at(0)); | |
242 | ret = m_barseries->append(invalidList); |
|
242 | ret = m_barseries->append(invalidList); | |
243 | QVERIFY(ret == false); |
|
243 | QVERIFY(ret == false); | |
244 |
QVERIFY(m_barseries-> |
|
244 | QVERIFY(m_barseries->count() == count); | |
245 |
|
245 | |||
246 | // Try append list with null pointers (should fail, count remains same) |
|
246 | // Try append list with null pointers (should fail, count remains same) | |
247 | QList<QBarSet*> invalidList2; |
|
247 | QList<QBarSet*> invalidList2; | |
248 | invalidList2.append(0); |
|
248 | invalidList2.append(0); | |
249 | invalidList2.append(0); |
|
249 | invalidList2.append(0); | |
250 | invalidList2.append(0); |
|
250 | invalidList2.append(0); | |
251 | ret = m_barseries->append(invalidList2); |
|
251 | ret = m_barseries->append(invalidList2); | |
252 | QVERIFY(ret == false); |
|
252 | QVERIFY(ret == false); | |
253 |
QVERIFY(m_barseries-> |
|
253 | QVERIFY(m_barseries->count() == count); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 |
void tst_QBarSeries:: |
|
256 | void tst_QBarSeries::count_data() | |
257 | { |
|
257 | { | |
258 |
|
258 | |||
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 |
void tst_QBarSeries:: |
|
261 | void tst_QBarSeries::count() | |
262 | { |
|
262 | { | |
263 |
QVERIFY(m_barseries-> |
|
263 | QVERIFY(m_barseries->count() == 0); | |
264 |
QVERIFY(m_barseries_with_sets-> |
|
264 | QVERIFY(m_barseries_with_sets->count() == m_testSets.count()); | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | void tst_QBarSeries::barSets_data() |
|
267 | void tst_QBarSeries::barSets_data() | |
268 | { |
|
268 | { | |
269 |
|
269 | |||
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | void tst_QBarSeries::barSets() |
|
272 | void tst_QBarSeries::barSets() | |
273 | { |
|
273 | { | |
274 | QVERIFY(m_barseries->barSets().count() == 0); |
|
274 | QVERIFY(m_barseries->barSets().count() == 0); | |
275 |
|
275 | |||
276 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); |
|
276 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); | |
277 | QVERIFY(sets.count() == m_testSets.count()); |
|
277 | QVERIFY(sets.count() == m_testSets.count()); | |
278 |
|
278 | |||
279 | for (int i=0; i<m_testSets.count(); i++) { |
|
279 | for (int i=0; i<m_testSets.count(); i++) { | |
280 | QVERIFY(sets.at(i) == m_testSets.at(i)); |
|
280 | QVERIFY(sets.at(i) == m_testSets.at(i)); | |
281 | } |
|
281 | } | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | void tst_QBarSeries::setLabelsVisible_data() |
|
284 | void tst_QBarSeries::setLabelsVisible_data() | |
285 | { |
|
285 | { | |
286 |
|
286 | |||
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | void tst_QBarSeries::setLabelsVisible() |
|
289 | void tst_QBarSeries::setLabelsVisible() | |
290 | { |
|
290 | { | |
291 | // labels should be invisible by default |
|
291 | // labels should be invisible by default | |
292 | QVERIFY(m_barseries->isLabelsVisible() == false); |
|
292 | QVERIFY(m_barseries->isLabelsVisible() == false); | |
293 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
293 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); | |
294 |
|
294 | |||
295 | // turn labels to visible |
|
295 | // turn labels to visible | |
296 | m_barseries_with_sets->setLabelsVisible(true); |
|
296 | m_barseries_with_sets->setLabelsVisible(true); | |
297 | // TODO: test the signal |
|
297 | // TODO: test the signal | |
298 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
298 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); | |
299 |
|
299 | |||
300 | // turn labels to invisible |
|
300 | // turn labels to invisible | |
301 | m_barseries_with_sets->setLabelsVisible(false); |
|
301 | m_barseries_with_sets->setLabelsVisible(false); | |
302 | // TODO: test the signal |
|
302 | // TODO: test the signal | |
303 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
303 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); | |
304 |
|
304 | |||
305 | // without parameter, should turn labels to visible |
|
305 | // without parameter, should turn labels to visible | |
306 | m_barseries_with_sets->setLabelsVisible(); |
|
306 | m_barseries_with_sets->setLabelsVisible(); | |
307 | // TODO: test the signal |
|
307 | // TODO: test the signal | |
308 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
308 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); | |
309 | } |
|
309 | } | |
310 |
|
310 | |||
311 | void tst_QBarSeries::mouseclicked_data() |
|
311 | void tst_QBarSeries::mouseclicked_data() | |
312 | { |
|
312 | { | |
313 |
|
313 | |||
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | void tst_QBarSeries::mouseclicked() |
|
316 | void tst_QBarSeries::mouseclicked() | |
317 | { |
|
317 | { | |
318 | QBarSeries* series = new QBarSeries(); |
|
318 | QBarSeries* series = new QBarSeries(); | |
319 |
|
319 | |||
320 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
320 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
321 | *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); |
|
321 | *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
322 | series->append(set1); |
|
322 | series->append(set1); | |
323 |
|
323 | |||
324 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
324 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
325 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); |
|
325 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
326 | series->append(set2); |
|
326 | series->append(set2); | |
327 |
|
327 | |||
328 | QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int))); |
|
328 | QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int))); | |
329 |
|
329 | |||
330 | QChartView view(new QChart()); |
|
330 | QChartView view(new QChart()); | |
331 | view.resize(400,300); |
|
331 | view.resize(400,300); | |
332 | view.chart()->addSeries(series); |
|
332 | view.chart()->addSeries(series); | |
333 | view.show(); |
|
333 | view.show(); | |
334 | QTest::qWaitForWindowShown(&view); |
|
334 | QTest::qWaitForWindowShown(&view); | |
335 |
|
335 | |||
336 | //==================================================================================== |
|
336 | //==================================================================================== | |
337 | // barset 1, bar 0 |
|
337 | // barset 1, bar 0 | |
338 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(102,142)); |
|
338 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(102,142)); | |
339 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
339 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
340 |
|
340 | |||
341 | QCOMPARE(seriesSpy.count(), 1); |
|
341 | QCOMPARE(seriesSpy.count(), 1); | |
342 |
|
342 | |||
343 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
343 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
344 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
344 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
345 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); |
|
345 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
346 | QVERIFY(seriesSpyArg.at(1).toInt() == 0); |
|
346 | QVERIFY(seriesSpyArg.at(1).toInt() == 0); | |
347 |
|
347 | |||
348 | //==================================================================================== |
|
348 | //==================================================================================== | |
349 | // barset 1, bar 1 |
|
349 | // barset 1, bar 1 | |
350 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142)); |
|
350 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142)); | |
351 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
351 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
352 |
|
352 | |||
353 | QCOMPARE(seriesSpy.count(), 1); |
|
353 | QCOMPARE(seriesSpy.count(), 1); | |
354 |
|
354 | |||
355 | seriesSpyArg = seriesSpy.takeFirst(); |
|
355 | seriesSpyArg = seriesSpy.takeFirst(); | |
356 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
356 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
357 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); |
|
357 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
358 | QVERIFY(seriesSpyArg.at(1).toInt() == 1); |
|
358 | QVERIFY(seriesSpyArg.at(1).toInt() == 1); | |
359 |
|
359 | |||
360 | //==================================================================================== |
|
360 | //==================================================================================== | |
361 | // barset 1, bar 2 |
|
361 | // barset 1, bar 2 | |
362 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142)); |
|
362 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142)); | |
363 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
363 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
364 |
|
364 | |||
365 | QCOMPARE(seriesSpy.count(), 1); |
|
365 | QCOMPARE(seriesSpy.count(), 1); | |
366 |
|
366 | |||
367 | seriesSpyArg = seriesSpy.takeFirst(); |
|
367 | seriesSpyArg = seriesSpy.takeFirst(); | |
368 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
368 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
369 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); |
|
369 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
370 | QVERIFY(seriesSpyArg.at(1).toInt() == 2); |
|
370 | QVERIFY(seriesSpyArg.at(1).toInt() == 2); | |
371 |
|
371 | |||
372 | //==================================================================================== |
|
372 | //==================================================================================== | |
373 | // barset 2, bar 0 |
|
373 | // barset 2, bar 0 | |
374 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142)); |
|
374 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142)); | |
375 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
375 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
376 |
|
376 | |||
377 | QCOMPARE(seriesSpy.count(), 1); |
|
377 | QCOMPARE(seriesSpy.count(), 1); | |
378 |
|
378 | |||
379 | seriesSpyArg = seriesSpy.takeFirst(); |
|
379 | seriesSpyArg = seriesSpy.takeFirst(); | |
380 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
380 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
381 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); |
|
381 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
382 | QVERIFY(seriesSpyArg.at(1).toInt() == 0); |
|
382 | QVERIFY(seriesSpyArg.at(1).toInt() == 0); | |
383 |
|
383 | |||
384 | //==================================================================================== |
|
384 | //==================================================================================== | |
385 | // barset 2, bar 1 |
|
385 | // barset 2, bar 1 | |
386 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142)); |
|
386 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142)); | |
387 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
387 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
388 |
|
388 | |||
389 | QCOMPARE(seriesSpy.count(), 1); |
|
389 | QCOMPARE(seriesSpy.count(), 1); | |
390 |
|
390 | |||
391 | seriesSpyArg = seriesSpy.takeFirst(); |
|
391 | seriesSpyArg = seriesSpy.takeFirst(); | |
392 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
392 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
393 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); |
|
393 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
394 | QVERIFY(seriesSpyArg.at(1).toInt() == 1); |
|
394 | QVERIFY(seriesSpyArg.at(1).toInt() == 1); | |
395 |
|
395 | |||
396 | //==================================================================================== |
|
396 | //==================================================================================== | |
397 | // barset 2, bar 2 |
|
397 | // barset 2, bar 2 | |
398 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142)); |
|
398 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142)); | |
399 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
399 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
400 |
|
400 | |||
401 | QCOMPARE(seriesSpy.count(), 1); |
|
401 | QCOMPARE(seriesSpy.count(), 1); | |
402 |
|
402 | |||
403 | seriesSpyArg = seriesSpy.takeFirst(); |
|
403 | seriesSpyArg = seriesSpy.takeFirst(); | |
404 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
404 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
405 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); |
|
405 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
406 | QVERIFY(seriesSpyArg.at(1).toInt() == 2); |
|
406 | QVERIFY(seriesSpyArg.at(1).toInt() == 2); | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
409 | void tst_QBarSeries::mousehovered_data() |
|
409 | void tst_QBarSeries::mousehovered_data() | |
410 | { |
|
410 | { | |
411 |
|
411 | |||
412 | } |
|
412 | } | |
413 |
|
413 | |||
414 | void tst_QBarSeries::mousehovered() |
|
414 | void tst_QBarSeries::mousehovered() | |
415 | { |
|
415 | { | |
416 | QBarSeries* series = new QBarSeries(); |
|
416 | QBarSeries* series = new QBarSeries(); | |
417 |
|
417 | |||
418 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
418 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
419 | *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); |
|
419 | *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
420 | series->append(set1); |
|
420 | series->append(set1); | |
421 |
|
421 | |||
422 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
422 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
423 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); |
|
423 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
424 | series->append(set2); |
|
424 | series->append(set2); | |
425 |
|
425 | |||
426 | QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool))); |
|
426 | QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool))); | |
427 |
|
427 | |||
428 | QChartView view(new QChart()); |
|
428 | QChartView view(new QChart()); | |
429 | view.resize(400,300); |
|
429 | view.resize(400,300); | |
430 | view.chart()->addSeries(series); |
|
430 | view.chart()->addSeries(series); | |
431 | view.show(); |
|
431 | view.show(); | |
432 | QTest::qWaitForWindowShown(&view); |
|
432 | QTest::qWaitForWindowShown(&view); | |
433 |
|
433 | |||
434 | //this is hack since view does not get events otherwise |
|
434 | //this is hack since view does not get events otherwise | |
435 | view.setMouseTracking(true); |
|
435 | view.setMouseTracking(true); | |
436 |
|
436 | |||
437 | //======================================================================= |
|
437 | //======================================================================= | |
438 | // move mouse to left border |
|
438 | // move mouse to left border | |
439 | QTest::mouseMove(view.viewport(), QPoint(0, 142)); |
|
439 | QTest::mouseMove(view.viewport(), QPoint(0, 142)); | |
440 |
|
440 | |||
441 | QVERIFY(seriesSpy.count() == 0); |
|
441 | QVERIFY(seriesSpy.count() == 0); | |
442 |
|
442 | |||
443 | //======================================================================= |
|
443 | //======================================================================= | |
444 | // move mouse on top of set1 |
|
444 | // move mouse on top of set1 | |
445 | QTest::mouseMove(view.viewport(), QPoint(102,142)); |
|
445 | QTest::mouseMove(view.viewport(), QPoint(102,142)); | |
446 |
|
446 | |||
447 | QVERIFY(seriesSpy.count() == 1); |
|
447 | QVERIFY(seriesSpy.count() == 1); | |
448 |
|
448 | |||
449 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
449 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
450 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
450 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
451 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
451 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
452 | QVERIFY(seriesSpyArg.at(1).toBool() == true); |
|
452 | QVERIFY(seriesSpyArg.at(1).toBool() == true); | |
453 |
|
453 | |||
454 | //======================================================================= |
|
454 | //======================================================================= | |
455 | // move mouse from top of set1 to top of set2 |
|
455 | // move mouse from top of set1 to top of set2 | |
456 | QTest::mouseMove(view.viewport(), QPoint(127,142)); |
|
456 | QTest::mouseMove(view.viewport(), QPoint(127,142)); | |
457 |
|
457 | |||
458 | QVERIFY(seriesSpy.count() == 2); |
|
458 | QVERIFY(seriesSpy.count() == 2); | |
459 |
|
459 | |||
460 | // should leave set1 |
|
460 | // should leave set1 | |
461 | seriesSpyArg = seriesSpy.takeFirst(); |
|
461 | seriesSpyArg = seriesSpy.takeFirst(); | |
462 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
462 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
463 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
463 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
464 | QVERIFY(seriesSpyArg.at(1).toBool() == false); |
|
464 | QVERIFY(seriesSpyArg.at(1).toBool() == false); | |
465 |
|
465 | |||
466 | // should enter set2 |
|
466 | // should enter set2 | |
467 | seriesSpyArg = seriesSpy.takeFirst(); |
|
467 | seriesSpyArg = seriesSpy.takeFirst(); | |
468 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
468 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
469 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
469 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
470 | QVERIFY(seriesSpyArg.at(1).toBool() == true); |
|
470 | QVERIFY(seriesSpyArg.at(1).toBool() == true); | |
471 |
|
471 | |||
472 | //======================================================================= |
|
472 | //======================================================================= | |
473 | // move mouse from top of set2 to background |
|
473 | // move mouse from top of set2 to background | |
474 | QTest::mouseMove(view.viewport(), QPoint(127,0)); |
|
474 | QTest::mouseMove(view.viewport(), QPoint(127,0)); | |
475 | QVERIFY(seriesSpy.count() == 1); |
|
475 | QVERIFY(seriesSpy.count() == 1); | |
476 |
|
476 | |||
477 | // should leave set2 |
|
477 | // should leave set2 | |
478 | seriesSpyArg = seriesSpy.takeFirst(); |
|
478 | seriesSpyArg = seriesSpy.takeFirst(); | |
479 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
479 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
480 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
480 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
481 | QVERIFY(seriesSpyArg.at(1).toBool() == false); |
|
481 | QVERIFY(seriesSpyArg.at(1).toBool() == false); | |
482 | } |
|
482 | } | |
483 |
|
483 | |||
484 | void tst_QBarSeries::clearWithAnimations() |
|
484 | void tst_QBarSeries::clearWithAnimations() | |
485 | { |
|
485 | { | |
486 | QBarSeries* series = new QBarSeries(); |
|
486 | QBarSeries* series = new QBarSeries(); | |
487 |
|
487 | |||
488 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
488 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
489 | *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); |
|
489 | *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
490 | series->append(set1); |
|
490 | series->append(set1); | |
491 |
|
491 | |||
492 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
492 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
493 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); |
|
493 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
494 | series->append(set2); |
|
494 | series->append(set2); | |
495 |
|
495 | |||
496 | QChartView view(new QChart()); |
|
496 | QChartView view(new QChart()); | |
497 | view.resize(400,300); |
|
497 | view.resize(400,300); | |
498 | view.chart()->setAnimationOptions(QChart::SeriesAnimations); |
|
498 | view.chart()->setAnimationOptions(QChart::SeriesAnimations); | |
499 | view.chart()->addSeries(series); |
|
499 | view.chart()->addSeries(series); | |
500 | view.show(); |
|
500 | view.show(); | |
501 |
|
501 | |||
502 | series->clear(); |
|
502 | series->clear(); | |
503 | } |
|
503 | } | |
504 |
|
504 | |||
505 | QTEST_MAIN(tst_QBarSeries) |
|
505 | QTEST_MAIN(tst_QBarSeries) | |
506 |
|
506 | |||
507 | #include "tst_qbarseries.moc" |
|
507 | #include "tst_qbarseries.moc" | |
508 |
|
508 |
General Comments 0
You need to be logged in to leave comments.
Login now