2017-04-27 18:26:36 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "profile-widget/profilewidget2.h"
|
2021-06-05 16:42:56 +00:00
|
|
|
#include "profile-widget/profilescene.h"
|
2021-08-03 07:51:37 +00:00
|
|
|
#include "core/device.h"
|
2020-10-25 08:14:16 +00:00
|
|
|
#include "core/event.h"
|
2018-05-11 15:25:41 +00:00
|
|
|
#include "core/subsurface-string.h"
|
2018-06-03 20:15:19 +00:00
|
|
|
#include "core/qthelper.h"
|
2018-08-15 09:52:50 +00:00
|
|
|
#include "core/settings/qPrefTechnicalDetails.h"
|
|
|
|
#include "core/settings/qPrefPartialPressureGas.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "profile-widget/diveeventitem.h"
|
|
|
|
#include "profile-widget/divetextitem.h"
|
|
|
|
#include "profile-widget/divetooltipitem.h"
|
2020-11-25 17:30:49 +00:00
|
|
|
#include "profile-widget/divehandler.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/planner.h"
|
|
|
|
#include "profile-widget/ruleritem.h"
|
|
|
|
#include "core/pref.h"
|
2016-03-06 14:52:55 +00:00
|
|
|
#include "qt-models/diveplannermodel.h"
|
|
|
|
#include "qt-models/models.h"
|
2019-08-05 17:41:15 +00:00
|
|
|
#include "core/errorhelper.h"
|
2015-11-06 00:05:44 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/simplewidgets.h"
|
2019-11-13 14:08:40 +00:00
|
|
|
#include "commands/command.h"
|
2018-06-17 06:48:54 +00:00
|
|
|
#include "core/gettextfromc.h"
|
2018-06-30 09:36:37 +00:00
|
|
|
#include "core/imagedownloader.h"
|
2015-11-06 00:05:44 +00:00
|
|
|
#endif
|
2015-02-09 20:27:59 +00:00
|
|
|
|
2014-03-16 04:12:34 +00:00
|
|
|
#include <QMessageBox>
|
2014-04-03 19:16:15 +00:00
|
|
|
#include <QInputDialog>
|
2015-01-17 15:02:03 +00:00
|
|
|
#include <QDebug>
|
2015-02-09 20:58:40 +00:00
|
|
|
#include <QWheelEvent>
|
2015-11-05 20:50:51 +00:00
|
|
|
#include <QMenu>
|
2021-04-25 19:31:44 +00:00
|
|
|
#include <QMimeData>
|
2018-05-29 10:49:47 +00:00
|
|
|
#include <QElapsedTimer>
|
2014-01-16 17:02:32 +00:00
|
|
|
|
2014-01-15 15:20:05 +00:00
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
#include <QTableView>
|
|
|
|
#endif
|
|
|
|
|
2018-07-15 15:56:18 +00:00
|
|
|
// Constant describing at which z-level the thumbnails are located.
|
|
|
|
// We might add more constants here for easier customability.
|
|
|
|
static const double thumbnailBaseZValue = 100.0;
|
2021-10-04 19:41:17 +00:00
|
|
|
|
2022-08-28 20:42:54 +00:00
|
|
|
static double calcZoom(int zoomLevel)
|
|
|
|
{
|
|
|
|
// Base of exponential zoom function: one wheel-click will increase the zoom by 15%.
|
|
|
|
constexpr double zoomFactor = 1.15;
|
|
|
|
return zoomLevel == 0 ? 1.0 : pow(zoomFactor, zoomLevel);
|
|
|
|
}
|
2018-07-15 15:56:18 +00:00
|
|
|
|
2021-08-09 14:48:08 +00:00
|
|
|
ProfileWidget2::ProfileWidget2(DivePlannerPointsModel *plannerModelIn, double dpr, QWidget *parent) : QGraphicsView(parent),
|
|
|
|
profileScene(new ProfileScene(dpr, false, false)),
|
2021-07-01 16:56:50 +00:00
|
|
|
currentState(INIT),
|
2021-01-25 14:06:53 +00:00
|
|
|
plannerModel(plannerModelIn),
|
2014-02-04 23:47:50 +00:00
|
|
|
zoomLevel(0),
|
2022-03-12 13:06:12 +00:00
|
|
|
zoomedPosition(0.0),
|
2016-02-06 21:25:58 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2014-02-05 16:34:45 +00:00
|
|
|
toolTipItem(new ToolTipItem()),
|
2016-02-06 21:25:58 +00:00
|
|
|
#endif
|
2021-07-01 16:56:50 +00:00
|
|
|
d(nullptr),
|
|
|
|
dc(0),
|
2021-12-03 07:50:52 +00:00
|
|
|
empty(true),
|
2022-08-28 20:42:54 +00:00
|
|
|
panning(false),
|
2021-01-05 01:55:42 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2014-08-05 21:27:00 +00:00
|
|
|
mouseFollowerVertical(new DiveLineItem()),
|
2014-08-06 17:54:37 +00:00
|
|
|
mouseFollowerHorizontal(new DiveLineItem()),
|
2014-03-25 21:34:09 +00:00
|
|
|
rulerItem(new RulerItem2()),
|
2016-02-06 21:25:58 +00:00
|
|
|
#endif
|
2021-07-29 04:50:59 +00:00
|
|
|
shouldCalculateMax(true)
|
2014-01-14 16:30:13 +00:00
|
|
|
{
|
2014-02-07 16:59:58 +00:00
|
|
|
setupSceneAndFlags();
|
|
|
|
setupItemOnScene();
|
|
|
|
addItemsToScene();
|
|
|
|
scene()->installEventFilter(this);
|
2015-11-12 00:37:18 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2015-11-03 20:17:50 +00:00
|
|
|
setAcceptDrops(true);
|
|
|
|
|
2018-06-30 09:36:37 +00:00
|
|
|
connect(Thumbnailer::instance(), &Thumbnailer::thumbnailChanged, this, &ProfileWidget2::updateThumbnail, Qt::QueuedConnection);
|
2020-04-17 21:18:58 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::picturesRemoved, this, &ProfileWidget2::picturesRemoved);
|
|
|
|
connect(&diveListNotifier, &DiveListNotifier::picturesAdded, this, &ProfileWidget2::picturesAdded);
|
2020-03-03 21:42:51 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::cylinderEdited, this, &ProfileWidget2::profileChanged);
|
|
|
|
connect(&diveListNotifier, &DiveListNotifier::eventsChanged, this, &ProfileWidget2::profileChanged);
|
2020-04-14 20:07:00 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::pictureOffsetChanged, this, &ProfileWidget2::pictureOffsetChanged);
|
2021-01-27 22:41:51 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &ProfileWidget2::divesChanged);
|
2021-08-17 18:19:41 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::deviceEdited, this, &ProfileWidget2::replot);
|
2022-02-19 17:47:25 +00:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::diveComputerEdited, this, &ProfileWidget2::replot);
|
2015-11-12 00:37:18 +00:00
|
|
|
#endif // SUBSURFACE_MOBILE
|
2014-05-24 15:39:40 +00:00
|
|
|
|
2015-02-02 21:12:11 +00:00
|
|
|
#if !defined(QT_NO_DEBUG) && defined(SHOW_PLOT_INFO_TABLE)
|
2014-02-07 16:59:58 +00:00
|
|
|
QTableView *diveDepthTableView = new QTableView();
|
2021-06-28 18:29:46 +00:00
|
|
|
diveDepthTableView->setModel(profileScene->dataModel);
|
2014-03-07 15:42:13 +00:00
|
|
|
diveDepthTableView->show();
|
2014-02-07 16:59:58 +00:00
|
|
|
#endif
|
2020-11-25 19:03:49 +00:00
|
|
|
|
|
|
|
auto tec = qPrefTechnicalDetails::instance();
|
|
|
|
connect(tec, &qPrefTechnicalDetails::calcalltissuesChanged , this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
connect(tec, &qPrefTechnicalDetails::calcceilingChanged , this, &ProfileWidget2::actionRequestedReplot);
|
2021-01-19 15:50:08 +00:00
|
|
|
connect(tec, &qPrefTechnicalDetails::gflowChanged , this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
connect(tec, &qPrefTechnicalDetails::gfhighChanged , this, &ProfileWidget2::actionRequestedReplot);
|
2020-11-25 19:03:49 +00:00
|
|
|
connect(tec, &qPrefTechnicalDetails::dcceilingChanged , this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
connect(tec, &qPrefTechnicalDetails::eadChanged , this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
connect(tec, &qPrefTechnicalDetails::calcceiling3mChanged , this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
connect(tec, &qPrefTechnicalDetails::modChanged , this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
connect(tec, &qPrefTechnicalDetails::calcndlttsChanged , this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
connect(tec, &qPrefTechnicalDetails::hrgraphChanged , this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
connect(tec, &qPrefTechnicalDetails::rulergraphChanged , this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
connect(tec, &qPrefTechnicalDetails::show_sacChanged , this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
connect(tec, &qPrefTechnicalDetails::zoomed_plotChanged , this, &ProfileWidget2::actionRequestedReplot);
|
2021-08-28 21:32:25 +00:00
|
|
|
connect(tec, &qPrefTechnicalDetails::decoinfoChanged , this, &ProfileWidget2::actionRequestedReplot);
|
2020-11-25 19:03:49 +00:00
|
|
|
connect(tec, &qPrefTechnicalDetails::show_pictures_in_profileChanged , this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
connect(tec, &qPrefTechnicalDetails::tankbarChanged , this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
connect(tec, &qPrefTechnicalDetails::percentagegraphChanged , this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
|
|
|
|
auto pp_gas = qPrefPartialPressureGas::instance();
|
|
|
|
connect(pp_gas, &qPrefPartialPressureGas::pheChanged, this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
connect(pp_gas, &qPrefPartialPressureGas::pn2Changed, this, &ProfileWidget2::actionRequestedReplot);
|
|
|
|
connect(pp_gas, &qPrefPartialPressureGas::po2Changed, this, &ProfileWidget2::actionRequestedReplot);
|
2021-07-01 16:56:50 +00:00
|
|
|
|
|
|
|
setProfileState();
|
2014-02-07 16:59:58 +00:00
|
|
|
}
|
2014-01-15 14:23:40 +00:00
|
|
|
|
2019-07-15 18:41:42 +00:00
|
|
|
ProfileWidget2::~ProfileWidget2()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-10 15:50:57 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2022-02-19 13:06:58 +00:00
|
|
|
void ProfileWidget2::keyPressEvent(QKeyEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->key()) {
|
|
|
|
case Qt::Key_Delete: return keyDeleteAction();
|
|
|
|
case Qt::Key_Up: return keyUpAction();
|
|
|
|
case Qt::Key_Down: return keyDownAction();
|
|
|
|
case Qt::Key_Left: return keyLeftAction();
|
|
|
|
case Qt::Key_Right: return keyRightAction();
|
|
|
|
}
|
|
|
|
QGraphicsView::keyPressEvent(e);
|
2018-01-10 15:50:57 +00:00
|
|
|
}
|
|
|
|
#endif // SUBSURFACE_MOBILE
|
|
|
|
|
2014-02-07 16:59:58 +00:00
|
|
|
void ProfileWidget2::addItemsToScene()
|
|
|
|
{
|
2017-03-25 12:03:37 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
|
|
|
scene()->addItem(toolTipItem);
|
2014-02-27 18:20:03 +00:00
|
|
|
scene()->addItem(rulerItem);
|
|
|
|
scene()->addItem(rulerItem->sourceNode());
|
|
|
|
scene()->addItem(rulerItem->destNode());
|
2014-08-05 21:27:00 +00:00
|
|
|
scene()->addItem(mouseFollowerHorizontal);
|
|
|
|
scene()->addItem(mouseFollowerVertical);
|
2014-08-05 22:47:02 +00:00
|
|
|
QPen pen(QColor(Qt::red).lighter());
|
|
|
|
pen.setWidth(0);
|
|
|
|
mouseFollowerHorizontal->setPen(pen);
|
|
|
|
mouseFollowerVertical->setPen(pen);
|
2016-02-06 21:25:58 +00:00
|
|
|
#endif
|
2014-02-07 16:59:58 +00:00
|
|
|
}
|
2014-01-15 14:23:40 +00:00
|
|
|
|
2014-02-07 16:59:58 +00:00
|
|
|
void ProfileWidget2::setupItemOnScene()
|
|
|
|
{
|
2016-02-06 21:25:58 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2014-03-11 22:09:54 +00:00
|
|
|
toolTipItem->setZValue(9998);
|
2021-06-28 18:29:46 +00:00
|
|
|
toolTipItem->setTimeAxis(profileScene->timeAxis);
|
2014-03-11 22:09:54 +00:00
|
|
|
rulerItem->setZValue(9997);
|
2021-06-28 18:29:46 +00:00
|
|
|
rulerItem->setAxis(profileScene->timeAxis, profileScene->profileYAxis);
|
2021-12-10 11:15:44 +00:00
|
|
|
mouseFollowerHorizontal->setZValue(9996);
|
|
|
|
mouseFollowerVertical->setZValue(9995);
|
2016-02-06 21:25:58 +00:00
|
|
|
#endif
|
2014-02-07 16:59:58 +00:00
|
|
|
}
|
2014-01-15 15:01:29 +00:00
|
|
|
|
2020-04-12 10:20:25 +00:00
|
|
|
void ProfileWidget2::replot()
|
2014-03-09 13:59:31 +00:00
|
|
|
{
|
2021-10-20 09:50:44 +00:00
|
|
|
plotDive(d, dc);
|
2014-03-09 13:59:31 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:59:58 +00:00
|
|
|
void ProfileWidget2::setupSceneAndFlags()
|
|
|
|
{
|
2021-06-05 16:42:56 +00:00
|
|
|
setScene(profileScene.get());
|
2014-02-07 16:59:58 +00:00
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setOptimizationFlags(QGraphicsView::DontSavePainterState);
|
|
|
|
setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
|
|
|
|
setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
|
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
2014-01-14 16:30:13 +00:00
|
|
|
|
2015-10-11 11:21:13 +00:00
|
|
|
void ProfileWidget2::resetZoom()
|
|
|
|
{
|
|
|
|
zoomLevel = 0;
|
2021-10-06 19:01:58 +00:00
|
|
|
zoomedPosition = 0.0;
|
2015-10-11 11:21:13 +00:00
|
|
|
}
|
|
|
|
|
2014-01-14 16:30:13 +00:00
|
|
|
// Currently just one dive, but the plan is to enable All of the selected dives.
|
2021-10-22 12:30:56 +00:00
|
|
|
void ProfileWidget2::plotDive(const struct dive *dIn, int dcIn, int flags)
|
2014-01-14 16:30:13 +00:00
|
|
|
{
|
2021-01-28 13:24:38 +00:00
|
|
|
d = dIn;
|
|
|
|
dc = dcIn;
|
|
|
|
if (!d) {
|
2021-07-01 16:56:50 +00:00
|
|
|
clear();
|
2021-01-28 13:24:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-03 07:50:52 +00:00
|
|
|
// If there was no previously displayed dive, turn off animations
|
|
|
|
if (empty)
|
|
|
|
flags |= RenderFlags::Instant;
|
|
|
|
empty = false;
|
|
|
|
|
2018-05-29 10:49:47 +00:00
|
|
|
QElapsedTimer measureDuration; // let's measure how long this takes us (maybe we'll turn of TTL calculation later
|
2014-06-04 20:41:50 +00:00
|
|
|
measureDuration.start();
|
2014-03-11 21:54:28 +00:00
|
|
|
|
2021-08-03 07:51:37 +00:00
|
|
|
DivePlannerPointsModel *model = currentState == EDIT || currentState == PLAN ? plannerModel : nullptr;
|
|
|
|
bool inPlanner = currentState == PLAN;
|
|
|
|
|
2022-08-28 20:42:54 +00:00
|
|
|
double zoom = calcZoom(zoomLevel);
|
2021-10-22 16:23:15 +00:00
|
|
|
profileScene->plotDive(d, dc, model, inPlanner, flags & RenderFlags::Instant,
|
|
|
|
flags & RenderFlags::DontRecalculatePlotInfo,
|
|
|
|
shouldCalculateMax, zoom, zoomedPosition);
|
2021-08-03 07:51:37 +00:00
|
|
|
|
2015-12-01 23:36:20 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2021-10-21 20:17:37 +00:00
|
|
|
rulerItem->setVisible(prefs.rulergraph && currentState != PLAN && currentState != EDIT);
|
2021-08-03 07:51:37 +00:00
|
|
|
toolTipItem->setPlotInfo(profileScene->plotInfo);
|
|
|
|
rulerItem->setPlotInfo(d, profileScene->plotInfo);
|
2014-02-07 19:59:21 +00:00
|
|
|
|
2021-06-30 05:49:56 +00:00
|
|
|
if ((currentState == EDIT || currentState == PLAN) && plannerModel) {
|
2014-05-22 02:31:26 +00:00
|
|
|
repositionDiveHandlers();
|
2021-01-25 14:06:53 +00:00
|
|
|
plannerModel->deleteTemporaryPlan();
|
2014-05-22 02:31:26 +00:00
|
|
|
}
|
2021-10-26 05:42:13 +00:00
|
|
|
|
|
|
|
// On zoom / pan don't recreate the picture thumbnails, only change their position.
|
|
|
|
if (flags & RenderFlags::DontRecalculatePlotInfo)
|
|
|
|
updateThumbnails();
|
|
|
|
else
|
|
|
|
plotPicturesInternal(d, flags & RenderFlags::Instant);
|
2018-10-17 09:28:33 +00:00
|
|
|
|
2021-01-28 13:24:38 +00:00
|
|
|
toolTipItem->refresh(d, mapToScene(mapFromGlobal(QCursor::pos())), currentState == PLAN);
|
2018-01-10 12:55:29 +00:00
|
|
|
#endif
|
2014-07-21 21:54:28 +00:00
|
|
|
|
2014-06-04 20:41:50 +00:00
|
|
|
// OK, how long did this take us? Anything above the second is way too long,
|
|
|
|
// so if we are calculation TTS / NDL then let's force that off.
|
2021-01-05 01:55:42 +00:00
|
|
|
qint64 elapsedTime = measureDuration.elapsed();
|
|
|
|
if (verbose)
|
|
|
|
qDebug() << "Profile calculation for dive " << d->number << "took" << elapsedTime << "ms" << " -- calculated ceiling preference is" << prefs.calcceiling;
|
|
|
|
if (elapsedTime > 1000 && prefs.calcndltts) {
|
2018-08-15 09:52:50 +00:00
|
|
|
qPrefTechnicalDetails::set_calcndltts(false);
|
2015-11-05 18:51:12 +00:00
|
|
|
report_error(qPrintable(tr("Show NDL / TTS was disabled because of excessive processing time")));
|
2014-06-04 20:41:50 +00:00
|
|
|
}
|
2014-01-14 16:30:13 +00:00
|
|
|
}
|
|
|
|
|
2021-01-27 22:41:51 +00:00
|
|
|
void ProfileWidget2::divesChanged(const QVector<dive *> &dives, DiveField field)
|
|
|
|
{
|
|
|
|
// If the mode of the currently displayed dive changed, replot
|
|
|
|
if (field.mode &&
|
2022-09-17 17:51:53 +00:00
|
|
|
std::find(dives.begin(), dives.end(), d) != dives.end())
|
2021-01-27 22:41:51 +00:00
|
|
|
replot();
|
|
|
|
}
|
|
|
|
|
2018-05-21 16:20:29 +00:00
|
|
|
void ProfileWidget2::actionRequestedReplot(bool)
|
2016-01-25 17:54:23 +00:00
|
|
|
{
|
|
|
|
settingsChanged();
|
|
|
|
}
|
|
|
|
|
2021-06-15 16:16:44 +00:00
|
|
|
void ProfileWidget2::settingsChanged()
|
|
|
|
{
|
2020-12-29 22:03:38 +00:00
|
|
|
replot();
|
2014-01-14 16:30:13 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void ProfileWidget2::resizeEvent(QResizeEvent *event)
|
2014-01-14 16:30:13 +00:00
|
|
|
{
|
2014-02-11 04:45:08 +00:00
|
|
|
QGraphicsView::resizeEvent(event);
|
2021-08-28 21:36:09 +00:00
|
|
|
profileScene->resize(viewport()->size());
|
2021-10-22 16:23:15 +00:00
|
|
|
plotDive(d, dc, RenderFlags::Instant | RenderFlags::DontRecalculatePlotInfo); // disable animation on resize events
|
2014-01-15 14:55:33 +00:00
|
|
|
}
|
|
|
|
|
2016-02-06 21:25:58 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2014-05-26 20:51:46 +00:00
|
|
|
void ProfileWidget2::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
QGraphicsView::mousePressEvent(event);
|
2022-08-28 20:42:54 +00:00
|
|
|
|
|
|
|
if (!event->isAccepted()) {
|
|
|
|
panning = true;
|
|
|
|
panningOriginalMousePosition = mapToScene(event->pos()).x();
|
|
|
|
panningOriginalProfilePosition = zoomedPosition;
|
2022-08-29 06:03:18 +00:00
|
|
|
viewport()->setCursor(Qt::ClosedHandCursor);
|
2022-08-28 20:42:54 +00:00
|
|
|
}
|
2014-05-26 20:51:46 +00:00
|
|
|
}
|
|
|
|
|
2014-06-30 22:08:16 +00:00
|
|
|
void ProfileWidget2::divePlannerHandlerClicked()
|
|
|
|
{
|
2021-07-29 15:19:50 +00:00
|
|
|
shouldCalculateMax = false;
|
2014-06-30 22:08:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::divePlannerHandlerReleased()
|
|
|
|
{
|
2022-02-19 10:58:36 +00:00
|
|
|
if (currentState == EDIT)
|
|
|
|
emit stopMoved(1);
|
2021-07-29 15:19:50 +00:00
|
|
|
shouldCalculateMax = true;
|
2014-06-30 22:08:16 +00:00
|
|
|
replot();
|
|
|
|
}
|
|
|
|
|
2014-05-26 20:51:46 +00:00
|
|
|
void ProfileWidget2::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
QGraphicsView::mouseReleaseEvent(event);
|
2022-08-29 06:03:18 +00:00
|
|
|
if (panning) {
|
|
|
|
panning = false;
|
|
|
|
viewport()->setCursor(Qt::ArrowCursor);
|
|
|
|
}
|
2021-06-30 05:49:56 +00:00
|
|
|
if (currentState == PLAN || currentState == EDIT) {
|
2021-07-29 15:19:50 +00:00
|
|
|
shouldCalculateMax = true;
|
2014-05-26 20:51:46 +00:00
|
|
|
replot();
|
|
|
|
}
|
|
|
|
}
|
2016-02-06 21:25:58 +00:00
|
|
|
#endif
|
2014-05-26 20:51:46 +00:00
|
|
|
|
2021-10-06 19:01:58 +00:00
|
|
|
void ProfileWidget2::setZoom(int level)
|
2018-07-15 15:56:18 +00:00
|
|
|
{
|
2021-10-06 19:01:58 +00:00
|
|
|
zoomLevel = level;
|
2021-10-22 16:23:15 +00:00
|
|
|
plotDive(d, dc, RenderFlags::DontRecalculatePlotInfo);
|
2018-07-15 15:56:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-06 21:25:58 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2014-02-28 04:09:57 +00:00
|
|
|
void ProfileWidget2::wheelEvent(QWheelEvent *event)
|
2014-02-04 23:47:50 +00:00
|
|
|
{
|
2021-07-01 16:56:50 +00:00
|
|
|
if (!d)
|
2014-03-10 15:59:01 +00:00
|
|
|
return;
|
2022-08-28 20:42:54 +00:00
|
|
|
if (panning)
|
|
|
|
return; // No change in zoom level while panning.
|
2015-01-02 00:28:37 +00:00
|
|
|
if (event->buttons() == Qt::LeftButton)
|
2014-08-06 11:51:54 +00:00
|
|
|
return;
|
2021-10-06 19:01:58 +00:00
|
|
|
if (event->angleDelta().y() > 0 && zoomLevel < 20)
|
|
|
|
setZoom(++zoomLevel);
|
|
|
|
else if (event->angleDelta().y() < 0 && zoomLevel > 0)
|
|
|
|
setZoom(--zoomLevel);
|
2014-02-04 23:47:50 +00:00
|
|
|
}
|
|
|
|
|
2014-05-21 18:52:24 +00:00
|
|
|
void ProfileWidget2::mouseDoubleClickEvent(QMouseEvent *event)
|
|
|
|
{
|
2021-06-30 05:49:56 +00:00
|
|
|
if ((currentState == PLAN || currentState == EDIT) && plannerModel) {
|
2014-05-21 18:52:24 +00:00
|
|
|
QPointF mappedPos = mapToScene(event->pos());
|
2021-10-26 14:37:38 +00:00
|
|
|
if (!profileScene->pointOnProfile(mappedPos))
|
2014-05-21 18:52:24 +00:00
|
|
|
return;
|
|
|
|
|
2021-06-28 18:29:46 +00:00
|
|
|
int minutes = lrint(profileScene->timeAxis->valueAt(mappedPos) / 60);
|
|
|
|
int milimeters = lrint(profileScene->profileYAxis->valueAt(mappedPos) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);
|
2021-02-27 18:42:42 +00:00
|
|
|
plannerModel->addStop(milimeters, minutes * 60);
|
2022-02-19 10:58:36 +00:00
|
|
|
if (currentState == EDIT)
|
|
|
|
emit stopAdded();
|
2014-05-21 18:52:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void ProfileWidget2::mouseMoveEvent(QMouseEvent *event)
|
2014-02-04 23:47:50 +00:00
|
|
|
{
|
2021-10-06 19:01:58 +00:00
|
|
|
QGraphicsView::mouseMoveEvent(event);
|
|
|
|
|
2015-01-14 16:41:56 +00:00
|
|
|
QPointF pos = mapToScene(event->pos());
|
2022-08-28 20:42:54 +00:00
|
|
|
if (panning) {
|
|
|
|
double oldPos = zoomedPosition;
|
|
|
|
zoomedPosition = profileScene->calcZoomPosition(calcZoom(zoomLevel),
|
|
|
|
panningOriginalProfilePosition,
|
|
|
|
panningOriginalMousePosition - pos.x());
|
|
|
|
if (oldPos != zoomedPosition)
|
|
|
|
plotDive(d, dc, RenderFlags::Instant | RenderFlags::DontRecalculatePlotInfo); // TODO: animations don't work when scrolling
|
2014-02-04 23:47:50 +00:00
|
|
|
}
|
2014-08-05 21:27:00 +00:00
|
|
|
|
2022-08-28 20:42:54 +00:00
|
|
|
toolTipItem->refresh(d, mapToScene(mapFromGlobal(QCursor::pos())), currentState == PLAN);
|
|
|
|
|
2021-12-10 11:15:44 +00:00
|
|
|
if (currentState == PLAN || currentState == EDIT) {
|
|
|
|
QRectF rect = profileScene->profileRegion;
|
|
|
|
auto [miny, maxy] = profileScene->profileYAxis->screenMinMax();
|
|
|
|
double x = std::clamp(pos.x(), rect.left(), rect.right());
|
|
|
|
double y = std::clamp(pos.y(), miny, maxy);
|
|
|
|
mouseFollowerHorizontal->setLine(rect.left(), y, rect.right(), y);
|
|
|
|
mouseFollowerVertical->setLine(x, rect.top(), x, rect.bottom());
|
|
|
|
}
|
2014-02-04 23:47:50 +00:00
|
|
|
}
|
|
|
|
|
2014-02-05 18:15:59 +00:00
|
|
|
bool ProfileWidget2::eventFilter(QObject *object, QEvent *event)
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
QGraphicsScene *s = qobject_cast<QGraphicsScene *>(object);
|
|
|
|
if (s && event->type() == QEvent::GraphicsSceneHelp) {
|
2014-02-05 18:15:59 +00:00
|
|
|
event->ignore();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return QGraphicsView::eventFilter(object, event);
|
|
|
|
}
|
2016-02-06 21:25:58 +00:00
|
|
|
#endif
|
2014-02-07 18:34:42 +00:00
|
|
|
|
2018-01-10 15:36:45 +00:00
|
|
|
template <typename T>
|
2019-04-01 20:15:19 +00:00
|
|
|
static void hideAll(const T &container)
|
2018-01-10 15:36:45 +00:00
|
|
|
{
|
2021-01-24 08:13:56 +00:00
|
|
|
for (auto &item: container)
|
2018-01-10 15:36:45 +00:00
|
|
|
item->setVisible(false);
|
|
|
|
}
|
|
|
|
|
2021-07-01 16:56:50 +00:00
|
|
|
void ProfileWidget2::clear()
|
2014-02-07 18:34:42 +00:00
|
|
|
{
|
2020-04-19 17:33:19 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
|
|
|
clearPictures();
|
|
|
|
#endif
|
2014-05-22 00:23:19 +00:00
|
|
|
disconnectTemporaryConnections();
|
2021-08-03 07:51:37 +00:00
|
|
|
profileScene->clear();
|
2021-07-01 16:56:50 +00:00
|
|
|
handles.clear();
|
|
|
|
gases.clear();
|
2021-12-03 07:50:52 +00:00
|
|
|
empty = true;
|
2014-02-07 18:34:42 +00:00
|
|
|
}
|
|
|
|
|
2021-01-28 13:24:38 +00:00
|
|
|
void ProfileWidget2::setProfileState(const dive *dIn, int dcIn)
|
|
|
|
{
|
|
|
|
d = dIn;
|
|
|
|
dc = dcIn;
|
|
|
|
|
|
|
|
setProfileState();
|
|
|
|
}
|
|
|
|
|
2014-02-07 18:34:42 +00:00
|
|
|
void ProfileWidget2::setProfileState()
|
|
|
|
{
|
2014-02-07 18:54:12 +00:00
|
|
|
if (currentState == PROFILE)
|
|
|
|
return;
|
2014-02-07 18:34:42 +00:00
|
|
|
|
2014-05-22 00:23:19 +00:00
|
|
|
disconnectTemporaryConnections();
|
2014-06-03 22:09:12 +00:00
|
|
|
|
2014-02-07 18:54:12 +00:00
|
|
|
currentState = PROFILE;
|
2021-07-29 04:50:59 +00:00
|
|
|
setBackgroundBrush(getColor(::BACKGROUND, profileScene->isGrayscale));
|
2014-02-07 19:38:00 +00:00
|
|
|
|
2016-02-06 21:25:58 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
|
|
|
toolTipItem->readPos();
|
|
|
|
toolTipItem->setVisible(true);
|
2014-05-21 15:57:48 +00:00
|
|
|
rulerItem->setVisible(prefs.rulergraph);
|
2016-02-06 21:25:58 +00:00
|
|
|
mouseFollowerHorizontal->setVisible(false);
|
|
|
|
mouseFollowerVertical->setVisible(false);
|
2015-11-06 00:05:44 +00:00
|
|
|
#endif
|
2021-07-01 16:56:50 +00:00
|
|
|
|
|
|
|
handles.clear();
|
|
|
|
gases.clear();
|
2014-02-07 18:34:42 +00:00
|
|
|
}
|
2014-02-17 22:15:40 +00:00
|
|
|
|
2015-11-06 00:05:44 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2021-01-25 13:38:57 +00:00
|
|
|
void ProfileWidget2::connectPlannerModel()
|
|
|
|
{
|
|
|
|
connect(plannerModel, &DivePlannerPointsModel::dataChanged, this, &ProfileWidget2::replot);
|
|
|
|
connect(plannerModel, &DivePlannerPointsModel::cylinderModelEdited, this, &ProfileWidget2::replot);
|
|
|
|
connect(plannerModel, &DivePlannerPointsModel::modelReset, this, &ProfileWidget2::pointsReset);
|
|
|
|
connect(plannerModel, &DivePlannerPointsModel::rowsInserted, this, &ProfileWidget2::pointInserted);
|
|
|
|
connect(plannerModel, &DivePlannerPointsModel::rowsRemoved, this, &ProfileWidget2::pointsRemoved);
|
|
|
|
connect(plannerModel, &DivePlannerPointsModel::rowsMoved, this, &ProfileWidget2::pointsMoved);
|
|
|
|
}
|
|
|
|
|
2021-06-30 05:49:56 +00:00
|
|
|
void ProfileWidget2::setEditState(const dive *d, int dc)
|
2014-05-21 18:52:24 +00:00
|
|
|
{
|
2021-06-30 05:49:56 +00:00
|
|
|
if (currentState == EDIT)
|
2014-05-21 18:52:24 +00:00
|
|
|
return;
|
|
|
|
|
2021-01-28 13:24:38 +00:00
|
|
|
setProfileState(d, dc);
|
2014-08-06 19:33:36 +00:00
|
|
|
mouseFollowerHorizontal->setVisible(true);
|
|
|
|
mouseFollowerVertical->setVisible(true);
|
2014-05-22 00:23:19 +00:00
|
|
|
disconnectTemporaryConnections();
|
2014-05-24 15:39:40 +00:00
|
|
|
|
2021-01-25 13:38:57 +00:00
|
|
|
connectPlannerModel();
|
|
|
|
|
2022-03-12 12:10:29 +00:00
|
|
|
currentState = EDIT;
|
2021-02-27 15:01:28 +00:00
|
|
|
|
|
|
|
pointsReset();
|
|
|
|
repositionDiveHandlers();
|
2014-05-21 18:52:24 +00:00
|
|
|
}
|
|
|
|
|
2021-01-28 13:24:38 +00:00
|
|
|
void ProfileWidget2::setPlanState(const dive *d, int dc)
|
2014-05-21 18:52:24 +00:00
|
|
|
{
|
|
|
|
if (currentState == PLAN)
|
|
|
|
return;
|
2014-05-25 18:12:00 +00:00
|
|
|
|
2021-01-28 13:24:38 +00:00
|
|
|
setProfileState(d, dc);
|
2014-08-06 19:33:36 +00:00
|
|
|
mouseFollowerHorizontal->setVisible(true);
|
|
|
|
mouseFollowerVertical->setVisible(true);
|
2014-05-22 00:23:19 +00:00
|
|
|
disconnectTemporaryConnections();
|
2014-05-25 17:16:43 +00:00
|
|
|
|
2021-01-25 13:38:57 +00:00
|
|
|
connectPlannerModel();
|
|
|
|
|
2022-03-12 12:10:29 +00:00
|
|
|
currentState = PLAN;
|
2014-06-30 21:46:51 +00:00
|
|
|
setBackgroundBrush(QColor("#D7E3EF"));
|
2021-02-27 15:01:28 +00:00
|
|
|
|
|
|
|
pointsReset();
|
|
|
|
repositionDiveHandlers();
|
2014-05-21 18:52:24 +00:00
|
|
|
}
|
2016-02-06 21:25:58 +00:00
|
|
|
#endif
|
2014-05-21 18:52:24 +00:00
|
|
|
|
2021-01-10 13:04:43 +00:00
|
|
|
bool ProfileWidget2::isPlanner() const
|
2014-05-26 22:17:34 +00:00
|
|
|
{
|
|
|
|
return currentState == PLAN;
|
|
|
|
}
|
|
|
|
|
2019-07-06 10:09:15 +00:00
|
|
|
#if 0 // TODO::: FINISH OR DISABLE
|
2019-07-06 10:35:33 +00:00
|
|
|
struct int ProfileWidget2::getEntryFromPos(QPointF pos)
|
2014-11-19 22:31:28 +00:00
|
|
|
{
|
|
|
|
// find the time stamp corresponding to the mouse position
|
2017-03-23 01:13:49 +00:00
|
|
|
int seconds = lrint(timeAxis->valueAt(pos));
|
2014-11-19 22:31:28 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < plotInfo.nr; i++) {
|
2019-07-06 10:35:33 +00:00
|
|
|
if (plotInfo.entry[i].sec >= seconds)
|
|
|
|
return i;
|
2014-11-19 22:31:28 +00:00
|
|
|
}
|
2019-07-06 10:35:33 +00:00
|
|
|
return plotInfo.nr - 1;
|
2014-11-19 22:31:28 +00:00
|
|
|
}
|
2019-07-06 10:09:15 +00:00
|
|
|
#endif
|
2014-11-19 22:31:28 +00:00
|
|
|
|
2015-11-06 00:05:44 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2020-08-24 20:37:08 +00:00
|
|
|
/// Prints cylinder information for display.
|
|
|
|
/// eg : "Cyl 1 (AL80 EAN32)"
|
|
|
|
static QString printCylinderDescription(int i, const cylinder_t *cylinder)
|
|
|
|
{
|
|
|
|
QString label = gettextFromC::tr("Cyl") + QString(" %1").arg(i+1);
|
|
|
|
if( cylinder != NULL ) {
|
|
|
|
QString mix = get_gas_string(cylinder->gasmix);
|
|
|
|
label += QString(" (%2 %3)").arg(cylinder->type.description).arg(mix);
|
|
|
|
}
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2021-04-25 20:35:41 +00:00
|
|
|
static bool isDiveTextItem(const QGraphicsItem *item, const DiveTextItem *textItem)
|
|
|
|
{
|
|
|
|
while (item) {
|
|
|
|
if (item == textItem)
|
|
|
|
return true;
|
|
|
|
item = item->parentItem();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
|
2014-02-17 22:15:40 +00:00
|
|
|
{
|
2021-06-30 05:49:56 +00:00
|
|
|
if (currentState == EDIT || currentState == PLAN) {
|
2014-05-25 03:33:39 +00:00
|
|
|
QGraphicsView::contextMenuEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
2014-05-19 05:39:34 +00:00
|
|
|
QMenu m;
|
2021-01-28 13:24:38 +00:00
|
|
|
if (!d)
|
2014-02-17 22:15:40 +00:00
|
|
|
return;
|
2014-05-19 05:39:34 +00:00
|
|
|
// figure out if we are ontop of the dive computer name in the profile
|
|
|
|
QGraphicsItem *sceneItem = itemAt(mapFromGlobal(event->globalPos()));
|
2021-08-03 07:51:37 +00:00
|
|
|
if (isDiveTextItem(sceneItem, profileScene->diveComputerText)) {
|
2021-08-17 05:51:07 +00:00
|
|
|
const struct divecomputer *currentdc = get_dive_dc_const(d, dc);
|
|
|
|
if (!currentdc->deviceid && dc == 0 && number_of_computers(d) == 1)
|
|
|
|
// nothing to do, can't rename, delete or reorder
|
2014-05-19 05:39:34 +00:00
|
|
|
return;
|
2021-04-25 20:35:41 +00:00
|
|
|
// create menu to show when right clicking on dive computer name
|
|
|
|
if (dc > 0)
|
|
|
|
m.addAction(tr("Make first dive computer"), this, &ProfileWidget2::makeFirstDC);
|
|
|
|
if (number_of_computers(d) > 1) {
|
|
|
|
m.addAction(tr("Delete this dive computer"), this, &ProfileWidget2::deleteCurrentDC);
|
|
|
|
m.addAction(tr("Split this dive computer into own dive"), this, &ProfileWidget2::splitCurrentDC);
|
2014-05-19 05:39:34 +00:00
|
|
|
}
|
2021-08-17 05:51:07 +00:00
|
|
|
if (currentdc->deviceid)
|
|
|
|
m.addAction(tr("Rename this dive computer"), this, &ProfileWidget2::renameCurrentDC);
|
2021-04-25 20:35:41 +00:00
|
|
|
m.exec(event->globalPos());
|
|
|
|
// don't show the regular profile context menu
|
|
|
|
return;
|
2014-05-19 05:39:34 +00:00
|
|
|
}
|
2021-04-25 20:35:41 +00:00
|
|
|
|
2014-05-19 05:39:34 +00:00
|
|
|
// create the profile context menu
|
2020-01-30 14:03:48 +00:00
|
|
|
QPointF scenePos = mapToScene(mapFromGlobal(event->globalPos()));
|
2021-06-28 18:29:46 +00:00
|
|
|
qreal sec_val = profileScene->timeAxis->valueAt(scenePos);
|
2020-01-30 14:03:48 +00:00
|
|
|
int seconds = (sec_val < 0.0) ? 0 : (int)sec_val;
|
2020-08-24 20:37:08 +00:00
|
|
|
DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem);
|
|
|
|
|
|
|
|
// Add or edit Gas Change
|
2021-01-28 13:24:38 +00:00
|
|
|
if (d && item && event_is_gaschange(item->getEvent())) {
|
2020-08-24 20:37:08 +00:00
|
|
|
int eventTime = item->getEvent()->time.seconds;
|
|
|
|
QMenu *gasChange = m.addMenu(tr("Edit Gas Change"));
|
2021-01-28 13:24:38 +00:00
|
|
|
for (int i = 0; i < d->cylinders.nr; i++) {
|
|
|
|
const cylinder_t *cylinder = get_cylinder(d, i);
|
2020-08-24 20:37:08 +00:00
|
|
|
QString label = printCylinderDescription(i, cylinder);
|
|
|
|
gasChange->addAction(label, [this, i, eventTime] { changeGas(i, eventTime); });
|
|
|
|
}
|
2021-01-28 13:24:38 +00:00
|
|
|
} else if (d && d->cylinders.nr > 1) {
|
2014-11-19 21:03:58 +00:00
|
|
|
// if we have more than one gas, offer to switch to another one
|
|
|
|
QMenu *gasChange = m.addMenu(tr("Add gas change"));
|
2021-01-28 13:24:38 +00:00
|
|
|
for (int i = 0; i < d->cylinders.nr; i++) {
|
|
|
|
const cylinder_t *cylinder = get_cylinder(d, i);
|
2020-08-24 20:37:08 +00:00
|
|
|
QString label = printCylinderDescription(i, cylinder);
|
|
|
|
gasChange->addAction(label, [this, i, seconds] { changeGas(i, seconds); });
|
|
|
|
}
|
2014-02-17 22:15:40 +00:00
|
|
|
}
|
2020-03-02 21:02:33 +00:00
|
|
|
m.addAction(tr("Add setpoint change"), [this, seconds]() { ProfileWidget2::addSetpointChange(seconds); });
|
|
|
|
m.addAction(tr("Add bookmark"), [this, seconds]() { addBookmark(seconds); });
|
|
|
|
m.addAction(tr("Split dive into two"), [this, seconds]() { splitDive(seconds); });
|
2018-08-16 22:58:30 +00:00
|
|
|
const struct event *ev = NULL;
|
2018-05-08 14:24:51 +00:00
|
|
|
enum divemode_t divemode = UNDEF_COMP_TYPE;
|
2018-04-08 20:09:26 +00:00
|
|
|
|
2021-01-28 13:24:38 +00:00
|
|
|
get_current_divemode(get_dive_dc_const(d, dc), seconds, &ev, &divemode);
|
2018-04-08 20:09:26 +00:00
|
|
|
QMenu *changeMode = m.addMenu(tr("Change divemode"));
|
2020-03-02 21:34:39 +00:00
|
|
|
if (divemode != OC)
|
|
|
|
changeMode->addAction(gettextFromC::tr(divemode_text_ui[OC]),
|
|
|
|
[this, seconds](){ addDivemodeSwitch(seconds, OC); });
|
|
|
|
if (divemode != CCR)
|
|
|
|
changeMode->addAction(gettextFromC::tr(divemode_text_ui[CCR]),
|
|
|
|
[this, seconds](){ addDivemodeSwitch(seconds, CCR); });
|
|
|
|
if (divemode != PSCR)
|
|
|
|
changeMode->addAction(gettextFromC::tr(divemode_text_ui[PSCR]),
|
|
|
|
[this, seconds](){ addDivemodeSwitch(seconds, PSCR); });
|
2015-04-23 20:56:24 +00:00
|
|
|
|
2014-03-16 04:12:34 +00:00
|
|
|
if (DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem)) {
|
2020-03-02 21:34:39 +00:00
|
|
|
m.addAction(tr("Remove event"), [this,item] { removeEvent(item); });
|
|
|
|
m.addAction(tr("Hide similar events"), [this, item] { hideEvents(item); });
|
2021-06-05 07:29:41 +00:00
|
|
|
const struct event *dcEvent = item->getEvent();
|
2020-03-02 21:34:39 +00:00
|
|
|
if (dcEvent->type == SAMPLE_EVENT_BOOKMARK)
|
|
|
|
m.addAction(tr("Edit name"), [this, item] { editName(item); });
|
2019-07-06 10:09:15 +00:00
|
|
|
#if 0 // TODO::: FINISH OR DISABLE
|
2017-08-26 19:11:44 +00:00
|
|
|
QPointF scenePos = mapToScene(event->pos());
|
2019-07-06 10:35:33 +00:00
|
|
|
int idx = getEntryFromPos(scenePos);
|
2014-11-20 00:15:10 +00:00
|
|
|
// this shows how to figure out if we should ask the user if they want adjust interpolated pressures
|
|
|
|
// at either side of a gas change
|
|
|
|
if (dcEvent->type == SAMPLE_EVENT_GASCHANGE || dcEvent->type == SAMPLE_EVENT_GASCHANGE2) {
|
|
|
|
qDebug() << "figure out if there are interpolated pressures";
|
2019-07-06 10:35:33 +00:00
|
|
|
int gasChangeIdx = idx;
|
|
|
|
while (gasChangeIdx > 0) {
|
|
|
|
--gasChangeIdx;
|
|
|
|
if (plotInfo.entry[gasChangeIdx].sec <= dcEvent->time.seconds)
|
2014-11-20 00:15:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-07-06 10:35:33 +00:00
|
|
|
const struct plot_data &gasChangeEntry = plotInfo.entry[newGasIdx];
|
|
|
|
qDebug() << "at gas change at" << gasChangeEntry->sec << ": sensor pressure" << get_plot_sensor_pressure(&plotInfo, newGasIdx)
|
|
|
|
<< "interpolated" << ;get_plot_sensor_pressure(&plotInfo, newGasIdx);
|
2014-11-20 00:15:10 +00:00
|
|
|
// now gasChangeEntry points at the gas change, that entry has the final pressure of
|
|
|
|
// the old tank, the next entry has the starting pressure of the next tank
|
2019-07-06 10:35:33 +00:00
|
|
|
if (gasChangeIdx < plotInfo.nr - 1) {
|
|
|
|
int newGasIdx = gasChangeIdx + 1;
|
|
|
|
const struct plot_data &newGasEntry = plotInfo.entry[newGasIdx];
|
2014-11-20 00:15:10 +00:00
|
|
|
qDebug() << "after gas change at " << newGasEntry->sec << ": sensor pressure" << newGasEntry->pressure[0] << "interpolated" << newGasEntry->pressure[1];
|
2021-01-28 13:24:38 +00:00
|
|
|
if (get_plot_sensor_pressure(&plotInfo, gasChangeIdx) == 0 || get_cylinder(d, gasChangeEntry->sensor[0])->sample_start.mbar == 0) {
|
2014-11-20 00:15:10 +00:00
|
|
|
// if we have no sensorpressure or if we have no pressure from samples we can assume that
|
|
|
|
// we only have interpolated pressure (the pressure in the entry may be stored in the sensor
|
|
|
|
// pressure field if this is the first or last entry for this tank... see details in gaspressures.c
|
|
|
|
pressure_t pressure;
|
2019-07-06 10:35:33 +00:00
|
|
|
pressure.mbar = get_plot_interpolated_pressure(&plotInfo, gasChangeIdx) ? : get_plot_sensor_pressure(&plotInfo, gasChangeIdx);
|
2017-11-18 08:35:06 +00:00
|
|
|
QAction *adjustOldPressure = m.addAction(tr("Adjust pressure of cyl. %1 (currently interpolated as %2)")
|
Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.
It mainly does:
- turn the "sample->sensor" index into an array of two indexes, to
match the pressures themselves.
- get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
since a CCR dive should now simply set the sample->sensor[] indices
correctly instead.
- in a couple of places, start actually looping over the sensors rather
than special-case the O2 case (although often the small "loops" are
just unrolled, since it's just two cases.
but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.
It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.
For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.
In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.
But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 02:49:45 +00:00
|
|
|
.arg(gasChangeEntry->sensor[0] + 1).arg(get_pressure_string(pressure)));
|
2014-11-20 00:15:10 +00:00
|
|
|
}
|
2021-01-28 13:24:38 +00:00
|
|
|
if (get_plot_sensor_pressure(&plotInfo, newGasIdx) == 0 || get_cylinder(d, newGasEntry->sensor[0])->sample_start.mbar == 0) {
|
2014-11-20 00:15:10 +00:00
|
|
|
// we only have interpolated press -- see commend above
|
|
|
|
pressure_t pressure;
|
2019-07-06 10:35:33 +00:00
|
|
|
pressure.mbar = get_plot_interpolated_pressure(&plotInfo, newGasIdx) ? : get_plot_sensor_pressure(&plotInfo, newGasIdx);
|
2017-11-18 08:35:06 +00:00
|
|
|
QAction *adjustOldPressure = m.addAction(tr("Adjust pressure of cyl. %1 (currently interpolated as %2)")
|
Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.
It mainly does:
- turn the "sample->sensor" index into an array of two indexes, to
match the pressures themselves.
- get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
since a CCR dive should now simply set the sample->sensor[] indices
correctly instead.
- in a couple of places, start actually looping over the sensors rather
than special-case the O2 case (although often the small "loops" are
just unrolled, since it's just two cases.
but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.
It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.
For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.
In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.
But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 02:49:45 +00:00
|
|
|
.arg(newGasEntry->sensor[0] + 1).arg(get_pressure_string(pressure)));
|
2014-11-20 00:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2014-02-17 22:15:40 +00:00
|
|
|
}
|
|
|
|
bool some_hidden = false;
|
|
|
|
for (int i = 0; i < evn_used; i++) {
|
|
|
|
if (ev_namelist[i].plot_ev == false) {
|
|
|
|
some_hidden = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-03-02 20:58:09 +00:00
|
|
|
if (some_hidden)
|
|
|
|
m.addAction(tr("Unhide all events"), this, &ProfileWidget2::unhideEvents);
|
2014-02-17 22:15:40 +00:00
|
|
|
m.exec(event->globalPos());
|
|
|
|
}
|
|
|
|
|
2014-06-11 20:56:33 +00:00
|
|
|
void ProfileWidget2::deleteCurrentDC()
|
|
|
|
{
|
2021-01-28 13:24:38 +00:00
|
|
|
if (d)
|
|
|
|
Command::deleteDiveComputer(mutable_dive(), dc);
|
2014-06-11 20:56:33 +00:00
|
|
|
}
|
|
|
|
|
2019-03-31 08:20:13 +00:00
|
|
|
void ProfileWidget2::splitCurrentDC()
|
|
|
|
{
|
2021-01-28 13:24:38 +00:00
|
|
|
if (d)
|
|
|
|
Command::splitDiveComputer(mutable_dive(), dc);
|
2019-03-31 08:20:13 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 05:39:34 +00:00
|
|
|
void ProfileWidget2::makeFirstDC()
|
|
|
|
{
|
2021-01-28 13:24:38 +00:00
|
|
|
if (d)
|
|
|
|
Command::moveDiveComputerToFront(mutable_dive(), dc);
|
2014-05-19 05:39:34 +00:00
|
|
|
}
|
|
|
|
|
2021-08-17 05:51:07 +00:00
|
|
|
void ProfileWidget2::renameCurrentDC()
|
|
|
|
{
|
2021-08-17 07:10:33 +00:00
|
|
|
bool ok;
|
2022-03-11 21:49:53 +00:00
|
|
|
struct divecomputer *currentdc = get_dive_dc(mutable_dive(), dc);
|
|
|
|
if (!currentdc)
|
|
|
|
return;
|
2021-08-17 07:10:33 +00:00
|
|
|
QString newName = QInputDialog::getText(this, tr("Edit nickname"),
|
2022-03-11 21:49:53 +00:00
|
|
|
tr("Set new nickname for %1 (serial %2):").arg(currentdc->model).arg(currentdc->serial),
|
|
|
|
QLineEdit::Normal, get_dc_nickname(currentdc), &ok);
|
2021-08-17 18:19:41 +00:00
|
|
|
if (ok)
|
2022-03-11 21:49:53 +00:00
|
|
|
Command::editDeviceNickname(currentdc, newName);
|
2021-08-17 05:51:07 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 21:23:40 +00:00
|
|
|
void ProfileWidget2::hideEvents(DiveEventItem *item)
|
2014-03-16 04:12:34 +00:00
|
|
|
{
|
2021-06-05 07:29:41 +00:00
|
|
|
const struct event *event = item->getEvent();
|
2014-03-16 04:12:34 +00:00
|
|
|
|
2015-11-05 20:58:24 +00:00
|
|
|
if (QMessageBox::question(this,
|
2014-03-16 04:12:34 +00:00
|
|
|
TITLE_OR_TEXT(tr("Hide events"), tr("Hide all %1 events?").arg(event->name)),
|
|
|
|
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
|
2018-01-07 10:12:48 +00:00
|
|
|
if (!empty_string(event->name)) {
|
2014-03-16 04:12:34 +00:00
|
|
|
for (int i = 0; i < evn_used; i++) {
|
2014-05-15 00:45:39 +00:00
|
|
|
if (same_string(event->name, ev_namelist[i].ev_name)) {
|
2014-03-16 04:12:34 +00:00
|
|
|
ev_namelist[i].plot_ev = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-08-03 07:51:37 +00:00
|
|
|
Q_FOREACH (DiveEventItem *evItem, profileScene->eventItems) {
|
2014-05-22 18:40:22 +00:00
|
|
|
if (same_string(evItem->getEvent()->name, event->name))
|
2014-05-15 00:45:39 +00:00
|
|
|
evItem->hide();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
item->hide();
|
2014-03-16 04:12:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::unhideEvents()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < evn_used; i++) {
|
|
|
|
ev_namelist[i].plot_ev = true;
|
|
|
|
}
|
2021-08-03 07:51:37 +00:00
|
|
|
Q_FOREACH (DiveEventItem *item, profileScene->eventItems)
|
2014-05-15 00:51:45 +00:00
|
|
|
item->show();
|
2014-03-16 04:12:34 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 21:23:40 +00:00
|
|
|
void ProfileWidget2::removeEvent(DiveEventItem *item)
|
2014-03-16 04:12:34 +00:00
|
|
|
{
|
2021-06-05 07:29:41 +00:00
|
|
|
struct event *event = item->getEventMutable();
|
2021-01-28 13:24:38 +00:00
|
|
|
if (!event || !d)
|
2020-03-04 17:25:47 +00:00
|
|
|
return;
|
2014-03-16 04:12:34 +00:00
|
|
|
|
2015-11-05 20:58:24 +00:00
|
|
|
if (QMessageBox::question(this, TITLE_OR_TEXT(
|
|
|
|
tr("Remove the selected event?"),
|
|
|
|
tr("%1 @ %2:%3").arg(event->name).arg(event->time.seconds / 60).arg(event->time.seconds % 60, 2, 10, QChar('0'))),
|
2020-03-04 17:25:47 +00:00
|
|
|
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok)
|
2021-01-28 13:24:38 +00:00
|
|
|
Command::removeEvent(mutable_dive(), dc, event);
|
2014-03-16 04:12:34 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 21:02:33 +00:00
|
|
|
void ProfileWidget2::addBookmark(int seconds)
|
2014-03-16 04:12:34 +00:00
|
|
|
{
|
2021-01-28 13:24:38 +00:00
|
|
|
if (d)
|
|
|
|
Command::addEventBookmark(mutable_dive(), dc, seconds);
|
2014-03-16 04:12:34 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 20:48:53 +00:00
|
|
|
void ProfileWidget2::addDivemodeSwitch(int seconds, int divemode)
|
2018-04-07 18:39:41 +00:00
|
|
|
{
|
2021-01-28 13:24:38 +00:00
|
|
|
if (d)
|
|
|
|
Command::addEventDivemodeSwitch(mutable_dive(), dc, seconds, divemode);
|
2018-04-07 18:39:41 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 21:02:33 +00:00
|
|
|
void ProfileWidget2::addSetpointChange(int seconds)
|
2014-11-26 13:22:41 +00:00
|
|
|
{
|
2021-01-28 13:24:38 +00:00
|
|
|
if (!d)
|
|
|
|
return;
|
|
|
|
SetpointDialog dialog(mutable_dive(), dc, seconds);
|
2020-03-03 22:09:25 +00:00
|
|
|
dialog.exec();
|
2014-11-26 13:22:41 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 21:02:33 +00:00
|
|
|
void ProfileWidget2::splitDive(int seconds)
|
2018-07-02 19:13:44 +00:00
|
|
|
{
|
2018-07-20 18:26:06 +00:00
|
|
|
if (!d)
|
|
|
|
return;
|
2021-01-28 13:24:38 +00:00
|
|
|
Command::splitDives(mutable_dive(), duration_t{ seconds });
|
2018-07-02 19:13:44 +00:00
|
|
|
}
|
|
|
|
|
2020-01-30 14:03:48 +00:00
|
|
|
void ProfileWidget2::changeGas(int tank, int seconds)
|
2014-02-17 22:15:40 +00:00
|
|
|
{
|
2021-01-28 13:24:38 +00:00
|
|
|
if (!d || tank < 0 || tank >= d->cylinders.nr)
|
2020-01-30 14:03:48 +00:00
|
|
|
return;
|
2015-03-11 18:23:50 +00:00
|
|
|
|
2021-01-28 13:24:38 +00:00
|
|
|
Command::addGasSwitch(mutable_dive(), dc, seconds, tank);
|
2014-02-20 01:18:26 +00:00
|
|
|
}
|
2015-11-06 00:05:44 +00:00
|
|
|
#endif
|
2014-03-25 21:34:09 +00:00
|
|
|
|
2015-11-06 00:05:44 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2020-03-02 21:23:40 +00:00
|
|
|
void ProfileWidget2::editName(DiveEventItem *item)
|
2014-04-03 19:16:15 +00:00
|
|
|
{
|
2021-06-05 07:29:41 +00:00
|
|
|
struct event *event = item->getEventMutable();
|
2021-01-28 13:24:38 +00:00
|
|
|
if (!event || !d)
|
2020-03-04 17:13:02 +00:00
|
|
|
return;
|
2014-04-03 19:16:15 +00:00
|
|
|
bool ok;
|
2015-11-05 20:58:24 +00:00
|
|
|
QString newName = QInputDialog::getText(this, tr("Edit name of bookmark"),
|
2014-04-03 19:16:15 +00:00
|
|
|
tr("Custom name:"), QLineEdit::Normal,
|
|
|
|
event->name, &ok);
|
2014-04-03 19:52:05 +00:00
|
|
|
if (ok && !newName.isEmpty()) {
|
|
|
|
if (newName.length() > 22) { //longer names will display as garbage.
|
2014-04-03 19:16:15 +00:00
|
|
|
QMessageBox lengthWarning;
|
2014-07-28 14:12:51 +00:00
|
|
|
lengthWarning.setText(tr("Name is too long!"));
|
2014-04-03 19:16:15 +00:00
|
|
|
lengthWarning.exec();
|
|
|
|
return;
|
|
|
|
}
|
2021-01-28 13:24:38 +00:00
|
|
|
Command::renameEvent(mutable_dive(), dc, event, qPrintable(newName));
|
2014-04-03 19:16:15 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-06 00:05:44 +00:00
|
|
|
#endif
|
2014-05-22 00:18:10 +00:00
|
|
|
|
2014-05-22 00:23:19 +00:00
|
|
|
void ProfileWidget2::disconnectTemporaryConnections()
|
|
|
|
{
|
2018-01-09 18:32:41 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2021-01-25 14:06:53 +00:00
|
|
|
if (plannerModel) {
|
|
|
|
disconnect(plannerModel, &DivePlannerPointsModel::dataChanged, this, &ProfileWidget2::replot);
|
|
|
|
disconnect(plannerModel, &DivePlannerPointsModel::cylinderModelEdited, this, &ProfileWidget2::replot);
|
|
|
|
|
|
|
|
disconnect(plannerModel, &DivePlannerPointsModel::modelReset, this, &ProfileWidget2::pointsReset);
|
|
|
|
disconnect(plannerModel, &DivePlannerPointsModel::rowsInserted, this, &ProfileWidget2::pointInserted);
|
|
|
|
disconnect(plannerModel, &DivePlannerPointsModel::rowsRemoved, this, &ProfileWidget2::pointsRemoved);
|
|
|
|
disconnect(plannerModel, &DivePlannerPointsModel::rowsMoved, this, &ProfileWidget2::pointsMoved);
|
|
|
|
}
|
2015-11-12 00:37:18 +00:00
|
|
|
#endif
|
2014-05-22 00:23:19 +00:00
|
|
|
}
|
|
|
|
|
2021-01-24 08:13:56 +00:00
|
|
|
int ProfileWidget2::handleIndex(const DiveHandler *h) const
|
|
|
|
{
|
|
|
|
auto it = std::find_if(handles.begin(), handles.end(),
|
|
|
|
[h] (const std::unique_ptr<DiveHandler> &h2)
|
|
|
|
{ return h == h2.get(); });
|
|
|
|
return it != handles.end() ? it - handles.begin() : -1;
|
|
|
|
}
|
|
|
|
|
2015-11-06 00:05:44 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2021-01-24 22:29:28 +00:00
|
|
|
|
|
|
|
DiveHandler *ProfileWidget2::createHandle()
|
2014-05-22 00:18:10 +00:00
|
|
|
{
|
2021-01-28 13:24:38 +00:00
|
|
|
DiveHandler *item = new DiveHandler(d);
|
2014-05-22 00:18:10 +00:00
|
|
|
scene()->addItem(item);
|
2021-01-25 14:51:37 +00:00
|
|
|
connect(item, &DiveHandler::moved, this, &ProfileWidget2::divePlannerHandlerMoved);
|
2020-04-12 10:48:38 +00:00
|
|
|
connect(item, &DiveHandler::clicked, this, &ProfileWidget2::divePlannerHandlerClicked);
|
|
|
|
connect(item, &DiveHandler::released, this, &ProfileWidget2::divePlannerHandlerReleased);
|
2021-01-24 22:29:28 +00:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsSimpleTextItem *ProfileWidget2::createGas()
|
|
|
|
{
|
2014-05-22 00:18:10 +00:00
|
|
|
QGraphicsSimpleTextItem *gasChooseBtn = new QGraphicsSimpleTextItem();
|
|
|
|
scene()->addItem(gasChooseBtn);
|
|
|
|
gasChooseBtn->setZValue(10);
|
|
|
|
gasChooseBtn->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
2021-01-24 22:29:28 +00:00
|
|
|
return gasChooseBtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::pointsReset()
|
|
|
|
{
|
|
|
|
handles.clear();
|
|
|
|
gases.clear();
|
2021-01-25 14:06:53 +00:00
|
|
|
int count = plannerModel->rowCount();
|
2021-01-24 22:29:28 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
handles.emplace_back(createHandle());
|
|
|
|
gases.emplace_back(createGas());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::pointInserted(const QModelIndex &, int from, int to)
|
|
|
|
{
|
|
|
|
for (int i = from; i <= to; ++i) {
|
|
|
|
handles.emplace(handles.begin() + i, createHandle());
|
|
|
|
gases.emplace(gases.begin() + i, createGas());
|
|
|
|
}
|
|
|
|
|
2021-02-27 21:06:05 +00:00
|
|
|
// Note: we don't replot the dive here, because when removing multiple
|
|
|
|
// points, these might trickle in one-by-one. Instead, the model will
|
|
|
|
// emit a data-changed signal.
|
2014-05-22 00:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::pointsRemoved(const QModelIndex &, int start, int end)
|
2021-01-24 08:13:56 +00:00
|
|
|
{
|
|
|
|
// Qt's model/view API is mad. The end-point is inclusive, which means that the empty range is [0,-1]!
|
|
|
|
handles.erase(handles.begin() + start, handles.begin() + end + 1);
|
|
|
|
gases.erase(gases.begin() + start, gases.begin() + end + 1);
|
2014-05-22 00:18:10 +00:00
|
|
|
scene()->clearSelection();
|
2021-02-27 21:06:05 +00:00
|
|
|
|
|
|
|
// Note: we don't replot the dive here, because when removing multiple
|
|
|
|
// points, these might trickle in one-by-one. Instead, the model will
|
|
|
|
// emit a data-changed signal.
|
2014-05-22 00:18:10 +00:00
|
|
|
}
|
2014-05-22 02:31:26 +00:00
|
|
|
|
2021-01-24 22:29:28 +00:00
|
|
|
void ProfileWidget2::pointsMoved(const QModelIndex &, int start, int end, const QModelIndex &, int row)
|
|
|
|
{
|
|
|
|
moveInVector(handles, start, end + 1, row);
|
|
|
|
moveInVector(gases, start, end + 1, row);
|
|
|
|
}
|
|
|
|
|
2014-05-22 02:31:26 +00:00
|
|
|
void ProfileWidget2::repositionDiveHandlers()
|
|
|
|
{
|
2018-01-10 15:36:45 +00:00
|
|
|
hideAll(gases);
|
2014-05-22 02:31:26 +00:00
|
|
|
// Re-position the user generated dive handlers
|
|
|
|
for (int i = 0; i < plannerModel->rowCount(); i++) {
|
|
|
|
struct divedatapoint datapoint = plannerModel->at(i);
|
|
|
|
if (datapoint.time == 0) // those are the magic entries for tanks
|
|
|
|
continue;
|
2021-01-24 08:13:56 +00:00
|
|
|
DiveHandler *h = handles[i].get();
|
2014-05-30 02:47:03 +00:00
|
|
|
h->setVisible(datapoint.entered);
|
2021-06-28 18:29:46 +00:00
|
|
|
h->setPos(profileScene->timeAxis->posAtValue(datapoint.time), profileScene->profileYAxis->posAtValue(datapoint.depth.mm));
|
2014-10-21 21:27:50 +00:00
|
|
|
QPointF p1;
|
|
|
|
if (i == 0) {
|
|
|
|
if (prefs.drop_stone_mode)
|
|
|
|
// place the text on the straight line from the drop to stone position
|
2021-06-28 18:29:46 +00:00
|
|
|
p1 = QPointF(profileScene->timeAxis->posAtValue(datapoint.depth.mm / prefs.descrate),
|
|
|
|
profileScene->profileYAxis->posAtValue(datapoint.depth.mm));
|
2014-10-21 21:27:50 +00:00
|
|
|
else
|
|
|
|
// place the text on the straight line from the origin to the first position
|
2021-06-28 18:29:46 +00:00
|
|
|
p1 = QPointF(profileScene->timeAxis->posAtValue(0), profileScene->profileYAxis->posAtValue(0));
|
2014-10-21 21:27:50 +00:00
|
|
|
} else {
|
|
|
|
// place the text on the line from the last position
|
|
|
|
p1 = handles[i - 1]->pos();
|
|
|
|
}
|
2014-05-22 02:31:26 +00:00
|
|
|
QPointF p2 = handles[i]->pos();
|
|
|
|
QLineF line(p1, p2);
|
|
|
|
QPointF pos = line.pointAt(0.5);
|
|
|
|
gases[i]->setPos(pos);
|
2021-01-28 13:24:38 +00:00
|
|
|
if (datapoint.cylinderid >= 0 && datapoint.cylinderid < d->cylinders.nr)
|
|
|
|
gases[i]->setText(get_gas_string(get_cylinder(d, datapoint.cylinderid)->gasmix));
|
2021-01-25 20:45:29 +00:00
|
|
|
else
|
|
|
|
gases[i]->setText(QString());
|
2015-05-07 21:40:34 +00:00
|
|
|
gases[i]->setVisible(datapoint.entered &&
|
|
|
|
(i == 0 || gases[i]->text() != gases[i-1]->text()));
|
2014-05-22 02:31:26 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-23 23:51:30 +00:00
|
|
|
|
2021-01-25 14:51:37 +00:00
|
|
|
void ProfileWidget2::divePlannerHandlerMoved()
|
2014-05-23 23:51:30 +00:00
|
|
|
{
|
2014-05-24 15:39:40 +00:00
|
|
|
DiveHandler *activeHandler = qobject_cast<DiveHandler *>(sender());
|
2021-01-25 14:51:37 +00:00
|
|
|
int index = handleIndex(activeHandler);
|
2014-05-23 23:51:30 +00:00
|
|
|
|
2021-01-25 14:51:37 +00:00
|
|
|
// Grow the time axis if necessary.
|
2021-06-28 18:29:46 +00:00
|
|
|
int minutes = lrint(profileScene->timeAxis->valueAt(activeHandler->pos()) / 60);
|
|
|
|
if (minutes * 60 > profileScene->timeAxis->maximum() * 0.9)
|
2021-09-11 19:57:49 +00:00
|
|
|
profileScene->timeAxis->setBounds(0.0, profileScene->timeAxis->maximum() * 1.02);
|
2014-05-23 23:51:30 +00:00
|
|
|
|
|
|
|
divedatapoint data = plannerModel->at(index);
|
2021-06-28 18:29:46 +00:00
|
|
|
data.depth.mm = lrint(profileScene->profileYAxis->valueAt(activeHandler->pos()) / M_OR_FT(1, 1)) * M_OR_FT(1, 1);
|
|
|
|
data.time = lrint(profileScene->timeAxis->valueAt(activeHandler->pos()));
|
2014-05-23 23:51:30 +00:00
|
|
|
|
2021-01-25 14:51:37 +00:00
|
|
|
plannerModel->editStop(index, data);
|
2014-05-23 23:51:30 +00:00
|
|
|
}
|
2014-05-24 15:39:40 +00:00
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
std::vector<int> ProfileWidget2::selectedDiveHandleIndices() const
|
|
|
|
{
|
|
|
|
std::vector<int> res;
|
|
|
|
res.reserve(scene()->selectedItems().size());
|
|
|
|
for (QGraphicsItem *item: scene()->selectedItems()) {
|
|
|
|
if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler *>(item))
|
|
|
|
res.push_back(handleIndex(handler));
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-05-24 15:39:40 +00:00
|
|
|
void ProfileWidget2::keyDownAction()
|
|
|
|
{
|
2021-06-30 05:49:56 +00:00
|
|
|
if ((currentState != EDIT && currentState != PLAN) || !plannerModel)
|
2014-05-24 15:39:40 +00:00
|
|
|
return;
|
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
std::vector<int> handleIndices = selectedDiveHandleIndices();
|
|
|
|
for (int row: handleIndices) {
|
|
|
|
divedatapoint dp = plannerModel->at(row);
|
2014-05-24 15:39:40 +00:00
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
dp.depth.mm += M_OR_FT(1, 5);
|
|
|
|
plannerModel->editStop(row, dp);
|
2014-05-24 15:39:40 +00:00
|
|
|
}
|
2022-02-19 10:58:36 +00:00
|
|
|
if (currentState == EDIT && !handleIndices.empty())
|
|
|
|
emit stopMoved(handleIndices.size()); // TODO: Accumulate key moves
|
2014-05-24 15:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::keyUpAction()
|
|
|
|
{
|
2021-06-30 05:49:56 +00:00
|
|
|
if ((currentState != EDIT && currentState != PLAN) || !plannerModel)
|
2014-05-24 15:39:40 +00:00
|
|
|
return;
|
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
std::vector<int> handleIndices = selectedDiveHandleIndices();
|
|
|
|
for (int row: handleIndices) {
|
|
|
|
divedatapoint dp = plannerModel->at(row);
|
2014-05-24 15:39:40 +00:00
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
if (dp.depth.mm <= 0)
|
|
|
|
continue;
|
2014-05-24 15:39:40 +00:00
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
dp.depth.mm -= M_OR_FT(1, 5);
|
|
|
|
plannerModel->editStop(row, dp);
|
2014-05-24 15:39:40 +00:00
|
|
|
}
|
2022-02-19 10:58:36 +00:00
|
|
|
if (currentState == EDIT && !handleIndices.empty())
|
|
|
|
emit stopMoved(handleIndices.size()); // TODO: Accumulate key moves
|
2014-05-24 15:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::keyLeftAction()
|
|
|
|
{
|
2021-06-30 05:49:56 +00:00
|
|
|
if ((currentState != EDIT && currentState != PLAN) || !plannerModel)
|
2014-05-24 15:39:40 +00:00
|
|
|
return;
|
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
std::vector<int> handleIndices = selectedDiveHandleIndices();
|
|
|
|
for (int row: handleIndices) {
|
|
|
|
divedatapoint dp = plannerModel->at(row);
|
2014-05-24 15:39:40 +00:00
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
if (dp.time / 60 <= 0)
|
|
|
|
continue;
|
2014-05-24 15:39:40 +00:00
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
dp.time -= 60;
|
|
|
|
plannerModel->editStop(row, dp);
|
2014-05-24 15:39:40 +00:00
|
|
|
}
|
2022-02-19 10:58:36 +00:00
|
|
|
if (currentState == EDIT && !handleIndices.empty())
|
|
|
|
emit stopMoved(handleIndices.size()); // TODO: Accumulate key moves
|
2014-05-24 15:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::keyRightAction()
|
|
|
|
{
|
2021-06-30 05:49:56 +00:00
|
|
|
if ((currentState != EDIT && currentState != PLAN) || !plannerModel)
|
2014-05-24 15:39:40 +00:00
|
|
|
return;
|
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
std::vector<int> handleIndices = selectedDiveHandleIndices();
|
|
|
|
for (int row: handleIndices) {
|
|
|
|
divedatapoint dp = plannerModel->at(row);
|
2014-05-24 15:39:40 +00:00
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
dp.time += 60;
|
|
|
|
plannerModel->editStop(row, dp);
|
2014-05-24 15:39:40 +00:00
|
|
|
}
|
2022-02-19 10:58:36 +00:00
|
|
|
if (currentState == EDIT && !handleIndices.empty())
|
|
|
|
emit stopMoved(handleIndices.size()); // TODO: Accumulate key moves
|
2014-05-24 15:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::keyDeleteAction()
|
|
|
|
{
|
2021-06-30 05:49:56 +00:00
|
|
|
if ((currentState != EDIT && currentState != PLAN) || !plannerModel)
|
2014-05-24 15:39:40 +00:00
|
|
|
return;
|
|
|
|
|
2022-02-19 10:58:36 +00:00
|
|
|
std::vector<int> handleIndices = selectedDiveHandleIndices();
|
|
|
|
// For now, we have to convert to QVector.
|
|
|
|
for (int index: handleIndices)
|
|
|
|
handles[index]->hide();
|
|
|
|
if (!handleIndices.empty()) {
|
|
|
|
plannerModel->removeSelectedPoints(handleIndices);
|
|
|
|
if (currentState == EDIT)
|
|
|
|
emit stopRemoved(handleIndices.size());
|
2014-05-24 15:39:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 15:58:16 +00:00
|
|
|
void ProfileWidget2::clearPictures()
|
2014-06-03 22:24:01 +00:00
|
|
|
{
|
2014-07-21 21:54:28 +00:00
|
|
|
pictures.clear();
|
2018-04-06 15:58:16 +00:00
|
|
|
}
|
2014-07-21 21:54:28 +00:00
|
|
|
|
2018-07-15 15:56:18 +00:00
|
|
|
static const double unscaledDurationLineWidth = 2.5;
|
|
|
|
static const double unscaledDurationLinePenWidth = 0.5;
|
|
|
|
|
|
|
|
// Reset the duration line after an image was moved or we found a new duration
|
|
|
|
void ProfileWidget2::updateDurationLine(PictureEntry &e)
|
|
|
|
{
|
|
|
|
if (e.duration.seconds > 0) {
|
|
|
|
// We know the duration of this video, reset the line symbolizing its extent accordingly
|
2021-06-28 18:29:46 +00:00
|
|
|
double begin = profileScene->timeAxis->posAtValue(e.offset.seconds);
|
|
|
|
double end = profileScene->timeAxis->posAtValue(e.offset.seconds + e.duration.seconds);
|
2018-07-15 15:56:18 +00:00
|
|
|
double y = e.thumbnail->y();
|
|
|
|
|
|
|
|
// Undo scaling for pen-width and line-width. For this purpose, we use the scaling of the y-axis.
|
|
|
|
double scale = transform().m22();
|
|
|
|
double durationLineWidth = unscaledDurationLineWidth / scale;
|
|
|
|
double durationLinePenWidth = unscaledDurationLinePenWidth / scale;
|
|
|
|
e.durationLine.reset(new QGraphicsRectItem(begin, y - durationLineWidth - durationLinePenWidth, end - begin, durationLineWidth));
|
2021-07-29 04:50:59 +00:00
|
|
|
e.durationLine->setPen(QPen(getColor(DURATION_LINE, profileScene->isGrayscale), durationLinePenWidth));
|
|
|
|
e.durationLine->setBrush(getColor(::BACKGROUND, profileScene->isGrayscale));
|
2018-07-15 15:56:18 +00:00
|
|
|
e.durationLine->setVisible(prefs.show_pictures_in_profile);
|
|
|
|
scene()->addItem(e.durationLine.get());
|
|
|
|
} else {
|
|
|
|
// This is either a picture or a video with unknown duration.
|
|
|
|
// In case there was a line (how could that be?) remove it.
|
|
|
|
e.durationLine.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-30 09:36:37 +00:00
|
|
|
// This function is called asynchronously by the thumbnailer if a thumbnail
|
|
|
|
// was fetched from disk or freshly calculated.
|
2018-07-15 15:56:18 +00:00
|
|
|
void ProfileWidget2::updateThumbnail(QString filename, QImage thumbnail, duration_t duration)
|
2018-04-06 15:58:16 +00:00
|
|
|
{
|
2018-06-30 09:36:37 +00:00
|
|
|
// Find the picture with the given filename
|
|
|
|
auto it = std::find_if(pictures.begin(), pictures.end(), [&filename](const PictureEntry &e)
|
|
|
|
{ return e.filename == filename; });
|
2014-07-02 20:58:06 +00:00
|
|
|
|
2018-06-30 09:36:37 +00:00
|
|
|
// If we didn't find a picture, it does either not belong to the current dive,
|
|
|
|
// or its timestamp is outside of the profile.
|
|
|
|
if (it != pictures.end()) {
|
|
|
|
// Replace the pixmap of the thumbnail with the newly calculated one.
|
|
|
|
int size = Thumbnailer::defaultThumbnailSize();
|
|
|
|
it->thumbnail->setPixmap(QPixmap::fromImage(thumbnail.scaled(size, size, Qt::KeepAspectRatio)));
|
2018-07-15 15:56:18 +00:00
|
|
|
|
|
|
|
// If the duration changed, update the line
|
|
|
|
if (duration.seconds != it->duration.seconds) {
|
|
|
|
it->duration = duration;
|
|
|
|
updateDurationLine(*it);
|
|
|
|
// If we created / removed a duration line, we have to update the thumbnail paint order.
|
|
|
|
updateThumbnailPaintOrder();
|
|
|
|
}
|
2018-04-06 15:58:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-30 19:32:14 +00:00
|
|
|
// Create a PictureEntry object and add its thumbnail to the scene if profile pictures are shown.
|
2020-12-19 11:32:32 +00:00
|
|
|
ProfileWidget2::PictureEntry::PictureEntry(offset_t offsetIn, const QString &filenameIn, ProfileWidget2 *profile, bool synchronous) : offset(offsetIn),
|
2018-07-15 15:56:18 +00:00
|
|
|
duration(duration_t {0}),
|
2018-06-30 09:36:37 +00:00
|
|
|
filename(filenameIn),
|
|
|
|
thumbnail(new DivePictureItem)
|
|
|
|
{
|
2020-12-19 11:32:32 +00:00
|
|
|
QGraphicsScene *scene = profile->scene();
|
2018-06-30 19:32:14 +00:00
|
|
|
int size = Thumbnailer::defaultThumbnailSize();
|
|
|
|
scene->addItem(thumbnail.get());
|
|
|
|
thumbnail->setVisible(prefs.show_pictures_in_profile);
|
2019-02-02 20:23:52 +00:00
|
|
|
QImage img = Thumbnailer::instance()->fetchThumbnail(filename, synchronous).scaled(size, size, Qt::KeepAspectRatio);
|
2018-06-30 19:32:14 +00:00
|
|
|
thumbnail->setPixmap(QPixmap::fromImage(img));
|
|
|
|
thumbnail->setFileUrl(filename);
|
2020-12-19 11:32:32 +00:00
|
|
|
connect(thumbnail.get(), &DivePictureItem::removePicture, profile, &ProfileWidget2::removePicture);
|
2018-06-30 09:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Define a default sort order for picture-entries: sort lexicographically by timestamp and filename.
|
|
|
|
bool ProfileWidget2::PictureEntry::operator< (const PictureEntry &e) const
|
|
|
|
{
|
|
|
|
// Use std::tie() for lexicographical sorting.
|
|
|
|
return std::tie(offset.seconds, filename) < std::tie(e.offset.seconds, e.filename);
|
|
|
|
}
|
|
|
|
|
2018-07-15 15:56:18 +00:00
|
|
|
// This function updates the paint order of the thumbnails and duration-lines, such that later
|
|
|
|
// thumbnails are painted on top of previous thumbnails and duration-lines on top of the thumbnail
|
|
|
|
// they belong to.
|
|
|
|
void ProfileWidget2::updateThumbnailPaintOrder()
|
|
|
|
{
|
|
|
|
if (!pictures.size())
|
|
|
|
return;
|
|
|
|
// To get the correct sort order, we place in thumbnails at equal z-distances
|
|
|
|
// between thumbnailBaseZValue and (thumbnailBaseZValue + 1.0).
|
|
|
|
// Duration-lines are placed between the thumbnails.
|
|
|
|
double z = thumbnailBaseZValue;
|
|
|
|
double step = 1.0 / (double)pictures.size();
|
|
|
|
for (PictureEntry &e: pictures) {
|
|
|
|
e.thumbnail->setBaseZValue(z);
|
|
|
|
if (e.durationLine)
|
|
|
|
e.durationLine->setZValue(z + step / 2.0);
|
|
|
|
z += step;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-30 19:32:14 +00:00
|
|
|
// Calculate the y-coordinates of the thumbnails, which are supposed to be sorted by x-coordinate.
|
|
|
|
// This will also change the order in which the thumbnails are painted, to avoid weird effects,
|
2018-07-15 15:30:34 +00:00
|
|
|
// when items are added later to the scene. This is done using the QGraphicsItem::packBefore() function.
|
|
|
|
// We can't use the z-value, because that will be modified on hoverEnter and hoverExit events.
|
2018-06-30 10:55:55 +00:00
|
|
|
void ProfileWidget2::calculatePictureYPositions()
|
|
|
|
{
|
2018-07-15 15:30:34 +00:00
|
|
|
double lastX = -1.0, lastY = 0.0;
|
2021-10-26 07:40:38 +00:00
|
|
|
const double yStart = 0.05; // At which depth the thumbnails start (in fraction of total depth).
|
|
|
|
const double yStep = 0.01; // Increase of depth for overlapping thumbnails (in fraction of total depth).
|
|
|
|
const double xSpace = 18.0 * profileScene->dpr; // Horizontal range in which thumbnails are supposed to be overlapping (in pixels).
|
|
|
|
const int maxDepth = 14; // Maximal depth of thumbnail stack (in thumbnails).
|
2018-07-15 15:56:18 +00:00
|
|
|
for (PictureEntry &e: pictures) {
|
2021-10-26 13:07:51 +00:00
|
|
|
// Invisible items are outside of the shown range - ignore.
|
|
|
|
if (!e.thumbnail->isVisible())
|
|
|
|
continue;
|
|
|
|
|
2021-10-26 07:40:38 +00:00
|
|
|
// Let's put the picture at the correct time, but at a fixed "depth" on the profile
|
2018-06-30 10:55:55 +00:00
|
|
|
// not sure this is ideal, but it seems to look right.
|
2018-07-15 15:56:18 +00:00
|
|
|
double x = e.thumbnail->x();
|
2021-10-26 07:40:38 +00:00
|
|
|
if (x < 0.0)
|
|
|
|
continue;
|
2018-06-30 10:55:55 +00:00
|
|
|
double y;
|
2021-10-26 07:40:38 +00:00
|
|
|
if (lastX >= 0.0 && fabs(x - lastX) < xSpace * profileScene->dpr && lastY <= (yStart + maxDepth * yStep) - 1e-10)
|
|
|
|
y = lastY + yStep;
|
2018-06-30 10:55:55 +00:00
|
|
|
else
|
2021-10-26 07:40:38 +00:00
|
|
|
y = yStart;
|
2018-06-30 10:55:55 +00:00
|
|
|
lastX = x;
|
|
|
|
lastY = y;
|
2021-10-26 07:40:38 +00:00
|
|
|
double yScreen = profileScene->timeAxis->screenPosition(y);
|
|
|
|
e.thumbnail->setY(yScreen);
|
2018-07-15 15:56:18 +00:00
|
|
|
updateDurationLine(e); // If we changed the y-position, we also have to change the duration-line.
|
2018-06-30 10:55:55 +00:00
|
|
|
}
|
2018-07-15 15:56:18 +00:00
|
|
|
updateThumbnailPaintOrder();
|
2018-06-30 10:55:55 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 19:32:14 +00:00
|
|
|
void ProfileWidget2::updateThumbnailXPos(PictureEntry &e)
|
|
|
|
{
|
|
|
|
// Here, we only set the x-coordinate of the picture. The y-coordinate
|
|
|
|
// will be set later in calculatePictureYPositions().
|
2021-10-26 13:07:51 +00:00
|
|
|
// Thumbnails outside of the shown range are hidden.
|
|
|
|
double time = e.offset.seconds;
|
|
|
|
if (time >= profileScene->timeAxis->minimum() && time <= profileScene->timeAxis->maximum()) {
|
|
|
|
double x = profileScene->timeAxis->posAtValue(time);
|
|
|
|
e.thumbnail->setX(x);
|
|
|
|
e.thumbnail->setVisible(true);
|
|
|
|
} else {
|
|
|
|
e.thumbnail->setVisible(false);
|
|
|
|
}
|
2018-06-30 19:32:14 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 09:36:37 +00:00
|
|
|
// This function resets the picture thumbnails of the current dive.
|
2018-04-06 15:58:16 +00:00
|
|
|
void ProfileWidget2::plotPictures()
|
2019-02-02 20:23:52 +00:00
|
|
|
{
|
2021-01-28 13:24:38 +00:00
|
|
|
plotPicturesInternal(d, false);
|
2019-02-02 20:23:52 +00:00
|
|
|
}
|
|
|
|
|
2019-02-03 12:28:33 +00:00
|
|
|
void ProfileWidget2::plotPicturesInternal(const struct dive *d, bool synchronous)
|
2018-04-06 15:58:16 +00:00
|
|
|
{
|
2018-06-30 09:36:37 +00:00
|
|
|
pictures.clear();
|
2021-06-30 05:49:56 +00:00
|
|
|
if (currentState == EDIT || currentState == PLAN)
|
2018-06-30 09:36:37 +00:00
|
|
|
return;
|
2018-04-06 15:58:16 +00:00
|
|
|
|
2019-02-02 20:31:12 +00:00
|
|
|
// Fetch all pictures of the dive, but consider only those that are within the dive time.
|
2018-06-30 09:36:37 +00:00
|
|
|
// For each picture, create a PictureEntry object in the pictures-vector.
|
|
|
|
// emplace_back() constructs an object at the end of the vector. The parameters are passed directly to the constructor.
|
2019-02-02 20:31:12 +00:00
|
|
|
// Note that FOR_EACH_PICTURE handles d being null gracefully.
|
|
|
|
FOR_EACH_PICTURE(d) {
|
|
|
|
if (picture->offset.seconds > 0 && picture->offset.seconds <= d->duration.seconds)
|
2020-12-19 11:32:32 +00:00
|
|
|
pictures.emplace_back(picture->offset, QString(picture->filename), this, synchronous);
|
2018-06-30 09:36:37 +00:00
|
|
|
}
|
|
|
|
if (pictures.empty())
|
|
|
|
return;
|
|
|
|
// Sort pictures by timestamp (and filename if equal timestamps).
|
|
|
|
// This will allow for proper location of the pictures on the profile plot.
|
|
|
|
std::sort(pictures.begin(), pictures.end());
|
2021-10-26 05:42:13 +00:00
|
|
|
updateThumbnails();
|
|
|
|
}
|
2018-06-30 09:36:37 +00:00
|
|
|
|
2021-10-26 05:42:13 +00:00
|
|
|
void ProfileWidget2::updateThumbnails()
|
|
|
|
{
|
2018-06-30 19:32:14 +00:00
|
|
|
// Calculate thumbnail positions. First the x-coordinates and and then the y-coordinates.
|
|
|
|
for (PictureEntry &e: pictures)
|
|
|
|
updateThumbnailXPos(e);
|
2018-06-30 10:55:55 +00:00
|
|
|
calculatePictureYPositions();
|
2014-06-03 22:24:01 +00:00
|
|
|
}
|
2018-05-19 19:18:39 +00:00
|
|
|
|
2018-06-30 09:36:37 +00:00
|
|
|
// Remove the pictures with the given filenames from the profile plot.
|
2020-04-17 21:18:58 +00:00
|
|
|
void ProfileWidget2::picturesRemoved(dive *d, QVector<QString> fileUrls)
|
2018-06-30 09:36:37 +00:00
|
|
|
{
|
|
|
|
// To remove the pictures, we use the std::remove_if() algorithm.
|
|
|
|
// std::remove_if() does not actually delete the elements, but moves
|
|
|
|
// them to the end of the given range. It returns an iterator to the
|
|
|
|
// end of the new range of non-deleted elements. A subsequent call to
|
|
|
|
// std::erase on the range of deleted elements then ultimately shrinks the vector.
|
|
|
|
// (c.f. erase-remove idiom: https://en.wikipedia.org/wiki/Erase%E2%80%93remove_idiom)
|
|
|
|
auto it = std::remove_if(pictures.begin(), pictures.end(), [&fileUrls](const PictureEntry &e)
|
|
|
|
// Check whether filename of entry is in list of provided filenames
|
|
|
|
{ return std::find(fileUrls.begin(), fileUrls.end(), e.filename) != fileUrls.end(); });
|
|
|
|
pictures.erase(it, pictures.end());
|
2018-06-30 10:55:55 +00:00
|
|
|
calculatePictureYPositions();
|
2018-05-19 19:18:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 21:18:58 +00:00
|
|
|
void ProfileWidget2::picturesAdded(dive *d, QVector<PictureObj> pics)
|
|
|
|
{
|
|
|
|
for (const PictureObj &pic: pics) {
|
|
|
|
if (pic.offset.seconds > 0 && pic.offset.seconds <= d->duration.seconds) {
|
2020-12-19 11:32:32 +00:00
|
|
|
pictures.emplace_back(pic.offset, QString::fromStdString(pic.filename), this, false);
|
2020-04-17 21:18:58 +00:00
|
|
|
updateThumbnailXPos(pictures.back());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort pictures by timestamp (and filename if equal timestamps).
|
|
|
|
// This will allow for proper location of the pictures on the profile plot.
|
|
|
|
std::sort(pictures.begin(), pictures.end());
|
|
|
|
|
|
|
|
calculatePictureYPositions();
|
|
|
|
}
|
|
|
|
|
2020-12-19 11:32:32 +00:00
|
|
|
void ProfileWidget2::removePicture(const QString &fileUrl)
|
|
|
|
{
|
|
|
|
if (d)
|
2021-01-28 13:24:38 +00:00
|
|
|
Command::removePictures({ { mutable_dive(), { fileUrl.toStdString() } } });
|
2020-12-19 11:32:32 +00:00
|
|
|
}
|
|
|
|
|
2021-01-28 13:24:38 +00:00
|
|
|
void ProfileWidget2::profileChanged(dive *dive)
|
2020-03-01 16:16:08 +00:00
|
|
|
{
|
2021-01-28 13:24:38 +00:00
|
|
|
if (dive != d)
|
2020-03-01 16:16:08 +00:00
|
|
|
return; // Cylinders of a differnt dive than the shown one changed.
|
|
|
|
replot();
|
|
|
|
}
|
|
|
|
|
2018-01-10 12:55:29 +00:00
|
|
|
#endif
|
2015-11-03 20:17:50 +00:00
|
|
|
|
|
|
|
void ProfileWidget2::dropEvent(QDropEvent *event)
|
|
|
|
{
|
2020-04-14 20:07:00 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2021-01-28 13:24:38 +00:00
|
|
|
if (event->mimeData()->hasFormat("application/x-subsurfaceimagedrop") && d) {
|
2015-11-03 20:17:50 +00:00
|
|
|
QByteArray itemData = event->mimeData()->data("application/x-subsurfaceimagedrop");
|
|
|
|
QDataStream dataStream(&itemData, QIODevice::ReadOnly);
|
|
|
|
|
|
|
|
QString filename;
|
2020-04-14 20:07:00 +00:00
|
|
|
dataStream >> filename;
|
2015-11-03 20:17:50 +00:00
|
|
|
QPointF mappedPos = mapToScene(event->pos());
|
2021-06-28 18:29:46 +00:00
|
|
|
offset_t offset { (int32_t)lrint(profileScene->timeAxis->valueAt(mappedPos)) };
|
2021-01-28 13:24:38 +00:00
|
|
|
Command::setPictureOffset(mutable_dive(), filename, offset);
|
2015-11-03 20:17:50 +00:00
|
|
|
|
|
|
|
if (event->source() == this) {
|
|
|
|
event->setDropAction(Qt::MoveAction);
|
|
|
|
event->accept();
|
|
|
|
} else {
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
event->ignore();
|
|
|
|
}
|
2020-04-14 20:07:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2021-01-28 13:24:38 +00:00
|
|
|
void ProfileWidget2::pictureOffsetChanged(dive *dIn, QString filename, offset_t offset)
|
2020-04-14 20:07:00 +00:00
|
|
|
{
|
2021-01-28 13:24:38 +00:00
|
|
|
if (dIn != d)
|
2020-04-14 20:07:00 +00:00
|
|
|
return; // Picture of a different dive than the one shown changed.
|
|
|
|
|
|
|
|
// Calculate time in dive where picture was dropped and whether the new position is during the dive.
|
2021-01-28 13:24:38 +00:00
|
|
|
bool duringDive = d && offset.seconds > 0 && offset.seconds < d->duration.seconds;
|
2020-04-14 20:07:00 +00:00
|
|
|
|
|
|
|
// A picture was drag&dropped onto the profile: We have four cases to consider:
|
|
|
|
// 1a) The image was already shown on the profile and is moved to a different position on the profile.
|
|
|
|
// Calculate the new position and move the picture.
|
|
|
|
// 1b) The image was on the profile and is moved outside of the dive time.
|
|
|
|
// Remove the picture.
|
|
|
|
// 2a) The image was not on the profile and is moved into the dive time.
|
|
|
|
// Add the picture to the profile.
|
|
|
|
// 2b) The image was not on the profile and is moved outside of the dive time.
|
|
|
|
// Do nothing.
|
|
|
|
auto oldPos = std::find_if(pictures.begin(), pictures.end(), [filename](const PictureEntry &e)
|
|
|
|
{ return e.filename == filename; });
|
|
|
|
if (oldPos != pictures.end()) {
|
|
|
|
// Cases 1a) and 1b): picture is on profile
|
|
|
|
if (duringDive) {
|
|
|
|
// Case 1a): move to new position
|
|
|
|
// First, find new position. Note that we also have to compare filenames,
|
|
|
|
// because it is quite easy to generate equal offsets.
|
|
|
|
auto newPos = std::find_if(pictures.begin(), pictures.end(), [offset, &filename](const PictureEntry &e)
|
|
|
|
{ return std::tie(e.offset.seconds, e.filename) > std::tie(offset.seconds, filename); });
|
|
|
|
// Set new offset
|
|
|
|
oldPos->offset.seconds = offset.seconds;
|
|
|
|
updateThumbnailXPos(*oldPos);
|
|
|
|
|
|
|
|
// Move image from old to new position
|
|
|
|
int oldIndex = oldPos - pictures.begin();
|
|
|
|
int newIndex = newPos - pictures.begin();
|
|
|
|
moveInVector(pictures, oldIndex, oldIndex + 1, newIndex);
|
|
|
|
} else {
|
|
|
|
// Case 1b): remove picture
|
|
|
|
pictures.erase(oldPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// In both cases the picture list changed, therefore we must recalculate the y-coordinatesA.
|
|
|
|
calculatePictureYPositions();
|
|
|
|
} else {
|
|
|
|
// Cases 2a) and 2b): picture not on profile. We only have to take action for
|
|
|
|
// the first case: picture is moved into dive-time.
|
|
|
|
if (duringDive) {
|
|
|
|
// Case 2a): add the picture at the appropriate position.
|
|
|
|
// The case move from outside-to-outside of the profile plot was handled by
|
|
|
|
// the "&& duringDive" condition in the if above.
|
|
|
|
// As for case 1a), we have to also consider filenames in the case of equal offsets.
|
|
|
|
auto newPos = std::find_if(pictures.begin(), pictures.end(), [offset, &filename](const PictureEntry &e)
|
|
|
|
{ return std::tie(e.offset.seconds, e.filename) > std::tie(offset.seconds, filename); });
|
|
|
|
// emplace() constructs the element at the given position in the vector.
|
|
|
|
// The parameters are passed directly to the contructor.
|
|
|
|
// The call returns an iterator to the new element (which might differ from
|
|
|
|
// the old iterator, since the buffer might have been reallocated).
|
2020-12-19 11:32:32 +00:00
|
|
|
newPos = pictures.emplace(newPos, offset, filename, this, false);
|
2020-04-14 20:07:00 +00:00
|
|
|
updateThumbnailXPos(*newPos);
|
|
|
|
calculatePictureYPositions();
|
|
|
|
}
|
|
|
|
}
|
2015-11-03 20:17:50 +00:00
|
|
|
}
|
2020-04-14 20:07:00 +00:00
|
|
|
#endif
|
2015-11-03 20:17:50 +00:00
|
|
|
|
|
|
|
void ProfileWidget2::dragEnterEvent(QDragEnterEvent *event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasFormat("application/x-subsurfaceimagedrop")) {
|
|
|
|
if (event->source() == this) {
|
|
|
|
event->setDropAction(Qt::MoveAction);
|
|
|
|
event->accept();
|
|
|
|
} else {
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProfileWidget2::dragMoveEvent(QDragMoveEvent *event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasFormat("application/x-subsurfaceimagedrop")) {
|
|
|
|
if (event->source() == this) {
|
|
|
|
event->setDropAction(Qt::MoveAction);
|
|
|
|
event->accept();
|
|
|
|
} else {
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
}
|
2021-01-28 13:24:38 +00:00
|
|
|
|
|
|
|
struct dive *ProfileWidget2::mutable_dive() const
|
|
|
|
{
|
|
|
|
return const_cast<dive *>(d);
|
|
|
|
}
|