forked from qt-creator/qt-creator
Move some BaseTextDocument setup from BaseTextEditorWidget
There is a 1-to-1 relationship between BaseTextDocument and QTextDocument, so it doesn't make sense to do the setup between them in the editor widget. Move creation of BaseTextDocumentLayout and setting up of 'changed' signal to BaseTextDocument. This also avoids sending multiple 'changed' signals for a single QTextDocument::modificationChanged signal in case of splits. Change-Id: Iaab4fea594c5b50f502fd41c88948fac132de9f1 Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -2464,26 +2464,15 @@ void BaseTextEditorWidgetPrivate::setupDocumentSignals(const QSharedPointer<Base
|
||||
}
|
||||
|
||||
QTextDocument *doc = document->document();
|
||||
BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(doc->documentLayout());
|
||||
if (!documentLayout) {
|
||||
QTextOption opt = doc->defaultTextOption();
|
||||
opt.setTextDirection(Qt::LeftToRight);
|
||||
opt.setFlags(opt.flags() | QTextOption::IncludeTrailingSpaces
|
||||
| QTextOption::AddSpaceForLineAndParagraphSeparators
|
||||
);
|
||||
doc->setDefaultTextOption(opt);
|
||||
documentLayout = new BaseTextDocumentLayout(doc);
|
||||
doc->setDocumentLayout(documentLayout);
|
||||
}
|
||||
|
||||
q->setDocument(doc);
|
||||
q->setCursorWidth(2); // Applies to the document layout
|
||||
|
||||
BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(doc->documentLayout());
|
||||
QTC_CHECK(documentLayout);
|
||||
QObject::connect(documentLayout, SIGNAL(updateBlock(QTextBlock)), q, SLOT(slotUpdateBlockNotify(QTextBlock)));
|
||||
QObject::connect(documentLayout, SIGNAL(updateExtraArea()), q, SLOT(slotUpdateExtraArea()));
|
||||
QObject::connect(q, SIGNAL(requestBlockUpdate(QTextBlock)), documentLayout, SIGNAL(updateBlock(QTextBlock)));
|
||||
QObject::connect(doc, SIGNAL(modificationChanged(bool)), q, SIGNAL(changed()));
|
||||
QObject::connect(q, SIGNAL(changed()), document.data(), SIGNAL(changed()));
|
||||
QObject::connect(doc, SIGNAL(contentsChange(int,int,int)), q,
|
||||
SLOT(editorContentsChange(int,int,int)), Qt::DirectConnection);
|
||||
QObject::connect(document.data(), SIGNAL(aboutToReload()), q, SLOT(documentAboutToBeReloaded()));
|
||||
|
||||
Reference in New Issue
Block a user