![]() ![]() The Saved Styles and Undo/Redo will always be the last in the stack regardless of the active layer type. ![]() These buttons change the style options in the main panel. On the side of the dock we have the different style options. You can also access the stack via the Python bindings if needed. I will also add that the undo stack is stored on the layer object itself, so closing the dock doesn’t clear the stack nor does changing the active layer. Undo/Redo now allows for fearless style changes, so style away to your hearts content and rollback anything you don’t like. Any style change will now add an entry to the style undo stack so you can rollback and forward any changes. Well not to fear we now have a undo/redo stack. What happens if you apply something you didn’t mean. This might not always be what you want so you can disable it for those cases and use manual apply. Every widget in the dock can request a redraw on change so you can see feedback instantly in the canvas. I really hated the open close, change, apply, repeat workflow of the old dialogs. One of the key things for me when doing this dock was instant feedback. No going back! Dock break downĪs you can see in the image there is a few main things in the dock, the layer selection, style options selector (come back to this later), undo/redo, live update and apply. I’m not bragging when I say that it will change your life in QGIS for the better, it has become a part of my daily workflow. If you haven’t used the style dock yet I would strongly encourage you to grab the nightly QGIS builds and give it a crack, F7 to open anytime, or use the paint brush icon on the layers panel. Nothing has made me feel more productive then working on this feature and seeing the gains it allows in day to day work. Of all the features I have added to QGIS this is my favorite. We now have styles (vector and raster), labels, saved styles, undo redo, and plugin support (yep!) After many iterations of the UIs and the APIs I’m pretty happy with the release state of the dock. The first stage was getting labels working and then moving on to styles. This post is part of a series exploring the new style dock.Ī while ago did a post about the new style dock in QGIS. This is just an example, hand editing xml is well gross, but I’m sure you can see great uses for being able to expand the style dock. The style state of the layer will also be saved to the undo stack so you don’t have to worry about that. Pro Tip: Raise widgetChanged whenever you need to tell the style dock to trigger the apply method. ![]() ![]() # Read the xml and set it back to the style. We can just connect this to the text changed event and add some logic to the apply method. Now can we 1 UP it and make it live edit? Sure can! The style dock will call apply() whenever we raise the widgetChanged signal. Iface.activeLayer().writeStyle( rootNode, doc, '') # Create the editor and set the xml from the layer. Adding some logic to the _init_ method of the CustomPanel class class CustomPanel(QgsLayerStylingPanel): As an example I’m going to load the style xml and show it in the panel. If your widget is expensive to create you can create a cache here. Remember, the create method is called any time this new item is selected. Using the above code we will see a new icon on the side panel This createPanel method will be called any time the item is selected in the left panel of the style dock. We also have the createPanel method which just returns the widget, you could also use this method to return different widgets based on layer type if you needed. This must return True if the layer can be supported for the widget, if the layer isn’t support it’s not shown in the layer style dock. You can also see we have a supportsLayer() method. Iface.registerMapStylePanelFactory(factory) # make sure you keep a instance of the the factory around # Also make a instance and tell the style dock about it Return CustomPanel(layer, canvas, parent) Return layer.type() = QgsMapLayer.VectorLayerĭef createPanel(self, layer, canvas, parent): The factory object looks like this: class PanelFactory(QgsLayerStylingPanelFactory): Then we need to create a factory object ( QgsLayerStylingPanelFactory) which will hold the metadata for the panel widget, things like icon, title, and the widget it self as required. Super(CustomPanel, self)._init_(layer, canvas, parent) While building the dock it became evident that being able to add your own panels with be super neat, why lock the user to what styling controls we have built into core.Īfter one, or two, API iterations it is now possible to add your own panels to the style dock.įirst we need to make a new widget using QgsLayerStylingPanel class CustomPanel(QgsLayerStylingPanel):ĭef _init_(self, layer, canvas, parent): In part 1 I talked about the new style dock and the in built functions it has in this post I would like to cover how you can extend that dock using plugin panels. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |