diff -r 943b258d5443 -r 5664ec82aed7 QTfrontend/ui/widget/selectWeapon.cpp --- a/QTfrontend/ui/widget/selectWeapon.cpp Sat Oct 07 01:05:55 2017 +0200 +++ b/QTfrontend/ui/widget/selectWeapon.cpp Sat Oct 07 03:43:06 2017 +0200 @@ -189,11 +189,19 @@ setWeapons(*cDefaultAmmoStore); } +//Save current weapons set. void SelWeaponWidget::save() { + //The save() function is called by ANY change of the combo box. + //If an entry is deleted, this code would just re-add the deleted + //item. We use isDeleted to check if we are currently deleting to + //prevent this. + if (isDeleting) + return; // TODO make this return if success or not, so that the page can react // properly and not goBack if saving failed - if (m_name->text() == "") return; + if (m_name->text() == "") + return; QString state1; QString state2; @@ -240,7 +248,7 @@ wconf->remove(curWeaponsName); } wconf->setValue(m_name->text(), stateFull); - emit weaponsChanged(); + emit weaponsEdited(curWeaponsName, m_name->text(), stateFull); } int SelWeaponWidget::operator [] (unsigned int weaponIndex) const @@ -256,10 +264,11 @@ void SelWeaponWidget::deleteWeaponsName() { - if (curWeaponsName == "") return; + QString delWeaponsName = curWeaponsName; + if (delWeaponsName == "") return; for(int i = 0; i < cDefaultAmmos.size(); i++) - if (!cDefaultAmmos[i].first.compare(m_name->text())) + if (!cDefaultAmmos[i].first.compare(delWeaponsName)) { QMessageBox deniedMsg(this); deniedMsg.setIcon(QMessageBox::Warning); @@ -273,19 +282,21 @@ QMessageBox reallyDeleteMsg(this); reallyDeleteMsg.setIcon(QMessageBox::Question); reallyDeleteMsg.setWindowTitle(QMessageBox::tr("Weapons - Are you sure?")); - reallyDeleteMsg.setText(QMessageBox::tr("Do you really want to delete the weapon set '%1'?").arg(curWeaponsName)); + reallyDeleteMsg.setText(QMessageBox::tr("Do you really want to delete the weapon set '%1'?").arg(delWeaponsName)); reallyDeleteMsg.setWindowModality(Qt::WindowModal); reallyDeleteMsg.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); if (reallyDeleteMsg.exec() == QMessageBox::Ok) { - wconf->remove(curWeaponsName); - emit weaponsDeleted(); + isDeleting = true; + wconf->remove(delWeaponsName); + emit weaponsDeleted(delWeaponsName); } } void SelWeaponWidget::newWeaponsName() { + save(); QString newName = tr("New"); if(wconf->contains(newName)) { @@ -294,6 +305,8 @@ while(wconf->contains(newName = tr("New (%1)").arg(i++))) ; } setWeaponsName(newName); + wconf->setValue(newName, *cEmptyAmmoStore); + emit weaponsAdded(newName, *cEmptyAmmoStore); } void SelWeaponWidget::setWeaponsName(const QString& name) @@ -312,6 +325,13 @@ } } +void SelWeaponWidget::switchWeapons(const QString& name) +{ + // Rescue old weapons set, then select new one + save(); + setWeaponsName(name); +} + QStringList SelWeaponWidget::getWeaponNames() const { return wconf->allKeys(); @@ -319,6 +339,7 @@ void SelWeaponWidget::copy() { + save(); if(wconf->contains(curWeaponsName)) { QString ammo = getWeaponsString(curWeaponsName); @@ -331,6 +352,8 @@ } setWeaponsName(newName); setWeapons(ammo); + wconf->setValue(newName, ammo); + emit weaponsAdded(newName, ammo); } } @@ -352,3 +375,8 @@ return sl.join(QString()); } + +void SelWeaponWidget::deletionDone() +{ + isDeleting = false; +}