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

Layer user notes only available for QgsVectorLayer when reading a project with flag QgsProject.FlagDontResolveLayers #58818

Open
2 tasks done
jmkerloch opened this issue Sep 20, 2024 · 0 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!

Comments

@jmkerloch
Copy link
Contributor

What is the bug or the crash?

When a QgsProject is read from a file with flag QgsProject.FlagDontResolveLayers we can get layer user notes only for QgsVectorLayer

I looked into the code for differences between QgqVectorLayer and other layer (for instance QgsRasterLayer).

For QgsRasterLayer the main difference is that we never load symbology if the data provider is not set (consequence of the QgsProject.FlagDontResolveLayers flags:

if ( ! mDataProvider )
{
if ( !( mReadFlags & QgsMapLayer::FlagDontResolveLayers ) )
{
QgsDebugError( QStringLiteral( "Raster data provider could not be created for %1" ).arg( mDataSource ) );
}
return false;
}
QString error;
const bool res = readSymbology( layer_node, error, context );

Steps to reproduce the issue

  1. Create a QGIS project
  2. Load a vector layer
  3. Add a layer note to this vector layer
  4. Load a raster layer
  5. Add a layer note to this raster layer
  6. Save QGIS project
  7. Run this python code
qgs_project = QgsProject()
path = "/path/to/created/qgis_project.qgz"
project_qgs.read(path, QgsProject.FlagDontResolveLayers)

for name, layer in project_qgs.mapLayers().items():
    print(f"{name=} {QgsLayerNotesUtils.layerNotes(layer)=}")

There should be a layer note available for all layers.

Versions

<style type="text/css"> p, li { white-space: pre-wrap; } </style>
QGIS version 3.36.3-Maidenhead QGIS code revision 2df9655
Qt version 5.15.3
Python version 3.10.12
GDAL/OGR version 3.4.1
PROJ version 8.2.1
EPSG Registry database version v10.041 (2021-12-03)
GEOS version 3.10.2-CAPI-1.16.0
SQLite version 3.37.2
PDAL version 2.3.0
PostgreSQL client version 14.11 (Ubuntu 14.11-0ubuntu0.22.04.1)
SpatiaLite version 5.0.1
QWT version 6.1.4
QScintilla2 version 2.11.6
OS version Ubuntu 22.04.3 LTS
       
Active Python plugins
plugin_reloader 0.11
french_locator_filter 1.1.1
processing 2.12.99
MetaSearch 0.3.6
grassprovider 2.12.99
db_manager 0.1.20
menu_from_project 2.2.0-beta1
QGIS version 3.36.3-Maidenhead QGIS code revision [2df9655](https://github.com/qgis/QGIS/commit/2df9655469b) Qt version 5.15.3 Python version 3.10.12 GDAL/OGR version 3.4.1 PROJ version 8.2.1 EPSG Registry database version v10.041 (2021-12-03) GEOS version 3.10.2-CAPI-1.16.0 SQLite version 3.37.2 PDAL version 2.3.0 PostgreSQL client version 14.11 (Ubuntu 14.11-0ubuntu0.22.04.1) SpatiaLite version 5.0.1 QWT version 6.1.4 QScintilla2 version 2.11.6 OS version Ubuntu 22.04.3 LTS

Active Python plugins
plugin_reloader
0.11
french_locator_filter
1.1.1
processing
2.12.99
MetaSearch
0.3.6
grassprovider
2.12.99
db_manager
0.1.20
menu_from_project
2.2.0-beta1

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

I need to access layer user note for the plugin https://plugins.qgis.org/plugins/menu_from_project/

This plugin allow user to have a menu with all layer and group inside a QGIS project.

To avoid manual parsing of the .xml for QGIS project we would like to go with a QgsProject that already have all the needed informations.

@jmkerloch jmkerloch added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!
Projects
None yet
Development

No branches or pull requests

1 participant