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 "ui_diveplanner.h"
|
|
|
|
#include "mainwindow.h"
|
2013-09-02 19:21:08 +00:00
|
|
|
#include "tableview.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-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-06-20 15:33:26 +00:00
|
|
|
|
2013-06-27 14:10:03 +00:00
|
|
|
#define TIME_INITIAL_MAX 30
|
|
|
|
|
2013-07-02 17:14:09 +00:00
|
|
|
#define MAX_DEEPNESS 150
|
|
|
|
#define MIN_DEEPNESS 40
|
|
|
|
|
2013-08-30 10:14:30 +00:00
|
|
|
QStringListModel *airTypes(){
|
2013-08-30 18:06:26 +00:00
|
|
|
static QStringListModel *self = new QStringListModel(QStringList()
|
|
|
|
<< QObject::tr("AIR")
|
|
|
|
<< QObject::tr("EAN32")
|
|
|
|
<< QObject::tr("EAN36"));
|
2013-08-30 10:14:30 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2013-08-30 18:06:26 +00:00
|
|
|
QString strForAir(const divedatapoint& p){
|
|
|
|
return p.o2 == 209 ? QObject::tr("AIR")
|
|
|
|
: p.o2 == 320 ? QObject::tr("EAN32")
|
|
|
|
: p.o2 == 360 ? QObject::tr("EAN36")
|
|
|
|
: QObject::tr("Choose Gas");
|
|
|
|
}
|
|
|
|
|
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-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-07-02 14:12:15 +00:00
|
|
|
timeLine->setLine(
|
|
|
|
fromPercent(10, Qt::Horizontal),
|
|
|
|
fromPercent(90, Qt::Vertical),
|
|
|
|
fromPercent(90, Qt::Horizontal),
|
|
|
|
fromPercent(90, Qt::Vertical)
|
|
|
|
);
|
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-07-02 15:01:47 +00:00
|
|
|
timeLine->setColor(profile_color[TIME_GRID].at(0));
|
2013-06-20 19:48:24 +00:00
|
|
|
timeLine->updateTicks();
|
|
|
|
scene()->addItem(timeLine);
|
|
|
|
|
|
|
|
depthLine = new Ruler();
|
|
|
|
depthLine->setMinimum(0);
|
2013-06-27 22:52:58 +00:00
|
|
|
depthLine->setMaximum(40);
|
2013-06-20 19:48:24 +00:00
|
|
|
depthLine->setTickInterval(10);
|
2013-07-02 14:12:15 +00:00
|
|
|
depthLine->setLine(
|
|
|
|
fromPercent(10, Qt::Horizontal),
|
|
|
|
fromPercent(10, Qt::Vertical),
|
|
|
|
fromPercent(10, Qt::Horizontal),
|
|
|
|
fromPercent(90, Qt::Vertical)
|
|
|
|
);
|
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-07-02 15:01:47 +00:00
|
|
|
depthLine->setColor(profile_color[DEPTH_GRID].at(0));
|
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-07-21 15:56:21 +00:00
|
|
|
#define ADDBTN(obj, icon, text, horizontal, vertical, tooltip, slot) \
|
|
|
|
obj = new Button(); \
|
|
|
|
obj->setPixmap(QPixmap(icon)); \
|
|
|
|
obj->setPos(fromPercent(horizontal, Qt::Horizontal), fromPercent(vertical, Qt::Vertical)); \
|
|
|
|
obj->setToolTip(tooltip); \
|
|
|
|
scene()->addItem(obj); \
|
|
|
|
connect(obj, SIGNAL(clicked()), this, SLOT(slot));
|
|
|
|
|
|
|
|
ADDBTN(plusDepth, ":plus", "" , 5, 5, tr("Increase maximum depth by 10m"), increaseDepth());
|
2013-08-30 19:21:55 +00:00
|
|
|
ADDBTN(plusTime, ":plus", "" , 95, 95, tr("Increase minimum time by 10m"), increaseTime());
|
2013-07-21 15:56:21 +00:00
|
|
|
ADDBTN(lessDepth, ":minimum","" , 2, 5, tr("Decreases maximum depth by 10m"), decreaseDepth());
|
|
|
|
ADDBTN(lessTime, ":minimum","" , 92, 95, tr("Decreases minimum time by 10m"), decreaseTime());
|
2013-07-21 16:01:33 +00:00
|
|
|
#undef ADDBTN
|
2013-07-02 17:36:52 +00:00
|
|
|
minMinutes = TIME_INITIAL_MAX;
|
2013-07-04 14:06:28 +00:00
|
|
|
|
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-08-30 10:14:30 +00:00
|
|
|
gasListView->setModel(airTypes());
|
2013-07-21 16:54:21 +00:00
|
|
|
gasListView->hide();
|
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-08-30 18:53:10 +00:00
|
|
|
connect(plannerModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(createDecoStops()));
|
|
|
|
|
|
|
|
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-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;
|
|
|
|
createDecoStops();
|
|
|
|
}
|
|
|
|
|
2013-07-04 14:28:39 +00:00
|
|
|
void DivePlannerGraphics::keyDownAction()
|
|
|
|
{
|
|
|
|
if(scene()->selectedItems().count()){
|
|
|
|
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.depth / 1000 >= depthLine->maximum())
|
2013-07-04 14:28:39 +00:00
|
|
|
continue;
|
|
|
|
|
2013-08-26 19:34:06 +00:00
|
|
|
dp.depth += 1000;
|
|
|
|
plannerModel->editStop(row, dp);
|
2013-07-04 14:28:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerGraphics::keyUpAction()
|
|
|
|
{
|
|
|
|
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.depth / 1000 <= 0)
|
2013-07-04 14:28:39 +00:00
|
|
|
continue;
|
|
|
|
|
2013-08-26 19:34:06 +00:00
|
|
|
dp.depth -= 1000;
|
|
|
|
plannerModel->editStop(row, dp);
|
2013-07-04 14:28:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
createDecoStops();
|
|
|
|
}
|
|
|
|
|
2013-07-04 15:30:05 +00:00
|
|
|
void DivePlannerGraphics::keyLeftAction()
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
Q_FOREACH(DiveHandler *h, handles){
|
|
|
|
if (h->pos().x() == xpos){
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
Q_FOREACH(DiveHandler *h, handles){
|
|
|
|
if (h->pos().x() == xpos){
|
|
|
|
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();
|
|
|
|
if(selCount){
|
2013-08-30 18:53:10 +00:00
|
|
|
QVector<int> selectedIndexes;
|
2013-07-04 14:16:42 +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;
|
|
|
|
for(int i = num; i != 0; i--){
|
|
|
|
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-08-30 19:08:55 +00:00
|
|
|
createDecoStops();
|
2013-08-30 18:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool intLessThan(int a, int b){
|
|
|
|
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);
|
|
|
|
for(int i = v2.count()-1; i >= 0; i--){
|
|
|
|
divepoints.remove(v2[i]);
|
|
|
|
}
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
|
2013-07-04 14:06:28 +00:00
|
|
|
void DivePlannerGraphics::keyEscAction()
|
|
|
|
{
|
|
|
|
if (scene()->selectedItems().count()){
|
|
|
|
scene()->clearSelection();
|
|
|
|
return;
|
|
|
|
}
|
2013-09-16 14:38:41 +00:00
|
|
|
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-07-02 17:14:09 +00:00
|
|
|
if (depthLine->maximum() + 10 > MAX_DEEPNESS)
|
|
|
|
return;
|
|
|
|
depthLine->setMaximum( depthLine->maximum() + 10);
|
|
|
|
depthLine->updateTicks();
|
|
|
|
createDecoStops();
|
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();
|
|
|
|
createDecoStops();
|
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()
|
|
|
|
{
|
|
|
|
if (depthLine->maximum() - 10 < MIN_DEEPNESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Q_FOREACH(DiveHandler *d, handles){
|
|
|
|
if (depthLine->valueAt(d->pos()) > depthLine->maximum() - 10){
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
depthLine->setMaximum(depthLine->maximum() - 10);
|
|
|
|
depthLine->updateTicks();
|
|
|
|
createDecoStops();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerGraphics::decreaseTime()
|
|
|
|
{
|
2013-07-21 12:44:52 +00:00
|
|
|
if (timeLine->maximum() -10 < TIME_INITIAL_MAX){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (timeLine->maximum() - 10 < dpMaxTime){
|
|
|
|
qDebug() << timeLine->maximum() << dpMaxTime;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
minMinutes -= 10;
|
|
|
|
timeLine->setMaximum(timeLine->maximum() -10);
|
|
|
|
timeLine->updateTicks();
|
|
|
|
createDecoStops();
|
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));
|
|
|
|
int meters = rint(depthLine->valueAt(mappedPos));
|
2013-08-26 19:34:06 +00:00
|
|
|
plannerModel->addStop(meters * 1000, minutes * 60, tr("Air"), 0);
|
2013-06-20 16:20:41 +00:00
|
|
|
}
|
|
|
|
|
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-06-23 20:09:29 +00:00
|
|
|
void DivePlannerGraphics::createDecoStops()
|
2013-06-20 16:20:41 +00:00
|
|
|
{
|
2013-06-26 23:41:39 +00:00
|
|
|
qDeleteAll(lines);
|
|
|
|
lines.clear();
|
|
|
|
|
2013-06-20 21:25:03 +00:00
|
|
|
// This needs to be done in the following steps:
|
|
|
|
// Get the user-input and calculate the dive info
|
2013-06-24 01:04:35 +00:00
|
|
|
// Not sure if this is the place to create the diveplan...
|
|
|
|
// We just start with a surface node at time = 0
|
2013-09-09 10:18:22 +00:00
|
|
|
struct diveplan diveplan = plannerModel->getDiveplan();
|
2013-06-24 01:04:35 +00:00
|
|
|
struct divedatapoint *dp = create_dp(0, 0, 209, 0, 0);
|
|
|
|
dp->entered = TRUE;
|
2013-06-24 04:27:52 +00:00
|
|
|
diveplan.dp = dp;
|
2013-08-30 09:52:58 +00:00
|
|
|
|
2013-08-26 19:34:06 +00:00
|
|
|
int rowCount = plannerModel->rowCount();
|
|
|
|
int lastIndex = -1;
|
|
|
|
for(int i = 0; i < rowCount; i++){
|
2013-08-30 09:54:41 +00:00
|
|
|
divedatapoint p = plannerModel->at(i);
|
|
|
|
int deltaT = lastIndex != -1 ? p.time - plannerModel->at(lastIndex).time : p.time;
|
2013-08-26 19:34:06 +00:00
|
|
|
lastIndex = i;
|
2013-08-30 09:54:41 +00:00
|
|
|
dp = plan_add_segment(&diveplan, deltaT, p.depth, p.o2, p.he, p.po2);
|
2013-08-26 19:34:06 +00:00
|
|
|
}
|
2013-08-30 09:52:58 +00:00
|
|
|
|
2013-06-24 01:04:35 +00:00
|
|
|
#if DEBUG_PLAN
|
2013-06-24 04:27:52 +00:00
|
|
|
dump_plan(&diveplan);
|
|
|
|
#endif
|
|
|
|
char *cache = NULL;
|
|
|
|
struct dive *dive = NULL;
|
|
|
|
char *errorString = NULL;
|
|
|
|
plan(&diveplan, &cache, &dive, &errorString);
|
|
|
|
#if DEBUG_PLAN
|
|
|
|
dump_plan(&diveplan);
|
2013-06-24 01:04:35 +00:00
|
|
|
#endif
|
|
|
|
|
2013-06-24 04:27:52 +00:00
|
|
|
while(dp->next)
|
|
|
|
dp = dp->next;
|
2013-06-26 23:41:39 +00:00
|
|
|
|
2013-07-21 12:44:52 +00:00
|
|
|
dpMaxTime = dp->time / 60.0 + 5;
|
|
|
|
|
2013-06-27 14:10:03 +00:00
|
|
|
if (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-08-26 19:34:06 +00:00
|
|
|
for(int i = 0; i < plannerModel->rowCount(); i++){
|
|
|
|
divedatapoint dp = plannerModel->at(i);
|
|
|
|
DiveHandler *h = handles.at(i);
|
|
|
|
h->setPos(timeLine->posAtValue(dp.time / 60), depthLine->posAtValue(dp.depth / 1000));
|
2013-07-21 15:12:31 +00:00
|
|
|
QPointF p1 = (i == 0) ? QPointF(timeLine->posAtValue(0), depthLine->posAtValue(0)) : handles[i-1]->pos();
|
|
|
|
QPointF p2 = handles[i]->pos();
|
|
|
|
QLineF line(p1, p2);
|
|
|
|
QPointF pos = line.pointAt(0.5);
|
|
|
|
gases[i]->setPos(pos);
|
2013-08-30 19:33:54 +00:00
|
|
|
gases[i]->setText( strForAir(dp));
|
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-06-24 04:27:52 +00:00
|
|
|
for (dp = diveplan.dp; dp != NULL; dp = dp->next) {
|
2013-06-27 08:56:46 +00:00
|
|
|
double xpos = timeLine->posAtValue(dp->time / 60.0);
|
|
|
|
double ypos = depthLine->posAtValue(dp->depth / 1000.0);
|
2013-07-02 16:39:54 +00:00
|
|
|
if(!dp->entered){
|
|
|
|
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-06-27 20:31:10 +00:00
|
|
|
deleteTemporaryDivePlan(diveplan.dp);
|
2013-07-05 21:42:35 +00:00
|
|
|
delete_single_dive(get_divenr(dive));
|
2013-06-27 20:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerGraphics::deleteTemporaryDivePlan(divedatapoint* dp)
|
|
|
|
{
|
|
|
|
if (!dp)
|
|
|
|
return;
|
|
|
|
deleteTemporaryDivePlan(dp->next);
|
|
|
|
free(dp);
|
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-06-24 00:32:23 +00:00
|
|
|
depthString->setText(QString::number(rint(depthLine->valueAt(mappedPos))) + "m" );
|
2013-07-02 14:12:15 +00:00
|
|
|
depthString->setPos(fromPercent(5, 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-06-20 18:15:10 +00:00
|
|
|
moveActiveHandler(mappedPos);
|
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-06-21 19:28:17 +00:00
|
|
|
void DivePlannerGraphics::moveActiveHandler(const QPointF& pos)
|
2013-06-20 18:15:10 +00:00
|
|
|
{
|
2013-06-21 19:28:17 +00:00
|
|
|
double xpos = timeLine->posAtValue(rint(timeLine->valueAt(pos)));
|
|
|
|
double ypos = depthLine->posAtValue(rint(depthLine->valueAt(pos)));
|
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-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-07-04 14:01:59 +00:00
|
|
|
if (event->modifiers()){
|
|
|
|
QGraphicsView::mousePressEvent(event);
|
2013-07-04 15:30:05 +00:00
|
|
|
return;
|
2013-07-04 14:01:59 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 17:46:40 +00:00
|
|
|
QPointF mappedPos = mapToScene(event->pos());
|
2013-07-04 13:34:30 +00:00
|
|
|
Q_FOREACH(QGraphicsItem *item, scene()->items(mappedPos, Qt::IntersectsItemBoundingRect, Qt::AscendingOrder, transform())){
|
2013-06-23 20:09:29 +00:00
|
|
|
if (DiveHandler *h = qgraphicsitem_cast<DiveHandler*>(item)) {
|
2013-06-20 17:46:40 +00:00
|
|
|
activeDraggedHandler = h;
|
|
|
|
activeDraggedHandler->setBrush(Qt::red);
|
2013-07-04 13:29:28 +00:00
|
|
|
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-07-04 13:29:28 +00:00
|
|
|
QPointF mappedPos = mapToScene(event->pos());
|
|
|
|
int minutes = rint(timeLine->valueAt(mappedPos));
|
|
|
|
int meters = rint(depthLine->valueAt(mappedPos));
|
|
|
|
double xpos = timeLine->posAtValue(minutes);
|
|
|
|
double ypos = depthLine->posAtValue(meters);
|
|
|
|
Q_FOREACH(DiveHandler* handler, handles){
|
|
|
|
if (xpos == handler->pos().x() && handler != activeDraggedHandler){
|
|
|
|
qDebug() << "There's already an point at that place.";
|
|
|
|
//TODO: Move this later to a KMessageWidget.
|
|
|
|
activeDraggedHandler->setPos(originalHandlerPos);
|
|
|
|
activeDraggedHandler = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-26 17:54:07 +00:00
|
|
|
int pos = handles.indexOf(activeDraggedHandler);
|
2013-08-26 19:34:06 +00:00
|
|
|
divedatapoint data = plannerModel->at(pos);
|
2013-08-26 17:54:07 +00:00
|
|
|
|
2013-08-26 19:36:30 +00:00
|
|
|
data.depth = rint(depthLine->valueAt(mappedPos)) * 1000;
|
|
|
|
data.time = rint(timeLine->valueAt(mappedPos)) * 60;
|
2013-08-26 17:54:07 +00:00
|
|
|
|
2013-08-26 19:34:06 +00:00
|
|
|
plannerModel->editStop(pos, data);
|
2013-08-26 17:54:07 +00:00
|
|
|
|
2013-06-27 22:52:58 +00:00
|
|
|
activeDraggedHandler->setBrush(QBrush(Qt::white));
|
2013-07-04 13:29:28 +00:00
|
|
|
activeDraggedHandler->setPos(QPointF(xpos, ypos));
|
|
|
|
|
2013-06-26 23:41:39 +00:00
|
|
|
createDecoStops();
|
2013-06-20 17:46:40 +00:00
|
|
|
activeDraggedHandler = 0;
|
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
|
|
|
|
|
|
|
void DiveHandler::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
|
|
|
{
|
|
|
|
if (event->modifiers().testFlag(Qt::ControlModifier)){
|
|
|
|
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)
|
|
|
|
{
|
2013-09-16 14:09:54 +00:00
|
|
|
maxText->setText(QString::number(maximum));
|
|
|
|
if(orientation == Qt::Horizontal)
|
|
|
|
maxText->setPos( line().x2(), line().y2() -5 );
|
|
|
|
else
|
|
|
|
maxText->setPos( line().x1() - 50, line().y2());
|
2013-06-20 18:52:27 +00:00
|
|
|
max = maximum;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Ruler::setMinimum(double minimum)
|
|
|
|
{
|
2013-09-16 14:09:54 +00:00
|
|
|
minText->setText(QString::number(minimum));
|
|
|
|
if(orientation == Qt::Horizontal)
|
|
|
|
minText->setPos( line().x1(), line().y2() -5 );
|
|
|
|
else
|
|
|
|
minText->setPos( line().x1() - 50, line().y1());
|
2013-06-20 18:52:27 +00:00
|
|
|
min = minimum;
|
|
|
|
}
|
|
|
|
|
2013-09-16 14:09:54 +00:00
|
|
|
Ruler::Ruler() : orientation(Qt::Horizontal),
|
|
|
|
minText(new QGraphicsSimpleTextItem(this)),
|
|
|
|
maxText(new QGraphicsSimpleTextItem(this))
|
2013-06-20 18:52:27 +00:00
|
|
|
{
|
2013-09-16 14:09:54 +00:00
|
|
|
minText->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
|
|
|
maxText->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
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-06-20 19:48:24 +00:00
|
|
|
QLineF m = line();
|
2013-07-02 15:01:47 +00:00
|
|
|
QGraphicsLineItem *item = NULL;
|
|
|
|
|
2013-06-23 20:09:29 +00:00
|
|
|
if (orientation == Qt::Horizontal) {
|
2013-06-20 19:48:24 +00:00
|
|
|
double steps = (max - min) / interval;
|
|
|
|
double stepSize = (m.x2() - m.x1()) / steps;
|
2013-07-02 14:14:11 +00:00
|
|
|
qreal pos;
|
2013-07-02 20:58:03 +00:00
|
|
|
for (pos = m.x1(); pos < m.x2(); pos += stepSize) {
|
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-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-06-23 20:09:29 +00:00
|
|
|
} else {
|
2013-06-20 19:48:24 +00:00
|
|
|
double steps = (max - min) / interval;
|
|
|
|
double stepSize = (m.y2() - m.y1()) / steps;
|
2013-07-02 14:14:11 +00:00
|
|
|
qreal pos;
|
|
|
|
for (pos = m.y1(); pos < m.y2(); pos += stepSize) {
|
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-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-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)
|
|
|
|
{
|
|
|
|
setPen(QPen(color));
|
|
|
|
}
|
|
|
|
|
2013-06-27 19:45:58 +00:00
|
|
|
Button::Button(QObject* parent): QObject(parent), QGraphicsRectItem()
|
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-07-02 17:14:09 +00:00
|
|
|
icon->setPixmap(pixmap.scaled(20,20, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
2013-06-27 19:45:58 +00:00
|
|
|
if(pixmap.isNull()){
|
|
|
|
icon->hide();
|
|
|
|
}else{
|
|
|
|
icon->show();
|
|
|
|
}
|
|
|
|
setRect(childrenBoundingRect());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::setText(const QString& t)
|
|
|
|
{
|
|
|
|
text->setText(t);
|
|
|
|
if(icon->pixmap().isNull()){
|
|
|
|
icon->hide();
|
|
|
|
text->setPos(0,0);
|
|
|
|
}else{
|
|
|
|
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
|
|
|
|
|
|
|
DivePlannerWidget::DivePlannerWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f), ui(new Ui::DivePlanner())
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2013-09-02 19:21:08 +00:00
|
|
|
ui->tableWidget->setTitle(tr("Dive Planner Points"));
|
|
|
|
ui->tableWidget->setModel(DivePlannerPointsModel::instance());
|
|
|
|
ui->tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
|
2013-09-03 16:59:20 +00:00
|
|
|
|
2013-09-09 22:57:22 +00:00
|
|
|
connect(ui->tableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addStop()));
|
2013-08-26 16:18:21 +00:00
|
|
|
connect(ui->startTime, SIGNAL(timeChanged(QTime)), this, SLOT(startTimeChanged(QTime)));
|
|
|
|
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)));
|
|
|
|
connect(ui->highGF, SIGNAL(textChanged(QString)), this, SLOT(gfhighChanged(QString)));
|
|
|
|
connect(ui->lowGF, SIGNAL(textChanged(QString)), this, SLOT(gflowChanged(QString)));
|
|
|
|
connect(ui->highGF, SIGNAL(textChanged(QString)), this, SLOT(gfhighChanged(QString)));
|
|
|
|
connect(ui->lastStop, SIGNAL(toggled(bool)), this, SLOT(lastStopChanged(bool)));
|
2013-09-09 10:18:22 +00:00
|
|
|
|
2013-09-16 14:38:41 +00:00
|
|
|
// Creating the plan
|
|
|
|
connect(ui->buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan()));
|
|
|
|
connect(ui->buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan()));
|
|
|
|
connect(plannerModel, SIGNAL(planCreated()), mainWindow(), SLOT(showProfile()));
|
|
|
|
connect(plannerModel, SIGNAL(planCanceled()), mainWindow(), SLOT(showProfile()));
|
|
|
|
|
2013-09-09 10:18:22 +00:00
|
|
|
/* set defaults. */
|
|
|
|
ui->startTime->setTime( QTime(1, 0) );
|
|
|
|
ui->ATMPressure->setText( "1013" );
|
|
|
|
ui->bottomSAC->setText("20");
|
|
|
|
ui->decoStopSAC->setText("17");
|
|
|
|
ui->lowGF->setText("30");
|
|
|
|
ui->highGF->setText("75");
|
2013-08-28 10:48:46 +00:00
|
|
|
}
|
|
|
|
|
2013-08-26 16:18:21 +00:00
|
|
|
void DivePlannerWidget::startTimeChanged(const QTime& time)
|
|
|
|
{
|
2013-08-26 19:34:06 +00:00
|
|
|
plannerModel->setStartTime(time);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerWidget::gfhighChanged(const QString& gfhigh)
|
|
|
|
{
|
2013-08-26 19:34:06 +00:00
|
|
|
plannerModel->setGFHigh(gfhigh.toShort());
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerWidget::gflowChanged(const QString& gflow)
|
|
|
|
{
|
2013-08-26 19:34:06 +00:00
|
|
|
plannerModel->setGFLow(gflow.toShort());
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerWidget::lastStopChanged(bool checked)
|
|
|
|
{
|
2013-08-26 19:34:06 +00:00
|
|
|
plannerModel->setLastStop6m(checked);
|
2013-08-26 11:43:37 +00:00
|
|
|
}
|
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-08-26 16:18:21 +00:00
|
|
|
if(role == Qt::DisplayRole){
|
|
|
|
divedatapoint p = divepoints.at(index.row());
|
|
|
|
switch(index.column()){
|
2013-09-09 09:48:03 +00:00
|
|
|
case CCSETPOINT: return p.po2;
|
2013-08-26 19:38:12 +00:00
|
|
|
case DEPTH: return p.depth / 1000;
|
|
|
|
case DURATION: return p.time / 60;
|
2013-08-30 18:06:26 +00:00
|
|
|
case GAS: return strForAir(p);
|
2013-08-26 16:18:21 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-02 19:21:08 +00:00
|
|
|
else if (role == Qt::DecorationRole){
|
2013-08-28 10:27:59 +00:00
|
|
|
switch(index.column()){
|
|
|
|
case REMOVE : return QIcon(":trash");
|
|
|
|
}
|
|
|
|
}
|
2013-09-02 19:21:08 +00:00
|
|
|
else if (role == Qt::FontRole){
|
|
|
|
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-08-30 16:27:15 +00:00
|
|
|
if(role == Qt::EditRole){
|
|
|
|
divedatapoint& p = divepoints[index.row()];
|
|
|
|
switch(index.column()){
|
|
|
|
case DEPTH: p.depth = value.toInt() * 1000; break;
|
|
|
|
case DURATION: p.time = value.toInt() * 60; break;
|
2013-09-09 09:48:03 +00:00
|
|
|
case CCSETPOINT:{
|
|
|
|
int po2 = 0;
|
|
|
|
QByteArray gasv = value.toByteArray();
|
|
|
|
if (validate_po2(gasv.data(), &po2))
|
|
|
|
p.po2 = po2;
|
|
|
|
} break;
|
2013-08-30 18:06:26 +00:00
|
|
|
case GAS: {
|
|
|
|
int o2 = 0;
|
|
|
|
int he = 0;
|
|
|
|
QByteArray gasv = value.toByteArray();
|
|
|
|
if (validate_gas(gasv.data(), &o2, &he)) {
|
|
|
|
p.o2 = o2;
|
|
|
|
p.he = he;
|
|
|
|
}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-08-26 16:18:21 +00:00
|
|
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal){
|
2013-08-26 12:14:19 +00:00
|
|
|
switch(section){
|
|
|
|
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-02 19:21:08 +00:00
|
|
|
else if (role == Qt::FontRole){
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
DivePlannerPointsModel::DivePlannerPointsModel(QObject* parent): QAbstractTableModel(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DivePlannerPointsModel* DivePlannerPointsModel::instance()
|
|
|
|
{
|
|
|
|
static DivePlannerPointsModel* self = new DivePlannerPointsModel();
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2013-08-26 16:18:21 +00:00
|
|
|
void DivePlannerPointsModel::createPlan()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::setGFHigh(short int gfhigh)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::setGFLow(short int ghflow)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivePlannerPointsModel::setStartTime(const QTime& t)
|
|
|
|
{
|
|
|
|
diveplan.when = t.msec();
|
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-08-26 20:02:34 +00:00
|
|
|
bool divePointsLessThan(const divedatapoint& p1, const divedatapoint& p2){
|
|
|
|
return p1.time <= p2.time;
|
|
|
|
}
|
2013-08-26 16:18:21 +00:00
|
|
|
int DivePlannerPointsModel::addStop(int meters, int minutes, const QString& gas, int ccpoint)
|
|
|
|
{
|
|
|
|
int row = divepoints.count();
|
2013-09-09 22:57:22 +00:00
|
|
|
if(meters == 0 && minutes == 0){
|
|
|
|
if(row == 0){
|
|
|
|
meters = 10000;
|
|
|
|
minutes = 600;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
divedatapoint p = at(row-1);
|
|
|
|
meters = p.depth;
|
|
|
|
minutes = p.time + 600;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-26 19:55:30 +00:00
|
|
|
// check if there's already a new stop before this one:
|
2013-08-26 20:02:34 +00:00
|
|
|
for(int i = 0; i < divepoints.count(); i++){
|
|
|
|
const divedatapoint& dp = divepoints.at(i);
|
2013-08-26 19:55:30 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the new stop
|
2013-08-26 16:18:21 +00:00
|
|
|
beginInsertRows(QModelIndex(), row, row);
|
|
|
|
divedatapoint point;
|
|
|
|
point.depth = meters;
|
|
|
|
point.time = minutes;
|
2013-09-09 20:45:03 +00:00
|
|
|
if (row == 0){
|
|
|
|
point.o2 = 209;
|
|
|
|
point.he = 0;
|
|
|
|
point.po2 = 0;
|
|
|
|
}else{
|
|
|
|
divedatapoint before = at(row-1);
|
|
|
|
point.o2 = before.o2;
|
|
|
|
point.he = before.he;
|
2013-09-09 22:57:22 +00:00
|
|
|
point.po2 = 0;
|
2013-09-09 20:45:03 +00:00
|
|
|
}
|
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-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()
|
|
|
|
{
|
|
|
|
if(rowCount()){
|
|
|
|
if (QMessageBox::warning(mainWindow(), tr("Save the Plan?"),
|
|
|
|
tr("You have a working plan, \n are you sure that you wanna cancel it?"),
|
|
|
|
QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
beginRemoveRows(QModelIndex(), 0, rowCount()-1);
|
|
|
|
divepoints.clear();
|
|
|
|
endRemoveRows();
|
|
|
|
emit planCanceled();
|
|
|
|
}
|