Skip to content

Commit

Permalink
fix deprecated QList::toSet in Qt 5.14+ (#36459)
Browse files Browse the repository at this point in the history
add an helper in qgis.h to avoid overwhelming the code
  • Loading branch information
3nids committed May 15, 2020
1 parent 0df50ca commit 8b7a17b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/core/qgis.h
Expand Up @@ -457,6 +457,16 @@ namespace qgis
return pmf;
}
};

template<class T>
QSet<T> listToSet( const QList<T> &list )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
return list.toSet();
#else
return QSet<T>( list.begin(), list.end() );
#endif
}
}
///@endcond
#endif
Expand Down
6 changes: 1 addition & 5 deletions src/core/qgsfeaturefiltermodel.cpp
Expand Up @@ -67,11 +67,7 @@ void QgsFeatureFilterModel::requestToReloadCurrentFeature( QgsFeatureRequest &re

QSet<QString> QgsFeatureFilterModel::requestedAttributes() const
{
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
return mIdentifierFields.toSet();
#else
return QSet<QString>( mIdentifierFields.begin(), mIdentifierFields.end() );
#endif
return qgis::listToSet( mIdentifierFields );
}

QVariant QgsFeatureFilterModel::entryIdentifier( const QgsFeatureExpressionValuesGatherer::Entry &entry ) const
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsstringstatisticalsummary.h
Expand Up @@ -20,6 +20,7 @@
#include <QVariantList>

#include "qgis_core.h"
#include "qgis.h"

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
Expand Down Expand Up @@ -164,7 +165,7 @@ class CORE_EXPORT QgsStringStatisticalSummary
* Returns the set of distinct string values.
* \see countDistinct()
*/
QSet< QString > distinctValues() const { return QSet<QString>::fromList( mValues.keys() ); }
QSet< QString > distinctValues() const { return qgis::listToSet( mValues.keys() ); }

/**
* Returns the number of missing (null) string values.
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorfilewriter.h
Expand Up @@ -76,7 +76,7 @@ class CORE_EXPORT QgsVectorFileWriter : public QgsFeatureSink
public:
SetOption( const QString &docString, const QStringList &values, const QString &defaultValue, bool allowNone = false )
: Option( docString, Set )
, values( values.toSet() )
, values( qgis::listToSet( values ) )
, defaultValue( defaultValue )
, allowNone( allowNone )
{}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayercache.h
Expand Up @@ -231,7 +231,7 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
* \see isFidCached()
* \since QGIS 3.0
*/
QgsFeatureIds cachedFeatureIds() const { return mCache.keys().toSet(); }
QgsFeatureIds cachedFeatureIds() const { return qgis::listToSet( mCache.keys() ); }

/**
* Gets the feature at the given feature id. Considers the changed, added, deleted and permanent features
Expand Down

0 comments on commit 8b7a17b

Please sign in to comment.