Skip to content

Commit

Permalink
ENH: ToolTable Widget - make display columns configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtJacobson committed Feb 17, 2019
1 parent f0c5bdd commit 1b98795
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions qtpyvcp/widgets/input_widgets/tool_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def __init__(self, columns):
self._columns = columns
self._padding = ' ' * 2

def setColumns(self, columns):
self._columns = columns

def displayText(self, value, locale):

if type(value) == float:
Expand Down Expand Up @@ -84,6 +87,10 @@ def __init__(self, parent=None):
self.setColumnCount(self.columnCount())
self.setRowCount(100) # (self.rowCount())

def setColumns(self, columns):
self._columns = columns
self.setColumnCount(len(columns))

def headerData(self, section, orientation, role=Qt.DisplayRole):
if role == Qt.DisplayRole and orientation == Qt.Horizontal:
return self._column_labels[self._columns[section]]
Expand All @@ -101,7 +108,7 @@ def flags(self, index):

def data(self, index, role=Qt.DisplayRole):
if role == Qt.DisplayRole or role == Qt.EditRole:
key = self.tt.columns[index.column()]
key = self._columns[index.column()]
tnum = sorted(self._tool_table)[index.row() + 1]
return self._tool_table[tnum][key]

Expand All @@ -124,7 +131,7 @@ def data(self, index, role=Qt.DisplayRole):
return QStandardItemModel.data(self, index, role)

def setData(self, index, value, role):
key = self.tt.columns[index.column()]
key = self._columns[index.column()]
tnum = sorted(self._tool_table)[index.row() + 1]
self._tool_table[tnum][key] = value
return True
Expand Down Expand Up @@ -181,8 +188,8 @@ def __init__(self, parent=None):

self.tool_model = ToolModel(self)

delegate = ItemDelegate(columns=self.tool_model._columns)
self.setItemDelegate(delegate)
self.item_delegate = ItemDelegate(columns=self.tool_model._columns)
self.setItemDelegate(self.item_delegate)

self.proxy_model = QSortFilterProxyModel()
self.proxy_model.setFilterKeyColumn(0)
Expand All @@ -191,6 +198,7 @@ def __init__(self, parent=None):
self.setModel(self.proxy_model)

# Properties
self._columns = self.tool_model._columns
self._confirm_actions = False
self._current_tool_color = QColor('sage')

Expand Down Expand Up @@ -261,6 +269,16 @@ def confirmAction(self, message):
else:
return False

@Property(str)
def displayColumns(self):
return "".join(self._columns)

@displayColumns.setter
def displayColumns(self, columns):
self._columns = [col for col in columns.upper() if col in 'TPXYZABCUVWDIJQR']
self.tool_model.setColumns(self._columns)
self.itemDelegate().setColumns(self._columns)

@Property(bool)
def confirmActions(self):
return self._confirm_actions
Expand Down

0 comments on commit 1b98795

Please # to comment.