Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QgsRasterLayer: readXml(): read layer notes even when opening with FlagDontResolveLayers #58835

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2216,9 +2216,9 @@ bool QgsRasterLayer::readSymbology( const QDomNode &layer_node, QString &errorMe
{
const QString rendererType = rasterRendererElem.attribute( QStringLiteral( "type" ) );
QgsRasterRendererRegistryEntry rendererEntry;
if ( QgsApplication::rasterRendererRegistry()->rendererData( rendererType, rendererEntry ) )
if ( mDataProvider && QgsApplication::rasterRendererRegistry()->rendererData( rendererType, rendererEntry ) )
nyalldawson marked this conversation as resolved.
Show resolved Hide resolved
{
QgsRasterRenderer *renderer = rendererEntry.rendererCreateFunction( rasterRendererElem, dataProvider() );
QgsRasterRenderer *renderer = rendererEntry.rendererCreateFunction( rasterRendererElem, mDataProvider );
mPipe->set( renderer );
}
}
Expand Down Expand Up @@ -2412,8 +2412,8 @@ bool QgsRasterLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &c
if ( !( mReadFlags & QgsMapLayer::FlagDontResolveLayers ) )
{
QgsDebugError( QStringLiteral( "Raster data provider could not be created for %1" ).arg( mDataSource ) );
return false;
}
return false;
}

QString error;
Expand Down Expand Up @@ -2452,7 +2452,7 @@ bool QgsRasterLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &c

const QDomNodeList noDataBandList = noDataElement.elementsByTagName( QStringLiteral( "noDataList" ) );

for ( int i = 0; i < noDataBandList.size(); ++i )
for ( int i = 0; mDataProvider && i < noDataBandList.size(); ++i )
{
const QDomElement bandElement = noDataBandList.at( i ).toElement();
bool ok;
Expand Down
26 changes: 26 additions & 0 deletions tests/src/python/test_qgsproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
QgsExpressionContextUtils,
QgsFeature,
QgsGeometry,
QgsLayerNotesUtils,
QgsLabelingEngineSettings,
QgsMapLayer,
QgsProject,
Expand Down Expand Up @@ -1879,6 +1880,31 @@ def test_remember_evaluate_default_values(self):
self.assertEqual(layers[0].dataProvider().providerProperty(QgsDataProvider.ProviderProperty.EvaluateDefaultValues, None), True)
self.assertEqual(layers[1].dataProvider().providerProperty(QgsDataProvider.ProviderProperty.EvaluateDefaultValues, None), True)

def testRasterLayerFlagDontResolveLayers(self):
"""
Test that we can read layer notes from a raster layer when opening with FlagDontResolveLayers
"""
tmpDir = QTemporaryDir()
tmpFile = f"{tmpDir.path()}/project.qgs"
copyfile(os.path.join(TEST_DATA_DIR, "landsat_4326.tif"), os.path.join(tmpDir.path(), "landsat_4326.tif"))

project = QgsProject()

l = QgsRasterLayer(os.path.join(tmpDir.path(), "landsat_4326.tif"), "landsat", "gdal")
self.assertTrue(l.isValid())
QgsLayerNotesUtils.setLayerNotes(l, 'my notes')
self.assertTrue(project.addMapLayers([l]))
self.assertTrue(project.write(tmpFile))
del project

# Read the project with FlagDontResolveLayers
project = QgsProject()
self.assertTrue(project.read(tmpFile, QgsProject.FlagDontResolveLayers))
layers = list(project.mapLayers().values())
self.assertEqual(QgsLayerNotesUtils.layerNotes(layers[0]), "my notes")

del project


if __name__ == '__main__':
unittest.main()
Loading