From 272b0ec18a046a9062b897da4ef9aaab0f7668c5 Mon Sep 17 00:00:00 2001 From: AngryFender Date: Fri, 5 Apr 2024 23:52:18 +0100 Subject: [PATCH] Github Issue #29: previous method to extract the raw texts with all the data and symbols on a QTextBlock level couldn't return QTextBlock with the shown format symbols so therefore returning QString as result. Also added another method to extract the formattings such as checkbox, link, bold, italic and strikethrough --- mktextdocument.cpp | 19 +++++++++++++++++-- mktextdocument.h | 3 ++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/mktextdocument.cpp b/mktextdocument.cpp index 4dec8bd..71546d2 100644 --- a/mktextdocument.cpp +++ b/mktextdocument.cpp @@ -667,7 +667,7 @@ void MkTextDocument::showSymbolsAtPos(QString &text, int pos, const QString &sym text.insert(pos,symbol); } -void MkTextDocument::extractSymbolsInBlock(QTextBlock &block) +void MkTextDocument::extractSymbolsInBlock(QTextBlock &block, QString &result) { QTextBlockUserData* data =block.userData(); if(data == nullptr){ @@ -692,12 +692,27 @@ void MkTextDocument::extractSymbolsInBlock(QTextBlock &block) if(formatData){ if(formatData->isHidden()){ formatData->setHidden(false); - showAllFormatSymbolsInTextBlock(block, formatData); + showFormatSymbolsInTextBlock(block, formatData, result); } } } } +void MkTextDocument::showFormatSymbolsInTextBlock(QTextBlock &block, FormatData *formatData, QString &result) +{ + QString textBlock = block.text(); + for(QVector::Iterator it = formatData->pos_begin(); it < formatData->pos_end(); it++) + { + showSymbolsAtPos(textBlock, (*it)->getPos(), (*it)->getSymbol()); + + if((*it)->getSymbol() == LINK_SYMBOL_URL_START){ + int pos = (*it)->getPos(); + textBlock.insert(pos+2,formatData->getLinkUrl(pos)); + } + } + result = textBlock; +} + void MkTextDocument::autoCompleteCodeBlock(int blockNumber ,bool &success) { QTextCursor editCursor(this->findBlockByNumber(blockNumber)); diff --git a/mktextdocument.h b/mktextdocument.h index 4f4ef39..43bcc4c 100644 --- a/mktextdocument.h +++ b/mktextdocument.h @@ -210,7 +210,8 @@ public slots: void showAllFormatSymbolsInTextBlock(QTextBlock &block, FormatData *formatData, SelectRange * selectRange = nullptr); void showSymbolsAtPos(QString &text, int pos, const QString &symbol); - void extractSymbolsInBlock(QTextBlock &block); + void extractSymbolsInBlock(QTextBlock &block, QString &result); + void showFormatSymbolsInTextBlock(QTextBlock &block, FormatData *formatData, QString &result); void autoCompleteCodeBlock(int blockNumber,bool &success); BlockData* checkValidCodeBlock(QTextBlock &block);