From 1889b6a1ea188b781a5d0c3e99b21db060281f5e Mon Sep 17 00:00:00 2001 From: Olivier Keshavjee Date: Thu, 25 Jun 2015 00:05:01 +0200 Subject: [PATCH] Trying to fixe some recursions in textEditView --- src/models/outlineModel.py | 4 +++- src/ui/views/textEditView.py | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/models/outlineModel.py b/src/models/outlineModel.py index 5b5b054b..93309473 100644 --- a/src/models/outlineModel.py +++ b/src/models/outlineModel.py @@ -89,10 +89,12 @@ class outlineModel(QAbstractItemModel): def setData(self, index, value, role=Qt.EditRole): item = index.internalPointer() if item.data(index.column(), role) != value: + item.setData(index.column(), value, role) #self.dataChanged.emit(index.sibling(index.row(), 0), #index.sibling(index.row(), max([i.value for i in Outline]))) + #print("Model emit", index.row(), index.column()) self.dataChanged.emit(index.sibling(index.row(), index.column()), index.sibling(index.row(), index.column())) @@ -388,7 +390,7 @@ class outlineItem(): return self._data[Outline(column)] else: - return None + return "" elif role == Qt.DecorationRole and column == Outline.title.value: if self.isFolder(): diff --git a/src/ui/views/textEditView.py b/src/ui/views/textEditView.py index 80d3edf8..e3a6974f 100644 --- a/src/ui/views/textEditView.py +++ b/src/ui/views/textEditView.py @@ -46,8 +46,12 @@ class textEditView(QTextEdit): self.updateTimer.setInterval(500) self.updateTimer.setSingleShot(True) self.updateTimer.timeout.connect(self.submit) + #self.updateTimer.timeout.connect(lambda: print("Timeout")) + self.updateTimer.stop() self.document().contentsChanged.connect(self.updateTimer.start, AUC) + #self.document().contentsChanged.connect(lambda: print("Document changed")) + #self.document().contentsChanged.connect(lambda: print(self.objectName(), "Contents changed")) if index: @@ -71,7 +75,7 @@ class textEditView(QTextEdit): def setModel(self, model): self._model = model - self._model.dataChanged.connect(self.update, AUC) + #self._model.dataChanged.connect(self.update, AUC) def setColumn(self, col): self._column = col @@ -167,6 +171,10 @@ class textEditView(QTextEdit): return elif self._index: + + if topLeft.parent() != self._index.parent(): + return + if topLeft.row() <= self._index.row() <= bottomRight.row(): if topLeft.column() <= Outline.type.value <= bottomRight.column(): # If item type change, we reset the index to set the proper @@ -175,6 +183,7 @@ class textEditView(QTextEdit): self.updateText() elif topLeft.column() <= self._column <= bottomRight.column(): + print(topLeft.column(), self._column, bottomRight.column()) self.updateText() elif self._indexes: @@ -198,15 +207,17 @@ class textEditView(QTextEdit): if self._updating: return - + #print("Updating", self.objectName()) self._updating = True if self._index: self.disconnectDocument() if self._textFormat == "html": if self.toHtml() != toString(self._model.data(self._index)): + #print(" Updating html") self.document().setHtml(toString(self._model.data(self._index))) else: if self.toPlainText() != toString(self._model.data(self._index)): + #print(" Updating plaintext") self.document().setPlainText(toString(self._model.data(self._index))) self.reconnectDocument() @@ -237,16 +248,18 @@ class textEditView(QTextEdit): def submit(self): if self._updating: return - + #print("Submitting", self.objectName()) if self._index: item = self._index.internalPointer() if self._textFormat == "html": if self.toHtml() != self._model.data(self._index): + #print(" Submitting html") self._updating = True self._model.setData(self._index, self.toHtml()) self._updating = False else: if self.toPlainText() != self._model.data(self._index): + #print(" Submitting plain text") self._updating = True self._model.setData(self._index, self.toPlainText()) self._updating = False