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
qquickfiledialogdelegate.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/qfileinfo.h>
7#include <QtGui/qpa/qplatformtheme.h>
8#include <QtQml/QQmlFile>
9#include <QtQml/qqmlexpression.h>
10#include <QtQuick/private/qquicklistview_p.h>
11#include <QtQuickTemplates2/private/qquickitemdelegate_p_p.h>
12
16
18
20{
21public:
22 Q_DECLARE_PUBLIC(QQuickFileDialogDelegate)
23
24 void highlightFile();
25 void chooseFile();
26
27 bool acceptKeyClick(Qt::Key key) const override;
28
29 QQuickDialog *dialog = nullptr;
33};
34
36{
38 QQuickListViewAttached *attached = static_cast<QQuickListViewAttached*>(
39 qmlAttachedPropertiesObject<QQuickListView>(q));
40 if (!attached)
41 return;
42
43 QQmlContext *delegateContext = qmlContext(q);
44 if (!delegateContext)
45 return;
46
47 bool converted = false;
48 const int index = q->property("index").toInt(&converted);
49 if (converted) {
50 attached->view()->setCurrentIndex(index);
51 if (fileDialog)
53 else if (folderDialog)
55 }
56}
57
59{
61 if (fileInfo.isDir()) {
62 // If it's a directory, navigate to it.
63 if (fileDialog)
65 else
67 } else {
69 // Otherwise it's a file, so select it and close the dialog.
71
72 // Prioritize closing the dialog with QQuickDialogPrivate::handleClick() over QQuickDialog::accept()
74 if (Q_LIKELY(attached)) {
75 auto *openButton = attached->buttonBox()->standardButton(QPlatformDialogHelper::Open);
76 if (Q_LIKELY(openButton)) {
77 emit openButton->clicked();
78 return;
79 }
80 }
82 }
83}
84
89
103
105{
106 Q_D(const QQuickFileDialogDelegate);
107 return d->dialog;
108}
109
111{
113 if (dialog == d->dialog)
114 return;
115
116 d->dialog = dialog;
117 d->fileDialog = qobject_cast<QQuickFileDialogImpl*>(dialog);
118 d->folderDialog = qobject_cast<QQuickFolderDialogImpl*>(dialog);
120}
121
123{
124 Q_D(const QQuickFileDialogDelegate);
125 return d->file;
126}
127
129{
131 QUrl adjustedFile = file;
132#ifdef Q_OS_WIN32
133 // Work around QTBUG-99105 (FolderListModel uses lowercase drive letter).
134 QString path = adjustedFile.path();
135 const int driveColonIndex = path.indexOf(QLatin1Char(':'));
136 if (driveColonIndex == 2) {
137 path.replace(1, 1, path.at(1).toUpper());
138 adjustedFile.setPath(path);
139 }
140#endif
141 if (adjustedFile == d->file)
142 return;
143
144 d->file = adjustedFile;
146}
147
149{
151 // We need to respond to being triggered by enter being pressed,
152 // but we can't use event->isAccepted() to check, because events are pre-accepted.
155
157
159}
160
162
163#include "moc_qquickfiledialogdelegate_p.cpp"
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory.
The QKeyEvent class describes a key event.
Definition qevent.h:424
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
Definition qobject_p.h:299
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
static QString urlToLocalFileOrQrc(const QString &)
If url is a local file returns a path suitable for passing to \l{QFile}.
Definition qqmlfile.cpp:742
void setCheckable(bool checkable)
Q_INVOKABLE QQuickAbstractButton * standardButton(QPlatformDialogHelper::StandardButton button) const
\qmlmethod AbstractButton QtQuick.Controls::DialogButtonBox::standardButton(StandardButton button)
virtual void accept()
\qmlmethod void QtQuick.Controls::Dialog::accept()
bool acceptKeyClick(Qt::Key key) const override
void setDialog(QQuickDialog *dialog)
void keyReleaseEvent(QKeyEvent *event) override
This event handler can be reimplemented in a subclass to receive key release events for an item.
QQuickFileDialogDelegate(QQuickItem *parent=nullptr)
static QQuickFileDialogImplPrivate * get(QQuickFileDialogImpl *dialog)
void setSelectedFile(const QUrl &file)
void setCurrentFolder(const QUrl &currentFolder, SetReason setReason=SetReason::External)
void setSelectedFolder(const QUrl &selectedFolder)
void setCurrentFolder(const QUrl &folder)
void setCurrentIndex(int idx)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
virtual void keyReleaseEvent(QKeyEvent *event)
This event handler can be reimplemented in a subclass to receive key release events for an item.
void setFocusPolicy(Qt::FocusPolicy policy)
Sets the focus policy of this item to policy.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
qsizetype indexOf(QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.cpp:4517
\inmodule QtCore
Definition qurl.h:94
Combined button and popup list for selecting options.
@ StrongFocus
Definition qnamespace.h:110
@ Key_Return
Definition qnamespace.h:667
@ Key_Enter
Definition qnamespace.h:668
#define Q_LIKELY(x)
DBusConnection * connection
GLuint64 key
GLuint index
[2]
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLsizei const GLchar *const * path
QQmlContext * qmlContext(const QObject *obj)
Definition qqml.cpp:75
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
QFile file
[0]
myObject disconnect()
[26]
QFileDialog dialog(this)
[1]
\inmodule QtCore \reentrant
Definition qchar.h:18