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:
parent
9cdddae7a6
commit
a0e87b914d
4 changed files with 54 additions and 8 deletions
|
@ -26,7 +26,7 @@ class FileTreeModel : public QAbstractItemModel
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FileTreeModel(QString gamePath, GameData *data);
|
explicit FileTreeModel(bool showUnknown, QString gamePath, GameData *data);
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
@ -48,4 +48,5 @@ private:
|
||||||
QHash<uint32_t, TreeInformation *> knownDirHashes;
|
QHash<uint32_t, TreeInformation *> knownDirHashes;
|
||||||
|
|
||||||
HashDatabase m_database;
|
HashDatabase m_database;
|
||||||
|
bool m_showUnknown = false;
|
||||||
};
|
};
|
|
@ -3,7 +3,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QMdiSubWindow>
|
#include <QCheckBox>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
#include <physis.hpp>
|
#include <physis.hpp>
|
||||||
|
|
||||||
#include "filetreemodel.h"
|
#include "filetreemodel.h"
|
||||||
|
@ -19,6 +20,11 @@ Q_SIGNALS:
|
||||||
void pathSelected(QString path);
|
void pathSelected(QString path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void refreshModel();
|
||||||
|
|
||||||
GameData *data = nullptr;
|
GameData *data = nullptr;
|
||||||
FileTreeModel *m_fileModel;
|
FileTreeModel *m_fileModel;
|
||||||
|
QSortFilterProxyModel *m_searchModel;
|
||||||
|
QCheckBox *m_unknownCheckbox;
|
||||||
|
QString m_gamePath;
|
||||||
};
|
};
|
|
@ -6,8 +6,9 @@
|
||||||
|
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
|
|
||||||
FileTreeModel::FileTreeModel(QString gamePath, GameData *data)
|
FileTreeModel::FileTreeModel(bool showUnknown, QString gamePath, GameData *data)
|
||||||
: gameData(data)
|
: gameData(data)
|
||||||
|
, m_showUnknown(showUnknown)
|
||||||
, QAbstractItemModel()
|
, QAbstractItemModel()
|
||||||
{
|
{
|
||||||
rootItem = new TreeInformation();
|
rootItem = new TreeInformation();
|
||||||
|
@ -176,6 +177,10 @@ void FileTreeModel::addKnownFolder(QString string)
|
||||||
|
|
||||||
void FileTreeModel::addFile(TreeInformation *parentItem, uint32_t name, QString realName)
|
void FileTreeModel::addFile(TreeInformation *parentItem, uint32_t name, QString realName)
|
||||||
{
|
{
|
||||||
|
if (realName.isEmpty() && !m_showUnknown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto fileItem = new TreeInformation();
|
auto fileItem = new TreeInformation();
|
||||||
fileItem->hash = name;
|
fileItem->hash = name;
|
||||||
fileItem->name = realName;
|
fileItem->name = realName;
|
||||||
|
@ -187,6 +192,10 @@ void FileTreeModel::addFile(TreeInformation *parentItem, uint32_t name, QString
|
||||||
|
|
||||||
void FileTreeModel::addFolder(TreeInformation *parentItem, uint32_t name)
|
void FileTreeModel::addFolder(TreeInformation *parentItem, uint32_t name)
|
||||||
{
|
{
|
||||||
|
if (!m_showUnknown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto fileItem = new TreeInformation();
|
auto fileItem = new TreeInformation();
|
||||||
fileItem->hash = name;
|
fileItem->hash = name;
|
||||||
fileItem->type = TreeType::Folder;
|
fileItem->type = TreeType::Folder;
|
||||||
|
|
|
@ -4,22 +4,43 @@
|
||||||
#include "filetreewindow.h"
|
#include "filetreewindow.h"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QTreeWidget>
|
#include <QTreeWidget>
|
||||||
|
|
||||||
FileTreeWindow::FileTreeWindow(QString gamePath, GameData *data, QWidget *parent)
|
FileTreeWindow::FileTreeWindow(QString gamePath, GameData *data, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
, m_gamePath(gamePath)
|
||||||
, data(data)
|
, data(data)
|
||||||
{
|
{
|
||||||
setWindowTitle(QStringLiteral("File Tree"));
|
auto layout = new QVBoxLayout();
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
auto layout = new QHBoxLayout();
|
|
||||||
setLayout(layout);
|
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();
|
auto treeWidget = new QTreeView();
|
||||||
treeWidget->setModel(m_fileModel);
|
treeWidget->setModel(m_searchModel);
|
||||||
layout->addWidget(treeWidget);
|
layout->addWidget(treeWidget);
|
||||||
|
|
||||||
treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
@ -46,6 +67,15 @@ FileTreeWindow::FileTreeWindow(QString gamePath, GameData *data, QWidget *parent
|
||||||
Q_EMIT pathSelected(path);
|
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"
|
#include "moc_filetreewindow.cpp"
|
Loading…
Add table
Reference in a new issue