Skip to content

Commit

Permalink
remove QgsVectorLayer::hasGeometryType in favor of QgsMapLayer::isSpa…
Browse files Browse the repository at this point in the history
…tial
  • Loading branch information
3nids committed Jul 5, 2017
1 parent 1c273f8 commit 5b8e2c2
Show file tree
Hide file tree
Showing 26 changed files with 62 additions and 70 deletions.
1 change: 1 addition & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -2411,6 +2411,7 @@ displayExpression instead. For the map tip use mapTipTemplate() instead.
- annotationForm() and setAnnotationForm() have been removed. Form path is stored in individual QgsFormAnnotation objects.
- setLayerTransparency, layerTransparency, and layerTransparencyChanged were removed. Use opacity, setOpacity and opacityChanged instead.
- The c++ signature for uniqueValues() has changed (the PyQGIS method remains unchanged)
- hasGeometryType() has been removed, replaced by QgsMapLayer::isSpatial()


QgsVectorLayerEditBuffer {#qgis_api_break_3_0_QgsVectorLayerEditBuffer}
Expand Down
10 changes: 4 additions & 6 deletions python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,6 @@ Returns point, line or polygon
:rtype: QgsWkbTypes.GeometryType
%End

bool hasGeometryType() const;
%Docstring
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeometry
:rtype: bool
%End

virtual QgsWkbTypes::Type wkbType() const;

%Docstring
Expand Down Expand Up @@ -1084,6 +1078,10 @@ Returns true if the provider is in editing mode
%End

virtual bool isSpatial() const;
%Docstring
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeometry
:rtype: bool
%End

virtual bool isModified() const;
%Docstring
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/db_manager/dlg_export_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def setupWorkingMode(self):
def checkSupports(self):
""" update options available for the current input layer """
allowSpatial = self.db.connector.hasSpatialSupport()
hasGeomType = self.inLayer and self.inLayer.hasGeometryType()
hasGeomType = self.inLayer and self.inLayer.isSpatial()
self.chkSourceSrid.setEnabled(allowSpatial and hasGeomType)
self.chkTargetSrid.setEnabled(allowSpatial and hasGeomType)
# self.chkSpatialIndex.setEnabled(allowSpatial and hasGeomType)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/db_manager/dlg_import_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def setupWorkingMode(self, mode):
def checkSupports(self):
""" update options available for the current input layer """
allowSpatial = self.db.connector.hasSpatialSupport()
hasGeomType = self.inLayer and self.inLayer.hasGeometryType()
hasGeomType = self.inLayer and self.inLayer.isSpatial()
isShapefile = self.inLayer and self.inLayer.providerType() == "ogr" and self.inLayer.storageType() == "ESRI Shapefile"

self.chkGeomColumn.setEnabled(allowSpatial and hasGeomType)
Expand Down Expand Up @@ -310,7 +310,7 @@ def accept(self):
if not pk:
pk = self.default_pk

if self.inLayer.hasGeometryType() and self.chkGeomColumn.isEnabled():
if self.inLayer.isSpatial() and self.chkGeomColumn.isEnabled():
geom = srcUri.geometryColumn() if not self.chkGeomColumn.isChecked() else self.editGeomColumn.text()
if not geom:
geom = self.default_geom
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/core/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def __init__(self, name='', description='', hidden=False, base_input=None, datat
def hasGeometry(self):
if self.base_layer is None:
return True
return self.base_layer.hasGeometryType()
return self.base_layer.isSpatial()

def getSupportedOutputVectorLayerExtensions(self):
exts = QgsVectorFileWriter.supportedFormatExtensions()
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ void QgsAttributeTableDialog::columnBoxInit()

mFilterButton->addAction( mActionShowAllFilter );
mFilterButton->addAction( mActionSelectedFilter );
if ( mLayer->hasGeometryType() )
if ( mLayer->isSpatial() )
{
mFilterButton->addAction( mActionVisibleFilter );
}
Expand Down Expand Up @@ -622,7 +622,7 @@ void QgsAttributeTableDialog::filterSelected()

void QgsAttributeTableDialog::filterVisible()
{
if ( !mLayer->hasGeometryType() )
if ( !mLayer->isSpatial() )
{
filterShowAll();
return;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgssnappinglayertreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ bool QgsSnappingLayerTreeModel::nodeShown( QgsLayerTreeNode *node ) const
else
{
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( QgsLayerTree::toLayer( node )->layer() );
return layer && layer->hasGeometryType();
return layer && layer->isSpatial();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(

QVBoxLayout *layout = nullptr;

if ( mLayer->hasGeometryType() )
if ( mLayer->isSpatial() )
{
// Create the Labeling dialog tab
layout = new QVBoxLayout( labelingFrame );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaplayerproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool QgsMapLayerProxyModel::filterAcceptsRow( int source_row, const QModelIndex
{
if ( QgsVectorLayer *vl = qobject_cast< QgsVectorLayer *>( layer ) )
{
if ( mFilters.testFlag( HasGeometry ) && vl->hasGeometryType() )
if ( mFilters.testFlag( HasGeometry ) && vl->isSpatial() )
return true;
if ( mFilters.testFlag( NoGeometry ) && vl->geometryType() == QgsWkbTypes::NullGeometry )
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsofflineediting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
int rc = sqlExec( db, sql );

// add geometry column
if ( layer->hasGeometryType() )
if ( layer->isSpatial() )
{
QString geomType = QLatin1String( "" );
switch ( layer->wkbType() )
Expand Down Expand Up @@ -576,7 +576,7 @@ QgsVectorLayer *QgsOfflineEditing::copyVectorLayer( QgsVectorLayer *layer, sqlit
// add new layer
QString connectionString = QStringLiteral( "dbname='%1' table='%2'%3 sql=" )
.arg( offlineDbPath,
tableName, layer->hasGeometryType() ? "(Geometry)" : "" );
tableName, layer->isSpatial() ? "(Geometry)" : "" );
QgsVectorLayer *newLayer = new QgsVectorLayer( connectionString,
layer->name() + " (offline)", QStringLiteral( "spatialite" ) );
if ( newLayer->isValid() )
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgssnappingconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ QgsSnappingConfig::IndividualLayerSettings QgsSnappingConfig::individualLayerSet

void QgsSnappingConfig::setIndividualLayerSettings( QgsVectorLayer *vl, const IndividualLayerSettings &individualLayerSettings )
{
if ( !vl || !vl->hasGeometryType() || mIndividualLayerSettings.value( vl ) == individualLayerSettings )
if ( !vl || !vl->isSpatial() || mIndividualLayerSettings.value( vl ) == individualLayerSettings )
{
return;
}
Expand Down Expand Up @@ -382,7 +382,7 @@ bool QgsSnappingConfig::addLayers( const QList<QgsMapLayer *> &layers )
Q_FOREACH ( QgsMapLayer *ml, layers )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( ml );
if ( vl && vl->hasGeometryType() )
if ( vl && vl->isSpatial() )
{
mIndividualLayerSettings.insert( vl, IndividualLayerSettings( enabled, type, tolerance, units ) );
changed = true;
Expand Down Expand Up @@ -449,7 +449,7 @@ void QgsSnappingConfig::readLegacySettings()
for ( ; layerIt != layerIdList.constEnd(); ++layerIt, ++tolIt, ++tolUnitIt, ++snapIt, ++enabledIt )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mProject->mapLayer( *layerIt ) );
if ( !vlayer || !vlayer->hasGeometryType() )
if ( !vlayer || !vlayer->isSpatial() )
continue;

SnappingType t( *snapIt == QLatin1String( "to_vertex" ) ? Vertex :
Expand Down
29 changes: 12 additions & 17 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,20 +615,14 @@ QgsWkbTypes::GeometryType QgsVectorLayer::geometryType() const
return QgsWkbTypes::UnknownGeometry;
}

bool QgsVectorLayer::hasGeometryType() const
{
QgsWkbTypes::GeometryType t = geometryType();
return t != QgsWkbTypes::NullGeometry && t != QgsWkbTypes::UnknownGeometry;
}

QgsWkbTypes::Type QgsVectorLayer::wkbType() const
{
return mWkbType;
}

QgsRectangle QgsVectorLayer::boundingBoxOfSelected() const
{
if ( !mValid || !hasGeometryType() || mSelectedFeatureIds.isEmpty() ) //no selected features
if ( !mValid || !isSpatial() || mSelectedFeatureIds.isEmpty() ) //no selected features
{
return QgsRectangle( 0, 0, 0, 0 );
}
Expand Down Expand Up @@ -801,7 +795,7 @@ QgsRectangle QgsVectorLayer::extent() const
QgsRectangle rect;
rect.setMinimal();

if ( !hasGeometryType() )
if ( !isSpatial() )
return rect;

if ( !mValidExtent && mLazyExtent && mDataProvider )
Expand Down Expand Up @@ -922,7 +916,7 @@ bool QgsVectorLayer::setSubsetString( const QString &subset )

bool QgsVectorLayer::simplifyDrawingCanbeApplied( const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint ) const
{
if ( mValid && mDataProvider && !mEditBuffer && ( hasGeometryType() && geometryType() != QgsWkbTypes::PointGeometry ) && ( mSimplifyMethod.simplifyHints() & simplifyHint ) && renderContext.useRenderingOptimization() )
if ( mValid && mDataProvider && !mEditBuffer && ( isSpatial() && geometryType() != QgsWkbTypes::PointGeometry ) && ( mSimplifyMethod.simplifyHints() & simplifyHint ) && renderContext.useRenderingOptimization() )
{
double maximumSimplificationScale = mSimplifyMethod.maximumScale();

Expand Down Expand Up @@ -1461,7 +1455,7 @@ void QgsVectorLayer::setDataSource( const QString &dataSource, const QString &ba
}

// if the default style failed to load or was disabled use some very basic defaults
if ( !defaultLoadedFlag && hasGeometryType() )
if ( !defaultLoadedFlag && isSpatial() )
{
// add single symbol renderer
setRenderer( QgsFeatureRenderer::defaultRenderer( geometryType() ) );
Expand Down Expand Up @@ -1832,7 +1826,7 @@ bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage, con
bool result = true;
emit readCustomSymbology( node.toElement(), errorMessage );

if ( hasGeometryType() )
if ( isSpatial() )
{
// try renderer v2 first
QDomElement rendererElement = node.firstChildElement( RENDERER_TAG_NAME );
Expand Down Expand Up @@ -2132,7 +2126,7 @@ bool QgsVectorLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &err

emit writeCustomSymbology( mapLayerNode, doc, errorMessage );

if ( hasGeometryType() )
if ( isSpatial() )
{
if ( mRenderer )
{
Expand Down Expand Up @@ -2193,7 +2187,7 @@ bool QgsVectorLayer::readSld( const QDomNode &node, QString &errorMessage )
errorMessage = QStringLiteral( "Warning: Name element not found within NamedLayer while it's required." );
}

if ( hasGeometryType() )
if ( isSpatial() )
{
QgsFeatureRenderer *r = QgsFeatureRenderer::loadSld( node, geometryType(), errorMessage );
if ( !r )
Expand Down Expand Up @@ -2222,7 +2216,7 @@ bool QgsVectorLayer::writeSld( QDomNode &node, QDomDocument &doc, QString &error
QgsSymbolLayerUtils::mergeScaleDependencies( maximumScale(), minimumScale(), localProps );
}

if ( hasGeometryType() )
if ( isSpatial() )
{
node.appendChild( mRenderer->writeSld( doc, name(), localProps ) );
}
Expand Down Expand Up @@ -2613,7 +2607,7 @@ void QgsVectorLayer::setCoordinateSystem()
// for this layer
//

if ( hasGeometryType() )
if ( isSpatial() )
{
// get CRS directly from provider
setCrs( mDataProvider->crs() );
Expand Down Expand Up @@ -2698,7 +2692,8 @@ bool QgsVectorLayer::isEditable() const

bool QgsVectorLayer::isSpatial() const
{
return geometryType() != QgsWkbTypes::NullGeometry;
QgsWkbTypes::GeometryType t = geometryType();
return t != QgsWkbTypes::NullGeometry && t != QgsWkbTypes::UnknownGeometry;
}

bool QgsVectorLayer::isReadOnly() const
Expand All @@ -2725,7 +2720,7 @@ bool QgsVectorLayer::isModified() const

void QgsVectorLayer::setRenderer( QgsFeatureRenderer *r )
{
if ( !hasGeometryType() )
if ( !isSpatial() )
return;

if ( r != mRenderer )
Expand Down
4 changes: 1 addition & 3 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
//! Returns point, line or polygon
QgsWkbTypes::GeometryType geometryType() const;

//! Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeometry
bool hasGeometryType() const;

//! Returns the WKBType or WKBUnknown in case of error
QgsWkbTypes::Type wkbType() const override;

Expand Down Expand Up @@ -1065,6 +1062,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
//! Returns true if the provider is in editing mode
virtual bool isEditable() const override;

//! Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeometry
virtual bool isSpatial() const override;

//! Returns true if the provider has been modified since the last commit
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayercache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int QgsVectorLayerCache::cacheSize()

void QgsVectorLayerCache::setCacheGeometry( bool cacheGeometry )
{
bool shouldCacheGeometry = cacheGeometry && mLayer->hasGeometryType();
bool shouldCacheGeometry = cacheGeometry && mLayer->isSpatial();
bool mustInvalidate = shouldCacheGeometry && !mCacheGeometry; // going from no geometry -> geometry, so have to clear existing cache entries
mCacheGeometry = shouldCacheGeometry;
if ( cacheGeometry )
Expand Down Expand Up @@ -377,7 +377,7 @@ QgsFeatureIterator QgsVectorLayerCache::getFeatures( const QgsFeatureRequest &fe
QgsFeatureRequest myRequest = QgsFeatureRequest( featureRequest );

// Make sure if we cache the geometry, it gets fetched
if ( mCacheGeometry && mLayer->hasGeometryType() )
if ( mCacheGeometry && mLayer->isSpatial() )
myRequest.setFlags( featureRequest.flags() & ~QgsFeatureRequest::NoGeometry );

// Make sure, all the cached attributes are requested as well
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayereditbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ bool QgsVectorLayerEditBuffer::deleteFeatures( const QgsFeatureIds &fids )

bool QgsVectorLayerEditBuffer::changeGeometry( QgsFeatureId fid, const QgsGeometry &geom )
{
if ( !L->hasGeometryType() )
if ( !L->isSpatial() )
{
return false;
}
Expand Down
Loading

0 comments on commit 5b8e2c2

Please sign in to comment.