summaryrefslogtreecommitdiff
path: root/src/mapdata.py
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2011-11-04 00:04:26 +0100
committerTreeki <treeki@gmail.com>2011-11-04 00:04:26 +0100
commit2015541472eb19b8039e98bfeec3aa5678dd0b75 (patch)
treef101114b55d27883d0ca4681602e12d05a4b4c26 /src/mapdata.py
parentfd78999a93710ba53c915779c126e664323a728f (diff)
downloadkoopatlas-2015541472eb19b8039e98bfeec3aa5678dd0b75.tar.gz
koopatlas-2015541472eb19b8039e98bfeec3aa5678dd0b75.zip
finally fixed the layer models and such crap
Diffstat (limited to '')
-rw-r--r--src/mapdata.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/mapdata.py b/src/mapdata.py
index 2a19da6..c82021b 100644
--- a/src/mapdata.py
+++ b/src/mapdata.py
@@ -1,4 +1,9 @@
+from common import *
+
class KPLayer(object):
+ def __repr__(self):
+ return "<KPLayer %r>" % self.name
+
def __init__(self):
self.name = ''
self.tileset = ''
@@ -42,13 +47,95 @@ class KPMap(object):
self.nextLayerNumber = 1
self.layers = [self.createNewLayer() for x in range(4)]
+ self.layerModel = KPMap.LayerModel(self.layers)
self.nodes = []
self.paths = []
self.doodads = []
+
+ # LAYERS
+ class LayerModel(QtCore.QAbstractListModel):
+ def __init__(self, layerList):
+ QtCore.QAbstractListModel.__init__(self)
+ self.list = layerList
+
+
+ def headerData(self, section, orientation, role = Qt.DisplayRole):
+ return 'Layer'
+
+ def rowCount(self, parent):
+ return len(self.list)
+
+ 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
+ except IndexError:
+ pass
+
+ return QtCore.QVariant()
+
+ def flags(self, index):
+ if not index.isValid():
+ return Qt.ItemIsEnabled
+
+ return Qt.ItemIsEditable \
+ | 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
+ self.dataChanged.emit(index, index)
+ return True
+
+ return False
+
+
def createNewLayer(self):
layer = KPLayer()
layer.name = "Layer %d" % self.nextLayerNumber
self.nextLayerNumber += 1
return layer
+ def appendLayer(self, layer):
+ return self.insertLayer(len(self.layers), layer)
+
+ def insertLayer(self, index, layer):
+ self.layerModel.beginInsertRows(QtCore.QModelIndex(), index, index)
+ self.layers.insert(index, layer)
+ self.layerModel.endInsertRows()
+ return index
+
+ def moveLayer(self, fromIndex, toIndex):
+ if fromIndex == toIndex:
+ return
+ if fromIndex < 0 or toIndex < 0:
+ raise ValueError
+ if fromIndex >= len(self.layers) or toIndex > len(self.layers):
+ raise ValueError
+
+ self.layerModel.beginMoveRows(
+ QtCore.QModelIndex(), fromIndex, fromIndex,
+ QtCore.QModelIndex(), toIndex)
+
+ toMove = self.layers[fromIndex]
+ newIndex = ((toIndex > fromIndex) and (toIndex - 1)) or toIndex
+
+ del self.layers[fromIndex]
+ self.layers.insert(newIndex, toMove)
+
+ self.layerModel.endMoveRows()
+
+ return newIndex
+
+ def removeLayer(self, layer):
+ if layer not in self.layers:
+ raise ValueError
+
+ index = self.layers.index(layer)
+ self.layerModel.beginRemoveRows(QtCore.QModelIndex(), index, index)
+ del self.layers[index]
+ self.layerModel.endRemoveRows()
+