Skip to content
Permalink
Browse files

[addlayerbutton] Removed all the individual source select slots

In favour of the unified dialog.
  • Loading branch information
elpaso committed Jun 2, 2017
1 parent 25b959c commit fc76d120c25dea43812f6bcff32873152c8ef659
Showing with 33 additions and 192 deletions.
  1. +21 −167 src/app/qgisapp.cpp
  2. +12 −25 src/app/qgisapp.h
@@ -1587,7 +1587,7 @@ bool QgisApp::event( QEvent *event )
return done;
}

void QgisApp::dataSourceManager()
void QgisApp::dataSourceManager( QString pageName )
{
if ( ! mDataSourceManagerDialog )
{
@@ -1605,6 +1605,11 @@ void QgisApp::dataSourceManager()
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::replaceSelectedVectorLayer, this, &QgisApp::replaceSelectedVectorLayer );
connect( mDataSourceManagerDialog, static_cast<void ( QgsDataSourceManagerDialog::* )()>( &QgsDataSourceManagerDialog::addRasterLayer ), this, static_cast<void ( QgisApp::* )()>( &QgisApp::addRasterLayer ) );
}
// Try to open the dialog on a particular page
if ( ! pageName.isEmpty( ) )
{
mDataSourceManagerDialog->openPage( pageName );
}
if ( QgsSettings().value( "/qgis/dataSourceManagerNonModal", true ).toBool( ) )
{
mDataSourceManagerDialog->show();
@@ -1839,7 +1844,7 @@ void QgisApp::createActions()

// Layer Menu Items

connect( mActionDataSourceManager, &QAction::triggered, this, &QgisApp::dataSourceManager );
connect( mActionDataSourceManager, &QAction::triggered, this, [ = ]( ) { dataSourceManager( ); } );
connect( mActionNewVectorLayer, &QAction::triggered, this, &QgisApp::newVectorLayer );
connect( mActionNewSpatiaLiteLayer, &QAction::triggered, this, &QgisApp::newSpatialiteLayer );
connect( mActionNewGeoPackageLayer, &QAction::triggered, this, &QgisApp::newGeoPackageLayer );
@@ -1848,20 +1853,20 @@ void QgisApp::createActions()
connect( mActionShowAlignRasterTool, &QAction::triggered, this, &QgisApp::showAlignRasterTool );
connect( mActionEmbedLayers, &QAction::triggered, this, &QgisApp::embedLayers );
connect( mActionAddLayerDefinition, &QAction::triggered, this, &QgisApp::addLayerDefinition );
connect( mActionAddOgrLayer, &QAction::triggered, this, [ = ] { addVectorLayer(); } );
connect( mActionAddRasterLayer, &QAction::triggered, this, [ = ] { addRasterLayer(); } );
connect( mActionAddPgLayer, &QAction::triggered, this, &QgisApp::addDatabaseLayer );
connect( mActionAddSpatiaLiteLayer, &QAction::triggered, this, &QgisApp::addSpatiaLiteLayer );
connect( mActionAddMssqlLayer, &QAction::triggered, this, &QgisApp::addMssqlLayer );
connect( mActionAddDb2Layer, &QAction::triggered, this, &QgisApp::addDb2Layer );
connect( mActionAddOracleLayer, &QAction::triggered, this, &QgisApp::addOracleLayer );
connect( mActionAddWmsLayer, &QAction::triggered, this, &QgisApp::addWmsLayer );
connect( mActionAddWcsLayer, &QAction::triggered, this, &QgisApp::addWcsLayer );
connect( mActionAddWfsLayer, &QAction::triggered, this, [ = ] { addWfsLayer(); } );
connect( mActionAddAfsLayer, &QAction::triggered, this, [ = ] { addAfsLayer(); } );
connect( mActionAddAmsLayer, &QAction::triggered, this, [ = ] { addAmsLayer(); } );
connect( mActionAddDelimitedText, &QAction::triggered, this, &QgisApp::addDelimitedTextLayer );
connect( mActionAddVirtualLayer, &QAction::triggered, this, &QgisApp::addVirtualLayer );
connect( mActionAddOgrLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "ogr" ) ); } );
connect( mActionAddRasterLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "raster" ) ); } );
connect( mActionAddPgLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "postgres" ) ); } );
connect( mActionAddSpatiaLiteLayer, &QAction::triggered, [ = ] { dataSourceManager( QStringLiteral( "spatialite" ) ); } );
connect( mActionAddMssqlLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "mssql" ) ); } );
connect( mActionAddDb2Layer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "DB2" ) ); } );
connect( mActionAddOracleLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "oracle" ) ); } );
connect( mActionAddWmsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "wms" ) ); } );
connect( mActionAddWcsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "wcs" ) ); } );
connect( mActionAddWfsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "WFS" ) ); } );
connect( mActionAddAfsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "arcgisfeatureserver" ) ); } );
connect( mActionAddAmsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "arcgismapserver" ) ); } );
connect( mActionAddDelimitedText, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "delimitedtext" ) ); } );
connect( mActionAddVirtualLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "virtual" ) ); } );
connect( mActionOpenTable, &QAction::triggered, this, &QgisApp::attributeTable );
connect( mActionOpenFieldCalc, &QAction::triggered, this, &QgisApp::fieldCalculator );
connect( mActionToggleEditing, &QAction::triggered, this, [ = ] { toggleEditing(); } );
@@ -3896,31 +3901,6 @@ QString QgisApp::crsAndFormatAdjustedLayerUri( const QString &uri, const QString
return newuri;
}

/**
This method prompts the user for a list of vector file names with a dialog.
*/
void QgisApp::addVectorLayer()
{
freezeCanvases();
QgsOpenVectorLayerDialog *ovl = new QgsOpenVectorLayerDialog( this );

if ( ovl->exec() )
{
QStringList selectedSources = ovl->dataSources();
QString enc = ovl->encoding();
if ( !selectedSources.isEmpty() )
{
addVectorLayers( selectedSources, enc, ovl->dataSourceType() );
}
}

freezeCanvases( false );
refreshMapCanvas();

delete ovl;
}


bool QgisApp::addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType )
{
bool wasfrozen = mMapCanvas->isFrozen();
@@ -4667,132 +4647,6 @@ void QgisApp::addOracleLayer()
#endif
} // QgisApp::addOracleLayer()

void QgisApp::addWmsLayer()
{
// Fudge for now
QgsDebugMsg( "about to addRasterLayer" );

// TODO: QDialog for now, switch to QWidget in future
QDialog *wmss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "wms" ), this ) );
if ( !wmss )
{
QMessageBox::warning( this, tr( "WMS" ), tr( "Cannot get WMS select dialog from provider." ) );
return;
}
connect( wmss, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
this, SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
wmss->exec();
delete wmss;
}

void QgisApp::addWcsLayer()
{
QgsDebugMsg( "about to addWcsLayer" );

// TODO: QDialog for now, switch to QWidget in future
QDialog *wcss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "wcs" ), this ) );
if ( !wcss )
{
QMessageBox::warning( this, tr( "WCS" ), tr( "Cannot get WCS select dialog from provider." ) );
return;
}
connect( wcss, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
this, SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
wcss->exec();
delete wcss;
}

void QgisApp::addWfsLayer()
{
QgsDebugMsg( "about to addWfsLayer" );

// TODO: QDialog for now, switch to QWidget in future
QDialog *wfss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "WFS" ), this ) );
if ( !wfss )
{
QMessageBox::warning( this, tr( "WFS" ), tr( "Cannot get WFS select dialog from provider." ) );
return;
}
connect( wfss, SIGNAL( addWfsLayer( QString, QString ) ),
this, SLOT( addWfsLayer( QString, QString ) ) );

wfss->exec();
delete wfss;
}

void QgisApp::addWfsLayer( const QString &uri, const QString &typeName )
{
// TODO: this should be eventually moved to a more reasonable place
addVectorLayer( uri, typeName, QStringLiteral( "WFS" ) );
}

void QgisApp::addAfsLayer()
{
if ( !mapCanvas() )
{
return;
}

QgsDebugMsg( "about to addAfsLayer" );

// TODO: QDialog for now, switch to QWidget in future
QgsSourceSelectDialog *afss = dynamic_cast<QgsSourceSelectDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "arcgisfeatureserver" ), this ) );
if ( !afss )
{
QMessageBox::warning( this, tr( "ArcGIS Feature Server" ), tr( "Cannot get ArcGIS Feature Server select dialog from provider." ) );
return;
}
afss->setCurrentExtentAndCrs( mapCanvas()->extent(), mapCanvas()->mapSettings().destinationCrs() );
connect( afss, &QgsSourceSelectDialog::addLayer,
this, [ = ]( const QString & uri, const QString & typeName ) { addAfsLayer( uri, typeName ); } );

bool wasFrozen = mapCanvas()->isFrozen();
freezeCanvases();
afss->exec();
if ( !wasFrozen )
freezeCanvases( false );
delete afss;
}

void QgisApp::addAfsLayer( const QString &uri, const QString &typeName )
{
// TODO: this should be eventually moved to a more reasonable place
addVectorLayer( uri, typeName, QStringLiteral( "arcgisfeatureserver" ) );
}

void QgisApp::addAmsLayer()
{
if ( !mapCanvas() )
{
return;
}

QgsDebugMsg( "about to addAmsLayer" );

// TODO: QDialog for now, switch to QWidget in future
QgsSourceSelectDialog *amss = dynamic_cast<QgsSourceSelectDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "arcgismapserver" ), this ) );
if ( !amss )
{
QMessageBox::warning( this, tr( "ArcGIS Map Server" ), tr( "Cannot get ArcGIS Map Server select dialog from provider." ) );
return;
}
amss->setCurrentExtentAndCrs( mapCanvas()->extent(), mapCanvas()->mapSettings().destinationCrs() );
connect( amss, &QgsSourceSelectDialog::addLayer,
this, [ = ]( const QString & uri, const QString & typeName ) { addAmsLayer( uri, typeName ); } );

bool wasFrozen = mapCanvas()->isFrozen();
freezeCanvases();
amss->exec();
if ( !wasFrozen )
freezeCanvases( false );
delete amss;
}

void QgisApp::addAmsLayer( const QString &uri, const QString &typeName )
{
// TODO: this should be eventually moved to a more reasonable place
addRasterLayer( uri, typeName, QStringLiteral( "arcgismapserver" ) );
}

void QgisApp::fileExit()
{
@@ -758,8 +758,13 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Watch for QFileOpenEvent.
virtual bool event( QEvent *event ) override;

//! Open the DataSourceManager dialog/dock
void dataSourceManager( );

/**
* \brief dataSourceManager Open the DataSourceManager dialog/dock
* \param pageName the page name, usually the provider name or "browser" (for the browser panel)
* or "ogr" (vector layers) or "raster" (raster layers)
*/
void dataSourceManager( QString pageName = QString( ) );

/** Add a raster layer directly without prompting user for location
The caller must provide information compatible with the provider plugin
@@ -794,20 +799,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
bool addRasterLayers( const QStringList &layerQStringList, bool guiWarning = true );

/** \brief Open one or more raster layers and add to the map
* Will prompt user for file names using a file selection dialog
*/
void addRasterLayer();

//! Open a plugin layer using its provider
QgsPluginLayer *addPluginLayer( const QString &uri, const QString &baseName, const QString &providerKey );

void addWfsLayer( const QString &uri, const QString &typeName );

void addAfsLayer( const QString &uri, const QString &typeName );

void addAmsLayer( const QString &uri, const QString &typeName );

void versionReplyFinished();

QgsMessageLogViewer *logViewer() { return mLogViewer; }
@@ -1292,6 +1286,11 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
Is called from the legend when the current legend item has changed*/
void activateDeactivateLayerRelatedActions( QgsMapLayer *layer );

/** \brief Open one or more raster layers and add to the map
* Will prompt user for file names using a file selection dialog
*/
void addRasterLayer();

void selectionChanged( QgsMapLayer *layer );

void extentChanged();
@@ -1304,20 +1303,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
// void debugHook();
//! Add a Layer Definition file
void addLayerDefinition();
//! Add a vector layer to the map
void addVectorLayer();
//! Exit Qgis
void fileExit();
//! Add a WMS layer to the map
void addWmsLayer();
//! Add a WCS layer to the map
void addWcsLayer();
//! Add a WFS layer to the map
void addWfsLayer();
//! Add a ArcGIS FeatureServer layer to the map
void addAfsLayer();
//! Add a ArcGIS MapServer layer to the map
void addAmsLayer();
//! Set map tool to Zoom out
void zoomOut();
//! Set map tool to Zoom in

0 comments on commit fc76d12

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