diff --git a/src/models/outlineModel.py b/src/models/outlineModel.py index 76c370f9..9abe986c 100644 --- a/src/models/outlineModel.py +++ b/src/models/outlineModel.py @@ -94,8 +94,13 @@ class outlineModel(QAbstractItemModel): #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())) + self.dataChanged.emit(index, index) + + if index.column() == Outline.type.value: + # If type changed, then the icon of title changed. + # Some views might be glad to know it. + self.dataChanged.emit(index.sibling(index.row(), Outline.title.value), + index.sibling(index.row(), Outline.title.value)) return True @@ -434,6 +439,15 @@ class outlineItem(): updateWordCount = False if column in [Outline.wordCount.value, Outline.goal.value, Outline.setGoal.value]: updateWordCount = not Outline(column) in self._data or self._data[Outline(column)] != data + + # Stuff to do before + if column == Outline.type.value: + oldType = self._data[Outline.type] + if oldType == "html" and data in ["txt", "t2t"]: + # Resource inneficient way to convert HTML to plain text + e = QTextEdit() + e.setHtml(self._data[Outline.text]) + self._data[Outline.text] = e.toPlainText() # Setting data self._data[Outline(column)] = data @@ -442,14 +456,6 @@ class outlineItem(): if column == Outline.text.value: wc = wordCount(data) self.setData(Outline.wordCount.value, wc) - - if column == Outline.type.value: - oldType = self._data[Outline.type] - if oldType == "html" and data in ["txt", "t2t"]: - # Resource inneficient way to convert HTML to plain text - e = QTextEdit() - e.setHtml(self._data[Outline.text]) - self._data[Outline.text] = e.toPlainText() if updateWordCount: self.updateWordCount() diff --git a/src/ui/views/textEditView.py b/src/ui/views/textEditView.py index 03ea6fba..02305eb8 100644 --- a/src/ui/views/textEditView.py +++ b/src/ui/views/textEditView.py @@ -137,6 +137,12 @@ class textEditView(QTextEdit): else: self._textFormat = "text" + # Accept richtext maybe + if self._textFormat == "html": + self.setAcceptRichText(True) + else: + self.setAcceptRichText(False) + # Setting highlighter if self._highlighting: item = index.internalPointer() @@ -147,12 +153,6 @@ class textEditView(QTextEdit): self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat) - # Accept richtext maybe - if self._textFormat == "html": - self.setAcceptRichText(True) - else: - self.setAcceptRichText - def setCurrentModelIndexes(self, indexes): self._index = None self._indexes = [] @@ -175,15 +175,22 @@ class textEditView(QTextEdit): if topLeft.parent() != self._index.parent(): return + #print("Model changed: ({}:{}), ({}:{}/{}), ({}:{}) for {} of {}".format( + #topLeft.row(), topLeft.column(), + #self._index.row(), self._index.row(), self._column, + #bottomRight.row(), bottomRight.column(), + #self.objectName(), self.parent().objectName())) + 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 + if self._column == Outline.text.value and \ + topLeft.column() <= Outline.type.value <= bottomRight.column(): + # If item type change, and we display the main text, + # we reset the index to set the proper # highlighter and other defaults self.setupEditorForIndex(self._index) self.updateText() elif topLeft.column() <= self._column <= bottomRight.column(): - print(topLeft.column(), self._column, bottomRight.column()) self.updateText() elif self._indexes: @@ -399,4 +406,5 @@ class textEditView(QTextEdit): def applyFormat(self, _format): #FIXME - print(_format) \ No newline at end of file + print(_format) + \ No newline at end of file