Skip to content
Permalink
Browse files
Fix various crashes on a vector layer with a broken provider
  • Loading branch information
rouault committed May 31, 2021
1 parent 0c0a1f8 commit 452ce092294b75c4a055f4c704866a8f8ff29124
@@ -8742,7 +8742,7 @@ void QgisApp::fieldCalculator()
void QgisApp::attributeTable( QgsAttributeTableFilterModel::FilterMode filter )
{
QgsVectorLayer *myLayer = qobject_cast<QgsVectorLayer *>( activeLayer() );
if ( !myLayer )
if ( !myLayer || !myLayer->dataProvider() )
{
return;
}
@@ -9016,7 +9016,7 @@ void QgisApp::saveStyleFile( QgsMapLayer *layer )
layer = activeLayer();
}

if ( !layer )
if ( !layer || !layer->dataProvider() )
return;

switch ( layer->type() )
@@ -507,7 +507,7 @@ void QgisAppInterface::showLayerProperties( QgsMapLayer *l, const QString &page

QDialog *QgisAppInterface::showAttributeTable( QgsVectorLayer *l, const QString &filterExpression )
{
if ( l )
if ( l && l->dataProvider() )
{
QgsAttributeTableDialog *dialog = new QgsAttributeTableDialog( l, QgsAttributeTableFilterModel::ShowFilteredList );
dialog->setFilterExpression( filterExpression );
@@ -94,7 +94,7 @@ void QgsMapToolIdentifyAction::showAttributeTable( QgsMapLayer *layer, const QLi
resultsDialog()->clear();

QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
if ( !vl )
if ( !vl || !vl->dataProvider() )
return;

QString filter = QStringLiteral( "$id IN (" );
@@ -821,7 +821,10 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
currentLayer = it.value();
if ( currentLayer->type() == QgsMapLayerType::VectorLayer )
{

QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( currentLayer );
QgsVectorDataProvider *provider = vlayer->dataProvider();
if ( !provider )
continue;
QTableWidgetItem *twi = new QTableWidgetItem( QString::number( j ) );
twWFSLayers->setVerticalHeaderItem( j, twi );

@@ -839,8 +842,6 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
psb->setValue( QgsProject::instance()->readNumEntry( QStringLiteral( "WFSLayersPrecision" ), "/" + currentLayer->id(), 8 ) );
twWFSLayers->setCellWidget( j, 2, psb );

QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( currentLayer );
QgsVectorDataProvider *provider = vlayer->dataProvider();
if ( ( provider->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ) && ( provider->capabilities() & QgsVectorDataProvider::ChangeGeometries ) )
{
QCheckBox *cbu = new QCheckBox();
@@ -290,12 +290,15 @@ QList<QgsRelation> QgsRelationManager::discoverRelations( const QList<QgsRelatio
QList<QgsRelation> result;
for ( const QgsVectorLayer *layer : std::as_const( layers ) )
{
const auto constDiscoverRelations = layer->dataProvider()->discoverRelations( layer, layers );
for ( const QgsRelation &relation : constDiscoverRelations )
if ( const QgsVectorDataProvider *provider = layer->dataProvider() )
{
if ( !hasRelationWithEqualDefinition( existingRelations, relation ) )
const auto constDiscoverRelations = provider->discoverRelations( layer, layers );
for ( const QgsRelation &relation : constDiscoverRelations )
{
result.append( relation );
if ( !hasRelationWithEqualDefinition( existingRelations, relation ) )
{
result.append( relation );
}
}
}
}
@@ -342,4 +345,3 @@ void QgsRelationManager::setPolymorphicRelations( const QList<QgsPolymorphicRela
for ( const QgsPolymorphicRelation &newRelation : relations )
addPolymorphicRelation( newRelation );
}

@@ -284,7 +284,8 @@ QgsVectorLayer *QgsVectorLayer::clone() const
layer->addJoin( join );
}

layer->setProviderEncoding( dataProvider()->encoding() );
if ( mDataProvider )
layer->setProviderEncoding( mDataProvider->encoding() );
layer->setDisplayExpression( displayExpression() );
layer->setMapTipTemplate( mapTipTemplate() );
layer->setReadOnly( isReadOnly() );
@@ -3756,7 +3757,10 @@ void QgsVectorLayer::setRenderer( QgsFeatureRenderer *r )

void QgsVectorLayer::addFeatureRendererGenerator( QgsFeatureRendererGenerator *generator )
{
mRendererGenerators << generator;
if ( generator )
{
mRendererGenerators << generator;
}
}

void QgsVectorLayer::removeFeatureRendererGenerator( const QString &id )
@@ -34,7 +34,9 @@
QgsVectorLayerFeatureSource::QgsVectorLayerFeatureSource( const QgsVectorLayer *layer )
{
QMutexLocker locker( &layer->mFeatureSourceConstructorMutex );
mProviderFeatureSource.reset( layer->dataProvider()->featureSource() );
const QgsVectorDataProvider *provider = layer->dataProvider();
if ( provider )
mProviderFeatureSource.reset( provider->featureSource() );
mFields = layer->fields();
mId = layer->id();

@@ -75,7 +77,7 @@ QgsVectorLayerFeatureSource::QgsVectorLayerFeatureSource( const QgsVectorLayer *
{
#endif
// If we are inside a transaction the iterator "sees" the current status
if ( layer->dataProvider() && ! layer->dataProvider()->transaction() )
if ( provider && ! provider->transaction() )
{
mAddedFeatures = QgsFeatureMap( layer->editBuffer()->addedFeatures() );
mChangedGeometries = QgsGeometryMap( layer->editBuffer()->changedGeometries() );
@@ -293,13 +295,16 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayerFeat
}
else // no filter or filter by rect
{
if ( mSource->mHasEditBuffer )
{
mChangedFeaturesIterator = mSource->mProviderFeatureSource->getFeatures( mChangedFeaturesRequest );
}
else
if ( mSource->mProviderFeatureSource )
{
mProviderIterator = mSource->mProviderFeatureSource->getFeatures( mProviderRequest );
if ( mSource->mHasEditBuffer )
{
mChangedFeaturesIterator = mSource->mProviderFeatureSource->getFeatures( mChangedFeaturesRequest );
}
else
{
mProviderIterator = mSource->mProviderFeatureSource->getFeatures( mProviderRequest );
}
}

rewindEditBuffer();
@@ -437,8 +442,11 @@ bool QgsVectorLayerFeatureIterator::fetchFeature( QgsFeature &f )
if ( mProviderIterator.isClosed() )
{
mChangedFeaturesIterator.close();
mProviderIterator = mSource->mProviderFeatureSource->getFeatures( mProviderRequest );
mProviderIterator.setInterruptionChecker( mInterruptionChecker );
if ( mSource->mProviderFeatureSource )
{
mProviderIterator = mSource->mProviderFeatureSource->getFeatures( mProviderRequest );
mProviderIterator.setInterruptionChecker( mInterruptionChecker );
}
}

while ( mProviderIterator.nextFeature( f ) )
@@ -537,7 +537,7 @@ QMap<QString, QString> QgsMapToolIdentify::derivedAttributesForPoint( const QgsP

bool QgsMapToolIdentify::identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext )
{
if ( !layer || !layer->isSpatial() )
if ( !layer || !layer->isSpatial() || !layer->dataProvider() )
return false;

if ( !layer->isInScaleRange( mCanvas->mapSettings().scale() ) )
@@ -59,9 +59,13 @@ QgsFieldCalculator::QgsFieldCalculator( QgsVectorLayer *vl, QWidget *parent )

if ( !vl )
return;
QgsVectorDataProvider *dataProvider = vl->dataProvider();
if ( !dataProvider )
return;

mCanAddAttribute = vl->dataProvider()->capabilities() & QgsVectorDataProvider::AddAttributes;
mCanChangeAttributeValue = vl->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
const QgsVectorDataProvider::Capabilities caps = dataProvider->capabilities();
mCanAddAttribute = caps & QgsVectorDataProvider::AddAttributes;
mCanChangeAttributeValue = caps & QgsVectorDataProvider::ChangeAttributeValues;

QgsExpressionContext expContext( QgsExpressionContextUtils::globalProjectLayerScopes( mVectorLayer ) );

@@ -321,6 +321,11 @@ void QgsSourceFieldsProperties::editingToggled()

void QgsSourceFieldsProperties::addAttributeClicked()
{
if ( !mLayer || !mLayer->dataProvider() )
{
return;
}

QgsAddAttrDialog dialog( mLayer, this );
if ( dialog.exec() == QDialog::Accepted )
{
@@ -364,7 +369,7 @@ void QgsSourceFieldsProperties::deleteAttributeClicked()

void QgsSourceFieldsProperties::calculateFieldClicked()
{
if ( !mLayer )
if ( !mLayer || !mLayer->dataProvider() )
{
return;
}
@@ -1143,6 +1143,8 @@ void QgsVectorLayerProperties::loadDefaultMetadata()

void QgsVectorLayerProperties::saveStyleAs()
{
if ( !mLayer->dataProvider() )
return;
QgsVectorLayerSaveStyleDialog dlg( mLayer );
QgsSettings settings;

0 comments on commit 452ce09

Please sign in to comment.