widgets/qdialogbuttonbox.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4enum { -
5 AcceptRole = QDialogButtonBox::AcceptRole, -
6 RejectRole = QDialogButtonBox::RejectRole, -
7 DestructiveRole = QDialogButtonBox::DestructiveRole, -
8 ActionRole = QDialogButtonBox::ActionRole, -
9 HelpRole = QDialogButtonBox::HelpRole, -
10 YesRole = QDialogButtonBox::YesRole, -
11 NoRole = QDialogButtonBox::NoRole, -
12 ApplyRole = QDialogButtonBox::ApplyRole, -
13 ResetRole = QDialogButtonBox::ResetRole, -
14 -
15 AlternateRole = 0x10000000, -
16 Stretch = 0x20000000, -
17 EOL = 0x40000000, -
18 Reverse = 0x80000000 -
19}; -
20 -
21static QDialogButtonBox::ButtonRole roleFor(QDialogButtonBox::StandardButton button) -
22{ -
23 switch (button) { -
24 case QDialogButtonBox::Ok: -
25 case QDialogButtonBox::Save: -
26 case QDialogButtonBox::Open: -
27 case QDialogButtonBox::SaveAll: -
28 case QDialogButtonBox::Retry: -
29 case QDialogButtonBox::Ignore: -
30 return QDialogButtonBox::AcceptRole;
executed: return QDialogButtonBox::AcceptRole;
Execution Count:996
996
31 -
32 case QDialogButtonBox::Cancel: -
33 case QDialogButtonBox::Close: -
34 case QDialogButtonBox::Abort: -
35 return QDialogButtonBox::RejectRole;
executed: return QDialogButtonBox::RejectRole;
Execution Count:954
954
36 -
37 case QDialogButtonBox::Discard: -
38 return QDialogButtonBox::DestructiveRole;
executed: return QDialogButtonBox::DestructiveRole;
Execution Count:12
12
39 -
40 case QDialogButtonBox::Help: -
41 return QDialogButtonBox::HelpRole;
executed: return QDialogButtonBox::HelpRole;
Execution Count:50
50
42 -
43 case QDialogButtonBox::Apply: -
44 return QDialogButtonBox::ApplyRole;
executed: return QDialogButtonBox::ApplyRole;
Execution Count:10
10
45 -
46 case QDialogButtonBox::Yes: -
47 case QDialogButtonBox::YesToAll: -
48 return QDialogButtonBox::YesRole;
executed: return QDialogButtonBox::YesRole;
Execution Count:60
60
49 -
50 case QDialogButtonBox::No: -
51 case QDialogButtonBox::NoToAll: -
52 return QDialogButtonBox::NoRole;
executed: return QDialogButtonBox::NoRole;
Execution Count:56
56
53 -
54 case QDialogButtonBox::RestoreDefaults: -
55 case QDialogButtonBox::Reset: -
56 return QDialogButtonBox::ResetRole;
executed: return QDialogButtonBox::ResetRole;
Execution Count:18
18
57 -
58 case QDialogButtonBox::NoButton: -
59 ; -
60 }
never executed: }
0
61 -
62 return QDialogButtonBox::InvalidRole;
executed: return QDialogButtonBox::InvalidRole;
Execution Count:4
4
63} -
64 -
65static const uint layouts[2][5][14] = -
66{ -
67 -
68 { -
69 -
70 { ResetRole, Stretch, YesRole, AcceptRole, AlternateRole, DestructiveRole, NoRole, ActionRole, RejectRole, ApplyRole, -
71 HelpRole, EOL, EOL, EOL }, -
72 -
73 -
74 { HelpRole, ResetRole, ApplyRole, ActionRole, Stretch, DestructiveRole | Reverse, -
75 AlternateRole | Reverse, RejectRole | Reverse, AcceptRole | Reverse, NoRole | Reverse, YesRole | Reverse, EOL, EOL }, -
76 -
77 -
78 { HelpRole, ResetRole, Stretch, YesRole, NoRole, ActionRole, AcceptRole, AlternateRole, -
79 ApplyRole, DestructiveRole, RejectRole, EOL }, -
80 -
81 -
82 { HelpRole, ResetRole, Stretch, ActionRole, ApplyRole | Reverse, DestructiveRole | Reverse, -
83 AlternateRole | Reverse, RejectRole | Reverse, AcceptRole | Reverse, NoRole | Reverse, YesRole | Reverse, EOL }, -
84 -
85 -
86 { ResetRole, ApplyRole, ActionRole, Stretch, HelpRole, EOL, EOL, EOL, EOL, EOL, EOL, EOL, EOL, EOL } -
87 }, -
88 -
89 -
90 { -
91 -
92 { ActionRole, YesRole, AcceptRole, AlternateRole, DestructiveRole, NoRole, RejectRole, ApplyRole, ResetRole, -
93 HelpRole, Stretch, EOL, EOL, EOL }, -
94 -
95 -
96 { YesRole, NoRole, AcceptRole, RejectRole, AlternateRole, DestructiveRole, Stretch, ActionRole, ApplyRole, -
97 ResetRole, HelpRole, EOL, EOL }, -
98 -
99 -
100 { AcceptRole, AlternateRole, ApplyRole, ActionRole, YesRole, NoRole, Stretch, ResetRole, -
101 DestructiveRole, RejectRole, HelpRole, EOL }, -
102 -
103 -
104 { YesRole, NoRole, AcceptRole, RejectRole, AlternateRole, DestructiveRole, ApplyRole, ActionRole, Stretch, -
105 ResetRole, HelpRole, EOL, EOL, EOL }, -
106 -
107 -
108 { ActionRole, ApplyRole, ResetRole, Stretch, HelpRole, EOL, EOL, EOL, EOL, EOL, EOL, EOL, EOL, EOL } -
109 } -
110}; -
111 -
112 -
113class QDialogButtonBoxPrivate : public QWidgetPrivate -
114{ -
115 inline QDialogButtonBox* q_func() { return static_cast<QDialogButtonBox *>(q_ptr); } inline const QDialogButtonBox* q_func() const { return static_cast<const QDialogButtonBox *>(q_ptr); } friend class QDialogButtonBox; -
116 -
117public: -
118 QDialogButtonBoxPrivate(Qt::Orientation orient); -
119 -
120 QList<QAbstractButton *> buttonLists[QDialogButtonBox::NRoles]; -
121 QHash<QPushButton *, QDialogButtonBox::StandardButton> standardButtonHash; -
122 -
123 Qt::Orientation orientation; -
124 QDialogButtonBox::ButtonLayout layoutPolicy; -
125 QBoxLayout *buttonLayout; -
126 bool internalRemove; -
127 bool center; -
128 -
129 void createStandardButtons(QDialogButtonBox::StandardButtons buttons); -
130 -
131 void layoutButtons(); -
132 void initLayout(); -
133 void resetLayout(); -
134 QPushButton *createButton(QDialogButtonBox::StandardButton button, bool doLayout = true); -
135 void addButton(QAbstractButton *button, QDialogButtonBox::ButtonRole role, bool doLayout = true); -
136 void _q_handleButtonDestroyed(); -
137 void _q_handleButtonClicked(); -
138 void addButtonsToLayout(const QList<QAbstractButton *> &buttonList, bool reverse); -
139 void retranslateStrings(); -
140 const char *standardButtonText(QDialogButtonBox::StandardButton sbutton) const; -
141}; -
142 -
143QDialogButtonBoxPrivate::QDialogButtonBoxPrivate(Qt::Orientation orient) -
144 : orientation(orient), buttonLayout(0), internalRemove(false), center(false) -
145{ -
146}
executed: }
Execution Count:352
352
147 -
148void QDialogButtonBoxPrivate::initLayout() -
149{ -
150 QDialogButtonBox * const q = q_func(); -
151 layoutPolicy = QDialogButtonBox::ButtonLayout(q->style()->styleHint(QStyle::SH_DialogButtonLayout, 0, q)); -
152 bool createNewLayout = buttonLayout == 0
evaluated: buttonLayout == 0
TRUEFALSE
yes
Evaluation Count:352
yes
Evaluation Count:235
235-352
153 || (orientation == Qt::Horizontal && qobject_cast<QVBoxLayout *>(buttonLayout) != 0)
evaluated: orientation == Qt::Horizontal
TRUEFALSE
yes
Evaluation Count:43
yes
Evaluation Count:192
partially evaluated: qobject_cast<QVBoxLayout *>(buttonLayout) != 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:43
0-192
154 || (orientation == Qt::Vertical && qobject_cast<QHBoxLayout *>(buttonLayout) != 0);
evaluated: orientation == Qt::Vertical
TRUEFALSE
yes
Evaluation Count:192
yes
Evaluation Count:43
partially evaluated: qobject_cast<QHBoxLayout *>(buttonLayout) != 0
TRUEFALSE
yes
Evaluation Count:192
no
Evaluation Count:0
0-192
155 if (createNewLayout) {
evaluated: createNewLayout
TRUEFALSE
yes
Evaluation Count:544
yes
Evaluation Count:43
43-544
156 delete buttonLayout; -
157 if (orientation == Qt::Horizontal)
evaluated: orientation == Qt::Horizontal
TRUEFALSE
yes
Evaluation Count:350
yes
Evaluation Count:194
194-350
158 buttonLayout = new QHBoxLayout(q);
executed: buttonLayout = new QHBoxLayout(q);
Execution Count:350
350
159 else -
160 buttonLayout = new QVBoxLayout(q);
executed: buttonLayout = new QVBoxLayout(q);
Execution Count:194
194
161 } -
162 -
163 int left, top, right, bottom; -
164 setLayoutItemMargins(QStyle::SE_PushButtonLayoutItem); -
165 getLayoutItemMargins(&left, &top, &right, &bottom); -
166 buttonLayout->setContentsMargins(-left, -top, -right, -bottom); -
167 -
168 if (!q->testAttribute(Qt::WA_WState_OwnSizePolicy)) {
partially evaluated: !q->testAttribute(Qt::WA_WState_OwnSizePolicy)
TRUEFALSE
yes
Evaluation Count:587
no
Evaluation Count:0
0-587
169 QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::ButtonBox); -
170 if (orientation == Qt::Vertical)
evaluated: orientation == Qt::Vertical
TRUEFALSE
yes
Evaluation Count:194
yes
Evaluation Count:393
194-393
171 sp.transpose();
executed: sp.transpose();
Execution Count:194
194
172 q->setSizePolicy(sp); -
173 q->setAttribute(Qt::WA_WState_OwnSizePolicy, false); -
174 }
executed: }
Execution Count:587
587
175 -
176 -
177 q->setFocusPolicy(Qt::TabFocus); -
178}
executed: }
Execution Count:587
587
179 -
180void QDialogButtonBoxPrivate::resetLayout() -
181{ -
182 -
183 initLayout(); -
184 layoutButtons(); -
185}
executed: }
Execution Count:235
235
186 -
187void QDialogButtonBoxPrivate::addButtonsToLayout(const QList<QAbstractButton *> &buttonList, -
188 bool reverse) -
189{ -
190 int start = reverse ? buttonList.count() - 1 : 0;
evaluated: reverse
TRUEFALSE
yes
Evaluation Count:1718
yes
Evaluation Count:5813
1718-5813
191 int end = reverse ? -1 : buttonList.count();
evaluated: reverse
TRUEFALSE
yes
Evaluation Count:1718
yes
Evaluation Count:5813
1718-5813
192 int step = reverse ? -1 : 1;
evaluated: reverse
TRUEFALSE
yes
Evaluation Count:1718
yes
Evaluation Count:5813
1718-5813
193 -
194 for (int i = start; i != end; i += step) {
evaluated: i != end
TRUEFALSE
yes
Evaluation Count:1014
yes
Evaluation Count:7531
1014-7531
195 QAbstractButton *button = buttonList.at(i); -
196 buttonLayout->addWidget(button); -
197 button->show(); -
198 }
executed: }
Execution Count:1014
1014
199}
executed: }
Execution Count:7531
7531
200 -
201void QDialogButtonBoxPrivate::layoutButtons() -
202{ -
203 QDialogButtonBox * const q = q_func(); -
204 const int MacGap = 36 - 8; -
205 -
206 for (int i = buttonLayout->count() - 1; i >= 0; --i) {
evaluated: i >= 0
TRUEFALSE
yes
Evaluation Count:1109
yes
Evaluation Count:939
939-1109
207 QLayoutItem *item = buttonLayout->takeAt(i); -
208 if (QWidget *widget = item->widget())
evaluated: QWidget *widget = item->widget()
TRUEFALSE
yes
Evaluation Count:404
yes
Evaluation Count:705
404-705
209 widget->hide();
executed: widget->hide();
Execution Count:404
404
210 delete item; -
211 }
executed: }
Execution Count:1109
1109
212 -
213 int tmpPolicy = layoutPolicy; -
214 -
215 static const int M = 5; -
216 static const int ModalRoles[M] = { AcceptRole, RejectRole, DestructiveRole, YesRole, NoRole }; -
217 if (tmpPolicy == QDialogButtonBox::MacLayout) {
partially evaluated: tmpPolicy == QDialogButtonBox::MacLayout
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:939
0-939
218 bool hasModalButton = false; -
219 for (int i = 0; i < M; ++i) {
never evaluated: i < M
0
220 if (!buttonLists[ModalRoles[i]].isEmpty()) {
never evaluated: !buttonLists[ModalRoles[i]].isEmpty()
0
221 hasModalButton = true; -
222 break;
never executed: break;
0
223 } -
224 }
never executed: }
0
225 if (!hasModalButton)
never evaluated: !hasModalButton
0
226 tmpPolicy = 4;
never executed: tmpPolicy = 4;
0
227 }
never executed: }
0
228 -
229 const uint *currentLayout = layouts[orientation == Qt::Vertical][tmpPolicy]; -
230 -
231 if (center)
evaluated: center
TRUEFALSE
yes
Evaluation Count:148
yes
Evaluation Count:791
148-791
232 buttonLayout->addStretch();
executed: buttonLayout->addStretch();
Execution Count:148
148
233 -
234 QList<QAbstractButton *> acceptRoleList = buttonLists[AcceptRole]; -
235 -
236 while (*currentLayout != EOL) {
evaluated: *currentLayout != EOL
TRUEFALSE
yes
Evaluation Count:10329
yes
Evaluation Count:939
939-10329
237 int role = (*currentLayout & ~Reverse); -
238 bool reverse = (*currentLayout & Reverse); -
239 -
240 switch (role) { -
241 case Stretch: -
242 if (!center)
evaluated: !center
TRUEFALSE
yes
Evaluation Count:791
yes
Evaluation Count:148
148-791
243 buttonLayout->addStretch();
executed: buttonLayout->addStretch();
Execution Count:791
791
244 break;
executed: break;
Execution Count:939
939
245 case AcceptRole: { -
246 if (acceptRoleList.isEmpty())
evaluated: acceptRoleList.isEmpty()
TRUEFALSE
yes
Evaluation Count:348
yes
Evaluation Count:591
348-591
247 break;
executed: break;
Execution Count:348
348
248 -
249 QAbstractButton *button = acceptRoleList.first(); -
250 buttonLayout->addWidget(button); -
251 button->show(); -
252 } -
253 break;
executed: break;
Execution Count:591
591
254 case AlternateRole: -
255 { -
256 if (acceptRoleList.size() < 2)
evaluated: acceptRoleList.size() < 2
TRUEFALSE
yes
Evaluation Count:920
yes
Evaluation Count:19
19-920
257 break;
executed: break;
Execution Count:920
920
258 QList<QAbstractButton *> list = acceptRoleList; -
259 list.removeFirst(); -
260 addButtonsToLayout(list, reverse); -
261 } -
262 break;
executed: break;
Execution Count:19
19
263 case DestructiveRole: -
264 { -
265 const QList<QAbstractButton *> &list = buttonLists[role]; -
266 if (tmpPolicy == QDialogButtonBox::MacLayout
partially evaluated: tmpPolicy == QDialogButtonBox::MacLayout
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:939
0-939
267 && !list.isEmpty() && buttonLayout->count() > 1)
never evaluated: !list.isEmpty()
never evaluated: buttonLayout->count() > 1
0
268 buttonLayout->addSpacing(MacGap);
never executed: buttonLayout->addSpacing(MacGap);
0
269 -
270 addButtonsToLayout(list, reverse); -
271 -
272 -
273 -
274 -
275 -
276 if (tmpPolicy == QDialogButtonBox::MacLayout && !list.isEmpty())
partially evaluated: tmpPolicy == QDialogButtonBox::MacLayout
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:939
never evaluated: !list.isEmpty()
0-939
277 buttonLayout->addSpacing(MacGap);
never executed: buttonLayout->addSpacing(MacGap);
0
278 } -
279 break;
executed: break;
Execution Count:939
939
280 case RejectRole: -
281 case ActionRole: -
282 case HelpRole: -
283 case YesRole: -
284 case NoRole: -
285 case ApplyRole: -
286 case ResetRole: -
287 addButtonsToLayout(buttonLists[role], reverse); -
288 }
executed: }
Execution Count:6573
6573
289 ++currentLayout; -
290 }
executed: }
Execution Count:10329
10329
291 -
292 QWidget *lastWidget = 0; -
293 q->setFocusProxy(0); -
294 for (int i = 0; i < buttonLayout->count(); ++i) {
evaluated: i < buttonLayout->count()
TRUEFALSE
yes
Evaluation Count:2544
yes
Evaluation Count:939
939-2544
295 QLayoutItem *item = buttonLayout->itemAt(i); -
296 if (QWidget *widget = item->widget()) {
evaluated: QWidget *widget = item->widget()
TRUEFALSE
yes
Evaluation Count:1605
yes
Evaluation Count:939
939-1605
297 if (lastWidget)
evaluated: lastWidget
TRUEFALSE
yes
Evaluation Count:899
yes
Evaluation Count:706
706-899
298 QWidget::setTabOrder(lastWidget, widget);
executed: QWidget::setTabOrder(lastWidget, widget);
Execution Count:899
899
299 else -
300 q->setFocusProxy(widget);
executed: q->setFocusProxy(widget);
Execution Count:706
706
301 lastWidget = widget; -
302 }
executed: }
Execution Count:1605
1605
303 }
executed: }
Execution Count:2544
2544
304 -
305 if (center)
evaluated: center
TRUEFALSE
yes
Evaluation Count:148
yes
Evaluation Count:791
148-791
306 buttonLayout->addStretch();
executed: buttonLayout->addStretch();
Execution Count:148
148
307}
executed: }
Execution Count:939
939
308 -
309QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardButton sbutton, -
310 bool doLayout) -
311{ -
312 QDialogButtonBox * const q = q_func(); -
313 const char *buttonText = 0; -
314 int icon = 0; -
315 -
316 switch (sbutton) { -
317 case QDialogButtonBox::Ok: -
318 icon = QStyle::SP_DialogOkButton; -
319 break;
executed: break;
Execution Count:256
256
320 case QDialogButtonBox::Save: -
321 icon = QStyle::SP_DialogSaveButton; -
322 break;
executed: break;
Execution Count:37
37
323 case QDialogButtonBox::Open: -
324 icon = QStyle::SP_DialogOpenButton; -
325 break;
executed: break;
Execution Count:196
196
326 case QDialogButtonBox::Cancel: -
327 icon = QStyle::SP_DialogCancelButton; -
328 break;
executed: break;
Execution Count:470
470
329 case QDialogButtonBox::Close: -
330 icon = QStyle::SP_DialogCloseButton; -
331 break;
executed: break;
Execution Count:5
5
332 case QDialogButtonBox::Apply: -
333 icon = QStyle::SP_DialogApplyButton; -
334 break;
executed: break;
Execution Count:5
5
335 case QDialogButtonBox::Reset: -
336 icon = QStyle::SP_DialogResetButton; -
337 break;
executed: break;
Execution Count:7
7
338 case QDialogButtonBox::Help: -
339 icon = QStyle::SP_DialogHelpButton; -
340 break;
executed: break;
Execution Count:25
25
341 case QDialogButtonBox::Discard: -
342 icon = QStyle::SP_DialogDiscardButton; -
343 break;
executed: break;
Execution Count:6
6
344 case QDialogButtonBox::Yes: -
345 icon = QStyle::SP_DialogYesButton; -
346 break;
executed: break;
Execution Count:27
27
347 case QDialogButtonBox::No: -
348 icon = QStyle::SP_DialogNoButton; -
349 break;
executed: break;
Execution Count:26
26
350 case QDialogButtonBox::YesToAll: -
351 case QDialogButtonBox::NoToAll: -
352 case QDialogButtonBox::SaveAll: -
353 case QDialogButtonBox::Abort: -
354 case QDialogButtonBox::Retry: -
355 case QDialogButtonBox::Ignore: -
356 case QDialogButtonBox::RestoreDefaults: -
357 break;
executed: break;
Execution Count:18
18
358 case QDialogButtonBox::NoButton: -
359 return 0;
executed: return 0;
Execution Count:11
11
360 ; -
361 } -
362 buttonText = standardButtonText(sbutton); -
363 -
364 QPushButton *button = new QPushButton(QDialogButtonBox::tr(buttonText), q); -
365 QStyle *style = q->style(); -
366 if (style->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons, 0, q) && icon != 0)
partially evaluated: style->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons, 0, q)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1082
never evaluated: icon != 0
0-1082
367 button->setIcon(style->standardIcon(QStyle::StandardPixmap(icon), 0, q));
never executed: button->setIcon(style->standardIcon(QStyle::StandardPixmap(icon), 0, q));
0
368 if (style != QApplication::style())
partially evaluated: style != QApplication::style()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1082
0-1082
369 button->setStyle(style);
never executed: button->setStyle(style);
0
370 standardButtonHash.insert(button, sbutton); -
371 if (roleFor(sbutton) != QDialogButtonBox::InvalidRole) {
evaluated: roleFor(sbutton) != QDialogButtonBox::InvalidRole
TRUEFALSE
yes
Evaluation Count:1078
yes
Evaluation Count:4
4-1078
372 addButton(button, roleFor(sbutton), doLayout); -
373 } else {
executed: }
Execution Count:1078
1078
374 QMessageLogger("widgets/qdialogbuttonbox.cpp", 529, __PRETTY_FUNCTION__).warning("QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); -
375 }
executed: }
Execution Count:4
4
376 return button;
executed: return button;
Execution Count:1082
1082
377} -
378 -
379void QDialogButtonBoxPrivate::addButton(QAbstractButton *button, QDialogButtonBox::ButtonRole role, -
380 bool doLayout) -
381{ -
382 QDialogButtonBox * const q = q_func(); -
383 QObject::connect(button, "2""clicked()", q, "1""_q_handleButtonClicked()"); -
384 QObject::connect(button, "2""destroyed()", q, "1""_q_handleButtonDestroyed()"); -
385 buttonLists[role].append(button); -
386 if (doLayout)
evaluated: doLayout
TRUEFALSE
yes
Evaluation Count:243
yes
Evaluation Count:954
243-954
387 layoutButtons();
executed: layoutButtons();
Execution Count:243
243
388}
executed: }
Execution Count:1197
1197
389 -
390void QDialogButtonBoxPrivate::createStandardButtons(QDialogButtonBox::StandardButtons buttons) -
391{ -
392 uint i = QDialogButtonBox::FirstButton; -
393 while (i <= QDialogButtonBox::LastButton) {
evaluated: i <= QDialogButtonBox::LastButton
TRUEFALSE
yes
Evaluation Count:8298
yes
Evaluation Count:461
461-8298
394 if (i & buttons) {
evaluated: i & buttons
TRUEFALSE
yes
Evaluation Count:954
yes
Evaluation Count:7344
954-7344
395 createButton(QDialogButtonBox::StandardButton(i), false); -
396 }
executed: }
Execution Count:954
954
397 i = i << 1; -
398 }
executed: }
Execution Count:8298
8298
399 layoutButtons(); -
400}
executed: }
Execution Count:461
461
401 -
402const char *QDialogButtonBoxPrivate::standardButtonText(QDialogButtonBox::StandardButton sbutton) const -
403{ -
404 const char *buttonText = 0; -
405 bool gnomeLayout = (layoutPolicy == QDialogButtonBox::GnomeLayout); -
406 switch (sbutton) { -
407 case QDialogButtonBox::Ok: -
408 buttonText = gnomeLayout ? "&OK" : "OK";
partially evaluated: gnomeLayout
TRUEFALSE
yes
Evaluation Count:257
no
Evaluation Count:0
0-257
409 break;
executed: break;
Execution Count:257
257
410 case QDialogButtonBox::Save: -
411 buttonText = gnomeLayout ? "&Save" : "Save";
partially evaluated: gnomeLayout
TRUEFALSE
yes
Evaluation Count:37
no
Evaluation Count:0
0-37
412 break;
executed: break;
Execution Count:37
37
413 case QDialogButtonBox::Open: -
414 buttonText = "Open"; -
415 break;
executed: break;
Execution Count:196
196
416 case QDialogButtonBox::Cancel: -
417 buttonText = gnomeLayout ? "&Cancel" : "Cancel";
partially evaluated: gnomeLayout
TRUEFALSE
yes
Evaluation Count:470
no
Evaluation Count:0
0-470
418 break;
executed: break;
Execution Count:470
470
419 case QDialogButtonBox::Close: -
420 buttonText = gnomeLayout ? "&Close" : "Close";
partially evaluated: gnomeLayout
TRUEFALSE
yes
Evaluation Count:5
no
Evaluation Count:0
0-5
421 break;
executed: break;
Execution Count:5
5
422 case QDialogButtonBox::Apply: -
423 buttonText = "Apply"; -
424 break;
executed: break;
Execution Count:5
5
425 case QDialogButtonBox::Reset: -
426 buttonText = "Reset"; -
427 break;
executed: break;
Execution Count:7
7
428 case QDialogButtonBox::Help: -
429 buttonText = "Help"; -
430 break;
executed: break;
Execution Count:25
25
431 case QDialogButtonBox::Discard: -
432 if (layoutPolicy == QDialogButtonBox::MacLayout)
partially evaluated: layoutPolicy == QDialogButtonBox::MacLayout
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
433 buttonText = "Don't Save";
never executed: buttonText = "Don't Save";
0
434 else if (layoutPolicy == QDialogButtonBox::GnomeLayout)
partially evaluated: layoutPolicy == QDialogButtonBox::GnomeLayout
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-6
435 buttonText = "Close without Saving";
executed: buttonText = "Close without Saving";
Execution Count:6
6
436 else -
437 buttonText = "Discard";
never executed: buttonText = "Discard";
0
438 break;
executed: break;
Execution Count:6
6
439 case QDialogButtonBox::Yes: -
440 buttonText = "&Yes"; -
441 break;
executed: break;
Execution Count:27
27
442 case QDialogButtonBox::YesToAll: -
443 buttonText = "Yes to &All"; -
444 break;
executed: break;
Execution Count:3
3
445 case QDialogButtonBox::No: -
446 buttonText = "&No"; -
447 break;
executed: break;
Execution Count:26
26
448 case QDialogButtonBox::NoToAll: -
449 buttonText = "N&o to All"; -
450 break;
executed: break;
Execution Count:2
2
451 case QDialogButtonBox::SaveAll: -
452 buttonText = "Save All"; -
453 break;
executed: break;
Execution Count:3
3
454 case QDialogButtonBox::Abort: -
455 buttonText = "Abort"; -
456 break;
executed: break;
Execution Count:2
2
457 case QDialogButtonBox::Retry: -
458 buttonText = "Retry"; -
459 break;
executed: break;
Execution Count:4
4
460 case QDialogButtonBox::Ignore: -
461 buttonText = "Ignore"; -
462 break;
executed: break;
Execution Count:2
2
463 case QDialogButtonBox::RestoreDefaults: -
464 buttonText = "Restore Defaults"; -
465 break;
executed: break;
Execution Count:2
2
466 case QDialogButtonBox::NoButton: -
467 ; -
468 }
never executed: }
0
469 return buttonText;
executed: return buttonText;
Execution Count:1083
1083
470} -
471 -
472void QDialogButtonBoxPrivate::retranslateStrings() -
473{ -
474 const char *buttonText = 0; -
475 QHash<QPushButton *, QDialogButtonBox::StandardButton>::iterator it = standardButtonHash.begin(); -
476 while (it != standardButtonHash.end()) {
evaluated: it != standardButtonHash.end()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
477 buttonText = standardButtonText(it.value()); -
478 if (buttonText) {
partially evaluated: buttonText
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
479 QPushButton *button = it.key(); -
480 button->setText(QDialogButtonBox::tr(buttonText)); -
481 }
executed: }
Execution Count:1
1
482 ++it; -
483 }
executed: }
Execution Count:1
1
484}
executed: }
Execution Count:1
1
485 -
486 -
487 -
488 -
489 -
490 -
491QDialogButtonBox::QDialogButtonBox(QWidget *parent) -
492 : QWidget(*new QDialogButtonBoxPrivate(Qt::Horizontal), parent, 0) -
493{ -
494 d_func()->initLayout(); -
495}
executed: }
Execution Count:305
305
496 -
497 -
498 -
499 -
500 -
501 -
502QDialogButtonBox::QDialogButtonBox(Qt::Orientation orientation, QWidget *parent) -
503 : QWidget(*new QDialogButtonBoxPrivate(orientation), parent, 0) -
504{ -
505 d_func()->initLayout(); -
506}
executed: }
Execution Count:2
2
507 -
508 -
509 -
510 -
511 -
512 -
513 -
514QDialogButtonBox::QDialogButtonBox(StandardButtons buttons, Qt::Orientation orientation, -
515 QWidget *parent) -
516 : QWidget(*new QDialogButtonBoxPrivate(orientation), parent, 0) -
517{ -
518 d_func()->initLayout(); -
519 d_func()->createStandardButtons(buttons); -
520}
executed: }
Execution Count:45
45
521 -
522 -
523 -
524 -
525QDialogButtonBox::~QDialogButtonBox() -
526{ -
527} -
528Qt::Orientation QDialogButtonBox::orientation() const -
529{ -
530 return d_func()->orientation;
executed: return d_func()->orientation;
Execution Count:15
15
531} -
532 -
533void QDialogButtonBox::setOrientation(Qt::Orientation orientation) -
534{ -
535 QDialogButtonBoxPrivate * const d = d_func(); -
536 if (orientation == d->orientation)
evaluated: orientation == d->orientation
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:192
1-192
537 return;
executed: return;
Execution Count:1
1
538 -
539 d->orientation = orientation; -
540 d->resetLayout(); -
541}
executed: }
Execution Count:192
192
542 -
543 -
544 -
545 -
546 -
547 -
548void QDialogButtonBox::clear() -
549{ -
550 QDialogButtonBoxPrivate * const d = d_func(); -
551 -
552 -
553 d->standardButtonHash.clear(); -
554 for (int i = 0; i < NRoles; ++i) {
evaluated: i < NRoles
TRUEFALSE
yes
Evaluation Count:27
yes
Evaluation Count:3
3-27
555 QList<QAbstractButton *> &list = d->buttonLists[i]; -
556 while (list.count()) {
evaluated: list.count()
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:27
8-27
557 QAbstractButton *button = list.takeAt(0); -
558 QObject::disconnect(button, "2""destroyed()", this, "1""_q_handleButtonDestroyed()"); -
559 delete button; -
560 }
executed: }
Execution Count:8
8
561 }
executed: }
Execution Count:27
27
562}
executed: }
Execution Count:3
3
563 -
564 -
565 -
566 -
567 -
568 -
569QList<QAbstractButton *> QDialogButtonBox::buttons() const -
570{ -
571 const QDialogButtonBoxPrivate * const d = d_func(); -
572 QList<QAbstractButton *> finalList; -
573 for (int i = 0; i < NRoles; ++i) {
evaluated: i < NRoles
TRUEFALSE
yes
Evaluation Count:1521
yes
Evaluation Count:169
169-1521
574 const QList<QAbstractButton *> &list = d->buttonLists[i]; -
575 for (int j = 0; j < list.count(); ++j)
evaluated: j < list.count()
TRUEFALSE
yes
Evaluation Count:258
yes
Evaluation Count:1521
258-1521
576 finalList.append(list.at(j));
executed: finalList.append(list.at(j));
Execution Count:258
258
577 }
executed: }
Execution Count:1521
1521
578 return finalList;
executed: return finalList;
Execution Count:169
169
579} -
580 -
581 -
582 -
583 -
584 -
585 -
586 -
587QDialogButtonBox::ButtonRole QDialogButtonBox::buttonRole(QAbstractButton *button) const -
588{ -
589 const QDialogButtonBoxPrivate * const d = d_func(); -
590 for (int i = 0; i < NRoles; ++i) {
evaluated: i < NRoles
TRUEFALSE
yes
Evaluation Count:871
yes
Evaluation Count:2
2-871
591 const QList<QAbstractButton *> &list = d->buttonLists[i]; -
592 for (int j = 0; j < list.count(); ++j) {
evaluated: j < list.count()
TRUEFALSE
yes
Evaluation Count:319
yes
Evaluation Count:687
319-687
593 if (list.at(j) == button)
evaluated: list.at(j) == button
TRUEFALSE
yes
Evaluation Count:184
yes
Evaluation Count:135
135-184
594 return ButtonRole(i);
executed: return ButtonRole(i);
Execution Count:184
184
595 }
executed: }
Execution Count:135
135
596 }
executed: }
Execution Count:687
687
597 return InvalidRole;
executed: return InvalidRole;
Execution Count:2
2
598} -
599 -
600 -
601 -
602 -
603 -
604 -
605void QDialogButtonBox::removeButton(QAbstractButton *button) -
606{ -
607 QDialogButtonBoxPrivate * const d = d_func(); -
608 -
609 if (!button)
partially evaluated: !button
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:509
0-509
610 return;
never executed: return;
0
611 -
612 -
613 if (QPushButton *pushButton = qobject_cast<QPushButton *>(button))
evaluated: QPushButton *pushButton = qobject_cast<QPushButton *>(button)
TRUEFALSE
yes
Evaluation Count:63
yes
Evaluation Count:446
63-446
614 d->standardButtonHash.remove(pushButton);
executed: d->standardButtonHash.remove(pushButton);
Execution Count:63
63
615 for (int i = 0; i < NRoles; ++i) {
evaluated: i < NRoles
TRUEFALSE
yes
Evaluation Count:4581
yes
Evaluation Count:509
509-4581
616 QList<QAbstractButton *> &list = d->buttonLists[i]; -
617 for (int j = 0; j < list.count(); ++j) {
evaluated: j < list.count()
TRUEFALSE
yes
Evaluation Count:744
yes
Evaluation Count:4129
744-4129
618 if (list.at(j) == button) {
evaluated: list.at(j) == button
TRUEFALSE
yes
Evaluation Count:452
yes
Evaluation Count:292
292-452
619 list.takeAt(j); -
620 if (!d->internalRemove) {
evaluated: !d->internalRemove
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:446
6-446
621 disconnect(button, "2""clicked()", this, "1""_q_handleButtonClicked()"); -
622 disconnect(button, "2""destroyed()", this, "1""_q_handleButtonDestroyed()"); -
623 }
executed: }
Execution Count:6
6
624 break;
executed: break;
Execution Count:452
452
625 } -
626 }
executed: }
Execution Count:292
292
627 }
executed: }
Execution Count:4581
4581
628 if (!d->internalRemove)
evaluated: !d->internalRemove
TRUEFALSE
yes
Evaluation Count:63
yes
Evaluation Count:446
63-446
629 button->setParent(0);
executed: button->setParent(0);
Execution Count:63
63
630}
executed: }
Execution Count:509
509
631void QDialogButtonBox::addButton(QAbstractButton *button, ButtonRole role) -
632{ -
633 QDialogButtonBoxPrivate * const d = d_func(); -
634 if (role <= InvalidRole || role >= NRoles) {
evaluated: role <= InvalidRole
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:46
partially evaluated: role >= NRoles
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:46
0-46
635 QMessageLogger("widgets/qdialogbuttonbox.cpp", 932, __PRETTY_FUNCTION__).warning("QDialogButtonBox::addButton: Invalid ButtonRole, button not added"); -
636 return;
executed: return;
Execution Count:4
4
637 } -
638 removeButton(button); -
639 button->setParent(this); -
640 d->addButton(button, role); -
641}
executed: }
Execution Count:46
46
642QPushButton *QDialogButtonBox::addButton(const QString &text, ButtonRole role) -
643{ -
644 QDialogButtonBoxPrivate * const d = d_func(); -
645 if (role <= InvalidRole || role >= NRoles) {
evaluated: role <= InvalidRole
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:73
partially evaluated: role >= NRoles
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:73
0-73
646 QMessageLogger("widgets/qdialogbuttonbox.cpp", 951, __PRETTY_FUNCTION__).warning("QDialogButtonBox::addButton: Invalid ButtonRole, button not added"); -
647 return 0;
executed: return 0;
Execution Count:4
4
648 } -
649 QPushButton *button = new QPushButton(text, this); -
650 d->addButton(button, role); -
651 return button;
executed: return button;
Execution Count:73
73
652} -
653QPushButton *QDialogButtonBox::addButton(StandardButton button) -
654{ -
655 QDialogButtonBoxPrivate * const d = d_func(); -
656 return d->createButton(button);
executed: return d->createButton(button);
Execution Count:139
139
657} -
658void QDialogButtonBox::setStandardButtons(StandardButtons buttons) -
659{ -
660 QDialogButtonBoxPrivate * const d = d_func(); -
661 -
662 qDeleteAll(d->standardButtonHash.keys()); -
663 d->standardButtonHash.clear(); -
664 -
665 d->createStandardButtons(buttons); -
666}
executed: }
Execution Count:416
416
667 -
668QDialogButtonBox::StandardButtons QDialogButtonBox::standardButtons() const -
669{ -
670 const QDialogButtonBoxPrivate * const d = d_func(); -
671 StandardButtons standardButtons = NoButton; -
672 QHash<QPushButton *, StandardButton>::const_iterator it = d->standardButtonHash.constBegin(); -
673 while (it != d->standardButtonHash.constEnd()) {
evaluated: it != d->standardButtonHash.constEnd()
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:11
11-36
674 standardButtons |= it.value(); -
675 ++it; -
676 }
executed: }
Execution Count:36
36
677 return standardButtons;
executed: return standardButtons;
Execution Count:11
11
678} -
679 -
680 -
681 -
682 -
683 -
684 -
685 -
686QPushButton *QDialogButtonBox::button(StandardButton which) const -
687{ -
688 const QDialogButtonBoxPrivate * const d = d_func(); -
689 return d->standardButtonHash.key(which);
executed: return d->standardButtonHash.key(which);
Execution Count:1938
1938
690} -
691 -
692 -
693 -
694 -
695 -
696 -
697 -
698QDialogButtonBox::StandardButton QDialogButtonBox::standardButton(QAbstractButton *button) const -
699{ -
700 const QDialogButtonBoxPrivate * const d = d_func(); -
701 return d->standardButtonHash.value(static_cast<QPushButton *>(button));
executed: return d->standardButtonHash.value(static_cast<QPushButton *>(button));
Execution Count:63
63
702} -
703 -
704void QDialogButtonBoxPrivate::_q_handleButtonClicked() -
705{ -
706 QDialogButtonBox * const q = q_func(); -
707 if (QAbstractButton *button = qobject_cast<QAbstractButton *>(q->sender())) {
partially evaluated: QAbstractButton *button = qobject_cast<QAbstractButton *>(q->sender())
TRUEFALSE
yes
Evaluation Count:51
no
Evaluation Count:0
0-51
708 q->clicked(button); -
709 -
710 switch (q->buttonRole(button)) { -
711 case AcceptRole: -
712 case YesRole: -
713 q->accepted(); -
714 break;
executed: break;
Execution Count:28
28
715 case RejectRole: -
716 case NoRole: -
717 q->rejected(); -
718 break;
executed: break;
Execution Count:16
16
719 case HelpRole: -
720 q->helpRequested(); -
721 break;
executed: break;
Execution Count:2
2
722 default: -
723 break;
executed: break;
Execution Count:5
5
724 } -
725 }
executed: }
Execution Count:51
51
726}
executed: }
Execution Count:51
51
727 -
728void QDialogButtonBoxPrivate::_q_handleButtonDestroyed() -
729{ -
730 QDialogButtonBox * const q = q_func(); -
731 if (QObject *object = q->sender()) {
partially evaluated: QObject *object = q->sender()
TRUEFALSE
yes
Evaluation Count:446
no
Evaluation Count:0
0-446
732 QBoolBlocker skippy(internalRemove); -
733 q->removeButton(static_cast<QAbstractButton *>(object)); -
734 }
executed: }
Execution Count:446
446
735}
executed: }
Execution Count:446
446
736void QDialogButtonBox::setCenterButtons(bool center) -
737{ -
738 QDialogButtonBoxPrivate * const d = d_func(); -
739 if (d->center != center) {
partially evaluated: d->center != center
TRUEFALSE
yes
Evaluation Count:42
no
Evaluation Count:0
0-42
740 d->center = center; -
741 d->resetLayout(); -
742 }
executed: }
Execution Count:42
42
743}
executed: }
Execution Count:42
42
744 -
745bool QDialogButtonBox::centerButtons() const -
746{ -
747 const QDialogButtonBoxPrivate * const d = d_func(); -
748 return d->center;
executed: return d->center;
Execution Count:1
1
749} -
750 -
751 -
752 -
753 -
754void QDialogButtonBox::changeEvent(QEvent *event) -
755{ -
756 typedef QHash<QPushButton *, QDialogButtonBox::StandardButton> StandardButtonHash; -
757 -
758 QDialogButtonBoxPrivate * const d = d_func(); -
759 switch (event->type()) { -
760 case QEvent::StyleChange: -
761 if (!d->standardButtonHash.empty()) {
partially evaluated: !d->standardButtonHash.empty()
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
762 QStyle *newStyle = style(); -
763 const StandardButtonHash::iterator end = d->standardButtonHash.end(); -
764 for (StandardButtonHash::iterator it = d->standardButtonHash.begin(); it != end; ++it)
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1
1
765 it.key()->setStyle(newStyle);
executed: it.key()->setStyle(newStyle);
Execution Count:1
1
766 }
executed: }
Execution Count:1
1
767 -
768 -
769 -
770 -
771 d->resetLayout(); -
772 QWidget::changeEvent(event); -
773 break;
executed: break;
Execution Count:1
1
774 default: -
775 QWidget::changeEvent(event); -
776 break;
executed: break;
Execution Count:45
45
777 } -
778}
executed: }
Execution Count:46
46
779 -
780 -
781 -
782 -
783bool QDialogButtonBox::event(QEvent *event) -
784{ -
785 QDialogButtonBoxPrivate * const d = d_func(); -
786 if (event->type() == QEvent::Show) {
evaluated: event->type() == QEvent::Show
TRUEFALSE
yes
Evaluation Count:138
yes
Evaluation Count:5357
138-5357
787 QList<QAbstractButton *> acceptRoleList = d->buttonLists[AcceptRole]; -
788 QPushButton *firstAcceptButton = acceptRoleList.isEmpty() ? 0 : qobject_cast<QPushButton *>(acceptRoleList.at(0));
evaluated: acceptRoleList.isEmpty()
TRUEFALSE
yes
Evaluation Count:37
yes
Evaluation Count:101
37-101
789 bool hasDefault = false; -
790 QWidget *dialog = 0; -
791 QWidget *p = this; -
792 while (p && !p->isWindow()) {
partially evaluated: p
TRUEFALSE
yes
Evaluation Count:139
no
Evaluation Count:0
evaluated: !p->isWindow()
TRUEFALSE
yes
Evaluation Count:129
yes
Evaluation Count:10
0-139
793 p = p->parentWidget(); -
794 if ((dialog = qobject_cast<QDialog *>(p)))
evaluated: (dialog = qobject_cast<QDialog *>(p))
TRUEFALSE
yes
Evaluation Count:128
yes
Evaluation Count:1
1-128
795 break;
executed: break;
Execution Count:128
128
796 }
executed: }
Execution Count:1
1
797 -
798 for (QForeachContainer<__typeof__((dialog ? dialog : this)->findChildren<QPushButton *>())> _container_((dialog ? dialog : this)->findChildren<QPushButton *>()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QPushButton *pb = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
799 if (pb->isDefault() && pb != firstAcceptButton) {
evaluated: pb->isDefault()
TRUEFALSE
yes
Evaluation Count:39
yes
Evaluation Count:248
evaluated: pb != firstAcceptButton
TRUEFALSE
yes
Evaluation Count:26
yes
Evaluation Count:13
13-248
800 hasDefault = true; -
801 break;
executed: break;
Execution Count:26
26
802 } -
803 }
executed: }
Execution Count:261
261
804 if (!hasDefault && firstAcceptButton)
evaluated: !hasDefault
TRUEFALSE
yes
Evaluation Count:112
yes
Evaluation Count:26
evaluated: firstAcceptButton
TRUEFALSE
yes
Evaluation Count:94
yes
Evaluation Count:18
18-112
805 firstAcceptButton->setDefault(true);
executed: firstAcceptButton->setDefault(true);
Execution Count:94
94
806 }else if (event->type() == QEvent::LanguageChange) {
executed: }
Execution Count:138
evaluated: event->type() == QEvent::LanguageChange
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:5356
1-5356
807 d->retranslateStrings(); -
808 }
executed: }
Execution Count:1
1
809 return QWidget::event(event);
executed: return QWidget::event(event);
Execution Count:5495
5495
810} -
811 -
812 -
813 -
814 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial