Skip to content

Commit

Permalink
[processing] Fix occasional crash in Processing gui unit test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 10, 2019
1 parent 8f6cb53 commit d7c5f6e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Expand Up @@ -28,11 +28,13 @@ Processing map layer combo box.
%End
public:

QgsProcessingMapLayerComboBox( QgsProcessingParameterDefinition *parameter, QWidget *parent = 0 );
QgsProcessingMapLayerComboBox( const QgsProcessingParameterDefinition *parameter, QWidget *parent = 0 );
%Docstring
Constructor for QgsProcessingMapLayerComboBox, with the specified ``parameter`` definition.
%End

~QgsProcessingMapLayerComboBox();

void setLayer( QgsMapLayer *layer );
%Docstring
Sets the combo box to the specified ``layer``, if ``layer`` is compatible with the
Expand Down
14 changes: 8 additions & 6 deletions src/gui/processing/qgsprocessingmaplayercombobox.cpp
Expand Up @@ -28,9 +28,9 @@

///@cond PRIVATE

QgsProcessingMapLayerComboBox::QgsProcessingMapLayerComboBox( QgsProcessingParameterDefinition *parameter, QWidget *parent )
QgsProcessingMapLayerComboBox::QgsProcessingMapLayerComboBox( const QgsProcessingParameterDefinition *parameter, QWidget *parent )
: QWidget( parent )
, mParameter( parameter )
, mParameter( parameter->clone() )
{
QHBoxLayout *layout = new QHBoxLayout();
layout->setMargin( 0 );
Expand Down Expand Up @@ -68,9 +68,9 @@ QgsProcessingMapLayerComboBox::QgsProcessingMapLayerComboBox( QgsProcessingParam
{
QList<int> dataTypes;
if ( mParameter->type() == QgsProcessingParameterFeatureSource::typeName() )
dataTypes = static_cast< QgsProcessingParameterFeatureSource *>( mParameter )->dataTypes();
dataTypes = static_cast< QgsProcessingParameterFeatureSource *>( mParameter.get() )->dataTypes();
else if ( mParameter->type() == QgsProcessingParameterVectorLayer::typeName() )
dataTypes = static_cast< QgsProcessingParameterVectorLayer *>( mParameter )->dataTypes();
dataTypes = static_cast< QgsProcessingParameterVectorLayer *>( mParameter.get() )->dataTypes();

if ( dataTypes.contains( QgsProcessing::TypeVectorAnyGeometry ) || dataTypes.isEmpty() )
filters = QgsMapLayerProxyModel::HasGeometry;
Expand Down Expand Up @@ -119,6 +119,8 @@ QgsProcessingMapLayerComboBox::QgsProcessingMapLayerComboBox( QgsProcessingParam
setAcceptDrops( true );
}

QgsProcessingMapLayerComboBox::~QgsProcessingMapLayerComboBox() = default;

void QgsProcessingMapLayerComboBox::setLayer( QgsMapLayer *layer )
{
if ( layer || mParameter->flags() & QgsProcessingParameterDefinition::FlagOptional )
Expand Down Expand Up @@ -276,8 +278,8 @@ QString QgsProcessingMapLayerComboBox::compatibleUriFromMimeData( const QMimeDat
|| mParameter->type() == QgsProcessingParameterMapLayer::typeName() )
&& u.layerType == QLatin1String( "vector" ) && u.providerKey == QLatin1String( "ogr" ) )
{
QList< int > dataTypes = mParameter->type() == QgsProcessingParameterFeatureSource::typeName() ? static_cast< QgsProcessingParameterFeatureSource * >( mParameter )->dataTypes()
: ( mParameter->type() == QgsProcessingParameterVectorLayer::typeName() ? static_cast<QgsProcessingParameterVectorLayer *>( mParameter )->dataTypes()
QList< int > dataTypes = mParameter->type() == QgsProcessingParameterFeatureSource::typeName() ? static_cast< QgsProcessingParameterFeatureSource * >( mParameter.get() )->dataTypes()
: ( mParameter->type() == QgsProcessingParameterVectorLayer::typeName() ? static_cast<QgsProcessingParameterVectorLayer *>( mParameter.get() )->dataTypes()
: QList< int >() );
switch ( QgsWkbTypes::geometryType( u.wkbType ) )
{
Expand Down
6 changes: 4 additions & 2 deletions src/gui/processing/qgsprocessingmaplayercombobox.h
Expand Up @@ -47,7 +47,9 @@ class GUI_EXPORT QgsProcessingMapLayerComboBox : public QWidget
/**
* Constructor for QgsProcessingMapLayerComboBox, with the specified \a parameter definition.
*/
QgsProcessingMapLayerComboBox( QgsProcessingParameterDefinition *parameter, QWidget *parent = nullptr );
QgsProcessingMapLayerComboBox( const QgsProcessingParameterDefinition *parameter, QWidget *parent = nullptr );

~QgsProcessingMapLayerComboBox() override;

/**
* Sets the combo box to the specified \a layer, if \a layer is compatible with the
Expand Down Expand Up @@ -115,7 +117,7 @@ class GUI_EXPORT QgsProcessingMapLayerComboBox : public QWidget
void selectionChanged( const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect );

private:
QgsProcessingParameterDefinition *mParameter = nullptr;
std::unique_ptr< QgsProcessingParameterDefinition > mParameter;
QgsMapLayerComboBox *mCombo = nullptr;
QToolButton *mSelectButton = nullptr;
QCheckBox *mUseSelectionCheckBox = nullptr;
Expand Down

0 comments on commit d7c5f6e

Please sign in to comment.