r24282 by jghali - #16350: Undo of ungrouped grouped object crashes Scribus

scribus-commit scribus-commit at lists.scribus.net
Tue Nov 24 18:40:34 UTC 2020


Author: jghali
Date: Tue Nov 24 18:40:34 2020
New Revision: 24282

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24282
Log:
#16350: Undo of ungrouped grouped object crashes Scribus

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

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24282&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Tue Nov 24 18:40:34 2020
@@ -1582,10 +1582,12 @@
 {
 	m_docUpdater->beginUpdate();
 	m_Selection->delaySignalsOn();
+	++m_undoRedoOngoing;
 }
 
 void ScribusDoc::undoRedoDone()
 {
+	--m_undoRedoOngoing;
 	m_Selection->delaySignalsOff();
 	m_docUpdater->endUpdate();
 }
@@ -1872,17 +1874,19 @@
 	double x, y, w, h;
 	if (isUndo)
 	{
-		tempSelect.addItem(select.last());
+		tempSelect.addItem(select.first()->Parent);
 		tempSelect.getGroupRect(&x, &y, &w, &h);
 		itemSelection_UnGroupObjects(&tempSelect);
 	}
 	else
 	{
-		for (int i = 0; i < select.size()-1; ++i)
+		for (int i = 0; i < select.size() - 1; ++i)
 			tempSelect.addItem(select.at(i));
 		tempSelect.getGroupRect(&x, &y, &w, &h);
+		PageItem_Group* oldGroupItem = select.last()->asGroupFrame();
+		PageItem* newGroupItem = itemSelection_GroupObjects(false, false, &tempSelect, oldGroupItem);
 		select.removeLast();
-		select.append(itemSelection_GroupObjects(false, false,&tempSelect));
+		select.append(newGroupItem);
 		is->setItem(select);
 	}
 	QRectF rect(x, y , w, h);
@@ -2305,6 +2309,11 @@
 bool ScribusDoc::isModified() const
 {
 	return m_modified;
+}
+
+bool ScribusDoc::isUndoRedoOngoing() const
+{
+	return (m_undoRedoOngoing != 0);
 }
 
 /** sets page properties */
@@ -14903,7 +14912,7 @@
 	itemList.append(groupItem);
 }
 
-PageItem * ScribusDoc::itemSelection_GroupObjects(bool changeLock, bool lock, Selection* customSelection)
+PageItem * ScribusDoc::itemSelection_GroupObjects(bool changeLock, bool lock, Selection* customSelection, PageItem_Group* groupItem)
 {
 	Selection* itemSelection = (customSelection != nullptr) ? customSelection : m_Selection;
 	if (itemSelection->count() < 1)
@@ -14988,8 +14997,11 @@
 	double gh = maxy - miny;
 
 	m_undoManager->setUndoEnabled(false);
-	int z = itemAdd(PageItem::Group, PageItem::Rectangle, gx, gy, gw, gh, 0, CommonStrings::None, CommonStrings::None);
-	PageItem *groupItem = Items->takeAt(z);
+	if (!groupItem)
+	{
+		int z = itemAdd(PageItem::Group, PageItem::Rectangle, gx, gy, gw, gh, 0, CommonStrings::None, CommonStrings::None);
+		groupItem = Items->takeAt(z)->asGroupFrame();
+	}
 	Items->insert(lowestItem, groupItem);
 	groupItem->setItemName( tr("Group%1").arg(GroupCounter));
 	groupItem->AutoName = false;
@@ -15074,6 +15086,7 @@
 		if (d >= 0)
 			list->removeAt(d);
 		itemSelection->removeItem(currItem);
+		QList<PageItem*> oldGroupItems = currItem->groupItemList;
 		int gcount = currItem->groupItemList.count();
 		for (int j = 0; j < gcount; j++)
 		{
@@ -15097,6 +15110,7 @@
 			ScItemState<QList<QPointer<PageItem> > > *is = new ScItemState<QList<QPointer<PageItem> > >(UndoManager::Ungroup);
 			is->set("UNGROUP");
 			Selection tempSelection(this, false);
+			tempSelection.addItems(oldGroupItems);
 			tempSelection.addItem(currItem, true);
 			is->setItem(tempSelection.selectionList());
 			m_undoManager->action(this, is);
@@ -15112,7 +15126,7 @@
 		currItem = toDelete.at(i);
 		if (currItem->isWelded())
 			currItem->unWeld();
-		if (!UndoManager::undoEnabled())
+		if (!UndoManager::undoEnabled() && !isUndoRedoOngoing())
 			delete currItem;
 	}
 

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24282&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h	(original)
+++ trunk/Scribus/scribus/scribusdoc.h	Tue Nov 24 18:40:34 2020
@@ -107,6 +107,7 @@
 	bool isLoading() const;
 	void setModified(bool);
 	bool isModified() const;
+	bool isUndoRedoOngoing() const;
 /** Setzt die Seitenattribute */
 	void setPage(double w, double h, double t, double l, double r, double b, double sp, double ab, bool atf, int fp);
 
@@ -1087,7 +1088,7 @@
 	PageItem* groupObjectsSelection(Selection* customSelection = nullptr);
 	PageItem* groupObjectsList(QList<PageItem*> &itemList);
 	void groupObjectsToItem(PageItem* groupItem, QList<PageItem*> &itemList);
-	PageItem * itemSelection_GroupObjects  (bool changeLock, bool lock, Selection* customSelection = nullptr);
+	PageItem * itemSelection_GroupObjects  (bool changeLock, bool lock, Selection* customSelection = nullptr, PageItem_Group* groupItem = nullptr);
 	void itemSelection_UnGroupObjects(Selection* customSelection = nullptr);
 	void addToGroup(PageItem* group, PageItem* item);
 	void removeFromGroup(PageItem* item);
@@ -1283,6 +1284,7 @@
 	UndoManager * const m_undoManager;
 	bool m_loading {false};
 	bool m_modified {false};
+	int  m_undoRedoOngoing {0};
 	int m_ActiveLayer {0};
 	double m_docUnitRatio;
 	int m_rotMode {0};
@@ -1369,11 +1371,13 @@
 	PageItem *DraggedElem {nullptr};
 	PageItem *ElemToLink {nullptr};
 	QList<PageItem*> DragElements;
+
 private:
 	StyleSet<ParagraphStyle> m_docParagraphStyles;
 	StyleSet<CharStyle> m_docCharStyles;
 	StyleSet<TableStyle> m_docTableStyles;
 	StyleSet<CellStyle> m_docCellStyles;
+
 public:
 	ScLayers Layers;
 	//bool marginColored;




More information about the scribus-commit mailing list