Update KDescendantsProxyModel code from KF5 kitemmodels, tag v5.24.0-rc3

parent 05250753
......@@ -31,19 +31,19 @@ typedef KHash2Map<QPersistentModelIndex, int> Mapping;
class KDescendantsProxyModelPrivate
{
KDescendantsProxyModelPrivate(KDescendantsProxyModel * qq)
KDescendantsProxyModelPrivate(KDescendantsProxyModel *qq)
: q_ptr(qq),
m_rowCount(0),
m_ignoreNextLayoutAboutToBeChanged(false),
m_ignoreNextLayoutChanged(false),
m_relayouting(false),
m_displayAncestorData( false ),
m_ancestorSeparator( QLatin1String( " / " ) )
m_displayAncestorData(false),
m_ancestorSeparator(QStringLiteral(" / "))
{
}
Q_DECLARE_PUBLIC(KDescendantsProxyModel)
KDescendantsProxyModel * const q_ptr;
KDescendantsProxyModel *const q_ptr;
mutable QVector<QPersistentModelIndex> m_pendingParents;
......@@ -102,8 +102,7 @@ void KDescendantsProxyModelPrivate::synchronousMappingRefresh()
m_pendingParents.append(QModelIndex());
m_relayouting = true;
while (!m_pendingParents.isEmpty())
{
while (!m_pendingParents.isEmpty()) {
processPendingParents();
}
m_relayouting = false;
......@@ -111,8 +110,7 @@ void KDescendantsProxyModelPrivate::synchronousMappingRefresh()
void KDescendantsProxyModelPrivate::scheduleProcessPendingParents() const
{
// Q_Q(const KDescendantsProxyModel);
const_cast<KDescendantsProxyModelPrivate*>(this)->processPendingParents();
const_cast<KDescendantsProxyModelPrivate *>(this)->processPendingParents();
}
void KDescendantsProxyModelPrivate::processPendingParents()
......@@ -121,18 +119,13 @@ void KDescendantsProxyModelPrivate::processPendingParents()
const QVector<QPersistentModelIndex>::iterator begin = m_pendingParents.begin();
QVector<QPersistentModelIndex>::iterator it = begin;
// Process chunkSize elements per invocation.
// static const int chunkSize = 30;
const QVector<QPersistentModelIndex>::iterator end =
/* (m_pendingParents.size() > chunkSize) ? begin + chunkSize : */ m_pendingParents.end();
const QVector<QPersistentModelIndex>::iterator end = m_pendingParents.end();
QVector<QPersistentModelIndex> newPendingParents;
while (it != end && it != m_pendingParents.end()) {
const QModelIndex sourceParent = *it;
if (!sourceParent.isValid() && m_rowCount > 0)
{
if (!sourceParent.isValid() && m_rowCount > 0) {
// It was removed from the source model before it was inserted.
it = m_pendingParents.erase(it);
continue;
......@@ -150,32 +143,34 @@ void KDescendantsProxyModelPrivate::processPendingParents()
const int proxyEndRow = proxyParent.row() + rowCount;
const int proxyStartRow = proxyEndRow - rowCount + 1;
if (!m_relayouting)
if (!m_relayouting) {
q->beginInsertRows(QModelIndex(), proxyStartRow, proxyEndRow);
}
updateInternalIndexes(proxyStartRow, rowCount);
m_mapping.insert(sourceIndex, proxyEndRow);
it = m_pendingParents.erase(it);
m_rowCount += rowCount;
if (!m_relayouting)
if (!m_relayouting) {
q->endInsertRows();
}
for (int sourceRow = 0; sourceRow < rowCount; ++sourceRow ) {
for (int sourceRow = 0; sourceRow < rowCount; ++sourceRow) {
static const int column = 0;
const QModelIndex child = q->sourceModel()->index(sourceRow, column, sourceParent);
Q_ASSERT(child.isValid());
if (q->sourceModel()->hasChildren(child))
{
if (q->sourceModel()->hasChildren(child)) {
Q_ASSERT(q->sourceModel()->rowCount(child) > 0);
newPendingParents.append(child);
}
}
}
m_pendingParents += newPendingParents;
if (!m_pendingParents.isEmpty())
if (!m_pendingParents.isEmpty()) {
processPendingParents();
}
// scheduleProcessPendingParents();
}
......@@ -187,8 +182,7 @@ void KDescendantsProxyModelPrivate::updateInternalIndexes(int start, int offset)
Mapping::right_iterator it = m_mapping.rightLowerBound(start);
const Mapping::right_iterator end = m_mapping.rightEnd();
while (it != end)
{
while (it != end) {
updates.insert(it.key() + offset, *it);
++it;
}
......@@ -198,8 +192,7 @@ void KDescendantsProxyModelPrivate::updateInternalIndexes(int start, int offset)
QHash<int, QPersistentModelIndex>::const_iterator it = updates.constBegin();
const QHash<int, QPersistentModelIndex>::const_iterator end = updates.constEnd();
for ( ; it != end; ++it)
{
for (; it != end; ++it) {
m_mapping.insert(it.value(), it.key());
}
}
......@@ -216,12 +209,19 @@ KDescendantsProxyModel::~KDescendantsProxyModel()
delete d_ptr;
}
#if 0
void KDescendantsProxyModel::setRootIndex(const QModelIndex &index)
{
Q_UNUSED(index)
}
#endif
QModelIndexList KDescendantsProxyModel::match(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const
{
return QAbstractProxyModel::match(start, role, value, hits, flags);
}
void KDescendantsProxyModel::setDisplayAncestorData( bool display )
void KDescendantsProxyModel::setDisplayAncestorData(bool display)
{
Q_D(KDescendantsProxyModel);
d->m_displayAncestorData = display;
......@@ -229,11 +229,11 @@ void KDescendantsProxyModel::setDisplayAncestorData( bool display )
bool KDescendantsProxyModel::displayAncestorData() const
{
Q_D(const KDescendantsProxyModel );
Q_D(const KDescendantsProxyModel);
return d->m_displayAncestorData;
}
void KDescendantsProxyModel::setAncestorSeparator( const QString &separator )
void KDescendantsProxyModel::setAncestorSeparator(const QString &separator)
{
Q_D(KDescendantsProxyModel);
d->m_ancestorSeparator = separator;
......@@ -241,75 +241,55 @@ void KDescendantsProxyModel::setAncestorSeparator( const QString &separator )
QString KDescendantsProxyModel::ancestorSeparator() const
{
Q_D(const KDescendantsProxyModel );
Q_D(const KDescendantsProxyModel);
return d->m_ancestorSeparator;
}
void KDescendantsProxyModel::setSourceModel(QAbstractItemModel *_sourceModel)
{
Q_D(const KDescendantsProxyModel );
beginResetModel();
static const char *modelSignals[] = {
SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
SIGNAL(rowsInserted(QModelIndex,int,int)),
SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
SIGNAL(rowsRemoved(QModelIndex,int,int)),
SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
SIGNAL(modelAboutToBeReset()),
SIGNAL(modelReset()),
SIGNAL(dataChanged(QModelIndex,QModelIndex)),
SIGNAL(layoutAboutToBeChanged()),
SIGNAL(layoutChanged()),
SIGNAL(destroyed())
};
static const char *proxySlots[] = {
SLOT(sourceRowsAboutToBeInserted(QModelIndex,int,int)),
SLOT(sourceRowsInserted(QModelIndex,int,int)),
SLOT(sourceRowsAboutToBeRemoved(QModelIndex,int,int)),
SLOT(sourceRowsRemoved(QModelIndex,int,int)),
SLOT(sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
SLOT(sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)),
SLOT(sourceModelAboutToBeReset()),
SLOT(sourceModelReset()),
SLOT(sourceDataChanged(QModelIndex,QModelIndex)),
SLOT(sourceLayoutAboutToBeChanged()),
SLOT(sourceLayoutChanged()),
SLOT(sourceModelDestroyed())
};
if (sourceModel()) {
disconnect(sourceModel(), SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
this, SLOT(sourceRowsAboutToBeInserted(QModelIndex,int,int)));
disconnect(sourceModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(sourceRowsInserted(QModelIndex,int,int)));
disconnect(sourceModel(), SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
this, SLOT(sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
disconnect(sourceModel(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT(sourceRowsRemoved(QModelIndex,int,int)));
// disconnect(sourceModel(), SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
// this, SLOT(sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
// disconnect(sourceModel(), SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
// this, SLOT(sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)));
disconnect(sourceModel(), SIGNAL(modelAboutToBeReset()),
this, SLOT(sourceModelAboutToBeReset()));
disconnect(sourceModel(), SIGNAL(modelReset()),
this, SLOT(sourceModelReset()));
disconnect(sourceModel(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SLOT(sourceDataChanged(QModelIndex,QModelIndex)));
disconnect(sourceModel(), SIGNAL(layoutAboutToBeChanged()),
this, SLOT(sourceLayoutAboutToBeChanged()));
disconnect(sourceModel(), SIGNAL(layoutChanged()),
this, SLOT(sourceLayoutChanged()));
disconnect(sourceModel(), SIGNAL(destroyed()),
this, SLOT(sourceModelDestroyed()));
for (int i = 0; i < int(sizeof modelSignals / sizeof * modelSignals); ++i) {
disconnect(sourceModel(), modelSignals[i], this, proxySlots[i]);
}
}
QAbstractProxyModel::setSourceModel(_sourceModel);
if ( sourceModel()->hasChildren() )
{
Q_ASSERT( sourceModel()->rowCount() > 0 );
const_cast<KDescendantsProxyModelPrivate*>(d)->synchronousMappingRefresh();
}
if (_sourceModel) {
connect(_sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
SLOT(sourceRowsAboutToBeInserted(QModelIndex,int,int)));
connect(_sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
SLOT(sourceRowsInserted(QModelIndex,int,int)));
connect(_sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
SLOT(sourceRowsAboutToBeRemoved(QModelIndex,int,int)));
connect(_sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
SLOT(sourceRowsRemoved(QModelIndex,int,int)));
// connect(_sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
// SLOT(sourceRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
// connect(_sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
// SLOT(sourceRowsMoved(QModelIndex,int,int,QModelIndex,int)));
connect(_sourceModel, SIGNAL(modelAboutToBeReset()),
SLOT(sourceModelAboutToBeReset()));
connect(_sourceModel, SIGNAL(modelReset()),
SLOT(sourceModelReset()));
connect(_sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
SLOT(sourceDataChanged(QModelIndex,QModelIndex)));
connect(_sourceModel, SIGNAL(layoutAboutToBeChanged()),
SLOT(sourceLayoutAboutToBeChanged()));
connect(_sourceModel, SIGNAL(layoutChanged()),
SLOT(sourceLayoutChanged()));
connect(_sourceModel, SIGNAL(destroyed()),
SLOT(sourceModelDestroyed()));
for (int i = 0; i < int(sizeof modelSignals / sizeof * modelSignals); ++i) {
connect(_sourceModel, modelSignals[i], this, proxySlots[i]);
}
}
endResetModel();
......@@ -330,24 +310,26 @@ bool KDescendantsProxyModel::hasChildren(const QModelIndex &parent) const
int KDescendantsProxyModel::rowCount(const QModelIndex &parent) const
{
Q_D(const KDescendantsProxyModel);
if (d->m_pendingParents.contains(parent) || parent.isValid() || !sourceModel())
if (d->m_pendingParents.contains(parent) || parent.isValid() || !sourceModel()) {
return 0;
}
if (d->m_mapping.isEmpty() && sourceModel()->hasChildren())
{
if (d->m_mapping.isEmpty() && sourceModel()->hasChildren()) {
Q_ASSERT(sourceModel()->rowCount() > 0);
const_cast<KDescendantsProxyModelPrivate*>(d)->synchronousMappingRefresh();
const_cast<KDescendantsProxyModelPrivate *>(d)->synchronousMappingRefresh();
}
return d->m_rowCount;
}
QModelIndex KDescendantsProxyModel::index(int row, int column, const QModelIndex &parent) const
{
if (parent.isValid())
if (parent.isValid()) {
return QModelIndex();
}
if (!hasIndex(row, column, parent))
if (!hasIndex(row, column, parent)) {
return QModelIndex();
}
return createIndex(row, column);
}
......@@ -355,8 +337,9 @@ QModelIndex KDescendantsProxyModel::index(int row, int column, const QModelIndex
QModelIndex KDescendantsProxyModel::mapToSource(const QModelIndex &proxyIndex) const
{
Q_D(const KDescendantsProxyModel);
if (d->m_mapping.isEmpty() || !proxyIndex.isValid() || !sourceModel())
if (d->m_mapping.isEmpty() || !proxyIndex.isValid() || !sourceModel()) {
return QModelIndex();
}
const Mapping::right_const_iterator result = d->m_mapping.rightLowerBound(proxyIndex.row());
Q_ASSERT(result != d->m_mapping.rightEnd());
......@@ -399,11 +382,9 @@ QModelIndex KDescendantsProxyModel::mapToSource(const QModelIndex &proxyIndex) c
// We traverse the ancestors of L, until we can index the desired row in the source.
QModelIndex ancestor = sourceLastChild;
while (ancestor.isValid())
{
while (ancestor.isValid()) {
const int ancestorRow = ancestor.row();
if (verticalDistance <= ancestorRow)
{
if (verticalDistance <= ancestorRow) {
return ancestor.sibling(ancestorRow - verticalDistance, proxyIndex.column());
}
verticalDistance -= (ancestorRow + 1);
......@@ -417,11 +398,13 @@ QModelIndex KDescendantsProxyModel::mapFromSource(const QModelIndex &sourceIndex
{
Q_D(const KDescendantsProxyModel);
if (!sourceModel())
if (!sourceModel()) {
return QModelIndex();
}
if (d->m_mapping.isEmpty())
if (d->m_mapping.isEmpty()) {
return QModelIndex();
}
{
// TODO: Consider a parent Mapping to speed this up.
......@@ -431,18 +414,14 @@ QModelIndex KDescendantsProxyModel::mapFromSource(const QModelIndex &sourceIndex
const QModelIndex sourceParent = sourceIndex.parent();
Mapping::right_const_iterator result = end;
for ( ; it != end; ++it )
{
for (; it != end; ++it) {
QModelIndex index = it.value();
bool found_block = false;
while (index.isValid())
{
while (index.isValid()) {
const QModelIndex ancestor = index.parent();
if (ancestor == sourceParent && index.row() >= sourceIndex.row())
{
if (ancestor == sourceParent && index.row() >= sourceIndex.row()) {
found_block = true;
if (result == end || it.key() < result.key())
{
if (result == end || it.key() < result.key()) {
result = it;
break; // Leave the while loop. index is still valid.
}
......@@ -452,17 +431,17 @@ QModelIndex KDescendantsProxyModel::mapFromSource(const QModelIndex &sourceIndex
if (found_block && !index.isValid())
// Looked through the ascendants of it.key() without finding sourceParent.
// That means we've already got the result we need.
{
break;
}
}
Q_ASSERT(result != end);
const QModelIndex sourceLastChild = result.value();
int proxyRow = result.key();
QModelIndex index = sourceLastChild;
while (index.isValid())
{
while (index.isValid()) {
const QModelIndex ancestor = index.parent();
if (ancestor == sourceParent)
{
if (ancestor == sourceParent) {
return createIndex(proxyRow - (index.row() - sourceIndex.row()), sourceIndex.column());
}
proxyRow -= (index.row() + 1);
......@@ -476,34 +455,34 @@ QModelIndex KDescendantsProxyModel::mapFromSource(const QModelIndex &sourceIndex
int KDescendantsProxyModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid() /* || rowCount(parent) == 0 */ || !sourceModel())
if (parent.isValid() /* || rowCount(parent) == 0 */ || !sourceModel()) {
return 0;
}
return sourceModel()->columnCount();
}
QVariant KDescendantsProxyModel::data(const QModelIndex &index, int role) const
{
Q_D(const KDescendantsProxyModel );
Q_D(const KDescendantsProxyModel);
if (!sourceModel())
if (!sourceModel()) {
return QVariant();
}
if (!index.isValid())
if (!index.isValid()) {
return sourceModel()->data(index, role);
}
QModelIndex sourceIndex = mapToSource( index );
QModelIndex sourceIndex = mapToSource(index);
if ((d->m_displayAncestorData) && ( role == Qt::DisplayRole ) )
{
if (!sourceIndex.isValid())
{
if ((d->m_displayAncestorData) && (role == Qt::DisplayRole)) {
if (!sourceIndex.isValid()) {
return QVariant();
}
QString displayData = sourceIndex.data().toString();
sourceIndex = sourceIndex.parent();
while (sourceIndex.isValid())
{
while (sourceIndex.isValid()) {
displayData.prepend(d->m_ancestorSeparator);
displayData.prepend(sourceIndex.data().toString());
sourceIndex = sourceIndex.parent();
......@@ -516,16 +495,18 @@ QVariant KDescendantsProxyModel::data(const QModelIndex &index, int role) const
QVariant KDescendantsProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (!sourceModel() || columnCount() <= section)
if (!sourceModel() || columnCount() <= section) {
return QVariant();
}
return QAbstractProxyModel::headerData(section, orientation, role);
}
Qt::ItemFlags KDescendantsProxyModel::flags(const QModelIndex &index) const
{
if (!index.isValid() || !sourceModel())
if (!index.isValid() || !sourceModel()) {
return QAbstractProxyModel::flags(index);
}
const QModelIndex srcIndex = mapToSource(index);
Q_ASSERT(srcIndex.isValid());
......@@ -536,8 +517,7 @@ void KDescendantsProxyModelPrivate::sourceRowsAboutToBeInserted(const QModelInde
{
Q_Q(KDescendantsProxyModel);
if (!q->sourceModel()->hasChildren(parent))
{
if (!q->sourceModel()->hasChildren(parent)) {
Q_ASSERT(q->sourceModel()->rowCount(parent) == 0);
// parent was not a parent before.
return;
......@@ -547,19 +527,16 @@ void KDescendantsProxyModelPrivate::sourceRowsAboutToBeInserted(const QModelInde
const int rowCount = q->sourceModel()->rowCount(parent);
if (rowCount > start)
{
if (rowCount > start) {
const QModelIndex belowStart = q->sourceModel()->index(start, 0, parent);
proxyStart = q->mapFromSource(belowStart).row();
} else if (rowCount == 0)
{
} else if (rowCount == 0) {
proxyStart = q->mapFromSource(parent).row() + 1;
} else {
Q_ASSERT(rowCount == start);
static const int column = 0;
QModelIndex idx = q->sourceModel()->index(rowCount - 1, column, parent);
while (q->sourceModel()->hasChildren(idx))
{
while (q->sourceModel()->hasChildren(idx)) {
Q_ASSERT(q->sourceModel()->rowCount(idx) > 0);
idx = q->sourceModel()->index(q->sourceModel()->rowCount(idx) - 1, column, idx);
}
......@@ -576,16 +553,14 @@ void KDescendantsProxyModelPrivate::sourceRowsInserted(const QModelIndex &parent
{
Q_Q(KDescendantsProxyModel);
const QModelIndex sourceStart = q->sourceModel()->index(start, 0, parent);
Q_ASSERT(sourceStart.isValid());
Q_ASSERT(q->sourceModel()->index(start, 0, parent).isValid());
const int rowCount = q->sourceModel()->rowCount(parent);
Q_ASSERT(rowCount > 0);
const int difference = end - start + 1;
if (rowCount == difference)
{
if (rowCount == difference) {
// @p parent was not a parent before.
m_pendingParents.append(parent);
scheduleProcessPendingParents();
......@@ -598,8 +573,7 @@ void KDescendantsProxyModelPrivate::sourceRowsInserted(const QModelIndex &parent
updateInternalIndexes(proxyStart, difference);
if (rowCount - 1 == end)
{
if (rowCount - 1 == end) {
// The previously last row (the mapped one) is no longer the last.
// For example,
......@@ -668,13 +642,11 @@ void KDescendantsProxyModelPrivate::sourceRowsInserted(const QModelIndex &parent
m_mapping.insert(newIndex, newProxyRow);
}
for (int row = start; row <= end; ++row)
{
for (int row = start; row <= end; ++row) {
static const int column = 0;
const QModelIndex idx = q->sourceModel()->index(row, column, parent);
Q_ASSERT(idx.isValid());
if (q->sourceModel()->hasChildren(idx))
{
if (q->sourceModel()->hasChildren(idx)) {
Q_ASSERT(q->sourceModel()->rowCount(idx) > 0);
m_pendingParents.append(idx);
}
......@@ -694,8 +666,7 @@ void KDescendantsProxyModelPrivate::sourceRowsAboutToBeRemoved(const QModelIndex
static const int column = 0;
QModelIndex idx = q->sourceModel()->index(end, column, parent);
while (q->sourceModel()->hasChildren(idx))
{
while (q->sourceModel()->hasChildren(idx)) {
Q_ASSERT(q->sourceModel()->rowCount(idx) > 0);
idx = q->sourceModel()->index(q->sourceModel()->rowCount(idx) - 1, column, idx);
}
......@@ -706,7 +677,8 @@ void KDescendantsProxyModelPrivate::sourceRowsAboutToBeRemoved(const QModelIndex
q->beginRemoveRows(QModelIndex(), proxyStart, proxyEnd);
}
static QModelIndex getFirstDeepest(QAbstractItemModel *model, const QModelIndex &parent, int *count) {
static QModelIndex getFirstDeepest(QAbstractItemModel *model, const QModelIndex &parent, int *count)
{
static const int column = 0;
Q_ASSERT(model->hasChildren(parent));
Q_ASSERT(model->rowCount(parent) > 0);
......@@ -714,9 +686,10 @@ static QModelIndex getFirstDeepest(QAbstractItemModel *model, const QModelIndex
(*count)++;
const QModelIndex child = model->index(row, column, parent);
Q_ASSERT(child.isValid());
if (model->hasChildren(child))
if (model->hasChildren(child)) {
return getFirstDeepest(model, child, count);
}
}
return model->index(model->rowCount(parent) - 1, column, parent);
}
......@@ -727,7 +700,6 @@ void KDescendantsProxyModelPrivate::sourceRowsRemoved(const QModelIndex &parent,
const int rowCount = q->sourceModel()->rowCount(parent);
const int proxyStart = m_removePair.first;
const int proxyEnd = m_removePair.second;
......@@ -737,12 +709,14 @@ void KDescendantsProxyModelPrivate::sourceRowsRemoved(const QModelIndex &parent,
const Mapping::right_iterator endIt = m_mapping.rightUpperBound(proxyEnd);
if (endIt != m_mapping.rightEnd())
while (it != endIt)
while (it != endIt) {
it = m_mapping.eraseRight(it);
}
else
while (it != m_mapping.rightUpperBound(proxyEnd))
while (it != m_mapping.rightUpperBound(proxyEnd)) {
it = m_mapping.eraseRight(it);
}
}
m_removePair = qMakePair(-1, -1);
m_rowCount -= difference;
......@@ -778,7 +752,7 @@ void KDescendantsProxyModelPrivate::sourceRowsRemoved(const QModelIndex &parent,
if (lowerBound == m_mapping.rightEnd()) {
int proxyRow = (lowerBound - 1).key();
for (int row = newEnd.row(); row >= 0; --row ) {
for (int row = newEnd.row(); row >= 0; --row) {
const QModelIndex newEndSibling = q->sourceModel()->index(row, column, parent);
if (!q->sourceModel()->hasChildren(newEndSibling)) {
++proxyRow;
......@@ -815,10 +789,11 @@ void KDescendantsProxyModelPrivate::sourceRowsRemoved(const QModelIndex &parent,
}
count += (target.row() + 1);
target = target.parent();
if (target.isValid())
if (target.isValid()) {
targetParents.push_back(target);
}
}
}
QModelIndex boundParent = boundAbove.value().parent();
QModelIndex prevParent = boundParent;
......@@ -827,15 +802,18 @@ void KDescendantsProxyModelPrivate::sourceRowsRemoved(const QModelIndex &parent,
prevParent = boundParent;
boundParent = boundParent.parent();
if (targetParents.contains(prevParent))
if (targetParents.contains(prevParent)) {
break;
}
if (!m_mapping.leftContains(prevParent))
if (!m_mapping.leftContains(prevParent)) {
break;
}