Skip to content

Commit

Permalink
Section span option was added to table/tree view footer.
Browse files Browse the repository at this point in the history
  • Loading branch information
titov-vv committed Mar 7, 2024
1 parent 5df2168 commit a30724c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions jal/db/balances_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def configureView(self):
self._view.setItemDelegateForColumn(self.fieldIndex('currency_name'), self._grid_delegate)
self._view.setItemDelegateForColumn(self.fieldIndex('value'), self._float_delegate)
self._view.setItemDelegateForColumn(self.fieldIndex('value_common'), self._float_delegate)
self._view.footer().set_span(self.fieldIndex('account_name'), [self.fieldIndex('account_name'), self.fieldIndex('value')])
self._view.footer().set_span(self.fieldIndex('value_common'), [self.fieldIndex('currency_name'), self.fieldIndex('value_common')])
super().configureView()

@Slot()
Expand Down
17 changes: 16 additions & 1 deletion jal/widgets/custom/table_footer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class FooterView(QHeaderView):
def __init__(self, parent: QTreeView, table_header: QHeaderView):
super().__init__(Qt.Horizontal, parent)
self._span = {}
self._parent = parent
self._model = None
self._linked_header = table_header
Expand Down Expand Up @@ -47,10 +48,24 @@ def on_header_geometry(self):
self.setGeometry(cr.left(), cr.top() + cr.height() - hs.height() + 1, hs.width(), hs.height())

def on_header_resize(self, section: int, _old_size: int, new_size: int) -> None:
self.resizeSection(section, new_size)
if section not in self._span:
self.resizeSection(section, new_size)
return
if self._span[section] != section:
self.setSectionHidden(section, True)
return
size = 0
for i in [k for k, v in self._span.items() if v == section]: # Add all sections that spans to target section
size += new_size if i == section else self._linked_header.sectionSize(i)
self.resizeSection(section, size)

def on_header_move(self, _section: int, old: int, new: int) -> None:
self.moveSection(old, new)

def on_model_update(self, top_left, bottom_right, _role) -> None:
self.headerDataChanged(Qt.Horizontal, top_left.column(), bottom_right.column())

def set_span(self, section: int, span: list):
span += [section] # protection to have section itself included into span
for i in span:
self._span[i] = section

0 comments on commit a30724c

Please sign in to comment.