Skip to content
Permalink
Browse files

remove QgsVectorLayer::hasGeometryType in favor of QgsMapLayer::isSpa…

…tial
  • Loading branch information
3nids committed Jul 5, 2017
1 parent 1c273f8 commit 5b8e2c2f279ee8d9323770231fc4f703da31f5bc
@@ -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}
@@ -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
@@ -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
@@ -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)
@@ -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)
@@ -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
@@ -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()
@@ -397,7 +397,7 @@ void QgsAttributeTableDialog::columnBoxInit()

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

void QgsAttributeTableDialog::filterVisible()
{
if ( !mLayer->hasGeometryType() )
if ( !mLayer->isSpatial() )
{
filterShowAll();
return;
@@ -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();
}
}

@@ -133,7 +133,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(

QVBoxLayout *layout = nullptr;

if ( mLayer->hasGeometryType() )
if ( mLayer->isSpatial() )
{
// Create the Labeling dialog tab
layout = new QVBoxLayout( labelingFrame );
@@ -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;
@@ -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() )
@@ -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() )
@@ -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;
}
@@ -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;
@@ -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 :
@@ -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 );
}
@@ -801,7 +795,7 @@ QgsRectangle QgsVectorLayer::extent() const
QgsRectangle rect;
rect.setMinimal();

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

if ( !mValidExtent && mLazyExtent && mDataProvider )
@@ -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();

@@ -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() ) );
@@ -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 );
@@ -2132,7 +2126,7 @@ bool QgsVectorLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &err

emit writeCustomSymbology( mapLayerNode, doc, errorMessage );

if ( hasGeometryType() )
if ( isSpatial() )
{
if ( mRenderer )
{
@@ -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 )
@@ -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 ) );
}
@@ -2613,7 +2607,7 @@ void QgsVectorLayer::setCoordinateSystem()
// for this layer
//

if ( hasGeometryType() )
if ( isSpatial() )
{
// get CRS directly from provider
setCrs( mDataProvider->crs() );
@@ -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
@@ -2725,7 +2720,7 @@ bool QgsVectorLayer::isModified() const

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

if ( r != mRenderer )
@@ -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;

@@ -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
@@ -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 )
@@ -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
@@ -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;
}

0 comments on commit 5b8e2c2

Please sign in to comment.
You can’t perform that action at this time.