diff --git a/rwviewer/ArchiveContentsWidget.cpp b/rwviewer/ArchiveContentsWidget.cpp index a86caf9c..f8c08b01 100644 --- a/rwviewer/ArchiveContentsWidget.cpp +++ b/rwviewer/ArchiveContentsWidget.cpp @@ -1,26 +1,48 @@ #include "ArchiveContentsWidget.hpp" +#include 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)); +} diff --git a/rwviewer/ArchiveContentsWidget.hpp b/rwviewer/ArchiveContentsWidget.hpp index 13fdf551..78faacce 100644 --- a/rwviewer/ArchiveContentsWidget.hpp +++ b/rwviewer/ArchiveContentsWidget.hpp @@ -3,14 +3,18 @@ #define _ARCHIVECONTENTSWIDGET_HPP_ #include #include +#include +#include #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 \ No newline at end of file +#endif