[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepim/libkdepim
From:       Stephen Kelly <steveire () gmail ! com>
Date:       2010-09-20 11:59:39
Message-ID: 20100920120346.4AC51AC88E () svn ! kde ! org
[Download RAW message or body]

SVN commit 1177503 by skelly:

Backport 1177499

 M  +27 -3     kdescendantsproxymodel.cpp  


--- trunk/KDE/kdepim/libkdepim/kdescendantsproxymodel.cpp #1177502:1177503
@@ -640,12 +640,36 @@
     const QModelIndex oldIndex = q->sourceModel()->index(rowCount - 1 - difference, \
column, parent);  Q_ASSERT(m_mapping.leftContains(oldIndex));
 
-    // oldIndex is E in the source. proxyRow is 4.
-    const int proxyRow = m_mapping.takeLeft(oldIndex);
     const QModelIndex newIndex = q->sourceModel()->index(rowCount - 1, column, \
parent);  
+    QModelIndex indexAbove = oldIndex;
+
+    if (start > 0) {
+      // If we have something like this:
+      //
+      // - A
+      // - - B
+      // - - C
+      //
+      // and we then insert D as a sibling of A below it, we need to remove the \
mapping for A, +      // and the row number used for D must take into account the \
descendants of A. +
+      while (q->sourceModel()->hasChildren(indexAbove)) {
+      Q_ASSERT(q->sourceModel()->rowCount(indexAbove) > 0);
+        indexAbove = q->sourceModel()->index(q->sourceModel()->rowCount(indexAbove) \
- 1,  column, indexAbove); +      }
+      Q_ASSERT(q->sourceModel()->rowCount(indexAbove) == 0);
+    }
+
+    Q_ASSERT(m_mapping.leftContains(indexAbove));
+
+    const int newProxyRow = m_mapping.leftToRight(indexAbove) + difference;
+
+    // oldIndex is E in the source. proxyRow is 4.
+    m_mapping.removeLeft(oldIndex);
+
     // newIndex is J. (proxyRow + difference) is 5.
-    m_mapping.insert(newIndex, proxyRow + difference);
+    m_mapping.insert(newIndex, newProxyRow);
   }
 
   for (int row = start; row <= end; ++row)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic