Skip to content

Commit

Permalink
[vector tile] Add basic GUI support for labeling configuration
Browse files Browse the repository at this point in the history
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 14, 2020
1 parent 2b1107a commit 5d59048
Show file tree
Hide file tree
Showing 9 changed files with 701 additions and 3 deletions.
Expand Up @@ -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

};
Expand Down
14 changes: 13 additions & 1 deletion src/app/qgslayerstylingwidget.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgslayerstylingwidget.h
Expand Up @@ -45,6 +45,7 @@ class QgsVectorLayer3DRendererWidget;
class QgsMeshLayer3DRendererWidget;
class QgsMessageBar;
class QgsVectorTileBasicRendererWidget;
class QgsVectorTileBasicLabelingWidget;

class APP_EXPORT QgsLayerStyleManagerWidgetFactory : public QgsMapLayerConfigWidgetFactory
{
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 12 additions & 2 deletions src/core/vectortile/qgsvectortilebasiclabeling.cpp
Expand Up @@ -16,6 +16,7 @@
#include "qgsvectortilebasiclabeling.h"

#include "qgsexpressioncontextutils.h"
#include "qgslogger.h"
#include "qgsvectortilelayer.h"
#include "qgsvectortilerenderer.h"
#include "qgsvectortileutils.h"
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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() )
{
Expand Down
4 changes: 4 additions & 0 deletions src/core/vectortile/qgsvectortilebasiclabeling.h
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5d59048

Please sign in to comment.