Skip to content

Commit

Permalink
Set layer type and consider available style-categories
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Oct 7, 2024
1 parent 5244b55 commit acbd713
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion QgisModelBaker/gui/topping_wizard/layer_style_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(self, parent=None):
self.style_categories_list_view.model().check
)
else:
self.model = QgsMapLayerStyleCategoriesModel(Qgis.LayerType.Vector)
self.model = QgsMapLayerStyleCategoriesModel(QgsMapLayer.VectorLayer)
self.style_categories_list_view.setModel(self.model)
self.style_categories_list_view.setWordWrap(True)
self.style_categories_list_view.setItemDelegate(
Expand All @@ -125,6 +125,13 @@ def __init__(self, parent=None):

self.ok_button.clicked.connect(self.accept)

def set_layer_type(self, type):
if Qgis.QGIS_VERSION_INT < 34000:
return
# we need to reset the model with new type
self.model = QgsMapLayerStyleCategoriesModel(type)
self.style_categories_list_view.setModel(self.model)

def select_all_items(self, state):
if Qgis.QGIS_VERSION_INT < 34000:
self.model.check_all(Qt.Checked if state else Qt.Unchecked)
Expand Down
13 changes: 13 additions & 0 deletions QgisModelBaker/gui/topping_wizard/layers_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class LayerModel(QgsLayerTreeModel):

class Roles(IntEnum):
CATEGORIES = Qt.UserRole + 1
LAYERTYPE = Qt.UserRole + 2

class Columns(IntEnum):
NAME = 0
Expand Down Expand Up @@ -205,6 +206,15 @@ def data(self, index, role):
"categories", QgsMapLayer.StyleCategory.AllStyleCategories
)

if (
role == LayerModel.Roles.LAYERTYPE
and index.column() == LayerModel.Columns.USE_STYLE
):
node = self.index2node(index)
if not QgsLayerTree.isGroup(node):
layer = QgsProject.instance().mapLayersByName(node.name())[0]
return layer.type()

return QgsLayerTreeModel.data(self, index, role)

# this is unusual that it's not first data and then role (could be changed)
Expand Down Expand Up @@ -561,6 +571,9 @@ def open_categories_dialog(self, index):
self.categories_dialog.setWindowTitle(
self.tr(f"Layer Style Categories of {layername}")
)
self.categories_dialog.set_layer_type(
index.data(int(LayerModel.Roles.LAYERTYPE))
)
categories = index.data(int(LayerModel.Roles.CATEGORIES))
self.categories_dialog.set_categories(categories)
if self.categories_dialog.exec_():
Expand Down

0 comments on commit acbd713

Please sign in to comment.