Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquicklabsplatformmessagedialog.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
7#if QT_DEPRECATED_SINCE(6, 9)
8
9#include <QtQml/qqmlinfo.h>
10
11QT_BEGIN_NAMESPACE
12
13/*!
14 \qmltype MessageDialog
15 \inherits Dialog
16//! \nativetype QQuickLabsPlatformMessageDialog
17 \inqmlmodule Qt.labs.platform
18 \since 5.8
19 \deprecated [6.9] Use QtQuick.Dialogs::MessageDialog instead.
20 \brief A native message dialog.
21
22 The MessageDialog type provides a QML API for native platform message dialogs.
23
24 \image {qtlabsplatform-messagedialog-android.png} {A native message dialog}
25
26 A message dialog is used to inform the user, or ask the user a question.
27 A message dialog displays a primary \l text to alert the user to a situation,
28 an \l {informativeText}{informative text} to further explain the alert or to
29 ask the user a question, and an optional \l {detailedText}{detailed text} to
30 provide even more data if the user requests it. A message box can also display
31 a configurable set of \l buttons for accepting a user response.
32
33 To show a message dialog, construct an instance of MessageDialog, set the
34 desired properties, and call \l {Dialog::}{open()}.
35
36 \code
37 MessageDialog {
38 buttons: MessageDialog.Ok
39 text: "The document has been modified."
40 }
41 \endcode
42
43 The user must click the \uicontrol OK button to dismiss the message dialog.
44 A modal message dialog blocks the rest of the GUI until the message is
45 dismissed.
46
47 A more elaborate approach than just alerting the user to an event is to
48 also ask the user what to do about it. Store the question in the
49 \l {informativeText}{informative text} property, and specify the \l buttons
50 property to the set of buttons you want as the set of user responses. The
51 buttons are specified by combining values using the bitwise OR operator. The
52 display order for the buttons is platform dependent.
53
54 \code
55 MessageDialog {
56 text: "The document has been modified."
57 informativeText: "Do you want to save your changes?"
58 buttons: MessageDialog.Ok | MessageDialog.Cancel
59
60 onAccepted: document.save()
61 }
62 \endcode
63
64 \image {qtlabsplatform-messagedialog-informative-android.png} {A native informative message dialog}
65
66 The \l clicked() signal passes the information of which button was clicked.
67
68 A native platform message dialog is currently available on the following platforms:
69
70 \list
71 \li Android
72 \li iOS
73 \li macOS
74 \endlist
75
76 \input includes/widgets.qdocinc 1
77
78 \labs
79
80 \sa QtQuick.Dialogs::MessageDialog
81*/
82
83/*!
84 \qmlsignal Qt.labs.platform::MessageDialog::clicked(button)
85
86 This signal is emitted when a dialog \a button is clicked.
87
88 \sa buttons
89*/
90
91/*!
92 \qmlsignal Qt.labs.platform::MessageDialog::okClicked()
93
94 This signal is emitted when \uicontrol Ok is clicked.
95*/
96
97/*!
98 \qmlsignal Qt.labs.platform::MessageDialog::saveClicked()
99
100 This signal is emitted when \uicontrol Save is clicked.
101*/
102
103/*!
104 \qmlsignal Qt.labs.platform::MessageDialog::saveAllClicked()
105
106 This signal is emitted when \uicontrol {Save All} is clicked.
107*/
108
109/*!
110 \qmlsignal Qt.labs.platform::MessageDialog::openClicked()
111
112 This signal is emitted when \uicontrol Open is clicked.
113*/
114
115/*!
116 \qmlsignal Qt.labs.platform::MessageDialog::yesClicked()
117
118 This signal is emitted when \uicontrol Yes is clicked.
119*/
120
121/*!
122 \qmlsignal Qt.labs.platform::MessageDialog::yesToAllClicked()
123
124 This signal is emitted when \uicontrol {Yes To All} is clicked.
125*/
126
127/*!
128 \qmlsignal Qt.labs.platform::MessageDialog::noClicked()
129
130 This signal is emitted when \uicontrol No is clicked.
131*/
132
133/*!
134 \qmlsignal Qt.labs.platform::MessageDialog::noToAllClicked()
135
136 This signal is emitted when \uicontrol {No To All} is clicked.
137*/
138
139/*!
140 \qmlsignal Qt.labs.platform::MessageDialog::abortClicked()
141
142 This signal is emitted when \uicontrol Abort is clicked.
143*/
144
145/*!
146 \qmlsignal Qt.labs.platform::MessageDialog::retryClicked()
147
148 This signal is emitted when \uicontrol Retry is clicked.
149*/
150
151/*!
152 \qmlsignal Qt.labs.platform::MessageDialog::ignoreClicked()
153
154 This signal is emitted when \uicontrol Ignore is clicked.
155*/
156
157/*!
158 \qmlsignal Qt.labs.platform::MessageDialog::closeClicked()
159
160 This signal is emitted when \uicontrol Close is clicked.
161*/
162
163/*!
164 \qmlsignal Qt.labs.platform::MessageDialog::cancelClicked()
165
166 This signal is emitted when \uicontrol Cancel is clicked.
167*/
168
169/*!
170 \qmlsignal Qt.labs.platform::MessageDialog::discardClicked()
171
172 This signal is emitted when \uicontrol Discard is clicked.
173*/
174
175/*!
176 \qmlsignal Qt.labs.platform::MessageDialog::helpClicked()
177
178 This signal is emitted when \uicontrol Help is clicked.
179*/
180
181/*!
182 \qmlsignal Qt.labs.platform::MessageDialog::applyClicked()
183
184 This signal is emitted when \uicontrol Apply is clicked.
185*/
186
187/*!
188 \qmlsignal Qt.labs.platform::MessageDialog::resetClicked()
189
190 This signal is emitted when \uicontrol Reset is clicked.
191*/
192
193/*!
194 \qmlsignal Qt.labs.platform::MessageDialog::restoreDefaultsClicked()
195
196 This signal is emitted when \uicontrol {Restore Defaults} is clicked.
197*/
198
199QQuickLabsPlatformMessageDialog::QQuickLabsPlatformMessageDialog(QObject *parent)
200 : QQuickLabsPlatformDialog(QPlatformTheme::MessageDialog, parent),
201 m_options(QMessageDialogOptions::create())
202{
203}
204
205/*!
206 \qmlproperty string Qt.labs.platform::MessageDialog::text
207
208 This property holds the text to be displayed on the message dialog.
209
210 \sa informativeText, detailedText
211*/
212QString QQuickLabsPlatformMessageDialog::text() const
213{
214 return m_options->text();
215}
216
217void QQuickLabsPlatformMessageDialog::setText(const QString &text)
218{
219 if (m_options->text() == text)
220 return;
221
222 m_options->setText(text);
223 emit textChanged();
224}
225
226/*!
227 \qmlproperty string Qt.labs.platform::MessageDialog::informativeText
228
229 This property holds the informative text that provides a fuller description for the message.
230
231 Informative text can be used to expand upon the \l text to give more information to the user.
232
233 \sa text, detailedText
234*/
235QString QQuickLabsPlatformMessageDialog::informativeText() const
236{
237 return m_options->informativeText();
238}
239
240void QQuickLabsPlatformMessageDialog::setInformativeText(const QString &text)
241{
242 if (m_options->informativeText() == text)
243 return;
244
245 m_options->setInformativeText(text);
246 emit informativeTextChanged();
247}
248
249/*!
250 \qmlproperty string Qt.labs.platform::MessageDialog::detailedText
251
252 This property holds the text to be displayed in the details area.
253
254 \sa text, informativeText
255*/
256QString QQuickLabsPlatformMessageDialog::detailedText() const
257{
258 return m_options->detailedText();
259}
260
261void QQuickLabsPlatformMessageDialog::setDetailedText(const QString &text)
262{
263 if (m_options->detailedText() == text)
264 return;
265
266 m_options->setDetailedText(text);
267 emit detailedTextChanged();
268}
269
270/*!
271 \qmlproperty flags Qt.labs.platform::MessageDialog::buttons
272
273 This property holds a combination of buttons that are used by the message dialog.
274 The default value is \c MessageDialog.NoButton.
275
276 Possible flags:
277 \value MessageDialog.Ok An "OK" button defined with the \c AcceptRole.
278 \value MessageDialog.Open An "Open" button defined with the \c AcceptRole.
279 \value MessageDialog.Save A "Save" button defined with the \c AcceptRole.
280 \value MessageDialog.Cancel A "Cancel" button defined with the \c RejectRole.
281 \value MessageDialog.Close A "Close" button defined with the \c RejectRole.
282 \value MessageDialog.Discard A "Discard" or "Don't Save" button, depending on the platform, defined with the \c DestructiveRole.
283 \value MessageDialog.Apply An "Apply" button defined with the \c ApplyRole.
284 \value MessageDialog.Reset A "Reset" button defined with the \c ResetRole.
285 \value MessageDialog.RestoreDefaults A "Restore Defaults" button defined with the \c ResetRole.
286 \value MessageDialog.Help A "Help" button defined with the \c HelpRole.
287 \value MessageDialog.SaveAll A "Save All" button defined with the \c AcceptRole.
288 \value MessageDialog.Yes A "Yes" button defined with the \c YesRole.
289 \value MessageDialog.YesToAll A "Yes to All" button defined with the \c YesRole.
290 \value MessageDialog.No A "No" button defined with the \c NoRole.
291 \value MessageDialog.NoToAll A "No to All" button defined with the \c NoRole.
292 \value MessageDialog.Abort An "Abort" button defined with the \c RejectRole.
293 \value MessageDialog.Retry A "Retry" button defined with the \c AcceptRole.
294 \value MessageDialog.Ignore An "Ignore" button defined with the \c AcceptRole.
295 \value MessageDialog.NoButton The dialog has no buttons.
296
297 \sa clicked()
298*/
299QPlatformDialogHelper::StandardButtons QQuickLabsPlatformMessageDialog::buttons() const
300{
301 return m_options->standardButtons();
302}
303
304void QQuickLabsPlatformMessageDialog::setButtons(QPlatformDialogHelper::StandardButtons buttons)
305{
306 if (m_options->standardButtons() == buttons)
307 return;
308
309 m_options->setStandardButtons(buttons);
310 emit buttonsChanged();
311}
312
313void QQuickLabsPlatformMessageDialog::onCreate(QPlatformDialogHelper *dialog)
314{
315 if (QPlatformMessageDialogHelper *messageDialog = qobject_cast<QPlatformMessageDialogHelper *>(dialog)) {
316 connect(messageDialog, &QPlatformMessageDialogHelper::clicked, this, &QQuickLabsPlatformMessageDialog::handleClick);
317 messageDialog->setOptions(m_options);
318 }
319}
320
321void QQuickLabsPlatformMessageDialog::onShow(QPlatformDialogHelper *dialog)
322{
323 m_options->setWindowTitle(title());
324 if (QPlatformMessageDialogHelper *messageDialog = qobject_cast<QPlatformMessageDialogHelper *>(dialog))
325 messageDialog->setOptions(m_options);
326}
327
328void QQuickLabsPlatformMessageDialog::handleClick(QPlatformDialogHelper::StandardButton button)
329{
330 done(button);
331 emit clicked(button);
332
333 switch (button) {
334 case QPlatformDialogHelper::Ok: emit okClicked(); break;
335 case QPlatformDialogHelper::Save: emit saveClicked(); break;
336 case QPlatformDialogHelper::SaveAll: emit saveAllClicked(); break;
337 case QPlatformDialogHelper::Open: emit openClicked(); break;
338 case QPlatformDialogHelper::Yes: emit yesClicked(); break;
339 case QPlatformDialogHelper::YesToAll: emit yesToAllClicked(); break;
340 case QPlatformDialogHelper::No: emit noClicked(); break;
341 case QPlatformDialogHelper::NoToAll: emit noToAllClicked(); break;
342 case QPlatformDialogHelper::Abort: emit abortClicked(); break;
343 case QPlatformDialogHelper::Retry: emit retryClicked(); break;
344 case QPlatformDialogHelper::Ignore: emit ignoreClicked(); break;
345 case QPlatformDialogHelper::Close: emit closeClicked(); break;
346 case QPlatformDialogHelper::Cancel: emit cancelClicked(); break;
347 case QPlatformDialogHelper::Discard: emit discardClicked(); break;
348 case QPlatformDialogHelper::Help: emit helpClicked(); break;
349 case QPlatformDialogHelper::Apply: emit applyClicked(); break;
350 case QPlatformDialogHelper::Reset: emit resetClicked(); break;
351 case QPlatformDialogHelper::RestoreDefaults: emit restoreDefaultsClicked(); break;
352 default: qmlWarning(this) << "unknown button" << int(button); break;
353 }
354}
355
356QT_END_NAMESPACE
357
358#include "moc_qquicklabsplatformmessagedialog_p.cpp"
359
360#endif // QT_DEPRECATED_SINCE(6, 9)