[ui] Fix single feat. renderer symbol levels reset when changing style (fixes #26547)

This commit is contained in:
nirvn 2019-08-26 10:28:31 +07:00 committed by Mathieu Pellerin
parent 10c5b2f9db
commit 648af3ed89
7 changed files with 34 additions and 10 deletions

View File

@ -76,6 +76,11 @@ This method should be called whenever the renderer is actually set on the layer.
Emitted when expression context variables on the associated
vector layers have been changed. Will request the parent dialog
to re-synchronize with the variables.
%End
void symbolLevelsChanged();
%Docstring
Emitted when the symbol levels settings have been changed.
%End
protected:

View File

@ -71,6 +71,7 @@ Returns the symbol that is currently active in the widget. Can be ``None``.
:return: The active symbol.
%End
protected:
void loadSymbol();
@ -78,7 +79,6 @@ Returns the symbol that is currently active in the widget. Can be ``None``.
Reload the current symbol in the view.
%End
void updateUi();
%Docstring
Update the state of the UI based on the currently set symbol layer.

View File

@ -320,7 +320,7 @@ void QgsRendererWidget::showSymbolLevelsDialog( QgsFeatureRenderer *r )
QgsSymbolLevelsWidget *widget = new QgsSymbolLevelsWidget( r, r->usingSymbolLevels(), panel );
widget->setPanelTitle( tr( "Symbol Levels" ) );
connect( widget, &QgsPanelWidget::widgetChanged, widget, &QgsSymbolLevelsWidget::apply );
connect( widget, &QgsPanelWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
connect( widget, &QgsPanelWidget::widgetChanged, [ = ]() { emit widgetChanged(); emit symbolLevelsChanged(); } );
panel->openPanel( widget );
return;
}
@ -329,6 +329,7 @@ void QgsRendererWidget::showSymbolLevelsDialog( QgsFeatureRenderer *r )
if ( dlg.exec() )
{
emit widgetChanged();
emit symbolLevelsChanged();
}
}

View File

@ -88,6 +88,11 @@ class GUI_EXPORT QgsRendererWidget : public QgsPanelWidget
*/
void layerVariablesChanged();
/**
* Emitted when the symbol levels settings have been changed.
*/
void symbolLevelsChanged();
protected:
QgsVectorLayer *mLayer = nullptr;
QgsStyle *mStyle = nullptr;

View File

@ -57,6 +57,12 @@ QgsSingleSymbolRendererWidget::QgsSingleSymbolRendererWidget( QgsVectorLayer *la
mSelector = new QgsSymbolSelectorWidget( mSingleSymbol, mStyle, mLayer, nullptr );
connect( mSelector, &QgsSymbolSelectorWidget::symbolModified, this, &QgsSingleSymbolRendererWidget::changeSingleSymbol );
connect( mSelector, &QgsPanelWidget::showPanel, this, &QgsPanelWidget::openPanel );
connect( this, &QgsRendererWidget::symbolLevelsChanged, [ = ]()
{
delete mSingleSymbol;
mSingleSymbol = mRenderer->symbol()->clone();
mSelector->loadSymbol( mSingleSymbol );
} );
QVBoxLayout *layout = new QVBoxLayout( this );
layout->setContentsMargins( 0, 0, 0, 0 );

View File

@ -385,6 +385,13 @@ QgsSymbolWidgetContext QgsSymbolSelectorWidget::context() const
void QgsSymbolSelectorWidget::loadSymbol( QgsSymbol *symbol, SymbolLayerItem *parent )
{
if ( !parent )
{
mSymbol = symbol;
model->clear();
parent = static_cast<SymbolLayerItem *>( model->invisibleRootItem() );
}
SymbolLayerItem *symbolItem = new SymbolLayerItem( symbol );
QFont boldFont = symbolItem->font();
boldFont.setBold( true );

View File

@ -127,6 +127,14 @@ class GUI_EXPORT QgsSymbolSelectorWidget: public QgsPanelWidget, private Ui::Qgs
*/
QgsSymbol *symbol() { return mSymbol; }
/**
* Load the given symbol into the widget.
* \param symbol The symbol to load.
* \param parent The parent symbol layer item. If the parent parameter is null, the whole symbol and model will be reset.
* \note not available in Python bindings
*/
void loadSymbol( QgsSymbol *symbol, SymbolLayerItem *parent = nullptr ) SIP_SKIP;
protected:
/**
@ -134,14 +142,6 @@ class GUI_EXPORT QgsSymbolSelectorWidget: public QgsPanelWidget, private Ui::Qgs
*/
void loadSymbol();
/**
* Load the given symbol into the widget.
* \param symbol The symbol to load.
* \param parent The parent symbol layer item.
* \note not available in Python bindings
*/
void loadSymbol( QgsSymbol *symbol, SymbolLayerItem *parent ) SIP_SKIP;
/**
* Update the state of the UI based on the currently set symbol layer.
*/