Skip to content

Commit

Permalink
Remove item from MultipleLayer when layer is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 authored and nyalldawson committed Dec 9, 2020
1 parent 57e1e14 commit 1e89dd0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/gui/processing/qgsprocessingmultipleselectiondialog.cpp
Expand Up @@ -20,6 +20,7 @@
#include "qgsvectorlayer.h"
#include "qgsmeshlayer.h"
#include "qgsrasterlayer.h"
#include "qgsproject.h"
#include "processing/models/qgsprocessingmodelchildparametersource.h"
#include <QStandardItemModel>
#include <QStandardItem>
Expand Down Expand Up @@ -328,6 +329,24 @@ void QgsProcessingMultipleInputPanelWidget::addDirectory()

void QgsProcessingMultipleInputPanelWidget::populateFromProject( QgsProject *project )
{
connect( project, &QgsProject::layerRemoved, this, [&]( const QString & layerId )
{
for ( int i = 0; i < mModel->rowCount(); ++i )
{
const QStandardItem *item = mModel->item( i );
if ( item->data( Qt::UserRole ) == layerId )
{
bool isChecked = ( item->checkState() == Qt::Checked );
mModel->removeRow( i );

if ( isChecked )
emit selectionChanged();

break;
}
}
} );

QgsSettings settings;
auto addLayer = [&]( const QgsMapLayer * layer )
{
Expand Down
10 changes: 9 additions & 1 deletion src/gui/processing/qgsprocessingwidgetwrapperimpl.cpp
Expand Up @@ -4093,7 +4093,7 @@ void QgsProcessingFieldWidgetWrapper::setParentLayerWrapperValue( const QgsAbstr
QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( layers.at( 0 ) );
QgsFields fields = vlayer && vlayer->isValid() ? vlayer->fields() : QgsFields();
const QList< QgsMapLayer * > remainingLayers = layers.mid( 1 );
for ( QgsMapLayer* layer : remainingLayers )
for ( QgsMapLayer *layer : remainingLayers )
{
if ( fields.isEmpty() )
break;
Expand Down Expand Up @@ -6472,6 +6472,14 @@ void QgsProcessingMultipleLayerPanelWidget::setValue( const QVariant &value )
void QgsProcessingMultipleLayerPanelWidget::setProject( QgsProject *project )
{
mProject = project;
connect( mProject, &QgsProject::layerRemoved, this, [&]( const QString & layerId )
{
if ( mValue.removeAll( layerId ) )
{
updateSummaryText();
emit changed();
}
} );
}

void QgsProcessingMultipleLayerPanelWidget::setModel( QgsProcessingModelAlgorithm *model, const QString &modelChildAlgorithmID )
Expand Down

0 comments on commit 1e89dd0

Please sign in to comment.