Fix assert (in beginRemoveRows) when deselecting an empty child of a selected child in korganizer

After
   int proxyEndRemove = proxyStartRemove;
   proxyEndRemove += rc; was adding 0 (empty root)
and then --proxyEndRemove; was making us end up with proxyEndRemove < proxyStartRemove.

REVIEW: 129657
wilder
David Faure 9 years ago
parent 3d3658e5e1
commit 24db696bab
  1. 14
      autotests/kselectionproxymodeltest.cpp
  2. 6
      src/kselectionproxymodel.cpp

@ -310,6 +310,13 @@ void KSelectionProxyModelTest::deselection_data()
<< 1
<< QStringList{"4"} << 5;
++testNumber;
QTest::newRow(QByteArray("test" + QByteArray::number(testNumber)).data())
<< static_cast<int>(KSelectionProxyModel::ChildrenOfExactSelection)
<< QStringList{"6", "7"} << 1
<< 0
<< QStringList{"7"} << 1;
++testNumber;
}
void KSelectionProxyModelTest::deselection()
@ -604,6 +611,13 @@ void KSelectionProxyModelTest::removeRows_data()
<< 1
<< QStringList{"9", "9"} << 2;
++testNumber;
QTest::newRow(QByteArray("test" + QByteArray::number(testNumber)).data())
<< static_cast<int>(kspm_mode) << connectSelectionModelFirst << false
<< QStringList{"6", "8", "11"} << 4
<< 0
<< QStringList{"8", "8"} << 4;
++testNumber;
}
}

@ -1176,7 +1176,7 @@ QPair<int, int> KSelectionProxyModelPrivate::beginRemoveRows(const QModelIndex &
}
--proxyEndRemove;
if (proxyEndRemove >= 0) {
if (proxyEndRemove >= proxyStartRemove) {
return qMakePair(proxyStartRemove, proxyEndRemove);
}
return qMakePair(-1, -1);
@ -1750,7 +1750,7 @@ void KSelectionProxyModelPrivate::removeSelectionFromProxy(const QItemSelection
}
--proxyEndRemove;
if (proxyEndRemove >= 0) {
if (proxyEndRemove >= proxyStartRemove) {
q->beginRemoveRows(QModelIndex(), proxyStartRemove, proxyEndRemove);
rootIt = m_rootIndexList.erase(rootRemoveStart, rootIt);
@ -1953,7 +1953,7 @@ void KSelectionProxyModelPrivate::insertSelectionIntoProxy(const QItemSelection
if (rowCount == 0) {
// Even if the newindex doesn't have any children to put into the model yet,
// We still need to make sure it's future children are inserted into the model.
// We still need to make sure its future children are inserted into the model.
m_rootIndexList.insert(rootListRow, newIndex);
if (!m_resetting || m_layoutChanging) {
emit q->rootIndexAdded(newIndex);

Loading…
Cancel
Save