Add Bool and Italic columns to GlyphDBEdit.
This commit is contained in:
parent
4ab9bd44dd
commit
215d814777
1 changed files with 36 additions and 1 deletions
|
|
@ -44,6 +44,9 @@ class Column(object):
|
||||||
def image(self, glyph_data):
|
def image(self, glyph_data):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def checkState(self, glyph_data):
|
||||||
|
return None
|
||||||
|
|
||||||
def sortKey(self, glyph_data):
|
def sortKey(self, glyph_data):
|
||||||
return self.data(glyph_data)
|
return self.data(glyph_data)
|
||||||
|
|
||||||
|
|
@ -74,10 +77,38 @@ class ElevationColumn(Column):
|
||||||
glyph_data.elevation = value
|
glyph_data.elevation = value
|
||||||
|
|
||||||
|
|
||||||
|
class BoldColumn(Column):
|
||||||
|
header = 'Bold'
|
||||||
|
|
||||||
|
def sortKey(self, glyph_data):
|
||||||
|
return glyph_data.bold
|
||||||
|
|
||||||
|
def checkState(self, glyph_data):
|
||||||
|
return Qt.Checked if glyph_data.bold else Qt.Unchecked
|
||||||
|
|
||||||
|
def setData(self, glyph_data, value):
|
||||||
|
glyph_data.bold = value
|
||||||
|
|
||||||
|
|
||||||
|
class ItalicColumn(Column):
|
||||||
|
header = 'Italic'
|
||||||
|
|
||||||
|
def sortKey(self, glyph_data):
|
||||||
|
return glyph_data.italic
|
||||||
|
|
||||||
|
def checkState(self, glyph_data):
|
||||||
|
return Qt.Checked if glyph_data.italic else Qt.Unchecked
|
||||||
|
|
||||||
|
def setData(self, glyph_data, value):
|
||||||
|
glyph_data.italic = value
|
||||||
|
|
||||||
|
|
||||||
class GlyphDBModel(QAbstractTableModel):
|
class GlyphDBModel(QAbstractTableModel):
|
||||||
COLUMNS = [
|
COLUMNS = [
|
||||||
TextColumn(),
|
TextColumn(),
|
||||||
ElevationColumn(),
|
ElevationColumn(),
|
||||||
|
BoldColumn(),
|
||||||
|
ItalicColumn(),
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, glyphdb, parent=None):
|
def __init__(self, glyphdb, parent=None):
|
||||||
|
|
@ -88,7 +119,7 @@ class GlyphDBModel(QAbstractTableModel):
|
||||||
self.updateData()
|
self.updateData()
|
||||||
|
|
||||||
def flags(self, index):
|
def flags(self, index):
|
||||||
return super().flags(index) | Qt.ItemIsEditable
|
return super().flags(index) | Qt.ItemIsEditable | Qt.ItemIsUserCheckable
|
||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
return len(self.values)
|
return len(self.values)
|
||||||
|
|
@ -109,12 +140,16 @@ class GlyphDBModel(QAbstractTableModel):
|
||||||
return column.image(data)
|
return column.image(data)
|
||||||
elif role == Qt.EditRole:
|
elif role == Qt.EditRole:
|
||||||
return column.data(data)
|
return column.data(data)
|
||||||
|
elif role == Qt.CheckStateRole:
|
||||||
|
return column.checkState(data)
|
||||||
|
|
||||||
def setData(self, index, value, role):
|
def setData(self, index, value, role):
|
||||||
glyph_data = self.values[index.row()]
|
glyph_data = self.values[index.row()]
|
||||||
column = self.COLUMNS[index.column()]
|
column = self.COLUMNS[index.column()]
|
||||||
if role == Qt.EditRole:
|
if role == Qt.EditRole:
|
||||||
column.setData(glyph_data, value)
|
column.setData(glyph_data, value)
|
||||||
|
if role == Qt.CheckStateRole:
|
||||||
|
column.setData(glyph_data, value == Qt.Checked)
|
||||||
self.dataChanged.emit(index, index)
|
self.dataChanged.emit(index, index)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue