src/ldDocument.cpp

changeset 985
ed7b31b9f904
parent 984
a7b6f987d269
child 988
ac4a2ae54f76
equal deleted inserted replaced
984:a7b6f987d269 985:ed7b31b9f904
309 QFile* OpenLDrawFile (QString relpath, bool subdirs, QString* pathpointer) 309 QFile* OpenLDrawFile (QString relpath, bool subdirs, QString* pathpointer)
310 { 310 {
311 print ("Opening %1...\n", relpath); 311 print ("Opening %1...\n", relpath);
312 QString path = FindDocumentPath (relpath, subdirs); 312 QString path = FindDocumentPath (relpath, subdirs);
313 313
314 if (pathpointer != nullptr) 314 if (pathpointer)
315 *pathpointer = path; 315 *pathpointer = path;
316 316
317 if (path.isEmpty()) 317 if (path.isEmpty())
318 return nullptr; 318 return nullptr;
319 319
382 } 382 }
383 383
384 if (not fp) 384 if (not fp)
385 return nullptr; 385 return nullptr;
386 386
387 LDDocument* load = (fileToOverride != nullptr ? fileToOverride : g_win->newDocument (implicit)); 387 LDDocument* load = (fileToOverride ? fileToOverride : g_win->newDocument (implicit));
388 load->setFullPath (fullpath); 388 load->setFullPath (fullpath);
389 load->setName (LDDocument::shortenName (load->fullPath())); 389 load->setName (LDDocument::shortenName (load->fullPath()));
390 390
391 // Loading the file shouldn't count as actual edits to the document. 391 // Loading the file shouldn't count as actual edits to the document.
392 load->history()->setIgnoring (true); 392 load->history()->setIgnoring (true);
531 } 531 }
532 } 532 }
533 533
534 // We cannot open this file if the document this would replace is not 534 // We cannot open this file if the document this would replace is not
535 // safe to close. 535 // safe to close.
536 if (documentToReplace != nullptr and not documentToReplace->isSafeToClose()) 536 if (documentToReplace and not documentToReplace->isSafeToClose())
537 return; 537 return;
538 538
539 g_loadingMainFile = true; 539 g_loadingMainFile = true;
540 540
541 // If we're replacing an existing document, clear the document and 541 // If we're replacing an existing document, clear the document and
542 // make it ready for being loaded to. 542 // make it ready for being loaded to.
543 if (documentToReplace != nullptr) 543 if (documentToReplace)
544 { 544 {
545 file = documentToReplace; 545 file = documentToReplace;
546 file->clear(); 546 file->clear();
547 } 547 }
548 548
611 path = fullPath(); 611 path = fullPath();
612 612
613 // If the second object in the list holds the file name, update that now. 613 // If the second object in the list holds the file name, update that now.
614 LDObject* nameObject = getObject (1); 614 LDObject* nameObject = getObject (1);
615 615
616 if (nameObject != nullptr and nameObject->type() == OBJ_Comment) 616 if (nameObject and nameObject->type() == OBJ_Comment)
617 { 617 {
618 LDComment* nameComment = static_cast<LDComment*> (nameObject); 618 LDComment* nameComment = static_cast<LDComment*> (nameObject);
619 619
620 if (nameComment->text().left (6) == "Name: ") 620 if (nameComment->text().left (6) == "Name: ")
621 { 621 {
625 } 625 }
626 } 626 }
627 627
628 QByteArray data; 628 QByteArray data;
629 629
630 if (sizeptr != nullptr) 630 if (sizeptr)
631 *sizeptr = 0; 631 *sizeptr = 0;
632 632
633 // File is open, now save the model to it. Note that LDraw requires files to have DOS line endings. 633 // File is open, now save the model to it. Note that LDraw requires files to have DOS line endings.
634 for (LDObject* obj : objects()) 634 for (LDObject* obj : objects())
635 { 635 {
636 QByteArray subdata ((obj->asText() + "\r\n").toUtf8()); 636 QByteArray subdata ((obj->asText() + "\r\n").toUtf8());
637 data.append (subdata); 637 data.append (subdata);
638 638
639 if (sizeptr != nullptr) 639 if (sizeptr)
640 *sizeptr += subdata.size(); 640 *sizeptr += subdata.size();
641 } 641 }
642 642
643 QFile f (path); 643 QFile f (path);
644 644
931 if (obj->type() == OBJ_Subfile) 931 if (obj->type() == OBJ_Subfile)
932 { 932 {
933 LDSubfile* ref = static_cast<LDSubfile*> (obj); 933 LDSubfile* ref = static_cast<LDSubfile*> (obj);
934 LDDocument* fileInfo = GetDocument (ref->fileInfo()->name()); 934 LDDocument* fileInfo = GetDocument (ref->fileInfo()->name());
935 935
936 if (fileInfo != nullptr) 936 if (fileInfo)
937 { 937 {
938 ref->setFileInfo (fileInfo); 938 ref->setFileInfo (fileInfo);
939 } 939 }
940 else 940 else
941 { 941 {
972 // 972 //
973 void LDDocument::addObjects (const LDObjectList& objs) 973 void LDDocument::addObjects (const LDObjectList& objs)
974 { 974 {
975 for (LDObject* obj : objs) 975 for (LDObject* obj : objs)
976 { 976 {
977 if (obj != nullptr) 977 if (obj)
978 addObject (obj); 978 addObject (obj);
979 } 979 }
980 } 980 }
981 981
982 // ============================================================================= 982 // =============================================================================
1124 continue; 1124 continue;
1125 } 1125 }
1126 1126
1127 LDPolygon* data = obj->getPolygon(); 1127 LDPolygon* data = obj->getPolygon();
1128 1128
1129 if (data != nullptr) 1129 if (data)
1130 { 1130 {
1131 m_polygonData << *data; 1131 m_polygonData << *data;
1132 delete data; 1132 delete data;
1133 } 1133 }
1134 } 1134 }
1182 if (m_config->useLogoStuds() and renderinline) 1182 if (m_config->useLogoStuds() and renderinline)
1183 { 1183 {
1184 // Ensure logoed studs are loaded first 1184 // Ensure logoed studs are loaded first
1185 LoadLogoStuds(); 1185 LoadLogoStuds();
1186 1186
1187 if (name() == "stud.dat" and g_logoedStud != nullptr) 1187 if (name() == "stud.dat" and g_logoedStud)
1188 return g_logoedStud->inlineContents (deep, renderinline); 1188 return g_logoedStud->inlineContents (deep, renderinline);
1189 else if (name() == "stud2.dat" and g_logoedStud2 != nullptr) 1189 else if (name() == "stud2.dat" and g_logoedStud2)
1190 return g_logoedStud2->inlineContents (deep, renderinline); 1190 return g_logoedStud2->inlineContents (deep, renderinline);
1191 } 1191 }
1192 1192
1193 LDObjectList objs, objcache; 1193 LDObjectList objs, objcache;
1194 1194

mercurial