diff --git a/src/app/valentina/dialogs/dialogfinalmeasurements.cpp b/src/app/valentina/dialogs/dialogfinalmeasurements.cpp index c5f612956..6f6250869 100644 --- a/src/app/valentina/dialogs/dialogfinalmeasurements.cpp +++ b/src/app/valentina/dialogs/dialogfinalmeasurements.cpp @@ -29,6 +29,7 @@ #include "dialogfinalmeasurements.h" #include "ui_dialogfinalmeasurements.h" #include "../vmisc/vsettings.h" +#include "../vmisc/compatibility.h" #include "../qmuparser/qmudef.h" #include "../qmuparser/qmutokenparser.h" #include "../vpatterndb/vtranslatevars.h" @@ -38,31 +39,6 @@ #define DIALOG_MAX_FORMULA_HEIGHT 64 -namespace -{ -#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) -template -void Move(QVector &vector, int from, int to) -{ - Q_ASSERT_X(from >= 0 && from < vector.size(), "QVector::move(int,int)", "'from' is out-of-range"); - Q_ASSERT_X(to >= 0 && to < vector.size(), "QVector::move(int,int)", "'to' is out-of-range"); - if (from == to) // don't detach when no-op - { - return; - } - T * const b = vector.begin(); - if (from < to) - { - std::rotate(b + from, b + from + 1, b + to + 1); - } - else - { - std::rotate(b + to, b + from, b + from + 1); - } -} -#endif // QT_VERSION < QT_VERSION_CHECK(5, 6, 0) -} - //--------------------------------------------------------------------------------------------------------------------- DialogFinalMeasurements::DialogFinalMeasurements(VPattern *doc, QWidget *parent) : QDialog(parent), @@ -314,12 +290,7 @@ void DialogFinalMeasurements::MoveUp() return; } -#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) Move(m_measurements, row, row-1); -#else - m_measurements.move(row, row-1); -#endif - UpdateTree(); ui->tableWidget->selectRow(row-1); @@ -336,12 +307,7 @@ void DialogFinalMeasurements::MoveDown() return; } -#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) Move(m_measurements, row, row+1); -#else - m_measurements.move(row, row+1); -#endif - UpdateTree(); ui->tableWidget->selectRow(row+1); diff --git a/src/libs/vgeometry/vsplinepath.cpp b/src/libs/vgeometry/vsplinepath.cpp index 6c92ecee1..6c4df33e9 100644 --- a/src/libs/vgeometry/vsplinepath.cpp +++ b/src/libs/vgeometry/vsplinepath.cpp @@ -369,11 +369,7 @@ qreal VSplinePath::GetEndAngle() const { if (CountPoints() > 0) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) - return GetSplinePath().constLast().Angle1(); -#else - return GetSplinePath().last().Angle1(); // clazy:exclude=detaching-temporary -#endif + return ConstLast(GetSplinePath()).Angle1(); } else { diff --git a/src/libs/vmisc/compatibility.h b/src/libs/vmisc/compatibility.h index 0c7d9ee05..da25b5139 100644 --- a/src/libs/vmisc/compatibility.h +++ b/src/libs/vmisc/compatibility.h @@ -58,6 +58,28 @@ inline const T& ConstFirst (const C &container) #endif } +//--------------------------------------------------------------------------------------------------------------------- +template class Cont> +inline const T& ConstLast (const Cont &container) +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) + return container.constLast(); +#else + return container.last(); // clazy:exclude=detaching-temporary +#endif +} + +//--------------------------------------------------------------------------------------------------------------------- +template +inline const T& ConstLast (const C &container) +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) + return container.constLast(); +#else + return container.last(); // clazy:exclude=detaching-temporary +#endif +} + //--------------------------------------------------------------------------------------------------------------------- template inline typename T::IntersectType Intersects(const T &l1, const T &l2, QPointF *intersectionPoint) @@ -135,4 +157,37 @@ inline void SwapItemsAt(T &container, int i, int j) #endif } +//--------------------------------------------------------------------------------------------------------------------- +template +inline void Move(T &vector, int from, int to) +{ +#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0) + Q_ASSERT_X(from >= 0 && from < vector.size(), "QVector::move(int,int)", "'from' is out-of-range"); + Q_ASSERT_X(to >= 0 && to < vector.size(), "QVector::move(int,int)", "'to' is out-of-range"); + if (from == to) // don't detach when no-op + { + return; + } + T * const b = vector.begin(); + from < to ? std::rotate(b + from, b + from + 1, b + to + 1): + std::rotate(b + to, b + from, b + from + 1); +#else + vector.move(from, to); +#endif // QT_VERSION < QT_VERSION_CHECK(5, 6, 0) +} + +//--------------------------------------------------------------------------------------------------------------------- +template +inline void AppendTo(Cont &container, const Input &input) +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) + container.append(input); +#else + for (auto &item : input) + { + container.append(item); + } +#endif // QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) +} + #endif // COMPATIBILITY_H diff --git a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp index 4f6d5662e..d2c3042d6 100644 --- a/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp +++ b/src/libs/vtools/tools/drawTools/operation/vtoolmove.cpp @@ -59,6 +59,7 @@ #include "../vmisc/vabstractapplication.h" #include "../vmisc/vcommonsettings.h" #include "../vmisc/diagnostic.h" +#include "../vmisc/compatibility.h" #include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vformula.h" #include "../ifc/ifcdef.h" @@ -99,18 +100,8 @@ QPointF GetOriginPoint(const QVector objects, const VContainer *data, q case GOType::SplinePath: case GOType::CubicBezier: case GOType::CubicBezierPath: - { -#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) - originObjects.append(data->GeometricObject(id)->GetPoints()); -#else - const QVector points = data->GeometricObject(id)->GetPoints(); - for (auto &point : points) - { - originObjects.append(point); - } -#endif // QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) + AppendTo(originObjects, data->GeometricObject(id)->GetPoints()); break; - } case GOType::Unknown: case GOType::PlaceLabel: Q_UNREACHABLE();