summaryrefslogtreecommitdiff
path: root/src/ui.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui.py')
-rw-r--r--src/ui.py53
1 files changed, 16 insertions, 37 deletions
diff --git a/src/ui.py b/src/ui.py
index 95ced0c..57c396b 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -3,38 +3,6 @@ from editorui import *
class KPLayerList(QtGui.QWidget):
- class LayerModel(QtCore.QAbstractListModel):
- def headerData(self, section, orientation, role = Qt.DisplayRole):
- return 'Layer'
-
- def rowCount(self, parent):
- return len(KP.map.layers)
-
- def data(self, index, role = Qt.DisplayRole):
- try:
- if (role == Qt.DisplayRole or role == Qt.EditRole) and index.isValid():
- return KP.map.layers[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:
- KP.map.layers[index.row()].name = value
- self.dataChanged.emit(index, index)
- return True
-
- return False
def __init__(self):
@@ -43,7 +11,7 @@ class KPLayerList(QtGui.QWidget):
self.layout = QtGui.QVBoxLayout()
self.layout.setSpacing(0)
- self.model = KPLayerList.LayerModel()
+ self.model = KP.map.layerModel
self.listView = QtGui.QListView()
self.listView.setModel(self.model)
@@ -64,14 +32,25 @@ class KPLayerList(QtGui.QWidget):
tb.addAction(QtGui.QIcon(), 'Move Down', self.moveDown)
+ def selectedLayerIndex(self):
+ return self.listView.selectionModel().currentIndex().row()
+ def selectedLayer(self):
+ return KP.map.layers[self.listView.selectionModel().currentIndex().row()]
+
+
def addLayer(self):
- pass
+ KP.map.appendLayer(KP.map.createNewLayer())
+
def removeLayer(self):
- pass
+ KP.map.removeLayer(self.selectedLayer())
+
def moveUp(self):
- pass
+ index = self.selectedLayerIndex()
+ KP.map.moveLayer(index, index - 1)
+
def moveDown(self):
- pass
+ index = self.selectedLayerIndex()
+ KP.map.moveLayer(index, index + 2)
class KPMainWindow(QtGui.QMainWindow):