[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/work/koffice-change-tracking/libs/kotext
From: Ganesh Paramasivam <ganesh () crystalfab ! com>
Date: 2010-11-05 10:48:11
Message-ID: 20101105104811.246A3AC89B () svn ! kde ! org
[Download RAW message or body]
SVN commit 1193263 by ganeshp:
Insert delete fragments before saving the document and revert the insertion after the \
save
M +2 -2 KoTextEditor.cpp
M +1 -1 KoTextEditor.h
M +62 -0 KoTextShapeData.cpp
--- branches/work/koffice-change-tracking/libs/kotext/KoTextEditor.cpp \
#1193262:1193263 @@ -314,13 +314,13 @@
return &(d->caret);
}
-void KoTextEditor::addCommand(QUndoCommand *command)
+void KoTextEditor::addCommand(QUndoCommand *command, bool addCommandToStack)
{
d->updateState(KoTextEditor::Private::Custom, \
(!command->text().isEmpty())?command->text():i18n("Text")); //kDebug() << "will push \
the custom command: " << command->text(); d->headCommand = command;
QUndoStack *stack = KoTextDocument(d->document).undoStack();
- if (stack)
+ if (stack && addCommandToStack)
stack->push(command);
else
command->redo();
--- branches/work/koffice-change-tracking/libs/kotext/KoTextEditor.h #1193262:1193263
@@ -78,7 +78,7 @@
///This should be used only as read-only cursor or within a QUndoCommand \
sub-class which will be added to the textEditor with addCommand. For examples of \
proper implementation of such undoCommands, see the TextShape commands. QTextCursor* \
cursor();
- void addCommand(QUndoCommand *command);
+ void addCommand(QUndoCommand *command, bool addCommandToStack = true);
void registerTrackedChange(QTextCursor &selection, KoGenChange::Type changeType, \
QString title, QTextFormat &format, QTextFormat &prevFormat, bool applyToWholeBlock = \
false);
--- branches/work/koffice-change-tracking/libs/kotext/KoTextShapeData.cpp \
#1193262:1193263 @@ -48,6 +48,16 @@
#include "opendocument/KoTextLoader.h"
#include "opendocument/KoTextWriter.h"
+#include <KoChangeTracker.h>
+#include <KoChangeTrackerElement.h>
+#include <KoTextAnchor.h>
+#include <KoInlineTextObjectManager.h>
+#include <KoCanvasBase.h>
+#include <KoShapeController.h>
+#include <KoShapeContainer.h>
+#include <KUndoStack>
+#include <QUndoCommand>
+
class KoTextShapeDataPrivate : public KoTextShapeDataBasePrivate
{
public:
@@ -219,11 +229,63 @@
return true;
}
+class InsertDeleteChangesCommand:public QUndoCommand
+{
+ public:
+ InsertDeleteChangesCommand(QTextDocument *document, QUndoCommand *parent=0);
+ void redo();
+
+ private:
+ QTextDocument *m_document;
+ void insertDeleteChanges();
+};
+
+InsertDeleteChangesCommand::InsertDeleteChangesCommand(QTextDocument \
*document,QUndoCommand *parent):QUndoCommand("Insert Delete \
Changes",parent),m_document(document) +{
+}
+
+void InsertDeleteChangesCommand::redo()
+{
+ insertDeleteChanges();
+}
+
+static bool isPositionLessThan(KoChangeTrackerElement *element1, \
KoChangeTrackerElement *element2) +{
+ return element1->getDeleteChangeMarker()->position() < \
element2->getDeleteChangeMarker()->position(); +}
+
+void InsertDeleteChangesCommand::insertDeleteChanges()
+{
+ int numAddedChars = 0;
+ QVector<KoChangeTrackerElement *> elementVector;
+ KoTextDocument(m_document).changeTracker()->getDeletedChanges(elementVector);
+ qSort(elementVector.begin(), elementVector.end(), isPositionLessThan);
+
+ foreach (KoChangeTrackerElement *element, elementVector) {
+ if (element->isValid()) {
+ QTextCursor caret(element->getDeleteChangeMarker()->document());
+ caret.setPosition(element->getDeleteChangeMarker()->position() + \
numAddedChars + 1); + QTextCharFormat f = caret.charFormat();
+ f.setProperty(KoCharacterStyle::ChangeTrackerId, \
element->getDeleteChangeMarker()->changeId()); + \
f.clearProperty(KoCharacterStyle::InlineInstanceId); + \
caret.setCharFormat(f); + KoChangeTracker::insertDeleteFragment(caret, \
element->getDeleteChangeMarker()); + numAddedChars += \
KoChangeTracker::fragmentLength(element->getDeleteData()); + }
+ }
+}
+
void KoTextShapeData::saveOdf(KoShapeSavingContext &context, KoDocumentRdfBase \
*rdfData, int from, int to) const {
Q_D(const KoTextShapeData);
+ InsertDeleteChangesCommand *insertCommand = new \
InsertDeleteChangesCommand(document()); + \
KoTextDocument(document()).textEditor()->addCommand(insertCommand, false); +
KoTextWriter writer(context, rdfData);
writer.write(d->document, from, to);
+
+ insertCommand->undo();
+ delete insertCommand;
}
void KoTextShapeData::relayoutFor(KoTextPage &textPage)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic