Navigation Menu

Skip to content

Commit

Permalink
Avoid 'array compared against 0' error for QgsRasterLayer constructor
Browse files Browse the repository at this point in the history
... by explicitly passing QString arguments. Otherwise the string
literals are implictly converted to bool and the wrong constructor
is called.

This is not an ideal solution as the API is still misleading, but I
can't see an alternative solution without breaking API and making
one of the constructors explicit or changing their signature.
  • Loading branch information
nyalldawson committed Feb 4, 2015
1 parent 6e8d19c commit cb5ef02
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/core/raster/qgsrasterlayer.h
Expand Up @@ -196,6 +196,11 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
const QString & baseName = QString::null,
bool loadDefaultStyleFlag = true );

//TODO - QGIS 3.0
//This constructor is confusing if used with string literals for providerKey,
//as the previous constructor will be called with the literal for providerKey
//implicitly converted to a bool.
//for QGIS 3.0, make either constructor explicit or alter the signatures
/** \brief [ data provider interface ] Constructor in provider mode */
QgsRasterLayer( const QString & uri,
const QString & baseName,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsrasterformatsaveoptionswidget.cpp
Expand Up @@ -310,7 +310,7 @@ QString QgsRasterFormatSaveOptionsWidget::validateOptions( bool gui, bool report
settings.setValue( "/Projections/defaultBehaviour", "useProject" );
}
tmpLayer = true;
rasterLayer = new QgsRasterLayer( mRasterFileName, QFileInfo( mRasterFileName ).baseName(), "gdal" );
rasterLayer = new QgsRasterLayer( mRasterFileName, QFileInfo( mRasterFileName ).baseName(), QString( "gdal" ) );
// restore /Projections/defaultBehaviour
if ( defaultProjectionOption == "prompt" )
{
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testqgslegendrenderer.cpp
Expand Up @@ -127,7 +127,7 @@ void TestQgsLegendRenderer::init()

static char raster_array[] = { 1, 2, 2, 1 };
QString rasterUri = QString( "MEM:::DATAPOINTER=%1,PIXELS=2,LINES=2" ).arg(( qulonglong ) raster_array );
mRL = new QgsRasterLayer( rasterUri, "Raster Layer", "gdal" );
mRL = new QgsRasterLayer( rasterUri, QString( "Raster Layer" ), QString( "gdal" ) );
QgsMapLayerRegistry::instance()->addMapLayer( mRL );

QgsCategoryList cats;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testziplayer.cpp
Expand Up @@ -110,7 +110,7 @@ QgsMapLayer *TestZipLayer::getLayer( QString myPath, QString myName, QString myP
}
else if ( myProviderKey == "gdal" )
{
myLayer = new QgsRasterLayer( myPath, myName, "gdal" );
myLayer = new QgsRasterLayer( myPath, myName, QString( "gdal" ) );
}
// item should not have other provider key, but if it does will return NULL

Expand Down

0 comments on commit cb5ef02

Please sign in to comment.