r19894 by craig - Move the item to pattern/symbol conversion code to scribusdoc. Attempt and fail at fixing #11365 but leave the code behind in case someone follows up, with comments

scribus-commit scribus-commit at lists.scribus.net
Mon Mar 2 22:10:19 UTC 2015


Author: craig
Date: Mon Mar  2 22:10:19 2015
New Revision: 19894

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=19894
Log:
Move the item to pattern/symbol conversion code to scribusdoc. Attempt and fail at fixing #11365 but leave the code behind in case someone follows up, with comments

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

Modified: trunk/Scribus/scribus/scpage.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19894&path=/trunk/Scribus/scribus/scpage.cpp
==============================================================================
--- trunk/Scribus/scribus/scpage.cpp (original)
+++ trunk/Scribus/scribus/scpage.cpp Mon Mar  2 22:10:19 2015
@@ -214,6 +214,8 @@
 			restorePageItemDeletion(dynamic_cast<ScItemState< QList<PageItem*> >*>(ss), isUndo);
 		else if (ss->contains("CONVERT_ITEM"))
 			restorePageItemConversion(dynamic_cast<ScItemState<std::pair<PageItem*, PageItem*> >*>(ss), isUndo);
+		else if (ss->contains("CONVERT_ITEM_TO_SYMBOL"))
+			restorePageItemConversionToSymbol(dynamic_cast<ScItemState<std::pair<PageItem*, PageItem*> >*>(ss), isUndo);
 		else if (ss->contains("PAGE_ATTRS"))
 			restorePageAttributes(ss, isUndo);
 	}
@@ -423,6 +425,31 @@
 	m_Doc->setMasterPageMode(oldMPMode);
 }
 
+void ScPage::restorePageItemConversionToSymbol(ScItemState<std::pair<PageItem*, PageItem*> >* state, bool isUndo)
+{
+	if (!state)
+		return;
+
+	PageItem *oldItem=state->getItem().first;
+	PageItem *newItem=state->getItem().second;
+	QString patternName=state->getDescription();
+	bool oldMPMode=m_Doc->masterPageMode();
+	m_Doc->setMasterPageMode(!oldItem->OnMasterPage.isEmpty());
+	if (isUndo)
+	{
+		m_Doc->Items->replace(m_Doc->Items->indexOf(newItem), oldItem);
+		oldItem->updatePolyClip();
+		m_Doc->AdjustItemSize(oldItem);
+		if (m_Doc->docPatterns.contains(patternName))
+			m_Doc->docPatterns.remove(patternName);
+	}
+	else
+	{
+		m_Doc->Items->replace(m_Doc->Items->indexOf(oldItem), newItem);
+	}
+	m_Doc->setMasterPageMode(oldMPMode);
+}
+
 void ScPage::setXOffset(const double newCanvasXOffset)
 {
 	m_xOffset = newCanvasXOffset;

Modified: trunk/Scribus/scribus/scpage.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19894&path=/trunk/Scribus/scribus/scpage.h
==============================================================================
--- trunk/Scribus/scribus/scpage.h (original)
+++ trunk/Scribus/scribus/scpage.h Mon Mar  2 22:10:19 2015
@@ -105,7 +105,8 @@
 	void restorePageItemDeletion(ScItemState< QList<PageItem*> > *state, bool isUndo);
 	void restorePageAttributes(SimpleState *state, bool isUndo);
 	void restorePageItemConversion(ScItemState<std::pair<PageItem*, PageItem*> >*state, bool isUndo);
-	
+	void restorePageItemConversionToSymbol(ScItemState<std::pair<PageItem*, PageItem*> >*state, bool isUndo);
+
 	double m_xOffset;
 	double m_yOffset;
 	double m_width;

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19894&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Mon Mar  2 22:10:19 2015
@@ -8985,124 +8985,20 @@
 {
 	if (!HaveDoc)
 		return;
-	uint docSelectionCount = doc->m_Selection->count();
-	QString patternName = "Pattern_"+doc->m_Selection->itemAt(0)->itemName();
+	if (doc->m_Selection->isEmpty())
+		return;
+	QString patternName("Pattern_"+doc->m_Selection->itemAt(0)->itemName());
 	patternName = patternName.trimmed().simplified().replace(" ", "_");
-	undoManager->setUndoEnabled(false);
-	PageItem* currItem;
-	Selection itemSelection(this, false);
-	itemSelection.copy(*doc->m_Selection, false);
-	view->Deselect(true);
-	if (docSelectionCount > 1)
-		currItem = doc->groupObjectsSelection(&itemSelection);
-	else
-		currItem = itemSelection.itemAt(0);
-	QList<PageItem*> allItems;
-	if (currItem->isGroup())
-		allItems = currItem->asGroupFrame()->getItemList();
-	else
-		allItems.append(currItem);
-	QStringList results;
-	for (int i = 0; i < allItems.count(); i++)
-	{
-		PageItem *item = allItems.at(i);
-		if ((!results.contains(item->pattern())) && ((item->GrType == 8) || (item->itemType() == PageItem::Symbol)))
-			results.append(item->pattern());
-		if (!item->strokePattern().isEmpty())
-		{
-			if (!results.contains(item->strokePattern()))
-				results.append(item->strokePattern());
-		}
-		if (!item->patternMask().isEmpty())
-		{
-			if (!results.contains(item->patternMask()))
-				results.append(item->patternMask());
-		}
-	}
-	patternsDependingOnThis.clear();
-	QStringList mainPatterns = doc->docPatterns.keys();
-	for (int i = 0; i < results.count(); i++)
-	{
-		QString temp = results[i];
-		for (int j = 0; j < mainPatterns.count(); j++)
-		{
-			if (mainPatterns[j] != temp)
-			{
-				QStringList subPatterns;
-				subPatterns = doc->getUsedPatternsHelper(mainPatterns[j], subPatterns);
-				if (subPatterns.contains(temp))
-					patternsDependingOnThis.prepend(mainPatterns[j]);
-			}
-		}
-		patternsDependingOnThis.prepend(temp);
-	}
-	 // #12753: We cannot replace currently edited symbol
-	if (doc->symbolEditMode())
-		patternsDependingOnThis.prepend(doc->getEditedSymbol());
-	allItems.clear();
 	Query dia(this, "tt", 1, tr("&Name:"), tr("New Entry"));
 	dia.setEditText(patternName, true);
 	dia.setForbiddenList(patternsDependingOnThis);
 	dia.setTestList(doc->docPatterns.keys());
 	dia.setCheckMode(true);
 	if (!dia.exec())
-	{
-		undoManager->setUndoEnabled(true);
-		return;
-	}
+		return;
 	patternName = dia.getEditText();
-	ScPattern pat = ScPattern();
-	pat.setDoc(doc);
-	double minx =  std::numeric_limits<double>::max();
-	double miny =  std::numeric_limits<double>::max();
-	double maxx = -std::numeric_limits<double>::max();
-	double maxy = -std::numeric_limits<double>::max();
-	double x1, x2, y1, y2;
-	currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
-	minx = qMin(minx, x1);
-	miny = qMin(miny, y1);
-	maxx = qMax(maxx, x2);
-	maxy = qMax(maxy, y2);
-	pat.pattern = currItem->DrawObj_toImage(qMin(qMax(maxx - minx, maxy - miny), 500.0));
-	pat.width = maxx - minx;
-	pat.height = maxy - miny;
-	pat.items.append(currItem);
-	// #11274 : OwnPage is not meaningful for pattern items
-	// We set consequently pattern item's OwnPage to -1 
-	QList<PageItem*> patternItems = pat.items;
-	while (patternItems.count() > 0)
-	{
-		PageItem* patItem = patternItems.takeAt(0);
-		if (patItem->isGroup())
-			patternItems += patItem->groupItemList;
-		patItem->OwnPage = -1;
-	}
-	if (doc->docPatterns.contains(patternName))
-		doc->docPatterns.remove(patternName);
-	doc->addPattern(patternName, pat);
-	int d = -1;
-	double sx = minx;
-	double sy = miny;
-	if (currItem->isGroupChild())
-	{
-		sx = currItem->gXpos;
-		sy = currItem->gYpos;
-		d = currItem->parentGroup()->groupItemList.indexOf(currItem);
-	}
-	else
-		d = doc->Items->indexOf(currItem);
-	currItem->gXpos = currItem->xPos() - minx;
-	currItem->gYpos = currItem->yPos() - miny;
-	currItem->setXYPos(currItem->gXpos, currItem->gYpos, true);
-	int z = doc->itemAdd(PageItem::Symbol, PageItem::Rectangle, sx, sy, maxx - minx, maxy - miny, 0, CommonStrings::None, CommonStrings::None, true);
-	PageItem* groupItem = doc->Items->takeAt(z);
-	groupItem->setPattern(patternName);
-	groupItem->Parent = currItem->Parent;
-	if (currItem->isGroupChild())
-		currItem->parentGroup()->groupItemList.replace(d, groupItem);
-	else
-		doc->Items->replace(d, groupItem);
-	doc->m_Selection->delaySignalsOff();
+	undoManager->setUndoEnabled(false);
+	doc->itemSelection_convertItemsToSymbol(patternName);
 	propertiesPalette->updateColorList();
 	symbolPalette->updateSymbolList();
 	emit UpdateRequest(reqColorsUpdate);

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19894&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Mon Mar  2 22:10:19 2015
@@ -15749,6 +15749,135 @@
 	changed();
 }
 
+void ScribusDoc::itemSelection_convertItemsToSymbol(QString& patternName)
+{
+	uint docSelectionCount = m_Selection->count();
+	/* #11365 will be fixed once undo here is fixed
+	UndoTransaction activeTransaction;
+	if (UndoManager::undoEnabled()) // && !m_itemCreationTransaction)
+		activeTransaction = undoManager->beginTransaction();
+	*/
+	PageItem* currItem;
+	Selection itemSelection(this, false);
+	itemSelection.copy(*m_Selection, false);
+	m_View->Deselect(true);
+	if (docSelectionCount > 1)
+		currItem = groupObjectsSelection(&itemSelection);
+	else
+		currItem = itemSelection.itemAt(0);
+	QList<PageItem*> allItems;
+	if (currItem->isGroup())
+		allItems = currItem->asGroupFrame()->getItemList();
+	else
+		allItems.append(currItem);
+	QStringList results;
+	for (int i = 0; i < allItems.count(); i++)
+	{
+		PageItem *item = allItems.at(i);
+		if ((!results.contains(item->pattern())) && ((item->GrType == 8) || (item->itemType() == PageItem::Symbol)))
+			results.append(item->pattern());
+		if (!item->strokePattern().isEmpty())
+		{
+			if (!results.contains(item->strokePattern()))
+				results.append(item->strokePattern());
+		}
+		if (!item->patternMask().isEmpty())
+		{
+			if (!results.contains(item->patternMask()))
+				results.append(item->patternMask());
+		}
+	}
+	m_ScMW->patternsDependingOnThis.clear();
+	QStringList mainPatterns = docPatterns.keys();
+	for (int i = 0; i < results.count(); i++)
+	{
+		QString temp = results[i];
+		for (int j = 0; j < mainPatterns.count(); j++)
+		{
+			if (mainPatterns[j] != temp)
+			{
+				QStringList subPatterns;
+				subPatterns = getUsedPatternsHelper(mainPatterns[j], subPatterns);
+				if (subPatterns.contains(temp))
+					m_ScMW->patternsDependingOnThis.prepend(mainPatterns[j]);
+			}
+		}
+		m_ScMW->patternsDependingOnThis.prepend(temp);
+	}
+	 // #12753: We cannot replace currently edited symbol
+	if (symbolEditMode())
+		m_ScMW->patternsDependingOnThis.prepend(getEditedSymbol());
+	allItems.clear();
+
+	ScPattern pat = ScPattern();
+	pat.setDoc(this);
+	double minx =  std::numeric_limits<double>::max();
+	double miny =  std::numeric_limits<double>::max();
+	double maxx = -std::numeric_limits<double>::max();
+	double maxy = -std::numeric_limits<double>::max();
+	double x1, x2, y1, y2;
+	currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
+	minx = qMin(minx, x1);
+	miny = qMin(miny, y1);
+	maxx = qMax(maxx, x2);
+	maxy = qMax(maxy, y2);
+	pat.pattern = currItem->DrawObj_toImage(qMin(qMax(maxx - minx, maxy - miny), 500.0));
+	pat.width = maxx - minx;
+	pat.height = maxy - miny;
+	pat.items.append(currItem);
+	// #11274 : OwnPage is not meaningful for pattern items
+	// We set consequently pattern item's OwnPage to -1
+	QList<PageItem*> patternItems = pat.items;
+	while (patternItems.count() > 0)
+	{
+		PageItem* patItem = patternItems.takeAt(0);
+		if (patItem->isGroup())
+			patternItems += patItem->groupItemList;
+		patItem->OwnPage = -1;
+	}
+	if (docPatterns.contains(patternName))
+		docPatterns.remove(patternName);
+	addPattern(patternName, pat);
+	int d = -1;
+	double sx = minx;
+	double sy = miny;
+	if (currItem->isGroupChild())
+	{
+		sx = currItem->gXpos;
+		sy = currItem->gYpos;
+		d = currItem->parentGroup()->groupItemList.indexOf(currItem);
+	}
+	else
+		d = Items->indexOf(currItem);
+	currItem->gXpos = currItem->xPos() - minx;
+	currItem->gYpos = currItem->yPos() - miny;
+	currItem->setXYPos(currItem->gXpos, currItem->gYpos, true);
+	int z = itemAdd(PageItem::Symbol, PageItem::Rectangle, sx, sy, maxx - minx, maxy - miny, 0, CommonStrings::None, CommonStrings::None, true);
+	PageItem* groupItem = Items->takeAt(z);
+	groupItem->setPattern(patternName);
+	groupItem->Parent = currItem->Parent;
+	if (currItem->isGroupChild())
+		currItem->parentGroup()->groupItemList.replace(d, groupItem);
+	else
+		Items->replace(d, groupItem);
+	/* #11365 will be fixed once undo here is fixed
+	if (UndoManager::undoEnabled())
+	{
+		ScItemState<QPair<PageItem*, PageItem*> > *is = new ScItemState<QPair<PageItem*, PageItem*> >("Convert Item");
+		is->set("CONVERT_ITEM_TO_SYMBOL", "convert_item_to_symbol");
+		is->setItem(qMakePair(currItem, groupItem));
+		is->setDescription(patternName);
+		//Undo target rests with the Page for object specific undo
+		UndoObject *target = Pages->at(0);
+		if (groupItem->OwnPage > -1)
+			target = Pages->at(groupItem->OwnPage);
+		undoManager->action(target, is);
+	}*/
+	m_Selection->delaySignalsOff();
+	if (activeTransaction)
+		activeTransaction.commit();
+}
+
 //CB-->Doc
 //Fix size/move item calls
 //CB TODO Use the selection loop properly

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19894&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Mon Mar  2 22:10:19 2015
@@ -1060,7 +1060,7 @@
 	void resizeGroupToContents(PageItem* group);
 	void itemSelection_resizeGroupToContents(Selection *customSelection=0);
 	void itemSelection_convertItemsTo(const PageItem::ItemType newType, Selection* restoredSelection=0, Selection* customSelection=0);
-
+	void itemSelection_convertItemsToSymbol(QString& patternName);
 	void itemSelection_ApplyParagraphStyle(const ParagraphStyle & newstyle, Selection* customSelection=0, bool rmDirectFormatting = false);
 	void itemSelection_SetParagraphStyle(const ParagraphStyle & newstyle, Selection* customSelection=0);
 	void itemSelection_ApplyCharStyle(const CharStyle & newstyle, Selection* customSelection=0, QString ETEA = "");




More information about the scribus-commit mailing list