Don't update line width in background.

This commit is contained in:
Roy Qu 2024-05-07 16:00:33 +08:00
parent 89e2c330e3
commit e29b7c0148
4 changed files with 0 additions and 110 deletions

View File

@ -92,22 +92,6 @@ int Document::lineWidth(int line)
return 0; return 0;
} }
void Document::updateLineWidth(int line)
{
QMutexLocker locker(&mMutex);
if (line>=0 && line < mLines.size()) {
if (mLines[line]->mWidth<0) {
int width;
QList<int> glyphPositions = mGlyphCalculator.calcLineWidth(
mLines[line]->lineText(),
mLines[line]->glyphStartCharList(),
width);
setLineWidth(line, width,glyphPositions);
mLines[line]->mIsTempWidth = true;
}
}
}
int Document::lineWidth(int line, const QString &newText) int Document::lineWidth(int line, const QString &newText)
{ {
QMutexLocker locker(&mMutex); QMutexLocker locker(&mMutex);
@ -1268,12 +1252,6 @@ void Document::invalidateAllLineWidth()
line->invalidateWidth(); line->invalidateWidth();
} }
mIndexOfLongestLine = -1; mIndexOfLongestLine = -1;
FindMaxLineWidthThread *thread = new FindMaxLineWidthThread(mLines, mGlyphCalculator);
connect(thread, &FindMaxLineWidthThread::maxWidthLineFound,
this, &Document::maxWidthLineFound);
connect(thread, &QThread::finished,
thread, &QThread::deleteLater);
thread->start();
} }
void Document::invalidateAllNonTempLineWidth() void Document::invalidateAllNonTempLineWidth()
@ -1778,29 +1756,4 @@ void GlyphCalculator::setFont(const QFont &newFont)
mSpaceWidth = mFontMetrics.horizontalAdvance(" "); mSpaceWidth = mFontMetrics.horizontalAdvance(" ");
} }
FindMaxLineWidthThread::FindMaxLineWidthThread(const DocumentLines &lines, const GlyphCalculator &glyphCalculator, QObject *parent):
QThread(parent),
mLines{lines},
mGlyphCalculator{glyphCalculator}
{
}
void FindMaxLineWidthThread::run()
{
int maxWidth = 0;
int maxWidthLine = -1;
for (int i=0;i<mLines.size();i++) {
int width = mLines[i]->mWidth;
if ( width < 0 )
width = mGlyphCalculator.stringWidth(mLines[i]->lineText(),0);
if (width > maxWidth) {
maxWidth = width;
maxWidthLine = i;
}
}
if (maxWidthLine >= 0)
emit maxWidthLineFound(maxWidthLine);
}
} }

View File

@ -36,7 +36,6 @@ QList<int> calcGlyphStartCharList(const QString &text);
void expandGlyphStartCharList(const QString& strAdded, int oldStrLen, QList<int> &glyphStartCharList); void expandGlyphStartCharList(const QString& strAdded, int oldStrLen, QList<int> &glyphStartCharList);
class Document; class Document;
class FindMaxLineWidthThread;
using SearchConfirmAroundProc = std::function<bool ()>; using SearchConfirmAroundProc = std::function<bool ()>;
/** /**
@ -180,7 +179,6 @@ private:
bool mIsTempWidth; bool mIsTempWidth;
UpdateWidthFunc mUpdateWidthFunc; UpdateWidthFunc mUpdateWidthFunc;
friend class Document; friend class Document;
friend class FindMaxLineWidthThread;
}; };
typedef std::shared_ptr<DocumentLine> PDocumentLine; typedef std::shared_ptr<DocumentLine> PDocumentLine;
@ -275,26 +273,6 @@ private:
bool mForceMonospace; bool mForceMonospace;
}; };
class FindMaxLineWidthThread: public QThread {
Q_OBJECT
public:
explicit FindMaxLineWidthThread(
const DocumentLines &lines,
const GlyphCalculator& glyphCalculator,
QObject* parent=nullptr);
FindMaxLineWidthThread(const FindMaxLineWidthThread&) = delete;
signals:
void maxWidthLineFound(int line);
private:
DocumentLines mLines;
GlyphCalculator mGlyphCalculator;
// QThread interface
protected:
void run() override;
};
/** /**
* @brief The Document class * @brief The Document class
* *
@ -349,8 +327,6 @@ public:
*/ */
int lineWidth(int line); int lineWidth(int line);
void updateLineWidth(int line);
/** /**
* @brief get width of the specified text / line * @brief get width of the specified text / line
* *
@ -646,7 +622,6 @@ signals:
void inserted(int startLine, int count); void inserted(int startLine, int count);
void putted(int line); void putted(int line);
void maxLineWidthChanged(); void maxLineWidthChanged();
void lineWidthUpdateNeeded(int line);
protected: protected:
QString getTextStr() const; QString getTextStr() const;
void setUpdateState(bool Updating); void setUpdateState(bool Updating);
@ -654,9 +629,6 @@ protected:
void addItem(const QString& s); void addItem(const QString& s);
void putTextStr(const QString& text); void putTextStr(const QString& text);
void internalClear(); void internalClear();
void maxWidthLineFound(int line) {
emit lineWidthUpdateNeeded(line);
}
private: private:
void invalidateAllLineWidth(); void invalidateAllLineWidth();
bool lineWidthValid(int line); bool lineWidthValid(int line);

View File

@ -44,20 +44,6 @@
#define UPDATE_HORIZONTAL_SCROLLBAR_EVENT ((QEvent::Type)(QEvent::User+1)) #define UPDATE_HORIZONTAL_SCROLLBAR_EVENT ((QEvent::Type)(QEvent::User+1))
#define UPDATE_VERTICAL_SCROLLBAR_EVENT ((QEvent::Type)(QEvent::User+2)) #define UPDATE_VERTICAL_SCROLLBAR_EVENT ((QEvent::Type)(QEvent::User+2))
#define UPDATE_LINE_WIDTH_EVENT ((QEvent::Type)(QEvent::User+3))
class UpdateLineWidthEvent: public QEvent{
public:
explicit UpdateLineWidthEvent(int line):
QEvent{UPDATE_LINE_WIDTH_EVENT},
mLine{line}
{
}
int line() const { return mLine; }
private:
int mLine;
};
namespace QSynedit { namespace QSynedit {
QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent), QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
@ -91,7 +77,6 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent),
connect(mDocument.get(), &Document::cleared, this, &QSynEdit::updateVScrollbar); connect(mDocument.get(), &Document::cleared, this, &QSynEdit::updateVScrollbar);
connect(mDocument.get(), &Document::deleted, this, &QSynEdit::updateVScrollbar); connect(mDocument.get(), &Document::deleted, this, &QSynEdit::updateVScrollbar);
connect(mDocument.get(), &Document::inserted, this, &QSynEdit::updateVScrollbar); connect(mDocument.get(), &Document::inserted, this, &QSynEdit::updateVScrollbar);
connect(mDocument.get(), &Document::lineWidthUpdateNeeded, this, &QSynEdit::onLineWidthUpdateNeeded);
mGutterWidth = 0; mGutterWidth = 0;
@ -1770,12 +1755,6 @@ void QSynEdit::onMaxLineWidthChanged()
updateHScrollBarLater(); updateHScrollBarLater();
} }
void QSynEdit::onLineWidthUpdateNeeded(int line)
{
UpdateLineWidthEvent * event = new UpdateLineWidthEvent(line);
qApp->postEvent(this,event);
}
void QSynEdit::updateHScrollBarLater() void QSynEdit::updateHScrollBarLater()
{ {
QEvent * event = new QEvent(UPDATE_HORIZONTAL_SCROLLBAR_EVENT); QEvent * event = new QEvent(UPDATE_HORIZONTAL_SCROLLBAR_EVENT);
@ -3164,12 +3143,6 @@ void QSynEdit::doUpdateVScrollbar()
verticalScrollBar()->setSingleStep(mTextHeight); verticalScrollBar()->setSingleStep(mTextHeight);
} }
void QSynEdit::doUpdateLineWidth(int line)
{
mDocument->updateLineWidth(line);
}
void QSynEdit::updateCaret() void QSynEdit::updateCaret()
{ {
if (mDocument->maxLineWidth()<0) if (mDocument->maxLineWidth()<0)
@ -6008,12 +5981,6 @@ bool QSynEdit::event(QEvent *event)
event->setAccepted(true); event->setAccepted(true);
doUpdateHScrollbar(); doUpdateHScrollbar();
break; break;
case UPDATE_LINE_WIDTH_EVENT: {
event->setAccepted(true);
UpdateLineWidthEvent* updateEvent = dynamic_cast<UpdateLineWidthEvent *>(event);
doUpdateLineWidth(updateEvent->line());
}
break;
case QEvent::KeyPress:{ case QEvent::KeyPress:{
QKeyEvent* keyEvent = dynamic_cast<QKeyEvent *>(event); QKeyEvent* keyEvent = dynamic_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab) if(keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab)

View File

@ -525,7 +525,6 @@ private:
void doUpdateHScrollbar(); void doUpdateHScrollbar();
void updateVScrollbar(); void updateVScrollbar();
void doUpdateVScrollbar(); void doUpdateVScrollbar();
void doUpdateLineWidth(int line);
void updateCaret(); void updateCaret();
void recalcCharExtent(); void recalcCharExtent();
QString expandAtWideGlyphs(const QString& S); QString expandAtWideGlyphs(const QString& S);
@ -646,7 +645,6 @@ private:
private slots: private slots:
void onMaxLineWidthChanged(); void onMaxLineWidthChanged();
void onLineWidthUpdateNeeded(int line);
void updateHScrollBarLater(); void updateHScrollBarLater();
void onBookMarkOptionsChanged(); void onBookMarkOptionsChanged();
void onGutterChanged(); void onGutterChanged();