mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-28 00:06:23 -05:00
Vector tiles browser integration (+gui to add/edit connections)
This commit is contained in:
parent
62bcc92339
commit
0828c21291
@ -337,6 +337,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsvectorlayerproperties.h"
|
||||
#include "qgsvectorlayerdigitizingproperties.h"
|
||||
#include "qgsvectortilelayer.h"
|
||||
#include "qgsmapthemes.h"
|
||||
#include "qgsmessagelogviewer.h"
|
||||
#include "qgsdataitem.h"
|
||||
@ -2013,6 +2014,11 @@ void QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList &lst )
|
||||
QgsMeshLayer *layer = new QgsMeshLayer( uri, u.name, u.providerKey );
|
||||
addMapLayer( layer );
|
||||
}
|
||||
else if ( u.layerType == QLatin1String( "vector-tile" ) )
|
||||
{
|
||||
QgsVectorTileLayer *layer = new QgsVectorTileLayer( uri, u.name );
|
||||
addMapLayer( layer );
|
||||
}
|
||||
else if ( u.layerType == QLatin1String( "plugin" ) )
|
||||
{
|
||||
addPluginLayer( uri, u.name, u.providerKey );
|
||||
|
||||
@ -645,10 +645,13 @@ SET(QGIS_CORE_SRCS
|
||||
validity/qgsvaliditycheckregistry.cpp
|
||||
|
||||
vectortile/qgsvectortilebasicrenderer.cpp
|
||||
vectortile/qgsvectortileconnection.cpp
|
||||
vectortile/qgsvectortiledataitems.cpp
|
||||
vectortile/qgsvectortilelayer.cpp
|
||||
vectortile/qgsvectortilelayerrenderer.cpp
|
||||
vectortile/qgsvectortileloader.cpp
|
||||
vectortile/qgsvectortilemvtdecoder.cpp
|
||||
vectortile/qgsvectortileprovidermetadata.cpp
|
||||
vectortile/qgsvectortileutils.cpp
|
||||
|
||||
${CMAKE_CURRENT_BINARY_DIR}/qgsexpression_texts.cpp
|
||||
@ -1346,10 +1349,13 @@ SET(QGIS_CORE_HDRS
|
||||
validity/qgsvaliditycheckregistry.h
|
||||
|
||||
vectortile/qgsvectortilebasicrenderer.h
|
||||
vectortile/qgsvectortileconnection.h
|
||||
vectortile/qgsvectortiledataitems.h
|
||||
vectortile/qgsvectortilelayer.h
|
||||
vectortile/qgsvectortilelayerrenderer.h
|
||||
vectortile/qgsvectortileloader.h
|
||||
vectortile/qgsvectortilemvtdecoder.h
|
||||
vectortile/qgsvectortileprovidermetadata.h
|
||||
vectortile/qgsvectortilerenderer.h
|
||||
vectortile/qgsvectortileutils.h
|
||||
)
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
#include "qgsmessagelog.h"
|
||||
#include "qgsprovidermetadata.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
#include "qgsvectortileprovidermetadata.h"
|
||||
#include "qgsproject.h"
|
||||
#include "providers/memory/qgsmemoryprovider.h"
|
||||
#include "providers/gdal/qgsgdalprovider.h"
|
||||
@ -106,7 +107,6 @@ QgsProviderRegistry::QgsProviderRegistry( const QString &pluginPath )
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
void QgsProviderRegistry::init()
|
||||
{
|
||||
// add static providers
|
||||
@ -116,6 +116,8 @@ void QgsProviderRegistry::init()
|
||||
Q_NOWARN_DEPRECATED_POP
|
||||
mProviders[ QgsGdalProvider::providerKey() ] = new QgsGdalProviderMetadata();
|
||||
mProviders[ QgsOgrProvider::providerKey() ] = new QgsOgrProviderMetadata();
|
||||
QgsProviderMetadata *vt = new QgsVectorTileProviderMetadata();
|
||||
mProviders[ vt->key() ] = vt;
|
||||
#ifdef HAVE_STATIC_PROVIDERS
|
||||
mProviders[ QgsWmsProvider::providerKey() ] = new QgsWmsProviderMetadata();
|
||||
mProviders[ QgsPostgresProvider::providerKey() ] = new QgsPostgresProviderMetadata();
|
||||
|
||||
74
src/core/vectortile/qgsvectortileconnection.cpp
Normal file
74
src/core/vectortile/qgsvectortileconnection.cpp
Normal file
@ -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
|
||||
55
src/core/vectortile/qgsvectortileconnection.h
Normal file
55
src/core/vectortile/qgsvectortileconnection.h
Normal file
@ -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
|
||||
78
src/core/vectortile/qgsvectortiledataitems.cpp
Normal file
78
src/core/vectortile/qgsvectortiledataitems.cpp
Normal file
@ -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
|
||||
60
src/core/vectortile/qgsvectortiledataitems.h
Normal file
60
src/core/vectortile/qgsvectortiledataitems.h
Normal file
@ -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
|
||||
42
src/core/vectortile/qgsvectortileprovidermetadata.cpp
Normal file
42
src/core/vectortile/qgsvectortileprovidermetadata.cpp
Normal file
@ -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
|
||||
41
src/core/vectortile/qgsvectortileprovidermetadata.h
Normal file
41
src/core/vectortile/qgsvectortileprovidermetadata.h
Normal file
@ -0,0 +1,41 @@
|
||||
/***************************************************************************
|
||||
qgsvectortileprovidermetadata.h
|
||||
--------------------------------------
|
||||
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. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef QGSVECTORTILEPROVIDERMETADATA_H
|
||||
#define QGSVECTORTILEPROVIDERMETADATA_H
|
||||
|
||||
|
||||
#include "qgsprovidermetadata.h"
|
||||
|
||||
///@cond PRIVATE
|
||||
#define SIP_NO_FILE
|
||||
|
||||
/**
|
||||
* This metadata class does not support creation of provider instances, because
|
||||
* vector tile layer currently does not have a concept of data providers. This class
|
||||
* is only used to create data item provider (for browser integration).
|
||||
*/
|
||||
class QgsVectorTileProviderMetadata : public QgsProviderMetadata
|
||||
{
|
||||
public:
|
||||
QgsVectorTileProviderMetadata();
|
||||
QList< QgsDataItemProvider * > dataItemProviders() const override;
|
||||
|
||||
//static QString staticKey();
|
||||
};
|
||||
|
||||
///@endcond
|
||||
|
||||
#endif // QGSVECTORTILEPROVIDERMETADATA_H
|
||||
@ -321,6 +321,10 @@ SET(QGIS_GUI_SRCS
|
||||
tableeditor/qgstableeditorformattingwidget.cpp
|
||||
tableeditor/qgstableeditorwidget.cpp
|
||||
|
||||
vectortile/qgsvectortileconnectiondialog.cpp
|
||||
vectortile/qgsvectortiledataitemguiprovider.cpp
|
||||
vectortile/qgsvectortileproviderguimetadata.cpp
|
||||
|
||||
qgisinterface.cpp
|
||||
qgsactionmenu.cpp
|
||||
qgsaddattrdialog.cpp
|
||||
@ -1085,6 +1089,10 @@ SET(QGIS_GUI_HDRS
|
||||
tableeditor/qgstableeditorformattingwidget.h
|
||||
tableeditor/qgstableeditorwidget.h
|
||||
|
||||
vectortile/qgsvectortileconnectiondialog.h
|
||||
vectortile/qgsvectortiledataitemguiprovider.h
|
||||
vectortile/qgsvectortileproviderguimetadata.h
|
||||
|
||||
qgsbrowserdockwidget_p.h
|
||||
)
|
||||
|
||||
@ -1200,6 +1208,7 @@ INCLUDE_DIRECTORIES(
|
||||
${CMAKE_SOURCE_DIR}/src/gui/providers/ogr
|
||||
${CMAKE_SOURCE_DIR}/src/gui/raster
|
||||
${CMAKE_SOURCE_DIR}/src/gui/vector
|
||||
${CMAKE_SOURCE_DIR}/src/gui/vectortile
|
||||
${CMAKE_SOURCE_DIR}/src/gui/tableeditor
|
||||
${CMAKE_SOURCE_DIR}/src/core
|
||||
${CMAKE_SOURCE_DIR}/src/core/annotations
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
#include "qgslogger.h"
|
||||
#include "qgsgdalguiprovider.h"
|
||||
#include "qgsogrguiprovider.h"
|
||||
#include "qgsvectortileproviderguimetadata.h"
|
||||
|
||||
#ifdef HAVE_STATIC_PROVIDERS
|
||||
#include "qgswmsprovidergui.h"
|
||||
@ -66,6 +67,9 @@ void QgsProviderGuiRegistry::loadStaticProviders( )
|
||||
QgsProviderGuiMetadata *ogr = new QgsOgrGuiProviderMetadata();
|
||||
mProviders[ ogr->key() ] = ogr;
|
||||
|
||||
QgsProviderGuiMetadata *vt = new QgsVectorTileProviderGuiMetadata();
|
||||
mProviders[ vt->key() ] = vt;
|
||||
|
||||
#ifdef HAVE_STATIC_PROVIDERS
|
||||
QgsProviderGuiMetadata *wms = new QgsWmsProviderGuiMetadata();
|
||||
mProviders[ wms->key() ] = wms;
|
||||
|
||||
62
src/gui/vectortile/qgsvectortileconnectiondialog.cpp
Normal file
62
src/gui/vectortile/qgsvectortileconnectiondialog.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/***************************************************************************
|
||||
qgsvectortileconnectiondialog.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 "qgsvectortileconnectiondialog.h"
|
||||
#include "qgsvectortileconnection.h"
|
||||
#include "qgsgui.h"
|
||||
#include <QMessageBox>
|
||||
|
||||
QgsVectorTileConnectionDialog::QgsVectorTileConnectionDialog( QWidget *parent )
|
||||
: QDialog( parent )
|
||||
{
|
||||
setupUi( this );
|
||||
QgsGui::enableAutoGeometryRestore( this );
|
||||
|
||||
// Behavior for min and max zoom checkbox
|
||||
connect( mCheckBoxZMin, &QCheckBox::toggled, mSpinZMin, &QSpinBox::setEnabled );
|
||||
connect( mCheckBoxZMax, &QCheckBox::toggled, mSpinZMax, &QSpinBox::setEnabled );
|
||||
}
|
||||
|
||||
void QgsVectorTileConnectionDialog::setConnection( const QgsVectorTileConnection &conn )
|
||||
{
|
||||
mEditName->setText( conn.name );
|
||||
mEditUrl->setText( conn.url );
|
||||
mCheckBoxZMin->setChecked( conn.zMin != -1 );
|
||||
mSpinZMin->setValue( conn.zMin != -1 ? conn.zMin : 0 );
|
||||
mCheckBoxZMax->setChecked( conn.zMax != -1 );
|
||||
mSpinZMax->setValue( conn.zMax != -1 ? conn.zMax : 14 );
|
||||
}
|
||||
|
||||
QgsVectorTileConnection QgsVectorTileConnectionDialog::connection() const
|
||||
{
|
||||
QgsVectorTileConnection conn;
|
||||
conn.name = mEditName->text();
|
||||
conn.url = mEditUrl->text();
|
||||
if ( mCheckBoxZMin->isChecked() )
|
||||
conn.zMin = mSpinZMin->value();
|
||||
if ( mCheckBoxZMax->isChecked() )
|
||||
conn.zMax = mSpinZMax->value();
|
||||
return conn;
|
||||
}
|
||||
|
||||
void QgsVectorTileConnectionDialog::accept()
|
||||
{
|
||||
if ( mCheckBoxZMin->isChecked() && mCheckBoxZMax->isChecked() && mSpinZMax->value() < mSpinZMin->value() )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Connection Properties" ), tr( "The maximum zoom level (%1) cannot be lower than the minimum zoom level (%2)." ).arg( mSpinZMax->value() ).arg( mSpinZMin->value() ) );
|
||||
return;
|
||||
}
|
||||
QDialog::accept();
|
||||
}
|
||||
45
src/gui/vectortile/qgsvectortileconnectiondialog.h
Normal file
45
src/gui/vectortile/qgsvectortileconnectiondialog.h
Normal file
@ -0,0 +1,45 @@
|
||||
/***************************************************************************
|
||||
qgsvectortileconnectiondialog.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 QGSVECTORTILECONNECTIONDIALOG_H
|
||||
#define QGSVECTORTILECONNECTIONDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "ui_qgsvectortileconnectiondialog.h"
|
||||
|
||||
|
||||
struct QgsVectorTileConnection;
|
||||
|
||||
|
||||
class QgsVectorTileConnectionDialog : public QDialog, public Ui::QgsVectorTileConnectionDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QgsVectorTileConnectionDialog( QWidget *parent = nullptr );
|
||||
|
||||
void setConnection( const QgsVectorTileConnection &conn );
|
||||
|
||||
QgsVectorTileConnection connection() const;
|
||||
|
||||
void accept() override;
|
||||
|
||||
private:
|
||||
|
||||
QString mBaseKey;
|
||||
QString mCredentialsBaseKey;
|
||||
};
|
||||
|
||||
#endif // QGSVECTORTILECONNECTIONDIALOG_H
|
||||
108
src/gui/vectortile/qgsvectortiledataitemguiprovider.cpp
Normal file
108
src/gui/vectortile/qgsvectortiledataitemguiprovider.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/***************************************************************************
|
||||
qgsvectortiledataitemguiprovider.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 "qgsvectortiledataitemguiprovider.h"
|
||||
|
||||
#include "qgsvectortiledataitems.h"
|
||||
#include "qgsvectortileconnectiondialog.h"
|
||||
#include "qgsvectortileconnection.h"
|
||||
#include "qgsmanageconnectionsdialog.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
|
||||
void QgsVectorTileDataItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *menu, const QList<QgsDataItem *> &, QgsDataItemGuiContext )
|
||||
{
|
||||
if ( QgsVectorTileLayerItem *layerItem = qobject_cast< QgsVectorTileLayerItem * >( item ) )
|
||||
{
|
||||
QAction *actionEdit = new QAction( tr( "Edit…" ), this );
|
||||
connect( actionEdit, &QAction::triggered, this, [layerItem] { editConnection( layerItem ); } );
|
||||
menu->addAction( actionEdit );
|
||||
|
||||
QAction *actionDelete = new QAction( tr( "Delete" ), this );
|
||||
connect( actionDelete, &QAction::triggered, this, [layerItem] { deleteConnection( layerItem ); } );
|
||||
menu->addAction( actionDelete );
|
||||
}
|
||||
|
||||
if ( QgsVectorTileRootItem *rootItem = qobject_cast< QgsVectorTileRootItem * >( item ) )
|
||||
{
|
||||
QAction *actionNew = new QAction( tr( "New Connection…" ), this );
|
||||
connect( actionNew, &QAction::triggered, this, [rootItem] { newConnection( rootItem ); } );
|
||||
menu->addAction( actionNew );
|
||||
|
||||
QAction *actionSaveXyzTilesServers = new QAction( tr( "Save Connections…" ), this );
|
||||
connect( actionSaveXyzTilesServers, &QAction::triggered, this, [] { saveXyzTilesServers(); } );
|
||||
menu->addAction( actionSaveXyzTilesServers );
|
||||
|
||||
QAction *actionLoadXyzTilesServers = new QAction( tr( "Load Connections…" ), this );
|
||||
connect( actionLoadXyzTilesServers, &QAction::triggered, this, [rootItem] { loadXyzTilesServers( rootItem ); } );
|
||||
menu->addAction( actionLoadXyzTilesServers );
|
||||
}
|
||||
}
|
||||
|
||||
void QgsVectorTileDataItemGuiProvider::editConnection( QgsDataItem *item )
|
||||
{
|
||||
QgsVectorTileConnectionDialog dlg;
|
||||
dlg.setConnection( QgsVectorTileConnectionUtils::connection( item->name() ) );
|
||||
if ( !dlg.exec() )
|
||||
return;
|
||||
|
||||
QgsVectorTileConnectionUtils::deleteConnection( item->name() );
|
||||
QgsVectorTileConnectionUtils::addConnection( dlg.connection() );
|
||||
|
||||
item->parent()->refreshConnections();
|
||||
}
|
||||
|
||||
void QgsVectorTileDataItemGuiProvider::deleteConnection( QgsDataItem *item )
|
||||
{
|
||||
if ( QMessageBox::question( nullptr, tr( "Delete Connection" ), tr( "Are you sure you want to delete the connection “%1”?" ).arg( item->name() ),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) != QMessageBox::Yes )
|
||||
return;
|
||||
|
||||
QgsVectorTileConnectionUtils::deleteConnection( item->name() );
|
||||
|
||||
item->parent()->refreshConnections();
|
||||
}
|
||||
|
||||
void QgsVectorTileDataItemGuiProvider::newConnection( QgsDataItem *item )
|
||||
{
|
||||
QgsVectorTileConnectionDialog dlg;
|
||||
if ( !dlg.exec() )
|
||||
return;
|
||||
|
||||
QgsVectorTileConnectionUtils::addConnection( dlg.connection() );
|
||||
item->refreshConnections();
|
||||
}
|
||||
|
||||
void QgsVectorTileDataItemGuiProvider::saveXyzTilesServers()
|
||||
{
|
||||
QgsManageConnectionsDialog dlg( nullptr, QgsManageConnectionsDialog::Export, QgsManageConnectionsDialog::XyzTiles );
|
||||
dlg.exec();
|
||||
}
|
||||
|
||||
void QgsVectorTileDataItemGuiProvider::loadXyzTilesServers( QgsDataItem *item )
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName( nullptr, tr( "Load Connections" ), QDir::homePath(),
|
||||
tr( "XML files (*.xml *.XML)" ) );
|
||||
if ( fileName.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QgsManageConnectionsDialog dlg( nullptr, QgsManageConnectionsDialog::Import, QgsManageConnectionsDialog::XyzTiles, fileName );
|
||||
dlg.exec();
|
||||
item->refreshConnections();
|
||||
}
|
||||
42
src/gui/vectortile/qgsvectortiledataitemguiprovider.h
Normal file
42
src/gui/vectortile/qgsvectortiledataitemguiprovider.h
Normal file
@ -0,0 +1,42 @@
|
||||
/***************************************************************************
|
||||
qgsvectortiledataitemguiprovider.h
|
||||
--------------------------------------
|
||||
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. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef QGSVECTORTILEDATAITEMGUIPROVIDER_H
|
||||
#define QGSVECTORTILEDATAITEMGUIPROVIDER_H
|
||||
|
||||
#include "qgsdataitemguiprovider.h"
|
||||
|
||||
|
||||
class QgsVectorTileDataItemGuiProvider : public QObject, public QgsDataItemGuiProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
QString name() override { return QStringLiteral( "Vector Tiles" ); }
|
||||
|
||||
void populateContextMenu( QgsDataItem *item, QMenu *menu,
|
||||
const QList<QgsDataItem *> &selectedItems, QgsDataItemGuiContext context ) override;
|
||||
|
||||
private:
|
||||
static void editConnection( QgsDataItem *item );
|
||||
static void deleteConnection( QgsDataItem *item );
|
||||
static void newConnection( QgsDataItem *item );
|
||||
static void saveXyzTilesServers();
|
||||
static void loadXyzTilesServers( QgsDataItem *item );
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // QGSVECTORTILEDATAITEMGUIPROVIDER_H
|
||||
30
src/gui/vectortile/qgsvectortileproviderguimetadata.cpp
Normal file
30
src/gui/vectortile/qgsvectortileproviderguimetadata.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
/***************************************************************************
|
||||
qgsvectortileproviderguimetadata.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 "qgsvectortileproviderguimetadata.h"
|
||||
|
||||
#include "qgsvectortiledataitemguiprovider.h"
|
||||
|
||||
|
||||
QgsVectorTileProviderGuiMetadata::QgsVectorTileProviderGuiMetadata()
|
||||
: QgsProviderGuiMetadata( QStringLiteral( "vectortile" ) )
|
||||
{
|
||||
}
|
||||
|
||||
QList<QgsDataItemGuiProvider *> QgsVectorTileProviderGuiMetadata::dataItemGuiProviders()
|
||||
{
|
||||
return QList<QgsDataItemGuiProvider *>()
|
||||
<< new QgsVectorTileDataItemGuiProvider;
|
||||
}
|
||||
33
src/gui/vectortile/qgsvectortileproviderguimetadata.h
Normal file
33
src/gui/vectortile/qgsvectortileproviderguimetadata.h
Normal file
@ -0,0 +1,33 @@
|
||||
/***************************************************************************
|
||||
qgsvectortileproviderguimetadata.h
|
||||
--------------------------------------
|
||||
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. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef QGSVECTORTILEPROVIDERGUIMETADATA_H
|
||||
#define QGSVECTORTILEPROVIDERGUIMETADATA_H
|
||||
|
||||
#include <QList>
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "qgsproviderguimetadata.h"
|
||||
|
||||
class QgsVectorTileProviderGuiMetadata: public QgsProviderGuiMetadata
|
||||
{
|
||||
public:
|
||||
QgsVectorTileProviderGuiMetadata();
|
||||
|
||||
QList<QgsDataItemGuiProvider *> dataItemGuiProviders() override;
|
||||
|
||||
};
|
||||
|
||||
#endif // QGSVECTORTILEPROVIDERGUIMETADATA_H
|
||||
168
src/ui/qgsvectortileconnectiondialog.ui
Normal file
168
src/ui/qgsvectortileconnectiondialog.ui
Normal file
@ -0,0 +1,168 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>QgsVectorTileConnectionDialog</class>
|
||||
<widget class="QDialog" name="QgsVectorTileConnectionDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>659</width>
|
||||
<height>506</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Vector Tiles Connection</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="mGroupBox">
|
||||
<property name="title">
|
||||
<string>Connection Details</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="7" column="2">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>URL</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="2">
|
||||
<widget class="QSpinBox" name="mSpinZMax">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>14</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLineEdit" name="mEditName">
|
||||
<property name="toolTip">
|
||||
<string>Name of the new connection</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLineEdit" name="mEditUrl">
|
||||
<property name="toolTip">
|
||||
<string>URL of the connection, {x}, {y}, and {z} will be replaced with actual values. Use {-y} for inverted y axis.</string>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>http://example.com/{z}/{x}/{y}.png</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="mCheckBoxZMax">
|
||||
<property name="text">
|
||||
<string>Max. Zoom Level</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="mCheckBoxZMin">
|
||||
<property name="text">
|
||||
<string>Min. Zoom Level</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QSpinBox" name="mSpinZMin">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>mEditName</tabstop>
|
||||
<tabstop>mEditUrl</tabstop>
|
||||
<tabstop>mCheckBoxZMin</tabstop>
|
||||
<tabstop>mSpinZMin</tabstop>
|
||||
<tabstop>mCheckBoxZMax</tabstop>
|
||||
<tabstop>mSpinZMax</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>QgsVectorTileConnectionDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>224</x>
|
||||
<y>381</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>QgsVectorTileConnectionDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>292</x>
|
||||
<y>387</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
Loading…
x
Reference in New Issue
Block a user