Skip to content

Commit 251dada

Browse files
author
jef
committed
apply #3594
git-svn-id: http://svn.osgeo.org/qgis/trunk@15453 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c19e333 commit 251dada

File tree

3 files changed

+72
-66
lines changed

3 files changed

+72
-66
lines changed

src/core/qgsproject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do
715715
}
716716

717717
// have the layer restore state that is stored in Dom node
718-
if ( mapLayer->readXML( node ) )
718+
if ( mapLayer->readXML( node ) && mapLayer->isValid() )
719719
{
720720
mapLayer = QgsMapLayerRegistry::instance()->addMapLayer( mapLayer );
721721
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
@@ -746,7 +746,7 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do
746746
vIt->first->createJoinCaches();
747747
vIt->first->updateFieldMap();
748748
//for old symbology, it is necessary to read the symbology again after having the complete field map
749-
if( !vIt->first->isUsingRendererV2() )
749+
if ( !vIt->first->isUsingRendererV2() )
750750
{
751751
vIt->first->readSymbology( vIt->second, errorMessage );
752752
}

src/core/raster/qgsrasterlayer.cpp

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,7 +2732,6 @@ void QgsRasterLayer::setMinimumMaximumUsingLastExtent()
27322732

27332733
void QgsRasterLayer::setMinimumMaximumUsingDataset()
27342734
{
2735-
double myMinMax[2];
27362735
if ( rasterType() == QgsRasterLayer::GrayOrUndefined || drawingStyle() == QgsRasterLayer::SingleBandGray || drawingStyle() == QgsRasterLayer::MultiBandSingleBandGray )
27372736
{
27382737
QgsRasterBandStats myRasterBandStats = bandStatistics( bandNumber( mGrayBandName ) );
@@ -3182,27 +3181,33 @@ bool QgsRasterLayer::readXml( QDomNode & layer_node )
31823181

31833182
if ( pkeyNode.isNull() )
31843183
{
3185-
mProviderKey = "";
3184+
mProviderKey = "gdal";
31863185
}
31873186
else
31883187
{
31893188
QDomElement pkeyElt = pkeyNode.toElement();
31903189
mProviderKey = pkeyElt.text();
3190+
if ( mProviderKey.isEmpty() )
3191+
{
3192+
mProviderKey = "gdal";
3193+
}
31913194
}
31923195

31933196
// Open the raster source based on provider and datasource
31943197

3195-
if ( !mProviderKey.isEmpty() )
3196-
{
3197-
// Go down the raster-data-provider paradigm
3198+
// Go down the raster-data-provider paradigm
3199+
3200+
// Collect provider-specific information
31983201

3199-
// Collect provider-specific information
3202+
QDomNode rpNode = layer_node.namedItem( "rasterproperties" );
32003203

3201-
QDomNode rpNode = layer_node.namedItem( "rasterproperties" );
3204+
// Collect sublayer names and styles
3205+
QStringList layers;
3206+
QStringList styles;
3207+
QString format;
32023208

3203-
// Collect sublayer names and styles
3204-
QStringList layers;
3205-
QStringList styles;
3209+
if ( mProviderKey == "wms" )
3210+
{
32063211
QDomElement layerElement = rpNode.firstChildElement( "wmsSublayer" );
32073212
while ( !layerElement.isNull() )
32083213
{
@@ -3218,28 +3223,28 @@ bool QgsRasterLayer::readXml( QDomNode & layer_node )
32183223
}
32193224

32203225
// Collect format
3221-
QString format = rpNode.namedItem( "wmsFormat" ).toElement().text();
3222-
3223-
// Collect CRS
3224-
setDataProvider( mProviderKey, layers, styles, format, crs().authid() );
3226+
format = rpNode.namedItem( "wmsFormat" ).toElement().text();
32253227
}
3226-
else
3227-
{
3228-
// Go down the monolithic-gdal-provider paradigm
3229-
3230-
if ( !readFile( source() ) ) // Data source name set in
3231-
// QgsMapLayer::readXML()
3232-
{
3233-
QgsLogger::warning( QString( __FILE__ ) + ":" + QString( __LINE__ ) +
3234-
" unable to read from raster file " + source() );
3235-
return false;
3236-
}
32373228

3238-
}
3229+
// Collect CRS
3230+
setDataProvider( mProviderKey, layers, styles, format, crs().authid() );
32393231

32403232
QString theError;
3241-
return readSymbology( layer_node, theError );
3233+
bool res = readSymbology( layer_node, theError );
32423234

3235+
// old wms settings we need to correct
3236+
if ( res &&
3237+
mProviderKey == "wms" &&
3238+
mDrawingStyle == MultiBandColor &&
3239+
mRedBandName == TRSTRING_NOT_SET &&
3240+
mGreenBandName == TRSTRING_NOT_SET &&
3241+
mBlueBandName == TRSTRING_NOT_SET )
3242+
{
3243+
mDrawingStyle = SingleBandColorDataStyle;
3244+
mGrayBandName = bandName( 1 );
3245+
}
3246+
3247+
return res;
32433248
} // QgsRasterLayer::readXml( QDomNode & layer_node )
32443249

32453250
/*
@@ -3254,13 +3259,13 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum
32543259
QDomElement rasterPropertiesElement = document.createElement( "rasterproperties" );
32553260
layer_node.appendChild( rasterPropertiesElement );
32563261

3257-
if ( !mProviderKey.isEmpty() )
3258-
{
3259-
QStringList sl = subLayers();
3260-
QStringList sls = mDataProvider->subLayerStyles();
3262+
QStringList sl = subLayers();
3263+
QStringList sls = mDataProvider->subLayerStyles();
32613264

3262-
QStringList::const_iterator layerStyle = sls.begin();
3265+
QStringList::const_iterator layerStyle = sls.begin();
32633266

3267+
if ( mProviderKey == "wms" )
3268+
{
32643269
// <rasterproperties><wmsSublayer>
32653270
for ( QStringList::const_iterator layerName = sl.begin();
32663271
layerName != sl.end();
@@ -3297,7 +3302,6 @@ bool QgsRasterLayer::writeSymbology( QDomNode & layer_node, QDomDocument & docum
32973302
document.createTextNode( mDataProvider->imageEncoding() );
32983303
formatElement.appendChild( formatText );
32993304
rasterPropertiesElement.appendChild( formatElement );
3300-
33013305
}
33023306

33033307
// <mDrawingStyle>

src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
131131
CPLErrorReset();
132132
if ( mGdalBaseDataset == NULL )
133133
{
134-
QMessageBox::warning( 0, QObject::tr( "Warning" ),
135-
QObject::tr( "Cannot open GDAL dataset %1: %2" ).arg( uri ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
134+
QgsDebugMsg( QString( "Cannot open GDAL dataset %1: %2" ).arg( uri ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
136135
return;
137136
}
138137

@@ -301,44 +300,44 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri )
301300
//ifdefs below to remove compiler warning about unused vars
302301
#ifdef QGISDEBUG
303302
#if 0
304-
int success;
305-
double GDALminimum = GDALGetRasterMinimum( myGdalBand, &success );
303+
int success;
304+
double GDALminimum = GDALGetRasterMinimum( myGdalBand, &success );
306305

307-
if ( ! success )
308-
{
309-
QgsDebugMsg( "myGdalBand->GetMinimum() failed" );
310-
}
306+
if ( ! success )
307+
{
308+
QgsDebugMsg( "myGdalBand->GetMinimum() failed" );
309+
}
311310

312-
double GDALmaximum = GDALGetRasterMaximum( myGdalBand, &success );
311+
double GDALmaximum = GDALGetRasterMaximum( myGdalBand, &success );
313312

314-
if ( ! success )
315-
{
316-
QgsDebugMsg( "myGdalBand->GetMaximum() failed" );
317-
}
313+
if ( ! success )
314+
{
315+
QgsDebugMsg( "myGdalBand->GetMaximum() failed" );
316+
}
318317

319-
double GDALnodata = GDALGetRasterNoDataValue( myGdalBand, &success );
318+
double GDALnodata = GDALGetRasterNoDataValue( myGdalBand, &success );
320319

321-
if ( ! success )
322-
{
323-
QgsDebugMsg( "myGdalBand->GetNoDataValue() failed" );
324-
}
320+
if ( ! success )
321+
{
322+
QgsDebugMsg( "myGdalBand->GetNoDataValue() failed" );
323+
}
325324

326-
QgsLogger::debug( "GDALminium: ", GDALminimum, __FILE__, __FUNCTION__, __LINE__ );
327-
QgsLogger::debug( "GDALmaximum: ", GDALmaximum, __FILE__, __FUNCTION__, __LINE__ );
328-
QgsLogger::debug( "GDALnodata: ", GDALnodata, __FILE__, __FUNCTION__, __LINE__ );
325+
QgsLogger::debug( "GDALminium: ", GDALminimum, __FILE__, __FUNCTION__, __LINE__ );
326+
QgsLogger::debug( "GDALmaximum: ", GDALmaximum, __FILE__, __FUNCTION__, __LINE__ );
327+
QgsLogger::debug( "GDALnodata: ", GDALnodata, __FILE__, __FUNCTION__, __LINE__ );
329328

330-
double GDALrange[2]; // calculated min/max, as opposed to the
331-
// dataset provided
329+
double GDALrange[2]; // calculated min/max, as opposed to the
330+
// dataset provided
332331

333-
GDALComputeRasterMinMax( myGdalBand, 1, GDALrange );
334-
QgsLogger::debug( "approximate computed GDALminium:", GDALrange[0], __FILE__, __FUNCTION__, __LINE__, 1 );
335-
QgsLogger::debug( "approximate computed GDALmaximum:", GDALrange[1], __FILE__, __FUNCTION__, __LINE__, 1 );
332+
GDALComputeRasterMinMax( myGdalBand, 1, GDALrange );
333+
QgsLogger::debug( "approximate computed GDALminium:", GDALrange[0], __FILE__, __FUNCTION__, __LINE__, 1 );
334+
QgsLogger::debug( "approximate computed GDALmaximum:", GDALrange[1], __FILE__, __FUNCTION__, __LINE__, 1 );
336335

337-
GDALComputeRasterMinMax( myGdalBand, 0, GDALrange );
338-
QgsLogger::debug( "exactly computed GDALminium:", GDALrange[0] );
339-
QgsLogger::debug( "exactly computed GDALmaximum:", GDALrange[1] );
336+
GDALComputeRasterMinMax( myGdalBand, 0, GDALrange );
337+
QgsLogger::debug( "exactly computed GDALminium:", GDALrange[0] );
338+
QgsLogger::debug( "exactly computed GDALmaximum:", GDALrange[1] );
340339

341-
QgsDebugMsg( "starting manual stat computation" );
340+
QgsDebugMsg( "starting manual stat computation" );
342341
#endif
343342
#endif
344343

@@ -1184,7 +1183,10 @@ int QgsGdalProvider::dataType( int bandNo ) const
11841183

11851184
int QgsGdalProvider::bandCount() const
11861185
{
1187-
return GDALGetRasterCount( mGdalDataset );
1186+
if ( mGdalDataset )
1187+
return GDALGetRasterCount( mGdalDataset );
1188+
else
1189+
return 1;
11881190
}
11891191

11901192
int QgsGdalProvider::colorInterpretation( int theBandNo ) const

0 commit comments

Comments
 (0)