Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add a provider source widget for gdal file based layers, and allow
changing layer file source from raster layer properties
- Loading branch information
Showing
with
232 additions
and 38 deletions.
- +3 −0 src/gui/CMakeLists.txt
- +57 −0 src/gui/providers/gdal/qgsgdalfilesourcewidget.cpp
- +45 −0 src/gui/providers/gdal/qgsgdalfilesourcewidget.h
- +50 −0 src/gui/providers/gdal/qgsgdalguiprovider.cpp
- +11 −0 src/gui/providers/gdal/qgsgdalguiprovider.h
- +27 −9 src/gui/raster/qgsrasterlayerproperties.cpp
- +3 −0 src/gui/raster/qgsrasterlayerproperties.h
- +36 −29 src/ui/qgsrasterlayerpropertiesbase.ui
@@ -0,0 +1,57 @@ | ||
/*************************************************************************** | ||
qgsgdalfilesourcewidget.cpp | ||
-------------------------------------- | ||
Date : December 2020 | ||
Copyright : (C) 2020 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 "qgsgdalfilesourcewidget.h" | ||
///@cond PRIVATE | ||
|
||
#include "qgsproviderregistry.h" | ||
#include "ogr/qgsogrhelperfunctions.h" | ||
|
||
#include <gdal.h> | ||
|
||
QgsGdalFileSourceWidget::QgsGdalFileSourceWidget( QWidget *parent ) | ||
: QgsProviderSourceWidget( parent ) | ||
{ | ||
QHBoxLayout *layout = new QHBoxLayout(); | ||
layout->setContentsMargins( 0, 0, 0, 0 ); | ||
|
||
mFileWidget = new QgsFileWidget(); | ||
mFileWidget->setDialogTitle( tr( "Open GDAL Supported Raster Dataset(s)" ) ); | ||
mFileWidget->setFilter( QgsProviderRegistry::instance()->fileRasterFilters() ); | ||
mFileWidget->setStorageMode( QgsFileWidget::GetFile ); | ||
mFileWidget->setOptions( QFileDialog::HideNameFilterDetails ); | ||
layout->addWidget( mFileWidget ); | ||
|
||
setLayout( layout ); | ||
} | ||
|
||
void QgsGdalFileSourceWidget::setSourceUri( const QString &uri ) | ||
{ | ||
mSourceParts = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "gdal" ), uri ); | ||
|
||
mFileWidget->setFilePath( mSourceParts.value( QStringLiteral( "path" ) ).toString() ); | ||
} | ||
|
||
QString QgsGdalFileSourceWidget::sourceUri() const | ||
{ | ||
QVariantMap parts = mSourceParts; | ||
parts.insert( QStringLiteral( "path" ), mFileWidget->filePath() ); | ||
return QgsProviderRegistry::instance()->encodeUri( QStringLiteral( "gdal" ), parts ); | ||
} | ||
|
||
|
||
///@endcond |
@@ -0,0 +1,45 @@ | ||
/*************************************************************************** | ||
qgsgdalfilesourcewidget.h | ||
-------------------------------------- | ||
Date : December 2020 | ||
Copyright : (C) 2020 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 QGGDALFILESOURCEWIDGET_H | ||
#define QGGDALFILESOURCEWIDGET_H | ||
|
||
#include "ui_qgsgdalsourceselectbase.h" | ||
#include "qgsprovidersourcewidget.h" | ||
#include "qgis_gui.h" | ||
#include "qgis_sip.h" | ||
|
||
///@cond PRIVATE | ||
#define SIP_NO_FILE | ||
|
||
class QgsGdalFileSourceWidget : public QgsProviderSourceWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QgsGdalFileSourceWidget( QWidget *parent = nullptr ); | ||
|
||
void setSourceUri( const QString &uri ) override; | ||
QString sourceUri() const override; | ||
|
||
private: | ||
QgsFileWidget *mFileWidget = nullptr; | ||
|
||
QVariantMap mSourceParts; | ||
}; | ||
|
||
///@endcond | ||
#endif // QGGDALFILESOURCEWIDGET_H |
Oops, something went wrong.