diff options
| author | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-01-25 21:10:44 +0000 |
|---|---|---|
| committer | craig <craig@11d20701-8431-0410-a711-e3c959e3b870> | 2012-01-25 21:10:44 +0000 |
| commit | 98a30cc8b97ed2f16cc15742327ae8ea732fc9a6 (patch) | |
| tree | 470e34491c4d1978df2d9700d6ce75a53d908acb /scribus | |
| parent | 4f4d36f57f4b613364dfb18e262fb6c5e4e690e3 (diff) | |
| download | scribus-98a30cc8b97ed2f16cc15742327ae8ea732fc9a6.tar.gz scribus-98a30cc8b97ed2f16cc15742327ae8ea732fc9a6.tar.xz scribus-98a30cc8b97ed2f16cc15742327ae8ea732fc9a6.zip | |
#10082: Backport new Query dialog code and adjust usage to new duplicate check method, and move to declared vars
git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17234 11d20701-8431-0410-a711-e3c959e3b870
Diffstat (limited to 'scribus')
| -rw-r--r-- | scribus/javadocs.cpp | 19 | ||||
| -rw-r--r-- | scribus/patterndialog.cpp | 7 | ||||
| -rw-r--r-- | scribus/query.cpp | 50 | ||||
| -rw-r--r-- | scribus/query.h | 6 | ||||
| -rw-r--r-- | scribus/scrapbookpalette.cpp | 98 | ||||
| -rw-r--r-- | scribus/scribus.cpp | 17 | ||||
| -rw-r--r-- | scribus/shadebutton.cpp | 12 |
7 files changed, 92 insertions, 117 deletions
diff --git a/scribus/javadocs.cpp b/scribus/javadocs.cpp index 4994add..b7e7bcc 100644 --- a/scribus/javadocs.cpp +++ b/scribus/javadocs.cpp @@ -74,21 +74,13 @@ JavaDocs::JavaDocs(QWidget* parent, ScribusDoc *doc, ScribusView* vie) : QDialog 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 @@ void JavaDocs::slotAdd() } delete dia2; } - delete dia; } void JavaDocs::slotEdit() diff --git a/scribus/patterndialog.cpp b/scribus/patterndialog.cpp index a7b1778..d4d8ddb 100644 --- a/scribus/patterndialog.cpp +++ b/scribus/patterndialog.cpp @@ -84,15 +84,10 @@ void PatternDialog::renamePattern() 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); diff --git a/scribus/query.cpp b/scribus/query.cpp index 0bc8287..afae1d2 100644 --- a/scribus/query.cpp +++ b/scribus/query.cpp @@ -9,6 +9,7 @@ for which a new license (GPL+exception) is in place. #include <QLabel> #include <QLineEdit> #include <QPushButton> +#include <QMessageBox> #include "commonstrings.h" #include "util_icon.h" @@ -44,6 +45,8 @@ Query::Query( QWidget* parent, const char* name, bool modal, Qt::WFlags fl, QSt 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 @@ void Query::Leave() { 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 @@ void Query::setEditText(QString newText, bool setSelected) 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; +} diff --git a/scribus/query.h b/scribus/query.h index d50ff8f..805e792 100644 --- a/scribus/query.h +++ b/scribus/query.h @@ -29,6 +29,9 @@ public: 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 @@ private: QPushButton* cancelButton; QLineEdit* answerEdit; QLabel* questionLabel; + QStringList checkList; + QStringList forbiddenList; + bool checkMode; }; #endif // QUERY_H diff --git a/scribus/scrapbookpalette.cpp b/scribus/scrapbookpalette.cpp index cbc04bd..73cacc6 100644 --- a/scribus/scrapbookpalette.cpp +++ b/scribus/scrapbookpalette.cpp @@ -925,26 +925,13 @@ bool Biblio::copyObj(int id) 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 @@ void Biblio::renameObj() 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 @@ void Biblio::ObjFromMenu(QString text) 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 @@ void Biblio::ObjFromMainMenu(QString text, int scrapID) 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(); diff --git a/scribus/scribus.cpp b/scribus/scribus.cpp index 1505862..1ff9926 100644 --- a/scribus/scribus.cpp +++ b/scribus/scribus.cpp @@ -7075,14 +7075,13 @@ void ScribusMainWindow::setItemFSize(int id) else { bool ok = false; - Query* dia = new Query(this, "New", 1, 0, tr("&Size:"), tr("Size")); - if (dia->exec()) + Query dia(this, "New", 1, 0, tr("&Size:"), tr("Size")); + if (dia.exec()) { - c = qRound(dia->getEditText().toDouble(&ok)); + 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 @@ void ScribusMainWindow::PutToPatterns() 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(); diff --git a/scribus/shadebutton.cpp b/scribus/shadebutton.cpp index dd84efa..7d12172 100644 --- a/scribus/shadebutton.cpp +++ b/scribus/shadebutton.cpp @@ -46,21 +46,17 @@ void ShadeButton::setShade(QAction *act) 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(); |
