Skip to content
Permalink
Browse files

[vector tile] Add basic GUI support for labeling configuration

This adds a new tab in the layer styling dock widget for vector tile layers.

The new QgsVectorTileBasicLabelingWidget class is based on the code used for QgsVectorTileBasicRendererWidget
  • Loading branch information
wonder-sk committed May 13, 2020
1 parent 2b1107a commit 5d59048387ac2a8b5dfdb003c44f215f2c0e2dcf
@@ -145,6 +145,14 @@ Sets list of styles of the renderer
QList<QgsVectorTileBasicLabelingStyle> styles() const;
%Docstring
Returns list of styles of the renderer
%End
void setStyle( int index, const QgsVectorTileBasicLabelingStyle &style );
%Docstring
Updates style definition at the paricular index of the list (the index must be in interval [0,N-1] otherwise this function does nothing)
%End
QgsVectorTileBasicLabelingStyle style( int index ) const;
%Docstring
Returns style definition at the particular index
%End

};
@@ -36,6 +36,7 @@
#include "qgsstyle.h"
#include "qgsvectorlayer.h"
#include "qgsvectortilelayer.h"
#include "qgsvectortilebasiclabelingwidget.h"
#include "qgsvectortilebasicrendererwidget.h"
#include "qgsmeshlayer.h"
#include "qgsproject.h"
@@ -233,7 +234,10 @@ void QgsLayerStylingWidget::setLayer( QgsMapLayer *layer )
symbolItem->setData( Qt::UserRole, Symbology );
symbolItem->setToolTip( tr( "Symbology" ) );
mOptionsListWidget->addItem( symbolItem );

QListWidgetItem *labelItem = new QListWidgetItem( QgsApplication::getThemeIcon( QStringLiteral( "labelingSingle.svg" ) ), QString() );
labelItem->setData( Qt::UserRole, VectorLabeling );
labelItem->setToolTip( tr( "Labels" ) );
mOptionsListWidget->addItem( labelItem );
break;
}

@@ -626,6 +630,14 @@ void QgsLayerStylingWidget::updateCurrentWidgetLayer()
mWidgetStack->setMainPanel( mVectorTileStyleWidget );
break;
}
case 1: // Labeling
{
mVectorTileLabelingWidget = new QgsVectorTileBasicLabelingWidget( vtLayer, mMapCanvas, mMessageBar, mWidgetStack );
mVectorTileLabelingWidget->setDockMode( true );
connect( mVectorTileLabelingWidget, &QgsPanelWidget::widgetChanged, this, &QgsLayerStylingWidget::autoApply );
mWidgetStack->setMainPanel( mVectorTileLabelingWidget );
break;
}
default:
break;
}
@@ -45,6 +45,7 @@ class QgsVectorLayer3DRendererWidget;
class QgsMeshLayer3DRendererWidget;
class QgsMessageBar;
class QgsVectorTileBasicRendererWidget;
class QgsVectorTileBasicLabelingWidget;

class APP_EXPORT QgsLayerStyleManagerWidgetFactory : public QgsMapLayerConfigWidgetFactory
{
@@ -151,6 +152,7 @@ class APP_EXPORT QgsLayerStylingWidget : public QWidget, private Ui::QgsLayerSty
QgsRendererRasterPropertiesWidget *mRasterStyleWidget = nullptr;
QgsRendererMeshPropertiesWidget *mMeshStyleWidget = nullptr;
QgsVectorTileBasicRendererWidget *mVectorTileStyleWidget = nullptr;
QgsVectorTileBasicLabelingWidget *mVectorTileLabelingWidget = nullptr;
QList<QgsMapLayerConfigWidgetFactory *> mPageFactories;
QMap<int, QgsMapLayerConfigWidgetFactory *> mUserPages;
QgsLayerStyleManagerWidgetFactory *mStyleManagerFactory = nullptr;
@@ -16,6 +16,7 @@
#include "qgsvectortilebasiclabeling.h"

#include "qgsexpressioncontextutils.h"
#include "qgslogger.h"
#include "qgsvectortilelayer.h"
#include "qgsvectortilerenderer.h"
#include "qgsvectortileutils.h"
@@ -151,7 +152,10 @@ QList<QgsAbstractLabelProvider *> QgsVectorTileBasicLabelProvider::subProviders(
{
QList<QgsAbstractLabelProvider *> lst;
for ( QgsVectorLayerLabelProvider *subprovider : qgis::as_const( mSubProviders ) )
lst << subprovider;
{
if ( subprovider ) // sub-providers that failed to initialize are set to null
lst << subprovider;
}
return lst;
}

@@ -170,7 +174,11 @@ bool QgsVectorTileBasicLabelProvider::prepare( QgsRenderContext &context, QSet<Q
QgsExpressionContextScopePopper popper( context.expressionContext(), scope );

mSubProviders[i]->setFields( fields );
mSubProviders[i]->prepare( context, attributeNames );
if ( !mSubProviders[i]->prepare( context, attributeNames ) )
{
QgsDebugMsg( QStringLiteral( "Failed to prepare labeling for style index" ) + QString::number( i ) );
mSubProviders[i] = nullptr;
}
}
return true;
}
@@ -196,6 +204,8 @@ void QgsVectorTileBasicLabelProvider::registerTileFeatures( const QgsVectorTileR
filterExpression.prepare( &context.expressionContext() );

QgsVectorLayerLabelProvider *subProvider = mSubProviders[i];
if ( !subProvider )
continue; // sub-providers that failed to initialize are set to null

if ( layerStyle.layerName().isEmpty() )
{
@@ -119,6 +119,10 @@ class CORE_EXPORT QgsVectorTileBasicLabeling : public QgsVectorTileLabeling
void setStyles( const QList<QgsVectorTileBasicLabelingStyle> &styles ) { mStyles = styles; }
//! Returns list of styles of the renderer
QList<QgsVectorTileBasicLabelingStyle> styles() const { return mStyles; }
//! Updates style definition at the paricular index of the list (the index must be in interval [0,N-1] otherwise this function does nothing)
void setStyle( int index, const QgsVectorTileBasicLabelingStyle &style ) { mStyles[index] = style; }
//! Returns style definition at the particular index
QgsVectorTileBasicLabelingStyle style( int index ) const { return mStyles[index]; }

private:
//! List of rendering styles
@@ -323,6 +323,7 @@ SET(QGIS_GUI_SRCS
tableeditor/qgstableeditorformattingwidget.cpp
tableeditor/qgstableeditorwidget.cpp

vectortile/qgsvectortilebasiclabelingwidget.cpp
vectortile/qgsvectortilebasicrendererwidget.cpp
vectortile/qgsvectortileconnectiondialog.cpp
vectortile/qgsvectortiledataitemguiprovider.cpp
@@ -1107,6 +1108,7 @@ SET(QGIS_GUI_HDRS
tableeditor/qgstableeditorformattingwidget.h
tableeditor/qgstableeditorwidget.h

vectortile/qgsvectortilebasiclabelingwidget.h
vectortile/qgsvectortilebasicrendererwidget.h
vectortile/qgsvectortileconnectiondialog.h
vectortile/qgsvectortiledataitemguiprovider.h

0 comments on commit 5d59048

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