Skip to content

Commit

Permalink
Merge pull request #4969 from boundlessgeo/unified-layer-dialog-raste…
Browse files Browse the repository at this point in the history
…r-mods

Unified layer dialog raster mods
  • Loading branch information
elpaso authored Aug 6, 2017
2 parents 7f5b4db + 3a715db commit 0e2458e
Show file tree
Hide file tree
Showing 19 changed files with 834 additions and 57 deletions.
8 changes: 8 additions & 0 deletions python/gui/qgsabstractdatasourcewidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ Emitted when a raster layer has been selected for addition
Emitted when a vector layer has been selected for addition
%End

void addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
%Docstring
Emitted when one or more OGR supported layers are selected for addition
\param layerQStringList list of layers protocol URIs
\param enc encoding
\param dataSourceType string (can be "file" or "database")
%End

void progress( int, int );
%Docstring
Emitted when a progress dialog is shown by the provider dialog
Expand Down
1 change: 0 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsuserprofile.h"

#include "qgssublayersdialog.h"
#include "ogr/qgsopenvectorlayerdialog.h"
#include "ogr/qgsvectorlayersaveasdialog.h"

#include "qgsosmdownloaddialog.h"
Expand Down
5 changes: 0 additions & 5 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,8 @@ SET(QGIS_GUI_SRCS
locator/qgslocatorfilter.cpp
locator/qgslocatorwidget.cpp

ogr/qgsopenvectorlayerdialog.cpp
ogr/qgsogrhelperfunctions.cpp
ogr/qgsnewogrconnection.cpp
ogr/qgsopenvectorlayerdialog.cpp
ogr/qgsvectorlayersaveasdialog.cpp

qgisinterface.cpp
Expand Down Expand Up @@ -508,7 +506,6 @@ SET(QGIS_GUI_MOC_HDRS
qgsdatasourcemanagerdialog.h
qgsabstractdatasourcewidget.h

ogr/qgsopenvectorlayerdialog.h
ogr/qgsnewogrconnection.h
ogr/qgsvectorlayersaveasdialog.h

Expand Down Expand Up @@ -718,7 +715,6 @@ SET(QGIS_GUI_HDRS
qgsdatasourcemanagerdialog.h
qgsabstractdatasourcewidget.h

ogr/qgsopenvectorlayerdialog.h
ogr/qgsogrhelperfunctions.h
ogr/qgsnewogrconnection.h
ogr/qgsvectorlayersaveasdialog.h
Expand Down Expand Up @@ -816,7 +812,6 @@ SET(QGIS_GUI_UI_HDRS
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgssqlcomposerdialogbase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgssublayersdialogbase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgstablewidgetuibase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsopenvectorlayerdialogbase.h
)

IF(ENABLE_MODELTEST)
Expand Down
3 changes: 0 additions & 3 deletions src/gui/ogr/qgsopenvectorlayerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ class GUI_EXPORT QgsOpenVectorLayerDialog : public QgsAbstractDataSourceWidget,
void on_cmbConnections_currentIndexChanged( const QString &text );
void on_buttonBox_helpRequested() { QgsHelp::openHelp( QStringLiteral( "working_with_vector/supported_data.html#loading-a-layer-from-a-file" ) ); }

signals:
//! Emitted when in embedded mode
void addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
};

#endif // QGSOPENVECTORDIALOG_H
7 changes: 7 additions & 0 deletions src/gui/qgsabstractdatasourcewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
//! Emitted when a vector layer has been selected for addition
void addVectorLayer( const QString &uri, const QString &layerName );

/** Emitted when one or more OGR supported layers are selected for addition
* \param layerList list of layers protocol URIs
* \param encoding encoding
* \param dataSourceType string (can be "file" or "database")
*/
void addVectorLayers( const QStringList &layerList, const QString &encoding, const QString &dataSourceType );

//! Emitted when a progress dialog is shown by the provider dialog
void progress( int, int );

Expand Down
48 changes: 15 additions & 33 deletions src/gui/qgsdatasourcemanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "qgsbrowserdockwidget.h"
#include "qgssettings.h"
#include "qgsproviderregistry.h"
#include "qgsopenvectorlayerdialog.h"
#include "qgsabstractdatasourcewidget.h"
#include "qgsmapcanvas.h"

Expand Down Expand Up @@ -56,32 +55,14 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent, QgsMapC
connect( mBrowserWidget, &QgsBrowserDockWidget::connectionsChanged, this, &QgsDataSourceManagerDialog::connectionsChanged );
connect( this, &QgsDataSourceManagerDialog::updateProjectHome, mBrowserWidget, &QgsBrowserDockWidget::updateProjectHome );

// VECTOR Layers (completely different interface: it's not a provider)
QgsOpenVectorLayerDialog *ovl = new QgsOpenVectorLayerDialog( this, Qt::Widget, QgsProviderRegistry::WidgetMode::Embedded );
ui->mOptionsStackedWidget->addWidget( ovl );
QListWidgetItem *ogrItem = new QListWidgetItem( tr( "Vector" ), ui->mOptionsListWidget );
ogrItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddOgrLayer.svg" ) ) );
ogrItem->setToolTip( tr( "Add Vector layer" ) );
connect( ovl, &QgsOpenVectorLayerDialog::addVectorLayers, this, &QgsDataSourceManagerDialog::vectorLayersAdded );
connect( ovl, &QgsOpenVectorLayerDialog::rejected, this, &QgsDataSourceManagerDialog::reject );
mPageNames.append( QStringLiteral( "ogr" ) );

// RASTER (forward to app)
ui->mOptionsStackedWidget->addWidget( new QWidget() );
QListWidgetItem *rasterItem = new QListWidgetItem( tr( "Raster" ), ui->mOptionsListWidget );
rasterItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddRasterLayer.svg" ) ) );
rasterItem->setToolTip( tr( "Open a GDAL Supported Raster Data Source" ) );
mPageNames.append( QStringLiteral( "raster" ) );

// Add data provider dialogs
QWidget *dlg = nullptr;

dlg = providerDialog( QStringLiteral( "delimitedtext" ), tr( "Delimited Text" ), QStringLiteral( "/mActionAddDelimitedTextLayer.svg" ) );
addVectorProviderDialog( QStringLiteral( "ogr" ), tr( "Vector" ), QStringLiteral( "/mActionAddOgrLayer.svg" ) );

if ( dlg )
{
connect( dlg, SIGNAL( addVectorLayer( QString, QString, QString ) ), this, SLOT( vectorLayerAdded( QString, QString, QString ) ) );
}
addRasterProviderDialog( QStringLiteral( "gdal" ), tr( "Raster" ), QStringLiteral( "/mActionAddRasterLayer.svg" ) );

addVectorProviderDialog( QStringLiteral( "delimitedtext" ), tr( "Delimited Text" ), QStringLiteral( "/mActionAddDelimitedTextLayer.svg" ) );

#ifdef HAVE_POSTGRESQL
addDbProviderDialog( QStringLiteral( "postgres" ), tr( "PostgreSQL" ), QStringLiteral( "/mActionAddPostgisLayer.svg" ) );
Expand All @@ -97,11 +78,13 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent, QgsMapC
addDbProviderDialog( QStringLiteral( "oracle" ), tr( "Oracle" ), QStringLiteral( "/mActionAddOracleLayer.svg" ) );
#endif

dlg = providerDialog( QStringLiteral( "virtual" ), tr( "Virtual Layer" ), QStringLiteral( "/mActionAddVirtualLayer.svg" ) );
dlg = addVectorProviderDialog( QStringLiteral( "virtual" ), tr( "Virtual Layer" ), QStringLiteral( "/mActionAddVirtualLayer.svg" ) );

// Apparently this is the only provider using replaceVectorLayer, we should
// move this in to the base abstract class when it is used by at least one
// additional provider.
if ( dlg )
{
connect( dlg, SIGNAL( addVectorLayer( QString, QString, QString ) ), this, SLOT( vectorLayerAdded( QString, QString, QString ) ) );
connect( dlg, SIGNAL( replaceVectorLayer( QString, QString, QString, QString ) ), this, SIGNAL( replaceSelectedVectorLayer( QString, QString, QString, QString ) ) );
}

Expand Down Expand Up @@ -136,11 +119,6 @@ void QgsDataSourceManagerDialog::setCurrentPage( int index )
mPreviousRow = ui->mOptionsStackedWidget->currentIndex();
ui->mOptionsStackedWidget->setCurrentIndex( index );
setWindowTitle( tr( "Data Source Manager | %1" ).arg( ui->mOptionsListWidget->currentItem()->text() ) );
if ( 0 <= index && index < mPageNames.size() && mPageNames.at( index ) == QStringLiteral( "raster" ) )
{
emit addRasterLayer();
QTimer::singleShot( 0, this, &QgsDataSourceManagerDialog::setPreviousPage );
}
}

void QgsDataSourceManagerDialog::setPreviousPage()
Expand Down Expand Up @@ -197,7 +175,7 @@ QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::providerDialog( const Q
}
}

void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey, const QString providerName, const QString icon, QString title )
QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey, const QString providerName, const QString icon, QString title )
{
QgsAbstractDataSourceWidget *dlg = providerDialog( providerKey, providerName, icon, title );
if ( dlg )
Expand All @@ -211,9 +189,10 @@ void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey,
connect( dlg, SIGNAL( connectionsChanged() ), this, SIGNAL( connectionsChanged() ) );
connect( this, SIGNAL( providerDialogsRefreshRequested() ), dlg, SLOT( refresh() ) );
}
return dlg;
}

void QgsDataSourceManagerDialog::addRasterProviderDialog( const QString providerKey, const QString providerName, const QString icon, QString title )
QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::addRasterProviderDialog( const QString providerKey, const QString providerName, const QString icon, QString title )
{
QgsAbstractDataSourceWidget *dlg = providerDialog( providerKey, providerName, icon, title );
if ( dlg )
Expand All @@ -223,17 +202,20 @@ void QgsDataSourceManagerDialog::addRasterProviderDialog( const QString provider
connect( dlg, SIGNAL( connectionsChanged() ), this, SIGNAL( connectionsChanged() ) );
connect( this, SIGNAL( providerDialogsRefreshRequested() ), dlg, SLOT( refresh() ) );
}
return dlg;
}

void QgsDataSourceManagerDialog::addVectorProviderDialog( const QString providerKey, const QString providerName, const QString icon, QString title )
QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::addVectorProviderDialog( const QString providerKey, const QString providerName, const QString icon, QString title )
{
QgsAbstractDataSourceWidget *dlg = providerDialog( providerKey, providerName, icon, title );
if ( dlg )
{
connect( dlg, &QgsAbstractDataSourceWidget::addVectorLayer, this, [ = ]( const QString & vectorLayerPath, const QString & baseName )
{ this->vectorLayerAdded( vectorLayerPath, baseName, providerKey ); } );
connect( dlg, &QgsAbstractDataSourceWidget::addVectorLayers, this, &QgsDataSourceManagerDialog::vectorLayersAdded );
connect( this, SIGNAL( providerDialogsRefreshRequested() ), dlg, SLOT( refresh() ) );
}
return dlg;
}

void QgsDataSourceManagerDialog::showEvent( QShowEvent *e )
Expand Down
6 changes: 3 additions & 3 deletions src/gui/qgsdatasourcemanagerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva
private:
// Return the dialog from the provider
QgsAbstractDataSourceWidget *providerDialog( const QString providerKey, const QString providerName, const QString icon, QString title = QString() );
void addDbProviderDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString() );
void addRasterProviderDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString() );
void addVectorProviderDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString() );
QgsAbstractDataSourceWidget *addDbProviderDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString() );
QgsAbstractDataSourceWidget *addRasterProviderDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString() );
QgsAbstractDataSourceWidget *addVectorProviderDialog( QString const providerKey, QString const providerName, QString const icon, QString title = QString() );
Ui::QgsDataSourceManagerDialog *ui;
QgsBrowserDockWidget *mBrowserWidget = nullptr;
int mPreviousRow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void QgsDelimitedTextSourceSelect::addButtonClicked()


// add the layer to the map
emit addVectorLayer( QString::fromAscii( url.toEncoded() ), txtLayerName->text(), QStringLiteral( "delimitedtext" ) );
emit addVectorLayer( QString::fromAscii( url.toEncoded() ), txtLayerName->text() );
if ( widgetMode() == QgsProviderRegistry::WidgetMode::None )
{
accept();
Expand Down
3 changes: 0 additions & 3 deletions src/providers/delimitedtext/qgsdelimitedtextsourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ class QgsDelimitedTextSourceSelect : public QgsAbstractDataSourceWidget, private
void updateFieldsAndEnable();
void enableAccept();
bool validate();

signals:
void addVectorLayer( const QString &, const QString &, const QString & );
};

#endif // QGSDELIMITEDTEXTSOURCESELECT_H
2 changes: 2 additions & 0 deletions src/providers/gdal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ SET(GDAL_SRCS
qgsgdalproviderbase.cpp
qgsgdalprovider.cpp
qgsgdaldataitems.cpp
qgsgdalsourceselect.cpp
)
SET(GDAL_MOC_HDRS
qgsgdalprovider.h
qgsgdaldataitems.h
qgsgdalsourceselect.h
)

INCLUDE_DIRECTORIES (
Expand Down
48 changes: 48 additions & 0 deletions src/providers/gdal/qgsgdalsourceselect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/***************************************************************************
qgsgdalsourceselect.h
-------------------
begin : August 05 2017
copyright : (C) 2017 by Alessandro Pasotti
email : apasotti at boundlessgeo 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 "qgsgdalsourceselect.h"
#include "qgsproviderregistry.h"

QgsGdalSourceSelect::QgsGdalSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ):
QgsAbstractDataSourceWidget( parent, fl, widgetMode )
{
setupUi( this );
setupButtons( buttonBox );
mQgsFileWidget->setFilter( QgsProviderRegistry::instance()->fileRasterFilters() );
connect( mQgsFileWidget, &QgsFileWidget::fileChanged, this, [ = ]( const QString & path )
{
mRasterPath = path;
emit enableButtons( ! mRasterPath.isEmpty() );
} );
}

QgsGdalSourceSelect::~QgsGdalSourceSelect()
{

}

void QgsGdalSourceSelect::addButtonClicked()
{
QFileInfo baseName( mRasterPath );
emit addRasterLayer( mRasterPath, baseName.baseName(), QStringLiteral( "gdal" ) );
}

QGISEXTERN QgsGdalSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
{
return new QgsGdalSourceSelect( parent, fl, widgetMode );
}
47 changes: 47 additions & 0 deletions src/providers/gdal/qgsgdalsourceselect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/***************************************************************************
qgsgdalsourceselect.h
-------------------
begin : August 05 2017
copyright : (C) 2017 by Alessandro Pasotti
email : apasotti at boundlessgeo 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 QGGDALSOURCESELECT_H
#define QGGDALSOURCESELECT_H

#include "ui_qgsgdalsourceselectbase.h"
#include "qgsabstractdatasourcewidget.h"


/** \class QgsGdalSourceSelect
* \brief Dialog to select GDAL supported rasters
*/
class QgsGdalSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsGdalSourceSelectBase
{
Q_OBJECT

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

~QgsGdalSourceSelect();

public slots:
//! Determines the tables the user selected and closes the dialog
void addButtonClicked() override;

private:

QString mRasterPath;

};

#endif // QGGDALSOURCESELECT_H
18 changes: 17 additions & 1 deletion src/providers/ogr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ SET (OGR_SRCS
qgsogrfeatureiterator.cpp
qgsogrconnpool.cpp
qgsogrexpressioncompiler.cpp
qgsogrsourceselect.cpp
)

SET(OGR_MOC_HDRS qgsogrprovider.h qgsogrdataitems.h qgsogrconnpool.h)
SET(OGR_MOC_HDRS
qgsogrprovider.h
qgsogrdataitems.h
qgsogrconnpool.h
qgsogrsourceselect.h
)

########################################################
# Build
Expand All @@ -20,9 +26,11 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/symbology-ng
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/gui

${CMAKE_BINARY_DIR}/src/core
${CMAKE_BINARY_DIR}/src/gui
${CMAKE_BINARY_DIR}/src/ui
)
INCLUDE_DIRECTORIES(SYSTEM
${GDAL_INCLUDE_DIR}
Expand All @@ -35,6 +43,14 @@ ADD_LIBRARY(ogrprovider MODULE ${OGR_SRCS} ${OGR_MOC_SRCS})
TARGET_LINK_LIBRARIES(ogrprovider
qgis_core
)


IF (WITH_GUI)
TARGET_LINK_LIBRARIES (ogrprovider
qgis_gui
)
ENDIF ()

IF (MSVC)
#needed for linking to gdal which needs odbc
SET(TARGET_LINK_LIBRARIES ${TARGET_LINK_LIBRARIE} odbc32 odbccp32)
Expand Down
Loading

0 comments on commit 0e2458e

Please sign in to comment.