2012-12-03 20:44:16 +00:00
|
|
|
|
|
|
|
#include "idtableproxymodel.hpp"
|
|
|
|
|
2013-08-18 14:53:28 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2014-07-04 11:24:35 +00:00
|
|
|
#include "idtablebase.hpp"
|
2012-12-03 20:44:16 +00:00
|
|
|
|
2013-08-18 15:28:04 +00:00
|
|
|
void CSMWorld::IdTableProxyModel::updateColumnMap()
|
|
|
|
{
|
|
|
|
mColumnMap.clear();
|
|
|
|
|
|
|
|
if (mFilter)
|
|
|
|
{
|
|
|
|
std::vector<int> columns = mFilter->getReferencedColumns();
|
|
|
|
|
2014-07-04 11:24:35 +00:00
|
|
|
const IdTableBase& table = dynamic_cast<const IdTableBase&> (*sourceModel());
|
2013-08-18 15:28:04 +00:00
|
|
|
|
|
|
|
for (std::vector<int>::const_iterator iter (columns.begin()); iter!=columns.end(); ++iter)
|
|
|
|
mColumnMap.insert (std::make_pair (*iter,
|
|
|
|
table.searchColumnIndex (static_cast<CSMWorld::Columns::ColumnId> (*iter))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-18 14:53:28 +00:00
|
|
|
bool CSMWorld::IdTableProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex& sourceParent)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
if (!mFilter)
|
|
|
|
return true;
|
|
|
|
|
2013-08-18 15:28:04 +00:00
|
|
|
return mFilter->test (
|
2014-07-04 11:24:35 +00:00
|
|
|
dynamic_cast<IdTableBase&> (*sourceModel()), sourceRow, mColumnMap);
|
2013-08-18 14:53:28 +00:00
|
|
|
}
|
|
|
|
|
2012-12-03 20:44:16 +00:00
|
|
|
CSMWorld::IdTableProxyModel::IdTableProxyModel (QObject *parent)
|
|
|
|
: QSortFilterProxyModel (parent)
|
2014-02-13 14:01:10 +00:00
|
|
|
{
|
|
|
|
setSortCaseSensitivity (Qt::CaseInsensitive);
|
|
|
|
}
|
2012-12-03 20:44:16 +00:00
|
|
|
|
|
|
|
QModelIndex CSMWorld::IdTableProxyModel::getModelIndex (const std::string& id, int column) const
|
|
|
|
{
|
2014-07-04 11:24:35 +00:00
|
|
|
return mapFromSource (dynamic_cast<IdTableBase&> (*sourceModel()).getModelIndex (id, column));
|
2013-08-18 14:53:28 +00:00
|
|
|
}
|
|
|
|
|
2013-08-22 07:17:57 +00:00
|
|
|
void CSMWorld::IdTableProxyModel::setFilter (const boost::shared_ptr<CSMFilter::Node>& filter)
|
2013-08-18 14:53:28 +00:00
|
|
|
{
|
|
|
|
mFilter = filter;
|
2013-08-18 15:28:04 +00:00
|
|
|
updateColumnMap();
|
2015-05-27 00:27:57 +00:00
|
|
|
reset();
|
2014-10-07 09:11:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CSMWorld::IdTableProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
|
|
|
{
|
2014-10-07 20:59:21 +00:00
|
|
|
return QSortFilterProxyModel::lessThan(left, right);
|
2014-10-07 09:11:44 +00:00
|
|
|
}
|
2015-05-24 23:15:07 +00:00
|
|
|
|
|
|
|
void CSMWorld::IdTableProxyModel::refreshFilter()
|
|
|
|
{
|
|
|
|
updateColumnMap();
|
|
|
|
invalidateFilter();
|
|
|
|
}
|