mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-07 00:03:52 -05:00
[ui] Allow toggling of vector tile labels in the layer tree right-click menu and style panel
This commit is contained in:
parent
1f1d1f981c
commit
951d7e3307
@ -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,8 +1338,9 @@ void QgsAppLayerTreeViewMenuProvider::toggleLabels( bool enabled )
|
||||
const QList<QgsLayerTreeLayer *> selectedLayerNodes = mView->selectedLayerNodes();
|
||||
for ( QgsLayerTreeLayer *l : selectedLayerNodes )
|
||||
{
|
||||
QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( l->layer() );
|
||||
if ( !vlayer || !vlayer->isSpatial() )
|
||||
if ( QgsVectorLayer *vlayer = qobject_cast< QgsVectorLayer * >( l->layer() ) )
|
||||
{
|
||||
if ( !vlayer->isSpatial() )
|
||||
continue;
|
||||
|
||||
if ( enabled && !vlayer->labeling() )
|
||||
@ -1353,4 +1357,11 @@ void QgsAppLayerTreeViewMenuProvider::toggleLabels( bool enabled )
|
||||
vlayer->emitStyleChanged();
|
||||
vlayer->triggerRepaint();
|
||||
}
|
||||
else if ( QgsVectorTileLayer *vectorTilelayer = qobject_cast< QgsVectorTileLayer * >( l->layer() ) )
|
||||
{
|
||||
vectorTilelayer->setLabelsEnabled( enabled );
|
||||
vectorTilelayer->emitStyleChanged();
|
||||
vectorTilelayer->triggerRepaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<void ( QComboBox::* )( int )>( &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<QgsVectorTileBasicLabeling *>( 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 )
|
||||
|
||||
@ -59,6 +59,7 @@ class GUI_EXPORT QgsVectorTileBasicLabelingWidget : public QgsMapLayerConfigWidg
|
||||
void editStyleAtIndex( const QModelIndex &index );
|
||||
void removeStyle();
|
||||
|
||||
void labelModeChanged();
|
||||
void updateLabelingFromWidget();
|
||||
|
||||
private:
|
||||
|
||||
@ -11,6 +11,39 @@
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QComboBox" name="mLabelModeComboBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QStackedWidget" name="mOptionsStackedWidget">
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="mNoLabelPage"/>
|
||||
<widget class="QWidget" name="mRuleBasedLabelPage">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_1">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="bottomMargin">
|
||||
@ -124,6 +157,10 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QgsFilterLineEdit</class>
|
||||
@ -138,6 +175,7 @@
|
||||
<tabstop>btnAddRule</tabstop>
|
||||
<tabstop>btnRemoveRule</tabstop>
|
||||
<tabstop>btnEditRule</tabstop>
|
||||
<tabstop>mCheckLabelsEnabled</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../images/images.qrc"/>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user