Refactoring. Hide compatibility layer behind a function.

fromList().

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2020-01-16 19:46:05 +02:00
parent 658eafc3d3
commit 7998687b03
6 changed files with 25 additions and 47 deletions

View File

@ -32,6 +32,7 @@
#include "../vmisc/diagnostic.h" #include "../vmisc/diagnostic.h"
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "../vmisc/compatibility.h"
#include "vlayoutdef.h" #include "vlayoutdef.h"
#include "../ifc/exception/vexception.h" #include "../ifc/exception/vexception.h"
#include "../vpatterndb/floatItemData/floatitemdef.h" #include "../vpatterndb/floatItemData/floatitemdef.h"
@ -343,11 +344,7 @@ bool VBank::PrepareUnsorted()
Insert(unsorted, group, i, square); Insert(unsorted, group, i, square);
} }
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) groups = ConvertToVector(uniqueGroup);
groups = QVector<uint>(uniqueGroup.begin(), uniqueGroup.end());
#else
groups = QVector<uint>::fromList(uniqueGroup.toList());
#endif
std::sort(groups.begin(), groups.end()); std::sort(groups.begin(), groups.end());
PrepareGroup(); PrepareGroup();

View File

@ -113,6 +113,17 @@ inline QVector<T> ConvertToVector(const C<T> &container)
#endif #endif
} }
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
inline QVector<T> ConvertToVector(const QSet<T> &container)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
return QVector<T>(container.begin(), container.end());
#else
return container.toList().toVector();
#endif
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
template <typename T> template <typename T>
inline void SwapItemsAt(T &container, int i, int j) inline void SwapItemsAt(T &container, int i, int j)

View File

@ -36,6 +36,7 @@
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vmisc/compatibility.h"
#include "../vpatterndb/vpiecenode.h" #include "../vpatterndb/vpiecenode.h"
#include "../vpatterndb/floatItemData/vpatternlabeldata.h" #include "../vpatterndb/floatItemData/vpatternlabeldata.h"
#include "../vpatterndb/floatItemData/vpiecelabeldata.h" #include "../vpatterndb/floatItemData/vpiecelabeldata.h"
@ -162,16 +163,8 @@ bool SavePieceOptions::mergeWith(const QUndoCommand *command)
{ {
const VPiece candidate = saveCommand->NewDet(); const VPiece candidate = saveCommand->NewDet();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) auto currentSet = ConvertToSet(m_newDet.Dependencies());
QList<quint32> currentDependencies = m_newDet.Dependencies(); auto candidateSet = ConvertToSet(candidate.Dependencies());
QList<quint32> candidateDependencies = candidate.Dependencies();
auto currentSet = QSet<quint32>(currentDependencies.begin(), currentDependencies.end());
auto candidateSet = QSet<quint32>(candidateDependencies.begin(), candidateDependencies.end());
#else
auto currentSet = QSet<quint32>::fromList(m_newDet.Dependencies());
auto candidateSet = QSet<quint32>::fromList(candidate.Dependencies());
#endif
if (currentSet != candidateSet) if (currentSet != candidateSet)
{ {

View File

@ -36,6 +36,7 @@
#include "../tools/nodeDetails/vtoolpiecepath.h" #include "../tools/nodeDetails/vtoolpiecepath.h"
#include "../tools/vtoolseamallowance.h" #include "../tools/vtoolseamallowance.h"
#include "../vpatterndb/vpiecenode.h" #include "../vpatterndb/vpiecenode.h"
#include "../vmisc/compatibility.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
SavePiecePathOptions::SavePiecePathOptions(quint32 pieceId, const VPiecePath &oldPath, const VPiecePath &newPath, SavePiecePathOptions::SavePiecePathOptions(quint32 pieceId, const VPiecePath &oldPath, const VPiecePath &newPath,
@ -129,16 +130,8 @@ bool SavePiecePathOptions::mergeWith(const QUndoCommand *command)
{ {
const VPiecePath candidate = saveCommand->NewPath(); const VPiecePath candidate = saveCommand->NewPath();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) auto currentSet = ConvertToSet(m_newPath.Dependencies());
QList<quint32> currentDependencies = m_newPath.Dependencies(); auto candidateSet = ConvertToSet(candidate.Dependencies());
QList<quint32> candidateDependencies = candidate.Dependencies();
auto currentSet = QSet<quint32>(currentDependencies.begin(), currentDependencies.end());
auto candidateSet = QSet<quint32>(candidateDependencies.begin(), candidateDependencies.end());
#else
auto currentSet = QSet<quint32>::fromList(m_newPath.Dependencies());
auto candidateSet = QSet<quint32>::fromList(candidate.Dependencies());
#endif
if (currentSet != candidateSet) if (currentSet != candidateSet)
{ {

View File

@ -31,6 +31,7 @@
#include <QDomNode> #include <QDomNode>
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vmisc/compatibility.h"
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "vundocommand.h" #include "vundocommand.h"
@ -93,16 +94,7 @@ void SaveToolOptions::redo()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVector<quint32> SaveToolOptions::Missing(const QList<quint32> &list1, const QList<quint32> &list2) const QVector<quint32> SaveToolOptions::Missing(const QList<quint32> &list1, const QList<quint32> &list2) const
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) return ConvertToVector(ConvertToSet(list1).subtract(ConvertToSet(list2)));
auto set1 = QSet<quint32>(list1.begin(), list1.end());
auto set2 = QSet<quint32>(list2.begin(), list2.end());
QSet<quint32> substracted = set1.subtract(set2);
return QVector<quint32>(substracted.begin(), substracted.end());
#else
auto set1 = QSet<quint32>::fromList(list1);
auto set2 = QSet<quint32>::fromList(list2);
return set1.subtract(set2).toList().toVector();
#endif
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -116,13 +108,8 @@ bool SaveToolOptions::mergeWith(const QUndoCommand *command)
} }
else else
{ {
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) auto currentSet = ConvertToSet(newDependencies);
auto currentSet = QSet<quint32>(newDependencies.begin(), newDependencies.end()); auto candidateSet = ConvertToSet(saveCommand->NewDependencies());
auto candidateSet = QSet<quint32>(saveCommand->NewDependencies().begin(), saveCommand->NewDependencies().end());
#else
auto currentSet = QSet<quint32>::fromList(newDependencies);
auto candidateSet = QSet<quint32>::fromList(saveCommand->NewDependencies());
#endif
if (currentSet != candidateSet) if (currentSet != candidateSet)
{ {

View File

@ -31,6 +31,7 @@
#include "../qmuparser/qmuformulabase.h" #include "../qmuparser/qmuformulabase.h"
#include "../vpatterndb/vtranslatevars.h" #include "../vpatterndb/vtranslatevars.h"
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
#include "../vmisc/compatibility.h"
#include <QtTest> #include <QtTest>
#include <QTranslator> #include <QTranslator>
@ -185,11 +186,7 @@ void TST_AbstractRegExp::CallTestCheckNoOriginalNamesInTranslation()
QFETCH(QString, originalName); QFETCH(QString, originalName);
static const QStringList originalNames = AllNames(); static const QStringList originalNames = AllNames();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) static const auto names = ConvertToSet<QString>(originalNames);
static const auto names = QSet<QString>(originalNames.begin(), originalNames.end());
#else
static const auto names = QSet<QString>::fromList(originalNames);
#endif
const QString translated = m_trMs->VarToUser(originalName); const QString translated = m_trMs->VarToUser(originalName);
if (names.contains(translated)) if (names.contains(translated))