Skip to content

Commit

Permalink
Move QgsVectorDataProvider::FeatureCountState enum to qgscoreenums.h
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 18, 2021
1 parent c47b2fb commit 239092e
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 43 deletions.
8 changes: 8 additions & 0 deletions python/core/auto_additions/qgscoreenums.py
Expand Up @@ -17,3 +17,11 @@
QgsMapLayer.PointCloudLayer.__doc__ = "Added in 3.18"
QgsMapLayerType.__doc__ = 'Types of layers that can be added to a map\n\n.. versionadded:: 3.8\n\n' + '* ``VectorLayer``: ' + QgsMapLayerType.VectorLayer.__doc__ + '\n' + '* ``RasterLayer``: ' + QgsMapLayerType.RasterLayer.__doc__ + '\n' + '* ``PluginLayer``: ' + QgsMapLayerType.PluginLayer.__doc__ + '\n' + '* ``MeshLayer``: ' + QgsMapLayerType.MeshLayer.__doc__ + '\n' + '* ``VectorTileLayer``: ' + QgsMapLayerType.VectorTileLayer.__doc__ + '\n' + '* ``AnnotationLayer``: ' + QgsMapLayerType.AnnotationLayer.__doc__ + '\n' + '* ``PointCloudLayer``: ' + QgsMapLayerType.PointCloudLayer.__doc__
# --
QgsVectorDataProvider.FeatureCountState = FeatureCountState
# monkey patching scoped based enum
QgsVectorDataProvider.Uncounted = FeatureCountState.Uncounted
QgsVectorDataProvider.Uncounted.__doc__ = "Feature count not yet computed"
QgsVectorDataProvider.UnknownCount = FeatureCountState.UnknownCount
QgsVectorDataProvider.UnknownCount.__doc__ = "Provider returned an unknown feature count"
FeatureCountState.__doc__ = 'Enumeration of feature count states\n\n.. versionadded:: 3.20\n\n' + '* ``Uncounted``: ' + FeatureCountState.Uncounted.__doc__ + '\n' + '* ``UnknownCount``: ' + FeatureCountState.UnknownCount.__doc__
# --
6 changes: 6 additions & 0 deletions python/core/auto_generated/qgscoreenums.sip.in
Expand Up @@ -20,6 +20,12 @@ enum class QgsMapLayerType
PointCloudLayer,
};

enum class FeatureCountState
{
Uncounted,
UnknownCount,
};

/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
Expand Up @@ -62,14 +62,6 @@ of feature and attribute information from a spatial datasource.

static const int EditingCapabilities;

enum FeatureCountState
{
//! Feature count not yet computed
Uncounted,
//! Provider returned an unknown feature count
UnknownCount,
};

QgsVectorDataProvider( const QString &uri = QString(),
const QgsDataProvider::ProviderOptions &providerOptions = QgsDataProvider::ProviderOptions(),
QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
Expand Down
15 changes: 10 additions & 5 deletions scripts/sipify.pl
Expand Up @@ -1082,8 +1082,13 @@ sub detect_non_method_member{
{
push @OUTPUT_PYTHON, "$ACTUAL_CLASS.$enum_member = $ACTUAL_CLASS.$enum_qualname.$enum_member\n";
}
push @OUTPUT_PYTHON, "$ACTUAL_CLASS.$enum_qualname.$enum_member.__doc__ = \"$comment\"\n";
push @enum_members_doc, "'* ``$enum_member``: ' + $ACTUAL_CLASS.$enum_qualname.$enum_member.__doc__";
if ( $ACTUAL_CLASS ne "" ){
push @OUTPUT_PYTHON, "$ACTUAL_CLASS.$enum_qualname.$enum_member.__doc__ = \"$comment\"\n";
push @enum_members_doc, "'* ``$enum_member``: ' + $ACTUAL_CLASS.$enum_qualname.$enum_member.__doc__";
} else {
push @OUTPUT_PYTHON, "$enum_qualname.$enum_member.__doc__ = \"$comment\"\n";
push @enum_members_doc, "'* ``$enum_member``: ' + $enum_qualname.$enum_member.__doc__";
}
}
}
$enum_decl = fix_annotations($enum_decl);
Expand Down Expand Up @@ -1161,10 +1166,10 @@ sub detect_non_method_member{

# catch Q_DECLARE_FLAGS
if ( $LINE =~ m/^(\s*)Q_DECLARE_FLAGS\(\s*(.*?)\s*,\s*(.*?)\s*\)\s*$/ ){
my $ACTUAL_CLASS = $CLASSNAME[$#CLASSNAME];
my $ACTUAL_CLASS = $#CLASSNAME >= 0 ? $CLASSNAME[$#CLASSNAME].'::' : '';
dbg_info("Declare flags: $ACTUAL_CLASS");
$LINE = "$1typedef QFlags<${ACTUAL_CLASS}::$3> $2;\n";
$QFLAG_HASH{"${ACTUAL_CLASS}::$2"} = "${ACTUAL_CLASS}::$3";
$LINE = "$1typedef QFlags<${ACTUAL_CLASS}$3> $2;\n";
$QFLAG_HASH{"${ACTUAL_CLASS}$2"} = "${ACTUAL_CLASS}$3";
}
# catch Q_DECLARE_OPERATORS_FOR_FLAGS
if ( $LINE =~ m/^(\s*)Q_DECLARE_OPERATORS_FOR_FLAGS\(\s*(.*?)\s*\)\s*$/ ){
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsapplayertreeviewmenuprovider.h
Expand Up @@ -18,9 +18,10 @@
#include <QObject>

#include "qgslayertreeview.h"
#include "qgsmaplayer.h"
#include "qgscoreenums.h"

class QAction;
class QgsCoordinateReferenceSystem;

struct LegendLayerAction
{
Expand Down
22 changes: 11 additions & 11 deletions src/core/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -259,8 +259,8 @@ void QgsOgrProvider::repack()

}

if ( mFeaturesCounted != QgsVectorDataProvider::Uncounted &&
mFeaturesCounted != QgsVectorDataProvider::UnknownCount )
if ( mFeaturesCounted != static_cast< long >( FeatureCountState::Uncounted ) &&
mFeaturesCounted != static_cast< long >( FeatureCountState::UnknownCount ) )
{
long oldcount = mFeaturesCounted;
recalculateFeatureCount();
Expand Down Expand Up @@ -1842,7 +1842,7 @@ long QgsOgrProvider::featureCount() const
{
if ( ( mReadFlags & QgsDataProvider::SkipFeatureCount ) != 0 )
{
return QgsVectorDataProvider::UnknownCount;
return static_cast< long >( FeatureCountState::UnknownCount );
}
if ( mRefreshFeatureCount )
{
Expand Down Expand Up @@ -2238,8 +2238,8 @@ bool QgsOgrProvider::addFeatures( QgsFeatureList &flist, Flags flags )
returnvalue = false;
}

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

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

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

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

void QgsOgrProvider::reloadProviderData()
{
mFeaturesCounted = QgsVectorDataProvider::Uncounted;
mFeaturesCounted = static_cast< long >( FeatureCountState::Uncounted );
bool wasValid = mValid;
QgsOgrConnPool::instance()->invalidateConnections( QgsOgrProviderUtils::connectionPoolId( dataSourceUri( true ), mShareSameDatasetAmongLayers ) );
close();
Expand Down
3 changes: 2 additions & 1 deletion src/core/providers/ogr/qgsogrprovider.h
Expand Up @@ -26,6 +26,7 @@ email : sherman at mrcc.com
#include "qgsvectorlayerexporter.h"
#include "qgsprovidermetadata.h"
#include "qgis_sip.h"
#include "qgscoreenums.h"

///@cond PRIVATE
#define SIP_NO_FILE
Expand Down Expand Up @@ -309,7 +310,7 @@ class QgsOgrProvider final: public QgsVectorDataProvider
//! Whether the next call to featureCount() should refresh the feature count
mutable bool mRefreshFeatureCount = true;

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

mutable QStringList mSubLayerList;

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsbrowserproxymodel.h
Expand Up @@ -17,7 +17,7 @@

#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgsmaplayer.h"
#include "qgscoreenums.h"
#include <QSortFilterProxyModel>

class QgsBrowserModel;
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgscoreenums.h
Expand Up @@ -37,4 +37,15 @@ enum class QgsMapLayerType SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsMapLayer, LayerT
PointCloudLayer, //!< Added in 3.18
};

/**
* \ingroup core
* \brief Enumeration of feature count states
* \since QGIS 3.20
*/
enum class FeatureCountState SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsVectorDataProvider, FeatureCountState ) : int
{
Uncounted = -2, //!< Feature count not yet computed
UnknownCount = -1, //!< Provider returned an unknown feature count
};

#endif // QGSCOREENUMS_H
2 changes: 1 addition & 1 deletion src/core/qgsdataitem.h
Expand Up @@ -29,7 +29,7 @@
#include <QVector>
#include <QDateTime>

#include "qgsmaplayer.h"
#include "qgscoreenums.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsmimedatautils.h"
#include "qgswkbtypes.h"
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmapclippingutils.h
Expand Up @@ -18,7 +18,7 @@

#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgsmaplayer.h"
#include "qgscoreenums.h"

#include <QList>
#include <QPainterPath>
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaplayerfactory.h
Expand Up @@ -19,7 +19,7 @@
#define QGSMAPLAYERFACTORY_H

#include "qgis_core.h"
#include "qgsmaplayer.h"
#include "qgscoreenums.h"

#include <QString>

Expand Down
11 changes: 0 additions & 11 deletions src/core/vector/qgsvectordataprovider.h
Expand Up @@ -105,17 +105,6 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeat
ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes |
RenameAttributes;

/**
* Enumeration of feature count states
*/
enum FeatureCountState
{
//! Feature count not yet computed
Uncounted = -2,
//! Provider returned an unknown feature count
UnknownCount = -1,
};

/**
* Constructor for a vector data provider.
*
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsdatasourceselectdialog.h
Expand Up @@ -19,7 +19,7 @@
#include "ui_qgsdatasourceselectdialog.h"

#include "qgis_gui.h"
#include "qgsmaplayer.h"
#include "qgscoreenums.h"
#include "qgsmimedatautils.h"
#include "qgsbrowserguimodel.h"
#include "qgsbrowserproxymodel.h"
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsidentifymenu.h
Expand Up @@ -20,6 +20,7 @@

#include "qgsmaplayeractionregistry.h"
#include "qgsmaptoolidentify.h"
#include "qgsexpressioncontext.h"
#include "qgis_gui.h"
#include "qgis_sip.h"

Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsmaplayeractionregistry.h
Expand Up @@ -22,10 +22,11 @@
#include <QMap>
#include <QAction>

#include "qgsmaplayer.h"
#include "qgscoreenums.h"
#include "qgis_gui.h"

class QgsFeature;
class QgsMapLayer;

/**
* \ingroup gui
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsmaplayerstylecategoriesmodel.h
Expand Up @@ -21,6 +21,7 @@

#include <QAbstractListModel>

#include "qgscoreenums.h"
#include "qgsmaplayer.h"
#include "qgis_gui.h"

Expand Down

0 comments on commit 239092e

Please sign in to comment.