When deleting spot, selects the remaining one just before, fixes #5269

This commit is contained in:
Pandagrapher 2019-04-23 17:19:28 +02:00
parent 4cc2a34323
commit 13cad6cf73
3 changed files with 21 additions and 8 deletions

View File

@ -1718,28 +1718,32 @@ int ControlSpotPanel::getSelectedSpot()
return id;
}
void ControlSpotPanel::setSelectedSpot(const int id)
bool ControlSpotPanel::setSelectedSpot(const int id)
{
// printf("setSelectedSpot: %d\n", id);
MyMutex::MyLock lock(mTreeview);
disableParamlistener(true);
const Gtk::TreeModel::Children children = treemodel_->children();
for (auto iter = children.begin(); iter != children.end(); iter++) {
const Gtk::TreeModel::Row row = *iter;
if (row[spots_.id] == id) {
disableParamlistener(true);
treeview_->set_cursor(treemodel_->get_path(row));
load_ControlSpot_param();
updateParamVisibility();
updateCurveOpacity(row);
disableParamlistener(false);
return true;
}
}
disableParamlistener(false);
return false;
}
int ControlSpotPanel::getNewId()

View File

@ -152,8 +152,9 @@ public:
* Setter of selected spot
*
* @param id The id of spot to be selected
* @return True if a spot corresponding to the id has been selected
*/
void setSelectedSpot(const int id);
bool setSelectedSpot(const int id);
// Control spot creation functions
/**

View File

@ -1569,13 +1569,21 @@ void Locallab::write(ProcParams* pp, ParamsEdited* pedited)
if (pp->locallab.spots.at(i).id == spotId) {
// ProcParams update
pp->locallab.nbspot--;
pp->locallab.selspot = 0;
pp->locallab.spots.erase(pp->locallab.spots.begin() + i);
expsettings->deleteControlSpot(spotId);
// Select one remaining spot
// Select the first remaining spot before deleted one
if (pp->locallab.nbspot > 0) {
expsettings->setSelectedSpot(pp->locallab.spots.at(pp->locallab.selspot).id);
for (int j = i - 1; j >= 0; j--) { // procparams spots uses zero-based index whereas spot ids use one-based index
if (expsettings->setSelectedSpot(j + 1)) { // True if an existing spot has been selected on controlspotpanel
pp->locallab.selspot = j;
break;
}
}
} else {
// Reset selspot
pp->locallab.selspot = 0;
}
// Update Locallab tools GUI with selected spot