269 |
269 |
270 fp->deleteLater(); |
270 fp->deleteLater(); |
271 return nullptr; |
271 return nullptr; |
272 } |
272 } |
273 |
273 |
274 LDObjectList DocumentManager::loadFileContents (QFile* fp, int* numWarnings, bool* ok) |
274 void DocumentManager::loadFileContents(QIODevice* input, Model& model, int* numWarnings, bool* ok) |
275 { |
275 { |
276 LDObjectList objs; |
|
277 |
|
278 if (numWarnings) |
276 if (numWarnings) |
279 *numWarnings = 0; |
277 *numWarnings = 0; |
280 |
278 |
281 DocumentLoader* loader = new DocumentLoader (m_loadingMainFile); |
279 DocumentLoader* loader = new DocumentLoader {&model, m_loadingMainFile}; |
282 loader->read (fp); |
280 loader->read(input); |
283 loader->start(); |
281 loader->start(); |
284 |
282 |
285 // After start() returns, if the loader isn't done yet, it's delaying |
283 // After start() returns, if the loader isn't done yet, it's delaying |
286 // its next iteration through the event loop. We need to catch this here |
284 // its next iteration through the event loop. We need to catch this here |
287 // by telling the event loop to tick, which will tick the file loader again. |
285 // by telling the event loop to tick, which will tick the file loader again. |
290 qApp->processEvents(); |
288 qApp->processEvents(); |
291 |
289 |
292 // If we wanted the success value, supply that now |
290 // If we wanted the success value, supply that now |
293 if (ok) |
291 if (ok) |
294 *ok = not loader->hasAborted(); |
292 *ok = not loader->hasAborted(); |
295 |
|
296 objs = loader->objects(); |
|
297 delete loader; |
|
298 return objs; |
|
299 } |
293 } |
300 |
294 |
301 LDDocument* DocumentManager::openDocument (QString path, bool search, bool implicit, LDDocument* fileToOverride, |
295 LDDocument* DocumentManager::openDocument (QString path, bool search, bool implicit, LDDocument* fileToOverride, |
302 bool* aborted) |
296 bool* aborted) |
303 { |
297 { |
333 // Loading the file shouldn't count as actual edits to the document. |
327 // Loading the file shouldn't count as actual edits to the document. |
334 load->history()->setIgnoring (true); |
328 load->history()->setIgnoring (true); |
335 |
329 |
336 int numWarnings; |
330 int numWarnings; |
337 bool ok; |
331 bool ok; |
338 LDObjectList objs = loadFileContents (fp, &numWarnings, &ok); |
332 Model model; |
|
333 loadFileContents(fp, model, &numWarnings, &ok); |
|
334 load->merge(model); |
339 fp->close(); |
335 fp->close(); |
340 fp->deleteLater(); |
336 fp->deleteLater(); |
341 |
337 |
342 if (aborted) |
338 if (aborted) |
343 *aborted = ok == false; |
339 *aborted = ok == false; |
409 |
403 |
410 if (m_logoedStud and m_logoedStud2) |
404 if (m_logoedStud and m_logoedStud2) |
411 print (tr ("Logoed studs loaded.\n")); |
405 print (tr ("Logoed studs loaded.\n")); |
412 } |
406 } |
413 |
407 |
414 bool DocumentManager::preInline (LDDocument* doc, LDObjectList& objs, bool deep, bool renderinline) |
408 bool DocumentManager::preInline (LDDocument* doc, Model& model, bool deep, bool renderinline) |
415 { |
409 { |
416 // Possibly substitute with logoed studs: |
410 // Possibly substitute with logoed studs: |
417 // stud.dat -> stud-logo.dat |
411 // stud.dat -> stud-logo.dat |
418 // stud2.dat -> stud-logo2.dat |
412 // stud2.dat -> stud-logo2.dat |
419 if (m_config->useLogoStuds() and renderinline) |
413 if (m_config->useLogoStuds() and renderinline) |
421 // Ensure logoed studs are loaded first |
415 // Ensure logoed studs are loaded first |
422 loadLogoedStuds(); |
416 loadLogoedStuds(); |
423 |
417 |
424 if (doc->name() == "stud.dat" and m_logoedStud) |
418 if (doc->name() == "stud.dat" and m_logoedStud) |
425 { |
419 { |
426 objs = m_logoedStud->inlineContents (deep, renderinline); |
420 m_logoedStud->inlineContents(model, deep, renderinline); |
427 return true; |
421 return true; |
428 } |
422 } |
429 else if (doc->name() == "stud2.dat" and m_logoedStud2) |
423 else if (doc->name() == "stud2.dat" and m_logoedStud2) |
430 { |
424 { |
431 objs = m_logoedStud2->inlineContents (deep, renderinline); |
425 m_logoedStud2->inlineContents(model, deep, renderinline); |
432 return true; |
426 return true; |
433 } |
427 } |
434 } |
428 } |
435 return false; |
429 return false; |
436 } |
430 } |