--- a/src/ldDocument.cpp Sun Apr 12 23:02:26 2015 +0300 +++ b/src/ldDocument.cpp Tue Jul 07 21:35:20 2015 +0300 @@ -181,7 +181,7 @@ // Implicit files are not compiled by the GL renderer. Now that this // part is no longer implicit, it needs to be compiled. - if (g_win != null) + if (g_win != nullptr) g_win->R()->compiler()->compileDocument (self()); } else @@ -190,7 +190,7 @@ print ("Closed %1", name()); } - if (g_win != null) + if (g_win != nullptr) g_win->updateDocumentList(); // If the current document just became implicit (e.g. it was 'closed'), @@ -218,7 +218,7 @@ { for (LDDocumentWeakPtr weakfile : g_allDocuments) { - if (weakfile == null) + if (weakfile == nullptr) continue; LDDocumentPtr file (weakfile.toStrongRef()); @@ -278,7 +278,7 @@ for (LDDocumentWeakPtr doc : g_allDocuments) { - if (doc == null) + if (doc == nullptr) continue; QString partpath = format ("%1/%2", Dirname (doc.toStrongRef()->fullPath()), relpath); @@ -341,11 +341,11 @@ print ("Opening %1...\n", relpath); QString path = FindDocumentPath (relpath, subdirs); - if (pathpointer != null) + if (pathpointer != nullptr) *pathpointer = path; if (path.isEmpty()) - return null; + return nullptr; QFile* fp = new QFile (path); @@ -353,7 +353,7 @@ return fp; fp->deleteLater(); - return null; + return nullptr; } // ============================================================================= @@ -382,7 +382,7 @@ connect (dlg, SIGNAL (rejected()), this, SLOT (abort())); } else - dlg = null; + dlg = nullptr; // Begin working work (0); @@ -424,7 +424,7 @@ print ("Couldn't parse line #%1: %2", progress() + 1, obj.staticCast<LDError>()->reason()); - if (warnings() != null) + if (warnings() != nullptr) (*warnings())++; } @@ -539,7 +539,7 @@ if (not fp) return LDDocumentPtr(); - LDDocumentPtr load = (fileToOverride != null ? fileToOverride : LDDocument::createNew()); + LDDocumentPtr load = (fileToOverride != nullptr ? fileToOverride : LDDocument::createNew()); load->setImplicit (implicit); load->setFullPath (fullpath); load->setName (LDDocument::shortenName (load->fullPath())); @@ -690,7 +690,7 @@ for (LDDocumentWeakPtr doc : g_allDocuments) { - if (doc != null and doc.toStrongRef()->name() == shortName) + if (doc != nullptr and doc.toStrongRef()->name() == shortName) { documentToReplace = doc; break; @@ -699,14 +699,14 @@ // We cannot open this file if the document this would replace is not // safe to close. - if (documentToReplace != null and not documentToReplace->isSafeToClose()) + if (documentToReplace != nullptr and not documentToReplace->isSafeToClose()) return; g_loadingMainFile = true; // If we're replacing an existing document, clear the document and // make it ready for being loaded to. - if (documentToReplace != null) + if (documentToReplace != nullptr) { file = documentToReplace; file->clear(); @@ -714,7 +714,7 @@ file = OpenDocument (path, false, false, file); - if (file == null) + if (file == nullptr) { if (not g_aborted) { @@ -785,7 +785,7 @@ // If the second object in the list holds the file name, update that now. LDObjectPtr nameObject = getObject (1); - if (nameObject != null and nameObject->type() == OBJ_Comment) + if (nameObject != nullptr and nameObject->type() == OBJ_Comment) { LDCommentPtr nameComment = nameObject.staticCast<LDComment>(); @@ -799,7 +799,7 @@ QByteArray data; - if (sizeptr != null) + if (sizeptr != nullptr) *sizeptr = 0; // File is open, now save the model to it. Note that LDraw requires files to @@ -809,7 +809,7 @@ QByteArray subdata ((obj->asText() + "\r\n").toUtf8()); data.append (subdata); - if (sizeptr != null) + if (sizeptr != nullptr) *sizeptr += subdata.size(); } @@ -889,7 +889,7 @@ return v; } -static int32 StringToNumber (QString a, bool* ok = null) +static int32 StringToNumber (QString a, bool* ok = nullptr) { int base = 10; @@ -949,9 +949,9 @@ // need to handle MLCAD-style invertnext, clip and noclip separately. if (commentTextSimplified == "BFC CERTIFY INVERTNEXT") return LDSpawn<LDBFC> (BFCStatement::InvertNext); - elif (commentTextSimplified == "BFC CERTIFY CLIP") + else if (commentTextSimplified == "BFC CERTIFY CLIP") return LDSpawn<LDBFC> (BFCStatement::Clip); - elif (commentTextSimplified == "BFC CERTIFY NOCLIP") + else if (commentTextSimplified == "BFC CERTIFY NOCLIP") return LDSpawn<LDBFC> (BFCStatement::NoClip); } @@ -1107,7 +1107,7 @@ LDSubfilePtr ref = obj.staticCast<LDSubfile>(); LDDocumentPtr fileInfo = GetDocument (ref->fileInfo()->name()); - if (fileInfo != null) + if (fileInfo != nullptr) { ref->setFileInfo (fileInfo); } @@ -1148,7 +1148,7 @@ { for (LDObjectPtr obj : objs) { - if (obj != null) + if (obj != nullptr) addObject (obj); } } @@ -1190,7 +1190,6 @@ { int idx = obj->lineNumber(); obj->deselect(); - assert (m_objects[idx] == obj); if (not isImplicit() and not (flags() & DOCF_IsBeingDestroyed)) { @@ -1219,24 +1218,25 @@ // void LDDocument::setObject (int idx, LDObjectPtr obj) { - assert (idx >= 0 and idx < m_objects.size()); + if (idx >= 0 and idx < m_objects.size()) + { + // Mark this change to history + if (not m_history->isIgnoring()) + { + QString oldcode = getObject (idx)->asText(); + QString newcode = obj->asText(); + *m_history << new EditHistory (idx, oldcode, newcode); + } - // Mark this change to history - if (not m_history->isIgnoring()) - { - QString oldcode = getObject (idx)->asText(); - QString newcode = obj->asText(); - *m_history << new EditHistory (idx, oldcode, newcode); + m_objectVertices.remove (m_objects[idx]); + m_objects[idx]->deselect(); + m_objects[idx]->setDocument (LDDocumentPtr()); + obj->setDocument (self()); + addKnownVertices (obj); + g_win->R()->compileObject (obj); + m_objects[idx] = obj; + needVertexMerge(); } - - m_objectVertices.remove (m_objects[idx]); - m_objects[idx]->deselect(); - m_objects[idx]->setDocument (LDDocumentPtr()); - obj->setDocument (self()); - addKnownVertices (obj); - g_win->R()->compileObject (obj); - m_objects[idx] = obj; - needVertexMerge(); } // ============================================================================= @@ -1296,7 +1296,7 @@ LDPolygon* data = obj->getPolygon(); - if (data != null) + if (data != nullptr) { m_polygonData << *data; delete data; @@ -1330,7 +1330,7 @@ for (QVector<Vertex> const& verts : m_objectVertices) m_vertices << verts; - RemoveDuplicates (m_vertices); + removeDuplicates (m_vertices); m_needVertexMerge = false; } @@ -1354,9 +1354,9 @@ // Ensure logoed studs are loaded first LoadLogoStuds(); - if (name() == "stud.dat" and g_logoedStud != null) + if (name() == "stud.dat" and g_logoedStud != nullptr) return g_logoedStud->inlineContents (deep, renderinline); - elif (name() == "stud2.dat" and g_logoedStud2 != null) + else if (name() == "stud2.dat" and g_logoedStud2 != nullptr) return g_logoedStud2->inlineContents (deep, renderinline); } @@ -1399,7 +1399,7 @@ { // Implicit files were loaded for caching purposes and must never be set // current. - if (f != null and f->isImplicit()) + if (f != nullptr and f->isImplicit()) return; g_currentDocument = f; @@ -1457,26 +1457,24 @@ // void LDDocument::addToSelection (LDObjectPtr obj) // [protected] { - if (obj->isSelected()) - return; - - assert (obj->document() == self()); - m_sel << obj; - g_win->R()->compileObject (obj); - obj->setSelected (true); + if (not obj->isSelected() and obj->document() == self()) + { + m_sel << obj; + g_win->R()->compileObject (obj); + obj->setSelected (true); + } } // ============================================================================= // void LDDocument::removeFromSelection (LDObjectPtr obj) // [protected] { - if (not obj->isSelected()) - return; - - assert (obj->document() == self()); - m_sel.removeOne (obj); - g_win->R()->compileObject (obj); - obj->setSelected (false); + if (obj->isSelected() and obj->document() == self()) + { + m_sel.removeOne (obj); + g_win->R()->compileObject (obj); + obj->setSelected (false); + } } // ============================================================================= @@ -1485,8 +1483,6 @@ { for (LDObjectPtr obj : m_sel) removeFromSelection (obj); - - assert (m_sel.isEmpty()); } // ============================================================================= @@ -1502,10 +1498,13 @@ { int a = m_objects.indexOf (one); int b = m_objects.indexOf (other); - assert (a != b and a != -1 and b != -1); - m_objects[b] = one; - m_objects[a] = other; - addToHistory (new SwapHistory (one->id(), other->id())); + + if (a != b and a != -1 and b != -1) + { + m_objects[b] = one; + m_objects[a] = other; + addToHistory (new SwapHistory (one->id(), other->id())); + } } // =============================================================================