r14438 by fschmid - Fixed Bug #8652: "duplicated names for patterns make scribus crash"

scribus-commit scribus-commit at lists.scribus.net
Sun Dec 20 11:05:32 CET 2009


Revision: 14438
Author: fschmid
Date: 2009-12-19T22:23:52.111649Z
Commit message: Fixed Bug #8652: "duplicated names for patterns make scribus crash"

Changeset: 
M  /trunk/Scribus/scribus/scribus.cpp
M  /trunk/Scribus/scribus/ui/patterndialog.cpp
M  /trunk/Scribus/scribus/ui/scrapbookpalette.cpp
M  /trunk/Scribus/scribus/ui/query.cpp
M  /trunk/Scribus/scribus/ui/javadocs.cpp
M  /trunk/Scribus/scribus/ui/query.h

Diffs:
Index: scribus/ui/patterndialog.cpp
===================================================================
--- scribus/ui/patterndialog.cpp	(revision 14437)
+++ scribus/ui/patterndialog.cpp	(revision 14438)
@@ -84,15 +84,10 @@
 		QString newName = "";
 		Query dia(this, "tt", 1, 0, tr("&Name:"), tr("Rename Entry"));
 		dia.setEditText(it->text(), true);
+		dia.setTestList(dialogPatterns.keys());
 		if (dia.exec())
 		{
 			newName = dia.getEditText();
-			while (dialogPatterns.contains(newName))
-			{
-				if (!dia.exec())
-					return;
-				newName = dia.getEditText();
-			}
 			ScPattern pat = dialogPatterns.take(it->text());
 			dialogPatterns.insert(newName, pat);
 			replaceMap.insert(patternName, newName);
Index: scribus/ui/query.cpp
===================================================================
--- scribus/ui/query.cpp	(revision 14437)
+++ scribus/ui/query.cpp	(revision 14438)
@@ -9,6 +9,7 @@
 #include <QLabel>
 #include <QLineEdit>
 #include <QPushButton>
+#include <QMessageBox>
 #include "commonstrings.h"
 #include "util_icon.h"
 
@@ -44,6 +45,7 @@
 	queryLayout->addLayout( okCancelLayout );
 	setMaximumSize(sizeHint());
 	answerEdit->setFocus();
+	checkList = QStringList();
 
 	// signals and slots connections
 	connect( okButton, SIGNAL( clicked() ), this, SLOT( Leave() ) );
@@ -58,6 +60,14 @@
 {
 	if (answerEdit->text().isEmpty())
 		return;
+	if (!checkList.isEmpty())
+	{
+		if (checkList.contains(answerEdit->text()))
+		{
+			QMessageBox::warning(this, CommonStrings::trWarning, tr("Name \"%1\" is not unique.\nPlease choose another.").arg(answerEdit->text()), CommonStrings::tr_OK);
+			return;
+		}
+	}
 	else
 		accept();
 }
@@ -73,3 +83,8 @@
 	if (setSelected)
 		answerEdit->selectAll();
 }
+
+void Query::setTestList(QStringList tList)
+{
+	checkList = tList;
+}
Index: scribus/ui/scrapbookpalette.cpp
===================================================================
--- scribus/ui/scrapbookpalette.cpp	(revision 14437)
+++ scribus/ui/scrapbookpalette.cpp	(revision 14438)
@@ -913,18 +913,10 @@
 	{
 		Query *dia = new Query(this, "tt", 1, 0, tr("&Name:"), tr("New Entry"));
 		dia->setEditText(nam, true);
+		dia->setTestList(activeBView->objectMap.keys());
 		if (dia->exec())
 		{
 			nam = dia->getEditText();
-			while (activeBView->objectMap.contains(nam))
-			{
-				if (!dia->exec())
-				{
-					delete dia;
-					return false;
-				}
-				nam = dia->getEditText();
-			}
 		}
 		else
 		{
@@ -1112,19 +1104,10 @@
 	QString OldName = ite->text();
 	Query *dia = new Query(this, "tt", 1, 0, tr("&Name:"), tr("New Name"));
 	dia->setEditText(ite->text(), true);
+	dia->setTestList(activeBView->objectMap.keys());
 	if (dia->exec())
 	{
 		nam = dia->getEditText();
-		while (activeBView->objectMap.contains(nam))
-		{
-			QMessageBox::warning(this, CommonStrings::trWarning, tr("Name \"%1\" is not unique.\nPlease choose another.").arg(nam), CommonStrings::tr_OK);
-			if (!dia->exec())
-			{
-				delete dia;
-				return;
-			}
-			nam = dia->getEditText();
-		}
 	}
 	else
 	{
@@ -1256,18 +1239,10 @@
 	qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
 	Query *dia = new Query(this, "tt", 1, 0, tr("&Name:"), tr("New Entry"));
 	dia->setEditText(nam, true);
+	dia->setTestList(activeBView->objectMap.keys());
 	if (dia->exec())
 	{
 		nam = dia->getEditText();
-		while (activeBView->objectMap.contains(nam))
-		{
-			if (!dia->exec())
-			{
-				delete dia;
-				return;
-			}
-			nam = dia->getEditText();
-		}
 	}
 	else
 	{
Index: scribus/ui/javadocs.cpp
===================================================================
--- scribus/ui/javadocs.cpp	(revision 14437)
+++ scribus/ui/javadocs.cpp	(revision 14438)
@@ -76,19 +76,11 @@
 	QString nam;
 	Query *dia = new Query(this, "tt", 1, 0, tr("&New Script:"), tr("New Script"));
 	dia->setEditText( tr("New Script"), false );
+	dia->setTestList(Doc->JavaScripts.keys());
 	if (dia->exec())
 	{
 		nam = dia->getEditText();
 		nam.replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" );
-		while (Doc->JavaScripts.contains(nam) || (nam.isEmpty()))
-		{
-			if (!dia->exec())
-			{
-				delete dia;
-				return;
-			}
-			nam = dia->getEditText();
-		}
 		Editor* dia2 = new Editor(this, "", View);
 		dia2->EditTex->setText("function "+nam+"()\n{\n}");
 		if (dia2->exec())
Index: scribus/ui/query.h
===================================================================
--- scribus/ui/query.h	(revision 14437)
+++ scribus/ui/query.h	(revision 14438)
@@ -29,6 +29,7 @@
 
 	const QString getEditText();
 	void setEditText(QString newText, bool setSelected);
+	void setTestList(QStringList tList);
 
 public slots:
 	void Leave();
@@ -41,6 +42,7 @@
 	QPushButton* cancelButton;
 	QLineEdit* answerEdit;
 	QLabel* questionLabel;
+	QStringList checkList;
 };
 
 #endif // QUERY_H
Index: scribus/scribus.cpp
===================================================================
--- scribus/scribus.cpp	(revision 14437)
+++ scribus/scribus.cpp	(revision 14438)
@@ -9272,16 +9272,9 @@
 	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());
 	if (dia.exec())
-	{
 		patternName = dia.getEditText();
-		while (doc->docPatterns.contains(patternName))
-		{
-			if (!dia.exec())
-				return;
-			patternName = dia.getEditText();
-		}
-	}
 	else
 		return;
 	bool wasUndo = undoManager->undoEnabled();




More information about the scribus-commit mailing list