openrw/rwviewer/ArchiveContentsWidget.cpp

49 lines
1.4 KiB
C++
Raw Normal View History

2014-02-10 15:34:09 +00:00
#include "ArchiveContentsWidget.hpp"
#include <QVBoxLayout>
2014-02-10 15:34:09 +00:00
ArchiveContentsWidget::ArchiveContentsWidget(QWidget* parent, Qt::WindowFlags flags)
: QDockWidget(parent, flags), filter(nullptr), model(nullptr)
2014-02-10 15:34:09 +00:00
{
setWindowTitle("Archive");
QVBoxLayout* layout = new QVBoxLayout();
QWidget* intermediate = new QWidget();
searchbox = new QLineEdit();
searchbox->setPlaceholderText("Search");
2014-02-10 16:21:30 +00:00
table = new QListView();
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)));
2014-02-10 15:34:09 +00:00
}
void ArchiveContentsWidget::setArchive(const LoaderIMG& archive)
{
auto m = new IMGArchiveModel(archive);
filter->setSourceModel(m);
if(model) {
delete model;
}
model = m;
2014-02-10 17:22:07 +00:00
}
void ArchiveContentsWidget::selectedIndexChanged(const QModelIndex& current)
{
auto mts = filter->mapToSource(current);
if(mts.row() < model->getArchive().getAssetCount()) {
auto& f = model->getArchive().getAssetInfoByIndex(mts.row());
2014-02-10 17:22:07 +00:00
emit selectedFileChanged(f.name);
}
2014-02-10 15:34:09 +00:00
}
void ArchiveContentsWidget::setFilter(const QString &f)
{
filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
}