diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-05-23 17:33:01 +0200 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2020-05-23 17:33:01 +0200 |
| commit | 064ef4cfeb7307cae1cfbc640ca3c47e8032f365 (patch) | |
| tree | 2969f197f0d8c9ecbdb8ba7f4becdbabe32d7e0c /src | |
| parent | ee995b8df5a1b9c708a069e62f0e786ff359e76b (diff) | |
Update IFileTree implementations following uibase changes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/archivefiletree.cpp | 29 | ||||
| -rw-r--r-- | src/qdirfiletree.cpp | 19 | ||||
| -rw-r--r-- | src/qdirfiletree.h | 7 |
3 files changed, 23 insertions, 32 deletions
diff --git a/src/archivefiletree.cpp b/src/archivefiletree.cpp index 0b715f4f..6ba06924 100644 --- a/src/archivefiletree.cpp +++ b/src/archivefiletree.cpp @@ -33,23 +33,11 @@ class ArchiveFileEntry : public virtual FileTreeEntry { public: /** - * @brief Create a new entry corresponding to a file. + * @brief Create a new entry. * - * @param parent The tree containing this file. - * @param name The name of this file. - * @param index The index of the file in the archive. - * @param time The modification time of this file. - */ - ArchiveFileEntry(std::shared_ptr<const IFileTree> parent, QString name, int index, QDateTime time) : - FileTreeEntry(parent, name, time), m_Index(index) { - } - - /** - * @brief Create a new entry corresponding to a directory. - * - * @param parent The tree containing this directory. - * @param name The name of this directory. - * @param index The index of the directory in the archive, or -1. + * @param parent The tree containing this entry. + * @param name The name of this entry. + * @param index The index of the entry in the archive. */ ArchiveFileEntry(std::shared_ptr<const IFileTree> parent, QString name, int index) : FileTreeEntry(parent, name), m_Index(index) { @@ -98,7 +86,7 @@ public: // Overrides: /** * @override */ - std::shared_ptr<FileTreeEntry> addFile(QString path, QDateTime time = QDateTime()) override { + std::shared_ptr<FileTreeEntry> addFile(QString path) override { // Cannot add file to an archive. throw UnsupportedOperationException(QObject::tr("Cannot create file within an archive.")); } @@ -159,7 +147,7 @@ protected: return std::make_shared<ArchiveFileTreeImpl>(parent, name, -1, std::vector<File>{}); } - virtual void doPopulate(std::shared_ptr<const IFileTree> parent, std::vector<std::shared_ptr<FileTreeEntry>>& entries) const override { + virtual bool doPopulate(std::shared_ptr<const IFileTree> parent, std::vector<std::shared_ptr<FileTreeEntry>>& entries) const override { // Sort by name: std::sort(std::begin(m_Files), std::end(m_Files), @@ -200,7 +188,7 @@ protected: // If it is not a directory, then it is a file in directly under this tree: if (!std::get<1>(p)) { entries.push_back( - std::make_shared<ArchiveFileEntry>(parent, currentName, std::get<2>(p), QDateTime())); + std::make_shared<ArchiveFileEntry>(parent, currentName, std::get<2>(p))); currentName = ""; } else { @@ -219,6 +207,9 @@ protected: if (currentName != "") { entries.push_back(std::make_shared<ArchiveFileTreeImpl>(parent, currentName, currentIndex, std::move(currentFiles))); } + + // Let the parent class sort the entries: + return false; } virtual std::shared_ptr<IFileTree> doClone() const override { diff --git a/src/qdirfiletree.cpp b/src/qdirfiletree.cpp index 5570060a..e80c7127 100644 --- a/src/qdirfiletree.cpp +++ b/src/qdirfiletree.cpp @@ -14,9 +14,7 @@ std::shared_ptr<const QDirFileTree> QDirFileTree::makeTree(QDir directory) { /** * */ -QDirFileTree::QDirFileTree(std::shared_ptr<const IFileTree> parent, QDir directory) : FileTreeEntry(parent, directory.dirName()), IFileTree(), qDir(directory) { - qDir.setFilter(qDir.filter() | QDir::NoDotAndDotDot); -} +QDirFileTree::QDirFileTree(std::shared_ptr<const IFileTree> parent, QDir directory) : FileTreeEntry(parent, directory.dirName()), IFileTree(), qDir(directory) { } /** * No mutable operations allowed. @@ -24,21 +22,22 @@ QDirFileTree::QDirFileTree(std::shared_ptr<const IFileTree> parent, QDir directo bool QDirFileTree::beforeReplace(IFileTree const* dstTree, FileTreeEntry const* destination, FileTreeEntry const* source) { return false; } bool QDirFileTree::beforeInsert(IFileTree const* entry, FileTreeEntry const* name) { return false; } bool QDirFileTree::beforeRemove(IFileTree const* entry, FileTreeEntry const* name) { return false; } -std::shared_ptr<FileTreeEntry> QDirFileTree::makeFile(std::shared_ptr<const IFileTree> parent, QString name, QDateTime time) const { return nullptr; } +std::shared_ptr<FileTreeEntry> QDirFileTree::makeFile(std::shared_ptr<const IFileTree> parent, QString name) const { return nullptr; } std::shared_ptr<IFileTree> QDirFileTree::makeDirectory(std::shared_ptr<const IFileTree> parent, QString name) const { return nullptr; } -void QDirFileTree::doPopulate(std::shared_ptr<const IFileTree> parent, std::vector<std::shared_ptr<FileTreeEntry>>& entries) const { - QDirIterator iter(qDir); - while (iter.hasNext()) { - QString name = iter.next(); - QFileInfo info = iter.fileInfo(); +bool QDirFileTree::doPopulate(std::shared_ptr<const IFileTree> parent, std::vector<std::shared_ptr<FileTreeEntry>>& entries) const { + auto infoList = qDir.entryInfoList(qDir.filter() | QDir::NoDotAndDotDot, QDir::Name | QDir::DirsFirst | QDir::IgnoreCase); + for (auto& info : infoList) { if (info.isDir()) { entries.push_back(std::shared_ptr<QDirFileTree>(new QDirFileTree(parent, QDir(info.absoluteFilePath())))); } else { - entries.push_back(createFileEntry(parent, info.fileName(), info.fileTime(QFileDevice::FileModificationTime))); + entries.push_back(createFileEntry(parent, info.fileName())); } } + + // Vector is already sorted: + return true; } std::shared_ptr<IFileTree> QDirFileTree::doClone() const { diff --git a/src/qdirfiletree.h b/src/qdirfiletree.h index 000ef69a..e6b8706e 100644 --- a/src/qdirfiletree.h +++ b/src/qdirfiletree.h @@ -43,17 +43,18 @@ public: */ static std::shared_ptr<const QDirFileTree> makeTree(QDir directory); + QDirFileTree(std::shared_ptr<const IFileTree> parent, QDir directory); + protected: - QDirFileTree(std::shared_ptr<const IFileTree> parent, QDir directory); virtual bool beforeReplace(IFileTree const* dstTree, FileTreeEntry const* destination, FileTreeEntry const* source) override; virtual bool beforeInsert(IFileTree const* entry, FileTreeEntry const* name) override; virtual bool beforeRemove(IFileTree const* entry, FileTreeEntry const* name) override; - virtual std::shared_ptr<FileTreeEntry> makeFile(std::shared_ptr<const IFileTree> parent, QString name, QDateTime time) const override; + virtual std::shared_ptr<FileTreeEntry> makeFile(std::shared_ptr<const IFileTree> parent, QString name) const override; virtual std::shared_ptr<IFileTree> makeDirectory(std::shared_ptr<const IFileTree> parent, QString name) const override; - virtual void doPopulate(std::shared_ptr<const IFileTree> parent, std::vector<std::shared_ptr<FileTreeEntry>>& entries) const override; + virtual bool doPopulate(std::shared_ptr<const IFileTree> parent, std::vector<std::shared_ptr<FileTreeEntry>>& entries) const override; virtual std::shared_ptr<IFileTree> doClone() const override; QDir qDir; |
