From 9a8751c7c8b53e6fc2bc59a8cf584b42bf9a9e0e Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 1 Apr 2024 15:45:04 +0800 Subject: [PATCH] fix: cpu load high. --- libs/qsynedit/qsynedit/document.cpp | 46 ++++++++++++++++------------- libs/qsynedit/qsynedit/document.h | 3 +- libs/qsynedit/qsynedit/qsynedit.cpp | 1 - 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/libs/qsynedit/qsynedit/document.cpp b/libs/qsynedit/qsynedit/document.cpp index 3e4ad69e..e99467c1 100644 --- a/libs/qsynedit/qsynedit/document.cpp +++ b/libs/qsynedit/qsynedit/document.cpp @@ -145,19 +145,6 @@ int Document::blockEnded(int line) int Document::maxLineWidth() { QMutexLocker locker(&mMutex); - if (mIndexOfLongestLine < 0) { - int MaxLen = -1; - mIndexOfLongestLine = -1; - if (mLines.count() > 0 ) { - for (int i=0;imWidth; - if (len > MaxLen) { - MaxLen = len; - mIndexOfLongestLine = i; - } - } - } - } if (mIndexOfLongestLine >= 0) { return mLines[mIndexOfLongestLine]->width(); } else @@ -1179,7 +1166,7 @@ void Document::endSetLinesWidth() mSetLineWidthLockCount--; if (mSetLineWidthLockCount == 0) { if (mMaxLineChangedInSetLinesWidth) - emit maxLineWidthChanged(); + updateMaxLineWidthAndNotify(); } } @@ -1195,30 +1182,47 @@ void Document::setLineWidth(int line, const QString &lineText, int newWidth, con mLines[line]->mGlyphStartPositionList = glyphStartPositionList; if (mIndexOfLongestLine<0) { mIndexOfLongestLine = line; - notifyMaxLineWidthChanged(); + updateMaxLineWidthChanged(); } else if (mIndexOfLongestLine == line) { if (oldWidth > newWidth) { mIndexOfLongestLine = -1; - notifyMaxLineWidthChanged(); - } else { - notifyMaxLineWidthChanged(); + updateMaxLineWidthChanged(); + } else if (oldWidth < newWidth) { + updateMaxLineWidthChanged(); } } else if (mLines[mIndexOfLongestLine]->mWidth < newWidth) { mIndexOfLongestLine = line; - notifyMaxLineWidthChanged(); + updateMaxLineWidthChanged(); } Q_ASSERT(mLines[line]->mGlyphStartPositionList.length() == mLines[line]->mGlyphStartCharList.length()); } -void Document::notifyMaxLineWidthChanged() +void Document::updateMaxLineWidthChanged() { if (mSetLineWidthLockCount>0) { mMaxLineChangedInSetLinesWidth = true; } else { - emit maxLineWidthChanged(); + updateMaxLineWidthAndNotify(); } } +void Document::updateMaxLineWidthAndNotify() +{ + int MaxLen = -1; + mIndexOfLongestLine = -1; + if (mLines.count() > 0 ) { + for (int i=0;imWidth; + if (len > MaxLen) { + MaxLen = len; + mIndexOfLongestLine = i; + } + } + } + if (mIndexOfLongestLine>=0) + emit maxLineWidthChanged(); +} + QList Document::calcGlyphPositionList(const QString &lineText, const QList &glyphStartCharList, int left, int &right) const { return calcGlyphPositionList(lineText, glyphStartCharList, diff --git a/libs/qsynedit/qsynedit/document.h b/libs/qsynedit/qsynedit/document.h index dd0d15d4..4b47a0a0 100644 --- a/libs/qsynedit/qsynedit/document.h +++ b/libs/qsynedit/qsynedit/document.h @@ -579,7 +579,8 @@ private: void beginSetLinesWidth(); void endSetLinesWidth(); void setLineWidth(int line, const QString& lineText, int newWidth, const QList glyphStartPositionList); - void notifyMaxLineWidthChanged(); + void updateMaxLineWidthChanged(); + void updateMaxLineWidthAndNotify(); int glyphWidth(const QString& glyph, int left, const QFontMetrics &fontMetrics, diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 50c3bfbf..1ff1e89b 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -930,7 +930,6 @@ void QSynEdit::invalidateLines(int firstLine, int lastLine) { if (!isVisible()) return; - // qDebug()<<"invalidate lines:"<