Consistent variable names in UndoCommands class

Implements a uniform variable naming scheme in the undocommands
class.

Signed-off-by: Grace Karanja <gracie.karanja89@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Grace Karanja 2015-03-17 07:48:45 +03:00 committed by Dirk Hohndel
parent d2b8fb31eb
commit 8fe738bf64
2 changed files with 21 additions and 22 deletions

View file

@ -2,18 +2,18 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "divelist.h" #include "divelist.h"
UndoDeleteDive::UndoDeleteDive(QList<dive *> diveList) UndoDeleteDive::UndoDeleteDive(QList<dive *> deletedDives)
: diveList(deletedDives)
{ {
dives = diveList;
setText("delete dive"); setText("delete dive");
if (dives.count() > 1) if (diveList.count() > 1)
setText(QString("delete %1 dives").arg(QString::number(dives.count()))); setText(QString("delete %1 dives").arg(QString::number(diveList.count())));
} }
void UndoDeleteDive::undo() void UndoDeleteDive::undo()
{ {
for (int i = 0; i < dives.count(); i++) for (int i = 0; i < diveList.count(); i++)
record_dive(dives.at(i)); record_dive(diveList.at(i));
mark_divelist_changed(true); mark_divelist_changed(true);
MainWindow::instance()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
} }
@ -21,32 +21,31 @@ void UndoDeleteDive::undo()
void UndoDeleteDive::redo() void UndoDeleteDive::redo()
{ {
QList<struct dive*> newList; QList<struct dive*> newList;
for (int i = 0; i < dives.count(); i++) { for (int i = 0; i < diveList.count(); i++) {
//make a copy of the dive before deleting it //make a copy of the dive before deleting it
struct dive* d = alloc_dive(); struct dive* d = alloc_dive();
copy_dive(dives.at(i), d); copy_dive(diveList.at(i), d);
newList.append(d); newList.append(d);
//delete the dive //delete the dive
delete_single_dive(get_divenr(dives.at(i))); delete_single_dive(get_divenr(diveList.at(i)));
} }
mark_divelist_changed(true); mark_divelist_changed(true);
MainWindow::instance()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
dives.clear(); diveList.clear();
dives = newList; diveList = newList;
} }
UndoShiftTime::UndoShiftTime(QList<int> diveList, int amount) UndoShiftTime::UndoShiftTime(QList<int> changedDives, int amount)
: diveList(changedDives), timeChanged(amount)
{ {
setText("shift time"); setText("shift time");
dives = diveList;
timeChanged = amount;
} }
void UndoShiftTime::undo() void UndoShiftTime::undo()
{ {
for (int i = 0; i < dives.count(); i++) { for (int i = 0; i < diveList.count(); i++) {
struct dive* d = get_dive_by_uniq_id(dives.at(i)); struct dive* d = get_dive_by_uniq_id(diveList.at(i));
d->when -= timeChanged; d->when -= timeChanged;
} }
mark_divelist_changed(true); mark_divelist_changed(true);
@ -55,8 +54,8 @@ void UndoShiftTime::undo()
void UndoShiftTime::redo() void UndoShiftTime::redo()
{ {
for (int i = 0; i < dives.count(); i++) { for (int i = 0; i < diveList.count(); i++) {
struct dive* d = get_dive_by_uniq_id(dives.at(i)); struct dive* d = get_dive_by_uniq_id(diveList.at(i));
d->when += timeChanged; d->when += timeChanged;
} }
mark_divelist_changed(true); mark_divelist_changed(true);

View file

@ -7,22 +7,22 @@
class UndoDeleteDive : public QUndoCommand { class UndoDeleteDive : public QUndoCommand {
public: public:
UndoDeleteDive(QList<struct dive*> diveList); UndoDeleteDive(QList<struct dive*> deletedDives);
virtual void undo(); virtual void undo();
virtual void redo(); virtual void redo();
private: private:
QList<struct dive*> dives; QList<struct dive*> diveList;
}; };
class UndoShiftTime : public QUndoCommand { class UndoShiftTime : public QUndoCommand {
public: public:
UndoShiftTime(QList<int> diveList, int amount); UndoShiftTime(QList<int> changedDives, int amount);
virtual void undo(); virtual void undo();
virtual void redo(); virtual void redo();
private: private:
QList<int> dives; QList<int> diveList;
int timeChanged; int timeChanged;
}; };