Update IFileTree implementations following uibase changes.

This commit is contained in:
Mikaël Capelle
2020-05-23 17:33:01 +02:00
parent ee995b8df5
commit 064ef4cfeb
3 changed files with 23 additions and 32 deletions
+10 -19
View File
@@ -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 {
+9 -10
View File
@@ -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 {
+4 -3
View File
@@ -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;