From dff92f188a811f13a0d8008439cc6f4264b44a89 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 15 Jul 2014 03:29:43 -0700 Subject: [PATCH] Planner: don't allow the user to remove the last point This causes all kinds of assumptions to go wrong - and it makes no sense. Move the point to where you want it or cancel the plan. Fixes #623 Signed-off-by: Dirk Hohndel --- qt-ui/diveplanner.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index b099cbe40..6b3c7b591 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -206,9 +206,12 @@ void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas())); m.addAction(action); } - m.addSeparator(); - m.addAction(QObject::tr("Remove this point"), this, SLOT(selfRemove())); - m.exec(event->screenPos()); + // don't allow removing the last point + if (DivePlannerPointsModel::instance()->rowCount() > 1) { + m.addSeparator(); + m.addAction(QObject::tr("Remove this point"), this, SLOT(selfRemove())); + m.exec(event->screenPos()); + } } void DiveHandler::selfRemove() @@ -530,7 +533,8 @@ QVariant DivePlannerPointsModel::data(const QModelIndex &index, int role) const } else if (role == Qt::DecorationRole) { switch (index.column()) { case REMOVE: - return p.entered ? QIcon(":trash") : QVariant(); + if (rowCount() > 1) + return p.entered ? QIcon(":trash") : QVariant(); } } else if (role == Qt::FontRole) { if (divepoints.at(index.row()).entered) { @@ -872,7 +876,7 @@ divedatapoint DivePlannerPointsModel::at(int row) void DivePlannerPointsModel::remove(const QModelIndex &index) { - if (index.column() != REMOVE) + if (index.column() != REMOVE || rowCount() == 1) return; divedatapoint dp = at(index.row());