Skip to content
Permalink
Browse files

Merge pull request #42754 from rouault/fix_crash_bad_vector_layer

Gui: fix crash when opening vector layer property dialog on a bad layer
  • Loading branch information
elpaso authored and nyalldawson committed Apr 17, 2021
1 parent 90ca175 commit 6eadd09f9212429178282003362a5dd10633dd31
Showing with 16 additions and 3 deletions.
  1. +6 −0 src/core/raster/qgsrasterlayer.cpp
  2. +10 −3 src/gui/vector/qgsvectorlayerproperties.cpp
@@ -315,6 +315,9 @@ QgsLegendColorList QgsRasterLayer::legendSymbologyItems() const

QString QgsRasterLayer::htmlMetadata() const
{
if ( !mDataProvider )
return QString();

QgsLayerMetadataFormatter htmlFormatter( metadata() );
QString myMetadata = QStringLiteral( "<html><head></head>\n<body>\n" );

@@ -2161,6 +2164,9 @@ bool QgsRasterLayer::writeXml( QDomNode &layer_node,
QDomDocument &document,
const QgsReadWriteContext &context ) const
{
if ( !mDataProvider )
return false;

// first get the layer element so that we can append the type attribute

QDomElement mapLayerNode = layer_node.toElement();
@@ -908,7 +908,10 @@ void QgsVectorLayerProperties::loadDefaultStyle_clicked()
QString msg;
bool defaultLoadedFlag = false;

if ( mLayer->dataProvider()->isSaveAndLoadStyleToDatabaseSupported() )
const QgsVectorDataProvider *provider = mLayer->dataProvider();
if ( !provider )
return;
if ( provider->isSaveAndLoadStyleToDatabaseSupported() )
{
QMessageBox askToUser;
askToUser.setText( tr( "Load default style from: " ) );
@@ -963,7 +966,10 @@ void QgsVectorLayerProperties::saveDefaultStyle_clicked()
{
apply();
QString errorMsg;
if ( mLayer->dataProvider()->isSaveAndLoadStyleToDatabaseSupported() )
const QgsVectorDataProvider *provider = mLayer->dataProvider();
if ( !provider )
return;
if ( provider->isSaveAndLoadStyleToDatabaseSupported() )
{
QMessageBox askToUser;
askToUser.setText( tr( "Save default style to: " ) );
@@ -1823,7 +1829,8 @@ void QgsVectorLayerProperties::optionsStackedWidget_CurrentChanged( int index )

void QgsVectorLayerProperties::mSimplifyDrawingGroupBox_toggled( bool checked )
{
if ( !( mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::SimplifyGeometries ) )
const QgsVectorDataProvider *provider = mLayer->dataProvider();
if ( !( provider && ( provider->capabilities() & QgsVectorDataProvider::SimplifyGeometries ) != 0 ) )
{
mSimplifyDrawingAtProvider->setEnabled( false );
}

0 comments on commit 6eadd09

Please sign in to comment.