1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2024-12-22 07:43:09 +00:00

Add sorting to ExtractDialog.

* src/vorta/views/extract_dialog.py : Implement `ExtractSortProxyModel` inheriting from
	 `FileTreeSortProxyModel`.

* src/vorta/views/extract_dialog.py (ExtractDialog.__init__): Use sortproxymodel.

* src/vorta/views/extract_dialog.py (ExtractDialog): Implement `slot_sorted` that moves the viewport.
This commit is contained in:
real-yfprojects 2022-07-01 20:40:01 +02:00
parent 7eedd39319
commit e7772f517b
No known key found for this signature in database
GPG key ID: 00F630DFDEE25747

View file

@ -13,7 +13,8 @@
from vorta.utils import get_asset, pretty_bytes, uses_dark_mode
from .partials.treemodel import (FileSystemItem, FileTreeModel, path_to_str,
from .partials.treemodel import (FileSystemItem, FileTreeModel,
FileTreeSortProxyModel, path_to_str,
relative_path)
uifile = get_asset("UI/extractdialog.ui")
@ -58,7 +59,16 @@ def __init__(self, archive, model):
view = self.treeView
view.setAlternatingRowColors(True)
view.setUniformRowHeights(True) # Allows for scrolling optimizations.
view.setModel(self.model)
# add sort proxy model
self.sortproxy = ExtractSortProxyModel(self)
self.sortproxy.setSourceModel(self.model)
view.setModel(self.sortproxy)
self.sortproxy.sorted.connect(self.slot_sorted)
view.setSortingEnabled(True)
# header
header = view.header()
header.setStretchLastSection(False)
header.setSectionResizeMode(1, QHeaderView.ResizeToContents)
@ -89,6 +99,13 @@ def retranslateUi(self, dialog):
if hasattr(self, "extractButton"):
self.extractButton.setText(self.tr("Extract"))
def slot_sorted(self, column, order):
"""React the tree view being sorted."""
# reveal selection
selectedRows = self.treeView.selectionModel().selectedRows()
if selectedRows:
self.treeView.scrollTo(selectedRows[0])
def parse_json_lines(lines, model: "ExtractTree"):
"""Parse json output of `borg list`."""
@ -123,6 +140,33 @@ def parse_json_lines(lines, model: "ExtractTree"):
)
# ---- Sorting ---------------------------------------------------------------
class ExtractSortProxyModel(FileTreeSortProxyModel):
"""
Sort a ExtractTree model.
"""
def choose_data(self, index: QModelIndex):
"""Choose the data of index used for comparison."""
item: FileSystemItem[FileData] = index.internalPointer()
column = index.column()
if column == 0:
# file name
return self.extract_path(index)
elif column == 1:
return item.data.last_modified
elif column == 2:
return item.data.size
else:
return item.data.health
# ---- ExtractTree -----------------------------------------------------------
class FileType(enum.Enum):
"""File type of an item inside a borg archive."""