Skip to content

Commit

Permalink
[MLV] Add switching to first/last widget in viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
Sobottasgithub committed Feb 4, 2024
1 parent 3a53708 commit e0c049e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/LogViewer/ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def __init__(self):
self.uiAction_goToRow.triggered.connect(self.openGoToRowWidget)
self.uiAction_firstRow.triggered.connect(self.goToFirstRow)
self.uiAction_lastRow.triggered.connect(self.goToLastRow)
self.uiAction_firstRowInViewport.triggered.connect(self.goToFirstRowInViewport)
self.uiAction_lastRowInViewport.triggered.connect(self.goToLastRowInViewport)

self.uiWidget_listView.doubleClicked.connect(self.inspectLine)
self.uiWidget_listView.clicked.connect(self.listViewClicked)
Expand Down Expand Up @@ -124,6 +126,8 @@ def toggleUiItems(self):
self.uiSpinBox_goToRow.setEnabled(self.file != None)
self.uiCombobox_searchInput.setEnabled(self.file != None)
self.uiCombobox_filterInput.setEnabled(self.file != None)
self.uiAction_lastRowInViewport.setEnabled(self.file != None)
self.uiAction_firstRowInViewport.setEnabled(self.file != None)

def export(self):
if self.rawlog:
Expand Down Expand Up @@ -628,6 +632,32 @@ def goToLastRow(self, *args):
self.uiWidget_listView.setCurrentRow(index)
self.statusbar.showDynamicText(str("Done ✓ | Switched to last row: %d" % index))
break

@catch_exceptions(logger=logger)
def goToFirstRowInViewport(self, *args):
lastIndex = self.uiWidget_listView.selectedIndexes()[0].row()

This comment has been minimized.

Copy link
@tmolitor-stud-tu

tmolitor-stud-tu Feb 7, 2024

Member

should be named currentIndex

# Counts backwards from the current entry
for index in range(self.uiWidget_listView.selectedIndexes()[0].row(), -1, -1):
# The entry height is added to the Y position of the entry to see if that line is still in the viewport
if self.uiWidget_listView.visualItemRect(self.rawlog[index]["uiItem"]).height() + self.uiWidget_listView.visualItemRect(self.rawlog[index]["uiItem"]).y() < 0:
self.uiWidget_listView.setCurrentRow(lastIndex)
self.statusbar.showDynamicText(str("Done ✓ | Switched to the first line in the viewport: %d" % lastIndex))
break
else:
lastIndex = index

This comment has been minimized.

Copy link
@tmolitor-stud-tu

tmolitor-stud-tu Feb 7, 2024

Member

why save it in this local variable right before the function returns? that's a noop.


@catch_exceptions(logger=logger)
def goToLastRowInViewport(self, *args):
lastIndex = self.uiWidget_listView.selectedIndexes()[0].row()

This comment has been minimized.

Copy link
@tmolitor-stud-tu

tmolitor-stud-tu Feb 7, 2024

Member

same here

# Counts upwards from the current entry
for index in range(self.uiWidget_listView.selectedIndexes()[0].row(), 32):
# If the item position is larger than the listview-height, it must be the last one in our viewport
if self.uiWidget_listView.visualItemRect(self.rawlog[index]["uiItem"]).y() > self.uiWidget_listView.height():
self.uiWidget_listView.setCurrentRow(lastIndex)
self.statusbar.showDynamicText(str("Done ✓ | Switched to the last line in the viewport: %d" % lastIndex))
break
else:
lastIndex = index

This comment has been minimized.

Copy link
@tmolitor-stud-tu

tmolitor-stud-tu Feb 7, 2024

Member

same here


def cancelFilter(self):
for index in range(len(self.rawlog)):
Expand Down
18 changes: 18 additions & 0 deletions src/LogViewer/ui/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@
<addaction name="uiAction_goToRow"/>
<addaction name="uiAction_firstRow"/>
<addaction name="uiAction_lastRow"/>
<addaction name="uiAction_firstRowInViewport"/>
<addaction name="uiAction_lastRowInViewport"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
Expand Down Expand Up @@ -437,6 +439,22 @@
<string>Ctrl+End</string>
</property>
</action>
<action name="uiAction_firstRowInViewport">
<property name="text">
<string>First row in viewport</string>
</property>
<property name="shortcut">
<string>Home</string>
</property>
</action>
<action name="uiAction_lastRowInViewport">
<property name="text">
<string>Last row in viewport</string>
</property>
<property name="shortcut">
<string>End</string>
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down

0 comments on commit e0c049e

Please sign in to comment.