Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update featureCount() methods to return long long for Win64 compatibi…
…lity
  • Loading branch information
rouault authored and nyalldawson committed Jun 15, 2021
1 parent 5a9968c commit 92fc435
Show file tree
Hide file tree
Showing 65 changed files with 158 additions and 160 deletions.
Expand Up @@ -439,7 +439,7 @@ iterator, eg by restricting the returned attributes or geometry.

virtual QgsWkbTypes::Type wkbType() const;

virtual long featureCount() const;
virtual long long featureCount() const;

virtual QString sourceName() const;

Expand Down
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgsfeaturesource.sip.in
Expand Up @@ -75,7 +75,7 @@ if the feature count is unknown.
sipRes = true;
%End

virtual long featureCount() const = 0;
virtual long long featureCount() const = 0;
%Docstring
Returns the number of features contained in the source, or -1
if the feature count is unknown.
Expand Down
Expand Up @@ -113,12 +113,12 @@ Query the provider for features specified in request.
Returns the geometry type which is returned by this layer
%End

virtual long featureCount() const = 0;
virtual long long featureCount() const = 0;

%Docstring
Number of features in the layer

:return: long containing number of features
:return: number of features
%End

virtual bool empty() const;
Expand Down
4 changes: 2 additions & 2 deletions python/core/auto_generated/vector/qgsvectorlayer.sip.in
Expand Up @@ -1052,7 +1052,7 @@ Writes the symbology of the layer into the document provided in SLD 1.1 format
virtual bool readSld( const QDomNode &node, QString &errorMessage ) ${SIP_FINAL};


long featureCount( const QString &legendKey ) const;
long long featureCount( const QString &legendKey ) const;
%Docstring
Number of features rendered with specified legend key. Features must be first
calculated by :py:func:`~QgsVectorLayer.countSymbolFeatures`
Expand Down Expand Up @@ -1792,7 +1792,7 @@ Returns list of attribute indexes. i.e. a list from 0 ... :py:func:`~QgsVectorLa
Returns the list of attributes which make up the layer's primary keys.
%End

virtual long featureCount() const ${SIP_FINAL};
virtual long long featureCount() const ${SIP_FINAL};

%Docstring
Returns feature count including changes which have not yet been committed
Expand Down
Expand Up @@ -226,7 +226,7 @@ if the feature count is unknown.
sipRes = true;
%End

long featureCount() const;
long long featureCount() const;
%Docstring
Returns the number of features contained in the source, or -1
if the feature count is unknown.
Expand Down
Expand Up @@ -41,7 +41,7 @@ Calculates the feature count and Ids per symbol
%End


long featureCount( const QString &legendKey ) const;
long long featureCount( const QString &legendKey ) const;
%Docstring
Returns the feature count for a particular ``legendKey``.
If the key has not been found, -1 will be returned.
Expand Down
Expand Up @@ -192,7 +192,7 @@ the QgsVectorLayerSelectedFeatureSource will not be reflected.

virtual QgsWkbTypes::Type wkbType() const;

virtual long featureCount() const;
virtual long long featureCount() const;

virtual QString sourceName() const;

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsattributetabledialog.cpp
Expand Up @@ -387,7 +387,7 @@ void QgsAttributeTableDialog::updateTitle()
: qobject_cast<QWidget *>( this );
w->setWindowTitle( tr( " %1 — Features Total: %2, Filtered: %3, Selected: %4" )
.arg( mLayer->name() )
.arg( std::max( static_cast< long >( mMainView->featureCount() ), mLayer->featureCount() ) ) // layer count may be estimated, so use larger of the two
.arg( std::max( static_cast< long long >( mMainView->featureCount() ), mLayer->featureCount() ) ) // layer count may be estimated, so use larger of the two
.arg( mMainView->filteredFeatureCount() )
.arg( mLayer->selectedFeatureCount() )
);
Expand Down
4 changes: 2 additions & 2 deletions src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -1311,12 +1311,12 @@ QgsWkbTypes::Type QgsProcessingFeatureSource::wkbType() const
return mSource->wkbType();
}

long QgsProcessingFeatureSource::featureCount() const
long long QgsProcessingFeatureSource::featureCount() const
{
if ( mFeatureLimit == -1 )
return mSource->featureCount();
else
return std::min( mFeatureLimit, static_cast< long long >( mSource->featureCount() ) );
return std::min( mFeatureLimit, mSource->featureCount() );
}

QString QgsProcessingFeatureSource::sourceName() const
Expand Down
2 changes: 1 addition & 1 deletion src/core/processing/qgsprocessingutils.h
Expand Up @@ -506,7 +506,7 @@ class CORE_EXPORT QgsProcessingFeatureSource : public QgsFeatureSource
QgsCoordinateReferenceSystem sourceCrs() const override;
QgsFields fields() const override;
QgsWkbTypes::Type wkbType() const override;
long featureCount() const override;
long long featureCount() const override;
QString sourceName() const override;
QSet<QVariant> uniqueValues( int fieldIndex, int limit = -1 ) const override;
QVariant minimumValue( int fieldIndex ) const override;
Expand Down
4 changes: 2 additions & 2 deletions src/core/providers/memory/qgsmemoryprovider.cpp
Expand Up @@ -367,14 +367,14 @@ QgsWkbTypes::Type QgsMemoryProvider::wkbType() const
return mWkbType;
}

long QgsMemoryProvider::featureCount() const
long long QgsMemoryProvider::featureCount() const
{
if ( mSubsetString.isEmpty() )
return mFeatures.count();

// subset string set, no alternative but testing each feature
QgsFeatureIterator fit = QgsFeatureIterator( new QgsMemoryFeatureIterator( new QgsMemoryFeatureSource( this ), true, QgsFeatureRequest().setNoAttributes() ) );
int count = 0;
long long count = 0;
QgsFeature feature;
while ( fit.nextFeature( feature ) )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/providers/memory/qgsmemoryprovider.h
Expand Up @@ -56,7 +56,7 @@ class QgsMemoryProvider final: public QgsVectorDataProvider
QString storageType() const override;
QgsFeatureIterator getFeatures( const QgsFeatureRequest &request ) const override;
QgsWkbTypes::Type wkbType() const override;
long featureCount() const override;
long long featureCount() const override;
QgsFields fields() const override;
bool addFeatures( QgsFeatureList &flist, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
bool deleteFeatures( const QgsFeatureIds &id ) override;
Expand Down
28 changes: 14 additions & 14 deletions src/core/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -260,10 +260,10 @@ void QgsOgrProvider::repack()

}

if ( mFeaturesCounted != static_cast< long >( Qgis::FeatureCountState::Uncounted ) &&
mFeaturesCounted != static_cast< long >( Qgis::FeatureCountState::UnknownCount ) )
if ( mFeaturesCounted != static_cast< long long >( Qgis::FeatureCountState::Uncounted ) &&
mFeaturesCounted != static_cast< long long >( Qgis::FeatureCountState::UnknownCount ) )
{
long oldcount = mFeaturesCounted;
long long oldcount = mFeaturesCounted;
recalculateFeatureCount();
if ( oldcount != mFeaturesCounted )
emit dataChanged();
Expand Down Expand Up @@ -854,7 +854,7 @@ void QgsOgrProvider::addSubLayerDetailsToSubLayerList( int i, QgsOgrLayer *layer

if ( slowGeomTypeRetrieval || wkbFlatten( layerGeomType ) != wkbUnknown )
{
int layerFeatureCount = withFeatureCount ? layer->GetApproxFeatureCount() : -1;
long long layerFeatureCount = withFeatureCount ? layer->GetApproxFeatureCount() : -1;

QString geom = ogrWkbGeometryTypeName( layerGeomType );

Expand Down Expand Up @@ -1839,11 +1839,11 @@ QgsWkbTypes::Type QgsOgrProvider::wkbType() const
/**
* Returns the feature count
*/
long QgsOgrProvider::featureCount() const
long long QgsOgrProvider::featureCount() const
{
if ( ( mReadFlags & QgsDataProvider::SkipFeatureCount ) != 0 )
{
return static_cast< long >( Qgis::FeatureCountState::UnknownCount );
return static_cast< long long >( Qgis::FeatureCountState::UnknownCount );
}
if ( mRefreshFeatureCount )
{
Expand Down Expand Up @@ -2239,8 +2239,8 @@ bool QgsOgrProvider::addFeatures( QgsFeatureList &flist, Flags flags )
returnvalue = false;
}

if ( mFeaturesCounted != static_cast< long >( Qgis::FeatureCountState::Uncounted ) &&
mFeaturesCounted != static_cast< long >( Qgis::FeatureCountState::UnknownCount ) )
if ( mFeaturesCounted != static_cast< long long >( Qgis::FeatureCountState::Uncounted ) &&
mFeaturesCounted != static_cast< long long >( Qgis::FeatureCountState::UnknownCount ) )
{
if ( returnvalue )
mFeaturesCounted += flist.size();
Expand Down Expand Up @@ -2585,7 +2585,7 @@ bool QgsOgrProvider::_setSubsetString( const QString &theSQL, bool updateFeature
if ( !mOgrOrigLayer )
return false;

if ( theSQL == mSubsetString && mFeaturesCounted != static_cast< long >( Qgis::FeatureCountState::Uncounted ) )
if ( theSQL == mSubsetString && mFeaturesCounted != static_cast< long long >( Qgis::FeatureCountState::Uncounted ) )
return true;

const bool subsetStringHasChanged { theSQL != mSubsetString };
Expand Down Expand Up @@ -3205,8 +3205,8 @@ bool QgsOgrProvider::deleteFeatures( const QgsFeatureIds &id )
}
else
{
if ( mFeaturesCounted != static_cast< long >( Qgis::FeatureCountState::Uncounted ) &&
mFeaturesCounted != static_cast< long >( Qgis::FeatureCountState::UnknownCount ) )
if ( mFeaturesCounted != static_cast< long long >( Qgis::FeatureCountState::Uncounted ) &&
mFeaturesCounted != static_cast< long long >( Qgis::FeatureCountState::UnknownCount ) )
{
if ( returnvalue )
mFeaturesCounted -= id.size();
Expand Down Expand Up @@ -5046,7 +5046,7 @@ void QgsOgrProvider::recalculateFeatureCount() const
{
if ( !mOgrLayer )
{
mFeaturesCounted = static_cast< long >( Qgis::FeatureCountState::Uncounted );
mFeaturesCounted = static_cast< long long >( Qgis::FeatureCountState::Uncounted );
return;
}

Expand All @@ -5064,7 +5064,7 @@ void QgsOgrProvider::recalculateFeatureCount() const
mFeaturesCounted = mOgrLayer->GetApproxFeatureCount();
if ( mFeaturesCounted == -1 )
{
mFeaturesCounted = static_cast< long >( Qgis::FeatureCountState::UnknownCount );
mFeaturesCounted = static_cast< long long >( Qgis::FeatureCountState::UnknownCount );
}
}
else
Expand Down Expand Up @@ -5408,7 +5408,7 @@ void QgsOgrProvider::close()

void QgsOgrProvider::reloadProviderData()
{
mFeaturesCounted = static_cast< long >( Qgis::FeatureCountState::Uncounted );
mFeaturesCounted = static_cast< long long >( Qgis::FeatureCountState::Uncounted );
bool wasValid = mValid;
QgsOgrConnPool::instance()->invalidateConnections( QgsOgrProviderUtils::connectionPoolId( dataSourceUri( true ), mShareSameDatasetAmongLayers ) );
close();
Expand Down
4 changes: 2 additions & 2 deletions src/core/providers/ogr/qgsogrprovider.h
Expand Up @@ -122,7 +122,7 @@ class QgsOgrProvider final: public QgsVectorDataProvider
bool setSubsetString( const QString &theSQL, bool updateFeatureCount = true ) override;
QgsWkbTypes::Type wkbType() const override;
virtual size_t layerCount() const;
long featureCount() const override;
long long featureCount() const override;
QgsFields fields() const override;
QgsRectangle extent() const override;
QVariant defaultValue( int fieldId ) const override;
Expand Down Expand Up @@ -309,7 +309,7 @@ class QgsOgrProvider final: public QgsVectorDataProvider
//! Whether the next call to featureCount() should refresh the feature count
mutable bool mRefreshFeatureCount = true;

mutable long mFeaturesCounted = static_cast< long >( Qgis::FeatureCountState::Uncounted );
mutable long long mFeaturesCounted = static_cast< long long >( Qgis::FeatureCountState::Uncounted );

mutable QStringList mSubLayerList;

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsfeaturesource.h
Expand Up @@ -105,7 +105,7 @@ class CORE_EXPORT QgsFeatureSource
* Returns the number of features contained in the source, or -1
* if the feature count is unknown.
*/
virtual long featureCount() const = 0;
virtual long long featureCount() const = 0;

/**
* Determines if there are any features available in the source.
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorfilewriter.cpp
Expand Up @@ -3148,7 +3148,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormatV2( Pre
QgsWkbTypes::Type destWkbType = details.destWkbType;

int lastProgressReport = 0;
long total = details.featureCount;
long long total = details.featureCount;

// Special rules for OGR layers
if ( details.providerType == QLatin1String( "ogr" ) && !details.dataSourceUri.isEmpty() )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorfilewriter.h
Expand Up @@ -958,7 +958,7 @@ class CORE_EXPORT QgsVectorFileWriter : public QgsFeatureSink
QgsWkbTypes::Type sourceWkbType = QgsWkbTypes::Unknown;
QgsFields sourceFields;
QString providerType;
long featureCount = 0;
long long featureCount = 0;
QgsFeatureIds selectedFeatureIds;
QString dataSourceUri;
QString storageType;
Expand Down
4 changes: 2 additions & 2 deletions src/core/vector/qgsvectordataprovider.h
Expand Up @@ -153,9 +153,9 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeat

/**
* Number of features in the layer
* \returns long containing number of features
* \returns number of features
*/
long featureCount() const override = 0;
long long featureCount() const override = 0;

/**
* Returns TRUE if the layer does not contain any feature.
Expand Down
4 changes: 2 additions & 2 deletions src/core/vector/qgsvectorlayer.cpp
Expand Up @@ -763,7 +763,7 @@ bool QgsVectorLayer::diagramsEnabled() const
return false;
}

long QgsVectorLayer::featureCount( const QString &legendKey ) const
long long QgsVectorLayer::featureCount( const QString &legendKey ) const
{
if ( !mSymbolFeatureCounted )
return -1;
Expand Down Expand Up @@ -3417,7 +3417,7 @@ QgsAttributeList QgsVectorLayer::primaryKeyAttributes() const
return pkAttributesList;
}

long QgsVectorLayer::featureCount() const
long long QgsVectorLayer::featureCount() const
{
if ( ! mDataProvider )
return -1;
Expand Down
6 changes: 3 additions & 3 deletions src/core/vector/qgsvectorlayer.h
Expand Up @@ -1109,7 +1109,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* calculated by countSymbolFeatures()
* \returns number of features rendered by symbol or -1 if failed or counts are not available
*/
long featureCount( const QString &legendKey ) const;
long long featureCount( const QString &legendKey ) const;

/**
* Ids of features rendered with specified legend key. Features must be first
Expand Down Expand Up @@ -1708,7 +1708,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* If you need only the count of committed features call this method on this layer's provider.
* \returns the number of features on this layer or -1 if unknown.
*/
long featureCount() const FINAL;
long long featureCount() const FINAL;

/**
* Makes layer read-only (editing disabled) or not
Expand Down Expand Up @@ -2977,7 +2977,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
bool mSymbolFeatureCounted = false;

// Feature counts for each renderer legend key
QHash<QString, long> mSymbolFeatureCountMap;
QHash<QString, long long> mSymbolFeatureCountMap;
QHash<QString, QgsFeatureIds> mSymbolFeatureIdMap;

//! True while an undo command is active
Expand Down
2 changes: 1 addition & 1 deletion src/core/vector/qgsvectorlayercache.cpp
Expand Up @@ -209,7 +209,7 @@ QgsFields QgsVectorLayerCache::fields() const
return mLayer->fields();
}

long QgsVectorLayerCache::featureCount() const
long long QgsVectorLayerCache::featureCount() const
{
return mLayer->featureCount();
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/vector/qgsvectorlayercache.h
Expand Up @@ -292,7 +292,7 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
* Returns the number of features contained in the source, or -1
* if the feature count is unknown.
*/
long featureCount() const;
long long featureCount() const;

protected:

Expand Down
4 changes: 2 additions & 2 deletions src/core/vector/qgsvectorlayerexporter.cpp
Expand Up @@ -387,8 +387,8 @@ Qgis::VectorExportResult QgsVectorLayerExporter::exportLayer( QgsVectorLayer *la
if ( !ct.isValid() )
shallTransform = false;

long n = 0;
long approxTotal = onlySelected ? layer->selectedFeatureCount() : layer->featureCount();
long long n = 0;
long long approxTotal = onlySelected ? layer->selectedFeatureCount() : layer->featureCount();

if ( errorMessage )
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/vector/qgsvectorlayerfeaturecounter.cpp
Expand Up @@ -101,12 +101,12 @@ bool QgsVectorLayerFeatureCounter::run()
return true;
}

QHash<QString, long> QgsVectorLayerFeatureCounter::symbolFeatureCountMap() const
QHash<QString, long long> QgsVectorLayerFeatureCounter::symbolFeatureCountMap() const
{
return mSymbolFeatureCountMap;
}

long QgsVectorLayerFeatureCounter::featureCount( const QString &legendKey ) const
long long QgsVectorLayerFeatureCounter::featureCount( const QString &legendKey ) const
{
return mSymbolFeatureCountMap.value( legendKey, -1 );
}
Expand Down

0 comments on commit 92fc435

Please sign in to comment.