1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-12 22:02:49 +01:00
openrw/rwviewer/ItemListWidget.cpp

46 lines
1.5 KiB
C++
Raw Normal View History

2014-06-08 02:58:49 +02:00
#include "ItemListWidget.hpp"
#include <QHeaderView>
2016-09-09 22:13:21 +02:00
#include <QVBoxLayout>
2014-02-10 16:34:09 +01:00
2014-06-08 02:58:49 +02:00
ItemListWidget::ItemListWidget(QWidget* parent, Qt::WindowFlags flags)
2016-09-09 22:13:21 +02:00
: QDockWidget(parent, flags), filter(nullptr), model(nullptr) {
setWindowTitle("Items");
QVBoxLayout* layout = new QVBoxLayout();
QWidget* intermediate = new QWidget();
2016-09-09 22:13:21 +02:00
searchbox = new QLineEdit();
searchbox->setPlaceholderText("Search");
2016-09-09 22:13:21 +02:00
table = new QTableView();
layout->addWidget(searchbox);
layout->addWidget(table);
table->setSelectionBehavior(QAbstractItemView::SelectRows);
intermediate->setLayout(layout);
setWidget(intermediate);
2016-09-09 22:13:21 +02:00
filter = new QSortFilterProxyModel;
table->setModel(filter);
filter->setFilterKeyColumn(-1); // Search all columns
connect(table->selectionModel(),
SIGNAL(currentChanged(QModelIndex, QModelIndex)),
SLOT(selectedIndexChanged(QModelIndex)));
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString)));
2014-02-10 16:34:09 +01:00
}
2016-09-09 22:13:21 +02:00
void ItemListWidget::worldLoaded(GameWorld* world) {
if (model) delete model;
model = new ItemListModel(world, this);
filter->setSourceModel(model);
2014-02-10 18:22:07 +01:00
}
2016-09-09 22:13:21 +02:00
void ItemListWidget::selectedIndexChanged(const QModelIndex& current) {
auto mts = filter->mapToSource(current);
if (mts.isValid()) {
emit selectedItemChanged(model->getIDOf(mts.row()));
}
2014-02-10 16:34:09 +01:00
}
2016-09-09 22:13:21 +02:00
void ItemListWidget::setFilter(const QString& f) {
filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
}