Planner: add event that explains when planner turns red

I don't know why the plot_info was walked backwards - for our purposes
walking forward needs to make a lot more sense. And the event nicely goes
away when the diveplan gets modified and the displayed_dive gets reset.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-07-11 10:26:22 -07:00
parent 6c9aaf406a
commit fbd00c6b0d

View file

@ -9,6 +9,7 @@
#include "preferences.h" #include "preferences.h"
#include "helpers.h" #include "helpers.h"
#include "diveplanner.h" #include "diveplanner.h"
#include "libdivecomputer/parser.h"
#include <QPen> #include <QPen>
#include <QPainter> #include <QPainter>
@ -151,6 +152,7 @@ int DiveProfileItem::maxCeiling(int row)
void DiveProfileItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) void DiveProfileItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{ {
bool eventAdded = false;
if (!shouldCalculateStuff(topLeft, bottomRight)) if (!shouldCalculateStuff(topLeft, bottomRight))
return; return;
@ -164,12 +166,17 @@ void DiveProfileItem::modelDataChanged(const QModelIndex &topLeft, const QModelI
int currState = qobject_cast<ProfileWidget2 *>(scene()->views().first())->currentState; int currState = qobject_cast<ProfileWidget2 *>(scene()->views().first())->currentState;
if (currState == ProfileWidget2::PLAN) { if (currState == ProfileWidget2::PLAN) {
plot_data *entry = dataModel->data().entry + dataModel->rowCount() - 1; plot_data *entry = dataModel->data().entry;
for (int i = dataModel->rowCount() - 1; i >= 0; i--, entry--) { for (int i = 0; i < dataModel->rowCount(); i++, entry++) {
int max = maxCeiling(i); int max = maxCeiling(i);
// Don't scream if we violate the ceiling by a few cm // Don't scream if we violate the ceiling by a few cm
if (entry->depth < max - 100) if (entry->depth < max - 100) {
profileColor = QColor(Qt::red); profileColor = QColor(Qt::red);
if (!eventAdded) {
add_event(&displayed_dive.dc, entry->sec, SAMPLE_EVENT_CEILING, -1, max / 1000, "planned waypoint above ceiling");
eventAdded = true;
}
}
} }
} }