after removing all MapViews, old layers from processing are still visible in MapLayerComboBox widgets

Issue #937 closed
Andreas Janz created an issue

How to reproduce:

  • open enmap_berlin in a MapView
  • use GDAL Translate algo to create a copy
  • close all MapView

Now, the MapLayerComboBox widgets should be empty again. Instead we still see the old layer from processing:

With time, the layer list gets bigger and bigger, even after closing all Data Sources and Map Views:

Comments (29)

  1. Benjamin Jakimow
    • changed status to open

    How does the QGIS layer tree look like, does it still contains the layer which is removed from the EnMAP-Box layer tree?

  2. Andreas Janz reporter

    Alright, when QGIS is running, I can see those layers in the Layers panel and delete them manually.

  3. Andreas Janz reporter

    Can you prevent that the layers are opened in QGIS in the first place? Or don’t we have controll over that?

  4. Andreas Janz reporter

    How about a button that removes all QgsProject.mapLayers() that aren’t owned by the EnMAP-Box? Simple and easy.

  5. Benjamin Jakimow

    This seems to be related to the way how QGIS processes QgsProcessingAlgorithm. So I thinks it’s better if you find a solution for, as as you have already developed most (if not all) of our QgsProcessingAlgorithms.

  6. Andreas Janz reporter

    Is this a serious suggestion?

    Why not? A common usecase is to just use the EnMAP-Box with a minimized QGIS.

  7. Andreas Janz reporter

    I would suggest you check the processing panel:

    If you can’t prevent QGIS from loading the layers into the QgsProject.mapLayers() list, I would really suggest the “Close non-EnMAP-Box layer” button, which I’m happy to implement.

  8. Benjamin Jakimow

    This look to me like implementing a dirty workaround that could remove potentially important project layers (e.g. those created by other QGIS projects or were users spend hours to setup a sophisticated layer styling)
    I would prefer to discuss this in the following order:
    1. how would the optimal solution look like?
    2. how can we achieve this optimal solution? This requires to better understand the QGIS API, e.g. why such layers are loaded to the QGIS layer. QGIS is open source - just check QGIS\python\plugins\processing processing
    3. if the optimal solution is too complicated, what would be a solution with less negative side-effects?

  9. Benjamin Jakimow

    addressing 1., it could be an idea to show processing framework results which have been started from the EnMAP-Box within the EnMAP-Box only.
    In principle this should be possible running these processing algorithms with a modified QgsProcessingContext.

  10. Andreas Janz reporter

    addressing 1., it could be an idea to show processing framework results which have been started from the EnMAP-Box within the EnMAP-Box only.

    Sounds very good! 👍

  11. Benjamin Jakimow

    However, it probably requires some upstream fixes in QGIS, as their processing plugin python assumes in several places that QgsProject is QgsProject.instance()

  12. Agustin Lobo

    Wow! that’s really handy! no option in the GUI? Something like “Show EnMapBox maplayer only”?

    If the user is using EnMapBox, should this not be the default?

  13. Andreas Janz reporter

    To show EnMAP-Box maplayers only use QgsMapLayerComboBox().setProject(enmapbox.project())

    @Benjamin Jakimow no, that isn’t a good solution. When I manually add a layer to QGIS, I want to be able to select that layer in the QgsMapLayerComboBox widget.

  14. Benjamin Jakimow

    According to the title of this isse you don’t want to see layers which are not opened in the EnMAP-Box.
    So I don’t get the problem.

  15. Andreas Janz reporter

    Yes, QgsMapLayerComboBox().setProject(enmapbox.project()) will solve the problem described in the title.

    BUT: it will introduce a new problem. When I manually add a layer to QGIS, this layer can’t be selected anymore.

  16. Benjamin Jakimow

    @Andreas Janz indeed. because its in QGIS but not the EnMAP-Box. Just add it to a EnMAP-Box layer tree and it will become available.

  17. Andreas Janz reporter

    Alright, yes, the QgsMapLayerComboBox().setProject(enmapbox.project()) option is a possible way to go.

    BUT: it would be better, if the result layers from processing algorithms executed from within the EnMAP-Box wouldn’t be opened in the QGIS Layers panel, in the first place. But I guess, we can’t fix that behaviour easily?

  18. Log in to comment