def getLayers():
        layers = []
        for l in QgsMapLayerRegistry.instance().mapLayers().values():
            if TLayer.isTLayer(l):
                layers.append(l)

        return layers
Exemplo n.º 2
0
    def getLayers():
        layers = []
        for l in QgsMapLayerRegistry.instance().mapLayers().values():
            if TLayer.isTLayer(l):
                layers.append(l)

        return layers
    def currentLayerChanged(self):
        layer = self._iface.activeLayer()
        # Ensure settings dialog doesn't come up

        if TLayer.isTLayer(layer):
            QSettings().setValue('/qgis/digitizing/disable_enter_attribute_values_dialog', True)
        else:
            QSettings().setValue('/qgis/digitizing/disable_enter_attribute_values_dialog',
                                 self._disable_enter_attribute_values_dialog_global_default)
Exemplo n.º 4
0
    def currentLayerChanged(self):
        layer = self._iface.activeLayer()
        # Ensure settings dialog doesn't come up

        if TLayer.isTLayer(layer):
            QSettings().setValue(
                '/qgis/digitizing/disable_enter_attribute_values_dialog', True)
        else:
            QSettings().setValue(
                '/qgis/digitizing/disable_enter_attribute_values_dialog',
                self._disable_enter_attribute_values_dialog_global_default)
    def rebuildLegend(self):
        
        if layerManager._rebuildingLegend:
            return

        layerManager._rebuildingLegend = True

        root = QgsProject.instance().layerTreeRoot()
        try:
            parentsToRoot = []
            for lid, tLayer in self.getTLayers(False).iteritems():
                if Brokers.instance().find(TLayer.getBrokerId(tLayer.layer())) is None:
                    continue

                broker = tLayer.getBroker()
                nodeLayer = self._addLayerToGroup(tLayer.layer(), broker)
                if not nodeLayer:
                    return
                if nodeLayer and nodeLayer.parent().parent() != root:
                    if not nodeLayer.parent() in parentsToRoot:
                        parentsToRoot.append(nodeLayer.parent())

            # handle nested node groups!
            for parent in parentsToRoot:
                broker = Brokers.instance().findByName(parent.name())
                nodeGroup = root.addGroup(broker.name())
                nodeGroup.setCustomProperty(TLayer.kBrokerId, broker.id())
                for child in parent.findLayers():
                    nodeGroup.insertChildNode(1, child.clone())
                parent.removeAllChildren()
                parent.parent().removeChildNode(parent)
                

            # handle removed brokers
            removed = []
            for lid in root.findLayerIds():
                layer = QgsMapLayerRegistry.instance().mapLayer(lid)
                if TLayer.isTLayer(layer):
                    bid = TLayer.getBrokerId(layer)
                    if Brokers.instance().find(bid) is None:
                        Log.debug("Broker not found")
                        nodeLayer = root.findLayer(lid)
                        if not nodeLayer.parent().name() in removed:
                            removed.append(nodeLayer.parent())
                        root.removeChildNode(nodeLayer)

            # Remove empty or groups referencing older renamed brokers
            for node in root.children():
                if self._isBrokerGroup(node) and not node.children():
                    removed.append(node)
             
            # perform removal                
            for node in removed:
                #Log.progress("Broker " + group + " not found in list of Brokers. Removing from legend")
                #nodeGrp     = root.findGroup(group)
                root.removeChildNode(node)
    
        except Exception as e:
            Log.debug(e)
            exc_type, exc_value, exc_traceback = sys.exc_info()
            Log.debug(repr(traceback.format_exception(exc_type, exc_value,
                                                      exc_traceback)))

        layerManager._rebuildingLegend = False
Exemplo n.º 6
0
    def rebuildLegend(self):

        if layerManager._rebuildingLegend:
            return

        layerManager._rebuildingLegend = True

        root = QgsProject.instance().layerTreeRoot()

        try:
            parentsToRoot = []
            for lid, tLayer in self.getTLayers(False).iteritems():
                if Brokers.instance().find(TLayer.getBrokerId(
                        tLayer.layer())) is None:
                    continue

                broker = tLayer.getBroker()
                nodeLayer = self._addLayerToGroup(tLayer.layer(), broker)
                if not nodeLayer:
                    return
                if nodeLayer and nodeLayer.parent().parent() != root:
                    if not nodeLayer.parent() in parentsToRoot:
                        parentsToRoot.append(nodeLayer.parent())

            # handle nested node groups!
            for parent in parentsToRoot:
                broker = Brokers.instance().findByName(parent.name())
                nodeGroup = root.addGroup(broker.name())
                nodeGroup.setCustomProperty(TLayer.kBrokerId, broker.id())
                for child in parent.findLayers():
                    nodeGroup.insertChildNode(1, child.clone())
                parent.removeAllChildren()
                parent.parent().removeChildNode(parent)

            # handle removed brokers
            removed = []
            for lid in root.findLayerIds():
                layer = QgsMapLayerRegistry.instance().mapLayer(lid)
                if TLayer.isTLayer(layer):
                    bid = TLayer.getBrokerId(layer)
                    if Brokers.instance().find(bid) is None:
                        Log.debug("Broker not found")
                        nodeLayer = root.findLayer(lid)
                        if not nodeLayer.parent().name() in removed:
                            removed.append(nodeLayer.parent())
                        root.removeChildNode(nodeLayer)

            # Remove empty or groups referencing older renamed brokers
            for node in root.children():
                if self._isBrokerGroup(node) and not node.children():
                    removed.append(node)

            # perform removal
            for node in removed:
                #Log.progress("Broker " + group + " not found in list of Brokers. Removing from legend")
                #nodeGrp     = root.findGroup(group)
                root.removeChildNode(node)

        except Exception as e:
            Log.debug(e)
            exc_type, exc_value, exc_traceback = sys.exc_info()
            Log.debug(
                repr(
                    traceback.format_exception(exc_type, exc_value,
                                               exc_traceback)))
        finally:
            layerManager._rebuildingLegend = False