From e8ca757b068e548ee7c75417827a7977fe6d4ded Mon Sep 17 00:00:00 2001 From: Ismail Sunni Date: Fri, 18 Feb 2022 16:10:25 +0100 Subject: [PATCH] Show style name in style panel title. Fix #25724. --- src/app/qgisapp.cpp | 22 ++++++++++++++++++++++ src/app/qgslayerstylingwidget.cpp | 4 ++++ src/app/qgslayerstylingwidget.h | 3 +++ 3 files changed, 29 insertions(+) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index df1fd1f9294..38e919c2e28 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -1286,6 +1286,28 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers mMapStyleWidget = new QgsLayerStylingWidget( mMapCanvas, mInfoBar, mMapLayerPanelFactories ); mMapStylingDock->setWidget( mMapStyleWidget ); connect( mMapStyleWidget, &QgsLayerStylingWidget::styleChanged, this, &QgisApp::updateLabelToolButtons ); + connect( mMapStyleWidget, &QgsLayerStylingWidget::layerChanged, this, [ = ]( QgsMapLayer * layer ) + { + if ( !layer->styleManager()->isDefault( layer->styleManager()->currentStyle() ) ) + { + mMapStylingDock->setWindowTitle( tr( "Layer Styling (%1)" ).arg( layer->styleManager()->currentStyle() ) ); + } + else + { + mMapStylingDock->setWindowTitle( tr( "Layer Styling" ) ); + } + } ); + connect( mMapStyleWidget, &QgsLayerStylingWidget::layerStyleChanged, this, [ = ]( QString styleName ) + { + if ( tr( "default" ) != styleName ) + { + mMapStylingDock->setWindowTitle( tr( "Layer Styling (%1)" ).arg( styleName ) ); + } + else + { + mMapStylingDock->setWindowTitle( tr( "Layer Styling" ) ); + } + } ); connect( mMapStylingDock, &QDockWidget::visibilityChanged, mActionStyleDock, &QAction::setChecked ); addDockWidget( Qt::RightDockWidgetArea, mMapStylingDock ); diff --git a/src/app/qgslayerstylingwidget.cpp b/src/app/qgslayerstylingwidget.cpp index f79be77b783..d7fe8dfbf36 100644 --- a/src/app/qgslayerstylingwidget.cpp +++ b/src/app/qgslayerstylingwidget.cpp @@ -33,6 +33,7 @@ #include "qgsrasterrendererwidget.h" #include "qgsmapcanvas.h" #include "qgsmaplayer.h" +#include "qgsmaplayerstylemanager.h" #include "qgsstyle.h" #include "qgsvectorlayer.h" #include "qgspointcloudlayer.h" @@ -157,6 +158,7 @@ void QgsLayerStylingWidget::setLayer( QgsMapLayer *layer ) if ( mCurrentLayer ) { disconnect( mCurrentLayer, &QgsMapLayer::styleChanged, this, &QgsLayerStylingWidget::updateCurrentWidgetLayer ); + disconnect( mCurrentLayer->styleManager(), &QgsMapLayerStyleManager::currentStyleChanged, this, &QgsLayerStylingWidget::emitLayerStyleChanged ); } if ( !layer || !layer->isSpatial() || !QgsProject::instance()->layerIsEmbedded( layer->id() ).isEmpty() ) @@ -180,6 +182,7 @@ void QgsLayerStylingWidget::setLayer( QgsMapLayer *layer ) mUndoWidget->setUndoStack( layer->undoStackStyles() ); connect( mCurrentLayer, &QgsMapLayer::styleChanged, this, &QgsLayerStylingWidget::updateCurrentWidgetLayer ); + connect( mCurrentLayer->styleManager(), &QgsMapLayerStyleManager::currentStyleChanged, this, &QgsLayerStylingWidget::emitLayerStyleChanged ); int lastPage = mOptionsListWidget->currentIndex().row(); mOptionsListWidget->blockSignals( true ); @@ -300,6 +303,7 @@ void QgsLayerStylingWidget::setLayer( QgsMapLayer *layer ) mLastStyleXml = doc.createElement( QStringLiteral( "style" ) ); doc.appendChild( mLastStyleXml ); mCurrentLayer->writeStyle( mLastStyleXml, doc, errorMsg, QgsReadWriteContext() ); + emit layerChanged( layer ); } void QgsLayerStylingWidget::apply() diff --git a/src/app/qgslayerstylingwidget.h b/src/app/qgslayerstylingwidget.h index d97b079288e..8c753e68976 100644 --- a/src/app/qgslayerstylingwidget.h +++ b/src/app/qgslayerstylingwidget.h @@ -116,6 +116,8 @@ class APP_EXPORT QgsLayerStylingWidget : public QWidget, private Ui::QgsLayerSty signals: void styleChanged( QgsMapLayer *layer ); + void layerChanged( QgsMapLayer *layer ); + void layerStyleChanged( const QString ¤tStyleName ); public slots: void setLayer( QgsMapLayer *layer ); @@ -153,6 +155,7 @@ class APP_EXPORT QgsLayerStylingWidget : public QWidget, private Ui::QgsLayerSty private: void pushUndoItem( const QString &name, bool triggerRepaint = true ); + void emitLayerStyleChanged( const QString ¤tStyleName ) {emit layerStyleChanged( currentStyleName );}; int mNotSupportedPage; int mLayerPage; QTimer *mAutoApplyTimer = nullptr;