Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vector tiles browser integration (+gui to add/edit connections)
- Loading branch information
Showing
18 changed files
with
866 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/*************************************************************************** | ||
qgsvectortileconnection.cpp | ||
--------------------- | ||
begin : March 2020 | ||
copyright : (C) 2020 by Martin Dobias | ||
email : wonder dot sk at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsvectortileconnection.h" | ||
|
||
#include "qgslogger.h" | ||
#include "qgsdatasourceuri.h" | ||
#include "qgssettings.h" | ||
|
||
///@cond PRIVATE | ||
|
||
QString QgsVectorTileConnection::encodedUri() const | ||
{ | ||
QgsDataSourceUri uri; | ||
uri.setParam( QStringLiteral( "type" ), QStringLiteral( "xyz" ) ); | ||
uri.setParam( QStringLiteral( "url" ), url ); | ||
if ( zMin != -1 ) | ||
uri.setParam( QStringLiteral( "zmin" ), QString::number( zMin ) ); | ||
if ( zMax != -1 ) | ||
uri.setParam( QStringLiteral( "zmax" ), QString::number( zMax ) ); | ||
return uri.encodedUri(); | ||
} | ||
|
||
QStringList QgsVectorTileConnectionUtils::connectionList() | ||
{ | ||
QgsSettings settings; | ||
settings.beginGroup( QStringLiteral( "qgis/connections-vector-tile" ) ); | ||
QStringList connList = settings.childGroups(); | ||
|
||
return connList; | ||
} | ||
|
||
QgsVectorTileConnection QgsVectorTileConnectionUtils::connection( const QString &name ) | ||
{ | ||
QgsSettings settings; | ||
settings.beginGroup( "qgis/connections-vector-tile/" + name ); | ||
|
||
QgsVectorTileConnection conn; | ||
conn.name = name; | ||
conn.url = settings.value( QStringLiteral( "url" ) ).toString(); | ||
conn.zMin = settings.value( QStringLiteral( "zmin" ), -1 ).toInt(); | ||
conn.zMax = settings.value( QStringLiteral( "zmax" ), -1 ).toInt(); | ||
return conn; | ||
} | ||
|
||
void QgsVectorTileConnectionUtils::deleteConnection( const QString &name ) | ||
{ | ||
QgsSettings settings; | ||
settings.remove( "qgis/connections-vector-tile/" + name ); | ||
} | ||
|
||
void QgsVectorTileConnectionUtils::addConnection( const QgsVectorTileConnection &conn ) | ||
{ | ||
QgsSettings settings; | ||
|
||
settings.beginGroup( "qgis/connections-vector-tile/" + conn.name ); | ||
settings.setValue( QStringLiteral( "url" ), conn.url ); | ||
settings.setValue( QStringLiteral( "zmin" ), conn.zMin ); | ||
settings.setValue( QStringLiteral( "zmax" ), conn.zMax ); | ||
} | ||
|
||
///@endcond |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*************************************************************************** | ||
qgsvectortileconnection.h | ||
--------------------- | ||
begin : March 2020 | ||
copyright : (C) 2020 by Martin Dobias | ||
email : wonder dot sk at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSVECTORTILECONNECTION_H | ||
#define QGSVECTORTILECONNECTION_H | ||
|
||
#include "qgis_core.h" | ||
|
||
///@cond PRIVATE | ||
#define SIP_NO_FILE | ||
|
||
#include <QStringList> | ||
|
||
struct QgsVectorTileConnection | ||
{ | ||
QString name; | ||
QString url; | ||
int zMin = -1; | ||
int zMax = -1; | ||
|
||
QString encodedUri() const; | ||
}; | ||
|
||
//! Utility class for handling list of connections to vector tile layers | ||
class CORE_EXPORT QgsVectorTileConnectionUtils | ||
{ | ||
public: | ||
//! Returns list of existing connections, unless the hidden ones | ||
static QStringList connectionList(); | ||
|
||
//! Returns connection details | ||
static QgsVectorTileConnection connection( const QString &name ); | ||
|
||
//! Removes a connection from the list | ||
static void deleteConnection( const QString &name ); | ||
|
||
//! Adds a new connection to the list | ||
static void addConnection( const QgsVectorTileConnection &conn ); | ||
}; | ||
|
||
///@endcond | ||
|
||
#endif // QGSVECTORTILECONNECTION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*************************************************************************** | ||
qgsvectortiledataitems.cpp | ||
--------------------- | ||
begin : March 2020 | ||
copyright : (C) 2020 by Martin Dobias | ||
email : wonder dot sk at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#include "qgsvectortiledataitems.h" | ||
|
||
#include "qgssettings.h" | ||
#include "qgsvectortileconnection.h" | ||
|
||
///@cond PRIVATE | ||
|
||
QgsVectorTileRootItem::QgsVectorTileRootItem( QgsDataItem *parent, QString name, QString path ) | ||
: QgsDataCollectionItem( parent, name, path, QStringLiteral( "vectortile" ) ) | ||
{ | ||
mCapabilities |= Fast; | ||
mIconName = QStringLiteral( "mIconWms.svg" ); | ||
populate(); | ||
} | ||
|
||
QVector<QgsDataItem *> QgsVectorTileRootItem::createChildren() | ||
{ | ||
QVector<QgsDataItem *> connections; | ||
const auto connectionList = QgsVectorTileConnectionUtils::connectionList(); | ||
for ( const QString &connName : connectionList ) | ||
{ | ||
QgsVectorTileConnection connection( QgsVectorTileConnectionUtils::connection( connName ) ); | ||
QgsDataItem *conn = new QgsVectorTileLayerItem( this, connName, mPath + '/' + connName, connection.encodedUri() ); | ||
connections.append( conn ); | ||
} | ||
return connections; | ||
} | ||
|
||
|
||
// --------------------------------------------------------------------------- | ||
|
||
|
||
QgsVectorTileLayerItem::QgsVectorTileLayerItem( QgsDataItem *parent, QString name, QString path, const QString &encodedUri ) | ||
: QgsLayerItem( parent, name, path, encodedUri, QgsLayerItem::VectorTile, QString() ) | ||
{ | ||
setState( Populated ); | ||
} | ||
|
||
|
||
// --------------------------------------------------------------------------- | ||
|
||
QString QgsVectorTileDataItemProvider::name() | ||
{ | ||
return QStringLiteral( "Vector Tiles" ); | ||
} | ||
|
||
QString QgsVectorTileDataItemProvider::dataProviderKey() const | ||
{ | ||
return QStringLiteral( "vectortile" ); | ||
} | ||
|
||
int QgsVectorTileDataItemProvider::capabilities() const | ||
{ | ||
return QgsDataProvider::Net; | ||
} | ||
|
||
QgsDataItem *QgsVectorTileDataItemProvider::createDataItem( const QString &path, QgsDataItem *parentItem ) | ||
{ | ||
if ( path.isEmpty() ) | ||
return new QgsVectorTileRootItem( parentItem, QStringLiteral( "Vector Tiles" ), QStringLiteral( "vectortile:" ) ); | ||
return nullptr; | ||
} | ||
|
||
///@endcond |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*************************************************************************** | ||
qgsvectortiledataitems.h | ||
--------------------- | ||
begin : March 2020 | ||
copyright : (C) 2020 by Martin Dobias | ||
email : wonder dot sk at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSVECTORTILEDATAITEMS_H | ||
#define QGSVECTORTILEDATAITEMS_H | ||
|
||
#include "qgsdataitem.h" | ||
#include "qgsdataitemprovider.h" | ||
|
||
///@cond PRIVATE | ||
#define SIP_NO_FILE | ||
|
||
//! Root item for XYZ tile layers | ||
class CORE_EXPORT QgsVectorTileRootItem : public QgsDataCollectionItem | ||
{ | ||
Q_OBJECT | ||
public: | ||
QgsVectorTileRootItem( QgsDataItem *parent, QString name, QString path ); | ||
|
||
QVector<QgsDataItem *> createChildren() override; | ||
|
||
QVariant sortKey() const override { return 8; } | ||
|
||
}; | ||
|
||
//! Item implementation for XYZ tile layers | ||
class CORE_EXPORT QgsVectorTileLayerItem : public QgsLayerItem | ||
{ | ||
Q_OBJECT | ||
public: | ||
QgsVectorTileLayerItem( QgsDataItem *parent, QString name, QString path, const QString &encodedUri ); | ||
|
||
}; | ||
|
||
|
||
//! Provider for XYZ root data item | ||
class QgsVectorTileDataItemProvider : public QgsDataItemProvider | ||
{ | ||
public: | ||
QString name() override; | ||
QString dataProviderKey() const override; | ||
int capabilities() const override; | ||
|
||
QgsDataItem *createDataItem( const QString &path, QgsDataItem *parentItem ) override; | ||
}; | ||
|
||
///@endcond | ||
|
||
#endif // QGSVECTORTILEDATAITEMS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*************************************************************************** | ||
qgsvectortileprovidermetadata.cpp | ||
-------------------------------------- | ||
Date : March 2020 | ||
Copyright : (C) 2020 by Martin Dobias | ||
Email : wonder dot sk at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsvectortileprovidermetadata.h" | ||
|
||
#include "qgsvectortiledataitems.h" | ||
|
||
///@cond PRIVATE | ||
|
||
#define PROVIDER_KEY QStringLiteral( "vectortile" ) | ||
#define PROVIDER_DESCRIPTION QStringLiteral( "Vector tile provider" ) | ||
|
||
QgsVectorTileProviderMetadata::QgsVectorTileProviderMetadata() | ||
: QgsProviderMetadata( PROVIDER_KEY, PROVIDER_DESCRIPTION ) | ||
{ | ||
} | ||
|
||
QList<QgsDataItemProvider *> QgsVectorTileProviderMetadata::dataItemProviders() const | ||
{ | ||
QList< QgsDataItemProvider * > providers; | ||
providers << new QgsVectorTileDataItemProvider; | ||
return providers; | ||
} | ||
|
||
//QString QgsVectorTileProviderMetadata::staticKey() | ||
//{ | ||
// return PROVIDER_KEY; | ||
//} | ||
|
||
///@endcond |
Oops, something went wrong.