r17006 by fschmid - Do not allow replacing a pattern with a new pattern that refers to the old one.

scribus-commit scribus-commit at lists.scribus.net
Tue Nov 22 10:19:53 UTC 2011


Author: fschmid
Date: Tue Nov 22 10:19:53 2011
New Revision: 17006

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17006
Log:
Do not allow replacing a pattern with a new pattern that refers to the old one.

Modified:
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/ui/query.cpp
    trunk/Scribus/scribus/ui/query.h

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17006&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Tue Nov 22 10:19:53 2011
@@ -9706,14 +9706,6 @@
 	uint docSelectionCount = doc->m_Selection->count();
 	QString patternName = "Pattern_"+doc->m_Selection->itemAt(0)->itemName();
 	patternName = patternName.trimmed().simplified().replace(" ", "_");
-	Query dia(this, "tt", 1, 0, tr("&Name:"), tr("New Entry"));
-	dia.setEditText(patternName, true);
-	dia.setTestList(doc->docPatterns.keys());
-	dia.setCheckMode(true);
-	if (dia.exec())
-		patternName = dia.getEditText();
-	else
-		return;
 	bool wasUndo = undoManager->undoEnabled();
 	undoManager->setUndoEnabled(false);
 	PageItem* currItem;
@@ -9724,6 +9716,55 @@
 		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 ii = 0; ii < allItems.count(); ii++)
+	{
+		PageItem *item = allItems.at(ii);
+		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 b = 0; b < results.count(); b++)
+	{
+		QString temp = results[b];
+		for (int a = 0; a < mainPatterns.count(); a++)
+		{
+			if (mainPatterns[a] != temp)
+			{
+				QStringList subPatterns;
+				subPatterns = doc->getUsedPatternsHelper(mainPatterns[a], subPatterns);
+				if (subPatterns.contains(temp))
+					patternsDependingOnThis.prepend(mainPatterns[a]);
+			}
+		}
+		patternsDependingOnThis.prepend(temp);
+	}
+	allItems.clear();
+	Query dia(this, "tt", 1, 0, tr("&Name:"), tr("New Entry"));
+	dia.setEditText(patternName, true);
+	dia.setForbiddenList(patternsDependingOnThis);
+	dia.setTestList(doc->docPatterns.keys());
+	dia.setCheckMode(true);
+	if (dia.exec())
+		patternName = dia.getEditText();
+	else
+		return;
 	ScPattern pat = ScPattern();
 	pat.setDoc(doc);
 	double minx =  std::numeric_limits<double>::max();
@@ -9755,11 +9796,11 @@
 	PageItem* groupItem = doc->Items->takeAt(z);
 	groupItem->setPattern(patternName);
 	doc->Items->replace(d, groupItem);
+	doc->m_Selection->delaySignalsOff();
 	propertiesPalette->updateColorList();
 	symbolPalette->updateSymbolList();
 	if (outlinePalette->isVisible())
 		outlinePalette->BuildTree();
-	doc->m_Selection->delaySignalsOff();
 	view->DrawNew();
 	undoManager->setUndoEnabled(wasUndo);
 }

Modified: trunk/Scribus/scribus/ui/query.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17006&path=/trunk/Scribus/scribus/ui/query.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/query.cpp (original)
+++ trunk/Scribus/scribus/ui/query.cpp Tue Nov 22 10:19:53 2011
@@ -61,6 +61,14 @@
 {
 	if (answerEdit->text().isEmpty())
 		return;
+	if (!forbiddenList.isEmpty())
+	{
+		if (forbiddenList.contains(answerEdit->text()))
+		{
+			QMessageBox::warning(this, CommonStrings::trWarning, tr("Name \"%1\" is not allowed.\nPlease choose another.").arg(answerEdit->text()), CommonStrings::tr_OK);
+			return;
+		}
+	}
 	if (!checkList.isEmpty())
 	{
 		if (checkList.contains(answerEdit->text()))
@@ -106,6 +114,11 @@
 	checkList = tList;
 }
 
+void Query::setForbiddenList(QStringList tList)
+{
+	forbiddenList = tList;
+}
+
 void Query::setCheckMode(bool mode)
 {
 	checkMode = mode;

Modified: trunk/Scribus/scribus/ui/query.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17006&path=/trunk/Scribus/scribus/ui/query.h
==============================================================================
--- trunk/Scribus/scribus/ui/query.h (original)
+++ trunk/Scribus/scribus/ui/query.h Tue Nov 22 10:19:53 2011
@@ -30,6 +30,7 @@
 	const QString getEditText();
 	void setEditText(QString newText, bool setSelected);
 	void setTestList(QStringList tList);
+	void setForbiddenList(QStringList tList);
 	void setCheckMode(bool mode);
 
 public slots:
@@ -44,6 +45,7 @@
 	QLineEdit* answerEdit;
 	QLabel* questionLabel;
 	QStringList checkList;
+	QStringList forbiddenList;
 	bool checkMode;
 };
 




More information about the scribus-commit mailing list