Skip to content

Commit

Permalink
Fixed QObject::connect.
Browse files Browse the repository at this point in the history
  • Loading branch information
shoops committed May 20, 2024
1 parent 7e8de8f commit c3cf3f6
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions copasi/plotUI/CQCustomPlot.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2022 - 2024 by Pedro Mendes, Rector and Visitors of the
// University of Virginia, University of Heidelberg, and University
// of Connecticut School of Medicine.
// All rights reserved.
// Copyright (C) 2022 - 2024 by Pedro Mendes, Rector and Visitors of the
// University of Virginia, University of Heidelberg, and University
// of Connecticut School of Medicine.
// All rights reserved.

#include <copasi/config.h>

Expand Down Expand Up @@ -1429,13 +1429,15 @@ void CQCustomPlot::setupStatusbar(QStatusBar * bar)

if (!mpPosLabel)
mpPosLabel = new QLabel("1 / 1", this);

bar->addPermanentWidget(mpPosLabel, 0);

if (!mpScrollbar)
{
mpScrollbar = new QScrollBar(Qt::Horizontal, this);
QObject::connect(mpScrollbar, &QScrollBar::valueChanged, this, &CQCustomPlot::setupLegend);
}

bar->addPermanentWidget(mpScrollbar, 1);

if (!mpMaxLegend)
Expand All @@ -1445,10 +1447,10 @@ void CQCustomPlot::setupStatusbar(QStatusBar * bar)
mpMaxLegend->setValue(9);
mpMaxLegend->setMinimum(1);
mpMaxLegend->setMaximum(1000);
QObject::connect(mpMaxLegend, &QSpinBox::valueChanged, this, &CQCustomPlot::setupLegend);
QObject::connect(mpMaxLegend, QOverload<int>::of(&QSpinBox::valueChanged), this, &CQCustomPlot::setupLegend);
}
bar->addPermanentWidget(mpMaxLegend, 0);

bar->addPermanentWidget(mpMaxLegend, 0);

setupLegend();
}
Expand Down Expand Up @@ -2266,7 +2268,7 @@ void CQCustomPlot::legendClicked(QCPLegend * legend, QCPAbstractLegendItem * ite
{
auto * pCurve = plItem->plottable();

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

showCurve(pCurve, !pCurve->visible(), !wasMoved);
Expand Down Expand Up @@ -2350,28 +2352,35 @@ void CQCustomPlot::setupLegend()
return;

int maxItems = mpMaxLegend->value();

if (maxItems == 0)
return;

int numItems = mCurves.size();
int numPages = floor((double)numItems / (double)maxItems);

if (numPages * maxItems >= numItems)
numPages -= 1;

int currentPage = mpScrollbar->value();

if (currentPage > numPages)
currentPage = numPages;

mpScrollbar->setMaximum(numPages);
mpPosLabel->setText(QString("%1 / %2").arg(currentPage+1).arg(numPages+1));
mpPosLabel->setText(QString("%1 / %2").arg(currentPage + 1).arg(numPages + 1));

legend->clearItems();

for (int i = (currentPage) *maxItems; i < ((currentPage+1) *maxItems) && i < numItems; ++i)
{
for (int i = (currentPage) * maxItems; i < ((currentPage + 1) *maxItems) && i < numItems; ++i)
{
auto * current = mCurves[i];

if (!current->addToLegend())
continue;

auto plItem = legend->itemWithPlottable(current);

if (!plItem)
continue;

Expand All @@ -2380,7 +2389,7 @@ void CQCustomPlot::setupLegend()
legendFont.setItalic(!current->visible());
legendFont.setBold(current->visible());
plItem->setFont(legendFont);
}
}

legend->setVisible(true);

Expand All @@ -2394,8 +2403,7 @@ void increaseRange(QCPAxis* axis, double lowerMultiplier = 1.0, double upperMult

QCPRange range = axis->range();
double offset = fabs(range.upper - range.lower) / 100;
axis->setRange(range.lower - lowerMultiplier * offset, range.upper + upperMultiplier*offset);

axis->setRange(range.lower - lowerMultiplier * offset, range.upper + upperMultiplier * offset);
}

void CQCustomPlot::showCurve(QCPAbstractPlottable * pCurve, bool on, bool rescale /* = true */)
Expand All @@ -2404,19 +2412,20 @@ void CQCustomPlot::showCurve(QCPAbstractPlottable * pCurve, bool on, bool rescal
return;

auto * plItem = legend->itemWithPlottable(pCurve);

if (plItem != NULL)
{
plItem->setVisible(true);
QFont legendFont = plItem->font();
legendFont.setItalic(!on);
legendFont.setBold(on);
plItem->setFont(legendFont);

assert(pCurve == plItem->plottable());
}

pCurve->setVisible(on);

auto pBuddy = mY2Map.find(pCurve);

if (pBuddy != mY2Map.end())
Expand Down

0 comments on commit c3cf3f6

Please sign in to comment.