some renames

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97
2025-01-14 18:48:20 +02:00
parent 0b6ce5525d
commit 2292df16cc
4 changed files with 44 additions and 45 deletions

View File

@ -40,12 +40,11 @@
#include <QFileSystemModel> #include <QFileSystemModel>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QStack> #include <QStack>
#include <algorithm>
#include "FileSystem.h" #include "FileSystem.h"
#include "SeparatorPrefixTree.h" #include "SeparatorPrefixTree.h"
#include "StringUtils.h" #include "StringUtils.h"
FileIgnoreProxy::FileIgnoreProxy(QString root, QObject* parent) : QSortFilterProxyModel(parent), root(root) {} FileIgnoreProxy::FileIgnoreProxy(QString root, QObject* parent) : QSortFilterProxyModel(parent), m_root(root) {}
// NOTE: Sadly, we have to do sorting ourselves. // NOTE: Sadly, we have to do sorting ourselves.
bool FileIgnoreProxy::lessThan(const QModelIndex& left, const QModelIndex& right) const bool FileIgnoreProxy::lessThan(const QModelIndex& left, const QModelIndex& right) const
{ {
@ -104,10 +103,10 @@ QVariant FileIgnoreProxy::data(const QModelIndex& index, int role) const
if (index.column() == 0 && role == Qt::CheckStateRole) { if (index.column() == 0 && role == Qt::CheckStateRole) {
QFileSystemModel* fsm = qobject_cast<QFileSystemModel*>(sourceModel()); QFileSystemModel* fsm = qobject_cast<QFileSystemModel*>(sourceModel());
auto blockedPath = relPath(fsm->filePath(sourceIndex)); auto blockedPath = relPath(fsm->filePath(sourceIndex));
auto cover = blocked.cover(blockedPath); auto cover = m_blocked.cover(blockedPath);
if (!cover.isNull()) { if (!cover.isNull()) {
return QVariant(Qt::Unchecked); return QVariant(Qt::Unchecked);
} else if (blocked.exists(blockedPath)) { } else if (m_blocked.exists(blockedPath)) {
return QVariant(Qt::PartiallyChecked); return QVariant(Qt::PartiallyChecked);
} else { } else {
return QVariant(Qt::Checked); return QVariant(Qt::Checked);
@ -130,7 +129,7 @@ bool FileIgnoreProxy::setData(const QModelIndex& index, const QVariant& value, i
QString FileIgnoreProxy::relPath(const QString& path) const QString FileIgnoreProxy::relPath(const QString& path) const
{ {
return QDir(root).relativeFilePath(path); return QDir(m_root).relativeFilePath(path);
} }
bool FileIgnoreProxy::setFilterState(QModelIndex index, Qt::CheckState state) bool FileIgnoreProxy::setFilterState(QModelIndex index, Qt::CheckState state)
@ -146,18 +145,18 @@ bool FileIgnoreProxy::setFilterState(QModelIndex index, Qt::CheckState state)
bool changed = false; bool changed = false;
if (state == Qt::Unchecked) { if (state == Qt::Unchecked) {
// blocking a path // blocking a path
auto& node = blocked.insert(blockedPath); auto& node = m_blocked.insert(blockedPath);
// get rid of all blocked nodes below // get rid of all blocked nodes below
node.clear(); node.clear();
changed = true; changed = true;
} else if (state == Qt::Checked || state == Qt::PartiallyChecked) { } else if (state == Qt::Checked || state == Qt::PartiallyChecked) {
if (!blocked.remove(blockedPath)) { if (!m_blocked.remove(blockedPath)) {
auto cover = blocked.cover(blockedPath); auto cover = m_blocked.cover(blockedPath);
qDebug() << "Blocked by cover" << cover; qDebug() << "Blocked by cover" << cover;
// uncover // uncover
blocked.remove(cover); m_blocked.remove(cover);
// block all contents, except for any cover // block all contents, except for any cover
QModelIndex rootIndex = fsm->index(FS::PathCombine(root, cover)); QModelIndex rootIndex = fsm->index(FS::PathCombine(m_root, cover));
QModelIndex doing = rootIndex; QModelIndex doing = rootIndex;
int row = 0; int row = 0;
QStack<QModelIndex> todo; QStack<QModelIndex> todo;
@ -179,7 +178,7 @@ bool FileIgnoreProxy::setFilterState(QModelIndex index, Qt::CheckState state)
todo.push(node); todo.push(node);
} else { } else {
// or just block this one. // or just block this one.
blocked.insert(relpath); m_blocked.insert(relpath);
} }
row++; row++;
} }
@ -229,7 +228,7 @@ bool FileIgnoreProxy::shouldExpand(QModelIndex index)
return false; return false;
} }
auto blockedPath = relPath(fsm->filePath(sourceIndex)); auto blockedPath = relPath(fsm->filePath(sourceIndex));
auto found = blocked.find(blockedPath); auto found = m_blocked.find(blockedPath);
if (found) { if (found) {
return !found->leaf(); return !found->leaf();
} }
@ -239,8 +238,8 @@ bool FileIgnoreProxy::shouldExpand(QModelIndex index)
void FileIgnoreProxy::setBlockedPaths(QStringList paths) void FileIgnoreProxy::setBlockedPaths(QStringList paths)
{ {
beginResetModel(); beginResetModel();
blocked.clear(); m_blocked.clear();
blocked.insert(paths); m_blocked.insert(paths);
endResetModel(); endResetModel();
} }
@ -272,5 +271,5 @@ bool FileIgnoreProxy::ignoreFile(QFileInfo fileInfo) const
bool FileIgnoreProxy::filterFile(const QString& fileName) const bool FileIgnoreProxy::filterFile(const QString& fileName) const
{ {
return blocked.covers(fileName) || ignoreFile(QFileInfo(QDir(root), fileName)); return m_blocked.covers(fileName) || ignoreFile(QFileInfo(QDir(m_root), fileName));
} }

View File

@ -61,8 +61,8 @@ class FileIgnoreProxy : public QSortFilterProxyModel {
void setBlockedPaths(QStringList paths); void setBlockedPaths(QStringList paths);
inline const SeparatorPrefixTree<'/'>& blockedPaths() const { return blocked; } inline const SeparatorPrefixTree<'/'>& blockedPaths() const { return m_blocked; }
inline SeparatorPrefixTree<'/'>& blockedPaths() { return blocked; } inline SeparatorPrefixTree<'/'>& blockedPaths() { return m_blocked; }
// list of file names that need to be removed completely from model // list of file names that need to be removed completely from model
inline QStringList& ignoreFilesWithName() { return m_ignoreFiles; } inline QStringList& ignoreFilesWithName() { return m_ignoreFiles; }
@ -78,8 +78,8 @@ class FileIgnoreProxy : public QSortFilterProxyModel {
bool ignoreFile(QFileInfo file) const; bool ignoreFile(QFileInfo file) const;
private: private:
const QString root; const QString m_root;
SeparatorPrefixTree<'/'> blocked; SeparatorPrefixTree<'/'> m_blocked;
QStringList m_ignoreFiles; QStringList m_ignoreFiles;
SeparatorPrefixTree<'/'> m_ignoreFilePaths; SeparatorPrefixTree<'/'> m_ignoreFilePaths;
}; };

View File

@ -60,40 +60,40 @@
#include "SeparatorPrefixTree.h" #include "SeparatorPrefixTree.h"
ExportInstanceDialog::ExportInstanceDialog(InstancePtr instance, QWidget* parent) ExportInstanceDialog::ExportInstanceDialog(InstancePtr instance, QWidget* parent)
: QDialog(parent), ui(new Ui::ExportInstanceDialog), m_instance(instance) : QDialog(parent), m_ui(new Ui::ExportInstanceDialog), m_instance(instance)
{ {
ui->setupUi(this); m_ui->setupUi(this);
auto model = new QFileSystemModel(this); auto model = new QFileSystemModel(this);
model->setIconProvider(&icons); model->setIconProvider(&m_icons);
auto root = instance->instanceRoot(); auto root = instance->instanceRoot();
proxyModel = new FileIgnoreProxy(root, this); m_proxyModel = new FileIgnoreProxy(root, this);
proxyModel->setSourceModel(model); m_proxyModel->setSourceModel(model);
auto prefix = QDir(instance->instanceRoot()).relativeFilePath(instance->gameRoot()); auto prefix = QDir(instance->instanceRoot()).relativeFilePath(instance->gameRoot());
proxyModel->ignoreFilesWithPath().insert({ FS::PathCombine(prefix, "logs"), FS::PathCombine(prefix, "crash-reports") }); m_proxyModel->ignoreFilesWithPath().insert({ FS::PathCombine(prefix, "logs"), FS::PathCombine(prefix, "crash-reports") });
proxyModel->ignoreFilesWithName().append({ ".DS_Store", "thumbs.db", "Thumbs.db" }); m_proxyModel->ignoreFilesWithName().append({ ".DS_Store", "thumbs.db", "Thumbs.db" });
proxyModel->ignoreFilesWithPath().insert( m_proxyModel->ignoreFilesWithPath().insert(
{ FS::PathCombine(prefix, ".cache"), FS::PathCombine(prefix, ".fabric"), FS::PathCombine(prefix, ".quilt") }); { FS::PathCombine(prefix, ".cache"), FS::PathCombine(prefix, ".fabric"), FS::PathCombine(prefix, ".quilt") });
loadPackIgnore(); loadPackIgnore();
ui->treeView->setModel(proxyModel); m_ui->treeView->setModel(m_proxyModel);
ui->treeView->setRootIndex(proxyModel->mapFromSource(model->index(root))); m_ui->treeView->setRootIndex(m_proxyModel->mapFromSource(model->index(root)));
ui->treeView->sortByColumn(0, Qt::AscendingOrder); m_ui->treeView->sortByColumn(0, Qt::AscendingOrder);
connect(proxyModel, SIGNAL(rowsInserted(QModelIndex, int, int)), SLOT(rowsInserted(QModelIndex, int, int))); connect(m_proxyModel, SIGNAL(rowsInserted(QModelIndex, int, int)), SLOT(rowsInserted(QModelIndex, int, int)));
model->setFilter(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Hidden); model->setFilter(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs | QDir::Hidden);
model->setRootPath(root); model->setRootPath(root);
auto headerView = ui->treeView->header(); auto headerView = m_ui->treeView->header();
headerView->setSectionResizeMode(QHeaderView::ResizeToContents); headerView->setSectionResizeMode(QHeaderView::ResizeToContents);
headerView->setSectionResizeMode(0, QHeaderView::Stretch); headerView->setSectionResizeMode(0, QHeaderView::Stretch);
ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel")); m_ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("OK")); m_ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("OK"));
} }
ExportInstanceDialog::~ExportInstanceDialog() ExportInstanceDialog::~ExportInstanceDialog()
{ {
delete ui; delete m_ui;
} }
/// Save icon to instance's folder is needed /// Save icon to instance's folder is needed
@ -144,7 +144,7 @@ void ExportInstanceDialog::doExport()
auto files = QFileInfoList(); auto files = QFileInfoList();
if (!MMCZip::collectFileListRecursively(m_instance->instanceRoot(), nullptr, &files, if (!MMCZip::collectFileListRecursively(m_instance->instanceRoot(), nullptr, &files,
std::bind(&FileIgnoreProxy::filterFile, proxyModel, std::placeholders::_1))) { std::bind(&FileIgnoreProxy::filterFile, m_proxyModel, std::placeholders::_1))) {
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance")); QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
QDialog::done(QDialog::Rejected); QDialog::done(QDialog::Rejected);
return; return;
@ -176,13 +176,13 @@ void ExportInstanceDialog::rowsInserted(QModelIndex parent, int top, int bottom)
{ {
// WARNING: possible off-by-one? // WARNING: possible off-by-one?
for (int i = top; i < bottom; i++) { for (int i = top; i < bottom; i++) {
auto node = proxyModel->index(i, 0, parent); auto node = m_proxyModel->index(i, 0, parent);
if (proxyModel->shouldExpand(node)) { if (m_proxyModel->shouldExpand(node)) {
auto expNode = node.parent(); auto expNode = node.parent();
if (!expNode.isValid()) { if (!expNode.isValid()) {
continue; continue;
} }
ui->treeView->expand(node); m_ui->treeView->expand(node);
} }
} }
} }
@ -202,15 +202,15 @@ void ExportInstanceDialog::loadPackIgnore()
auto ignoreData = ignoreFile.readAll(); auto ignoreData = ignoreFile.readAll();
auto string = QString::fromUtf8(ignoreData); auto string = QString::fromUtf8(ignoreData);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
proxyModel->setBlockedPaths(string.split('\n', Qt::SkipEmptyParts)); m_proxyModel->setBlockedPaths(string.split('\n', Qt::SkipEmptyParts));
#else #else
proxyModel->setBlockedPaths(string.split('\n', QString::SkipEmptyParts)); m_proxyModel->setBlockedPaths(string.split('\n', QString::SkipEmptyParts));
#endif #endif
} }
void ExportInstanceDialog::savePackIgnore() void ExportInstanceDialog::savePackIgnore()
{ {
auto ignoreData = proxyModel->blockedPaths().toStringList().join('\n').toUtf8(); auto ignoreData = m_proxyModel->blockedPaths().toStringList().join('\n').toUtf8();
auto filename = ignoreFileName(); auto filename = ignoreFileName();
try { try {
FS::write(filename, ignoreData); FS::write(filename, ignoreData);

View File

@ -65,10 +65,10 @@ class ExportInstanceDialog : public QDialog {
QString ignoreFileName(); QString ignoreFileName();
private: private:
Ui::ExportInstanceDialog* ui; Ui::ExportInstanceDialog* m_ui;
InstancePtr m_instance; InstancePtr m_instance;
FileIgnoreProxy* proxyModel; FileIgnoreProxy* m_proxyModel;
FastFileIconProvider icons; FastFileIconProvider m_icons;
private slots: private slots:
void rowsInserted(QModelIndex parent, int top, int bottom); void rowsInserted(QModelIndex parent, int top, int bottom);