Skip to content
Permalink
Browse files

[addlayerbutton] Added WFS, WMS and vector layers

  • Loading branch information
elpaso committed Jun 2, 2017
1 parent 3cf93bc commit ff83bfe24d5c059c5531b6f6094e57bd23c58696
@@ -0,0 +1,8 @@
<svg height="24" width="24" xmlns="http://www.w3.org/2000/svg">
<g transform="matrix(1.6141779 0 0 1.6141779 -29.159575 -29.159576)">
<rect fill="#5a8c5a" height="13" rx="2.6149371" ry="2.6149368" width="13" x="19" y="19"/>
<path d="m21.6 25.499999l7.8 0" style="fill:#fff;fill-rule:evenodd;stroke:#fff;stroke-width:2.5999999;stroke-linecap:round;stroke-linejoin:round;overflow:visible"/>
<path d="m25.5 29.399999l0-7.799999" style="fill:#fff;fill-rule:evenodd;stroke:#fff;stroke-width:2.5999999;stroke-linecap:round;stroke-linejoin:round;overflow:visible"/>
<path d="m20.3 25.499999h10.4c0 0 0 0 0-2.6 0-2.599999-.65-2.599999-5.2-2.599999-4.55 0-5.2 0-5.2 2.599999 0 2.6 0 2.6 0 2.6z" fill="#fcffff" fill-rule="evenodd" opacity=".3"/>
</g>
</svg>
@@ -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}
@@ -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();
@@ -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.
@@ -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 );

@@ -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 ),
@@ -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" ) ); } );
}

}
@@ -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;
}
}
@@ -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
@@ -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
@@ -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" ) );
@@ -400,7 +407,7 @@ void QgsWFSSourceSelect::addLayer()
emit addWfsLayer( mUri, layerName );
}

if ( !mHoldDialogOpen->isChecked() )
if ( !( mHoldDialogOpen->isChecked() || mEmbeddedMode ) )
{
accept();
}
@@ -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
@@ -51,7 +51,6 @@
#include <QPicture>
#include <QUrl>
#include <QValidator>

#include <QNetworkRequest>
#include <QNetworkReply>

@@ -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" ) );

0 comments on commit ff83bfe

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