Skip to content

Commit dcab8ca

Browse files
committedJun 2, 2017
[addlayerbutton] Added more providers and get canvas from ctor
1 parent 9a51d89 commit dcab8ca

File tree

2 files changed

+66
-31
lines changed

2 files changed

+66
-31
lines changed
 

‎src/app/qgsdatasourcemanagerdialog.cpp

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323
#include "qgssettings.h"
2424
#include "qgsproviderregistry.h"
2525
#include "qgsopenvectorlayerdialog.h"
26+
#include "qgssourceselectdialog.h"
27+
#include "qgsmapcanvas.h"
2628

27-
QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent ) :
29+
30+
QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas, QWidget *parent ) :
2831
QDialog( parent ),
29-
ui( new Ui::QgsDataSourceManagerDialog )
32+
ui( new Ui::QgsDataSourceManagerDialog ),
33+
mMapCanvas( mapCanvas )
3034
{
3135
ui->setupUi( this );
3236

@@ -61,44 +65,45 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent ) :
6165
// Add data provider dialogs
6266
QDialog *dlg;
6367

64-
/////////////////////////////////////////////////////////////////////////////
65-
// WMS
6668

67-
dlg = providerDialog( QStringLiteral( "wms" ), tr( "WMS" ), QStringLiteral( "/mActionAddWmsLayer.svg" ) );
68-
if ( dlg )
69-
{
70-
// Forward
71-
connect( dlg, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
72-
this, SLOT( rasterLayerAdded( QString const &, QString const &, QString const & ) ) );
73-
}
69+
#ifdef HAVE_POSTGRESQL
70+
addDbProviderDialog( QStringLiteral( "postgres" ), tr( "PostgreSQL" ), QStringLiteral( "/mActionAddPostgisLayer.svg" ) );
71+
#endif
7472

75-
/////////////////////////////////////////////////////////////////////////////
76-
// WFS
73+
addDbProviderDialog( QStringLiteral( "spatialite" ), tr( "Spatialite" ), QStringLiteral( "/mActionAddSpatiaLiteLayer.svg" ) );
74+
75+
addDbProviderDialog( QStringLiteral( "mssql" ), tr( "MSSQL" ), QStringLiteral( "/mActionAddMssqlLayer.svg" ) );
76+
77+
addDbProviderDialog( QStringLiteral( "DB2" ), tr( "DB2" ), QStringLiteral( "/mActionAddDb2Layer.svg" ) );
78+
79+
addRasterProviderDialog( QStringLiteral( "wms" ), tr( "WMS" ), QStringLiteral( "/mActionAddWmsLayer.svg" ) );
80+
81+
addRasterProviderDialog( QStringLiteral( "arcgismapserver" ), tr( "ArcGIS Map Server" ), QStringLiteral( "/mActionAddAmsLayer.svg" ) );
82+
83+
addRasterProviderDialog( QStringLiteral( "wcs" ), tr( "WCS" ), QStringLiteral( "/mActionAddWcsLayer.svg" ) );
7784

7885
dlg = providerDialog( QStringLiteral( "WFS" ), tr( "WFS" ), QStringLiteral( "/mActionAddWfsLayer.svg" ) );
7986
if ( dlg )
8087
{
8188
// Forward (if only a common interface for the signals had been used in the providers ...)
82-
connect( dlg, SIGNAL( addWfsLayer( QString, QString ) ), this, SIGNAL( addWfsLayer( QString, QString ) ) );
83-
connect( this, &QgsDataSourceManagerDialog::addWfsLayer,
89+
connect( dlg, SIGNAL( addFsLayer( QString, QString ) ), this, SIGNAL( addFsLayer( QString, QString ) ) );
90+
connect( this, &QgsDataSourceManagerDialog::addFsLayer,
8491
this, [ = ]( const QString & vectorLayerPath, const QString & baseName )
8592
{ this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "WFS" ) ); } );
8693
}
8794

88-
#ifdef HAVE_POSTGRESQL
89-
/////////////////////////////////////////////////////////////////////////////
90-
// POSTGIS
91-
dlg = providerDialog( QStringLiteral( "postgres" ), tr( "PostgreSQL" ), QStringLiteral( "/mActionAddPostgisLayer.svg" ) );
92-
if ( dlg )
95+
QgsSourceSelectDialog *afss = dynamic_cast<QgsSourceSelectDialog *>( providerDialog( QStringLiteral( "arcgisfeatureserver" ),
96+
tr( "ArcGIS Feature Server" ),
97+
QStringLiteral( "/mActionAddAfsLayer.svg" ) ) );
98+
if ( afss && mMapCanvas )
9399
{
94-
connect( dlg, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ),
95-
this, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ) );
96-
connect( dlg, SIGNAL( progress( int, int ) ),
97-
this, SIGNAL( showProgress( int, int ) ) );
98-
connect( dlg, SIGNAL( progressMessage( QString ) ),
99-
this, SIGNAL( showStatusMessage( QString ) ) );
100+
afss->setCurrentExtentAndCrs( mMapCanvas->extent(), mMapCanvas->mapSettings().destinationCrs() );
101+
// Forward (if only a common interface for the signals had been used in the providers ...)
102+
connect( afss, SIGNAL( addLayer( QString, QString ) ), this, SIGNAL( addFsLayer( QString, QString ) ) );
103+
connect( this, &QgsDataSourceManagerDialog::addFsLayer,
104+
this, [ = ]( const QString & vectorLayerPath, const QString & baseName )
105+
{ this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "arcgisfeatureserver" ) ); } );
100106
}
101-
#endif
102107

103108
}
104109

@@ -109,8 +114,8 @@ QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()
109114

110115
void QgsDataSourceManagerDialog::setCurrentPage( int index )
111116
{
112-
// TODO: change window title according to the active page
113117
ui->mStackedWidget->setCurrentIndex( index );
118+
setWindowTitle( tr( "Data Source Manager | %1" ).arg( ui->mList->currentItem()->text( ) ) );
114119
}
115120

116121
void QgsDataSourceManagerDialog::rasterLayerAdded( const QString &uri, const QString &baseName, const QString &providerKey )
@@ -128,6 +133,7 @@ void QgsDataSourceManagerDialog::vectorLayersAdded( const QStringList &layerQStr
128133
emit addVectorLayers( layerQStringList, enc, dataSourceType );
129134
}
130135

136+
131137
QDialog *QgsDataSourceManagerDialog::providerDialog( const QString providerKey, const QString providerName, const QString icon )
132138
{
133139
QDialog *dlg = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( providerKey, this, Qt::Widget, true ) );
@@ -144,3 +150,28 @@ QDialog *QgsDataSourceManagerDialog::providerDialog( const QString providerKey,
144150
return dlg;
145151
}
146152
}
153+
154+
void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey, const QString providerName, const QString icon )
155+
{
156+
QDialog *dlg = providerDialog( providerKey, providerName, icon );
157+
if ( dlg )
158+
{
159+
connect( dlg, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ),
160+
this, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ) );
161+
connect( dlg, SIGNAL( progress( int, int ) ),
162+
this, SIGNAL( showProgress( int, int ) ) );
163+
connect( dlg, SIGNAL( progressMessage( QString ) ),
164+
this, SIGNAL( showStatusMessage( QString ) ) );
165+
}
166+
}
167+
168+
void QgsDataSourceManagerDialog::addRasterProviderDialog( const QString providerKey, const QString providerName, const QString icon )
169+
{
170+
QDialog *dlg = providerDialog( providerKey, providerName, icon );
171+
if ( dlg )
172+
{
173+
// Forward
174+
connect( dlg, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
175+
this, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ) );
176+
}
177+
}

‎src/app/qgsdatasourcemanagerdialog.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <QDialog>
2222
class QgsBrowserDockWidget;
2323
class QgsRasterLayer;
24-
24+
class QgsMapCanvas;
2525

2626
namespace Ui
2727
{
@@ -33,7 +33,7 @@ class QgsDataSourceManagerDialog : public QDialog
3333
Q_OBJECT
3434

3535
public:
36-
explicit QgsDataSourceManagerDialog( QWidget *parent = 0 );
36+
explicit QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas, QWidget *parent = 0 );
3737
~QgsDataSourceManagerDialog();
3838

3939
public slots:
@@ -50,7 +50,7 @@ class QgsDataSourceManagerDialog : public QDialog
5050
//! For signal forwarding to QgisApp
5151
void addRasterLayer( QString const &uri, QString const &baseName, QString const &providerKey );
5252
void addVectorLayer( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey );
53-
void addWfsLayer( const QString &uri, const QString &typeName );
53+
void addFsLayer( const QString &uri, const QString &typeName );
5454
void addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
5555
void showProgress( int progress, int totalSteps );
5656
void showStatusMessage( const QString &message );
@@ -59,8 +59,12 @@ class QgsDataSourceManagerDialog : public QDialog
5959
private:
6060
//! Return the dialog from the provider
6161
QDialog *providerDialog( QString const providerKey, QString const providerName, QString const icon );
62+
void addDbProviderDialog( QString const providerKey, QString const providerName, QString const icon );
63+
void addRasterProviderDialog( QString const providerKey, QString const providerName, QString const icon );
6264
Ui::QgsDataSourceManagerDialog *ui;
6365
QgsBrowserDockWidget *mBrowserWidget = nullptr;
66+
//! Map canvas
67+
QgsMapCanvas *mMapCanvas = nullptr;
6468
};
6569

6670
#endif // QGSDATASOURCEMANAGERDIALOG_H

0 commit comments

Comments
 (0)
Please sign in to comment.