182 else |
182 else |
183 { |
183 { |
184 g_explicitDocuments.removeOne (self().toStrongRef()); |
184 g_explicitDocuments.removeOne (self().toStrongRef()); |
185 print ("Closed %1", name()); |
185 print ("Closed %1", name()); |
186 int count = 0; |
186 int count = 0; |
187 for (LDObjectPtr obj : g_allObjects) |
187 |
|
188 for (LDObjectWeakPtr obj : g_allObjects) |
188 { |
189 { |
189 LDSubfilePtr ref = obj.dynamicCast<LDSubfile>(); |
190 if (obj == null) |
190 if (ref && ref->fileInfo() == self()) |
191 continue; |
|
192 |
|
193 LDSubfilePtr ref = obj.toStrongRef().dynamicCast<LDSubfile>(); |
|
194 |
|
195 if (ref != null && ref->fileInfo() == self()) |
191 count++; |
196 count++; |
192 } |
197 } |
193 } |
198 } |
194 |
199 |
195 if (g_win != null) |
200 if (g_win != null) |
216 |
221 |
217 // ============================================================================= |
222 // ============================================================================= |
218 // |
223 // |
219 LDDocumentPtr findDocument (QString name) |
224 LDDocumentPtr findDocument (QString name) |
220 { |
225 { |
221 for (LDDocumentPtr file : g_allDocuments) |
226 for (LDDocumentWeakPtr file : g_allDocuments) |
222 { |
227 { |
223 if (file->name() == name) |
228 if (file != null && file.toStrongRef()->name() == name) |
224 return file; |
229 return file.toStrongRef(); |
225 } |
230 } |
226 |
231 |
227 return LDDocumentPtr(); |
232 return LDDocumentPtr(); |
228 } |
233 } |
229 |
234 |
271 |
276 |
272 // Try find it relative to other currently open documents. We want a file |
277 // Try find it relative to other currently open documents. We want a file |
273 // in the immediate vicinity of a current model to override stock LDraw stuff. |
278 // in the immediate vicinity of a current model to override stock LDraw stuff. |
274 QString reltop = basename (dirname (relpath)); |
279 QString reltop = basename (dirname (relpath)); |
275 |
280 |
276 for (LDDocumentPtr doc : g_allDocuments) |
281 for (LDDocumentWeakPtr doc : g_allDocuments) |
277 { |
282 { |
278 if (doc->fullPath().isEmpty()) |
283 if (doc == null) |
279 continue; |
284 continue; |
280 |
285 |
281 QString partpath = format ("%1/%2", dirname (doc->fullPath()), relpath); |
286 QString partpath = format ("%1/%2", dirname (doc.toStrongRef()->fullPath()), relpath); |
282 QFile f (partpath); |
287 QFile f (partpath); |
283 |
288 |
284 if (f.exists()) |
289 if (f.exists()) |
285 { |
290 { |
286 // ensure we don't mix subfiles and 48-primitives with non-subfiles and non-48 |
291 // ensure we don't mix subfiles and 48-primitives with non-subfiles and non-48 |