[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-11-30 19:32:05
Message-ID: 200811302032.06401.pierre.stirnweiss () t-online ! de
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Sunday 30 November 2008 09:01:31 Pierre Stirnweiss wrote:
>
> This is what I propose:
> - keeping the idea of "macro command" which parents any subsequent "undo
> command" created after undoCommandAdded signal, I would like to avoid
> having "opened command" at the end of a user action. This is as far as I
> have seen so far only the case for text keying. I think we could use the
> merging facility in that case. That would make things clearer. I will try
> an implementation, and commit if it compiles/work with correct behavior.
>
> - then, I would like to group everything that is related to a user action
> in one place. For example, I don't see why a new paragraph action (this is
> just one example, I am pretty sure there are others) is half made in the
> TextSelectionHandler and in the TextTool. This is confusing and a hell to
> debug.
>

I have committed a working version of the above. To summarize what I have 
done:
- the text tool public interface has not been changed.
- in the private part, the following was done:
  i. declare an enum of editing actions. this is used for the merging test 
(for implementing QUndoCommand::id()

 ii. transfer the declaration of UndoTextCommand from the addUndoCommand 
method to the header, the implementation is in the cpp file. This is to make it 
accessible from friend classes

- I have created two "commands" derived from QUndoCommand in the command 
subdir: the TextInsertTextCommand and the TextInsertParagraphCommand. both are 
declared friend of the TextTool.

These commands explicitly set themselves as the m_currentCommand in the 
TextTool at the begining of their cstr and set back the m_currentCommand to 0 
at the end. In between, all the changes to the document are done (minus the 
removal of inlineObjects, which I have not yet looked into, still TODO). 
That way all the undoCommandAdded will create a UndoTextCommand parented on 
the current command. When the command is finished, the currentCommand pointer 
is reset so no further commands are getting eaten up.
The TextInsertTextCommand checks whether it can merge with a previous one. If 
so, the commands are merged, "transferring" the child UndoTextCommands to the 
new common command.
The TextInsertParagraphCommand does not merge with the insertText. That 
behavior was done on purpose (see previous post), but can easily be modified.

I think grouping all editing actions of a single user perspective action into 
one single object is actually clearer and easier to maintain down the road.

It might also help with the call of Florian for making the undo/redo available 
to other tool, I am not really sure what is exactly needed there but would be 
glad to look into it also.


If this solution is acceptable for everybody, I have already most of the 
editing actions ready.

Pierre

[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 Sunday 30 November 2008 09:01:31 Pierre Stirnweiss 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;</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; This is what I \
propose:</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; - \
keeping the idea of "macro command" which parents any subsequent "undo</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; command" created after \
undoCommandAdded signal, I would like to avoid</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; having "opened command" at the end of a user \
action. This is as far as I</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; have seen so far only the case for text keying. I think we \
could use the</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; \
merging facility in that case. That would make things clearer. I will try</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; an implementation, and \
commit if it compiles/work with correct behavior.</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; - then, I would like to group everything \
that is related to a user action</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; in one place. For example, I don't see why a new paragraph \
action (this is</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; just \
one example, I am pretty sure there are others) is half made in the</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; TextSelectionHandler and \
in the TextTool. This is confusing and a hell 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; debug.</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 have committed a working \
version of the above. To summarize what I have done:</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 text tool public interface has not been \
changed.</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;">- in the \
private part, the following was done:</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. declare an enum of editing actions. this is \
used for the merging test (for implementing QUndoCommand::id()</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;"> ii. transfer the declaration \
of UndoTextCommand from the addUndoCommand method to the header, the implementation \
is in the cpp file. This is to make it accessible from friend classes</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 have created two \
"commands" derived from QUndoCommand in the command subdir: the TextInsertTextCommand \
and the TextInsertParagraphCommand. both are declared friend of the TextTool.</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;">These commands explicitly set \
themselves as the m_currentCommand in the TextTool at the begining of their cstr and \
set back the m_currentCommand to 0 at the end. In between, all the changes to the \
document are done (minus the removal of inlineObjects, which I have not yet looked \
into, still TODO). </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;">That way all the undoCommandAdded will create a UndoTextCommand \
parented on the current command. When the command is finished, the currentCommand \
pointer is reset so no further commands are getting eaten up.</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 TextInsertTextCommand \
checks whether it can merge with a previous one. If so, the commands are merged, \
"transferring" the child UndoTextCommands to the new common command.</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 \
TextInsertParagraphCommand does not merge with the insertText. That behavior was done \
on purpose (see previous post), but can easily be modified.</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 grouping all editing \
actions of a single user perspective action into one single object is actually \
clearer and easier to maintain down the road.</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;">It might also help with the \
call of Florian for making the undo/redo available to other tool, I am not really \
sure what is exactly needed there but would be glad to look into it also.</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;">If this solution is \
acceptable for everybody, I have already most of the editing actions ready.</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></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