From 3be8978573a9bba0d10afca15eff2419d4191eb8 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Fri, 11 Sep 2015 15:54:17 +0200 Subject: [PATCH] Don't offer gas selection for the last waypoint in planner Since the gas selection list on a waypoint refers to a gaschange there influencing the following segments, there must not be a gas selection on the last manually entered waypoint since from there the planner handles the gas selection. Signed-off-by: Robert C. Helling --- qt-ui/diveplanner.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 7f0d129..b4413d1 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -40,14 +40,18 @@ int DiveHandler::parentIndex() void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { QMenu m; - GasSelectionModel *model = GasSelectionModel::instance(); - model->repopulate(); - int rowCount = model->rowCount(); - for (int i = 0; i < rowCount; i++) { - QAction *action = new QAction(&m); - action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString()); - connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas())); - m.addAction(action); + // Don't have a gas selection for the last point + QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS); + if (index.sibling(index.row() + 1, index.column()).isValid()) { + GasSelectionModel *model = GasSelectionModel::instance(); + model->repopulate(); + int rowCount = model->rowCount(); + for (int i = 0; i < rowCount; i++) { + QAction *action = new QAction(&m); + action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString()); + connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas())); + m.addAction(action); + } } // don't allow removing the last point if (plannerModel->rowCount() > 1) { -- 2.3.2 (Apple Git-55)