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

List:       koffice-devel
Subject:    Patch for Inline Objects Deletion - Updated Patch
From:       Ganesh Paramasivam <ganesh () crystalfab ! com>
Date:       2010-02-19 5:15:36
Message-ID: 9ecf537e1002182103j354631e7y9710834c0d51801b () mail ! gmail ! com
[Download RAW message or body]

Pierre,

Please find the latest version of the patch which enables the deletion
of inline objects. This has most of the code that needs to be there.
There are still some more bugs. I will fix those issues and send an
undated final patch soon.

Some points

- Instead of trying to remove a KoShape from the document I have
instead used the setVisible() of KoShape to make it invisible/visible
during a deletetion/undo-deletion. The shape would eventually get
deleted in the destructor of the command. This seems to work fine (
i.e the user would see what he expects see when a inline object is
deleted ).

- There seems to be bug in the Qt 4.5.x where QTextDocument emits a
undoCommandAdded even-though it merges a command with a previous
command. So we would encounter situations where the app thinks that
there are multiple undo-commands on the QTextDocument's undo stack but
the stack instead has just one merged undo command. This bug has been
fixed in 4.6. The patch handles both versions of Qt ( with the bug and
without the bug ). To do this I had to have the same merge rules in
DeleteCommand ( in checkMerge ) as that of QTextDocument's internal
rules. More info is available in the comments within the mergeWith()
function.

- The code to paste a text containing inline objects is not yet there.
I still need to figure out how to clone a KoShape. We can already copy
a non-inline shape. Need to figure out how and where this is done and
follow the same approach in TextPasteCommand.cpp

Let me know what you think about this.

Thanks,
Ganesh

["inline-objects-deletion-v2.patch" (application/octet-stream)]

Index: plugins/textshape/tests/CMakeLists.txt
===================================================================
--- plugins/textshape/tests/CMakeLists.txt	(revision 1092498)
+++ plugins/textshape/tests/CMakeLists.txt	(working copy)
@@ -34,6 +34,7 @@
     ../commands/TextCommandBase.cpp
     ../commands/TextPasteCommand.cpp
     ../commands/TextCutCommand.cpp
+    ../commands/ChangeTrackedDeleteCommand.cpp
     ../commands/DeleteCommand.cpp
     ../commands/ShowChangesCommand.cpp
     ../commands/AcceptChangeCommand.cpp
Index: plugins/textshape/TextTool.cpp
===================================================================
--- plugins/textshape/TextTool.cpp	(revision 1092498)
+++ plugins/textshape/TextTool.cpp	(working copy)
@@ -37,6 +37,7 @@
 #include "commands/ChangeListLevelCommand.h"
 #include "commands/ListItemNumberingCommand.h"
 #include "commands/ShowChangesCommand.h"
+#include "commands/ChangeTrackedDeleteCommand.h"
 #include "commands/DeleteCommand.h"
 
 #include <KoCanvasBase.h>
@@ -756,9 +757,9 @@
 void TextTool::deleteSelection()
 {
     if (m_actionRecordChanges->isChecked())
+      m_textEditor->addCommand(new \
ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, this)); +    else
       m_textEditor->addCommand(new DeleteCommand(DeleteCommand::NextChar, this));
-    else
-      m_textEditor->deleteChar();
     editingPluginEvents();
 }
 
@@ -909,9 +910,9 @@
             if (!m_textEditor->hasSelection() && event->modifiers() & \
                Qt::ControlModifier) // delete prev word.
                 m_textEditor->movePosition(QTextCursor::PreviousWord, \
QTextCursor::KeepAnchor);  if (m_actionRecordChanges->isChecked())
+              m_textEditor->addCommand(new \
ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::PreviousChar, this)); +        \
                else
               m_textEditor->addCommand(new \
                DeleteCommand(DeleteCommand::PreviousChar, this));
-            else
-              m_textEditor->deletePreviousChar();
             editingPluginEvents();
         }
         ensureCursorVisible();
@@ -928,9 +929,9 @@
         // the event only gets through when the Del is not used in the app
         // if the app forwards Del then deleteSelection is used
         if (m_actionRecordChanges->isChecked())
+          m_textEditor->addCommand(new \
ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, this)); +        \
                else
           m_textEditor->addCommand(new DeleteCommand(DeleteCommand::NextChar, \
                this));
-        else
-          m_textEditor->deleteChar();
         editingPluginEvents();
     } else if ((event->key() == Qt::Key_Left) && (event->modifiers() | \
Qt::ShiftModifier) == Qt::ShiftModifier)  moveOperation = QTextCursor::Left;
@@ -1085,9 +1086,9 @@
         m_textEditor->setPosition(m_textEditor->position() + \
event->replacementStart());  for (int i = event->replacementLength(); i > 0; --i) {
             if (m_actionRecordChanges->isChecked())
+              m_textEditor->addCommand(new \
ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, this)); +            \
                else
               m_textEditor->addCommand(new DeleteCommand(DeleteCommand::NextChar, \
                this));
-            else
-              m_textEditor->deleteChar();
         }
     }
     QTextBlock block = m_textEditor->block();
Index: plugins/textshape/CMakeLists.txt
===================================================================
--- plugins/textshape/CMakeLists.txt	(revision 1092498)
+++ plugins/textshape/CMakeLists.txt	(working copy)
@@ -66,6 +66,7 @@
     commands/TextPasteCommand.cpp
     commands/TextCutCommand.cpp
     commands/ShowChangesCommand.cpp
+    commands/ChangeTrackedDeleteCommand.cpp
     commands/DeleteCommand.cpp
     commands/AcceptChangeCommand.cpp
     commands/RejectChangeCommand.cpp
Index: plugins/textshape/commands/TextCutCommand.cpp
===================================================================
--- plugins/textshape/commands/TextCutCommand.cpp	(revision 1092498)
+++ plugins/textshape/commands/TextCutCommand.cpp	(working copy)
@@ -21,6 +21,7 @@
 
 #include <KoTextEditor.h>
 #include <TextTool.h>
+#include "ChangeTrackedDeleteCommand.h"
 #include "DeleteCommand.h"
 #include <KAction>
 #include <klocale.h>
@@ -46,8 +47,8 @@
         m_first = false;
         m_tool->copy();
         if(m_tool->m_actionShowChanges->isChecked())
+            m_tool->m_textEditor->addCommand(new \
ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, m_tool)); +        \
                else
             m_tool->m_textEditor->addCommand(new \
                DeleteCommand(DeleteCommand::NextChar, m_tool));
-        else
-            m_tool->m_textEditor->deleteChar();
     }
 }
Index: plugins/textshape/commands/DeleteCommand.cpp
===================================================================
--- plugins/textshape/commands/DeleteCommand.cpp	(revision 1090853)
+++ plugins/textshape/commands/DeleteCommand.cpp	(working copy)
@@ -19,46 +19,41 @@
  * Boston, MA 02110-1301, USA.*/
 
 #include "DeleteCommand.h"
-#include <KoTextEditor.h>
-#include <TextTool.h>
 #include <klocale.h>
-#include <KoChangeTracker.h>
-#include <KoChangeTrackerElement.h>
+#include <TextTool.h>
+#include <QUndoCommand>
+#include <KoTextEditor.h>
 #include <KoTextDocument.h>
 #include <KoTextDocumentLayout.h>
 #include <KoInlineTextObjectManager.h>
-#include <KAction>
-#include <QTextDocumentFragment>
-#include <QUndoCommand>
+#include <KoTextAnchor.h>
+#include <KoCanvasBase.h>
+#include <KoShapeController.h>
 
-#include <KDebug>
-//#include <iostream>
-#include <QDebug>
-
-using namespace std;
 DeleteCommand::DeleteCommand(DeleteMode mode, TextTool *tool, QUndoCommand *parent) \
:  TextCommandBase (parent),
     m_tool(tool),
     m_first(true),
     m_undone(false),
-    m_mode(mode),
-    m_removedElements()
+    m_mode(mode)
 {
-      setText(i18n("Delete"));
+    setText(i18n("Delete"));
 }
 
 void DeleteCommand::undo()
 {
     TextCommandBase::undo();
     UndoRedoFinalizer finalizer(this);
+    insertDeletedShapes();
+    m_undone = true;
+}
 
-    QTextDocument *document = m_tool->m_textEditor->document();
-    KoTextDocument(document).changeTracker()->elementById(m_addedChangeElement)->setValid(false);
                
-    foreach (int changeId, m_removedElements) {
-      KoTextDocument(document).changeTracker()->elementById(changeId)->setValid(true);
 +void DeleteCommand::insertDeletedShapes()
+{
+    foreach (KoShape *shape, m_removedShapes) {
+        //Need to re-insert the shapes. Following the visibility approach for now.
+        shape->setVisible(true);
     }
-
-    m_undone = true;
 }
 
 void DeleteCommand::redo()
@@ -66,12 +61,13 @@
     m_undone = false;
     if (!m_first) {
         TextCommandBase::redo();
-        UndoRedoFinalizer finalizer(this);
-        QTextDocument *document = m_tool->m_textEditor->document();
-        KoTextDocument(document).changeTracker()->elementById(m_addedChangeElement)->setValid(true);
                
-        foreach (int changeId, m_removedElements) {
-          KoTextDocument(document).changeTracker()->elementById(changeId)->setValid(false);
 +
+        foreach (KoShape *shape, m_removedShapes) {
+            //Need to re-insert the shapes. Following the visibility approach for \
now. +            shape->setVisible(false);
         }
+
+        UndoRedoFinalizer finalizer(this);
     } else {
         m_first = false;
         m_tool->m_textEditor->beginEditBlock();
@@ -111,150 +107,90 @@
 
 void DeleteCommand::deleteSelection(QTextCursor &selection)
 {
-    QTextDocument *document = m_tool->m_textEditor->document();
-    KoTextDocumentLayout *layout = \
                qobject_cast<KoTextDocumentLayout*>(document->documentLayout());
-    Q_ASSERT(layout);
-    Q_ASSERT(layout->inlineTextObjectManager());
+    QTextCursor cursor(selection);
 
-    QTextCursor checker = QTextCursor(selection);
-    KoDeleteChangeMarker *deleteChangemarker = 0;
-    KoDeleteChangeMarker *testMarker;
+    //Store the position and length. Will be used in checkMerge
+    m_position = (cursor.anchor() < cursor.position()) ? \
cursor.anchor():cursor.position(); +    m_length = qAbs(cursor.anchor() - \
cursor.position()); +    qDebug() << m_position << " " << m_length;
 
-    bool backwards = (checker.anchor() > checker.position());
-    int selectionBegin = qMin(checker.anchor(), checker.position());
-    int selectionEnd = qMax(checker.anchor(), checker.position());
-    int changeId;
-
-    QTextDocumentFragment prefix;
-    QTextDocumentFragment sufix;
-    QTextDocument delText;
-    QTextCursor delTextCursor(&delText);
-
-    checker.setPosition(selectionBegin);
-
-    if (KoTextDocument(document).changeTracker()->displayChanges()) {
-        if (KoTextDocument(document).changeTracker()->containsInlineChanges(checker.charFormat())) \
                {
-            int changeId = \
                checker.charFormat().property(KoCharacterStyle::ChangeTrackerId).toInt();
                
-            if (KoTextDocument(document).changeTracker()->elementById(changeId)->getChangeType() \
                == KoGenChange::deleteChange) {
-                prefix =  \
                KoTextDocument(document).changeTracker()->elementById(changeId)->getDeleteData();
                
-                delTextCursor.insertFragment(prefix);
-                KoTextDocument(document).changeTracker()->elementById(changeId)->setValid(false);
                
-                    m_removedElements.push_back(changeId);
-            }
+    //Store the charFormat. If the selection has multiple charFormats leave \
m_charFormat as inValid.Will be used in checkMerge +    QTextCharFormat tempFormat;
+    for (int i = m_position; i < (m_position + m_length); i++) {
+        cursor.setPosition(i);
+        tempFormat = cursor.charFormat();
+        
+        if (!m_format.isValid()) {
+            m_format = tempFormat;
+        } else {
+            if (tempFormat != m_format ) {
+                //Encountered a second charFormat. Set m_formar to invalid - Default \
QTextCharFormat +                m_format = QTextCharFormat();
+                break;    
+            } 
         }
-    } else {
-        testMarker = \
dynamic_cast<KoDeleteChangeMarker*>(layout->inlineTextObjectManager()->inlineTextObject(checker));
                
-        if (testMarker) {
-            prefix = \
KoTextDocument(document).changeTracker()->elementById(testMarker->changeId())->getDeleteData();
                
-            delTextCursor.insertFragment(prefix);
-            KoTextDocument(document).changeTracker()->elementById(testMarker->changeId())->setValid(false);
                
-                m_removedElements.push_back(testMarker->changeId());
-        }
     }
 
-    checker.setPosition(selectionEnd);
-    if (!checker.atEnd()) {
-        checker.movePosition(QTextCursor::NextCharacter);
-        testMarker = \
dynamic_cast<KoDeleteChangeMarker*>(layout->inlineTextObjectManager()->inlineTextObject(checker));
                
-        if (testMarker) {
-            sufix =  \
KoTextDocument(document).changeTracker()->elementById(testMarker->changeId())->getDeleteData();
                
-            KoTextDocument(document).changeTracker()->elementById(testMarker->changeId())->setValid(false);
                
-                m_removedElements.push_back(testMarker->changeId());
-            }
-    }
-    checker.setPosition(selectionBegin);
+    //Delete any inline objects present within the selection
+    deleteInlineObjects(selection);
+    
+    //Now finally Delete the selected text
+    selection.deleteChar();
+}
 
-    while ((checker.position() < selectionEnd) && (!checker.atEnd())) {
-        QChar charAtPos = document->characterAt(checker.position());
-        checker.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
-        if (layout->inlineTextObjectManager()->inlineTextObject(checker) && \
                charAtPos.unicode() != 0x2029) {
-            testMarker = \
dynamic_cast<KoDeleteChangeMarker*>(layout->inlineTextObjectManager()->inlineTextObject(checker));
                
-            if (testMarker) {
-                QTextDocumentFragment inter = \
KoTextDocument(document).changeTracker()->elementById(testMarker->changeId())->getDeleteData();
                
-                delTextCursor.insertFragment(inter);
+void DeleteCommand::deleteInlineObjects(QTextCursor &selection)
+{
+    QTextCursor cursor(selection);
+    QTextDocument *document = m_tool->m_textEditor->document();
+    KoTextDocumentLayout *layout = \
qobject_cast<KoTextDocumentLayout*>(document->documentLayout()); +    \
Q_ASSERT(layout);  
-                if (KoTextDocument(document).changeTracker()->displayChanges())
-                            checker.movePosition(QTextCursor::NextCharacter, \
QTextCursor::KeepAnchor, inter.toPlainText().length()); +    \
KoInlineTextObjectManager *manager = layout->inlineTextObjectManager(); +    \
KoInlineObject *object;  
-                KoTextDocument(document).changeTracker()->elementById(testMarker->changeId())->setValid(false);
                
-                    m_removedElements.push_back(testMarker->changeId());
-           }
+    if (cursor.hasSelection()) {
+        QString selected = cursor.selectedText();
+        cursor.setPosition(cursor.selectionStart() + 1);
+        int position = cursor.position();
+        const QChar *data = selected.constData();
+        for (int i = 0; i < selected.length(); i++) {
+            if (data->unicode() == QChar::ObjectReplacementCharacter) {
+                cursor.setPosition(position);
+                object = manager->inlineTextObject(cursor);
+                deleteTextAnchor(object);
+                m_invalidInlineObjects.append(object);
+            } else {
+                position++;
+            }
+            data++;
         }
-        else {
-            delTextCursor.insertFragment(checker.selection());
-        }
-        checker.setPosition(checker.position());
-    }
+    } else {
+        if (!(m_mode == PreviousChar))
+            cursor.movePosition(QTextCursor::Right);
 
-    delTextCursor.insertFragment(sufix);
-
-    if (!sufix.isEmpty()) {
-        if (KoTextDocument(document).changeTracker()->displayChanges()) {
-            selection.setPosition(selectionBegin);
-            selection.setPosition(selectionEnd + sufix.toPlainText().length() + 1, \
                QTextCursor::KeepAnchor);
-            selectionEnd += (sufix.toPlainText().length() + 1);
-        } else {
-            selection.setPosition(selectionBegin);
-            selection.setPosition(selectionEnd + 1, QTextCursor::KeepAnchor);
-            selectionEnd += 1;
-        }
+        object = manager->inlineTextObject(cursor);
+        deleteTextAnchor(object);
+        m_invalidInlineObjects.append(object);
     }
+}
 
-    if (!prefix.isEmpty()) {
-        if (KoTextDocument(document).changeTracker()->displayChanges()) {
-            selection.setPosition(selectionBegin - prefix.toPlainText().length() - \
                1);
-            selection.setPosition(selectionEnd, QTextCursor::KeepAnchor);
-            selectionBegin -= (prefix.toPlainText().length() + 1);
-        } else {
-            selection.setPosition(selectionBegin - 1);
-            selection.setPosition(selectionEnd, QTextCursor::KeepAnchor);
-            selectionBegin -= 1;
+void DeleteCommand::deleteTextAnchor(KoInlineObject *object)
+{
+    if (object) {
+        KoTextAnchor *anchor = dynamic_cast<KoTextAnchor *>(object);
+        if (anchor) {
+                KoShape *shape = anchor->shape();
+                // Need to remove the shape. For now just make the shape invisible 
+                shape->setVisible(false);
+                m_removedShapes.append(shape);
         }
     }
-
-    QTextDocumentFragment deletedFragment = selection.selection();
-    changeId = KoTextDocument(document).changeTracker()->getDeleteChangeId(i18n("Delete"), \
deletedFragment, selection.charFormat().property( KoCharacterStyle::ChangeTrackerId \
                ).toInt());
-    KoChangeTrackerElement *element = \
                KoTextDocument(document).changeTracker()->elementById(changeId);
-    deleteChangemarker = new \
                KoDeleteChangeMarker(KoTextDocument(document).changeTracker());
-    deleteChangemarker->setChangeId(changeId);
-    element->setDeleteChangeMarker(deleteChangemarker);
-    layout->inlineTextObjectManager()->insertInlineObject(selection, \
                deleteChangemarker);
-
-    m_addedChangeElement = changeId;
-
-    //Clear the changeTrackerId of the marker. Should be done in \
                KoInlineTextObjectManager ideally.
-    selection.setPosition(selectionBegin);
-    selection.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
-    QTextCharFormat markerFormat = selection.charFormat();
-    markerFormat.setProperty(KoCharacterStyle::ChangeTrackerId,0);
-    selection.mergeCharFormat(markerFormat);
-    selection.setPosition(selectionBegin + 1);
-
-    //set the change-tracker-id to the char-format of deleted text
-    QTextCharFormat f;
-    f.setProperty(KoCharacterStyle::ChangeTrackerId, \
                deleteChangemarker->changeId());
-    delTextCursor.setPosition(0);
-    delTextCursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
-    delTextCursor.mergeCharFormat(f);
-    
-    //Insert the deleted data again after the marker with the charformat set to the \
                change-id
-    QTextDocumentFragment deletedDataFragment(&delText);
-    KoTextDocument(document).changeTracker()->elementById(deleteChangemarker->changeId())->setDeleteData(deletedDataFragment);
                
-
-    if (KoTextDocument(document).changeTracker()->displayChanges()) {
-        selection.insertFragment(deletedDataFragment);
-
-        if (backwards)
-            selection.movePosition(QTextCursor::PreviousCharacter, \
                QTextCursor::MoveAnchor, deletedDataFragment.toPlainText().length() + \
                1);
-    } else {
-        if (backwards)
-            selection.movePosition(QTextCursor::PreviousCharacter, \
                QTextCursor::MoveAnchor,1);
-    }
 }
 
 int DeleteCommand::id() const
 {
-    return 98765;
+    // Should be an enum declared somewhere. TextCommandBase.h ???
+    return 56789;
 }
 
 bool DeleteCommand::mergeWith( const QUndoCommand *command)
@@ -285,40 +221,59 @@
     if (command->id() != id())
         return false;
 
+    if (!checkMerge(command))
+        return false;
+
     DeleteCommand *other = const_cast<DeleteCommand *>(static_cast<const \
                DeleteCommand *>(command));
-    if (other->m_removedElements.contains(m_addedChangeElement)) {
-        removeChangeElement(m_addedChangeElement);
-        other->m_removedElements.removeAll(m_addedChangeElement);
-        m_addedChangeElement = other->m_addedChangeElement;
+    
+    m_removedShapes += other->m_removedShapes;
+    other->m_removedShapes.clear();
 
-        m_removedElements += other->m_removedElements;
-        other->m_removedElements.clear();
+    m_invalidInlineObjects += other->m_invalidInlineObjects;
+    other->m_invalidInlineObjects.clear();
 
-        for(int i=0; i < command->childCount(); i++)
-            new UndoTextCommand(m_tool->m_textEditor->document(), this);
+    //Normally one would expect the code below to be present. But in this case we \
reach here only if checkMerge return true. +    //And checkMerge checks the same \
conditions that QTextDocument checks before it merges commands in its internal undo \
stack. +    //So for 4.6.0 and above the number of children would be 0. So the loop \
even if present would be useless +    //And for Qt 4.5.x because of a bug in Qt there \
will be a child present. But it should not be processed. So no loop needed. +    \
//for(int i=0; i < command->childCount(); i++) +    //    new \
UndoTextCommand(m_tool->m_textEditor->document(), this);  
+    return true;
+}
+
+bool DeleteCommand::checkMerge( const QUndoCommand *command )
+{
+    DeleteCommand *other = const_cast<DeleteCommand *>(static_cast<const \
DeleteCommand *>(command)); +
+    if (m_position == other->m_position
+        && m_format == other->m_format) {
+        m_length += other->m_length;
         return true;
     }
+
+    if ( (other->m_position + other->m_length == m_position)
+        && (m_format == other->m_format)) {
+        m_position = other->m_position;
+        m_length += other->m_length;
+        return true;
+    }
+
     return false;
 }
 
 DeleteCommand::~DeleteCommand()
 {
-    if (m_undone) {
-        removeChangeElement(m_addedChangeElement);
-    } else {
-        foreach (int changeId, m_removedElements) {
-           removeChangeElement(changeId);
+    if (!m_undone) {
+        foreach (KoInlineObject *object, m_invalidInlineObjects) {
+            QTextDocument *document = m_tool->m_textEditor->document();
+            KoTextDocumentLayout *layout = \
qobject_cast<KoTextDocumentLayout*>(document->documentLayout()); +            \
KoInlineTextObjectManager *manager = layout->inlineTextObjectManager(); +            \
manager->removeInlineObject(object);  }
+
+        foreach (KoShape *shape, m_removedShapes)
+            delete shape;
     }
 }
 
-void DeleteCommand::removeChangeElement(int changeId)
-{
-    QTextDocument *document = m_tool->m_textEditor->document();
-    KoTextDocumentLayout *layout = \
                qobject_cast<KoTextDocumentLayout*>(document->documentLayout());
-    KoChangeTrackerElement *element = \
                KoTextDocument(document).changeTracker()->elementById(changeId);
-    KoDeleteChangeMarker *marker = element->getDeleteChangeMarker();
-    layout->inlineTextObjectManager()->removeInlineObject(marker);
-    KoTextDocument(document).changeTracker()->removeById(changeId);
-}
Index: plugins/textshape/commands/ChangeTrackedDeleteCommand.cpp
===================================================================
--- plugins/textshape/commands/ChangeTrackedDeleteCommand.cpp	(revision 1090816)
+++ plugins/textshape/commands/ChangeTrackedDeleteCommand.cpp	(working copy)
@@ -18,7 +18,7 @@
  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301, USA.*/
 
-#include "DeleteCommand.h"
+#include "ChangeTrackedDeleteCommand.h"
 #include <KoTextEditor.h>
 #include <TextTool.h>
 #include <klocale.h>
@@ -36,7 +36,7 @@
 #include <QDebug>
 
 using namespace std;
-DeleteCommand::DeleteCommand(DeleteMode mode, TextTool *tool, QUndoCommand *parent) \
: +ChangeTrackedDeleteCommand::ChangeTrackedDeleteCommand(DeleteMode mode, TextTool \
*tool, QUndoCommand *parent) :  TextCommandBase (parent),
     m_tool(tool),
     m_first(true),
@@ -47,7 +47,7 @@
       setText(i18n("Delete"));
 }
 
-void DeleteCommand::undo()
+void ChangeTrackedDeleteCommand::undo()
 {
     TextCommandBase::undo();
     UndoRedoFinalizer finalizer(this);
@@ -61,7 +61,7 @@
     m_undone = true;
 }
 
-void DeleteCommand::redo()
+void ChangeTrackedDeleteCommand::redo()
 {
     m_undone = false;
     if (!m_first) {
@@ -83,7 +83,7 @@
     }
 }
 
-void DeleteCommand::deleteChar()
+void ChangeTrackedDeleteCommand::deleteChar()
 {
     QTextCursor *caret = m_tool->m_textEditor->cursor();
 
@@ -96,7 +96,7 @@
     deleteSelection(*caret);
 }
 
-void DeleteCommand::deletePreviousChar()
+void ChangeTrackedDeleteCommand::deletePreviousChar()
 {
     QTextCursor *caret = m_tool->m_textEditor->cursor();
 
@@ -109,7 +109,7 @@
     deleteSelection(*caret);
 }
 
-void DeleteCommand::deleteSelection(QTextCursor &selection)
+void ChangeTrackedDeleteCommand::deleteSelection(QTextCursor &selection)
 {
     QTextDocument *document = m_tool->m_textEditor->document();
     KoTextDocumentLayout *layout = \
qobject_cast<KoTextDocumentLayout*>(document->documentLayout()); @@ -252,12 +252,12 \
@@  }
 }
 
-int DeleteCommand::id() const
+int ChangeTrackedDeleteCommand::id() const
 {
     return 98765;
 }
 
-bool DeleteCommand::mergeWith( const QUndoCommand *command)
+bool ChangeTrackedDeleteCommand::mergeWith( const QUndoCommand *command)
 {
     class UndoTextCommand : public QUndoCommand
     {
@@ -285,7 +285,7 @@
     if (command->id() != id())
         return false;
 
-    DeleteCommand *other = const_cast<DeleteCommand *>(static_cast<const \
DeleteCommand *>(command)); +    ChangeTrackedDeleteCommand *other = \
const_cast<ChangeTrackedDeleteCommand *>(static_cast<const ChangeTrackedDeleteCommand \
*>(command));  if (other->m_removedElements.contains(m_addedChangeElement)) {
         removeChangeElement(m_addedChangeElement);
         other->m_removedElements.removeAll(m_addedChangeElement);
@@ -302,7 +302,7 @@
     return false;
 }
 
-DeleteCommand::~DeleteCommand()
+ChangeTrackedDeleteCommand::~ChangeTrackedDeleteCommand()
 {
     if (m_undone) {
         removeChangeElement(m_addedChangeElement);
@@ -313,7 +313,7 @@
     }
 }
 
-void DeleteCommand::removeChangeElement(int changeId)
+void ChangeTrackedDeleteCommand::removeChangeElement(int changeId)
 {
     QTextDocument *document = m_tool->m_textEditor->document();
     KoTextDocumentLayout *layout = \
qobject_cast<KoTextDocumentLayout*>(document->documentLayout());

Property changes on: plugins/textshape/commands/ChangeTrackedDeleteCommand.cpp
___________________________________________________________________
Added: svn:mergeinfo

Index: plugins/textshape/commands/DeleteCommand.h
===================================================================
--- plugins/textshape/commands/DeleteCommand.h	(revision 1090853)
+++ plugins/textshape/commands/DeleteCommand.h	(working copy)
@@ -22,11 +22,13 @@
 
 #include <QUndoStack>
 #include "TextCommandBase.h"
+#include <QTextCharFormat>
 #include <QList>
 
 class TextTool;
 class QTextCursor;
-class KoChangeTrackerElement;
+class KoInlineObject;
+class KoShape;
 
 class DeleteCommand : public TextCommandBase
 {
@@ -43,20 +45,26 @@
     virtual void redo();
 
     virtual int id() const;
-    virtual bool mergeWith ( const QUndoCommand *command);
+    virtual bool mergeWith(const QUndoCommand *command);
 
 private:
     TextTool *m_tool;
+    QList<KoShape *> m_removedShapes;
+    QList<KoInlineObject *> m_invalidInlineObjects;
     bool m_first;
     bool m_undone;
     DeleteMode m_mode;
-    QList<int> m_removedElements;
-    int m_addedChangeElement;
+    int m_position;
+    int m_length;
+    QTextCharFormat m_format;
 
     virtual void deleteChar();
     virtual void deletePreviousChar();
     virtual void deleteSelection(QTextCursor &selection);
-    virtual void removeChangeElement(int changeId);
+    virtual void deleteInlineObjects(QTextCursor &selection);
+    virtual void deleteTextAnchor(KoInlineObject *object);
+    virtual void insertDeletedShapes();
+    virtual bool checkMerge(const QUndoCommand *command);
 };
 
 #endif // DELTECOMMAND_H
Index: plugins/textshape/commands/ChangeTrackedDeleteCommand.h
===================================================================
--- plugins/textshape/commands/ChangeTrackedDeleteCommand.h	(revision 1090816)
+++ plugins/textshape/commands/ChangeTrackedDeleteCommand.h	(working copy)
@@ -17,8 +17,8 @@
  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301, USA.*/
 
-#ifndef DELETECOMMAND_H
-#define DELETECOMMAND_H
+#ifndef CHANGETRACKEDDELETECOMMAND_H
+#define CHANGETRACKEDDELETECOMMAND_H
 
 #include <QUndoStack>
 #include "TextCommandBase.h"
@@ -28,7 +28,7 @@
 class QTextCursor;
 class KoChangeTrackerElement;
 
-class DeleteCommand : public TextCommandBase
+class ChangeTrackedDeleteCommand : public TextCommandBase
 {
 public:
     enum DeleteMode {
@@ -36,8 +36,8 @@
         NextChar
     };
 
-    DeleteCommand(DeleteMode mode, TextTool *tool, QUndoCommand* parent = 0);
-    ~DeleteCommand();
+    ChangeTrackedDeleteCommand(DeleteMode mode, TextTool *tool, QUndoCommand* parent \
= 0); +    ~ChangeTrackedDeleteCommand();
 
     virtual void undo();
     virtual void redo();
@@ -59,4 +59,4 @@
     virtual void removeChangeElement(int changeId);
 };
 
-#endif // DELTECOMMAND_H
+#endif // CHANGETRACKEDDELTECOMMAND_H

Property changes on: plugins/textshape/commands/ChangeTrackedDeleteCommand.h
___________________________________________________________________
Added: svn:mergeinfo

Index: plugins/textshape/commands/TextPasteCommand.cpp
===================================================================
--- plugins/textshape/commands/TextPasteCommand.cpp	(revision 1092498)
+++ plugins/textshape/commands/TextPasteCommand.cpp	(working copy)
@@ -30,6 +30,7 @@
 
 #include <QApplication>
 #include <QMimeData>
+#include "ChangeTrackedDeleteCommand.h"
 #include "DeleteCommand.h"
 #include <KAction>
 
@@ -65,9 +66,9 @@
         m_first = false;
         if (editor->hasSelection()) { //TODO
             if (m_tool->m_actionShowChanges->isChecked())
+                editor->addCommand(new \
ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, m_tool)); +          \
                else
                 editor->addCommand(new DeleteCommand(DeleteCommand::NextChar, \
                m_tool));
-            else
-                editor->deleteChar();
         }
 
         // check for mime type
Index: plugins/textshape/TextTool.h
===================================================================
--- plugins/textshape/TextTool.h	(revision 1092498)
+++ plugins/textshape/TextTool.h	(working copy)
@@ -272,6 +272,7 @@
     friend class TextPasteCommand;
     friend class TextCutCommand;
     friend class ShowChangesCommand;
+    friend class ChangeTrackedDeleteCommand;
     friend class DeleteCommand;
     TextShape *m_textShape;
     KoTextShapeData *m_textShapeData;



_______________________________________________
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