mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 02:12:45 +01:00
Added filename filter to archive window
This commit is contained in:
parent
a6537784b6
commit
687917c2fd
@ -1,26 +1,48 @@
|
||||
#include "ArchiveContentsWidget.hpp"
|
||||
#include <QVBoxLayout>
|
||||
|
||||
ArchiveContentsWidget::ArchiveContentsWidget(QWidget* parent, Qt::WindowFlags flags)
|
||||
: QDockWidget(parent, flags), model(nullptr)
|
||||
: QDockWidget(parent, flags), filter(nullptr), model(nullptr)
|
||||
{
|
||||
setWindowTitle("Archive");
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
QWidget* intermediate = new QWidget();
|
||||
|
||||
searchbox = new QLineEdit();
|
||||
searchbox->setPlaceholderText("Search");
|
||||
|
||||
table = new QListView();
|
||||
setWidget(table);
|
||||
layout->addWidget(searchbox);
|
||||
layout->addWidget(table);
|
||||
intermediate->setLayout(layout);
|
||||
setWidget(intermediate);
|
||||
|
||||
filter = new QSortFilterProxyModel;
|
||||
table->setModel(filter);
|
||||
connect(table->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(selectedIndexChanged(QModelIndex)));
|
||||
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString)));
|
||||
}
|
||||
|
||||
void ArchiveContentsWidget::setArchive(const LoaderIMG& archive)
|
||||
{
|
||||
auto m = table->model();
|
||||
model = new IMGArchiveModel(archive);
|
||||
table->setModel(model);
|
||||
delete m;
|
||||
connect(table->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(selectedIndexChanged(QModelIndex)));
|
||||
auto m = new IMGArchiveModel(archive);
|
||||
filter->setSourceModel(m);
|
||||
if(model) {
|
||||
delete model;
|
||||
}
|
||||
model = m;
|
||||
}
|
||||
|
||||
void ArchiveContentsWidget::selectedIndexChanged(const QModelIndex& current)
|
||||
{
|
||||
if(current.row() < model->getArchive().getAssetCount()) {
|
||||
auto& f = model->getArchive().getAssetInfoByIndex(current.row());
|
||||
auto mts = filter->mapToSource(current);
|
||||
if(mts.row() < model->getArchive().getAssetCount()) {
|
||||
auto& f = model->getArchive().getAssetInfoByIndex(mts.row());
|
||||
emit selectedFileChanged(f.name);
|
||||
}
|
||||
}
|
||||
|
||||
void ArchiveContentsWidget::setFilter(const QString &f)
|
||||
{
|
||||
filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
|
||||
}
|
||||
|
@ -3,14 +3,18 @@
|
||||
#define _ARCHIVECONTENTSWIDGET_HPP_
|
||||
#include <QDockWidget>
|
||||
#include <QListView>
|
||||
#include <QLineEdit>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include "IMGArchiveModel.hpp"
|
||||
|
||||
class ArchiveContentsWidget : public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QSortFilterProxyModel* filter;
|
||||
IMGArchiveModel* model;
|
||||
QListView* table;
|
||||
QLineEdit* searchbox;
|
||||
|
||||
public:
|
||||
ArchiveContentsWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0);
|
||||
@ -22,6 +26,8 @@ signals:
|
||||
|
||||
public slots:
|
||||
void selectedIndexChanged(const QModelIndex& current);
|
||||
|
||||
void setFilter(const QString& f);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user