From 1ddb07f2ee144c0565977ae2740ef494f2afeed7 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 16 Apr 2024 17:12:32 +0300 Subject: [PATCH] Refactoring. Avoid unnecessary copy by using a "const" reference. --- src/app/puzzle/xml/vplayoutfilewriter.cpp | 2 +- src/libs/vgeometry/vabstractcurve.cpp | 2 +- src/libs/vpatterndb/testpassmark.cpp | 2 +- src/libs/vtools/tools/toolsdef.cpp | 2 +- src/test/ValentinaTest/tst_vposter.cpp | 16 ++++++++-------- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/app/puzzle/xml/vplayoutfilewriter.cpp b/src/app/puzzle/xml/vplayoutfilewriter.cpp index 56824754e..c8e079960 100644 --- a/src/app/puzzle/xml/vplayoutfilewriter.cpp +++ b/src/app/puzzle/xml/vplayoutfilewriter.cpp @@ -95,7 +95,7 @@ auto LinesToString(const QVector &lines) -> QString { QStringList l; l.reserve(lines.size()); - for (auto line : lines) + for (const auto &line : lines) { l.append(LineToString(line)); } diff --git a/src/libs/vgeometry/vabstractcurve.cpp b/src/libs/vgeometry/vabstractcurve.cpp index cc4be22d3..a3d991892 100644 --- a/src/libs/vgeometry/vabstractcurve.cpp +++ b/src/libs/vgeometry/vabstractcurve.cpp @@ -611,7 +611,7 @@ auto VAbstractCurve::ShowDirection(const QVector &arrows, qreal { QPainterPath path; - for (auto arrow : arrows) + for (const auto &arrow : arrows) { if (not arrow.first.isNull() && not arrow.second.isNull()) { diff --git a/src/libs/vpatterndb/testpassmark.cpp b/src/libs/vpatterndb/testpassmark.cpp index 3c5c3a2fa..bcdf0eb44 100644 --- a/src/libs/vpatterndb/testpassmark.cpp +++ b/src/libs/vpatterndb/testpassmark.cpp @@ -44,7 +44,7 @@ namespace auto PassmarkShapeToJson(const QVector &shape) -> QJsonArray { QJsonArray shapeArray; - for (auto line : shape) + for (const auto &line : shape) { QJsonObject const lineObject{ {"type", "QLineF"}, diff --git a/src/libs/vtools/tools/toolsdef.cpp b/src/libs/vtools/tools/toolsdef.cpp index 479a8802e..8dfda0333 100644 --- a/src/libs/vtools/tools/toolsdef.cpp +++ b/src/libs/vtools/tools/toolsdef.cpp @@ -51,7 +51,7 @@ auto SourceToObjects(const QVector &source) -> QVector QVector ids; ids.reserve(source.size()); - for (auto s : source) + for (const auto &s : source) { ids.append(s.id); } diff --git a/src/test/ValentinaTest/tst_vposter.cpp b/src/test/ValentinaTest/tst_vposter.cpp index 4910995d3..211cf8f1f 100644 --- a/src/test/ValentinaTest/tst_vposter.cpp +++ b/src/test/ValentinaTest/tst_vposter.cpp @@ -35,8 +35,8 @@ #include //--------------------------------------------------------------------------------------------------------------------- -TST_VPoster::TST_VPoster(QObject *parent) : - QObject(parent) +TST_VPoster::TST_VPoster(QObject *parent) + : QObject(parent) { } @@ -45,12 +45,12 @@ TST_VPoster::TST_VPoster(QObject *parent) : void TST_VPoster::BigPoster() { QPrinter printer; - printer.setResolution(static_cast(PrintDPI));// By default + printer.setResolution(static_cast(PrintDPI)); // By default printer.setPageSize(QPageSize(QPageSize::A4)); printer.setFullPage(true); // We need to set full page because otherwise QPrinter->pageRect returns different values in Windows and Linux - //sets the margins to 0 to perform the test. + // sets the margins to 0 to perform the test. printer.setPageMargins(QMarginsF(), QPageLayout::Millimeter); const QSize image(2622, 3178); // Little bit bigger than A1 @@ -59,7 +59,7 @@ void TST_VPoster::BigPoster() QCOMPARE(poster.size(), 12); - for (auto p : poster) + for (const auto &p : poster) { QCOMPARE(p.rect.size(), PageRect(printer).size()); } @@ -70,7 +70,7 @@ void TST_VPoster::BigPoster() void TST_VPoster::SmallPoster() { QPrinter printer; - printer.setResolution(96);// By default + printer.setResolution(96); // By default printer.setPageSize(QPageSize(QPageSize::A4)); const QSize image(700, 1000); // Little bit less than A4 @@ -89,8 +89,8 @@ auto TST_VPoster::PageRect(const QPrinter &printer) const -> QRect // we can't use method pageRect(QPrinter::Point). Our dpi different can be different. // We convert value yourself to pixels. const QRectF rect = printer.pageRect(QPrinter::Millimeter); - QRect pageRect(qFloor(ToPixel(rect.x())), qFloor(ToPixel(rect.y())), - qFloor(ToPixel(rect.width())), qFloor(ToPixel(rect.height()))); + QRect pageRect(qFloor(ToPixel(rect.x())), qFloor(ToPixel(rect.y())), qFloor(ToPixel(rect.width())), + qFloor(ToPixel(rect.height()))); return pageRect; }