forked from qt-creator/qt-creator
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user