Skip to content

Commit

Permalink
refactor row filter of cs gui and remove usages of deprecated commit.…
Browse files Browse the repository at this point in the history
…hex property
  • Loading branch information
Sinerum committed Jul 9, 2024
1 parent c752ce5 commit 1e16db9
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions varats/varats/gui/cs_gen/case_study_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ def revisions_of_project(self) -> None:
def show_revision_data(self, index: QModelIndex) -> None:
"""Update the revision data field."""
commit = self.revision_list.model().data(index, Qt.WhatsThisRole)
commit_info = f"{commit.hex}:\n" \
commit_info = f"{commit.id}:\n" \
f"{commit.author.name}, " \
f"<{commit.author.email}>\n\n" \
f"{commit.message}"
self.selected_commit = commit.hex
self.selected_commit = commit.id
self.revision_details.setText(commit_info)
self.revision_details.update()

Expand Down Expand Up @@ -304,12 +304,18 @@ def filterAcceptsRow(
) -> bool:
commit_index = self.sourceModel().index(source_row, 0, source_parent)
author_index = self.sourceModel().index(source_row, 1, source_parent)
return ((not self.cs_filter) or FullCommitHash(self.sourceModel().data(commit_index,Qt.WhatsThisRole).hex) in self._case_study.revisions) and (self.sourceModel().data(commit_index,
Qt.DisplayRole).lower() \
.__contains__(self.filter_string.lower()) \
or self.sourceModel().data(author_index,
Qt.DisplayRole).lower() \
.__contains__(self.filter_string.lower()))
hash_filter = self.sourceModel().data(
commit_index, Qt.DisplayRole
).lower().__contains__(self.filter_string.lower())
author_filter = self.sourceModel().data(
author_index, Qt.DisplayRole
).lower().__contains__(self.filter_string.lower())
case_study_filter = (
not self.cs_filter
) or FullCommitHash.from_pygit_commit(
self.sourceModel().data(commit_index, Qt.WhatsThisRole)
) in self._case_study.revisions
return case_study_filter and (hash_filter or author_filter)


class CommitTableModel(QAbstractTableModel):
Expand Down Expand Up @@ -378,28 +384,29 @@ def sort(self, column: int, order: Qt.SortOrder = ...) -> None:

def __split_commit_data(self, commit: pygit2.Commit, column: int) -> tp.Any:
if column == 0:
return ShortCommitHash(commit.hex).hash
return ShortCommitHash.from_pygit_commit(commit).hash
if column == 1:
return commit.author.name
if column == 2:
tzinfo = timezone(timedelta(minutes=commit.author.offset))
date = datetime.fromtimestamp(float(commit.author.time), tzinfo)
return QDateTime(date)
if column == 3:
return self._cmap.short_time_id(ShortCommitHash(commit.hex))
return self._cmap.time_id(FullCommitHash.from_pygit_commit(commit))

def data(self, index: QModelIndex, role: int = Qt.DisplayRole) -> tp.Any:
commit = self._data[index.row()]
chash = FullCommitHash.from_pygit_commit(commit)
if role == Qt.DisplayRole:
return self.__split_commit_data(commit, index.column())
if is_revision_blocked(FullCommitHash(commit.hex), self._project):
if is_revision_blocked(chash, self._project):
if role == Qt.ForegroundRole:
return QColor(50, 100, 255)
if role == Qt.ToolTipRole:
return "Blocked"
if self._case_study and self._experiment_type:
if role == Qt.ForegroundRole:
chash = ShortCommitHash(commit.hex)
chash = chash.to_short_commit_hash()
if chash in self._status_data.index:
if self._status_data.loc[
chash, "file_status"
Expand Down

0 comments on commit 1e16db9

Please sign in to comment.