optimaze qsynedit processing

This commit is contained in:
Roy Qu 2024-03-31 08:36:20 +08:00
parent 65809f6edf
commit 8584380587
3 changed files with 26 additions and 32 deletions

View File

@ -195,7 +195,7 @@ void Document::insertItem(int line, const QString &s)
mUpdateDocumentLineWidthFunc);
documentLine->setLineText(s);
mLines.insert(line,documentLine);
setIndexOfLongestLine(-1);
mIndexOfLongestLine = -1;
endUpdate();
}
@ -288,8 +288,8 @@ void Document::setContents(const QStringList &text)
foreach (const QString& s,text) {
addItem(s);
}
mIndexOfLongestLine = -1;
emit inserted(FirstAdded,text.count());
setIndexOfLongestLine(-1);
}
}
@ -346,7 +346,7 @@ void Document::addLines(const QStringList &strings)
for (const QString& s:strings) {
addItem(s);
}
setIndexOfLongestLine(-1);
mIndexOfLongestLine = -1;
emit inserted(FirstAdded,strings.count());
}
}
@ -386,7 +386,7 @@ void Document::deleteLines(int index, int numLines)
});
if (mIndexOfLongestLine>=index) {
if (mIndexOfLongestLine <index+numLines) {
setIndexOfLongestLine(-1);
mIndexOfLongestLine = -1;
} else {
mIndexOfLongestLine -= numLines;
}
@ -441,9 +441,9 @@ void Document::deleteAt(int index)
}
beginUpdate();
if (mIndexOfLongestLine == index)
setIndexOfLongestLine(-1);
mIndexOfLongestLine = -1;
else if (mIndexOfLongestLine>index)
setIndexOfLongestLine(-1);
mIndexOfLongestLine -= 1;
mLines.removeAt(index);
emit deleted(index,1);
endUpdate();
@ -475,7 +475,7 @@ void Document::putLine(int index, const QString &s, bool notify) {
mLines[index]->setLineText(s);
if (mIndexOfLongestLine == index) {
// width is invalidated, so we must recalculate longest line
setIndexOfLongestLine(-1);
mIndexOfLongestLine = -1;
}
if (notify)
emit putted(index);
@ -501,7 +501,6 @@ void Document::insertLines(int index, int numLines)
return;
beginUpdate();
auto action = finally([this]{
setIndexOfLongestLine(-1);
endUpdate();
});
PDocumentLine line;
@ -510,6 +509,7 @@ void Document::insertLines(int index, int numLines)
line = std::make_shared<DocumentLine>(mUpdateDocumentLineWidthFunc);
mLines[i]=line;
}
mIndexOfLongestLine = -1;
emit inserted(index,numLines);
}
@ -632,7 +632,6 @@ void Document::loadFromFile(const QString& filename, const QByteArray& encoding,
auto action = finally([this]{
if (mLines.count()>0)
emit inserted(0,mLines.count());
setIndexOfLongestLine(-1);
endUpdate();
});
//test for utf8 / utf 8 bom
@ -1161,7 +1160,7 @@ void Document::internalClear()
beginUpdate();
int oldCount = mLines.count();
mLines.clear();
setIndexOfLongestLine(-1);
mIndexOfLongestLine = -1;
emit deleted(0,oldCount);
endUpdate();
}
@ -1195,19 +1194,23 @@ void Document::setLineWidth(int line, const QString &lineText, int newWidth, con
mLines[line]->mWidth = newWidth;
mLines[line]->mGlyphStartPositionList = glyphStartPositionList;
if (mIndexOfLongestLine<0) {
setIndexOfLongestLine(line);
mIndexOfLongestLine = line;
notifyMaxLineWidthChanged();
} else if (mIndexOfLongestLine == line) {
if (oldWidth > newWidth)
setIndexOfLongestLine(-1);
else
emitMaxLineWidthChanged();
if (oldWidth > newWidth) {
mIndexOfLongestLine = -1;
notifyMaxLineWidthChanged();
} else {
notifyMaxLineWidthChanged();
}
} else if (mLines[mIndexOfLongestLine]->mWidth < newWidth) {
setIndexOfLongestLine(line);
mIndexOfLongestLine = line;
notifyMaxLineWidthChanged();
}
Q_ASSERT(mLines[line]->mGlyphStartPositionList.length() == mLines[line]->mGlyphStartCharList.length());
}
void Document::emitMaxLineWidthChanged()
void Document::notifyMaxLineWidthChanged()
{
if (mSetLineWidthLockCount>0) {
mMaxLineChangedInSetLinesWidth = true;
@ -1216,14 +1219,6 @@ void Document::emitMaxLineWidthChanged()
}
}
void Document::setIndexOfLongestLine(int line)
{
mIndexOfLongestLine = line;
//mIndexOfLongestLine may not change, but it's width changed.
//so we must emit the signal here
emitMaxLineWidthChanged();
}
QList<int> Document::calcGlyphPositionList(const QString &lineText, const QList<int> &glyphStartCharList, int left, int &right) const
{
return calcGlyphPositionList(lineText, glyphStartCharList,
@ -1277,8 +1272,7 @@ void Document::invalidateAllLineWidth()
for (PDocumentLine& line:mLines) {
line->invalidateWidth();
}
setIndexOfLongestLine(-1);
// mIndexOfLongestLine = -1;
mIndexOfLongestLine = -1;
}
DocumentLine::DocumentLine(DocumentLine::UpdateWidthFunc updateWidthFunc):

View File

@ -579,8 +579,7 @@ private:
void beginSetLinesWidth();
void endSetLinesWidth();
void setLineWidth(int line, const QString& lineText, int newWidth, const QList<int> glyphStartPositionList);
void emitMaxLineWidthChanged();
void setIndexOfLongestLine(int line);
void notifyMaxLineWidthChanged();
int glyphWidth(const QString& glyph, int left,
const QFontMetrics &fontMetrics,

View File

@ -3218,8 +3218,8 @@ void QSynEdit::recalcCharExtent()
}
mTextHeight *= mLineSpacingFactor;
mTopPos = currentTopRow * mTextHeight;
mLeftPos = currentLeftCol * mCharWidth;
setTopPos(currentTopRow * mTextHeight);
setLeftPos(currentLeftCol * mCharWidth);
onSizeOrFontChanged();
}
@ -6799,6 +6799,7 @@ void QSynEdit::setLeftPos(int value)
//value = std::min(value,maxScrollWidth());
value = std::max(value, 0);
if (value != mLeftPos) {
mLeftPos = value;
setStatusChanged(StatusChange::scLeftPos);
if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssHorizontal)
horizontalScrollBar()->setValue(value);
@ -6824,10 +6825,10 @@ void QSynEdit::setTopPos(int value)
value = std::max(value, 0);
if (value != mTopPos) {
setStatusChanged(StatusChange::scTopPos);
mTopPos = value;
if (mScrollBars == ScrollStyle::ssBoth || mScrollBars == ScrollStyle::ssVertical) {
verticalScrollBar()->setValue(value);
} else {
mTopPos = value;
invalidate();
}
}