diff options
Diffstat (limited to 'src/widgets/dialogs/qfiledialog_p.h')
-rw-r--r-- | src/widgets/dialogs/qfiledialog_p.h | 155 |
1 files changed, 63 insertions, 92 deletions
diff --git a/src/widgets/dialogs/qfiledialog_p.h b/src/widgets/dialogs/qfiledialog_p.h index 2e49696b77..d5ee1c537b 100644 --- a/src/widgets/dialogs/qfiledialog_p.h +++ b/src/widgets/dialogs/qfiledialog_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWidgets module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QFILEDIALOG_P_H #define QFILEDIALOG_P_H @@ -57,7 +21,7 @@ #include "private/qdialog_p.h" #include "qplatformdefs.h" -#include "qfilesystemmodel_p.h" +#include <QtGui/private/qfilesystemmodel_p.h> #include <qlistview.h> #include <qtreeview.h> #include <qcombobox.h> @@ -69,6 +33,7 @@ #include <qstackedwidget.h> #include <qdialogbuttonbox.h> #include <qabstractproxymodel.h> +#include <qfileiconprovider.h> #if QT_CONFIG(completer) #include <qcompleter.h> #endif @@ -98,24 +63,30 @@ class QPlatformDialogHelper; struct QFileDialogArgs { - QFileDialogArgs() : parent(0), mode(QFileDialog::AnyFile) {} + QFileDialogArgs(const QUrl &url = {}); - QWidget *parent; + QWidget *parent = nullptr; QString caption; QUrl directory; QString selection; QString filter; - QFileDialog::FileMode mode; - QFileDialog::Options options; + QFileDialog::FileMode mode = QFileDialog::AnyFile; + QFileDialog::Options options = {}; }; -#define UrlRole (Qt::UserRole + 1) - class Q_WIDGETS_EXPORT QFileDialogPrivate : public QDialogPrivate { Q_DECLARE_PUBLIC(QFileDialog) public: + using PersistentModelIndexList = QList<QPersistentModelIndex>; + + struct HistoryItem + { + QString path; + PersistentModelIndexList selection; + }; + QFileDialogPrivate(); QPlatformFileDialogHelper *platformFileDialogHelper() const @@ -125,12 +96,9 @@ public: void createMenuActions(); void createWidgets(); - void init(const QUrl &directory = QUrl(), const QString &nameFilter = QString(), - const QString &caption = QString()); + void init(const QFileDialogArgs &args); bool itemViewKeyboardEvent(QKeyEvent *event); QString getEnvironmentVariable(const QString &string); - static QUrl workingDirectory(const QUrl &path); - static QString initialSelection(const QUrl &path); QStringList typedFiles() const; QList<QUrl> userSelectedFiles() const; QStringList addDefaultSuffixToFiles(const QStringList &filesToFix) const; @@ -152,11 +120,11 @@ public: QLineEdit *lineEdit() const; - static int maxNameLength(const QString &path); + static long maxNameLength(const QString &path); QString basename(const QString &path) const { - int separator = QDir::toNativeSeparators(path).lastIndexOf(QDir::separator()); + const qsizetype separator = QDir::toNativeSeparators(path).lastIndexOf(QDir::separator()); if (separator != -1) return path.mid(separator + 1); return path; @@ -164,13 +132,9 @@ public: QDir::Filters filterForMode(QDir::Filters filters) const { - const QFileDialog::FileMode fileMode = q_func()->fileMode(); - if (fileMode == QFileDialog::DirectoryOnly) { - filters |= QDir::Drives | QDir::AllDirs | QDir::Dirs; + filters |= QDir::Drives | QDir::AllDirs | QDir::Dirs | QDir::Files; + if (q_func()->testOption(QFileDialog::ShowDirsOnly)) filters &= ~QDir::Files; - } else { - filters |= QDir::Drives | QDir::AllDirs | QDir::Files | QDir::Dirs; - } return filters; } @@ -180,7 +144,7 @@ public: { #if defined(Q_OS_WIN) QString n(path); - n.replace(QLatin1Char('\\'), QLatin1Char('/')); + n.replace(u'\\', u'/'); return n; #else // the compile should optimize away this return path; @@ -197,34 +161,36 @@ public: void retranslateWindowTitle(); void retranslateStrings(); void emitFilesSelected(const QStringList &files); - - void _q_goHome(); - void _q_pathChanged(const QString &); - void _q_navigateBackward(); - void _q_navigateForward(); - void _q_navigateToParent(); - void _q_createDirectory(); - void _q_showListView(); - void _q_showDetailsView(); - void _q_showContextMenu(const QPoint &position); - void _q_renameCurrent(); - void _q_deleteCurrent(); - void _q_showHidden(); - void _q_showHeader(QAction *); - void _q_updateOkButton(); - void _q_currentChanged(const QModelIndex &index); - void _q_enterDirectory(const QModelIndex &index); - void _q_emitUrlSelected(const QUrl &file); - void _q_emitUrlsSelected(const QList<QUrl> &files); - void _q_nativeCurrentChanged(const QUrl &file); - void _q_nativeEnterDirectory(const QUrl &directory); - void _q_goToDirectory(const QString &); - void _q_useNameFilter(int index); - void _q_selectionChanged(); - void _q_goToUrl(const QUrl &url); - void _q_autoCompleteFileName(const QString &); - void _q_rowsInserted(const QModelIndex & parent); - void _q_fileRenamed(const QString &path, const QString &oldName, const QString &newName); + void saveHistorySelection(); + + void goHome(); + void pathChanged(const QString &); + void navigate(HistoryItem &); + void navigateBackward(); + void navigateForward(); + void navigateToParent(); + void createDirectory(); + void showListView(); + void showDetailsView(); + void showContextMenu(const QPoint &position); + void renameCurrent(); + void deleteCurrent(); + void showHidden(); + void showHeader(QAction *); + void updateOkButton(); + void currentChanged(const QModelIndex &index); + void enterDirectory(const QModelIndex &index); + void emitUrlSelected(const QUrl &file); + void emitUrlsSelected(const QList<QUrl> &files); + void nativeCurrentChanged(const QUrl &file); + void nativeEnterDirectory(const QUrl &directory); + void goToDirectory(const QString &); + void useNameFilter(int index); + void selectionChanged(); + void goToUrl(const QUrl &url); + void autoCompleteFileName(const QString &); + void rowsInserted(const QModelIndex & parent); + void fileRenamed(const QString &path, const QString &oldName, const QString &newName); // layout #if QT_CONFIG(proxymodel) @@ -241,7 +207,7 @@ public: QString setWindowTitle; - QStringList currentHistory; + QList<HistoryItem> currentHistory; int currentHistoryLocation; QAction *renameAction; @@ -255,6 +221,7 @@ public: // dialog. Returning false means that a non-native dialog must be // used instead. bool canBeNativeDialog() const override; + void setVisible(bool visible) override; inline bool usingWidgets() const; inline void setDirectory_sys(const QUrl &directory); @@ -282,6 +249,7 @@ public: QByteArray splitterState; QByteArray headerData; QList<QUrl> sidebarUrls; + QFileIconProvider defaultIconProvider; ~QFileDialogPrivate(); @@ -290,13 +258,15 @@ private: virtual void helperPrepareShow(QPlatformDialogHelper *) override; virtual void helperDone(QDialog::DialogCode, QPlatformDialogHelper *) override; - Q_DISABLE_COPY(QFileDialogPrivate) + void itemNotFound(const QString &fileName, QFileDialog::FileMode mode); + bool itemAlreadyExists(const QString &fileName); + Q_DISABLE_COPY_MOVE(QFileDialogPrivate) }; class QFileDialogLineEdit : public QLineEdit { public: - QFileDialogLineEdit(QWidget *parent = 0) : QLineEdit(parent), d_ptr(0){} + QFileDialogLineEdit(QWidget *parent = nullptr) : QLineEdit(parent), d_ptr(nullptr){} void setFileDialogPrivate(QFileDialogPrivate *d_pointer) {d_ptr = d_pointer; } void keyPressEvent(QKeyEvent *e) override; bool hideOnEsc; @@ -307,7 +277,8 @@ private: class QFileDialogComboBox : public QComboBox { public: - QFileDialogComboBox(QWidget *parent = 0) : QComboBox(parent), urlModel(0) {} + QFileDialogComboBox(QWidget *parent = nullptr) : + QComboBox(parent), urlModel(nullptr), d_ptr(nullptr) {} void setFileDialogPrivate(QFileDialogPrivate *d_pointer); void showPopup() override; void setHistory(const QStringList &paths); @@ -323,7 +294,7 @@ private: class QFileDialogListView : public QListView { public: - QFileDialogListView(QWidget *parent = 0); + QFileDialogListView(QWidget *parent = nullptr) : QListView(parent), d_ptr(nullptr) {} void setFileDialogPrivate(QFileDialogPrivate *d_pointer); QSize sizeHint() const override; protected: @@ -335,7 +306,7 @@ private: class QFileDialogTreeView : public QTreeView { public: - QFileDialogTreeView(QWidget *parent); + QFileDialogTreeView(QWidget *parent) : QTreeView(parent), d_ptr(nullptr) {} void setFileDialogPrivate(QFileDialogPrivate *d_pointer); QSize sizeHint() const override; |