mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-22 21:39:55 +00:00
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 "idtableproxymodel.hpp"
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "idtable.hpp"
|
#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)
|
bool CSMWorld::IdTableProxyModel::filterAcceptsRow (int sourceRow, const QModelIndex& sourceParent)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
|
@ -13,9 +28,9 @@ bool CSMWorld::IdTableProxyModel::filterAcceptsRow (int sourceRow, const QModelI
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
std::map<std::string, const CSMFilter::Node *> otherFilters; /// \todo get other filters;
|
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)
|
CSMWorld::IdTableProxyModel::IdTableProxyModel (QObject *parent)
|
||||||
|
@ -32,5 +47,6 @@ void CSMWorld::IdTableProxyModel::setFilter (const boost::shared_ptr<CSMFilter::
|
||||||
{
|
{
|
||||||
mFilter = filter;
|
mFilter = filter;
|
||||||
mUserValue = userValue;
|
mUserValue = userValue;
|
||||||
|
updateColumnMap();
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
}
|
}
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
#include "../filter/node.hpp"
|
#include "../filter/node.hpp"
|
||||||
|
@ -17,9 +19,12 @@ namespace CSMWorld
|
||||||
|
|
||||||
boost::shared_ptr<CSMFilter::Node> mFilter;
|
boost::shared_ptr<CSMFilter::Node> mFilter;
|
||||||
std::string mUserValue;
|
std::string mUserValue;
|
||||||
|
std::map<int, int> mColumnMap; // column ID, column index in this model (or -1)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void updateColumnMap();
|
||||||
|
|
||||||
bool filterAcceptsRow (int sourceRow, const QModelIndex& sourceParent) const;
|
bool filterAcceptsRow (int sourceRow, const QModelIndex& sourceParent) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue