Commit 48255c92 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

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: default avatarDaniel Teske <daniel.teske@digia.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent bc8e9ca1
......@@ -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
......
......@@ -179,7 +179,6 @@ private:
QList<Core::Id> m_categoryIds;
mutable QList<int> m_mapping;
mutable bool m_mappingUpToDate;
TaskModel *m_sourceModel;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment