2013-06-20 15:33:26 +00:00
|
|
|
#include "diveplanner.h"
|
2013-07-02 13:13:06 +00:00
|
|
|
#include "graphicsview-common.h"
|
2013-08-28 10:48:46 +00:00
|
|
|
#include "models.h"
|
2013-08-30 10:14:30 +00:00
|
|
|
#include "modeldelegates.h"
|
2013-08-30 19:43:10 +00:00
|
|
|
#include "mainwindow.h"
|
2013-09-19 04:02:53 +00:00
|
|
|
#include "maintab.h"
|
2013-09-02 19:21:08 +00:00
|
|
|
#include "tableview.h"
|
2013-09-16 22:21:13 +00:00
|
|
|
#include "graphicsview-common.h"
|
2013-07-02 13:13:06 +00:00
|
|
|
|
2013-06-24 01:04:35 +00:00
|
|
|
#include "../dive.h"
|
2013-07-05 21:42:35 +00:00
|
|
|
#include "../divelist.h"
|
2013-08-30 18:06:26 +00:00
|
|
|
#include "../planner.h"
|
2013-09-20 23:41:42 +00:00
|
|
|
#include "helpers.h"
|
2013-08-30 10:14:30 +00:00
|
|
|
|
2013-06-20 15:37:41 +00:00
|
|
|
#include <QMouseEvent>
|
2013-06-20 16:39:41 +00:00
|
|
|
#include <QDebug>
|
2013-07-02 17:36:52 +00:00
|
|
|
#include <QGraphicsSceneMouseEvent>
|
2013-07-04 15:58:11 +00:00
|
|
|
#include <QMessageBox>
|
2013-07-21 15:56:21 +00:00
|
|
|
#include <QStringListModel>
|
2013-07-21 16:54:21 +00:00
|
|
|
#include <QListView>
|
|
|
|
#include <QModelIndex>
|
2013-08-28 10:48:46 +00:00
|
|
|
#include <QSettings>
|
2013-09-02 19:21:08 +00:00
|
|
|
#include <QTableView>
|
2013-09-16 22:21:13 +00:00
|
|
|
#include <QColor>
|
2013-06-20 15:33:26 +00:00
|
|
|
|
2013-10-03 20:34:50 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2013-06-27 14:10:03 +00:00
|
|
|
#define TIME_INITIAL_MAX 30
|
|
|
|
|
2013-09-22 19:37:49 +00:00
|
|
|
#define MAX_DEPTH M_OR_FT(150, 450)
|
|
|
|
#define MIN_DEPTH M_OR_FT(20, 60)
|
2013-07-02 17:14:09 +00:00
|
|
|
|
2013-09-22 19:37:49 +00:00
|
|
|
#define M_OR_FT(_m,_f) ((prefs.units.length == units::METERS) ? ((_m) * 1000) : ((_f) * 304.8))
|
|
|
|
|
2013-11-11 08:09:19 +00:00
|
|
|
QString gasToStr(const int o2Permille, const int hePermille) {
|
|
|
|
uint o2 = (o2Permille + 5) / 10, he = (hePermille + 5) / 10;
|
|
|
|
QString result = is_air(o2Permille, hePermille) ? QObject::tr("AIR")
|
|
|
|
: he == 0 ? QString("EAN%1").arg(o2, 2, 10, QChar('0'))
|
|
|
|
: QString("%1/%2").arg(o2).arg(he);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString dpGasToStr(const divedatapoint& p)
|
|
|
|
{
|
|
|
|
return gasToStr(p.o2, p.he);
|
2013-08-30 18:06:26 +00:00
|
|
|
}
|
|
|
|
|
2013-09-16 22:21:13 +00:00
|
|
|
QColor getColor(const color_indice_t i)
|
|
|
|
{
|
|
|
|
return profile_color[i].at(0);
|
|
|
|
}
|
|
|
|
|
2013-08-26 19:34:06 +00:00
|
|
|
static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
|
2013-07-04 13:06:52 +00:00
|
|
|
|
2013-07-04 13:29:28 +00:00
|
|
|
DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0)
|
2013-06-20 15:33:26 +00:00
|
|
|
{
|
2013-07-02 13:13:06 +00:00
|
|
|
fill_profile_color();
|
|
|
|
setBackgroundBrush(profile_color[BACKGROUND].at(0));
|
2013-06-20 16:53:12 +00:00
|
|
|
setMouseTracking(true);
|
2013-06-23 20:09:29 +00:00
|
|
|
setScene(new QGraphicsScene());
|
2013-07-02 13:53:08 +00:00
|
|
|
scene()->setSceneRect(0,0,1920,1080);
|
|
|
|
|
|
|
|
verticalLine = new QGraphicsLineItem(
|
|
|
|
fromPercent(0, Qt::Horizontal),
|
|
|
|
fromPercent(0, Qt::Vertical),
|
|
|
|
fromPercent(0, Qt::Horizontal),
|
2013-07-02 14:12:15 +00:00
|
|
|
fromPercent(100, Qt::Vertical)
|
|
|
|
);
|
2013-06-20 16:53:12 +00:00
|
|
|
|
|
|
|
verticalLine->setPen(QPen(Qt::DotLine));
|
|
|
|
scene()->addItem(verticalLine);
|
|
|
|
|
2013-07-02 14:12:15 +00:00
|
|
|
horizontalLine = new QGraphicsLineItem(
|
|
|
|
fromPercent(0, Qt::Horizontal),
|
|
|
|
fromPercent(0, Qt::Vertical),
|
|
|
|
fromPercent(100, Qt::Horizontal),
|
|
|
|
fromPercent(0, Qt::Vertical)
|
|
|
|
);
|
2013-09-16 22:21:13 +00:00
|
|
|
|
2013-06-20 16:53:12 +00:00
|
|
|
horizontalLine->setPen(QPen(Qt::DotLine));
|
|
|
|
scene()->addItem(horizontalLine);
|
2013-06-20 19:48:24 +00:00
|
|
|
|
|
|
|
timeLine = new Ruler();
|
|
|
|
timeLine->setMinimum(0);
|
2013-06-27 14:10:03 +00:00
|
|
|
timeLine->setMaximum(TIME_INITIAL_MAX);
|
2013-06-20 19:48:24 +00:00
|
|
|
timeLine->setTickInterval(10);
|
2013-09-16 22:21:13 +00:00
|
|
|
timeLine->setColor(getColor(TIME_GRID));
|
2013-07-02 14:12:15 +00:00
|
|
|
timeLine->setLine(
|
|
|
|
fromPercent(10, Qt::Horizontal),
|
2013-11-17 23:20:07 +00:00
|
|
|
fromPercent(85, Qt::Vertical),
|
2013-07-02 14:12:15 +00:00
|
|
|
fromPercent(90, Qt::Horizontal),
|
2013-11-17 23:20:07 +00:00
|
|
|
fromPercent(85, Qt::Vertical)
|
2013-07-02 14:12:15 +00:00
|
|
|
);
|
2013-06-20 19:48:24 +00:00
|
|
|
timeLine->setOrientation(Qt::Horizontal);
|
2013-07-02 14:12:15 +00:00
|
|
|
timeLine->setTickSize(fromPercent(1, Qt::Vertical));
|
2013-09-16 23:10:12 +00:00
|
|
|
timeLine->setTextColor(getColor(TIME_TEXT));
|
2013-06-20 19:48:24 +00:00
|
|
|
timeLine->updateTicks();
|
|
|
|
scene()->addItem(timeLine);
|
|
|
|
|
|
|
|
depthLine = new Ruler();
|
|
|
|
depthLine->setMinimum(0);
|
2013-09-22 19:37:49 +00:00
|
|
|
depthLine->setMaximum(M_OR_FT(40,120));
|
|
|
|
depthLine->setTickInterval(M_OR_FT(10,30));
|
2013-07-02 14:12:15 +00:00
|
|
|
depthLine->setLine(
|
|
|
|
fromPercent(10, Qt::Horizontal),
|
|
|
|
fromPercent(10, Qt::Vertical),
|
|
|
|
fromPercent(10, Qt::Horizontal),
|
2013-11-17 23:20:07 +00:00
|
|
|
fromPercent(85, Qt::Vertical)
|
2013-07-02 14:12:15 +00:00
|
|
|
);
|
2013-06-20 19:48:24 +00:00
|
|
|
depthLine->setOrientation(Qt::Vertical);
|
2013-07-02 14:12:15 +00:00
|
|
|
depthLine->setTickSize(fromPercent(1, Qt::Horizontal));
|
2013-09-16 22:21:13 +00:00
|
|
|
depthLine->setColor(getColor(DEPTH_GRID));
|
2013-09-16 23:10:12 +00:00
|
|
|
depthLine->setTextColor(getColor(SAMPLE_DEEP));
|
2013-06-20 19:48:24 +00:00
|
|
|
depthLine->updateTicks();
|
|
|
|
scene()->addItem(depthLine);
|
2013-06-20 20:54:36 +00:00
|
|
|
|
|
|
|
timeString = new QGraphicsSimpleTextItem();
|
|
|
|
timeString->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
2013-07-02 16:31:25 +00:00
|
|
|
timeString->setBrush(profile_color[TIME_TEXT].at(0));
|
2013-06-20 20:54:36 +00:00
|
|
|
scene()->addItem(timeString);
|
|
|
|
|
|
|
|
depthString = new QGraphicsSimpleTextItem();
|
|
|
|
depthString->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
2013-07-02 16:31:25 +00:00
|
|
|
depthString->setBrush(profile_color[SAMPLE_DEEP].at(0));
|
2013-06-20 20:54:36 +00:00
|
|
|
scene()->addItem(depthString);
|
2013-06-21 19:44:38 +00:00
|
|
|
|
2013-06-27 22:52:58 +00:00
|
|
|
diveBg = new QGraphicsPolygonItem();
|
2013-07-02 16:39:54 +00:00
|
|
|
diveBg->setPen(QPen(QBrush(),0));
|
2013-06-27 22:52:58 +00:00
|
|
|
scene()->addItem(diveBg);
|
|
|
|
|
2013-09-22 19:37:49 +00:00
|
|
|
QString incrText;
|
|
|
|
if (prefs.units.length == units::METERS)
|
|
|
|
incrText = tr("10m");
|
|
|
|
else
|
|
|
|
incrText = tr("30ft");
|
2013-07-04 14:06:28 +00:00
|
|
|
|
2013-11-17 23:20:07 +00:00
|
|
|
timeHandler = new ExpanderGraphics();
|
|
|
|
timeHandler->increaseBtn->setPixmap(QString(":plan_plus"));
|
|
|
|
timeHandler->decreaseBtn->setPixmap(QString(":plan_minus"));
|
|
|
|
timeHandler->icon->setPixmap(QString(":icon_time"));
|
|
|
|
connect(timeHandler->increaseBtn, SIGNAL(clicked()), this, SLOT(increaseTime()));
|
|
|
|
connect(timeHandler->decreaseBtn, SIGNAL(clicked()), this, SLOT(decreaseTime()));
|
2013-11-18 23:13:05 +00:00
|
|
|
timeHandler->setPos(fromPercent(83, Qt::Horizontal), fromPercent(100, Qt::Vertical));
|
2013-11-17 23:20:07 +00:00
|
|
|
timeHandler->setZValue(-2);
|
|
|
|
scene()->addItem(timeHandler);
|
|
|
|
|
|
|
|
depthHandler = new ExpanderGraphics();
|
|
|
|
depthHandler->increaseBtn->setPixmap(QString(":arrow_up"));
|
|
|
|
depthHandler->decreaseBtn->setPixmap(QString(":arrow_down"));
|
|
|
|
depthHandler->icon->setPixmap(QString(":icon_depth"));
|
2013-11-19 00:34:59 +00:00
|
|
|
// Inverted here in the slots because the 'up' graphi should increase the depness,
|
|
|
|
// and the down should decrease.
|
|
|
|
connect(depthHandler->increaseBtn, SIGNAL(clicked()), this, SLOT(decreaseDepth()));
|
|
|
|
connect(depthHandler->decreaseBtn, SIGNAL(clicked()), this, SLOT(increaseDepth()));
|
2013-11-18 23:13:05 +00:00
|
|
|
depthHandler->setPos(fromPercent(0, Qt::Horizontal), fromPercent(100, Qt::Vertical));
|
2013-11-17 23:20:07 +00:00
|
|
|
depthHandler->setZValue(-2);
|
|
|
|
scene()->addItem(depthHandler);
|
|
|
|
|
|
|
|
minMinutes = TIME_INITIAL_MAX;
|
2013-07-04 14:16:42 +00:00
|
|
|
QAction *action = NULL;
|
2013-07-04 14:06:28 +00:00
|
|
|
|
2013-07-04 14:16:42 +00:00
|
|
|
#define ADD_ACTION( SHORTCUT, Slot ) \
|
|
|
|
action = new QAction(this); \
|
|
|
|
action->setShortcut( SHORTCUT ); \
|
2013-07-04 15:30:05 +00:00
|
|
|
action->setShortcutContext(Qt::WindowShortcut); \
|
2013-07-04 14:16:42 +00:00
|
|
|
addAction(action); \
|
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT( Slot ))
|
|
|
|
|
|
|
|
ADD_ACTION(Qt::Key_Escape, keyEscAction());
|
|
|
|
ADD_ACTION(Qt::Key_Delete, keyDeleteAction());
|
2013-07-04 14:28:39 +00:00
|
|
|
ADD_ACTION(Qt::Key_Up, keyUpAction());
|
|
|
|
ADD_ACTION(Qt::Key_Down, keyDownAction());
|
2013-07-04 15:30:05 +00:00
|
|
|
ADD_ACTION(Qt::Key_Left, keyLeftAction());
|
|
|
|
ADD_ACTION(Qt::Key_Right, keyRightAction());
|
2013-07-04 14:16:42 +00:00
|
|
|
#undef ADD_ACTION
|
2013-07-04 14:06:28 +00:00
|
|
|
|
2013-07-21 16:54:21 +00:00
|
|
|
// Prepare the stuff for the gas-choices.
|
|
|
|
gasListView = new QListView();
|
2013-08-26 11:49:28 +00:00
|
|
|
gasListView->setWindowFlags(Qt::Popup);
|
2013-11-14 19:39:35 +00:00
|
|
|
gasListView->setModel(GasSelectionModel::instance());
|
2013-07-21 16:54:21 +00:00
|
|
|
gasListView->hide();
|
2013-09-21 15:50:09 +00:00
|
|
|
gasListView->installEventFilter(this);
|
2013-07-21 15:56:21 +00:00
|
|
|
|
2013-07-21 16:54:21 +00:00
|
|
|
connect(gasListView, SIGNAL(activated(QModelIndex)), this, SLOT(selectGas(QModelIndex)));
|
2013-09-19 03:19:49 +00:00
|
|
|
connect(plannerModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(drawProfile()));
|
2013-08-30 18:53:10 +00:00
|
|
|
|
|
|
|
connect(plannerModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)),
|
2013-08-26 17:17:39 +00:00
|
|
|
this, SLOT(pointInserted(const QModelIndex&, int, int)));
|
2013-08-30 18:53:10 +00:00
|
|
|
connect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
|
|
|
|
this, SLOT(pointsRemoved(const QModelIndex&, int, int)));
|
2013-06-27 22:52:58 +00:00
|
|
|
setRenderHint(QPainter::Antialiasing);
|
2013-06-27 19:45:58 +00:00
|
|
|
}
|
|
|
|
|
2013-09-21 15:50:09 +00:00
|
|
|
bool DivePlannerGraphics::eventFilter(QObject *object, QEvent* event)
|
|
|
|
{
|
2013-11-14 17:20:11 +00:00
|
|
|
if (object != gasListView)
|
|
|
|
return false;
|
|
|
|
if (event->type() == QEvent::KeyPress) {
|
2013-09-21 15:50:09 +00:00
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
|
|
|
|
if (ke->key() == Qt::Key_Escape)
|
|
|
|
gasListView->hide();
|
|
|
|
}
|
2013-11-14 17:20:11 +00:00
|
|
|
if (event->type() == QEvent::MouseButtonPress){
|
|
|
|
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
|
|
|
if (!gasListView->geometry().contains(me->pos()))
|
|
|
|
gasListView->hide();
|
|
|
|
}
|
2013-09-21 15:50:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-26 17:17:39 +00:00
|
|
|
void DivePlannerGraphics::pointInserted(const QModelIndex& parent, int start , int end)
|
|
|
|
{
|
|
|
|
DiveHandler *item = new DiveHandler ();
|
|
|
|
scene()->addItem(item);
|
|
|
|
handles << item;
|
|
|
|
|
|
|
|
Button *gasChooseBtn = new Button();
|
|
|
|
scene()->addItem(gasChooseBtn);
|
|
|
|
gasChooseBtn->setZValue(10);
|
|
|
|
connect(gasChooseBtn, SIGNAL(clicked()), this, SLOT(prepareSelectGas()));
|
|
|
|
|
|
|
|
gases << gasChooseBtn;
|
2013-09-19 03:19:49 +00:00
|
|
|
drawProfile();
|
2013-08-26 17:17:39 +00:00
|
|
|
}
|
|
|
|
|
2013-07-04 14:28:39 +00:00
|
|
|
void DivePlannerGraphics::keyDownAction()
|
|
|
|
{
|
2013-10-11 13:21:04 +00:00
|
|
|
Q_FOREACH(QGraphicsItem *i, scene()->selectedItems()) {
|
|
|
|
if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler*>(i)) {
|
|
|
|
int row = handles.indexOf(handler);
|
|
|
|
divedatapoint dp = plannerModel->at(row);
|
|
|
|
if (dp.depth >= depthLine->maximum())
|
|
|
|
continue;
|
2013-07-04 14:28:39 +00:00
|
|
|
|
2013-10-11 13:21:04 +00:00
|
|
|
dp.depth += M_OR_FT(1,5);
|
|
|
|
plannerModel->editStop(row, dp);
|
2013-07-04 14:28:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerGraphics::keyUpAction()
|
|
|
|
{
|
2013-09-22 19:34:50 +00:00
|
|
|
Q_FOREACH(QGraphicsItem *i, scene()->selectedItems()) {
|
|
|
|
if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler*>(i)) {
|
2013-08-26 19:34:06 +00:00
|
|
|
int row = handles.indexOf(handler);
|
|
|
|
divedatapoint dp = plannerModel->at(row);
|
|
|
|
|
2013-09-22 19:37:49 +00:00
|
|
|
if (dp.depth <= 0)
|
2013-07-04 14:28:39 +00:00
|
|
|
continue;
|
|
|
|
|
2013-09-22 19:37:49 +00:00
|
|
|
dp.depth -= M_OR_FT(1,5);
|
2013-08-26 19:34:06 +00:00
|
|
|
plannerModel->editStop(row, dp);
|
2013-07-04 14:28:39 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-19 03:19:49 +00:00
|
|
|
drawProfile();
|
2013-07-04 14:28:39 +00:00
|
|
|
}
|
|
|
|
|
2013-07-04 15:30:05 +00:00
|
|
|
void DivePlannerGraphics::keyLeftAction()
|
|
|
|
{
|
2013-09-22 19:34:50 +00:00
|
|
|
Q_FOREACH(QGraphicsItem *i, scene()->selectedItems()) {
|
|
|
|
if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler*>(i)) {
|
2013-08-26 19:34:06 +00:00
|
|
|
int row = handles.indexOf(handler);
|
|
|
|
divedatapoint dp = plannerModel->at(row);
|
|
|
|
|
|
|
|
if (dp.time / 60 <= 0)
|
2013-07-04 15:30:05 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// don't overlap positions.
|
|
|
|
// maybe this is a good place for a 'goto'?
|
2013-08-26 19:34:06 +00:00
|
|
|
double xpos = timeLine->posAtValue((dp.time - 60) / 60);
|
2013-07-04 15:30:05 +00:00
|
|
|
bool nextStep = false;
|
2013-09-22 19:34:50 +00:00
|
|
|
Q_FOREACH(DiveHandler *h, handles) {
|
|
|
|
if (h->pos().x() == xpos) {
|
2013-07-04 15:30:05 +00:00
|
|
|
nextStep = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(nextStep)
|
|
|
|
continue;
|
|
|
|
|
2013-08-26 19:34:06 +00:00
|
|
|
dp.time -= 60;
|
|
|
|
plannerModel->editStop(row, dp);
|
2013-07-04 15:30:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerGraphics::keyRightAction()
|
|
|
|
{
|
2013-09-22 19:34:50 +00:00
|
|
|
Q_FOREACH(QGraphicsItem *i, scene()->selectedItems()) {
|
|
|
|
if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler*>(i)) {
|
2013-08-26 19:34:06 +00:00
|
|
|
int row = handles.indexOf(handler);
|
|
|
|
divedatapoint dp = plannerModel->at(row);
|
|
|
|
if (dp.time / 60 >= timeLine->maximum())
|
2013-07-04 15:30:05 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// don't overlap positions.
|
|
|
|
// maybe this is a good place for a 'goto'?
|
2013-08-26 19:34:06 +00:00
|
|
|
double xpos = timeLine->posAtValue((dp.time + 60) / 60);
|
2013-07-04 15:30:05 +00:00
|
|
|
bool nextStep = false;
|
2013-09-22 19:34:50 +00:00
|
|
|
Q_FOREACH(DiveHandler *h, handles) {
|
|
|
|
if (h->pos().x() == xpos) {
|
2013-07-04 15:30:05 +00:00
|
|
|
nextStep = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(nextStep)
|
|
|
|
continue;
|
|
|
|
|
2013-08-26 19:34:06 +00:00
|
|
|
dp.time += 60;
|
|
|
|
plannerModel->editStop(row, dp);
|
2013-07-04 15:30:05 +00:00
|
|
|
}
|
2013-08-30 19:43:10 +00:00
|
|
|
}
|
2013-07-04 15:30:05 +00:00
|
|
|
}
|
2013-07-04 14:28:39 +00:00
|
|
|
|
2013-07-04 14:16:42 +00:00
|
|
|
void DivePlannerGraphics::keyDeleteAction()
|
|
|
|
{
|
2013-07-21 15:12:31 +00:00
|
|
|
int selCount = scene()->selectedItems().count();
|
2013-09-22 19:34:50 +00:00
|
|
|
if(selCount) {
|
2013-08-30 18:53:10 +00:00
|
|
|
QVector<int> selectedIndexes;
|
2013-09-22 19:34:50 +00:00
|
|
|
Q_FOREACH(QGraphicsItem *i, scene()->selectedItems()) {
|
|
|
|
if (DiveHandler *handler = qgraphicsitem_cast<DiveHandler*>(i)) {
|
2013-08-30 18:53:10 +00:00
|
|
|
selectedIndexes.push_back(handles.indexOf(handler));
|
2013-07-04 14:16:42 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-30 18:53:10 +00:00
|
|
|
plannerModel->removeSelectedPoints(selectedIndexes);
|
2013-07-04 14:16:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-30 18:53:10 +00:00
|
|
|
void DivePlannerGraphics::pointsRemoved(const QModelIndex& , int start, int end)
|
|
|
|
{ // start and end are inclusive.
|
|
|
|
int num = (end - start) + 1;
|
2013-09-22 19:34:50 +00:00
|
|
|
for(int i = num; i != 0; i--) {
|
2013-08-30 18:53:10 +00:00
|
|
|
delete handles.back();
|
|
|
|
handles.pop_back();
|
2013-08-30 19:08:55 +00:00
|
|
|
delete gases.back();
|
|
|
|
gases.pop_back();
|
2013-08-30 18:53:10 +00:00
|
|
|
}
|
|
|
|
scene()->clearSelection();
|
2013-09-19 03:19:49 +00:00
|
|
|
drawProfile();
|
2013-08-30 18:53:10 +00:00
|
|
|
}
|
|
|
|
|
2013-09-22 19:34:50 +00:00
|
|
|
bool intLessThan(int a, int b) {
|
2013-08-30 18:53:10 +00:00
|
|
|
return a <= b;
|
|
|
|
}
|
|
|
|
void DivePlannerPointsModel::removeSelectedPoints(const QVector< int >& rows)
|
|
|
|
{
|
|
|
|
int firstRow = rowCount() - rows.count();
|
|
|
|
QVector<int> v2 = rows;
|
|
|
|
std::sort(v2.begin(), v2.end(), intLessThan);
|
|
|
|
beginRemoveRows(QModelIndex(), firstRow, rowCount()-1);
|
2013-09-22 19:34:50 +00:00
|
|
|
for(int i = v2.count()-1; i >= 0; i--) {
|
2013-08-30 18:53:10 +00:00
|
|
|
divepoints.remove(v2[i]);
|
|
|
|
}
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
2013-07-04 14:06:28 +00:00
|
|
|
void DivePlannerGraphics::keyEscAction()
|
|
|
|
{
|
2013-09-22 19:34:50 +00:00
|
|
|
if (scene()->selectedItems().count()) {
|
2013-07-04 14:06:28 +00:00
|
|
|
scene()->clearSelection();
|
|
|
|
return;
|
|
|
|
}
|
2013-09-22 15:45:14 +00:00
|
|
|
if (DivePlannerPointsModel::instance()->isPlanner())
|
|
|
|
plannerModel->cancelPlan();
|
2013-07-04 14:06:28 +00:00
|
|
|
}
|
|
|
|
|
2013-07-02 13:53:08 +00:00
|
|
|
qreal DivePlannerGraphics::fromPercent(qreal percent, Qt::Orientation orientation)
|
|
|
|
{
|
|
|
|
qreal total = orientation == Qt::Horizontal ? sceneRect().width() : sceneRect().height();
|
|
|
|
qreal result = (total * percent) / 100;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-06-21 19:51:13 +00:00
|
|
|
void DivePlannerGraphics::increaseDepth()
|
|
|
|
{
|
2013-09-22 19:37:49 +00:00
|
|
|
if (depthLine->maximum() + M_OR_FT(10,30) > MAX_DEPTH)
|
2013-07-02 17:14:09 +00:00
|
|
|
return;
|
2013-09-22 19:37:49 +00:00
|
|
|
depthLine->setMaximum( depthLine->maximum() + M_OR_FT(10,30));
|
2013-07-02 17:14:09 +00:00
|
|
|
depthLine->updateTicks();
|
2013-09-19 03:19:49 +00:00
|
|
|
drawProfile();
|
2013-06-21 19:51:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerGraphics::increaseTime()
|
|
|
|
{
|
2013-07-02 17:36:52 +00:00
|
|
|
minMinutes += 10;
|
|
|
|
timeLine->setMaximum( minMinutes );
|
|
|
|
timeLine->updateTicks();
|
2013-09-19 03:19:49 +00:00
|
|
|
drawProfile();
|
2013-06-20 15:33:26 +00:00
|
|
|
}
|
2013-06-20 15:37:41 +00:00
|
|
|
|
2013-07-21 12:27:04 +00:00
|
|
|
void DivePlannerGraphics::decreaseDepth()
|
|
|
|
{
|
2013-09-22 19:37:49 +00:00
|
|
|
if (depthLine->maximum() - M_OR_FT(10,30) < MIN_DEPTH)
|
2013-07-21 12:27:04 +00:00
|
|
|
return;
|
|
|
|
|
2013-09-22 19:37:49 +00:00
|
|
|
Q_FOREACH(DiveHandler *d, handles) {
|
|
|
|
if (depthLine->valueAt(d->pos()) > depthLine->maximum() - M_OR_FT(10,30)) {
|
2013-07-21 12:27:04 +00:00
|
|
|
QMessageBox::warning(mainWindow(),
|
|
|
|
tr("Handler Position Error"),
|
|
|
|
tr("One or more of your stops will be lost with this operations, \n"
|
|
|
|
"Please, remove them first."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-09-22 19:37:49 +00:00
|
|
|
depthLine->setMaximum(depthLine->maximum() - M_OR_FT(10,30));
|
2013-07-21 12:27:04 +00:00
|
|
|
depthLine->updateTicks();
|
2013-09-19 03:19:49 +00:00
|
|
|
drawProfile();
|
2013-07-21 12:27:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerGraphics::decreaseTime()
|
|
|
|
{
|
2013-10-11 13:21:04 +00:00
|
|
|
if (timeLine->maximum() - 10 < TIME_INITIAL_MAX || timeLine->maximum() - 10 < dpMaxTime)
|
2013-07-21 12:44:52 +00:00
|
|
|
return;
|
2013-10-11 13:21:04 +00:00
|
|
|
|
2013-07-21 12:44:52 +00:00
|
|
|
minMinutes -= 10;
|
2013-09-22 19:34:50 +00:00
|
|
|
timeLine->setMaximum(timeLine->maximum() - 10);
|
2013-07-21 12:44:52 +00:00
|
|
|
timeLine->updateTicks();
|
2013-09-19 03:19:49 +00:00
|
|
|
drawProfile();
|
2013-07-21 12:27:04 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 21:40:59 +00:00
|
|
|
void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
|
2013-06-20 15:37:41 +00:00
|
|
|
{
|
2013-06-20 16:56:28 +00:00
|
|
|
QPointF mappedPos = mapToScene(event->pos());
|
2013-06-23 20:09:29 +00:00
|
|
|
if (isPointOutOfBoundaries(mappedPos))
|
2013-06-20 16:56:28 +00:00
|
|
|
return;
|
|
|
|
|
2013-06-24 01:04:35 +00:00
|
|
|
int minutes = rint(timeLine->valueAt(mappedPos));
|
2013-09-22 19:37:49 +00:00
|
|
|
int milimeters = rint(depthLine->valueAt(mappedPos) / M_OR_FT(1,1)) * M_OR_FT(1,1);
|
2013-11-12 02:19:04 +00:00
|
|
|
plannerModel->addStop(milimeters, minutes * 60, -1, 0, 0);
|
2013-06-20 16:20:41 +00:00
|
|
|
}
|
|
|
|
|
2013-09-20 12:36:14 +00:00
|
|
|
void DivePlannerPointsModel::createSimpleDive()
|
|
|
|
{
|
2013-11-14 20:45:32 +00:00
|
|
|
// plannerModel->addStop(0, 0, O2_IN_AIR, 0, 0);
|
2013-11-08 09:15:04 +00:00
|
|
|
plannerModel->addStop(M_OR_FT(15,45), 1 * 60, O2_IN_AIR, 0, 0);
|
|
|
|
plannerModel->addStop(M_OR_FT(15,45), 40 * 60, O2_IN_AIR, 0, 0);
|
|
|
|
plannerModel->addStop(M_OR_FT(5,15), 42 * 60, O2_IN_AIR, 0, 0);
|
|
|
|
plannerModel->addStop(M_OR_FT(5,15), 45 * 60, O2_IN_AIR, 0, 0);
|
2013-09-20 12:36:14 +00:00
|
|
|
}
|
|
|
|
|
2013-11-01 15:48:34 +00:00
|
|
|
void DivePlannerPointsModel::loadFromDive(dive* d)
|
|
|
|
{
|
|
|
|
/* We need to make a copy, because
|
|
|
|
* as soon as the model is modified, it will
|
|
|
|
* remove all samples from the current dive.
|
|
|
|
* */
|
2013-11-18 19:55:56 +00:00
|
|
|
memcpy(&backupDive, current_dive, sizeof(struct dive));
|
|
|
|
copy_samples(current_dive, &backupDive);
|
|
|
|
copy_events(current_dive, &backupDive);
|
2013-11-14 09:36:21 +00:00
|
|
|
copy_cylinders(current_dive, stagingDive); // this way the correct cylinder data is shown
|
|
|
|
CylindersModel::instance()->setDive(stagingDive);
|
2013-11-13 13:39:05 +00:00
|
|
|
int lasttime = 0;
|
2013-11-18 19:55:56 +00:00
|
|
|
// we start with the first gas and see if it was changed
|
|
|
|
int o2 = backupDive.cylinder[0].gasmix.o2.permille;
|
|
|
|
int he = backupDive.cylinder[0].gasmix.he.permille;
|
|
|
|
for (int i = 0; i < backupDive.dc.samples; i++) {
|
|
|
|
const sample &s = backupDive.dc.sample[i];
|
2013-11-15 20:41:00 +00:00
|
|
|
if (s.time.seconds == 0)
|
|
|
|
continue;
|
2013-11-18 19:55:56 +00:00
|
|
|
get_gas_from_events(&backupDive.dc, lasttime, &o2, &he);
|
2013-11-08 09:15:04 +00:00
|
|
|
plannerModel->addStop(s.depth.mm, s.time.seconds, o2, he, 0);
|
2013-11-13 13:39:05 +00:00
|
|
|
lasttime = s.time.seconds;
|
2013-11-01 15:48:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-18 19:55:56 +00:00
|
|
|
void DivePlannerPointsModel::restoreBackupDive()
|
|
|
|
{
|
|
|
|
memcpy(current_dive, &backupDive, sizeof(struct dive));
|
|
|
|
}
|
|
|
|
|
2013-11-14 09:36:21 +00:00
|
|
|
void DivePlannerPointsModel::copyCylinders(dive *d)
|
|
|
|
{
|
|
|
|
copy_cylinders(stagingDive, d);
|
|
|
|
}
|
|
|
|
|
2013-11-11 08:09:19 +00:00
|
|
|
QStringList& DivePlannerPointsModel::getGasList()
|
|
|
|
{
|
|
|
|
static QStringList list;
|
|
|
|
list.clear();
|
|
|
|
if (!stagingDive) {
|
|
|
|
list.push_back(tr("AIR"));
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
cylinder_t *cyl = &stagingDive->cylinder[i];
|
|
|
|
if (cylinder_nodata(cyl))
|
|
|
|
break;
|
|
|
|
list.push_back(gasToStr(cyl->gasmix.o2.permille, cyl->gasmix.he.permille));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2013-07-21 16:54:21 +00:00
|
|
|
void DivePlannerGraphics::prepareSelectGas()
|
2013-07-21 15:56:21 +00:00
|
|
|
{
|
2013-07-21 16:54:21 +00:00
|
|
|
currentGasChoice = static_cast<Button*>(sender());
|
|
|
|
QPoint c = QCursor::pos();
|
|
|
|
gasListView->setGeometry(c.x(), c.y(), 150, 100);
|
|
|
|
gasListView->show();
|
2013-07-21 15:56:21 +00:00
|
|
|
}
|
|
|
|
|
2013-07-21 16:54:21 +00:00
|
|
|
void DivePlannerGraphics::selectGas(const QModelIndex& index)
|
|
|
|
{
|
|
|
|
QString gasSelected = gasListView->model()->data(index, Qt::DisplayRole).toString();
|
2013-08-30 18:06:26 +00:00
|
|
|
int idx = gases.indexOf(currentGasChoice);
|
|
|
|
plannerModel->setData(plannerModel->index(idx, DivePlannerPointsModel::GAS), gasSelected);
|
2013-07-21 16:54:21 +00:00
|
|
|
gasListView->hide();
|
|
|
|
}
|
|
|
|
|
2013-09-19 03:19:49 +00:00
|
|
|
void DivePlannerGraphics::drawProfile()
|
2013-06-20 16:20:41 +00:00
|
|
|
{
|
2013-06-26 23:41:39 +00:00
|
|
|
qDeleteAll(lines);
|
|
|
|
lines.clear();
|
|
|
|
|
2013-09-16 15:11:06 +00:00
|
|
|
plannerModel->createTemporaryPlan();
|
2013-09-09 10:18:22 +00:00
|
|
|
struct diveplan diveplan = plannerModel->getDiveplan();
|
2013-09-16 15:11:06 +00:00
|
|
|
struct divedatapoint *dp = diveplan.dp;
|
2013-11-08 09:15:04 +00:00
|
|
|
if (!dp) {
|
|
|
|
plannerModel->deleteTemporaryPlan();
|
|
|
|
return;
|
|
|
|
}
|
2013-09-22 19:34:50 +00:00
|
|
|
while(dp->next)
|
2013-06-24 04:27:52 +00:00
|
|
|
dp = dp->next;
|
2013-06-26 23:41:39 +00:00
|
|
|
|
2013-09-19 14:13:53 +00:00
|
|
|
if (!activeDraggedHandler && (timeLine->maximum() < dp->time / 60.0 + 5 || dp->time / 60.0 + 15 < timeLine->maximum())) {
|
2013-07-02 17:36:52 +00:00
|
|
|
double newMax = fmax(dp->time / 60.0 + 5, minMinutes);
|
2013-06-27 14:10:03 +00:00
|
|
|
timeLine->setMaximum(newMax);
|
2013-06-26 22:14:55 +00:00
|
|
|
timeLine->updateTicks();
|
2013-06-27 14:10:03 +00:00
|
|
|
}
|
2013-06-26 22:14:55 +00:00
|
|
|
|
2013-06-20 21:25:03 +00:00
|
|
|
// Re-position the user generated dive handlers
|
2013-11-12 02:19:04 +00:00
|
|
|
int last = 0;
|
2013-11-14 20:45:32 +00:00
|
|
|
for (int i = 0; i < plannerModel->rowCount(); i++) {
|
2013-08-26 19:34:06 +00:00
|
|
|
divedatapoint dp = plannerModel->at(i);
|
2013-11-12 02:19:04 +00:00
|
|
|
if (dp.time == 0) // those are the magic entries for tanks
|
|
|
|
continue;
|
2013-08-26 19:34:06 +00:00
|
|
|
DiveHandler *h = handles.at(i);
|
2013-09-22 19:37:49 +00:00
|
|
|
h->setPos(timeLine->posAtValue(dp.time / 60), depthLine->posAtValue(dp.depth));
|
2013-11-12 02:19:04 +00:00
|
|
|
QPointF p1 = handles[last]->pos();
|
2013-07-21 15:12:31 +00:00
|
|
|
QPointF p2 = handles[i]->pos();
|
|
|
|
QLineF line(p1, p2);
|
|
|
|
QPointF pos = line.pointAt(0.5);
|
|
|
|
gases[i]->setPos(pos);
|
2013-11-12 02:19:04 +00:00
|
|
|
gases[i]->setText(dpGasToStr(plannerModel->at(i)));
|
|
|
|
last = i;
|
2013-07-21 15:12:31 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 12:54:17 +00:00
|
|
|
// (re-) create the profile with different colors for segments that were
|
|
|
|
// entered vs. segments that were calculated
|
|
|
|
double lastx = timeLine->posAtValue(0);
|
|
|
|
double lasty = depthLine->posAtValue(0);
|
2013-06-27 22:52:58 +00:00
|
|
|
|
|
|
|
QPolygonF poly;
|
|
|
|
poly.append(QPointF(lastx, lasty));
|
2013-09-16 15:11:06 +00:00
|
|
|
|
2013-06-24 04:27:52 +00:00
|
|
|
for (dp = diveplan.dp; dp != NULL; dp = dp->next) {
|
2013-11-12 02:19:04 +00:00
|
|
|
if (dp->time == 0) // magic entry for available tank
|
|
|
|
continue;
|
2013-06-27 08:56:46 +00:00
|
|
|
double xpos = timeLine->posAtValue(dp->time / 60.0);
|
2013-09-22 19:37:49 +00:00
|
|
|
double ypos = depthLine->posAtValue(dp->depth);
|
2013-09-22 19:34:50 +00:00
|
|
|
if (!dp->entered) {
|
2013-07-02 16:39:54 +00:00
|
|
|
QGraphicsLineItem *item = new QGraphicsLineItem(lastx, lasty, xpos, ypos);
|
|
|
|
item->setPen(QPen(QBrush(Qt::red),0));
|
|
|
|
scene()->addItem(item);
|
|
|
|
lines << item;
|
|
|
|
}
|
2013-06-27 08:56:46 +00:00
|
|
|
lastx = xpos;
|
|
|
|
lasty = ypos;
|
2013-06-27 22:52:58 +00:00
|
|
|
poly.append(QPointF(lastx, lasty));
|
2013-06-24 04:27:52 +00:00
|
|
|
}
|
2013-06-27 20:31:10 +00:00
|
|
|
|
2013-06-27 22:52:58 +00:00
|
|
|
diveBg->setPolygon(poly);
|
|
|
|
QRectF b = poly.boundingRect();
|
2013-07-02 14:21:28 +00:00
|
|
|
QLinearGradient pat(
|
2013-06-27 22:52:58 +00:00
|
|
|
b.x(),
|
|
|
|
b.y(),
|
|
|
|
b.x(),
|
|
|
|
b.height() + b.y()
|
|
|
|
);
|
|
|
|
|
2013-07-02 14:21:28 +00:00
|
|
|
pat.setColorAt(1, profile_color[DEPTH_BOTTOM].first());
|
|
|
|
pat.setColorAt(0, profile_color[DEPTH_TOP].first());
|
|
|
|
diveBg->setBrush(pat);
|
2013-06-27 22:52:58 +00:00
|
|
|
|
2013-09-16 15:11:06 +00:00
|
|
|
plannerModel->deleteTemporaryPlan();
|
2013-06-20 15:37:41 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 21:40:59 +00:00
|
|
|
void DivePlannerGraphics::resizeEvent(QResizeEvent* event)
|
2013-06-20 16:28:04 +00:00
|
|
|
{
|
2013-06-23 20:09:29 +00:00
|
|
|
QGraphicsView::resizeEvent(event);
|
2013-06-27 17:48:03 +00:00
|
|
|
fitInView(sceneRect(), Qt::IgnoreAspectRatio);
|
2013-06-20 16:28:04 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 21:40:59 +00:00
|
|
|
void DivePlannerGraphics::showEvent(QShowEvent* event)
|
2013-06-20 16:28:04 +00:00
|
|
|
{
|
2013-06-23 20:09:29 +00:00
|
|
|
QGraphicsView::showEvent(event);
|
2013-06-27 17:48:03 +00:00
|
|
|
fitInView(sceneRect(), Qt::IgnoreAspectRatio);
|
2013-06-20 16:28:04 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 21:40:59 +00:00
|
|
|
void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event)
|
2013-06-20 16:53:12 +00:00
|
|
|
{
|
|
|
|
QPointF mappedPos = mapToScene(event->pos());
|
2013-06-20 16:56:28 +00:00
|
|
|
if (isPointOutOfBoundaries(mappedPos))
|
2013-06-20 16:53:12 +00:00
|
|
|
return;
|
2013-06-20 17:20:45 +00:00
|
|
|
|
2013-07-02 14:12:15 +00:00
|
|
|
verticalLine->setPos(mappedPos.x(), fromPercent(0, Qt::Vertical));
|
|
|
|
horizontalLine->setPos(fromPercent(0, Qt::Horizontal), mappedPos.y());
|
|
|
|
|
2013-09-22 19:37:49 +00:00
|
|
|
depthString->setText(get_depth_string(depthLine->valueAt(mappedPos), true, false));
|
2013-11-09 11:09:59 +00:00
|
|
|
depthString->setPos(fromPercent(1, Qt::Horizontal), mappedPos.y());
|
2013-06-24 00:32:23 +00:00
|
|
|
timeString->setText(QString::number(rint(timeLine->valueAt(mappedPos))) + "min");
|
2013-07-02 14:12:15 +00:00
|
|
|
timeString->setPos(mappedPos.x()+1, fromPercent(95, Qt::Vertical));
|
2013-06-20 17:20:45 +00:00
|
|
|
|
2013-07-02 16:31:25 +00:00
|
|
|
// calculate the correct color for the depthString.
|
|
|
|
// QGradient doesn't returns it's interpolation, meh.
|
|
|
|
double percent = depthLine->percentAt(mappedPos);
|
|
|
|
QColor& startColor = profile_color[SAMPLE_SHALLOW].first();
|
|
|
|
QColor& endColor = profile_color[SAMPLE_DEEP].first();
|
|
|
|
short redDelta = (endColor.red() - startColor.red()) * percent + startColor.red();
|
|
|
|
short greenDelta = (endColor.green() - startColor.green()) * percent + startColor.green();
|
|
|
|
short blueDelta = (endColor.blue() - startColor.blue()) * percent + startColor.blue();
|
|
|
|
depthString->setBrush( QColor(redDelta, greenDelta, blueDelta));
|
|
|
|
|
2013-06-23 20:09:29 +00:00
|
|
|
if (activeDraggedHandler)
|
2013-09-19 14:13:53 +00:00
|
|
|
moveActiveHandler(mappedPos, handles.indexOf(activeDraggedHandler));
|
2013-06-20 17:20:45 +00:00
|
|
|
if (!handles.count())
|
|
|
|
return;
|
|
|
|
|
2013-06-23 20:09:29 +00:00
|
|
|
if (handles.last()->x() > mappedPos.x()) {
|
|
|
|
verticalLine->setPen(QPen(QBrush(Qt::red), 0, Qt::SolidLine));
|
|
|
|
horizontalLine->setPen(QPen(QBrush(Qt::red), 0, Qt::SolidLine));
|
|
|
|
} else {
|
2013-06-20 17:20:45 +00:00
|
|
|
verticalLine->setPen(QPen(Qt::DotLine));
|
|
|
|
horizontalLine->setPen(QPen(Qt::DotLine));
|
|
|
|
}
|
2013-06-20 16:53:12 +00:00
|
|
|
}
|
2013-06-20 16:56:28 +00:00
|
|
|
|
2013-09-19 14:13:53 +00:00
|
|
|
void DivePlannerGraphics::moveActiveHandler(const QPointF& mappedPos, const int pos)
|
2013-06-20 18:15:10 +00:00
|
|
|
{
|
2013-09-19 14:13:53 +00:00
|
|
|
divedatapoint data = plannerModel->at(pos);
|
2013-09-22 18:01:18 +00:00
|
|
|
int mintime = 0, maxtime = (timeLine->maximum() + 10) * 60;
|
|
|
|
if (pos > 0)
|
|
|
|
mintime = plannerModel->at(pos - 1).time;
|
|
|
|
if (pos < plannerModel->size() - 1)
|
|
|
|
maxtime = plannerModel->at(pos + 1).time;
|
|
|
|
|
2013-09-19 14:13:53 +00:00
|
|
|
int minutes = rint(timeLine->valueAt(mappedPos));
|
2013-09-22 18:01:18 +00:00
|
|
|
if (minutes * 60 <= mintime || minutes * 60 >= maxtime)
|
|
|
|
return;
|
|
|
|
|
2013-09-22 19:37:49 +00:00
|
|
|
int milimeters = rint(depthLine->valueAt(mappedPos) / M_OR_FT(1,1)) * M_OR_FT(1,1);
|
2013-09-19 14:13:53 +00:00
|
|
|
double xpos = timeLine->posAtValue(minutes);
|
2013-09-22 19:37:49 +00:00
|
|
|
double ypos = depthLine->posAtValue(milimeters);
|
2013-09-19 14:13:53 +00:00
|
|
|
|
2013-09-22 19:37:49 +00:00
|
|
|
data.depth = milimeters;
|
2013-09-19 14:13:53 +00:00
|
|
|
data.time = rint(timeLine->valueAt(mappedPos)) * 60;
|
|
|
|
|
|
|
|
plannerModel->editStop(pos, data);
|
|
|
|
|
2013-07-04 13:29:28 +00:00
|
|
|
activeDraggedHandler->setPos(QPointF(xpos, ypos));
|
2013-06-27 08:56:46 +00:00
|
|
|
qDeleteAll(lines);
|
2013-06-26 23:41:39 +00:00
|
|
|
lines.clear();
|
2013-09-20 04:02:50 +00:00
|
|
|
drawProfile();
|
2013-06-20 18:15:10 +00:00
|
|
|
}
|
|
|
|
|
2013-06-21 19:28:17 +00:00
|
|
|
bool DivePlannerGraphics::isPointOutOfBoundaries(const QPointF& point)
|
2013-06-20 16:56:28 +00:00
|
|
|
{
|
2013-06-21 19:07:44 +00:00
|
|
|
double xpos = timeLine->valueAt(point);
|
|
|
|
double ypos = depthLine->valueAt(point);
|
|
|
|
|
2013-06-23 20:09:29 +00:00
|
|
|
if (xpos > timeLine->maximum() ||
|
|
|
|
xpos < timeLine->minimum() ||
|
|
|
|
ypos > depthLine->maximum() ||
|
|
|
|
ypos < depthLine->minimum())
|
2013-06-20 16:56:28 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-20 17:29:32 +00:00
|
|
|
|
2013-06-20 21:40:59 +00:00
|
|
|
void DivePlannerGraphics::mousePressEvent(QMouseEvent* event)
|
2013-06-20 17:46:40 +00:00
|
|
|
{
|
2013-09-22 19:34:50 +00:00
|
|
|
if (event->modifiers()) {
|
2013-07-04 14:01:59 +00:00
|
|
|
QGraphicsView::mousePressEvent(event);
|
2013-07-04 15:30:05 +00:00
|
|
|
return;
|
2013-07-04 14:01:59 +00:00
|
|
|
}
|
|
|
|
|
2013-09-22 15:45:14 +00:00
|
|
|
QPointF mappedPos = mapToScene(event->pos());
|
2013-11-15 01:29:36 +00:00
|
|
|
if (event->button() == Qt::LeftButton){
|
|
|
|
Q_FOREACH(QGraphicsItem *item, scene()->items(mappedPos, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, transform())) {
|
|
|
|
if (DiveHandler *h = qgraphicsitem_cast<DiveHandler*>(item)) {
|
|
|
|
activeDraggedHandler = h;
|
|
|
|
activeDraggedHandler->setBrush(Qt::red);
|
|
|
|
originalHandlerPos = activeDraggedHandler->pos();
|
|
|
|
}
|
2013-06-20 17:46:40 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-04 15:30:05 +00:00
|
|
|
QGraphicsView::mousePressEvent(event);
|
2013-06-20 17:46:40 +00:00
|
|
|
}
|
2013-06-20 17:29:32 +00:00
|
|
|
|
2013-06-20 21:40:59 +00:00
|
|
|
void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event)
|
2013-06-20 17:46:40 +00:00
|
|
|
{
|
2013-06-23 20:09:29 +00:00
|
|
|
if (activeDraggedHandler) {
|
2013-09-22 18:01:18 +00:00
|
|
|
/* we already deal with all the positioning in the life update,
|
|
|
|
* so all we need to do here is change the color of the handler */
|
2013-06-27 22:52:58 +00:00
|
|
|
activeDraggedHandler->setBrush(QBrush(Qt::white));
|
2013-06-20 17:46:40 +00:00
|
|
|
activeDraggedHandler = 0;
|
2013-09-20 04:02:50 +00:00
|
|
|
drawProfile();
|
2013-06-20 20:34:42 +00:00
|
|
|
}
|
2013-06-20 17:46:40 +00:00
|
|
|
}
|
2013-06-20 17:29:32 +00:00
|
|
|
|
2013-07-21 13:03:04 +00:00
|
|
|
DiveHandler::DiveHandler(): QGraphicsEllipseItem()
|
2013-06-20 17:29:32 +00:00
|
|
|
{
|
2013-07-04 13:06:52 +00:00
|
|
|
setRect(-5,-5,10,10);
|
|
|
|
setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
2013-07-04 14:01:59 +00:00
|
|
|
setFlag(QGraphicsItem::ItemIsSelectable);
|
2013-06-27 22:52:58 +00:00
|
|
|
setBrush(Qt::white);
|
|
|
|
setZValue(2);
|
2013-06-20 17:29:32 +00:00
|
|
|
}
|
2013-07-04 14:01:59 +00:00
|
|
|
|
2013-11-15 01:29:36 +00:00
|
|
|
void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
|
|
|
{
|
|
|
|
QMenu m;
|
|
|
|
m.addAction(QObject::tr("Remove this Point"), this, SLOT(selfRemove()));
|
|
|
|
m.exec(event->screenPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiveHandler::selfRemove()
|
|
|
|
{
|
|
|
|
setSelected(true);
|
|
|
|
DivePlannerGraphics *view = qobject_cast<DivePlannerGraphics*>(scene()->views().first());
|
|
|
|
view->keyDeleteAction();
|
|
|
|
}
|
|
|
|
|
2013-07-04 14:01:59 +00:00
|
|
|
void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
|
|
|
{
|
2013-11-15 01:29:36 +00:00
|
|
|
if (event->button() != Qt::LeftButton)
|
|
|
|
return;
|
|
|
|
|
2013-09-22 19:34:50 +00:00
|
|
|
if (event->modifiers().testFlag(Qt::ControlModifier)) {
|
2013-07-04 14:01:59 +00:00
|
|
|
setSelected(true);
|
|
|
|
}
|
2013-07-04 14:06:28 +00:00
|
|
|
// mousePressEvent 'grabs' the mouse and keyboard, annoying.
|
2013-07-04 14:01:59 +00:00
|
|
|
ungrabMouse();
|
2013-08-30 18:53:10 +00:00
|
|
|
|
|
|
|
/* hack. Sometimes the keyboard is grabbed, sometime it's not,
|
|
|
|
so, let's force a grab and release, to get rid of a warning. */
|
|
|
|
grabKeyboard();
|
2013-07-04 14:01:59 +00:00
|
|
|
ungrabKeyboard();
|
|
|
|
}
|
2013-06-20 18:52:27 +00:00
|
|
|
|
|
|
|
void Ruler::setMaximum(double maximum)
|
|
|
|
{
|
|
|
|
max = maximum;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Ruler::setMinimum(double minimum)
|
|
|
|
{
|
|
|
|
min = minimum;
|
|
|
|
}
|
|
|
|
|
2013-09-16 23:10:12 +00:00
|
|
|
void Ruler::setTextColor(const QColor& color)
|
|
|
|
{
|
|
|
|
textColor = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ruler::Ruler() : orientation(Qt::Horizontal)
|
2013-06-20 18:52:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Ruler::setOrientation(Qt::Orientation o)
|
|
|
|
{
|
|
|
|
orientation = o;
|
2013-09-16 14:09:54 +00:00
|
|
|
// position the elements on the screen.
|
|
|
|
setMinimum(minimum());
|
|
|
|
setMaximum(maximum());
|
2013-06-20 18:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Ruler::updateTicks()
|
|
|
|
{
|
2013-06-20 19:48:24 +00:00
|
|
|
qDeleteAll(ticks);
|
2013-06-23 20:21:01 +00:00
|
|
|
ticks.clear();
|
2013-09-16 23:10:12 +00:00
|
|
|
qDeleteAll(labels);
|
|
|
|
labels.clear();
|
|
|
|
|
2013-06-20 19:48:24 +00:00
|
|
|
QLineF m = line();
|
2013-07-02 15:01:47 +00:00
|
|
|
QGraphicsLineItem *item = NULL;
|
2013-09-16 23:10:12 +00:00
|
|
|
QGraphicsSimpleTextItem *label = NULL;
|
|
|
|
|
|
|
|
double steps = (max - min) / interval;
|
|
|
|
qreal pos;
|
|
|
|
double currValue = min;
|
2013-07-02 15:01:47 +00:00
|
|
|
|
2013-06-23 20:09:29 +00:00
|
|
|
if (orientation == Qt::Horizontal) {
|
2013-06-20 19:48:24 +00:00
|
|
|
double stepSize = (m.x2() - m.x1()) / steps;
|
2013-09-16 23:10:12 +00:00
|
|
|
for (pos = m.x1(); pos < m.x2(); pos += stepSize, currValue += interval) {
|
2013-07-02 15:01:47 +00:00
|
|
|
item = new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this);
|
|
|
|
item->setPen(pen());
|
|
|
|
ticks.push_back(item);
|
2013-09-16 23:10:12 +00:00
|
|
|
|
|
|
|
label = new QGraphicsSimpleTextItem(QString::number(currValue), this);
|
|
|
|
label->setBrush(QBrush(textColor));
|
|
|
|
label->setFlag(ItemIgnoresTransformations);
|
|
|
|
label->setPos(pos - label->boundingRect().width()/2, m.y1() + tickSize + 5);
|
|
|
|
labels.push_back(label);
|
2013-06-20 19:48:24 +00:00
|
|
|
}
|
2013-07-02 15:01:47 +00:00
|
|
|
item = new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this);
|
|
|
|
item->setPen(pen());
|
|
|
|
ticks.push_back(item);
|
2013-09-16 23:10:12 +00:00
|
|
|
|
|
|
|
label = new QGraphicsSimpleTextItem(QString::number(currValue), this);
|
|
|
|
label->setBrush(QBrush(textColor));
|
|
|
|
label->setFlag(ItemIgnoresTransformations);
|
|
|
|
label->setPos(pos - label->boundingRect().width()/2, m.y1() + tickSize + 5);
|
|
|
|
labels.push_back(label);
|
2013-06-23 20:09:29 +00:00
|
|
|
} else {
|
2013-06-20 19:48:24 +00:00
|
|
|
double stepSize = (m.y2() - m.y1()) / steps;
|
2013-09-16 23:10:12 +00:00
|
|
|
for (pos = m.y1(); pos < m.y2(); pos += stepSize, currValue += interval) {
|
2013-07-02 15:01:47 +00:00
|
|
|
item = new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this);
|
|
|
|
item->setPen(pen());
|
|
|
|
ticks.push_back(item);
|
2013-09-16 23:10:12 +00:00
|
|
|
|
2013-09-22 19:37:49 +00:00
|
|
|
label = new QGraphicsSimpleTextItem(get_depth_string(currValue, false, false), this);
|
2013-09-16 23:10:12 +00:00
|
|
|
label->setBrush(QBrush(textColor));
|
|
|
|
label->setFlag(ItemIgnoresTransformations);
|
|
|
|
label->setPos(m.x2() - 80, pos);
|
|
|
|
labels.push_back(label);
|
2013-06-20 19:48:24 +00:00
|
|
|
}
|
2013-07-02 15:01:47 +00:00
|
|
|
item = new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this);
|
|
|
|
item->setPen(pen());
|
|
|
|
ticks.push_back(item);
|
2013-09-16 23:10:12 +00:00
|
|
|
|
2013-09-22 19:37:49 +00:00
|
|
|
label = new QGraphicsSimpleTextItem(get_depth_string(currValue, false, false), this);
|
2013-09-16 23:10:12 +00:00
|
|
|
label->setBrush(QBrush(textColor));
|
|
|
|
label->setFlag(ItemIgnoresTransformations);
|
|
|
|
label->setPos(m.x2() - 80, pos);
|
|
|
|
labels.push_back(label);
|
2013-06-20 19:48:24 +00:00
|
|
|
}
|
2013-06-20 18:52:27 +00:00
|
|
|
}
|
|
|
|
|
2013-07-02 14:12:15 +00:00
|
|
|
void Ruler::setTickSize(qreal size)
|
|
|
|
{
|
|
|
|
tickSize = size;
|
|
|
|
}
|
|
|
|
|
2013-06-20 19:48:24 +00:00
|
|
|
void Ruler::setTickInterval(double i)
|
2013-06-20 18:52:27 +00:00
|
|
|
{
|
2013-06-20 19:48:24 +00:00
|
|
|
interval = i;
|
2013-06-20 18:52:27 +00:00
|
|
|
}
|
2013-06-20 20:34:42 +00:00
|
|
|
|
|
|
|
qreal Ruler::valueAt(const QPointF& p)
|
|
|
|
{
|
|
|
|
QLineF m = line();
|
2013-06-23 20:09:29 +00:00
|
|
|
double retValue = orientation == Qt::Horizontal ?
|
|
|
|
max * (p.x() - m.x1()) / (m.x2() - m.x1()) :
|
|
|
|
max * (p.y() - m.y1()) / (m.y2() - m.y1());
|
2013-06-21 18:53:20 +00:00
|
|
|
return retValue;
|
2013-06-20 20:34:42 +00:00
|
|
|
}
|
2013-06-20 21:25:03 +00:00
|
|
|
|
|
|
|
qreal Ruler::posAtValue(qreal value)
|
|
|
|
{
|
|
|
|
QLineF m = line();
|
2013-06-21 18:53:20 +00:00
|
|
|
double size = max - min;
|
|
|
|
double percent = value / size;
|
2013-06-23 20:09:29 +00:00
|
|
|
double realSize = orientation == Qt::Horizontal ?
|
|
|
|
m.x2() - m.x1() :
|
|
|
|
m.y2() - m.y1();
|
2013-06-21 18:53:20 +00:00
|
|
|
double retValue = realSize * percent;
|
2013-06-23 20:09:29 +00:00
|
|
|
retValue = (orientation == Qt::Horizontal) ?
|
|
|
|
retValue + m.x1() :
|
|
|
|
retValue + m.y1();
|
2013-06-21 18:53:20 +00:00
|
|
|
return retValue;
|
2013-06-20 21:40:59 +00:00
|
|
|
}
|
|
|
|
|
2013-07-02 16:31:25 +00:00
|
|
|
qreal Ruler::percentAt(const QPointF& p)
|
|
|
|
{
|
|
|
|
qreal value = valueAt(p);
|
|
|
|
double size = max - min;
|
|
|
|
double percent = value / size;
|
|
|
|
return percent;
|
|
|
|
}
|
|
|
|
|
2013-06-21 19:07:44 +00:00
|
|
|
double Ruler::maximum() const
|
|
|
|
{
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Ruler::minimum() const
|
|
|
|
{
|
|
|
|
return min;
|
|
|
|
}
|
|
|
|
|
2013-07-02 15:01:47 +00:00
|
|
|
void Ruler::setColor(const QColor& color)
|
|
|
|
{
|
2013-09-16 22:21:13 +00:00
|
|
|
QPen defaultPen(color);
|
|
|
|
defaultPen.setJoinStyle(Qt::RoundJoin);
|
|
|
|
defaultPen.setCapStyle(Qt::RoundCap);
|
|
|
|
defaultPen.setWidth(2);
|
|
|
|
defaultPen.setCosmetic(true);
|
|
|
|
setPen(defaultPen);
|
2013-07-02 15:01:47 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 23:20:07 +00:00
|
|
|
Button::Button(QObject* parent, QGraphicsItem *itemParent): QObject(parent), QGraphicsRectItem(itemParent)
|
2013-06-21 19:44:38 +00:00
|
|
|
{
|
2013-08-26 17:17:39 +00:00
|
|
|
icon = new QGraphicsPixmapItem(this);
|
2013-06-27 19:45:58 +00:00
|
|
|
text = new QGraphicsSimpleTextItem(this);
|
|
|
|
icon->setPos(0,0);
|
|
|
|
text->setPos(0,0);
|
2013-06-21 19:44:38 +00:00
|
|
|
setFlag(ItemIgnoresTransformations);
|
2013-07-02 17:14:09 +00:00
|
|
|
setPen(QPen(QBrush(), 0));
|
2013-06-27 19:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Button::setPixmap(const QPixmap& pixmap)
|
|
|
|
{
|
2013-11-17 23:20:07 +00:00
|
|
|
icon->setPixmap(pixmap);
|
2013-09-22 19:34:50 +00:00
|
|
|
if(pixmap.isNull())
|
2013-06-27 19:45:58 +00:00
|
|
|
icon->hide();
|
2013-09-22 19:34:50 +00:00
|
|
|
else
|
2013-06-27 19:45:58 +00:00
|
|
|
icon->show();
|
2013-09-22 19:34:50 +00:00
|
|
|
|
2013-06-27 19:45:58 +00:00
|
|
|
setRect(childrenBoundingRect());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::setText(const QString& t)
|
|
|
|
{
|
|
|
|
text->setText(t);
|
2013-09-22 19:34:50 +00:00
|
|
|
if(icon->pixmap().isNull()) {
|
2013-06-27 19:45:58 +00:00
|
|
|
icon->hide();
|
|
|
|
text->setPos(0,0);
|
2013-09-22 19:34:50 +00:00
|
|
|
} else {
|
2013-06-27 19:45:58 +00:00
|
|
|
icon->show();
|
|
|
|
text->setPos(22,0);
|
|
|
|
}
|
|
|
|
setRect(childrenBoundingRect());
|
2013-06-21 19:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Button::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
|
|
|
{
|
2013-07-02 17:36:52 +00:00
|
|
|
event->ignore();
|
2013-06-21 19:44:38 +00:00
|
|
|
emit clicked();
|
|
|
|
}
|
2013-08-26 11:43:37 +00:00
|
|
|
|
2013-10-03 18:54:25 +00:00
|
|
|
DivePlannerWidget::DivePlannerWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f)
|
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
|
|
|
ui.tableWidget->setTitle(tr("Dive Planner Points"));
|
|
|
|
ui.tableWidget->setModel(DivePlannerPointsModel::instance());
|
|
|
|
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
|
2013-11-09 22:06:26 +00:00
|
|
|
ui.cylinderTableWidget->setTitle(tr("Available Gases"));
|
|
|
|
ui.cylinderTableWidget->setModel(CylindersModel::instance());
|
2013-11-12 19:57:33 +00:00
|
|
|
QTableView *view = ui.cylinderTableWidget->view();
|
|
|
|
view->setColumnHidden(CylindersModel::START, true);
|
|
|
|
view->setColumnHidden(CylindersModel::END, true);
|
|
|
|
view->setColumnHidden(CylindersModel::DEPTH, false);
|
|
|
|
view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate());
|
2013-11-10 12:02:53 +00:00
|
|
|
connect(ui.cylinderTableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addCylinder_clicked()));
|
2013-10-03 18:54:25 +00:00
|
|
|
connect(ui.tableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addStop()));
|
2013-11-14 19:39:35 +00:00
|
|
|
|
|
|
|
connect(CylindersModel::instance(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
|
|
GasSelectionModel::instance(), SLOT(repopulate()));
|
|
|
|
connect(CylindersModel::instance(), SIGNAL(rowsInserted(QModelIndex,int,int)),
|
|
|
|
GasSelectionModel::instance(), SLOT(repopulate()));
|
|
|
|
connect(CylindersModel::instance(), SIGNAL(rowsRemoved(QModelIndex,int,int)),
|
|
|
|
GasSelectionModel::instance(), SLOT(repopulate()));
|
|
|
|
|
2013-11-10 12:02:53 +00:00
|
|
|
ui.tableWidget->setBtnToolTip(tr("add dive data point"));
|
2013-11-14 18:55:35 +00:00
|
|
|
connect(ui.startTime, SIGNAL(timeChanged(QTime)), plannerModel, SLOT(setStartTime(QTime)));
|
2013-10-03 18:54:25 +00:00
|
|
|
connect(ui.ATMPressure, SIGNAL(textChanged(QString)), this, SLOT(atmPressureChanged(QString)));
|
|
|
|
connect(ui.bottomSAC, SIGNAL(textChanged(QString)), this, SLOT(bottomSacChanged(QString)));
|
|
|
|
connect(ui.decoStopSAC, SIGNAL(textChanged(QString)), this, SLOT(decoSacChanged(QString)));
|
2013-11-14 18:55:33 +00:00
|
|
|
connect(ui.gfhigh, SIGNAL(valueChanged(int)), plannerModel, SLOT(setGFHigh(int)));
|
|
|
|
connect(ui.gflow, SIGNAL(valueChanged(int)), plannerModel, SLOT(setGFLow(int)));
|
2013-11-14 18:55:35 +00:00
|
|
|
connect(ui.lastStop, SIGNAL(toggled(bool)), plannerModel, SLOT(setLastStop6m(bool)));
|
2013-09-09 10:18:22 +00:00
|
|
|
|
2013-09-16 14:38:41 +00:00
|
|
|
// Creating the plan
|
2013-10-03 18:54:25 +00:00
|
|
|
connect(ui.buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan()));
|
|
|
|
connect(ui.buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan()));
|
2013-09-16 14:38:41 +00:00
|
|
|
connect(plannerModel, SIGNAL(planCreated()), mainWindow(), SLOT(showProfile()));
|
2013-09-16 15:30:58 +00:00
|
|
|
connect(plannerModel, SIGNAL(planCreated()), mainWindow(), SLOT(refreshDisplay()));
|
2013-09-16 14:38:41 +00:00
|
|
|
connect(plannerModel, SIGNAL(planCanceled()), mainWindow(), SLOT(showProfile()));
|
|
|
|
|
2013-09-09 10:18:22 +00:00
|
|
|
/* set defaults. */
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.startTime->setTime( QTime(1, 0) );
|
|
|
|
ui.ATMPressure->setText( "1013" );
|
|
|
|
ui.bottomSAC->setText("20");
|
|
|
|
ui.decoStopSAC->setText("17");
|
2013-11-14 18:55:34 +00:00
|
|
|
ui.gflow->setValue(prefs.gflow);
|
|
|
|
ui.gfhigh->setValue(prefs.gfhigh);
|
2013-09-26 21:14:09 +00:00
|
|
|
|
|
|
|
setMinimumWidth(0);
|
|
|
|
setMinimumHeight(0);
|
2013-08-28 10:48:46 +00:00
|
|
|
}
|
|
|
|
|
2013-11-10 12:02:53 +00:00
|
|
|
void DivePlannerPointsModel::addCylinder_clicked()
|
|
|
|
{
|
|
|
|
CylindersModel::instance()->add();
|
|
|
|
}
|
|
|
|
|
2013-08-26 16:18:21 +00:00
|
|
|
void DivePlannerWidget::atmPressureChanged(const QString& pressure)
|
|
|
|
{
|
2013-08-26 19:34:06 +00:00
|
|
|
plannerModel->setSurfacePressure(pressure.toInt());
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerWidget::bottomSacChanged(const QString& bottomSac)
|
|
|
|
{
|
2013-08-26 19:34:06 +00:00
|
|
|
plannerModel->setBottomSac(bottomSac.toInt());
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerWidget::decoSacChanged(const QString& decosac)
|
|
|
|
{
|
2013-08-26 19:34:06 +00:00
|
|
|
plannerModel->setDecoSac(decosac.toInt());
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
2013-11-09 00:09:46 +00:00
|
|
|
void DivePlannerPointsModel::setPlanMode(Mode m)
|
2013-09-19 02:33:53 +00:00
|
|
|
{
|
2013-11-09 00:09:46 +00:00
|
|
|
mode = m;
|
2013-09-19 02:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DivePlannerPointsModel::isPlanner()
|
|
|
|
{
|
|
|
|
return mode == PLAN;
|
|
|
|
}
|
|
|
|
|
2013-08-26 12:14:19 +00:00
|
|
|
int DivePlannerPointsModel::columnCount(const QModelIndex& parent) const
|
|
|
|
{
|
|
|
|
return COLUMNS;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant DivePlannerPointsModel::data(const QModelIndex& index, int role) const
|
|
|
|
{
|
2013-09-22 19:34:50 +00:00
|
|
|
if(role == Qt::DisplayRole) {
|
2013-08-26 16:18:21 +00:00
|
|
|
divedatapoint p = divepoints.at(index.row());
|
2013-09-22 19:34:50 +00:00
|
|
|
switch(index.column()) {
|
2013-11-08 12:22:59 +00:00
|
|
|
case CCSETPOINT: return p.po2;
|
|
|
|
case DEPTH: return rint(get_depth_units(p.depth, NULL, NULL));
|
|
|
|
case DURATION: return p.time / 60;
|
2013-11-12 02:19:04 +00:00
|
|
|
case GAS: return dpGasToStr(p);
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
2013-09-22 19:34:50 +00:00
|
|
|
} else if (role == Qt::DecorationRole) {
|
|
|
|
switch(index.column()) {
|
2013-08-28 10:27:59 +00:00
|
|
|
case REMOVE : return QIcon(":trash");
|
|
|
|
}
|
2013-09-22 19:34:50 +00:00
|
|
|
} else if (role == Qt::FontRole) {
|
2013-09-02 19:21:08 +00:00
|
|
|
return defaultModelFont();
|
|
|
|
}
|
2013-08-26 12:14:19 +00:00
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2013-08-30 10:14:30 +00:00
|
|
|
bool DivePlannerPointsModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
|
|
|
{
|
2013-11-12 02:19:04 +00:00
|
|
|
int o2 = 0;
|
|
|
|
int he = 0;
|
2013-09-22 19:34:50 +00:00
|
|
|
if(role == Qt::EditRole) {
|
2013-08-30 16:27:15 +00:00
|
|
|
divedatapoint& p = divepoints[index.row()];
|
2013-09-22 19:34:50 +00:00
|
|
|
switch(index.column()) {
|
2013-11-08 12:22:59 +00:00
|
|
|
case DEPTH: p.depth = units_to_depth(value.toInt()); break;
|
|
|
|
case DURATION: p.time = value.toInt() * 60; break;
|
|
|
|
case CCSETPOINT: {
|
|
|
|
int po2 = 0;
|
|
|
|
QByteArray gasv = value.toByteArray();
|
|
|
|
if (validate_po2(gasv.data(), &po2))
|
|
|
|
p.po2 = po2;
|
|
|
|
}
|
|
|
|
break;
|
2013-11-12 02:19:04 +00:00
|
|
|
case GAS:
|
2013-11-08 12:22:59 +00:00
|
|
|
QByteArray gasv = value.toByteArray();
|
|
|
|
if (validate_gas(gasv.data(), &o2, &he)) {
|
2013-11-12 02:19:04 +00:00
|
|
|
p.o2 = o2;
|
|
|
|
p.he = he;
|
2013-08-30 18:06:26 +00:00
|
|
|
}
|
2013-11-08 12:22:59 +00:00
|
|
|
break;
|
2013-08-30 16:27:15 +00:00
|
|
|
}
|
|
|
|
editStop(index.row(), p);
|
|
|
|
}
|
2013-08-30 18:06:26 +00:00
|
|
|
return QAbstractItemModel::setData(index, value, role);
|
2013-08-30 10:14:30 +00:00
|
|
|
}
|
|
|
|
|
2013-08-26 12:14:19 +00:00
|
|
|
QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
2013-09-22 19:34:50 +00:00
|
|
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
|
|
|
switch(section) {
|
2013-08-26 12:14:19 +00:00
|
|
|
case DEPTH: return tr("Final Depth");
|
|
|
|
case DURATION: return tr("Duration");
|
|
|
|
case GAS: return tr("Used Gas");
|
|
|
|
case CCSETPOINT: return tr("CC Set Point");
|
|
|
|
}
|
2013-09-22 19:34:50 +00:00
|
|
|
} else if (role == Qt::FontRole) {
|
2013-09-02 19:21:08 +00:00
|
|
|
return defaultModelFont();
|
|
|
|
}
|
2013-08-26 12:14:19 +00:00
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2013-08-30 10:14:30 +00:00
|
|
|
Qt::ItemFlags DivePlannerPointsModel::flags(const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
|
|
|
}
|
|
|
|
|
2013-08-26 12:14:19 +00:00
|
|
|
int DivePlannerPointsModel::rowCount(const QModelIndex& parent) const
|
|
|
|
{
|
2013-08-26 16:18:21 +00:00
|
|
|
return divepoints.count();
|
2013-08-26 12:14:19 +00:00
|
|
|
}
|
|
|
|
|
2013-11-09 00:09:46 +00:00
|
|
|
DivePlannerPointsModel::DivePlannerPointsModel(QObject* parent): QAbstractTableModel(parent), mode(NOTHING)
|
2013-08-26 12:14:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DivePlannerPointsModel* DivePlannerPointsModel::instance()
|
|
|
|
{
|
|
|
|
static DivePlannerPointsModel* self = new DivePlannerPointsModel();
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2013-08-26 16:18:21 +00:00
|
|
|
void DivePlannerPointsModel::setBottomSac(int sac)
|
|
|
|
{
|
|
|
|
diveplan.bottomsac = sac;
|
2013-09-09 10:27:46 +00:00
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1));
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::setDecoSac(int sac)
|
|
|
|
{
|
|
|
|
diveplan.decosac = sac;
|
2013-09-09 10:27:46 +00:00
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1));
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 18:55:33 +00:00
|
|
|
void DivePlannerPointsModel::setGFHigh(const int gfhigh)
|
2013-08-26 16:18:21 +00:00
|
|
|
{
|
|
|
|
diveplan.gfhigh = gfhigh;
|
2013-09-09 10:27:46 +00:00
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1));
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
2013-11-14 18:55:33 +00:00
|
|
|
void DivePlannerPointsModel::setGFLow(const int ghflow)
|
2013-08-26 16:18:21 +00:00
|
|
|
{
|
|
|
|
diveplan.gflow = ghflow;
|
2013-09-09 10:27:46 +00:00
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1));
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::setSurfacePressure(int pressure)
|
|
|
|
{
|
|
|
|
diveplan.surface_pressure = pressure;
|
2013-09-09 10:27:46 +00:00
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1));
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::setLastStop6m(bool value)
|
|
|
|
{
|
2013-11-09 21:08:42 +00:00
|
|
|
set_last_stop(value);
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1));
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::setStartTime(const QTime& t)
|
|
|
|
{
|
2013-09-20 23:41:42 +00:00
|
|
|
diveplan.when = (t.msec() + QDateTime::currentMSecsSinceEpoch()) / 1000 - gettimezoneoffset();
|
2013-09-09 10:27:46 +00:00
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1));
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-22 19:34:50 +00:00
|
|
|
bool divePointsLessThan(const divedatapoint& p1, const divedatapoint& p2)
|
|
|
|
{
|
2013-08-26 20:02:34 +00:00
|
|
|
return p1.time <= p2.time;
|
|
|
|
}
|
2013-09-22 19:34:50 +00:00
|
|
|
|
2013-11-12 02:19:04 +00:00
|
|
|
bool DivePlannerPointsModel::addGas(int o2, int he)
|
|
|
|
{
|
|
|
|
if (is_air(o2, he))
|
|
|
|
o2 = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
2013-11-13 13:38:14 +00:00
|
|
|
cylinder_t *cyl = &stagingDive->cylinder[i];
|
2013-11-12 02:19:04 +00:00
|
|
|
if (cylinder_nodata(cyl)) {
|
2013-11-13 12:44:18 +00:00
|
|
|
fill_default_cylinder(cyl);
|
2013-11-12 02:19:04 +00:00
|
|
|
cyl->gasmix.o2.permille = o2;
|
|
|
|
cyl->gasmix.he.permille = he;
|
|
|
|
CylindersModel::instance()->setDive(stagingDive);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (cyl->gasmix.o2.permille == o2 && cyl->gasmix.he.permille == he)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
qDebug("too many gases");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-08 09:15:04 +00:00
|
|
|
int DivePlannerPointsModel::addStop(int milimeters, int minutes, int o2, int he, int ccpoint)
|
2013-08-26 16:18:21 +00:00
|
|
|
{
|
|
|
|
int row = divepoints.count();
|
2013-11-14 20:06:08 +00:00
|
|
|
if (minutes == 0 && milimeters == 0 && row != 0){
|
2013-11-15 02:54:13 +00:00
|
|
|
/* this is only possible if the user clicked on the 'plus' sign on the DivePoints Table */
|
|
|
|
struct divedatapoint& t = divepoints.last();
|
|
|
|
milimeters = t.depth;
|
|
|
|
minutes = t.time + 600; // 10 minutes.
|
2013-11-14 20:51:08 +00:00
|
|
|
} else if (minutes == 0 && milimeters == 0 && row == 0) {
|
2013-11-15 02:54:13 +00:00
|
|
|
milimeters = M_OR_FT(5, 15); // 5m / 15ft
|
|
|
|
minutes = 600; // 10 min
|
2013-11-14 20:06:08 +00:00
|
|
|
}
|
2013-11-12 02:19:04 +00:00
|
|
|
if (o2 != -1)
|
|
|
|
if (!addGas(o2, he))
|
|
|
|
qDebug("addGas failed"); // FIXME add error propagation
|
2013-09-09 22:57:22 +00:00
|
|
|
|
2013-08-26 19:55:30 +00:00
|
|
|
// check if there's already a new stop before this one:
|
2013-11-09 11:33:33 +00:00
|
|
|
for (int i = 0; i < row; i++) {
|
2013-08-26 20:02:34 +00:00
|
|
|
const divedatapoint& dp = divepoints.at(i);
|
2013-11-08 12:22:59 +00:00
|
|
|
if (dp.time == minutes) {
|
|
|
|
row = i;
|
|
|
|
beginRemoveRows(QModelIndex(), row, row);
|
|
|
|
divepoints.remove(row);
|
|
|
|
endRemoveRows();
|
|
|
|
break;
|
|
|
|
}
|
2013-09-22 19:34:50 +00:00
|
|
|
if (dp.time > minutes ) {
|
2013-08-26 20:02:34 +00:00
|
|
|
row = i;
|
|
|
|
break;
|
2013-08-26 19:55:30 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-15 02:54:13 +00:00
|
|
|
if (o2 == -1) {
|
|
|
|
if (row > 0) {
|
|
|
|
o2 = divepoints.at(row - 1).o2;
|
|
|
|
he = divepoints.at(row - 1).he;
|
|
|
|
} else {
|
|
|
|
// when we add a first data point we need to make sure that there is a
|
|
|
|
// tank for it to use;
|
|
|
|
// first check to the right, then to the left, but if there's nothing,
|
|
|
|
// we simply default to AIR
|
|
|
|
if (row < divepoints.count()) {
|
|
|
|
o2 = divepoints.at(row).o2;
|
|
|
|
he = divepoints.at(row).he;
|
|
|
|
} else {
|
|
|
|
o2 = O2_IN_AIR;
|
|
|
|
if (!addGas(o2, 0))
|
|
|
|
qDebug("addGas failed"); // FIXME add error propagation
|
|
|
|
}
|
|
|
|
}
|
2013-11-11 09:13:55 +00:00
|
|
|
}
|
2013-08-26 19:55:30 +00:00
|
|
|
// add the new stop
|
2013-08-26 16:18:21 +00:00
|
|
|
beginInsertRows(QModelIndex(), row, row);
|
|
|
|
divedatapoint point;
|
2013-09-22 19:37:49 +00:00
|
|
|
point.depth = milimeters;
|
2013-08-26 16:18:21 +00:00
|
|
|
point.time = minutes;
|
2013-11-08 09:15:04 +00:00
|
|
|
point.o2 = o2;
|
|
|
|
point.he = he;
|
|
|
|
point.po2 = ccpoint;
|
2013-08-26 16:18:21 +00:00
|
|
|
divepoints.append( point );
|
2013-08-26 20:02:34 +00:00
|
|
|
std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan);
|
2013-08-26 16:18:21 +00:00
|
|
|
endInsertRows();
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
2013-08-26 17:54:07 +00:00
|
|
|
void DivePlannerPointsModel::editStop(int row, divedatapoint newData)
|
|
|
|
{
|
|
|
|
divepoints[row] = newData;
|
2013-08-26 20:15:48 +00:00
|
|
|
std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan);
|
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1));
|
2013-08-26 17:54:07 +00:00
|
|
|
}
|
|
|
|
|
2013-09-22 18:01:18 +00:00
|
|
|
int DivePlannerPointsModel::size()
|
|
|
|
{
|
|
|
|
return divepoints.size();
|
|
|
|
}
|
|
|
|
|
2013-08-26 17:17:39 +00:00
|
|
|
divedatapoint DivePlannerPointsModel::at(int row)
|
|
|
|
{
|
|
|
|
return divepoints.at(row);
|
|
|
|
}
|
2013-08-30 19:08:55 +00:00
|
|
|
|
2013-09-02 19:21:08 +00:00
|
|
|
void DivePlannerPointsModel::remove(const QModelIndex& index)
|
2013-08-30 19:08:55 +00:00
|
|
|
{
|
|
|
|
if (index.column() != REMOVE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
beginRemoveRows(QModelIndex(), index.row(), index.row());
|
|
|
|
divepoints.remove(index.row());
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
2013-09-09 10:18:22 +00:00
|
|
|
|
|
|
|
struct diveplan DivePlannerPointsModel::getDiveplan()
|
|
|
|
{
|
|
|
|
return diveplan;
|
|
|
|
}
|
2013-09-16 14:38:41 +00:00
|
|
|
|
|
|
|
void DivePlannerPointsModel::cancelPlan()
|
|
|
|
{
|
2013-09-22 19:34:50 +00:00
|
|
|
if (mode == PLAN && rowCount()) {
|
2013-10-05 20:55:01 +00:00
|
|
|
if (QMessageBox::warning(mainWindow(), tr("Discard the Plan?"),
|
|
|
|
tr("You are about to discard your plan."),
|
|
|
|
QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard) != QMessageBox::Discard) {
|
|
|
|
return;
|
|
|
|
}
|
2013-09-16 14:38:41 +00:00
|
|
|
}
|
2013-11-09 00:09:46 +00:00
|
|
|
clear();
|
|
|
|
emit planCanceled();
|
2013-11-12 05:21:50 +00:00
|
|
|
if (mode != ADD)
|
|
|
|
free(stagingDive);
|
2013-11-09 00:09:46 +00:00
|
|
|
setPlanMode(NOTHING);
|
2013-11-10 12:02:53 +00:00
|
|
|
stagingDive = NULL;
|
|
|
|
CylindersModel::instance()->setDive(current_dive);
|
2013-11-09 22:06:26 +00:00
|
|
|
CylindersModel::instance()->update();
|
2013-11-09 00:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DivePlannerPointsModel::Mode DivePlannerPointsModel::currentMode() const
|
|
|
|
{
|
|
|
|
return mode;
|
|
|
|
}
|
2013-09-16 14:38:41 +00:00
|
|
|
|
2013-11-13 12:45:54 +00:00
|
|
|
QList<QPair<int, int> > DivePlannerPointsModel::collectGases(struct dive *d)
|
|
|
|
{
|
|
|
|
QList<QPair<int, int> > l;
|
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
cylinder_t *cyl = &d->cylinder[i];
|
|
|
|
if (!cylinder_nodata(cyl))
|
|
|
|
l.push_back(QPair<int, int>(cyl->gasmix.o2.permille, cyl->gasmix.he.permille));
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
void DivePlannerPointsModel::rememberTanks()
|
|
|
|
{
|
|
|
|
oldGases = collectGases(stagingDive);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DivePlannerPointsModel::tankInUse(int o2, int he)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < rowCount(); j++) {
|
|
|
|
divedatapoint& p = divepoints[j];
|
|
|
|
if (p.time == 0) // special entries that hold the available gases
|
|
|
|
continue;
|
|
|
|
if ((p.o2 == o2 && p.he == he) ||
|
|
|
|
(is_air(p.o2, p.he) && is_air(o2, he)))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::tanksUpdated()
|
|
|
|
{
|
2013-11-14 12:58:04 +00:00
|
|
|
// we don't know exactly what changed - what we care about is
|
|
|
|
// "did a gas change on us". So we look through the diveplan to
|
|
|
|
// see if there is a gas that is now missing and if there is, we
|
|
|
|
// replace it with the matching new gas.
|
|
|
|
QList<QPair<int,int> > gases = collectGases(stagingDive);
|
|
|
|
if (gases.length() == oldGases.length()) {
|
|
|
|
// either nothing relevant changed, or exactly ONE gasmix changed
|
|
|
|
for (int i = 0; i < gases.length(); i++) {
|
|
|
|
if (gases.at(i) != oldGases.at(i)) {
|
|
|
|
if (oldGases.count(oldGases.at(i)) > 1) {
|
|
|
|
// we had this gas more than once, so don't
|
|
|
|
// change segments that used this gas as it still exists
|
2013-11-13 12:45:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-11-14 12:58:04 +00:00
|
|
|
for (int j = 0; j < rowCount(); j++) {
|
|
|
|
divedatapoint& p = divepoints[j];
|
|
|
|
int o2 = oldGases.at(i).first;
|
|
|
|
int he = oldGases.at(i).second;
|
|
|
|
if ((p.o2 == o2 && p.he == he) ||
|
|
|
|
(is_air(p.o2, p.he) && (is_air(o2, he) || (o2 == 0 && he == 0)))) {
|
|
|
|
p.o2 = gases.at(i).first;
|
|
|
|
p.he = gases.at(i).second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-11-13 12:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-14 12:58:04 +00:00
|
|
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1));
|
2013-11-13 12:45:54 +00:00
|
|
|
}
|
|
|
|
|
2013-11-09 00:09:46 +00:00
|
|
|
void DivePlannerPointsModel::clear()
|
|
|
|
{
|
2013-11-12 05:21:50 +00:00
|
|
|
if (mode == ADD) {
|
|
|
|
stagingDive = current_dive;
|
|
|
|
} else {
|
|
|
|
if (!stagingDive)
|
|
|
|
stagingDive = alloc_dive();
|
|
|
|
memset(stagingDive->cylinder, 0, MAX_CYLINDERS * sizeof(cylinder_t));
|
|
|
|
}
|
2013-11-12 02:19:04 +00:00
|
|
|
CylindersModel::instance()->setDive(stagingDive);
|
2013-09-16 14:38:41 +00:00
|
|
|
beginRemoveRows(QModelIndex(), 0, rowCount()-1);
|
|
|
|
divepoints.clear();
|
|
|
|
endRemoveRows();
|
2013-11-10 12:02:53 +00:00
|
|
|
CylindersModel::instance()->clear();
|
2013-09-16 14:38:41 +00:00
|
|
|
}
|
2013-09-16 15:11:06 +00:00
|
|
|
|
2013-11-09 00:09:46 +00:00
|
|
|
|
2013-09-16 15:11:06 +00:00
|
|
|
void DivePlannerPointsModel::createTemporaryPlan()
|
|
|
|
{
|
|
|
|
// This needs to be done in the following steps:
|
|
|
|
// Get the user-input and calculate the dive info
|
|
|
|
// Not sure if this is the place to create the diveplan...
|
|
|
|
// We just start with a surface node at time = 0
|
2013-11-12 02:19:04 +00:00
|
|
|
struct divedatapoint *dp = create_dp(0, 0, 209, 0, 0);
|
|
|
|
dp->entered = TRUE;
|
2013-09-16 15:11:06 +00:00
|
|
|
diveplan.dp = dp;
|
|
|
|
int lastIndex = -1;
|
2013-09-22 19:34:50 +00:00
|
|
|
for (int i = 0; i < rowCount(); i++) {
|
2013-09-16 15:11:06 +00:00
|
|
|
divedatapoint p = at(i);
|
|
|
|
int deltaT = lastIndex != -1 ? p.time - at(lastIndex).time : p.time;
|
|
|
|
lastIndex = i;
|
|
|
|
dp = plan_add_segment(&diveplan, deltaT, p.depth, p.o2, p.he, p.po2);
|
|
|
|
}
|
|
|
|
char *cache = NULL;
|
|
|
|
tempDive = NULL;
|
2013-10-06 15:55:58 +00:00
|
|
|
const char *errorString = NULL;
|
2013-11-12 02:19:04 +00:00
|
|
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
cylinder_t *cyl = &stagingDive->cylinder[i];
|
|
|
|
if (cyl->depth.mm) {
|
|
|
|
dp = create_dp(0, cyl->depth.mm, cyl->gasmix.o2.permille, cyl->gasmix.he.permille, 0);
|
|
|
|
dp->next = diveplan.dp->next;
|
|
|
|
diveplan.dp->next = dp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if DEBUG_PLAN
|
|
|
|
dump_plan(&diveplan);
|
|
|
|
#endif
|
2013-09-19 03:40:34 +00:00
|
|
|
plan(&diveplan, &cache, &tempDive, isPlanner(), &errorString);
|
2013-11-07 08:25:42 +00:00
|
|
|
if (mode == ADD) {
|
2013-11-13 12:45:54 +00:00
|
|
|
// copy the samples and events, but don't overwrite the cylinders
|
2013-09-19 04:33:39 +00:00
|
|
|
copy_samples(tempDive, current_dive);
|
2013-11-08 09:15:04 +00:00
|
|
|
copy_events(tempDive, current_dive);
|
2013-11-07 08:25:42 +00:00
|
|
|
}
|
2013-09-16 15:11:06 +00:00
|
|
|
#if DEBUG_PLAN
|
|
|
|
dump_plan(&diveplan);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::deleteTemporaryPlan()
|
|
|
|
{
|
|
|
|
deleteTemporaryPlan(diveplan.dp);
|
|
|
|
delete_single_dive(get_divenr(tempDive));
|
|
|
|
tempDive = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::deleteTemporaryPlan(struct divedatapoint *dp)
|
|
|
|
{
|
2013-09-22 19:34:50 +00:00
|
|
|
if (!dp)
|
2013-09-16 15:11:06 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
deleteTemporaryPlan(dp->next);
|
|
|
|
free(dp);
|
|
|
|
}
|
2013-09-16 15:30:58 +00:00
|
|
|
|
|
|
|
void DivePlannerPointsModel::createPlan()
|
|
|
|
{
|
|
|
|
// Ok, so, here the diveplan creates a dive,
|
|
|
|
// puts it on the dive list, and we need to remember
|
|
|
|
// to not delete it later. mumble. ;p
|
2013-09-22 19:34:50 +00:00
|
|
|
char *cache = NULL;
|
2013-09-16 15:30:58 +00:00
|
|
|
tempDive = NULL;
|
2013-10-06 15:55:58 +00:00
|
|
|
const char *errorString = NULL;
|
2013-09-16 15:30:58 +00:00
|
|
|
|
|
|
|
createTemporaryPlan();
|
2013-09-19 03:40:34 +00:00
|
|
|
plan(&diveplan, &cache, &tempDive, isPlanner(), &errorString);
|
2013-09-16 15:30:58 +00:00
|
|
|
mark_divelist_changed(TRUE);
|
|
|
|
|
2013-09-16 22:21:13 +00:00
|
|
|
// Remove and clean the diveplan, so we don't delete
|
|
|
|
// the dive by mistake.
|
|
|
|
diveplan.dp = NULL;
|
2013-11-09 00:09:46 +00:00
|
|
|
clear();
|
2013-09-16 15:30:58 +00:00
|
|
|
planCreated();
|
2013-11-09 00:09:46 +00:00
|
|
|
setPlanMode(NOTHING);
|
2013-11-10 12:02:53 +00:00
|
|
|
free(stagingDive);
|
|
|
|
stagingDive = NULL;
|
|
|
|
CylindersModel::instance()->setDive(current_dive);
|
2013-11-09 22:06:26 +00:00
|
|
|
CylindersModel::instance()->update();
|
2013-09-16 15:30:58 +00:00
|
|
|
}
|
2013-11-17 23:20:07 +00:00
|
|
|
|
|
|
|
ExpanderGraphics::ExpanderGraphics(QGraphicsItem* parent): QGraphicsRectItem(parent)
|
|
|
|
{
|
|
|
|
icon = new QGraphicsPixmapItem(this);
|
|
|
|
bg = new QGraphicsPixmapItem(this);
|
|
|
|
leftWing = new QGraphicsPixmapItem(this);
|
|
|
|
rightWing = new QGraphicsPixmapItem(this);
|
|
|
|
|
|
|
|
QPixmap p;
|
|
|
|
#define CREATE(item, pixmap) \
|
|
|
|
p = QPixmap(QString( pixmap ));\
|
|
|
|
item->setPixmap(p); \
|
|
|
|
|
|
|
|
CREATE(icon, ":icon_time");
|
|
|
|
CREATE(bg, ":round_base");
|
|
|
|
CREATE(leftWing, ":left_wing");
|
|
|
|
CREATE(rightWing, ":right_wing");
|
|
|
|
#undef CREATE
|
|
|
|
|
|
|
|
decreaseBtn = new Button(0, this);
|
|
|
|
increaseBtn = new Button(0, this);
|
|
|
|
decreaseBtn->setPixmap(QPixmap(":arrow_down"));
|
|
|
|
increaseBtn->setPixmap(QPixmap(":arrow_up"));
|
|
|
|
|
|
|
|
setFlag(ItemIgnoresTransformations);
|
|
|
|
leftWing->setZValue(-2);
|
|
|
|
rightWing->setZValue(-2);
|
|
|
|
bg->setZValue(-1);
|
|
|
|
|
|
|
|
leftWing->setPos(0,0);
|
|
|
|
bg->setPos(leftWing->pos().x() + leftWing->boundingRect().width() -60, 5);
|
|
|
|
rightWing->setPos(leftWing->pos().x() + leftWing->boundingRect().width() - 20, 0);
|
|
|
|
decreaseBtn->setPos(leftWing->pos().x(), leftWing->pos().y() );
|
|
|
|
increaseBtn->setPos(rightWing->pos().x(), rightWing->pos().y() );
|
|
|
|
icon->setPos(bg->pos().x(), bg->pos().y() - 5);
|
2013-11-18 23:13:05 +00:00
|
|
|
|
|
|
|
//I need to bottom align the items, I need to make the 0,0 ( orgin ) to be
|
|
|
|
// the bottom of this item, so shift everything up.
|
|
|
|
QRectF r = childrenBoundingRect();
|
|
|
|
Q_FOREACH(QGraphicsItem *i, childItems()){
|
|
|
|
i->setPos(i->pos().x(), i->pos().y() - r.height());
|
|
|
|
}
|
2013-11-17 23:20:07 +00:00
|
|
|
}
|