Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickplatformmessagedialog.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
5
6#include <QtQuickTemplates2/private/qquickpopup_p_p.h>
7#include <QtQuickTemplates2/private/qquickpopupanchors_p.h>
8
10
12
13Q_LOGGING_CATEGORY(lcQuickPlatformMessageDialog, "qt.quick.dialogs.quickplatformmessagedialog")
14
16{
17 qCDebug(lcQuickPlatformMessageDialog)
18 << "creating non-native Qt Quick MessageDialog with parent" << parent;
19
20 // Set a parent so that we get deleted if we can't be shown for whatever reason.
21 // Our eventual parent should be the window, though.
22 setParent(parent);
23
24 auto qmlContext = ::qmlContext(parent);
25 if (!qmlContext) {
26 qmlWarning(parent) << "No QQmlContext for QQuickPlatformMessageDialog; can't create "
27 "non-native MessageDialog implementation";
28 return;
29 }
30
31 const auto dialogQmlUrl = QUrl(QStringLiteral(
32 "qrc:/qt-project.org/imports/QtQuick/Dialogs/quickimpl/qml/MessageDialog.qml"));
33
34 QQmlComponent messageDialogComponent(qmlContext->engine(), dialogQmlUrl, parent);
35 if (!messageDialogComponent.isReady()) {
36 qmlWarning(parent) << "Failed to load non-native MessageBox implementation:\n"
37 << messageDialogComponent.errorString();
38 return;
39 }
40
41 m_dialog = qobject_cast<QQuickMessageDialogImpl *>(messageDialogComponent.create());
42
43 if (!m_dialog) {
44 qmlWarning(parent) << "Failed to create an instance of the non-native MessageBox:\n"
45 << messageDialogComponent.errorString();
46 return;
47 }
48
49 m_dialog->setParent(this);
50
55}
56
58{
59 qCWarning(lcQuickPlatformMessageDialog)
60 << "exec() is not supported for the Qt Quick MessageDialog fallback";
61}
62
64 QWindow *parent)
65{
66 qCDebug(lcQuickPlatformMessageDialog)
67 << "show called with flags" << flags << "modality" << modality << "parent" << parent;
68 if (!m_dialog)
69 return false;
70
71 if (!parent)
72 return false;
73
74 auto quickWindow = qobject_cast<QQuickWindow *>(parent);
75 if (!quickWindow) {
76 qmlInfo(this->parent()) << "Parent window (" << parent
77 << ") of non-native dialog is not a QQuickWindow";
78 return false;
79 }
80 m_dialog->setParent(parent);
81 m_dialog->resetParentItem();
82
83 auto popupPrivate = QQuickPopupPrivate::get(m_dialog);
84 popupPrivate->getAnchors()->setCenterIn(m_dialog->parentItem());
85
86 QSharedPointer<QMessageDialogOptions> options = QPlatformMessageDialogHelper::options();
87 m_dialog->setTitle(options->windowTitle());
88 m_dialog->setOptions(options);
89
90 m_dialog->open();
91 return true;
92}
94{
95 if (isValid())
96 m_dialog->close();
97}
98
100{
101 return m_dialog;
102}
103
105{
106 return m_dialog;
107}
108
110
111#include "moc_qquickplatformmessagedialog_p.cpp"
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
void setParent(QObject *parent)
Makes the object a child of parent.
Definition qobject.cpp:2195
const QSharedPointer< QMessageDialogOptions > & options() const
void clicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role)
The QQmlComponent class encapsulates a QML component definition.
QQmlEngine * engine() const
Return the context's QQmlEngine, or \nullptr if the context has no QQmlEngine or the QQmlEngine was d...
void setTitle(const QString &title)
void accepted()
void rejected()
void setOptions(const QSharedPointer< QMessageDialogOptions > &options)
void buttonClicked(QPlatformDialogHelper::StandardButton button, QPlatformDialogHelper::ButtonRole role)
QQuickMessageDialogImpl * dialog() const
bool show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent) override
static QQuickPopupPrivate * get(QQuickPopup *popup)
void close()
\qmlmethod void QtQuick.Controls::Popup::close()
void open()
\qmlmethod void QtQuick.Controls::Popup::open()
\inmodule QtCore
Definition qurl.h:94
\inmodule QtGui
Definition qwindow.h:63
Combined button and popup list for selecting options.
WindowModality
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
#define qCDebug(category,...)
GLbitfield flags
QQmlContext * qmlContext(const QObject *obj)
Definition qqml.cpp:75
Q_QML_EXPORT QQmlInfo qmlInfo(const QObject *me)
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
#define QStringLiteral(str)
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
file setParent(multiPart)