Skip to content
Permalink
Browse files

Generic QgsDataSourceURI, WMS provider adapted to QgsDataSourceURI, e…

…nabled WMS drag-and-drop from browser
  • Loading branch information
blazek committed Jun 14, 2012
1 parent b97b405 commit 002384bd7fe2202ee1221b778a74b5539aea7c33
@@ -35,15 +35,10 @@ public:
bool loadDefaultStyleFlag = true );

/** \brief [ data provider interface ] Constructor in provider mode */
QgsRasterLayer( int dummy,
const QString & baseName = QString(),
const QString & path = QString(),
const QString & providerLib = QString(),
const QStringList & layers = QStringList(),
const QStringList & styles = QStringList(),
const QString & format = QString(),
const QString & crs = QString());

QgsRasterLayer( const QString & uri,
const QString & baseName,
const QString & providerKey,
bool loadDefaultStyleFlag = true );

/** \brief The destructor */
~QgsRasterLayer();
@@ -195,11 +190,7 @@ public:
QString redBandName();

/** [ data provider interface ] Set the data provider */
void setDataProvider( const QString & provider,
const QStringList & layers,
const QStringList & styles,
const QString & format,
const QString & crs );
void setDataProvider( const QString & provider );

/** \brief Mutator for drawing style */
void setDrawingStyle( const DrawingStyle & theDrawingStyle );
@@ -46,7 +46,7 @@ class QgisInterface : QObject
//! Add a raster layer given a raster layer file name
virtual QgsRasterLayer* addRasterLayer(QString rasterLayerPath, QString baseName = QString())=0;
//! Add a WMS layer
virtual QgsRasterLayer* addRasterLayer(const QString& url, const QString& layerName, const QString& providerKey, const QStringList& layers, const QStringList& styles, const QString& format, const QString& crs) = 0;
virtual QgsRasterLayer* addRasterLayer(const QString& uri, const QString& baseName, const QString& providerKey) = 0;

//! Add a project
virtual bool addProject(QString theProject)=0;
@@ -753,7 +753,7 @@ void QgisApp::dropEvent( QDropEvent *event )
}
else if ( u.layerType == "raster" )
{
addRasterLayer( u.uri, u.name, u.providerKey, QStringList(), QStringList(), QString(), QString() );
addRasterLayer( u.uri, u.name, u.providerKey );
}
}
}
@@ -2632,10 +2632,8 @@ void QgisApp::addWmsLayer()
QMessageBox::warning( this, tr( "WMS" ), tr( "Cannot get WMS select dialog from provider." ) );
return;
}
connect( wmss , SIGNAL( addRasterLayer( QString const &, QString const &, QString const &, QStringList const &, QStringList const &, QString const &,
QString const & ) ),
this , SLOT( addRasterLayer( QString const &, QString const &, QString const &, QStringList const &, QStringList const &, QString const &,
QString const & ) ) );
connect( wmss , SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
this , SLOT( addRasterLayer( QString const &, QString const &, QString const & ) ) );
wmss->exec();
delete wmss;
}
@@ -6813,22 +6811,17 @@ QgsRasterLayer* QgisApp::addRasterLayer( QString const & rasterFile, QString con

/** Add a raster layer directly without prompting user for location
The caller must provide information compatible with the provider plugin
using the rasterLayerPath and baseName. The provider can use these
using the uri 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.
\note Copied from the equivalent addVectorLayer function in this file
TODO Make it work for rasters specifically.
*/
QgsRasterLayer* QgisApp::addRasterLayer(
QString const &rasterLayerPath,
QString const &uri,
QString const &baseName,
QString const &providerKey,
QStringList const & layers,
QStringList const & styles,
QString const &format,
QString const &crs )
QString const &providerKey )
{
QgsDebugMsg( "about to get library for " + providerKey );

@@ -6839,42 +6832,20 @@ QgsRasterLayer* QgisApp::addRasterLayer(

mMapCanvas->freeze();

// Let render() do its own cursor management
// QApplication::setOverrideCursor(Qt::WaitCursor);

// create the layer
QgsRasterLayer *layer;
/* Eliminate the need to instantiate the layer based on provider type.
The caller is responsible for cobbling together the needed information to
open the layer
*/
QgsDebugMsg( "Creating new raster layer using " + rasterLayerPath
+ " with baseName of " + baseName
+ " and layer list of " + layers.join( ", " )
+ " and style list of " + styles.join( ", " )
+ " and format of " + format
+ " and providerKey of " + providerKey
+ " and CRS of " + crs );
QgsDebugMsg( "Creating new raster layer using " + uri
+ " with baseName of " + baseName );

// TODO: Remove the 0 when the raster layer becomes a full provider gateway.
layer = new QgsRasterLayer( 0, rasterLayerPath, baseName, providerKey, layers, styles, format, crs );
layer = new QgsRasterLayer( uri, baseName, providerKey );

QgsDebugMsg( "Constructed new layer." );

if ( layer && shouldAskUserForGDALSublayers( layer ) )
{
askUserForGDALSublayers( layer );

// The first layer loaded is not useful in that case. The user can select it in
// the list if he wants to load it.
delete layer;
}
else if ( layer && layer->isValid() )
if ( layer && layer->isValid() )
{
addRasterLayer( layer );

statusBar()->showMessage( mMapCanvas->extent().toString( 2 ) );

}
else
{
@@ -6889,10 +6860,6 @@ QgsRasterLayer* QgisApp::addRasterLayer(
mMapCanvas->refresh();

return layer;

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

} // QgisApp::addRasterLayer


@@ -468,16 +468,9 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
virtual bool event( QEvent * event );

/** Open a raster layer using the Raster Data Provider.
* Note this is included to support WMS layers only at this stage,
* GDAL layer support via a Provider is not yet implemented.
* \note added in 1.9
*/
QgsRasterLayer* addRasterLayer( QString const & rasterLayerPath,
QString const & baseName,
QString const & providerKey,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs );
QgsRasterLayer* addRasterLayer( QString const & uri, QString const & baseName, QString const & providerKey );

void addWfsLayer( QString uri, QString typeName );

@@ -107,10 +107,9 @@ QgsRasterLayer* QgisAppInterface::addRasterLayer( QString rasterLayerPath, QStri
return qgis->addRasterLayer( rasterLayerPath, baseName );
}

QgsRasterLayer* QgisAppInterface::addRasterLayer( const QString& url, const QString& baseName, const QString& providerKey,
const QStringList& layers, const QStringList& styles, const QString& format, const QString& crs )
QgsRasterLayer* QgisAppInterface::addRasterLayer( const QString& url, const QString& baseName, const QString& providerKey )
{
return qgis->addRasterLayer( url, baseName, providerKey, layers, styles, format, crs );
return qgis->addRasterLayer( url, baseName, providerKey );
}

bool QgisAppInterface::addProject( QString theProjectName )
@@ -64,8 +64,7 @@ class QgisAppInterface : public QgisInterface
//! Add a raster layer given its file name
QgsRasterLayer* addRasterLayer( QString rasterLayerPath, QString baseName );
//! Add a WMS layer
QgsRasterLayer* addRasterLayer( const QString& url, const QString& baseName, const QString& providerKey,
const QStringList& layers, const QStringList& styles, const QString& format, const QString& crs );
QgsRasterLayer* addRasterLayer( const QString& url, const QString& baseName, const QString& providerKey );

//! Add a project
bool addProject( QString theProjectName );
@@ -307,33 +307,7 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )
}
if ( type == QgsMapLayer::RasterLayer )
{
// This should go to WMS provider
QStringList URIParts = uri.split( "|" );
QString rasterLayerPath = URIParts.at( 0 );
QStringList layers;
QStringList styles;
QString format;
QString crs;
for ( int i = 1 ; i < URIParts.size(); i++ )
{
QString part = URIParts.at( i );
int pos = part.indexOf( "=" );
QString field = part.left( pos );
QString value = part.mid( pos + 1 );

if ( field == "layers" )
layers = value.split( "," );
if ( field == "styles" )
styles = value.split( "," );
if ( field == "format" )
format = value;
if ( field == "crs" )
crs = value;
}
QgsDebugMsg( "rasterLayerPath = " + rasterLayerPath );
QgsDebugMsg( "layers = " + layers.join( " " ) );

QgisApp::instance()->addRasterLayer( rasterLayerPath, layerItem->layerName(), providerKey, layers, styles, format, crs );
QgisApp::instance()->addRasterLayer( uri, layerItem->name(), providerKey );
}
}

@@ -413,7 +387,7 @@ void QgsBrowserDockWidget::showProperties( )
{
QgsDebugMsg( "creating raster layer" );
// should copy code from addLayer() to split uri ?
QgsRasterLayer* layer = new QgsRasterLayer( 0, layerItem->uri(), layerItem->uri(), layerItem->providerKey() );
QgsRasterLayer* layer = new QgsRasterLayer( layerItem->uri(), layerItem->uri(), layerItem->providerKey() );
if ( layer != NULL )
{
layerCrs = layer->crs();
@@ -207,33 +207,7 @@ bool QgsBrowser::layerClicked( QgsLayerItem *item )
}
if ( type == QgsMapLayer::RasterLayer )
{
// This should go to WMS provider
QStringList URIParts = uri.split( "|" );
QString rasterLayerPath = URIParts.at( 0 );
QStringList layers;
QStringList styles;
QString format;
QString crs;
for ( int i = 1 ; i < URIParts.size(); i++ )
{
QString part = URIParts.at( i );
int pos = part.indexOf( "=" );
QString field = part.left( pos );
QString value = part.mid( pos + 1 );

if ( field == "layers" )
layers = value.split( "," );
if ( field == "styles" )
styles = value.split( "," );
if ( field == "format" )
format = value;
if ( field == "crs" )
crs = value;
}
QgsDebugMsg( "rasterLayerPath = " + rasterLayerPath );
QgsDebugMsg( "layers = " + layers.join( " " ) );

mLayer = new QgsRasterLayer( 0, rasterLayerPath, "", providerKey, layers, styles, format, crs );
mLayer = new QgsRasterLayer( uri, "", providerKey );
}
}

@@ -127,11 +127,7 @@ Qt::ItemFlags QgsBrowserModel::flags( const QModelIndex & index ) const
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
if ( ptr->type() == QgsDataItem::Layer )
{
QgsLayerItem *layer = ( QgsLayerItem* ) ptr;
if ( layer->providerKey() != "wms" )
{
flags |= Qt::ItemIsDragEnabled;
}
flags |= Qt::ItemIsDragEnabled;
}
if ( ptr->acceptDrop() )
flags |= Qt::ItemIsDropEnabled;
@@ -368,7 +364,6 @@ QMimeData * QgsBrowserModel::mimeData( const QModelIndexList &indexes ) const
QgsDataItem* ptr = ( QgsDataItem* ) index.internalPointer();
if ( ptr->type() != QgsDataItem::Layer ) continue;
QgsLayerItem *layer = ( QgsLayerItem* ) ptr;
if ( layer->providerKey() == "wms" ) continue;
lst.append( QgsMimeDataUtils::Uri( layer ) );
}
}
@@ -21,6 +21,7 @@

#include <QStringList>
#include <QRegExp>
#include <QUrl>

QgsDataSourceURI::QgsDataSourceURI()
: mSSLmode( SSLprefer )
@@ -587,6 +588,36 @@ QString QgsDataSourceURI::uri() const
return theUri;
}

QByteArray QgsDataSourceURI::encodedUri() const
{
QUrl url;
foreach( QString key, mParams.uniqueKeys() )
{
foreach( QString value, mParams.values( key ) )
{
url.addQueryItem( key, value );
}
}
return url.encodedQuery();
}

void QgsDataSourceURI::setEncodedUri( const QByteArray & uri )
{
mParams.clear();
QUrl url;
url.setEncodedQuery( uri );
QPair<QString, QString> item;
foreach( item, url.queryItems() )
{
mParams.insertMulti( item.first, item.second );
}
}

void QgsDataSourceURI::setEncodedUri( const QString & uri )
{
setEncodedUri( uri.toAscii() );
}

QString QgsDataSourceURI::quotedTablename() const
{
if ( !mSchema.isEmpty() )
@@ -663,3 +694,32 @@ void QgsDataSourceURI::setSrid( QString srid )
{
mSrid = srid;
}

void QgsDataSourceURI::setParam( const QString &key, const QString &value )
{
// may be multiple
mParams.insertMulti( key, value );
}

void QgsDataSourceURI::setParam( const QString &key, const QStringList &value )
{
foreach( QString val, value )
{
mParams.insertMulti( key, val );
}
}

QString QgsDataSourceURI::param( const QString &key ) const
{
return mParams.value( key );
}

QStringList QgsDataSourceURI::params( const QString &key ) const
{
return mParams.values( key );
}

bool QgsDataSourceURI::hasParam( const QString &key ) const
{
return mParams.contains( key );
}

0 comments on commit 002384b

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