r22792 by jghali - Refactor NodeEditContext: exit functions early when possible

scribus-commit scribus-commit at lists.scribus.net
Sun Dec 16 19:47:36 UTC 2018


Author: jghali
Date: Sun Dec 16 19:47:36 2018
New Revision: 22792

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22792
Log:
Refactor NodeEditContext: exit functions early when possible

Modified:
    trunk/Scribus/scribus/nodeeditcontext.cpp

Modified: trunk/Scribus/scribus/nodeeditcontext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22792&path=/trunk/Scribus/scribus/nodeeditcontext.cpp
==============================================================================
--- trunk/Scribus/scribus/nodeeditcontext.cpp	(original)
+++ trunk/Scribus/scribus/nodeeditcontext.cpp	Sun Dec 16 19:47:36 2018
@@ -96,31 +96,31 @@
 	ScribusDoc* Doc = currItem->doc();
 	UndoManager* undoManager = UndoManager::instance();
 	ScItemState<QPair<FPointArray, FPointArray> >* state = nullptr;
-	
-	if (nodeTransaction) // is there the old clip stored for the undo action
-	{
-		FPointArray newClip(Doc->nodeEdit.m_isContourLine ? currItem->ContourLine : currItem->PoLine);
-		if (UndoManager::undoEnabled() && oldClip && (*oldClip != newClip))
-		{
-			QString name = Doc->nodeEdit.m_isContourLine ? Um::EditContour : Um::EditShape;
-			state = new ScItemState<QPair<FPointArray, FPointArray> >(name);
-			state->set("EDIT_SHAPE_OR_CONTOUR");
-			state->set("IS_CONTOUR", Doc->nodeEdit.m_isContourLine);
-			state->setItem(qMakePair(*oldClip, newClip));
-			state->set("OLD_X", m_oldItemX);
-			state->set("OLD_Y", m_oldItemY);
-			state->set("NEW_X", currItem->xPos());
-			state->set("NEW_Y", currItem->yPos());
-			undoManager->action(currItem, state);
-			nodeTransaction.commit();
-		}
-		else
-			nodeTransaction.cancel();
+
+	if (nodeTransaction.isNull()) // is there the old clip stored for the undo action
+		return;
+	
+	FPointArray newClip(Doc->nodeEdit.m_isContourLine ? currItem->ContourLine : currItem->PoLine);
+	if (UndoManager::undoEnabled() && oldClip && (*oldClip != newClip))
+	{
+		QString name = Doc->nodeEdit.m_isContourLine ? Um::EditContour : Um::EditShape;
+		state = new ScItemState<QPair<FPointArray, FPointArray> >(name);
+		state->set("EDIT_SHAPE_OR_CONTOUR");
+		state->set("IS_CONTOUR", Doc->nodeEdit.m_isContourLine);
+		state->setItem(qMakePair(*oldClip, newClip));
+		state->set("OLD_X", m_oldItemX);
+		state->set("OLD_Y", m_oldItemY);
+		state->set("NEW_X", currItem->xPos());
+		state->set("NEW_Y", currItem->yPos());
+		undoManager->action(currItem, state);
+		nodeTransaction.commit();
+	}
+	else
+		nodeTransaction.cancel();
 		
-		nodeTransaction.reset();
-		delete oldClip;
-		oldClip = nullptr;
-	}
+	nodeTransaction.reset();
+	delete oldClip;
+	oldClip = nullptr;
 }
 
 
@@ -133,25 +133,25 @@
 	UndoManager* undoManager = UndoManager::instance();
 	ScItemState<QPair<FPointArray, FPointArray> >* state = nullptr;
 	
-	if (nodeTransaction) // is there the old clip stored for the undo action
-	{
-		FPointArray newClip(Doc->nodeEdit.m_isContourLine ? currItem->ContourLine : currItem->PoLine);
-		if (UndoManager::undoEnabled() && oldClip && (*oldClip != newClip))
-		{
-			QString name = Doc->nodeEdit.m_isContourLine ? Um::EditContour : Um::EditShape;
-			state = new ScItemState<QPair<FPointArray, FPointArray> >(name);
-			state->set("EDIT_SHAPE_OR_CONTOUR");
-			state->set("IS_CONTOUR", Doc->nodeEdit.m_isContourLine);
-			state->setItem(qMakePair(*oldClip, newClip));
-			undoManager->setUndoEnabled(false);
-		}
-		else
-		{
-			delete oldClip;
-			oldClip = nullptr;
-			nodeTransaction.cancel();
-			nodeTransaction.reset();
-		}
+	if (nodeTransaction.isNull()) // is there the old clip stored for the undo action
+		return nullptr;
+
+	FPointArray newClip(Doc->nodeEdit.m_isContourLine ? currItem->ContourLine : currItem->PoLine);
+	if (UndoManager::undoEnabled() && oldClip && (*oldClip != newClip))
+	{
+		QString name = Doc->nodeEdit.m_isContourLine ? Um::EditContour : Um::EditShape;
+		state = new ScItemState<QPair<FPointArray, FPointArray> >(name);
+		state->set("EDIT_SHAPE_OR_CONTOUR");
+		state->set("IS_CONTOUR", Doc->nodeEdit.m_isContourLine);
+		state->setItem(qMakePair(*oldClip, newClip));
+		undoManager->setUndoEnabled(false);
+	}
+	else
+	{
+		delete oldClip;
+		oldClip = nullptr;
+		nodeTransaction.cancel();
+		nodeTransaction.reset();
 	}
 	return state;
 }
@@ -501,6 +501,5 @@
 	}
 	delete oldClip;
 	oldClip = nullptr;
-	
-}
-
+}
+




More information about the scribus-commit mailing list