QTfrontend/model/ammoSchemeModel.cpp
changeset 12671 1d25f5555c38
parent 12263 41af2274953d
child 12902 fc47fc4af6bd
child 12927 c0320d66310d
--- a/QTfrontend/model/ammoSchemeModel.cpp	Sat Oct 07 03:43:06 2017 +0200
+++ b/QTfrontend/model/ammoSchemeModel.cpp	Sat Oct 07 18:43:31 2017 +0200
@@ -724,6 +724,18 @@
         return defaultScheme.size();
 }
 
+bool AmmoSchemeModel::hasScheme(QString name)
+{
+    for(int i=0; i<schemes.size(); i++)
+    {
+        if(schemes[i][0] == name)
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
 Qt::ItemFlags AmmoSchemeModel::flags(const QModelIndex & index) const
 {
     Q_UNUSED(index);
@@ -757,13 +769,29 @@
     if (row == -1)
     {
         QList<QVariant> newScheme = defaultScheme;
-        newScheme[0] = QVariant(tr("New"));
+
+        QString newName = tr("New");
+        if(hasScheme(newName))
+        {
+            //name already used -> look for an appropriate name:
+            int i=2;
+            while(hasScheme(newName = tr("New (%1)").arg(i++))) ;
+        }
+        newScheme[0] = QVariant(newName);
         schemes.insert(schemes.size(), newScheme);
     }
     else
     {
         QList<QVariant> newScheme = schemes[row];
-        newScheme[0] = QVariant(tr("Copy of %1").arg(newScheme[0].toString()));
+        QString oldName = newScheme[0].toString();
+        QString newName = tr("Copy of %1").arg(oldName);
+        if(hasScheme(newName))
+        {
+            //name already used -> look for an appropriate name:
+            int i=2;
+            while(hasScheme(newName = tr("Copy of %1 (%2)").arg(oldName).arg(i++)));
+        }
+        newScheme[0] = QVariant(newName);
         schemes.insert(schemes.size(), newScheme);
     }