From d5a1f96bddd861c9ba30696d5d24e2598c30b445 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 28 May 2019 16:21:52 +0300 Subject: [PATCH] constFirst() introduced since Qt 5.6. --HG-- branch : develop --- src/libs/vgeometry/vellipticalarc.cpp | 6 +-- src/libs/vgeometry/vsplinepath.cpp | 62 +++------------------------ src/libs/vlayout/vlayoutpiece.cpp | 2 +- src/libs/vmisc/def.h | 11 +++++ src/libs/vmisc/vcommonsettings.cpp | 38 ++-------------- 5 files changed, 23 insertions(+), 96 deletions(-) diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index fed637732..e63e9e036 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -277,11 +277,7 @@ QVector VEllipticalArc::GetPoints() const const QList sub = path.toSubpathPolygons(); if (not sub.isEmpty()) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) - polygon = path.toSubpathPolygons().constFirst(); -#else - polygon = path.toSubpathPolygons().first(); // clazy:exclude=detaching-temporary -#endif + polygon = ConstFirst (path.toSubpathPolygons()); if (not polygon.isEmpty()) { polygon.removeFirst(); // remove point (0;0) diff --git a/src/libs/vgeometry/vsplinepath.cpp b/src/libs/vgeometry/vsplinepath.cpp index 4dd5ae029..df0553b21 100644 --- a/src/libs/vgeometry/vsplinepath.cpp +++ b/src/libs/vgeometry/vsplinepath.cpp @@ -326,18 +326,7 @@ const VSplinePoint &VSplinePath::at(int indx) const //--------------------------------------------------------------------------------------------------------------------- qreal VSplinePath::GetStartAngle() const { - if (CountPoints() > 0) - { -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) - return GetSplinePath().constFirst().Angle2(); -#else - return GetSplinePath().first().Angle2(); // clazy:exclude=detaching-temporary -#endif - } - else - { - return 0; - } + return CountPoints() > 0 ? ConstFirst (GetSplinePath()).Angle2() : 0; } //--------------------------------------------------------------------------------------------------------------------- @@ -360,66 +349,27 @@ qreal VSplinePath::GetEndAngle() const //--------------------------------------------------------------------------------------------------------------------- qreal VSplinePath::GetC1Length() const { - if (CountPoints() > 0) - { -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) - return GetSplinePath().constFirst().Length2(); -#else - return GetSplinePath().first().Length2(); // clazy:exclude=detaching-temporary -#endif - } - else - { - return 0; - } + return CountPoints() > 0 ? ConstFirst (GetSplinePath()).Length2() : 0; } //--------------------------------------------------------------------------------------------------------------------- qreal VSplinePath::GetC2Length() const { - if (CountPoints() > 0) - { -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) - return GetSplinePath().constLast().Length1(); -#else - return GetSplinePath().last().Length1(); // clazy:exclude=detaching-temporary -#endif - } - else - { - return 0; - } + return CountPoints() > 0 ? ConstFirst (GetSplinePath()).Length1() : 0; } //--------------------------------------------------------------------------------------------------------------------- VPointF VSplinePath::FirstPoint() const { - if (not d->path.isEmpty()) - { -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) - return d->path.constFirst().P(); -#else - return d->path.first().P(); // clazy:exclude=detaching-temporary -#endif - } - else - { - return VPointF(); - } + return not d->path.isEmpty() ? ConstFirst (d->path).P() : VPointF(); } //--------------------------------------------------------------------------------------------------------------------- VPointF VSplinePath::LastPoint() const { const qint32 count = CountSubSpl(); - if (count >= 1) - { - return d->path.at(count).P();// Take last point of the last real spline - } - else - { - return VPointF(); - } + return count >= 1 ? d->path.at(count).P() :// Take last point of the last real spline + VPointF(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index db2ef1d92..a0cf4dbc4 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -249,7 +249,7 @@ QVector ConvertPassmarks(const VPiece &piece, const VContainer if (nodeIndex != -1) { layoutPassmark.lines = passmark.BuiltInSAPassmark(piece, pattern); - layoutPassmark.baseLine = passmark.BuiltInSAPassmarkBaseLine(piece).constFirst(); + layoutPassmark.baseLine = ConstFirst (passmark.BuiltInSAPassmarkBaseLine(piece)); layoutPassmark.type = pData.passmarkLineType; layoutPassmark.isBuiltIn = true; diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index a4177016e..88e563da5 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -356,6 +356,17 @@ enum class GSizes : unsigned char { ALL, #endif // defined(__cplusplus) #endif // QT_VERSION < QT_VERSION_CHECK(5, 8, 0) +template +const auto & ConstFirst (const T &container) +{ +#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) + return container.constFirst(); +#else + return container.first(); // clazy:exclude=detaching-temporary +#endif +} + + bool IsOptionSet(int argc, char *argv[], const char *option); void InitHighDpiScaling(int argc, char *argv[]); diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index 83d7490a5..ef7b1890e 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -1010,26 +1010,11 @@ void VCommonSettings::SetHideLabels(bool value) //--------------------------------------------------------------------------------------------------------------------- QString VCommonSettings::GetLabelDateFormat() const { -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) const QString format = value(*settingLabelDateFormat, - VCommonSettings::PredefinedDateFormats().constFirst()).toString(); -#else - const QString format = value(*settingLabelDateFormat, VCommonSettings::PredefinedDateFormats().first()).toString(); // clazy:exclude=detaching-temporary -#endif + ConstFirst (VCommonSettings::PredefinedDateFormats())).toString(); const QStringList allFormats = VCommonSettings::PredefinedDateFormats() + GetUserDefinedDateFormats(); - if (allFormats.contains(format)) - { - return format; - } - else - { -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) - return VCommonSettings::PredefinedDateFormats().constFirst(); -#else - return VCommonSettings::PredefinedDateFormats().first(); // clazy:exclude=detaching-temporary -#endif - } + return allFormats.contains(format) ? format : ConstFirst (VCommonSettings::PredefinedDateFormats()); } //--------------------------------------------------------------------------------------------------------------------- @@ -1081,26 +1066,11 @@ void VCommonSettings::SetUserDefinedDateFormats(const QStringList &formats) //--------------------------------------------------------------------------------------------------------------------- QString VCommonSettings::GetLabelTimeFormat() const { -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) const QString format = value(*settingLabelTimeFormat, - VCommonSettings::PredefinedTimeFormats().constFirst()).toString(); -#else - const QString format = value(*settingLabelTimeFormat, VCommonSettings::PredefinedTimeFormats().first()).toString(); // clazy:exclude=detaching-temporary -#endif + ConstFirst (VCommonSettings::PredefinedTimeFormats())).toString(); const QStringList allFormats = VCommonSettings::PredefinedTimeFormats() + GetUserDefinedTimeFormats(); - if (allFormats.contains(format)) - { - return format; - } - else - { -#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) - return VCommonSettings::PredefinedTimeFormats().constFirst(); -#else - return VCommonSettings::PredefinedTimeFormats().first(); // clazy:exclude=detaching-temporary -#endif - } + return allFormats.contains(format) ? format : ConstFirst (VCommonSettings::PredefinedTimeFormats()); } //---------------------------------------------------------------------------------------------------------------------