[Kst] kdeextragear-2/kst/kst

Rick Chern rchern at interchange.ubc.ca
Tue Aug 17 22:24:29 CEST 2004


CVS commit by rchern: 

- Don't allow blank plot names
- strip whitespace from beginning and end of names, but still allow whitespace in between.  Names that differ only by beginning/ending whitespace are considered duplicates and are not allowed.


  M +22 -14    kstplotdialog_i.cpp   1.81


--- kdeextragear-2/kst/kst/kstplotdialog_i.cpp  #1.80:1.81
@@ -522,4 +522,9 @@ void KstPlotDialogI::applyPlotColors(Kst
 
 void KstPlotDialogI::new_I() {
+  //check plot name
+  if (!checkPlotName()) {
+    return;
+  }
+
   KMdiChildView *c = KstApp::inst()->findWindow(_window->currentText());
   if (!c) {
@@ -533,10 +538,5 @@ void KstPlotDialogI::new_I() {
   }
 
-  //check plot name
-  if (!checkPlotName()) {
-    return;
-  }
-
-  Kst2DPlotPtr plot = static_cast<KstViewWindow*>(c)->view()->createPlot<Kst2DPlot>(Name->text());
+  Kst2DPlotPtr plot = static_cast<KstViewWindow*>(c)->view()->createPlot<Kst2DPlot>(Name->text().stripWhiteSpace());
 
   if (_reGrid->isChecked()) {
@@ -581,5 +581,5 @@ void KstPlotDialogI::new_I() {
   //doc->setDelay(UpdateDelay->value());
 
-  _plotName = Name->text();
+  _plotName = Name->text().stripWhiteSpace();
   update();
 
@@ -595,5 +595,5 @@ void KstPlotDialogI::edit_I() {
 
   //check the plot name
-  if (Name->text() != Select->currentText()) {
+  if (Name->text().stripWhiteSpace() != Select->currentText()) {
     if (!checkPlotName()) {
     return;
@@ -613,5 +613,5 @@ void KstPlotDialogI::edit_I() {
     Kst2DPlotPtr plot = *plots.at(index);
 
-    plot->setTagName(Name->text());
+    plot->setTagName(Name->text().stripWhiteSpace());
     /* add the curves */
     plot->Curves.clear();
@@ -1190,7 +1190,16 @@ void KstPlotDialogI::newWindow() {
 
 bool KstPlotDialogI::checkPlotName() {
+  //first check if name is blank
+  if (Name->text().stripWhiteSpace().isEmpty()) {
+    QString message = i18n("The plot name is empty. Please enter a unique name for the plot.");
+    KMessageBox::sorry(this, message);
+    Name->setFocus();
+    return false;
+  }
+
+  //now check if it's a duplicate
   KstApp *app = KstApp::inst();
   KMdiIterator<KMdiChildView*> *iter;
-  QString name = Name->text();
+  QString name = Name->text().stripWhiteSpace();
   //check the name
   KstViewObjectPtr rc;
@@ -1202,7 +1211,6 @@ bool KstPlotDialogI::checkPlotName() {
       rc = viewwindow->view()->findChild(name);
       if (rc) {
-        QString message = i18n("Could not create a new plot.\n"
-            "%1: not a unique plot name.\n"
-            "Change it to a unique name.").arg(Name->text());
+        QString message = i18n("%1: not a unique plot name.\n"
+            "Change it to a unique name.").arg(Name->text().stripWhiteSpace());
 
         KMessageBox::sorry(this, message);





More information about the Kst mailing list