Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qdialogbuttonbox.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | class QDialogButtonBoxPrivate : public QWidgetPrivate | - | ||||||||||||
5 | { | - | ||||||||||||
6 | 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; | - | ||||||||||||
7 | - | |||||||||||||
8 | public: | - | ||||||||||||
9 | QDialogButtonBoxPrivate(Qt::Orientation orient); | - | ||||||||||||
10 | - | |||||||||||||
11 | QList<QAbstractButton *> buttonLists[QDialogButtonBox::NRoles]; | - | ||||||||||||
12 | QHash<QPushButton *, QDialogButtonBox::StandardButton> standardButtonHash; | - | ||||||||||||
13 | - | |||||||||||||
14 | Qt::Orientation orientation; | - | ||||||||||||
15 | QDialogButtonBox::ButtonLayout layoutPolicy; | - | ||||||||||||
16 | QBoxLayout *buttonLayout; | - | ||||||||||||
17 | bool internalRemove; | - | ||||||||||||
18 | bool center; | - | ||||||||||||
19 | - | |||||||||||||
20 | void createStandardButtons(QDialogButtonBox::StandardButtons buttons); | - | ||||||||||||
21 | - | |||||||||||||
22 | void layoutButtons(); | - | ||||||||||||
23 | void initLayout(); | - | ||||||||||||
24 | void resetLayout(); | - | ||||||||||||
25 | QPushButton *createButton(QDialogButtonBox::StandardButton button, bool doLayout = true); | - | ||||||||||||
26 | void addButton(QAbstractButton *button, QDialogButtonBox::ButtonRole role, bool doLayout = true); | - | ||||||||||||
27 | void _q_handleButtonDestroyed(); | - | ||||||||||||
28 | void _q_handleButtonClicked(); | - | ||||||||||||
29 | void addButtonsToLayout(const QList<QAbstractButton *> &buttonList, bool reverse); | - | ||||||||||||
30 | void retranslateStrings(); | - | ||||||||||||
31 | }; | - | ||||||||||||
32 | - | |||||||||||||
33 | QDialogButtonBoxPrivate::QDialogButtonBoxPrivate(Qt::Orientation orient) | - | ||||||||||||
34 | : orientation(orient), buttonLayout(0), internalRemove(false), center(false) | - | ||||||||||||
35 | { | - | ||||||||||||
36 | } never executed: end of block | 0 | ||||||||||||
37 | - | |||||||||||||
38 | void QDialogButtonBoxPrivate::initLayout() | - | ||||||||||||
39 | { | - | ||||||||||||
40 | QDialogButtonBox * const q = q_func(); | - | ||||||||||||
41 | layoutPolicy = QDialogButtonBox::ButtonLayout(q->style()->styleHint(QStyle::SH_DialogButtonLayout, 0, q)); | - | ||||||||||||
42 | bool createNewLayout = buttonLayout == 0
| 0 | ||||||||||||
43 | || (orientation == Qt::Horizontal
| 0 | ||||||||||||
44 | || (orientation == Qt::Vertical
| 0 | ||||||||||||
45 | if (createNewLayout
| 0 | ||||||||||||
46 | delete buttonLayout; | - | ||||||||||||
47 | if (orientation == Qt::Horizontal
| 0 | ||||||||||||
48 | buttonLayout = new QHBoxLayout(q); never executed: buttonLayout = new QHBoxLayout(q); | 0 | ||||||||||||
49 | else | - | ||||||||||||
50 | buttonLayout = new QVBoxLayout(q); never executed: buttonLayout = new QVBoxLayout(q); | 0 | ||||||||||||
51 | } | - | ||||||||||||
52 | - | |||||||||||||
53 | int left, top, right, bottom; | - | ||||||||||||
54 | setLayoutItemMargins(QStyle::SE_PushButtonLayoutItem); | - | ||||||||||||
55 | getLayoutItemMargins(&left, &top, &right, &bottom); | - | ||||||||||||
56 | buttonLayout->setContentsMargins(-left, -top, -right, -bottom); | - | ||||||||||||
57 | - | |||||||||||||
58 | if (!q->testAttribute(Qt::WA_WState_OwnSizePolicy)
| 0 | ||||||||||||
59 | QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::ButtonBox); | - | ||||||||||||
60 | if (orientation == Qt::Vertical
| 0 | ||||||||||||
61 | sp.transpose(); never executed: sp.transpose(); | 0 | ||||||||||||
62 | q->setSizePolicy(sp); | - | ||||||||||||
63 | q->setAttribute(Qt::WA_WState_OwnSizePolicy, false); | - | ||||||||||||
64 | } never executed: end of block | 0 | ||||||||||||
65 | } never executed: end of block | 0 | ||||||||||||
66 | - | |||||||||||||
67 | void QDialogButtonBoxPrivate::resetLayout() | - | ||||||||||||
68 | { | - | ||||||||||||
69 | - | |||||||||||||
70 | initLayout(); | - | ||||||||||||
71 | layoutButtons(); | - | ||||||||||||
72 | } never executed: end of block | 0 | ||||||||||||
73 | - | |||||||||||||
74 | void QDialogButtonBoxPrivate::addButtonsToLayout(const QList<QAbstractButton *> &buttonList, | - | ||||||||||||
75 | bool reverse) | - | ||||||||||||
76 | { | - | ||||||||||||
77 | int start = reverse
| 0 | ||||||||||||
78 | int end = reverse
| 0 | ||||||||||||
79 | int step = reverse
| 0 | ||||||||||||
80 | - | |||||||||||||
81 | for (int i = start; i != end
| 0 | ||||||||||||
82 | QAbstractButton *button = buttonList.at(i); | - | ||||||||||||
83 | buttonLayout->addWidget(button); | - | ||||||||||||
84 | button->show(); | - | ||||||||||||
85 | } never executed: end of block | 0 | ||||||||||||
86 | } never executed: end of block | 0 | ||||||||||||
87 | - | |||||||||||||
88 | void QDialogButtonBoxPrivate::layoutButtons() | - | ||||||||||||
89 | { | - | ||||||||||||
90 | QDialogButtonBox * const q = q_func(); | - | ||||||||||||
91 | const int MacGap = 36 - 8; | - | ||||||||||||
92 | - | |||||||||||||
93 | for (int i = buttonLayout->count() - 1; i >= 0
| 0 | ||||||||||||
94 | QLayoutItem *item = buttonLayout->takeAt(i); | - | ||||||||||||
95 | if (QWidget *widget = item->widget()
| 0 | ||||||||||||
96 | widget->hide(); never executed: widget->hide(); | 0 | ||||||||||||
97 | delete item; | - | ||||||||||||
98 | } never executed: end of block | 0 | ||||||||||||
99 | - | |||||||||||||
100 | int tmpPolicy = layoutPolicy; | - | ||||||||||||
101 | - | |||||||||||||
102 | static const int M = 5; | - | ||||||||||||
103 | static const int ModalRoles[M] = { QPlatformDialogHelper::AcceptRole, QPlatformDialogHelper::RejectRole, | - | ||||||||||||
104 | QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::YesRole, QPlatformDialogHelper::NoRole }; | - | ||||||||||||
105 | if (tmpPolicy == QDialogButtonBox::MacLayout
| 0 | ||||||||||||
106 | bool hasModalButton = false; | - | ||||||||||||
107 | for (int i = 0; i < M
| 0 | ||||||||||||
108 | if (!buttonLists[ModalRoles[i]].isEmpty()
| 0 | ||||||||||||
109 | hasModalButton = true; | - | ||||||||||||
110 | break; never executed: break; | 0 | ||||||||||||
111 | } | - | ||||||||||||
112 | } never executed: end of block | 0 | ||||||||||||
113 | if (!hasModalButton
| 0 | ||||||||||||
114 | tmpPolicy = 4; never executed: tmpPolicy = 4; | 0 | ||||||||||||
115 | } never executed: end of block | 0 | ||||||||||||
116 | - | |||||||||||||
117 | const int *currentLayout = QPlatformDialogHelper::buttonLayout( | - | ||||||||||||
118 | orientation, static_cast<QPlatformDialogHelper::ButtonLayout>(tmpPolicy)); | - | ||||||||||||
119 | - | |||||||||||||
120 | if (center
| 0 | ||||||||||||
121 | buttonLayout->addStretch(); never executed: buttonLayout->addStretch(); | 0 | ||||||||||||
122 | - | |||||||||||||
123 | const QList<QAbstractButton *> &acceptRoleList = buttonLists[QPlatformDialogHelper::AcceptRole]; | - | ||||||||||||
124 | - | |||||||||||||
125 | while (*
| 0 | ||||||||||||
126 | int role = (*currentLayout & ~QPlatformDialogHelper::Reverse); | - | ||||||||||||
127 | bool reverse = (*currentLayout & QPlatformDialogHelper::Reverse); | - | ||||||||||||
128 | - | |||||||||||||
129 | switch (role) { | - | ||||||||||||
130 | case never executed: QPlatformDialogHelper::Stretch:case QPlatformDialogHelper::Stretch: never executed: case QPlatformDialogHelper::Stretch: | 0 | ||||||||||||
131 | if (!center
| 0 | ||||||||||||
132 | buttonLayout->addStretch(); never executed: buttonLayout->addStretch(); | 0 | ||||||||||||
133 | break; never executed: break; | 0 | ||||||||||||
134 | case never executed: QPlatformDialogHelper::AcceptRole:case QPlatformDialogHelper::AcceptRole: never executed: {case QPlatformDialogHelper::AcceptRole: | 0 | ||||||||||||
135 | if (acceptRoleList.isEmpty()
| 0 | ||||||||||||
136 | break; never executed: break; | 0 | ||||||||||||
137 | - | |||||||||||||
138 | QAbstractButton *button = acceptRoleList.first(); | - | ||||||||||||
139 | buttonLayout->addWidget(button); | - | ||||||||||||
140 | button->show(); | - | ||||||||||||
141 | } | - | ||||||||||||
142 | break; never executed: break; | 0 | ||||||||||||
143 | case never executed: QPlatformDialogHelper::AlternateRole:case QPlatformDialogHelper::AlternateRole: never executed: case QPlatformDialogHelper::AlternateRole: | 0 | ||||||||||||
144 | { | - | ||||||||||||
145 | if (acceptRoleList.size() < 2
| 0 | ||||||||||||
146 | break; never executed: break; | 0 | ||||||||||||
147 | QList<QAbstractButton *> list = acceptRoleList; | - | ||||||||||||
148 | list.removeFirst(); | - | ||||||||||||
149 | addButtonsToLayout(list, reverse); | - | ||||||||||||
150 | } | - | ||||||||||||
151 | break; never executed: break; | 0 | ||||||||||||
152 | case never executed: QPlatformDialogHelper::DestructiveRole:case QPlatformDialogHelper::DestructiveRole: never executed: case QPlatformDialogHelper::DestructiveRole: | 0 | ||||||||||||
153 | { | - | ||||||||||||
154 | const QList<QAbstractButton *> &list = buttonLists[role]; | - | ||||||||||||
155 | if (tmpPolicy == QDialogButtonBox::MacLayout
| 0 | ||||||||||||
156 | && !list.isEmpty()
| 0 | ||||||||||||
157 | buttonLayout->addSpacing(MacGap); never executed: buttonLayout->addSpacing(MacGap); | 0 | ||||||||||||
158 | - | |||||||||||||
159 | addButtonsToLayout(list, reverse); | - | ||||||||||||
160 | - | |||||||||||||
161 | - | |||||||||||||
162 | - | |||||||||||||
163 | - | |||||||||||||
164 | - | |||||||||||||
165 | if (tmpPolicy == QDialogButtonBox::MacLayout
| 0 | ||||||||||||
166 | buttonLayout->addSpacing(MacGap); never executed: buttonLayout->addSpacing(MacGap); | 0 | ||||||||||||
167 | } | - | ||||||||||||
168 | break; never executed: break; | 0 | ||||||||||||
169 | case never executed: QPlatformDialogHelper::RejectRole:case QPlatformDialogHelper::RejectRole: never executed: case QPlatformDialogHelper::RejectRole: | 0 | ||||||||||||
170 | case never executed: QPlatformDialogHelper::ActionRole:case QPlatformDialogHelper::ActionRole: never executed: case QPlatformDialogHelper::ActionRole: | 0 | ||||||||||||
171 | case never executed: QPlatformDialogHelper::HelpRole:case QPlatformDialogHelper::HelpRole: never executed: case QPlatformDialogHelper::HelpRole: | 0 | ||||||||||||
172 | case never executed: QPlatformDialogHelper::YesRole:case QPlatformDialogHelper::YesRole: never executed: case QPlatformDialogHelper::YesRole: | 0 | ||||||||||||
173 | case never executed: QPlatformDialogHelper::NoRole:case QPlatformDialogHelper::NoRole: never executed: case QPlatformDialogHelper::NoRole: | 0 | ||||||||||||
174 | case never executed: QPlatformDialogHelper::ApplyRole:case QPlatformDialogHelper::ApplyRole: never executed: case QPlatformDialogHelper::ApplyRole: | 0 | ||||||||||||
175 | case never executed: QPlatformDialogHelper::ResetRole:case QPlatformDialogHelper::ResetRole: never executed: case QPlatformDialogHelper::ResetRole: | 0 | ||||||||||||
176 | addButtonsToLayout(buttonLists[role], reverse); | - | ||||||||||||
177 | } never executed: end of block | 0 | ||||||||||||
178 | ++currentLayout; | - | ||||||||||||
179 | } never executed: end of block | 0 | ||||||||||||
180 | - | |||||||||||||
181 | QWidget *lastWidget = 0; | - | ||||||||||||
182 | q->setFocusProxy(0); | - | ||||||||||||
183 | for (int i = 0; i < buttonLayout->count()
| 0 | ||||||||||||
184 | QLayoutItem *item = buttonLayout->itemAt(i); | - | ||||||||||||
185 | if (QWidget *widget = item->widget()
| 0 | ||||||||||||
186 | if (lastWidget
| 0 | ||||||||||||
187 | QWidget::setTabOrder(lastWidget, widget); never executed: QWidget::setTabOrder(lastWidget, widget); | 0 | ||||||||||||
188 | else | - | ||||||||||||
189 | q->setFocusProxy(widget); never executed: q->setFocusProxy(widget); | 0 | ||||||||||||
190 | lastWidget = widget; | - | ||||||||||||
191 | } never executed: end of block | 0 | ||||||||||||
192 | } never executed: end of block | 0 | ||||||||||||
193 | - | |||||||||||||
194 | if (center
| 0 | ||||||||||||
195 | buttonLayout->addStretch(); never executed: buttonLayout->addStretch(); | 0 | ||||||||||||
196 | } never executed: end of block | 0 | ||||||||||||
197 | - | |||||||||||||
198 | QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardButton sbutton, | - | ||||||||||||
199 | bool doLayout) | - | ||||||||||||
200 | { | - | ||||||||||||
201 | QDialogButtonBox * const q = q_func(); | - | ||||||||||||
202 | int icon = 0; | - | ||||||||||||
203 | - | |||||||||||||
204 | switch (sbutton) { | - | ||||||||||||
205 | case never executed: QDialogButtonBox::Ok:case QDialogButtonBox::Ok: never executed: case QDialogButtonBox::Ok: | 0 | ||||||||||||
206 | icon = QStyle::SP_DialogOkButton; | - | ||||||||||||
207 | break; never executed: break; | 0 | ||||||||||||
208 | case never executed: QDialogButtonBox::Save:case QDialogButtonBox::Save: never executed: case QDialogButtonBox::Save: | 0 | ||||||||||||
209 | icon = QStyle::SP_DialogSaveButton; | - | ||||||||||||
210 | break; never executed: break; | 0 | ||||||||||||
211 | case never executed: QDialogButtonBox::Open:case QDialogButtonBox::Open: never executed: case QDialogButtonBox::Open: | 0 | ||||||||||||
212 | icon = QStyle::SP_DialogOpenButton; | - | ||||||||||||
213 | break; never executed: break; | 0 | ||||||||||||
214 | case never executed: QDialogButtonBox::Cancel:case QDialogButtonBox::Cancel: never executed: case QDialogButtonBox::Cancel: | 0 | ||||||||||||
215 | icon = QStyle::SP_DialogCancelButton; | - | ||||||||||||
216 | break; never executed: break; | 0 | ||||||||||||
217 | case never executed: QDialogButtonBox::Close:case QDialogButtonBox::Close: never executed: case QDialogButtonBox::Close: | 0 | ||||||||||||
218 | icon = QStyle::SP_DialogCloseButton; | - | ||||||||||||
219 | break; never executed: break; | 0 | ||||||||||||
220 | case never executed: QDialogButtonBox::Apply:case QDialogButtonBox::Apply: never executed: case QDialogButtonBox::Apply: | 0 | ||||||||||||
221 | icon = QStyle::SP_DialogApplyButton; | - | ||||||||||||
222 | break; never executed: break; | 0 | ||||||||||||
223 | case never executed: QDialogButtonBox::Reset:case QDialogButtonBox::Reset: never executed: case QDialogButtonBox::Reset: | 0 | ||||||||||||
224 | icon = QStyle::SP_DialogResetButton; | - | ||||||||||||
225 | break; never executed: break; | 0 | ||||||||||||
226 | case never executed: QDialogButtonBox::Help:case QDialogButtonBox::Help: never executed: case QDialogButtonBox::Help: | 0 | ||||||||||||
227 | icon = QStyle::SP_DialogHelpButton; | - | ||||||||||||
228 | break; never executed: break; | 0 | ||||||||||||
229 | case never executed: QDialogButtonBox::Discard:case QDialogButtonBox::Discard: never executed: case QDialogButtonBox::Discard: | 0 | ||||||||||||
230 | icon = QStyle::SP_DialogDiscardButton; | - | ||||||||||||
231 | break; never executed: break; | 0 | ||||||||||||
232 | case never executed: QDialogButtonBox::Yes:case QDialogButtonBox::Yes: never executed: case QDialogButtonBox::Yes: | 0 | ||||||||||||
233 | icon = QStyle::SP_DialogYesButton; | - | ||||||||||||
234 | break; never executed: break; | 0 | ||||||||||||
235 | case never executed: QDialogButtonBox::No:case QDialogButtonBox::No: never executed: case QDialogButtonBox::No: | 0 | ||||||||||||
236 | icon = QStyle::SP_DialogNoButton; | - | ||||||||||||
237 | break; never executed: break; | 0 | ||||||||||||
238 | case never executed: QDialogButtonBox::YesToAll:case QDialogButtonBox::YesToAll: never executed: case QDialogButtonBox::YesToAll: | 0 | ||||||||||||
239 | case never executed: QDialogButtonBox::NoToAll:case QDialogButtonBox::NoToAll: never executed: case QDialogButtonBox::NoToAll: | 0 | ||||||||||||
240 | case never executed: QDialogButtonBox::SaveAll:case QDialogButtonBox::SaveAll: never executed: case QDialogButtonBox::SaveAll: | 0 | ||||||||||||
241 | case never executed: QDialogButtonBox::Abort:case QDialogButtonBox::Abort: never executed: case QDialogButtonBox::Abort: | 0 | ||||||||||||
242 | case never executed: QDialogButtonBox::Retry:case QDialogButtonBox::Retry: never executed: case QDialogButtonBox::Retry: | 0 | ||||||||||||
243 | case never executed: QDialogButtonBox::Ignore:case QDialogButtonBox::Ignore: never executed: case QDialogButtonBox::Ignore: | 0 | ||||||||||||
244 | case never executed: QDialogButtonBox::RestoreDefaults:case QDialogButtonBox::RestoreDefaults: never executed: case QDialogButtonBox::RestoreDefaults: | 0 | ||||||||||||
245 | break; never executed: break; | 0 | ||||||||||||
246 | case never executed: QDialogButtonBox::NoButton:case QDialogButtonBox::NoButton: never executed: case QDialogButtonBox::NoButton: | 0 | ||||||||||||
247 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
248 | ; | - | ||||||||||||
249 | } | - | ||||||||||||
250 | QPushButton *button = new QPushButton(QGuiApplicationPrivate::platformTheme()->standardButtonText(sbutton), q); | - | ||||||||||||
251 | QStyle *style = q->style(); | - | ||||||||||||
252 | if (style->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons, 0, q)
| 0 | ||||||||||||
253 | button->setIcon(style->standardIcon(QStyle::StandardPixmap(icon), 0, q)); never executed: button->setIcon(style->standardIcon(QStyle::StandardPixmap(icon), 0, q)); | 0 | ||||||||||||
254 | if (style != QApplication::style()
| 0 | ||||||||||||
255 | button->setStyle(style); never executed: button->setStyle(style); | 0 | ||||||||||||
256 | standardButtonHash.insert(button, sbutton); | - | ||||||||||||
257 | QPlatformDialogHelper::ButtonRole role = QPlatformDialogHelper::buttonRole(static_cast<QPlatformDialogHelper::StandardButton>(sbutton)); | - | ||||||||||||
258 | if (role != QPlatformDialogHelper::InvalidRole
| 0 | ||||||||||||
259 | addButton(button, static_cast<QDialogButtonBox::ButtonRole>(role), doLayout); | - | ||||||||||||
260 | } never executed: else {end of block | 0 | ||||||||||||
261 | QMessageLogger(__FILE__, 411, __PRETTY_FUNCTION__).warning("QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); | - | ||||||||||||
262 | } never executed: end of block | 0 | ||||||||||||
263 | return never executed: button;return button; never executed: return button; | 0 | ||||||||||||
264 | } | - | ||||||||||||
265 | - | |||||||||||||
266 | void QDialogButtonBoxPrivate::addButton(QAbstractButton *button, QDialogButtonBox::ButtonRole role, | - | ||||||||||||
267 | bool doLayout) | - | ||||||||||||
268 | { | - | ||||||||||||
269 | QDialogButtonBox * const q = q_func(); | - | ||||||||||||
270 | QObject::connect(button, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "428"), q, qFlagLocation("1""_q_handleButtonClicked()" "\0" __FILE__ ":" "428")); | - | ||||||||||||
271 | QObject::connect(button, qFlagLocation("2""destroyed()" "\0" __FILE__ ":" "429"), q, qFlagLocation("1""_q_handleButtonDestroyed()" "\0" __FILE__ ":" "429")); | - | ||||||||||||
272 | buttonLists[role].append(button); | - | ||||||||||||
273 | if (doLayout
| 0 | ||||||||||||
274 | layoutButtons(); never executed: layoutButtons(); | 0 | ||||||||||||
275 | } never executed: end of block | 0 | ||||||||||||
276 | - | |||||||||||||
277 | void QDialogButtonBoxPrivate::createStandardButtons(QDialogButtonBox::StandardButtons buttons) | - | ||||||||||||
278 | { | - | ||||||||||||
279 | uint i = QDialogButtonBox::FirstButton; | - | ||||||||||||
280 | while (i <= QDialogButtonBox::LastButton
| 0 | ||||||||||||
281 | if (i & buttons
| 0 | ||||||||||||
282 | createButton(QDialogButtonBox::StandardButton(i), false); | - | ||||||||||||
283 | } never executed: end of block | 0 | ||||||||||||
284 | i = i << 1; | - | ||||||||||||
285 | } never executed: end of block | 0 | ||||||||||||
286 | layoutButtons(); | - | ||||||||||||
287 | } never executed: end of block | 0 | ||||||||||||
288 | - | |||||||||||||
289 | void QDialogButtonBoxPrivate::retranslateStrings() | - | ||||||||||||
290 | { | - | ||||||||||||
291 | typedef QHash<QPushButton *, QDialogButtonBox::StandardButton>::iterator Iterator; | - | ||||||||||||
292 | - | |||||||||||||
293 | const Iterator end = standardButtonHash.end(); | - | ||||||||||||
294 | for (Iterator it = standardButtonHash.begin(); it != end
| 0 | ||||||||||||
295 | const QString text = QGuiApplicationPrivate::platformTheme()->standardButtonText(it.value()); | - | ||||||||||||
296 | if (!text.isEmpty()
| 0 | ||||||||||||
297 | it.key()->setText(text); never executed: it.key()->setText(text); | 0 | ||||||||||||
298 | } never executed: end of block | 0 | ||||||||||||
299 | } never executed: end of block | 0 | ||||||||||||
300 | - | |||||||||||||
301 | - | |||||||||||||
302 | - | |||||||||||||
303 | - | |||||||||||||
304 | - | |||||||||||||
305 | - | |||||||||||||
306 | QDialogButtonBox::QDialogButtonBox(QWidget *parent) | - | ||||||||||||
307 | : QWidget(*new QDialogButtonBoxPrivate(Qt::Horizontal), parent, 0) | - | ||||||||||||
308 | { | - | ||||||||||||
309 | d_func()->initLayout(); | - | ||||||||||||
310 | } never executed: end of block | 0 | ||||||||||||
311 | - | |||||||||||||
312 | - | |||||||||||||
313 | - | |||||||||||||
314 | - | |||||||||||||
315 | - | |||||||||||||
316 | - | |||||||||||||
317 | QDialogButtonBox::QDialogButtonBox(Qt::Orientation orientation, QWidget *parent) | - | ||||||||||||
318 | : QWidget(*new QDialogButtonBoxPrivate(orientation), parent, 0) | - | ||||||||||||
319 | { | - | ||||||||||||
320 | d_func()->initLayout(); | - | ||||||||||||
321 | } never executed: end of block | 0 | ||||||||||||
322 | QDialogButtonBox::QDialogButtonBox(StandardButtons buttons, QWidget *parent) | - | ||||||||||||
323 | : QWidget(*new QDialogButtonBoxPrivate(Qt::Horizontal), parent, 0) | - | ||||||||||||
324 | { | - | ||||||||||||
325 | d_func()->initLayout(); | - | ||||||||||||
326 | d_func()->createStandardButtons(buttons); | - | ||||||||||||
327 | } never executed: end of block | 0 | ||||||||||||
328 | - | |||||||||||||
329 | - | |||||||||||||
330 | - | |||||||||||||
331 | - | |||||||||||||
332 | - | |||||||||||||
333 | - | |||||||||||||
334 | - | |||||||||||||
335 | QDialogButtonBox::QDialogButtonBox(StandardButtons buttons, Qt::Orientation orientation, | - | ||||||||||||
336 | QWidget *parent) | - | ||||||||||||
337 | : QWidget(*new QDialogButtonBoxPrivate(orientation), parent, 0) | - | ||||||||||||
338 | { | - | ||||||||||||
339 | d_func()->initLayout(); | - | ||||||||||||
340 | d_func()->createStandardButtons(buttons); | - | ||||||||||||
341 | } never executed: end of block | 0 | ||||||||||||
342 | - | |||||||||||||
343 | - | |||||||||||||
344 | - | |||||||||||||
345 | - | |||||||||||||
346 | QDialogButtonBox::~QDialogButtonBox() | - | ||||||||||||
347 | { | - | ||||||||||||
348 | } | - | ||||||||||||
349 | Qt::Orientation QDialogButtonBox::orientation() const | - | ||||||||||||
350 | { | - | ||||||||||||
351 | return never executed: d_func()->orientation;return d_func()->orientation; never executed: return d_func()->orientation; | 0 | ||||||||||||
352 | } | - | ||||||||||||
353 | - | |||||||||||||
354 | void QDialogButtonBox::setOrientation(Qt::Orientation orientation) | - | ||||||||||||
355 | { | - | ||||||||||||
356 | QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
357 | if (orientation == d->orientation
| 0 | ||||||||||||
358 | return; never executed: return; | 0 | ||||||||||||
359 | - | |||||||||||||
360 | d->orientation = orientation; | - | ||||||||||||
361 | d->resetLayout(); | - | ||||||||||||
362 | } never executed: end of block | 0 | ||||||||||||
363 | - | |||||||||||||
364 | - | |||||||||||||
365 | - | |||||||||||||
366 | - | |||||||||||||
367 | - | |||||||||||||
368 | - | |||||||||||||
369 | void QDialogButtonBox::clear() | - | ||||||||||||
370 | { | - | ||||||||||||
371 | QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
372 | - | |||||||||||||
373 | - | |||||||||||||
374 | d->standardButtonHash.clear(); | - | ||||||||||||
375 | for (int i = 0; i < NRoles
| 0 | ||||||||||||
376 | QList<QAbstractButton *> &list = d->buttonLists[i]; | - | ||||||||||||
377 | while (list.count()
| 0 | ||||||||||||
378 | QAbstractButton *button = list.takeAt(0); | - | ||||||||||||
379 | QObject::disconnect(button, qFlagLocation("2""destroyed()" "\0" __FILE__ ":" "668"), this, qFlagLocation("1""_q_handleButtonDestroyed()" "\0" __FILE__ ":" "668")); | - | ||||||||||||
380 | delete button; | - | ||||||||||||
381 | } never executed: end of block | 0 | ||||||||||||
382 | } never executed: end of block | 0 | ||||||||||||
383 | } never executed: end of block | 0 | ||||||||||||
384 | - | |||||||||||||
385 | - | |||||||||||||
386 | - | |||||||||||||
387 | - | |||||||||||||
388 | - | |||||||||||||
389 | - | |||||||||||||
390 | QList<QAbstractButton *> QDialogButtonBox::buttons() const | - | ||||||||||||
391 | { | - | ||||||||||||
392 | const QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
393 | QList<QAbstractButton *> finalList; | - | ||||||||||||
394 | for (int i = 0; i < NRoles
| 0 | ||||||||||||
395 | const QList<QAbstractButton *> &list = d->buttonLists[i]; | - | ||||||||||||
396 | for (int j = 0; j < list.count()
| 0 | ||||||||||||
397 | finalList.append(list.at(j)); never executed: finalList.append(list.at(j)); | 0 | ||||||||||||
398 | } never executed: end of block | 0 | ||||||||||||
399 | return never executed: finalList;return finalList; never executed: return finalList; | 0 | ||||||||||||
400 | } | - | ||||||||||||
401 | - | |||||||||||||
402 | - | |||||||||||||
403 | - | |||||||||||||
404 | - | |||||||||||||
405 | - | |||||||||||||
406 | - | |||||||||||||
407 | - | |||||||||||||
408 | QDialogButtonBox::ButtonRole QDialogButtonBox::buttonRole(QAbstractButton *button) const | - | ||||||||||||
409 | { | - | ||||||||||||
410 | const QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
411 | for (int i = 0; i < NRoles
| 0 | ||||||||||||
412 | const QList<QAbstractButton *> &list = d->buttonLists[i]; | - | ||||||||||||
413 | for (int j = 0; j < list.count()
| 0 | ||||||||||||
414 | if (list.at(j) == button
| 0 | ||||||||||||
415 | return never executed: ButtonRole(i);return ButtonRole(i); never executed: return ButtonRole(i); | 0 | ||||||||||||
416 | } never executed: end of block | 0 | ||||||||||||
417 | } never executed: end of block | 0 | ||||||||||||
418 | return never executed: InvalidRole;return InvalidRole; never executed: return InvalidRole; | 0 | ||||||||||||
419 | } | - | ||||||||||||
420 | - | |||||||||||||
421 | - | |||||||||||||
422 | - | |||||||||||||
423 | - | |||||||||||||
424 | - | |||||||||||||
425 | - | |||||||||||||
426 | void QDialogButtonBox::removeButton(QAbstractButton *button) | - | ||||||||||||
427 | { | - | ||||||||||||
428 | QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
429 | - | |||||||||||||
430 | if (!button
| 0 | ||||||||||||
431 | return; never executed: return; | 0 | ||||||||||||
432 | - | |||||||||||||
433 | - | |||||||||||||
434 | if (QPushButton *pushButton = qobject_cast<QPushButton *>(button)
| 0 | ||||||||||||
435 | d->standardButtonHash.remove(pushButton); never executed: d->standardButtonHash.remove(pushButton); | 0 | ||||||||||||
436 | for (int i = 0; i < NRoles
| 0 | ||||||||||||
437 | QList<QAbstractButton *> &list = d->buttonLists[i]; | - | ||||||||||||
438 | for (int j = 0; j < list.count()
| 0 | ||||||||||||
439 | if (list.at(j) == button
| 0 | ||||||||||||
440 | list.takeAt(j); | - | ||||||||||||
441 | if (!d->internalRemove
| 0 | ||||||||||||
442 | disconnect(button, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "731"), this, qFlagLocation("1""_q_handleButtonClicked()" "\0" __FILE__ ":" "731")); | - | ||||||||||||
443 | disconnect(button, qFlagLocation("2""destroyed()" "\0" __FILE__ ":" "732"), this, qFlagLocation("1""_q_handleButtonDestroyed()" "\0" __FILE__ ":" "732")); | - | ||||||||||||
444 | } never executed: end of block | 0 | ||||||||||||
445 | break; never executed: break; | 0 | ||||||||||||
446 | } | - | ||||||||||||
447 | } never executed: end of block | 0 | ||||||||||||
448 | } never executed: end of block | 0 | ||||||||||||
449 | if (!d->internalRemove
| 0 | ||||||||||||
450 | button->setParent(0); never executed: button->setParent(0); | 0 | ||||||||||||
451 | } never executed: end of block | 0 | ||||||||||||
452 | void QDialogButtonBox::addButton(QAbstractButton *button, ButtonRole role) | - | ||||||||||||
453 | { | - | ||||||||||||
454 | QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
455 | if (role <= InvalidRole
| 0 | ||||||||||||
456 | QMessageLogger(__FILE__, 757, __PRETTY_FUNCTION__).warning("QDialogButtonBox::addButton: Invalid ButtonRole, button not added"); | - | ||||||||||||
457 | return; never executed: return; | 0 | ||||||||||||
458 | } | - | ||||||||||||
459 | removeButton(button); | - | ||||||||||||
460 | button->setParent(this); | - | ||||||||||||
461 | d->addButton(button, role); | - | ||||||||||||
462 | } never executed: end of block | 0 | ||||||||||||
463 | QPushButton *QDialogButtonBox::addButton(const QString &text, ButtonRole role) | - | ||||||||||||
464 | { | - | ||||||||||||
465 | QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
466 | if (role <= InvalidRole
| 0 | ||||||||||||
467 | QMessageLogger(__FILE__, 776, __PRETTY_FUNCTION__).warning("QDialogButtonBox::addButton: Invalid ButtonRole, button not added"); | - | ||||||||||||
468 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||||||||
469 | } | - | ||||||||||||
470 | QPushButton *button = new QPushButton(text, this); | - | ||||||||||||
471 | d->addButton(button, role); | - | ||||||||||||
472 | return never executed: button;return button; never executed: return button; | 0 | ||||||||||||
473 | } | - | ||||||||||||
474 | QPushButton *QDialogButtonBox::addButton(StandardButton button) | - | ||||||||||||
475 | { | - | ||||||||||||
476 | QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
477 | return never executed: d->createButton(button);return d->createButton(button); never executed: return d->createButton(button); | 0 | ||||||||||||
478 | } | - | ||||||||||||
479 | void QDialogButtonBox::setStandardButtons(StandardButtons buttons) | - | ||||||||||||
480 | { | - | ||||||||||||
481 | QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
482 | - | |||||||||||||
483 | qDeleteAll(d->standardButtonHash.keys()); | - | ||||||||||||
484 | d->standardButtonHash.clear(); | - | ||||||||||||
485 | - | |||||||||||||
486 | d->createStandardButtons(buttons); | - | ||||||||||||
487 | } never executed: end of block | 0 | ||||||||||||
488 | - | |||||||||||||
489 | QDialogButtonBox::StandardButtons QDialogButtonBox::standardButtons() const | - | ||||||||||||
490 | { | - | ||||||||||||
491 | const QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
492 | StandardButtons standardButtons = NoButton; | - | ||||||||||||
493 | QHash<QPushButton *, StandardButton>::const_iterator it = d->standardButtonHash.constBegin(); | - | ||||||||||||
494 | while (it != d->standardButtonHash.constEnd()
| 0 | ||||||||||||
495 | standardButtons |= it.value(); | - | ||||||||||||
496 | ++it; | - | ||||||||||||
497 | } never executed: end of block | 0 | ||||||||||||
498 | return never executed: standardButtons;return standardButtons; never executed: return standardButtons; | 0 | ||||||||||||
499 | } | - | ||||||||||||
500 | - | |||||||||||||
501 | - | |||||||||||||
502 | - | |||||||||||||
503 | - | |||||||||||||
504 | - | |||||||||||||
505 | - | |||||||||||||
506 | - | |||||||||||||
507 | QPushButton *QDialogButtonBox::button(StandardButton which) const | - | ||||||||||||
508 | { | - | ||||||||||||
509 | const QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
510 | return never executed: d->standardButtonHash.key(which);return d->standardButtonHash.key(which); never executed: return d->standardButtonHash.key(which); | 0 | ||||||||||||
511 | } | - | ||||||||||||
512 | - | |||||||||||||
513 | - | |||||||||||||
514 | - | |||||||||||||
515 | - | |||||||||||||
516 | - | |||||||||||||
517 | - | |||||||||||||
518 | - | |||||||||||||
519 | QDialogButtonBox::StandardButton QDialogButtonBox::standardButton(QAbstractButton *button) const | - | ||||||||||||
520 | { | - | ||||||||||||
521 | const QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
522 | return never executed: d->standardButtonHash.value(static_cast<QPushButton *>(button));return d->standardButtonHash.value(static_cast<QPushButton *>(button)); never executed: return d->standardButtonHash.value(static_cast<QPushButton *>(button)); | 0 | ||||||||||||
523 | } | - | ||||||||||||
524 | - | |||||||||||||
525 | void QDialogButtonBoxPrivate::_q_handleButtonClicked() | - | ||||||||||||
526 | { | - | ||||||||||||
527 | QDialogButtonBox * const q = q_func(); | - | ||||||||||||
528 | if (QAbstractButton *button = qobject_cast<QAbstractButton *>(q->sender())
| 0 | ||||||||||||
529 | - | |||||||||||||
530 | - | |||||||||||||
531 | - | |||||||||||||
532 | - | |||||||||||||
533 | const QDialogButtonBox::ButtonRole buttonRole = q->buttonRole(button); | - | ||||||||||||
534 | QPointer<QDialogButtonBox> guard(q); | - | ||||||||||||
535 | - | |||||||||||||
536 | q->clicked(button); | - | ||||||||||||
537 | - | |||||||||||||
538 | if (!guard
| 0 | ||||||||||||
539 | return; never executed: return; | 0 | ||||||||||||
540 | - | |||||||||||||
541 | switch (buttonRole) { | - | ||||||||||||
542 | case never executed: QPlatformDialogHelper::AcceptRole:case QPlatformDialogHelper::AcceptRole: never executed: case QPlatformDialogHelper::AcceptRole: | 0 | ||||||||||||
543 | case never executed: QPlatformDialogHelper::YesRole:case QPlatformDialogHelper::YesRole: never executed: case QPlatformDialogHelper::YesRole: | 0 | ||||||||||||
544 | q->accepted(); | - | ||||||||||||
545 | break; never executed: break; | 0 | ||||||||||||
546 | case never executed: QPlatformDialogHelper::RejectRole:case QPlatformDialogHelper::RejectRole: never executed: case QPlatformDialogHelper::RejectRole: | 0 | ||||||||||||
547 | case never executed: QPlatformDialogHelper::NoRole:case QPlatformDialogHelper::NoRole: never executed: case QPlatformDialogHelper::NoRole: | 0 | ||||||||||||
548 | q->rejected(); | - | ||||||||||||
549 | break; never executed: break; | 0 | ||||||||||||
550 | case never executed: QPlatformDialogHelper::HelpRole:case QPlatformDialogHelper::HelpRole: never executed: case QPlatformDialogHelper::HelpRole: | 0 | ||||||||||||
551 | q->helpRequested(); | - | ||||||||||||
552 | break; never executed: break; | 0 | ||||||||||||
553 | default never executed: :default: never executed: default: | 0 | ||||||||||||
554 | break; never executed: break; | 0 | ||||||||||||
555 | } | - | ||||||||||||
556 | } | - | ||||||||||||
557 | } never executed: end of block | 0 | ||||||||||||
558 | - | |||||||||||||
559 | void QDialogButtonBoxPrivate::_q_handleButtonDestroyed() | - | ||||||||||||
560 | { | - | ||||||||||||
561 | QDialogButtonBox * const q = q_func(); | - | ||||||||||||
562 | if (QObject *object = q->sender()
| 0 | ||||||||||||
563 | QBoolBlocker skippy(internalRemove); | - | ||||||||||||
564 | q->removeButton(static_cast<QAbstractButton *>(object)); | - | ||||||||||||
565 | } never executed: end of block | 0 | ||||||||||||
566 | } never executed: end of block | 0 | ||||||||||||
567 | void QDialogButtonBox::setCenterButtons(bool center) | - | ||||||||||||
568 | { | - | ||||||||||||
569 | QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
570 | if (d->center != center
| 0 | ||||||||||||
571 | d->center = center; | - | ||||||||||||
572 | d->resetLayout(); | - | ||||||||||||
573 | } never executed: end of block | 0 | ||||||||||||
574 | } never executed: end of block | 0 | ||||||||||||
575 | - | |||||||||||||
576 | bool QDialogButtonBox::centerButtons() const | - | ||||||||||||
577 | { | - | ||||||||||||
578 | const QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
579 | return never executed: d->center;return d->center; never executed: return d->center; | 0 | ||||||||||||
580 | } | - | ||||||||||||
581 | - | |||||||||||||
582 | - | |||||||||||||
583 | - | |||||||||||||
584 | - | |||||||||||||
585 | void QDialogButtonBox::changeEvent(QEvent *event) | - | ||||||||||||
586 | { | - | ||||||||||||
587 | typedef QHash<QPushButton *, QDialogButtonBox::StandardButton> StandardButtonHash; | - | ||||||||||||
588 | - | |||||||||||||
589 | QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
590 | switch (event->type()) { | - | ||||||||||||
591 | case never executed: QEvent::StyleChange:case QEvent::StyleChange: never executed: case QEvent::StyleChange: | 0 | ||||||||||||
592 | if (!d->standardButtonHash.empty()
| 0 | ||||||||||||
593 | QStyle *newStyle = style(); | - | ||||||||||||
594 | const StandardButtonHash::iterator end = d->standardButtonHash.end(); | - | ||||||||||||
595 | for (StandardButtonHash::iterator it = d->standardButtonHash.begin(); it != end
| 0 | ||||||||||||
596 | it.key()->setStyle(newStyle); never executed: it.key()->setStyle(newStyle); | 0 | ||||||||||||
597 | } never executed: end of block | 0 | ||||||||||||
598 | - | |||||||||||||
599 | - | |||||||||||||
600 | - | |||||||||||||
601 | - | |||||||||||||
602 | d->resetLayout(); | - | ||||||||||||
603 | QWidget::changeEvent(event); | - | ||||||||||||
604 | break; never executed: break; | 0 | ||||||||||||
605 | default never executed: :default: never executed: default: | 0 | ||||||||||||
606 | QWidget::changeEvent(event); | - | ||||||||||||
607 | break; never executed: break; | 0 | ||||||||||||
608 | } | - | ||||||||||||
609 | } | - | ||||||||||||
610 | - | |||||||||||||
611 | - | |||||||||||||
612 | - | |||||||||||||
613 | - | |||||||||||||
614 | bool QDialogButtonBox::event(QEvent *event) | - | ||||||||||||
615 | { | - | ||||||||||||
616 | QDialogButtonBoxPrivate * const d = d_func(); | - | ||||||||||||
617 | if (event->type() == QEvent::Show
| 0 | ||||||||||||
618 | QList<QAbstractButton *> acceptRoleList = d->buttonLists[AcceptRole]; | - | ||||||||||||
619 | QPushButton *firstAcceptButton = acceptRoleList.isEmpty()
| 0 | ||||||||||||
620 | bool hasDefault = false; | - | ||||||||||||
621 | QWidget *dialog = 0; | - | ||||||||||||
622 | QWidget *p = this; | - | ||||||||||||
623 | while (p
| 0 | ||||||||||||
624 | p = p->parentWidget(); | - | ||||||||||||
625 | if ((
| 0 | ||||||||||||
626 | break; never executed: break; | 0 | ||||||||||||
627 | } never executed: end of block | 0 | ||||||||||||
628 | - | |||||||||||||
629 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype((dialog ? dialog : this)->findChildren<QPushButton *>())>::type> _container_(((dialog ? dialog : this)->findChildren<QPushButton *>())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QPushButton *pb = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||
630 | if (pb->isDefault()
| 0 | ||||||||||||
631 | hasDefault = true; | - | ||||||||||||
632 | break; never executed: break; | 0 | ||||||||||||
633 | } | - | ||||||||||||
634 | } never executed: end of block | 0 | ||||||||||||
635 | if (!hasDefault
| 0 | ||||||||||||
636 | firstAcceptButton->setDefault(true); never executed: firstAcceptButton->setDefault(true); | 0 | ||||||||||||
637 | } never executed: else if (event->type() == QEvent::LanguageChangeend of block
| 0 | ||||||||||||
638 | d->retranslateStrings(); | - | ||||||||||||
639 | } never executed: end of block | 0 | ||||||||||||
640 | return never executed: QWidget::event(event);return QWidget::event(event); never executed: return QWidget::event(event); | 0 | ||||||||||||
641 | } | - | ||||||||||||
642 | - | |||||||||||||
643 | - | |||||||||||||
644 | - | |||||||||||||
Switch to Source code | Preprocessed file |