View Issue Details

IDProjectCategoryView StatusLast Update
0011011ScribusUndo/Redopublic2012-11-13 20:35
Reportercezaryece Assigned ToChelen  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version1.5.0svn 
Fixed in Version1.5.0svn 
Summary0011011: [PATCH] undo does not restore items welding
DescriptionIf you delete welded item after undo welding info is not restored.
TagsNo tags attached.
Patch

Activities

cezaryece

2012-08-07 10:42

updater  

undo4welding.diff (5,263 bytes)   
diff --git a/Scribus/scribus/pageitem.cpp b/Scribus/scribus/pageitem.cpp
index cd7f342..4126f3e 100644
--- a/Scribus/scribus/pageitem.cpp
+++ b/Scribus/scribus/pageitem.cpp
@@ -4949,6 +4949,10 @@ void PageItem::restore(UndoState *state, bool isUndo)
 			restoreAppMode(ss, isUndo);
 		else if (ss->contains("CONNECT_PATH"))
 			restoreConnectPath(ss, isUndo);
+		else if (ss->contains("WELD_ITEMS"))
+			restoreWeldItems(ss, isUndo);
+		else if (ss->contains("UNWELD_ITEM"))
+			restoreUnWeldItem(ss, isUndo);
 	}
 	if (!OnMasterPage.isEmpty())
 		m_Doc->setCurrentPage(oldCurrentPage);
@@ -4979,6 +4983,51 @@ void PageItem::restoreConnectPath(SimpleState *state, bool isUndo)
 	ContourLine = PoLine.copy();
 }
 
+void PageItem::restoreWeldItems(SimpleState *state, bool isUndo)
+{
+	if (isUndo)
+	{
+		unWeld();
+	}
+	else
+	{
+		ScItemState<PageItem*> *is = dynamic_cast<ScItemState<PageItem*>*>(state);
+		PageItem* wIt = is->getItem();
+		weldTo(wIt);
+	}
+	m_Doc->changed();
+	m_Doc->regionsChanged()->update(QRectF());
+}
+
+void PageItem::restoreUnWeldItem(SimpleState *state, bool isUndo)
+{
+	if (isUndo)
+	{
+		ScItemState<PageItem*> *is = dynamic_cast<ScItemState<PageItem*>*>(state);
+		PageItem* wIt = is->getItem();
+		{
+			weldingInfo wInf;
+			wInf.weldItem = wIt;
+			wInf.weldID = is->getInt("thisID");
+			wInf.weldPoint = FPoint(is->getDouble("thisPoint_x"), is->getDouble("thisPoint_y"));
+			weldList.append(wInf);
+		}
+		{
+			weldingInfo wInf;
+			wInf.weldItem = this;
+			wInf.weldID = is->getInt("ID");
+			wInf.weldPoint = FPoint(is->getDouble("Point_x"), is->getDouble("Point_y"));
+			wIt->weldList.append(wInf);
+		}
+	}
+	else
+	{
+		unWeld();
+	}
+	m_Doc->changed();
+	m_Doc->regionsChanged()->update(QRectF());
+}
+
 bool PageItem::checkGradientUndoRedo(SimpleState *ss, bool isUndo)
 {
 	if (ss->contains("SNAP_TO_PATCH"))
@@ -10062,6 +10111,13 @@ void PageItem::weldTo(PageItem* pIt)
 		return;
 	addWelded(pIt);
 	pIt->addWelded(this);
+	if(undoManager->undoEnabled())
+	{
+		ScItemState<PageItem*> *is = new ScItemState<PageItem*>(Um::WeldItems,"",Um::IGroup);
+		is->set("WELD_ITEMS", "weld_items");
+		is->setItem(pIt);
+		undoManager->action(this, is, getUPixmap());
+	}
 	update();
 	pIt->update();
 }
@@ -10145,6 +10201,10 @@ QList<PageItem*> PageItem::itemsWeldedTo(PageItem* except)
 
 void PageItem::unWeld()
 {
+	UndoTransaction* activeTransaction = NULL;
+	if (undoManager->undoEnabled())
+		activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::WeldItems + "/" + Um::Selection, Um::IGroup,
+																			  Um::WeldItems, "", Um::IDelete));
 	for (int a = 0 ; a < weldList.count(); a++)
 	{
 		weldingInfo wInf = weldList.at(a);
@@ -10156,10 +10216,29 @@ void PageItem::unWeld()
 			if (pIt2 == this)
 			{
 				pIt->weldList.removeAt(b);
+				if(undoManager->undoEnabled())
+				{
+					ScItemState<PageItem*> *is = new ScItemState<PageItem*>(Um::WeldItems,"",Um::IGroup);
+					is->set("UNWELD_ITEM", "unweld_item");
+					is->setItem(pIt);
+					is->set("thisPoint_x", wInf.weldPoint.x());
+					is->set("thisPoint_y", wInf.weldPoint.y());
+					is->set("thisID", wInf.weldID);
+					is->set("Point_x", wInf2.weldPoint.x());
+					is->set("Point_y", wInf2.weldPoint.y());
+					is->set("ID", wInf2.weldID);
+					undoManager->action(this, is, getUPixmap());
+				}
 				break;
 			}
 		}
 	}
+	if (activeTransaction)
+	{
+		activeTransaction->commit();
+		delete activeTransaction;
+		activeTransaction = NULL;
+	}
 	weldList.clear();
 }
 
diff --git a/Scribus/scribus/pageitem.h b/Scribus/scribus/pageitem.h
index 49f9c00..bb476a5 100644
--- a/Scribus/scribus/pageitem.h
+++ b/Scribus/scribus/pageitem.h
@@ -1436,6 +1436,10 @@ protected:
 	void restoreUnlinkTextFrame(UndoState *state, bool isUndo);
 	void restoreReverseText(UndoState *state, bool isUndo);
 	void restorePathOperation(UndoState *state, bool isUndo);
+
+	void restoreWeldItems(SimpleState *state, bool isUndo);
+	void restoreUnWeldItem(SimpleState *state, bool isUndo);
+	
 	/*@}*/
 
 	/**
diff --git a/Scribus/scribus/undomanager.cpp b/Scribus/scribus/undomanager.cpp
index 355f876..6c7adf2 100644
--- a/Scribus/scribus/undomanager.cpp
+++ b/Scribus/scribus/undomanager.cpp
@@ -1042,6 +1042,7 @@ void UndoManager::languageChange()
 	UndoManager::PathOperation		= tr("Path Operation");
 	UndoManager::ChangePageAttrs    = tr("Change Page Attributes");
 	UndoManager::Transform          = tr("Transform");
+	UndoManager::WeldItems          = tr("Weld Items");
 }
 
 void UndoManager::initIcons()
@@ -1305,6 +1306,7 @@ QString UndoManager::ClearImage         = "";
 QString UndoManager::PathOperation      = "";
 QString UndoManager::ChangePageAttrs    = "";
 QString UndoManager::Transform          = "";
+QString UndoManager::WeldItems          = "";
 
 /*** Icons for UndoObjects *******************************************/
 QPixmap *UndoManager::IImageFrame      = 0;
diff --git a/Scribus/scribus/undomanager.h b/Scribus/scribus/undomanager.h
index 24e92df..278dd28 100644
--- a/Scribus/scribus/undomanager.h
+++ b/Scribus/scribus/undomanager.h
@@ -652,6 +652,7 @@ public:
 	static QString UnlinkTextFrame;
 	static QString ClearImage;
 	static QString PathOperation;
+	static QString WeldItems;
 	/*@}*/
 
 	/**
undo4welding.diff (5,263 bytes)   

cezaryece

2012-08-07 10:44

updater   ~0028777

Attached patch solving issue.

Chelen

2012-10-08 09:29

developer   ~0029022

It looks like restoreUnWeldItem(SimpleState *state, bool isUndo) can be improve a little but why does this patch is not in the trunk? (or not notice as being in the trunk?)

jghali

2012-10-08 21:10

administrator   ~0029024

Seems it somewhat passed through ;) Committed!

Issue History

Date Modified Username Field Change
2012-08-07 08:12 cezaryece New Issue
2012-08-07 08:12 cezaryece Status new => assigned
2012-08-07 08:12 cezaryece Assigned To => Chelen
2012-08-07 08:33 jghali Priority high => normal
2012-08-07 10:42 cezaryece File Added: undo4welding.diff
2012-08-07 10:44 cezaryece Note Added: 0028777
2012-08-08 07:38 cezaryece Summary BUG: undo do not restore items welding => BUG: undo does not restore items welding
2012-08-08 15:07 ale Summary BUG: undo does not restore items welding => [PATCH] undo does not restore items welding
2012-10-08 09:29 Chelen Note Added: 0029022
2012-10-08 21:10 jghali Note Added: 0029024
2012-10-08 21:10 jghali Status assigned => resolved
2012-10-08 21:10 jghali Fixed in Version => 1.5.0svn
2012-10-08 21:10 jghali Resolution open => fixed
2012-11-13 20:35 cbradney Status resolved => closed