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

48 lines
1.4 KiB
C++
Raw Normal View History

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