File indexing completed on 2024-05-19 04:56:03
0001 /** 0002 * \file filesystemmodel.h 0003 * \cond 0004 * Taken from Qt Git, revision e73bd4a 0005 * qtbase/src/widgets/dialogs/qfilesystemmodel.h 0006 * Adapted for Kid3 with the following changes: 0007 * - Remove Q prefix from class names 0008 * - Remove QT_..._CONFIG, QT_..._NAMESPACE, Q_..._EXPORT... 0009 * - Allow compilation without Qt private headers (USE_QT_PRIVATE_HEADERS) 0010 * - Replace include guards by #pragma once 0011 * - Remove dependencies to Qt5::Widgets 0012 */ 0013 /**************************************************************************** 0014 ** 0015 ** Copyright (C) 2016 The Qt Company Ltd. 0016 ** Contact: https://www.qt.io/licensing/ 0017 ** 0018 ** This file is part of the QtWidgets module of the Qt Toolkit. 0019 ** 0020 ** $QT_BEGIN_LICENSE:LGPL$ 0021 ** Commercial License Usage 0022 ** Licensees holding valid commercial Qt licenses may use this file in 0023 ** accordance with the commercial license agreement provided with the 0024 ** Software or, alternatively, in accordance with the terms contained in 0025 ** a written agreement between you and The Qt Company. For licensing terms 0026 ** and conditions see https://www.qt.io/terms-conditions. For further 0027 ** information use the contact form at https://www.qt.io/contact-us. 0028 ** 0029 ** GNU Lesser General Public License Usage 0030 ** Alternatively, this file may be used under the terms of the GNU Lesser 0031 ** General Public License version 3 as published by the Free Software 0032 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 0033 ** packaging of this file. Please review the following information to 0034 ** ensure the GNU Lesser General Public License version 3 requirements 0035 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 0036 ** 0037 ** GNU General Public License Usage 0038 ** Alternatively, this file may be used under the terms of the GNU 0039 ** General Public License version 2.0 or (at your option) the GNU General 0040 ** Public license version 3 or any later version approved by the KDE Free 0041 ** Qt Foundation. The licenses are as published by the Free Software 0042 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 0043 ** included in the packaging of this file. Please review the following 0044 ** information to ensure the GNU General Public License requirements will 0045 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 0046 ** https://www.gnu.org/licenses/gpl-3.0.html. 0047 ** 0048 ** $QT_END_LICENSE$ 0049 ** 0050 ****************************************************************************/ 0051 0052 #pragma once 0053 0054 #include <QtCore/qabstractitemmodel.h> 0055 #include <QtCore/qpair.h> 0056 #include <QtCore/qdir.h> 0057 #include <QtCore/qdiriterator.h> 0058 #include "kid3api.h" 0059 0060 class ExtendedInformation; 0061 class FileSystemModelPrivate; 0062 class AbstractFileDecorationProvider; 0063 0064 class KID3_CORE_EXPORT FileSystemModel : public QAbstractItemModel 0065 { 0066 Q_OBJECT 0067 Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks) 0068 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) 0069 Q_PROPERTY(bool nameFilterDisables READ nameFilterDisables WRITE setNameFilterDisables) 0070 0071 Q_SIGNALS: 0072 void rootPathChanged(const QString &newPath); 0073 void fileRenamed(const QString &path, const QString &oldName, const QString &newName); 0074 void directoryLoaded(const QString &path); 0075 void fileRenameFailed(const QString &path, const QString &oldName, const QString &newName); 0076 0077 public: 0078 enum Roles { 0079 FileIconRole = Qt::DecorationRole, 0080 FilePathRole = Qt::UserRole + 1, 0081 FileNameRole = Qt::UserRole + 2, 0082 FilePermissions = Qt::UserRole + 3 0083 }; 0084 0085 explicit FileSystemModel(QObject *parent = Q_NULLPTR); 0086 ~FileSystemModel(); 0087 0088 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; 0089 QModelIndex index(const QString &path, int column = 0) const; 0090 QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE; 0091 using QObject::parent; 0092 QModelIndex sibling(int row, int column, const QModelIndex &idx) const Q_DECL_OVERRIDE; 0093 bool hasChildren(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; 0094 bool canFetchMore(const QModelIndex &parent) const Q_DECL_OVERRIDE; 0095 void fetchMore(const QModelIndex &parent) Q_DECL_OVERRIDE; 0096 0097 int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; 0098 int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; 0099 0100 QVariant myComputer(int role = Qt::DisplayRole) const; 0101 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; 0102 bool setData(const QModelIndex &idx, const QVariant &value, int role = Qt::EditRole) Q_DECL_OVERRIDE; 0103 0104 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; 0105 0106 Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; 0107 0108 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) Q_DECL_OVERRIDE; 0109 0110 QStringList mimeTypes() const Q_DECL_OVERRIDE; 0111 QMimeData *mimeData(const QModelIndexList &indexes) const Q_DECL_OVERRIDE; 0112 bool dropMimeData(const QMimeData *data, Qt::DropAction action, 0113 int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE; 0114 Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE; 0115 0116 #ifndef USE_QT_PRIVATE_HEADERS 0117 QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE; 0118 #endif 0119 0120 // QFileSystemModel specific API 0121 void clear(); 0122 QModelIndex setRootPath(const QString &newPath); 0123 QString rootPath() const; 0124 QDir rootDirectory() const; 0125 0126 void setDecorationProvider(AbstractFileDecorationProvider *provider); 0127 AbstractFileDecorationProvider *decorationProvider() const; 0128 0129 void setFilter(QDir::Filters filters); 0130 QDir::Filters filter() const; 0131 0132 void setResolveSymlinks(bool enable); 0133 bool resolveSymlinks() const; 0134 0135 void setReadOnly(bool enable); 0136 bool isReadOnly() const; 0137 0138 void setNameFilterDisables(bool enable); 0139 bool nameFilterDisables() const; 0140 0141 void setNameFilters(const QStringList &filters); 0142 QStringList nameFilters() const; 0143 0144 void setSortIgnoringPunctuation(bool ignore); 0145 bool sortIgnoringPunctuation() const; 0146 0147 QString filePath(const QModelIndex &index) const; 0148 bool isDir(const QModelIndex &index) const; 0149 qint64 size(const QModelIndex &index) const; 0150 QString type(const QModelIndex &index) const; 0151 QDateTime lastModified(const QModelIndex &index) const; 0152 0153 QModelIndex mkdir(const QModelIndex &parent, const QString &name); 0154 bool rmdir(const QModelIndex &aindex); 0155 inline QString fileName(const QModelIndex &index) const; 0156 inline QVariant fileDecoration(const QModelIndex &index) const; 0157 QFile::Permissions permissions(const QModelIndex &index) const; 0158 QFileInfo fileInfo(const QModelIndex &index) const; 0159 bool remove(const QModelIndex &aindex); 0160 0161 #if QT_VERSION < 0x050f00 0162 static QString wildcardToRegularExpression(const QString &pattern); 0163 #endif 0164 0165 protected: 0166 FileSystemModel(FileSystemModelPrivate &, QObject *parent = Q_NULLPTR); 0167 void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE; 0168 bool event(QEvent *event) Q_DECL_OVERRIDE; 0169 0170 private: 0171 Q_DECLARE_PRIVATE(FileSystemModel) 0172 Q_DISABLE_COPY(FileSystemModel) 0173 0174 Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &directory, const QStringList &list)) 0175 Q_PRIVATE_SLOT(d_func(), void _q_performDelayedSort()) 0176 Q_PRIVATE_SLOT(d_func(), void _q_fileSystemChanged(const QString &path, const QVector<QPair<QString, QFileInfo> > &)) 0177 Q_PRIVATE_SLOT(d_func(), void _q_resolvedName(const QString &fileName, const QString &resolvedName)) 0178 0179 friend class QFileDialogPrivate; 0180 #ifndef USE_QT_PRIVATE_HEADERS 0181 QScopedPointer<FileSystemModelPrivate> d_ptr; 0182 #endif 0183 }; 0184 0185 inline QString FileSystemModel::fileName(const QModelIndex &aindex) const 0186 { return aindex.data(Qt::DisplayRole).toString(); } 0187 inline QVariant FileSystemModel::fileDecoration(const QModelIndex &aindex) const 0188 { return aindex.data(Qt::DecorationRole); } 0189 0190 // Kid3, needed by moc generated moc_filesystemmodel.cpp. 0191 #include "filesystemmodel_p.h" 0192 /** \endcond */