1
Fork 0
mirror of https://github.com/redstrate/Novus.git synced 2025-04-22 12:07:45 +00:00

sagasu: Hide unknown entries by default, add search bar

This commit is contained in:
Joshua Goins 2023-10-12 20:42:59 -04:00
parent 9cdddae7a6
commit a0e87b914d
4 changed files with 54 additions and 8 deletions

View file

@ -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<uint32_t, TreeInformation *> knownDirHashes;
HashDatabase m_database;
bool m_showUnknown = false;
};

View file

@ -3,7 +3,8 @@
#pragma once
#include <QMdiSubWindow>
#include <QCheckBox>
#include <QSortFilterProxyModel>
#include <physis.hpp>
#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;
};

View file

@ -6,8 +6,9 @@
#include <QtConcurrent>
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;

View file

@ -4,22 +4,43 @@
#include "filetreewindow.h"
#include <QHBoxLayout>
#include <QLineEdit>
#include <QMenu>
#include <QTreeWidget>
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"