QTfrontend/ui/page/pageeditteam.cpp
changeset 12670 967990d958bc
parent 12669 bc34fc75670e
child 12684 5f68b259305c
--- a/QTfrontend/ui/page/pageeditteam.cpp	Sat Oct 07 20:07:21 2017 +0200
+++ b/QTfrontend/ui/page/pageeditteam.cpp	Sun Oct 08 04:14:49 2017 +0200
@@ -610,7 +610,35 @@
 
 void PageEditTeam::saveTeam()
 {
-    data().saveToFile();
+    HWTeam team = data();
+    if(!team.wouldOverwriteOtherFile())
+    {
+        team.saveToFile();
+    }
+    else
+    {
+        // Name already used -> look for an appropriate name:
+        int i=2;
+        QString origName = team.name();
+        QString newName;
+        while(team.wouldOverwriteOtherFile())
+        {
+            newName = tr("%1 (%2)").arg(origName).arg(i++);
+            team.setName(newName);
+            if(i > 1000)
+                break;
+        }
+
+        QMessageBox teamNameFixedMsg(this);
+        teamNameFixedMsg.setIcon(QMessageBox::Warning);
+        teamNameFixedMsg.setWindowTitle(QMessageBox::tr("Teams - Name already taken"));
+        teamNameFixedMsg.setText(QMessageBox::tr("The team name '%1' is already taken, so your team has been renamed to '%2'.").arg(origName).arg(team.name()));
+        teamNameFixedMsg.setWindowModality(Qt::WindowModal);
+        teamNameFixedMsg.setStandardButtons(QMessageBox::Ok);
+        teamNameFixedMsg.exec();
+
+        team.saveToFile();
+    }
 }
 
 // When the "Use default for all binds" is pressed...