summaryrefslogtreecommitdiff
path: root/kodereviewer/models/line_model.py
diff options
context:
space:
mode:
Diffstat (limited to 'kodereviewer/models/line_model.py')
-rw-r--r--kodereviewer/models/line_model.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/kodereviewer/models/line_model.py b/kodereviewer/models/line_model.py
index 1814829..03d14c6 100644
--- a/kodereviewer/models/line_model.py
+++ b/kodereviewer/models/line_model.py
@@ -1,7 +1,9 @@
"""Model used for line numbers in Editor.qml"""
+import logging
from enum import auto, IntEnum
from typing import Optional
+import rich
from PySide6.QtCore import QAbstractListModel, QByteArray, QModelIndex, QObject, QPersistentModelIndex, QStandardPaths, QUrl, Qt, Signal, Slot, Property
from PySide6.QtQuick import QQuickTextDocument
from PySide6.QtQml import QmlElement
@@ -9,6 +11,8 @@ from PySide6.QtQml import QmlElement
QML_IMPORT_NAME = "org.deprecated.kodereviewer"
QML_IMPORT_MAJOR_VERSION = 1
+logger = logging.getLogger(__name__)
+
@QmlElement
class LineModel(QAbstractListModel):
@@ -27,15 +31,17 @@ class LineModel(QAbstractListModel):
return self._document
def set_document(self, document):
- print('setting document')
+ logger.debug('setting document')
if document == self._document:
+ logger.debug(f'Document {document} == {self._document}')
return
+ logger.debug(f'Setting document {document}')
self._document = document
self.documentChanged.emit()
self.resetModel()
documentChanged = Signal()
- document = Property(QQuickTextDocument, fget=get_document, fset=set_document,
+ document = Property(QObject, fget=get_document, fset=set_document,
notify=documentChanged)
def data(self,
@@ -43,29 +49,28 @@ class LineModel(QAbstractListModel):
role: int = Qt.ItemDataRole.DisplayRole) -> object:
if not index.isValid():
- print('index not valid')
+ logger.debug('index not valid')
return
if self._document is None:
- print('document none')
+ logger.debug('document none')
return
row = index.row()
if row < 0 or row > self.rowCount():
- print(f'row: {row}')
+ logger.debug(f'row: {row}')
return
if role == self.Roles.LineHeight:
text_doc = self._document.textDocument()
return int(text_doc.documentLayout().blockBoundingRect(text_doc.findBlockByNumber(row)).height())
- print('found role ?')
+ logger.debug('found role ?')
def rowCount(self, parent: QModelIndex | QPersistentModelIndex = QModelIndex()) -> int:
if self._document is None:
- print('document is none: row count 0')
+ logger.debug('rowCount: _document is None')
return 0
- print(f'returning {self._document.textDocument().blockCount()}')
return self._document.textDocument().blockCount();
def roleNames(self) -> dict[int, QByteArray]:
@@ -76,6 +81,6 @@ class LineModel(QAbstractListModel):
@Slot()
def resetModel(self) -> None:
- print('reseting model?')
+ logger.debug('reseting model?')
self.beginResetModel()
self.endResetModel()