TextEditors: Update block revisions only once per document

Instead of once per editor.
Also remove a related unused function.

Change-Id: I4bcd86b9b0ec61b87500e546cf2138ec5d854561
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Eike Ziller
2014-01-28 13:59:45 +01:00
parent 7f21e8b29f
commit 7e30653f8f
3 changed files with 21 additions and 44 deletions

View File

@@ -71,6 +71,7 @@ public:
QTextCursor indentOrUnindent(const QTextCursor &textCursor, bool doIndent);
void resetRevisions();
void updateRevisions();
QString m_defaultPath;
QString m_suggestedFileName;
@@ -161,6 +162,23 @@ void BaseTextDocumentPrivate::resetRevisions()
block.setRevision(documentLayout->lastSaveRevision);
}
void BaseTextDocumentPrivate::updateRevisions()
{
BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(m_document->documentLayout());
QTC_ASSERT(documentLayout, return);
int oldLastSaveRevision = documentLayout->lastSaveRevision;
documentLayout->lastSaveRevision = m_document->revision();
if (oldLastSaveRevision != documentLayout->lastSaveRevision) {
for (QTextBlock block = m_document->begin(); block.isValid(); block = block.next()) {
if (block.revision() < 0 || block.revision() != oldLastSaveRevision)
block.setRevision(-documentLayout->lastSaveRevision - 1);
else
block.setRevision(documentLayout->lastSaveRevision);
}
}
}
BaseTextDocument::BaseTextDocument() : d(new BaseTextDocumentPrivate(this))
{
connect(d->m_document, SIGNAL(modificationChanged(bool)), this, SIGNAL(changed()));
@@ -451,6 +469,7 @@ bool BaseTextDocument::save(QString *errorString, const QString &saveFileName, b
// inform about the new filename
const QFileInfo fi(fName);
d->updateRevisions();
d->m_document->setModified(false);
setFilePath(QDir::cleanPath(fi.absoluteFilePath()));
emit changed();
@@ -539,6 +558,7 @@ bool BaseTextDocument::open(QString *errorString, const QString &fileName, const
qobject_cast<BaseTextDocumentLayout*>(d->m_document->documentLayout());
QTC_ASSERT(documentLayout, return true);
documentLayout->lastSaveRevision = d->m_autoSaveRevision = d->m_document->revision();
d->updateRevisions();
d->m_document->setModified(fileName != realFileName);
setFilePath(QDir::cleanPath(fi.absoluteFilePath()));
}