Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Fix crashes in expression widget when no layer is available
- Loading branch information
|
@@ -71,7 +71,7 @@ class QgsFeatureExpressionValuesGatherer: public QThread |
|
|
Entry( const QgsFeatureId &_featureId, const QString &_value, const QgsVectorLayer *layer ) |
|
|
: featureId( _featureId ) |
|
|
, value( _value ) |
|
|
, feature( QgsFeature( layer->fields() ) ) |
|
|
, feature( QgsFeature( layer ? layer->fields() : QgsFields() ) ) |
|
|
{} |
|
|
|
|
|
QVariantList identifierFields; |
|
|
|
@@ -83,7 +83,7 @@ QgsFeatureExpressionValuesGatherer::Entry QgsFeatureFilterModel::createEntry( co |
|
|
for ( const QVariant &v : constValues ) |
|
|
values << QStringLiteral( "(%1)" ).arg( v.toString() ); |
|
|
|
|
|
return QgsFeatureExpressionValuesGatherer::Entry( constValues, values.join( QLatin1Char( ' ' ) ), QgsFeature( sourceLayer()->fields() ) ); |
|
|
return QgsFeatureExpressionValuesGatherer::Entry( constValues, values.join( QLatin1Char( ' ' ) ), QgsFeature( sourceLayer() ? sourceLayer()->fields() : QgsFields() ) ); |
|
|
} |
|
|
|
|
|
bool QgsFeatureFilterModel::compareEntries( const QgsFeatureExpressionValuesGatherer::Entry &a, const QgsFeatureExpressionValuesGatherer::Entry &b ) const |
|
|
|
@@ -50,11 +50,14 @@ void QgsFeaturePickerModelBase::setSourceLayer( QgsVectorLayer *sourceLayer ) |
|
|
return; |
|
|
|
|
|
mSourceLayer = sourceLayer; |
|
|
mExpressionContext = sourceLayer->createExpressionContext(); |
|
|
if ( mSourceLayer ) |
|
|
mExpressionContext = mSourceLayer->createExpressionContext(); |
|
|
|
|
|
reload(); |
|
|
emit sourceLayerChanged(); |
|
|
|
|
|
setDisplayExpression( sourceLayer->displayExpression() ); |
|
|
if ( mSourceLayer ) |
|
|
setDisplayExpression( mSourceLayer->displayExpression() ); |
|
|
} |
|
|
|
|
|
|
|
@@ -279,7 +282,7 @@ void QgsFeaturePickerModelBase::updateCompleter() |
|
|
// We got strings for a filter selection |
|
|
std::sort( entries.begin(), entries.end(), []( const QgsFeatureExpressionValuesGatherer::Entry & a, const QgsFeatureExpressionValuesGatherer::Entry & b ) { return a.value.localeAwareCompare( b.value ) < 0; } ); |
|
|
|
|
|
if ( mAllowNull ) |
|
|
if ( mAllowNull && mSourceLayer ) |
|
|
{ |
|
|
entries.prepend( QgsFeatureExpressionValuesGatherer::nullEntry( mSourceLayer ) ); |
|
|
} |
|
|