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

View File

@ -113,6 +113,17 @@ inline QVector<T> ConvertToVector(const C<T> &container)
#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>
inline void SwapItemsAt(T &container, int i, int j)

View File

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

View File

@ -36,6 +36,7 @@
#include "../tools/nodeDetails/vtoolpiecepath.h"
#include "../tools/vtoolseamallowance.h"
#include "../vpatterndb/vpiecenode.h"
#include "../vmisc/compatibility.h"
//---------------------------------------------------------------------------------------------------------------------
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();
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QList<quint32> currentDependencies = m_newPath.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
auto currentSet = ConvertToSet(m_newPath.Dependencies());
auto candidateSet = ConvertToSet(candidate.Dependencies());
if (currentSet != candidateSet)
{

View File

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

View File

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