Skip to content

Commit

Permalink
Adds interaction filter for selecting individual commits
Browse files Browse the repository at this point in the history
  • Loading branch information
boehmseb committed Aug 3, 2023
1 parent ae257da commit d9957bc
Show file tree
Hide file tree
Showing 11 changed files with 2,288 additions and 2,034 deletions.
12 changes: 12 additions & 0 deletions icons/breeze/light/vcs-commit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions icons/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<file>breeze/light/document-save.svg</file>
<file>breeze/light/application-exit.svg</file>
<file>breeze/light/document-open.svg</file>
<file>breeze/light/vcs-commit.svg</file>
<file>operators/and-operator.svg</file>
<file>operators/or-operator.svg</file>
<file>operators/not-operator.svg</file>
Expand Down
2 changes: 1 addition & 1 deletion icons/update-icons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
script=$(readlink -f "$0")
scriptpath=$(dirname "${script}")

pyrcc5 icons.qrc -o "${scriptpath}"/../varats/gui/icons_rc.py
pyrcc5 icons.qrc -o "${scriptpath}"/../varats/varats/gui/icons_rc.py
50 changes: 50 additions & 0 deletions uicomponents/SingleCommitFilterProperties.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SingleCommitFilterProperties</class>
<widget class="QWidget" name="SingleCommitFilterProperties">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>397</width>
<height>51</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Commit</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="uiCommitHash">
<property name="font">
<font>
<family>Monospace</family>
</font>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
1 change: 1 addition & 0 deletions uicomponents/update_ui
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pyuic5 --import-from varats.gui -x FilterMain.ui -o ${scriptpath}/../varats/vara
pyuic5 -x FilterProperties.ui -o ${scriptpath}/../varats/varats/gui/views/ui_FilterProperties.py
pyuic5 -x FilterNodeProperties.ui -o ${scriptpath}/../varats/varats/gui/views/ui_FilterNodeProperties.py
pyuic5 -x FilterUnaryWarning.ui -o ${scriptpath}/../varats/varats/gui/views/ui_FilterUnaryWarning.py
pyuic5 -x SingleCommitFilterProperties.ui -o ${scriptpath}/../varats/varats/gui/views/ui_SingleCommitFilterProperties.py
pyuic5 -x AuthorFilterProperties.ui -o ${scriptpath}/../varats/varats/gui/views/ui_AuthorFilterProperties.py
pyuic5 -x CommitterFilterProperties.ui -o ${scriptpath}/../varats/varats/gui/views/ui_CommitterFilterProperties.py
pyuic5 -x AuthorDateMinFilter.ui -o ${scriptpath}/../varats/varats/gui/views/ui_AuthorDateMinFilter.py
Expand Down
42 changes: 42 additions & 0 deletions varats/varats/data/filtertree_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
│ ├── TargetOperator
└── ConcreteInteractionFilter
├── UnaryInteractionFilter
│ ├── SingleCommitFilter
│ ├── AuthorFilter
│ ├── CommitterFilter
│ ├── AuthorDateMinFilter
Expand All @@ -68,6 +69,7 @@
from PyQt5.QtCore import QDateTime, Qt

from varats.base.version_header import VersionHeader
from varats.utils.git_util import UNCOMMITTED_COMMIT_HASH


class SecretYamlObject(yaml.YAMLObject):
Expand Down Expand Up @@ -255,6 +257,46 @@ def __init__(
super().__init__(parent, comment)


class SingleCommitFilter(UnaryInteractionFilter):
yaml_tag = u'!SingleCommitFilter'

def __init__(
self,
parent: tp.Optional[InteractionFilter] = None,
comment: tp.Optional[str] = None,
commit_hash: tp.Optional[str] = None
) -> None:
super().__init__(parent, comment)
if commit_hash:
self._commit_hash = commit_hash
else:
self._commit_hash = UNCOMMITTED_COMMIT_HASH.hash

def commit(self) -> str:
return self._commit_hash

def setCommit(self, commit_hash: str) -> None:
self._commit_hash = commit_hash

def data(self, column: int) -> tp.Any:
val = super().data(column)

if column == 2:
val = self.commit()

return val

def setData(self, column: int, value: tp.Any) -> None:
super().setData(column, value)

if column == 2:
self.setCommit(value)

@staticmethod
def resource() -> str:
return ":/breeze/light/vcs-commit.svg"


class AuthorFilter(UnaryInteractionFilter):
yaml_tag = u'!AuthorFilter'

Expand Down
7 changes: 7 additions & 0 deletions varats/varats/gui/filtertree_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
OrOperator,
SourceOperator,
TargetOperator,
SingleCommitFilter,
)


Expand Down Expand Up @@ -254,6 +255,12 @@ def addTargetNode(self) -> bool:
num_children = self.getNode(self._selection).childCount()
return self.insertRows(TargetOperator, num_children, 1, self._selection)

def addSingleCommitFilterNode(self) -> bool:
num_children = self.getNode(self._selection).childCount()
return self.insertRows(
SingleCommitFilter, num_children, 1, self._selection
)

def addCommitterFilterNode(self) -> bool:
num_children = self.getNode(self._selection).childCount()
return self.insertRows(
Expand Down
47 changes: 43 additions & 4 deletions varats/varats/gui/filtertree_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
from varats.gui.views.ui_FilterNodeProperties import Ui_FilterNodeProperties
from varats.gui.views.ui_FilterProperties import Ui_FilterProperties
from varats.gui.views.ui_FilterUnaryWarning import Ui_FilterUnaryWarning
from varats.gui.views.ui_SingleCommitFilterProperties import (
Ui_SingleCommitFilterProperties,
)


def _showTimeDurationHelp() -> None:
Expand Down Expand Up @@ -81,6 +84,7 @@ def __init__(self, parent=None):

self._node_editor = NodeEditor(self)
self._filter_unary_warning = FilterUnaryWarning(self)
self._single_commit_editor = SingleCommitFilterEditor(self)
self._author_filter_editor = AuthorFilterEditor(self)
self._committer_filter_editor = CommitterFilterEditor(self)
self._author_date_min_filter_editor = AuthorDateMinFilterEditor(self)
Expand All @@ -102,6 +106,7 @@ def __init__(self, parent=None):

self.layoutNode.addWidget(self._node_editor)
self.layoutNodeWarning.addWidget(self._filter_unary_warning)
self.layoutNodeSpec.addWidget(self._single_commit_editor)
self.layoutNodeSpec.addWidget(self._author_filter_editor)
self.layoutNodeSpec.addWidget(self._committer_filter_editor)
self.layoutNodeSpec.addWidget(self._author_date_min_filter_editor)
Expand Down Expand Up @@ -130,6 +135,8 @@ def setSelection(self, current: QModelIndex, old: QModelIndex) -> None:
pass
if node.name() == 'TargetOperator':
pass
if node.name() == 'SingleCommitFilter':
self._single_commit_editor.setVisible(True)
if node.name() == 'AuthorFilter':
self._author_filter_editor.setVisible(True)
if node.name() == 'CommitterFilter':
Expand All @@ -153,6 +160,7 @@ def setSelection(self, current: QModelIndex, old: QModelIndex) -> None:

self._node_editor.setSelection(current)

self._single_commit_editor.setSelection(current)
self._author_filter_editor.setSelection(current)
self._filter_unary_warning.setSelection(current)
self._committer_filter_editor.setSelection(current)
Expand All @@ -170,6 +178,7 @@ def setModel(self, model) -> None:

self._node_editor.setModel(model)
self._filter_unary_warning.setModel(model)
self._single_commit_editor.setModel(model)
self._author_filter_editor.setModel(model)
self._committer_filter_editor.setModel(model)
self._author_date_min_filter_editor.setModel(model)
Expand All @@ -183,6 +192,7 @@ def setModel(self, model) -> None:

def _setEditorsInvisible(self):
self._author_filter_editor.setVisible(False)
self._single_commit_editor.setVisible(False)
self._committer_filter_editor.setVisible(False)
self._author_date_min_filter_editor.setVisible(False)
self._author_date_max_filter_editor.setVisible(False)
Expand Down Expand Up @@ -237,6 +247,25 @@ def setSelection(self, current: QModelIndex) -> None:
self.uiWarningLabel.hide()


class SingleCommitFilterEditor(QWidget, Ui_SingleCommitFilterProperties):

def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)

self._data_mapper = QDataWidgetMapper()

def setModel(self, model):
self._model = model
self._data_mapper.setModel(model)
self._data_mapper.addMapping(self.uiCommitHash, 2)

def setSelection(self, current: QModelIndex) -> None:
parent = current.parent()
self._data_mapper.setRootIndex(parent)
self._data_mapper.setCurrentModelIndex(current)


class AuthorFilterEditor(QWidget, Ui_AuthorFilterProperties):

def __init__(self, parent=None):
Expand Down Expand Up @@ -471,6 +500,11 @@ def __init__(self, parent=None):
'Target Operator', self.addTargetNode
)
menu.addSeparator()
menu.addAction(
QIcon(QPixmap(":/breeze/light/vcs-commit.svg")),
'Single Commit Filter', self.addSingleCommitFilterNode
)
menu.addSeparator()
menu.addAction(
QIcon(QPixmap(":/breeze/light/im-user.svg")), 'Committer Filter',
self.addCommitterFilterNode
Expand Down Expand Up @@ -562,10 +596,8 @@ def closeEvent(self, event: QCloseEvent) -> None:
event.ignore()

def updateWindowTitle(self) -> None:
self.setWindowTitle(
"[*]{} - InteractionFilter Editor".
format(self._file_basename if self._file_basename else "Untitled")
)
filter_name = self._file_basename if self._file_basename else 'Untitled'
self.setWindowTitle(f"[*]{filter_name} - InteractionFilter Editor")

def addAndNode(self):
with self._lock:
Expand Down Expand Up @@ -602,6 +634,13 @@ def addTargetNode(self):
if modified:
self.setWindowModified(True)

def addSingleCommitFilterNode(self):
with self._lock:
modified = self._model.addSingleCommitFilterNode()
self.uiTree.selectionModel().clear()
if modified:
self.setWindowModified(True)

def addAuthorFilterNode(self):
with self._lock:
modified = self._model.addAuthorFilterNode()
Expand Down
Loading

0 comments on commit d9957bc

Please sign in to comment.