11 changes: 2 additions & 9 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
5 changes: 2 additions & 3 deletions src/app/qgisappinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
3 changes: 1 addition & 2 deletions src/app/qgisappinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
30 changes: 2 additions & 28 deletions src/app/qgsbrowserdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down Expand Up @@ -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();
Expand Down
28 changes: 1 addition & 27 deletions src/browser/qgsbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/core/qgsbrowsermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) );
}
}
Expand Down
60 changes: 60 additions & 0 deletions src/core/qgsdatasourceuri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

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

QgsDataSourceURI::QgsDataSourceURI()
: mSSLmode( SSLprefer )
Expand Down Expand Up @@ -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() )
Expand Down Expand Up @@ -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 );
}
42 changes: 42 additions & 0 deletions src/core/qgsdatasourceuri.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
78 changes: 78 additions & 0 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
10 changes: 6 additions & 4 deletions src/core/qgsprojectfiletransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ QgsProjectFileTransform::transform QgsProjectFileTransform::transformers[] =
{PFV( 1, 4, 0 ), PFV( 1, 5, 0 ), &QgsProjectFileTransform::transform1400to1500},
{PFV( 1, 5, 0 ), PFV( 1, 6, 0 ), &QgsProjectFileTransform::transformNull},
{PFV( 1, 6, 0 ), PFV( 1, 7, 0 ), &QgsProjectFileTransform::transformNull},
{PFV( 1, 7, 0 ), PFV( 1, 8, 0 ), &QgsProjectFileTransform::transform1700to1800}
{PFV( 1, 7, 0 ), PFV( 1, 8, 0 ), &QgsProjectFileTransform::transformNull},
{PFV( 1, 8, 0 ), PFV( 1, 9, 0 ), &QgsProjectFileTransform::transform1800to1900}
};

bool QgsProjectFileTransform::updateRevision( QgsProjectVersion newVersion )
Expand Down Expand Up @@ -454,7 +455,7 @@ void QgsProjectFileTransform::transform1400to1500()
}
}

void QgsProjectFileTransform::transform1700to1800()
void QgsProjectFileTransform::transform1800to1900()
{
if ( mDom.isNull() )
{
Expand All @@ -468,7 +469,8 @@ void QgsProjectFileTransform::transform1700to1800()
QDomNode layerNode = rasterPropertiesElem.parentNode();
QDomElement dataSourceElem = layerNode.firstChildElement( "datasource" );
QDomElement layerNameElem = layerNode.firstChildElement( "layername" );
QgsRasterLayer rasterLayer( QgsProject::instance()->readPath( dataSourceElem.text() ), layerNameElem.text() );
QDomElement layerProviderElem = layerNode.firstChildElement( "provider" );
QgsRasterLayer rasterLayer( QgsProject::instance()->readPath( dataSourceElem.text() ), layerNameElem.text(), layerProviderElem.isNull() ? "gdal" : layerProviderElem.text() );
convertRasterProperties( mDom, layerNode, rasterPropertiesElem, &rasterLayer );
}
QgsDebugMsg( mDom.toString() );
Expand Down Expand Up @@ -497,7 +499,7 @@ void QgsProjectFileTransform::convertRasterProperties( QDomDocument& doc, QDomNo
if ( !transparencyElem.isNull() )
{
double transparency = transparencyElem.text().toInt();
rasterRendererElem.setAttribute( "opacity", transparency / 255.0 );
rasterRendererElem.setAttribute( "opacity", QString::number( transparency / 255.0 ) );
}

//alphaBand was not saved until now (bug)
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsprojectfiletransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class QgsProjectFileTransform
void transform0110to1000();
void transform1100to1200();
void transform1400to1500();
void transform1700to1800();
void transform1800to1900();

//helper functions
static int rasterBandNumber( const QDomElement& rasterPropertiesElem, const QString bandName, QgsRasterLayer* rlayer );
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsbilinearrasterresampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "qgsrasterresampler.h"
#include <QColor>

class QgsBilinearRasterResampler: public QgsRasterResampler
class CORE_EXPORT QgsBilinearRasterResampler: public QgsRasterResampler
{
public:
QgsBilinearRasterResampler();
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgscubicrasterresampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "qgsrasterresampler.h"
#include <QColor>

class QgsCubicRasterResampler: public QgsRasterResampler
class CORE_EXPORT QgsCubicRasterResampler: public QgsRasterResampler
{
public:
QgsCubicRasterResampler();
Expand Down
8 changes: 4 additions & 4 deletions src/core/raster/qgsmultibandcolorrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ void QgsMultiBandColorRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
&& mAlphaBand < 1 && !mRedContrastEnhancement && !mGreenContrastEnhancement && !mBlueContrastEnhancement
&& !mInvertColor );

QgsRasterDataProvider::DataType redType;
QgsRasterDataProvider::DataType redType = QgsRasterDataProvider::UnknownDataType;
if ( mRedBand > 0 )
{
redType = ( QgsRasterDataProvider::DataType )mProvider->dataType( mRedBand );
}
QgsRasterDataProvider::DataType greenType;
QgsRasterDataProvider::DataType greenType = QgsRasterDataProvider::UnknownDataType;
if ( mGreenBand > 0 )
{
greenType = ( QgsRasterDataProvider::DataType )mProvider->dataType( mGreenBand );
}
QgsRasterDataProvider::DataType blueType;
QgsRasterDataProvider::DataType blueType = QgsRasterDataProvider::UnknownDataType;
if ( mBlueBand > 0 )
{
blueType = ( QgsRasterDataProvider::DataType )mProvider->dataType( mBlueBand );
Expand All @@ -136,7 +136,7 @@ void QgsMultiBandColorRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
transparencyType = ( QgsRasterDataProvider::DataType )mProvider->dataType( mAlphaBand );
}

double oversamplingX, oversamplingY;
double oversamplingX = 1.0, oversamplingY = 1.0;
QSet<int> bands;
if ( mRedBand > 0 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsmultibandcolorrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class QgsContrastEnhancement;
class QDomElement;

/**Renderer for multiband images with the color components*/
class QgsMultiBandColorRenderer: public QgsRasterRenderer
class CORE_EXPORT QgsMultiBandColorRenderer: public QgsRasterRenderer
{
public:
QgsMultiBandColorRenderer( QgsRasterDataProvider* provider, int redBand, int greenBand, int blueBand,
Expand Down
6 changes: 3 additions & 3 deletions src/core/raster/qgspalettedrasterrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ QgsRasterRenderer* QgsPalettedRasterRenderer::create( const QDomElement& elem, Q
}

int bandNumber = elem.attribute( "band", "-1" ).toInt();
int nColors;
QColor* colors;
int nColors = 0;
QColor* colors = 0;

QDomElement paletteElem = elem.firstChildElement( "colorPalette" );
if ( !paletteElem.isNull() )
Expand Down Expand Up @@ -118,7 +118,7 @@ void QgsPalettedRasterRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,

//rendering is faster without considering user-defined transparency
bool hasTransparency = usesTransparency( viewPort->mSrcCRS, viewPort->mDestCRS );
void* transparencyData;
void* transparencyData = 0;

while ( readNextRasterPart( mBandNumber, oversamplingX, oversamplingY, viewPort, nCols, nRows, nRasterCols, nRasterRows,
&rasterData, topLeftCol, topLeftRow ) )
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgspalettedrasterrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class QColor;
class QDomElement;

class QgsPalettedRasterRenderer: public QgsRasterRenderer
class CORE_EXPORT QgsPalettedRasterRenderer: public QgsRasterRenderer
{
public:
/**Renderer owns color array*/
Expand Down
200 changes: 59 additions & 141 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ email : tim at linfiniti.com
***************************************************************************/

#include "qgsapplication.h"
#include "qgsdatasourceuri.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"
#include "qgsmaplayerregistry.h"
Expand Down Expand Up @@ -89,6 +90,20 @@ 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 )
, QSTRING_NOT_SET( "Not Set" )
, TRSTRING_NOT_SET( tr( "Not Set" ) )
, mStandardDeviations( 0 )
, mDataProvider( 0 )
, mWidth( std::numeric_limits<int>::max() )
, mHeight( std::numeric_limits<int>::max() )
, mInvertColor( false )
, mRenderer( 0 )
{
init();
mValid = false;
}

QgsRasterLayer::QgsRasterLayer(
QString const & path,
Expand All @@ -109,18 +124,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;

Expand All @@ -131,15 +140,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 )
Expand All @@ -148,27 +156,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 );
Expand All @@ -188,8 +184,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

Expand Down Expand Up @@ -2293,34 +2287,18 @@ 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 )
{
Q_UNUSED( loadDefaultStyleFlag );
void QgsRasterLayer::setDataProvider( QString const & provider )
{
// 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 @@ -2335,29 +2313,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
Expand Down Expand Up @@ -2390,16 +2351,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();

Expand Down Expand Up @@ -3168,33 +3120,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
mFormat = rpNode.namedItem( "wmsFormat" ).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();
}
// <<< 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 );
Expand Down Expand Up @@ -3222,7 +3183,7 @@ bool QgsRasterLayer::readXml( const QDomNode& layer_node )
QgsDebugMsg( "data changed, reload provider" );
closeDataProvider();
init();
setDataProvider( mProviderKey, mLayers, mStyles, mFormat, mCrs );
setDataProvider( mProviderKey );
}
}

Expand All @@ -3244,49 +3205,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

Expand Down Expand Up @@ -3471,7 +3389,7 @@ bool QgsRasterLayer::update()
QgsDebugMsg( "reload data" );
closeDataProvider();
init();
setDataProvider( mProviderKey, mLayers, mStyles, mFormat, mCrs );
setDataProvider( mProviderKey );
emit dataChanged();
}
return mValid;
Expand Down
38 changes: 9 additions & 29 deletions src/core/raster/qgsrasterlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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();
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
};

Expand Down
8 changes: 4 additions & 4 deletions src/core/raster/qgsrasterrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void QgsRasterRenderer::startRasterRead( int bandNumber, QgsRasterViewPort* view

int totalMemoryUsage = pInfo.nCols * oversamplingX * pInfo.nRows * oversamplingY * mProvider->dataTypeSize( bandNumber );
int parts = totalMemoryUsage / 100000000 + 1;
int nPartsPerDimension = sqrt( parts );
int nPartsPerDimension = sqrt(( double ) parts );
pInfo.nColsPerPart = pInfo.nCols / nPartsPerDimension;
pInfo.nRowsPerPart = pInfo.nRows / nPartsPerDimension;
pInfo.currentCol = 0;
Expand Down Expand Up @@ -246,7 +246,7 @@ void QgsRasterRenderer::drawImage( QPainter* p, QgsRasterViewPort* viewPort, con
}

//get QgsRasterProjector
QgsRasterProjector* prj;
QgsRasterProjector* prj = 0;
QMap<int, RasterPartInfo>::const_iterator partInfoIt = mRasterPartInfos.constBegin();
if ( partInfoIt != mRasterPartInfos.constEnd() )
{
Expand Down Expand Up @@ -326,9 +326,9 @@ void QgsRasterRenderer::_writeXML( QDomDocument& doc, QDomElement& rasterRendere
}

rasterRendererElem.setAttribute( "type", mType );
rasterRendererElem.setAttribute( "opacity", mOpacity );
rasterRendererElem.setAttribute( "opacity", QString::number( mOpacity ) );
rasterRendererElem.setAttribute( "alphaBand", mAlphaBand );
rasterRendererElem.setAttribute( "maxOversampling", mMaxOversampling );
rasterRendererElem.setAttribute( "maxOversampling", QString::number( mMaxOversampling ) );
rasterRendererElem.setAttribute( "invertColor", mInvertColor );
if ( mZoomedInResampler )
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class QgsMapToPixel;
class QgsRasterResampler;
class QgsRasterProjector;
class QgsRasterTransparency;
class QgsRasterViewPort;
struct QgsRasterViewPort;

class QDomElement;

class QgsRasterRenderer
class CORE_EXPORT QgsRasterRenderer
{
public:
//Stores information about reading of a raster band. Columns and rows are in unsampled coordinates
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterrendererregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class QgsRasterRendererWidget;
typedef QgsRasterRenderer*( *QgsRasterRendererCreateFunc )( const QDomElement&, QgsRasterDataProvider* provider );
typedef QgsRasterRendererWidget*( *QgsRasterRendererWidgetCreateFunc )( QgsRasterLayer* );

struct QgsRasterRendererRegistryEntry
struct CORE_EXPORT QgsRasterRendererRegistryEntry
{
QgsRasterRendererRegistryEntry( const QString& theName, const QString& theVisibleName, QgsRasterRendererCreateFunc rendererFunction,
QgsRasterRendererWidgetCreateFunc widgetFunction );
Expand All @@ -41,7 +41,7 @@ struct QgsRasterRendererRegistryEntry
QgsRasterRendererWidgetCreateFunc widgetCreateFunction; //pointer to create function for renderer widget
};

class QgsRasterRendererRegistry
class CORE_EXPORT QgsRasterRendererRegistry
{
public:
static QgsRasterRendererRegistry* instance();
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsrastershader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void QgsRasterShader::writeXML( QDomDocument& doc, QDomElement& parent ) const
{
QDomElement itemElem = doc.createElement( "item" );
itemElem.setAttribute( "label", itemIt->label );
itemElem.setAttribute( "value", itemIt->value );
itemElem.setAttribute( "value", QString::number( itemIt->value ) );
itemElem.setAttribute( "color", itemIt->color.name() );
colorRampShaderElem.appendChild( itemElem );
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgssinglebandgrayrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void QgsSingleBandGrayRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort,
alphaType = ( QgsRasterDataProvider::DataType )mProvider->dataType( mAlphaBand );
}
void* rasterData;
void* alphaData;
void* alphaData = 0;
double currentAlpha = mOpacity;
int grayVal;
QRgb myDefaultColor = qRgba( 0, 0, 0, 0 );
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgssinglebandgrayrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class QgsContrastEnhancement;
class QDomElement;

class QgsSingleBandGrayRenderer: public QgsRasterRenderer
class CORE_EXPORT QgsSingleBandGrayRenderer: public QgsRasterRenderer
{
public:
QgsSingleBandGrayRenderer( QgsRasterDataProvider* provider, int grayBand );
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgssinglebandpseudocolorrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void QgsSingleBandPseudoColorRenderer::draw( QPainter* p, QgsRasterViewPort* vie
int topLeftCol = 0;
int topLeftRow = 0;
void* rasterData;
void* transparencyData;
void* transparencyData = 0;
double currentOpacity = mOpacity;
QgsRasterDataProvider::DataType rasterType = ( QgsRasterDataProvider::DataType )mProvider->dataType( mBand );
int red, green, blue;
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgssinglebandpseudocolorrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class QDomElement;
class QgsRasterShader;

class QgsSingleBandPseudoColorRenderer: public QgsRasterRenderer
class CORE_EXPORT QgsSingleBandPseudoColorRenderer: public QgsRasterRenderer
{
public:
/**Note: takes ownership of QgsRasterShader*/
Expand Down
3 changes: 1 addition & 2 deletions src/gui/qgisinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/raster/qgsmultibandcolorrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class QgsRasterDataProvider;
class QgsRasterLayer;
class QLineEdit;

class QgsMultiBandColorRendererWidget: public QgsRasterRendererWidget, private Ui::QgsMultiBandColorRendererWidgetBase
class GUI_EXPORT QgsMultiBandColorRendererWidget: public QgsRasterRendererWidget, private Ui::QgsMultiBandColorRendererWidgetBase
{
Q_OBJECT

Expand Down
2 changes: 1 addition & 1 deletion src/gui/raster/qgspalettedrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class QgsRasterLayer;

class QgsPalettedRendererWidget: public QgsRasterRendererWidget, private Ui::QgsPalettedRendererWidgetBase
class GUI_EXPORT QgsPalettedRendererWidget: public QgsRasterRendererWidget, private Ui::QgsPalettedRendererWidgetBase
{
Q_OBJECT

Expand Down
2 changes: 1 addition & 1 deletion src/gui/raster/qgsrasterrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class QgsRasterLayer;
class QgsRasterRenderer;

class QgsRasterRendererWidget: public QWidget
class GUI_EXPORT QgsRasterRendererWidget: public QWidget
{
public:
QgsRasterRendererWidget( QgsRasterLayer* layer ) { mRasterLayer = layer; }
Expand Down
2 changes: 1 addition & 1 deletion src/gui/raster/qgssinglebandgrayrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "qgsrasterrendererwidget.h"
#include "ui_qgssinglebandgrayrendererwidgetbase.h"

class QgsSingleBandGrayRendererWidget: public QgsRasterRendererWidget, private Ui::QgsSingleBandGrayRendererWidgetBase
class GUI_EXPORT QgsSingleBandGrayRendererWidget: public QgsRasterRendererWidget, private Ui::QgsSingleBandGrayRendererWidgetBase
{
Q_OBJECT
public:
Expand Down
2 changes: 1 addition & 1 deletion src/gui/raster/qgssinglebandpseudocolorrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "qgscolorrampshader.h"
#include "ui_qgssinglebandpseudocolorrendererwidgetbase.h"

class QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendererWidget,
class GUI_EXPORT QgsSingleBandPseudoColorRendererWidget: public QgsRasterRendererWidget,
private Ui::QgsSingleBandPseudoColorRendererWidgetBase
{
Q_OBJECT
Expand Down
9 changes: 8 additions & 1 deletion src/mapserver/qgsremoteowsbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* *
***************************************************************************/

#include "qgsdatasourceuri.h"
#include "qgsremoteowsbuilder.h"
#include "qgshttptransaction.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/grass/qgsgrassbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/grass/qgsgrassmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/plugins/grass/qgsgrassplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
}
}

Expand Down
17 changes: 15 additions & 2 deletions src/providers/wms/qgswmsconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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() )
Expand Down Expand Up @@ -122,15 +130,20 @@ QString QgsWMSConnection::connectionInfo()
return mConnectionInfo;
}

QgsWmsProvider *QgsWMSConnection::provider()
QgsDataSourceURI QgsWMSConnection::uri()
{
return mUri;
}

QgsWmsProvider * QgsWMSConnection::provider( )
{
// TODO: Create and bind to data provider

// load the server data provider plugin
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();

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

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

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

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


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

#include "qgslogger.h"

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

Expand Down Expand Up @@ -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 ) )
Expand All @@ -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 );
}
Expand Down Expand Up @@ -119,22 +120,23 @@ 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 )
{
// 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 );
}

Expand All @@ -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 )
{
Expand All @@ -182,6 +172,8 @@ QString QgsWMSLayerItem::createUri()
break;
}
}
mDataSourceUri.setParam( "format", format );

QString crs;
// get first known if possible
QgsCoordinateReferenceSystem testCrs;
Expand All @@ -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();
}

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

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

class QgsWMSConnectionItem : public QgsDataCollectionItem
Expand Down Expand Up @@ -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;
};

Expand Down
184 changes: 73 additions & 111 deletions src/providers/wms/qgswmsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:" ) )
{
mTiled = false;
mTileMatrixSet = 0;
mTileLayer = 0;
mTileDimensionValues.clear();

mMaxWidth = 0;
mMaxHeight = 0;
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" ) );

mIgnoreGetMapUrl = false;
mIgnoreGetFeatureInfoUrl = false;
mIgnoreAxisOrientation = false;
mInvertAxisOrientation = false;
if ( uri.hasParam( "maxWidth" ) && uri.hasParam( "maxHeight" ) )
{
mMaxWidth = uri.param( "maxWidth" ).toInt();
mMaxHeight = uri.param( "maxHeight" ).toInt();
}

QString layer;
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" );
}

// 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=" ) )
{
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( "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=" ) )
QStringList kv = param.split( "=" );
if ( kv.size() == 1 )
{
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 ) );
}
}
mTileDimensionValues.insert( kv[0], QString::null );
}
else if ( item.startsWith( "tiled=" ) )
else if ( kv.size() == 2 )
{
// 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
Expand Down Expand Up @@ -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" );
Expand Down Expand Up @@ -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" )
Expand Down Expand Up @@ -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 );
Expand All @@ -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() )
Expand Down Expand Up @@ -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" ) )
{
Expand Down Expand Up @@ -1310,6 +1267,7 @@ bool QgsWmsProvider::retrieveServerCapabilities( bool forceRefresh )
mErrorFormat = "text/plain";
mError = tr( "empty capabilities document" );
}
QgsDebugMsg( "response is empty" );
return false;
}

Expand All @@ -1318,6 +1276,7 @@ bool QgsWmsProvider::retrieveServerCapabilities( bool forceRefresh )
{
mErrorFormat = "text/html";
mError = mHttpCapabilitiesResponse;
QgsDebugMsg( "starts with <html>" );
return false;
}

Expand Down Expand Up @@ -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() )
{
Expand Down Expand Up @@ -2548,6 +2509,7 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )
metersPerUnit = 111319.49079327358;
break;

default:
case QGis::UnknownUnit:
QgsDebugMsg( "Unknown CRS units - assuming meters" );
metersPerUnit = 1.0;
Expand Down Expand Up @@ -2828,6 +2790,7 @@ void QgsWmsProvider::parseWMTSContents( QDomElement const &e )
}
}

QgsDebugMsg( QString( "add layer %1" ).arg( id ) );
mTileLayersSupported << l;
}

Expand Down Expand Up @@ -3947,8 +3910,7 @@ void QgsWmsProvider::identifyReplyFinished()

QgsCoordinateReferenceSystem QgsWmsProvider::crs()
{
// TODO: implement
return QgsCoordinateReferenceSystem();
return mCrs;
}

QString QgsWmsProvider::lastErrorTitle()
Expand Down
2 changes: 2 additions & 0 deletions src/providers/wms/qgswmsprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,8 @@ class QgsWmsProvider : public QgsRasterDataProvider

//! supported formats for GetFeatureInfo in order of preference
QStringList mSupportedGetFeatureFormats;

QgsCoordinateReferenceSystem mCrs;
};


Expand Down
41 changes: 19 additions & 22 deletions src/providers/wms/qgswmssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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() )
Expand All @@ -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;

Expand All @@ -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();
Expand All @@ -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=" );
}

connArgs << connInfo;
QgsDebugMsg( QString( "crs=%2 " ).arg( crs ) );

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 )
Expand Down
8 changes: 3 additions & 5 deletions src/providers/wms/qgswmssourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef QGSWMSSOURCESELECT_H
#define QGSWMSSOURCESELECT_H
#include "ui_qgswmssourceselectbase.h"
#include "qgsdatasourceuri.h"
#include "qgisgui.h"
#include "qgscontexthelp.h"

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