[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Re: questions regarding QTextDocument behaviour
From:       Pierre Stirnweiss <pierre.stirnweiss () t-online ! de>
Date:       2008-12-03 17:09:16
Message-ID: 200812031809.16736.pierre.stirnweiss () t-online ! de
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Tuesday 02 December 2008 06:04:30 Thorsten Zachmann wrote:
> Hello Pierre,
>
> > Thanks, I am looking into the functioning of the addShapes, new
> > frames,... so I can understand where the undo between shapes actually
> > falls down. I have a gut feeling, there might be just a repaint problem
> > (I wonder if the undo are done but the document is not repainted,...
>
> I don't think that is the case as you can trigger a repaint by switching to
> a different window and back but that does not change anything.
>

I think I have found  (one of) the problem(s). When deactivated, the text tool 
calls setUndoRedoEnable on the QTextDocument, which clears the QTextDocument 
internal undo/redo stack. The KWord undo/redo stack is not affected and 
therefore things become out of sync. This means that on activating the shape 
and tool again, the undo action (of KWord stack) calls a QTextDocument::undo 
(through undoTextCommand) but the QTextDocument's undo stack being empty, this 
has no effect.
I guess the reason deactivate empties the QTextDocument undo stack is that the 
text selection is saved in order to reselect on activating back the tool on 
the shape. This saving is done via the QTextCursor::position and anchor. If 
undo are done on the document when the texttool was not the active tool on 
that shape these positions might not be valid anymore.

From there I see 3 options:
- keep things as they are: not really an option since that means loosing sync 
between the KWord undo/redo stack and what will really be done as undo/redo.
- disable the selection saving functionality
- modify the way this selection saving works in order to keep the 
QTextDocument undo stack populated. This is the option I would like to try 
this evening.
  The way I see this working is the following:
  - save the cursor position and anchor as well as the selected text (or 1 or 
2 words before the cursor if there is no selection)
  - on activating the tool on the shape again, first test if the position and 
anchor are still within the document's text.
  - if yes check that the selected text on these positions is the same as the 
saved one.
  - if both tests are ok, select, if not position the QTextCursor at the end 
of the QTextDocument.

Pierre


> Thorsten
> _______________________________________________
> koffice-devel mailing list
> koffice-devel@kde.org
> https://mail.kde.org/mailman/listinfo/koffice-devel


[Attachment #5 (text/html)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" \
"http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" \
content="1" /><style type="text/css"> p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Sans Serif'; font-size:10pt; \
font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">On Tuesday 02 December 2008 06:04:30 Thorsten Zachmann wrote:</p> \
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">&gt; Hello Pierre,</p> <p \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">&gt;</p> <p style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">&gt; &gt; Thanks, I am \
looking into the functioning of the addShapes, new</p> <p style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">&gt; &gt; frames,... so I can understand where \
the undo between shapes actually</p> <p style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">&gt; &gt; falls down. I have a gut feeling, there might be just a \
repaint problem</p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">&gt; &gt; \
(I wonder if the undo are done but the document is not repainted,...</p> <p style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">&gt;</p> <p style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">&gt; I don't think that is \
the case as you can trigger a repaint by switching to</p> <p style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">&gt; a different window and back but that does \
not change anything.</p> <p style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">&gt;</p> <p style="-qt-paragraph-type:empty; margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;"></p> <p style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">I think I have found  (one of) the problem(s). \
When deactivated, the text tool calls setUndoRedoEnable on the QTextDocument, which \
clears the QTextDocument internal undo/redo stack. The KWord undo/redo stack is not \
affected and therefore things become out of sync. This means that on activating the \
shape and tool again, the undo action (of KWord stack) calls a QTextDocument::undo \
(through undoTextCommand) but the QTextDocument's undo stack being empty, this has no \
effect.</p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">I guess the \
reason deactivate empties the QTextDocument undo stack is that the text selection is \
saved in order to reselect on activating back the tool on the shape. This saving is \
done via the QTextCursor::position and anchor. If undo are done on the document when \
the texttool was not the active tool on that shape these positions might not be valid \
anymore.</p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"></p> <p style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">From there I see 3 options:</p> <p style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">- keep things as they are: not really an option \
since that means loosing sync between the KWord undo/redo stack and what will really \
be done as undo/redo.</p> <p style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">- disable the selection saving functionality</p> <p style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">- modify the way this \
selection saving works in order to keep the QTextDocument undo stack populated. This \
is the option I would like to try this evening.</p> <p style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">  The way I see this working is the \
following:</p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  - save \
the cursor position and anchor as well as the selected text (or 1 or 2 words before \
the cursor if there is no selection)</p> <p style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">  - on activating the tool on the shape again, \
first test if the position and anchor are still within the document's text.</p> <p \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  - if yes check that the \
selected text on these positions is the same as the saved one.</p> <p style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">  - if both tests are ok, \
select, if not position the QTextCursor at the end of the QTextDocument.</p> <p \
style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p> <p \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">Pierre</p> <p \
style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p> <p \
style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p> <p \
style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">&gt; Thorsten</p> <p style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">&gt; \
_______________________________________________</p> <p style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; -qt-user-state:0;">&gt; koffice-devel mailing list</p> <p style=" \
margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; -qt-user-state:0;">&gt; \
koffice-devel@kde.org</p> <p style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;">&gt; https://mail.kde.org/mailman/listinfo/koffice-devel</p> <p \
style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; \
margin-right:0px; -qt-block-indent:0; text-indent:0px; \
-qt-user-state:0;"></p></body></html>



_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic