From e86dd60fb52a68ef96930bfa4f2632265bf629fa Mon Sep 17 00:00:00 2001 From: Treeki Date: Fri, 4 Nov 2011 00:18:33 +0100 Subject: added checks for layer visibility (though they do nothing so far) --- src/mapdata.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src') 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 -- cgit v1.2.3