Trying to optimize things a bit

This commit is contained in:
Olivier Keshavjee 2015-06-24 19:53:51 +02:00
parent a14351956b
commit ce445500d3
3 changed files with 45 additions and 21 deletions

View file

@ -100,7 +100,7 @@ class editorWidget(QWidget, Ui_editorWidget_ui):
highlighting=True, highlighting=True,
autoResize=True) autoResize=True)
edt.setFrameShape(QFrame.NoFrame) edt.setFrameShape(QFrame.NoFrame)
edt.setStatusTip(itm.path()) edt.setStatusTip("{} ({})".format(itm.path(), itm.type()))
self.toggledSpellcheck.connect(edt.toggleSpellcheck, AUC) self.toggledSpellcheck.connect(edt.toggleSpellcheck, AUC)
self.dictChanged.connect(edt.setDict, AUC) self.dictChanged.connect(edt.setDict, AUC)
#edt.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) #edt.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

View file

@ -10,6 +10,7 @@ class metadataView(QWidget, Ui_metadataView):
def __init__(self, parent=None): def __init__(self, parent=None):
QWidget.__init__(self) QWidget.__init__(self)
self.setupUi(self) self.setupUi(self)
self._lastIndexes = None
self.txtSummarySentance.setColumn(Outline.summarySentance.value) self.txtSummarySentance.setColumn(Outline.summarySentance.value)
self.txtSummaryFull.setColumn(Outline.summaryFull.value) self.txtSummaryFull.setColumn(Outline.summaryFull.value)
self.txtNotes.setColumn(Outline.notes.value) self.txtNotes.setColumn(Outline.notes.value)
@ -34,9 +35,11 @@ class metadataView(QWidget, Ui_metadataView):
return indexes return indexes
def selectionChanged(self, sourceView): def selectionChanged(self, sourceView):
indexes = self.getIndexes(sourceView) indexes = self.getIndexes(sourceView)
if self._lastIndexes == indexes:
return
if len(indexes) == 0: if len(indexes) == 0:
self.setEnabled(False) self.setEnabled(False)
@ -55,6 +58,8 @@ class metadataView(QWidget, Ui_metadataView):
self.properties.selectionChanged(sourceView) self.properties.selectionChanged(sourceView)
self._lastIndexes = indexes
def setDict(self, d): def setDict(self, d):
self.txtNotes.setDict(d) self.txtNotes.setDict(d)
self.txtSummaryFull.setDict(d) self.txtSummaryFull.setDict(d)

View file

@ -26,6 +26,7 @@ class textEditView(QTextEdit):
self._updating = False self._updating = False
self._item = None self._item = None
self._highlighting = highlighting self._highlighting = highlighting
self._textFormat = "text"
self.setAcceptRichText(False) self.setAcceptRichText(False)
self.spellcheck = spellcheck self.spellcheck = spellcheck
@ -45,7 +46,9 @@ class textEditView(QTextEdit):
self.updateTimer.setInterval(500) self.updateTimer.setInterval(500)
self.updateTimer.setSingleShot(True) self.updateTimer.setSingleShot(True)
self.updateTimer.timeout.connect(self.submit) self.updateTimer.timeout.connect(self.submit)
self.updateTimer.stop()
self.document().contentsChanged.connect(self.updateTimer.start, AUC) self.document().contentsChanged.connect(self.updateTimer.start, AUC)
#self.document().contentsChanged.connect(lambda: print(self.objectName(), "Contents changed"))
if index: if index:
self.setCurrentModelIndex(index) self.setCurrentModelIndex(index)
@ -96,10 +99,10 @@ class textEditView(QTextEdit):
except TypeError: except TypeError:
pass pass
self.setupEditorForIndex(self._index)
#self.document().contentsChanged.connect(self.submit, AUC) #self.document().contentsChanged.connect(self.submit, AUC)
self.updateText() self.updateText()
self.setupEditorForIndex(self._index)
else: else:
self._index = QModelIndex() self._index = QModelIndex()
@ -112,6 +115,24 @@ class textEditView(QTextEdit):
self.setPlainText("") self.setPlainText("")
def setupEditorForIndex(self, index): def setupEditorForIndex(self, index):
# what type of text are we editing?
if type(index.model()) != outlineModel:
self._textFormat = "text"
return
if self._column != Outline.text.value:
self._textFormat = "text"
return
item = index.internalPointer()
if item.isHTML():
self._textFormat = "html"
elif item.isT2T():
self._textFormat = "t2t"
else:
self._textFormat = "text"
# Setting highlighter # Setting highlighter
if self._highlighting: if self._highlighting:
item = index.internalPointer() item = index.internalPointer()
@ -123,10 +144,10 @@ class textEditView(QTextEdit):
self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat) self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
# Accept richtext maybe # Accept richtext maybe
if self.indexIsHtml(index): if self._textFormat == "html":
self.setAcceptRichText(True) self.setAcceptRichText(True)
else: else:
self.setAcceptRichText(False) self.setAcceptRichText
def setCurrentModelIndexes(self, indexes): def setCurrentModelIndexes(self, indexes):
self._index = None self._index = None
@ -164,6 +185,15 @@ class textEditView(QTextEdit):
if update: if update:
self.updateText() self.updateText()
def disconnectDocument(self):
try:
self.document().contentsChanged.disconnect(self.updateTimer.start)
except:
pass
def reconnectDocument(self):
self.document().contentsChanged.connect(self.updateTimer.start, AUC)
def updateText(self): def updateText(self):
if self._updating: if self._updating:
@ -171,12 +201,14 @@ class textEditView(QTextEdit):
self._updating = True self._updating = True
if self._index: if self._index:
if self.indexIsHtml(self._index): self.disconnectDocument()
if self._textFormat == "html":
if self.toHtml() != toString(self._model.data(self._index)): if self.toHtml() != toString(self._model.data(self._index)):
self.document().setHtml(toString(self._model.data(self._index))) self.document().setHtml(toString(self._model.data(self._index)))
else: else:
if self.toPlainText() != toString(self._model.data(self._index)): if self.toPlainText() != toString(self._model.data(self._index)):
self.document().setPlainText(toString(self._model.data(self._index))) self.document().setPlainText(toString(self._model.data(self._index)))
self.reconnectDocument()
elif self._indexes: elif self._indexes:
t = [] t = []
@ -208,7 +240,7 @@ class textEditView(QTextEdit):
if self._index: if self._index:
item = self._index.internalPointer() item = self._index.internalPointer()
if self.indexIsHtml(self._index): if self._textFormat == "html":
if self.toHtml() != self._model.data(self._index): if self.toHtml() != self._model.data(self._index):
self._updating = True self._updating = True
self._model.setData(self._index, self.toHtml()) self._model.setData(self._index, self.toHtml())
@ -227,19 +259,6 @@ class textEditView(QTextEdit):
self._model.setData(i, self.toPlainText()) self._model.setData(i, self.toPlainText())
self._updating = False self._updating = False
def indexIsHtml(self, index):
if not index.isValid():
return False
if type(index.model()) != outlineModel:
return False
item = index.internalPointer()
if item.isHTML():
return True
else:
return False
# ----------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------
# Resize stuff # Resize stuff