File: tst_graphtheme.cpp

package info (click to toggle)
qt6-graphs 6.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,124 kB
  • sloc: cpp: 65,200; javascript: 204; makefile: 23
file content (235 lines) | stat: -rw-r--r-- 8,626 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include <QtGraphs/QGraphTheme>
#include <QtTest/QtTest>

class tst_graphtheme : public QObject
{
    Q_OBJECT

private slots:
    void initTestCase();
    void cleanupTestCase();
    void init();
    void cleanup();

    void construct();

    void initialProperties();
    void initializeProperties();

    void overrideProperties();
    void setReset();

private:
    QGraphTheme *m_theme;
};

void tst_graphtheme::initTestCase() {}

void tst_graphtheme::cleanupTestCase() {}

void tst_graphtheme::init()
{
    m_theme = new QGraphTheme();
}

void tst_graphtheme::cleanup()
{
    delete m_theme;
}

void tst_graphtheme::construct()
{
    QGraphTheme *theme = new QGraphTheme();
    QVERIFY(theme);
    delete theme;
}

void tst_graphtheme::initialProperties()
{
    QVERIFY(m_theme);

    QCOMPARE(m_theme->colorTheme(), QGraphTheme::ColorTheme::Dark);
    QCOMPARE(m_theme->gridMajorBarsWidth(), 2.0);
    QCOMPARE(m_theme->gridMinorBarsWidth(), 1.0);
    QCOMPARE(m_theme->gridSmoothing(), 1.0);
    QCOMPARE(m_theme->gridMajorBarsColor(), QColor());
    QCOMPARE(m_theme->gridMinorBarsColor(), QColor());
    QCOMPARE(m_theme->axisYMajorColor(), QColor());
    QCOMPARE(m_theme->axisYMinorColor(), QColor());
    QCOMPARE(m_theme->axisYMajorBarWidth(), 2.0);
    QCOMPARE(m_theme->axisYMinorBarWidth(), 1.0);
    QCOMPARE(m_theme->axisYSmoothing(), 1.0);
    QCOMPARE(m_theme->axisYLabelsColor(), QColor());
    QCOMPARE(m_theme->axisYLabelsFont(), QFont());
    QCOMPARE(m_theme->axisXMajorColor(), QColor());
    QCOMPARE(m_theme->axisXMinorColor(), QColor());
    QCOMPARE(m_theme->axisXMajorBarWidth(), 2.0);
    QCOMPARE(m_theme->axisXMinorBarWidth(), 1.0);
    QCOMPARE(m_theme->axisXSmoothing(), 1.0);
    QCOMPARE(m_theme->axisXLabelsColor(), QColor());
    QCOMPARE(m_theme->axisXLabelsFont(), QFont());
    QCOMPARE(m_theme->shadowVisible(), false);
    QCOMPARE(m_theme->shadowColor(), QColor());
    QCOMPARE(m_theme->shadowBarWidth(), 0.0);
    QCOMPARE(m_theme->shadowXOffset(), 0.0);
    QCOMPARE(m_theme->shadowYOffset(), 0.0);
    QCOMPARE(m_theme->shadowSmoothing(), 5.0);
}

void tst_graphtheme::initializeProperties()
{
    QVERIFY(m_theme);

    m_theme->setColorTheme(QGraphTheme::ColorTheme::Dark);
    m_theme->setGridMajorBarsWidth(3.5);
    m_theme->setGridMinorBarsWidth(1.5);
    m_theme->setGridSmoothing(0.5);
    m_theme->setAxisYMajorBarWidth(4.5);
    m_theme->setAxisYMinorBarWidth(2.5);
    m_theme->setAxisYSmoothing(2.0);
    m_theme->setAxisYLabelsFont(QFont("Arial", 30));
    m_theme->setAxisXMajorBarWidth(6.0);
    m_theme->setAxisXMinorBarWidth(5.0);
    m_theme->setAxisXSmoothing(3.0);
    m_theme->setAxisXLabelsFont(QFont("Arial", 20));
    m_theme->setShadowVisible(true);
    m_theme->setShadowColor("#66000000");
    m_theme->setShadowBarWidth(2.0);
    m_theme->setShadowXOffset(1.0);
    m_theme->setShadowYOffset(-1.0);
    m_theme->setShadowSmoothing(2.0);

    QCOMPARE(m_theme->colorTheme(), QGraphTheme::ColorTheme::Dark);
    QCOMPARE(m_theme->gridMajorBarsWidth(), 3.5);
    QCOMPARE(m_theme->gridMinorBarsWidth(), 1.5);
    QCOMPARE(m_theme->gridSmoothing(), 0.5);
    QCOMPARE(m_theme->gridMajorBarsColor(), "#fffafafa");
    QCOMPARE(m_theme->gridMinorBarsColor(), "#ff969696");
    QCOMPARE(m_theme->axisYMajorColor(), "#fffafafa");
    QCOMPARE(m_theme->axisYMinorColor(), "#ff969696");
    QCOMPARE(m_theme->axisYMajorBarWidth(), 4.5);
    QCOMPARE(m_theme->axisYMinorBarWidth(), 2.5);
    QCOMPARE(m_theme->axisYSmoothing(), 2.0);
    QCOMPARE(m_theme->axisYLabelsColor(), "#fffafafa");
    QCOMPARE(m_theme->axisYLabelsFont(), QFont("Arial", 30));
    QCOMPARE(m_theme->axisXMajorColor(), "#fffafafa");
    QCOMPARE(m_theme->axisXMinorColor(), "#ff969696");
    QCOMPARE(m_theme->axisXMajorBarWidth(), 6.0);
    QCOMPARE(m_theme->axisXMinorBarWidth(), 5.0);
    QCOMPARE(m_theme->axisXSmoothing(), 3.0);
    QCOMPARE(m_theme->axisXLabelsColor(), "#fffafafa");
    QCOMPARE(m_theme->axisXLabelsFont(), QFont("Arial", 20));
    QCOMPARE(m_theme->shadowVisible(), true);
    QCOMPARE(m_theme->shadowColor(), "#66000000");
    QCOMPARE(m_theme->shadowBarWidth(), 2.0);
    QCOMPARE(m_theme->shadowXOffset(), 1.0);
    QCOMPARE(m_theme->shadowYOffset(), -1.0);
    QCOMPARE(m_theme->shadowSmoothing(), 2.0);
}

void tst_graphtheme::overrideProperties()
{
    QVERIFY(m_theme);

    // Calling this manually to initialize the theming
    m_theme->componentComplete();

    // Set a theme
    m_theme->setColorTheme(QGraphTheme::ColorTheme::Light);

    QCOMPARE(m_theme->colorTheme(), QGraphTheme::ColorTheme::Light);
    QCOMPARE(m_theme->gridMajorBarsColor(), "#ff141414");
    QCOMPARE(m_theme->gridMinorBarsColor(), "#ff323232");
    QCOMPARE(m_theme->axisYMajorColor(), "#ff141414");
    QCOMPARE(m_theme->axisYMinorColor(), "#ff323232");
    QCOMPARE(m_theme->axisXMajorColor(), "#ff141414");
    QCOMPARE(m_theme->axisXMinorColor(), "#ff323232");
    QCOMPARE(m_theme->axisYLabelsColor(), "#ff141414");
    QCOMPARE(m_theme->axisXLabelsColor(), "#ff141414");

    // Override colors individually
    m_theme->setGridMajorBarsColor("red");
    m_theme->setGridMinorBarsColor("green");
    m_theme->setAxisYMajorColor("yellow");
    m_theme->setAxisYMinorColor("blue");
    m_theme->setAxisXMajorColor("#ffddeeff");
    m_theme->setAxisXMinorColor("#ff112233");
    m_theme->setAxisYLabelsColor("#ffaabbcc");
    m_theme->setAxisXLabelsColor("#ff445566");

    QCOMPARE(m_theme->colorTheme(), QGraphTheme::ColorTheme::Light);
    QCOMPARE(m_theme->gridMajorBarsColor(), "red");
    QCOMPARE(m_theme->gridMinorBarsColor(), "green");
    QCOMPARE(m_theme->axisYMajorColor(), "yellow");
    QCOMPARE(m_theme->axisYMinorColor(), "blue");
    QCOMPARE(m_theme->axisXMajorColor(), "#ffddeeff");
    QCOMPARE(m_theme->axisXMinorColor(), "#ff112233");
    QCOMPARE(m_theme->axisYLabelsColor(), "#ffaabbcc");
    QCOMPARE(m_theme->axisXLabelsColor(), "#ff445566");

    // Override with a theme
    m_theme->setColorTheme(QGraphTheme::ColorTheme::Dark);

    QCOMPARE(m_theme->colorTheme(), QGraphTheme::ColorTheme::Dark);
    QCOMPARE(m_theme->gridMajorBarsColor(), "#fffafafa");
    QCOMPARE(m_theme->gridMinorBarsColor(), "#ff969696");
    QCOMPARE(m_theme->axisYMajorColor(), "#fffafafa");
    QCOMPARE(m_theme->axisYMinorColor(), "#ff969696");
    QCOMPARE(m_theme->axisXMajorColor(), "#fffafafa");
    QCOMPARE(m_theme->axisXMinorColor(), "#ff969696");
    QCOMPARE(m_theme->axisYLabelsColor(), "#fffafafa");
    QCOMPARE(m_theme->axisXLabelsColor(), "#fffafafa");
}

void tst_graphtheme::setReset()
{
    QVERIFY(m_theme);

    // Calling this manually to initialize the theming
    m_theme->componentComplete();

    // Set a theme
    m_theme->setColorTheme(QGraphTheme::ColorTheme::Light);

    QCOMPARE(m_theme->colorTheme(), QGraphTheme::ColorTheme::Light);
    QCOMPARE(m_theme->gridMajorBarsColor(), "#ff141414");
    QCOMPARE(m_theme->gridMinorBarsColor(), "#ff323232");
    QCOMPARE(m_theme->axisYMajorColor(), "#ff141414");
    QCOMPARE(m_theme->axisYMinorColor(), "#ff323232");
    QCOMPARE(m_theme->axisXMajorColor(), "#ff141414");
    QCOMPARE(m_theme->axisXMinorColor(), "#ff323232");
    QCOMPARE(m_theme->axisYLabelsColor(), "#ff141414");
    QCOMPARE(m_theme->axisXLabelsColor(), "#ff141414");

    // Reset theme
    m_theme->resetColorTheme();

    QCOMPARE(m_theme->colorTheme(), QGraphTheme::ColorTheme::Dark);
    QCOMPARE(m_theme->gridMajorBarsColor(), "#fffafafa");
    QCOMPARE(m_theme->gridMinorBarsColor(), "#ff969696");
    QCOMPARE(m_theme->axisYMajorColor(), "#fffafafa");
    QCOMPARE(m_theme->axisYMinorColor(), "#ff969696");
    QCOMPARE(m_theme->axisXMajorColor(), "#fffafafa");
    QCOMPARE(m_theme->axisXMinorColor(), "#ff969696");
    QCOMPARE(m_theme->axisYLabelsColor(), "#fffafafa");
    QCOMPARE(m_theme->axisXLabelsColor(), "#fffafafa");

    // Set another theme
    m_theme->setColorTheme(QGraphTheme::ColorTheme::Light);

    QCOMPARE(m_theme->colorTheme(), QGraphTheme::ColorTheme::Light);
    QCOMPARE(m_theme->gridMajorBarsColor(), "#ff141414");
    QCOMPARE(m_theme->gridMinorBarsColor(), "#ff323232");
    QCOMPARE(m_theme->axisYMajorColor(), "#ff141414");
    QCOMPARE(m_theme->axisYMinorColor(), "#ff323232");
    QCOMPARE(m_theme->axisXMajorColor(), "#ff141414");
    QCOMPARE(m_theme->axisXMinorColor(), "#ff323232");
    QCOMPARE(m_theme->axisYLabelsColor(), "#ff141414");
    QCOMPARE(m_theme->axisXLabelsColor(), "#ff141414");
}

QTEST_MAIN(tst_graphtheme)
#include "tst_graphtheme.moc"