forked from teamnwah/openmw-tes3coop
automatically build column map on filter change
This commit is contained in:
parent
ea8b9ce45b
commit
c7e97a83e1
2 changed files with 24 additions and 3 deletions
|
@ -1,11 +1,26 @@
|
|||
|
||||
#include "idtableproxymodel.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "idtable.hpp"
|
||||
|
||||
void CSMWorld::IdTableProxyModel::updateColumnMap()
|
||||
{
|
||||
mColumnMap.clear();
|
||||
|
||||
if (mFilter)
|
||||
{
|
||||
std::vector<int> columns = mFilter->getReferencedColumns();
|
||||
|
||||
const IdTable& table = dynamic_cast<const IdTable&> (*sourceModel());
|
||||
|
||||
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))));
|
||||
}
|
||||
}
|
||||
|
||||
bool CSMWorld::IdTableProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex& sourceParent)
|
||||
const
|
||||
{
|
||||
|
@ -13,9 +28,9 @@ bool CSMWorld::IdTableProxyModel::filterAcceptsRow (int sourceRow, const QModelI
|
|||
return true;
|
||||
|
||||
std::map<std::string, const CSMFilter::Node *> otherFilters; /// \todo get other filters;
|
||||
std::map<int, int> columns; /// \todo get columns
|
||||
|
||||
return mFilter->test (dynamic_cast<IdTable&> (*sourceModel()), sourceRow, otherFilters, columns, mUserValue);
|
||||
return mFilter->test (
|
||||
dynamic_cast<IdTable&> (*sourceModel()), sourceRow, otherFilters, mColumnMap, mUserValue);
|
||||
}
|
||||
|
||||
CSMWorld::IdTableProxyModel::IdTableProxyModel (QObject *parent)
|
||||
|
@ -32,5 +47,6 @@ void CSMWorld::IdTableProxyModel::setFilter (const boost::shared_ptr<CSMFilter::
|
|||
{
|
||||
mFilter = filter;
|
||||
mUserValue = userValue;
|
||||
updateColumnMap();
|
||||
invalidateFilter();
|
||||
}
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "../filter/node.hpp"
|
||||
|
@ -17,9 +19,12 @@ namespace CSMWorld
|
|||
|
||||
boost::shared_ptr<CSMFilter::Node> mFilter;
|
||||
std::string mUserValue;
|
||||
std::map<int, int> mColumnMap; // column ID, column index in this model (or -1)
|
||||
|
||||
private:
|
||||
|
||||
void updateColumnMap();
|
||||
|
||||
bool filterAcceptsRow (int sourceRow, const QModelIndex& sourceParent) const;
|
||||
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue