Skip to content

Commit

Permalink
- issue 3235: rescale only when not zoomed or moved
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed May 14, 2024
1 parent 14cf465 commit f98b225
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
20 changes: 18 additions & 2 deletions copasi/plotUI/CQCustomPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,8 +1407,12 @@ bool CQCustomPlot::saveData(const std::string & filename)

void CQCustomPlot::setCurvesVisibility(const bool & visibility)
{
// we want to rescale only if we are not hiding (visibility = true)
// and we did not moved / zoomed
bool shouldRescale = visibility && !wasMovedOrZoomed();

for (int i = 0; i < this->plottableCount(); ++i)
showCurve(plottable(i), visibility, visibility);
showCurve(plottable(i), visibility, shouldRescale);

QCustomPlot::replot();
}
Expand Down Expand Up @@ -2259,7 +2263,11 @@ void CQCustomPlot::legendClicked(QCPLegend * legend, QCPAbstractLegendItem * ite
if (plItem != NULL && event->button() == Qt::LeftButton)
{
auto * pCurve = plItem->plottable();
showCurve(pCurve, !pCurve->visible(), false);

// QWT rescales on click only if not zoomed in:
bool wasMoved = wasMovedOrZoomed();

showCurve(pCurve, !pCurve->visible(), !wasMoved);
//replot(false);
QCustomPlot::replot();
}
Expand Down Expand Up @@ -2423,6 +2431,14 @@ void CQCustomPlot::ensureCurvesVisible()
// increase axis a little bit, so that values at border are visible
increaseRange(xAxis);
increaseRange(yAxis, 1);

mOldX = xAxis->range();
mOldY = yAxis->range();
}

bool CQCustomPlot::wasMovedOrZoomed()
{
return mOldX != xAxis->range() || mOldY != yAxis->range();
}

#endif // COPASI_USE_QCUSTOMPLOT
3 changes: 3 additions & 0 deletions copasi/plotUI/CQCustomPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public slots:
std::set< std::string > getDependentObjectNames(const CDataModel & model);
void initializeIndependentData(const CDataModel & model);
void ensureCurvesVisible();
bool wasMovedOrZoomed();

private slots:
/**
Expand Down Expand Up @@ -354,6 +355,8 @@ private slots:
QScrollBar * mpScrollbar;
QLineEdit * mpMaxLegend;
QLabel * mpPosLabel;
QCPRange mOldX;
QCPRange mOldY;

signals:
void replotSignal();
Expand Down

0 comments on commit f98b225

Please sign in to comment.