diff options
-rw-r--r-- | src/mapdata.py | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/mapdata.py b/src/mapdata.py index c82021b..5e65599 100644 --- a/src/mapdata.py +++ b/src/mapdata.py @@ -8,6 +8,7 @@ class KPLayer(object): self.name = '' self.tileset = '' self.objects = [] + self.visible = True class KPNodeAction(object): @@ -68,8 +69,14 @@ class KPMap(object): def data(self, index, role = Qt.DisplayRole): try: - if (role == Qt.DisplayRole or role == Qt.EditRole) and index.isValid(): - return self.list[index.row()].name + if index.isValid(): + layer = self.list[index.row()] + + if (role == Qt.DisplayRole or role == Qt.EditRole): + return layer.name + elif role == Qt.CheckStateRole: + return (Qt.Checked if layer.visible else Qt.Unchecked) + except IndexError: pass @@ -79,14 +86,22 @@ class KPMap(object): if not index.isValid(): return Qt.ItemIsEnabled - return Qt.ItemIsEditable \ + return Qt.ItemIsEditable | Qt.ItemIsUserCheckable \ | QtCore.QAbstractListModel.flags(self, index) def setData(self, index, value, role = Qt.EditRole): - if index.isValid() and role == Qt.EditRole: - value = str(value.toString()) - if len(value) > 0: - self.list[index.row()].name = value + if index.isValid(): + layer = self.list[index.row()] + + if role == Qt.EditRole: + value = str(value.toString()) + if len(value) > 0: + layer.name = value + self.dataChanged.emit(index, index) + return True + + elif role == Qt.CheckStateRole: + layer.visible = value.toBool() self.dataChanged.emit(index, index) return True |