mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 13:53:53 +00:00
Merge remote-tracking branch 'smbas/fix-table-proxy-bugs'
This commit is contained in:
commit
fcf9ae42f4
3 changed files with 57 additions and 4 deletions
|
@ -50,6 +50,24 @@ QModelIndex CSMWorld::IdTableProxyModel::getModelIndex (const std::string& id, i
|
|||
return mapFromSource (dynamic_cast<IdTableBase&> (*sourceModel()).getModelIndex (id, column));
|
||||
}
|
||||
|
||||
void CSMWorld::IdTableProxyModel::setSourceModel(QAbstractItemModel *model)
|
||||
{
|
||||
QSortFilterProxyModel::setSourceModel(model);
|
||||
|
||||
connect(sourceModel(),
|
||||
SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
|
||||
this,
|
||||
SLOT(sourceRowsChanged(const QModelIndex &, int, int)));
|
||||
connect(sourceModel(),
|
||||
SIGNAL(rowsInserted(const QModelIndex &, int, int)),
|
||||
this,
|
||||
SLOT(sourceRowsChanged(const QModelIndex &, int, int)));
|
||||
connect(sourceModel(),
|
||||
SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
|
||||
this,
|
||||
SLOT(sourceDataChanged(const QModelIndex &, const QModelIndex &)));
|
||||
}
|
||||
|
||||
void CSMWorld::IdTableProxyModel::setFilter (const boost::shared_ptr<CSMFilter::Node>& filter)
|
||||
{
|
||||
beginResetModel();
|
||||
|
@ -60,6 +78,20 @@ void CSMWorld::IdTableProxyModel::setFilter (const boost::shared_ptr<CSMFilter::
|
|||
|
||||
bool CSMWorld::IdTableProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
||||
{
|
||||
Columns::ColumnId id = static_cast<Columns::ColumnId>(left.data(ColumnBase::Role_ColumnId).toInt());
|
||||
EnumColumnCache::const_iterator valuesIt = mEnumColumnCache.find(id);
|
||||
if (valuesIt == mEnumColumnCache.end())
|
||||
{
|
||||
if (Columns::hasEnums(id))
|
||||
{
|
||||
valuesIt = mEnumColumnCache.insert(std::make_pair(id, Columns::getEnums(id))).first;
|
||||
}
|
||||
}
|
||||
|
||||
if (valuesIt != mEnumColumnCache.end())
|
||||
{
|
||||
return valuesIt->second[left.data().toInt()] < valuesIt->second[right.data().toInt()];
|
||||
}
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
}
|
||||
|
||||
|
@ -68,3 +100,13 @@ void CSMWorld::IdTableProxyModel::refreshFilter()
|
|||
updateColumnMap();
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
void CSMWorld::IdTableProxyModel::sourceRowsChanged(const QModelIndex &/*parent*/, int /*start*/, int /*end*/)
|
||||
{
|
||||
refreshFilter();
|
||||
}
|
||||
|
||||
void CSMWorld::IdTableProxyModel::sourceDataChanged(const QModelIndex &/*topLeft*/, const QModelIndex &/*bottomRight*/)
|
||||
{
|
||||
refreshFilter();
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
#include "../filter/node.hpp"
|
||||
|
||||
#include "columns.hpp"
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class IdTableProxyModel : public QSortFilterProxyModel
|
||||
|
@ -20,6 +22,11 @@ namespace CSMWorld
|
|||
boost::shared_ptr<CSMFilter::Node> mFilter;
|
||||
std::map<int, int> mColumnMap; // column ID, column index in this model (or -1)
|
||||
|
||||
// Cache of enum values for enum columns (e.g. Modified, Record Type).
|
||||
// Used to speed up comparisons during the sort by such columns.
|
||||
typedef std::map<Columns::ColumnId, std::vector<std::string> > EnumColumnCache;
|
||||
mutable EnumColumnCache mEnumColumnCache;
|
||||
|
||||
private:
|
||||
|
||||
void updateColumnMap();
|
||||
|
@ -30,6 +37,8 @@ namespace CSMWorld
|
|||
|
||||
virtual QModelIndex getModelIndex (const std::string& id, int column) const;
|
||||
|
||||
virtual void setSourceModel(QAbstractItemModel *model);
|
||||
|
||||
void setFilter (const boost::shared_ptr<CSMFilter::Node>& filter);
|
||||
|
||||
void refreshFilter();
|
||||
|
@ -39,6 +48,12 @@ namespace CSMWorld
|
|||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
||||
|
||||
virtual bool filterAcceptsRow (int sourceRow, const QModelIndex& sourceParent) const;
|
||||
|
||||
private slots:
|
||||
|
||||
void sourceRowsChanged(const QModelIndex &parent, int start, int end);
|
||||
|
||||
void sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -653,10 +653,6 @@ void CSVWorld::Table::tableSizeUpdate()
|
|||
}
|
||||
|
||||
emit tableSizeChanged (size, deleted, modified);
|
||||
|
||||
// not really related to tableSizeUpdate() but placed here for convenience rather than
|
||||
// creating a bunch of extra connections & slot
|
||||
mProxyModel->refreshFilter();
|
||||
}
|
||||
|
||||
void CSVWorld::Table::selectionSizeUpdate()
|
||||
|
|
Loading…
Reference in a new issue