mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Undo: implement undo of rating and visibility rating
This was rather trivial and modeled after the previous edit UndoCommands. Since this is the first time we're editing integers a new constructor instantiation had to be added. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
512a2e6b68
commit
42cfd3f963
5 changed files with 86 additions and 16 deletions
|
@ -145,4 +145,14 @@ void editSuit(const QVector<dive *> dives, const QString &newValue, const QStrin
|
||||||
execute(new EditSuit(dives, newValue, oldValue));
|
execute(new EditSuit(dives, newValue, oldValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void editRating(const QVector<dive *> dives, int newValue, int oldValue)
|
||||||
|
{
|
||||||
|
execute(new EditRating(dives, newValue, oldValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
void editVisibility(const QVector<dive *> dives, int newValue, int oldValue)
|
||||||
|
{
|
||||||
|
execute(new EditVisibility(dives, newValue, oldValue));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Command
|
} // namespace Command
|
||||||
|
|
|
@ -55,6 +55,8 @@ void purgeUnusedDiveSites();
|
||||||
void editNotes(const QVector<dive *> dives, const QString &newValue, const QString &oldValue);
|
void editNotes(const QVector<dive *> dives, const QString &newValue, const QString &oldValue);
|
||||||
void editSuit(const QVector<dive *> dives, const QString &newValue, const QString &oldValue);
|
void editSuit(const QVector<dive *> dives, const QString &newValue, const QString &oldValue);
|
||||||
void editMode(const QVector<dive *> dives, int index, int newValue, int oldValue);
|
void editMode(const QVector<dive *> dives, int index, int newValue, int oldValue);
|
||||||
|
void editRating(const QVector<dive *> dives, int newValue, int oldValue);
|
||||||
|
void editVisibility(const QVector<dive *> dives, int newValue, int oldValue);
|
||||||
|
|
||||||
} // namespace Command
|
} // namespace Command
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,8 @@ void EditBase<T>::undo()
|
||||||
// class by virtue of a "using" declaration.
|
// class by virtue of a "using" declaration.
|
||||||
template
|
template
|
||||||
EditBase<QString>::EditBase(const QVector<dive *> &dives, QString oldValue, QString newValue);
|
EditBase<QString>::EditBase(const QVector<dive *> &dives, QString oldValue, QString newValue);
|
||||||
|
template
|
||||||
|
EditBase<int>::EditBase(const QVector<dive *> &dives, int oldValue, int newValue);
|
||||||
|
|
||||||
// Undo and redo do the same as just the stored value is exchanged
|
// Undo and redo do the same as just the stored value is exchanged
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -122,6 +124,48 @@ DiveField EditSuit::fieldId() const
|
||||||
return DiveField::SUIT;
|
return DiveField::SUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ***** Rating *****
|
||||||
|
void EditRating::set(struct dive *d, int value) const
|
||||||
|
{
|
||||||
|
d->rating = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int EditRating::data(struct dive *d) const
|
||||||
|
{
|
||||||
|
return d->rating;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString EditRating::fieldName() const
|
||||||
|
{
|
||||||
|
return tr("rating");
|
||||||
|
}
|
||||||
|
|
||||||
|
DiveField EditRating::fieldId() const
|
||||||
|
{
|
||||||
|
return DiveField::RATING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ***** Visibility ****
|
||||||
|
void EditVisibility::set(struct dive *d, int value) const
|
||||||
|
{
|
||||||
|
d->visibility = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int EditVisibility::data(struct dive *d) const
|
||||||
|
{
|
||||||
|
return d->visibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString EditVisibility::fieldName() const
|
||||||
|
{
|
||||||
|
return tr("visibility");
|
||||||
|
}
|
||||||
|
|
||||||
|
DiveField EditVisibility::fieldId() const
|
||||||
|
{
|
||||||
|
return DiveField::VISIBILITY;
|
||||||
|
}
|
||||||
|
|
||||||
// ***** Mode *****
|
// ***** Mode *****
|
||||||
// Editing the dive mode has very peculiar semantics for historic reasons:
|
// Editing the dive mode has very peculiar semantics for historic reasons:
|
||||||
// Since the dive-mode depends on the dive computer, the i-th dive computer
|
// Since the dive-mode depends on the dive computer, the i-th dive computer
|
||||||
|
|
|
@ -65,6 +65,24 @@ public:
|
||||||
DiveField fieldId() const override;
|
DiveField fieldId() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class EditRating : public EditBase<int> {
|
||||||
|
public:
|
||||||
|
using EditBase<int>::EditBase; // Use constructor of base class.
|
||||||
|
void set(struct dive *d, int value) const override;
|
||||||
|
int data(struct dive *d) const override;
|
||||||
|
QString fieldName() const override;
|
||||||
|
DiveField fieldId() const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class EditVisibility : public EditBase<int> {
|
||||||
|
public:
|
||||||
|
using EditBase<int>::EditBase; // Use constructor of base class.
|
||||||
|
void set(struct dive *d, int value) const override;
|
||||||
|
int data(struct dive *d) const override;
|
||||||
|
QString fieldName() const override;
|
||||||
|
DiveField fieldId() const override;
|
||||||
|
};
|
||||||
|
|
||||||
class EditMode : public EditBase<int> {
|
class EditMode : public EditBase<int> {
|
||||||
int index;
|
int index;
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -342,6 +342,12 @@ void MainTab::divesEdited(const QVector<dive *> &, DiveField field)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch(field) {
|
switch(field) {
|
||||||
|
case DiveField::RATING:
|
||||||
|
ui.rating->setCurrentStars(current_dive->rating);
|
||||||
|
break;
|
||||||
|
case DiveField::VISIBILITY:
|
||||||
|
ui.visibility->setCurrentStars(current_dive->visibility);
|
||||||
|
break;
|
||||||
case DiveField::SUIT:
|
case DiveField::SUIT:
|
||||||
ui.suit->setText(QString(current_dive->suit));
|
ui.suit->setText(QString(current_dive->suit));
|
||||||
break;
|
break;
|
||||||
|
@ -798,10 +804,6 @@ void MainTab::acceptChanges()
|
||||||
struct dive *cd = current_dive;
|
struct dive *cd = current_dive;
|
||||||
// now check if something has changed and if yes, edit the selected dives that
|
// 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)
|
// were identical with the master dive shown (and mark the divelist as changed)
|
||||||
if (displayed_dive.rating != cd->rating)
|
|
||||||
MODIFY_DIVES(selectedDives, EDIT_VALUE(rating));
|
|
||||||
if (displayed_dive.visibility != cd->visibility)
|
|
||||||
MODIFY_DIVES(selectedDives, EDIT_VALUE(visibility));
|
|
||||||
if (displayed_dive.airtemp.mkelvin != cd->airtemp.mkelvin)
|
if (displayed_dive.airtemp.mkelvin != cd->airtemp.mkelvin)
|
||||||
MODIFY_DIVES(selectedDives, EDIT_VALUE(airtemp.mkelvin));
|
MODIFY_DIVES(selectedDives, EDIT_VALUE(airtemp.mkelvin));
|
||||||
if (displayed_dive.watertemp.mkelvin != cd->watertemp.mkelvin)
|
if (displayed_dive.watertemp.mkelvin != cd->watertemp.mkelvin)
|
||||||
|
@ -1378,24 +1380,18 @@ void MainTab::on_notes_editingFinished()
|
||||||
|
|
||||||
void MainTab::on_rating_valueChanged(int value)
|
void MainTab::on_rating_valueChanged(int value)
|
||||||
{
|
{
|
||||||
if (acceptingEdit == true)
|
if (acceptingEdit == true || !current_dive)
|
||||||
return;
|
return;
|
||||||
if (displayed_dive.rating != value) {
|
|
||||||
displayed_dive.rating = value;
|
Command::editRating(getSelectedDivesCurrentLast(), value, current_dive->rating);
|
||||||
modified = true;
|
|
||||||
enableEdition();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainTab::on_visibility_valueChanged(int value)
|
void MainTab::on_visibility_valueChanged(int value)
|
||||||
{
|
{
|
||||||
if (acceptingEdit == true)
|
if (acceptingEdit == true || !current_dive)
|
||||||
return;
|
return;
|
||||||
if (displayed_dive.visibility != value) {
|
|
||||||
displayed_dive.visibility = value;
|
Command::editVisibility(getSelectedDivesCurrentLast(), value, current_dive->visibility);
|
||||||
modified = true;
|
|
||||||
enableEdition();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef MODIFY_DIVES
|
#undef MODIFY_DIVES
|
||||||
|
|
Loading…
Add table
Reference in a new issue