Context menu entry to change setpoint

This patch adds a context menu entry to add a setpoint change
event. In particular, this can be used to turn a logged dive into
a CCR dive.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Robert C. Helling 2014-11-26 14:22:41 +01:00 committed by Dirk Hohndel
parent 96a94f1a19
commit fb265c2929
4 changed files with 51 additions and 1 deletions

View file

@ -373,6 +373,18 @@ static int set_cylinder_index(struct plot_info *pi, int i, int cylinderindex, un
return i; return i;
} }
static int set_setpoint(struct plot_info *pi, int i, int setpoint, unsigned int end)
{
while (i < pi->nr) {
struct plot_data *entry = pi->entry + i;
if (entry->sec > end)
break;
entry->o2pressure.mbar = setpoint;
i++;
}
return i;
}
/* normally the first cylinder has index 0... if not, we need to fix this up here */ /* normally the first cylinder has index 0... if not, we need to fix this up here */
static int set_first_cylinder_index(struct plot_info *pi, int i, int cylinderindex, unsigned int end) static int set_first_cylinder_index(struct plot_info *pi, int i, int cylinderindex, unsigned int end)
{ {
@ -407,6 +419,27 @@ static void check_gas_change_events(struct dive *dive, struct divecomputer *dc,
set_cylinder_index(pi, i, cylinderindex, ~0u); set_cylinder_index(pi, i, cylinderindex, ~0u);
} }
static void check_setpoint_events(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
{
int i = 0;
pressure_t setpoint;
setpoint.mbar = 0;
struct event *ev = get_next_event(dc->events, "SP change");
if (!ev)
return;
do {
i = set_setpoint(pi, i, setpoint.mbar, ev->time.seconds);
setpoint.mbar = ev->value;
if(setpoint.mbar)
dc->dctype = CCR;
ev = get_next_event(ev->next, "SP change");
} while (ev);
set_setpoint(pi, i, setpoint.mbar, ~0u);
}
struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer *dc) struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer *dc)
{ {
@ -1014,6 +1047,7 @@ void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plo
last_pi_entry_new = populate_plot_entries(dive, dc, pi); last_pi_entry_new = populate_plot_entries(dive, dc, pi);
check_gas_change_events(dive, dc, pi); /* Populate the gas index from the gas change events */ check_gas_change_events(dive, dc, pi); /* Populate the gas index from the gas change events */
check_setpoint_events(dive, dc, pi); /* Populate setpoints */
setup_gas_sensor_pressure(dive, dc, pi); /* Try to populate our gas pressure knowledge */ setup_gas_sensor_pressure(dive, dc, pi); /* Try to populate our gas pressure knowledge */
populate_pressure_information(dive, dc, pi, false); /* .. calculate missing pressure entries for all gasses except o2 */ populate_pressure_information(dive, dc, pi, false); /* .. calculate missing pressure entries for all gasses except o2 */
if (dc->dctype == CCR) /* For CCR dives.. */ if (dc->dctype == CCR) /* For CCR dives.. */

View file

@ -1128,6 +1128,8 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
gasChange->addAction(action); gasChange->addAction(action);
} }
} }
QAction *setpointAction = m.addAction(tr("Add set-point change"), this, SLOT(addSetpointChange()));
setpointAction->setData(event->globalPos());
QAction *action = m.addAction(tr("Add bookmark"), this, SLOT(addBookmark())); QAction *action = m.addAction(tr("Add bookmark"), this, SLOT(addBookmark()));
action->setData(event->globalPos()); action->setData(event->globalPos());
if (DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem)) { if (DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem)) {
@ -1282,6 +1284,14 @@ void ProfileWidget2::addBookmark()
replot(); replot();
} }
void ProfileWidget2::addSetpointChange()
{
QAction *action = qobject_cast<QAction *>(sender());
QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint()));
SetpointDialog::instance()->setpointData(current_dc, timeAxis->valueAt(scenePos));
SetpointDialog::instance()->show();
}
void ProfileWidget2::changeGas() void ProfileWidget2::changeGas()
{ {
QAction *action = qobject_cast<QAction *>(sender()); QAction *action = qobject_cast<QAction *>(sender());

View file

@ -92,6 +92,7 @@ slots: // Necessary to call from QAction's signals.
void setPlanState(); void setPlanState();
void setAddState(); void setAddState();
void changeGas(); void changeGas();
void addSetpointChange();
void addBookmark(); void addBookmark();
void hideEvents(); void hideEvents();
void unhideEvents(); void unhideEvents();

View file

@ -172,13 +172,18 @@ void SetpointDialog::setpointData(struct divecomputer *divecomputer, int second)
{ {
dc = divecomputer; dc = divecomputer;
time = second; time = second;
qDebug() << second << time;
} }
void SetpointDialog::buttonClicked(QAbstractButton *button) void SetpointDialog::buttonClicked(QAbstractButton *button)
{ {
if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) {
add_event(dc, time, SAMPLE_EVENT_PO2, 0, ui.spinbox->value(), "SP change"); qDebug() << time << (int)(1000.0 * ui.spinbox->value());
add_event(dc, time, SAMPLE_EVENT_PO2, 0, (int)(1000.0 * ui.spinbox->value()), "SP change");
} }
mark_divelist_changed(true);
MainWindow::instance()->graphics()->replot();
} }
SetpointDialog::SetpointDialog(QWidget *parent) : QDialog(parent) SetpointDialog::SetpointDialog(QWidget *parent) : QDialog(parent)