TaskModel: Do not duplicate items

When inserting new items into the TaskFilterModel we could end up
duplicating the items. Do not do that.

Change-Id: I2450bac185a881e16f23368b39ce5e273c061d99
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Tobias Hunger
2014-04-10 12:10:39 +02:00
parent bc8e9ca14f
commit 48255c9229
2 changed files with 4 additions and 8 deletions

View File

@@ -327,9 +327,11 @@ void TaskModel::setFileNotFound(const QModelIndex &idx, bool b)
/////
TaskFilterModel::TaskFilterModel(TaskModel *sourceModel, QObject *parent) : QAbstractItemModel(parent),
m_mappingUpToDate(false), m_sourceModel(sourceModel)
m_sourceModel(sourceModel)
{
Q_ASSERT(m_sourceModel);
updateMapping();
connect(m_sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(handleNewRows(QModelIndex,int,int)));
connect(m_sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
@@ -472,15 +474,12 @@ QModelIndex TaskFilterModel::mapToSource(const QModelIndex &index) const
void TaskFilterModel::invalidateFilter()
{
beginResetModel();
m_mappingUpToDate = false;
updateMapping();
endResetModel();
}
void TaskFilterModel::updateMapping() const
{
if (m_mappingUpToDate)
return;
m_mapping.clear();
for (int i = 0; i < m_sourceModel->rowCount(); ++i) {
QModelIndex index = m_sourceModel->index(i, 0);
@@ -488,8 +487,6 @@ void TaskFilterModel::updateMapping() const
if (filterAcceptsTask(task))
m_mapping.append(i);
}
m_mappingUpToDate = true;
}
bool TaskFilterModel::filterAcceptsTask(const Task &task) const

View File

@@ -179,7 +179,6 @@ private:
QList<Core::Id> m_categoryIds;
mutable QList<int> m_mapping;
mutable bool m_mappingUpToDate;
TaskModel *m_sourceModel;
};