Skip to content
Permalink
Browse files

[addlayerbutton] Added more providers and get canvas from ctor

  • Loading branch information
elpaso committed Jun 2, 2017
1 parent 9a51d89 commit dcab8ca1b5e3b80eff663ea864f89a2becf319e2
Showing with 66 additions and 31 deletions.
  1. +59 −28 src/app/qgsdatasourcemanagerdialog.cpp
  2. +7 −3 src/app/qgsdatasourcemanagerdialog.h
@@ -23,10 +23,14 @@
#include "qgssettings.h"
#include "qgsproviderregistry.h"
#include "qgsopenvectorlayerdialog.h"
#include "qgssourceselectdialog.h"
#include "qgsmapcanvas.h"

QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent ) :

QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas, QWidget *parent ) :
QDialog( parent ),
ui( new Ui::QgsDataSourceManagerDialog )
ui( new Ui::QgsDataSourceManagerDialog ),
mMapCanvas( mapCanvas )
{
ui->setupUi( this );

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

/////////////////////////////////////////////////////////////////////////////
// WMS

dlg = providerDialog( QStringLiteral( "wms" ), tr( "WMS" ), QStringLiteral( "/mActionAddWmsLayer.svg" ) );
if ( dlg )
{
// Forward
connect( dlg, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
this, SLOT( rasterLayerAdded( QString const &, QString const &, QString const & ) ) );
}
#ifdef HAVE_POSTGRESQL
addDbProviderDialog( QStringLiteral( "postgres" ), tr( "PostgreSQL" ), QStringLiteral( "/mActionAddPostgisLayer.svg" ) );
#endif

/////////////////////////////////////////////////////////////////////////////
// WFS
addDbProviderDialog( QStringLiteral( "spatialite" ), tr( "Spatialite" ), QStringLiteral( "/mActionAddSpatiaLiteLayer.svg" ) );

addDbProviderDialog( QStringLiteral( "mssql" ), tr( "MSSQL" ), QStringLiteral( "/mActionAddMssqlLayer.svg" ) );

addDbProviderDialog( QStringLiteral( "DB2" ), tr( "DB2" ), QStringLiteral( "/mActionAddDb2Layer.svg" ) );

addRasterProviderDialog( QStringLiteral( "wms" ), tr( "WMS" ), QStringLiteral( "/mActionAddWmsLayer.svg" ) );

addRasterProviderDialog( QStringLiteral( "arcgismapserver" ), tr( "ArcGIS Map Server" ), QStringLiteral( "/mActionAddAmsLayer.svg" ) );

addRasterProviderDialog( QStringLiteral( "wcs" ), tr( "WCS" ), QStringLiteral( "/mActionAddWcsLayer.svg" ) );

dlg = providerDialog( QStringLiteral( "WFS" ), tr( "WFS" ), QStringLiteral( "/mActionAddWfsLayer.svg" ) );
if ( dlg )
{
// Forward (if only a common interface for the signals had been used in the providers ...)
connect( dlg, SIGNAL( addWfsLayer( QString, QString ) ), this, SIGNAL( addWfsLayer( QString, QString ) ) );
connect( this, &QgsDataSourceManagerDialog::addWfsLayer,
connect( dlg, SIGNAL( addFsLayer( QString, QString ) ), this, SIGNAL( addFsLayer( QString, QString ) ) );
connect( this, &QgsDataSourceManagerDialog::addFsLayer,
this, [ = ]( const QString & vectorLayerPath, const QString & baseName )
{ this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "WFS" ) ); } );
}

#ifdef HAVE_POSTGRESQL
/////////////////////////////////////////////////////////////////////////////
// POSTGIS
dlg = providerDialog( QStringLiteral( "postgres" ), tr( "PostgreSQL" ), QStringLiteral( "/mActionAddPostgisLayer.svg" ) );
if ( dlg )
QgsSourceSelectDialog *afss = dynamic_cast<QgsSourceSelectDialog *>( providerDialog( QStringLiteral( "arcgisfeatureserver" ),
tr( "ArcGIS Feature Server" ),
QStringLiteral( "/mActionAddAfsLayer.svg" ) ) );
if ( afss && mMapCanvas )
{
connect( dlg, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ),
this, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ) );
connect( dlg, SIGNAL( progress( int, int ) ),
this, SIGNAL( showProgress( int, int ) ) );
connect( dlg, SIGNAL( progressMessage( QString ) ),
this, SIGNAL( showStatusMessage( QString ) ) );
afss->setCurrentExtentAndCrs( mMapCanvas->extent(), mMapCanvas->mapSettings().destinationCrs() );
// Forward (if only a common interface for the signals had been used in the providers ...)
connect( afss, SIGNAL( addLayer( QString, QString ) ), this, SIGNAL( addFsLayer( QString, QString ) ) );
connect( this, &QgsDataSourceManagerDialog::addFsLayer,
this, [ = ]( const QString & vectorLayerPath, const QString & baseName )
{ this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "arcgisfeatureserver" ) ); } );
}
#endif

}

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

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

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


QDialog *QgsDataSourceManagerDialog::providerDialog( const QString providerKey, const QString providerName, const QString icon )
{
QDialog *dlg = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( providerKey, this, Qt::Widget, true ) );
@@ -144,3 +150,28 @@ QDialog *QgsDataSourceManagerDialog::providerDialog( const QString providerKey,
return dlg;
}
}

void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey, const QString providerName, const QString icon )
{
QDialog *dlg = providerDialog( providerKey, providerName, icon );
if ( dlg )
{
connect( dlg, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ),
this, SIGNAL( addDatabaseLayers( QStringList const &, QString const & ) ) );
connect( dlg, SIGNAL( progress( int, int ) ),
this, SIGNAL( showProgress( int, int ) ) );
connect( dlg, SIGNAL( progressMessage( QString ) ),
this, SIGNAL( showStatusMessage( QString ) ) );
}
}

void QgsDataSourceManagerDialog::addRasterProviderDialog( const QString providerKey, const QString providerName, const QString icon )
{
QDialog *dlg = providerDialog( providerKey, providerName, icon );
if ( dlg )
{
// Forward
connect( dlg, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
this, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ) );
}
}
@@ -21,7 +21,7 @@
#include <QDialog>
class QgsBrowserDockWidget;
class QgsRasterLayer;

class QgsMapCanvas;

namespace Ui
{
@@ -33,7 +33,7 @@ class QgsDataSourceManagerDialog : public QDialog
Q_OBJECT

public:
explicit QgsDataSourceManagerDialog( QWidget *parent = 0 );
explicit QgsDataSourceManagerDialog( QgsMapCanvas *mapCanvas, QWidget *parent = 0 );
~QgsDataSourceManagerDialog();

public slots:
@@ -50,7 +50,7 @@ class QgsDataSourceManagerDialog : public QDialog
//! For signal forwarding to QgisApp
void addRasterLayer( QString const &uri, QString const &baseName, QString const &providerKey );
void addVectorLayer( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey );
void addWfsLayer( const QString &uri, const QString &typeName );
void addFsLayer( const QString &uri, const QString &typeName );
void addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
void showProgress( int progress, int totalSteps );
void showStatusMessage( const QString &message );
@@ -59,8 +59,12 @@ class QgsDataSourceManagerDialog : public QDialog
private:
//! Return the dialog from the provider
QDialog *providerDialog( QString const providerKey, QString const providerName, QString const icon );
void addDbProviderDialog( QString const providerKey, QString const providerName, QString const icon );
void addRasterProviderDialog( QString const providerKey, QString const providerName, QString const icon );
Ui::QgsDataSourceManagerDialog *ui;
QgsBrowserDockWidget *mBrowserWidget = nullptr;
//! Map canvas
QgsMapCanvas *mMapCanvas = nullptr;
};

#endif // QGSDATASOURCEMANAGERDIALOG_H

0 comments on commit dcab8ca

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