mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Since everything is C++ now, we can use unique_ptr<>s. This makes the code significantly shorter, because we can now use the default move constructor and assignment operators. This has a semantic change when std::move()-ing the divelog: now not the contents of the tables are moved, but the pointers. That is, the moved-from object now has no more tables and must not be used anymore. This made it necessary to replace std::move()s by std::swap()s. In that regard, the old code was in principle broken: it used moved-from objects, which may work but usually doesn't. This commit adds a myriad of .get() function calls where the code expects a C-style pointer. The plan is to remove virtually all of them, when we move free-standing functions into the class it acts on. Or, replace C-style pointers by references where we don't support NULL. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
38 lines
921 B
C++
38 lines
921 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, dc->serial, 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
|