r17234 by craig - #10082: Backport new Query dialog code and adjust usage to new duplicate check method, and move to declared vars
scribus-commit
scribus-commit at lists.scribus.net
Wed Jan 25 21:10:45 UTC 2012
Author: craig
Date: Wed Jan 25 21:10:44 2012
New Revision: 17234
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17234
Log:
#10082: Backport new Query dialog code and adjust usage to new duplicate check method, and move to declared vars
Modified:
branches/Version14x/Scribus/scribus/javadocs.cpp
branches/Version14x/Scribus/scribus/patterndialog.cpp
branches/Version14x/Scribus/scribus/query.cpp
branches/Version14x/Scribus/scribus/query.h
branches/Version14x/Scribus/scribus/scrapbookpalette.cpp
branches/Version14x/Scribus/scribus/scribus.cpp
branches/Version14x/Scribus/scribus/shadebutton.cpp
Modified: branches/Version14x/Scribus/scribus/javadocs.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17234&path=/branches/Version14x/Scribus/scribus/javadocs.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/javadocs.cpp (original)
+++ branches/Version14x/Scribus/scribus/javadocs.cpp Wed Jan 25 21:10:44 2012
@@ -74,21 +74,13 @@
void JavaDocs::slotAdd()
{
QString nam;
- Query *dia = new Query(this, "tt", 1, 0, tr("&New Script:"), tr("New Script"));
- dia->setEditText( tr("New Script"), false );
- if (dia->exec())
+ Query dia(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 = 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())
@@ -101,7 +93,6 @@
}
delete dia2;
}
- delete dia;
}
void JavaDocs::slotEdit()
Modified: branches/Version14x/Scribus/scribus/patterndialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17234&path=/branches/Version14x/Scribus/scribus/patterndialog.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/patterndialog.cpp (original)
+++ branches/Version14x/Scribus/scribus/patterndialog.cpp Wed Jan 25 21:10:44 2012
@@ -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);
Modified: branches/Version14x/Scribus/scribus/query.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17234&path=/branches/Version14x/Scribus/scribus/query.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/query.cpp (original)
+++ branches/Version14x/Scribus/scribus/query.cpp Wed Jan 25 21:10:44 2012
@@ -9,6 +9,7 @@
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
+#include <QMessageBox>
#include "commonstrings.h"
#include "util_icon.h"
@@ -44,6 +45,8 @@
queryLayout->addLayout( okCancelLayout );
setMaximumSize(sizeHint());
answerEdit->setFocus();
+ checkList = QStringList();
+ checkMode = false;
// signals and slots connections
connect( okButton, SIGNAL( clicked() ), this, SLOT( Leave() ) );
@@ -58,6 +61,38 @@
{
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()))
+ {
+ if (checkMode)
+ {
+ int ret = QMessageBox::warning(this,
+ CommonStrings::trWarning,
+ tr("Name \"%1\" already exists.\nDo you want to replace the current contents?").arg(answerEdit->text()),
+ QMessageBox::Yes | QMessageBox::No,
+ QMessageBox::No);
+ if (ret == QMessageBox::No)
+ return;
+ else
+ accept();
+ }
+ else
+ {
+ QMessageBox::warning(this, CommonStrings::trWarning, tr("Name \"%1\" is not unique.\nPlease choose another.").arg(answerEdit->text()), CommonStrings::tr_OK);
+ return;
+ }
+ }
+ accept();
+ }
else
accept();
}
@@ -73,3 +108,18 @@
if (setSelected)
answerEdit->selectAll();
}
+
+void Query::setTestList(QStringList tList)
+{
+ checkList = tList;
+}
+
+void Query::setForbiddenList(QStringList tList)
+{
+ forbiddenList = tList;
+}
+
+void Query::setCheckMode(bool mode)
+{
+ checkMode = mode;
+}
Modified: branches/Version14x/Scribus/scribus/query.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17234&path=/branches/Version14x/Scribus/scribus/query.h
==============================================================================
--- branches/Version14x/Scribus/scribus/query.h (original)
+++ branches/Version14x/Scribus/scribus/query.h Wed Jan 25 21:10:44 2012
@@ -29,6 +29,9 @@
const QString getEditText();
void setEditText(QString newText, bool setSelected);
+ void setTestList(QStringList tList);
+ void setForbiddenList(QStringList tList);
+ void setCheckMode(bool mode);
public slots:
void Leave();
@@ -41,6 +44,9 @@
QPushButton* cancelButton;
QLineEdit* answerEdit;
QLabel* questionLabel;
+ QStringList checkList;
+ QStringList forbiddenList;
+ bool checkMode;
};
#endif // QUERY_H
Modified: branches/Version14x/Scribus/scribus/scrapbookpalette.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17234&path=/branches/Version14x/Scribus/scribus/scrapbookpalette.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/scrapbookpalette.cpp (original)
+++ branches/Version14x/Scribus/scribus/scrapbookpalette.cpp Wed Jan 25 21:10:44 2012
@@ -925,26 +925,13 @@
BibView* bv = (BibView*)Frame3->widget(id);
if (bv->objectMap.contains(nam))
{
- Query *dia = new Query(this, "tt", 1, 0, tr("&Name:"), tr("New Entry"));
- dia->setEditText(nam, true);
- if (dia->exec())
- {
- nam = dia->getEditText();
- while (activeBView->objectMap.contains(nam))
- {
- if (!dia->exec())
- {
- delete dia;
- return false;
- }
- nam = dia->getEditText();
- }
- }
+ Query dia(this, "tt", 1, 0, tr("&Name:"), tr("New Entry"));
+ dia.setEditText(nam, true);
+ dia.setTestList(activeBView->objectMap.keys());
+ if (dia.exec())
+ nam = dia.getEditText();
else
- {
- delete dia;
return false;
- }
}
QPixmap pm;
QByteArray cf;
@@ -1124,28 +1111,13 @@
QPixmap ObjPreview;
QListWidgetItem *ite = actItem;
QString OldName = ite->text();
- Query *dia = new Query(this, "tt", 1, 0, tr("&Name:"), tr("New Name"));
- dia->setEditText(ite->text(), true);
- 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();
- }
- }
+ Query dia(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();
else
- {
- delete dia;
return;
- }
- delete dia;
ite->setText(nam);
ObjData = activeBView->objectMap[OldName].Data;
ObjPreview = activeBView->objectMap[OldName].Preview;
@@ -1280,27 +1252,13 @@
nam += "("+ tmp.setNum(tempCount) + ")";
}
qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- Query *dia = new Query(this, "tt", 1, 0, tr("&Name:"), tr("New Entry"));
- dia->setEditText(nam, true);
- if (dia->exec())
- {
- nam = dia->getEditText();
- while (activeBView->objectMap.contains(nam))
- {
- if (!dia->exec())
- {
- delete dia;
- return;
- }
- nam = dia->getEditText();
- }
- }
+ Query dia(this, "tt", 1, 0, tr("&Name:"), tr("New Entry"));
+ dia.setEditText(nam, true);
+ dia.setTestList(activeBView->objectMap.keys());
+ if (dia.exec())
+ nam = dia.getEditText();
else
- {
- delete dia;
return;
- }
- delete dia;
QString ff = text;
activeBView->checkAndChange(ff, QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename + "/" + nam + ".sce")), QDir::cleanPath(QDir::toNativeSeparators(activeBView->ScFilename)));
ScPreview *pre = new ScPreview();
@@ -1443,27 +1401,13 @@
if (actBView->objectMap.contains(nam))
nam += "("+ tmp.setNum(tempCount) + ")";
qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
- Query *dia = new Query(this, "tt", 1, 0, tr("&Name:"), tr("New Entry"));
- dia->setEditText(nam, true);
- if (dia->exec())
- {
- nam = dia->getEditText();
- while (activeBView->objectMap.contains(nam))
- {
- if (!dia->exec())
- {
- delete dia;
- return;
- }
- nam = dia->getEditText();
- }
- }
+ Query dia(this, "tt", 1, 0, tr("&Name:"), tr("New Entry"));
+ dia.setEditText(nam, true);
+ dia.setTestList(activeBView->objectMap.keys());
+ if (dia.exec())
+ nam = dia.getEditText();
else
- {
- delete dia;
- return;
- }
- delete dia;
+ return;
QString ff = text;
actBView->checkAndChange(ff, QDir::cleanPath(QDir::toNativeSeparators(actBView->ScFilename + "/" + nam + ".sce")), QDir::cleanPath(QDir::toNativeSeparators(actBView->ScFilename)));
ScPreview *pre = new ScPreview();
Modified: branches/Version14x/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17234&path=/branches/Version14x/Scribus/scribus/scribus.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/scribus.cpp (original)
+++ branches/Version14x/Scribus/scribus/scribus.cpp Wed Jan 25 21:10:44 2012
@@ -7075,14 +7075,13 @@
else
{
bool ok = false;
- Query* dia = new Query(this, "New", 1, 0, tr("&Size:"), tr("Size"));
- if (dia->exec())
- {
- c = qRound(dia->getEditText().toDouble(&ok));
+ Query dia(this, "New", 1, 0, tr("&Size:"), tr("Size"));
+ if (dia.exec())
+ {
+ c = qRound(dia.getEditText().toDouble(&ok));
if ((ok) && (c < 1025) && (c > 0))
doc->itemSelection_SetFontSize(c*10);
}
- delete dia;
}
if (currItem->asTextFrame())
currItem->asTextFrame()->updateUndo(currItem->HasSel? PageItem::PARAMSEL : PageItem::PARAMFULL);
@@ -9730,16 +9729,10 @@
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();
- while (doc->docPatterns.contains(patternName))
- {
- if (!dia.exec())
- return;
- patternName = dia.getEditText();
- }
- }
else
return;
bool wasUndo = undoManager->undoEnabled();
Modified: branches/Version14x/Scribus/scribus/shadebutton.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17234&path=/branches/Version14x/Scribus/scribus/shadebutton.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/shadebutton.cpp (original)
+++ branches/Version14x/Scribus/scribus/shadebutton.cpp Wed Jan 25 21:10:44 2012
@@ -46,21 +46,17 @@
if (c == 0)
{
- Query* dia = new Query(this, "New", 1, 0, tr("&Shade:"), tr("Shade"));
- if (dia->exec())
- {
- c = dia->getEditText().toInt(&ok);
+ Query dia(this, "New", 1, 0, tr("&Shade:"), tr("Shade"));
+ if (dia.exec())
+ {
+ c = dia.getEditText().toInt(&ok);
if (ok)
b = qMax(qMin(c, 100),0);
else
b = 100;
- delete dia;
}
else
- {
- delete dia;
return;
- }
}
setText(QString::number(b)+" %");
emit clicked();
More information about the scribus-commit
mailing list