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
qquicklabsplatformdialog.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
5
6#include <QtCore/qloggingcategory.h>
7#include <QtGui/private/qguiapplication_p.h>
8#include <QtQuick/qquickitem.h>
9#include <QtQuick/qquickwindow.h>
10
12
14
19
55Q_LOGGING_CATEGORY(qtLabsPlatformDialogs, "qt.labs.platform.dialogs")
56
58 : QObject(parent),
59 m_visible(false),
60 m_complete(false),
61 m_result(0),
62 m_parentWindow(nullptr),
63 m_flags(Qt::Dialog),
64 m_modality(Qt::WindowModal),
65 m_type(type),
66 m_handle(nullptr)
67{
68}
69
74
76{
77 return m_handle;
78}
79
87QQmlListProperty<QObject> QQuickLabsPlatformDialog::data()
88{
89 return QQmlListProperty<QObject>(this, &m_data);
90}
91
102{
103 return m_parentWindow;
104}
105
107{
108 if (m_parentWindow == window)
109 return;
110
111 m_parentWindow = window;
113}
114
121{
122 return m_title;
123}
124
126{
127 if (m_title == title)
128 return;
129
130 m_title = title;
132}
133
139Qt::WindowFlags QQuickLabsPlatformDialog::flags() const
140{
141 return m_flags;
142}
143
145{
146 if (m_flags == flags)
147 return;
148
149 m_flags = flags;
151}
152
164{
165 return m_modality;
166}
167
169{
170 if (m_modality == modality)
171 return;
172
173 m_modality = modality;
175}
176
185{
186 return m_handle && m_visible;
187}
188
190{
191 if (visible)
192 open();
193 else
194 close();
195}
196
210{
211 return m_result;
212}
213
215{
216 if (m_result == result)
217 return;
218
219 m_result = result;
221}
222
231{
232 if (m_visible || !create())
233 return;
234
235 onShow(m_handle);
236 m_visible = m_handle->show(m_flags, m_modality, m_parentWindow);
237 if (m_visible)
239}
240
249{
250 if (!m_handle || !m_visible)
251 return;
252
253 onHide(m_handle);
254 m_handle->hide();
255 m_visible = false;
257}
258
270
282
291{
292 close();
294
295 if (result == Accepted)
296 emit accepted();
297 else if (result == Rejected)
298 emit rejected();
299}
300
304
306{
307 m_complete = true;
308 if (!m_parentWindow)
310}
311
312static const char *qmlTypeName(const QObject *object)
313{
314 return object->metaObject()->className() + qstrlen("QQuickLabsPlatform");
315}
316
318{
319 if (!m_handle) {
320 if (useNativeDialog())
321 m_handle = QGuiApplicationPrivate::platformTheme()->createPlatformDialogHelper(m_type);
322 if (!m_handle)
323 m_handle = QWidgetPlatform::createDialog(m_type, this);
324 qCDebug(qtLabsPlatformDialogs) << qmlTypeName(this) << "->" << m_handle;
325 if (m_handle) {
326 onCreate(m_handle);
329 }
330 }
331 return m_handle;
332}
333
335{
336 delete m_handle;
337 m_handle = nullptr;
338}
339
345
350
355
360
362{
363 QObject *obj = parent();
364 while (obj) {
366 if (window)
367 return window;
369 if (item && item->window())
370 return item->window();
371 obj = obj->parent();
372 }
373 return nullptr;
374}
375
377
378#include "moc_qquicklabsplatformdialog_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:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
The QPlatformDialogHelper class allows for platform-specific customization of dialogs.
virtual void hide()=0
virtual bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent)=0
The QPlatformTheme class allows customizing the UI based on themes.
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
virtual void reject()
\qmlmethod void Qt.labs.platform::Dialog::reject()
void open()
\qmlmethod void Qt.labs.platform::Dialog::open()
void close()
\qmlmethod void Qt.labs.platform::Dialog::close()
bool isVisible() const
\qmlproperty bool Qt.labs.platform::Dialog::visible
void classBegin() override
Invoked after class creation, but before any properties have been set.
virtual void onShow(QPlatformDialogHelper *dialog)
virtual void onHide(QPlatformDialogHelper *dialog)
QPlatformDialogHelper * handle() const
virtual void done(int result)
\qmlmethod void Qt.labs.platform::Dialog::done(int result)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
QQmlListProperty< QObject > data
\qmldefault \qmlproperty list<QtObject> Qt.labs.platform::Dialog::data
void setTitle(const QString &title)
virtual void onCreate(QPlatformDialogHelper *dialog)
virtual void accept()
\qmlmethod void Qt.labs.platform::Dialog::accept()
void setFlags(Qt::WindowFlags flags)
void setModality(Qt::WindowModality modality)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtGui
Definition qwindow.h:63
Combined button and popup list for selecting options.
static QPlatformDialogHelper * createDialog(QPlatformTheme::DialogType type, QObject *parent=nullptr)
Definition qcompare.h:63
WindowModality
@ AA_DontUseNativeDialogs
Definition qnamespace.h:458
size_t qstrlen(const char *str)
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLenum type
GLbitfield flags
GLhandleARB obj
[2]
GLuint64EXT * result
[6]
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
Definition qquickitem.h:492
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]