Skip to content

Commit

Permalink
[feature] add vector tile page to the Datasource Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Apr 16, 2020
1 parent 9c4feb5 commit f786e5d
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/core/vectortile/qgsvectortileconnection.cpp
Expand Up @@ -98,6 +98,18 @@ void QgsVectorTileProviderConnection::addConnection( const QString &name, QgsVec
settings.setValue( QStringLiteral( "zmax" ), conn.zMax );
}

QString QgsVectorTileProviderConnection::selectedConnection()
{
QgsSettings settings;
return settings.value( QStringLiteral( "qgis/connections-vector-tile/selected" ) ).toString();
}

void QgsVectorTileProviderConnection::setSelectedConnection( const QString &name )
{
QgsSettings settings;
return settings.setValue( QStringLiteral( "qgis/connections-vector-tile/selected" ), name );
}

//

QgsVectorTileProviderConnection::QgsVectorTileProviderConnection( const QString &name )
Expand Down
4 changes: 4 additions & 0 deletions src/core/vectortile/qgsvectortileconnection.h
Expand Up @@ -59,6 +59,10 @@ class CORE_EXPORT QgsVectorTileProviderConnection : public QgsAbstractProviderCo
static void deleteConnection( const QString &name );
//! Adds a new connection to the list
static void addConnection( const QString &name, Data conn );
//! Returns last used connection
static QString selectedConnection();
//! Saves name of the last used connection
static void setSelectedConnection( const QString &connName );
};

///@endcond
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -326,6 +326,7 @@ SET(QGIS_GUI_SRCS
vectortile/qgsvectortileconnectiondialog.cpp
vectortile/qgsvectortiledataitemguiprovider.cpp
vectortile/qgsvectortileproviderguimetadata.cpp
vectortile/qgsvectortilesourceselect.cpp

qgisinterface.cpp
qgsactionmenu.cpp
Expand Down Expand Up @@ -1098,6 +1099,7 @@ SET(QGIS_GUI_HDRS
vectortile/qgsvectortileconnectiondialog.h
vectortile/qgsvectortiledataitemguiprovider.h
vectortile/qgsvectortileproviderguimetadata.h
vectortile/qgsvectortilesourceselect.h

qgsbrowserdockwidget_p.h
)
Expand Down
25 changes: 24 additions & 1 deletion src/gui/vectortile/qgsvectortileproviderguimetadata.cpp
Expand Up @@ -13,12 +13,28 @@
* *
***************************************************************************/

#include "qgsapplication.h"
#include "qgssourceselectprovider.h"
#include "qgsvectortilesourceselect.h"
#include "qgsvectortileproviderguimetadata.h"

#include "qgsvectortiledataitemguiprovider.h"

///@cond PRIVATE

class QgsVectorTileSourceSelectProvider : public QgsSourceSelectProvider
{
public:

QString providerKey() const override { return QStringLiteral( "vectortile" ); }
QString text() const override { return QStringLiteral( "Vector Tile" ); } // untranslatable string as acronym for this particular case. Use QObject::tr() otherwise
int ordering() const override { return QgsSourceSelectProvider::OrderRemoteProvider + 12; }
QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddXyzLayer.svg" ) ); }
QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
{
return new QgsVectorTileSourceSelect( parent, fl, widgetMode );
}
};

QgsVectorTileProviderGuiMetadata::QgsVectorTileProviderGuiMetadata()
: QgsProviderGuiMetadata( QStringLiteral( "vectortile" ) )
{
Expand All @@ -30,4 +46,11 @@ QList<QgsDataItemGuiProvider *> QgsVectorTileProviderGuiMetadata::dataItemGuiPro
<< new QgsVectorTileDataItemGuiProvider;
}

QList<QgsSourceSelectProvider *> QgsVectorTileProviderGuiMetadata::sourceSelectProviders()
{
QList<QgsSourceSelectProvider *> providers;
providers << new QgsVectorTileSourceSelectProvider;
return providers;
}

///@endcond
2 changes: 1 addition & 1 deletion src/gui/vectortile/qgsvectortileproviderguimetadata.h
Expand Up @@ -30,7 +30,7 @@ class QgsVectorTileProviderGuiMetadata: public QgsProviderGuiMetadata
QgsVectorTileProviderGuiMetadata();

QList<QgsDataItemGuiProvider *> dataItemGuiProviders() override;

QList<QgsSourceSelectProvider *> sourceSelectProviders() override;
};

///@endcond
Expand Down
144 changes: 144 additions & 0 deletions src/gui/vectortile/qgsvectortilesourceselect.cpp
@@ -0,0 +1,144 @@
/***************************************************************************
qgsvectortilesourceselect.cpp
---------------------------------
begin : April 2020
copyright : (C) 2020 by Alexander Bruy
email : alexander dot bruy 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 "qgshelp.h"
#include "qgsgui.h"
#include "qgsmanageconnectionsdialog.h"
#include "qgsvectortilesourceselect.h"
#include "qgsvectortileconnection.h"
#include "qgsvectortileconnectiondialog.h"

#include <QFileDialog>
#include <QMessageBox>

QgsVectorTileSourceSelect::QgsVectorTileSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode theWidgetMode )
: QgsAbstractDataSourceWidget( parent, fl, theWidgetMode )
{
setupUi( this );

setWindowTitle( tr( "Add Vector Tile Layer" ) );
mConnectionsGroupBox->setTitle( tr( "Vector Tile Connections" ) );

QgsGui::enableAutoGeometryRestore( this );

connect( btnNew, &QPushButton::clicked, this, &QgsVectorTileSourceSelect::btnNew_clicked );
connect( btnEdit, &QPushButton::clicked, this, &QgsVectorTileSourceSelect::btnEdit_clicked );
connect( btnDelete, &QPushButton::clicked, this, &QgsVectorTileSourceSelect::btnDelete_clicked );
connect( btnSave, &QPushButton::clicked, this, &QgsVectorTileSourceSelect::btnSave_clicked );
connect( btnLoad, &QPushButton::clicked, this, &QgsVectorTileSourceSelect::btnLoad_clicked );
connect( cmbConnections, &QComboBox::currentTextChanged, this, &QgsVectorTileSourceSelect::cmbConnections_currentTextChanged );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsVectorTileSourceSelect::showHelp );
setupButtons( buttonBox );

// hide import/export buttons and disable help button
btnSave->hide();
btnLoad->hide();
buttonBox->button( QDialogButtonBox::Help )->setEnabled( false );

populateConnectionList();
}

void QgsVectorTileSourceSelect::btnNew_clicked()
{
QgsVectorTileConnectionDialog nc( this );
if ( nc.exec() )
{
QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
populateConnectionList();
emit connectionsChanged();
}
}

void QgsVectorTileSourceSelect::btnEdit_clicked()
{
QgsVectorTileConnectionDialog nc( this );
QString uri = QgsVectorTileProviderConnection::encodedUri( QgsVectorTileProviderConnection::connection( cmbConnections->currentText() ) );
nc.setConnection( cmbConnections->currentText(), uri );
if ( nc.exec() )
{
QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
populateConnectionList();
emit connectionsChanged();
}
}

void QgsVectorTileSourceSelect::btnDelete_clicked()
{
QString msg = tr( "Are you sure you want to remove the %1 connection and all associated settings?" )
.arg( cmbConnections->currentText() );
if ( QMessageBox::Yes != QMessageBox::question( this, tr( "Confirm Delete" ), msg, QMessageBox::Yes | QMessageBox::No ) )
return;

QgsVectorTileProviderConnection::deleteConnection( cmbConnections->currentText() );

populateConnectionList();
emit connectionsChanged();
}

void QgsVectorTileSourceSelect::btnSave_clicked()
{
}

void QgsVectorTileSourceSelect::btnLoad_clicked()
{
}

void QgsVectorTileSourceSelect::addButtonClicked()
{
QString uri = QgsVectorTileProviderConnection::encodedUri( QgsVectorTileProviderConnection::connection( cmbConnections->currentText() ) );
emit addVectorTileLayer( uri, cmbConnections->currentText() );
}

void QgsVectorTileSourceSelect::populateConnectionList()
{
cmbConnections->blockSignals( true );
cmbConnections->clear();
cmbConnections->addItems( QgsVectorTileProviderConnection::connectionList() );
cmbConnections->blockSignals( false );

setConnectionListPosition();

btnEdit->setDisabled( cmbConnections->count() == 0 );
btnDelete->setDisabled( cmbConnections->count() == 0 );
cmbConnections->setDisabled( cmbConnections->count() == 0 );
}

void QgsVectorTileSourceSelect::setConnectionListPosition()
{
QString toSelect = QgsVectorTileProviderConnection::selectedConnection();

cmbConnections->setCurrentIndex( cmbConnections->findText( toSelect ) );

if ( cmbConnections->currentIndex() < 0 )
{
if ( toSelect.isNull() )
cmbConnections->setCurrentIndex( 0 );
else
cmbConnections->setCurrentIndex( cmbConnections->count() - 1 );
}
emit enableButtons( !cmbConnections->currentText().isEmpty() );
}

void QgsVectorTileSourceSelect::cmbConnections_currentTextChanged( const QString &text )
{
QgsVectorTileProviderConnection::setSelectedConnection( text );
emit enableButtons( !text.isEmpty() );
}

void QgsVectorTileSourceSelect::showHelp()
{
}
65 changes: 65 additions & 0 deletions src/gui/vectortile/qgsvectortilesourceselect.h
@@ -0,0 +1,65 @@
/***************************************************************************
qgsvectortilesourceselect.h
---------------------------------
begin : April 2020
copyright : (C) 2020 by Alexander Bruy
email : alexander dot bruy 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 QGSVECTORTILESOURCESELECT_H
#define QGSVECTORTILESOURCESELECT_H

#include "qgsabstractdatasourcewidget.h"
#include "ui_qgstilesourceselectbase.h"

/*!
* \brief Dialog to create connections to vector tile servers.
*
* This dialog allows the user to define and save connection information
* for vector tile servers.
*
* The user can then connect and add layers from the vector tile server
* to the map canvas.
*/
class QgsVectorTileSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsTileSourceSelectBase
{
Q_OBJECT

public:
//! Constructor
QgsVectorTileSourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );

//! Determines the layers the user selected
void addButtonClicked() override;

private slots:

//! Opens the create connection dialog to build a new connection
void btnNew_clicked();
//! Opens a dialog to edit an existing connection
void btnEdit_clicked();
//! Deletes the selected connection
void btnDelete_clicked();
//! Saves connections to the file
void btnSave_clicked();
//! Loads connections from the file
void btnLoad_clicked();
//! Stores the selected datasource whenerver it is changed
void cmbConnections_currentTextChanged( const QString &text );

private:
void populateConnectionList();
void setConnectionListPosition();
void showHelp();
};

#endif // QGSVECTORTILESOURCESELECT_H

0 comments on commit f786e5d

Please sign in to comment.