diff --git a/sagasu/include/filetreemodel.h b/sagasu/include/filetreemodel.h index 65f4afe..0ed6f05 100644 --- a/sagasu/include/filetreemodel.h +++ b/sagasu/include/filetreemodel.h @@ -26,7 +26,7 @@ class FileTreeModel : public QAbstractItemModel Q_OBJECT public: - explicit FileTreeModel(QString gamePath, GameData *data); + explicit FileTreeModel(bool showUnknown, QString gamePath, GameData *data); int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; @@ -48,4 +48,5 @@ private: QHash knownDirHashes; HashDatabase m_database; + bool m_showUnknown = false; }; \ No newline at end of file diff --git a/sagasu/include/filetreewindow.h b/sagasu/include/filetreewindow.h index 43d5429..5df53f5 100644 --- a/sagasu/include/filetreewindow.h +++ b/sagasu/include/filetreewindow.h @@ -3,7 +3,8 @@ #pragma once -#include +#include +#include #include #include "filetreemodel.h" @@ -19,6 +20,11 @@ Q_SIGNALS: void pathSelected(QString path); private: + void refreshModel(); + GameData *data = nullptr; FileTreeModel *m_fileModel; + QSortFilterProxyModel *m_searchModel; + QCheckBox *m_unknownCheckbox; + QString m_gamePath; }; \ No newline at end of file diff --git a/sagasu/src/filetreemodel.cpp b/sagasu/src/filetreemodel.cpp index 9cae4d0..bc489b4 100644 --- a/sagasu/src/filetreemodel.cpp +++ b/sagasu/src/filetreemodel.cpp @@ -6,8 +6,9 @@ #include -FileTreeModel::FileTreeModel(QString gamePath, GameData *data) +FileTreeModel::FileTreeModel(bool showUnknown, QString gamePath, GameData *data) : gameData(data) + , m_showUnknown(showUnknown) , QAbstractItemModel() { rootItem = new TreeInformation(); @@ -176,6 +177,10 @@ void FileTreeModel::addKnownFolder(QString string) void FileTreeModel::addFile(TreeInformation *parentItem, uint32_t name, QString realName) { + if (realName.isEmpty() && !m_showUnknown) { + return; + } + auto fileItem = new TreeInformation(); fileItem->hash = name; fileItem->name = realName; @@ -187,6 +192,10 @@ void FileTreeModel::addFile(TreeInformation *parentItem, uint32_t name, QString void FileTreeModel::addFolder(TreeInformation *parentItem, uint32_t name) { + if (!m_showUnknown) { + return; + } + auto fileItem = new TreeInformation(); fileItem->hash = name; fileItem->type = TreeType::Folder; diff --git a/sagasu/src/filetreewindow.cpp b/sagasu/src/filetreewindow.cpp index ea71f74..de602da 100644 --- a/sagasu/src/filetreewindow.cpp +++ b/sagasu/src/filetreewindow.cpp @@ -4,22 +4,43 @@ #include "filetreewindow.h" #include +#include #include #include FileTreeWindow::FileTreeWindow(QString gamePath, GameData *data, QWidget *parent) : QWidget(parent) + , m_gamePath(gamePath) , data(data) { - setWindowTitle(QStringLiteral("File Tree")); - - auto layout = new QHBoxLayout(); + auto layout = new QVBoxLayout(); + layout->setContentsMargins(0, 0, 0, 0); setLayout(layout); - m_fileModel = new FileTreeModel(gamePath, data); + m_searchModel = new QSortFilterProxyModel(); + m_searchModel->setRecursiveFilteringEnabled(true); + m_searchModel->setFilterCaseSensitivity(Qt::CaseSensitivity::CaseInsensitive); + + auto searchLayout = new QHBoxLayout(); + layout->addLayout(searchLayout); + + auto searchEdit = new QLineEdit(); + searchEdit->setPlaceholderText(QStringLiteral("Search...")); + searchEdit->setClearButtonEnabled(true); + connect(searchEdit, &QLineEdit::textChanged, this, [this](const QString &text) { + m_searchModel->setFilterRegularExpression(text); + }); + searchLayout->addWidget(searchEdit); + + m_unknownCheckbox = new QCheckBox(); + m_unknownCheckbox->setToolTip(QStringLiteral("Show unknown files and folders.")); + connect(m_unknownCheckbox, &QCheckBox::clicked, this, [this] { + refreshModel(); + }); + searchLayout->addWidget(m_unknownCheckbox); auto treeWidget = new QTreeView(); - treeWidget->setModel(m_fileModel); + treeWidget->setModel(m_searchModel); layout->addWidget(treeWidget); treeWidget->setContextMenuPolicy(Qt::CustomContextMenu); @@ -46,6 +67,15 @@ FileTreeWindow::FileTreeWindow(QString gamePath, GameData *data, QWidget *parent Q_EMIT pathSelected(path); } }); + + refreshModel(); +} + +void FileTreeWindow::refreshModel() +{ + // TODO: this should really be handled by the proxy + m_fileModel = new FileTreeModel(m_unknownCheckbox->isChecked(), m_gamePath, data); + m_searchModel->setSourceModel(m_fileModel); } #include "moc_filetreewindow.cpp" \ No newline at end of file