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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-07-15 03:29:43 -07:00
parent 133e104393
commit dff92f188a

View file

@ -206,9 +206,12 @@ void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas())); connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas()));
m.addAction(action); m.addAction(action);
} }
// don't allow removing the last point
if (DivePlannerPointsModel::instance()->rowCount() > 1) {
m.addSeparator(); m.addSeparator();
m.addAction(QObject::tr("Remove this point"), this, SLOT(selfRemove())); m.addAction(QObject::tr("Remove this point"), this, SLOT(selfRemove()));
m.exec(event->screenPos()); m.exec(event->screenPos());
}
} }
void DiveHandler::selfRemove() void DiveHandler::selfRemove()
@ -530,6 +533,7 @@ QVariant DivePlannerPointsModel::data(const QModelIndex &index, int role) const
} else if (role == Qt::DecorationRole) { } else if (role == Qt::DecorationRole) {
switch (index.column()) { switch (index.column()) {
case REMOVE: case REMOVE:
if (rowCount() > 1)
return p.entered ? QIcon(":trash") : QVariant(); return p.entered ? QIcon(":trash") : QVariant();
} }
} else if (role == Qt::FontRole) { } else if (role == Qt::FontRole) {
@ -872,7 +876,7 @@ divedatapoint DivePlannerPointsModel::at(int row)
void DivePlannerPointsModel::remove(const QModelIndex &index) void DivePlannerPointsModel::remove(const QModelIndex &index)
{ {
if (index.column() != REMOVE) if (index.column() != REMOVE || rowCount() == 1)
return; return;
divedatapoint dp = at(index.row()); divedatapoint dp = at(index.row());