Skip to content

Commit fc76d12

Browse files
committedJun 2, 2017
[addlayerbutton] Removed all the individual source select slots
In favour of the unified dialog.
1 parent 25b959c commit fc76d12

File tree

2 files changed

+33
-192
lines changed

2 files changed

+33
-192
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 21 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ bool QgisApp::event( QEvent *event )
15871587
return done;
15881588
}
15891589

1590-
void QgisApp::dataSourceManager()
1590+
void QgisApp::dataSourceManager( QString pageName )
15911591
{
15921592
if ( ! mDataSourceManagerDialog )
15931593
{
@@ -1605,6 +1605,11 @@ void QgisApp::dataSourceManager()
16051605
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::replaceSelectedVectorLayer, this, &QgisApp::replaceSelectedVectorLayer );
16061606
connect( mDataSourceManagerDialog, static_cast<void ( QgsDataSourceManagerDialog::* )()>( &QgsDataSourceManagerDialog::addRasterLayer ), this, static_cast<void ( QgisApp::* )()>( &QgisApp::addRasterLayer ) );
16071607
}
1608+
// Try to open the dialog on a particular page
1609+
if ( ! pageName.isEmpty( ) )
1610+
{
1611+
mDataSourceManagerDialog->openPage( pageName );
1612+
}
16081613
if ( QgsSettings().value( "/qgis/dataSourceManagerNonModal", true ).toBool( ) )
16091614
{
16101615
mDataSourceManagerDialog->show();
@@ -1839,7 +1844,7 @@ void QgisApp::createActions()
18391844

18401845
// Layer Menu Items
18411846

1842-
connect( mActionDataSourceManager, &QAction::triggered, this, &QgisApp::dataSourceManager );
1847+
connect( mActionDataSourceManager, &QAction::triggered, this, [ = ]( ) { dataSourceManager( ); } );
18431848
connect( mActionNewVectorLayer, &QAction::triggered, this, &QgisApp::newVectorLayer );
18441849
connect( mActionNewSpatiaLiteLayer, &QAction::triggered, this, &QgisApp::newSpatialiteLayer );
18451850
connect( mActionNewGeoPackageLayer, &QAction::triggered, this, &QgisApp::newGeoPackageLayer );
@@ -1848,20 +1853,20 @@ void QgisApp::createActions()
18481853
connect( mActionShowAlignRasterTool, &QAction::triggered, this, &QgisApp::showAlignRasterTool );
18491854
connect( mActionEmbedLayers, &QAction::triggered, this, &QgisApp::embedLayers );
18501855
connect( mActionAddLayerDefinition, &QAction::triggered, this, &QgisApp::addLayerDefinition );
1851-
connect( mActionAddOgrLayer, &QAction::triggered, this, [ = ] { addVectorLayer(); } );
1852-
connect( mActionAddRasterLayer, &QAction::triggered, this, [ = ] { addRasterLayer(); } );
1853-
connect( mActionAddPgLayer, &QAction::triggered, this, &QgisApp::addDatabaseLayer );
1854-
connect( mActionAddSpatiaLiteLayer, &QAction::triggered, this, &QgisApp::addSpatiaLiteLayer );
1855-
connect( mActionAddMssqlLayer, &QAction::triggered, this, &QgisApp::addMssqlLayer );
1856-
connect( mActionAddDb2Layer, &QAction::triggered, this, &QgisApp::addDb2Layer );
1857-
connect( mActionAddOracleLayer, &QAction::triggered, this, &QgisApp::addOracleLayer );
1858-
connect( mActionAddWmsLayer, &QAction::triggered, this, &QgisApp::addWmsLayer );
1859-
connect( mActionAddWcsLayer, &QAction::triggered, this, &QgisApp::addWcsLayer );
1860-
connect( mActionAddWfsLayer, &QAction::triggered, this, [ = ] { addWfsLayer(); } );
1861-
connect( mActionAddAfsLayer, &QAction::triggered, this, [ = ] { addAfsLayer(); } );
1862-
connect( mActionAddAmsLayer, &QAction::triggered, this, [ = ] { addAmsLayer(); } );
1863-
connect( mActionAddDelimitedText, &QAction::triggered, this, &QgisApp::addDelimitedTextLayer );
1864-
connect( mActionAddVirtualLayer, &QAction::triggered, this, &QgisApp::addVirtualLayer );
1856+
connect( mActionAddOgrLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "ogr" ) ); } );
1857+
connect( mActionAddRasterLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "raster" ) ); } );
1858+
connect( mActionAddPgLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "postgres" ) ); } );
1859+
connect( mActionAddSpatiaLiteLayer, &QAction::triggered, [ = ] { dataSourceManager( QStringLiteral( "spatialite" ) ); } );
1860+
connect( mActionAddMssqlLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "mssql" ) ); } );
1861+
connect( mActionAddDb2Layer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "DB2" ) ); } );
1862+
connect( mActionAddOracleLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "oracle" ) ); } );
1863+
connect( mActionAddWmsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "wms" ) ); } );
1864+
connect( mActionAddWcsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "wcs" ) ); } );
1865+
connect( mActionAddWfsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "WFS" ) ); } );
1866+
connect( mActionAddAfsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "arcgisfeatureserver" ) ); } );
1867+
connect( mActionAddAmsLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "arcgismapserver" ) ); } );
1868+
connect( mActionAddDelimitedText, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "delimitedtext" ) ); } );
1869+
connect( mActionAddVirtualLayer, &QAction::triggered, this, [ = ] { dataSourceManager( QStringLiteral( "virtual" ) ); } );
18651870
connect( mActionOpenTable, &QAction::triggered, this, &QgisApp::attributeTable );
18661871
connect( mActionOpenFieldCalc, &QAction::triggered, this, &QgisApp::fieldCalculator );
18671872
connect( mActionToggleEditing, &QAction::triggered, this, [ = ] { toggleEditing(); } );
@@ -3896,31 +3901,6 @@ QString QgisApp::crsAndFormatAdjustedLayerUri( const QString &uri, const QString
38963901
return newuri;
38973902
}
38983903

3899-
/**
3900-
This method prompts the user for a list of vector file names with a dialog.
3901-
*/
3902-
void QgisApp::addVectorLayer()
3903-
{
3904-
freezeCanvases();
3905-
QgsOpenVectorLayerDialog *ovl = new QgsOpenVectorLayerDialog( this );
3906-
3907-
if ( ovl->exec() )
3908-
{
3909-
QStringList selectedSources = ovl->dataSources();
3910-
QString enc = ovl->encoding();
3911-
if ( !selectedSources.isEmpty() )
3912-
{
3913-
addVectorLayers( selectedSources, enc, ovl->dataSourceType() );
3914-
}
3915-
}
3916-
3917-
freezeCanvases( false );
3918-
refreshMapCanvas();
3919-
3920-
delete ovl;
3921-
}
3922-
3923-
39243904
bool QgisApp::addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType )
39253905
{
39263906
bool wasfrozen = mMapCanvas->isFrozen();
@@ -4667,132 +4647,6 @@ void QgisApp::addOracleLayer()
46674647
#endif
46684648
} // QgisApp::addOracleLayer()
46694649

4670-
void QgisApp::addWmsLayer()
4671-
{
4672-
// Fudge for now
4673-
QgsDebugMsg( "about to addRasterLayer" );
4674-
4675-
// TODO: QDialog for now, switch to QWidget in future
4676-
QDialog *wmss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "wms" ), this ) );
4677-
if ( !wmss )
4678-
{
4679-
QMessageBox::warning( this, tr( "WMS" ), tr( "Cannot get WMS select dialog from provider." ) );
4680-
return;
4681-
}
4682-
connect( wmss, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
4683-
this, SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
4684-
wmss->exec();
4685-
delete wmss;
4686-
}
4687-
4688-
void QgisApp::addWcsLayer()
4689-
{
4690-
QgsDebugMsg( "about to addWcsLayer" );
4691-
4692-
// TODO: QDialog for now, switch to QWidget in future
4693-
QDialog *wcss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "wcs" ), this ) );
4694-
if ( !wcss )
4695-
{
4696-
QMessageBox::warning( this, tr( "WCS" ), tr( "Cannot get WCS select dialog from provider." ) );
4697-
return;
4698-
}
4699-
connect( wcss, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
4700-
this, SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
4701-
wcss->exec();
4702-
delete wcss;
4703-
}
4704-
4705-
void QgisApp::addWfsLayer()
4706-
{
4707-
QgsDebugMsg( "about to addWfsLayer" );
4708-
4709-
// TODO: QDialog for now, switch to QWidget in future
4710-
QDialog *wfss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "WFS" ), this ) );
4711-
if ( !wfss )
4712-
{
4713-
QMessageBox::warning( this, tr( "WFS" ), tr( "Cannot get WFS select dialog from provider." ) );
4714-
return;
4715-
}
4716-
connect( wfss, SIGNAL( addWfsLayer( QString, QString ) ),
4717-
this, SLOT( addWfsLayer( QString, QString ) ) );
4718-
4719-
wfss->exec();
4720-
delete wfss;
4721-
}
4722-
4723-
void QgisApp::addWfsLayer( const QString &uri, const QString &typeName )
4724-
{
4725-
// TODO: this should be eventually moved to a more reasonable place
4726-
addVectorLayer( uri, typeName, QStringLiteral( "WFS" ) );
4727-
}
4728-
4729-
void QgisApp::addAfsLayer()
4730-
{
4731-
if ( !mapCanvas() )
4732-
{
4733-
return;
4734-
}
4735-
4736-
QgsDebugMsg( "about to addAfsLayer" );
4737-
4738-
// TODO: QDialog for now, switch to QWidget in future
4739-
QgsSourceSelectDialog *afss = dynamic_cast<QgsSourceSelectDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "arcgisfeatureserver" ), this ) );
4740-
if ( !afss )
4741-
{
4742-
QMessageBox::warning( this, tr( "ArcGIS Feature Server" ), tr( "Cannot get ArcGIS Feature Server select dialog from provider." ) );
4743-
return;
4744-
}
4745-
afss->setCurrentExtentAndCrs( mapCanvas()->extent(), mapCanvas()->mapSettings().destinationCrs() );
4746-
connect( afss, &QgsSourceSelectDialog::addLayer,
4747-
this, [ = ]( const QString & uri, const QString & typeName ) { addAfsLayer( uri, typeName ); } );
4748-
4749-
bool wasFrozen = mapCanvas()->isFrozen();
4750-
freezeCanvases();
4751-
afss->exec();
4752-
if ( !wasFrozen )
4753-
freezeCanvases( false );
4754-
delete afss;
4755-
}
4756-
4757-
void QgisApp::addAfsLayer( const QString &uri, const QString &typeName )
4758-
{
4759-
// TODO: this should be eventually moved to a more reasonable place
4760-
addVectorLayer( uri, typeName, QStringLiteral( "arcgisfeatureserver" ) );
4761-
}
4762-
4763-
void QgisApp::addAmsLayer()
4764-
{
4765-
if ( !mapCanvas() )
4766-
{
4767-
return;
4768-
}
4769-
4770-
QgsDebugMsg( "about to addAmsLayer" );
4771-
4772-
// TODO: QDialog for now, switch to QWidget in future
4773-
QgsSourceSelectDialog *amss = dynamic_cast<QgsSourceSelectDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "arcgismapserver" ), this ) );
4774-
if ( !amss )
4775-
{
4776-
QMessageBox::warning( this, tr( "ArcGIS Map Server" ), tr( "Cannot get ArcGIS Map Server select dialog from provider." ) );
4777-
return;
4778-
}
4779-
amss->setCurrentExtentAndCrs( mapCanvas()->extent(), mapCanvas()->mapSettings().destinationCrs() );
4780-
connect( amss, &QgsSourceSelectDialog::addLayer,
4781-
this, [ = ]( const QString & uri, const QString & typeName ) { addAmsLayer( uri, typeName ); } );
4782-
4783-
bool wasFrozen = mapCanvas()->isFrozen();
4784-
freezeCanvases();
4785-
amss->exec();
4786-
if ( !wasFrozen )
4787-
freezeCanvases( false );
4788-
delete amss;
4789-
}
4790-
4791-
void QgisApp::addAmsLayer( const QString &uri, const QString &typeName )
4792-
{
4793-
// TODO: this should be eventually moved to a more reasonable place
4794-
addRasterLayer( uri, typeName, QStringLiteral( "arcgismapserver" ) );
4795-
}
47964650

47974651
void QgisApp::fileExit()
47984652
{

‎src/app/qgisapp.h

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,13 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
758758
//! Watch for QFileOpenEvent.
759759
virtual bool event( QEvent *event ) override;
760760

761-
//! Open the DataSourceManager dialog/dock
762-
void dataSourceManager( );
761+
762+
/**
763+
* \brief dataSourceManager Open the DataSourceManager dialog/dock
764+
* \param pageName the page name, usually the provider name or "browser" (for the browser panel)
765+
* or "ogr" (vector layers) or "raster" (raster layers)
766+
*/
767+
void dataSourceManager( QString pageName = QString( ) );
763768

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

797-
/** \brief Open one or more raster layers and add to the map
798-
* Will prompt user for file names using a file selection dialog
799-
*/
800-
void addRasterLayer();
801-
802802
//! Open a plugin layer using its provider
803803
QgsPluginLayer *addPluginLayer( const QString &uri, const QString &baseName, const QString &providerKey );
804804

805-
void addWfsLayer( const QString &uri, const QString &typeName );
806-
807-
void addAfsLayer( const QString &uri, const QString &typeName );
808-
809-
void addAmsLayer( const QString &uri, const QString &typeName );
810-
811805
void versionReplyFinished();
812806

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

1289+
/** \brief Open one or more raster layers and add to the map
1290+
* Will prompt user for file names using a file selection dialog
1291+
*/
1292+
void addRasterLayer();
1293+
12951294
void selectionChanged( QgsMapLayer *layer );
12961295

12971296
void extentChanged();
@@ -1304,20 +1303,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
13041303
// void debugHook();
13051304
//! Add a Layer Definition file
13061305
void addLayerDefinition();
1307-
//! Add a vector layer to the map
1308-
void addVectorLayer();
13091306
//! Exit Qgis
13101307
void fileExit();
1311-
//! Add a WMS layer to the map
1312-
void addWmsLayer();
1313-
//! Add a WCS layer to the map
1314-
void addWcsLayer();
1315-
//! Add a WFS layer to the map
1316-
void addWfsLayer();
1317-
//! Add a ArcGIS FeatureServer layer to the map
1318-
void addAfsLayer();
1319-
//! Add a ArcGIS MapServer layer to the map
1320-
void addAmsLayer();
13211308
//! Set map tool to Zoom out
13221309
void zoomOut();
13231310
//! Set map tool to Zoom in

0 commit comments

Comments
 (0)
Please sign in to comment.