1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
From a9134500e4e599ba316617941bcd04f640ed3999 Mon Sep 17 00:00:00 2001
From: Dag Andersen <danders@get2net.dk>
Date: Tue, 23 Aug 2016 13:30:13 +0200
Subject: [PATCH 70/80] Plan: Guard against trying to move a task into the same
porition
QAbstractItemModel cannot handle this and it causes a crash (later)
---
plan/libs/kernel/kptproject.cpp | 4 ++++
plan/libs/models/kptnodeitemmodel.cpp | 9 +++++++++
2 files changed, 13 insertions(+)
diff --git a/plan/libs/kernel/kptproject.cpp b/plan/libs/kernel/kptproject.cpp
index 451e897..fdf43bc 100644
--- a/plan/libs/kernel/kptproject.cpp
+++ b/plan/libs/kernel/kptproject.cpp
@@ -1565,6 +1565,10 @@ bool Project::moveTask( Node* node, Node *newParent, int newPos )
Node *oldParent = node->parentNode();
int oldPos = oldParent->indexOf( node );
int i = newPos < 0 ? newParent->numChildren() : newPos;
+ if ( oldParent == newParent && i == oldPos ) {
+ // no need to move to where it already is
+ return false;
+ }
int newRow = i;
if ( oldParent == newParent && newPos > oldPos ) {
++newRow; // itemmodels wants new row *before* node is removed from old position
diff --git a/plan/libs/models/kptnodeitemmodel.cpp b/plan/libs/models/kptnodeitemmodel.cpp
index e66277f..5581f8f 100644
--- a/plan/libs/models/kptnodeitemmodel.cpp
+++ b/plan/libs/models/kptnodeitemmodel.cpp
@@ -4036,6 +4036,15 @@ bool NodeItemModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
if ( pos >= 0 && n->parentNode() == par && par->indexOf( n ) < pos ) {
--pos;
}
+ if ( n->parentNode() == par ) {
+ // avoid drop into the same position, QAbstractItemModel does not like it
+ int crow = par->indexOf( n );
+ if ( ( ( pos == -1 ) && ( crow == par->numChildren() - 1 ) ) || ( pos == crow ) ) {
+ delete cmd;
+ cmd = 0;
+ continue;
+ }
+ }
cmd->addCommand( new NodeMoveCmd( m_project, n, par, pos ) );
offset++;
}
--
2.7.4
|