subsurface/commands/command_device.cpp
Berthold Stoeger b9a2eff3c9 core: turn string data in struct divecomputer into std::string
Simplifies memory management.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00

38 lines
937 B
C++

// SPDX-License-Identifier: GPL-2.0
#include "command_device.h"
#include "core/divelog.h"
#include "core/subsurface-qt/divelistnotifier.h"
namespace Command {
EditDeviceNickname::EditDeviceNickname(const struct divecomputer *dc, const QString &nicknameIn) :
nickname(nicknameIn.toStdString())
{
index = get_or_add_device_for_dc(divelog.devices.get(), dc);
if (index == -1)
return;
setText(Command::Base::tr("Set nickname of device %1 (serial %2) to %3").arg(dc->model.c_str(), dc->serial.c_str(), nicknameIn));
}
bool EditDeviceNickname::workToBeDone()
{
return get_device(divelog.devices.get(), index) != nullptr;
}
void EditDeviceNickname::redo()
{
device *dev = get_device_mutable(divelog.devices.get(), index);
if (!dev)
return;
std::swap(dev->nickName, nickname);
emit diveListNotifier.deviceEdited();
}
void EditDeviceNickname::undo()
{
redo(); // undo() and redo() do the same thing
}
} // namespace Command