mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 06:15:26 +00:00
Profile context menu entry to split a dive
Allow the user to manually split a dive in two. Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit is contained in:
parent
8697f7a84d
commit
00f4fa0d1d
4 changed files with 39 additions and 0 deletions
20
core/dive.c
20
core/dive.c
|
@ -3441,6 +3441,10 @@ static int split_dive_at(struct dive *dive, int a, int b)
|
|||
if ((nr = get_divenr(dive)) < 0)
|
||||
return 0;
|
||||
|
||||
/* Splitting should leave at least 3 samples per dive */
|
||||
if (a < 3 || b > dive->dc.samples - 4)
|
||||
return 0;
|
||||
|
||||
/* We're not trying to be efficient here.. */
|
||||
d1 = create_new_copy(dive);
|
||||
d2 = create_new_copy(dive);
|
||||
|
@ -3583,6 +3587,22 @@ int split_dive(struct dive *dive)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void split_dive_at_time(struct dive *dive, duration_t time)
|
||||
{
|
||||
int i = 0;
|
||||
struct sample *sample = dive->dc.sample;
|
||||
|
||||
if (!dive)
|
||||
return;
|
||||
while(sample->time.seconds < time.seconds) {
|
||||
++sample;
|
||||
++i;
|
||||
if (dive->dc.samples == i)
|
||||
return;
|
||||
}
|
||||
split_dive_at(dive, i, i - 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* "dc_maxtime()" is how much total time this dive computer
|
||||
* has for this dive. Note that it can differ from "duration"
|
||||
|
|
|
@ -761,6 +761,7 @@ extern int dive_getUniqID(struct dive *d);
|
|||
extern unsigned int dc_airtemp(struct divecomputer *dc);
|
||||
extern unsigned int dc_watertemp(struct divecomputer *dc);
|
||||
extern int split_dive(struct dive *);
|
||||
extern void split_dive_at_time(struct dive *dive, duration_t time);
|
||||
extern struct dive *merge_dives(struct dive *a, struct dive *b, int offset, bool prefer_downloaded);
|
||||
extern struct dive *try_to_merge(struct dive *a, struct dive *b, bool prefer_downloaded);
|
||||
extern struct event *clone_event(const struct event *src_ev);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "desktop-widgets/diveplanner.h"
|
||||
#include "desktop-widgets/simplewidgets.h"
|
||||
#include "desktop-widgets/divepicturewidget.h"
|
||||
#include "desktop-widgets/mainwindow.h"
|
||||
#include "core/qthelper.h"
|
||||
#include "core/gettextfromc.h"
|
||||
#endif
|
||||
|
@ -1427,6 +1428,8 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
|
|||
setpointAction->setData(event->globalPos());
|
||||
QAction *action = m.addAction(tr("Add bookmark"), this, SLOT(addBookmark()));
|
||||
action->setData(event->globalPos());
|
||||
QAction *splitAction = m.addAction(tr("Split dive into two"), this, SLOT(splitDive()));
|
||||
splitAction->setData(event->globalPos());
|
||||
struct event *ev = NULL;
|
||||
enum divemode_t divemode = UNDEF_COMP_TYPE;
|
||||
QPointF scenePos = mapToScene(mapFromGlobal(event->globalPos()));
|
||||
|
@ -1640,6 +1643,20 @@ void ProfileWidget2::addSetpointChange()
|
|||
SetpointDialog::instance()->show();
|
||||
}
|
||||
|
||||
void ProfileWidget2::splitDive()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint()));
|
||||
duration_t time;
|
||||
time.seconds = lrint(timeAxis->valueAt((scenePos)));
|
||||
split_dive_at_time(&displayed_dive, time);
|
||||
emit updateDiveInfo(false);
|
||||
mark_divelist_changed(true);
|
||||
replot();
|
||||
MainWindow::instance()->refreshProfile();
|
||||
MainWindow::instance()->refreshDisplay();
|
||||
}
|
||||
|
||||
void ProfileWidget2::changeGas()
|
||||
{
|
||||
QAction *action = qobject_cast<QAction *>(sender());
|
||||
|
|
|
@ -115,6 +115,7 @@ slots: // Necessary to call from QAction's signals.
|
|||
void setAddState();
|
||||
void changeGas();
|
||||
void addSetpointChange();
|
||||
void splitDive();
|
||||
void addBookmark();
|
||||
void addDivemodeSwitch();
|
||||
void hideEvents();
|
||||
|
|
Loading…
Add table
Reference in a new issue