mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Merge branch 'Planner'
This commit is contained in:
commit
9cc8e39d42
12 changed files with 87 additions and 72 deletions
|
@ -59,13 +59,15 @@ void DivePlannerPointsModel::removeSelectedPoints(const QVector<int> &rows)
|
|||
endRemoveRows();
|
||||
}
|
||||
|
||||
void DivePlannerPointsModel::createSimpleDive()
|
||||
void DivePlannerPointsModel::createSimpleDive(bool planner)
|
||||
{
|
||||
// plannerModel->addStop(0, 0, O2_IN_AIR, 0, 0);
|
||||
plannerModel->addStop(M_OR_FT(15, 45), 1 * 60, O2_IN_AIR, 0, 0, true);
|
||||
plannerModel->addStop(M_OR_FT(15, 45), 40 * 60, O2_IN_AIR, 0, 0, true);
|
||||
plannerModel->addStop(M_OR_FT(5, 15), 42 * 60, O2_IN_AIR, 0, 0, true);
|
||||
plannerModel->addStop(M_OR_FT(5, 15), 45 * 60, O2_IN_AIR, 0, 0, true);
|
||||
if (!planner) {
|
||||
plannerModel->addStop(M_OR_FT(5, 15), 42 * 60, O2_IN_AIR, 0, 0, true);
|
||||
plannerModel->addStop(M_OR_FT(5, 15), 45 * 60, O2_IN_AIR, 0, 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
void DivePlannerPointsModel::loadFromDive(dive *d)
|
||||
|
@ -215,9 +217,7 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
|
|||
QTableView *view = ui.cylinderTableWidget->view();
|
||||
view->setColumnHidden(CylindersModel::START, true);
|
||||
view->setColumnHidden(CylindersModel::END, true);
|
||||
#ifdef ENABLE_PLANNER
|
||||
view->setColumnHidden(CylindersModel::DEPTH, false);
|
||||
#endif
|
||||
view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this));
|
||||
connect(ui.cylinderTableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addCylinder_clicked()));
|
||||
connect(ui.tableWidget, SIGNAL(addButtonClicked()), DivePlannerPointsModel::instance(), SLOT(addStop()));
|
||||
|
@ -783,7 +783,7 @@ void DivePlannerPointsModel::createTemporaryPlan()
|
|||
#endif
|
||||
if (plannerModel->recalcQ())
|
||||
plan(&diveplan, &cache, &tempDive, isPlanner());
|
||||
if (mode == ADD) {
|
||||
if (mode == ADD || mode == PLAN) {
|
||||
// copy the samples and events, but don't overwrite the cylinders
|
||||
copy_samples(tempDive, current_dive);
|
||||
copy_events(tempDive, current_dive);
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
void removeSelectedPoints(const QVector<int> &rows);
|
||||
void setPlanMode(Mode mode);
|
||||
bool isPlanner();
|
||||
void createSimpleDive();
|
||||
void createSimpleDive(bool planner = false);
|
||||
void clear();
|
||||
Mode currentMode() const;
|
||||
bool setRecalc(bool recalc);
|
||||
|
|
|
@ -88,9 +88,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
|||
|
||||
ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this));
|
||||
ui.weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate(this));
|
||||
#ifdef ENABLE_PLANNER
|
||||
ui.cylinders->view()->setColumnHidden(CylindersModel::DEPTH, true);
|
||||
#endif
|
||||
completers.buddy = new QCompleter(&buddyModel, ui.buddy);
|
||||
completers.divemaster = new QCompleter(&diveMasterModel, ui.divemaster);
|
||||
completers.location = new QCompleter(&locationModel, ui.location);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <QStringList>
|
||||
#include <QSettings>
|
||||
#include <QShortcut>
|
||||
#include <fcntl.h>
|
||||
#include "divelistview.h"
|
||||
#include "starwidget.h"
|
||||
|
||||
|
@ -87,9 +88,6 @@ MainWindow::MainWindow() : QMainWindow(),
|
|||
ui.ListWidget->scrollTo(ui.ListWidget->model()->index(0, 0), QAbstractItemView::PositionAtCenter);
|
||||
ui.divePlannerWidget->settingsChanged();
|
||||
|
||||
#ifndef ENABLE_PLANNER
|
||||
ui.menuLog->removeAction(ui.actionDivePlanner);
|
||||
#endif
|
||||
#ifdef NO_MARBLE
|
||||
ui.layoutWidget->hide();
|
||||
ui.menuView->removeAction(ui.actionViewGlobe);
|
||||
|
@ -298,29 +296,6 @@ void MainWindow::enableDcShortcuts()
|
|||
ui.actionNextDC->setShortcut(Qt::Key_Right);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionDivePlanner_triggered()
|
||||
{
|
||||
int i;
|
||||
struct dive *dive;
|
||||
if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING ||
|
||||
ui.InfoWidget->isEditing()) {
|
||||
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to plan a dive."));
|
||||
return;
|
||||
}
|
||||
disableDcShortcuts();
|
||||
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN);
|
||||
DivePlannerPointsModel::instance()->clear();
|
||||
CylindersModel::instance()->clear();
|
||||
for_each_dive (i, dive) {
|
||||
if (dive->selected) {
|
||||
DivePlannerPointsModel::instance()->copyCylindersFrom(dive);
|
||||
CylindersModel::instance()->copyFromDive(dive);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ui.infoPane->setCurrentIndex(PLANNERWIDGET);
|
||||
}
|
||||
|
||||
void MainWindow::showProfile()
|
||||
{
|
||||
enableDcShortcuts();
|
||||
|
@ -381,18 +356,18 @@ void MainWindow::on_actionEditDeviceNames_triggered()
|
|||
DiveComputerManagementDialog::instance()->show();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAddDive_triggered()
|
||||
bool MainWindow::plannerStateClean()
|
||||
{
|
||||
if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING ||
|
||||
ui.InfoWidget->isEditing()) {
|
||||
QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to add a dive."));
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
dive_list()->rememberSelection();
|
||||
dive_list()->unselectDives();
|
||||
disableDcShortcuts();
|
||||
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::createFakeDiveForAddAndPlan()
|
||||
{
|
||||
// now cheat - create one dive that we use to store the info tab data in
|
||||
//TODO: C-function create_temporary_dive ?
|
||||
struct dive *dive = alloc_dive();
|
||||
|
@ -405,8 +380,53 @@ void MainWindow::on_actionAddDive_triggered()
|
|||
// this isn't in the UI yet, so let's call the C helper function - we'll fix this up when
|
||||
// accepting the dive
|
||||
select_dive(get_divenr(dive));
|
||||
ui.InfoWidget->setCurrentIndex(0);
|
||||
ui.InfoWidget->updateDiveInfo(selected_dive);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionDivePlanner_triggered()
|
||||
{
|
||||
if(!plannerStateClean())
|
||||
return;
|
||||
|
||||
dive_list()->rememberSelection();
|
||||
dive_list()->unselectDives();
|
||||
|
||||
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
|
||||
DivePlannerPointsModel::instance()->clear();
|
||||
CylindersModel::instance()->clear();
|
||||
int i;
|
||||
struct dive *dive;
|
||||
for_each_dive (i, dive) {
|
||||
if (dive->selected) {
|
||||
DivePlannerPointsModel::instance()->copyCylindersFrom(dive);
|
||||
CylindersModel::instance()->copyFromDive(dive);
|
||||
break;
|
||||
}
|
||||
}
|
||||
createFakeDiveForAddAndPlan();
|
||||
|
||||
ui.InfoWidget->setCurrentIndex(0);
|
||||
ui.infoPane->setCurrentIndex(MAINTAB);
|
||||
|
||||
ui.newProfile->setPlanState();
|
||||
ui.infoPane->setCurrentIndex(PLANNERWIDGET);
|
||||
DivePlannerPointsModel::instance()->clear();
|
||||
DivePlannerPointsModel::instance()->createSimpleDive(true);
|
||||
ui.ListWidget->reload(DiveTripModel::CURRENT);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAddDive_triggered()
|
||||
{
|
||||
if(!plannerStateClean())
|
||||
return;
|
||||
|
||||
dive_list()->rememberSelection();
|
||||
dive_list()->unselectDives();
|
||||
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
|
||||
|
||||
createFakeDiveForAddAndPlan();
|
||||
|
||||
ui.InfoWidget->setCurrentIndex(0);
|
||||
ui.InfoWidget->addDiveStarted();
|
||||
ui.infoPane->setCurrentIndex(MAINTAB);
|
||||
|
||||
|
|
|
@ -172,6 +172,9 @@ private:
|
|||
void updateLastUsedDir(const QString &s);
|
||||
bool filesAsArguments;
|
||||
UpdateManager *updateManager;
|
||||
|
||||
bool plannerStateClean();
|
||||
void createFakeDiveForAddAndPlan();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -67,9 +67,7 @@ CylindersModel::CylindersModel(QObject *parent) : current(0), rows(0)
|
|||
{
|
||||
// enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH};
|
||||
setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("WorkPress") << tr("StartPress") << tr("EndPress") << trUtf8("O" UTF8_SUBSCRIPT_2 "%") << tr("He%")
|
||||
#ifdef ENABLE_PLANNER
|
||||
<< tr("Switch at")
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -145,11 +143,9 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
|
|||
case HE:
|
||||
ret = percent_string(cyl->gasmix.he);
|
||||
break;
|
||||
#ifdef ENABLE_PLANNER
|
||||
case DEPTH:
|
||||
ret = get_depth_string(cyl->depth, true);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case Qt::DecorationRole:
|
||||
|
@ -265,13 +261,11 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
|
|||
changed = true;
|
||||
}
|
||||
break;
|
||||
#ifdef ENABLE_PLANNER
|
||||
case DEPTH:
|
||||
if (CHANGED()) {
|
||||
cyl->depth = string_to_depth(vString.toUtf8().data());
|
||||
changed = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
dataChanged(index, index);
|
||||
if (addDiveMode)
|
||||
|
|
|
@ -102,9 +102,7 @@ public:
|
|||
END,
|
||||
O2,
|
||||
HE,
|
||||
#ifdef ENABLE_PLANNER
|
||||
DEPTH,
|
||||
#endif
|
||||
COLUMNS
|
||||
};
|
||||
|
||||
|
|
|
@ -363,7 +363,7 @@ void ProfileWidget2::plotDives(QList<dive *> dives)
|
|||
//TODO: This is a temporary hack to help me understand the Planner.
|
||||
// It seems that each time the 'createTemporaryPlan' runs, a new
|
||||
// dive is created, and thus, we can plot that. hm...
|
||||
if (currentState == ADD) {
|
||||
if (currentState == ADD || currentState == PLAN) {
|
||||
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
|
||||
plannerModel->createTemporaryPlan();
|
||||
if (!plannerModel->getDiveplan().dp) {
|
||||
|
@ -509,7 +509,7 @@ void ProfileWidget2::plotDives(QList<dive *> dives)
|
|||
prefs.animation = animSpeedBackup;
|
||||
}
|
||||
|
||||
if (currentState == ADD) { // TODO: figure a way to move this from here.
|
||||
if (currentState == ADD || currentState == PLAN) { // TODO: figure a way to move this from here.
|
||||
repositionDiveHandlers();
|
||||
DivePlannerPointsModel *model = DivePlannerPointsModel::instance();
|
||||
model->deleteTemporaryPlan();
|
||||
|
@ -770,8 +770,25 @@ void ProfileWidget2::setPlanState()
|
|||
{
|
||||
if (currentState == PLAN)
|
||||
return;
|
||||
|
||||
setProfileState();
|
||||
disconnectTemporaryConnections();
|
||||
//TODO: Move this method to another place, shouldn't be on mainwindow.
|
||||
MainWindow::instance()->disableDcShortcuts();
|
||||
actionsForKeys[Qt::Key_Left]->setShortcut(Qt::Key_Left);
|
||||
actionsForKeys[Qt::Key_Right]->setShortcut(Qt::Key_Right);
|
||||
actionsForKeys[Qt::Key_Up]->setShortcut(Qt::Key_Up);
|
||||
actionsForKeys[Qt::Key_Down]->setShortcut(Qt::Key_Down);
|
||||
actionsForKeys[Qt::Key_Escape]->setShortcut(Qt::Key_Escape);
|
||||
actionsForKeys[Qt::Key_Delete]->setShortcut(Qt::Key_Delete);
|
||||
|
||||
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
|
||||
connect(plannerModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(replot()));
|
||||
connect(plannerModel, SIGNAL(cylinderModelEdited()), this, SLOT(replot()));
|
||||
connect(plannerModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
|
||||
this, SLOT(pointInserted(const QModelIndex &, int, int)));
|
||||
connect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
|
||||
this, SLOT(pointsRemoved(const QModelIndex &, int, int)));
|
||||
/* show the same stuff that the profile shows. */
|
||||
currentState = PLAN; /* enable the add state. */
|
||||
setBackgroundBrush(QColor(Qt::green).light());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue