but crashes if you have a divelist. be warned.
From 6fbd39e17f550632eeb4a7ccffbf0cbed27de265 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Wed, 28 May 2014 15:43:32 -0300 Subject: [PATCH] Fixes showing the Empty Profile when Add / Plan dive is cancelled.
for some reason the next selected dive is NULL after cancelling the plan. I'm investigating. This patch fixes the show of the empty profile and it also untangles some parts of the code, keeping the mainwindow where it should belong : the mainwindow. Signed-off-by: Tomaz Canabrava <[email protected]> --- qt-ui/diveplanner.cpp | 10 +++------- qt-ui/mainwindow.cpp | 9 +++++++++ qt-ui/mainwindow.h | 1 + qt-ui/profile/profilewidget2.cpp | 24 ++++++++++++------------ 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index e8e0b2c..6943283 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -256,7 +256,7 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg connect(ui.buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan())); connect(plannerModel, SIGNAL(planCreated()), MainWindow::instance(), SLOT(removeFakeDiveForAddAndPlan())); connect(plannerModel, SIGNAL(planCreated()), MainWindow::instance(), SLOT(showProfile())); - connect(plannerModel, SIGNAL(planCanceled()), MainWindow::instance(), SLOT(showProfile())); + connect(plannerModel, SIGNAL(planCanceled()), MainWindow::instance(), SLOT(planCanceled())); /* set defaults. */ ui.startTime->setTime(QTime(1, 0)); @@ -653,18 +653,14 @@ void DivePlannerPointsModel::cancelPlan() return; } } - // we unselected all dives earlier, so restore that first and then recreate the dive list - MainWindow::instance()->removeFakeDiveForAddAndPlan(); - MainWindow::instance()->dive_list()->restoreSelection(); - MainWindow::instance()->dive_list()->reload(DiveTripModel::CURRENT); - MainWindow::instance()->refreshDisplay(); - emit planCanceled(); + if (mode != ADD) { free(stagingDive); stagingDive = NULL; } setPlanMode(NOTHING); diveplan.dp = NULL; + emit planCanceled(); } DivePlannerPointsModel::Mode DivePlannerPointsModel::currentMode() const diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index ff932d3..6cf7160 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -397,6 +397,15 @@ void MainWindow::removeFakeDiveForAddAndPlan() delete_single_dive(idx); } +void MainWindow::planCanceled() +{ + removeFakeDiveForAddAndPlan(); + showProfile(); + dive_list()->restoreSelection(); + dive_list()->reload(DiveTripModel::CURRENT); + refreshDisplay(); +} + void MainWindow::on_actionDivePlanner_triggered() { if(!plannerStateClean()) diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 8825347..f34c7a5 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -152,6 +152,7 @@ slots: void showProfile(); void editCurrentDive(); void removeFakeDiveForAddAndPlan(); + void planCanceled(); private: Ui::MainWindow ui; diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 6cb2580..8f26687 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -88,7 +88,8 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent), rulerItem(new RulerItem2()), isGrayscale(false), printMode(false), - shouldCalculateMaxTime(true) + shouldCalculateMaxTime(true), + backgroundFile(":poster") { memset(&plotInfo, 0, sizeof(plotInfo)); @@ -566,9 +567,9 @@ void ProfileWidget2::mouseReleaseEvent(QMouseEvent *event) void ProfileWidget2::fixBackgroundPos() { + static QPixmap toBeScaled(backgroundFile); if (currentState != EMPTY) return; - QPixmap toBeScaled = QPixmap(backgroundFile); QPixmap p = toBeScaled.scaledToHeight(viewport()->height() - 40, Qt::SmoothTransformation); int x = viewport()->width() / 2 - p.width() / 2; int y = viewport()->height() / 2 - p.height() / 2; @@ -666,7 +667,6 @@ void ProfileWidget2::setEmptyState() currentState = EMPTY; MainWindow::instance()->setToolButtonsEnabled(false); - backgroundFile = QString(":poster"); fixBackgroundPos(); background->setVisible(true); @@ -684,12 +684,14 @@ void ProfileWidget2::setEmptyState() pn2GasItem->setVisible(false); po2GasItem->setVisible(false); pheGasItem->setVisible(false); - Q_FOREACH (DiveCalculatedTissue *tissue, allTissues) { - tissue->setVisible(false); - } - Q_FOREACH (DiveEventItem *event, eventItems) { - event->setVisible(false); - } + + #define HIDE_ALL(TYPE, CONTAINER) \ + Q_FOREACH (TYPE *item, CONTAINER) item->setVisible(false); + HIDE_ALL(DiveCalculatedTissue, allTissues); + HIDE_ALL(DiveEventItem, eventItems); + HIDE_ALL(DiveHandler, handles); + HIDE_ALL(QGraphicsSimpleTextItem, gases); + #undef HIDE_ALL } void ProfileWidget2::setProfileState() @@ -1030,10 +1032,8 @@ void ProfileWidget2::disconnectTemporaryConnections() disconnect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(pointsRemoved(const QModelIndex &, int, int))); - - Q_FOREACH (QAction *action, actionsForKeys.values()) { + Q_FOREACH (QAction *action, actionsForKeys.values()) action->setShortcut(QKeySequence()); - } } void ProfileWidget2::pointInserted(const QModelIndex &parent, int start, int end) -- 1.9.3
_______________________________________________ subsurface mailing list [email protected] http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
