aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--commands/command.cpp9
-rw-r--r--commands/command.h3
-rw-r--r--commands/command_device.cpp41
-rw-r--r--commands/command_device.h17
-rw-r--r--commands/command_divelist.cpp13
-rw-r--r--core/subsurface-qt/divelistnotifier.h4
6 files changed, 15 insertions, 72 deletions
diff --git a/commands/command.cpp b/commands/command.cpp
index 4125d994b..ff53db16c 100644
--- a/commands/command.cpp
+++ b/commands/command.cpp
@@ -381,14 +381,9 @@ void addPictures(const std::vector<PictureListForAddition> &pictures)
execute(new AddPictures(pictures));
}
-void removeDevice(int idx)
+void editDeviceNickname(struct divecomputer *dc, const QString &nickname)
{
- execute(new RemoveDevice(idx));
-}
-
-void editDeviceNickname(int idx, const QString &nickname)
-{
- execute(new EditDeviceNickname(idx, nickname));
+ execute(new EditDeviceNickname(dc, nickname));
}
void createFilterPreset(const QString &name, const FilterData &data)
diff --git a/commands/command.h b/commands/command.h
index bb6edcd81..19908ca7c 100644
--- a/commands/command.h
+++ b/commands/command.h
@@ -141,8 +141,7 @@ void addPictures(const std::vector<PictureListForAddition> &pictures);
// 8) Device commands
-void removeDevice(int idx);
-void editDeviceNickname(int idx, const QString &nickname);
+void editDeviceNickname(struct divecomputer *dc, const QString &nickname);
// 9) Filter commands
diff --git a/commands/command_device.cpp b/commands/command_device.cpp
index afd368b55..a72a4340d 100644
--- a/commands/command_device.cpp
+++ b/commands/command_device.cpp
@@ -5,43 +5,14 @@
namespace Command {
-RemoveDevice::RemoveDevice(int indexIn) : index(indexIn)
+EditDeviceNickname::EditDeviceNickname(const struct divecomputer *dc, const QString &nicknameIn) :
+ nickname(nicknameIn.toStdString())
{
- const device *dev = get_device(&device_table, index);
- if (!dev)
- return;
-
- setText(Command::Base::tr("Delete device %1 (0x%2)").arg(QString::fromStdString(dev->model),
- QString::number(dev->deviceId)));
-}
-
-bool RemoveDevice::workToBeDone()
-{
- return get_device(&device_table, index) != nullptr;
-}
-
-void RemoveDevice::redo()
-{
- dev = *get_device(&device_table, index);
- remove_from_device_table(&device_table, index);
- emit diveListNotifier.deviceDeleted(index);
-}
-
-void RemoveDevice::undo()
-{
- index = add_to_device_table(&device_table, &dev);
- emit diveListNotifier.deviceAdded(index);
-}
-
-EditDeviceNickname::EditDeviceNickname(int indexIn, const QString &nicknameIn) :
- index(indexIn), nickname(nicknameIn.toStdString())
-{
- const device *dev = get_device(&device_table, index);
- if (!dev)
+ index = get_or_add_device_for_dc(&device_table, dc);
+ if (index == -1)
return;
- setText(Command::Base::tr("Set nickname of device %1 (0x%2) to %3").arg(QString::fromStdString(dev->model),
- QString::number(dev->deviceId,1 ,16), nicknameIn));
+ setText(Command::Base::tr("Set nickname of device %1 (serial %2) to %3").arg(dc->model, dc->serial, nicknameIn));
}
bool EditDeviceNickname::workToBeDone()
@@ -55,7 +26,7 @@ void EditDeviceNickname::redo()
if (!dev)
return;
std::swap(dev->nickName, nickname);
- emit diveListNotifier.deviceEdited(index);
+ emit diveListNotifier.deviceEdited();
}
void EditDeviceNickname::undo()
diff --git a/commands/command_device.h b/commands/command_device.h
index c1cf1a240..b948e63e9 100644
--- a/commands/command_device.h
+++ b/commands/command_device.h
@@ -12,24 +12,9 @@ struct device;
// We put everything in a namespace, so that we can shorten names without polluting the global namespace
namespace Command {
-class RemoveDevice final : public Base {
-public:
- RemoveDevice(int index);
-private:
- // for undo
- device dev;
-
- // for redo
- int index;
-
- void undo() override;
- void redo() override;
- bool workToBeDone() override;
-};
-
class EditDeviceNickname final : public Base {
public:
- EditDeviceNickname(int index, const QString &nickname);
+ EditDeviceNickname(const divecomputer *dc, const QString &nickname);
private:
// for redo and undo
int index;
diff --git a/commands/command_divelist.cpp b/commands/command_divelist.cpp
index baf81c1ac..f7e6b8f71 100644
--- a/commands/command_divelist.cpp
+++ b/commands/command_divelist.cpp
@@ -553,10 +553,8 @@ void ImportDives::redoit()
divesAndSitesToRemove = std::move(divesAndSitesToRemoveNew);
// Add devices
- for (const device &dev: devicesToAddAndRemove.devices) {
- int idx = add_to_device_table(&device_table, &dev);
- emit diveListNotifier.deviceAdded(idx);
- }
+ for (const device &dev: devicesToAddAndRemove.devices)
+ add_to_device_table(&device_table, &dev);
// Add new filter presets
for (auto &it: filterPresetsToAdd) {
@@ -583,11 +581,8 @@ void ImportDives::undoit()
setSelection(selection, currentDive);
// Remove devices
- for (const device &dev: devicesToAddAndRemove.devices) {
- int idx = remove_device(&device_table, &dev);
- if (idx >= 0)
- emit diveListNotifier.deviceDeleted(idx);
- }
+ for (const device &dev: devicesToAddAndRemove.devices)
+ remove_device(&device_table, &dev);
// Remove filter presets. Do this in reverse order.
for (auto it = filterPresetsToRemove.rbegin(); it != filterPresetsToRemove.rend(); ++it) {
diff --git a/core/subsurface-qt/divelistnotifier.h b/core/subsurface-qt/divelistnotifier.h
index 033458915..a778f7d91 100644
--- a/core/subsurface-qt/divelistnotifier.h
+++ b/core/subsurface-qt/divelistnotifier.h
@@ -132,9 +132,7 @@ signals:
void picturesAdded(dive *d, QVector<PictureObj> pics);
// Devices related signals
- void deviceAdded(int index);
- void deviceDeleted(int index);
- void deviceEdited(int index);
+ void deviceEdited();
// Filter related signals
void filterPresetAdded(int index);