Skip to content

Commit acead27

Browse files
committed
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
1 parent 8463ddb commit acead27

14 files changed

+819
-37
lines changed

python/gui/qgsabstractdatasourcewidget.sip

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ Emitted when a raster layer has been selected for addition
8282
Emitted when a vector layer has been selected for addition
8383
%End
8484

85+
void addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
86+
%Docstring
87+
Emitted when one or more OGR supported layers are selected for addition
88+
\param layerQStringList list of layers protocol URIs
89+
\param enc encoding
90+
\param dataSourceType string (can be "file" or "database")
91+
%End
92+
8593
void progress( int, int );
8694
%Docstring
8795
Emitted when a progress dialog is shown by the provider dialog

src/app/qgisapp.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
294294
#include "qgsuserprofile.h"
295295

296296
#include "qgssublayersdialog.h"
297-
#include "ogr/qgsopenvectorlayerdialog.h"
298297
#include "ogr/qgsvectorlayersaveasdialog.h"
299298

300299
#include "qgsosmdownloaddialog.h"

src/gui/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,8 @@ SET(QGIS_GUI_SRCS
179179
locator/qgslocatorfilter.cpp
180180
locator/qgslocatorwidget.cpp
181181

182-
ogr/qgsopenvectorlayerdialog.cpp
183182
ogr/qgsogrhelperfunctions.cpp
184183
ogr/qgsnewogrconnection.cpp
185-
ogr/qgsopenvectorlayerdialog.cpp
186184
ogr/qgsvectorlayersaveasdialog.cpp
187185

188186
qgisinterface.cpp
@@ -508,7 +506,6 @@ SET(QGIS_GUI_MOC_HDRS
508506
qgsdatasourcemanagerdialog.h
509507
qgsabstractdatasourcewidget.h
510508

511-
ogr/qgsopenvectorlayerdialog.h
512509
ogr/qgsnewogrconnection.h
513510
ogr/qgsvectorlayersaveasdialog.h
514511

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

721-
ogr/qgsopenvectorlayerdialog.h
722718
ogr/qgsogrhelperfunctions.h
723719
ogr/qgsnewogrconnection.h
724720
ogr/qgsvectorlayersaveasdialog.h
@@ -816,7 +812,6 @@ SET(QGIS_GUI_UI_HDRS
816812
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgssqlcomposerdialogbase.h
817813
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgssublayersdialogbase.h
818814
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgstablewidgetuibase.h
819-
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsopenvectorlayerdialogbase.h
820815
)
821816

822817
IF(ENABLE_MODELTEST)

src/gui/ogr/qgsopenvectorlayerdialog.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ class GUI_EXPORT QgsOpenVectorLayerDialog : public QgsAbstractDataSourceWidget,
9595
void on_cmbConnections_currentIndexChanged( const QString &text );
9696
void on_buttonBox_helpRequested() { QgsHelp::openHelp( QStringLiteral( "working_with_vector/supported_data.html#loading-a-layer-from-a-file" ) ); }
9797

98-
signals:
99-
//! Emitted when in embedded mode
100-
void addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
10198
};
10299

103100
#endif // QGSOPENVECTORDIALOG_H

src/gui/qgsabstractdatasourcewidget.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
8686
//! Emitted when a vector layer has been selected for addition
8787
void addVectorLayer( const QString &uri, const QString &layerName );
8888

89+
/** Emitted when one or more OGR supported layers are selected for addition
90+
* \param layerQStringList list of layers protocol URIs
91+
* \param enc encoding
92+
* \param dataSourceType string (can be "file" or "database")
93+
*/
94+
void addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
95+
8996
//! Emitted when a progress dialog is shown by the provider dialog
9097
void progress( int, int );
9198

src/gui/qgsdatasourcemanagerdialog.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "qgsbrowserdockwidget.h"
2323
#include "qgssettings.h"
2424
#include "qgsproviderregistry.h"
25-
#include "qgsopenvectorlayerdialog.h"
2625
#include "qgsabstractdatasourcewidget.h"
2726
#include "qgsmapcanvas.h"
2827

@@ -56,26 +55,13 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent, QgsMapC
5655
connect( mBrowserWidget, &QgsBrowserDockWidget::connectionsChanged, this, &QgsDataSourceManagerDialog::connectionsChanged );
5756
connect( this, &QgsDataSourceManagerDialog::updateProjectHome, mBrowserWidget, &QgsBrowserDockWidget::updateProjectHome );
5857

59-
// VECTOR Layers (completely different interface: it's not a provider)
60-
QgsOpenVectorLayerDialog *ovl = new QgsOpenVectorLayerDialog( this, Qt::Widget, QgsProviderRegistry::WidgetMode::Embedded );
61-
ui->mOptionsStackedWidget->addWidget( ovl );
62-
QListWidgetItem *ogrItem = new QListWidgetItem( tr( "Vector" ), ui->mOptionsListWidget );
63-
ogrItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddOgrLayer.svg" ) ) );
64-
ogrItem->setToolTip( tr( "Add Vector layer" ) );
65-
connect( ovl, &QgsOpenVectorLayerDialog::addVectorLayers, this, &QgsDataSourceManagerDialog::vectorLayersAdded );
66-
connect( ovl, &QgsOpenVectorLayerDialog::rejected, this, &QgsDataSourceManagerDialog::reject );
67-
mPageNames.append( QStringLiteral( "ogr" ) );
68-
69-
// RASTER (forward to app)
70-
ui->mOptionsStackedWidget->addWidget( new QWidget() );
71-
QListWidgetItem *rasterItem = new QListWidgetItem( tr( "Raster" ), ui->mOptionsListWidget );
72-
rasterItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddRasterLayer.svg" ) ) );
73-
rasterItem->setToolTip( tr( "Open a GDAL Supported Raster Data Source" ) );
74-
mPageNames.append( QStringLiteral( "raster" ) );
75-
7658
// Add data provider dialogs
7759
QWidget *dlg = nullptr;
7860

61+
addVectorProviderDialog( QStringLiteral( "ogr" ), tr( "Vector" ), QStringLiteral( "/mActionAddOgrLayer.svg" ) );
62+
63+
addRasterProviderDialog( QStringLiteral( "gdal" ), tr( "Raster" ), QStringLiteral( "/mActionAddRasterLayer.svg" ) );
64+
7965
addVectorProviderDialog( QStringLiteral( "delimitedtext" ), tr( "Delimited Text" ), QStringLiteral( "/mActionAddDelimitedTextLayer.svg" ) );
8066

8167
#ifdef HAVE_POSTGRESQL
@@ -133,11 +119,6 @@ void QgsDataSourceManagerDialog::setCurrentPage( int index )
133119
mPreviousRow = ui->mOptionsStackedWidget->currentIndex();
134120
ui->mOptionsStackedWidget->setCurrentIndex( index );
135121
setWindowTitle( tr( "Data Source Manager | %1" ).arg( ui->mOptionsListWidget->currentItem()->text() ) );
136-
if ( 0 <= index && index < mPageNames.size() && mPageNames.at( index ) == QStringLiteral( "raster" ) )
137-
{
138-
emit addRasterLayer();
139-
QTimer::singleShot( 0, this, &QgsDataSourceManagerDialog::setPreviousPage );
140-
}
141122
}
142123

143124
void QgsDataSourceManagerDialog::setPreviousPage()
@@ -231,6 +212,7 @@ QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::addVectorProviderDialog
231212
{
232213
connect( dlg, &QgsAbstractDataSourceWidget::addVectorLayer, this, [ = ]( const QString & vectorLayerPath, const QString & baseName )
233214
{ this->vectorLayerAdded( vectorLayerPath, baseName, providerKey ); } );
215+
connect( dlg, &QgsAbstractDataSourceWidget::addVectorLayers, this, &QgsDataSourceManagerDialog::vectorLayersAdded );
234216
connect( this, SIGNAL( providerDialogsRefreshRequested() ), dlg, SLOT( refresh() ) );
235217
}
236218
return dlg;

src/providers/gdal/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ SET(GDAL_SRCS
22
qgsgdalproviderbase.cpp
33
qgsgdalprovider.cpp
44
qgsgdaldataitems.cpp
5+
qgsgdalsourceselect.cpp
56
)
67
SET(GDAL_MOC_HDRS
78
qgsgdalprovider.h
89
qgsgdaldataitems.h
10+
qgsgdalsourceselect.h
911
)
1012

1113
INCLUDE_DIRECTORIES (
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/***************************************************************************
2+
qgsgdalsourceselect.h
3+
-------------------
4+
begin : August 05 2017
5+
copyright : (C) 2017 by Alessandro Pasotti
6+
email : apasotti at boundlessgeo dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsgdalsourceselect.h"
19+
#include "qgsproviderregistry.h"
20+
21+
QgsGdalSourceSelect::QgsGdalSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ):
22+
QgsAbstractDataSourceWidget( parent, fl, widgetMode )
23+
{
24+
setupUi( this );
25+
setupButtons( buttonBox );
26+
mQgsFileWidget->setFilter( QgsProviderRegistry::instance()->fileRasterFilters() );
27+
connect( mQgsFileWidget, &QgsFileWidget::fileChanged, this, [ = ]( const QString & path )
28+
{
29+
mRasterPath = path;
30+
emit enableButtons( ! mRasterPath.isEmpty() );
31+
} );
32+
}
33+
34+
QgsGdalSourceSelect::~QgsGdalSourceSelect()
35+
{
36+
37+
}
38+
39+
void QgsGdalSourceSelect::addButtonClicked()
40+
{
41+
QFileInfo baseName( mRasterPath );
42+
emit addRasterLayer( mRasterPath, baseName.baseName(), QStringLiteral( "gdal" ) );
43+
}
44+
45+
QGISEXTERN QgsGdalSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
46+
{
47+
return new QgsGdalSourceSelect( parent, fl, widgetMode );
48+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/***************************************************************************
2+
qgsgdalsourceselect.h
3+
-------------------
4+
begin : August 05 2017
5+
copyright : (C) 2017 by Alessandro Pasotti
6+
email : apasotti at boundlessgeo dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
#ifndef QGGDALSOURCESELECT_H
18+
#define QGGDALSOURCESELECT_H
19+
20+
#include "ui_qgsgdalsourceselectbase.h"
21+
#include "qgsabstractdatasourcewidget.h"
22+
23+
24+
/** \class QgsGdalSourceSelect
25+
* \brief Dialog to select GDAL supported rasters
26+
*/
27+
class QgsGdalSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsGdalSourceSelectBase
28+
{
29+
Q_OBJECT
30+
31+
public:
32+
//! Constructor
33+
QgsGdalSourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
34+
35+
~QgsGdalSourceSelect();
36+
37+
public slots:
38+
//! Determines the tables the user selected and closes the dialog
39+
void addButtonClicked() override;
40+
41+
private:
42+
43+
QString mRasterPath;
44+
45+
};
46+
47+
#endif // QGGDALSOURCESELECT_H

src/providers/ogr/CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ SET (OGR_SRCS
55
qgsogrfeatureiterator.cpp
66
qgsogrconnpool.cpp
77
qgsogrexpressioncompiler.cpp
8+
qgsogrsourceselect.cpp
89
)
910

10-
SET(OGR_MOC_HDRS qgsogrprovider.h qgsogrdataitems.h qgsogrconnpool.h)
11+
SET(OGR_MOC_HDRS
12+
qgsogrprovider.h
13+
qgsogrdataitems.h
14+
qgsogrconnpool.h
15+
qgsogrsourceselect.h
16+
)
1117

1218
########################################################
1319
# Build
@@ -20,9 +26,11 @@ INCLUDE_DIRECTORIES(
2026
${CMAKE_SOURCE_DIR}/src/core/metadata
2127
${CMAKE_SOURCE_DIR}/src/core/symbology-ng
2228
${CMAKE_SOURCE_DIR}/src/core/expression
29+
${CMAKE_SOURCE_DIR}/src/gui
2330

2431
${CMAKE_BINARY_DIR}/src/core
2532
${CMAKE_BINARY_DIR}/src/gui
33+
${CMAKE_BINARY_DIR}/src/ui
2634
)
2735
INCLUDE_DIRECTORIES(SYSTEM
2836
${GDAL_INCLUDE_DIR}
@@ -35,6 +43,14 @@ ADD_LIBRARY(ogrprovider MODULE ${OGR_SRCS} ${OGR_MOC_SRCS})
3543
TARGET_LINK_LIBRARIES(ogrprovider
3644
qgis_core
3745
)
46+
47+
48+
IF (WITH_GUI)
49+
TARGET_LINK_LIBRARIES (ogrprovider
50+
qgis_gui
51+
)
52+
ENDIF ()
53+
3854
IF (MSVC)
3955
#needed for linking to gdal which needs odbc
4056
SET(TARGET_LINK_LIBRARIES ${TARGET_LINK_LIBRARIE} odbc32 odbccp32)

0 commit comments

Comments
 (0)