7#include <QtCore/qloggingcategory.h>
8#include <QtGui/private/qguiapplication_p.h>
9#include <QtGui/qpa/qplatformtheme.h>
10#include <QtQml/qqmlinfo.h>
11#include <QtQml/qqmlfile.h>
12#include <QtQuick/private/qquickitemview_p_p.h>
13#include <QtQuickTemplates2/private/qquickdialogbuttonbox_p_p.h>
14#include <QtQuickTemplates2/private/qquickpopupitem_p_p.h>
15#include <QtQuickControls2Impl/private/qquickplatformtheme_p.h>
16#include <QtQuickDialogs2Utils/private/qquickfilenamefilter_p.h>
23Q_LOGGING_CATEGORY(lcCurrentFolder,
"qt.quick.dialogs.quickfiledialogimpl.currentFolder")
25Q_LOGGING_CATEGORY(lcUpdateSelectedFile, "qt.quick.dialogs.quickfiledialogimpl.updateSelectedFile")
28Q_LOGGING_CATEGORY(lcAttachedNameFilters, "qt.quick.dialogs.quickfiledialogimplattached.namefilters")
29Q_LOGGING_CATEGORY(lcAttachedCurrentIndex, "qt.quick.dialogs.quickfiledialogimplattached.currentIndex")
42 emit q->nameFiltersChanged();
54 qmlWarning(
q).nospace() <<
"Can't update Open button's enabled state because it wasn't found";
76 qCDebug(lcUpdateSelectedFile) <<
"updateSelectedFile called with oldFolderPath" << oldFolderPath;
79 int newSelectedFileIndex = -1;
89 const int indexOfFolder = oldFolderPath.
indexOf(newFolderPath);
90 if (indexOfFolder != -1) {
96 newSelectedFilePath = newFolderPath +
QLatin1Char(
'/') + relativePaths.first();
99 const QDir newFolderDir(newFolderPath);
101 if (!newFolderDir.
exists()) {
102 qmlWarning(
q) <<
"Directory" << newSelectedFilePath <<
"doesn't exist; can't get a file entry list for it";
107 const QFileInfo newSelectedFileInfo(newSelectedFilePath);
108 newSelectedFileIndex = filesInNewDir.
indexOf(newSelectedFileInfo);
112 static const bool preselectFirstFile = []() {
120 if (preselectFirstFile && newSelectedFilePath.
isEmpty()) {
127 const QDir newFolderDir(newFolderPath);
128 if (newFolderDir.
exists()) {
131 newSelectedFileIndex = 0;
137 qCDebug(lcUpdateSelectedFile).nospace() <<
"updateSelectedFile is setting selectedFile to " << newSelectedFileUrl
138 <<
", newSelectedFileIndex is " << newSelectedFileIndex;
139 q->setSelectedFile(newSelectedFileUrl);
142 if (newSelectedFileIndex != -1)
161 qCDebug(lcSelectedFile) <<
"setting fileDialogListView's currentIndex to" << newCurrentIndex;
171 currentItem->forceActiveFocus();
182 qCDebug(lcSelectedFile) <<
"tryUpdateFileDialogListViewCurrentIndex called with newCurrentIndex" << newCurrentIndex;
191 qCDebug(lcSelectedFile) <<
"- trying to set currentIndex to" << newCurrentIndex
193 <<
"items; setting pendingCurrentIndexToSet to" << newCurrentIndex;
211 qCDebug(lcSelectedFile) <<
"- ListView has expected count;"
218 qCDebug(lcSelectedFile) <<
"- reset pendingCurrentIndexToSet to -1";
235 if (fileInfo.
isDir()) {
262 return d->currentFolder;
269 <<
" (old currentFolder is " <<
d->currentFolder <<
")";
278 d->cachedFileList.clear();
279 qCDebug(lcCurrentFolder) <<
"- cachedFileList size is now " <<
d->cachedFileList.size();
291 d->updateSelectedFile(oldFolderPath);
299 return d->selectedFile;
332 qCDebug(lcSelectedFile) <<
"setting initial currentFolder to" << fileDirUrl <<
"and selectedFile to" <<
file;
335 d->setCurrentIndexToInitiallySelectedFile =
true;
342 const QFileInfo newSelectedFileInfo(
d->selectedFile.toLocalFile());
343 const int indexOfSelectedFileInFileDialogListView =
d->cachedFileList.indexOf(newSelectedFileInfo);
344 d->tryUpdateFileDialogListViewCurrentIndex(indexOfSelectedFileInFileDialogListView);
356 qCDebug(lcOptions).nospace() <<
"setOptions called with:"
367 d->selectedNameFilter->setOptions(
options);
370 if (
auto attached =
d->attachedOrWarn()) {
372 attached->fileNameLabel()->setVisible(isSaveMode);
373 attached->fileNameTextField()->setVisible(isSaveMode);
386 return d->options ?
d->options->nameFilters() :
QStringList();
398 if (!
d->selectedNameFilter) {
402 d->selectedNameFilter->setOptions(
d->options);
404 return d->selectedNameFilter;
425 <<
"; failed to find Open button in DialogButtonBox of " <<
this;
429 acceptButton->setText(!
label.isEmpty()
444 <<
"; failed to find Open button in DialogButtonBox of " <<
this;
448 rejectButton->setText(!
label.isEmpty()
454 qCDebug(lcNameFilters) <<
"selectNameFilter called with" <<
filter;
456 d->selectedNameFilter->update(
filter);
487 if (buttonCount == 0)
492 if (!rightMostButton) {
493 qmlWarning(
this) <<
"Can't find right-most button in DialogButtonBox";
498 if (!keyNavigationAttached) {
499 qmlWarning(
this) <<
"Can't create attached KeyNavigation object on" << QDebug::toString(rightMostButton);
526 qmlAttachedPropertiesObject<QQuickFileDialogImpl>(
q,
false));
528 qmlWarning(
q) <<
"Expected FileDialogImpl attached object to be present on" <<
this;
532void QQuickFileDialogImplAttachedPrivate::nameFiltersComboBoxItemActivated(
int index)
534 qCDebug(lcAttachedNameFilters) <<
"nameFiltersComboBoxItemActivated called with" <<
index;
535 auto fileDialogImpl = qobject_cast<QQuickFileDialogImpl*>(
parent);
542void QQuickFileDialogImplAttachedPrivate::fileDialogListViewCurrentIndexChanged()
544 auto fileDialogImpl = qobject_cast<QQuickFileDialogImpl*>(
parent);
549 if (!fileDialogDelegate)
554 <<
" with moveReason " << moveReason
555 <<
"; the file at that index is " << fileDialogDelegate->file();
563 fileDialogImpl->setSelectedFile(fileDialogDelegate->file());
564 }
else if (fileDialogImplPrivate->setCurrentIndexToInitiallySelectedFile) {
569 const QFileInfo newSelectedFileInfo(fileDialogImplPrivate->selectedFile.toLocalFile());
570 const int indexOfSelectedFileInFileDialogListView = fileDialogImplPrivate->cachedFileList.indexOf(newSelectedFileInfo);
571 fileDialogImplPrivate->tryUpdateFileDialogListViewCurrentIndex(indexOfSelectedFileInFileDialogListView);
572 fileDialogImplPrivate->setCurrentIndexToInitiallySelectedFile =
false;
576void QQuickFileDialogImplAttachedPrivate::fileNameChangedByUser()
578 auto fileDialogImpl = qobject_cast<QQuickFileDialogImpl *>(
parent);
588 if (!qobject_cast<QQuickFileDialogImpl*>(
parent)) {
589 qmlWarning(
this) <<
"FileDialogImpl attached properties should only be "
590 <<
"accessed through the root FileDialogImpl instance";
608 if (fileDialogImpl) {
623 if (fileDialogImpl) {
640 return d->nameFiltersComboBox;
652 d, &QQuickFileDialogImplAttachedPrivate::nameFiltersComboBoxItemActivated);
660 return d->nameFiltersComboBox ?
d->nameFiltersComboBox->currentText() :
QString();
666 qCDebug(lcAttachedNameFilters) <<
"selectNameFilter called with" <<
filter;
667 if (!
d->nameFiltersComboBox)
670 const int indexInComboBox =
d->nameFiltersComboBox->find(
filter);
671 if (indexInComboBox == -1)
674 qCDebug(lcAttachedNameFilters) <<
"setting ComboBox's currentIndex to" << indexInComboBox;
675 d->nameFiltersComboBox->setCurrentIndex(indexInComboBox);
681 return d->fileDialogListView;
693 d, &QQuickFileDialogImplAttachedPrivate::fileDialogListViewCurrentIndexChanged);
701 return d->breadcrumbBar;
717 return d->fileNameLabel;
734 return d->fileNameTextField;
743 if (
d->fileNameTextField)
745 d, &QQuickFileDialogImplAttachedPrivate::fileNameChangedByUser);
749 if (
d->fileNameTextField)
751 d, &QQuickFileDialogImplAttachedPrivate::fileNameChangedByUser);
758#include "moc_qquickfiledialogimpl_p.cpp"
QString absolutePath() const
Returns the absolute path (a path that starts with "/" or with a drive specification),...
bool exists() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString initiallySelectedNameFilter() const
AcceptMode acceptMode() const
QUrl initialDirectory() const
QStringList nameFilters() const
FileMode fileMode() const
\inmodule QtCore \reentrant
QString absoluteFilePath() const
Returns an absolute path including the file name.
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory.
QDir dir() const
Returns the path of the object's parent directory as a QDir object.
static QPlatformTheme * platformTheme()
qsizetype size() const noexcept
bool isEmpty() const noexcept
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)
static bool disconnect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot)
QObject * parent() const
Returns a pointer to the parent object.
static QString urlToLocalFileOrQrc(const QString &)
If url is a local file returns a path suitable for passing to QFile.
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.
void activated(int index)
Q_INVOKABLE QString textAt(int index) const
\qmlmethod string QtQuick.Controls::ComboBox::textAt(int index)
Q_INVOKABLE QQuickItem * itemAt(int index) const
\qmlmethod Item QtQuick.Controls::Container::itemAt(int index)
virtual void handleClick(QQuickAbstractButton *button)
static QQuickDialogPrivate * get(QQuickDialog *dialog)
virtual void handleAccept()
static QPlatformDialogHelper::ButtonRole buttonRole(QQuickAbstractButton *button)
Popup dialog with standard buttons and a title, used for short-term interaction with the user.
virtual void handleReject()
QPointer< QQuickTextField > fileNameTextField
QPointer< QQuickListView > fileDialogListView
QPointer< QQuickComboBox > nameFiltersComboBox
void setNameFiltersComboBox(QQuickComboBox *nameFiltersComboBox)
QQuickTextField * fileNameTextField
QQuickDialogButtonBox * buttonBox
void fileNameLabelChanged()
QQuickFolderBreadcrumbBar * breadcrumbBar
QQuickListView * fileDialogListView
QQuickLabel * fileNameLabel
QQuickFileDialogImplAttached(QObject *parent=nullptr)
void breadcrumbBarChanged()
void setFileNameTextField(QQuickTextField *fileNameTextField)
void nameFiltersComboBoxChanged()
void setFileNameLabel(QQuickLabel *fileNameLabel)
void setButtonBox(QQuickDialogButtonBox *buttonBox)
void setBreadcrumbBar(QQuickFolderBreadcrumbBar *breadcrumbBar)
void fileDialogListViewChanged()
void setFileDialogListView(QQuickListView *fileDialogListView)
QString selectedNameFilter() const
QQuickComboBox * nameFiltersComboBox
void selectNameFilter(const QString &filter)
void fileNameTextFieldChanged()
static QDir::SortFlags fileListSortFlags()
static QQuickFileDialogImplPrivate * get(QQuickFileDialogImpl *dialog)
QQuickFileDialogImplAttached * attachedOrWarn()
void fileDialogListViewCountChanged()
void setFileDialogListViewCurrentIndex(int newCurrentIndex)
void updateSelectedFile(const QString &oldFolderPath)
void handleAccept() override
void handleClick(QQuickAbstractButton *button) override
static QFileInfoList fileList(const QDir &dir)
int pendingCurrentIndexToSet
void tryUpdateFileDialogListViewCurrentIndex(int newCurrentIndex)
void setNameFilters(const QStringList &filters)
QFileInfoList cachedFileList
void setRejectLabel(const QString &label)
void setSelectedFile(const QUrl &file)
void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data) override
void setAcceptLabel(const QString &label)
void filterSelected(const QString &filter)
void setFileName(const QString &fileName)
void setOptions(const QSharedPointer< QFileDialogOptions > &options)
void selectedFileChanged(const QUrl &selectedFileUrl)
void setCurrentFolder(const QUrl ¤tFolder, SetReason setReason=SetReason::External)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
QQuickFileDialogImpl(QObject *parent=nullptr)
void selectNameFilter(const QString &filter)
QQuickFileNameFilter * selectedNameFilter
static QQuickFileDialogImplAttached * qmlAttachedProperties(QObject *object)
QSharedPointer< QFileDialogOptions > options() const
void setInitialCurrentFolderAndSelectedFile(const QUrl &file)
void currentFolderChanged(const QUrl &folderUrl)
MovementReason moveReason
QQuickTextField * textField
QQuickAbstractButton * upButton
static QQuickItemViewPrivate * get(QQuickItemView *o)
Q_INVOKABLE void positionViewAtIndex(int index, int mode)
void currentIndexChanged()
void setCurrentIndex(int idx)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Q_INVOKABLE void forceActiveFocus()
\qmlmethod point QtQuick::Item::mapToItem(Item item, real x, real y) \qmlmethod point QtQuick::Item::...
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
static QQuickKeyNavigationAttached * qmlAttachedProperties(QObject *)
Exception-safe wrapper around QObject::blockSignals().
\macro QT_RESTRICTED_CAST_FROM_ASCII
QStringList split(const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the string into substrings wherever sep occurs, and returns the list of those strings.
qsizetype size() const
Returns the number of characters in this string.
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
QString fileName(ComponentFormattingOptions options=FullyDecoded) const
bool isValid() const
Returns true if the URL is non-empty and valid; otherwise returns false.
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
bool canConvert(QMetaType targetType) const
Combined button and popup list for selecting options.
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLenum GLenum GLsizei count
GLuint GLsizei const GLchar * label
[43]
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * path
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
QString qEnvironmentVariable(const char *varName, const QString &defaultValue)
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]
\inmodule QtCore \reentrant
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent
QT_BEGIN_NAMESPACE bool toBool(const QString &str)