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

[FEATURE] Layer tree embedded widgets #3170

Merged
merged 7 commits into from Jun 3, 2016

Conversation

Projects
None yet
4 participants
@wonder-sk
Copy link
Member

wonder-sk commented Jun 2, 2016

This allows definition of widgets embedded into layer tree for individual layers in the layer properties dialog (in new Legend tab). The idea is to have a way to quickly access to some actions that are often used with a layer.

The implementation comes with transparency widget, in the future there may be more standard widgets coming, e.g. to setup filtering, selection, style or other stuff. The API allows plugins to register their own widgets, which will be useful for various domain specific plugins to assign custom widgets to layers they manage.

Here's an implementation of a simple combo box to switch current style of a layer:

qgis-embedded-widget

from PyQt4.QtGui import QComboBox

from qgis.core import QgsMapLayer
from qgis.gui import QgsLayerTreeEmbeddedWidgetProvider, QgsLayerTreeEmbeddedWidgetRegistry

class LayerStyleComboBox(QComboBox):

    def __init__(self, layer):
        QComboBox.__init__(self)
        self.layer = layer

        for style_name in layer.styleManager().styles():
            self.addItem(style_name)

        idx = self.findText(layer.styleManager().currentStyle())
        if idx != -1:
          self.setCurrentIndex(idx)

        self.currentIndexChanged.connect(self.on_current_changed)

    def on_current_changed(self, index):
        self.layer.styleManager().setCurrentStyle(self.itemText(index))


class LayerStyleWidgetProvider(QgsLayerTreeEmbeddedWidgetProvider):

    def __init__(self):
        QgsLayerTreeEmbeddedWidgetProvider.__init__(self)

    def id(self):
        return "style"

    def name(self):
        return "Layer style chooser"

    def createWidget(self, layer, widgetIndex):
        return LayerStyleComboBox(layer)

    def supportsLayer(self, layer):
        return True   # any layer is fine


provider = LayerStyleWidgetProvider()

QgsLayerTreeEmbeddedWidgetRegistry.instance().addProvider(provider)

If there are no objections, I would like to merge it for 2.16

@NathanW2

This comment has been minimized.

Copy link
Member

NathanW2 commented Jun 2, 2016

Nice!

On Fri, Jun 3, 2016 at 7:27 AM, Martin Dobias notifications@github.com
wrote:

This allows definition of widgets embedded into layer tree for individual
layers in the layer properties dialog (in new Legend tab). The idea is to
have a way to quickly access to some actions that are often used with a
layer.

The implementation comes with transparency widget, in the future there may
be more standard widgets coming, e.g. to setup filtering, selection, style
or other stuff. The API allows plugins to register their own widgets, which
will be useful for various domain specific plugins to assign custom widgets
to layers they manage.

Here's an implementation of a simple combo box to switch current style of
a layer:

[image: qgis-embedded-widget]
https://cloud.githubusercontent.com/assets/193367/15761574/43f248b6-2919-11e6-8337-62da6ef0f0da.png

from PyQt4.QtGui import QComboBox
from qgis.core import QgsMapLayerfrom qgis.gui import QgsLayerTreeEmbeddedWidgetProvider, QgsLayerTreeEmbeddedWidgetRegistry
class LayerStyleComboBox(QComboBox):

def __init__(self, layer):
    QComboBox.__init__(self)
    self.layer = layer

    for style_name in layer.styleManager().styles():
        self.addItem(style_name)

    idx = self.findText(layer.styleManager().currentStyle())
    if idx != -1:
      self.setCurrentIndex(idx)

    self.currentIndexChanged.connect(self.on_current_changed)

def on_current_changed(self, index):
    self.layer.styleManager().setCurrentStyle(self.itemText(index))

class LayerStyleWidgetProvider(QgsLayerTreeEmbeddedWidgetProvider):

def __init__(self):
    QgsLayerTreeEmbeddedWidgetProvider.__init__(self)

def id(self):
    return "style"

def name(self):
    return "Layer style chooser"

def createWidget(self, layer, widgetIndex):
    return LayerStyleComboBox(layer)

def supportsLayer(self, layer):
    return True   # any layer is fine

provider = LayerStyleWidgetProvider()

QgsLayerTreeEmbeddedWidgetRegistry.instance().addProvider(provider)

If there are no objections, I would like to merge it for 2.16

You can view, comment on, or merge this pull request online at:

#3170
Commit Summary

  • Integration of embedded widgets into layer tree + config GUI
  • Refactoring
  • Integrate into layer dialogs, save in layer's properties
  • Handle legend node in parent gracefully with embedded widgets
  • Update API docs
  • Added python bindings

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#3170, or mute the thread
https://github.com/notifications/unsubscribe/AAXS3G1BLO4MkxvWv9raYIlKQZsTnJXTks5qH0rEgaJpZM4Is_6Z
.

@nyalldawson

This comment has been minimized.

Copy link
Contributor

nyalldawson commented Jun 2, 2016

Code and testing looks good. +1 to merge

Only one very minor thing : the transparency slider is much slower than the same one in the styling dock. @NathanW2 i think that uses a timeout to prevent trying to refresh the map too often, right? A similar approach should be used here. But it's not a blocker, since that widget isn't enabled by default anyway.

@NathanW2

This comment has been minimized.

Copy link
Member

NathanW2 commented Jun 2, 2016

Yeah I use a 100ms delay on any updates for that reason.

On Fri, Jun 3, 2016 at 8:41 AM, Nyall Dawson notifications@github.com
wrote:

Code and testing looks good. +1 to merge

Only one very minor thing : the transparency slider is much slower than
the same one in the styling dock. @NathanW2 https://github.com/nathanw2
i think that uses a timeout to prevent trying to refresh the map too often,
right? A similar approach should be used here. But it's not a blocker,
since that widget isn't enabled by default anyway.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#3170 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAXS3NfSqdIsSj5qZHje8japIxEFTgTHks5qH1wLgaJpZM4Is_6Z
.

@mhugo

This comment has been minimized.

Copy link
Contributor

mhugo commented Jun 3, 2016

Very cool feature, thanks !

@wonder-sk

This comment has been minimized.

Copy link
Member Author

wonder-sk commented Jun 3, 2016

Thanks for the review and hints guys - added the delayed update and the GUI indeed feels much snappier!

@wonder-sk wonder-sk merged commit 9c7dbb9 into qgis:master Jun 3, 2016

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.