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),
|
TaskFilterModel::TaskFilterModel(TaskModel *sourceModel, QObject *parent) : QAbstractItemModel(parent),
|
||||||
m_mappingUpToDate(false), m_sourceModel(sourceModel)
|
m_sourceModel(sourceModel)
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_sourceModel);
|
Q_ASSERT(m_sourceModel);
|
||||||
|
updateMapping();
|
||||||
|
|
||||||
connect(m_sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
|
connect(m_sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
|
||||||
this, SLOT(handleNewRows(QModelIndex,int,int)));
|
this, SLOT(handleNewRows(QModelIndex,int,int)));
|
||||||
connect(m_sourceModel, SIGNAL(rowsAboutToBeRemoved(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()
|
void TaskFilterModel::invalidateFilter()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_mappingUpToDate = false;
|
updateMapping();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskFilterModel::updateMapping() const
|
void TaskFilterModel::updateMapping() const
|
||||||
{
|
{
|
||||||
if (m_mappingUpToDate)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_mapping.clear();
|
m_mapping.clear();
|
||||||
for (int i = 0; i < m_sourceModel->rowCount(); ++i) {
|
for (int i = 0; i < m_sourceModel->rowCount(); ++i) {
|
||||||
QModelIndex index = m_sourceModel->index(i, 0);
|
QModelIndex index = m_sourceModel->index(i, 0);
|
||||||
@@ -488,8 +487,6 @@ void TaskFilterModel::updateMapping() const
|
|||||||
if (filterAcceptsTask(task))
|
if (filterAcceptsTask(task))
|
||||||
m_mapping.append(i);
|
m_mapping.append(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_mappingUpToDate = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TaskFilterModel::filterAcceptsTask(const Task &task) const
|
bool TaskFilterModel::filterAcceptsTask(const Task &task) const
|
||||||
|
|||||||
@@ -179,7 +179,6 @@ private:
|
|||||||
QList<Core::Id> m_categoryIds;
|
QList<Core::Id> m_categoryIds;
|
||||||
|
|
||||||
mutable QList<int> m_mapping;
|
mutable QList<int> m_mapping;
|
||||||
mutable bool m_mappingUpToDate;
|
|
||||||
|
|
||||||
TaskModel *m_sourceModel;
|
TaskModel *m_sourceModel;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user