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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-10-30 08:55:59 +01:00 committed by Dirk Hohndel
parent 261f07dfa4
commit 9bca38afcf
2 changed files with 9 additions and 2 deletions

View file

@ -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;
}

View file

@ -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;