Skip to content
Permalink
Browse files

Add raster widget to data source manager dialog

Also:
- created source select widget for GDAL provider
- created source select widget for OGR provider
- added addVecorLayers signal to the base class
  • Loading branch information
elpaso committed Aug 5, 2017
1 parent 8463ddb commit acead27197b7762e78366f3553b27ed352a7d604
@@ -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
@@ -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"
@@ -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
@@ -508,7 +506,6 @@ SET(QGIS_GUI_MOC_HDRS
qgsdatasourcemanagerdialog.h
qgsabstractdatasourcewidget.h

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

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

ogr/qgsopenvectorlayerdialog.h
ogr/qgsogrhelperfunctions.h
ogr/qgsnewogrconnection.h
ogr/qgsvectorlayersaveasdialog.h
@@ -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)
@@ -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
@@ -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 layerQStringList list of layers protocol URIs
* \param enc encoding
* \param dataSourceType string (can be "file" or "database")
*/
void addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );

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

@@ -22,7 +22,6 @@
#include "qgsbrowserdockwidget.h"
#include "qgssettings.h"
#include "qgsproviderregistry.h"
#include "qgsopenvectorlayerdialog.h"
#include "qgsabstractdatasourcewidget.h"
#include "qgsmapcanvas.h"

@@ -56,26 +55,13 @@ 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;

addVectorProviderDialog( QStringLiteral( "ogr" ), tr( "Vector" ), QStringLiteral( "/mActionAddOgrLayer.svg" ) );

addRasterProviderDialog( QStringLiteral( "gdal" ), tr( "Raster" ), QStringLiteral( "/mActionAddRasterLayer.svg" ) );

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

#ifdef HAVE_POSTGRESQL
@@ -133,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()
@@ -231,6 +212,7 @@ QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::addVectorProviderDialog
{
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;
@@ -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 (
@@ -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 );
}
@@ -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
@@ -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
@@ -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}
@@ -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)

0 comments on commit acead27

Please sign in to comment.
You can’t perform that action at this time.