mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
undo/device: adjust device management infrastructure
We no longer need the remove infrastructure, and the edit nickname function becomes much more intuitive to use by passing in the dive computer for which we want to create a nickname instead of the internal index into the array of devices. This also removes / simplifies the device list update signals in the DiveListNotifier. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
fbe17e620e
commit
e7a5ec46f5
6 changed files with 15 additions and 72 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
index = get_or_add_device_for_dc(&device_table, dc);
|
||||
if (index == -1)
|
||||
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)
|
||||
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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue