Commit f161f1a2 authored by Eike Ziller's avatar Eike Ziller

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: default avatarEike Ziller <eike.ziller@digia.com>
parent c233ad0b
......@@ -83,6 +83,17 @@ BaseTextDocumentPrivate::BaseTextDocumentPrivate(BaseTextDocument *q) :
BaseTextDocument::BaseTextDocument() : d(new BaseTextDocumentPrivate(this))
{
connect(d->m_document, SIGNAL(modificationChanged(bool)), this, SIGNAL(changed()));
// set new document layout
QTextOption opt = d->m_document->defaultTextOption();
opt.setTextDirection(Qt::LeftToRight);
opt.setFlags(opt.flags() | QTextOption::IncludeTrailingSpaces
| QTextOption::AddSpaceForLineAndParagraphSeparators
);
d->m_document->setDefaultTextOption(opt);
BaseTextDocumentLayout *documentLayout = new BaseTextDocumentLayout(d->m_document);
d->m_document->setDocumentLayout(documentLayout);
}
BaseTextDocument::~BaseTextDocument()
......
......@@ -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()));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment