Skip to content

Commit ff83bfe

Browse files
committed
[addlayerbutton] Added WFS, WMS and vector layers
1 parent 3cf93bc commit ff83bfe

11 files changed

+341
-131
lines changed
Lines changed: 8 additions & 0 deletions
Loading

src/app/CMakeLists.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,43 @@ INCLUDE_DIRECTORIES(SYSTEM
533533
${QT_QTUITOOLS_INCLUDE_DIR}
534534
${QSCINTILLA_INCLUDE_DIR}
535535
${QEXTSERIALPORT_INCLUDE_DIR}
536+
)
537+
INCLUDE_DIRECTORIES(
538+
../analysis/raster
539+
../analysis/openstreetmap
540+
../core
541+
../core/annotations
542+
../core/auth
543+
../core/gps
544+
../core/composer
545+
../core/dxf
546+
../core/geometry
547+
../core/metadata
548+
../core/layertree
549+
../core/providers/memory
550+
../core/raster
551+
../core/scalebar
552+
../core/symbology-ng
553+
../gui
554+
../gui/symbology-ng
555+
../gui/attributetable
556+
../gui/auth
557+
../gui/raster
558+
../gui/editorwidgets
559+
../gui/editorwidgets/core
560+
../gui/layertree
561+
../plugins
562+
../python
563+
gps
564+
ogr
565+
openstreetmap
566+
dwg
567+
dwg/libdxfrw
568+
${CMAKE_SOURCE_DIR}/src/native
569+
${CMAKE_BINARY_DIR}/src/native
570+
)
571+
INCLUDE_DIRECTORIES(SYSTEM
572+
>>>>>>> [addlayerbutton] Added WFS, WMS and vector layers
536573
${SPATIALITE_INCLUDE_DIR}
537574
${SQLITE3_INCLUDE_DIR}
538575
${PROJ_INCLUDE_DIR}

src/app/qgisapp.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,13 @@ void QgisApp::dataSourceManager()
15921592
if ( ! mDataSourceManagerDialog )
15931593
{
15941594
mDataSourceManagerDialog = new QgsDataSourceManagerDialog( this );
1595+
// Forward signals
1596+
connect( mDataSourceManagerDialog, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
1597+
this, SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
1598+
connect( mDataSourceManagerDialog, SIGNAL( addVectorLayer( QString const &, QString const &, QString const & ) ),
1599+
this, SLOT( addVectorLayer( QString const &, QString const &, QString const & ) ) );
1600+
connect( mDataSourceManagerDialog, SIGNAL( addVectorLayers( QStringList const &, QString const &, QString const & ) ),
1601+
this, SLOT( addVectorLayers( QStringList const &, QString const &, QString const & ) ) );
15951602
}
15961603
// TODO: handle docked
15971604
mDataSourceManagerDialog->exec();

src/app/qgisapp.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -168,23 +168,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
168168
QgisApp( QgisApp const & ) = delete;
169169
QgisApp &operator=( QgisApp const & ) = delete;
170170

171-
/** Add a vector layer directly without prompting user for location
172-
The caller must provide information compatible with the provider plugin
173-
using the vectorLayerPath and baseName. The provider can use these
174-
parameters in any way necessary to initialize the layer. The baseName
175-
parameter is used in the Map Legend so it should be formed in a meaningful
176-
way.
177-
*/
178-
QgsVectorLayer *addVectorLayer( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey );
179-
180-
/** \brief overloaded version of the private addLayer method that takes a list of
181-
* file names instead of prompting user with a dialog.
182-
\param enc encoding type for the layer
183-
\param dataSourceType type of ogr datasource
184-
\returns true if successfully added layer
185-
*/
186-
bool addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
187-
188171
/** Overloaded vesion of the private addRasterLayer()
189172
Method that takes a list of file names instead of prompting
190173
user with a dialog.
@@ -794,6 +777,23 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
794777
*/
795778
QgsRasterLayer *addRasterLayer( QString const &uri, QString const &baseName, QString const &providerKey );
796779

780+
/** Add a vector layer directly without prompting user for location
781+
The caller must provide information compatible with the provider plugin
782+
using the vectorLayerPath and baseName. The provider can use these
783+
parameters in any way necessary to initialize the layer. The baseName
784+
parameter is used in the Map Legend so it should be formed in a meaningful
785+
way.
786+
*/
787+
QgsVectorLayer *addVectorLayer( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey );
788+
789+
/** \brief overloaded version of the private addLayer method that takes a list of
790+
* file names instead of prompting user with a dialog.
791+
\param enc encoding type for the layer
792+
\param dataSourceType type of ogr datasource
793+
\returns true if successfully added layer
794+
*/
795+
bool addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
796+
797797
//! Open a plugin layer using its provider
798798
QgsPluginLayer *addPluginLayer( const QString &uri, const QString &baseName, const QString &providerKey );
799799

Lines changed: 81 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1+
/***************************************************************************
2+
qgsdatasourcemanagerdialog.cpp - datasource manager dialog
3+
4+
---------------------
5+
begin : May 19, 2017
6+
copyright : (C) 2017 by Alessandro Pasotti
7+
email : apasotti at itopen dot it
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
117
#include <QMessageBox>
218
#include <QListWidgetItem>
3-
#include <QMdiArea>
4-
#include <QMdiSubWindow>
519

620
#include "qgsdatasourcemanagerdialog.h"
721
#include "ui_qgsdatasourcemanagerdialog.h"
822
#include "qgsbrowserdockwidget.h"
923
#include "qgssettings.h"
1024
#include "qgsproviderregistry.h"
25+
#include "qgsopenvectorlayerdialog.h"
1126

1227
QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent ) :
1328
QDialog( parent ),
@@ -27,34 +42,47 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QWidget *parent ) :
2742
// Bind list index to the stacked dialogs
2843
connect( ui->mList, SIGNAL( currentRowChanged( int ) ), this, SLOT( setCurrentPage( int ) ) );
2944

30-
// Add the browser widget to the first stacked widget page
45+
/////////////////////////////////////////////////////////////////////////////
46+
// BROWSER Add the browser widget to the first stacked widget page
47+
3148
mBrowserWidget = new QgsBrowserDockWidget( QStringLiteral( "Browser" ), this );
3249
mBrowserWidget->setFeatures( QDockWidget::NoDockWidgetFeatures );
3350
ui->mStackedWidget->addWidget( mBrowserWidget );
3451

52+
/////////////////////////////////////////////////////////////////////////////
53+
// VECTOR Layers (completely different interface: it's not a provider)
54+
55+
QgsOpenVectorLayerDialog *ovl = new QgsOpenVectorLayerDialog( this, Qt::Widget, true );
56+
ui->mStackedWidget->addWidget( ovl );
57+
QListWidgetItem *ogrItem = new QListWidgetItem( tr( "Vector files" ), ui->mList );
58+
ogrItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddOgrLayer.svg" ) ) );
59+
connect( ovl, &QgsOpenVectorLayerDialog::addVectorLayers, this, &QgsDataSourceManagerDialog::vectorLayersAdded );
60+
3561
// Add data provider dialogs
62+
QDialog *dlg;
3663

64+
/////////////////////////////////////////////////////////////////////////////
3765
// WMS
38-
QDialog *wmss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "wms" ), this ) );
39-
if ( !wmss )
66+
67+
dlg = providerDialog( QStringLiteral( "wms" ), tr( "WMS" ), QStringLiteral( "/mActionAddWmsLayer.svg" ) );
68+
if ( dlg )
4069
{
41-
QMessageBox::warning( this, tr( "WMS" ), tr( "Cannot get WMS select dialog from provider." ) );
70+
// Forward
71+
connect( dlg, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
72+
this, SLOT( rasterLayerAdded( QString const &, QString const &, QString const & ) ) );
4273
}
43-
else
74+
75+
/////////////////////////////////////////////////////////////////////////////
76+
// WFS
77+
78+
dlg = providerDialog( QStringLiteral( "WFS" ), tr( "WFS" ), QStringLiteral( "/mActionAddWfsLayer.svg" ) );
79+
if ( dlg )
4480
{
45-
connect( wmss, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
46-
qApp, SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
47-
//wmss->exec();
48-
wmss->setWindowFlags( Qt::Widget );
49-
QMdiArea *wmsMdi = new QMdiArea( this );
50-
QMdiSubWindow *wmsSub;
51-
wmsMdi->setViewMode( QMdiArea::TabbedView );
52-
wmsSub = wmsMdi->addSubWindow( wmss );
53-
wmsSub->show();
54-
ui->mStackedWidget->addWidget( wmsMdi );
55-
mDialogs.append( wmss ); // TODO: rm
56-
QListWidgetItem *wmsItem = new QListWidgetItem( tr( "WMS" ), ui->mList );
57-
wmsItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddWmsLayer.svg" ) ) );
81+
// 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,
84+
this, [ = ]( const QString & vectorLayerPath, const QString & baseName )
85+
{ this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "WFS" ) ); } );
5886
}
5987

6088
}
@@ -66,5 +94,38 @@ QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()
6694

6795
void QgsDataSourceManagerDialog::setCurrentPage( int index )
6896
{
97+
// TODO: change window title according to the active page
6998
ui->mStackedWidget->setCurrentIndex( index );
7099
}
100+
101+
void QgsDataSourceManagerDialog::rasterLayerAdded( const QString &uri, const QString &baseName, const QString &providerKey )
102+
{
103+
emit( addRasterLayer( uri, baseName, providerKey ) );
104+
}
105+
106+
void QgsDataSourceManagerDialog::vectorLayerAdded( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey )
107+
{
108+
emit( addVectorLayer( vectorLayerPath, baseName, providerKey ) );
109+
}
110+
111+
void QgsDataSourceManagerDialog::vectorLayersAdded( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType )
112+
{
113+
emit addVectorLayers( layerQStringList, enc, dataSourceType );
114+
}
115+
116+
QDialog *QgsDataSourceManagerDialog::providerDialog( const QString providerKey, const QString providerName, const QString icon )
117+
{
118+
QDialog *dlg = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( providerKey, this, Qt::Widget ) );
119+
if ( !dlg )
120+
{
121+
QMessageBox::warning( this, providerName, tr( "Cannot get %1 select dialog from provider %2." ).arg( providerName, providerKey ) );
122+
return nullptr;
123+
}
124+
else
125+
{
126+
ui->mStackedWidget->addWidget( dlg );
127+
QListWidgetItem *wmsItem = new QListWidgetItem( providerName, ui->mList );
128+
wmsItem->setIcon( QgsApplication::getThemeIcon( icon ) );
129+
return dlg;
130+
}
131+
}

src/app/qgsdatasourcemanagerdialog.h

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1+
/***************************************************************************
2+
qgsdatasourcemanagerdialog.h - datasource manager dialog
3+
4+
---------------------
5+
begin : May 19, 2017
6+
copyright : (C) 2017 by Alessandro Pasotti
7+
email : apasotti at itopen dot it
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
117
#ifndef QGSDATASOURCEMANAGERDIALOG_H
218
#define QGSDATASOURCEMANAGERDIALOG_H
319

420
#include <QList>
521
#include <QDialog>
622
class QgsBrowserDockWidget;
23+
class QgsRasterLayer;
724

825

926
namespace Ui
@@ -20,12 +37,27 @@ class QgsDataSourceManagerDialog : public QDialog
2037
~QgsDataSourceManagerDialog();
2138

2239
public slots:
40+
41+
//! Sync current page with the leftbar list
2342
void setCurrentPage( int index );
2443

44+
//! For signal forwarding to QgisApp
45+
void rasterLayerAdded( QString const &uri, QString const &baseName, QString const &providerKey );
46+
void vectorLayerAdded( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey );
47+
void vectorLayersAdded( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
48+
49+
signals:
50+
//! For signal forwarding to QgisApp
51+
void addRasterLayer( QString const &uri, QString const &baseName, QString const &providerKey );
52+
void addVectorLayer( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey );
53+
void addWfsLayer( const QString &uri, const QString &typeName );
54+
void addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
55+
2556
private:
57+
//! Return the dialog from the provider
58+
QDialog *providerDialog( QString const providerKey, QString const providerName, QString const icon );
2659
Ui::QgsDataSourceManagerDialog *ui;
2760
QgsBrowserDockWidget *mBrowserWidget = nullptr;
28-
QList<QDialog *> mDialogs;
2961
};
3062

3163
#endif // QGSDATASOURCEMANAGERDIALOG_H

src/providers/wfs/qgswfssourceselect.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,19 @@ QgsWFSSourceSelect::QgsWFSSourceSelect( QWidget *parent, Qt::WindowFlags fl, boo
5252
: QDialog( parent, fl )
5353
, mCapabilities( nullptr )
5454
, mSQLComposerDialog( nullptr )
55+
, mEmbeddedMode( embeddedMode )
5556
{
5657
setupUi( this );
5758

58-
if ( embeddedMode )
59+
if ( mEmbeddedMode || ( Qt::Widget == fl ) )
5960
{
60-
buttonBox->button( QDialogButtonBox::Close )->hide();
61+
// For some osbscure reson hiding does not work!
62+
// buttonBox->button( QDialogButtonBox::Close )->hide();
63+
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
64+
mHoldDialogOpen->setHidden( true );
65+
mHoldDialogOpen->hide();
66+
// Set this in any event, to prevent auto-close
67+
mEmbeddedMode = true;
6168
}
6269

6370
mAddButton = new QPushButton( tr( "&Add" ) );
@@ -400,7 +407,7 @@ void QgsWFSSourceSelect::addLayer()
400407
emit addWfsLayer( mUri, layerName );
401408
}
402409

403-
if ( !mHoldDialogOpen->isChecked() )
410+
if ( !( mHoldDialogOpen->isChecked() || mEmbeddedMode ) )
404411
{
405412
accept();
406413
}

src/providers/wfs/qgswfssourceselect.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
7272
QgsWfsCapabilities::Capabilities mCaps;
7373
QModelIndex mSQLIndex;
7474
QgsSQLComposerDialog *mSQLComposerDialog = nullptr;
75+
//! Embedded mode, without 'Close'
76+
bool mEmbeddedMode;
7577

7678
/** Returns the best suited CRS from a set of authority ids
7779
1. project CRS if contained in the set

src/providers/wms/qgswmssourceselect.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#include <QPicture>
5252
#include <QUrl>
5353
#include <QValidator>
54-
5554
#include <QNetworkRequest>
5655
#include <QNetworkReply>
5756

@@ -64,9 +63,11 @@ QgsWMSSourceSelect::QgsWMSSourceSelect( QWidget *parent, Qt::WindowFlags fl, boo
6463
{
6564
setupUi( this );
6665

67-
if ( mEmbeddedMode )
66+
if ( mEmbeddedMode || ( Qt::Widget == fl ) )
6867
{
69-
buttonBox->button( QDialogButtonBox::Close )->hide();
68+
// For some osbscure reson hiding does not work!
69+
// buttonBox->button( QDialogButtonBox::Close )->hide();
70+
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
7071
}
7172

7273
mAddButton = new QPushButton( tr( "&Add" ) );

0 commit comments

Comments
 (0)