Browse Source

Fix tree item delete error

Kandrashin Denis 13 years ago
parent
commit
bbb40dd605
1 changed files with 11 additions and 4 deletions
  1. 11 4
      source/fb2tree.cpp

+ 11 - 4
source/fb2tree.cpp

@@ -579,12 +579,19 @@ void Fb2TreeView::deleteNode()
 {
 {
     if (Fb2TreeModel * m = model()) {
     if (Fb2TreeModel * m = model()) {
         QModelIndex index = currentIndex();
         QModelIndex index = currentIndex();
-        QModelIndex result = m->parent(index);
-        setCurrentIndex(result);
+        QModelIndex parent = m->parent(index);
+
+        QModelIndex result = parent;
+        int row = index.row();
+        int last = m->rowCount(result) - 1;
+        if (last > 0)  {
+            if (row >= last) row = last;
+            result = m->index(row, 0, parent);
+        }
         emit currentChanged(result, index);
         emit currentChanged(result, index);
         emit QTreeView::activated(result);
         emit QTreeView::activated(result);
-        m->removeRow(index.row(), result);
-        scrollTo(result);
+        setCurrentIndex(result);
+        m->removeRow(row, parent);
     }
     }
 }
 }