diff --git a/jal/languages/en.ts b/jal/languages/en.ts index 541e0cbd..32b93449 100644 --- a/jal/languages/en.ts +++ b/jal/languages/en.ts @@ -1344,83 +1344,82 @@ HoldingsModel - + Qty - + Since - + Open - + Last - + Share, % - + P/L, % - + P/L - + Paid - + Value - + Value, - + Last quote date: - + N/A - + Money - + Currency/Account/Asset - + Asset Name - - + Exp: diff --git a/jal/languages/ru.ts b/jal/languages/ru.ts index dee9492f..0bbaabdc 100644 --- a/jal/languages/ru.ts +++ b/jal/languages/ru.ts @@ -1344,83 +1344,82 @@ HoldingsModel - + Qty Кол-во - + Since С - + Open Цена откр. - + Last Цена закр. - + Share, % Доля, % - + P/L, % ПиУ, % - + P/L ПиУ - + Paid Выплачено - + Value Оценка - + Value, Оценка, - + Last quote date: Дата последней котировки: - + N/A N/A - + Money Деньги - + Currency/Account/Asset Валюта/Счёт/ЦБ - + Asset Name Ценная бумага - - + Exp: Эксп: diff --git a/jal/widgets/delegates.py b/jal/widgets/delegates.py index 5b05e9ee..3d3de1a0 100644 --- a/jal/widgets/delegates.py +++ b/jal/widgets/delegates.py @@ -64,9 +64,34 @@ def keyPressEvent(self, event: QKeyEvent) -> None: super().keyPressEvent(event) + +# ---------------------------------------------------------------------------------------------------------------------- +# QTreeView doesn't draw grid lines and have no normal method to implement it +# So the purpose of this delegate is solely to draw dotted box around report cell +class GridLinesDelegate(QStyledItemDelegate): + def __init__(self, parent=None): + self._parent = parent + super().__init__(parent=parent) + + def paint_grid(self, painter, option, index): + if issubclass(type(self._parent), QTreeView): # Extra code for tree views - to draw grid lines + painter.save() + pen = painter.pen() + pen.setWidth(1) + pen.setStyle(Qt.DotLine) + pen.setColor(Qt.GlobalColor.lightGray) + painter.setPen(pen) + painter.drawRect(option.rect) + painter.restore() + + def paint(self, painter, option, index): + self.paint_grid(painter, option, index) + super().paint(painter, option, index) + + # ---------------------------------------------------------------------------------------------------------------------- # Delegate to convert timestamp from unix-time to QDateTime and display it according to the given format -class TimestampDelegate(QStyledItemDelegate): +class TimestampDelegate(GridLinesDelegate): def __init__(self, display_format='%d/%m/%Y %H:%M:%S', parent=None): super().__init__(parent=parent) self._parent = parent @@ -98,18 +123,6 @@ def setModelData(self, editor, model, index): timestamp = editor.dateTime().toSecsSinceEpoch() model.setData(index, timestamp) - def paint(self, painter, option, index): - super().paint(painter, option, index) - if issubclass(type(self._parent), QTreeView): # Extra code for tree views - to draw grid lines - painter.save() - pen = painter.pen() - pen.setWidth(1) - pen.setStyle(Qt.DotLine) - pen.setColor(Qt.GlobalColor.lightGray) - painter.setPen(pen) - painter.drawRect(option.rect) - painter.restore() - # ----------------------------------------------------------------------------------------------------------------------- # Delegate for float numbers formatting @@ -119,7 +132,7 @@ def paint(self, painter, option, index): # 'colors' - make Green/Red background for positive/negative values # 'percent' - multiply values by 100 in order to display percents # 'empty_zero' - display nothing instead of number 0 -class FloatDelegate(QStyledItemDelegate): +class FloatDelegate(GridLinesDelegate): DEFAULT_TOLERANCE = 6 def __init__(self, tolerance=None, allow_tail=True, colors=False, percent=False, empty_zero=False, parent=None): @@ -185,18 +198,6 @@ def initStyleOption(self, option, index): if self._colors and self._color is not None: option.backgroundBrush = QBrush(self._color) - def paint(self, painter, option, index): - super().paint(painter, option, index) - if issubclass(type(self._parent), QTreeView): # Extra code for tree views - to draw grid lines - painter.save() - pen = painter.pen() - pen.setWidth(1) - pen.setStyle(Qt.DotLine) - pen.setColor(Qt.GlobalColor.lightGray) - painter.setPen(pen) - painter.drawRect(option.rect) - painter.restore() - # ---------------------------------------------------------------------------------------------------------------------- # Delegate to apply currency filter for AssetSelector widgets based on current account @@ -211,7 +212,7 @@ def setEditorData(self, editor, index): # ---------------------------------------------------------------------------------------------------------------------- # Toggle True/False by mouse click and display status by relevant icon -class BoolDelegate(QStyledItemDelegate): +class BoolDelegate(GridLinesDelegate): def __init__(self, parent=None): self._parent = parent super().__init__(parent=parent) @@ -229,15 +230,7 @@ def paint(self, painter, option, index): icon = JalIcon[JalIcon.CANCEL] icon.paint(painter, option.rect, Qt.AlignVCenter | Qt.AlignCenter) painter.restore() - if issubclass(type(self._parent), QTreeView): # Extra code for tree views - to draw grid lines - painter.save() - pen = painter.pen() - pen.setWidth(1) - pen.setStyle(Qt.DotLine) - pen.setColor(Qt.GlobalColor.lightGray) - painter.setPen(pen) - painter.drawRect(option.rect) - painter.restore() + self.paint_grid(painter, option, index) def editorEvent(self, event, model, option, index): if event.type() == QEvent.MouseButtonPress: @@ -275,25 +268,6 @@ def setModelData(self, editor, model, index): model.setData(index, editor.currentData()) -# ---------------------------------------------------------------------------------------------------------------------- -# QTreeView doesn't draw grid lines and have no normal method to implement it -# So the purpose of this delegate is solely to draw dotted box around report cell -class GridLinesDelegate(QStyledItemDelegate): - def __init__(self, parent=None): - super().__init__(parent=parent) - - def paint(self, painter, option, index): - painter.save() - pen = painter.pen() - pen.setWidth(1) - pen.setStyle(Qt.DotLine) - pen.setColor(Qt.GlobalColor.lightGray) - painter.setPen(pen) - painter.drawRect(option.rect) - painter.restore() - super().paint(painter, option, index) - - # ----------------------------------------------------------------------------------------------------------------------- # Base class for lookup delegate that allows Asset, Peer, Category and Tag selection class LookupSelectorDelegate(QStyledItemDelegate):