@@ -1,94 +1,89 | |||
|
1 | 1 | ############################# BUILD CONFIG ###################################### |
|
2 | 2 | |
|
3 | 3 | TARGET = QtCharts |
|
4 | 4 | |
|
5 | 5 | QT = core gui widgets |
|
6 | 6 | |
|
7 | 7 | QMAKE_DOCS = $$PWD/doc/qtcharts.qdocconf |
|
8 | 8 | |
|
9 | 9 | QMAKE_TARGET_PRODUCT = "Qt Charts (Qt $$QT_VERSION)" |
|
10 | 10 | QMAKE_TARGET_DESCRIPTION = "Charts component for Qt." |
|
11 | 11 | |
|
12 | 12 | ############################# SOURCES ########################################## |
|
13 | 13 | |
|
14 | 14 | SOURCES += \ |
|
15 | 15 | $$PWD/chartdataset.cpp \ |
|
16 | 16 | $$PWD/chartpresenter.cpp \ |
|
17 | 17 | $$PWD/chartthememanager.cpp \ |
|
18 | 18 | $$PWD/qchart.cpp \ |
|
19 | 19 | $$PWD/qchartview.cpp \ |
|
20 | 20 | $$PWD/qabstractseries.cpp \ |
|
21 | 21 | $$PWD/chartbackground.cpp \ |
|
22 | 22 | $$PWD/chartelement.cpp \ |
|
23 | 23 | $$PWD/chartitem.cpp \ |
|
24 | 24 | $$PWD/scroller.cpp \ |
|
25 | 25 | $$PWD/charttitle.cpp \ |
|
26 | 26 | $$PWD/qpolarchart.cpp |
|
27 | 27 | |
|
28 | 28 | contains(QT_CONFIG, opengl): SOURCES += $$PWD/glwidget.cpp |
|
29 | 29 | |
|
30 | 30 | PRIVATE_HEADERS += \ |
|
31 | 31 | $$PWD/chartdataset_p.h \ |
|
32 | 32 | $$PWD/chartitem_p.h \ |
|
33 | 33 | $$PWD/chartpresenter_p.h \ |
|
34 | 34 | $$PWD/chartthememanager_p.h \ |
|
35 | 35 | $$PWD/chartbackground_p.h \ |
|
36 | 36 | $$PWD/chartelement_p.h \ |
|
37 | 37 | $$PWD/chartconfig_p.h \ |
|
38 | 38 | $$PWD/qchart_p.h \ |
|
39 | 39 | $$PWD/qchartview_p.h \ |
|
40 | 40 | $$PWD/scroller_p.h \ |
|
41 | 41 | $$PWD/qabstractseries_p.h \ |
|
42 | 42 | $$PWD/charttitle_p.h \ |
|
43 | 43 | $$PWD/charthelpers_p.h |
|
44 | 44 | |
|
45 | 45 | contains(QT_CONFIG, opengl): PRIVATE_HEADERS += $$PWD/glwidget_p.h |
|
46 | 46 | |
|
47 | 47 | PUBLIC_HEADERS += \ |
|
48 | 48 | $$PWD/qchart.h \ |
|
49 | 49 | $$PWD/qchartglobal.h \ |
|
50 | 50 | $$PWD/qabstractseries.h \ |
|
51 | 51 | $$PWD/qchartview.h \ |
|
52 | 52 | $$PWD/chartsnamespace.h \ |
|
53 | 53 | $$PWD/qpolarchart.h |
|
54 | 54 | |
|
55 | 55 | include($$PWD/animations/animations.pri) |
|
56 | 56 | include($$PWD/areachart/areachart.pri) |
|
57 | 57 | include($$PWD/axis/axis.pri) |
|
58 | 58 | include($$PWD/domain/domain.pri) |
|
59 | 59 | include($$PWD/barchart/barchart.pri) |
|
60 | 60 | include($$PWD/legend/legend.pri) |
|
61 | 61 | include($$PWD/linechart/linechart.pri) |
|
62 | 62 | include($$PWD/piechart/piechart.pri) |
|
63 | 63 | include($$PWD/scatterchart/scatter.pri) |
|
64 | 64 | include($$PWD/splinechart/splinechart.pri) |
|
65 | 65 | include($$PWD/themes/themes.pri) |
|
66 | 66 | include($$PWD/xychart/xychart.pri) |
|
67 | 67 | include($$PWD/layout/layout.pri) |
|
68 | 68 | include($$PWD/boxplotchart/boxplotchart.pri) |
|
69 | 69 | |
|
70 | 70 | HEADERS += $$PUBLIC_HEADERS |
|
71 | 71 | HEADERS += $$PRIVATE_HEADERS |
|
72 | 72 | HEADERS += $$THEMES |
|
73 | 73 | |
|
74 | 74 | OTHER_FILES += doc/qtcharts.qdocconf \ |
|
75 | 75 | doc/src/* \ |
|
76 | 76 | doc/images/* |
|
77 | 77 | |
|
78 | #Define for unit tests | |
|
79 | CONFIG(debug, debug|release) { | |
|
80 | DEFINES += BUILD_PRIVATE_UNIT_TESTS | |
|
81 | } | |
|
82 | ||
|
83 | 78 | msvc { |
|
84 | 79 | # Suppress "conversion from 'size_t' to 'int', possible loss of data" warnings in 64bit |
|
85 | 80 | # builds resulting from usage of str::sort |
|
86 | 81 | QMAKE_CXXFLAGS_WARN_ON += -wd4267 |
|
87 | 82 | } |
|
88 | 83 | |
|
89 | 84 | win32:!winrt:!wince { |
|
90 | 85 | # ChartThemeSystem uses Windows native API |
|
91 | 86 | LIBS += -luser32 |
|
92 | 87 | } |
|
93 | 88 | |
|
94 | 89 | load(qt_module) |
@@ -1,77 +1,70 | |||
|
1 | 1 | /****************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
|
4 | 4 | ** Contact: http://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:COMM$ |
|
9 | 9 | ** |
|
10 | 10 | ** Commercial License Usage |
|
11 | 11 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
12 | 12 | ** accordance with the commercial license agreement provided with the |
|
13 | 13 | ** Software or, alternatively, in accordance with the terms contained in |
|
14 | 14 | ** a written agreement between you and The Qt Company. For licensing terms |
|
15 | 15 | ** and conditions see http://www.qt.io/terms-conditions. For further |
|
16 | 16 | ** information use the contact form at http://www.qt.io/contact-us. |
|
17 | 17 | ** |
|
18 | 18 | ** $QT_END_LICENSE$ |
|
19 | 19 | ** |
|
20 | 20 | ******************************************************************************/ |
|
21 | 21 | |
|
22 | 22 | #ifndef QCHARTGLOBAL_H |
|
23 | 23 | #define QCHARTGLOBAL_H |
|
24 | 24 | |
|
25 | 25 | #include <QtCore/QtGlobal> |
|
26 | 26 | |
|
27 | 27 | #define QT_CHARTS_VERSION_STR "2.1.1" |
|
28 | 28 | /* |
|
29 | 29 | QT_CHARTS_VERSION is (major << 16) + (minor << 8) + patch. |
|
30 | 30 | */ |
|
31 | 31 | #define QT_CHARTS_VERSION 0x020101 |
|
32 | 32 | /* |
|
33 | 33 | can be used like #if (QT_CHARTS_VERSION >= QT_CHARTS_VERSION_CHECK(1, 1, 0)) |
|
34 | 34 | */ |
|
35 | 35 | #define QT_CHARTS_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch)) |
|
36 | 36 | |
|
37 | 37 | #ifndef QT_STATIC |
|
38 | 38 | # if defined(QT_BUILD_CHARTS_LIB) |
|
39 | 39 | # define QT_CHARTS_EXPORT Q_DECL_EXPORT |
|
40 | 40 | # else |
|
41 | 41 | # define QT_CHARTS_EXPORT Q_DECL_IMPORT |
|
42 | 42 | # endif |
|
43 | 43 | #else |
|
44 | 44 | # define QT_CHARTS_EXPORT |
|
45 | 45 | #endif |
|
46 | 46 | |
|
47 | #if defined(BUILD_PRIVATE_UNIT_TESTS) && defined(QT_BUILD_CHARTS_LIB) | |
|
48 | # define QT_CHARTS_AUTOTEST_EXPORT Q_DECL_EXPORT | |
|
49 | #elif defined(BUILD_PRIVATE_UNIT_TESTS) && !defined(QT_BUILD_CHARTS_LIB) | |
|
50 | # define QT_CHARTS_AUTOTEST_EXPORT Q_DECL_IMPORT | |
|
51 | #else | |
|
52 | # define QT_CHARTS_AUTOTEST_EXPORT | |
|
53 | #endif | |
|
54 | ||
|
47 | #define QT_CHARTS_AUTOTEST_EXPORT Q_AUTOTEST_EXPORT | |
|
55 | 48 | |
|
56 | 49 | #define QT_CHARTS_NAMESPACE QtCharts |
|
57 | 50 | |
|
58 | 51 | #ifdef QT_CHARTS_NAMESPACE |
|
59 | 52 | # define QT_CHARTS_BEGIN_NAMESPACE namespace QT_CHARTS_NAMESPACE { |
|
60 | 53 | # define QT_CHARTS_END_NAMESPACE } |
|
61 | 54 | # define QT_CHARTS_USE_NAMESPACE using namespace QT_CHARTS_NAMESPACE; |
|
62 | 55 | #else |
|
63 | 56 | # define QT_CHARTS_BEGIN_NAMESPACE |
|
64 | 57 | # define QT_CHARTS_END_NAMESPACE |
|
65 | 58 | # define QT_CHARTS_USE_NAMESPACE |
|
66 | 59 | #endif |
|
67 | 60 | |
|
68 | 61 | /* |
|
69 | 62 | On Windows min and max conflict with standard macros |
|
70 | 63 | */ |
|
71 | 64 | #ifdef Q_OS_WIN |
|
72 | 65 | #ifndef NOMINMAX |
|
73 | 66 | #define NOMINMAX |
|
74 | 67 | #endif |
|
75 | 68 | #endif |
|
76 | 69 | |
|
77 | 70 | #endif // QCHARTGLOBAL_H |
@@ -1,15 +1,10 | |||
|
1 | 1 | !include( ../tests.pri ) { |
|
2 | 2 | error( "Couldn't find the tests.pri file!" ) |
|
3 | 3 | } |
|
4 | 4 | |
|
5 | 5 | QT += testlib widgets |
|
6 | 6 | |
|
7 | 7 | !contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_") |
|
8 | 8 | |
|
9 | 9 | INCLUDEPATH += ../inc |
|
10 | 10 | HEADERS += ../inc/tst_definitions.h |
|
11 | ||
|
12 | #Define for unit tests | |
|
13 | CONFIG(debug, debug|release) { | |
|
14 | DEFINES += BUILD_PRIVATE_UNIT_TESTS | |
|
15 | } |
@@ -1,399 +1,399 | |||
|
1 | 1 | /****************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
|
4 | 4 | ** Contact: http://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:COMM$ |
|
9 | 9 | ** |
|
10 | 10 | ** Commercial License Usage |
|
11 | 11 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
12 | 12 | ** accordance with the commercial license agreement provided with the |
|
13 | 13 | ** Software or, alternatively, in accordance with the terms contained in |
|
14 | 14 | ** a written agreement between you and The Qt Company. For licensing terms |
|
15 | 15 | ** and conditions see http://www.qt.io/terms-conditions. For further |
|
16 | 16 | ** information use the contact form at http://www.qt.io/contact-us. |
|
17 | 17 | ** |
|
18 | 18 | ** $QT_END_LICENSE$ |
|
19 | 19 | ** |
|
20 | 20 | ******************************************************************************/ |
|
21 |
#ifndef BUILD_ |
|
|
21 | #ifndef QT_BUILD_INTERNAL | |
|
22 | 22 | #include <QtTest/QtTest> |
|
23 | 23 | |
|
24 | 24 | class tst_ChartDataSet: public QObject { |
|
25 | 25 | |
|
26 | 26 | Q_OBJECT |
|
27 | 27 | |
|
28 | 28 | private Q_SLOTS: |
|
29 | 29 | void skip(); |
|
30 | 30 | |
|
31 | 31 | }; |
|
32 | 32 | |
|
33 | 33 | void tst_ChartDataSet::skip() |
|
34 | 34 | { |
|
35 |
QSKIP("This test requires |
|
|
35 | QSKIP("This test requires a developer build of the library"); | |
|
36 | 36 | } |
|
37 | 37 | |
|
38 | 38 | QTEST_MAIN(tst_ChartDataSet) |
|
39 | 39 | #include "tst_chartdataset.moc" |
|
40 | 40 | |
|
41 | 41 | #else |
|
42 | 42 | |
|
43 | 43 | #include <QtTest/QtTest> |
|
44 | 44 | #include <QtCharts/QAbstractAxis> |
|
45 | 45 | #include <QtCharts/QValueAxis> |
|
46 | 46 | #include <QtCharts/QBarCategoryAxis> |
|
47 | 47 | #include <QtCharts/QCategoryAxis> |
|
48 | 48 | #ifndef QT_ON_ARM |
|
49 | 49 | #include <QtCharts/QDateTimeAxis> |
|
50 | 50 | #endif |
|
51 | 51 | #include <QtCharts/QLineSeries> |
|
52 | 52 | #include <QtCharts/QAreaSeries> |
|
53 | 53 | #include <QtCharts/QScatterSeries> |
|
54 | 54 | #include <QtCharts/QSplineSeries> |
|
55 | 55 | #include <QtCharts/QPieSeries> |
|
56 | 56 | #include <QtCharts/QBarSeries> |
|
57 | 57 | #include <QtCharts/QPercentBarSeries> |
|
58 | 58 | #include <QtCharts/QStackedBarSeries> |
|
59 | 59 | #include <private/chartdataset_p.h> |
|
60 | 60 | #include <private/abstractdomain_p.h> |
|
61 | 61 | #include <tst_definitions.h> |
|
62 | 62 | |
|
63 | 63 | QT_CHARTS_USE_NAMESPACE |
|
64 | 64 | |
|
65 | 65 | Q_DECLARE_METATYPE(AbstractDomain *) |
|
66 | 66 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
67 | 67 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
68 | 68 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
69 | 69 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
70 | 70 | Q_DECLARE_METATYPE(Qt::Alignment) |
|
71 | 71 | Q_DECLARE_METATYPE(QList<Qt::Alignment>) |
|
72 | 72 | Q_DECLARE_METATYPE(QLineSeries *) |
|
73 | 73 | |
|
74 | 74 | class tst_ChartDataSet: public QObject { |
|
75 | 75 | |
|
76 | 76 | Q_OBJECT |
|
77 | 77 | public: |
|
78 | 78 | tst_ChartDataSet():m_dataset(0){}; |
|
79 | 79 | |
|
80 | 80 | public Q_SLOTS: |
|
81 | 81 | void initTestCase(); |
|
82 | 82 | void cleanupTestCase(); |
|
83 | 83 | void init(); |
|
84 | 84 | void cleanup(); |
|
85 | 85 | |
|
86 | 86 | private Q_SLOTS: |
|
87 | 87 | void chartdataset_data(); |
|
88 | 88 | void chartdataset(); |
|
89 | 89 | void addSeries_data(); |
|
90 | 90 | void addSeries(); |
|
91 | 91 | void removeSeries_data(); |
|
92 | 92 | void removeSeries(); |
|
93 | 93 | void addAxis_data(); |
|
94 | 94 | void addAxis(); |
|
95 | 95 | void removeAxis_data(); |
|
96 | 96 | void removeAxis(); |
|
97 | 97 | void attachAxis_data(); |
|
98 | 98 | void attachAxis(); |
|
99 | 99 | void detachAxis_data(); |
|
100 | 100 | void detachAxis(); |
|
101 | 101 | |
|
102 | 102 | private: |
|
103 | 103 | ChartDataSet* m_dataset; |
|
104 | 104 | }; |
|
105 | 105 | |
|
106 | 106 | void tst_ChartDataSet::initTestCase() |
|
107 | 107 | { |
|
108 | 108 | qRegisterMetaType<AbstractDomain*>(); |
|
109 | 109 | qRegisterMetaType<QAbstractAxis*>(); |
|
110 | 110 | qRegisterMetaType<QAbstractSeries*>(); |
|
111 | 111 | } |
|
112 | 112 | |
|
113 | 113 | void tst_ChartDataSet::cleanupTestCase() |
|
114 | 114 | { |
|
115 | 115 | QTest::qWait(1); // Allow final deleteLaters to run |
|
116 | 116 | } |
|
117 | 117 | |
|
118 | 118 | void tst_ChartDataSet::init() |
|
119 | 119 | { |
|
120 | 120 | Q_ASSERT(!m_dataset); |
|
121 | 121 | m_dataset = new ChartDataSet(0); |
|
122 | 122 | } |
|
123 | 123 | |
|
124 | 124 | |
|
125 | 125 | void tst_ChartDataSet::cleanup() |
|
126 | 126 | { |
|
127 | 127 | delete m_dataset; |
|
128 | 128 | m_dataset = 0; |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | void tst_ChartDataSet::chartdataset_data() |
|
132 | 132 | { |
|
133 | 133 | } |
|
134 | 134 | |
|
135 | 135 | void tst_ChartDataSet::chartdataset() |
|
136 | 136 | { |
|
137 | 137 | QVERIFY(m_dataset->axes().isEmpty()); |
|
138 | 138 | QVERIFY(m_dataset->series().isEmpty()); |
|
139 | 139 | m_dataset->createDefaultAxes(); |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | |
|
143 | 143 | void tst_ChartDataSet::addSeries_data() |
|
144 | 144 | { |
|
145 | 145 | QTest::addColumn<QAbstractSeries*>("series"); |
|
146 | 146 | |
|
147 | 147 | QAbstractSeries* line = new QLineSeries(this); |
|
148 | 148 | QTest::newRow("line") << line; |
|
149 | 149 | |
|
150 | 150 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this))); |
|
151 | 151 | QTest::newRow("area") << area; |
|
152 | 152 | |
|
153 | 153 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
154 | 154 | QTest::newRow("scatter") << scatter; |
|
155 | 155 | |
|
156 | 156 | QAbstractSeries* spline = new QSplineSeries(this); |
|
157 | 157 | QTest::newRow("spline") << spline; |
|
158 | 158 | |
|
159 | 159 | QAbstractSeries* pie = new QPieSeries(this); |
|
160 | 160 | QTest::newRow("pie") << pie; |
|
161 | 161 | |
|
162 | 162 | QAbstractSeries* bar = new QBarSeries(this); |
|
163 | 163 | QTest::newRow("bar") << bar; |
|
164 | 164 | |
|
165 | 165 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
166 | 166 | QTest::newRow("percent") << percent; |
|
167 | 167 | |
|
168 | 168 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
169 | 169 | QTest::newRow("stacked") << stacked; |
|
170 | 170 | } |
|
171 | 171 | |
|
172 | 172 | void tst_ChartDataSet::addSeries() |
|
173 | 173 | { |
|
174 | 174 | QFETCH(QAbstractSeries*, series); |
|
175 | 175 | QVERIFY(m_dataset->series().isEmpty()); |
|
176 | 176 | |
|
177 | 177 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
178 | 178 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
179 | 179 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
180 | 180 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
181 | 181 | |
|
182 | 182 | m_dataset->addSeries(series); |
|
183 | 183 | |
|
184 | 184 | QCOMPARE(m_dataset->series().count(),1); |
|
185 | 185 | TRY_COMPARE(spy0.count(), 0); |
|
186 | 186 | TRY_COMPARE(spy1.count(), 0); |
|
187 | 187 | TRY_COMPARE(spy2.count(), 1); |
|
188 | 188 | TRY_COMPARE(spy3.count(), 0); |
|
189 | 189 | } |
|
190 | 190 | |
|
191 | 191 | void tst_ChartDataSet::removeSeries_data() |
|
192 | 192 | { |
|
193 | 193 | addSeries_data(); |
|
194 | 194 | } |
|
195 | 195 | |
|
196 | 196 | void tst_ChartDataSet::removeSeries() |
|
197 | 197 | { |
|
198 | 198 | QFETCH(QAbstractSeries*, series); |
|
199 | 199 | QVERIFY(m_dataset->series().isEmpty()); |
|
200 | 200 | m_dataset->addSeries(series); |
|
201 | 201 | |
|
202 | 202 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
203 | 203 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
204 | 204 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
205 | 205 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
206 | 206 | |
|
207 | 207 | m_dataset->removeSeries(series); |
|
208 | 208 | |
|
209 | 209 | QCOMPARE(m_dataset->series().count(),0); |
|
210 | 210 | TRY_COMPARE(spy0.count(), 0); |
|
211 | 211 | TRY_COMPARE(spy1.count(), 0); |
|
212 | 212 | TRY_COMPARE(spy2.count(), 0); |
|
213 | 213 | TRY_COMPARE(spy3.count(), 1); |
|
214 | 214 | |
|
215 | 215 | delete series; |
|
216 | 216 | } |
|
217 | 217 | |
|
218 | 218 | void tst_ChartDataSet::addAxis_data() |
|
219 | 219 | { |
|
220 | 220 | QTest::addColumn<QAbstractAxis*>("axis"); |
|
221 | 221 | QAbstractAxis* value = new QValueAxis(this); |
|
222 | 222 | QAbstractAxis* category = new QCategoryAxis(this); |
|
223 | 223 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); |
|
224 | 224 | #ifndef Q_WS_QWS |
|
225 | 225 | QAbstractAxis* datetime = new QDateTimeAxis(this); |
|
226 | 226 | #endif |
|
227 | 227 | |
|
228 | 228 | QTest::newRow("value") << value; |
|
229 | 229 | QTest::newRow("category") << category; |
|
230 | 230 | QTest::newRow("barcategory") << barcategory; |
|
231 | 231 | #ifndef Q_WS_QWS |
|
232 | 232 | QTest::newRow("datetime") << datetime; |
|
233 | 233 | #endif |
|
234 | 234 | } |
|
235 | 235 | |
|
236 | 236 | void tst_ChartDataSet::addAxis() |
|
237 | 237 | { |
|
238 | 238 | QFETCH(QAbstractAxis*, axis); |
|
239 | 239 | QVERIFY(m_dataset->axes().isEmpty()); |
|
240 | 240 | |
|
241 | 241 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
242 | 242 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
243 | 243 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
244 | 244 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
245 | 245 | |
|
246 | 246 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
247 | 247 | |
|
248 | 248 | QCOMPARE(m_dataset->axes().count(),1); |
|
249 | 249 | TRY_COMPARE(spy0.count(), 1); |
|
250 | 250 | TRY_COMPARE(spy1.count(), 0); |
|
251 | 251 | TRY_COMPARE(spy2.count(), 0); |
|
252 | 252 | TRY_COMPARE(spy3.count(), 0); |
|
253 | 253 | } |
|
254 | 254 | |
|
255 | 255 | void tst_ChartDataSet::removeAxis_data() |
|
256 | 256 | { |
|
257 | 257 | addAxis_data(); |
|
258 | 258 | } |
|
259 | 259 | |
|
260 | 260 | void tst_ChartDataSet::removeAxis() |
|
261 | 261 | { |
|
262 | 262 | QFETCH(QAbstractAxis*, axis); |
|
263 | 263 | QVERIFY(m_dataset->series().isEmpty()); |
|
264 | 264 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
265 | 265 | |
|
266 | 266 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
267 | 267 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
268 | 268 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
269 | 269 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
270 | 270 | |
|
271 | 271 | m_dataset->removeAxis(axis); |
|
272 | 272 | |
|
273 | 273 | QCOMPARE(m_dataset->axes().count(),0); |
|
274 | 274 | QCOMPARE(m_dataset->series().count(),0); |
|
275 | 275 | TRY_COMPARE(spy0.count(), 0); |
|
276 | 276 | TRY_COMPARE(spy1.count(), 1); |
|
277 | 277 | TRY_COMPARE(spy2.count(), 0); |
|
278 | 278 | TRY_COMPARE(spy3.count(), 0); |
|
279 | 279 | |
|
280 | 280 | delete axis; |
|
281 | 281 | } |
|
282 | 282 | |
|
283 | 283 | void tst_ChartDataSet::attachAxis_data() |
|
284 | 284 | { |
|
285 | 285 | |
|
286 | 286 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
287 | 287 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
288 | 288 | QTest::addColumn<QList<Qt::Alignment> >("alignment"); |
|
289 | 289 | QTest::addColumn<QAbstractSeries*>("attachSeries"); |
|
290 | 290 | QTest::addColumn<QAbstractAxis*>("attachAxis"); |
|
291 | 291 | QTest::addColumn<bool>("success"); |
|
292 | 292 | |
|
293 | 293 | { |
|
294 | 294 | QList<QAbstractSeries*> series; |
|
295 | 295 | QList<QAbstractAxis*> axes; |
|
296 | 296 | QList<Qt::Alignment> alignment; |
|
297 | 297 | QAbstractSeries* line = new QLineSeries(this); |
|
298 | 298 | QAbstractAxis* value1 = new QValueAxis(this); |
|
299 | 299 | QAbstractAxis* value2 = new QValueAxis(this); |
|
300 | 300 | series << line << 0; |
|
301 | 301 | axes << value1 << value2; |
|
302 | 302 | alignment << Qt::AlignBottom << Qt::AlignLeft; |
|
303 | 303 | QTest::newRow("first") << series << axes << alignment << line << value2 << true ; |
|
304 | 304 | } |
|
305 | 305 | |
|
306 | 306 | { |
|
307 | 307 | QList<QAbstractSeries*> series; |
|
308 | 308 | QList<QAbstractAxis*> axes; |
|
309 | 309 | QList<Qt::Alignment> alignment; |
|
310 | 310 | QAbstractSeries* line = new QLineSeries(this); |
|
311 | 311 | QAbstractAxis* value1 = new QValueAxis(this); |
|
312 | 312 | QAbstractAxis* value2 = new QValueAxis(this); |
|
313 | 313 | series << 0 << line; |
|
314 | 314 | axes << value1 << value2; |
|
315 | 315 | alignment << Qt::AlignBottom << Qt::AlignLeft; |
|
316 | 316 | QTest::newRow("second") << series << axes << alignment << line << value1 << true; |
|
317 | 317 | } |
|
318 | 318 | |
|
319 | 319 | } |
|
320 | 320 | |
|
321 | 321 | void tst_ChartDataSet::attachAxis() |
|
322 | 322 | { |
|
323 | 323 | QFETCH(QList<QAbstractSeries*>, series); |
|
324 | 324 | QFETCH(QList<QAbstractAxis*>, axis); |
|
325 | 325 | QFETCH(QList<Qt::Alignment>, alignment); |
|
326 | 326 | QFETCH(QAbstractSeries*, attachSeries); |
|
327 | 327 | QFETCH(QAbstractAxis*, attachAxis); |
|
328 | 328 | QFETCH(bool, success); |
|
329 | 329 | |
|
330 | 330 | Q_ASSERT(series.count() == axis.count()); |
|
331 | 331 | Q_ASSERT(series.count() == alignment.count()); |
|
332 | 332 | |
|
333 | 333 | QVERIFY(m_dataset->series().isEmpty()); |
|
334 | 334 | QVERIFY(m_dataset->axes().isEmpty()); |
|
335 | 335 | |
|
336 | 336 | for(int i = 0 ; i < series.count() ; i++){ |
|
337 | 337 | if(series[i]) m_dataset->addSeries(series[i]); |
|
338 | 338 | if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]); |
|
339 | 339 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); |
|
340 | 340 | } |
|
341 | 341 | |
|
342 | 342 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
343 | 343 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
344 | 344 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
345 | 345 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
346 | 346 | |
|
347 | 347 | QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success); |
|
348 | 348 | |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | void tst_ChartDataSet::detachAxis_data() |
|
352 | 352 | { |
|
353 | 353 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
354 | 354 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
355 | 355 | QTest::addColumn<QAbstractSeries*>("detachSeries"); |
|
356 | 356 | QTest::addColumn<QAbstractAxis*>("detachAxis"); |
|
357 | 357 | QTest::addColumn<bool>("success"); |
|
358 | 358 | |
|
359 | 359 | { |
|
360 | 360 | QList<QAbstractSeries*> series; |
|
361 | 361 | QList<QAbstractAxis*> axes; |
|
362 | 362 | QAbstractSeries* line = new QLineSeries(this); |
|
363 | 363 | QAbstractAxis* value = new QValueAxis(this); |
|
364 | 364 | series << line; |
|
365 | 365 | axes << value; |
|
366 | 366 | QTest::newRow("first") << series << axes << line << value << true; |
|
367 | 367 | } |
|
368 | 368 | } |
|
369 | 369 | |
|
370 | 370 | void tst_ChartDataSet::detachAxis() |
|
371 | 371 | { |
|
372 | 372 | QFETCH(QList<QAbstractSeries*>, series); |
|
373 | 373 | QFETCH(QList<QAbstractAxis*>, axis); |
|
374 | 374 | QFETCH(QAbstractSeries*, detachSeries); |
|
375 | 375 | QFETCH(QAbstractAxis*, detachAxis); |
|
376 | 376 | QFETCH(bool, success); |
|
377 | 377 | |
|
378 | 378 | Q_ASSERT(series.count() == axis.count()); |
|
379 | 379 | |
|
380 | 380 | QVERIFY(m_dataset->series().isEmpty()); |
|
381 | 381 | QVERIFY(m_dataset->axes().isEmpty()); |
|
382 | 382 | |
|
383 | 383 | for(int i = 0; i < series.count(); i++) { |
|
384 | 384 | if(series[i]) m_dataset->addSeries(series[i]); |
|
385 | 385 | if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom); |
|
386 | 386 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); |
|
387 | 387 | } |
|
388 | 388 | |
|
389 | 389 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
390 | 390 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
391 | 391 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
392 | 392 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
393 | 393 | |
|
394 | 394 | QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success); |
|
395 | 395 | } |
|
396 | 396 | |
|
397 | 397 | QTEST_MAIN(tst_ChartDataSet) |
|
398 | 398 | #include "tst_chartdataset.moc" |
|
399 | 399 | #endif |
@@ -1,748 +1,748 | |||
|
1 | 1 | /****************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2015 The Qt Company Ltd. |
|
4 | 4 | ** Contact: http://www.qt.io/licensing/ |
|
5 | 5 | ** |
|
6 | 6 | ** This file is part of the Qt Charts module. |
|
7 | 7 | ** |
|
8 | 8 | ** $QT_BEGIN_LICENSE:COMM$ |
|
9 | 9 | ** |
|
10 | 10 | ** Commercial License Usage |
|
11 | 11 | ** Licensees holding valid commercial Qt licenses may use this file in |
|
12 | 12 | ** accordance with the commercial license agreement provided with the |
|
13 | 13 | ** Software or, alternatively, in accordance with the terms contained in |
|
14 | 14 | ** a written agreement between you and The Qt Company. For licensing terms |
|
15 | 15 | ** and conditions see http://www.qt.io/terms-conditions. For further |
|
16 | 16 | ** information use the contact form at http://www.qt.io/contact-us. |
|
17 | 17 | ** |
|
18 | 18 | ** $QT_END_LICENSE$ |
|
19 | 19 | ** |
|
20 | 20 | ******************************************************************************/ |
|
21 |
#ifndef BUILD_ |
|
|
21 | #ifndef QT_BUILD_INTERNAL | |
|
22 | 22 | |
|
23 | 23 | #include <QtTest/QtTest> |
|
24 | 24 | |
|
25 | 25 | class tst_Domain: public QObject { |
|
26 | 26 | |
|
27 | 27 | Q_OBJECT |
|
28 | 28 | |
|
29 | 29 | private Q_SLOTS: |
|
30 | 30 | void skip(); |
|
31 | 31 | |
|
32 | 32 | }; |
|
33 | 33 | |
|
34 | 34 | void tst_Domain::skip() |
|
35 | 35 | { |
|
36 |
QSKIP("This test requires |
|
|
36 | QSKIP("This test requires a developer build of the library"); | |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | QTEST_MAIN(tst_Domain) |
|
40 | 40 | #include "tst_domain.moc" |
|
41 | 41 | |
|
42 | 42 | #else |
|
43 | 43 | |
|
44 | 44 | #include <QtTest/QtTest> |
|
45 | 45 | #include <private/xydomain_p.h> |
|
46 | 46 | #include <private/qabstractaxis_p.h> |
|
47 | 47 | #include <tst_definitions.h> |
|
48 | 48 | |
|
49 | 49 | QT_CHARTS_USE_NAMESPACE |
|
50 | 50 | |
|
51 | 51 | Q_DECLARE_METATYPE(XYDomain*) |
|
52 | 52 | Q_DECLARE_METATYPE(QSizeF) |
|
53 | 53 | Q_DECLARE_METATYPE(QMargins) |
|
54 | 54 | |
|
55 | 55 | |
|
56 | 56 | class AxisMock: public QAbstractAxisPrivate |
|
57 | 57 | { |
|
58 | 58 | Q_OBJECT |
|
59 | 59 | public: |
|
60 | 60 | AxisMock(Qt::Alignment alignment):QAbstractAxisPrivate(0){ setAlignment(alignment);}; |
|
61 | 61 | void initializeGraphics(QGraphicsItem* item) |
|
62 | 62 | { |
|
63 | 63 | Q_UNUSED(item); |
|
64 | 64 | }; |
|
65 | 65 | |
|
66 | 66 | void initializeDomain(AbstractDomain* domain) |
|
67 | 67 | { |
|
68 | 68 | Q_UNUSED(domain); |
|
69 | 69 | }; |
|
70 | 70 | void setMin(const QVariant &min) |
|
71 | 71 | { |
|
72 | 72 | Q_UNUSED(min); |
|
73 | 73 | } |
|
74 | 74 | qreal min() { return m_min;} |
|
75 | 75 | void setMax(const QVariant &max) |
|
76 | 76 | { |
|
77 | 77 | Q_UNUSED(max); |
|
78 | 78 | } |
|
79 | 79 | qreal max() { return m_max; } |
|
80 | 80 | void setRange(const QVariant &min, const QVariant &max) |
|
81 | 81 | { |
|
82 | 82 | Q_UNUSED(min); |
|
83 | 83 | Q_UNUSED(max); |
|
84 | 84 | }; |
|
85 | 85 | |
|
86 | 86 | void setRange(qreal min, qreal max) |
|
87 | 87 | { |
|
88 | 88 | m_min=min; |
|
89 | 89 | m_max=max; |
|
90 | 90 | emit rangeChanged(min,max); |
|
91 | 91 | }; |
|
92 | 92 | |
|
93 | 93 | int count () const { return m_count; } |
|
94 | 94 | |
|
95 | 95 | void handleDomainUpdated(){}; |
|
96 | 96 | public: |
|
97 | 97 | int m_count; |
|
98 | 98 | qreal m_min; |
|
99 | 99 | qreal m_max; |
|
100 | 100 | }; |
|
101 | 101 | |
|
102 | 102 | class tst_Domain: public QObject |
|
103 | 103 | { |
|
104 | 104 | Q_OBJECT |
|
105 | 105 | |
|
106 | 106 | public Q_SLOTS: |
|
107 | 107 | void initTestCase(); |
|
108 | 108 | void cleanupTestCase(); |
|
109 | 109 | void init(); |
|
110 | 110 | void cleanup(); |
|
111 | 111 | |
|
112 | 112 | private Q_SLOTS: |
|
113 | 113 | void domain(); |
|
114 | 114 | void handleHorizontalAxisRangeChanged_data(); |
|
115 | 115 | void handleHorizontalAxisRangeChanged(); |
|
116 | 116 | void handleVerticalAxisRangeChanged_data(); |
|
117 | 117 | void handleVerticalAxisRangeChanged(); |
|
118 | 118 | void isEmpty_data(); |
|
119 | 119 | void isEmpty(); |
|
120 | 120 | void maxX_data(); |
|
121 | 121 | void maxX(); |
|
122 | 122 | void maxY_data(); |
|
123 | 123 | void maxY(); |
|
124 | 124 | void minX_data(); |
|
125 | 125 | void minX(); |
|
126 | 126 | void minY_data(); |
|
127 | 127 | void minY(); |
|
128 | 128 | void operatorEquals_data(); |
|
129 | 129 | void operatorEquals(); |
|
130 | 130 | void setRange_data(); |
|
131 | 131 | void setRange(); |
|
132 | 132 | void setRangeX_data(); |
|
133 | 133 | void setRangeX(); |
|
134 | 134 | void setRangeY_data(); |
|
135 | 135 | void setRangeY(); |
|
136 | 136 | void spanX_data(); |
|
137 | 137 | void spanX(); |
|
138 | 138 | void spanY_data(); |
|
139 | 139 | void spanY(); |
|
140 | 140 | void zoomIn_data(); |
|
141 | 141 | void zoomIn(); |
|
142 | 142 | void zoomOut_data(); |
|
143 | 143 | void zoomOut(); |
|
144 | 144 | void move_data(); |
|
145 | 145 | void move(); |
|
146 | 146 | }; |
|
147 | 147 | |
|
148 | 148 | void tst_Domain::initTestCase() |
|
149 | 149 | { |
|
150 | 150 | } |
|
151 | 151 | |
|
152 | 152 | void tst_Domain::cleanupTestCase() |
|
153 | 153 | { |
|
154 | 154 | QTest::qWait(1); // Allow final deleteLaters to run |
|
155 | 155 | } |
|
156 | 156 | |
|
157 | 157 | void tst_Domain::init() |
|
158 | 158 | { |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | void tst_Domain::cleanup() |
|
162 | 162 | { |
|
163 | 163 | } |
|
164 | 164 | |
|
165 | 165 | void tst_Domain::domain() |
|
166 | 166 | { |
|
167 | 167 | XYDomain domain; |
|
168 | 168 | |
|
169 | 169 | QCOMPARE(domain.isEmpty(), true); |
|
170 | 170 | QCOMPARE(domain.maxX(), 0.0); |
|
171 | 171 | QCOMPARE(domain.maxY(), 0.0); |
|
172 | 172 | QCOMPARE(domain.minX(), 0.0); |
|
173 | 173 | QCOMPARE(domain.minY(), 0.0); |
|
174 | 174 | } |
|
175 | 175 | |
|
176 | 176 | void tst_Domain::handleHorizontalAxisRangeChanged_data() |
|
177 | 177 | { |
|
178 | 178 | QTest::addColumn<qreal>("min"); |
|
179 | 179 | QTest::addColumn<qreal>("max"); |
|
180 | 180 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
181 | 181 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
182 | 182 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
183 | 183 | } |
|
184 | 184 | |
|
185 | 185 | void tst_Domain::handleHorizontalAxisRangeChanged() |
|
186 | 186 | { |
|
187 | 187 | QFETCH(qreal, min); |
|
188 | 188 | QFETCH(qreal, max); |
|
189 | 189 | |
|
190 | 190 | XYDomain domain; |
|
191 | 191 | |
|
192 | 192 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
193 | 193 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
194 | 194 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
195 | 195 | |
|
196 | 196 | AxisMock axis(Qt::AlignBottom); |
|
197 | 197 | QObject::connect(&axis,SIGNAL(rangeChanged(qreal,qreal)),&domain,SLOT(handleHorizontalAxisRangeChanged(qreal,qreal))); |
|
198 | 198 | axis.setRange(min,max); |
|
199 | 199 | |
|
200 | 200 | QVERIFY(qFuzzyCompare(domain.minX(), min)); |
|
201 | 201 | QVERIFY(qFuzzyCompare(domain.maxX(), max)); |
|
202 | 202 | |
|
203 | 203 | QList<QVariant> arg1 = spy1.first(); |
|
204 | 204 | QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min)); |
|
205 | 205 | QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max)); |
|
206 | 206 | |
|
207 | 207 | TRY_COMPARE(spy0.count(), 1); |
|
208 | 208 | TRY_COMPARE(spy1.count(), 1); |
|
209 | 209 | TRY_COMPARE(spy2.count(), 0); |
|
210 | 210 | |
|
211 | 211 | } |
|
212 | 212 | |
|
213 | 213 | void tst_Domain::handleVerticalAxisRangeChanged_data() |
|
214 | 214 | { |
|
215 | 215 | QTest::addColumn<qreal>("min"); |
|
216 | 216 | QTest::addColumn<qreal>("max"); |
|
217 | 217 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
218 | 218 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
219 | 219 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
220 | 220 | } |
|
221 | 221 | |
|
222 | 222 | void tst_Domain::handleVerticalAxisRangeChanged() |
|
223 | 223 | { |
|
224 | 224 | QFETCH(qreal, min); |
|
225 | 225 | QFETCH(qreal, max); |
|
226 | 226 | |
|
227 | 227 | XYDomain domain; |
|
228 | 228 | |
|
229 | 229 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
230 | 230 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
231 | 231 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
232 | 232 | |
|
233 | 233 | AxisMock axis(Qt::AlignLeft); |
|
234 | 234 | QObject::connect(&axis, SIGNAL(rangeChanged(qreal,qreal)), &domain, SLOT(handleVerticalAxisRangeChanged(qreal,qreal))); |
|
235 | 235 | axis.setRange(min,max); |
|
236 | 236 | |
|
237 | 237 | QVERIFY(qFuzzyCompare(domain.minY(), min)); |
|
238 | 238 | QVERIFY(qFuzzyCompare(domain.maxY(), max)); |
|
239 | 239 | |
|
240 | 240 | QList<QVariant> arg1 = spy2.first(); |
|
241 | 241 | QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min)); |
|
242 | 242 | QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max)); |
|
243 | 243 | |
|
244 | 244 | TRY_COMPARE(spy0.count(), 1); |
|
245 | 245 | TRY_COMPARE(spy1.count(), 0); |
|
246 | 246 | TRY_COMPARE(spy2.count(), 1); |
|
247 | 247 | } |
|
248 | 248 | |
|
249 | 249 | void tst_Domain::isEmpty_data() |
|
250 | 250 | { |
|
251 | 251 | QTest::addColumn<qreal>("minX"); |
|
252 | 252 | QTest::addColumn<qreal>("maxX"); |
|
253 | 253 | QTest::addColumn<qreal>("minY"); |
|
254 | 254 | QTest::addColumn<qreal>("maxY"); |
|
255 | 255 | QTest::addColumn<QSizeF>("size"); |
|
256 | 256 | QTest::addColumn<bool>("isEmpty"); |
|
257 | 257 | QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << QSizeF(1,1) << true; |
|
258 | 258 | QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << QSizeF(1,1) << true; |
|
259 | 259 | QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << QSizeF(1,1) << true; |
|
260 | 260 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << QSizeF(1,1) << false; |
|
261 | 261 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << QSizeF(-11,1) << true; |
|
262 | 262 | } |
|
263 | 263 | |
|
264 | 264 | void tst_Domain::isEmpty() |
|
265 | 265 | { |
|
266 | 266 | QFETCH(qreal, minX); |
|
267 | 267 | QFETCH(qreal, maxX); |
|
268 | 268 | QFETCH(qreal, minY); |
|
269 | 269 | QFETCH(qreal, maxY); |
|
270 | 270 | QFETCH(QSizeF, size); |
|
271 | 271 | QFETCH(bool, isEmpty); |
|
272 | 272 | |
|
273 | 273 | XYDomain domain; |
|
274 | 274 | domain.setRange(minX, maxX, minY, maxY); |
|
275 | 275 | domain.setSize(size); |
|
276 | 276 | QCOMPARE(domain.isEmpty(), isEmpty); |
|
277 | 277 | } |
|
278 | 278 | |
|
279 | 279 | void tst_Domain::maxX_data() |
|
280 | 280 | { |
|
281 | 281 | QTest::addColumn<qreal>("maxX1"); |
|
282 | 282 | QTest::addColumn<qreal>("maxX2"); |
|
283 | 283 | QTest::addColumn<int>("count"); |
|
284 | 284 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
285 | 285 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
286 | 286 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
287 | 287 | } |
|
288 | 288 | |
|
289 | 289 | void tst_Domain::maxX() |
|
290 | 290 | { |
|
291 | 291 | QFETCH(qreal, maxX1); |
|
292 | 292 | QFETCH(qreal, maxX2); |
|
293 | 293 | QFETCH(int, count); |
|
294 | 294 | |
|
295 | 295 | XYDomain domain; |
|
296 | 296 | |
|
297 | 297 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
298 | 298 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
299 | 299 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
300 | 300 | |
|
301 | 301 | domain.setMaxX(maxX1); |
|
302 | 302 | QCOMPARE(domain.maxX(), maxX1); |
|
303 | 303 | domain.setMaxX(maxX2); |
|
304 | 304 | QCOMPARE(domain.maxX(), maxX2); |
|
305 | 305 | |
|
306 | 306 | TRY_COMPARE(spy0.count(), count); |
|
307 | 307 | TRY_COMPARE(spy1.count(), count); |
|
308 | 308 | TRY_COMPARE(spy2.count(), 0); |
|
309 | 309 | |
|
310 | 310 | } |
|
311 | 311 | |
|
312 | 312 | void tst_Domain::maxY_data() |
|
313 | 313 | { |
|
314 | 314 | QTest::addColumn<qreal>("maxY1"); |
|
315 | 315 | QTest::addColumn<qreal>("maxY2"); |
|
316 | 316 | QTest::addColumn<int>("count"); |
|
317 | 317 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
318 | 318 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
319 | 319 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
320 | 320 | } |
|
321 | 321 | |
|
322 | 322 | void tst_Domain::maxY() |
|
323 | 323 | { |
|
324 | 324 | QFETCH(qreal, maxY1); |
|
325 | 325 | QFETCH(qreal, maxY2); |
|
326 | 326 | QFETCH(int, count); |
|
327 | 327 | |
|
328 | 328 | XYDomain domain; |
|
329 | 329 | |
|
330 | 330 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
331 | 331 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
332 | 332 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
333 | 333 | |
|
334 | 334 | domain.setMaxY(maxY1); |
|
335 | 335 | QCOMPARE(domain.maxY(), maxY1); |
|
336 | 336 | domain.setMaxY(maxY2); |
|
337 | 337 | QCOMPARE(domain.maxY(), maxY2); |
|
338 | 338 | |
|
339 | 339 | TRY_COMPARE(spy0.count(), count); |
|
340 | 340 | TRY_COMPARE(spy1.count(), 0); |
|
341 | 341 | TRY_COMPARE(spy2.count(), count); |
|
342 | 342 | } |
|
343 | 343 | |
|
344 | 344 | void tst_Domain::minX_data() |
|
345 | 345 | { |
|
346 | 346 | QTest::addColumn<qreal>("minX1"); |
|
347 | 347 | QTest::addColumn<qreal>("minX2"); |
|
348 | 348 | QTest::addColumn<int>("count"); |
|
349 | 349 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
350 | 350 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
351 | 351 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
352 | 352 | } |
|
353 | 353 | |
|
354 | 354 | void tst_Domain::minX() |
|
355 | 355 | { |
|
356 | 356 | QFETCH(qreal, minX1); |
|
357 | 357 | QFETCH(qreal, minX2); |
|
358 | 358 | QFETCH(int, count); |
|
359 | 359 | |
|
360 | 360 | XYDomain domain; |
|
361 | 361 | |
|
362 | 362 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
363 | 363 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
364 | 364 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
365 | 365 | |
|
366 | 366 | domain.setMinX(minX1); |
|
367 | 367 | QCOMPARE(domain.minX(), minX1); |
|
368 | 368 | domain.setMinX(minX2); |
|
369 | 369 | QCOMPARE(domain.minX(), minX2); |
|
370 | 370 | |
|
371 | 371 | TRY_COMPARE(spy0.count(), count); |
|
372 | 372 | TRY_COMPARE(spy1.count(), count); |
|
373 | 373 | TRY_COMPARE(spy2.count(), 0); |
|
374 | 374 | } |
|
375 | 375 | |
|
376 | 376 | void tst_Domain::minY_data() |
|
377 | 377 | { |
|
378 | 378 | QTest::addColumn<qreal>("minY1"); |
|
379 | 379 | QTest::addColumn<qreal>("minY2"); |
|
380 | 380 | QTest::addColumn<int>("count"); |
|
381 | 381 | QTest::newRow("1") << 0.0 << 1.0 << 1; |
|
382 | 382 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; |
|
383 | 383 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; |
|
384 | 384 | } |
|
385 | 385 | |
|
386 | 386 | void tst_Domain::minY() |
|
387 | 387 | { |
|
388 | 388 | QFETCH(qreal, minY1); |
|
389 | 389 | QFETCH(qreal, minY2); |
|
390 | 390 | QFETCH(int, count); |
|
391 | 391 | |
|
392 | 392 | XYDomain domain; |
|
393 | 393 | |
|
394 | 394 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
395 | 395 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
396 | 396 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
397 | 397 | |
|
398 | 398 | domain.setMinY(minY1); |
|
399 | 399 | QCOMPARE(domain.minY(), minY1); |
|
400 | 400 | domain.setMinY(minY2); |
|
401 | 401 | QCOMPARE(domain.minY(), minY2); |
|
402 | 402 | |
|
403 | 403 | TRY_COMPARE(spy0.count(), count); |
|
404 | 404 | TRY_COMPARE(spy1.count(), 0); |
|
405 | 405 | TRY_COMPARE(spy2.count(), count); |
|
406 | 406 | } |
|
407 | 407 | |
|
408 | 408 | void tst_Domain::operatorEquals_data() |
|
409 | 409 | { |
|
410 | 410 | |
|
411 | 411 | QTest::addColumn<XYDomain*>("domain1"); |
|
412 | 412 | QTest::addColumn<XYDomain*>("domain2"); |
|
413 | 413 | QTest::addColumn<bool>("equals"); |
|
414 | 414 | QTest::addColumn<bool>("notEquals"); |
|
415 | 415 | XYDomain* a; |
|
416 | 416 | XYDomain* b; |
|
417 | 417 | a = new XYDomain(); |
|
418 | 418 | a->setRange(0, 100, 0, 100); |
|
419 | 419 | b = new XYDomain(); |
|
420 | 420 | b->setRange(0, 100, 0, 100); |
|
421 | 421 | QTest::newRow("equals") << a << b << true << false; |
|
422 | 422 | a = new XYDomain(); |
|
423 | 423 | a->setRange(0, 100, 0, 100); |
|
424 | 424 | b = new XYDomain(); |
|
425 | 425 | b->setRange(0, 100, 0, 1); |
|
426 | 426 | QTest::newRow("equals") << a << b << false << true; |
|
427 | 427 | a = new XYDomain(); |
|
428 | 428 | a->setRange(0, 100, 0, 100); |
|
429 | 429 | b = new XYDomain(); |
|
430 | 430 | b->setRange(0, 1, 0, 100); |
|
431 | 431 | QTest::newRow("equals") << a << b << false << true; |
|
432 | 432 | |
|
433 | 433 | } |
|
434 | 434 | |
|
435 | 435 | void tst_Domain::operatorEquals() |
|
436 | 436 | { |
|
437 | 437 | QFETCH(XYDomain*, domain1); |
|
438 | 438 | QFETCH(XYDomain*, domain2); |
|
439 | 439 | QFETCH(bool, equals); |
|
440 | 440 | QFETCH(bool, notEquals); |
|
441 | 441 | |
|
442 | 442 | XYDomain domain; |
|
443 | 443 | |
|
444 | 444 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
445 | 445 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
446 | 446 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
447 | 447 | |
|
448 | 448 | QCOMPARE(*domain1==*domain2, equals); |
|
449 | 449 | QCOMPARE(*domain1!=*domain2, notEquals); |
|
450 | 450 | |
|
451 | 451 | TRY_COMPARE(spy0.count(), 0); |
|
452 | 452 | TRY_COMPARE(spy1.count(), 0); |
|
453 | 453 | TRY_COMPARE(spy2.count(), 0); |
|
454 | 454 | |
|
455 | 455 | delete domain1; |
|
456 | 456 | delete domain2; |
|
457 | 457 | } |
|
458 | 458 | |
|
459 | 459 | void tst_Domain::setRange_data() |
|
460 | 460 | { |
|
461 | 461 | QTest::addColumn<qreal>("minX"); |
|
462 | 462 | QTest::addColumn<qreal>("maxX"); |
|
463 | 463 | QTest::addColumn<qreal>("minY"); |
|
464 | 464 | QTest::addColumn<qreal>("maxY"); |
|
465 | 465 | QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0; |
|
466 | 466 | QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0; |
|
467 | 467 | QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0; |
|
468 | 468 | } |
|
469 | 469 | |
|
470 | 470 | void tst_Domain::setRange() |
|
471 | 471 | { |
|
472 | 472 | QFETCH(qreal, minX); |
|
473 | 473 | QFETCH(qreal, maxX); |
|
474 | 474 | QFETCH(qreal, minY); |
|
475 | 475 | QFETCH(qreal, maxY); |
|
476 | 476 | |
|
477 | 477 | XYDomain domain; |
|
478 | 478 | |
|
479 | 479 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
480 | 480 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
481 | 481 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
482 | 482 | |
|
483 | 483 | domain.setRange(minX, maxX, minY, maxY); |
|
484 | 484 | |
|
485 | 485 | QCOMPARE(domain.minX(), minX); |
|
486 | 486 | QCOMPARE(domain.maxX(), maxX); |
|
487 | 487 | QCOMPARE(domain.minY(), minY); |
|
488 | 488 | QCOMPARE(domain.maxY(), maxY); |
|
489 | 489 | |
|
490 | 490 | TRY_COMPARE(spy0.count(), 1); |
|
491 | 491 | TRY_COMPARE(spy1.count(), 1); |
|
492 | 492 | TRY_COMPARE(spy2.count(), 1); |
|
493 | 493 | |
|
494 | 494 | } |
|
495 | 495 | |
|
496 | 496 | void tst_Domain::setRangeX_data() |
|
497 | 497 | { |
|
498 | 498 | QTest::addColumn<qreal>("min"); |
|
499 | 499 | QTest::addColumn<qreal>("max"); |
|
500 | 500 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
501 | 501 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
502 | 502 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
503 | 503 | } |
|
504 | 504 | |
|
505 | 505 | void tst_Domain::setRangeX() |
|
506 | 506 | { |
|
507 | 507 | QFETCH(qreal, min); |
|
508 | 508 | QFETCH(qreal, max); |
|
509 | 509 | |
|
510 | 510 | XYDomain domain; |
|
511 | 511 | |
|
512 | 512 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
513 | 513 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
514 | 514 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
515 | 515 | |
|
516 | 516 | domain.setRangeX(min, max); |
|
517 | 517 | |
|
518 | 518 | QVERIFY(qFuzzyCompare(domain.minX(), min)); |
|
519 | 519 | QVERIFY(qFuzzyCompare(domain.maxX(), max)); |
|
520 | 520 | |
|
521 | 521 | QList<QVariant> arg1 = spy1.first(); |
|
522 | 522 | QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min)); |
|
523 | 523 | QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max)); |
|
524 | 524 | |
|
525 | 525 | TRY_COMPARE(spy0.count(), 1); |
|
526 | 526 | TRY_COMPARE(spy1.count(), 1); |
|
527 | 527 | TRY_COMPARE(spy2.count(), 0); |
|
528 | 528 | } |
|
529 | 529 | |
|
530 | 530 | void tst_Domain::setRangeY_data() |
|
531 | 531 | { |
|
532 | 532 | QTest::addColumn<qreal>("min"); |
|
533 | 533 | QTest::addColumn<qreal>("max"); |
|
534 | 534 | QTest::newRow("-1 1") << -1.0 << 1.0; |
|
535 | 535 | QTest::newRow("0 1") << 0.0 << 1.0; |
|
536 | 536 | QTest::newRow("-1 0") << -1.0 << 0.0; |
|
537 | 537 | } |
|
538 | 538 | |
|
539 | 539 | void tst_Domain::setRangeY() |
|
540 | 540 | { |
|
541 | 541 | QFETCH(qreal, min); |
|
542 | 542 | QFETCH(qreal, max); |
|
543 | 543 | |
|
544 | 544 | XYDomain domain; |
|
545 | 545 | |
|
546 | 546 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
547 | 547 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
548 | 548 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
549 | 549 | |
|
550 | 550 | domain.setRangeY(min, max); |
|
551 | 551 | |
|
552 | 552 | QVERIFY(qFuzzyCompare(domain.minY(), min)); |
|
553 | 553 | QVERIFY(qFuzzyCompare(domain.maxY(), max)); |
|
554 | 554 | |
|
555 | 555 | QList<QVariant> arg1 = spy2.first(); |
|
556 | 556 | QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min)); |
|
557 | 557 | QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max)); |
|
558 | 558 | |
|
559 | 559 | TRY_COMPARE(spy0.count(), 1); |
|
560 | 560 | TRY_COMPARE(spy1.count(), 0); |
|
561 | 561 | TRY_COMPARE(spy2.count(), 1); |
|
562 | 562 | } |
|
563 | 563 | |
|
564 | 564 | void tst_Domain::spanX_data() |
|
565 | 565 | { |
|
566 | 566 | QTest::addColumn<qreal>("minX"); |
|
567 | 567 | QTest::addColumn<qreal>("maxX"); |
|
568 | 568 | QTest::addColumn<qreal>("spanX"); |
|
569 | 569 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
570 | 570 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
571 | 571 | } |
|
572 | 572 | |
|
573 | 573 | void tst_Domain::spanX() |
|
574 | 574 | { |
|
575 | 575 | QFETCH(qreal, minX); |
|
576 | 576 | QFETCH(qreal, maxX); |
|
577 | 577 | QFETCH(qreal, spanX); |
|
578 | 578 | |
|
579 | 579 | XYDomain domain; |
|
580 | 580 | |
|
581 | 581 | domain.setRangeX(minX, maxX); |
|
582 | 582 | |
|
583 | 583 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
584 | 584 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
585 | 585 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
586 | 586 | |
|
587 | 587 | QCOMPARE(domain.spanX(), spanX); |
|
588 | 588 | |
|
589 | 589 | TRY_COMPARE(spy0.count(), 0); |
|
590 | 590 | TRY_COMPARE(spy1.count(), 0); |
|
591 | 591 | TRY_COMPARE(spy2.count(), 0); |
|
592 | 592 | } |
|
593 | 593 | |
|
594 | 594 | void tst_Domain::spanY_data() |
|
595 | 595 | { |
|
596 | 596 | QTest::addColumn<qreal>("minY"); |
|
597 | 597 | QTest::addColumn<qreal>("maxY"); |
|
598 | 598 | QTest::addColumn<qreal>("spanY"); |
|
599 | 599 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; |
|
600 | 600 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; |
|
601 | 601 | } |
|
602 | 602 | |
|
603 | 603 | void tst_Domain::spanY() |
|
604 | 604 | { |
|
605 | 605 | QFETCH(qreal, minY); |
|
606 | 606 | QFETCH(qreal, maxY); |
|
607 | 607 | QFETCH(qreal, spanY); |
|
608 | 608 | |
|
609 | 609 | XYDomain domain; |
|
610 | 610 | |
|
611 | 611 | domain.setRangeY(minY, maxY); |
|
612 | 612 | |
|
613 | 613 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
614 | 614 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
615 | 615 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
616 | 616 | |
|
617 | 617 | QCOMPARE(domain.spanY(), spanY); |
|
618 | 618 | |
|
619 | 619 | TRY_COMPARE(spy0.count(), 0); |
|
620 | 620 | TRY_COMPARE(spy1.count(), 0); |
|
621 | 621 | TRY_COMPARE(spy2.count(), 0); |
|
622 | 622 | } |
|
623 | 623 | |
|
624 | 624 | void tst_Domain::zoomIn_data() |
|
625 | 625 | { |
|
626 | 626 | QTest::addColumn<QMargins>("range"); |
|
627 | 627 | QTest::addColumn<QSizeF>("size"); |
|
628 | 628 | QTest::addColumn<QMargins>("zoom"); |
|
629 | 629 | QTest::addColumn<QMargins>("result"); |
|
630 | 630 | |
|
631 | 631 | QTest::newRow("first") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) << |
|
632 | 632 | QMargins(100, 100, 900, 900) << QMargins(100,100,900,900); |
|
633 | 633 | QTest::newRow("second") << QMargins(0,0,2000,2000) << QSizeF(1000, 1000) << |
|
634 | 634 | QMargins(100, 100, 900, 900) << QMargins(200,200,1800,1800); |
|
635 | 635 | } |
|
636 | 636 | |
|
637 | 637 | void tst_Domain::zoomIn() |
|
638 | 638 | { |
|
639 | 639 | QFETCH(QMargins, range); |
|
640 | 640 | QFETCH(QSizeF, size); |
|
641 | 641 | QFETCH(QMargins, zoom); |
|
642 | 642 | QFETCH(QMargins, result); |
|
643 | 643 | |
|
644 | 644 | XYDomain domain; |
|
645 | 645 | domain.setRange(range.left(), range.right(), range.top(),range.bottom()); |
|
646 | 646 | domain.setSize(size); |
|
647 | 647 | |
|
648 | 648 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
649 | 649 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
650 | 650 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
651 | 651 | |
|
652 | 652 | domain.zoomIn(QRectF(zoom.left(),zoom.top(),zoom.right()-zoom.left(),zoom.bottom()-zoom.top())); |
|
653 | 653 | |
|
654 | 654 | QCOMPARE(domain.minX(),qreal(result.left())); |
|
655 | 655 | QCOMPARE(domain.maxX(),qreal(result.right())); |
|
656 | 656 | QCOMPARE(domain.minY(),qreal(result.top())); |
|
657 | 657 | QCOMPARE(domain.maxY(),qreal(result.bottom())); |
|
658 | 658 | |
|
659 | 659 | TRY_COMPARE(spy0.count(), 1); |
|
660 | 660 | TRY_COMPARE(spy1.count(), 1); |
|
661 | 661 | TRY_COMPARE(spy2.count(), 1); |
|
662 | 662 | } |
|
663 | 663 | |
|
664 | 664 | void tst_Domain::zoomOut_data() |
|
665 | 665 | { |
|
666 | 666 | QTest::addColumn<QMargins>("range"); |
|
667 | 667 | QTest::addColumn<QSizeF>("size"); |
|
668 | 668 | QTest::addColumn<QMargins>("zoom"); |
|
669 | 669 | QTest::addColumn<QMargins>("result"); |
|
670 | 670 | |
|
671 | 671 | QTest::newRow("first") << QMargins(100,100,900,900) << QSizeF(1000, 1000) << |
|
672 | 672 | QMargins(100, 100, 900, 900) << QMargins(0,0,1000,1000); |
|
673 | 673 | QTest::newRow("second") << QMargins(200,200,1800,1800) << QSizeF(1000, 1000) << |
|
674 | 674 | QMargins(100, 100, 900, 900) << QMargins(0,0,2000,2000); |
|
675 | 675 | } |
|
676 | 676 | |
|
677 | 677 | void tst_Domain::zoomOut() |
|
678 | 678 | { |
|
679 | 679 | QFETCH(QMargins, range); |
|
680 | 680 | QFETCH(QSizeF, size); |
|
681 | 681 | QFETCH(QMargins, zoom); |
|
682 | 682 | QFETCH(QMargins, result); |
|
683 | 683 | |
|
684 | 684 | XYDomain domain; |
|
685 | 685 | domain.setRange(range.left(), range.right(), range.top(),range.bottom()); |
|
686 | 686 | domain.setSize(size); |
|
687 | 687 | |
|
688 | 688 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
689 | 689 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
690 | 690 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
691 | 691 | |
|
692 | 692 | domain.zoomOut(QRectF(zoom.left(),zoom.top(),zoom.right()-zoom.left(),zoom.bottom()-zoom.top())); |
|
693 | 693 | |
|
694 | 694 | QCOMPARE(domain.minX(),qreal(result.left())); |
|
695 | 695 | QCOMPARE(domain.maxX(),qreal(result.right())); |
|
696 | 696 | QCOMPARE(domain.minY(),qreal(result.top())); |
|
697 | 697 | QCOMPARE(domain.maxY(),qreal(result.bottom())); |
|
698 | 698 | |
|
699 | 699 | TRY_COMPARE(spy0.count(), 1); |
|
700 | 700 | TRY_COMPARE(spy1.count(), 1); |
|
701 | 701 | TRY_COMPARE(spy2.count(), 1); |
|
702 | 702 | } |
|
703 | 703 | |
|
704 | 704 | void tst_Domain::move_data() |
|
705 | 705 | { |
|
706 | 706 | QTest::addColumn<QMargins>("range"); |
|
707 | 707 | QTest::addColumn<QSizeF>("size"); |
|
708 | 708 | QTest::addColumn<int>("dx"); |
|
709 | 709 | QTest::addColumn<int>("dy"); |
|
710 | 710 | QTest::addColumn<QMargins>("result"); |
|
711 | 711 | |
|
712 | 712 | QTest::newRow("first") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) << |
|
713 | 713 | 10 << 10 << QMargins(10,10,1010,1010); |
|
714 | 714 | QTest::newRow("second") << QMargins(0,0,1000,1000) << QSizeF(1000, 1000) << |
|
715 | 715 | -10 << -10 << QMargins(-10,-10,990,990); |
|
716 | 716 | } |
|
717 | 717 | |
|
718 | 718 | void tst_Domain::move() |
|
719 | 719 | { |
|
720 | 720 | QFETCH(QMargins, range); |
|
721 | 721 | QFETCH(QSizeF, size); |
|
722 | 722 | QFETCH(int, dx); |
|
723 | 723 | QFETCH(int, dy); |
|
724 | 724 | QFETCH(QMargins, result); |
|
725 | 725 | |
|
726 | 726 | XYDomain domain; |
|
727 | 727 | domain.setRange(range.left(), range.right(), range.top(),range.bottom()); |
|
728 | 728 | domain.setSize(size); |
|
729 | 729 | |
|
730 | 730 | QSignalSpy spy0(&domain, SIGNAL(updated())); |
|
731 | 731 | QSignalSpy spy1(&domain, SIGNAL(rangeHorizontalChanged(qreal,qreal))); |
|
732 | 732 | QSignalSpy spy2(&domain, SIGNAL(rangeVerticalChanged(qreal,qreal))); |
|
733 | 733 | |
|
734 | 734 | domain.move(dx, dy); |
|
735 | 735 | |
|
736 | 736 | QCOMPARE(domain.minX(),qreal(result.left())); |
|
737 | 737 | QCOMPARE(domain.maxX(),qreal(result.right())); |
|
738 | 738 | QCOMPARE(domain.minY(),qreal(result.top())); |
|
739 | 739 | QCOMPARE(domain.maxY(),qreal(result.bottom())); |
|
740 | 740 | |
|
741 | 741 | TRY_COMPARE(spy0.count(), 1); |
|
742 | 742 | TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0)); |
|
743 | 743 | TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0)); |
|
744 | 744 | } |
|
745 | 745 | |
|
746 | 746 | QTEST_MAIN(tst_Domain) |
|
747 | 747 | #include "tst_domain.moc" |
|
748 | 748 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now