Skip to content

Commit

Permalink
Refactor GroupPlot to use modern C++ initialization and improve code …
Browse files Browse the repository at this point in the history
…clarity.
  • Loading branch information
przemek83 committed Jan 9, 2025
1 parent 7a7c9bb commit b0351e7
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/GroupPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

GroupPlot::GroupPlot(QWidget* parent)
: PlotBase(tr("Grouping"), parent),
marker_(new NotchedMarker({})),
picker_(new YAxisNumberPicker(canvas()))
marker_{std::make_unique<NotchedMarker>(QVector<Quantiles>{})},
picker_{std::make_unique<YAxisNumberPicker>(canvas())}
{
setStdScaleDraw(yRight);

Expand All @@ -21,7 +21,7 @@ GroupPlot::GroupPlot(QWidget* parent)
enableAxis(QwtPlot::yRight, true);

setAxisScaleDraw(xBottom, new StringsScaleDraw({}));
QFont font = axisFont(QwtPlot::xBottom);
QFont font{axisFont(QwtPlot::xBottom)};
font.setStyleStrategy(QFont::PreferAntialias);
setAxisFont(QwtPlot::xBottom, font);
}
Expand All @@ -33,8 +33,8 @@ void GroupPlot::setNewData(QVector<Quantiles> quantilesVector,
const QVector<QString>& intervalStrings)
{
tooltips_ = createTooltips(intervalStrings, quantilesVector);
QVector<QString> shortIntervalNames =
createAxisIntervalsNames(intervalStrings, quantilesVector);
QVector<QString> shortIntervalNames{
createAxisIntervalsNames(intervalStrings, quantilesVector)};
setAxisScaleDraw(xBottom,
new StringsScaleDraw(std::move(shortIntervalNames)));
marker_->setQuantiles(std::move(quantilesVector));
Expand All @@ -51,17 +51,18 @@ QVector<QString> GroupPlot::createAxisIntervalsNames(
{
QVector<QString> shortenNames;
shortenNames.reserve(intervalsNames.size());
const QString moreChars(QStringLiteral("..."));
for (int i = 0; i < intervalsNames.size(); ++i)
const QString moreChars{QStringLiteral("...")};
const qsizetype size{intervalsNames.size()};
for (qsizetype i{0}; i < size; ++i)
{
QString name = intervalsNames[i];
const QString countString =
QString(" (" + QString::number(quantilesVector[i].count_) + ")");
QString name{intervalsNames[i]};
const QString countString{
" (" + QString::number(quantilesVector[i].count_) + ")"};

if (name.size() + countString.size() > maxCharsInLabel_)
if ((name.size() + countString.size()) > maxCharsInLabel_)
{
name.chop(name.size() - maxCharsInLabel_ + countString.size() +
moreChars.size());
name.chop(name.size() - (maxCharsInLabel_ + countString.size() +
moreChars.size()));
name.append(moreChars);
}
name.append(countString);
Expand All @@ -75,8 +76,9 @@ QVector<QString> GroupPlot::createTooltips(
const QVector<Quantiles>& quantilesVector)
{
QVector<QString> tooltips;
tooltips.reserve(intervalsNames.size());
for (int i = 0; i < intervalsNames.size(); ++i)
const qsizetype size{intervalsNames.size()};
tooltips.reserve(size);
for (qsizetype i{0}; i < size; ++i)
tooltips.append("<B>" + intervalsNames.at(i) + "</B></BR>" +
quantilesVector.at(i).getValuesAsToolTip());
return tooltips;
Expand All @@ -93,8 +95,9 @@ bool GroupPlot::event(QEvent* event)
{
if (event->type() == QEvent::ToolTip)
{
const int x = picker_->getAreaOfMouse();
if (x >= 1 && x <= tooltips_.size() && picker_->getMouseInWidget())
const int x{picker_->getAreaOfMouse()};
if ((x >= 1) && (x <= tooltips_.size()) &&
(picker_->getMouseInWidget()))
{
setToolTip(tooltips_[x - 1]);
}
Expand Down

0 comments on commit b0351e7

Please sign in to comment.