diff options
-rw-r--r-- | src/main/python/shapes/line.py | 9 | ||||
-rw-r--r-- | src/main/python/utils/canvas.py | 5 | ||||
-rw-r--r-- | src/main/python/utils/streamTable.py | 19 |
3 files changed, 17 insertions, 16 deletions
diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index bbeab30..66be069 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -1,8 +1,9 @@ import math from PyQt5.QtGui import QPen, QPainterPath, QBrush, QPainterPathStroker, QPainter, QCursor, QPolygonF from PyQt5.QtWidgets import QGraphicsItem, QGraphicsPathItem, QGraphicsTextItem, QMenu, QGraphicsLineItem -from PyQt5.QtCore import Qt, QPointF, QRectF, QLineF +from PyQt5.QtCore import Qt, QPointF, QRectF, QLineF, pyqtSignal +from collections import defaultdict class Grabber(QGraphicsPathItem): """ @@ -122,6 +123,8 @@ class Grabber(QGraphicsPathItem): class LineLabel(QGraphicsTextItem): + nameChanged = pyqtSignal() + def __init__(self, pos, parent=None): super(LineLabel, self).__init__() self.setPlainText("abc") @@ -139,7 +142,8 @@ class LineLabel(QGraphicsTextItem): self.line.setPen(QPen(Qt.black, 2, Qt.SolidLine)) self.line.setFlag(QGraphicsItem.ItemStacksBehindParent) self.resetPos() - + self.values = defaultdict(lambda: 0) + def paint(self, painter, option, widget): painter.save() painter.setPen(QPen(Qt.black, 2, Qt.SolidLine)) @@ -264,6 +268,7 @@ class LineLabel(QGraphicsTextItem): def focusOutEvent(self, event): super(LineLabel, self).focusOutEvent(event) self.setTextInteractionFlags(Qt.NoTextInteraction) + self.nameChanged.emit() def __getstate__(self): return { diff --git a/src/main/python/utils/canvas.py b/src/main/python/utils/canvas.py index 5bd720b..47e95a9 100644 --- a/src/main/python/utils/canvas.py +++ b/src/main/python/utils/canvas.py @@ -100,9 +100,8 @@ class canvas(customView): @property def labelItems(self): - for i in self.items: - if isinstance(i, shapes.LineLabel): - yield i + return [i for i in self.items if isinstance(i, shapes.LineLabel)] + @property def canvasSize(self): return self._canvasSize diff --git a/src/main/python/utils/streamTable.py b/src/main/python/utils/streamTable.py index b52494a..bf9d6dc 100644 --- a/src/main/python/utils/streamTable.py +++ b/src/main/python/utils/streamTable.py @@ -24,9 +24,9 @@ class streamTableModel(QAbstractTableModel): elif role != Qt.DisplayRole: return None if index.row() == 0: - return self.list[index.column()][index.row()].toPlainText() + return self.list[index.column()].toPlainText() else: - return self.list[index.column()][index.row()] + return self.list[index.column()].values[self.header[index.row()]] def setData(self, index, value, role): if not index.isValid(): @@ -34,22 +34,20 @@ class streamTableModel(QAbstractTableModel): elif role != Qt.EditRole: return False if index.row() == 0: - self.list[index.column()][index.row()].setPlainText(value) + self.list[index.column()].setPlainText(value) else: - self.list[index.column()][index.row()] = value + self.list[index.column()].values[self.header[index.row()]] = value return True def insertColumn(self, int=None, item=None): int = int if int else self.rowCount()+1 self.beginInsertColumns(QModelIndex(), int, int) - self.list.insert(int, [item] + [0 for _ in range(self.rowCount()-1)]) + self.list.insert(int, item) self.endInsertColumns() self.updateEvent.emit() def insertRow(self, int=None, name="newVal"): self.beginInsertRows(QModelIndex(), int, int) - for item in self.list: - item.insert(int, 0) self.header.insert(int, name) self.endInsertRows() self.updateEvent.emit() @@ -67,11 +65,10 @@ class streamTable(QTableView): def __init__(self, itemLabels=[], canvas=None, parent=None): super(streamTable, self).__init__(parent=parent) self.canvas = canvas - list = [] - for i, item in enumerate(itemLabels): - list.append([item] + [0 for _ in range(5)]) + for i in itemLabels: + i.nameChanged.connect(self.repaint) header = ["name", "val1", "val2", "val3", "val4", "val5"] - self.model = streamTableModel(self, list, header) + self.model = streamTableModel(self, itemLabels, header) self.setShowGrid(False) self.horizontalHeader().hide() self.setModel(self.model) |