Generic QgsDataSourceURI, WMS provider adapted to QgsDataSourceURI, enabled WMS drag-and-drop from browser

This commit is contained in:
Radim Blazek 2012-06-14 11:40:07 +02:00
parent b97b4056bd
commit 002384bd7f
27 changed files with 412 additions and 479 deletions

View File

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

View File

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

View File

@ -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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,10 +21,16 @@
#include "qgis.h"
#include <QMap>
/** \ingroup core
* Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.
* This structure stores the database connection information, including host, database,
* user name, password, schema, password, and sql where clause
*
* Extended to support generic params so that it may be used by any provider.
* The 2 modes (the old - RDMS specific and the new generic) may not yet be mixed.
* (Radim Blazek 4/2012)
*/
class CORE_EXPORT QgsDataSourceURI
{
@ -38,15 +44,49 @@ class CORE_EXPORT QgsDataSourceURI
//! constructor which parses input URI
QgsDataSourceURI( QString uri );
//! constructor which parses input encoded URI (generic mode)
// \note added in 1.9
QgsDataSourceURI( const QByteArray & uri );
//! return connection part of URI
QString connectionInfo() const;
//! return complete uri
QString uri() const;
//! return complete encoded uri (generic mode)
// \note added in 1.9
QByteArray encodedUri() const;
//! set complete encoded uri (generic mode)
// \note added in 1.9
void setEncodedUri( const QByteArray & uri );
//! set complete encoded uri (generic mode)
// \note added in 1.9
void setEncodedUri( const QString & uri );
//! quoted table name
QString quotedTablename() const;
//! Set generic param (generic mode)
// \note if key exists, another is inserted
// \note added in 1.9
void setParam( const QString &key, const QString &value );
void setParam( const QString &key, const QStringList &value );
//! Get generic param (generic mode)
// \note added in 1.9
QString param( const QString &key ) const;
//! Get multiple generic param (generic mode)
// \note added in 1.9
QStringList params( const QString &key ) const;
//! Test if param exists (generic mode)
// \note added in 1.9
bool hasParam( const QString &key ) const;
//! Set all connection related members at once
//! \note This optional sslmode parameter has been added in version 1.1
void setConnection( const QString& aHost,
@ -163,6 +203,8 @@ class CORE_EXPORT QgsDataSourceURI
QGis::WkbType mWkbType;
//! SRID or a null string if not specified
QString mSrid;
//! Generic params store
QMap<QString, QString> mParams;
};
#endif //QGSDATASOURCEURI_H

View File

@ -165,6 +165,7 @@ bool QgsMapLayer::readXML( const QDomNode& layer_node )
mne = mnl.toElement();
mDataSource = mne.text();
// TODO: this should go to providers
if ( provider == "spatialite" )
{
QgsDataSourceURI uri( mDataSource );
@ -192,6 +193,82 @@ bool QgsMapLayer::readXML( const QDomNode& layer_node )
urlDest.setQueryItems( urlSource.queryItems() );
mDataSource = QString::fromAscii( urlDest.toEncoded() );
}
else if ( provider == "wms" )
{
// >>> BACKWARD COMPATIBILITY < 1.9
// For project file backward compatibility we must support old format:
// 1. mode: <url>
// example: http://example.org/wms?
// 2. mode: tiled=<width>;<height>;<resolution>;<resolution>...,ignoreUrl=GetMap;GetFeatureInfo,featureCount=<count>,username=<name>,password=<password>,url=<url>
// example: tiled=256;256;0.703;0.351,url=http://example.org/tilecache?
// example: featureCount=10,http://example.org/wms?
// example: ignoreUrl=GetMap;GetFeatureInfo,username=cimrman,password=jara,url=http://example.org/wms?
// This is modified version of old QgsWmsProvider::parseUri
// The new format has always params crs,format,layers,styles and that params
// should not appear in old format url -> use them to identify version
if ( !mDataSource.contains( "crs=" ) && !mDataSource.contains( "format=" ) )
{
QgsDebugMsg( "Old WMS URI format detected -> converting to new format" );
QgsDataSourceURI uri;
if ( !mDataSource.startsWith( "http:" ) )
{
QStringList parts = mDataSource.split( "," );
QStringListIterator iter( parts );
while ( iter.hasNext() )
{
QString item = iter.next();
if ( item.startsWith( "username=" ) )
{
uri.setParam( "username", item.mid( 9 ) );
}
else if ( item.startsWith( "password=" ) )
{
uri.setParam( "password", item.mid( 9 ) );
}
else if ( item.startsWith( "tiled=" ) )
{
// in < 1.9 tiled= may apper in to variants:
// tiled=width;height - non tiled mode, specifies max width and max height
// tiled=width;height;resolutions-1;resolution2;... - tile mode
QStringList params = item.mid( 6 ).split( ";" );
if ( params.size() == 2 ) // non tiled mode
{
uri.setParam( "maxWidth", params.takeFirst() );
uri.setParam( "maxHeight", params.takeFirst() );
}
else if ( params.size() > 2 ) // tiled mode
{
// resolutions are no more needed and size limit is not used for tiles
// we have to tell to the provider however that it is tiled
uri.setParam( "tileMatrixSet", "" );
}
}
else if ( item.startsWith( "featureCount=" ) )
{
uri.setParam( "featureCount", item.mid( 13 ) );
}
else if ( item.startsWith( "url=" ) )
{
uri.setParam( "url", item.mid( 4 ) );
}
else if ( item.startsWith( "ignoreUrl=" ) )
{
uri.setParam( "ignoreUrl", item.mid( 10 ).split( ";" ) );
}
}
}
else
{
uri.setParam( "url", mDataSource );
}
mDataSource = uri.encodedUri();
// At this point, the URI is obviously incomplete, we add additional params
// in QgsRasterLayer::readXml
}
// <<< BACKWARD COMPATIBILITY < 1.9
}
else
{
mDataSource = QgsProject::instance()->readPath( mDataSource );
@ -318,6 +395,7 @@ bool QgsMapLayer::writeXML( QDomNode & layer_node, QDomDocument & document )
QString src = source();
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this );
// TODO: what about postgres, mysql and others, they should not go through writePath()
if ( vlayer && vlayer->providerType() == "spatialite" )
{
QgsDataSourceURI uri( src );

View File

@ -16,6 +16,7 @@ email : tim at linfiniti.com
***************************************************************************/
#include "qgsapplication.h"
#include "qgsdatasourceuri.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"
#include "qgsmaplayerregistry.h"
@ -89,6 +90,12 @@ typedef bool isvalidrasterfilename_t( QString const & theFileNameQString, QStrin
// doubles can take for the current system. (Yes, 20 was arbitrary.)
#define TINY_VALUE std::numeric_limits<double>::epsilon() * 20
QgsRasterLayer::QgsRasterLayer()
: QgsMapLayer( RasterLayer )
{
init();
mValid = false;
}
QgsRasterLayer::QgsRasterLayer(
QString const & path,
@ -109,18 +116,12 @@ QgsRasterLayer::QgsRasterLayer(
// TODO, call constructor with provider key for now
init();
setDataProvider( "gdal", QStringList(), QStringList(), QString(), QString(), loadDefaultStyleFlag );
setDataProvider( "gdal" );
if ( mValid && loadDefaultStyleFlag )
{
bool defaultLoadedFlag = false;
loadDefaultStyle( defaultLoadedFlag );
// I'm no sure if this should be used somehow, in pre raster-providers there was
// only mLastViewPort init after this block, nothing to do with style
//if ( defaultLoadedFlag )
//{
//return;
//}
}
return;
@ -131,15 +132,14 @@ QgsRasterLayer::QgsRasterLayer(
* @todo Rename into a general constructor when the old raster interface is retired
* parameter dummy is just there to distinguish this function signature from the old non-provider one.
*/
QgsRasterLayer::QgsRasterLayer( int dummy,
QString const & rasterLayerPath,
QString const & baseName,
QString const & providerKey,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs )
: QgsMapLayer( RasterLayer, baseName, rasterLayerPath )
QgsRasterLayer::QgsRasterLayer( const QString & uri,
const QString & baseName,
const QString & providerKey,
bool loadDefaultStyleFlag )
: QgsMapLayer( RasterLayer, baseName, uri )
// Constant that signals property not used.
, QSTRING_NOT_SET( "Not Set" )
, TRSTRING_NOT_SET( tr( "Not Set" ) )
, mStandardDeviations( 0 )
, mDataProvider( 0 )
, mEditable( false )
@ -148,27 +148,15 @@ QgsRasterLayer::QgsRasterLayer( int dummy,
, mInvertColor( false )
, mModified( false )
, mProviderKey( providerKey )
, mLayers( layers )
, mStyles( styles )
, mFormat( format )
, mCrs( crs )
, mRenderer( 0 )
{
Q_UNUSED( dummy );
QgsDebugMsg( "(8 arguments) starting. with layer list of " +
layers.join( ", " ) + " and style list of " + styles.join( ", " ) + " and format of " +
format + " and CRS of " + crs );
QgsDebugMsg( "Entered" );
init();
// if we're given a provider type, try to create and bind one to this layer
bool loadDefaultStyleFlag = false ; // ???
setDataProvider( providerKey, layers, styles, format, crs, loadDefaultStyleFlag );
setDataProvider( providerKey );
// load default style if provider is gdal and if no style was given
// this should be an argument like in the other constructor
if ( mValid && providerKey == "gdal" && layers.isEmpty() && styles.isEmpty() )
if ( mValid && providerKey == "gdal" && loadDefaultStyleFlag )
{
bool defaultLoadedFlag = false;
loadDefaultStyle( defaultLoadedFlag );
@ -188,8 +176,6 @@ QgsRasterLayer::QgsRasterLayer( int dummy,
// TODO: Connect signals from the dataprovider to the qgisapp
QgsDebugMsg( "(8 arguments) exiting." );
emit statusChanged( tr( "QgsRasterLayer created" ) );
} // QgsRasterLayer ctor
@ -2293,26 +2279,11 @@ QgsRasterDataProvider* QgsRasterLayer::loadProvider( QString theProviderKey, QSt
return myDataProvider;
}
void QgsRasterLayer::setDataProvider( QString const & provider,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs )
{
setDataProvider( provider, layers, styles, format, crs, false );
}
/** Copied from QgsVectorLayer::setDataProvider
* TODO: Make it work in the raster environment
*/
void QgsRasterLayer::setDataProvider( QString const & provider,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & theCrs,
bool loadDefaultStyleFlag )
void QgsRasterLayer::setDataProvider( QString const & provider )
{
Q_UNUSED( loadDefaultStyleFlag );
// XXX should I check for and possibly delete any pre-existing providers?
// XXX How often will that scenario occur?
@ -2320,7 +2291,6 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
mValid = false; // assume the layer is invalid until we determine otherwise
// set the layer name (uppercase first character)
if ( ! mLayerName.isEmpty() ) // XXX shouldn't this happen in parent?
{
setLayerName( mLayerName );
@ -2335,29 +2305,12 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
return;
}
if ( !mDataProvider->isValid() )
{
if ( provider != "gdal" || !layers.isEmpty() || !styles.isEmpty() || !format.isNull() || !theCrs.isNull() )
{
QgsMessageLog::logMessage( tr( "Data provider is invalid (layers: %1, styles: %2, formats: %3)" )
.arg( layers.join( ", " ) )
.arg( styles.join( ", " ) )
.arg( format ),
tr( "Raster" ) );
}
return;
}
if ( provider == "gdal" )
{
// make sure that the /vsigzip or /vsizip is added to uri, if applicable
mDataSource = mDataProvider->dataSourceUri();
}
mDataProvider->addLayers( layers, styles );
mDataProvider->setImageEncoding( format );
mDataProvider->setImageCrs( theCrs );
setNoDataValue( mDataProvider->noDataValue() );
// get the extent
@ -2390,16 +2343,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
setDrawingStyle( MultiBandColor ); //sensible default
// Setup source CRS
if ( mProviderKey == "wms" )
{
QgsCoordinateReferenceSystem crs;
crs.createFromOgcWmsCrs( theCrs );
setCrs( crs );
}
else
{
setCrs( QgsCoordinateReferenceSystem( mDataProvider->crs() ) );
}
setCrs( QgsCoordinateReferenceSystem( mDataProvider->crs() ) );
QString mySourceWkt = crs().toWkt();
@ -3168,33 +3112,42 @@ bool QgsRasterLayer::readXml( const QDomNode& layer_node )
QDomNode rpNode = layer_node.namedItem( "rasterproperties" );
// Collect sublayer names and styles
mLayers.clear();
mStyles.clear();
if ( mProviderKey == "wms" )
{
QDomElement layerElement = rpNode.firstChildElement( "wmsSublayer" );
while ( !layerElement.isNull() )
// >>> BACKWARD COMPATIBILITY < 1.9
// The old WMS URI format does not contain all the informations, we add them here.
if ( !mDataSource.contains( "crs=" ) && !mDataSource.contains( "format=" ) )
{
// TODO: sublayer visibility - post-0.8 release timeframe
QgsDebugMsg( "Old WMS URI format detected -> adding params" );
QgsDataSourceURI uri;
uri.setEncodedUri( mDataSource );
QDomElement layerElement = rpNode.firstChildElement( "wmsSublayer" );
while ( !layerElement.isNull() )
{
// TODO: sublayer visibility - post-0.8 release timeframe
// collect name for the sublayer
mLayers += layerElement.namedItem( "name" ).toElement().text();
// collect name for the sublayer
uri.setParam( "layers", layerElement.namedItem( "name" ).toElement().text() );
// collect style for the sublayer
mStyles += layerElement.namedItem( "style" ).toElement().text();
// collect style for the sublayer
uri.setParam( "styles", layerElement.namedItem( "style" ).toElement().text() );
layerElement = layerElement.nextSiblingElement( "wmsSublayer" );
layerElement = layerElement.nextSiblingElement( "wmsSublayer" );
}
// Collect format
QDomNode formatNode = rpNode.namedItem( "wmsFormat" );
uri.setParam( "format", rpNode.namedItem( "wmsFormat" ).toElement().text() );
// WMS CRS URL param should not be mixed with that assigned to the layer.
// In the old WMS URI version there was no CRS and layer crs().authid() was used.
uri.setParam( "crs", crs().authid() );
mDataSource = uri.encodedUri();
}
// Collect format
mFormat = rpNode.namedItem( "wmsFormat" ).toElement().text();
// <<< BACKWARD COMPATIBILITY < 1.9
}
mCrs = crs().authid();
// Collect CRS
setDataProvider( mProviderKey, mLayers, mStyles, mFormat, mCrs );
setDataProvider( mProviderKey );
QString theError;
bool res = readSymbology( layer_node, theError );
@ -3222,7 +3175,7 @@ bool QgsRasterLayer::readXml( const QDomNode& layer_node )
QgsDebugMsg( "data changed, reload provider" );
closeDataProvider();
init();
setDataProvider( mProviderKey, mLayers, mStyles, mFormat, mCrs );
setDataProvider( mProviderKey );
}
}
@ -3244,49 +3197,6 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum
mRenderer->writeXML( document, layerElem );
}
//is it still needed?
#if 0
if ( mProviderKey == "wms" )
{
// <rasterproperties><wmsSublayer>
for ( QStringList::const_iterator layerName = sl.begin();
layerName != sl.end();
++layerName )
{
QgsDebugMsg( QString( "<rasterproperties><wmsSublayer> %1" ).arg( layerName->toLocal8Bit().data() ) );
QDomElement sublayerElement = document.createElement( "wmsSublayer" );
// TODO: sublayer visibility - post-0.8 release timeframe
// <rasterproperties><wmsSublayer><name>
QDomElement sublayerNameElement = document.createElement( "name" );
QDomText sublayerNameText = document.createTextNode( *layerName );
sublayerNameElement.appendChild( sublayerNameText );
sublayerElement.appendChild( sublayerNameElement );
// <rasterproperties><wmsSublayer><style>
QDomElement sublayerStyleElement = document.createElement( "style" );
QDomText sublayerStyleText = document.createTextNode( *layerStyle );
sublayerStyleElement.appendChild( sublayerStyleText );
sublayerElement.appendChild( sublayerStyleElement );
rasterPropertiesElement.appendChild( sublayerElement );
// This assumes there are exactly the same number of "layerName"s as there are "layerStyle"s
++layerStyle;
}
// <rasterproperties><wmsFormat>
QDomElement formatElement = document.createElement( "wmsFormat" );
QDomText formatText =
document.createTextNode( mDataProvider->imageEncoding() );
formatElement.appendChild( formatText );
rasterPropertiesElement.appendChild( formatElement );
}
#endif //0
return true;
} // bool QgsRasterLayer::writeSymbology
@ -3471,7 +3381,7 @@ bool QgsRasterLayer::update()
QgsDebugMsg( "reload data" );
closeDataProvider();
init();
setDataProvider( mProviderKey, mLayers, mStyles, mFormat, mCrs );
setDataProvider( mProviderKey );
emit dataChanged();
}
return mValid;

View File

@ -171,6 +171,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
{
Q_OBJECT
public:
/** \brief Constructor. Provider is not set. */
QgsRasterLayer();
/** \brief This is the constructor for the RasterLayer class.
*
* The main tasks carried out by the constructor are:
@ -187,20 +190,15 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
*
* -
* */
QgsRasterLayer( const QString & path = QString::null,
QgsRasterLayer( const QString & path,
const QString & baseName = QString::null,
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();
@ -290,19 +288,8 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** \brief Initialize default values */
void init();
// For backward compatibility (Python) get rid of it once python is updated
void setDataProvider( const QString & provider,
const QStringList & layers,
const QStringList & styles,
const QString & format,
const QString & crs );
/** [ data provider interface ] Set the data provider */
void setDataProvider( const QString & provider,
const QStringList & layers,
const QStringList & styles,
const QString & format,
const QString & crs,
bool loadDefaultStyleFlag );
void setDataProvider( const QString & provider );
static QLibrary* loadProviderLibrary( QString theProviderKey );
static QgsRasterDataProvider* loadProvider( QString theProviderKey, QString theDataSource = 0 );
@ -931,13 +918,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** \brief Flag indicating if the nodatavalue is valid*/
bool mValidNoDataValue;
/** WMS parameters */
/* TODO: put everything to URI */
QStringList mLayers;
QStringList mStyles;
QString mFormat;
QString mCrs;
QgsRasterRenderer* mRenderer;
};

View File

@ -95,8 +95,7 @@ class GUI_EXPORT QgisInterface : public QObject
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& url, const QString& layerName, const QString& providerKey ) = 0;
//! Add a project
virtual bool addProject( QString theProject ) = 0;

View File

@ -15,6 +15,7 @@
* *
***************************************************************************/
#include "qgsdatasourceuri.h"
#include "qgsremoteowsbuilder.h"
#include "qgshttptransaction.h"
#include "qgslogger.h"
@ -206,7 +207,13 @@ QgsRasterLayer* QgsRemoteOWSBuilder::wmsLayerFromUrl( const QString& url, const
QgsDebugMsg( "layerList first item: " + layerList.at( 0 ) );
QgsDebugMsg( "styleList first item: " + styleList.at( 0 ) );
result = new QgsRasterLayer( 0, baseUrl, "", "wms", layerList, styleList, format, crs );
QgsDataSourceURI uri;
uri.setParam( "url", baseUrl );
uri.setParam( "format", format );
uri.setParam( "crs", crs );
uri.setParam( "layers", layerList );
uri.setParam( "styles", styleList );
result = new QgsRasterLayer( uri.encodedUri(), "", "wms" );
if ( !result->isValid() )
{
return 0;

View File

@ -154,8 +154,7 @@ void QgsGrassBrowser::addMap()
{
QgsDebugMsg( QString( "add raster: %1" ).arg( uri ) );
//mIface->addRasterLayer( uri, map );
mIface->addRasterLayer( uri, map, "grassraster", QStringList(), QStringList(),
QString(), QString() );
mIface->addRasterLayer( uri, map, "grassraster" );
}
else if ( type == QgsGrassModel::Vector )
{

View File

@ -1689,8 +1689,7 @@ void QgsGrassModule::viewOutput()
+ "/cellhd/" + map;
//mIface->addRasterLayer( uri, map );
mIface->addRasterLayer( uri, map, "grassraster", QStringList(), QStringList(),
QString(), QString() );
mIface->addRasterLayer( uri, map, "grassraster" );
}
}

View File

@ -421,8 +421,7 @@ void QgsGrassPlugin::addRaster()
name.replace( '/', ' ' );
//qGisInterface->addRasterLayer( uri, sel->map );
qGisInterface->addRasterLayer( uri, sel->map, "grassraster", QStringList(), QStringList(),
QString(), QString() );
qGisInterface->addRasterLayer( uri, sel->map, "grassraster" );
}
}

View File

@ -20,6 +20,7 @@
#include "../providers/wms/qgswmsprovider.h"
#include "qgis.h" // GEO_EPSG_CRS_ID
#include "qgsdatasourceuri.h"
#include "qgsnewhttpconnection.h"
#include "qgsproject.h"
#include "qgsproviderregistry.h"
@ -48,6 +49,7 @@ QgsWMSConnection::QgsWMSConnection( QString theConnName ) :
QStringList connStringParts;
mConnectionInfo = settings.value( key + "/url" ).toString();
mUri.setParam( "url", settings.value( key + "/url" ).toString() );
// Check for credentials and prepend to the connection info
QString username = settings.value( credentialsKey + "/username" ).toString();
@ -61,6 +63,8 @@ QgsWMSConnection::QgsWMSConnection( QString theConnName ) :
password = QInputDialog::getText( 0, tr( "WMS Password for %1" ).arg( mConnName ), "Password", QLineEdit::Password );
}
mConnectionInfo = "username=" + username + ",password=" + password + ",url=" + mConnectionInfo;
mUri.setParam( "username", username );
mUri.setParam( "password", password );
}
bool ignoreGetMap = settings.value( key + "/ignoreGetMapURI", false ).toBool();
@ -75,24 +79,28 @@ QgsWMSConnection::QgsWMSConnection( QString theConnName ) :
{
connArgs += delim + "GetMap";
delim = ";";
mUri.setParam( "IgnoreGetMapUrl", "1" );
}
if ( ignoreGetFeatureInfo )
{
connArgs += delim + "GetFeatureInfo";
delim = ";";
mUri.setParam( "IgnoreGetFeatureInfoUrl", "1" );
}
if ( ignoreAxisOrientation )
{
connArgs += delim + "AxisOrientation";
delim = ";";
mUri.setParam( "IgnoreAxisOrientation", "1" );
}
if ( invertAxisOrientation )
{
connArgs += delim + "InvertAxisOrientation";
delim = ";";
mUri.setParam( "InvertAxisOrientation", "1" );
}
if( !connArgs.isEmpty() )
@ -122,7 +130,12 @@ QString QgsWMSConnection::connectionInfo()
return mConnectionInfo;
}
QgsWmsProvider *QgsWMSConnection::provider()
QgsDataSourceURI QgsWMSConnection::uri()
{
return mUri;
}
QgsWmsProvider * QgsWMSConnection::provider( )
{
// TODO: Create and bind to data provider
@ -130,7 +143,7 @@ QgsWmsProvider *QgsWMSConnection::provider()
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
QgsWmsProvider *wmsProvider =
( QgsWmsProvider* ) pReg->provider( "wms", mConnectionInfo );
( QgsWmsProvider* ) pReg->provider( "wms", mUri.encodedUri() );
return wmsProvider;
}

View File

@ -17,6 +17,7 @@
#ifndef QGSWMSCONNECTION_H
#define QGSWMSCONNECTION_H
#include "qgsdatasourceuri.h"
#include "qgisgui.h"
//#include "qgscontexthelp.h"
@ -56,6 +57,8 @@ class QgsWMSConnection : public QObject
QString connectionInfo();
QString mConnName;
QString mConnectionInfo;
QgsDataSourceURI uri();
QgsDataSourceURI mUri;
};

View File

@ -16,6 +16,7 @@
#include "qgslogger.h"
#include "qgsdatasourceuri.h"
#include "qgswmsconnection.h"
#include "qgswmssourceselect.h"
@ -43,8 +44,8 @@ QVector<QgsDataItem*> QgsWMSConnectionItem::createChildren()
if ( !wmsProvider )
return children;
QString mConnInfo = connection.connectionInfo();
QgsDebugMsg( "mConnInfo = " + mConnInfo );
QgsDataSourceURI uri = connection.uri();
QgsDebugMsg( "uri = " + uri.encodedUri() );
// Attention: supportedLayers() gives tree leafes, not top level
if ( !wmsProvider->supportedLayers( mLayerProperties ) )
@ -66,7 +67,7 @@ QVector<QgsDataItem*> QgsWMSConnectionItem::createChildren()
QgsDebugMsg( QString::number( layerProperty.orderId ) + " " + layerProperty.name + " " + layerProperty.title );
QString pathName = layerProperty.name.isEmpty() ? QString::number( layerProperty.orderId ) : layerProperty.name;
QgsWMSLayerItem * layer = new QgsWMSLayerItem( this, layerProperty.title, mPath + "/" + pathName, mCapabilitiesProperty, mConnInfo, layerProperty );
QgsWMSLayerItem * layer = new QgsWMSLayerItem( this, layerProperty.title, mPath + "/" + pathName, mCapabilitiesProperty, uri, layerProperty );
children.append( layer );
}
@ -119,14 +120,15 @@ void QgsWMSConnectionItem::deleteConnection()
// ---------------------------------------------------------------------------
QgsWMSLayerItem::QgsWMSLayerItem( QgsDataItem* parent, QString name, QString path, QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperty )
QgsWMSLayerItem::QgsWMSLayerItem( QgsDataItem* parent, QString name, QString path, QgsWmsCapabilitiesProperty capabilitiesProperty, QgsDataSourceURI dataSourceUri, QgsWmsLayerProperty layerProperty )
: QgsLayerItem( parent, name, path, QString(), QgsLayerItem::Raster, "wms" ),
mCapabilitiesProperty( capabilitiesProperty ),
mConnInfo( connInfo ),
mDataSourceUri( dataSourceUri ),
mLayerProperty( layerProperty )
//mProviderKey ("wms"),
//mLayerType ( QgsLayerItem::Raster )
{
QgsDebugMsg( "uri = " + mDataSourceUri.encodedUri() );
mUri = createUri();
// Populate everything, it costs nothing, all info about layers is collected
foreach( QgsWmsLayerProperty layerProperty, mLayerProperty.layer )
@ -134,7 +136,7 @@ QgsWMSLayerItem::QgsWMSLayerItem( QgsDataItem* parent, QString name, QString pat
// Attention, the name may be empty
QgsDebugMsg( QString::number( layerProperty.orderId ) + " " + layerProperty.name + " " + layerProperty.title );
QString pathName = layerProperty.name.isEmpty() ? QString::number( layerProperty.orderId ) : layerProperty.name;
QgsWMSLayerItem * layer = new QgsWMSLayerItem( this, layerProperty.title, mPath + "/" + pathName, mCapabilitiesProperty, mConnInfo, layerProperty );
QgsWMSLayerItem * layer = new QgsWMSLayerItem( this, layerProperty.title, mPath + "/" + pathName, mCapabilitiesProperty, mDataSourceUri, layerProperty );
mChildren.append( layer );
}
@ -151,28 +153,16 @@ QgsWMSLayerItem::~QgsWMSLayerItem()
QString QgsWMSLayerItem::createUri()
{
QString uri;
if ( mLayerProperty.name.isEmpty() )
return uri; // layer collection
QString rasterLayerPath = mConnInfo;
QString baseName = mLayerProperty.name;
return ""; // layer collection
// Number of styles must match number of layers
QStringList layers;
layers << mLayerProperty.name;
QStringList styles;
if ( mLayerProperty.style.size() > 0 )
{
styles.append( mLayerProperty.style[0].name );
}
else
{
styles << ""; // TODO: use loadDefaultStyleFlag
}
mDataSourceUri.setParam( "layers", mLayerProperty.name );
QString style = mLayerProperty.style.size() > 0 ? mLayerProperty.style[0].name : "";
mDataSourceUri.setParam( "styles", style );
QString format;
// get first supporte by qt and server
// get first supported by qt and server
QVector<QgsWmsSupportedFormat> formats = QgsWmsProvider::supportedFormats();
foreach( QgsWmsSupportedFormat f, formats )
{
@ -182,6 +172,8 @@ QString QgsWMSLayerItem::createUri()
break;
}
}
mDataSourceUri.setParam( "format", format );
QString crs;
// get first known if possible
QgsCoordinateReferenceSystem testCrs;
@ -198,9 +190,10 @@ QString QgsWMSLayerItem::createUri()
{
crs = mLayerProperty.crs[0];
}
uri = rasterLayerPath + "|layers=" + layers.join( "," ) + "|styles=" + styles.join( "," ) + "|format=" + format + "|crs=" + crs;
mDataSourceUri.setParam( "crs", crs );
//uri = rasterLayerPath + "|layers=" + layers.join( "," ) + "|styles=" + styles.join( "," ) + "|format=" + format + "|crs=" + crs;
return uri;
return mDataSourceUri.encodedUri();
}
// ---------------------------------------------------------------------------

View File

@ -16,6 +16,7 @@
#define QGSWMSDATAITEMS_H
#include "qgsdataitem.h"
#include "qgsdatasourceuri.h"
#include "qgswmsprovider.h"
class QgsWMSConnectionItem : public QgsDataCollectionItem
@ -46,13 +47,13 @@ class QgsWMSLayerItem : public QgsLayerItem
Q_OBJECT
public:
QgsWMSLayerItem( QgsDataItem* parent, QString name, QString path,
QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperties );
QgsWmsCapabilitiesProperty capabilitiesProperty, QgsDataSourceURI dataSourceUri, QgsWmsLayerProperty layerProperties );
~QgsWMSLayerItem();
QString createUri();
QgsWmsCapabilitiesProperty mCapabilitiesProperty;
QString mConnInfo;
QgsDataSourceURI mDataSourceUri;
QgsWmsLayerProperty mLayerProperty;
};

View File

@ -28,6 +28,7 @@
#include "qgswmsprovider.h"
#include "qgswmsconnection.h"
#include "qgscoordinatetransform.h"
#include "qgsdatasourceuri.h"
#include "qgsrasterlayer.h"
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"
@ -105,133 +106,86 @@ QgsWmsProvider::QgsWmsProvider( QString const &uri )
// 2) http://xxx.xxx.xx/yyy/yyy?
// 3) http://xxx.xxx.xx/yyy/yyy?zzz=www
mBaseUrl = prepareUri( mHttpUri );
mSupportedGetFeatureFormats = QStringList() << "text/html" << "text/plain" << "text/xml";
QgsDebugMsg( "mBaseUrl = " + mBaseUrl );
QgsDebugMsg( "exiting constructor." );
}
void QgsWmsProvider::parseUri( QString uri )
void QgsWmsProvider::parseUri( QString uriString )
{
// Strip off and store the user name and password (if they exist)
if ( !uri.startsWith( " http:" ) )
QgsDebugMsg( "uriString = " + uriString );
QgsDataSourceURI uri;
uri.setEncodedUri( uriString );
mTiled = false;
mTileMatrixSet = 0;
mTileLayer = 0;
mTileDimensionValues.clear();
mMaxWidth = 0;
mMaxHeight = 0;
mHttpUri = uri.param( "url" );
mBaseUrl = prepareUri( mHttpUri ); // must set here, setImageCrs is using that
QgsDebugMsg( "mBaseUrl = " + mBaseUrl );
mIgnoreGetMapUrl = uri.hasParam( "IgnoreGetMapUrl" );
mIgnoreGetFeatureInfoUrl = uri.hasParam( "IgnoreGetFeatureInfoUrl" );
mIgnoreAxisOrientation = uri.hasParam( "IgnoreAxisOrientation" ); // must be before parsing!
mInvertAxisOrientation = uri.hasParam( "InvertAxisOrientation" ); // must be before parsing!
mUserName = uri.param( "username" );
QgsDebugMsg( "set username to " + mUserName );
mPassword = uri.param( "password" );
QgsDebugMsg( "set password to " + mPassword );
addLayers( uri.params( "layers" ), uri.params( "styles" ) );
setImageEncoding( uri.param( "format" ) );
if ( uri.hasParam( "maxWidth" ) && uri.hasParam( "maxHeight" ) )
{
mTiled = false;
mTileMatrixSet = 0;
mTileLayer = 0;
mTileDimensionValues.clear();
mMaxWidth = uri.param( "maxWidth" ).toInt();
mMaxHeight = uri.param( "maxHeight" ).toInt();
}
mMaxWidth = 0;
mMaxHeight = 0;
if ( uri.hasParam( "tileMatrixSet" ) )
{
mTiled = true;
// tileMatrixSet may be empty if URI was converted from < 1.9 project file URI
// in that case it means that the source is WMS-C
mTileMatrixSetId = uri.param( "tileMatrixSet" );
}
mIgnoreGetMapUrl = false;
mIgnoreGetFeatureInfoUrl = false;
mIgnoreAxisOrientation = false;
mInvertAxisOrientation = false;
QString layer;
// uri potentially contains username and password
foreach( const QString &item, uri.split( "," ) )
if ( uri.hasParam( "tileDimensions" ) )
{
mTiled = true;
foreach( QString param, uri.params( "tileDimensions" ) )
{
QgsDebugMsg( "testing for creds: " + item );
if ( item.startsWith( "username=" ) )
QStringList kv = param.split( "=" );
if ( kv.size() == 1 )
{
mUserName = item.mid( 9 );
QgsDebugMsg( "set username to " + mUserName );
mTileDimensionValues.insert( kv[0], QString::null );
}
else if ( item.startsWith( "password=" ) )
else if ( kv.size() == 2 )
{
mPassword = item.mid( 9 );
QgsDebugMsg( "set password to " + mPassword );
}
else if ( item.startsWith( "maxSize=" ) )
{
QStringList params = item.mid( 8 ).split( ";" );
mMaxWidth = params[0].toInt();
mMaxHeight = params[1].toInt();
}
else if ( item.startsWith( "featureCount=" ) )
{
mFeatureCount = item.mid( 13 ).toInt();
}
else if ( item.startsWith( "url=" ) )
{
// strip the authentication information from the front of the uri
mHttpUri = item.mid( 4 );
QgsDebugMsg( "set httpuri to " + mHttpUri );
}
else if ( item.startsWith( "ignoreUrl=" ) )
{
foreach( const QString &param, item.mid( 10 ).split( ";" ) )
{
if ( param == "GetMap" )
{
mIgnoreGetMapUrl = true;
}
else if ( param == "GetFeatureInfo" )
{
mIgnoreGetFeatureInfoUrl = true;
}
else if ( param == "AxisOrientation" )
{
mIgnoreAxisOrientation = true;
}
else if ( param == "InvertAxisOrientation" )
{
mInvertAxisOrientation = true;
}
}
}
else if ( item.startsWith( "tileMatrixSet=" ) )
{
mTiled = true;
mTileMatrixSetId = item.mid( 14 );
}
else if ( item.startsWith( "tileDimensions=" ) )
{
mTiled = true;
foreach( const QString &param, item.mid( 15 ).split( ";" ) )
{
QStringList kv = param.split( "=" );
if ( kv.size() == 1 )
{
mTileDimensionValues.insert( kv[0], QString::null );
}
else if ( kv.size() == 2 )
{
mTileDimensionValues.insert( kv[0], kv[1] );
}
else
{
QgsDebugMsg( QString( "skipped dimension %1" ).arg( param ) );
}
}
}
else if ( item.startsWith( "tiled=" ) )
{
// old WMS-C or request limit notation
QStringList params = item.mid( 6 ).split( ";" );
if ( params.size() > 2 )
{
mTiled = true;
}
else
{
mMaxWidth = params[0].toInt();
mMaxHeight = params[1].toInt();
}
mTileDimensionValues.insert( kv[0], kv[1] );
}
else
{
QgsDebugMsg( QString( "ignoring item: %1" ).arg( item ) );
QgsDebugMsg( QString( "skipped dimension %1" ).arg( param ) );
}
}
}
// setImageCrs is using mTiled !!!
setImageCrs( uri.param( "crs" ) );
mCrs.createFromOgcWmsCrs( uri.param( "crs" ) );
mFeatureCount = uri.param( "featureCount" ).toInt(); // default to 0
}
QString QgsWmsProvider::prepareUri( QString uri ) const
@ -467,6 +421,7 @@ void QgsWmsProvider::setImageCrs( QString const & crs )
}
mValid = retrieveServerCapabilities();
QgsDebugMsg( QString( "mValid = %1 mTileLayersSupported.size() = %2" ).arg( mValid ).arg( mTileLayersSupported.size() ) );
if ( !mValid || mTileLayersSupported.size() == 0 )
{
QgsDebugMsg( "Tile layer not found" );
@ -575,7 +530,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
if ( mInvertAxisOrientation )
changeXY = !changeXY;
// compose the URL query string for the WMS server.
QString crsKey = "SRS"; //SRS in 1.1.1 and CRS in 1.3.0
if ( mCapabilities.version == "1.3.0" || mCapabilities.version == "1.3" )
@ -1089,9 +1044,9 @@ void QgsWmsProvider::tileReplyFinished()
.arg( status.toString() )
.arg( contentType )
.arg( text.size() )
.arg( reply->url().toString() ), tr( "WMS" ) );
.arg( reply->url().toString() ), tr( "WMS" ) );
#ifdef QGISDEBUG
QFile file( QDir::tempPath() + "/b0rken-image.png" );
QFile file( QDir::tempPath() + "/broken-image.png" );
if ( file.open( QIODevice::WriteOnly ) )
{
file.write( text );
@ -1117,6 +1072,7 @@ void QgsWmsProvider::tileReplyFinished()
r.height() / cr );
QgsDebugMsg( QString( "tile reply: length %1" ).arg( reply->bytesAvailable() ) );
QImage myLocalImage = QImage::fromData( reply->readAll() );
if ( !myLocalImage.isNull() )
@ -1279,6 +1235,7 @@ bool QgsWmsProvider::retrieveServerCapabilities( bool forceRefresh )
if ( mHttpCapabilitiesResponse.isNull() || forceRefresh )
{
QString url = mBaseUrl;
QgsDebugMsg( "url = " + url );
if ( !url.contains( "SERVICE=WMTS" ) &&
!url.contains( "/WMTSCapabilities.xml" ) )
{
@ -1310,6 +1267,7 @@ bool QgsWmsProvider::retrieveServerCapabilities( bool forceRefresh )
mErrorFormat = "text/plain";
mError = tr( "empty capabilities document" );
}
QgsDebugMsg( "response is empty" );
return false;
}
@ -1318,6 +1276,7 @@ bool QgsWmsProvider::retrieveServerCapabilities( bool forceRefresh )
{
mErrorFormat = "text/html";
mError = mHttpCapabilitiesResponse;
QgsDebugMsg( "starts with <html>" );
return false;
}
@ -1347,8 +1306,10 @@ bool QgsWmsProvider::retrieveServerCapabilities( bool forceRefresh )
void QgsWmsProvider::capabilitiesReplyFinished()
{
QgsDebugMsg( "entering." );
if ( mCapabilitiesReply->error() == QNetworkReply::NoError )
{
QgsDebugMsg( "reply ok" );
QVariant redirect = mCapabilitiesReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
if ( !redirect.isNull() )
{
@ -2829,6 +2790,7 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )
}
}
QgsDebugMsg( QString( "add layer %1" ).arg( id ) );
mTileLayersSupported << l;
}
@ -3948,8 +3910,7 @@ void QgsWmsProvider::identifyReplyFinished()
QgsCoordinateReferenceSystem QgsWmsProvider::crs()
{
// TODO: implement
return QgsCoordinateReferenceSystem();
return mCrs;
}
QString QgsWmsProvider::lastErrorTitle()

View File

@ -1103,6 +1103,8 @@ class QgsWmsProvider : public QgsRasterDataProvider
//! supported formats for GetFeatureInfo in order of preference
QStringList mSupportedGetFeatureFormats;
QgsCoordinateReferenceSystem mCrs;
};

View File

@ -22,6 +22,7 @@
#include "qgis.h" // GEO_EPSG_CRS_ID
#include "qgscontexthelp.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsdatasourceuri.h"
#include "qgsgenericprojectionselector.h"
#include "qgslogger.h"
#include "qgsmanageconnectionsdialog.h"
@ -419,6 +420,7 @@ void QgsWMSSourceSelect::on_btnConnect_clicked()
QgsWMSConnection connection( cmbConnections->currentText() );
QgsWmsProvider *wmsProvider = connection.provider();
mConnectionInfo = connection.connectionInfo();
mUri = connection.uri();
if ( wmsProvider )
{
@ -454,13 +456,13 @@ void QgsWMSSourceSelect::addClicked()
QStringList styles;
QString format;
QString crs;
QString connInfo = connectionInfo();
QStringList connArgs;
QgsDataSourceURI uri = mUri;
if ( mTileWidth->text().toInt() > 0 && mTileHeight->text().toInt() > 0 )
{
connArgs << QString( "maxSize=%1;%2" ).arg( mTileWidth->text().toInt() ).arg( mTileHeight->text().toInt() );
uri.setParam( "maxWidth", mTileWidth->text() );
uri.setParam( "maxHeight", mTileHeight->text() );
}
if ( lstTilesets->selectedItems().isEmpty() )
@ -478,7 +480,7 @@ void QgsWMSSourceSelect::addClicked()
styles = QStringList( item->data( Qt::UserRole + 2 ).toString() );
crs = item->data( Qt::UserRole + 4 ).toString();
connArgs << QString( "tileMatrixSet=%1" ).arg( item->data( Qt::UserRole + 3 ).toStringList().join( ";" ) );
uri.setParam( "tileMatrixSet", item->data( Qt::UserRole + 3 ).toStringList() );
const QgsWmtsTileLayer *layer = 0;
@ -505,7 +507,7 @@ void QgsWMSSourceSelect::addClicked()
QHash<QString, QString> dims;
dlg->selectedDimensions( dims );
QString dimString = "tileDimensions=";
QString dimString;
QString delim;
for ( QHash<QString, QString>::const_iterator it = dims.constBegin();
@ -518,32 +520,27 @@ void QgsWMSSourceSelect::addClicked()
delete dlg;
connArgs << dimString;
uri.setParam( "tileDimensions", dimString );
}
}
uri.setParam( "layers", layers );
uri.setParam( "styles", styles );
uri.setParam( "format", format );
uri.setParam( "crs", crs );
if ( mFeatureCount->text().toInt() > 0 )
{
connArgs << QString( "featureCount=%1" ).arg( mFeatureCount->text().toInt() );
uri.setParam( "featureCount", mFeatureCount->text() );
}
if ( !connArgs.isEmpty() )
{
if ( !connInfo.startsWith( "username=" ) && !connInfo.startsWith( "ignoreUrl=" ) )
{
connInfo.prepend( "url=" );
}
QgsDebugMsg( QString( "crs=%2 " ).arg( crs ) );
connArgs << connInfo;
connInfo = connArgs.join( "," );
}
QgsDebugMsg( QString( "connInfo=%1 crs=%2 " ).arg( connInfo ).arg( crs ) );
emit addRasterLayer( connInfo,
QgsDebugMsg( "uri = " + uri.encodedUri() );
emit addRasterLayer( uri.encodedUri(),
leLayerName->text().isEmpty() ? layers.join( "/" ) : leLayerName->text(),
"wms", layers, styles, format, crs );
"wms" );
}
void QgsWMSSourceSelect::enableLayersForCrs( QTreeWidgetItem *item )

View File

@ -18,6 +18,7 @@
#ifndef QGSWMSSOURCESELECT_H
#define QGSWMSSOURCESELECT_H
#include "ui_qgswmssourceselectbase.h"
#include "qgsdatasourceuri.h"
#include "qgisgui.h"
#include "qgscontexthelp.h"
@ -172,6 +173,7 @@ class QgsWMSSourceSelect : public QDialog, private Ui::QgsWMSSourceSelectBase
//! URI for selected connection
QString mConnectionInfo;
QgsDataSourceURI mUri;
//! layer name derived from latest layer selection (updated as long it's not edited manually)
QString mLastLayerName;
@ -201,11 +203,7 @@ class QgsWMSSourceSelect : public QDialog, private Ui::QgsWMSSourceSelectBase
signals:
void addRasterLayer( QString const & rasterLayerPath,
QString const & baseName,
QString const & providerKey,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs );
QString const & providerKey );
void connectionsChanged();
private slots:
void on_btnSearch_clicked();