Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickabstractdialog.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 <QtCore/qloggingcategory.h>
7#include <QtGui/private/qguiapplication_p.h>
8#include <QtQuick/qquickitem.h>
9#include <QtQuick/qquickwindow.h>
10#include <QtQuickDialogs2QuickImpl/private/qquickdialogimplfactory_p.h>
11
13
14Q_LOGGING_CATEGORY(lcDialogs, "qt.quick.dialogs")
15
16
73
107
109 : QObject(parent),
110 m_type(type)
111{
112}
113
115{
116 destroy();
117}
118
120{
121 return m_handle.get();
122}
123
132{
133 return QQmlListProperty<QObject>(this, &m_data);
134}
135
146{
147 return m_parentWindow;
148}
149
151{
152 qCDebug(lcDialogs) << "set parent window to" << window;
153 if (m_parentWindow == window)
154 return;
155
158}
159
166{
167 return m_title;
168}
169
171{
172 if (m_title == title)
173 return;
174
175 m_title = title;
177}
178
184Qt::WindowFlags QQuickAbstractDialog::flags() const
185{
186 return m_flags;
187}
188
190{
191 if (m_flags == flags)
192 return;
193
194 m_flags = flags;
196}
197
209{
210 return m_modality;
211}
212
214{
215 if (m_modality == modality)
216 return;
217
220}
221
230{
231 return m_handle && m_visible;
232}
233
235{
236 qCDebug(lcDialogs) << "setVisible called with" << visible;
237
238 if (visible) {
239 // Don't try to open before component completion, as we won't have a window yet,
240 // and open() sets m_visible to false if it fails.
241 if (!m_complete)
242 m_visibleRequested = true;
243 else
244 open();
245 } else {
246 close();
247 }
248}
249
263{
264 return m_result;
265}
266
268{
269 if (m_result == result)
270 return;
271
274}
275
284{
285 qCDebug(lcDialogs) << "open called";
286 if (m_visible || !create())
287 return;
288
289 onShow(m_handle.get());
291 if (m_visible) {
292 m_result = Rejected; // in case an accepted dialog gets re-opened, then closed
294 }
295}
296
306{
307 if (!m_handle || !m_visible)
308 return;
309
310 onHide(m_handle.get());
311 m_handle->hide();
312 m_visible = false;
314
315 if (m_result == Accepted)
316 emit accepted();
317 else // if (m_result == Rejected)
318 emit rejected();
319}
320
329{
330 done(Accepted);
331}
332
341{
342 done(Rejected);
343}
344
353{
355 close();
356}
357
359{
360}
361
363{
364 qCDebug(lcDialogs) << "componentComplete";
365 m_complete = true;
366
367 if (!m_parentWindow) {
368 qCDebug(lcDialogs) << "- no parent window; searching for one";
370 }
371
372 if (m_visibleRequested) {
373 qCDebug(lcDialogs) << "visible was bound to true before component completion; opening dialog";
374 open();
375 m_visibleRequested = false;
376 }
377}
378
379static const char *qmlTypeName(const QObject *object)
380{
381 return object->metaObject()->className() + qstrlen("QQuickPlatform");
382}
383
385{
386 return quickDialogType == QQuickDialogType::FolderDialog
387 ? QPlatformTheme::FileDialog : static_cast<QPlatformTheme::DialogType>(quickDialogType);
388}
389
391{
392 qCDebug(lcDialogs) << qmlTypeName(this) << "attempting to create dialog backend of type"
393 << int(m_type) << "with parent window" << m_parentWindow;
394 if (m_handle)
395 return m_handle.get();
396
397 qCDebug(lcDialogs) << "- attempting to create a native dialog";
398 if (useNativeDialog()) {
399 m_handle.reset(QGuiApplicationPrivate::platformTheme()->createPlatformDialogHelper(
401 }
402
403 if (!m_handle) {
404 qCDebug(lcDialogs) << "- attempting to create a quick dialog";
406 }
407
408 qCDebug(lcDialogs) << qmlTypeName(this) << "created ->" << m_handle.get();
409 if (m_handle) {
410 onCreate(m_handle.get());
413 }
414 return m_handle.get();
415}
416
418{
419 m_handle.reset();
420}
421
423{
425 qCDebug(lcDialogs) << " - Qt::AA_DontUseNativeDialogs was set; not using native dialog";
426 return false;
427 }
428
429 if (!QGuiApplicationPrivate::platformTheme()->usePlatformNativeDialog(toPlatformDialogType(m_type))) {
430 qCDebug(lcDialogs) << " - the platform theme told us a native dialog isn't available; not using native dialog";
431 return false;
432 }
433
434 return true;
435}
436
443{
445}
446
454{
456 m_firstShow = false;
457}
458
460{
462}
463
465{
466 QObject *obj = parent();
467 while (obj) {
469 if (window)
470 return window;
472 if (item && item->window())
473 return item->window();
474 obj = obj->parent();
475 }
476 return nullptr;
477}
478
480
481#include "moc_qquickabstractdialog_p.cpp"
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
QGraphicsWidget * window() const
QGraphicsObject * parent
the parent of the item
static QPlatformTheme * platformTheme()
\inmodule QtCore
Definition qobject.h:90
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
The QPlatformDialogHelper class allows for platform-specific customization of dialogs.
The QQmlListProperty class allows applications to expose list-like properties of QObject-derived clas...
Definition qqmllist.h:24
void open()
\qmlmethod void QtQuick.Dialogs::Dialog::open()
void setTitle(const QString &title)
std::unique_ptr< QPlatformDialogHelper > m_handle
Qt::WindowModality modality
QPlatformDialogHelper * handle() const
QQmlListProperty< QObject > data
\qmldefault \qmlproperty list<QtObject> QtQuick.Dialogs::Dialog::data
void setModality(Qt::WindowModality modality)
void close()
\qmlmethod void QtQuick.Dialogs::Dialog::close()
QWindow * findParentWindow() const
virtual void accept()
\qmlmethod void QtQuick.Dialogs::Dialog::accept()
bool isVisible() const
\qmlproperty bool QtQuick.Dialogs::Dialog::visible
void setFlags(Qt::WindowFlags flags)
void setResult(StandardCode result)
Qt::WindowModality m_modality
void classBegin() override
Invoked after class creation, but before any properties have been set.
void setParentWindow(QWindow *window)
virtual void onCreate(QPlatformDialogHelper *dialog)
virtual void onHide(QPlatformDialogHelper *dialog)
virtual bool useNativeDialog() const
virtual void done(StandardCode result)
\qmlmethod void QtQuick.Dialogs::Dialog::done(StandardCode result)
void setVisible(bool visible)
virtual void onShow(QPlatformDialogHelper *dialog)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
virtual void reject()
\qmlmethod void QtQuick.Dialogs::Dialog::reject()
static std::unique_ptr< QPlatformDialogHelper > createPlatformDialogHelper(QQuickDialogType type, QObject *parent)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtGui
Definition qwindow.h:63
Combined button and popup list for selecting options.
WindowModality
@ AA_DontUseNativeDialogs
Definition qnamespace.h:457
size_t qstrlen(const char *str)
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
GLenum type
GLbitfield flags
GLhandleARB obj
[2]
GLuint64EXT * result
[6]
QPlatformTheme::DialogType toPlatformDialogType(QQuickDialogType quickDialogType)
static const char * qmlTypeName(const QObject *object)
QQuickDialogType
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
Definition qquickitem.h:483
static const char * qmlTypeName(const QObject *object)
#define emit
#define Q_UNUSED(x)
QWindow * qobject_cast< QWindow * >(QObject *o)
Definition qwindow.h:367
QString title
[35]
QFileDialog dialog(this)
[1]
QGraphicsItem * item
aWidget window() -> setWindowTitle("New Window Title")
[2]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent