-=Freaky=-
21st June 2009, 11:57
hi guys,
i'm currently trying to convert the contents of a QTextDocument to another format, simply by processing it pretty much hierarchically:
- process each frame/table
- process each block/list
- process each fragment
the problem with this method is that a block's or fragments' text doesn't contain any newline characters (since they are converted to "ParagraphSeparators").
i tried to find the newline characters by selecting the current block with a new QTextCursor and then using a QTextDocumentFragment to get the "plain text".
QTextCursor::select( QTextCursor::BlockUnderCursor ) also selects the ParagraphSeparator before the block.
i created a new QTextDocumentFragment and gave the previously created QTextCursor as an argument in its constructor.
now QTextDocumentFragment::toPlainText() also contained the character before the block and when QTextDocumentFragment::toPlainText().at( 0 ) == '\n', i knew there was an '\n' before the current block.
i can also post the according code to this if that helps.
even though it seems kind of "quick&dirty", it works for a single newline before a block.
but if, for example, there was an empty line before a new block ("\n\nBlockText"), the 2 newlines ("\n\n") were put together as one ParagraphSeparator and therefore using QTextDocumentFragment as i explained above doesn't make it possible to know if there was an empty line before a block.
so... sorry for writing such a long text, but i found it pretty difficult to explain (probably because i'm not a native speaker ...).
i hope someone can help me out here.
maybe i just didn't find some easy trick, or maybe even my whole approach to processing the QTextDocument is crap?
thanks in advance!
sincerely,
julian
i'm currently trying to convert the contents of a QTextDocument to another format, simply by processing it pretty much hierarchically:
- process each frame/table
- process each block/list
- process each fragment
the problem with this method is that a block's or fragments' text doesn't contain any newline characters (since they are converted to "ParagraphSeparators").
i tried to find the newline characters by selecting the current block with a new QTextCursor and then using a QTextDocumentFragment to get the "plain text".
QTextCursor::select( QTextCursor::BlockUnderCursor ) also selects the ParagraphSeparator before the block.
i created a new QTextDocumentFragment and gave the previously created QTextCursor as an argument in its constructor.
now QTextDocumentFragment::toPlainText() also contained the character before the block and when QTextDocumentFragment::toPlainText().at( 0 ) == '\n', i knew there was an '\n' before the current block.
i can also post the according code to this if that helps.
even though it seems kind of "quick&dirty", it works for a single newline before a block.
but if, for example, there was an empty line before a new block ("\n\nBlockText"), the 2 newlines ("\n\n") were put together as one ParagraphSeparator and therefore using QTextDocumentFragment as i explained above doesn't make it possible to know if there was an empty line before a block.
so... sorry for writing such a long text, but i found it pretty difficult to explain (probably because i'm not a native speaker ...).
i hope someone can help me out here.
maybe i just didn't find some easy trick, or maybe even my whole approach to processing the QTextDocument is crap?
thanks in advance!
sincerely,
julian