From 35adf2d72910d0cb287396b08717067d70c8ceb3 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 16 Aug 2021 19:51:07 -1000 Subject: 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 --- profile-widget/profilewidget2.cpp | 15 +++++++++++++-- profile-widget/profilewidget2.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'profile-widget') diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index e296a8b9b..b714f72d4 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -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(); diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h index b60fc030e..429fd1800 100644 --- a/profile-widget/profilewidget2.h +++ b/profile-widget/profilewidget2.h @@ -166,6 +166,7 @@ private: void makeFirstDC(); void deleteCurrentDC(); void splitCurrentDC(); + void renameCurrentDC(); DivePlotDataModel *dataModel; DivePlannerPointsModel *plannerModel; // If null, no planning supported. -- cgit v1.2.3-70-g09d2