Changeset View
Changeset View
Standalone View
Standalone View
plugins/flake/textshape/kotext/KoTextEditor_undo.cpp
Show All 29 Lines | |||||
30 | #include <klocalizedstring.h> | 30 | #include <klocalizedstring.h> | ||
31 | 31 | | |||
32 | #include <QTextDocument> | 32 | #include <QTextDocument> | ||
33 | #include <QWeakPointer> | 33 | #include <QWeakPointer> | ||
34 | 34 | | |||
35 | #include "TextDebug.h" | 35 | #include "TextDebug.h" | ||
36 | 36 | | |||
37 | /** Calligra's undo/redo framework. | 37 | /** Calligra's undo/redo framework. | ||
38 | The @class KoTextEditor undo/redo framework sits between the @class QTextDocument and the apllication's undo/redo stack. | 38 | The @class KoTextEditor undo/redo framework sits between the @class QTextDocument and the application's undo/redo stack. | ||
39 | 39 | | |||
40 | When the @class QTextDocument is changed by an editing action, it internally creates an undo/redo command. When doing so a signal (undoCommandAdded()) is emitted by the @class QTextDocument in order for applications to update their undo/redo stack accordingly. | 40 | When the @class QTextDocument is changed by an editing action, it internally creates an undo/redo command. When doing so a signal (undoCommandAdded()) is emitted by the @class QTextDocument in order for applications to update their undo/redo stack accordingly. | ||
41 | Each @class QTextDocument used in Calligra is handled by a specific @class KoTextEditor. It is responsible for on the one hand edit the @class QTextDocument, and on the other hand to listen for the QTextDocument's signal. | 41 | Each @class QTextDocument used in Calligra is handled by a specific @class KoTextEditor. It is responsible for on the one hand edit the @class QTextDocument, and on the other hand to listen for the QTextDocument's signal. | ||
42 | 42 | | |||
43 | Calligra uses a @class KUndo2Stack as its application undo/redo stack. This stack is populated by @class KUndo2Command or sub-classes of it. | 43 | Calligra uses a @class KUndo2Stack as its application undo/redo stack. This stack is populated by @class KUndo2Command or sub-classes of it. | ||
44 | 44 | | |||
45 | In order to limit the number of command sub-classes, KoTextEditor provides a framework which uses a generic command. | 45 | In order to limit the number of command sub-classes, KoTextEditor provides a framework which uses a generic command. | ||
46 | 46 | | |||
47 | The framework is based on a sort of state machine. The KoTextEditor can be in several different states (see @enum KoTextEditor::Private::State). | 47 | The framework is based on a sort of state machine. The KoTextEditor can be in several different states (see @enum KoTextEditor::Private::State). | ||
48 | These are: | 48 | These are: | ||
49 | NoOp: this states indicates that the KoTextEditor is not editing the QTextDocument. | 49 | NoOp: this states indicates that the KoTextEditor is not editing the QTextDocument. | ||
50 | KeyPress: this state indicates that the user is typing text. All text typed in succession should correspond to one undo command. To be used when entering text outside of an insertTextCommand. | 50 | KeyPress: this state indicates that the user is typing text. All text typed in succession should correspond to one undo command. To be used when entering text outside of an insertTextCommand. | ||
51 | Delete: this state indicates that the user is deleting characters. All deletions done in succession should correspond to one undo command. To be used for deleting outside a deleteCommand. Currently not in use, our deltion is done through a command because of inline objects. | 51 | Delete: this state indicates that the user is deleting characters. All deletions done in succession should correspond to one undo command. To be used for deleting outside a deleteCommand. Currently not in use, our deletion is done through a command because of inline objects. | ||
52 | Format: this state indicates that we are formatting text. To be used when formatting outside of a command. | 52 | Format: this state indicates that we are formatting text. To be used when formatting outside of a command. | ||
53 | Custom: this state indicates that the QTextDocument is changed through a KUndo2Command. | 53 | Custom: this state indicates that the QTextDocument is changed through a KUndo2Command. | ||
54 | 54 | | |||
55 | KoTextEditor reacts differently when receiving the QTextDocument's signal, depending on its state. | 55 | KoTextEditor reacts differently when receiving the QTextDocument's signal, depending on its state. | ||
56 | 56 | | |||
57 | In addition the framework allows to encapsulate modifications in a on-the-fly created custom command (\sa beginEditBlock() endEditBlock()). | 57 | In addition the framework allows to encapsulate modifications in a on-the-fly created custom command (\sa beginEditBlock() endEditBlock()). | ||
58 | Furthermore the framework allows to push complete KUndo2Commands. | 58 | Furthermore the framework allows to push complete KUndo2Commands. | ||
59 | 59 | | |||
▲ Show 20 Lines • Show All 270 Lines • Show Last 20 Lines |