diff --git a/src/app/qgsapplayertreeviewmenuprovider.cpp b/src/app/qgsapplayertreeviewmenuprovider.cpp index dfb804d3b0c..02412829ad4 100644 --- a/src/app/qgsapplayertreeviewmenuprovider.cpp +++ b/src/app/qgsapplayertreeviewmenuprovider.cpp @@ -199,13 +199,16 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu() QAction *showFeatureCount = actions->actionShowFeatureCount( menu ); menu->addAction( showFeatureCount ); showFeatureCount->setEnabled( vlayer->isValid() ); + } - const QString iconName = vlayer && vlayer->labeling() && vlayer->labeling()->type() == QLatin1String( "rule-based" ) + if ( vlayer || vectorTileLayer ) + { + const QString iconName = vectorTileLayer || ( vlayer && vlayer->labeling() && vlayer->labeling()->type() == QLatin1String( "rule-based" ) ) ? QStringLiteral( "labelingRuleBased.svg" ) : QStringLiteral( "labelingSingle.svg" ); QAction *actionShowLabels = new QAction( QgsApplication::getThemeIcon( iconName ), tr( "Show &Labels" ), menu ); actionShowLabels->setCheckable( true ); - actionShowLabels->setChecked( vlayer->labelsEnabled() ); + actionShowLabels->setChecked( vectorTileLayer ? vectorTileLayer->labelsEnabled() : vlayer->labelsEnabled() ); connect( actionShowLabels, &QAction::toggled, this, &QgsAppLayerTreeViewMenuProvider::toggleLabels ); menu->addAction( actionShowLabels ); } @@ -1335,22 +1338,30 @@ void QgsAppLayerTreeViewMenuProvider::toggleLabels( bool enabled ) const QList selectedLayerNodes = mView->selectedLayerNodes(); for ( QgsLayerTreeLayer *l : selectedLayerNodes ) { - QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( l->layer() ); - if ( !vlayer || !vlayer->isSpatial() ) - continue; + if ( QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( l->layer() ) ) + { + if ( !vlayer->isSpatial() ) + continue; - if ( enabled && !vlayer->labeling() ) - { - // no labeling setup - create default labeling for layer - const QgsPalLayerSettings settings = QgsAbstractVectorLayerLabeling::defaultSettingsForLayer( vlayer ); - vlayer->setLabeling( new QgsVectorLayerSimpleLabeling( settings ) ); - vlayer->setLabelsEnabled( true ); + if ( enabled && !vlayer->labeling() ) + { + // no labeling setup - create default labeling for layer + const QgsPalLayerSettings settings = QgsAbstractVectorLayerLabeling::defaultSettingsForLayer( vlayer ); + vlayer->setLabeling( new QgsVectorLayerSimpleLabeling( settings ) ); + vlayer->setLabelsEnabled( true ); + } + else + { + vlayer->setLabelsEnabled( enabled ); + } + vlayer->emitStyleChanged(); + vlayer->triggerRepaint(); } - else + else if ( QgsVectorTileLayer *vectorTilelayer = qobject_cast< QgsVectorTileLayer * >( l->layer() ) ) { - vlayer->setLabelsEnabled( enabled ); + vectorTilelayer->setLabelsEnabled( enabled ); + vectorTilelayer->emitStyleChanged(); + vectorTilelayer->triggerRepaint(); } - vlayer->emitStyleChanged(); - vlayer->triggerRepaint(); } } diff --git a/src/gui/vectortile/qgsvectortilebasiclabelingwidget.cpp b/src/gui/vectortile/qgsvectortilebasiclabelingwidget.cpp index 2b03dca7e9b..e90375e339b 100644 --- a/src/gui/vectortile/qgsvectortilebasiclabelingwidget.cpp +++ b/src/gui/vectortile/qgsvectortilebasiclabelingwidget.cpp @@ -15,9 +15,10 @@ #include "qgsvectortilebasiclabelingwidget.h" +#include "qgis.h" +#include "qgsapplication.h" #include "qgsvectortilebasiclabeling.h" #include "qgsvectortilelayer.h" - #include "qgslabelinggui.h" #include "qgsmapcanvas.h" #include "qgsvectortileutils.h" @@ -332,6 +333,10 @@ QgsVectorTileBasicLabelingWidget::QgsVectorTileBasicLabelingWidget( QgsVectorTil connect( btnEditRule, &QPushButton::clicked, this, &QgsVectorTileBasicLabelingWidget::editStyle ); connect( btnRemoveRule, &QAbstractButton::clicked, this, &QgsVectorTileBasicLabelingWidget::removeStyle ); + mLabelModeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "labelingNone.svg" ) ), tr( "No Labels" ) ); + mLabelModeComboBox->addItem( QgsApplication::getThemeIcon( QStringLiteral( "labelingRuleBased.svg" ) ), tr( "Rule-based Labeling" ) ); + connect( mLabelModeComboBox, static_cast( &QComboBox::currentIndexChanged ), this, &QgsVectorTileBasicLabelingWidget::labelModeChanged ); + connect( viewStyles, &QAbstractItemView::doubleClicked, this, &QgsVectorTileBasicLabelingWidget::editStyleAtIndex ); if ( mMapCanvas ) @@ -374,16 +379,25 @@ QgsVectorTileBasicLabelingWidget::QgsVectorTileBasicLabelingWidget( QgsVectorTil void QgsVectorTileBasicLabelingWidget::setLayer( QgsVectorTileLayer *layer ) { + if ( mVTLayer ) + { + disconnect( mVTLayer ); + } + mVTLayer = layer; + connect( mVTLayer, &QgsMapLayer::styleChanged, this, [ = ]() { setLayer( mVTLayer ); } ); if ( layer && layer->labeling() && layer->labeling()->type() == QLatin1String( "basic" ) ) { mLabeling.reset( static_cast( layer->labeling()->clone() ) ); + whileBlocking( mLabelModeComboBox )->setCurrentIndex( layer->labelsEnabled() ? 1 : 0 ); } else { mLabeling.reset( new QgsVectorTileBasicLabeling() ); + whileBlocking( mLabelModeComboBox )->setCurrentIndex( 1 ); } + mOptionsStackedWidget->setCurrentIndex( mLabelModeComboBox->currentIndex() ); mModel = new QgsVectorTileBasicLabelingListModel( mLabeling.get(), viewStyles ); mProxyModel = new QgsVectorTileBasicLabelingProxyModel( mModel, viewStyles ); @@ -411,6 +425,13 @@ QgsVectorTileBasicLabelingWidget::~QgsVectorTileBasicLabelingWidget() = default; void QgsVectorTileBasicLabelingWidget::apply() { mVTLayer->setLabeling( mLabeling->clone() ); + mVTLayer->setLabelsEnabled( mLabelModeComboBox->currentIndex() == 1 ); +} + +void QgsVectorTileBasicLabelingWidget::labelModeChanged() +{ + mOptionsStackedWidget->setCurrentIndex( mLabelModeComboBox->currentIndex() ); + emit widgetChanged(); } void QgsVectorTileBasicLabelingWidget::addStyle( Qgis::GeometryType geomType ) diff --git a/src/gui/vectortile/qgsvectortilebasiclabelingwidget.h b/src/gui/vectortile/qgsvectortilebasiclabelingwidget.h index ab3e3b73568..b979fb38d0f 100644 --- a/src/gui/vectortile/qgsvectortilebasiclabelingwidget.h +++ b/src/gui/vectortile/qgsvectortilebasiclabelingwidget.h @@ -59,6 +59,7 @@ class GUI_EXPORT QgsVectorTileBasicLabelingWidget : public QgsMapLayerConfigWidg void editStyleAtIndex( const QModelIndex &index ); void removeStyle(); + void labelModeChanged(); void updateLabelingFromWidget(); private: diff --git a/src/ui/qgsvectortilebasiclabelingwidget.ui b/src/ui/qgsvectortilebasiclabelingwidget.ui index 68209bcb733..b53f3f7e28b 100644 --- a/src/ui/qgsvectortilebasiclabelingwidget.ui +++ b/src/ui/qgsvectortilebasiclabelingwidget.ui @@ -12,115 +12,152 @@ - - - 0 - - - - - - - - Hides any rules which are invisible because they fall outside the current map canvas zoom level - - - Visible rules only - - - - - - - - - true - - - QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked - - - true - - - QAbstractItemView::InternalMove - - - QAbstractItemView::ExtendedSelection - - - false + + + + 0 + 0 + - - - - - - Add rule + + + + 0 + + + 0 + + + + + + 0 - - + + 0 - - - :/images/themes/default/symbologyAdd.svg:/images/themes/default/symbologyAdd.svg + + 0 - - QToolButton::InstantPopup + + 0 - - - - - - Remove selected rules - - - - - - - :/images/themes/default/symbologyRemove.svg:/images/themes/default/symbologyRemove.svg - - - - - - - Edit current rule - - - - - - - :/images/themes/default/symbologyEdit.svg:/images/themes/default/symbologyEdit.svg - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - + + + + 0 + + + + + + + + Hides any rules which are invisible because they fall outside the current map canvas zoom level + + + Visible rules only + + + + + + + + + true + + + QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked + + + true + + + QAbstractItemView::InternalMove + + + QAbstractItemView::ExtendedSelection + + + false + + + + + + + + + Add rule + + + + + + + :/images/themes/default/symbologyAdd.svg:/images/themes/default/symbologyAdd.svg + + + QToolButton::InstantPopup + + + + + + + Remove selected rules + + + + + + + :/images/themes/default/symbologyRemove.svg:/images/themes/default/symbologyRemove.svg + + + + + + + Edit current rule + + + + + + + :/images/themes/default/symbologyEdit.svg:/images/themes/default/symbologyEdit.svg + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + @@ -138,6 +175,7 @@ btnAddRule btnRemoveRule btnEditRule + mCheckLabelsEnabled