Skip to content

Commit

Permalink
Merge pull request #35815 from alexbruy/ds-vectortiles
Browse files Browse the repository at this point in the history
Add vector tiles to Datasource manager dialog and Layers menu
  • Loading branch information
alexbruy committed Apr 17, 2020
2 parents a5eb38b + 6b17585 commit e9dd602
Show file tree
Hide file tree
Showing 31 changed files with 552 additions and 231 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -231,6 +231,7 @@
<file>themes/default/mActionAddWfsLayer.svg</file>
<file>themes/default/mActionAddWmsLayer.svg</file>
<file>themes/default/mActionAddXyzLayer.svg</file>
<file>themes/default/mActionAddVectorTileLayer.svg</file>
<file>themes/default/mActionAddGeonodeLayer.svg</file>
<file>themes/default/mActionAddDelimitedTextLayer.svg</file>
<file>themes/default/mActionAddVirtualLayer.svg</file>
Expand Down
1 change: 1 addition & 0 deletions images/themes/default/mActionAddVectorTileLayer.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
196 changes: 1 addition & 195 deletions images/themes/default/mIconVectorTileLayer.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion python/gui/auto_generated/qgisinterface.sip.in
Expand Up @@ -542,7 +542,14 @@ Returns the native draw action.

virtual QAction *actionAddXyzLayer() = 0;
%Docstring
Returns the native Add XYZ layer action.
Returns the native Add XYZ Layer action.

.. versionadded:: 3.14
%End

virtual QAction *actionAddVectorTileLayer() = 0;
%Docstring
Returns the native Add Vector Tile Layer action.

.. versionadded:: 3.14
%End
Expand Down Expand Up @@ -767,6 +774,13 @@ Adds a raster layer to the current project, from the specified raster data provi
virtual QgsMeshLayer *addMeshLayer( const QString &url, const QString &baseName, const QString &providerKey ) = 0;
%Docstring
Adds a mesh layer to the current project.
%End

virtual QgsVectorTileLayer *addVectorTileLayer( const QString &url, const QString &baseName ) = 0;
%Docstring
Adds a vector tile layer to the current project.

.. versionadded:: 3.14
%End

virtual bool addProject( const QString &project ) = 0;
Expand Down
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgsabstractdatasourcewidget.sip.in
Expand Up @@ -92,6 +92,13 @@ will be used.
Emitted when a mesh layer has been selected for addition.

.. versionadded:: 3.4
%End

void addVectorTileLayer( const QString &url, const QString &baseName );
%Docstring
Emitted when a vector tile layer has been selected for addition.

.. versionadded:: 3.14
%End

void addVectorLayers( const QStringList &layerList, const QString &encoding, const QString &dataSourceType );
Expand Down
3 changes: 2 additions & 1 deletion python/gui/auto_generated/qgsmanageconnectionsdialog.sip.in
Expand Up @@ -34,7 +34,8 @@ class QgsManageConnectionsDialog : QDialog
GeoNode,
XyzTiles,
ArcgisMapServer,
ArcgisFeatureServer
ArcgisFeatureServer,
VectorTile
};

QgsManageConnectionsDialog( QWidget *parent /TransferThis/ = 0, Mode mode = Export, Type type = WMS, const QString &fileName = QString() );
Expand Down
44 changes: 43 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -2323,6 +2323,7 @@ void QgisApp::dataSourceManager( const QString &pageName )
connect( mDataSourceManagerDialog, SIGNAL( addVectorLayers( QStringList const &, QString const &, QString const & ) ),
this, SLOT( addVectorLayers( QStringList const &, QString const &, QString const & ) ) );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::addMeshLayer, this, &QgisApp::addMeshLayer );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::addVectorTileLayer, this, &QgisApp::addVectorTileLayer );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::showStatusMessage, this, &QgisApp::showStatusMessage );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::addDatabaseLayers, this, &QgisApp::addDatabaseLayers );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::replaceSelectedVectorLayer, this, &QgisApp::replaceSelectedVectorLayer );
Expand Down Expand Up @@ -2662,6 +2663,7 @@ void QgisApp::createActions()
connect( mActionAddOracleLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "oracle" ) ); } );
connect( mActionAddWmsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "wms" ) ); } );
connect( mActionAddXyzLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "xyz" ) ); } );
connect( mActionAddVectorTileLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "vectortile" ) ); } );
connect( mActionAddWcsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "wcs" ) ); } );
connect( mActionAddWfsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "WFS" ) ); } );
connect( mActionAddAfsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "arcgisfeatureserver" ) ); } );
Expand Down Expand Up @@ -3971,6 +3973,7 @@ void QgisApp::setTheme( const QString &themeName )
mActionCustomProjection->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionCustomProjection.svg" ) ) );
mActionAddWmsLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddWmsLayer.svg" ) ) );
mActionAddXyzLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddXyzLayer.svg" ) ) );
mActionAddVectorTileLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddVectorTileLayer.svg" ) ) );
mActionAddWcsLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddWcsLayer.svg" ) ) );
mActionAddWfsLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddWfsLayer.svg" ) ) );
mActionAddAfsLayer->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddAfsLayer.svg" ) ) );
Expand Down Expand Up @@ -5458,7 +5461,6 @@ bool QgisApp::addVectorLayersPrivate( const QStringList &layerQStringList, const
return true;
}


QgsMeshLayer *QgisApp::addMeshLayer( const QString &url, const QString &baseName, const QString &providerKey )
{
return addMeshLayerPrivate( url, baseName, providerKey );
Expand Down Expand Up @@ -5538,6 +5540,46 @@ QgsMeshLayer *QgisApp::addMeshLayerPrivate( const QString &url, const QString &b
return layer.release();
}

QgsVectorTileLayer *QgisApp::addVectorTileLayer( const QString &url, const QString &baseName )
{
return addVectorTileLayerPrivate( url, baseName );
}

QgsVectorTileLayer *QgisApp::addVectorTileLayerPrivate( const QString &url, const QString &baseName, const bool guiWarning )
{
QgsCanvasRefreshBlocker refreshBlocker;
QgsSettings settings;

QString base( baseName );

if ( settings.value( QStringLiteral( "qgis/formatLayerName" ), false ).toBool() )
{
base = QgsMapLayer::formatLayerName( base );
}

QgsDebugMsgLevel( "completeBaseName: " + base, 2 );

// create the layer
std::unique_ptr<QgsVectorTileLayer> layer( new QgsVectorTileLayer( url, base ) );

if ( !layer || !layer->isValid() )
{
if ( guiWarning )
{
QString msg = tr( "%1 is not a valid or recognized data source." ).arg( url );
visibleMessageBar()->pushMessage( tr( "Invalid Data Source" ), msg, Qgis::Critical, messageTimeout() );
}

// since the layer is bad, stomp on it
return nullptr;
}

QgsProject::instance()->addMapLayer( layer.get() );
activateDeactivateLayerRelatedActions( activeLayer() );

return layer.release();
}

// present a dialog to choose zipitem layers
bool QgisApp::askUserForZipItemLayers( const QString &path )
{
Expand Down

0 comments on commit e9dd602

Please sign in to comment.