[Kst] extragear/graphics/kst/src/libkstapp

Andrew Walker arwalker at sumusltd.com
Tue Mar 28 20:29:54 CEST 2006


SVN commit 523647 by arwalker:

BUG:124367 Ensure a unique plot name. Nicolas, I believe this should fix the problem you described. Thanks for describing the scenario so cleanly.

 M  +30 -5     kst2dplot.cpp  


--- trunk/extragear/graphics/kst/src/libkstapp/kst2dplot.cpp #523646:523647
@@ -435,11 +435,36 @@
   _type = "Plot";
 
   if (name.isEmpty()) {
-    plotName = KST::suggestPlotName();
+    plotName = i18n("Copy-%1").arg(plot.tagName());
   } else {
     plotName = name;
   }
 
+  KstApp *app = KstApp::inst();
+  KMdiIterator<KMdiChildView*> *iter;
+  bool duplicate = true;
+  static int last = 0;
+  
+  // check for unique plot name
+  while (duplicate) {
+    duplicate = false;
+    iter = app->createIterator();
+    while (iter->currentItem() && !duplicate) {
+      KMdiChildView *childview = iter->currentItem();
+      KstViewWindow *viewwindow = dynamic_cast<KstViewWindow*>(childview);
+      if (viewwindow) {
+        if (viewwindow->view()->findChild(plotName)) {
+          ++last;
+          plotName = i18n("Copy%1-%2").arg(last).arg(plot.tagName());
+          duplicate = true;
+          break;
+        }
+      }
+      iter->next();
+    }
+    app->deleteIterator(iter);
+  }
+  
   commonConstructor(plotName,
                     plot._xScaleMode,
                     plot._yScaleMode,
@@ -3256,14 +3281,14 @@
 
 
 void Kst2DPlot::copyObjectQuietly(KstViewObject& parent, const QString& name) const {
-  QString plotName;
-
+  QString plotName; 
+  
   if (name.isEmpty()) {
-    plotName = KST::suggestPlotName();
+    plotName = i18n("Copy-%1").arg(tagName());
   } else {
     plotName = name;
   }
-
+  
   parent.appendChild(new Kst2DPlot(*this, plotName), true);
 }
 


More information about the Kst mailing list