Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add source widgets for vector tile VTPK and MBTiles layers
Allows changing the path to the .vtpk / .mbtiles file from the Layer Properties - Source tab (just like what we expose for GDAL sources in raster layer properties)
- Loading branch information
1 parent
d1c3e8d
commit 819544d
Showing
10 changed files
with
551 additions
and
0 deletions.
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
93 changes: 93 additions & 0 deletions
93
src/gui/providers/mbtilesvectortiles/qgsmbtilesvectortileguiprovider.cpp
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,93 @@ | ||
/*************************************************************************** | ||
qgsmbtilesvectortileguiprovider.cpp | ||
-------------------------------------- | ||
Date : March 2023 | ||
Copyright : (C) 2023 by Nyall Dawson | ||
Email : nyall dot dawson 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 "qgsmbtilesvectortileguiprovider.h" | ||
///@cond PRIVATE | ||
|
||
#include <QList> | ||
#include <QAction> | ||
#include <QDesktopServices> | ||
#include <QMenu> | ||
#include <QMessageBox> | ||
|
||
#include "qgsmaplayer.h" | ||
#include "qgsmbtilesvectortilesourcewidget.h" | ||
#include "qgsproviderregistry.h" | ||
#include "qgsmbtilesvectortiledataprovider.h" | ||
|
||
|
||
// | ||
// QgsMbtilesVectorTileGuiProviderMetadata | ||
// | ||
|
||
QgsMbtilesVectorTileSourceWidgetProvider::QgsMbtilesVectorTileSourceWidgetProvider() | ||
{ | ||
|
||
} | ||
|
||
QString QgsMbtilesVectorTileSourceWidgetProvider::providerKey() const | ||
{ | ||
return QgsMbTilesVectorTileDataProvider::MB_TILES_VECTOR_TILE_DATA_PROVIDER_KEY; | ||
} | ||
|
||
bool QgsMbtilesVectorTileSourceWidgetProvider::canHandleLayer( QgsMapLayer *layer ) const | ||
{ | ||
if ( layer->providerType() != QgsMbTilesVectorTileDataProvider::MB_TILES_VECTOR_TILE_DATA_PROVIDER_KEY ) | ||
return false; | ||
|
||
const QVariantMap parts = QgsProviderRegistry::instance()->decodeUri( | ||
QgsMbTilesVectorTileDataProvider::MB_TILES_VECTOR_TILE_DATA_PROVIDER_KEY, | ||
layer->source() ); | ||
if ( parts.value( QStringLiteral( "path" ) ).toString().isEmpty() ) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
QgsProviderSourceWidget *QgsMbtilesVectorTileSourceWidgetProvider::createWidget( QgsMapLayer *layer, QWidget *parent ) | ||
{ | ||
if ( layer->providerType() != QgsMbTilesVectorTileDataProvider::MB_TILES_VECTOR_TILE_DATA_PROVIDER_KEY ) | ||
return nullptr; | ||
|
||
const QVariantMap parts = QgsProviderRegistry::instance()->decodeUri( | ||
QgsMbTilesVectorTileDataProvider::MB_TILES_VECTOR_TILE_DATA_PROVIDER_KEY, | ||
layer->source() | ||
); | ||
|
||
if ( parts.value( QStringLiteral( "path" ) ).toString().isEmpty() ) | ||
return nullptr; | ||
|
||
return new QgsMbtilesVectorTileSourceWidget( parent ); | ||
} | ||
|
||
|
||
// | ||
// QgsMbtilesVectorTileGuiProviderMetadata | ||
// | ||
QgsMbtilesVectorTileGuiProviderMetadata::QgsMbtilesVectorTileGuiProviderMetadata(): | ||
QgsProviderGuiMetadata( QgsMbTilesVectorTileDataProvider::MB_TILES_VECTOR_TILE_DATA_PROVIDER_KEY ) | ||
{ | ||
} | ||
|
||
QList<QgsProviderSourceWidgetProvider *> QgsMbtilesVectorTileGuiProviderMetadata::sourceWidgetProviders() | ||
{ | ||
QList<QgsProviderSourceWidgetProvider *> providers; | ||
providers << new QgsMbtilesVectorTileSourceWidgetProvider(); | ||
return providers; | ||
} | ||
|
||
///@endcond |
45 changes: 45 additions & 0 deletions
45
src/gui/providers/mbtilesvectortiles/qgsmbtilesvectortileguiprovider.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,45 @@ | ||
/*************************************************************************** | ||
qgsmbtilesvectortileguiprovider.h | ||
-------------------------------------- | ||
Date : March 2023 | ||
Copyright : (C) 2023 by Nyall Dawson | ||
Email : nyall dot dawson 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 QGSMBTILESVECTORTILEGUIPROVIDER_H | ||
#define QGSMBTILESVECTORTILEGUIPROVIDER_H | ||
|
||
#include "qgsproviderguimetadata.h" | ||
#include "qgsprovidersourcewidgetprovider.h" | ||
|
||
///@cond PRIVATE | ||
#define SIP_NO_FILE | ||
|
||
class QgsMbtilesVectorTileSourceWidgetProvider : public QgsProviderSourceWidgetProvider | ||
{ | ||
public: | ||
QgsMbtilesVectorTileSourceWidgetProvider(); | ||
QString providerKey() const override; | ||
bool canHandleLayer( QgsMapLayer *layer ) const override; | ||
QgsProviderSourceWidget *createWidget( QgsMapLayer *layer, QWidget *parent = nullptr ) override; | ||
}; | ||
|
||
class QgsMbtilesVectorTileGuiProviderMetadata: public QgsProviderGuiMetadata | ||
{ | ||
public: | ||
QgsMbtilesVectorTileGuiProviderMetadata(); | ||
QList<QgsProviderSourceWidgetProvider *> sourceWidgetProviders() override; | ||
}; | ||
|
||
///@endcond | ||
#endif // QGSMBTILESVECTORTILEGUIPROVIDER_H |
76 changes: 76 additions & 0 deletions
76
src/gui/providers/mbtilesvectortiles/qgsmbtilesvectortilesourcewidget.cpp
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,76 @@ | ||
/*************************************************************************** | ||
qgsmbtilesvectortilesourcewidget.cpp | ||
-------------------------------------- | ||
Date : March 2023 | ||
Copyright : (C) 2023 by Nyall Dawson | ||
Email : nyall dot dawson 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 "qgsmbtilesvectortilesourcewidget.h" | ||
///@cond PRIVATE | ||
|
||
#include "qgsproviderregistry.h" | ||
#include "qgsfilewidget.h" | ||
#include "qgsmbtilesvectortiledataprovider.h" | ||
|
||
#include <QHBoxLayout> | ||
|
||
|
||
QgsMbtilesVectorTileSourceWidget::QgsMbtilesVectorTileSourceWidget( QWidget *parent ) | ||
: QgsProviderSourceWidget( parent ) | ||
{ | ||
QHBoxLayout *layout = new QHBoxLayout(); | ||
layout->setContentsMargins( 0, 0, 0, 0 ); | ||
|
||
mFileWidget = new QgsFileWidget(); | ||
mFileWidget->setDialogTitle( tr( "Select Mbtiles Dataset" ) ); | ||
mFileWidget->setFilter( tr( "Mbtiles Files" ) + QStringLiteral( " (*.mbtiles *.MBTILES)" ) ); | ||
mFileWidget->setStorageMode( QgsFileWidget::GetFile ); | ||
mFileWidget->setOptions( QFileDialog::HideNameFilterDetails ); | ||
layout->addWidget( mFileWidget ); | ||
|
||
setLayout( layout ); | ||
|
||
connect( mFileWidget, &QgsFileWidget::fileChanged, this, &QgsMbtilesVectorTileSourceWidget::validate ); | ||
} | ||
|
||
void QgsMbtilesVectorTileSourceWidget::setSourceUri( const QString &uri ) | ||
{ | ||
mSourceParts = QgsProviderRegistry::instance()->decodeUri( | ||
QgsMbTilesVectorTileDataProvider::MB_TILES_VECTOR_TILE_DATA_PROVIDER_KEY, | ||
uri | ||
); | ||
|
||
mFileWidget->setFilePath( mSourceParts.value( QStringLiteral( "path" ) ).toString() ); | ||
mIsValid = true; | ||
} | ||
|
||
QString QgsMbtilesVectorTileSourceWidget::sourceUri() const | ||
{ | ||
QVariantMap parts = mSourceParts; | ||
parts.insert( QStringLiteral( "path" ), mFileWidget->filePath() ); | ||
return QgsProviderRegistry::instance()->encodeUri( | ||
QgsMbTilesVectorTileDataProvider::MB_TILES_VECTOR_TILE_DATA_PROVIDER_KEY, | ||
parts | ||
); | ||
} | ||
|
||
void QgsMbtilesVectorTileSourceWidget::validate() | ||
{ | ||
const bool valid = !mFileWidget->filePath().isEmpty(); | ||
if ( valid != mIsValid ) | ||
emit validChanged( valid ); | ||
mIsValid = valid; | ||
} | ||
|
||
|
||
///@endcond |
50 changes: 50 additions & 0 deletions
50
src/gui/providers/mbtilesvectortiles/qgsmbtilesvectortilesourcewidget.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,50 @@ | ||
/*************************************************************************** | ||
qgsmbtilesvectortilesourcewidget.h | ||
-------------------------------------- | ||
Date : March 2023 | ||
Copyright : (C) 2023 by Nyall Dawson | ||
Email : nyall dot dawson 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 QGSMBTILESKVECTORTILESOURCEWIDGET_H | ||
#define QGSMBTILESKVECTORTILESOURCEWIDGET_H | ||
|
||
#include "qgsprovidersourcewidget.h" | ||
#include <QVariantMap> | ||
|
||
class QgsFileWidget; | ||
|
||
///@cond PRIVATE | ||
#define SIP_NO_FILE | ||
|
||
class QgsMbtilesVectorTileSourceWidget : public QgsProviderSourceWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QgsMbtilesVectorTileSourceWidget( QWidget *parent = nullptr ); | ||
|
||
void setSourceUri( const QString &uri ) override; | ||
QString sourceUri() const override; | ||
|
||
private slots: | ||
|
||
void validate(); | ||
|
||
private: | ||
QgsFileWidget *mFileWidget = nullptr; | ||
|
||
QVariantMap mSourceParts; | ||
bool mIsValid = false; | ||
}; | ||
|
||
///@endcond | ||
#endif // QGSMBTILESKVECTORTILESOURCEWIDGET_H |
Oops, something went wrong.