From 4ab9bd44dda66b8dd17c36cf8324f19eb170bd96 Mon Sep 17 00:00:00 2001 From: Andrey Golovizin Date: Mon, 1 Sep 2014 21:27:43 +0200 Subject: [PATCH] Implement editing in GlyphDBEdit. --- pixelocr/gui/glyphdbedit.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pixelocr/gui/glyphdbedit.py b/pixelocr/gui/glyphdbedit.py index 39ed1c0..1449539 100644 --- a/pixelocr/gui/glyphdbedit.py +++ b/pixelocr/gui/glyphdbedit.py @@ -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)