undo: remove TabDiveWidget::acceptChanges and rejectChanges

Since cylinders are now edited using the undo system, these
functions are not needed anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-02-27 18:40:32 +01:00
parent 04ce908e8e
commit 0732bb2302
3 changed files with 0 additions and 91 deletions

View file

@ -183,87 +183,6 @@ void TabDiveEquipment::editWeightWidget(const QModelIndex &index)
ui.weights->edit(index); ui.weights->edit(index);
} }
// tricky little macro to edit all the selected dives
// loop ove all DIVES and do WHAT.
#define MODIFY_DIVES(DIVES, WHAT) \
do { \
for (dive *mydive: DIVES) { \
invalidate_dive_cache(mydive); \
WHAT; \
} \
mark_divelist_changed(true); \
} while (0)
// Get the list of selected dives, but put the current dive at the last position of the vector
static QVector<dive *> getSelectedDivesCurrentLast()
{
QVector<dive *> res;
struct dive *d;
int i;
for_each_dive (i, d) {
if (d->selected && d != current_dive)
res.append(d);
}
res.append(current_dive);
return res;
}
// TODO: This is a temporary functions until undo of cylinders is implemented.
// Therefore it is not worth putting it in a header.
extern bool cylinders_equal(const dive *d1, const dive *d2);
void TabDiveEquipment::acceptChanges()
{
bool do_replot = false;
// now check if something has changed and if yes, edit the selected dives that
// were identical with the master dive shown (and mark the divelist as changed)
struct dive *cd = current_dive;
// Get list of selected dives, but put the current dive last;
// this is required in case the invocation wants to compare things
// to the original value in current_dive like it should
QVector<dive *> selectedDives = getSelectedDivesCurrentLast();
if (cylindersModel->model()->changed) {
mark_divelist_changed(true);
MODIFY_DIVES(selectedDives,
// if we started out with the same cylinder description (for multi-edit) or if we do copt & paste
// make sure that we have the same cylinder type and copy the gasmix, but DON'T copy the start
// and end pressures (those are per dive after all)
if (cylinders_equal(mydive, cd) && mydive != cd)
copy_cylinder_types(&displayed_dive, cd);
copy_cylinders(&displayed_dive.cylinders, &cd->cylinders);
);
/* if cylinders changed we may have changed gas change events
* and sensor idx in samples as well
* - so far this is ONLY supported for a single selected dive */
struct divecomputer *tdc = &current_dive->dc;
struct divecomputer *sdc = &displayed_dive.dc;
while(tdc && sdc) {
free_events(tdc->events);
copy_events(sdc, tdc);
free(tdc->sample);
copy_samples(sdc, tdc);
tdc = tdc->next;
sdc = sdc->next;
}
do_replot = true;
}
if (do_replot)
MainWindow::instance()->graphics->replot();
cylindersModel->model()->changed = false;
}
void TabDiveEquipment::rejectChanges()
{
cylindersModel->model()->changed = false;
cylindersModel->updateDive(current_dive);
weightModel->updateDive(current_dive);
}
void TabDiveEquipment::divesEdited(int i) void TabDiveEquipment::divesEdited(int i)
{ {
// No warning if only one dive was edited // No warning if only one dive was edited

View file

@ -21,8 +21,6 @@ public:
~TabDiveEquipment(); ~TabDiveEquipment();
void updateData() override; void updateData() override;
void clear() override; void clear() override;
void acceptChanges();
void rejectChanges();
void divesEdited(int i); void divesEdited(int i);
void closeWarning(); void closeWarning();

View file

@ -534,10 +534,6 @@ void MainTab::acceptChanges()
ui.dateEdit->setEnabled(true); ui.dateEdit->setEnabled(true);
hideMessage(); hideMessage();
// TODO: This is a temporary hack until the equipment tab is included in the undo system:
// The equipment tab is hardcoded at the first place of the "extra widgets".
((TabDiveEquipment *)extraWidgets[0])->acceptChanges();
if (lastMode == MANUALLY_ADDED_DIVE) { if (lastMode == MANUALLY_ADDED_DIVE) {
MainWindow::instance()->showProfile(); MainWindow::instance()->showProfile();
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
@ -606,10 +602,6 @@ void MainTab::rejectChanges()
clear_dive(&displayed_dive); clear_dive(&displayed_dive);
updateDiveInfo(); updateDiveInfo();
// TODO: This is a temporary hack until the equipment tab is included in the undo system:
// The equipment tab is hardcoded at the first place of the "extra widgets".
((TabDiveEquipment *)extraWidgets[0])->rejectChanges();
// the user could have edited the location and then canceled the edit // the user could have edited the location and then canceled the edit
// let's get the correct location back in view // let's get the correct location back in view
MapWidget::instance()->centerOnDiveSite(current_dive ? current_dive->dive_site : nullptr); MapWidget::instance()->centerOnDiveSite(current_dive ? current_dive->dive_site : nullptr);