PDA

View Full Version : QTextDocument - getting last modified QTextFragment objects



lukass
30th October 2010, 17:37
Hello.

QTextDocument have functions:

void QTextDocument::modificationChanged ( bool changed ) [signal]
bool isModified () const
void setModified ( bool m = true )
Is any way to get last modified QTextFragment objects?

Lykurg
30th October 2010, 18:32
Right now I don't know such a function, but (as for user changes) the cursor is on the last changed fragment. So may be that is enough for you.

lukass
30th October 2010, 19:31
Right now I don't know such a function, but (as for user changes) the cursor is on the last changed fragment. So may be that is enough for you.
Probably not.

I wont this:
example 1:
1) user have empty QTextDocument object, so object_ptr->isModified() returns false,
2) user added some rich text, so object_ptr->isModified() returns true,
3) user clicked 'add image' icon and afterwards application execute object_ptr->setModified(false),
4) in this moment I wont get QTextFragment or QTextBlock objects which contains 'some rich text' added by user in point 2.

example 2:
1) user have QTextDocument object which contains some rich text with images and object_ptr->isModified() returns false,
2) user deleted(by normal edit) some rich text with images, so object_ptr->isModified() returns true,
3) user clicked 'add image' icon and afterwards application execute object_ptr->setModified(false),
4) in this moment I wont get QTextFragment or QTextBlock objects which contains 'some rich text with images' deleted by user in point 2.

I think one of solutions is cloning QTextDocument in point 1 and comparing with current QTextDocument in point 4. But this solution is too hangry of memory and CPU time.

wysota
30th October 2010, 19:36
There is a QTextDocument::contentsChange() signal which is all you need.

lukass
31st October 2010, 13:31
There is a QTextDocument::contentsChange() signal which is all you need.


void QTextDocument::contentsChange ( int position, int charsRemoved, int charsAdded ) [signal]
I connected this signal to slot. I can track what is added on demand but how can I get removed QTextFragment objects indicated by position and charsRemoved?