コード例 #1
0
    def __init__(self, id, name, datatype, source, ressource):

        # unfortunately there is no option to retrieve the layer geometry (i. e.
        # point/line/polygon for vectorlayers) just from the json object.
        # Therefore they get a default polygon icon which will be updated as soon as
        # layer is added as WFS to QGIS - see def addQgsLayer()
        if datatype == 'Raster':
            self.icon = QgsLayerItem.iconRaster()
        elif datatype == 'Vector':
            self.icon = QgsLayerItem.iconPolygon()
        else:
            self.icon = QgsLayerItem.iconDefault()
        TreeItem.__init__(self, self.icon, name)
        self.id = id
        self.actiontype = 'layer'
        self.ressource = ressource
        self.dlg = None
        self.name = name
        self.source = source
        self.datatype = datatype
        self.qgisLayers = []
        self.settings = {
            'name': '',
            'appearance': {
                'hoverTemplate': None,
                'opacity': 1
            }
        }
        if PYTHON_VERSION >= 3:
            QgsProject.instance().layerRemoved.connect(self.updateLayerList)
        else:
            QgsMapLayerRegistry.instance().layerRemoved.connect(
                self.updateLayerList)
コード例 #2
0
def icon_per_geometry_type(geometry_type: str):
    """Return the icon for a geometry type.

    If not found, it will return the default icon.

    :param geometry_type: The geometry as a string.
    :type geometry_type: basestring

    :return: The icon.
    :rtype: QIcon
    """
    geometry_type = geometry_type.lower()
    if geometry_type == "raster":
        return QgsLayerItem.iconRaster()
    elif geometry_type == "mesh":
        return QgsLayerItem.iconMesh()
    elif geometry_type == "point":
        return QgsLayerItem.iconPoint()
    elif geometry_type == "line":
        return QgsLayerItem.iconLine()
    elif geometry_type == "polygon":
        return QgsLayerItem.iconPolygon()
    elif geometry_type == "no geometry":
        return QgsLayerItem.iconTable()
    else:
        return QgsLayerItem.iconDefault()
コード例 #3
0
ファイル: lyr_items.py プロジェクト: nyalldawson/slyr
    def __init__(self, parent, name, path, lyr_object=None, layer_path=''):
        super().__init__(QgsDataItem.Custom, parent, name, path)
        self.setCapabilities(QgsDataItem.Fertile | QgsDataItem.Collapse)
        self.layer_path = layer_path or path
        self.object = lyr_object
        if path:
            self.setIcon(GuiUtils.get_icon('icon.svg'))
        elif isinstance(self.object, (GroupLayer, BaseMapLayer)):
            self.setIcon(QgsDataCollectionItem.iconDir())
        elif self.object.__class__.__name__ in ('WmsMapLayer', 'RasterLayer'):
            self.setIcon(QgsLayerItem.iconRaster())
        else:
            wkb_type = VectorLayerConverter.layer_to_wkb_type(self.object)
            geometry_type = QgsWkbTypes.geometryType(wkb_type)
            if geometry_type == QgsWkbTypes.PointGeometry:
                self.setIcon(QgsLayerItem.iconPoint())
            elif geometry_type == QgsWkbTypes.LineGeometry:
                self.setIcon(QgsLayerItem.iconLine())
            elif geometry_type == QgsWkbTypes.PolygonGeometry:
                self.setIcon(QgsLayerItem.iconPolygon())
            else:
                self.setIcon(QgsLayerItem.iconDefault())

        if self.object:
            if isinstance(self.object, (GroupLayer, BaseMapLayer)):
                self.add_children()
            self.setState(QgsDataItem.Populated)
        self.setToolTip(
            QDir.toNativeSeparators(path) if not lyr_object else lyr_object.
            name)
        self.child_items = []
コード例 #4
0
    def __init__(self, parent, name, path, object=None, layer_path=''):
        super().__init__(QgsDataItem.Custom, parent, name, path)
        self.setCapabilities(QgsDataItem.Fertile | QgsDataItem.Collapse)
        self.layer_path = layer_path or path
        self.object = object
        if path:
            self.setIcon(GuiUtils.get_icon('icon.svg'))
        else:
            self.setIcon(QgsLayerItem.iconDefault())

        if self.object:
            self.setState(QgsDataItem.Populated)
        self.setToolTip(QDir.toNativeSeparators(path) if not object else object.name)
        self.child_items = []
コード例 #5
0
ファイル: gis.py プロジェクト: inasafe/inasafe
def layer_icon(layer):
    """Helper to get the layer icon.

    :param layer: A layer.
    :type layer: QgsMapLayer

    :returns: The icon for the given layer.
    :rtype: QIcon
    """
    if is_raster_layer(layer):
        return QgsLayerItem.iconRaster()
    elif is_point_layer(layer):
        return QgsLayerItem.iconPoint()
    elif is_line_layer(layer):
        return QgsLayerItem.iconLine()
    elif is_polygon_layer(layer):
        return QgsLayerItem.iconPolygon()
    else:
        return QgsLayerItem.iconDefault()
コード例 #6
0
ファイル: gis.py プロジェクト: north-road/inasafe
def layer_icon(layer):
    """Helper to get the layer icon.

    :param layer: A layer.
    :type layer: QgsMapLayer

    :returns: The icon for the given layer.
    :rtype: QIcon
    """
    if is_raster_layer(layer):
        return QgsLayerItem.iconRaster()
    elif is_point_layer(layer):
        return QgsLayerItem.iconPoint()
    elif is_line_layer(layer):
        return QgsLayerItem.iconLine()
    elif is_polygon_layer(layer):
        return QgsLayerItem.iconPolygon()
    else:
        return QgsLayerItem.iconDefault()