r18803 by jghali - #12038: Undo crashes Scribus after changing the page arrangement

scribus-commit scribus-commit at lists.scribus.net
Sat Feb 8 22:06:55 UTC 2014


Author: jghali
Date: Sat Feb  8 22:06:55 2014
New Revision: 18803

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=18803
Log:
#12038: Undo crashes Scribus after changing the page arrangement

Modified:
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribusdoc.cpp

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18803&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Sat Feb  8 22:06:55 2014
@@ -55,6 +55,7 @@
 #include <QQuickView>
 //>>
 #include <QRegExp>
+#include <QScopedPointer>
 #include <QStyleFactory>
 #include <QTableWidget>
 #include <QTextCodec>
@@ -7308,21 +7309,22 @@
 {
 	if (HaveDoc && doc->appMode == modeEditClip)
 		view->requestMode(submodeEndNodeEdit);
-	MovePages *dia = new MovePages(this, doc->currentPage()->pageNr()+1, doc->Pages->count(), true);
+	int currentPage = doc->currentPage()->pageNr();
+	QScopedPointer<MovePages> dia(new MovePages(this, currentPage + 1, doc->Pages->count(), true));
 	if (dia->exec())
 	{
 		int from = dia->getFromPage();
 		int to = dia->getToPage();
 		int wie = dia->getWhere();
 		int wo = dia->getWherePage();
-		if (from != wo || (wie == 2 && to != signed(doc->Pages->count()) ) )
-		{
-			doc->movePage(from-1, to, wo-1, wie);
-			updateGUIAfterPagesChanged();
-		}
+		if ((wie < 2) && (from <= wo) && (wo <= to))
+			return;
+		if (wie == 2 && to == signed(doc->Pages->count()))
+			return;
+		doc->movePage(from-1, to, wo-1, wie);
+		updateGUIAfterPagesChanged();
 		doc->updateEndnotesFrames();
 	}
-	delete dia;
 }
 
 void ScribusMainWindow::copyPage()

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18803&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Sat Feb  8 22:06:55 2014
@@ -2847,24 +2847,26 @@
 
 	if (isUndo)
 	{
-		int newPageDest=fromPage;
-		int newPageFrom=0;
-		int newPageTo  =0;
-		int newPosition=0;
-		int pagesMoved=toPage-fromPage;
+		int newPageDest = fromPage;
+		int newPageFrom = 0;
+		int newPageTo   = 0;
+		int newPosition = 0;
+		int pagesMoved  = toPage - fromPage;
 		switch (position)
 		{
 		case 0: //Before Page
-			newPageFrom=dest-pagesMoved;
+			newPageDest = (toPage <= dest) ? fromPage : toPage;
+			newPageFrom = (toPage <= dest) ? (dest - pagesMoved) : dest;
 			break;
 		case 1: //After Page
-			newPageFrom=dest-pagesMoved+1;
+			newPageDest = (toPage <= dest) ? fromPage : toPage;
+			newPageFrom = (toPage <= dest) ? (dest-pagesMoved + 1) : (dest + 1);
 			break;
 		case 2: //To End
-			newPageFrom=Pages->count()-pagesMoved;
+			newPageFrom = Pages->count() - pagesMoved;
 			break;
 		}
-		newPageTo=newPageFrom+pagesMoved;
+		newPageTo = newPageFrom + pagesMoved;
 		movePage(newPageFrom, newPageTo, newPageDest, newPosition);
 	}
 	else




More information about the scribus-commit mailing list