summaryrefslogtreecommitdiff
path: root/source/kde/patch/calligra/0069-Backport-Plan-Avoid-crash-in-special-cases.patch
blob: 75ec66b509423c31ff7a8d4d85d83879abe067e0 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
From b25d46bf9fa6d5b9ff34115edb4719592c191935 Mon Sep 17 00:00:00 2001
From: Dag Andersen <danders@get2net.dk>
Date: Tue, 23 Aug 2016 08:01:58 +0200
Subject: [PATCH 69/80] Backport: Plan: Avoid crash in special cases

Sometimes (eg. when New is pressed) the Project can be deleted before models
and thus cause a crash.
Added a Project::aboutToBeDeleted signal so models can adjust.

BUG: 346976
FIXED_IN: 2.9.12
---
 plan/libs/kernel/kptproject.cpp                   |  1 +
 plan/libs/kernel/kptproject.h                     |  2 ++
 plan/libs/models/kptaccountsmodel.cpp             |  2 ++
 plan/libs/models/kptcalendarmodel.cpp             |  4 ++++
 plan/libs/models/kptitemmodelbase.cpp             |  5 +++++
 plan/libs/models/kptitemmodelbase.h               |  1 +
 plan/libs/models/kptnodechartmodel.cpp            |  2 ++
 plan/libs/models/kptnodeitemmodel.cpp             |  4 ++++
 plan/libs/models/kptpertcpmmodel.cpp              |  4 ++++
 plan/libs/models/kptrelationmodel.cpp             |  2 ++
 plan/libs/models/kptresourceallocationmodel.cpp   |  2 ++
 plan/libs/models/kptresourceappointmentsmodel.cpp |  8 ++++++++
 plan/libs/models/kptresourcemodel.cpp             | 12 +++++++-----
 plan/libs/models/kptschedulemodel.cpp             | 13 +++++++++++++
 plan/libs/models/kptschedulemodel.h               |  2 ++
 plan/libs/models/kpttaskstatusmodel.cpp           |  2 ++
 16 files changed, 61 insertions(+), 5 deletions(-)

diff --git a/plan/libs/kernel/kptproject.cpp b/plan/libs/kernel/kptproject.cpp
index 158040b..451e897 100644
--- a/plan/libs/kernel/kptproject.cpp
+++ b/plan/libs/kernel/kptproject.cpp
@@ -89,6 +89,7 @@ void Project::deref()
     --m_refCount;
     Q_ASSERT( m_refCount >= 0 );
     if ( m_refCount <= 0 ) {
+        emit aboutToBeDeleted();
         deleteLater();
     }
 }
diff --git a/plan/libs/kernel/kptproject.h b/plan/libs/kernel/kptproject.h
index 1dbea7d..db18d36 100644
--- a/plan/libs/kernel/kptproject.h
+++ b/plan/libs/kernel/kptproject.h
@@ -519,6 +519,8 @@ public Q_SLOTS:
     void setMaxProgress( int max, ScheduleManager *sm = 0 );
 
 Q_SIGNALS:
+    /// Emitted when the project is about to be deleted (The destroyed signal is disabled)
+    void aboutToBeDeleted();
     /// Emitted when anything in the project is changed (use with care)
     void projectChanged();
     /// Emitted when the WBS code definition has changed. This may change all nodes.
diff --git a/plan/libs/models/kptaccountsmodel.cpp b/plan/libs/models/kptaccountsmodel.cpp
index 53f725a..4657979 100644
--- a/plan/libs/models/kptaccountsmodel.cpp
+++ b/plan/libs/models/kptaccountsmodel.cpp
@@ -533,6 +533,7 @@ void CostBreakdownItemModel::setProject( Project *project )
         disconnect( acc, SIGNAL(accountRemoved(const Account*)), this, SLOT(slotAccountRemoved(const Account*)) );
         disconnect( acc, SIGNAL(accountToBeRemoved(const Account*)), this, SLOT(slotAccountToBeRemoved(const Account*)) );
 
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         disconnect( m_project , SIGNAL(nodeChanged(Node*)), this, SLOT(slotDataChanged()) );
         disconnect( m_project , SIGNAL(nodeAdded(Node*)), this, SLOT(slotDataChanged()) );
         disconnect( m_project , SIGNAL(nodeRemoved(Node*)), this, SLOT(slotDataChanged()) );
@@ -553,6 +554,7 @@ void CostBreakdownItemModel::setProject( Project *project )
         connect( acc, SIGNAL(accountRemoved(const Account*)), this, SLOT(slotAccountRemoved(const Account*)) );
         connect( acc, SIGNAL(accountToBeRemoved(const Account*)), this, SLOT(slotAccountToBeRemoved(const Account*)) );
 
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         connect( m_project , SIGNAL(nodeChanged(Node*)), this, SLOT(slotDataChanged()) );
         connect( m_project , SIGNAL(nodeAdded(Node*)), this, SLOT(slotDataChanged()) );
         connect( m_project , SIGNAL(nodeRemoved(Node*)), this, SLOT(slotDataChanged()) );
diff --git a/plan/libs/models/kptcalendarmodel.cpp b/plan/libs/models/kptcalendarmodel.cpp
index 6c0f017..401379c 100644
--- a/plan/libs/models/kptcalendarmodel.cpp
+++ b/plan/libs/models/kptcalendarmodel.cpp
@@ -74,10 +74,12 @@ void CalendarDayItemModelBase::setProject( Project *project )
 {
     setCalendar( 0 );
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         disconnect( m_project, SIGNAL(calendarToBeRemoved(const Calendar*)), this, SLOT(slotCalendarToBeRemoved(const Calendar*)) );
     }
     m_project = project;
     if ( project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         connect( m_project, SIGNAL(calendarToBeRemoved(const Calendar*)), this, SLOT(slotCalendarToBeRemoved(const Calendar*)) );
     }
     reset();
@@ -136,6 +138,7 @@ void CalendarItemModel::slotCalendarRemoved( const Calendar * )
 void CalendarItemModel::setProject( Project *project )
 {
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         disconnect( m_project , SIGNAL(calendarChanged(Calendar*)), this, SLOT(slotCalendarChanged(Calendar*)) );
 
         disconnect( m_project, SIGNAL(calendarAdded(const Calendar*)), this, SLOT(slotCalendarInserted(const Calendar*)) );
@@ -146,6 +149,7 @@ void CalendarItemModel::setProject( Project *project )
     }
     m_project = project;
     if ( project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         connect( m_project, SIGNAL(calendarChanged(Calendar*)), this, SLOT(slotCalendarChanged(Calendar*)) );
 
         connect( m_project, SIGNAL(calendarAdded(const Calendar*)), this, SLOT(slotCalendarInserted(const Calendar*)) );
diff --git a/plan/libs/models/kptitemmodelbase.cpp b/plan/libs/models/kptitemmodelbase.cpp
index 499fcfe..ff74394 100644
--- a/plan/libs/models/kptitemmodelbase.cpp
+++ b/plan/libs/models/kptitemmodelbase.cpp
@@ -731,6 +731,11 @@ bool ItemModelBase::setData( const QModelIndex &index, const QVariant &value, in
     return false;
 }
 
+void ItemModelBase::projectDeleted()
+{
+    setProject(0);
+}
+
 } //namespace KPlato
 
 #include "kptitemmodelbase.moc"
diff --git a/plan/libs/models/kptitemmodelbase.h b/plan/libs/models/kptitemmodelbase.h
index 578c18e..5d3719d 100644
--- a/plan/libs/models/kptitemmodelbase.h
+++ b/plan/libs/models/kptitemmodelbase.h
@@ -309,6 +309,7 @@ protected Q_SLOTS:
     virtual void slotLayoutToBeChanged();
     virtual void slotLayoutChanged();
 
+    void projectDeleted();
 protected:
     Project *m_project;
     ScheduleManager *m_manager;
diff --git a/plan/libs/models/kptnodechartmodel.cpp b/plan/libs/models/kptnodechartmodel.cpp
index 025da86..9b8d397 100644
--- a/plan/libs/models/kptnodechartmodel.cpp
+++ b/plan/libs/models/kptnodechartmodel.cpp
@@ -294,6 +294,7 @@ void ChartItemModel::setProject( Project *project )
     m_bcws.clear();
     m_acwp.clear();
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         disconnect( m_project, SIGNAL(projectCalculated(ScheduleManager*)), this, SLOT(setScheduleManager(ScheduleManager*)) );
         disconnect( m_project, SIGNAL(nodeRemoved(Node*)), this, SLOT(slotNodeRemoved(Node*)) );
         disconnect( m_project, SIGNAL(nodeChanged(Node*)), this, SLOT(slotNodeChanged(Node*)) );
@@ -302,6 +303,7 @@ void ChartItemModel::setProject( Project *project )
     }
     m_project = project;
     if ( m_project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         connect( m_project, SIGNAL(projectCalculated(ScheduleManager*)), this, SLOT(setScheduleManager(ScheduleManager*)) );
         connect( m_project, SIGNAL(nodeRemoved(Node*)), this, SLOT(slotNodeRemoved(Node*)) );
         connect( m_project, SIGNAL(nodeChanged(Node*)), this, SLOT(slotNodeChanged(Node*)) );
diff --git a/plan/libs/models/kptnodeitemmodel.cpp b/plan/libs/models/kptnodeitemmodel.cpp
index 45b1650..e66277f 100644
--- a/plan/libs/models/kptnodeitemmodel.cpp
+++ b/plan/libs/models/kptnodeitemmodel.cpp
@@ -3122,6 +3122,7 @@ void NodeItemModel::slotWbsDefinitionChanged()
 void NodeItemModel::setProject( Project *project )
 {
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         disconnect( m_project, SIGNAL(localeChanged()), this, SLOT(slotLayoutChanged()) );
         disconnect( m_project, SIGNAL(wbsDefinitionChanged()), this, SLOT(slotWbsDefinitionChanged()) );
         disconnect( m_project, SIGNAL(nodeChanged(Node*)), this, SLOT(slotNodeChanged(Node*)) );
@@ -3139,6 +3140,7 @@ void NodeItemModel::setProject( Project *project )
     kDebug(planDbg())<<this<<m_project<<"->"<<project;
     m_nodemodel.setProject( project );
     if ( project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         connect( m_project, SIGNAL(localeChanged()), this, SLOT(slotLayoutChanged()) );
         connect( m_project, SIGNAL(wbsDefinitionChanged()), this, SLOT(slotWbsDefinitionChanged()) );
         connect( m_project, SIGNAL(nodeChanged(Node*)), this, SLOT(slotNodeChanged(Node*)) );
@@ -4381,6 +4383,7 @@ void MilestoneItemModel::slotNodeMoved( Node *node )
 void MilestoneItemModel::setProject( Project *project )
 {
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         disconnect( m_project, SIGNAL(localeChanged()), this, SLOT(slotLayoutChanged()) );
         disconnect( m_project, SIGNAL(wbsDefinitionChanged()), this, SLOT(slotWbsDefinitionChanged()) );
         disconnect( m_project, SIGNAL(nodeChanged(Node*)), this, SLOT(slotNodeChanged(Node*)) );
@@ -4397,6 +4400,7 @@ void MilestoneItemModel::setProject( Project *project )
     //kDebug(planDbg())<<m_project<<"->"<<project;
     m_nodemodel.setProject( project );
     if ( project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         connect( m_project, SIGNAL(localeChanged()), this, SLOT(slotLayoutChanged()) );
         connect( m_project, SIGNAL(wbsDefinitionChanged()), this, SLOT(slotWbsDefinitionChanged()) );
         connect( m_project, SIGNAL(nodeChanged(Node*)), this, SLOT(slotNodeChanged(Node*)) );
diff --git a/plan/libs/models/kptpertcpmmodel.cpp b/plan/libs/models/kptpertcpmmodel.cpp
index 71745ef..7340c61 100644
--- a/plan/libs/models/kptpertcpmmodel.cpp
+++ b/plan/libs/models/kptpertcpmmodel.cpp
@@ -82,6 +82,7 @@ void CriticalPathItemModel::slotNodeRemoved( Node *node )
 void CriticalPathItemModel::setProject( Project *project )
 {
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         disconnect( m_project, SIGNAL(nodeChanged(Node*)), this, SLOT(slotNodeChanged(Node*)) );
         disconnect( m_project, SIGNAL(nodeToBeAdded(Node*,int)), this, SLOT(slotNodeToBeInserted(Node*,int)) );
         disconnect( m_project, SIGNAL(nodeToBeRemoved(Node*)), this, SLOT(slotNodeToBeRemoved(Node*)) );
@@ -94,6 +95,7 @@ void CriticalPathItemModel::setProject( Project *project )
     m_project = project;
     m_nodemodel.setProject( project );
     if ( project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         connect( m_project, SIGNAL(nodeChanged(Node*)), this, SLOT(slotNodeChanged(Node*)) );
         connect( m_project, SIGNAL(nodeToBeAdded(Node*,int)), this, SLOT(slotNodeToBeInserted(Node*,int)) );
         connect( m_project, SIGNAL(nodeToBeRemoved(Node*)), this, SLOT(slotNodeToBeRemoved(Node*)) );
@@ -354,6 +356,7 @@ void PertResultItemModel::setProject( Project *project )
 {
     clear();
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         disconnect( m_project, SIGNAL(nodeChanged(Node*)), this, SLOT(slotNodeChanged(Node*)) );
         disconnect( m_project, SIGNAL(nodeToBeAdded(Node*,int)), this, SLOT(slotNodeToBeInserted(Node*,int)) );
         disconnect( m_project, SIGNAL(nodeToBeRemoved(Node*)), this, SLOT(slotNodeToBeRemoved(Node*)) );
@@ -366,6 +369,7 @@ void PertResultItemModel::setProject( Project *project )
     m_project = project;
     m_nodemodel.setProject( project );
     if ( project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         connect( m_project, SIGNAL(nodeChanged(Node*)), this, SLOT(slotNodeChanged(Node*)) );
         connect( m_project, SIGNAL(nodeToBeAdded(Node*,int)), this, SLOT(slotNodeToBeInserted(Node*,int)) );
         connect( m_project, SIGNAL(nodeToBeRemoved(Node*)), this, SLOT(slotNodeToBeRemoved(Node*)) );
diff --git a/plan/libs/models/kptrelationmodel.cpp b/plan/libs/models/kptrelationmodel.cpp
index b2617fb..a5acfb6 100644
--- a/plan/libs/models/kptrelationmodel.cpp
+++ b/plan/libs/models/kptrelationmodel.cpp
@@ -241,6 +241,7 @@ void RelationItemModel::slotLayoutChanged()
 void RelationItemModel::setProject( Project *project )
 {
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         disconnect( m_project, SIGNAL(nodeChanged(Node*)), this, SLOT(slotNodeChanged(Node*)) );
         disconnect( m_project, SIGNAL(nodeToBeRemoved(Node*)), this, SLOT(slotNodeToBeRemoved(Node*)) );
 
@@ -254,6 +255,7 @@ void RelationItemModel::setProject( Project *project )
     }
     m_project = project;
     if ( project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         connect( m_project, SIGNAL(nodeChanged(Node*)), this, SLOT(slotNodeChanged(Node*)) );
         connect( m_project, SIGNAL(nodeToBeRemoved(Node*)), this, SLOT(slotNodeToBeRemoved(Node*)) );
 
diff --git a/plan/libs/models/kptresourceallocationmodel.cpp b/plan/libs/models/kptresourceallocationmodel.cpp
index 11f909e..500a24c 100644
--- a/plan/libs/models/kptresourceallocationmodel.cpp
+++ b/plan/libs/models/kptresourceallocationmodel.cpp
@@ -425,6 +425,7 @@ void ResourceAllocationItemModel::slotResourceGroupRemoved( const ResourceGroup
 void ResourceAllocationItemModel::setProject( Project *project )
 {
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         disconnect( m_project, SIGNAL(resourceChanged(Resource*)), this, SLOT(slotResourceChanged(Resource*)) );
         disconnect( m_project, SIGNAL(resourceGroupChanged(ResourceGroup*)), this, SLOT(slotResourceGroupChanged(ResourceGroup*)) );
 
@@ -447,6 +448,7 @@ void ResourceAllocationItemModel::setProject( Project *project )
     }
     m_project = project;
     if ( m_project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         connect( m_project, SIGNAL(resourceChanged(Resource*)), this, SLOT(slotResourceChanged(Resource*)) );
         connect( m_project, SIGNAL(resourceGroupChanged(ResourceGroup*)), this, SLOT(slotResourceGroupChanged(ResourceGroup*)) );
 
diff --git a/plan/libs/models/kptresourceappointmentsmodel.cpp b/plan/libs/models/kptresourceappointmentsmodel.cpp
index b580dfe..f4700c6 100644
--- a/plan/libs/models/kptresourceappointmentsmodel.cpp
+++ b/plan/libs/models/kptresourceappointmentsmodel.cpp
@@ -220,7 +220,10 @@ void ResourceAppointmentsItemModel::setProject( Project *project )
 {
     kDebug(planDbg());
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
+
         disconnect( m_project, SIGNAL(resourceChanged(Resource*)), this, SLOT(slotResourceChanged(Resource*)) );
+
         disconnect( m_project, SIGNAL(resourceGroupChanged(ResourceGroup*)), this, SLOT(slotResourceGroupChanged(ResourceGroup*)) );
 
         disconnect( m_project, SIGNAL(resourceGroupToBeAdded(const ResourceGroup*,int)), this, SLOT(slotResourceGroupToBeInserted(const ResourceGroup*,int)) );
@@ -255,6 +258,7 @@ void ResourceAppointmentsItemModel::setProject( Project *project )
     }
     m_project = project;
     if ( m_project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         connect( m_project, SIGNAL(resourceChanged(Resource*)), this, SLOT(slotResourceChanged(Resource*)) );
         connect( m_project, SIGNAL(resourceGroupChanged(ResourceGroup*)), this, SLOT(slotResourceGroupChanged(ResourceGroup*)) );
 
@@ -1351,6 +1355,8 @@ void ResourceAppointmentsRowModel::setProject( Project *project )
 {
     //kDebug(planDbg())<<project;
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
+
         disconnect( m_project, SIGNAL(resourceGroupToBeAdded(const ResourceGroup*,int)), this, SLOT(slotResourceGroupToBeInserted(const ResourceGroup*,int)) );
 
         disconnect( m_project, SIGNAL(resourceGroupToBeRemoved(const ResourceGroup*)), this, SLOT(slotResourceGroupToBeRemoved(const ResourceGroup*)) );
@@ -1379,6 +1385,8 @@ void ResourceAppointmentsRowModel::setProject( Project *project )
     }
     m_project = project;
     if ( m_project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
+
         connect( m_project, SIGNAL(resourceGroupToBeAdded(const ResourceGroup*,int)), this, SLOT(slotResourceGroupToBeInserted(const ResourceGroup*,int)) );
 
         connect( m_project, SIGNAL(resourceGroupToBeRemoved(const ResourceGroup*)), this, SLOT(slotResourceGroupToBeRemoved(const ResourceGroup*)) );
diff --git a/plan/libs/models/kptresourcemodel.cpp b/plan/libs/models/kptresourcemodel.cpp
index 81f3493..23242df 100644
--- a/plan/libs/models/kptresourcemodel.cpp
+++ b/plan/libs/models/kptresourcemodel.cpp
@@ -599,6 +599,7 @@ void ResourceItemModel::slotLayoutChanged()
 void ResourceItemModel::setProject( Project *project )
 {
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         disconnect( m_project, SIGNAL(localeChanged()), this, SLOT(slotLayoutChanged()) );
         disconnect( m_project, SIGNAL(resourceChanged(Resource*)), this, SLOT(slotResourceChanged(Resource*)) );
         disconnect( m_project, SIGNAL(resourceGroupChanged(ResourceGroup*)), this, SLOT(slotResourceGroupChanged(ResourceGroup*)) );
@@ -623,6 +624,7 @@ void ResourceItemModel::setProject( Project *project )
     }
     m_project = project;
     if ( m_project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         connect( m_project, SIGNAL(localeChanged()), this, SLOT(slotLayoutChanged()) );
         connect( m_project, SIGNAL(resourceChanged(Resource*)), this, SLOT(slotResourceChanged(Resource*)) );
         connect( m_project, SIGNAL(resourceGroupChanged(ResourceGroup*)), this, SLOT(slotResourceGroupChanged(ResourceGroup*)) );
@@ -711,7 +713,7 @@ QModelIndex ResourceItemModel::parent( const QModelIndex &index ) const
     }
     //kDebug(planDbg())<<index.internalPointer()<<":"<<index.row()<<","<<index.column();
 
-    Resource *r = qobject_cast<Resource*>( object( index ) );
+    Resource *r = resource( index );
     if ( r && r->parentGroup() ) {
         // only resources have parent
         int row = m_project->indexOf(  r->parentGroup() );
@@ -732,8 +734,7 @@ QModelIndex ResourceItemModel::index( int row, int column, const QModelIndex &pa
         }
         return QModelIndex();
     }
-    QObject *p = object( parent );
-    ResourceGroup *g = qobject_cast<ResourceGroup*>( p );
+    ResourceGroup *g = group( parent );
     if ( g ) {
         if ( row < g->numResources() ) {
             return createIndex( row, column, g->resourceAt( row ) );
@@ -782,8 +783,7 @@ int ResourceItemModel::rowCount( const QModelIndex &parent ) const
     if ( ! parent.isValid() ) {
         return m_project->numResourceGroups();
     }
-    QObject *p = object( parent );
-    ResourceGroup *g = qobject_cast<ResourceGroup*>( p );
+    ResourceGroup *g = group( parent );
     if ( g ) {
         return g->numResources();
     }
@@ -1148,6 +1148,8 @@ QObject *ResourceItemModel::object( const QModelIndex &index ) const
 {
     QObject *o = 0;
     if ( index.isValid() ) {
+        Q_ASSERT( m_project );
+        Q_ASSERT(m_project->resourceGroups().contains(static_cast<ResourceGroup*>(index.internalPointer())) || m_project->resourceList().contains(static_cast<Resource*>(index.internalPointer())));
         o = static_cast<QObject*>( index.internalPointer() );
         Q_ASSERT( o );
     }
diff --git a/plan/libs/models/kptschedulemodel.cpp b/plan/libs/models/kptschedulemodel.cpp
index e3ce298..4d47ee5 100644
--- a/plan/libs/models/kptschedulemodel.cpp
+++ b/plan/libs/models/kptschedulemodel.cpp
@@ -171,6 +171,8 @@ void ScheduleItemModel::slotScheduleRemoved( const MainSchedule * )
 void ScheduleItemModel::setProject( Project *project )
 {
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
+
         disconnect( m_project, SIGNAL(scheduleManagerChanged(ScheduleManager*)), this, SLOT(slotManagerChanged(ScheduleManager*)) );
 
         disconnect( m_project, SIGNAL(scheduleManagerToBeAdded(const ScheduleManager*,int)), this, SLOT(slotScheduleManagerToBeInserted(const ScheduleManager*,int)) );
@@ -197,6 +199,8 @@ void ScheduleItemModel::setProject( Project *project )
     }
     m_project = project;
     if ( m_project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
+
         connect( m_project, SIGNAL(scheduleManagerChanged(ScheduleManager*)), this, SLOT(slotManagerChanged(ScheduleManager*)) );
 
         connect( m_project, SIGNAL(scheduleManagerToBeAdded(const ScheduleManager*,int)), this, SLOT(slotScheduleManagerToBeInserted(const ScheduleManager*,int)) );
@@ -1074,10 +1078,17 @@ void ScheduleLogItemModel::slotScheduleRemoved( const MainSchedule *sch )
     kDebug(planDbg())<<m_schedule<<sch;
 }
 
+void ScheduleLogItemModel::projectDeleted()
+{
+    setProject(0);
+}
+
 void ScheduleLogItemModel::setProject( Project *project )
 {
     kDebug(planDbg())<<m_project<<"->"<<project;
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
+
         disconnect( m_project, SIGNAL(scheduleManagerChanged(ScheduleManager*)), this, SLOT(slotManagerChanged(ScheduleManager*)) );
 
         disconnect( m_project, SIGNAL(scheduleManagerToBeRemoved(const ScheduleManager*)), this, SLOT(slotScheduleManagerToBeRemoved(const ScheduleManager*)) );
@@ -1096,6 +1107,8 @@ void ScheduleLogItemModel::setProject( Project *project )
     }
     m_project = project;
     if ( m_project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
+
         connect( m_project, SIGNAL(scheduleManagerChanged(ScheduleManager*)), this, SLOT(slotManagerChanged(ScheduleManager*)) );
 
         connect( m_project, SIGNAL(scheduleManagerToBeRemoved(const ScheduleManager*)), this, SLOT(slotScheduleManagerToBeRemoved(const ScheduleManager*)) );
diff --git a/plan/libs/models/kptschedulemodel.h b/plan/libs/models/kptschedulemodel.h
index c09d8fb..acc75b4 100644
--- a/plan/libs/models/kptschedulemodel.h
+++ b/plan/libs/models/kptschedulemodel.h
@@ -203,6 +203,8 @@ protected Q_SLOTS:
 
     void slotLogInserted( MainSchedule*, int firstrow, int lastrow );
 
+    void projectDeleted();
+
 protected:
     void addLogEntry( const Schedule::Log &log, int row );
 
diff --git a/plan/libs/models/kpttaskstatusmodel.cpp b/plan/libs/models/kpttaskstatusmodel.cpp
index e0693b8..9fb3b37 100644
--- a/plan/libs/models/kpttaskstatusmodel.cpp
+++ b/plan/libs/models/kpttaskstatusmodel.cpp
@@ -126,6 +126,7 @@ void TaskStatusItemModel::setProject( Project *project )
 {
     clear();
     if ( m_project ) {
+        disconnect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         disconnect( m_project, SIGNAL(localeChanged()), this, SLOT(slotLayoutChanged()) );
         disconnect( m_project, SIGNAL(wbsDefinitionChanged()), this, SLOT(slotWbsDefinitionChanged()) );
         disconnect( m_project, SIGNAL(nodeChanged(Node*)), this, SLOT(slotNodeChanged(Node*)) );
@@ -140,6 +141,7 @@ void TaskStatusItemModel::setProject( Project *project )
     m_project = project;
     m_nodemodel.setProject( project );
     if ( project ) {
+        connect(m_project, SIGNAL(aboutToBeDeleted()), this, SLOT(projectDeleted()));
         connect( m_project, SIGNAL(localeChanged()), this, SLOT(slotLayoutChanged()) );
         connect( m_project, SIGNAL(wbsDefinitionChanged()), this, SLOT(slotWbsDefinitionChanged()) );
         connect( m_project, SIGNAL(nodeChanged(Node*)), this, SLOT(slotNodeChanged(Node*)) );
-- 
2.7.4