diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-01-07 11:57:20 +0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-01-07 12:10:19 +0800 |
commit | c3fe1a9e9f79c77c533642df4f986238ef08452b (patch) | |
tree | 38236bef570eb5e955a6b8470e62a2917b706b34 /qt-ui/profilegraphics.cpp | |
parent | 9c617534a050ec0a0afd84ef578d7c6d0e800a59 (diff) | |
download | subsurface-c3fe1a9e9f79c77c533642df4f986238ef08452b.tar.gz |
Get rid of pointers to dive structures in the UI
The assumption that the pointer will keep pointing to a valid structure is
fundamentally flawed. And even if that is true today, it might change in
the future - just don't do it. Use the diveId instead.
The exception is when you own the structure and use it within one UI
interaction during which any way to change the dive_table is disabled
(e.g., while adding / editing a dive).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profilegraphics.cpp')
-rw-r--r-- | qt-ui/profilegraphics.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index 76eb64b84..5bb55d11b 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -52,7 +52,7 @@ extern int evn_used; QPoint(viewport()->geometry().width() - toolBarProxy->boundingRect().width(), \ viewport()->geometry().height() - toolBarProxy->boundingRect().height() ) -ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent), toolTip(0) , dive(0), diveDC(0), rulerItem(0), toolBarProxy(0) +ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent), toolTip(0) , diveId(0), diveDC(0), rulerItem(0), toolBarProxy(0) { printMode = false; isGrayscale = false; @@ -313,8 +313,8 @@ void ProfileGraphicsView::showEvent(QShowEvent* event) // but the dive was not ploted. // force a replot by modifying the dive // hold by the view, and issuing a plot. - if (dive && !scene()->items().count()) { - dive = 0; + if (diveId && !scene()->items().count()) { + diveId = 0; plot(get_dive(selected_dive)); } if (toolBarProxy) @@ -369,14 +369,14 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw) if (d) dc = select_dc(&d->dc); - if (!forceRedraw && dive == d && (d && dc == diveDC)) + if (!forceRedraw && getDiveById(diveId) == d && (d && dc == diveDC)) return; clear(); - dive = d; + diveId = d ? d->id : 0; diveDC = d ? dc : NULL; - if (!isVisible() || !dive || !mainWindow()) { + if (!isVisible() || !d || !mainWindow()) { return; } setBackgroundBrush(getColor(BACKGROUND)); @@ -415,14 +415,14 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw) * Set up limits that are independent of * the dive computer */ - calculate_max_limits(dive, dc, &gc); + calculate_max_limits(d, dc, &gc); QRectF profile_grid_area = scene()->sceneRect(); gc.maxx = (profile_grid_area.width() - 2 * profile_grid_area.x()); gc.maxy = (profile_grid_area.height() - 2 * profile_grid_area.y()); /* This is per-dive-computer */ - gc.pi = *create_plot_info(dive, dc, &gc, printMode); + gc.pi = *create_plot_info(d, dc, &gc, printMode); /* Bounding box */ QPen pen = defaultPen; @@ -483,7 +483,7 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw) if(mode == PLAN){ timeEditor = new GraphicsTextEditor(); - timeEditor->setPlainText( dive->duration.seconds ? QString::number(dive->duration.seconds/60) : tr("Set Duration: 10 minutes")); + timeEditor->setPlainText(d->duration.seconds ? QString::number(d->duration.seconds/60) : tr("Set Duration: 10 minutes")); timeEditor->setPos(profile_grid_area.width() - timeEditor->boundingRect().width(), timeMarkers->y()); timeEditor->document(); connect(timeEditor, SIGNAL(editingFinished(QString)), this, SLOT(edit_dive_time(QString))); @@ -720,6 +720,8 @@ void ProfileGraphicsView::plot_cylinder_pressure_text() int last_time[MAX_CYLINDERS] = { 0, }; struct plot_data *entry; struct plot_info *pi = &gc.pi; + struct dive *dive = getDiveById(diveId); + Q_ASSERT(dive != NULL); if (!get_cylinder_pressure_range(&gc)) return; @@ -888,6 +890,8 @@ void ProfileGraphicsView::plot_cylinder_pressure() if (!get_cylinder_pressure_range(&gc)) return; + struct dive *dive = getDiveById(diveId); + Q_ASSERT(dive != NULL); QPointF from, to; for (i = 0; i < gc.pi.nr; i++) { int mbar; @@ -1006,7 +1010,8 @@ void ProfileGraphicsView::plot_one_event(struct event *ev) int x = SCALEXGC(ev->time.seconds); int y = SCALEYGC(entry->depth); - + struct dive *dive = getDiveById(diveId); + Q_ASSERT(dive != NULL); EventItem *item = new EventItem(ev, 0, isGrayscale); item->setPos(x, y); scene()->addItem(item); |