Refactoring. Hide compatibility layer behind a function.

constLast(), move(), append().

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2020-01-17 15:14:00 +02:00
parent ad45daddeb
commit 716192e520
4 changed files with 59 additions and 51 deletions

View File

@ -29,6 +29,7 @@
#include "dialogfinalmeasurements.h" #include "dialogfinalmeasurements.h"
#include "ui_dialogfinalmeasurements.h" #include "ui_dialogfinalmeasurements.h"
#include "../vmisc/vsettings.h" #include "../vmisc/vsettings.h"
#include "../vmisc/compatibility.h"
#include "../qmuparser/qmudef.h" #include "../qmuparser/qmudef.h"
#include "../qmuparser/qmutokenparser.h" #include "../qmuparser/qmutokenparser.h"
#include "../vpatterndb/vtranslatevars.h" #include "../vpatterndb/vtranslatevars.h"
@ -38,31 +39,6 @@
#define DIALOG_MAX_FORMULA_HEIGHT 64 #define DIALOG_MAX_FORMULA_HEIGHT 64
namespace
{
#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
template <typename T>
void Move(QVector<T> &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) DialogFinalMeasurements::DialogFinalMeasurements(VPattern *doc, QWidget *parent)
: QDialog(parent), : QDialog(parent),
@ -314,12 +290,7 @@ void DialogFinalMeasurements::MoveUp()
return; return;
} }
#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
Move(m_measurements, row, row-1); Move(m_measurements, row, row-1);
#else
m_measurements.move(row, row-1);
#endif
UpdateTree(); UpdateTree();
ui->tableWidget->selectRow(row-1); ui->tableWidget->selectRow(row-1);
@ -336,12 +307,7 @@ void DialogFinalMeasurements::MoveDown()
return; return;
} }
#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
Move(m_measurements, row, row+1); Move(m_measurements, row, row+1);
#else
m_measurements.move(row, row+1);
#endif
UpdateTree(); UpdateTree();
ui->tableWidget->selectRow(row+1); ui->tableWidget->selectRow(row+1);

View File

@ -369,11 +369,7 @@ qreal VSplinePath::GetEndAngle() const
{ {
if (CountPoints() > 0) if (CountPoints() > 0)
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) return ConstLast(GetSplinePath()).Angle1();
return GetSplinePath().constLast().Angle1();
#else
return GetSplinePath().last().Angle1(); // clazy:exclude=detaching-temporary
#endif
} }
else else
{ {

View File

@ -58,6 +58,28 @@ inline const T& ConstFirst (const C &container)
#endif #endif
} }
//---------------------------------------------------------------------------------------------------------------------
template <typename T, template <typename> class Cont>
inline const T& ConstLast (const Cont<T> &container)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
return container.constLast();
#else
return container.last(); // clazy:exclude=detaching-temporary
#endif
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T, typename C>
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 <typename T> template <typename T>
inline typename T::IntersectType Intersects(const T &l1, const T &l2, QPointF *intersectionPoint) 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 #endif
} }
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
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 <typename Cont, typename Input>
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 #endif // COMPATIBILITY_H

View File

@ -59,6 +59,7 @@
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "../vmisc/vcommonsettings.h" #include "../vmisc/vcommonsettings.h"
#include "../vmisc/diagnostic.h" #include "../vmisc/diagnostic.h"
#include "../vmisc/compatibility.h"
#include "../vpatterndb/vcontainer.h" #include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/vformula.h" #include "../vpatterndb/vformula.h"
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
@ -99,18 +100,8 @@ QPointF GetOriginPoint(const QVector<quint32> objects, const VContainer *data, q
case GOType::SplinePath: case GOType::SplinePath:
case GOType::CubicBezier: case GOType::CubicBezier:
case GOType::CubicBezierPath: case GOType::CubicBezierPath:
{ AppendTo(originObjects, data->GeometricObject<VAbstractCurve>(id)->GetPoints());
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
originObjects.append(data->GeometricObject<VAbstractCurve>(id)->GetPoints());
#else
const QVector<QPointF> points = data->GeometricObject<VAbstractCurve>(id)->GetPoints();
for (auto &point : points)
{
originObjects.append(point);
}
#endif // QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
break; break;
}
case GOType::Unknown: case GOType::Unknown:
case GOType::PlaceLabel: case GOType::PlaceLabel:
Q_UNREACHABLE(); Q_UNREACHABLE();