From 9bca38afcfb9d90cf9e985d79f21182f0e1352b8 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 30 Oct 2022 08:55:59 +0100 Subject: [PATCH] profile: recalculate profile info when switching from empty state When the profile was to small, it would switch into empty state and clear the plot info. On resize events, the plot info is not recalculated. This means that when making the profile extremely small and then bigger, nothing is shown. This may also happen on startup. The profile is rendered into a 0x0 widget and then gets a resize event. Therefore, remember when the profile is empty and force a recalculation of the plot info. Signed-off-by: Berthold Stoeger --- profile-widget/profilescene.cpp | 10 ++++++++-- profile-widget/profilescene.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/profile-widget/profilescene.cpp b/profile-widget/profilescene.cpp index 4de13651f..211854746 100644 --- a/profile-widget/profilescene.cpp +++ b/profile-widget/profilescene.cpp @@ -90,6 +90,7 @@ ProfileScene::ProfileScene(double dpr, bool printMode, bool isGrayscale) : dpr(dpr), printMode(printMode), isGrayscale(isGrayscale), + empty(true), maxtime(-1), maxdepth(-1), profileYAxis(new DiveCartesianAxis(DiveCartesianAxis::Position::Left, true, 3, 0, TIME_GRID, Qt::red, true, true, @@ -200,6 +201,7 @@ void ProfileScene::clear() qDeleteAll(eventItems); eventItems.clear(); free_plot_info_data(&plotInfo); + empty = true; } static bool ppGraphsEnabled(const struct divecomputer *dc, bool simplified) @@ -429,6 +431,11 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM return; } + // If we come from the empty state, the plot info has to be recalculated. + if (empty) + keepPlotInfo = false; + empty = false; + int animSpeed = instant || printMode ? 0 : qPrefDisplay::animation_speed(); // A non-null planner_ds signals to create_plot_info_new that the dive is currently planned. @@ -465,9 +472,8 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM */ int newMaxDepth = get_maxdepth(&plotInfo); if (!calcMax) { - if (maxdepth < newMaxDepth) { + if (maxdepth < newMaxDepth) maxdepth = newMaxDepth; - } } else { maxdepth = newMaxDepth; } diff --git a/profile-widget/profilescene.h b/profile-widget/profilescene.h index eada4fb8d..5b1fbc93d 100644 --- a/profile-widget/profilescene.h +++ b/profile-widget/profilescene.h @@ -65,6 +65,7 @@ private: double dpr; // Device Pixel Ratio. A DPR of one corresponds to a "standard" PC screen. bool printMode; bool isGrayscale; + bool empty; // The profile currently shows nothing. int maxtime; int maxdepth;