Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquickmessagedialogimpl.cpp
Go to the documentation of this file.
1
// Copyright (C) 2021 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
5
#
include
"qquickmessagedialogimpl_p.h"
6
#
include
"qquickmessagedialogimpl_p_p.h"
7
8
#
include
<
QtQuickTemplates2
/
private
/
qquickdialogbuttonbox_p_p
.
h
>
9
10
QT_BEGIN_NAMESPACE
11
12
QQuickMessageDialogImplPrivate::QQuickMessageDialogImplPrivate() { }
13
14
void
QQuickMessageDialogImplPrivate
::
handleClick
(QQuickAbstractButton *button)
15
{
16
Q_Q(QQuickMessageDialogImpl);
17
18
if
(
const
QQuickMessageDialogImplAttached *attached =
attachedOrWarn
(
)
) {
19
QPlatformDialogHelper::StandardButton standardButton =
20
QQuickDialogButtonBoxPrivate::get(attached->buttonBox())->standardButton(button);
21
QPlatformDialogHelper::ButtonRole role = buttonRole(button);
22
23
emit q->buttonClicked(standardButton, role);
24
}
25
}
26
27
QQuickMessageDialogImplAttached *
QQuickMessageDialogImplPrivate
::
attachedOrWarn
()
28
{
29
Q_Q(QQuickMessageDialogImpl);
30
QQuickMessageDialogImplAttached *attached =
static_cast
<QQuickMessageDialogImplAttached *>(
31
qmlAttachedPropertiesObject<QQuickMessageDialogImpl>(q));
32
if
(!attached)
33
qmlWarning(q) <<
"Expected MessageDialogImpl attached object to be present on"
<<
this
;
34
return
attached;
35
}
36
37
QQuickMessageDialogImpl::QQuickMessageDialogImpl(QObject *parent)
38
: QQuickDialog(*(
new
QQuickMessageDialogImplPrivate), parent)
39
{
40
}
41
42
QSharedPointer<QMessageDialogOptions> QQuickMessageDialogImpl::options()
const
43
{
44
Q_D(
const
QQuickMessageDialogImpl);
45
return
d->options;
46
}
47
48
void
QQuickMessageDialogImpl::setOptions(
const
QSharedPointer<QMessageDialogOptions> &options)
49
{
50
Q_D(QQuickMessageDialogImpl);
51
d->options = options;
52
53
QQuickMessageDialogImplAttached *attached = d->attachedOrWarn();
54
55
if
(options && attached) {
56
attached->detailedTextButton()->setVisible(!d->options->detailedText().isEmpty());
57
attached->buttonBox()->setStandardButtons(d->options->standardButtons());
58
}
59
60
if
(showDetailedText())
61
toggleShowDetailedText();
62
63
emit optionsChanged();
64
}
65
66
QString QQuickMessageDialogImpl::text()
const
67
{
68
Q_D(
const
QQuickMessageDialogImpl);
69
return
d->options ? d->options->text() : QString();
70
}
71
72
QString QQuickMessageDialogImpl::informativeText()
const
73
{
74
Q_D(
const
QQuickMessageDialogImpl);
75
return
d->options ? d->options->informativeText() : QString();
76
}
77
78
QString QQuickMessageDialogImpl::detailedText()
const
79
{
80
Q_D(
const
QQuickMessageDialogImpl);
81
return
d->options ? d->options->detailedText() : QString();
82
}
83
84
bool
QQuickMessageDialogImpl::showDetailedText()
const
85
{
86
Q_D(
const
QQuickMessageDialogImpl);
87
return
d->m_showDetailedText;
88
}
89
90
void
QQuickMessageDialogImpl::toggleShowDetailedText()
91
{
92
Q_D(QQuickMessageDialogImpl);
93
d->m_showDetailedText = !d->m_showDetailedText;
94
emit showDetailedTextChanged();
95
}
96
97
void
QQuickMessageDialogImpl::itemChange(QQuickItem::ItemChange change,
const
QQuickItem::ItemChangeData &data)
98
{
99
Q_D(QQuickMessageDialogImpl);
100
QQuickDialog::itemChange(change, data);
101
102
if
(change != QQuickItem::ItemVisibleHasChanged || !isComponentComplete() || !data.boolValue)
103
return
;
104
105
if
(QQuickMessageDialogImplAttached *attached = d->attachedOrWarn(); attached && attached->buttonBox())
106
attached->buttonBox()->forceActiveFocus(Qt::OtherFocusReason);
107
}
108
109
QQuickMessageDialogImplAttached *QQuickMessageDialogImpl::qmlAttachedProperties(QObject *object)
110
{
111
return
new
QQuickMessageDialogImplAttached(object);
112
}
113
114
QQuickMessageDialogImplAttached::QQuickMessageDialogImplAttached(QObject *parent)
115
: QObject(*(
new
QQuickMessageDialogImplAttachedPrivate), parent)
116
{
117
if
(!qobject_cast<QQuickMessageDialogImpl *>(parent)) {
118
qmlWarning(
this
) <<
"MessageDialogImpl attached properties should only be "
119
<<
"accessed through the root MessageDialogImpl instance"
;
120
}
121
}
122
123
QQuickDialogButtonBox *QQuickMessageDialogImplAttached::buttonBox()
const
124
{
125
Q_D(
const
QQuickMessageDialogImplAttached);
126
return
d->buttonBox;
127
}
128
129
void
QQuickMessageDialogImplAttached::setButtonBox(QQuickDialogButtonBox *buttons)
130
{
131
Q_D(QQuickMessageDialogImplAttached);
132
if
(d->buttonBox == buttons)
133
return
;
134
135
if
(d->buttonBox) {
136
QQuickMessageDialogImpl *messageDialogImpl =
137
qobject_cast<QQuickMessageDialogImpl *>(parent());
138
if
(messageDialogImpl) {
139
auto
dialogPrivate = QQuickMessageDialogImplPrivate::get(messageDialogImpl);
140
QObjectPrivate::disconnect(d->buttonBox, &QQuickDialogButtonBox::clicked, dialogPrivate,
141
&QQuickMessageDialogImplPrivate::handleClick);
142
}
143
}
144
145
d->buttonBox = buttons;
146
147
if
(d->buttonBox) {
148
QQuickMessageDialogImpl *messageDialogImpl =
149
qobject_cast<QQuickMessageDialogImpl *>(parent());
150
if
(messageDialogImpl) {
151
auto
dialogPrivate = QQuickMessageDialogImplPrivate::get(messageDialogImpl);
152
QObjectPrivate::connect(d->buttonBox, &QQuickDialogButtonBox::clicked, dialogPrivate,
153
&QQuickMessageDialogImplPrivate::handleClick);
154
}
155
}
156
157
emit buttonBoxChanged();
158
}
159
160
QQuickButton *QQuickMessageDialogImplAttached::detailedTextButton()
const
161
{
162
Q_D(
const
QQuickMessageDialogImplAttached);
163
return
d->detailedTextButton;
164
}
165
void
QQuickMessageDialogImplAttached::setDetailedTextButton(QQuickButton *detailedTextButton)
166
{
167
Q_D(QQuickMessageDialogImplAttached);
168
169
if
(d->detailedTextButton == detailedTextButton)
170
return
;
171
172
if
(d->detailedTextButton) {
173
QQuickMessageDialogImpl *messageDialogImpl =
174
qobject_cast<QQuickMessageDialogImpl *>(parent());
175
if
(messageDialogImpl)
176
disconnect(d->detailedTextButton, &QQuickAbstractButton::clicked, messageDialogImpl,
177
&QQuickMessageDialogImpl::toggleShowDetailedText);
178
}
179
180
d->detailedTextButton = detailedTextButton;
181
182
if
(d->detailedTextButton) {
183
QQuickMessageDialogImpl *messageDialogImpl =
184
qobject_cast<QQuickMessageDialogImpl *>(parent());
185
if
(messageDialogImpl)
186
connect(d->detailedTextButton, &QQuickAbstractButton::clicked, messageDialogImpl,
187
&QQuickMessageDialogImpl::toggleShowDetailedText);
188
}
189
190
emit detailedTextButtonChanged();
191
}
192
193
QT_END_NAMESPACE
194
195
#
include
"moc_qquickmessagedialogimpl_p.cpp"
QQuickMessageDialogImplPrivate
Definition
qquickmessagedialogimpl_p_p.h:28
QQuickMessageDialogImplPrivate::attachedOrWarn
QQuickMessageDialogImplAttached * attachedOrWarn()
Definition
qquickmessagedialogimpl.cpp:27
QQuickMessageDialogImplPrivate::handleClick
void handleClick(QQuickAbstractButton *button) override
Definition
qquickmessagedialogimpl.cpp:14
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quickdialogs
quickdialogsquickimpl
qquickmessagedialogimpl.cpp
Generated on
for Qt by
1.18.0