145 changes: 40 additions & 105 deletions src/core/qgsdatasourceuri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

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

QgsDataSourceURI::QgsDataSourceURI()
: mSSLmode( SSLprefer )
Expand All @@ -33,11 +32,6 @@ QgsDataSourceURI::QgsDataSourceURI()
// do nothing
}

QgsDataSourceURI::QgsDataSourceURI( const QgsDataSourceURI& dataSourceURI )
{
mParams = dataSourceURI.mParams;
}

QgsDataSourceURI::QgsDataSourceURI( QString uri )
: mSSLmode( SSLprefer )
, mKeyColumn( "" )
Expand Down Expand Up @@ -536,47 +530,47 @@ QString QgsDataSourceURI::uri() const
{
theUri += " type=";

switch ( mWkbType )
switch( mWkbType )
{
case QGis::WKBPoint:
theUri += "POINT";
break;
case QGis::WKBLineString:
theUri += "LINESTRING";
break;
case QGis::WKBPolygon:
theUri += "POLYGON";
break;
case QGis::WKBMultiPoint:
theUri += "MULTIPOINT";
break;
case QGis::WKBMultiLineString:
theUri += "MULTILINESTRING";
break;
case QGis::WKBMultiPolygon:
theUri += "MULTIPOLYGON";
break;
case QGis::WKBPoint25D:
theUri += "POINTM";
break;
case QGis::WKBLineString25D:
theUri += "LINESTRINGM";
break;
case QGis::WKBPolygon25D:
theUri += "POLYGONM";
break;
case QGis::WKBMultiPoint25D:
theUri += "MULTIPOINTM";
break;
case QGis::WKBMultiLineString25D:
theUri += "MULTILINESTRINGM";
break;
case QGis::WKBMultiPolygon25D:
theUri += "MULTIPOLYGONM";
break;
case QGis::WKBUnknown:
case QGis::WKBNoGeometry:
break;
case QGis::WKBPoint:
theUri += "POINT";
break;
case QGis::WKBLineString:
theUri += "LINESTRING";
break;
case QGis::WKBPolygon:
theUri += "POLYGON";
break;
case QGis::WKBMultiPoint:
theUri += "MULTIPOINT";
break;
case QGis::WKBMultiLineString:
theUri += "MULTILINESTRING";
break;
case QGis::WKBMultiPolygon:
theUri += "MULTIPOLYGON";
break;
case QGis::WKBPoint25D:
theUri += "POINTM";
break;
case QGis::WKBLineString25D:
theUri += "LINESTRINGM";
break;
case QGis::WKBPolygon25D:
theUri += "POLYGONM";
break;
case QGis::WKBMultiPoint25D:
theUri += "MULTIPOINTM";
break;
case QGis::WKBMultiLineString25D:
theUri += "MULTILINESTRINGM";
break;
case QGis::WKBMultiPolygon25D:
theUri += "MULTIPOLYGONM";
break;
case QGis::WKBUnknown:
case QGis::WKBNoGeometry:
break;
}
}

Expand All @@ -593,36 +587,6 @@ 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() )
Expand Down Expand Up @@ -699,32 +663,3 @@ 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 );
}
45 changes: 0 additions & 45 deletions src/core/qgsdatasourceuri.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@

#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
{
Expand All @@ -41,55 +35,18 @@ class CORE_EXPORT QgsDataSourceURI
//! default constructor
QgsDataSourceURI();

//! copy constructor (generic mode)
QgsDataSourceURI( const QgsDataSourceURI& dataSourceURI );

//! 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,
Expand Down Expand Up @@ -206,8 +163,6 @@ 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
Expand Down
67 changes: 0 additions & 67 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ 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 );
Expand Down Expand Up @@ -193,71 +192,6 @@ 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=" ) )
{
QStringList params = item.mid( 6 ).split( ";" );

uri.setParam( "tileWidth", params.takeFirst() );
uri.setParam( "tileHeight", params.takeFirst() );

uri.setParam( "tileResolutions", params );
}
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 );
Expand Down Expand Up @@ -384,7 +318,6 @@ 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 );
Expand Down
199 changes: 145 additions & 54 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ email : tim at linfiniti.com
***************************************************************************/

#include "qgsapplication.h"
#include "qgsdatasourceuri.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"
#include "qgsmaplayerregistry.h"
Expand Down Expand Up @@ -81,12 +80,6 @@ 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,
Expand All @@ -106,12 +99,18 @@ QgsRasterLayer::QgsRasterLayer(

// TODO, call constructor with provider key for now
init();
setDataProvider( "gdal" );
setDataProvider( "gdal", QStringList(), QStringList(), QString(), QString(), loadDefaultStyleFlag );

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;

Expand All @@ -122,14 +121,15 @@ 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( 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" ) )
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 )
, mStandardDeviations( 0 )
, mDataProvider( 0 )
, mEditable( false )
Expand All @@ -138,15 +138,22 @@ QgsRasterLayer::QgsRasterLayer( const QString & uri,
, mInvertColor( false )
, mModified( false )
, mProviderKey( providerKey )
, mLayers( layers )
, mStyles( styles )
, mFormat( format )
, mCrs( crs )
{
init();
setDataProvider( providerKey );
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 );

if ( mValid && loadDefaultStyleFlag )
{
bool defaultLoadedFlag = false;
loadDefaultStyle( defaultLoadedFlag );
}

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

// Default for the popup menu
// TODO: popMenu = 0;
Expand All @@ -162,6 +169,8 @@ QgsRasterLayer::QgsRasterLayer( const QString & uri,

// TODO: Connect signals from the dataprovider to the qgisapp

QgsDebugMsg( "(8 arguments) exiting." );

emit statusChanged( tr( "QgsRasterLayer created" ) );
} // QgsRasterLayer ctor

Expand Down Expand Up @@ -2199,18 +2208,34 @@ 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 )
void QgsRasterLayer::setDataProvider( QString const & provider,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & theCrs,
bool loadDefaultStyleFlag )
{
Q_UNUSED( loadDefaultStyleFlag );
// XXX should I check for and possibly delete any pre-existing providers?
// XXX How often will that scenario occur?

mProviderKey = 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 );
Expand All @@ -2225,6 +2250,30 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
return;
}


QgsDebugMsg( QString( "Instantiated the data provider plugin with layer list of %1 and style list of %2 and format of %3 and CRS of %4" )
.arg( layers.join( ", " ) )
.arg( styles.join( ", " ) )
.arg( format )
.arg( theCrs )
);
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;
}

mDataProvider->addLayers( layers, styles );
mDataProvider->setImageEncoding( format );
mDataProvider->setImageCrs( theCrs );

setNoDataValue( mDataProvider->noDataValue() );

// get the extent
Expand All @@ -2250,7 +2299,16 @@ void QgsRasterLayer::setDataProvider( QString const & provider )
mDrawingStyle = MultiBandColor; //sensible default

// Setup source CRS
setCrs( QgsCoordinateReferenceSystem( mDataProvider->crs() ) );
if ( mProviderKey == "wms" )
{
QgsCoordinateReferenceSystem crs;
crs.createFromOgcWmsCrs( theCrs );
setCrs( crs );
}
else
{
setCrs( QgsCoordinateReferenceSystem( mDataProvider->crs() ) );
}

QString mySourceWkt = crs().toWkt();

Expand Down Expand Up @@ -3175,42 +3233,33 @@ 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" )
{
// >>> BACKWARD COMPATIBILITY < 1.9
// The old WMS URI format does not contains all the informations, we add them here.
if ( !mDataSource.contains( "crs=" ) && !mDataSource.contains( "format=" ) )
QDomElement layerElement = rpNode.firstChildElement( "wmsSublayer" );
while ( !layerElement.isNull() )
{
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
// TODO: sublayer visibility - post-0.8 release timeframe

// collect name for the sublayer
uri.setParam( "layers", layerElement.namedItem( "name" ).toElement().text() );
// collect name for the sublayer
mLayers += layerElement.namedItem( "name" ).toElement().text();

// collect style for the sublayer
uri.setParam( "styles", layerElement.namedItem( "style" ).toElement().text() );

layerElement = layerElement.nextSiblingElement( "wmsSublayer" );
}
// collect style for the sublayer
mStyles += layerElement.namedItem( "style" ).toElement().text();

// 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();
layerElement = layerElement.nextSiblingElement( "wmsSublayer" );
}
// <<< BACKWARD COMPATIBILITY < 1.9

// Collect format
mFormat = rpNode.namedItem( "wmsFormat" ).toElement().text();
}

setDataProvider( mProviderKey );
mCrs = crs().authid();
// Collect CRS
setDataProvider( mProviderKey, mLayers, mStyles, mFormat, mCrs );

QString theError;
bool res = readSymbology( layer_node, theError );
Expand Down Expand Up @@ -3238,7 +3287,7 @@ bool QgsRasterLayer::readXml( const QDomNode& layer_node )
QgsDebugMsg( "data changed, reload provider" );
closeDataProvider();
init();
setDataProvider( mProviderKey );
setDataProvider( mProviderKey, mLayers, mStyles, mFormat, mCrs );
}
}

Expand All @@ -3261,6 +3310,48 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum
QStringList sl = subLayers();
QStringList sls = mDataProvider->subLayerStyles();

QStringList::const_iterator layerStyle = sls.begin();

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

// <mDrawingStyle>
QDomElement drawStyleElement = document.createElement( "mDrawingStyle" );
QDomText drawStyleText = document.createTextNode( drawingStyleAsString() );
Expand Down Expand Up @@ -4561,7 +4652,7 @@ bool QgsRasterLayer::update()
QgsDebugMsg( "reload data" );
closeDataProvider();
init();
setDataProvider( mProviderKey );
setDataProvider( mProviderKey, mLayers, mStyles, mFormat, mCrs );
emit dataChanged();
}
return mValid;
Expand Down
38 changes: 29 additions & 9 deletions src/core/raster/qgsrasterlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ 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:
Expand All @@ -189,15 +186,20 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
*
* -
* */
QgsRasterLayer( const QString & path,
QgsRasterLayer( const QString & path = QString::null,
const QString & baseName = QString::null,
bool loadDefaultStyleFlag = true );

/** \brief [ data provider interface ] Constructor in provider mode */
QgsRasterLayer( const QString & uri,
const QString & baseName,
const QString & providerKey,
bool loadDefaultStyleFlag = true );
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() );


/** \brief The destructor */
~QgsRasterLayer();
Expand Down Expand Up @@ -289,8 +291,19 @@ 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 );
void setDataProvider( const QString & provider,
const QStringList & layers,
const QStringList & styles,
const QString & format,
const QString & crs,
bool loadDefaultStyleFlag );

static QLibrary* loadProviderLibrary( QString theProviderKey );
static QgsRasterDataProvider* loadProvider( QString theProviderKey, QString theDataSource = 0 );
Expand Down Expand Up @@ -906,6 +919,13 @@ 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;
};

/*#include <QColor>
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgisinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ 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 ) = 0;
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;

//! Add a project
virtual bool addProject( QString theProject ) = 0;
Expand Down
9 changes: 1 addition & 8 deletions src/mapserver/qgsremoteowsbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* *
***************************************************************************/

#include "qgsdatasourceuri.h"
#include "qgsremoteowsbuilder.h"
#include "qgshttptransaction.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -207,13 +206,7 @@ QgsRasterLayer* QgsRemoteOWSBuilder::wmsLayerFromUrl( const QString& url, const
QgsDebugMsg( "layerList first item: " + layerList.at( 0 ) );
QgsDebugMsg( "styleList first item: " + styleList.at( 0 ) );

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" );
result = new QgsRasterLayer( 0, baseUrl, "", "wms", layerList, styleList, format, crs );
if ( !result->isValid() )
{
return 0;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/grass/qgsgrassbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ void QgsGrassBrowser::addMap()
{
QgsDebugMsg( QString( "add raster: %1" ).arg( uri ) );
//mIface->addRasterLayer( uri, map );
mIface->addRasterLayer( uri, map, "grassraster" );
mIface->addRasterLayer( uri, map, "grassraster", QStringList(), QStringList(),
QString(), QString() );
}
else if ( type == QgsGrassModel::Vector )
{
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/grass/qgsgrassmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,8 @@ void QgsGrassModule::viewOutput()
+ "/cellhd/" + map;

//mIface->addRasterLayer( uri, map );
mIface->addRasterLayer( uri, map, "grassraster" );
mIface->addRasterLayer( uri, map, "grassraster", QStringList(), QStringList(),
QString(), QString() );
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/plugins/grass/qgsgrassplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ void QgsGrassPlugin::addRaster()
name.replace( '/', ' ' );

//qGisInterface->addRasterLayer( uri, sel->map );
qGisInterface->addRasterLayer( uri, sel->map, "grassraster" );
qGisInterface->addRasterLayer( uri, sel->map, "grassraster", QStringList(), QStringList(),
QString(), QString() );
}
}

Expand Down
16 changes: 2 additions & 14 deletions src/providers/wms/qgswmsconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
//#include "qgisapp.h" //for getThemeIcon
//#include "qgscontexthelp.h"
//#include "qgscoordinatereferencesystem.h"
#include "qgsdatasourceuri.h"
//#include "qgsgenericprojectionselector.h"
//#include "qgslogger.h"
//#include "qgsmanageconnectionsdialog.h"
Expand Down Expand Up @@ -64,7 +63,6 @@ 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();
Expand All @@ -78,8 +76,6 @@ 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();
Expand All @@ -92,13 +88,10 @@ QgsWMSConnection::QgsWMSConnection( QString theConnName ) :
connArgs += "GetMap";
if ( ignoreGetFeatureInfo )
connArgs += ";";
mUri.setParam( "ignoreUrl", "GetMap" );
}
if ( ignoreGetFeatureInfo )
{
connArgs += "GetFeatureInfo";
mUri.setParam( "ignoreUrl", "GetFeatureInfo" );
}

if ( mConnectionInfo.startsWith( "username=" ) )
{
mConnectionInfo.prepend( connArgs + "," );
Expand All @@ -122,11 +115,6 @@ QString QgsWMSConnection::connectionInfo( )
return mConnectionInfo;
}

QgsDataSourceURI QgsWMSConnection::uri()
{
return mUri;
}

QgsWmsProvider * QgsWMSConnection::provider( )
{
// TODO: Create and bind to data provider
Expand All @@ -135,7 +123,7 @@ QgsWmsProvider * QgsWMSConnection::provider( )
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();

QgsWmsProvider *wmsProvider =
( QgsWmsProvider* ) pReg->provider( "wms", mUri.encodedUri() );
( QgsWmsProvider* ) pReg->provider( "wms", mConnectionInfo );

return wmsProvider;
}
Expand Down
3 changes: 0 additions & 3 deletions src/providers/wms/qgswmsconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#ifndef QGSWMSCONNECTION_H
#define QGSWMSCONNECTION_H
#include "qgsdatasourceuri.h"
#include "qgisgui.h"
//#include "qgscontexthelp.h"

Expand Down Expand Up @@ -57,8 +56,6 @@ class QgsWMSConnection : public QObject
QString connectionInfo();
QString mConnName;
QString mConnectionInfo;
QgsDataSourceURI uri();
QgsDataSourceURI mUri;
};


Expand Down
43 changes: 25 additions & 18 deletions src/providers/wms/qgswmsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "qgslogger.h"

#include "qgsdatasourceuri.h"
#include "qgswmsconnection.h"
#include "qgswmssourceselect.h"

Expand All @@ -28,8 +27,8 @@ QVector<QgsDataItem*> QgsWMSConnectionItem::createChildren()
if ( !wmsProvider )
return children;

QgsDataSourceURI uri = connection.uri();
QgsDebugMsg( "uri = " + uri.encodedUri() );
QString mConnInfo = connection.connectionInfo();
QgsDebugMsg( "mConnInfo = " + mConnInfo );

// Attention: supportedLayers() gives tree leafes, not top level
if ( !wmsProvider->supportedLayers( mLayerProperties ) )
Expand All @@ -51,7 +50,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, uri, layerProperty );
QgsWMSLayerItem * layer = new QgsWMSLayerItem( this, layerProperty.title, mPath + "/" + pathName, mCapabilitiesProperty, mConnInfo, layerProperty );

children.append( layer );
}
Expand Down Expand Up @@ -104,23 +103,22 @@ void QgsWMSConnectionItem::deleteConnection()

// ---------------------------------------------------------------------------

QgsWMSLayerItem::QgsWMSLayerItem( QgsDataItem* parent, QString name, QString path, QgsWmsCapabilitiesProperty capabilitiesProperty, QgsDataSourceURI dataSourceUri, QgsWmsLayerProperty layerProperty )
QgsWMSLayerItem::QgsWMSLayerItem( QgsDataItem* parent, QString name, QString path, QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperty )
: QgsLayerItem( parent, name, path, QString(), QgsLayerItem::Raster, "wms" ),
mCapabilitiesProperty( capabilitiesProperty ),
mDataSourceUri( dataSourceUri ),
mConnInfo( connInfo ),
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 )
{
// 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, mDataSourceUri, layerProperty );
QgsWMSLayerItem * layer = new QgsWMSLayerItem( this, layerProperty.title, mPath + "/" + pathName, mCapabilitiesProperty, mConnInfo, layerProperty );
mChildren.append( layer );
}

Expand All @@ -137,16 +135,28 @@ QgsWMSLayerItem::~QgsWMSLayerItem()

QString QgsWMSLayerItem::createUri()
{
QString uri;
if ( mLayerProperty.name.isEmpty() )
return ""; // layer collection
return uri; // layer collection

QString rasterLayerPath = mConnInfo;
QString baseName = mLayerProperty.name;

// Number of styles must match number of layers
mDataSourceUri.setParam( "layers", mLayerProperty.name );
QString style = mLayerProperty.style.size() > 0 ? mLayerProperty.style[0].name : "";
mDataSourceUri.setParam( "styles", style );
QStringList layers;
layers << mLayerProperty.name;
QStringList styles;
if ( mLayerProperty.style.size() > 0 )
{
styles.append( mLayerProperty.style[0].name );
}
else
{
styles << ""; // TODO: use loadDefaultStyleFlag
}

QString format;
// get first supported by qt and server
// get first supporte by qt and server
QVector<QgsWmsSupportedFormat> formats = QgsWmsProvider::supportedFormats();
foreach( QgsWmsSupportedFormat f, formats )
{
Expand All @@ -156,8 +166,6 @@ QString QgsWMSLayerItem::createUri()
break;
}
}
mDataSourceUri.setParam( "format", format );

QString crs;
// get first known if possible
QgsCoordinateReferenceSystem testCrs;
Expand All @@ -174,10 +182,9 @@ QString QgsWMSLayerItem::createUri()
{
crs = mLayerProperty.crs[0];
}
mDataSourceUri.setParam( "crs", crs );
//uri = rasterLayerPath + "|layers=" + layers.join( "," ) + "|styles=" + styles.join( "," ) + "|format=" + format + "|crs=" + crs;
uri = rasterLayerPath + "|layers=" + layers.join( "," ) + "|styles=" + styles.join( "," ) + "|format=" + format + "|crs=" + crs;

return mDataSourceUri.encodedUri();
return uri;
}

// ---------------------------------------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions src/providers/wms/qgswmsdataitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define QGSWMSDATAITEMS_H

#include "qgsdataitem.h"
#include "qgsdatasourceuri.h"
#include "qgswmsprovider.h"

class QgsWMSConnectionItem : public QgsDataCollectionItem
Expand Down Expand Up @@ -33,13 +32,13 @@ class QgsWMSLayerItem : public QgsLayerItem
Q_OBJECT
public:
QgsWMSLayerItem( QgsDataItem* parent, QString name, QString path,
QgsWmsCapabilitiesProperty capabilitiesProperty, QgsDataSourceURI dataSourceUri, QgsWmsLayerProperty layerProperties );
QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperties );
~QgsWMSLayerItem();

QString createUri();

QgsWmsCapabilitiesProperty mCapabilitiesProperty;
QgsDataSourceURI mDataSourceUri;
QString mConnInfo;
QgsWmsLayerProperty mLayerProperty;
};

Expand Down
104 changes: 64 additions & 40 deletions src/providers/wms/qgswmsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <cmath>

#include "qgscoordinatetransform.h"
#include "qgsdatasourceuri.h"
#include "qgsrasterlayer.h"
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"
Expand Down Expand Up @@ -119,48 +118,77 @@ QgsWmsProvider::QgsWmsProvider( QString const &uri )
QgsDebugMsg( "exiting constructor." );
}

void QgsWmsProvider::parseUri( QString uriString )
void QgsWmsProvider::parseUri( QString uri )
{
QgsDebugMsg( "uriString = " + uriString );
QgsDataSourceURI uri;
uri.setEncodedUri( uriString );

mTiled = false;
mTileWidth = 0;
mTileHeight = 0;
mResolutions.clear();
mIgnoreGetMapUrl = false;
mIgnoreGetFeatureInfoUrl = false;

httpuri = uri.param( "url" );
QgsDebugMsg( "set httpuri to " + httpuri );
// Strip off and store the user name and password (if they exist)
if ( !uri.startsWith( " http:" ) )
{
mTiled = false;
mTileWidth = 0;
mTileHeight = 0;
mResolutions.clear();

mUserName = uri.param( "username" );
QgsDebugMsg( "set username to " + mUserName );
mIgnoreGetMapUrl = false;
mIgnoreGetFeatureInfoUrl = false;

mPassword = uri.param( "password" );
QgsDebugMsg( "set password to " + mPassword );
// uri potentially contains username and password
QStringList parts = uri.split( "," );
QStringListIterator iter( parts );
while ( iter.hasNext() )
{
QString item = iter.next();
QgsDebugMsg( "testing for creds: " + item );
if ( item.startsWith( "username=" ) )
{
mUserName = item.mid( 9 );
QgsDebugMsg( "set username to " + mUserName );
}
else if ( item.startsWith( "password=" ) )
{
mPassword = item.mid( 9 );
QgsDebugMsg( "set password to " + mPassword );
}
else if ( item.startsWith( "tiled=" ) )
{
QStringList params = item.mid( 6 ).split( ";" );

addLayers( uri.params( "layers" ), uri.params( "styles" ) );
setImageEncoding( uri.param( "format" ) );
setImageCrs( uri.param( "crs" ) );
mTiled = true;
mTileWidth = params.takeFirst().toInt();
mTileHeight = params.takeFirst().toInt();

if ( uri.hasParam( "tileWidth" ) )
{
mTiled = true;
mTileWidth = uri.param( "tileWidth" ).toInt();
mTileHeight = uri.param( "tileHeight" ).toInt();
foreach( QString p, uri.params( "tileResolutions" ) )
{
mResolutions << p.toDouble();
mResolutions.clear();
foreach( QString r, params )
{
mResolutions << r.toDouble();
}
qSort( mResolutions );
}
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
httpuri = item.mid( 4 );
QgsDebugMsg( "set httpuri to " + httpuri );
}
else if ( item.startsWith( "ignoreUrl=" ) )
{
foreach( QString param, item.mid( 10 ).split( ";" ) )
{
if ( param == "GetMap" )
{
mIgnoreGetMapUrl = true;
}
else if ( param == "GetFeatureInfo" )
{
mIgnoreGetFeatureInfoUrl = true;
}
}
}
}
qSort( mResolutions );
}

mFeatureCount = uri.param( "featureCount" ).toInt(); // default to 0

mIgnoreGetMapUrl = uri.params( "ignoreUrl" ).contains( "GetMap" );
mIgnoreGetFeatureInfoUrl = uri.params( "ignoreUrl" ).contains( "GetFeatureInfo" );
}

QString QgsWmsProvider::prepareUri( QString uri ) const
Expand Down Expand Up @@ -2246,7 +2274,6 @@ bool QgsWmsProvider::calculateExtent()
.arg( layers ).arg( styles ).arg( imageCrs ) );
for ( int i = 0; i < tilesetsSupported.size(); i++ )
{
QgsDebugMsg( "tilesetsSupported[i].crs = " + tilesetsSupported[i].crs + " imageCrs = " + imageCrs );
if ( tilesetsSupported[i].layers.join( "," ) == layers &&
tilesetsSupported[i].styles.join( "," ) == styles &&
tilesetsSupported[i].crs == imageCrs )
Expand Down Expand Up @@ -2277,7 +2304,6 @@ bool QgsWmsProvider::calculateExtent()

mCoordinateTransform = new QgsCoordinateTransform( qgisSrsSource, qgisSrsDest );
}
QgsDebugMsg( "imageCrs = " + imageCrs );

bool firstLayer = true; //flag to know if a layer is the first to be successfully transformed
for ( QStringList::Iterator it = activeSubLayers.begin();
Expand All @@ -2287,13 +2313,11 @@ bool QgsWmsProvider::calculateExtent()
QgsDebugMsg( "Sublayer Iterator: " + *it );
// This is the extent for the layer name in *it
QgsRectangle extent = extentForLayer.find( *it ).value();
QgsDebugMsg( "extent = " + extent.toString() );

// Convert to the user's CRS as required
try
{
extent = mCoordinateTransform->transformBoundingBox( extent, QgsCoordinateTransform::ForwardTransform );
QgsDebugMsg( "extent = " + extent.toString() );
}
catch ( QgsCsException &cse )
{
Expand Down
40 changes: 23 additions & 17 deletions src/providers/wms/qgswmssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#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"
Expand Down Expand Up @@ -408,7 +407,6 @@ void QgsWMSSourceSelect::on_btnConnect_clicked()
QgsWMSConnection connection( cmbConnections->currentText() );
QgsWmsProvider *wmsProvider = connection.provider( );
mConnectionInfo = connection.connectionInfo();
mUri = connection.uri();

if ( wmsProvider )
{
Expand Down Expand Up @@ -444,8 +442,9 @@ void QgsWMSSourceSelect::addClicked()
QStringList styles;
QString format;
QString crs;
QString connInfo = connectionInfo();

QgsDataSourceURI uri = mUri;
QString connArgs;

if ( lstTilesets->selectedItems().isEmpty() )
{
Expand All @@ -455,8 +454,7 @@ void QgsWMSSourceSelect::addClicked()

if ( mTileWidth->text().toInt() > 0 && mTileHeight->text().toInt() > 0 )
{
uri.setParam( "tileWidth", mTileWidth->text() );
uri.setParam( "tileHeight", mTileHeight->text() );
connArgs = QString( "tiled=%1;%2" ).arg( mTileWidth->text().toInt() ).arg( mTileHeight->text().toInt() );
}
}
else
Expand All @@ -467,27 +465,35 @@ void QgsWMSSourceSelect::addClicked()
format = item->data( Qt::UserRole + 2 ).toString();
crs = item->data( Qt::UserRole + 3 ).toString();

uri.setParam( "tileWidth", item->data( Qt::UserRole + 4 ).toString() );
uri.setParam( "tileHeight", item->data( Qt::UserRole + 5 ).toString() );
uri.setParam( "tileResolutions", item->data( Qt::UserRole + 6 ).toStringList() );
connArgs = QString( "tiled=%1;%2;%3" )
.arg( item->data( Qt::UserRole + 4 ).toInt() )
.arg( item->data( Qt::UserRole + 5 ).toInt() )
.arg( item->data( Qt::UserRole + 6 ).toStringList().join( ";" ) );
}
uri.setParam( "layers", layers );
uri.setParam( "styles", styles );
uri.setParam( "format", format );
uri.setParam( "crs", crs );

if ( mFeatureCount->text().toInt() > 0 )
{
uri.setParam( "featureCount", mFeatureCount->text() );
if ( !connArgs.isEmpty() )
connArgs += ",";
connArgs += QString( "featureCount=%1" ).arg( mFeatureCount->text().toInt() );
}

if ( !connArgs.isEmpty() )
{
if ( connInfo.startsWith( "username=" ) || connInfo.startsWith( "ignoreUrl=" ) )
{
connInfo.prepend( connArgs + "," );
}
else
{
connInfo.prepend( connArgs + ",url=" );
}
}
QgsDebugMsg( "crs = " + crs );

QgsDebugMsg( "uri = " + uri.encodedUri() );
emit addRasterLayer( uri.encodedUri(),
emit addRasterLayer( connInfo,
leLayerName->text().isEmpty() ? layers.join( "/" ) : leLayerName->text(),
"wms" );

"wms", layers, styles, format, crs );
}

void QgsWMSSourceSelect::enableLayersForCrs( QTreeWidgetItem *item )
Expand Down
8 changes: 5 additions & 3 deletions src/providers/wms/qgswmssourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#ifndef QGSWMSSOURCESELECT_H
#define QGSWMSSOURCESELECT_H
#include "ui_qgswmssourceselectbase.h"
#include "qgsdatasourceuri.h"
#include "qgisgui.h"
#include "qgscontexthelp.h"

Expand Down Expand Up @@ -173,7 +172,6 @@ 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;
Expand All @@ -200,7 +198,11 @@ class QgsWMSSourceSelect : public QDialog, private Ui::QgsWMSSourceSelectBase
signals:
void addRasterLayer( QString const & rasterLayerPath,
QString const & baseName,
QString const & providerKey );
QString const & providerKey,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs );
void connectionsChanged();
private slots:
void on_btnSearch_clicked();
Expand Down