Skip to content

Commit

Permalink
fix(MaskUI): Refresh masking widget for every setLayer call
Browse files Browse the repository at this point in the history
Fixes qgis#57248
Remove flaky code used to avoid as much as possible masking widget
populate. This cause refresh issues and populate is now way more efficient.
  • Loading branch information
troopa81 committed Jun 17, 2024
1 parent 0f9f776 commit b764794
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 42 deletions.
44 changes: 11 additions & 33 deletions src/gui/qgsmaskingwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ QgsMaskingWidget::QgsMaskingWidget( QWidget *parent ) :
QgsPanelWidget( parent )
{
setupUi( this );

connect( mMaskTargetsWidget, &QgsSymbolLayerSelectionWidget::changed, this, &QgsMaskingWidget::onSelectionChanged );
connect( mMaskSourcesWidget, &QgsMaskSourceSelectionWidget::changed, this, &QgsMaskingWidget::onSelectionChanged );
}

void QgsMaskingWidget::onSelectionChanged()
Expand All @@ -58,29 +61,6 @@ void QgsMaskingWidget::onSelectionChanged()
emit widgetChanged();
}

void QgsMaskingWidget::showEvent( QShowEvent *event )
{
Q_UNUSED( event );

// populate is quite long, so we delay it when the widget is first shown
if ( mMustPopulate )
{
disconnect( mMaskTargetsWidget, &QgsSymbolLayerSelectionWidget::changed, this, &QgsMaskingWidget::onSelectionChanged );
disconnect( mMaskSourcesWidget, &QgsMaskSourceSelectionWidget::changed, this, &QgsMaskingWidget::onSelectionChanged );

mMustPopulate = false;
populate();

connect( mMaskTargetsWidget, &QgsSymbolLayerSelectionWidget::changed, this, &QgsMaskingWidget::onSelectionChanged );
connect( mMaskSourcesWidget, &QgsMaskSourceSelectionWidget::changed, this, &QgsMaskingWidget::onSelectionChanged );

onSelectionChanged();
}
}




/**
* Symbol layer masks collector. It is an enhanced version of QgsVectorLayerUtils::symbolLayerMasks.
* Indeed, we need here to know both mask sources and targets for all masks
Expand All @@ -107,15 +87,15 @@ QList<QPair<QString, QList<QgsSymbolLayerReference>>> symbolLayerMasks( const Qg

void QgsMaskingWidget::setLayer( QgsVectorLayer *layer )
{
if ( mLayer != layer )
{
mLayer = layer;
mMustPopulate = true;
}
mLayer = layer;
populate();
}

void QgsMaskingWidget::populate()
{
mMaskSourcesWidget->blockSignals( true );
mMaskTargetsWidget->blockSignals( true );

mMaskSourcesWidget->update();
mMaskTargetsWidget->setLayer( mLayer );

Expand Down Expand Up @@ -175,6 +155,9 @@ void QgsMaskingWidget::populate()

mMaskSourcesWidget->setSelection( maskSources );
mMaskTargetsWidget->setSelection( maskedSymbolLayers );

mMaskSourcesWidget->blockSignals( false );
mMaskTargetsWidget->blockSignals( false );
}

void QgsMaskingWidget::apply()
Expand Down Expand Up @@ -276,11 +259,6 @@ void QgsMaskingWidget::apply()
}
}

bool QgsMaskingWidget::hasBeenPopulated()
{
return !mMustPopulate;
}

SymbolLayerVisitor::SymbolLayerVisitor( SymbolLayerVisitor::SymbolLayerCallback callback ) :
mCallback( callback )
{}
Expand Down
9 changes: 1 addition & 8 deletions src/gui/qgsmaskingwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ class GUI_EXPORT QgsMaskingWidget: public QgsPanelWidget, private Ui::QgsMasking
//! Applies the changes
void apply();

//! Widget has been populated or not
bool hasBeenPopulated();

protected:

void showEvent( QShowEvent * ) override;

private slots:

/**
Expand All @@ -70,7 +63,7 @@ class GUI_EXPORT QgsMaskingWidget: public QgsPanelWidget, private Ui::QgsMasking
void populate();

QPointer<QgsMessageBarItem> mMessageBarItem;
bool mMustPopulate = false;

friend class TestQgsMaskingWidget;
};

Expand Down
2 changes: 1 addition & 1 deletion src/gui/vector/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ void QgsVectorLayerProperties::apply()
mMetadataFilled = false;

// save masking settings
if ( mMaskingWidget && mMaskingWidget->hasBeenPopulated() )
if ( mMaskingWidget )
mMaskingWidget->apply();

//
Expand Down

0 comments on commit b764794

Please sign in to comment.