Skip to content

Commit

Permalink
fix some crash on invalid layers
Browse files Browse the repository at this point in the history
(cherry picked from commit 34488f8 & 8fbee12)
  • Loading branch information
jef-n committed Jun 29, 2015
1 parent 4050d44 commit d9a2b35
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class QgsVectorLayer : QgsMapLayer
/** Removes a vector layer join */
void removeJoin( const QString& joinLayerId );

const QList< QgsVectorJoinInfo >& vectorJoins() const;
const QList< QgsVectorJoinInfo > vectorJoins() const;

/**
* Add a new field which is calculated by the expression specified
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,7 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::writeAsVectorFormat( QgsVe

QGis::WkbType wkbType = layer->wkbType();

if ( layer->providerType() == "ogr" )
if ( layer->providerType() == "ogr" && layer->dataProvider() )
{
QStringList theURIParts = layer->dataProvider()->dataSourceUri().split( "|" );
QString srcFileName = theURIParts[0];
Expand Down
12 changes: 8 additions & 4 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2840,7 +2840,7 @@ int QgsVectorLayer::fieldNameIndex( const QString& fieldName ) const

bool QgsVectorLayer::addJoin( const QgsVectorJoinInfo& joinInfo )
{
return mJoinBuffer->addJoin( joinInfo );
return mJoinBuffer && mJoinBuffer->addJoin( joinInfo );
}

void QgsVectorLayer::checkJoinLayerRemove( QString theLayerId )
Expand All @@ -2850,12 +2850,16 @@ void QgsVectorLayer::checkJoinLayerRemove( QString theLayerId )

void QgsVectorLayer::removeJoin( const QString& joinLayerId )
{
mJoinBuffer->removeJoin( joinLayerId );
if ( mJoinBuffer )
mJoinBuffer->removeJoin( joinLayerId );
}

const QList< QgsVectorJoinInfo >& QgsVectorLayer::vectorJoins() const
const QList< QgsVectorJoinInfo > QgsVectorLayer::vectorJoins() const
{
return mJoinBuffer->vectorJoins();
if ( mJoinBuffer )
return mJoinBuffer->vectorJoins();
else
return QList< QgsVectorJoinInfo >();
}

void QgsVectorLayer::addExpressionField( const QString& exp, const QgsField& fld )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** Removes a vector layer join */
void removeJoin( const QString& joinLayerId );

const QList< QgsVectorJoinInfo >& vectorJoins() const;
const QList<QgsVectorJoinInfo> vectorJoins() const;

/**
* Add a new field which is calculated by the expression specified
Expand Down

0 comments on commit d9a2b35

Please sign in to comment.