Skip to content

Commit

Permalink
Vector tiles: styling panel integration + widget for basic renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Apr 7, 2020
1 parent 550cb5d commit f713cc3
Show file tree
Hide file tree
Showing 12 changed files with 660 additions and 12 deletions.
Expand Up @@ -172,6 +172,14 @@ Sets list of styles of the renderer
QList<QgsVectorTileBasicRendererStyle> styles() const;
%Docstring
Returns list of styles of the renderer
%End
void setStyle( int index, const QgsVectorTileBasicRendererStyle &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
QgsVectorTileBasicRendererStyle style( int index ) const;
%Docstring
Returns style definition at the particular index
%End

static QList<QgsVectorTileBasicRendererStyle> simpleStyle(
Expand Down
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -430,6 +430,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/gui/layertree
${CMAKE_SOURCE_DIR}/src/gui/locator
${CMAKE_SOURCE_DIR}/src/gui/vector
${CMAKE_SOURCE_DIR}/src/gui/vectortile
${CMAKE_SOURCE_DIR}/src/plugins
${CMAKE_SOURCE_DIR}/src/python
${CMAKE_SOURCE_DIR}/src/native
Expand Down
23 changes: 21 additions & 2 deletions src/app/qgslayerstylingwidget.cpp
Expand Up @@ -35,6 +35,8 @@
#include "qgsmaplayer.h"
#include "qgsstyle.h"
#include "qgsvectorlayer.h"
#include "qgsvectortilelayer.h"
#include "qgsvectortilebasicrendererwidget.h"
#include "qgsmeshlayer.h"
#include "qgsproject.h"
#include "qgsundowidget.h"
Expand Down Expand Up @@ -227,7 +229,11 @@ void QgsLayerStylingWidget::setLayer( QgsMapLayer *layer )

case QgsMapLayerType::VectorTileLayer:
{
// TODO
QListWidgetItem *symbolItem = new QListWidgetItem( QgsApplication::getThemeIcon( QStringLiteral( "propertyicons/symbology.svg" ) ), QString() );
symbolItem->setData( Qt::UserRole, Symbology );
symbolItem->setToolTip( tr( "Symbology" ) );
mOptionsListWidget->addItem( symbolItem );

break;
}

Expand Down Expand Up @@ -608,7 +614,20 @@ void QgsLayerStylingWidget::updateCurrentWidgetLayer()

case QgsMapLayerType::VectorTileLayer:
{
// TODO
QgsVectorTileLayer *vtLayer = qobject_cast<QgsVectorTileLayer *>( mCurrentLayer );
switch ( row )
{
case 0: // Style
{
mVectorTileStyleWidget = new QgsVectorTileBasicRendererWidget( vtLayer, mMapCanvas, mMessageBar, mWidgetStack );
mVectorTileStyleWidget->setDockMode( true );
connect( mVectorTileStyleWidget, &QgsPanelWidget::widgetChanged, this, &QgsLayerStylingWidget::autoApply );
mWidgetStack->setMainPanel( mVectorTileStyleWidget );
break;
}
default:
break;
}
break;
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/qgslayerstylingwidget.h
Expand Up @@ -44,6 +44,7 @@ class QgsMapLayerStyleManagerWidget;
class QgsVectorLayer3DRendererWidget;
class QgsMeshLayer3DRendererWidget;
class QgsMessageBar;
class QgsVectorTileBasicRendererWidget;

class APP_EXPORT QgsLayerStyleManagerWidgetFactory : public QgsMapLayerConfigWidgetFactory
{
Expand Down Expand Up @@ -149,6 +150,7 @@ class APP_EXPORT QgsLayerStylingWidget : public QWidget, private Ui::QgsLayerSty
#endif
QgsRendererRasterPropertiesWidget *mRasterStyleWidget = nullptr;
QgsRendererMeshPropertiesWidget *mMeshStyleWidget = nullptr;
QgsVectorTileBasicRendererWidget *mVectorTileStyleWidget = nullptr;
QList<QgsMapLayerConfigWidgetFactory *> mPageFactories;
QMap<int, QgsMapLayerConfigWidgetFactory *> mUserPages;
QgsLayerStyleManagerWidgetFactory *mStyleManagerFactory = nullptr;
Expand Down
3 changes: 2 additions & 1 deletion src/core/vectortile/qgsvectortilebasicrenderer.cpp
Expand Up @@ -89,7 +89,7 @@ void QgsVectorTileBasicRendererStyle::readXml( const QDomElement &elem, const Qg
if ( !symbolsElem.isNull() )
{
QgsSymbolMap symbolMap = QgsSymbolLayerUtils::loadSymbols( symbolsElem, context );
if ( !symbolMap.contains( QStringLiteral( "0" ) ) )
if ( symbolMap.contains( QStringLiteral( "0" ) ) )
{
mSymbol.reset( symbolMap.take( QStringLiteral( "0" ) ) );
}
Expand Down Expand Up @@ -219,6 +219,7 @@ void QgsVectorTileBasicRenderer::readXml( const QDomElement &elem, const QgsRead
QgsVectorTileBasicRendererStyle layerStyle;
layerStyle.readXml( elemStyle, context );
mStyles.append( layerStyle );
elemStyle = elemStyle.nextSiblingElement( QStringLiteral( "style" ) );
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/vectortile/qgsvectortilebasicrenderer.h
Expand Up @@ -142,6 +142,10 @@ class CORE_EXPORT QgsVectorTileBasicRenderer : public QgsVectorTileRenderer
void setStyles( const QList<QgsVectorTileBasicRendererStyle> &styles );
//! Returns list of styles of the renderer
QList<QgsVectorTileBasicRendererStyle> styles() const;
//! 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 QgsVectorTileBasicRendererStyle &style ) { mStyles[index] = style; }
//! Returns style definition at the particular index
QgsVectorTileBasicRendererStyle style( int index ) const { return mStyles[index]; }

//! Returns a list of styles to render all layers with the given fill/stroke colors, stroke widths and marker sizes
static QList<QgsVectorTileBasicRendererStyle> simpleStyle(
Expand Down
26 changes: 17 additions & 9 deletions src/core/vectortile/qgsvectortilelayer.cpp
Expand Up @@ -29,8 +29,18 @@ QgsVectorTileLayer::QgsVectorTileLayer( const QString &uri, const QString &baseN
{
mDataSource = uri;

mValid = loadDataSource();

// set a default renderer
QgsVectorTileBasicRenderer *renderer = new QgsVectorTileBasicRenderer;
renderer->setStyles( QgsVectorTileBasicRenderer::simpleStyleWithRandomColors() );
setRenderer( renderer );
}

bool QgsVectorTileLayer::loadDataSource()
{
QgsDataSourceUri dsUri;
dsUri.setEncodedUri( uri );
dsUri.setEncodedUri( mDataSource );

mSourceType = dsUri.param( QStringLiteral( "type" ) );
mSourcePath = dsUri.param( QStringLiteral( "url" ) );
Expand All @@ -53,7 +63,7 @@ QgsVectorTileLayer::QgsVectorTileLayer( const QString &uri, const QString &baseN
if ( !reader.open() )
{
QgsDebugMsg( QStringLiteral( "failed to open MBTiles file: " ) + mSourcePath );
return;
return false;
}

QgsDebugMsgLevel( QStringLiteral( "name: " ) + reader.metadataValue( QStringLiteral( "name" ) ), 2 );
Expand All @@ -75,16 +85,11 @@ QgsVectorTileLayer::QgsVectorTileLayer( const QString &uri, const QString &baseN
else
{
QgsDebugMsg( QStringLiteral( "Unknown source type: " ) + mSourceType );
return;
return false;
}

setCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3857" ) ) );
setValid( true );

// set a default renderer
QgsVectorTileBasicRenderer *renderer = new QgsVectorTileBasicRenderer;
renderer->setStyles( QgsVectorTileBasicRenderer::simpleStyleWithRandomColors() );
setRenderer( renderer );
return true;
}

QgsVectorTileLayer::~QgsVectorTileLayer() = default;
Expand All @@ -104,6 +109,8 @@ QgsMapLayerRenderer *QgsVectorTileLayer::createMapRenderer( QgsRenderContext &re

bool QgsVectorTileLayer::readXml( const QDomNode &layerNode, QgsReadWriteContext &context )
{
mValid = loadDataSource();

QString errorMsg;
return readSymbology( layerNode, errorMsg, context );
}
Expand Down Expand Up @@ -140,6 +147,7 @@ bool QgsVectorTileLayer::readSymbology( const QDomNode &node, QString &errorMess
}

r->readXml( elemRenderer, context );
setRenderer( r );
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/core/vectortile/qgsvectortilelayer.h
Expand Up @@ -137,6 +137,9 @@ class CORE_EXPORT QgsVectorTileLayer : public QgsMapLayer
//! Returns whether to render also borders of tiles (useful for debugging)
bool isTileBorderRenderingEnabled() const { return mTileBorderRendering; }

private:
bool loadDataSource();

private:
//! Type of the data source
QString mSourceType;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -321,6 +321,7 @@ SET(QGIS_GUI_SRCS
tableeditor/qgstableeditorformattingwidget.cpp
tableeditor/qgstableeditorwidget.cpp

vectortile/qgsvectortilebasicrendererwidget.cpp
vectortile/qgsvectortileconnectiondialog.cpp
vectortile/qgsvectortiledataitemguiprovider.cpp
vectortile/qgsvectortileproviderguimetadata.cpp
Expand Down Expand Up @@ -1091,6 +1092,7 @@ SET(QGIS_GUI_HDRS
tableeditor/qgstableeditorformattingwidget.h
tableeditor/qgstableeditorwidget.h

vectortile/qgsvectortilebasicrendererwidget.h
vectortile/qgsvectortileconnectiondialog.h
vectortile/qgsvectortiledataitemguiprovider.h
vectortile/qgsvectortileproviderguimetadata.h
Expand Down

0 comments on commit f713cc3

Please sign in to comment.