-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Plugin layer registry #12452
Comments
Author Name: luca76 - (luca76 -) +1 very interesting patch! |
Author Name: Marco Hugentobler (@mhugent) Martin, do you have time to review this patch? |
Author Name: Martin Dobias (@wonder-sk) Applied in 8f32f25 (SVN r12835) with several modifications:
I've modified also the sample plugin to reflect my changes. Sample plugin from the example:
Definition of the layer's type with auxiliary methods:
Registration:
Creation of the layer:
Finalization:
|
@bnegruimajing feel free to open a new issue if something is not working correctly and attach your testing code and more details (qgis version etc) |
@wonder-sk please disregard my remark. while building the sample for the bug report, I realized that the "# write plugin layer type to project (essential to be read from project)" comment in SamplePluginLayer.writeXml is not just sample code but actually quite important. I was expecting the QgsPluginLayer base class to take care of the necessary attributes to identify a plugin layer. |
Author Name: Mathias Walker (Mathias Walker)
Original Redmine Issue: 2392
Redmine category:python_plugins
Assignee: Martin Dobias
This patch adds a plugin layer registry to support plugin specific maplayers.
Plugins can register a function that creates the specific subclass of QgsMapLayer. This allows to instantiate the corresponding plugin layer when reading the project file.
Workflow
see sample plugin for details
create subclass of @QgsMapLayer@
*** implement @isEditable()@, @draw()@ and @writeXml()@
create subclass of @QgsPluginLayerCreator@
*** implement @Createlayer()@ e.g. as callback to a plugin function
init plugin
*** register PluginLayerCreator using @QgsPluginLayerRegistry.instance().addCreator()@
add layer
*** create PluginMapLayer instance of layer type @QgsMapLayer.PluginLayer@
*** add layer using @QgsMapLayerRegistry.instance().addMapLayer()@
save project
*** calls @PluginMapLayer.writeXml()@
*** save plugin id string as attribute @"type"@
load project
*** @QgsPluginLayerRegistry@ calls @Createlayer()@ for all registered @QgsPluginLayerCreators@
*** plugin creates and adds a new PluginMapLayer instance if the attribute @"type"@ matches their id string
unload plugin
*** unregister PluginLayerCreator using @QgsPluginLayerRegistry.instance().removeCreator()@
The text was updated successfully, but these errors were encountered: