# HG changeset patch # User Tobias Domhan # Date 1301088904 -7200 # Node ID 97c6505009915c96fed9ab9309d807a0e5b4de64 # Parent 3c43f00b0743ac9b82fdf17021a2548363993a26 solved issue 197 and other issues that were caused when copying or creating a new weapon set that was named like an already existing one. this will now be avoided. diff -r 3c43f00b0743 -r 97c650500991 QTfrontend/selectWeapon.cpp --- a/QTfrontend/selectWeapon.cpp Sun Mar 20 08:42:32 2011 +0000 +++ b/QTfrontend/selectWeapon.cpp Fri Mar 25 23:35:04 2011 +0200 @@ -30,6 +30,7 @@ #include #include #include +#include #include QImage getAmmoImage(int num) @@ -250,7 +251,13 @@ void SelWeaponWidget::newWeaponsName() { - setWeaponsName(tr("new")); + QString newName = tr("new"); + if(wconf->contains(newName)) { + //name already used -> look for an appropriate name: + int i=2; + while(wconf->contains(newName = tr("new")+QString::number(i++))); + } + setWeaponsName(newName); } void SelWeaponWidget::setWeaponsName(const QString& name) @@ -273,7 +280,15 @@ void SelWeaponWidget::copy() { - QString ammo = getWeaponsString(curWeaponsName); - setWeaponsName(tr("copy of") + " " + curWeaponsName); - setWeapons(ammo); + if(wconf->contains(curWeaponsName)) { + QString ammo = getWeaponsString(curWeaponsName); + QString newName = tr("copy of") + " " + curWeaponsName; + if(wconf->contains(newName)) { + //name already used -> look for an appropriate name: + int i=2; + while(wconf->contains(newName = tr("copy of") + " " + curWeaponsName+QString::number(i++))); + } + setWeaponsName(newName); + setWeapons(ammo); + } } diff -r 3c43f00b0743 -r 97c650500991 QTfrontend/selectWeapon.h --- a/QTfrontend/selectWeapon.h Sun Mar 20 08:42:32 2011 +0000 +++ b/QTfrontend/selectWeapon.h Fri Mar 25 23:35:04 2011 +0200 @@ -56,6 +56,7 @@ public slots: void setDefault(); void setWeapons(const QString& ammo); + //sets the name of the current set void setWeaponsName(const QString& name); void deleteWeaponsName(); void newWeaponsName(); @@ -67,10 +68,12 @@ void weaponsDeleted(); private: + //the name of the current weapon set QString curWeaponsName; QLineEdit* m_name; + //storage for all the weapons sets QSettings* wconf; const int m_numItems; @@ -79,6 +82,7 @@ typedef QList ItemsList; typedef QMap twi; twi weaponItems; + //layout element for each tab: QGridLayout* p1Layout; QGridLayout* p2Layout; QGridLayout* p3Layout;