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

List:       kde-commits
Subject:    [calligra/text-undo-munichsprint] libs/kotext: Add some debug statements
From:       Pierre Stirnweiss <pstirnweiss () googlemail ! com>
Date:       2012-02-22 21:15:55
Message-ID: 20120222211555.0961BA60B9 () git ! kde ! org
[Download RAW message or body]

Git commit 4c300ba3c4eb8003bf8a9d8d793090982c803514 by Pierre Stirnweiss.
Committed on 22/02/2012 at 22:06.
Pushed by pstirnweiss into branch 'text-undo-munichsprint'.

Add some debug statements

M  +59   -0    libs/kotext/KoTextEditor_undo.cpp

http://commits.kde.org/calligra/4c300ba3c4eb8003bf8a9d8d793090982c803514

diff --git a/libs/kotext/KoTextEditor_undo.cpp b/libs/kotext/KoTextEditor_undo.cpp
index 0261f47..063cc57 100644
--- a/libs/kotext/KoTextEditor_undo.cpp
+++ b/libs/kotext/KoTextEditor_undo.cpp
@@ -114,62 +114,86 @@ void KoTextEditor::Private::documentCommandAdded()
         KoTextEditor::Private *m_p;
     };
 
+    kDebug(32500) << "received a QTextDocument undoCommand signal";
+    kDebug(32500) << "commandStack count: " << commandStack.count();
+    kDebug(32500) << "addCommand: " << addNewCommand;
+    kDebug(32500) << "editorState: " << editorState;
     if (commandStack.isEmpty()) {
         //We have an empty stack. We need a head command which is to be pushed onto \
                our commandStack and on the application stack if there is one.
         //This command will serve as a parent for the auto-generated \
UndoTextCommands. +        kDebug(32500) << "empty stack, will push a new headCommand \
on both commandStack and application's stack. title: " << commandTitle;  \
commandStack.push(new KUndo2Command(commandTitle));  if \
                (KoTextDocument(document).undoStack()) {
             KoTextDocument(document).undoStack()->push(commandStack.top());
         }
         addNewCommand = false;
+        kDebug(32500) << "commandStack is now: " << commandStack.count();
     }
     else if (addNewCommand) {
         //We have already a headCommand on the commandStack. However we want a new \
child headCommand (nested commands) on the commandStack for parenting further \
UndoTextCommands. This shouldn't be pushed on the application's stack because it is a \
child of the current commandStack's top. +        kDebug(32500) << "we have a \
headCommand on the commandStack but need a new child command. we will push it only on \
                the commandStack: " << commandTitle;
         commandStack.push(new KUndo2Command(commandTitle, commandStack.top()));
         addNewCommand = false;
+        kDebug(32500) << "commandStack count is now: " << commandStack.count();
     }
     else if ((editorState == KeyPress || editorState == Delete) && \
!commandStack.isEmpty() && commandStack.top()->childCount()) {  //QTextDocument emits \
a signal on the first key press (or delte) and "merges" the subsequent ones, until an \
incompatible one is done. In which case it re-emit a signal.  //Here we are in \
KeyPress (or Delete) state. The fact that the commandStack isn't empty and its top \
command has children means that we just received such a signal. We therefore need to \
pop the previous headCommand (which were either key press or delete) and create a new \
one to parent the UndoTextCommands. This command also need to be pushed on the \
application's stack. +        kDebug(32500) << "we are in subsequent keyPress/delete \
state and still received a signal. we need to create a new headCommand: " << \
commandTitle; +        kDebug(32500) << "so we pop the current one and push the new \
one on both the commandStack and the application's stack";  commandStack.pop();
         commandStack.push(new KUndo2Command(commandTitle, \
!commandStack.isEmpty()?commandStack.top():0));  if \
                (KoTextDocument(document).undoStack()) {
             KoTextDocument(document).undoStack()->push(commandStack.top());
         }
+        kDebug(32500) << "commandStack count: " << commandStack.count();
     }
 
     //Now we can create our UndoTextCommand which is parented to the commandStack't \
top headCommand.  new UndoTextCommand(document, this, commandStack.top());
+    kDebug(32500) << "done creating the dummy UndoTextCommand";
 }
 
 //This method is used to update the KoTextEditor state, which will condition how the \
QTextDocument::undoCommandAdded signal will get handled.  void \
KoTextEditor::Private::updateState(KoTextEditor::Private::State newState, QString \
title)  {
+    kDebug(32500) << "updateState from: " << editorState << " to: " << newState << " \
with: " << title; +    kDebug(32500) << "commandStack count: " << \
commandStack.count();  if (editorState == Custom && newState != NoOp) {
         //We already are in a custom state (meaning that either a KUndo2Command was \
pushed on us, an on-the-fly macro command was started or we are executing a complex \
editing from within the KoTextEditor.  //In that state any update of the state \
different from NoOp is part of that "macro". However, updating the state means that \
we are now wanting to have a new command for parenting the UndoTextCommand generated \
after the signal from QTextDocument. This is to ensure that undo/redo actions are \
done in the proper order. Setting addNewCommand will ensure that we create such a \
child headCommand on the commandStack. This command will not be pushed on the \
application's stack. +        kDebug(32500) << "we are already in a custom state. a \
new state, which is not NoOp is part of the macro we are doing. we need however to \
create a new command on the commandStack to parent a signal induced UndoTextCommand"; \
addNewCommand = true;  if (!title.isEmpty())
             commandTitle = title;
         else
             commandTitle = i18n("Text");
+        kDebug(32500) << "returning now. commandStack is not modified at this \
stage";  return;
     }
     if (newState == NoOp && !commandStack.isEmpty()) {
         //Calling updateState to NoOp when the commandStack isn't empty means that \
the current headCommand on the commandStack is finished. Further UndoTextCommands do \
not belong to it. So we pop it.  //If after poping the headCommand we still have some \
commands on the commandStack means we have not finished with the highest "macro". In \
that case we need to stay in the "Custom" state.  //On the contrary, an empty \
commandStack means we have finished with the "macro". In that case, we set the editor \
to NoOp state. A signal from the QTextDocument should also generate a new \
headCommand. +        kDebug(32500) << "we are in a macro and update the state to \
NoOp. this means that the command on top of the commandStack is finished. we should \
pop it"; +        kDebug(32500) << "commandStack count before: " << \
commandStack.count();  commandStack.pop();
+        kDebug(32500) << "commandStack count after: " << commandStack.count();
         if (commandStack.isEmpty()) {
+            kDebug(32500) << "we have no more commands on the commandStack. the \
macro is complete. next signal induced command will need to be parented to a new \
headCommand. Also the editor should go to NoOp";  addNewCommand = true;
             editorState = NoOp;
         }
+        kDebug(32500) << "returning now. commandStack count: " << \
commandStack.count();  return;
     }
     if (editorState != newState || commandTitle != title) {
         //We are not in "Custom" state but either are moving to a new state (from \
editing to format,...) or the command type is the same, but not the command itself \
(like format:bold, format:italic). The later case is caracterised by a different \
                command title.
         //When we change command, we need to pop the current commandStack's top and \
ask for a new headCommand to be created. +        kDebug(32500) << "we are not in a \
custom state but change the command"; +        kDebug(32500) << "commandStack count: \
" << commandStack.count();  if (!commandStack.isEmpty()) {
+            kDebug(32500) << "the commandStack is not empty. however the command on \
it is not a macro. so we pop it and ask to recreate a new one: " << title;  \
commandStack.pop();  addNewCommand = true;
         }
@@ -179,37 +203,58 @@ void \
KoTextEditor::Private::updateState(KoTextEditor::Private::State newState, Q  \
commandTitle = title;  else
         commandTitle = i18n("Text");
+    kDebug(32500) << "returning now. commandStack count: " << commandStack.count();
 }
 
 /// This method is used to push a complete KUndo2Command on the KoTextEditor. This \
command will be pushed on the application's stack if needed. The logic allows to push \
several commands which are then going to be nested, provided these children are \
pushed from within the redo method of their parent.  void \
KoTextEditor::addCommand(KUndo2Command *command)  {
+    kDebug(32500) << "we receive a command to add on the stack.";
+    kDebug(32500) << "commandStack count: " << d->commandStack.count();
+    kDebug(32500) << "inCustomCommand counter: " << d->inCustomCommand << " will \
increase"; +
     //We increase the inCustomCommand counter to inform the framework that we are \
having a further KUndo2Command and update the KoTextEditor's state to Custom.  \
//However, this update will request a new headCommand to be pushed on the \
commandStack. This is what we want for internal complex editions but not in this \
case. Indeed, it must be the KUndo2Command which will parent the UndoTextCommands. \
                Therefore we set the addNewCommand back to false.
     //If the commandStack is empty, we are the highest "macro" command and we should \
therefore push the KUndo2Command on the application's stack.  //On the contrary, if \
the commandStack is not empty, or the pushed command has a parent, it means that we \
are adding a nested KUndo2Command. In which case we just want to put it on the \
commandStack to parent UndoTextCommands. We need to call the redo method manually \
though.  ++d->inCustomCommand;
+    kDebug(32500) << "we will now go to custom state";
     d->updateState(KoTextEditor::Private::Custom, \
(!command->text().isEmpty())?command->text():i18n("Text")); +    kDebug(32500) << \
"but will set the addCommand to false. we don't want a new headCommand";  \
d->addNewCommand = false; +    kDebug(32500) << "commandStack count is: " << \
d->commandStack.count();  if (d->commandStack.isEmpty()) {
+        kDebug(32500) << "the commandStack is empty. this means we are the top most \
command";  d->commandStack.push(command);
+        kDebug(32500) << "command pushed on the commandStack. count: " << \
d->commandStack.count();  KUndo2QStack *stack = \
KoTextDocument(d->document).undoStack();  if (stack && !command->hasParent()) {
+            kDebug(32500) << "we have an application stack and the command is not a \
sub command of a non text command (which have been pushed outside kotext";  \
stack->push(command); +            kDebug(32500) << "so we pushed it on the \
application's' stack";  } else {
+            kDebug(32500) << "we either have no application's stack, or our command \
is actually the child of a non kotext command";  command->redo();
+            kDebug(32500) << "still called redo on it";
         }
     }
     else {
+        kDebug(32500) << "the commandStack is not empty, our command is actually \
nested in another kotext command. we don't push on the application stack but only on \
the commandStack";  d->commandStack.push(command);
+        kDebug(32500) << "commandStack count after push: " << \
d->commandStack.count();  command->redo();
+        kDebug(32500) << "called redo still";
     }
 
     //When we reach that point, the command has been executed. We first need to \
clean up all the automatically generated headCommand on our commandStack, which could \
potentially have been created during the editing. When we reach our pushed command, \
the commandStack is clean. We can then call a state update to NoOp and decrease the \
inCustomCommand counter. +    kDebug(32500) << "the command has been executed. we \
need to clean up the commandStack of the auto generated headCommands"; +    \
kDebug(32500) << "before cleaning. commandStack count: " << d->commandStack.count();  \
while(d->commandStack.top() != command) {  d->commandStack.pop();
     }
+    kDebug(32500) << "after cleaning. commandStack count: " << \
d->commandStack.count() << " will set NoOp";  \
d->updateState(KoTextEditor::Private::NoOp); +    kDebug(32500) << "after NoOp set. \
                inCustomCounter: " << d->inCustomCommand << " will decrease and \
                return";
     --d->inCustomCommand;
 }
 
@@ -232,10 +277,16 @@ void KoTextEditor::instantlyExecuteCommand(KUndo2Command \
*command)  /// ***
 KUndo2Command *KoTextEditor::beginEditBlock(QString title)
 {
+    kDebug(32500) << "beginEditBlock";
+    kDebug(32500) << "commandStack count: " << d->commandStack.count();
+    kDebug(32500) << "inCustomCommand counter: " << d->inCustomCommand;
     if (!d->inCustomCommand) {
         // We are not in a custom macro command. So we first need to update the \
KoTextEditor's state to Custom. Additionnaly, if the commandStack is empty, we need \
to create a master headCommand for our macro and push it on the stack. +        \
kDebug(32500) << "we are not in a custom command. will update state to custom";  \
d->updateState(KoTextEditor::Private::Custom, title); +        kDebug(32500) << \
"commandStack count: " << d->commandStack.count();  if (d->commandStack.isEmpty()) {
+            kDebug(32500) << "the commandStack is empty. we need a dummy headCommand \
both on the commandStack and on the application's stack";  KUndo2Command *command = \
new KUndo2Command(title);  d->commandStack.push(command);
             ++d->inCustomCommand;
@@ -246,29 +297,37 @@ KUndo2Command *KoTextEditor::beginEditBlock(QString title)
             } else {
                 command->redo();
             }
+            kDebug(32500) << "done adding the headCommand. commandStack count: " << \
d->commandStack.count() << " inCommand counter: " << d->inCustomCommand;  }
     }
     //QTextDocument sends the undoCommandAdded signal at the end of the QTextCursor \
edit block. Since we want our master headCommand to parent the signal induced \
UndoTextCommands, we should not call QTextCursor::beginEditBlock for the headCommand. \
if (!(d->dummyMacroAdded && d->inCustomCommand == 1)) { +        kDebug(32500) << "we \
did not add a dummy command, or we are further down nesting. call beginEditBlock on \
                the caret to nest the QTextDoc changes";
         //we don't call beginEditBlock for the first headCommand because we want the \
signals to be sent before we finished our command.  d->caret.beginEditBlock();
     }
+    kDebug(32500) << "will return top od commandStack";
     return (d->commandStack.isEmpty())?0:d->commandStack.top();
 }
 
 void KoTextEditor::endEditBlock()
 {
+    kDebug(32500) << "endEditBlock";
     //Only the self created master headCommand (see beginEditBlock) is left on the \
commandStack, we need to decrease the inCustomCommand counter that we increased on \
                creation.
     //If we are not yet at this master headCommand, we can call \
QTextCursor::endEditBlock  if (d->dummyMacroAdded && d->inCustomCommand == 1) {
+        kDebug(32500) << "only the created dummy headCommand from beginEditBlock is \
                left. we need to decrease further the nesting counter";
         //we don't call caret.endEditBlock because we did not begin a block for the \
                first headCommand
         --d->inCustomCommand;
         d->dummyMacroAdded = false;
     } else {
+        kDebug(32500) << "we are not at our top dummy headCommand. call \
caret.endEditBlock";  d->caret.endEditBlock();
     }
     if (!d->inCustomCommand) {
         //We have now finished completely the macro, set the editor state to NoOp \
then. +        kDebug(32500) << "we have finished completely the macro, set the state \
to NoOp now. commandStack count: " << d->commandStack.count();  \
d->updateState(KoTextEditor::Private::NoOp); +        kDebug(32500) << "done setting \
the state. editorState: " << d->editorState << " commandStack count: " << \
d->commandStack.count();  }
 }


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

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