I need help to figure out what's happening here, spend a whole day without a clear approach.
when the plannerModel->setState(ADD) things works, when the planer->setState(PLAN), things don't. ( calling this from the MainWindow::on_actionDivePlanner_triggered ) Patches:
From 65a432e7ac815bace6eb33472b393af7a8394f60 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sun, 25 May 2014 14:16:43 -0300 Subject: [PATCH 1/7] Re Enable the Planner on the new profile. This correctly enables the planner on the new profile, but it doesn't triggers the correct pait on the canvas. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/diveplanner.cpp | 2 -- qt-ui/maintab.cpp | 2 -- qt-ui/mainwindow.cpp | 4 +--- qt-ui/models.cpp | 6 ------ qt-ui/models.h | 2 -- qt-ui/profile/profilewidget2.cpp | 9 +++++++++ 6 files changed, 10 insertions(+), 15 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 3ffacdd..4fff796 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -215,9 +215,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())); diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 2bb2614..34be53a 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -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); diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 19a16a8..2bfeca6 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -87,9 +87,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); @@ -318,6 +315,7 @@ void MainWindow::on_actionDivePlanner_triggered() break; } } + ui.newProfile->setPlanState(); ui.infoPane->setCurrentIndex(PLANNERWIDGET); } diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index dc9a718..5efcf5a 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -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: @@ -263,13 +259,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) diff --git a/qt-ui/models.h b/qt-ui/models.h index 34d7d48..17be8cb 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -102,9 +102,7 @@ public: END, O2, HE, -#ifdef ENABLE_PLANNER DEPTH, -#endif COLUMNS }; diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 2de64e7..71a2f48 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -773,6 +773,15 @@ void ProfileWidget2::setPlanState() setProfileState(); disconnectTemporaryConnections(); /* show the same stuff that the profile shows. */ + + 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))); + currentState = PLAN; /* enable the add state. */ setBackgroundBrush(QColor(Qt::green).light()); } -- 1.9.3
From 5f2f7f05aae088698b03333fb0065e5cef73a4c2 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sun, 25 May 2014 15:12:00 -0300 Subject: [PATCH 2/7] Planner states Add and Plan have a similar behavior So, the code is equal. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/profile/profilewidget2.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 71a2f48..c3e010c 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -770,9 +770,17 @@ void ProfileWidget2::setPlanState() { if (currentState == PLAN) return; + setProfileState(); disconnectTemporaryConnections(); - /* show the same stuff that the profile shows. */ + //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())); @@ -781,7 +789,7 @@ void ProfileWidget2::setPlanState() 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()); } -- 1.9.3
From 951f39b4c53c50e4cd75954f16e58d228037f753 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sun, 25 May 2014 15:15:57 -0300 Subject: [PATCH 3/7] Move method down below to easy comparisson with another. planner and add states are driving me nuts. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/mainwindow.cpp | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 2bfeca6..801268a 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -295,30 +295,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.newProfile->setPlanState(); - ui.infoPane->setCurrentIndex(PLANNERWIDGET); -} - void MainWindow::showProfile() { enableDcShortcuts(); @@ -379,6 +355,30 @@ void MainWindow::on_actionEditDeviceNames_triggered() DiveComputerManagementDialog::instance()->show(); } +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.newProfile->setPlanState(); + ui.infoPane->setCurrentIndex(PLANNERWIDGET); +} + void MainWindow::on_actionAddDive_triggered() { if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING || -- 1.9.3
From d7e900ff36ccdd0f0343b29f258f5601ba905461 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sun, 25 May 2014 15:19:36 -0300 Subject: [PATCH 4/7] small code cleanup. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/mainwindow.cpp | 25 ++++++++++++++++--------- qt-ui/mainwindow.h | 2 ++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 801268a..a10dac2 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -355,15 +355,24 @@ void MainWindow::on_actionEditDeviceNames_triggered() DiveComputerManagementDialog::instance()->show(); } -void MainWindow::on_actionDivePlanner_triggered() +bool MainWindow::plannerStateClean() { - 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; + QMessageBox::warning(this, tr("Warning"), tr("Please save or cancel the current dive edit before trying to add a dive.")); + return false; } + return true; +} + +void MainWindow::on_actionDivePlanner_triggered() +{ + if (!plannerStateClean()) + return; + + int i; + struct dive *dive; + disableDcShortcuts(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); DivePlannerPointsModel::instance()->clear(); @@ -381,11 +390,9 @@ void MainWindow::on_actionDivePlanner_triggered() void MainWindow::on_actionAddDive_triggered() { - 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.")); + if(!plannerStateClean()) return; - } + dive_list()->rememberSelection(); dive_list()->unselectDives(); disableDcShortcuts(); diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index a658fe3..667e381 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -172,6 +172,8 @@ private: void updateLastUsedDir(const QString &s); bool filesAsArguments; UpdateManager *updateManager; + + bool plannerStateClean(); }; #endif // MAINWINDOW_H -- 1.9.3
From 03d37e7b94069513bead69facd67f46cf189a0cb Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sun, 25 May 2014 15:36:34 -0300 Subject: [PATCH 5/7] remove uneeded call. The disableDcShortcuts is called inside of the ProfileGraphics ( I actually think that this method should be moved to there ) Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/mainwindow.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index a10dac2..1062e43 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -373,7 +373,6 @@ void MainWindow::on_actionDivePlanner_triggered() int i; struct dive *dive; - disableDcShortcuts(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); DivePlannerPointsModel::instance()->clear(); CylindersModel::instance()->clear(); @@ -395,7 +394,6 @@ void MainWindow::on_actionAddDive_triggered() dive_list()->rememberSelection(); dive_list()->unselectDives(); - disableDcShortcuts(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); // now cheat - create one dive that we use to store the info tab data in -- 1.9.3
From 481151df395f652ca40c4e7782a0135c1ec58806 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sun, 25 May 2014 15:56:39 -0300 Subject: [PATCH 6/7] Created a function to create a fake dive for Add and Plan states. This function should likely to move to C in the future, I'm only adding this here because I'm changing this file so much ( already 4 rewrotes of the function ) Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/mainwindow.cpp | 32 ++++++++++++++++++++------------ qt-ui/mainwindow.h | 1 + 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 1062e43..827401a 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -20,6 +20,7 @@ #include <QStringList> #include <QSettings> #include <QShortcut> +#include <fcntl.h> #include "divelistview.h" #include "starwidget.h" @@ -365,6 +366,24 @@ bool MainWindow::plannerStateClean() 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(); + dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset(); + dive->dc.model = "manually added dive"; // don't translate! this is stored in the XML file + + dive->latitude.udeg = 0; + dive->longitude.udeg = 0; + record_dive(dive); + // 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->updateDiveInfo(selected_dive); +} + + void MainWindow::on_actionDivePlanner_triggered() { if (!plannerStateClean()) @@ -396,20 +415,9 @@ void MainWindow::on_actionAddDive_triggered() dive_list()->unselectDives(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); - // 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(); - dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset(); - dive->dc.model = "manually added dive"; // don't translate! this is stored in the XML file + createFakeDiveForAddAndPlan(); - dive->latitude.udeg = 0; - dive->longitude.udeg = 0; - record_dive(dive); - // 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); ui.InfoWidget->addDiveStarted(); ui.infoPane->setCurrentIndex(MAINTAB); diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 667e381..8bb62b9 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -174,6 +174,7 @@ private: UpdateManager *updateManager; bool plannerStateClean(); + void createFakeDiveForAddAndPlan(); }; #endif // MAINWINDOW_H -- 1.9.3
From aadc20b4119459bd8ba852e73b5485d28ac93624 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sun, 25 May 2014 17:49:26 -0300 Subject: [PATCH 7/7] Make the planner show something. This is working in the wrong way, mostly because I'm setting the plannermodel to ADD state ( and the planner graphic to the correct PLAN state ), but I don't know why - when on PLAN state on the model, things just don't work. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/mainwindow.cpp | 19 ++++++++++++++----- qt-ui/profile/profilewidget2.cpp | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 827401a..ac02527 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -383,18 +383,19 @@ void MainWindow::createFakeDiveForAddAndPlan() ui.InfoWidget->updateDiveInfo(selected_dive); } - void MainWindow::on_actionDivePlanner_triggered() { - if (!plannerStateClean()) + if(!plannerStateClean()) return; - int i; - struct dive *dive; + dive_list()->rememberSelection(); + dive_list()->unselectDives(); - DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); + 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); @@ -402,8 +403,16 @@ void MainWindow::on_actionDivePlanner_triggered() break; } } + createFakeDiveForAddAndPlan(); + + ui.InfoWidget->setCurrentIndex(0); + ui.infoPane->setCurrentIndex(MAINTAB); + ui.newProfile->setPlanState(); ui.infoPane->setCurrentIndex(PLANNERWIDGET); + DivePlannerPointsModel::instance()->clear(); + DivePlannerPointsModel::instance()->createSimpleDive(); + ui.ListWidget->reload(DiveTripModel::CURRENT); } void MainWindow::on_actionAddDive_triggered() diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index c3e010c..28a0740 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -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(); -- 1.9.3
_______________________________________________ subsurface mailing list [email protected] http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
