summaryrefslogtreecommitdiff
path: root/kodereviewer/models
diff options
context:
space:
mode:
authorMatias Linares <matias.linares@comprandoengrupo.net>2024-10-03 10:48:42 -0300
committerMatias Linares <matias.linares@comprandoengrupo.net>2024-10-03 10:48:42 -0300
commit440fd1dd8c194e4e02fc47725296812fba31df5d (patch)
treea70a6c2da257b01359f3bf9f65b0a3f08e255e9d /kodereviewer/models
parent1ab1edca0520ccb33196928f4a48cd521ef41d7c (diff)
downloadkodereviewer-440fd1dd8c194e4e02fc47725296812fba31df5d.tar.gz
Better layout
Diffstat (limited to 'kodereviewer/models')
-rw-r--r--kodereviewer/models/__init__.py4
-rw-r--r--kodereviewer/models/comments.py1
-rw-r--r--kodereviewer/models/pull_request.py25
3 files changed, 24 insertions, 6 deletions
diff --git a/kodereviewer/models/__init__.py b/kodereviewer/models/__init__.py
index 853b618..b566981 100644
--- a/kodereviewer/models/__init__.py
+++ b/kodereviewer/models/__init__.py
@@ -1,9 +1,13 @@
from kodereviewer.models.comments import CommentModel
+from kodereviewer.models.line_model import LineModel
from kodereviewer.models.project import ProjectModel
from kodereviewer.models.pull_request import PullRequestModel
+from kodereviewer.models.label import LabelModel
__all__ = [
'CommentModel',
+ 'LabelModel'
+ 'LineModel',
'ProjectModel',
'PullRequestModel',
]
diff --git a/kodereviewer/models/comments.py b/kodereviewer/models/comments.py
index 06de3d7..0d92e23 100644
--- a/kodereviewer/models/comments.py
+++ b/kodereviewer/models/comments.py
@@ -37,7 +37,6 @@ class CommentModel(QAbstractListModel):
if self._pull_request is not None and self._pull_request == pull_request:
return
- print(f"Setting up pull request to {pull_request}")
self.beginResetModel()
self._pull_request = pull_request
self._pull_request.commentsLoaded.connect(self._reset_model)
diff --git a/kodereviewer/models/pull_request.py b/kodereviewer/models/pull_request.py
index 7d08efa..99e3495 100644
--- a/kodereviewer/models/pull_request.py
+++ b/kodereviewer/models/pull_request.py
@@ -1,5 +1,4 @@
-import json
-from os import path
+from copy import copy
from typing import Any, Optional
from PySide6.QtCore import QAbstractListModel, QByteArray, QModelIndex, QObject, QPersistentModelIndex, QStandardPaths, QUrl, Qt, Signal, Slot, Property
@@ -15,9 +14,17 @@ QML_IMPORT_MAJOR_VERSION = 1
class PullRequestModel(QAbstractListModel):
_project: Optional[Project]
+ _pull_requests: list[PullRequest]
+
+ # This attribute holds a reference to a reference to a newly
+ # copied PullRequest so Qt don't frees the memory of the pull
+ # request on _pull_requests
+ _current_pull_request: PullRequest
NumberRole = Qt.ItemDataRole.UserRole + 1
TitleRole = NumberRole + 1
+ StateRole = TitleRole + 1
+ DraftRole = StateRole + 1
def __init__(self):
super().__init__()
@@ -33,6 +40,10 @@ class PullRequestModel(QAbstractListModel):
return pull_request.number
if role == self.TitleRole:
return pull_request.title
+ if role == self.StateRole:
+ return pull_request.state
+ if role == self.DraftRole:
+ return pull_request.draft
if role == Qt.ItemDataRole.DisplayRole:
return f'{pull_request.number} - {pull_request.title}'
return None
@@ -46,6 +57,8 @@ class PullRequestModel(QAbstractListModel):
return {
self.NumberRole: QByteArray(b"number"),
self.TitleRole: QByteArray(b"title"),
+ self.StateRole: QByteArray(b"state"),
+ self.DraftRole: QByteArray(b"draft"),
}
def get_project(self) -> Optional[Project]:
@@ -64,12 +77,14 @@ class PullRequestModel(QAbstractListModel):
@Slot(int, result=PullRequest)
def get(self, index: int) -> Optional[PullRequest]:
- if self._project is not None:
- return self._project.pullRequests[index]
- return None
+ self._current_pull_request = self._pull_requests[index].copy()
+
+ return self._current_pull_request
def _reset_model(self) -> None:
print("Reseting pull request model")
self.beginResetModel()
+ if self._project is not None:
+ self._pull_requests = self._project.pullRequests
self.endResetModel()