Bug report #6243
QgsProject.read() should open a project file in "append" mode
|Affected QGIS version:||master||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:||invalid|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||15550|
QgsProject API Documentation states:
bool read (QFileInfo const &file)
read project file
bool read ()
presuming that the caller has already reset the map canvas, map registry, and legend
the first read (QFileInfo const &file) sets the project filename and calls the second read (). As you read, it says: "presuming that the caller has already reset the map canvas, map registry, and legend", so I wanted to use it to append my QGIS project file to current.
But it doesn't happen: current maplayers are cleared and substituted to the layers of the project file, althrough I still see the old project title in the window titlebar.
Here's how you can reproduce it:
- write a plugin with this code:
QgsProject.instance().read ( new QFileInfo ( "<path of a qgis file>" ) );
- open a different qgis project file
- launch the plugin
- all layers are substituted.
#3 Updated by Sandro Santilli about 8 years ago
The code is intentionally clearing all stuff, surely for project properties but don't know if for anything else too (assets referenced by layers?):
// before we start loading everything, let's clear out the current set of // properties first so that we don't have the properties from the previous // project still hanging around imp_->clear(); mEmbeddedLayers.clear();