Skip to content
Permalink
Browse files

Fixes #33277 : save correctly selective masking parameters

  • Loading branch information
troopa81 authored and nyalldawson committed May 12, 2020
1 parent 14bc947 commit bff60955e1af15b0602d551538279e437117395c
@@ -28,29 +28,54 @@
#include "qgsvectorlayerutils.h"
#include "qgsmasksymbollayer.h"
#include "qgsvectorlayerlabeling.h"
#include "qgsmessagebaritem.h"

QgsMaskingWidget::QgsMaskingWidget( QWidget *parent ) :
QgsPanelWidget( parent )
{
setupUi( this );
}

void QgsMaskingWidget::onSelectionChanged()
{
// display message if configuration is not consistent
bool printMessage =
( mMaskTargetsWidget->selection().empty() && !mMaskSourcesWidget->selection().empty() )
|| ( !mMaskTargetsWidget->selection().empty() && mMaskSourcesWidget->selection().empty() );

connect( mMaskTargetsWidget, &QgsSymbolLayerSelectionWidget::changed, this, [&]()
if ( mMessageBarItem && !printMessage )
{
mMaskSourcesWidget->setEnabled( ! mMaskTargetsWidget->selection().isEmpty() );
emit widgetChanged();
} );
connect( mMaskSourcesWidget, &QgsMaskSourceSelectionWidget::changed, this, [&]()
mMessageBar->popWidget( mMessageBarItem );
delete mMessageBarItem;
mMessageBarItem = nullptr;
}
else if ( !mMessageBarItem && printMessage )
{
emit widgetChanged();
} );
mMessageBarItem = new QgsMessageBarItem( tr( "You need to select both mask sources and masked symbol layers. If not, all configuration will be lost" ), Qgis::Warning, 0, this );
mMessageBar->pushItem( mMessageBarItem );
}

emit widgetChanged();
}

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

connect( mEditMaskSettingsGroup, &QGroupBox::toggled, this, [&]( bool on )
// populate is quite long, so we delay it when the widget is first shown
if ( _mustPopulate )
{
if ( on && mLayer )
{
populate();
}
} );
disconnect( mMaskTargetsWidget, &QgsSymbolLayerSelectionWidget::changed, this, &QgsMaskingWidget::onSelectionChanged );
disconnect( mMaskSourcesWidget, &QgsMaskSourceSelectionWidget::changed, this, &QgsMaskingWidget::onSelectionChanged );

_mustPopulate = false;
populate();

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

onSelectionChanged();
}
}

/**
@@ -141,10 +166,10 @@ QList<QPair<QgsSymbolLayerId, QList<QgsSymbolLayerReference>>> symbolLayerMasks(

void QgsMaskingWidget::setLayer( QgsVectorLayer *layer )
{
mLayer = layer;
if ( mEditMaskSettingsGroup->isChecked() )
if ( mLayer != layer )
{
populate();
mLayer = layer;
_mustPopulate = true;
}
}

@@ -23,6 +23,8 @@
#include "qgis_sip.h"
#include "qgis_gui.h"

class QgsMessageBarItem;

/**
* \ingroup gui
* Main widget for the configuration of mask sources and targets.
@@ -47,10 +49,21 @@ class GUI_EXPORT QgsMaskingWidget: public QgsPanelWidget, private Ui::QgsMasking
//! Emitted when a change is performed
void widgetChanged();

protected:

void showEvent( QShowEvent * ) override;

protected slots:

void onSelectionChanged();

private:
QgsVectorLayer *mLayer = nullptr;
//! Populate the mask source and target widgets
void populate();

QgsMessageBarItem *mMessageBarItem = nullptr;
bool _mustPopulate = false;
};

#endif
@@ -614,6 +614,9 @@ void QgsVectorLayerProperties::apply()
mMetadataWidget->acceptMetadata();
mMetadataFilled = false;

// save masking settings
mMaskingWidget->apply();

//
// Set up sql subset query if applicable
//
@@ -6,56 +6,44 @@
<rect>
<x>0</x>
<y>0</y>
<width>863</width>
<height>461</height>
<width>812</width>
<height>538</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="mEditMaskSettingsGroup">
<property name="title">
<string>Edit mask settings</string>
<widget class="QgsMessageBar" name="mMessageBar">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="checkable">
<bool>true</bool>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="checked">
<bool>false</bool>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Masked symbol layers</string>
</property>
</widget>
</item>
<item>
<widget class="QgsSymbolLayerSelectionWidget" name="mMaskTargetsWidget" native="true"/>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Mask sources</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>9</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Masked symbol layers</string>
</property>
</widget>
</item>
<item>
<widget class="QgsSymbolLayerSelectionWidget" name="mMaskTargetsWidget" native="true"/>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Mask sources</string>
</property>
</widget>
</item>
<item>
<widget class="QgsMaskSourceSelectionWidget" name="mMaskSourcesWidget" native="true">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsMaskSourceSelectionWidget" name="mMaskSourcesWidget" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
@@ -71,6 +59,12 @@
<header>qgssymbollayerselectionwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsMessageBar</class>
<extends>QFrame</extends>
<header>qgsmessagebar.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>

0 comments on commit bff6095

Please sign in to comment.
You can’t perform that action at this time.