Add (nonfunctional) dive computer rename hooks

This adds the menu item to rename a dive computer (ie create a nickname
for it) when right-clicking on the dive computer name of a dive computer
that has a serial number (indicated by having a non-zero ->deviceid).

It is nonfunctional because it's really just the skeleton code: it needs
the UI to actually ask for a new nickname, and then it needs to actually
do the proper "create_device_node(model,serial,nickname)" to set it (or
remove the nickname if empty).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds 2021-08-16 19:51:07 -10:00 committed by Dirk Hohndel
parent 2da7e9e5ad
commit 35adf2d729
2 changed files with 14 additions and 2 deletions

View file

@ -1304,8 +1304,9 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
// figure out if we are ontop of the dive computer name in the profile
QGraphicsItem *sceneItem = itemAt(mapFromGlobal(event->globalPos()));
if (isDiveTextItem(sceneItem, diveComputerText)) {
if (dc == 0 && number_of_computers(d) == 1)
// nothing to do, can't delete or reorder
const struct divecomputer *currentdc = get_dive_dc_const(d, dc);
if (!currentdc->deviceid && dc == 0 && number_of_computers(d) == 1)
// nothing to do, can't rename, delete or reorder
return;
// create menu to show when right clicking on dive computer name
if (dc > 0)
@ -1314,6 +1315,8 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
m.addAction(tr("Delete this dive computer"), this, &ProfileWidget2::deleteCurrentDC);
m.addAction(tr("Split this dive computer into own dive"), this, &ProfileWidget2::splitCurrentDC);
}
if (currentdc->deviceid)
m.addAction(tr("Rename this dive computer"), this, &ProfileWidget2::renameCurrentDC);
m.exec(event->globalPos());
// don't show the regular profile context menu
return;
@ -1442,6 +1445,14 @@ void ProfileWidget2::makeFirstDC()
Command::moveDiveComputerToFront(mutable_dive(), dc);
}
void ProfileWidget2::renameCurrentDC()
{
// Add UI code to give a new name, and do
// create_device_node(device_table, dc->model, serial, nickname)
// where 'serial' is the dc extradata for "Serial" and
// nickname is the new nickname (empty deletes the entry)
}
void ProfileWidget2::hideEvents(DiveEventItem *item)
{
const struct event *event = item->getEvent();

View file

@ -166,6 +166,7 @@ private:
void makeFirstDC();
void deleteCurrentDC();
void splitCurrentDC();
void renameCurrentDC();
DivePlotDataModel *dataModel;
DivePlannerPointsModel *plannerModel; // If null, no planning supported.