Implement editing in GlyphDBEdit.
This commit is contained in:
parent
ce3353c831
commit
4ab9bd44dd
1 changed files with 23 additions and 0 deletions
|
|
@ -34,9 +34,13 @@ from ..image import Image
|
|||
|
||||
class Column(object):
|
||||
header = None
|
||||
|
||||
def data(self, glyph_data):
|
||||
return None
|
||||
|
||||
def set_data(self, glyph_data, value):
|
||||
raise NotImplementedError
|
||||
|
||||
def image(self, glyph_data):
|
||||
return None
|
||||
|
||||
|
|
@ -50,6 +54,9 @@ class TextColumn(Column):
|
|||
def data(self, glyph_data):
|
||||
return glyph_data.text
|
||||
|
||||
def setData(self, glyph_data, value):
|
||||
glyph_data.text = value
|
||||
|
||||
def image(self, glyph_data):
|
||||
return glyph_data.image.qimage
|
||||
|
||||
|
|
@ -63,6 +70,9 @@ class ElevationColumn(Column):
|
|||
def sortKey(self, glyph_data):
|
||||
return glyph_data.elevation
|
||||
|
||||
def setData(self, glyph_data, value):
|
||||
glyph_data.elevation = value
|
||||
|
||||
|
||||
class GlyphDBModel(QAbstractTableModel):
|
||||
COLUMNS = [
|
||||
|
|
@ -77,6 +87,9 @@ class GlyphDBModel(QAbstractTableModel):
|
|||
self.reverse = None
|
||||
self.updateData()
|
||||
|
||||
def flags(self, index):
|
||||
return super().flags(index) | Qt.ItemIsEditable
|
||||
|
||||
def rowCount(self, parent):
|
||||
return len(self.values)
|
||||
|
||||
|
|
@ -94,6 +107,16 @@ class GlyphDBModel(QAbstractTableModel):
|
|||
return column.data(data)
|
||||
elif role == Qt.DecorationRole:
|
||||
return column.image(data)
|
||||
elif role == Qt.EditRole:
|
||||
return column.data(data)
|
||||
|
||||
def setData(self, index, value, role):
|
||||
glyph_data = self.values[index.row()]
|
||||
column = self.COLUMNS[index.column()]
|
||||
if role == Qt.EditRole:
|
||||
column.setData(glyph_data, value)
|
||||
self.dataChanged.emit(index, index)
|
||||
return True
|
||||
|
||||
def removeRows(self, row, count, parent=None):
|
||||
self.beginRemoveRows(parent, row, row + count - 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue