cylinders: add cylinder before hidden cylinders

When adding a cylinder, it was added at the end of the list.
This would make hidden cylinders visible as the new rule is
to only hide unused cylinders at the end of the list.

Therefore, add the cylinder after the last used cylinder,
i.e. before the first hidden cylinder.

This means that the position where the cylinder is added has
to be hidden in the undo command.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-11-21 11:39:02 +01:00 committed by Dirk Hohndel
parent a40b40ae7a
commit 1af67512a1
5 changed files with 42 additions and 34 deletions

View file

@ -1052,6 +1052,7 @@ AddCylinder::AddCylinder(bool currentDiveOnly) :
else
setText(Command::Base::tr("Add cylinder (%n dive(s))", "", dives.size()));
cyl = create_new_cylinder(dives[0]);
indexes.reserve(dives.size());
}
AddCylinder::~AddCylinder()
@ -1066,22 +1067,23 @@ bool AddCylinder::workToBeDone()
void AddCylinder::undo()
{
for (dive *d: dives) {
if (d->cylinders.nr <= 0)
continue;
remove_cylinder(d, d->cylinders.nr - 1);
update_cylinder_related_info(d);
emit diveListNotifier.cylinderRemoved(d, d->cylinders.nr);
invalidate_dive_cache(d); // Ensure that dive is written in git_save()
for (size_t i = 0; i < dives.size(); ++i) {
remove_cylinder(dives[i], indexes[i]);
update_cylinder_related_info(dives[i]);
emit diveListNotifier.cylinderRemoved(dives[i], indexes[i]);
invalidate_dive_cache(dives[i]); // Ensure that dive is written in git_save()
}
}
void AddCylinder::redo()
{
indexes.clear();
for (dive *d: dives) {
add_cloned_cylinder(&d->cylinders, cyl);
int index = first_hidden_cylinder(d);
indexes.push_back(index);
add_cylinder(&d->cylinders, index, clone_cylinder(cyl));
update_cylinder_related_info(d);
emit diveListNotifier.cylinderAdded(d, d->cylinders.nr - 1);
emit diveListNotifier.cylinderAdded(d, index);
invalidate_dive_cache(d); // Ensure that dive is written in git_save()
}
}