Skip to content

Commit

Permalink
removed vector layer filter
Browse files Browse the repository at this point in the history
layer selection is by ID and not added Icons for layer_select
  • Loading branch information
bogind committed Jul 17, 2022
1 parent 86ad17a commit ece9ef7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
46 changes: 38 additions & 8 deletions qlyrx.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,48 @@ def LoadStyle(self):
layer.triggerRepaint()


def getIcon(self,layer):
layerType = layer.type()
provider = layer.providerType()
if layerType == 0:
# Vector
geomType = layer.geometryType()
if geomType == 0:
# Points
icon = QIcon(":images/themes/default/mIconPointLayer.svg")
elif geomType == 1:
# Lines
icon = QIcon(":images/themes/default/mIconLineLayer.svg")
elif geomType == 2:
# Polygons
icon = QIcon(":images/themes/default/mIconPolygonLayer.svg")
else:
# Tables, maybe filter in advance
icon = QIcon(":images/themes/default/mIconTableLayer.svg")
elif layerType == 1:
# Raster
if provider == "wms":
icon = QIcon(":images/themes/default/mIconWms.svg")
elif provider == "gdal":
icon = QIcon(":images/themes/default/mIconRaster.svg")
elif provider == "arcgismapserver":
icon = QIcon(":images/themes/default/mIconRaster.svg")
elif layerType == 3:
icon = QIcon(":images/themes/default/mIconMeshLayer.svg")
return icon


def load_vectors(self):
"""
Populate the layer selection with vector layers only
"""
self.dlg.layer_select.clear()
# Filter vector layers
layers = [layer for layer in QgsProject.instance().mapLayers().values() if layer.type() == 0]
vector_layers = []
layers = [layer for layer in QgsProject.instance().mapLayers().values()]
for layer in layers:
#if layer.type() == QgsMapLayer.VectorLayer:
vector_layers.append(layer.name())
self.dlg.layer_select.addItems(vector_layers)
icon = self.getIcon(layer)
name = layer.name()
userData = {'id':layer.id()}
self.dlg.layer_select.addItem(icon,name,userData)


def enableQmlSaving(self):
Expand All @@ -258,8 +288,8 @@ def saveQML(self,layer):
def read_lyrx(self, file=None):
with open(file, mode="r", encoding="utf-8") as json_file:
data = json.load(json_file)
layerName = self.dlg.layer_select.currentText()
layer = [layer for layer in QgsProject.instance().mapLayers().values() if layer.name() == layerName][0]
layerID = self.dlg.layer_select.currentData()["id"]
layer = [layer for layer in QgsProject.instance().mapLayers().values() if layer.id() == layerID][0]
self.styler.initial_lyrx_parse(data,layer)
return data

Expand Down
8 changes: 4 additions & 4 deletions resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Resource object code
#
# Created by: The Resource Compiler for PyQt5 (Qt v5.11.2)
# Created by: The Resource Compiler for PyQt5 (Qt v5.15.2)
#
# WARNING! All changes made in this file will be lost!

Expand Down Expand Up @@ -2667,11 +2667,11 @@
\x00\x00\x00\x14\x00\x02\x00\x00\x00\x03\x00\x00\x00\x03\
\x00\x00\x00\x00\x00\x00\x00\x00\
\x00\x00\x00\x62\x00\x00\x00\x00\x00\x01\x00\x00\x68\x4c\
\x00\x00\x01\x74\xe4\x44\x3e\x4b\
\x00\x00\x01\x7c\x68\xbb\xa0\xd6\
\x00\x00\x00\x44\x00\x00\x00\x00\x00\x01\x00\x00\x31\xaa\
\x00\x00\x01\x74\xf4\xb9\x29\xac\
\x00\x00\x01\x7c\x68\xbb\xa0\xd6\
\x00\x00\x00\x24\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\
\x00\x00\x01\x74\xf4\xb6\xc6\xa4\
\x00\x00\x01\x7c\x68\xbb\xa0\xd6\
"

qt_version = [int(v) for v in QtCore.qVersion().split('.')]
Expand Down

0 comments on commit ece9ef7

Please sign in to comment.