From 1e2f1f7708379f36bbdf2936d0363a86478d497f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 7 Jul 2023 12:16:49 +0300 Subject: [PATCH] Refactoring. Code style. --- src/app/puzzle/layout/vppiece.cpp | 26 ++--- src/app/puzzle/layout/vppiece.h | 7 +- src/app/valentina/mainwindowsnogui.cpp | 2 +- src/libs/vdxf/vdxfengine.cpp | 9 +- src/libs/vformat/vwatermark.cpp | 42 ++++---- src/libs/vganalytics/vganalytics.cpp | 2 +- src/libs/vgeometry/vgobject.cpp | 143 +++++++++++++------------ src/libs/vlayout/vlayoutdef.h | 50 +++++---- src/libs/vlayout/vlayoutpiece.cpp | 12 +-- src/libs/vlayout/vlayoutpiece.h | 1 - src/libs/vlayout/vlayoutpiecepath.h | 12 +-- src/libs/vmisc/def.h | 24 +++++ 12 files changed, 181 insertions(+), 149 deletions(-) diff --git a/src/app/puzzle/layout/vppiece.cpp b/src/app/puzzle/layout/vppiece.cpp index b35072187..eeb6d7df2 100644 --- a/src/app/puzzle/layout/vppiece.cpp +++ b/src/app/puzzle/layout/vppiece.cpp @@ -67,7 +67,7 @@ auto CutEdge(const QLineF &edge) -> QVector } else { - const int n = qFloor(edge.length()/stickyShift); + const int n = qFloor(edge.length() / stickyShift); if (n <= 0) { @@ -77,11 +77,11 @@ auto CutEdge(const QLineF &edge) -> QVector else { points.reserve(n); - const qreal nShift = edge.length()/n; - for (int i = 1; i <= n+1; ++i) + const qreal nShift = edge.length() / n; + for (int i = 1; i <= n + 1; ++i) { QLineF l1 = edge; - l1.setLength(nShift*(i-1)); + l1.setLength(nShift * (i - 1)); points.append(l1.p2()); } } @@ -99,9 +99,9 @@ auto PrepareStickyPath(const QVector &path) -> QVector QVector stickyPath; - for (int i=0; i &path1, const QVector &path return closestDistance; } -} // namespace +} // namespace //--------------------------------------------------------------------------------------------------------------------- VPPiece::VPPiece(const VLayoutPiece &layoutPiece) - : VLayoutPiece(layoutPiece) + : VLayoutPiece(layoutPiece) { ClearTransformations(); @@ -375,14 +375,14 @@ auto VPPiece::StickyPosition(qreal &dx, qreal &dy) const -> bool QVector path; CastTo(GetMappedExternalContourPoints(), path); QRectF boundingRect = VLayoutPiece::BoundingRect(path); - const qreal stickyDistance = pieceGap+minStickyDistance; - QRectF stickyZone = QRectF(boundingRect.topLeft().x()-stickyDistance, boundingRect.topLeft().y()-stickyDistance, - boundingRect.width()+stickyDistance*2, boundingRect.height()+stickyDistance*2); + const qreal stickyDistance = pieceGap + minStickyDistance; + QRectF stickyZone = QRectF(boundingRect.topLeft().x() - stickyDistance, boundingRect.topLeft().y() - stickyDistance, + boundingRect.width() + stickyDistance * 2, boundingRect.height() + stickyDistance * 2); QVector stickyPath = PrepareStickyPath(path); QLineF closestDistance; - for (const auto& piece : allPieces) + for (const auto &piece : allPieces) { if (piece.isNull() || piece->GetUniqueID() == GetUniqueID()) { @@ -394,7 +394,7 @@ auto VPPiece::StickyPosition(qreal &dx, qreal &dy) const -> bool QRectF pieceBoundingRect = VLayoutPiece::BoundingRect(piecePath); if (stickyZone.intersects(pieceBoundingRect) || pieceBoundingRect.contains(stickyZone) || - stickyZone.contains(pieceBoundingRect)) + stickyZone.contains(pieceBoundingRect)) { if (not VPPiece::PathsSuperposition(path, piecePath)) { diff --git a/src/app/puzzle/layout/vppiece.h b/src/app/puzzle/layout/vppiece.h index 8d111cc22..7e211acb6 100644 --- a/src/app/puzzle/layout/vppiece.h +++ b/src/app/puzzle/layout/vppiece.h @@ -28,13 +28,13 @@ #ifndef VPPIECE_H #define VPPIECE_H -#include -#include #include #include +#include +#include -#include "../vlayout/vlayoutpiece.h" #include "../layout/layoutdef.h" +#include "../vlayout/vlayoutpiece.h" #include "vpiecegrainline.h" #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) @@ -47,6 +47,7 @@ class VPSheet; class VPPiece : public VLayoutPiece { Q_DECLARE_TR_FUNCTIONS(VPPiece) // NOLINT + public: VPPiece() = default; explicit VPPiece(const VLayoutPiece &layoutPiece); diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index de2b3b416..b14f5d772 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -497,7 +497,7 @@ void MainWindowsNoGUI::ExportData(const QVector &listDetails) QString::number(i + 1) + VLayoutExporter::ExportFormatSuffix(m_dialogSaveLayout->Format()); - QGraphicsRectItem *paper = + auto *paper = qgraphicsitem_cast(m_layoutSettings->LayoutPapers().at(i)); SCASSERT(paper != nullptr) diff --git a/src/libs/vdxf/vdxfengine.cpp b/src/libs/vdxf/vdxfengine.cpp index df689eff2..2c9cd0f70 100644 --- a/src/libs/vdxf/vdxfengine.cpp +++ b/src/libs/vdxf/vdxfengine.cpp @@ -104,16 +104,11 @@ QT_WARNING_POP //--------------------------------------------------------------------------------------------------------------------- auto PieceOutline(const VLayoutPiece &detail) -> QVector { - QVector outline; if (detail.IsSeamAllowance() && not detail.IsSeamAllowanceBuiltIn()) { - outline = detail.GetMappedSeamAllowancePoints(); + return detail.GetMappedSeamAllowancePoints(); } - else - { - outline = detail.GetMappedContourPoints(); - } - return outline; + return detail.GetMappedContourPoints(); } } // namespace diff --git a/src/libs/vformat/vwatermark.cpp b/src/libs/vformat/vwatermark.cpp index bc09d25a7..10be9b93c 100644 --- a/src/libs/vformat/vwatermark.cpp +++ b/src/libs/vformat/vwatermark.cpp @@ -27,33 +27,34 @@ *************************************************************************/ #include "vwatermark.h" -#include "../vmisc/projectversion.h" #include "../ifc/xml/vwatermarkconverter.h" +#include "../vmisc/compatibility.h" +#include "../vmisc/projectversion.h" const QString VWatermark::TagWatermark = QStringLiteral("watermark"); -const QString VWatermark::TagText = QStringLiteral("text"); -const QString VWatermark::TagImage = QStringLiteral("image"); +const QString VWatermark::TagText = QStringLiteral("text"); +const QString VWatermark::TagImage = QStringLiteral("image"); -const QString VWatermark::AttrOpacity = QStringLiteral("opacity"); -const QString VWatermark::AttrRotation = QStringLiteral("rotation"); -const QString VWatermark::AttrFont = QStringLiteral("font"); -const QString VWatermark::AttrPath = QStringLiteral("path"); +const QString VWatermark::AttrOpacity = QStringLiteral("opacity"); +const QString VWatermark::AttrRotation = QStringLiteral("rotation"); +const QString VWatermark::AttrFont = QStringLiteral("font"); +const QString VWatermark::AttrPath = QStringLiteral("path"); const QString VWatermark::AttrGrayscale = QStringLiteral("grayscale"); -const QString VWatermark::AttrShow = QStringLiteral("show"); +const QString VWatermark::AttrShow = QStringLiteral("show"); namespace { //--------------------------------------------------------------------------------------------------------------------- auto FileComment() -> QString { - return QString("Watermark created with Valentina v%1 (https://smart-pattern.com.ua/).") - .arg(APP_VERSION_STR); -} + return QString("Watermark created with Valentina v%1 (https://smart-pattern.com.ua/).").arg(APP_VERSION_STR); } +} // namespace //--------------------------------------------------------------------------------------------------------------------- VWatermark::VWatermark() -{} +{ +} //--------------------------------------------------------------------------------------------------------------------- void VWatermark::CreateEmptyWatermark() @@ -67,8 +68,9 @@ void VWatermark::CreateEmptyWatermark() wElement.appendChild(createElement(TagImage)); appendChild(wElement); - insertBefore(createProcessingInstruction(QStringLiteral("xml"), - QStringLiteral("version=\"1.0\" encoding=\"UTF-8\"")), this->firstChild()); + insertBefore( + createProcessingInstruction(QStringLiteral("xml"), QStringLiteral("version=\"1.0\" encoding=\"UTF-8\"")), + this->firstChild()); } //--------------------------------------------------------------------------------------------------------------------- @@ -138,11 +140,11 @@ void VWatermark::SetWatermark(const VWatermarkData &data) { SetAttribute(text, AttrShow, data.showText); SetAttributeOrRemoveIf(text, AttrText, data.text, - [](const QString &text) noexcept {return text.isEmpty();}); + [](const QString &text) noexcept { return text.isEmpty(); }); SetAttributeOrRemoveIf(text, AttrRotation, data.textRotation, - [](int textRotation) noexcept {return textRotation == 0;}); + [](int textRotation) noexcept { return textRotation == 0; }); SetAttributeOrRemoveIf(text, AttrFont, data.font.toString(), - [](const QString &fontString) noexcept {return fontString.isEmpty();}); + [](const QString &fontString) noexcept { return fontString.isEmpty(); }); SetAttribute(text, AttrColor, data.textColor.name()); } @@ -151,11 +153,11 @@ void VWatermark::SetWatermark(const VWatermarkData &data) { SetAttribute(image, AttrShow, data.showImage); SetAttributeOrRemoveIf(image, AttrPath, data.path, - [](const QString &path) noexcept {return path.isEmpty();}); + [](const QString &path) noexcept { return path.isEmpty(); }); SetAttributeOrRemoveIf(image, AttrRotation, data.imageRotation, - [](int imageRotation) noexcept {return imageRotation == 0;}); + [](int imageRotation) noexcept { return imageRotation == 0; }); SetAttributeOrRemoveIf(image, AttrGrayscale, data.grayscale, - [](bool grayscale) noexcept {return not grayscale;}); + [](bool grayscale) noexcept { return not grayscale; }); } } } diff --git a/src/libs/vganalytics/vganalytics.cpp b/src/libs/vganalytics/vganalytics.cpp index acdf4f167..9fd56d83c 100644 --- a/src/libs/vganalytics/vganalytics.cpp +++ b/src/libs/vganalytics/vganalytics.cpp @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/libs/vgeometry/vgobject.cpp b/src/libs/vgeometry/vgobject.cpp index c3b07c0b3..2427a2605 100644 --- a/src/libs/vgeometry/vgobject.cpp +++ b/src/libs/vgeometry/vgobject.cpp @@ -37,10 +37,11 @@ #include #include -#include "../vmisc/def.h" #include "../vmisc/compatibility.h" -#include "vgobject_p.h" +#include "../vmisc/def.h" #include "../vmisc/vabstractapplication.h" +#include "vgeometry/vgeometrydef.h" +#include "vgobject_p.h" namespace { @@ -82,15 +83,16 @@ auto GetEpsilon(const QPointF &t, QPointF p1, QPointF p2, qreal accuracy) -> dou return qAbs(PerpDotProduct(p1, p2, line.p2())); } -} // namespace +} // namespace //--------------------------------------------------------------------------------------------------------------------- /** * @brief VGObject default constructor. */ VGObject::VGObject() - :d(new VGObjectData) -{} + : d(new VGObjectData) +{ +} //--------------------------------------------------------------------------------------------------------------------- /** @@ -100,8 +102,9 @@ VGObject::VGObject() * @param mode mode creation. Used in modeling mode. */ VGObject::VGObject(const GOType &type, const quint32 &idObject, const Draw &mode) - :d(new VGObjectData(type, idObject, mode)) -{} + : d(new VGObjectData(type, idObject, mode)) +{ +} //--------------------------------------------------------------------------------------------------------------------- /** @@ -109,8 +112,9 @@ VGObject::VGObject(const GOType &type, const quint32 &idObject, const Draw &mode * @param obj object. */ VGObject::VGObject(const VGObject &obj) // NOLINT(modernize-use-equals-default) - :d (obj.d) -{} + : d(obj.d) +{ +} //--------------------------------------------------------------------------------------------------------------------- /** @@ -120,7 +124,7 @@ VGObject::VGObject(const VGObject &obj) // NOLINT(modernize-use-equals-default) */ auto VGObject::operator=(const VGObject &obj) -> VGObject & { - if ( &obj == this ) + if (&obj == this) { return *this; } @@ -130,12 +134,13 @@ auto VGObject::operator=(const VGObject &obj) -> VGObject & #ifdef Q_COMPILER_RVALUE_REFS //--------------------------------------------------------------------------------------------------------------------- -VGObject::VGObject(VGObject &&obj) Q_DECL_NOTHROW - :d (std::move(obj.d)) -{} +VGObject::VGObject(VGObject &&obj) noexcept + : d(std::move(obj.d)) +{ +} //--------------------------------------------------------------------------------------------------------------------- -auto VGObject::operator=(VGObject &&obj) Q_DECL_NOTHROW -> VGObject & +auto VGObject::operator=(VGObject &&obj) noexcept -> VGObject & { std::swap(d, obj.d); return *this; @@ -144,7 +149,8 @@ auto VGObject::operator=(VGObject &&obj) Q_DECL_NOTHROW -> VGObject & //--------------------------------------------------------------------------------------------------------------------- VGObject::~VGObject() // NOLINT(modernize-use-equals-default) -{} +{ +} //--------------------------------------------------------------------------------------------------------------------- /** @@ -293,8 +299,7 @@ auto VGObject::getIdTool() const -> quint32 //--------------------------------------------------------------------------------------------------------------------- auto VGObject::ToJson() const -> QJsonObject { - QJsonObject object - { + QJsonObject object{ {"id", static_cast(id())}, {"type", static_cast(getType())}, }; @@ -307,7 +312,7 @@ auto VGObject::BuildLine(const QPointF &p1, const qreal &length, const qreal &an { QLineF line = QLineF(); line.setP1(p1); - line.setAngle(angle);// First set angle then length. Length can have negative value. + line.setAngle(angle); // First set angle then length. Length can have negative value. line.setLength(length); return line; } @@ -324,7 +329,8 @@ auto VGObject::BuildRay(const QPointF &firstPoint, const qreal &angle, const QRe if (not rect.contains(firstPoint)) { // If point outside of scene rect create one around point and unite two rects. - QRectF rectangle(firstPoint.x()-rect.width()/2, firstPoint.y()-rect.height()/2, rect.width(), rect.height()); + QRectF rectangle(firstPoint.x() - rect.width() / 2, firstPoint.y() - rect.height() / 2, rect.width(), + rect.height()); rect = rect.united(rectangle); } const qreal diagonal = qSqrt(pow(rect.height(), 2) + pow(rect.width(), 2)); @@ -336,7 +342,7 @@ auto VGObject::BuildRay(const QPointF &firstPoint, const qreal &angle, const QRe //--------------------------------------------------------------------------------------------------------------------- auto VGObject::BuildAxis(const QPointF &p, const qreal &angle, const QRectF &scRect) -> QLineF { - const QPointF endP1 = BuildRay(p, angle+180, scRect); + const QPointF endP1 = BuildRay(p, angle + 180, scRect); const QPointF endP2 = BuildRay(p, angle, scRect); return {endP1, endP2}; } @@ -363,8 +369,8 @@ auto VGObject::ContactPoints(const QPointF &p, const QPointF ¢er, qreal radi return 1; } - const double d = QLineF (p, center).length(); - const double k = sqrt (d * d - radius * radius); + const double d = QLineF(p, center).length(); + const double k = sqrt(d * d - radius * radius); return IntersectionCircles(p, k, center, radius, p1, p2); } @@ -382,28 +388,28 @@ auto VGObject::LineIntersectRect(const QRectF &rec, const QLineF &line) -> QPoin QPointF point; QLineF::IntersectType type = Intersects(line, QLineF(QPointF(x1, y1), QPointF(x1, y2)), &point); - if ( type == QLineF::BoundedIntersection ) + if (type == QLineF::BoundedIntersection) { return point; } type = Intersects(line, QLineF(QPointF(x1, y1), QPointF(x2, y1)), &point); - if ( type == QLineF::BoundedIntersection ) + if (type == QLineF::BoundedIntersection) { return point; } type = Intersects(line, QLineF(QPointF(x1, y2), QPointF(x2, y2)), &point); - if ( type == QLineF::BoundedIntersection ) + if (type == QLineF::BoundedIntersection) { return point; } type = Intersects(line, QLineF(QPointF(x2, y1), QPointF(x2, y2)), &point); - if ( type == QLineF::BoundedIntersection ) + if (type == QLineF::BoundedIntersection) { return point; } @@ -411,33 +417,34 @@ auto VGObject::LineIntersectRect(const QRectF &rec, const QLineF &line) -> QPoin } //--------------------------------------------------------------------------------------------------------------------- -auto VGObject::IntersectionCircles(const QPointF &c1, double r1, const QPointF &c2, double r2, QPointF &p1, QPointF &p2) -> int +auto VGObject::IntersectionCircles(const QPointF &c1, double r1, const QPointF &c2, double r2, QPointF &p1, QPointF &p2) + -> int { - if (VFuzzyComparePossibleNulls(c1.x(), c2.x()) && VFuzzyComparePossibleNulls(c1.y(), c2.y()) - && VFuzzyComparePossibleNulls(r1, r2)) + if (VFuzzyComparePossibleNulls(c1.x(), c2.x()) && VFuzzyComparePossibleNulls(c1.y(), c2.y()) && + VFuzzyComparePossibleNulls(r1, r2)) { - return 3;// Circles are equal + return 3; // Circles are equal } - const double a = - 2.0 * (c2.x() - c1.x()); - const double b = - 2.0 * (c2.y() - c1.y()); - const double c = (c2.x() - c1.x())* (c2.x() - c1.x()) + (c2.y() - c1.y()) * (c2.y() - c1.y()) + r1 * r1 - r2 * r2; + const double a = -2.0 * (c2.x() - c1.x()); + const double b = -2.0 * (c2.y() - c1.y()); + const double c = (c2.x() - c1.x()) * (c2.x() - c1.x()) + (c2.y() - c1.y()) * (c2.y() - c1.y()) + r1 * r1 - r2 * r2; - const double x0 = -a*c/(a*a+b*b); - const double y0 = -b*c/(a*a+b*b); + const double x0 = -a * c / (a * a + b * b); + const double y0 = -b * c / (a * a + b * b); - if (c*c > r1*r1*(a*a+b*b)) + if (c * c > r1 * r1 * (a * a + b * b)) { return 0; } - if (VFuzzyComparePossibleNulls(c*c, r1*r1*(a*a+b*b))) + if (VFuzzyComparePossibleNulls(c * c, r1 * r1 * (a * a + b * b))) { - p1 = QPointF(x0 + c1.x(), y0 + c1.y()); + p1 = QPointF(x0 + c1.x(), y0 + c1.y()); return 1; } - const double d = r1*r1 - c*c/(a*a+b*b); - const double mult = sqrt (d / (a*a+b*b)); + const double d = r1 * r1 - c * c / (a * a + b * b); + const double mult = sqrt(d / (a * a + b * b)); const double ax = x0 + b * mult; const double bx = x0 - b * mult; @@ -459,8 +466,8 @@ auto VGObject::IntersectionCircles(const QPointF &c1, double r1, const QPointF & * @param p2 second intersection point. * @return 0 - intersection doesn't exist, 1 - one intersection point, 2 - two intersection points. */ -auto VGObject::LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1, - QPointF &p2) -> qint32 +auto VGObject::LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1, QPointF &p2) + -> qint32 { // Fix for issue #485. https://bitbucket.org/dismine/valentina/issues/485/error-when-drawing-a-curved-path if (qFuzzyIsNull(line.length())) @@ -468,14 +475,14 @@ auto VGObject::LineIntersectCircle(const QPointF ¢er, qreal radius, const QL return 0; } - //coefficient for equation of segment + // coefficient for equation of segment qreal a = 0, b = 0, c = 0; LineCoefficients(line, &a, &b, &c); // projection center of circle on to line - const QPointF p = ClosestPoint (line, center); + const QPointF p = ClosestPoint(line, center); // how many solutions? qint32 flag = 0; - const qreal d = QLineF (center, p).length(); + const qreal d = QLineF(center, p).length(); if (VFuzzyComparePossibleNulls(d, radius)) { flag = 1; @@ -492,11 +499,11 @@ auto VGObject::LineIntersectCircle(const QPointF ¢er, qreal radius, const QL } } // find distance from projection to points of intersection - const qreal k = qSqrt (qAbs(radius * radius - d * d)); - const qreal t = QLineF (QPointF (0, 0), QPointF (b, - a)).length(); + const qreal k = qSqrt(qAbs(radius * radius - d * d)); + const qreal t = QLineF(QPointF(0, 0), QPointF(b, -a)).length(); // add to projection a vectors aimed to points of intersection - p1 = addVector (p, QPointF (0, 0), QPointF (- b, a), k / t); - p2 = addVector (p, QPointF (0, 0), QPointF (b, - a), k / t); + p1 = addVector(p, QPointF(0, 0), QPointF(-b, a), k / t); + p2 = addVector(p, QPointF(0, 0), QPointF(b, -a), k / t); return flag; } @@ -512,7 +519,7 @@ auto VGObject::ClosestPoint(const QLineF &line, const QPointF &point) -> QPointF LineCoefficients(line, &a, &b, &c); qreal x = point.x() + a; qreal y = b + point.y(); - QLineF lin (point, QPointF(x, y)); + QLineF lin(point, QPointF(x, y)); QPointF p; QLineF::IntersectType intersect = Intersects(line, lin, &p); @@ -540,11 +547,11 @@ auto VGObject::addVector(const QPointF &p, const QPointF &p1, const QPointF &p2, */ void VGObject::LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c) { - //coefficient for equation of segment + // coefficient for equation of segment QPointF p1 = line.p1(); *a = line.p2().y() - p1.y(); *b = p1.x() - line.p2().x(); - *c = - *a * p1.x() - *b * p1.y(); + *c = -*a * p1.x() - *b * p1.y(); } //--------------------------------------------------------------------------------------------------------------------- @@ -572,33 +579,33 @@ auto VGObject::IsPointOnLineSegment(const QPointF &t, const QPointF &p1, const Q // should be good enough for us. const qreal degrees = 90; QLineF edge(p1, p2); - edge.setAngle(edge.angle()+degrees); + edge.setAngle(edge.angle() + degrees); edge.setLength(accuracy); QPointF sP1 = edge.p2(); edge = QLineF(p2, p1); - edge.setAngle(edge.angle()-degrees); + edge.setAngle(edge.angle() - degrees); edge.setLength(accuracy); QPointF sP2 = edge.p2(); edge = QLineF(p2, p1); - edge.setAngle(edge.angle()+degrees); + edge.setAngle(edge.angle() + degrees); edge.setLength(accuracy); QPointF sP3 = edge.p2(); edge = QLineF(p1, p2); - edge.setAngle(edge.angle()-degrees); + edge.setAngle(edge.angle() - degrees); edge.setLength(accuracy); QPointF sP4 = edge.p2(); QVector shape{sP1, sP2, sP3, sP4, sP1}; - for (int i=0; i < shape.size()-1; ++i) + for (int i = 0; i < shape.size() - 1; ++i) { const QPointF &sp1 = shape.at(i); - const QPointF &sp2 = shape.at(i+1); + const QPointF &sp2 = shape.at(i + 1); // This formula helps to determine on which side of a vector lies a point. - qreal position = (sp2.x()-sp1.x())*(t.y()-sp1.y())-(sp2.y()-sp1.y())*(t.x()-sp1.x()); + qreal position = (sp2.x() - sp1.x()) * (t.y() - sp1.y()) - (sp2.y() - sp1.y()) * (t.x() - sp1.x()); if (position < 0) { return false; @@ -612,13 +619,13 @@ auto VGObject::IsPointOnLineSegment(const QPointF &t, const QPointF &p1, const Q auto VGObject::IsLineSegmentOnLineSegment(const QLineF &seg1, const QLineF &seg2, qreal accuracy) -> bool { const bool onLine = IsPointOnLineviaPDP(seg1.p1(), seg2.p1(), seg2.p2(), accuracy) && - IsPointOnLineviaPDP(seg1.p2(), seg2.p1(), seg2.p2(), accuracy); + IsPointOnLineviaPDP(seg1.p2(), seg2.p1(), seg2.p2(), accuracy); if (onLine) { return IsPointOnLineSegment(seg1.p1(), seg2.p1(), seg2.p2(), accuracy) || - IsPointOnLineSegment(seg1.p2(), seg2.p1(), seg2.p2(), accuracy) || - IsPointOnLineSegment(seg2.p1(), seg1.p1(), seg1.p2(), accuracy) || - IsPointOnLineSegment(seg2.p2(), seg1.p1(), seg1.p2(), accuracy); + IsPointOnLineSegment(seg1.p2(), seg2.p1(), seg2.p2(), accuracy) || + IsPointOnLineSegment(seg2.p1(), seg1.p1(), seg1.p2(), accuracy) || + IsPointOnLineSegment(seg2.p2(), seg1.p1(), seg1.p2(), accuracy); } return onLine; @@ -654,7 +661,7 @@ auto VGObject::IsPointOnLineviaPDP(const QPointF &t, const QPointF &p1, const QP //--------------------------------------------------------------------------------------------------------------------- auto VGObject::PointInCircle(const QPointF &p, const QPointF ¢er, qreal radius) -> int { - const double d = QLineF (p, center).length(); + const double d = QLineF(p, center).length(); if (VFuzzyComparePossibleNulls(radius, d)) { return 1; // on circle @@ -681,9 +688,9 @@ auto VGObject::GetLengthContour(const QVector &contour, const QVector points; points << contour << newPoints; - for (qint32 i = 0; i < points.size()-1; ++i) + for (qint32 i = 0; i < points.size() - 1; ++i) { - QLineF line(points.at(i), points.at(i+1)); + QLineF line(points.at(i), points.at(i + 1)); length += line.length(); } return qFloor(length); @@ -712,13 +719,13 @@ auto VGObject::FlippingMatrix(const QLineF &axis) -> QTransform m.reset(); m.translate(p2.x(), p2.y()); - m.scale(m.m11(), m.m22()*-1); + m.scale(m.m11(), m.m22() * -1); m.translate(-p2.x(), -p2.y()); matrix *= m; m.reset(); m.translate(p2.x(), p2.y()); - m.rotate(-(360-angle)); + m.rotate(-(360 - angle)); m.translate(-p2.x(), -p2.y()); matrix *= m; diff --git a/src/libs/vlayout/vlayoutdef.h b/src/libs/vlayout/vlayoutdef.h index e25ef9b11..fcedbfd62 100644 --- a/src/libs/vlayout/vlayoutdef.h +++ b/src/libs/vlayout/vlayoutdef.h @@ -29,9 +29,9 @@ #ifndef VLAYOUTDEF_H #define VLAYOUTDEF_H +#include #include #include -#include #include #include @@ -79,19 +79,19 @@ enum class BestFrom : qint8 struct VBestSquareResData { - QSizeF bestSize{INT_MAX, INT_MAX}; + QSizeF bestSize{INT_MAX, INT_MAX}; // cppcheck-suppress unusedStructMember - int globalI{0}; // Edge of global contour + int globalI{0}; // Edge of global contour // cppcheck-suppress unusedStructMember - int detJ{0}; // Edge of detail - QTransform resMatrix{}; // Matrix for rotation and translation detail + int detJ{0}; // Edge of detail + QTransform resMatrix{}; // Matrix for rotation and translation detail // cppcheck-suppress unusedStructMember - bool resMirror{false}; - BestFrom type{BestFrom::Rotation}; + bool resMirror{false}; + BestFrom type{BestFrom::Rotation}; // cppcheck-suppress unusedStructMember - qreal depthPosition{INT_MAX}; + qreal depthPosition{INT_MAX}; // cppcheck-suppress unusedStructMember - qreal sidePosition{0}; + qreal sidePosition{0}; }; struct VCachedPositions @@ -100,28 +100,34 @@ struct VCachedPositions QPainterPath layoutAllowancePath{}; }; -enum class Cases : qint8 { CaseThreeGroup = 0, CaseTwoGroup, CaseDesc, UnknownCase}; +enum class Cases : qint8 +{ + CaseThreeGroup = 0, + CaseTwoGroup, + CaseDesc, + UnknownCase +}; /* Warning! Debugging doesn't work stable in debug mode. If you need big allocation use release mode. Or disable * Address Sanitizer. See page https://bitbucket.org/dismine/valentina/wiki/developers/Address_Sanitizer */ -//#define LAYOUT_DEBUG // Enable debug mode +// #define LAYOUT_DEBUG // Enable debug mode // This block help rule debug mode. Don't turn all options at the same time! #ifdef LAYOUT_DEBUG // Nice looking -# define SHOW_VERTICES // Show contour vertices -# define SHOW_DIRECTION // Show contour direction -# define ARRANGED_DETAILS // Show already arranged details -# define SHOW_SHEET // Show sheet rect -# define SHOW_CANDIDATE // Show each position +#define SHOW_VERTICES // Show contour vertices +#define SHOW_DIRECTION // Show contour direction +#define ARRANGED_DETAILS // Show already arranged details +#define SHOW_SHEET // Show sheet rect +#define SHOW_CANDIDATE // Show each position // Debugging -//# define SHOW_ROTATION // For each position show rotation part -//# define SHOW_COMBINE // For each position show edge combine part -//# define SHOW_MIRROR // For each position show mirror part -//# define SHOW_CANDIDATE_BEST // For only correct positions that pass checks -# define SHOW_BEST // Show only best position for workpiece -#endif//LAYOUT_DEBUG +// # define SHOW_ROTATION // For each position show rotation part +// # define SHOW_COMBINE // For each position show edge combine part +// # define SHOW_MIRROR // For each position show mirror part +// # define SHOW_CANDIDATE_BEST // For only correct positions that pass checks +#define SHOW_BEST // Show only best position for workpiece +#endif // LAYOUT_DEBUG #endif // VLAYOUTDEF_H diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 779562a76..65e2fe0de 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,8 @@ #include #include +#include "../vformat/vsinglelineoutlinechar.h" +#include "../vgeometry/vgobject.h" #include "../vgeometry/vlayoutplacelabel.h" #include "../vgeometry/vplacelabelitem.h" #include "../vgeometry/vpointf.h" @@ -62,15 +65,10 @@ #include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vpassmark.h" #include "../vpatterndb/vpiecenode.h" -#include "../vwidgets/global.h" -#include "vgobject.h" +#include "../vwidgets/vpiecegrainline.h" #include "vgraphicsfillitem.h" #include "vlayoutpiece_p.h" -#include "vpiecegrainline.h" -#include "vsinglelineoutlinechar.h" #include "vtextmanager.h" -#include -#include namespace { @@ -773,7 +771,7 @@ auto VLayoutPiece::Map(const GrainlineShape &shape) const -> GrainlineShape GrainlineShape mappedShape; mappedShape.reserve(shape.size()); - for (auto subShape : shape) + for (const auto &subShape : shape) { mappedShape.append(Map(subShape)); } diff --git a/src/libs/vlayout/vlayoutpiece.h b/src/libs/vlayout/vlayoutpiece.h index f7b2cdabb..13d146df6 100644 --- a/src/libs/vlayout/vlayoutpiece.h +++ b/src/libs/vlayout/vlayoutpiece.h @@ -41,7 +41,6 @@ #include #include "../vmisc/typedef.h" -#include "../vpatterndb/floatItemData/floatitemdef.h" #include "../vwidgets/vpiecegrainline.h" #include "qpainterpath.h" #include "vabstractpiece.h" diff --git a/src/libs/vlayout/vlayoutpiecepath.h b/src/libs/vlayout/vlayoutpiecepath.h index 471ad2c7e..aa49afa84 100644 --- a/src/libs/vlayout/vlayoutpiecepath.h +++ b/src/libs/vlayout/vlayoutpiecepath.h @@ -30,9 +30,9 @@ #define VLAYOUTPIECEPATH_H #include "vlayoutpoint.h" +#include #include #include -#include class VLayoutPiecePathData; class QPainterPath; @@ -48,17 +48,17 @@ public: auto operator=(const VLayoutPiecePath &path) -> VLayoutPiecePath &; #ifdef Q_COMPILER_RVALUE_REFS - VLayoutPiecePath(VLayoutPiecePath &&path) Q_DECL_NOTHROW; - auto operator=(VLayoutPiecePath &&path) Q_DECL_NOTHROW->VLayoutPiecePath &; + VLayoutPiecePath(VLayoutPiecePath &&path) noexcept; + auto operator=(VLayoutPiecePath &&path) noexcept -> VLayoutPiecePath &; #endif auto GetPainterPath() const -> QPainterPath; auto Points() const -> QVector; - void SetPoints(const QVector &points); + void SetPoints(const QVector &points); auto PenStyle() const -> Qt::PenStyle; - void SetPenStyle(const Qt::PenStyle &penStyle); + void SetPenStyle(const Qt::PenStyle &penStyle); auto IsCutPath() const -> bool; void SetCutPath(bool cut); @@ -70,7 +70,7 @@ private: QSharedDataPointer d; }; -Q_DECLARE_METATYPE(VLayoutPiecePath) +Q_DECLARE_METATYPE(VLayoutPiecePath) // NOLINT Q_DECLARE_TYPEINFO(VLayoutPiecePath, Q_MOVABLE_TYPE); // NOLINT #endif // VLAYOUTPIECEPATH_H diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 7b7e8ae1b..b3c7a2663 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -483,14 +483,19 @@ const int userMaterialPlaceholdersQuantity = 20; auto QPixmapFromCache(const QString &pixmapPath) -> QPixmap; void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX = -1, int hotY = -1); +//--------------------------------------------------------------------------------------------------------------------- template constexpr inline auto MmToPixel(T val) noexcept -> T { return (val / 25.4) * PrintDPI; } + +//--------------------------------------------------------------------------------------------------------------------- template constexpr inline auto CmToPixel(T val) noexcept -> T { return ((val * 10.0) / 25.4) * PrintDPI; } + +//--------------------------------------------------------------------------------------------------------------------- template constexpr inline auto InchToPixel(T val) noexcept -> T { return val * PrintDPI; @@ -515,14 +520,19 @@ Q_DECL_RELAXED_CONSTEXPR inline auto ToPixel(double val, const Unit &unit) -> do return 0; } +//--------------------------------------------------------------------------------------------------------------------- template constexpr inline auto PixelToInch(T pix) -> T { return pix / PrintDPI; } + +//--------------------------------------------------------------------------------------------------------------------- template constexpr inline auto PixelToMm(T pix) -> T { return PixelToInch(pix) * 25.4; } + +//--------------------------------------------------------------------------------------------------------------------- template constexpr inline auto PixelToCm(T pix) -> T { return PixelToInch(pix) * 2.54; @@ -547,16 +557,23 @@ Q_DECL_RELAXED_CONSTEXPR inline auto FromPixel(double pix, const Unit &unit) -> return 0; } +//--------------------------------------------------------------------------------------------------------------------- template constexpr inline auto Inch2ToPixel2(T val) -> T { return val * (PrintDPI * PrintDPI); } + +//--------------------------------------------------------------------------------------------------------------------- template constexpr inline auto Mm2ToPixel2(T val) -> T { + // There are 0.15500031 square inches in a square centimeter. return Inch2ToPixel2(val * 0.001550031); } + +//--------------------------------------------------------------------------------------------------------------------- template constexpr inline auto Cm2ToPixel2(T val) -> T { + // There are 0.15500031 square inches in a square centimeter. return Inch2ToPixel2(val * 0.15500031); } @@ -579,16 +596,23 @@ Q_DECL_RELAXED_CONSTEXPR inline auto ToPixel2(double val, const Unit &unit) -> d return 0; } +//--------------------------------------------------------------------------------------------------------------------- template constexpr inline auto Pixel2ToInch2(T pix) -> T { return pix / (PrintDPI * PrintDPI); } + +//--------------------------------------------------------------------------------------------------------------------- template constexpr inline auto Pixel2ToMm2(T pix) -> T { + // There are 0.15500031 square inches in a square centimeter. return Pixel2ToInch2(pix) / 0.001550031; } + +//--------------------------------------------------------------------------------------------------------------------- template constexpr inline auto Pixel2ToCm2(T pix) -> T { + // There are 0.15500031 square inches in a square centimeter. return Pixel2ToInch2(pix) / 0.15500031; }