widgets/qdial.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9class QDialPrivate : public QAbstractSliderPrivate -
10{ -
11 inline QDial* q_func() { return static_cast<QDial *>(q_ptr); } inline const QDial* q_func() const { return static_cast<const QDial *>(q_ptr); } friend class QDial; -
12public: -
13 QDialPrivate() -
14 { -
15 wrapping = false; -
16 tracking = true; -
17 doNotEmit = false; -
18 target = qreal(3.7); -
19 }
executed: }
Execution Count:7
7
20 -
21 qreal target; -
22 uint showNotches : 1; -
23 uint wrapping : 1; -
24 uint doNotEmit : 1; -
25 -
26 int valueFromPoint(const QPoint &) const; -
27 double angle(const QPoint &, const QPoint &) const; -
28 void init(); -
29 virtual int bound(int val) const; -
30}; -
31 -
32void QDialPrivate::init() -
33{ -
34 QDial * const q = q_func(); -
35 showNotches = false; -
36 q->setFocusPolicy(Qt::WheelFocus); -
37}
executed: }
Execution Count:7
7
38 -
39int QDialPrivate::bound(int val) const -
40{ -
41 if (wrapping) {
evaluated: wrapping
TRUEFALSE
yes
Evaluation Count:20
yes
Evaluation Count:27
20-27
42 if ((val >= minimum) && (val <= maximum))
evaluated: (val >= minimum)
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:3
evaluated: (val <= maximum)
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:3
3-17
43 return val;
executed: return val;
Execution Count:14
14
44 val = minimum + ((val - minimum) % (maximum - minimum)); -
45 if (val < minimum)
evaluated: val < minimum
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:3
3
46 val += maximum - minimum;
executed: val += maximum - minimum;
Execution Count:3
3
47 return val;
executed: return val;
Execution Count:6
6
48 } else { -
49 return QAbstractSliderPrivate::bound(val);
executed: return QAbstractSliderPrivate::bound(val);
Execution Count:27
27
50 } -
51} -
52void QDial::initStyleOption(QStyleOptionSlider *option) const -
53{ -
54 if (!option)
partially evaluated: !option
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
55 return;
never executed: return;
0
56 -
57 const QDialPrivate * const d = d_func(); -
58 option->initFrom(this); -
59 option->minimum = d->minimum; -
60 option->maximum = d->maximum; -
61 option->sliderPosition = d->position; -
62 option->sliderValue = d->value; -
63 option->singleStep = d->singleStep; -
64 option->pageStep = d->pageStep; -
65 option->upsideDown = !d->invertedAppearance; -
66 option->notchTarget = d->target; -
67 option->dialWrapping = d->wrapping; -
68 option->subControls = QStyle::SC_All; -
69 option->activeSubControls = QStyle::SC_None; -
70 if (!d->showNotches) {
partially evaluated: !d->showNotches
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
71 option->subControls &= ~QStyle::SC_DialTickmarks; -
72 option->tickPosition = QSlider::TicksAbove; -
73 } else {
executed: }
Execution Count:3
3
74 option->tickPosition = QSlider::NoTicks; -
75 }
never executed: }
0
76 option->tickInterval = notchSize(); -
77}
executed: }
Execution Count:3
3
78 -
79int QDialPrivate::valueFromPoint(const QPoint &p) const -
80{ -
81 const QDial * const q = q_func(); -
82 double yy = (double)q->height()/2.0 - p.y(); -
83 double xx = (double)p.x() - q->width()/2.0; -
84 double a = (xx || yy) ? qAtan2(yy, xx) : 0;
evaluated: xx
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1
partially evaluated: yy
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-3
85 -
86 if (a < Q_PI / -2)
partially evaluated: a < Q_PI / -2
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
87 a = a + Q_PI * 2;
never executed: a = a + Q_PI * 2;
0
88 -
89 int dist = 0; -
90 int minv = minimum, maxv = maximum; -
91 -
92 if (minimum < 0) {
partially evaluated: minimum < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
93 dist = -minimum; -
94 minv = 0; -
95 maxv = maximum + dist; -
96 }
never executed: }
0
97 -
98 int r = maxv - minv; -
99 int v; -
100 if (wrapping)
partially evaluated: wrapping
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
101 v = (int)(0.5 + minv + r * (Q_PI * 3 / 2 - a) / (2 * Q_PI));
never executed: v = (int)(0.5 + minv + r * (Q_PI * 3 / 2 - a) / (2 * Q_PI));
0
102 else -
103 v = (int)(0.5 + minv + r* (Q_PI * 4 / 3 - a) / (Q_PI * 10 / 6));
executed: v = (int)(0.5 + minv + r* (Q_PI * 4 / 3 - a) / (Q_PI * 10 / 6));
Execution Count:4
4
104 -
105 if (dist > 0)
partially evaluated: dist > 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
106 v -= dist;
never executed: v -= dist;
0
107 -
108 return !invertedAppearance ? bound(v) : maximum - bound(v);
executed: return !invertedAppearance ? bound(v) : maximum - bound(v);
Execution Count:4
4
109} -
110QDial::QDial(QWidget *parent) -
111 : QAbstractSlider(*new QDialPrivate, parent) -
112{ -
113 QDialPrivate * const d = d_func(); -
114 d->init(); -
115}
executed: }
Execution Count:7
7
116 -
117 -
118 -
119 -
120QDial::~QDial() -
121{ -
122} -
123 -
124 -
125void QDial::resizeEvent(QResizeEvent *e) -
126{ -
127 QWidget::resizeEvent(e); -
128}
executed: }
Execution Count:7
7
129 -
130 -
131 -
132 -
133 -
134void QDial::paintEvent(QPaintEvent *) -
135{ -
136 QStylePainter p(this); -
137 QStyleOptionSlider option; -
138 initStyleOption(&option); -
139 p.drawComplexControl(QStyle::CC_Dial, option); -
140}
executed: }
Execution Count:3
3
141 -
142 -
143 -
144 -
145 -
146void QDial::mousePressEvent(QMouseEvent *e) -
147{ -
148 QDialPrivate * const d = d_func(); -
149 if (d->maximum == d->minimum ||
partially evaluated: d->maximum == d->minimum
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
150 (e->button() != Qt::LeftButton) ||
partially evaluated: (e->button() != Qt::LeftButton)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
151 (e->buttons() ^ e->button())) {
partially evaluated: (e->buttons() ^ e->button())
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
152 e->ignore(); -
153 return;
never executed: return;
0
154 } -
155 e->accept(); -
156 setSliderPosition(d->valueFromPoint(e->pos())); -
157 -
158 -
159 -
160 -
161 setSliderDown(true); -
162}
executed: }
Execution Count:1
1
163 -
164 -
165 -
166 -
167 -
168 -
169void QDial::mouseReleaseEvent(QMouseEvent * e) -
170{ -
171 QDialPrivate * const d = d_func(); -
172 if (e->buttons() & (~e->button()) ||
partially evaluated: e->buttons() & (~e->button())
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
173 (e->button() != Qt::LeftButton)) {
partially evaluated: (e->button() != Qt::LeftButton)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
174 e->ignore(); -
175 return;
never executed: return;
0
176 } -
177 e->accept(); -
178 setValue(d->valueFromPoint(e->pos())); -
179 setSliderDown(false); -
180}
executed: }
Execution Count:1
1
181 -
182 -
183 -
184 -
185 -
186 -
187void QDial::mouseMoveEvent(QMouseEvent * e) -
188{ -
189 QDialPrivate * const d = d_func(); -
190 if (!(e->buttons() & Qt::LeftButton)) {
partially evaluated: !(e->buttons() & Qt::LeftButton)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2
0-2
191 e->ignore(); -
192 return;
never executed: return;
0
193 } -
194 e->accept(); -
195 d->doNotEmit = true; -
196 setSliderPosition(d->valueFromPoint(e->pos())); -
197 d->doNotEmit = false; -
198}
executed: }
Execution Count:2
2
199 -
200 -
201 -
202 -
203 -
204 -
205void QDial::sliderChange(SliderChange change) -
206{ -
207 QAbstractSlider::sliderChange(change); -
208}
executed: }
Execution Count:31
31
209 -
210void QDial::setWrapping(bool enable) -
211{ -
212 QDialPrivate * const d = d_func(); -
213 if (d->wrapping == enable)
evaluated: d->wrapping == enable
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4
1-4
214 return;
executed: return;
Execution Count:1
1
215 d->wrapping = enable; -
216 update(); -
217}
executed: }
Execution Count:4
4
218bool QDial::wrapping() const -
219{ -
220 const QDialPrivate * const d = d_func(); -
221 return d->wrapping;
executed: return d->wrapping;
Execution Count:2
2
222} -
223int QDial::notchSize() const -
224{ -
225 const QDialPrivate * const d = d_func(); -
226 -
227 int r = qMin(width(), height())/2; -
228 -
229 int l = (int)(r * (d->wrapping ? 6 : 5) * Q_PI / 6); -
230 -
231 if (d->maximum > d->minimum + d->pageStep)
partially evaluated: d->maximum > d->minimum + d->pageStep
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
232 l = (int)(0.5 + l * d->pageStep / (d->maximum - d->minimum));
executed: l = (int)(0.5 + l * d->pageStep / (d->maximum - d->minimum));
Execution Count:3
3
233 -
234 l = l * d->singleStep / (d->pageStep ? d->pageStep : 1);
partially evaluated: d->pageStep
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
235 if (l < 1)
evaluated: l < 1
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
1-2
236 l = 1;
executed: l = 1;
Execution Count:1
1
237 -
238 l = (int)(0.5 + d->target / l); -
239 -
240 if (!l)
partially evaluated: !l
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
241 l = 1;
never executed: l = 1;
0
242 return d->singleStep * l;
executed: return d->singleStep * l;
Execution Count:3
3
243} -
244 -
245void QDial::setNotchTarget(double target) -
246{ -
247 QDialPrivate * const d = d_func(); -
248 d->target = target; -
249 update(); -
250}
never executed: }
0
251qreal QDial::notchTarget() const -
252{ -
253 const QDialPrivate * const d = d_func(); -
254 return d->target;
never executed: return d->target;
0
255} -
256 -
257 -
258void QDial::setNotchesVisible(bool visible) -
259{ -
260 QDialPrivate * const d = d_func(); -
261 d->showNotches = visible; -
262 update(); -
263}
executed: }
Execution Count:2
2
264bool QDial::notchesVisible() const -
265{ -
266 const QDialPrivate * const d = d_func(); -
267 return d->showNotches;
executed: return d->showNotches;
Execution Count:2
2
268} -
269 -
270 -
271 -
272 -
273 -
274QSize QDial::minimumSizeHint() const -
275{ -
276 return QSize(50, 50);
executed: return QSize(50, 50);
Execution Count:2
2
277} -
278 -
279 -
280 -
281 -
282 -
283QSize QDial::sizeHint() const -
284{ -
285 return QSize(100, 100).expandedTo(QApplication::globalStrut());
executed: return QSize(100, 100).expandedTo(QApplication::globalStrut());
Execution Count:5
5
286} -
287 -
288 -
289 -
290 -
291bool QDial::event(QEvent *e) -
292{ -
293 return QAbstractSlider::event(e);
executed: return QAbstractSlider::event(e);
Execution Count:74
74
294} -
295 -
296 -
297 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial