undo: show multiple dive warning when editing equipment

When editing cylinders or weights directly in the table widgets,
no warning was shown if multiple dives were affected. To solve this,
emit signals from the respective models and catch them in dive
equipment tab. Not very nice, but it works for now.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-03-27 21:49:19 +01:00
parent 2eeb5f4fc2
commit 63414fc823
6 changed files with 22 additions and 8 deletions

View file

@ -35,6 +35,8 @@ TabDiveEquipment::TabDiveEquipment(QWidget *parent) : TabBase(parent),
connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &TabDiveEquipment::divesChanged); connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &TabDiveEquipment::divesChanged);
connect(ui.cylinders, &TableView::itemClicked, this, &TabDiveEquipment::editCylinderWidget); connect(ui.cylinders, &TableView::itemClicked, this, &TabDiveEquipment::editCylinderWidget);
connect(ui.weights, &TableView::itemClicked, this, &TabDiveEquipment::editWeightWidget); connect(ui.weights, &TableView::itemClicked, this, &TabDiveEquipment::editWeightWidget);
connect(cylindersModel->model(), &CylindersModel::divesEdited, this, &TabDiveEquipment::divesEdited);
connect(weightModel, &WeightModel::divesEdited, this, &TabDiveEquipment::divesEdited);
// Current display of things on Gnome3 looks like shit, so // Current display of things on Gnome3 looks like shit, so
// let's fix that. // let's fix that.

View file

@ -21,7 +21,6 @@ public:
~TabDiveEquipment(); ~TabDiveEquipment();
void updateData() override; void updateData() override;
void clear() override; void clear() override;
void divesEdited(int i);
void closeWarning(); void closeWarning();
private slots: private slots:
@ -32,6 +31,7 @@ private slots:
void editCylinderWidget(const QModelIndex &index); void editCylinderWidget(const QModelIndex &index);
void editWeightWidget(const QModelIndex &index); void editWeightWidget(const QModelIndex &index);
void on_suit_editingFinished(); void on_suit_editingFinished();
void divesEdited(int count);
private: private:
Ui::TabDiveEquipment ui; Ui::TabDiveEquipment ui;

View file

@ -473,7 +473,8 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
} else { } else {
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
// On the EquipmentTab - place an editCylinder command. // On the EquipmentTab - place an editCylinder command.
Command::editCylinder(index.row(), cyl, type, false); int count = Command::editCylinder(index.row(), cyl, type, false);
emit divesEdited(count);
#endif #endif
} }
return true; return true;
@ -718,10 +719,12 @@ void CylindersModel::commitTempCyl(int row)
return; return;
// Only submit a command if the type changed // Only submit a command if the type changed
if (!same_string(cyl->type.description, tempCyl.type.description) || gettextFromC::tr(cyl->type.description) != QString(tempCyl.type.description)) { if (!same_string(cyl->type.description, tempCyl.type.description) || gettextFromC::tr(cyl->type.description) != QString(tempCyl.type.description)) {
if (inPlanner) if (inPlanner) {
std::swap(*cyl, tempCyl); std::swap(*cyl, tempCyl);
else } else {
Command::editCylinder(tempRow, tempCyl, Command::EditCylinderType::TYPE, false); int count = Command::editCylinder(tempRow, tempCyl, Command::EditCylinderType::TYPE, false);
emit divesEdited(count);
}
} }
free_cylinder(tempCyl); free_cylinder(tempCyl);
tempRow = -1; tempRow = -1;

View file

@ -51,6 +51,9 @@ public:
bool updateBestMixes(); bool updateBestMixes();
bool cylinderUsed(int i) const; bool cylinderUsed(int i) const;
signals:
void divesEdited(int num);
public public
slots: slots:
void remove(QModelIndex index); void remove(QModelIndex index);

View file

@ -112,8 +112,10 @@ void WeightModel::commitTempWS()
return; return;
// Only submit a command if the type changed // Only submit a command if the type changed
weightsystem_t ws = d->weightsystems.weightsystems[tempRow]; weightsystem_t ws = d->weightsystems.weightsystems[tempRow];
if (!same_string(ws.description, tempWS.description) || gettextFromC::tr(ws.description) != QString(tempWS.description)) if (!same_string(ws.description, tempWS.description) || gettextFromC::tr(ws.description) != QString(tempWS.description)) {
Command::editWeight(tempRow, tempWS, false); int count = Command::editWeight(tempRow, tempWS, false);
emit divesEdited(count);
}
tempRow = -1; tempRow = -1;
#endif #endif
} }
@ -126,7 +128,8 @@ bool WeightModel::setData(const QModelIndex &index, const QVariant &value, int r
switch (index.column()) { switch (index.column()) {
case WEIGHT: case WEIGHT:
ws.weight = string_to_weight(qPrintable(vString)); ws.weight = string_to_weight(qPrintable(vString));
Command::editWeight(index.row(), ws, false); int count = Command::editWeight(index.row(), ws, false);
emit divesEdited(count);
return true; return true;
} }
return false; return false;

View file

@ -29,6 +29,9 @@ public:
void updateDive(dive *d); void updateDive(dive *d);
weightsystem_t weightSystemAt(const QModelIndex &index) const; weightsystem_t weightSystemAt(const QModelIndex &index) const;
signals:
void divesEdited(int num);
public public
slots: slots:
void weightsystemsReset(const QVector<dive *> &dives); void weightsystemsReset(const QVector<dive *> &dives);