Skip to content

Commit

Permalink
Remove duplicate QgsRasterLayer constructor
Browse files Browse the repository at this point in the history
Avoids confusing overload behavior when constructing QgsRasterLayers
from c++ code. This extra constructor was causing character literals
to be converted to a boolean loadDefaultStyle flag instead
of being used as the provider key. Removing the extra constructor
avoids this, and removes some duplicate code.
  • Loading branch information
nyalldawson committed Jan 27, 2017
1 parent d259cdf commit 45fc6dc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 56 deletions.
3 changes: 3 additions & 0 deletions doc/api_break.dox
Expand Up @@ -1569,6 +1569,9 @@ QgsRasterInterface {#qgis_api_break_3_0_QgsRasterInterface}
QgsRasterLayer {#qgis_api_break_3_0_QgsRasterLayer}
--------------

- The constructor variant with loadDefaultStyleFlag as the 3rd parameter was removed. Use the
constructor variant which accepts a data provider string and loadDefaultStyleFlag as the
4th parameter instead.
- setDrawingStyle() was removed. Use setRendererForDrawingStyle() or setRenderer() instead.
- previewAsPixmap() was removed. Use previewAsImage() instead.
- updateProgress() had no effect and was removed.
Expand Down
14 changes: 2 additions & 12 deletions python/core/raster/qgsrasterlayer.sip
Expand Up @@ -33,19 +33,9 @@ class QgsRasterLayer : QgsMapLayer
*
* -
* */
QgsRasterLayer( const QString &path,
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,
const QString &providerKey,
const QString &baseName = QString(),
const QString &providerKey = "gdal",
bool loadDefaultStyleFlag = true );

/** \brief The destructor */
Expand Down
32 changes: 0 additions & 32 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -104,38 +104,6 @@ QgsRasterLayer::QgsRasterLayer()
mValid = false;
}

QgsRasterLayer::QgsRasterLayer(
const QString& path,
const QString& baseName,
bool loadDefaultStyleFlag )
: QgsMapLayer( RasterLayer, baseName, path )
, QSTRING_NOT_SET( QStringLiteral( "Not Set" ) )
, TRSTRING_NOT_SET( tr( "Not Set" ) )
, mDataProvider( nullptr )
{
QgsDebugMsgLevel( "Entered", 4 );

// TODO, call constructor with provider key
init();
setDataProvider( QStringLiteral( "gdal" ) );
if ( !mValid ) return;

bool defaultLoadedFlag = false;
if ( mValid && loadDefaultStyleFlag )
{
loadDefaultStyle( defaultLoadedFlag );
}
if ( !defaultLoadedFlag )
{
setDefaultContrastEnhancement();
}
return;
} // QgsRasterLayer ctor

/**
* @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,
Expand Down
14 changes: 2 additions & 12 deletions src/core/raster/qgsrasterlayer.h
Expand Up @@ -179,19 +179,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
*
* -
* */
QgsRasterLayer( const QString &path,
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,
const QString &providerKey,
const QString &baseName = QString(),
const QString &providerKey = "gdal",
bool loadDefaultStyleFlag = true );

~QgsRasterLayer();
Expand Down

0 comments on commit 45fc6dc

Please sign in to comment.