diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 680683785..4de28a48b 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -175,7 +175,7 @@ QVector PrepareAllowance(const QVector &points) { QVector allowancePoints; allowancePoints.reserve(points.size()); - for(auto point : points) + for(auto &point : points) { allowancePoints.append(VSAPoint(point)); } @@ -206,8 +206,9 @@ QStringList PieceLabelText(const QVector &labelShape, const VTextManage QStringList text; if (labelShape.count() > 2) { - text.reserve(tm.GetSourceLinesCount()); - for (int i = 0; i < tm.GetSourceLinesCount(); ++i) + int sourceCount = tm.GetSourceLinesCount(); + text.reserve(sourceCount); + for (int i = 0; i < sourceCount; ++i) { text.append(tm.GetSourceLine(i).m_qsText); } @@ -219,9 +220,9 @@ QStringList PieceLabelText(const QVector &labelShape, const VTextManage QVector ConvertPlaceLabels(const VPiece &piece, const VContainer *pattern) { QVector labels; - const QVector placeLabels = piece.GetPlaceLabels(); + const auto placeLabels = piece.GetPlaceLabels(); labels.reserve(placeLabels.size()); - for(auto placeLabel : placeLabels) + for(auto &placeLabel : placeLabels) { const auto label = pattern->GeometricObject(placeLabel); if (label->IsVisible()) @@ -507,20 +508,11 @@ VLayoutPiece VLayoutPiece::Create(const VPiece &piece, vidtype id, const VContai template QVector VLayoutPiece::Map(QVector points) const { - for (int i = 0; i < points.size(); ++i) - { - points[i] = d->matrix.map(points.at(i)); - } - + std::transform(points.begin(), points.end(), points.begin(), + [this](const auto &point) { return d->matrix.map(point); }); if (d->mirror) { - QList list = ConvertToList(points); - - for (int k=0, s=list.size(), max=(s/2); k &path, int i) const } //--------------------------------------------------------------------------------------------------------------------- +// NOTE: Once C++17 is made mandatory, this method can further be refactored with std::optional int VLayoutPiece::EdgeByPoint(const QVector &path, const QPointF &p1) const { - if (p1.isNull()) + if (p1.isNull() || path.count() < 3) { return 0; } - if (path.count() < 3) + const auto points = Map(path); + const auto posIter = std::find_if(points.cbegin(), points.cend(), + [&p1](const auto &point){ return VFuzzyComparePoints(point, p1); }); + if (posIter != points.cend()) { - return 0; - } - - const QVector points = Map(path); - for (int i=0; i < points.size(); i++) - { - if (VFuzzyComparePoints(points.at(i), p1)) - { - int pos = i+1; - if (pos > points.size()) - { - pos = 1; - } - return pos; - } + return static_cast(posIter - points.cbegin() + 1); } return 0; // Did not find edge } diff --git a/src/libs/vmisc/compatibility.h b/src/libs/vmisc/compatibility.h index d8184e3f7..92cad1947 100644 --- a/src/libs/vmisc/compatibility.h +++ b/src/libs/vmisc/compatibility.h @@ -148,15 +148,16 @@ inline QVector ConvertToVector(const QSet &container) } //--------------------------------------------------------------------------------------------------------------------- -template -inline void SwapItemsAt(T &container, int i, int j) -{ -#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) - container.swapItemsAt(i, j); -#else - container.swap(i, j); -#endif -} +// NOTE: Delete if not necessary anymore +//template +//inline void SwapItemsAt(T &container, int i, int j) +//{ +//#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) +// container.swapItemsAt(i, j); +//#else +// container.swap(i, j); +//#endif +//} //--------------------------------------------------------------------------------------------------------------------- template