Skip to content

Commit

Permalink
[addlayerbutton] Added WFS, WMS and vector layers
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jun 2, 2017
1 parent 3cf93bc commit ff83bfe
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 131 deletions.
8 changes: 8 additions & 0 deletions images/themes/default/mActionDataSourceManager.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,43 @@ INCLUDE_DIRECTORIES(SYSTEM
${QT_QTUITOOLS_INCLUDE_DIR}
${QSCINTILLA_INCLUDE_DIR}
${QEXTSERIALPORT_INCLUDE_DIR}
)
INCLUDE_DIRECTORIES(
../analysis/raster
../analysis/openstreetmap
../core
../core/annotations
../core/auth
../core/gps
../core/composer
../core/dxf
../core/geometry
../core/metadata
../core/layertree
../core/providers/memory
../core/raster
../core/scalebar
../core/symbology-ng
../gui
../gui/symbology-ng
../gui/attributetable
../gui/auth
../gui/raster
../gui/editorwidgets
../gui/editorwidgets/core
../gui/layertree
../plugins
../python
gps
ogr
openstreetmap
dwg
dwg/libdxfrw
${CMAKE_SOURCE_DIR}/src/native
${CMAKE_BINARY_DIR}/src/native
)
INCLUDE_DIRECTORIES(SYSTEM
>>>>>>> [addlayerbutton] Added WFS, WMS and vector layers
${SPATIALITE_INCLUDE_DIR}
${SQLITE3_INCLUDE_DIR}
${PROJ_INCLUDE_DIR}
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,13 @@ void QgisApp::dataSourceManager()
if ( ! mDataSourceManagerDialog )
{
mDataSourceManagerDialog = new QgsDataSourceManagerDialog( this );
// Forward signals
connect( mDataSourceManagerDialog, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
this, SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
connect( mDataSourceManagerDialog, SIGNAL( addVectorLayer( QString const &, QString const &, QString const & ) ),
this, SLOT( addVectorLayer( QString const &, QString const &, QString const & ) ) );
connect( mDataSourceManagerDialog, SIGNAL( addVectorLayers( QStringList const &, QString const &, QString const & ) ),
this, SLOT( addVectorLayers( QStringList const &, QString const &, QString const & ) ) );
}
// TODO: handle docked
mDataSourceManagerDialog->exec();
Expand Down
34 changes: 17 additions & 17 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
QgisApp( QgisApp const & ) = delete;
QgisApp &operator=( QgisApp const & ) = delete;

/** Add a vector layer directly without prompting user for location
The caller must provide information compatible with the provider plugin
using the vectorLayerPath and baseName. The provider can use these
parameters in any way necessary to initialize the layer. The baseName
parameter is used in the Map Legend so it should be formed in a meaningful
way.
*/
QgsVectorLayer *addVectorLayer( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey );

/** \brief overloaded version of the private addLayer method that takes a list of
* file names instead of prompting user with a dialog.
\param enc encoding type for the layer
\param dataSourceType type of ogr datasource
\returns true if successfully added layer
*/
bool addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );

/** Overloaded vesion of the private addRasterLayer()
Method that takes a list of file names instead of prompting
user with a dialog.
Expand Down Expand Up @@ -794,6 +777,23 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
QgsRasterLayer *addRasterLayer( QString const &uri, QString const &baseName, QString const &providerKey );

/** Add a vector layer directly without prompting user for location
The caller must provide information compatible with the provider plugin
using the vectorLayerPath and baseName. The provider can use these
parameters in any way necessary to initialize the layer. The baseName
parameter is used in the Map Legend so it should be formed in a meaningful
way.
*/
QgsVectorLayer *addVectorLayer( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey );

/** \brief overloaded version of the private addLayer method that takes a list of
* file names instead of prompting user with a dialog.
\param enc encoding type for the layer
\param dataSourceType type of ogr datasource
\returns true if successfully added layer
*/
bool addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );

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

Expand Down
101 changes: 81 additions & 20 deletions src/app/qgsdatasourcemanagerdialog.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
/***************************************************************************
qgsdatasourcemanagerdialog.cpp - datasource manager dialog
---------------------
begin : May 19, 2017
copyright : (C) 2017 by Alessandro Pasotti
email : apasotti at itopen dot it
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include <QMessageBox>
#include <QListWidgetItem>
#include <QMdiArea>
#include <QMdiSubWindow>

#include "qgsdatasourcemanagerdialog.h"
#include "ui_qgsdatasourcemanagerdialog.h"
#include "qgsbrowserdockwidget.h"
#include "qgssettings.h"
#include "qgsproviderregistry.h"
#include "qgsopenvectorlayerdialog.h"

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

// Add the browser widget to the first stacked widget page
/////////////////////////////////////////////////////////////////////////////
// BROWSER Add the browser widget to the first stacked widget page

mBrowserWidget = new QgsBrowserDockWidget( QStringLiteral( "Browser" ), this );
mBrowserWidget->setFeatures( QDockWidget::NoDockWidgetFeatures );
ui->mStackedWidget->addWidget( mBrowserWidget );

/////////////////////////////////////////////////////////////////////////////
// VECTOR Layers (completely different interface: it's not a provider)

QgsOpenVectorLayerDialog *ovl = new QgsOpenVectorLayerDialog( this, Qt::Widget, true );
ui->mStackedWidget->addWidget( ovl );
QListWidgetItem *ogrItem = new QListWidgetItem( tr( "Vector files" ), ui->mList );
ogrItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddOgrLayer.svg" ) ) );
connect( ovl, &QgsOpenVectorLayerDialog::addVectorLayers, this, &QgsDataSourceManagerDialog::vectorLayersAdded );

// Add data provider dialogs
QDialog *dlg;

/////////////////////////////////////////////////////////////////////////////
// WMS
QDialog *wmss = dynamic_cast<QDialog *>( QgsProviderRegistry::instance()->createSelectionWidget( QStringLiteral( "wms" ), this ) );
if ( !wmss )

dlg = providerDialog( QStringLiteral( "wms" ), tr( "WMS" ), QStringLiteral( "/mActionAddWmsLayer.svg" ) );
if ( dlg )
{
QMessageBox::warning( this, tr( "WMS" ), tr( "Cannot get WMS select dialog from provider." ) );
// Forward
connect( dlg, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
this, SLOT( rasterLayerAdded( QString const &, QString const &, QString const & ) ) );
}
else

/////////////////////////////////////////////////////////////////////////////
// WFS

dlg = providerDialog( QStringLiteral( "WFS" ), tr( "WFS" ), QStringLiteral( "/mActionAddWfsLayer.svg" ) );
if ( dlg )
{
connect( wmss, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
qApp, SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
//wmss->exec();
wmss->setWindowFlags( Qt::Widget );
QMdiArea *wmsMdi = new QMdiArea( this );
QMdiSubWindow *wmsSub;
wmsMdi->setViewMode( QMdiArea::TabbedView );
wmsSub = wmsMdi->addSubWindow( wmss );
wmsSub->show();
ui->mStackedWidget->addWidget( wmsMdi );
mDialogs.append( wmss ); // TODO: rm
QListWidgetItem *wmsItem = new QListWidgetItem( tr( "WMS" ), ui->mList );
wmsItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddWmsLayer.svg" ) ) );
// 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,
this, [ = ]( const QString & vectorLayerPath, const QString & baseName )
{ this->vectorLayerAdded( vectorLayerPath, baseName, QStringLiteral( "WFS" ) ); } );
}

}
Expand All @@ -66,5 +94,38 @@ QgsDataSourceManagerDialog::~QgsDataSourceManagerDialog()

void QgsDataSourceManagerDialog::setCurrentPage( int index )
{
// TODO: change window title according to the active page
ui->mStackedWidget->setCurrentIndex( index );
}

void QgsDataSourceManagerDialog::rasterLayerAdded( const QString &uri, const QString &baseName, const QString &providerKey )
{
emit( addRasterLayer( uri, baseName, providerKey ) );
}

void QgsDataSourceManagerDialog::vectorLayerAdded( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey )
{
emit( addVectorLayer( vectorLayerPath, baseName, providerKey ) );
}

void QgsDataSourceManagerDialog::vectorLayersAdded( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType )
{
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 ) );
if ( !dlg )
{
QMessageBox::warning( this, providerName, tr( "Cannot get %1 select dialog from provider %2." ).arg( providerName, providerKey ) );
return nullptr;
}
else
{
ui->mStackedWidget->addWidget( dlg );
QListWidgetItem *wmsItem = new QListWidgetItem( providerName, ui->mList );
wmsItem->setIcon( QgsApplication::getThemeIcon( icon ) );
return dlg;
}
}
34 changes: 33 additions & 1 deletion src/app/qgsdatasourcemanagerdialog.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
/***************************************************************************
qgsdatasourcemanagerdialog.h - datasource manager dialog
---------------------
begin : May 19, 2017
copyright : (C) 2017 by Alessandro Pasotti
email : apasotti at itopen dot it
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSDATASOURCEMANAGERDIALOG_H
#define QGSDATASOURCEMANAGERDIALOG_H

#include <QList>
#include <QDialog>
class QgsBrowserDockWidget;
class QgsRasterLayer;


namespace Ui
Expand All @@ -20,12 +37,27 @@ class QgsDataSourceManagerDialog : public QDialog
~QgsDataSourceManagerDialog();

public slots:

//! Sync current page with the leftbar list
void setCurrentPage( int index );

//! For signal forwarding to QgisApp
void rasterLayerAdded( QString const &uri, QString const &baseName, QString const &providerKey );
void vectorLayerAdded( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey );
void vectorLayersAdded( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );

signals:
//! 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 addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );

private:
//! Return the dialog from the provider
QDialog *providerDialog( QString const providerKey, QString const providerName, QString const icon );
Ui::QgsDataSourceManagerDialog *ui;
QgsBrowserDockWidget *mBrowserWidget = nullptr;
QList<QDialog *> mDialogs;
};

#endif // QGSDATASOURCEMANAGERDIALOG_H
13 changes: 10 additions & 3 deletions src/providers/wfs/qgswfssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@ QgsWFSSourceSelect::QgsWFSSourceSelect( QWidget *parent, Qt::WindowFlags fl, boo
: QDialog( parent, fl )
, mCapabilities( nullptr )
, mSQLComposerDialog( nullptr )
, mEmbeddedMode( embeddedMode )
{
setupUi( this );

if ( embeddedMode )
if ( mEmbeddedMode || ( Qt::Widget == fl ) )
{
buttonBox->button( QDialogButtonBox::Close )->hide();
// For some osbscure reson hiding does not work!
// buttonBox->button( QDialogButtonBox::Close )->hide();
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
mHoldDialogOpen->setHidden( true );
mHoldDialogOpen->hide();
// Set this in any event, to prevent auto-close
mEmbeddedMode = true;
}

mAddButton = new QPushButton( tr( "&Add" ) );
Expand Down Expand Up @@ -400,7 +407,7 @@ void QgsWFSSourceSelect::addLayer()
emit addWfsLayer( mUri, layerName );
}

if ( !mHoldDialogOpen->isChecked() )
if ( !( mHoldDialogOpen->isChecked() || mEmbeddedMode ) )
{
accept();
}
Expand Down
2 changes: 2 additions & 0 deletions src/providers/wfs/qgswfssourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase
QgsWfsCapabilities::Capabilities mCaps;
QModelIndex mSQLIndex;
QgsSQLComposerDialog *mSQLComposerDialog = nullptr;
//! Embedded mode, without 'Close'
bool mEmbeddedMode;

/** Returns the best suited CRS from a set of authority ids
1. project CRS if contained in the set
Expand Down
7 changes: 4 additions & 3 deletions src/providers/wms/qgswmssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#include <QPicture>
#include <QUrl>
#include <QValidator>

#include <QNetworkRequest>
#include <QNetworkReply>

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

if ( mEmbeddedMode )
if ( mEmbeddedMode || ( Qt::Widget == fl ) )
{
buttonBox->button( QDialogButtonBox::Close )->hide();
// For some osbscure reson hiding does not work!
// buttonBox->button( QDialogButtonBox::Close )->hide();
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
}

mAddButton = new QPushButton( tr( "&Add" ) );
Expand Down
Loading

0 comments on commit ff83bfe

Please sign in to comment.