From 932db634977efff4873cf782c2cbd1aaa76c1672 Mon Sep 17 00:00:00 2001 From: Yann Lossouarn Date: Fri, 23 Feb 2024 18:21:40 +0100 Subject: [PATCH 1/8] Code smell improvement: capture 'matrix' by reference instead of capturing by value --- src/app/puzzle/scene/vpgraphicspiece.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/puzzle/scene/vpgraphicspiece.cpp b/src/app/puzzle/scene/vpgraphicspiece.cpp index aa9fe8fc8..9e1be89a0 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.cpp +++ b/src/app/puzzle/scene/vpgraphicspiece.cpp @@ -809,7 +809,7 @@ void VPGraphicsPiece::PaintInternalPaths(QPainter *painter, const VPPiecePtr &pi QVector points = piecePath.Points(); const QTransform matrix = VGObject::FlippingMatrix(piece->GetSeamMirrorLine()); std::transform(points.begin(), points.end(), points.begin(), - [matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); + [&matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); QVector casted; CastTo(points, casted); path.addPath(piece->GetMatrix().map(VPiecePath::MakePainterPath(casted))); From 7ff8aed6bcd530bc22f53b20e58ca725ed7f1153 Mon Sep 17 00:00:00 2001 From: Yann Lossouarn Date: Fri, 23 Feb 2024 18:31:01 +0100 Subject: [PATCH 2/8] Code smell improvement: capture variable by reference --- src/app/puzzle/scene/vpgraphicspiece.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/puzzle/scene/vpgraphicspiece.cpp b/src/app/puzzle/scene/vpgraphicspiece.cpp index 9e1be89a0..84e1eb922 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.cpp +++ b/src/app/puzzle/scene/vpgraphicspiece.cpp @@ -893,7 +893,7 @@ void VPGraphicsPiece::PaintPlaceLabels(QPainter *painter, const VPPiecePtr &piec for (auto &points : shape) { std::transform(points.begin(), points.end(), points.begin(), - [matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); + [&matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); } path.addPath(VAbstractPiece::LabelShapePath(piece->MapPlaceLabelShape(shape))); From eea5dca893d75e8d372742a3f152e9e3d17647ff Mon Sep 17 00:00:00 2001 From: Yann Lossouarn Date: Fri, 23 Feb 2024 18:34:20 +0100 Subject: [PATCH 3/8] Code smell & performance improvement : Capture large object "watermarkData" by reference. --- src/app/puzzle/scene/vpgraphicstilegrid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/puzzle/scene/vpgraphicstilegrid.cpp b/src/app/puzzle/scene/vpgraphicstilegrid.cpp index fe0dcac0e..dc6436788 100644 --- a/src/app/puzzle/scene/vpgraphicstilegrid.cpp +++ b/src/app/puzzle/scene/vpgraphicstilegrid.cpp @@ -167,7 +167,7 @@ void VPGraphicsTileGrid::paint(QPainter *painter, const QStyleOptionGraphicsItem VWatermarkData const watermarkData = layout->TileFactory()->WatermarkData(); - auto PaintWatermark = [painter, layout, xScale, yScale, watermarkData](const QRectF &img) + auto PaintWatermark = [painter, layout, xScale, yScale, &watermarkData](const QRectF &img) { if (not layout->LayoutSettings().WatermarkPath().isEmpty() && layout->LayoutSettings().GetShowWatermark() && watermarkData.opacity > 0) From ed6cd0a927c9abbff0a94abfa9f97a928757bc97 Mon Sep 17 00:00:00 2001 From: Yann Lossouarn Date: Fri, 23 Feb 2024 18:42:24 +0100 Subject: [PATCH 4/8] Code smell and performance : capture img and watermarkData by reference --- src/app/puzzle/vptilefactory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/puzzle/vptilefactory.cpp b/src/app/puzzle/vptilefactory.cpp index 9af3322dc..3919f85e9 100644 --- a/src/app/puzzle/vptilefactory.cpp +++ b/src/app/puzzle/vptilefactory.cpp @@ -689,7 +689,7 @@ void VPTileFactory::PaintWatermarkImage(QPainter *painter, const QRectF &img, co SCASSERT(painter != nullptr) const qreal opacity = watermarkData.opacity / 100.; - auto BrokenImage = [img, watermarkData, watermarkPath, opacity, folowColorScheme]() + auto BrokenImage = [&img, &watermarkData, watermarkPath, opacity, folowColorScheme]() { QString colorScheme = QStringLiteral("light"); From 0400b4fc7230fcc5f7d3f6b88944ed0186c34ae3 Mon Sep 17 00:00:00 2001 From: Yann Lossouarn Date: Fri, 23 Feb 2024 18:42:43 +0100 Subject: [PATCH 5/8] Code smell and performance : capture various variables by reference --- src/libs/vdxf/vdxfengine.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libs/vdxf/vdxfengine.cpp b/src/libs/vdxf/vdxfengine.cpp index 41c9179ab..2fd71fa29 100644 --- a/src/libs/vdxf/vdxfengine.cpp +++ b/src/libs/vdxf/vdxfengine.cpp @@ -912,7 +912,7 @@ void VDxfEngine::ExportAAMADrawSewLine(const QSharedPointer &deta const UTF8STRING &layer = not detail.IsSewLineOnDrawing() ? *layer14 : *layer8; QVector const points = detail.GetMappedFullContourPoints(); - auto DrawPolygon = [this, detailBlock, layer](const QVector &points, bool forceClosed) + auto DrawPolygon = [this, detailBlock, &layer](const QVector &points, bool forceClosed) { if (DRW_Entity *e = AAMAPolygon(points, layer, forceClosed)) { @@ -977,7 +977,7 @@ void VDxfEngine::ExportAAMADrawInternalPaths(const QSharedPointer { const QTransform matrix = VGObject::FlippingMatrix(detail.GetMappedSeamMirrorLine()); std::transform(points.begin(), points.end(), points.begin(), - [matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); + [&matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); DrawPolygon(points, iPath.PenStyle(), false); } } @@ -1015,7 +1015,7 @@ void VDxfEngine::ExportAAMADrawPlaceLabels(const QSharedPointer & for (auto &points : shape) { std::transform(points.begin(), points.end(), points.begin(), - [matrix](const VLayoutPoint &point) + [&matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); } @@ -1049,7 +1049,7 @@ void VDxfEngine::ExportAAMAIntcut(const QSharedPointer &detailBlo { const QTransform matrix = VGObject::FlippingMatrix(detail.GetMappedSeamMirrorLine()); std::transform(points.begin(), points.end(), points.begin(), - [matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); + [&matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); DrawPolygon(points, false); } } @@ -1524,7 +1524,7 @@ void VDxfEngine::ExportASTMDrawInternalPaths(const QSharedPointer { const QTransform matrix = VGObject::FlippingMatrix(detail.GetMappedSeamMirrorLine()); std::transform(points.begin(), points.end(), points.begin(), - [matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); + [&matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); DrawPolygon(points, iPath.PenStyle(), iPath.IsNotMirrored(), false); } } @@ -1576,7 +1576,7 @@ void VDxfEngine::ExportASTMDrawPlaceLabels(const QSharedPointer & for (auto &points : shape) { std::transform(points.begin(), points.end(), points.begin(), - [matrix](const VLayoutPoint &point) + [&matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); } @@ -1624,7 +1624,7 @@ void VDxfEngine::ExportASTMInternalCutout(const QSharedPointer &d { const QTransform matrix = VGObject::FlippingMatrix(detail.GetMappedSeamMirrorLine()); std::transform(points.begin(), points.end(), points.begin(), - [matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); + [&matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); DrawPolygon(points, intCut.IsNotMirrored(), false); } } @@ -1687,7 +1687,7 @@ void VDxfEngine::ExportASTMNotches(const QSharedPointer &detailBl return; } - auto ExportPassmark = [this, detailBlock, detail](const VLayoutPassmark &passmark) + auto ExportPassmark = [this, detailBlock, &detail](const VLayoutPassmark &passmark) { DRW_ASTMNotch *notch = ExportASTMNotch(passmark); DRW_ATTDEF *attdef = ExportASTMNotchDataDependecy(passmark, notch->layer, detail); From a1cf1763312f1db2152d8476ac51c19b1b0dfff1 Mon Sep 17 00:00:00 2001 From: Yann Lossouarn Date: Fri, 23 Feb 2024 18:51:02 +0100 Subject: [PATCH 6/8] Code smell and performance : capture various variables by reference --- src/libs/vgeometry/vellipticalarc.cpp | 2 +- src/libs/vhpgl/vhpglengine.cpp | 4 ++-- src/libs/vlayout/vabstractpiece.cpp | 22 +++++++++++----------- src/libs/vlayout/vabstractpiece.h | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 543dff413..f8f33cee3 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -516,7 +516,7 @@ auto VEllipticalArc::GetPoints() const -> QVector t.rotate(-d->rotationAngle); t.translate(-center.x(), -center.y()); - std::transform(points.begin(), points.end(), points.begin(), [t](const QPointF &point) { return t.map(point); }); + std::transform(points.begin(), points.end(), points.begin(), [&t](const QPointF &point) { return t.map(point); }); return IsFlipped() ? Reverse(points) : points; } diff --git a/src/libs/vhpgl/vhpglengine.cpp b/src/libs/vhpgl/vhpglengine.cpp index cfe211bdf..03c1ca4cf 100644 --- a/src/libs/vhpgl/vhpglengine.cpp +++ b/src/libs/vhpgl/vhpglengine.cpp @@ -502,7 +502,7 @@ void VHPGLEngine::PlotInternalPaths(QTextStream &out, const VLayoutPiece &detail { const QTransform matrix = VGObject::FlippingMatrix(detail.GetMappedSeamMirrorLine()); std::transform(points.begin(), points.end(), points.begin(), - [matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); + [&matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); PlotPath(out, CastToPoint(ConvertPath(points)), path.PenStyle()); } } @@ -531,7 +531,7 @@ void VHPGLEngine::PlotPlaceLabels(QTextStream &out, const VLayoutPiece &detail) for (auto &points : shape) { std::transform(points.begin(), points.end(), points.begin(), - [matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); + [&matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); } PlotShape(shape); diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index ad938c502..5cc8dc467 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -1906,7 +1906,7 @@ auto VAbstractPiece::GrainlineMainLine(const VGrainlineData &geom, const VContai //--------------------------------------------------------------------------------------------------------------------- auto VAbstractPiece::PlaceLabelShape(const VLayoutPlaceLabel &label) -> PlaceLabelImg { - auto LayoutPoint = [label](QPointF p, bool turnPoint = false, bool curvePoint = false) + auto LayoutPoint = [&label](QPointF p, bool turnPoint = false, bool curvePoint = false) { VLayoutPoint point(label.RotationMatrix().map(p)); point.SetTurnPoint(turnPoint); @@ -1917,7 +1917,7 @@ auto VAbstractPiece::PlaceLabelShape(const VLayoutPlaceLabel &label) -> PlaceLab const QPointF pos = label.Center(); const QRectF box = label.Box(); - auto SegmentShape = [pos, box, LayoutPoint]() + auto SegmentShape = [pos, &box, &LayoutPoint]() { QVector const shape{LayoutPoint(QPointF(pos.x(), pos.y() - box.height() / 2.0), true), LayoutPoint(QPointF(pos.x(), pos.y() + box.height() / 2.0), true)}; @@ -1925,7 +1925,7 @@ auto VAbstractPiece::PlaceLabelShape(const VLayoutPlaceLabel &label) -> PlaceLab return PlaceLabelImg{shape}; }; - auto RectangleShape = [pos, box, LayoutPoint]() + auto RectangleShape = [pos, &box, &LayoutPoint]() { QRectF const rect(QPointF(pos.x() - box.width() / 2.0, pos.y() - box.height() / 2.0), QPointF(pos.x() + box.width() / 2.0, pos.y() + box.height() / 2.0)); @@ -1937,7 +1937,7 @@ auto VAbstractPiece::PlaceLabelShape(const VLayoutPlaceLabel &label) -> PlaceLab return PlaceLabelImg{shape}; }; - auto CrossShape = [pos, box, LayoutPoint]() + auto CrossShape = [pos, &box, &LayoutPoint]() { QVector const shape1{LayoutPoint(QPointF(pos.x(), pos.y() - box.height() / 2.0), true), LayoutPoint(QPointF(pos.x(), pos.y() + box.height() / 2.0), true)}; @@ -1948,7 +1948,7 @@ auto VAbstractPiece::PlaceLabelShape(const VLayoutPlaceLabel &label) -> PlaceLab return PlaceLabelImg{shape1, shape2}; }; - auto TshapedShape = [pos, box, LayoutPoint]() + auto TshapedShape = [pos, &box, &LayoutPoint]() { QPointF const center2(pos.x(), pos.y() + box.height() / 2.0); @@ -1960,7 +1960,7 @@ auto VAbstractPiece::PlaceLabelShape(const VLayoutPlaceLabel &label) -> PlaceLab return PlaceLabelImg{shape1, shape2}; }; - auto DoubletreeShape = [pos, box, LayoutPoint]() + auto DoubletreeShape = [pos, &box, &LayoutPoint]() { QRectF const rect(QPointF(pos.x() - box.width() / 2.0, pos.y() - box.height() / 2.0), QPointF(pos.x() + box.width() / 2.0, pos.y() + box.height() / 2.0)); @@ -1972,7 +1972,7 @@ auto VAbstractPiece::PlaceLabelShape(const VLayoutPlaceLabel &label) -> PlaceLab return PlaceLabelImg{shape1, shape2}; }; - auto CornerShape = [pos, box, LayoutPoint]() + auto CornerShape = [pos, &box, &LayoutPoint]() { QVector const shape1{LayoutPoint(QPointF(pos.x(), pos.y()), true), LayoutPoint(QPointF(pos.x(), pos.y() + box.height() / 2.0), true)}; @@ -1983,7 +1983,7 @@ auto VAbstractPiece::PlaceLabelShape(const VLayoutPlaceLabel &label) -> PlaceLab return PlaceLabelImg{shape1, shape2}; }; - auto TriangleShape = [pos, box, LayoutPoint]() + auto TriangleShape = [pos, &box, &LayoutPoint]() { QRectF const rect(QPointF(pos.x() - box.width() / 2.0, pos.y() - box.height() / 2.0), QPointF(pos.x() + box.width() / 2.0, pos.y() + box.height() / 2.0)); @@ -1994,7 +1994,7 @@ auto VAbstractPiece::PlaceLabelShape(const VLayoutPlaceLabel &label) -> PlaceLab return PlaceLabelImg{shape}; }; - auto HshapedShape = [pos, box, LayoutPoint]() + auto HshapedShape = [pos, &box, &LayoutPoint]() { const QPointF center1(pos.x(), pos.y() - box.height() / 2.0); const QPointF center2(pos.x(), pos.y() + box.height() / 2.0); @@ -2010,7 +2010,7 @@ auto VAbstractPiece::PlaceLabelShape(const VLayoutPlaceLabel &label) -> PlaceLab return PlaceLabelImg{shape1, shape2, shape3}; }; - auto ButtonShape = [pos, box, LayoutPoint]() + auto ButtonShape = [pos, &box, &LayoutPoint]() { const qreal radius = qMin(box.width() / 2.0, box.height() / 2.0); QVector const shape1{LayoutPoint(QPointF(pos.x(), pos.y() - radius), true), @@ -2044,7 +2044,7 @@ auto VAbstractPiece::PlaceLabelShape(const VLayoutPlaceLabel &label) -> PlaceLab return PlaceLabelImg{shape1, shape2, shape3}; }; - auto CircleShape = [pos, box, LayoutPoint]() + auto CircleShape = [pos, &box, &LayoutPoint]() { const qreal radius = qMin(box.width() / 2.0, box.height() / 2.0); VArc arc(VPointF(pos), radius, 0, 360); diff --git a/src/libs/vlayout/vabstractpiece.h b/src/libs/vlayout/vabstractpiece.h index ee78f2c51..44354ce7b 100644 --- a/src/libs/vlayout/vabstractpiece.h +++ b/src/libs/vlayout/vabstractpiece.h @@ -940,7 +940,7 @@ template inline auto VAbstractPiece::MapVector(QVector points, const QTransform &matrix, bool mirror) -> QVector { std::transform(points.begin(), points.end(), points.begin(), - [matrix](const T &point) { return MapPoint(point, matrix); }); + [&matrix](const T &point) { return MapPoint(point, matrix); }); if (mirror) { std::reverse(points.begin(), points.end()); From 95db2eb133535e615814bedcd99db8ce084a3e76 Mon Sep 17 00:00:00 2001 From: Yann Lossouarn Date: Fri, 23 Feb 2024 22:05:30 +0100 Subject: [PATCH 7/8] Code smell and performance : capture various variables by reference --- src/libs/vlayout/vbestsquare.cpp | 2 +- src/libs/vlayout/vfoldline.cpp | 2 +- src/libs/vlayout/vlayoutpiece.cpp | 8 ++++---- src/libs/vpatterndb/vpassmark.cpp | 2 +- src/libs/vpatterndb/vpiece.cpp | 2 +- src/libs/vtools/dialogs/tools/dialogarc.cpp | 2 +- src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp | 2 +- src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp | 2 +- .../vtools/dialogs/tools/piece/dialogseamallowance.cpp | 4 ++-- src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp | 2 +- src/libs/vtools/tools/vtooluniondetails.cpp | 2 +- src/libs/vtools/visualization/path/vistoolarc.cpp | 2 +- .../vtools/visualization/path/vistoolarcwithlength.cpp | 2 +- 13 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/libs/vlayout/vbestsquare.cpp b/src/libs/vlayout/vbestsquare.cpp index 8d54786d3..c34238625 100644 --- a/src/libs/vlayout/vbestsquare.cpp +++ b/src/libs/vlayout/vbestsquare.cpp @@ -84,7 +84,7 @@ auto VBestSquare::operator=(VBestSquare &&res) noexcept -> VBestSquare & //--------------------------------------------------------------------------------------------------------------------- void VBestSquare::NewResult(const VBestSquareResData &data) { - auto SaveResult = [this, data]() + auto SaveResult = [this, &data]() { d->valideResult = true; d->data = data; diff --git a/src/libs/vlayout/vfoldline.cpp b/src/libs/vlayout/vfoldline.cpp index b9bd92035..63f9b11f8 100644 --- a/src/libs/vlayout/vfoldline.cpp +++ b/src/libs/vlayout/vfoldline.cpp @@ -459,7 +459,7 @@ auto VFoldLine::FoldLineThreeDotsPath() const -> QVector ThreeDotsPosData const data = ThreeDotsData(); QPainterPath dots; - auto DrawCircle = [&dots, data](const QPointF ¢er) + auto DrawCircle = [&dots, &data](const QPointF ¢er) { qreal const diameter = 2 * data.radius; qreal const x = center.x() - data.radius; diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 4787b213f..5d5c50158 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -1693,7 +1693,7 @@ auto VLayoutPiece::GetItem(bool textAsPaths, bool togetherWithNotches, bool show QVector points = path.Points(); const QTransform matrix = VGObject::FlippingMatrix(d->m_seamMirrorLine); std::transform(points.begin(), points.end(), points.begin(), - [matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); + [&matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); QVector casted; CastTo(points, casted); p.addPath(d->m_matrix.map(VPiecePath::MakePainterPath(casted))); @@ -1724,7 +1724,7 @@ auto VLayoutPiece::GetItem(bool textAsPaths, bool togetherWithNotches, bool show for (auto &points : shape) { std::transform(points.begin(), points.end(), points.begin(), - [matrix](const VLayoutPoint &point) { return MapPoint(point, matrix); }); + [&matrix](const VLayoutPoint &point) { return MapPoint(point, matrix); }); } path.addPath(d->m_matrix.map(LabelShapePath(shape))); @@ -2382,7 +2382,7 @@ auto VLayoutPiece::ConvertPassmarks(const VPiece &piece, const VContainer *patte continue; } - auto AddPassmark = [passmark, piece, pattern, &layoutPassmarks](PassmarkSide side) + auto AddPassmark = [&passmark, &piece, pattern, &layoutPassmarks](PassmarkSide side) { bool ok = false; VLayoutPassmark const layoutPassmark = PrepareSAPassmark(piece, pattern, passmark, side, ok); @@ -2392,7 +2392,7 @@ auto VLayoutPiece::ConvertPassmarks(const VPiece &piece, const VContainer *patte } }; - auto AddBuiltInPassmark = [passmark, piece, pattern, &layoutPassmarks]() + auto AddBuiltInPassmark = [&passmark, &piece, pattern, &layoutPassmarks]() { bool ok = false; VLayoutPassmark const layoutPassmark = PreapreBuiltInSAPassmark(piece, pattern, passmark, ok); diff --git a/src/libs/vpatterndb/vpassmark.cpp b/src/libs/vpatterndb/vpassmark.cpp index 340f27e8f..78844320f 100644 --- a/src/libs/vpatterndb/vpassmark.cpp +++ b/src/libs/vpatterndb/vpassmark.cpp @@ -95,7 +95,7 @@ auto PointsToSegments(const QVector &points) -> QVector //--------------------------------------------------------------------------------------------------------------------- auto PassmarkLength(const VPiecePassmarkData &passmarkData, qreal width, bool &ok) -> qreal { - auto ValidateLength = [passmarkData](qreal length) + auto ValidateLength = [&passmarkData](qreal length) { if (length <= accuracyPointOnLine) { diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index c1e5c01e9..75e9b688b 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -404,7 +404,7 @@ auto VPiece::PlaceLabelPath(const VContainer *data) const -> QPainterPath for (auto &points : shape) { std::transform(points.begin(), points.end(), points.begin(), - [matrix](const VLayoutPoint &point) { return MapPoint(point, matrix); }); + [&matrix](const VLayoutPoint &point) { return MapPoint(point, matrix); }); } path.addPath(LabelShapePath(shape)); diff --git a/src/libs/vtools/dialogs/tools/dialogarc.cpp b/src/libs/vtools/dialogs/tools/dialogarc.cpp index cdf6dac40..710e6ba7d 100644 --- a/src/libs/vtools/dialogs/tools/dialogarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarc.cpp @@ -271,7 +271,7 @@ void DialogArc::ShowDialog(bool click) const QSharedPointer point = data->GeometricObject(GetCenter()); QLineF const line = QLineF(static_cast(*point), scene->getScenePos()); - auto Angle = [line]() + auto Angle = [&line]() { if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier) { diff --git a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp index 0743c29c8..754f5cb29 100644 --- a/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp +++ b/src/libs/vtools/dialogs/tools/dialogarcwithlength.cpp @@ -298,7 +298,7 @@ void DialogArcWithLength::ShowDialog(bool click) const QSharedPointer point = data->GeometricObject(GetCenter()); QLineF const line = QLineF(static_cast(*point), scene->getScenePos()); - auto Angle = [line]() + auto Angle = [&line]() { if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier) { diff --git a/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp b/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp index 68296144e..3b38df43b 100644 --- a/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp +++ b/src/libs/vtools/dialogs/tools/dialogellipticalarc.cpp @@ -592,7 +592,7 @@ void DialogEllipticalArc::ShowDialog(bool click) const QSharedPointer center = data->GeometricObject(GetCenter()); QLineF line = QLineF(static_cast(*center), scene->getScenePos()); - auto Angle = [line]() + auto Angle = [&line]() { if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier) { diff --git a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp index 54dfed72c..93ed7ac25 100644 --- a/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/piece/dialogseamallowance.cpp @@ -1318,7 +1318,7 @@ void DialogSeamAllowance::ShowPlaceLabelsContextMenu(const QPoint &pos) QScopedPointer menu(new QMenu()); - auto InitAction = [currentLabel, &menu](const QString &text, PlaceLabelType type) + auto InitAction = [¤tLabel, &menu](const QString &text, PlaceLabelType type) { QAction *action = menu->addAction(text); action->setCheckable(true); @@ -1326,7 +1326,7 @@ void DialogSeamAllowance::ShowPlaceLabelsContextMenu(const QPoint &pos) return action; }; - auto SaveType = [this, currentLabel, labelId](PlaceLabelType type) + auto SaveType = [this, ¤tLabel, labelId](PlaceLabelType type) { VPlaceLabelItem newLabel = VPlaceLabelItem(currentLabel); newLabel.SetLabelType(type); diff --git a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp index 933d03346..b834ca7f0 100644 --- a/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp +++ b/src/libs/vtools/tools/nodeDetails/vtoolpiecepath.cpp @@ -328,7 +328,7 @@ void VToolPiecePath::RefreshGeometry() QVector points = path.PathPoints(this->getData(), cuttingPath); const QTransform matrix = VGObject::FlippingMatrix(mirrorLine); std::transform(points.begin(), points.end(), points.begin(), - [matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); + [&matrix](const VLayoutPoint &point) { return VAbstractPiece::MapPoint(point, matrix); }); QVector casted; CastTo(points, casted); p.addPath(VPiecePath::MakePainterPath(casted)); diff --git a/src/libs/vtools/tools/vtooluniondetails.cpp b/src/libs/vtools/tools/vtooluniondetails.cpp index 793d37e68..38aa20139 100644 --- a/src/libs/vtools/tools/vtooluniondetails.cpp +++ b/src/libs/vtools/tools/vtooluniondetails.cpp @@ -1559,7 +1559,7 @@ void CreateUnitedDetail(const VToolUnionDetailsInitData &initData, qreal dx, qre piece->RefreshGeometry(true); // Refresh internal paths } - auto DuplicateDetail = [initData](quint32 id) + auto DuplicateDetail = [&initData](quint32 id) { VToolSeamAllowanceInitData initPieceData; initPieceData.scene = initData.scene; diff --git a/src/libs/vtools/visualization/path/vistoolarc.cpp b/src/libs/vtools/visualization/path/vistoolarc.cpp index 92dd18d00..fb3f0906e 100644 --- a/src/libs/vtools/visualization/path/vistoolarc.cpp +++ b/src/libs/vtools/visualization/path/vistoolarc.cpp @@ -67,7 +67,7 @@ void VisToolArc::RefreshGeometry() { QLineF const r = QLineF(static_cast(*first), ScenePos()); - auto Angle = [r]() + auto Angle = [&r]() { if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier) { diff --git a/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp b/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp index 65aaedbc6..9c7d6dbf7 100644 --- a/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp +++ b/src/libs/vtools/visualization/path/vistoolarcwithlength.cpp @@ -65,7 +65,7 @@ void VisToolArcWithLength::RefreshGeometry() { QLineF const r = QLineF(static_cast(*first), ScenePos()); - auto Angle = [r]() + auto Angle = [&r]() { if (QGuiApplication::keyboardModifiers() == Qt::ShiftModifier) { From 55b2c1b4aea9d07219282561f778a31ec80ed42d Mon Sep 17 00:00:00 2001 From: Yann Lossouarn Date: Fri, 23 Feb 2024 23:46:32 +0100 Subject: [PATCH 8/8] Code cleaning : functions that should be const --- .../configpages/puzzlepreferencesconfigurationpage.cpp | 4 ++-- .../configpages/puzzlepreferencesconfigurationpage.h | 4 ++-- .../dialogs/configpages/puzzlepreferenceslayoutpage.cpp | 2 +- .../dialogs/configpages/puzzlepreferenceslayoutpage.h | 2 +- .../dialogs/configpages/puzzlepreferencespathpage.cpp | 4 ++-- .../dialogs/configpages/puzzlepreferencespathpage.h | 4 ++-- src/app/puzzle/layout/vppiece.cpp | 4 ++-- src/app/puzzle/layout/vppiece.h | 4 ++-- src/app/puzzle/layout/vpsheet.cpp | 2 +- src/app/puzzle/layout/vpsheet.h | 2 +- src/app/puzzle/scene/vpgraphicspiece.cpp | 4 ++-- src/app/puzzle/scene/vpgraphicspiece.h | 4 ++-- src/app/puzzle/scene/vpmaingraphicsview.cpp | 8 ++++---- src/app/puzzle/scene/vpmaingraphicsview.h | 8 ++++---- 14 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp index 4744e1e05..8312c88e8 100644 --- a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.cpp @@ -310,7 +310,7 @@ void PuzzlePreferencesConfigurationPage::InitShortcuts(bool defaults) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzlePreferencesConfigurationPage::UpdateShortcutsTable() +void PuzzlePreferencesConfigurationPage::UpdateShortcutsTable() const { for (int i = 0; i < m_transientShortcuts.length(); i++) { @@ -320,7 +320,7 @@ void PuzzlePreferencesConfigurationPage::UpdateShortcutsTable() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzlePreferencesConfigurationPage::RetranslateShortcutsTable() +void PuzzlePreferencesConfigurationPage::RetranslateShortcutsTable() const { VAbstractShortcutManager *manager = VAbstractApplication::VApp()->GetShortcutManager(); if (manager == nullptr) diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.h b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.h index d0d364e66..0471bbf5f 100644 --- a/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.h +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencesconfigurationpage.h @@ -61,8 +61,8 @@ private: void SetThemeModeComboBox(); void InitShortcuts(bool defaults = false); - void UpdateShortcutsTable(); - void RetranslateShortcutsTable(); + void UpdateShortcutsTable() const; + void RetranslateShortcutsTable() const; }; #endif // PUZZLEPREFERENCESCONFIGURATIONPAGE_H diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp index f3366e488..4f5bdfee4 100644 --- a/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.cpp @@ -680,7 +680,7 @@ void PuzzlePreferencesLayoutPage::ReadSettings() } //--------------------------------------------------------------------------------------------------------------------- -void PuzzlePreferencesLayoutPage::FindTemplate(QComboBox *box, qreal width, qreal height) +void PuzzlePreferencesLayoutPage::FindTemplate(QComboBox *box, qreal width, qreal height) const { SCASSERT(box != nullptr) const Unit paperUnit = LayoutUnit(); diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.h b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.h index b5aa24408..6db9c830e 100644 --- a/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.h +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferenceslayoutpage.h @@ -99,7 +99,7 @@ private: void ReadSettings(); - void FindTemplate(QComboBox *box, qreal width, qreal height); + void FindTemplate(QComboBox *box, qreal width, qreal height) const; }; #endif // PUZZLEPREFERENCESLAYOUTPAGE_H diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.cpp b/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.cpp index 6f9ba5d00..9b232d201 100644 --- a/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.cpp +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.cpp @@ -56,7 +56,7 @@ PuzzlePreferencesPathPage::PuzzlePreferencesPathPage(QWidget *parent) PuzzlePreferencesPathPage::~PuzzlePreferencesPathPage() = default; //--------------------------------------------------------------------------------------------------------------------- -void PuzzlePreferencesPathPage::Apply() +void PuzzlePreferencesPathPage::Apply() const { VPSettings *settings = VPApplication::VApp()->PuzzleSettings(); settings->SetPathSVGFonts(ui->pathTable->item(0, 1)->text()); @@ -78,7 +78,7 @@ void PuzzlePreferencesPathPage::changeEvent(QEvent *event) } //--------------------------------------------------------------------------------------------------------------------- -void PuzzlePreferencesPathPage::DefaultPath() +void PuzzlePreferencesPathPage::DefaultPath() const { const int row = ui->pathTable->currentRow(); QTableWidgetItem *item = ui->pathTable->item(row, 1); diff --git a/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.h b/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.h index 03959d1f7..42773b882 100644 --- a/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.h +++ b/src/app/puzzle/dialogs/configpages/puzzlepreferencespathpage.h @@ -44,13 +44,13 @@ public: explicit PuzzlePreferencesPathPage(QWidget *parent = nullptr); ~PuzzlePreferencesPathPage() override; - void Apply(); + void Apply() const; protected: void changeEvent(QEvent *event) override; private slots: - void DefaultPath(); + void DefaultPath() const; void EditPath(); private: diff --git a/src/app/puzzle/layout/vppiece.cpp b/src/app/puzzle/layout/vppiece.cpp index 10c90038a..3d85a3a18 100644 --- a/src/app/puzzle/layout/vppiece.cpp +++ b/src/app/puzzle/layout/vppiece.cpp @@ -217,7 +217,7 @@ void VPPiece::ClearTransformations() } //--------------------------------------------------------------------------------------------------------------------- -void VPPiece::SetPosition(QPointF point) +void VPPiece::SetPosition(QPointF point) const { QTransform matrix = GetMatrix(); const QPointF offset = MappedDetailBoundingRect().topLeft(); @@ -226,7 +226,7 @@ void VPPiece::SetPosition(QPointF point) } //--------------------------------------------------------------------------------------------------------------------- -auto VPPiece::GetPosition() -> QPointF +auto VPPiece::GetPosition() const -> QPointF { QTransform const matrix = GetMatrix(); return {matrix.dx(), matrix.dy()}; diff --git a/src/app/puzzle/layout/vppiece.h b/src/app/puzzle/layout/vppiece.h index 29645c7cf..03108dfa5 100644 --- a/src/app/puzzle/layout/vppiece.h +++ b/src/app/puzzle/layout/vppiece.h @@ -65,13 +65,13 @@ public: * @brief SetPosition Sets the position of the piece, in relation to the origin of the scene * @param point the point where to set the piece */ - void SetPosition(QPointF point); + void SetPosition(QPointF point) const; /** * @brief GetPosition Returns the position of the piece * @return the position of the piece */ - auto GetPosition() -> QPointF; + auto QPointF GetPosition() -> QPointF; /** * @brief RotateToGrainline rotates the piece to follow the grainline diff --git a/src/app/puzzle/layout/vpsheet.cpp b/src/app/puzzle/layout/vpsheet.cpp index eedf51c4b..81b2892cd 100644 --- a/src/app/puzzle/layout/vpsheet.cpp +++ b/src/app/puzzle/layout/vpsheet.cpp @@ -310,7 +310,7 @@ void VPSheetSceneData::RefreshSheetSize() } //--------------------------------------------------------------------------------------------------------------------- -void VPSheetSceneData::ConnectPiece(VPGraphicsPiece *piece) +void VPSheetSceneData::ConnectPiece(VPGraphicsPiece *piece) const { SCASSERT(piece != nullptr) diff --git a/src/app/puzzle/layout/vpsheet.h b/src/app/puzzle/layout/vpsheet.h index 457ef7e70..316190d4d 100644 --- a/src/app/puzzle/layout/vpsheet.h +++ b/src/app/puzzle/layout/vpsheet.h @@ -129,7 +129,7 @@ private: bool m_outOfBoundTmp{false}; bool m_pieceSuperpositionTmp{false}; - void ConnectPiece(VPGraphicsPiece *piece); + void ConnectPiece(VPGraphicsPiece *piece) const; }; class VPSheet : public QObject diff --git a/src/app/puzzle/scene/vpgraphicspiece.cpp b/src/app/puzzle/scene/vpgraphicspiece.cpp index 84e1eb922..2a6d87232 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.cpp +++ b/src/app/puzzle/scene/vpgraphicspiece.cpp @@ -205,7 +205,7 @@ VPGraphicsPiece::VPGraphicsPiece(const VPPiecePtr &piece, QGraphicsItem *parent) } //--------------------------------------------------------------------------------------------------------------------- -auto VPGraphicsPiece::GetPiece() -> VPPiecePtr +auto VPGraphicsPiece::GetPiece() const -> VPPiecePtr { return m_piece.toStrongRef(); } @@ -939,7 +939,7 @@ void VPGraphicsPiece::PaintStickyPath(QPainter *painter) } //--------------------------------------------------------------------------------------------------------------------- -void VPGraphicsPiece::PaintMirrorLine(QPainter *painter, const VPPiecePtr &piece) +void VPGraphicsPiece::PaintMirrorLine(QPainter *painter, const VPPiecePtr &piece) const { if (piece->IsShowFullPiece()) { diff --git a/src/app/puzzle/scene/vpgraphicspiece.h b/src/app/puzzle/scene/vpgraphicspiece.h index 55e2a35e0..1138d820c 100644 --- a/src/app/puzzle/scene/vpgraphicspiece.h +++ b/src/app/puzzle/scene/vpgraphicspiece.h @@ -50,7 +50,7 @@ public: * @brief GetPiece Returns the piece that corresponds to the graphics piece * @return the piece */ - auto GetPiece() -> VPPiecePtr; + auto GetPiece() const -> VPPiecePtr; auto type() const -> int override { return Type; } enum @@ -133,7 +133,7 @@ private: void PaintPassmarks(QPainter *painter, const VPPiecePtr &piece); void PaintPlaceLabels(QPainter *painter, const VPPiecePtr &piece); void PaintStickyPath(QPainter *painter); - void PaintMirrorLine(QPainter *painter, const VPPiecePtr &piece); + void PaintMirrorLine(QPainter *painter, const VPPiecePtr &piece) const; void PaintFoldLine(QPainter *painter, const VPPiecePtr &piece); void GroupMove(const QPointF &pos); diff --git a/src/app/puzzle/scene/vpmaingraphicsview.cpp b/src/app/puzzle/scene/vpmaingraphicsview.cpp index b991d965a..cde66c733 100644 --- a/src/app/puzzle/scene/vpmaingraphicsview.cpp +++ b/src/app/puzzle/scene/vpmaingraphicsview.cpp @@ -103,7 +103,7 @@ VPMainGraphicsView::VPMainGraphicsView(const VPLayoutPtr &layout, QWidget *paren } //--------------------------------------------------------------------------------------------------------------------- -void VPMainGraphicsView::RefreshLayout() +void VPMainGraphicsView::RefreshLayout() const { VPLayoutPtr const layout = m_layout.toStrongRef(); if (not layout.isNull()) @@ -117,7 +117,7 @@ void VPMainGraphicsView::RefreshLayout() } //--------------------------------------------------------------------------------------------------------------------- -void VPMainGraphicsView::RefreshPieces() +void VPMainGraphicsView::RefreshPieces() const { VPLayoutPtr const layout = m_layout.toStrongRef(); if (not layout.isNull()) @@ -570,7 +570,7 @@ void VPMainGraphicsView::SwitchScene(const VPSheetPtr &sheet) } //--------------------------------------------------------------------------------------------------------------------- -void VPMainGraphicsView::ClearSelection() +void VPMainGraphicsView::ClearSelection() const { VPLayoutPtr const layout = m_layout.toStrongRef(); if (layout.isNull()) @@ -593,7 +593,7 @@ void VPMainGraphicsView::ClearSelection() } //--------------------------------------------------------------------------------------------------------------------- -void VPMainGraphicsView::ZValueMove(int move) +void VPMainGraphicsView::ZValueMove(int move) const { VPLayoutPtr const layout = m_layout.toStrongRef(); if (layout.isNull()) diff --git a/src/app/puzzle/scene/vpmaingraphicsview.h b/src/app/puzzle/scene/vpmaingraphicsview.h index 7424d2079..0452304bc 100644 --- a/src/app/puzzle/scene/vpmaingraphicsview.h +++ b/src/app/puzzle/scene/vpmaingraphicsview.h @@ -52,7 +52,7 @@ public: /** * @brief RefreshLayout Refreshes the rectangles for the layout border and the margin */ - void RefreshLayout(); + void RefreshLayout() const; public slots: /** @@ -64,7 +64,7 @@ public slots: void on_ActiveSheetChanged(const VPSheetPtr &focusedSheet); - void RefreshPieces(); + void RefreshPieces() const; signals: /** @@ -108,9 +108,9 @@ private: void TranslatePiecesOn(qreal dx, qreal dy); void SwitchScene(const VPSheetPtr &sheet); - void ClearSelection(); + void ClearSelection() const; - void ZValueMove(int move); + void ZValueMove(int move) const; void RemovePiece() const; void MovePiece(QKeyEvent *event);