From 4a190ec8736ff95268286e76e42828357bd96b27 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 19 Jan 2024 21:36:54 +0800 Subject: [PATCH] work save --- libs/qsynedit/qsynedit/document.cpp | 99 +++++++++++++++++++++++++---- libs/qsynedit/qsynedit/document.h | 32 +++++++--- 2 files changed, 112 insertions(+), 19 deletions(-) diff --git a/libs/qsynedit/qsynedit/document.cpp b/libs/qsynedit/qsynedit/document.cpp index bde20ae8..c435c9d0 100644 --- a/libs/qsynedit/qsynedit/document.cpp +++ b/libs/qsynedit/qsynedit/document.cpp @@ -85,10 +85,10 @@ int Document::lineColumns(int index) { QMutexLocker locker(&mMutex); if (index>=0 && index < mLines.size()) { - if (mLines[index]->columns == -1) { + if (mLines[index]->columns() == -1) { return calculateLineColumns(index); } else - return mLines[index]->columns; + return mLines[index]->columns(); } else return 0; } @@ -789,6 +789,31 @@ void Document::saveToFile(QFile &file, const QByteArray& encoding, } } +int Document::gryphsColumns(const QStringList &gryphs, int colsBefore) const +{ + int columns = std::max(0,colsBefore); + for (int i=0;i0) { + //Combining character + QString gryph=mGryphs.last(); + gryph.append(mLineText[i]); + mGryphs[mGryphs.length()-1]=gryph; + } else { + mGryphs.append(mLineText[i]); + } + i++; + } +} + +int DocumentLine::columns() const +{ + return mColumns; +} + +const SyntaxState& DocumentLine::syntaxState() const +{ + return mSyntaxState; +} + +void DocumentLine::setSyntaxState(const SyntaxState &newSyntaxState) +{ + mSyntaxState = newSyntaxState; +} + UndoList::UndoList():QObject() { diff --git a/libs/qsynedit/qsynedit/document.h b/libs/qsynedit/qsynedit/document.h index 314de7ad..5ea2464f 100644 --- a/libs/qsynedit/qsynedit/document.h +++ b/libs/qsynedit/qsynedit/document.h @@ -30,14 +30,28 @@ namespace QSynedit { -struct DocumentLine { - QString lineText; - SyntaxState syntaxState; - int columns; // +class DocumentLine { public: - explicit DocumentLine(); - DocumentLine(const DocumentLine&)=delete; - DocumentLine& operator=(const DocumentLine&)=delete; + explicit DocumentLine(); + DocumentLine(const DocumentLine&)=delete; + DocumentLine& operator=(const DocumentLine&)=delete; + + const QStringList& glyphs() const; + int length() const; + + const QString& lineText() const; + void setLineText(const QString &newLineText); + + int columns() const; + + const SyntaxState& syntaxState() const; + void setSyntaxState(const SyntaxState &newSyntaxState); + +private: + QString mLineText; + QStringList mGlyphs; + SyntaxState mSyntaxState; + int mColumns; }; typedef std::shared_ptr PDocumentLine; @@ -100,7 +114,9 @@ public: void loadFromFile(const QString& filename, const QByteArray& encoding, QByteArray& realEncoding); void saveToFile(QFile& file, const QByteArray& encoding, const QByteArray& defaultEncoding, QByteArray& realEncoding); - int stringColumns(const QString& line, int colsBefore) const; + //int stringColumns(const QString &line, int colsBefore) const; + int gryphsColumns(const QStringList& gryphs, int colsBefore) const; + int tokenColumns(const QString &token) const; int charColumns(QChar ch) const; bool getAppendNewLineAtEOF();