[Okular-devel] An Undo / Redo framework for annotations

Jon Mease jon.mease at gmail.com
Wed Oct 17 02:36:58 UTC 2012


So I started working on the Undo/Redo framework and the first hurdle
to work out is memory management.  Right now when an annotation is
removed from a page it is automatically deleted (see
Page::removeAnnotation).  However if we want to be able to undo this
removal we obviously don't want to delete the annotation object right
away.

The solution that jumped out at me was to have the page class use
QSharedPointers to reference annotations.  This way the page class
just needs to make sure its shared pointer goes out of scope when an
annotation is removed and the QSharedPointer class is responsible for
actually deleting the annotation when it's no longer being referenced
my any shared pointer.  This way we can soon have a bunch of
QUndoCommands on the undo stack that reference the removed annotation
and the annotation won't be deleted until the annotation is both
removed from a page and all of these undo commands are deleted from
the undo stack.

I've submitted a review request that contains only this memory
management change (https://git.reviewboard.kde.org/r/106923/) but I
wanted to explain a little more of my reasoning here.

Let me know what you think!
-Jon

On Sun, Oct 14, 2012 at 12:16 PM, Fabio D'Urso <fabiodurso at hotmail.it> wrote:
> On Saturday, October 13, 2012 11:43:38 PM Jon Mease wrote:
>> Hello all,
> Hi,
>
>> My next goal for enhancing Okular's annotation framework is to
>> add undo / redo support when creating/editing/deleting annotations.
>> Looking back at the list archives it seems like this is something that
>> has been asked for and mentioned in bug reports for several years now.
>> Before starting in I wanted to ask whether anyone has already started
>> work on this.
>
> It's still unexplored land :D
> No one has worked on this yet
>
>> I have some experience with Qt's Undo/Redo framework and this is what
>> I'm planning on using.  At the highest level my thought is to write
>> QUndoCommands for each of the following annotation actions
>>     1) Creating a new annotation with a particular set of properties
>>     2) Deleting an existing annotation
>>     3) Editing an annotation's properties (color, opacity, etc)
>>     4) Moving an annotation's position
>>     5) Editing text in a text annotation (this would rely on the
>> undoAvailable signal of QTextEdit)
>
> Sounds mostly correct to me. You can join #okular on freenode to discuss your
> ideas live with other developers.
>
>> Does anyone have any thoughts on the subject?  Does an existing
>> undo/redo branch or patch exists somewhere?  If not, I'll probably get
>> started on one this coming week.
>
> Great! Keep us informed ;)
>
> Thank you,
> Fabio


More information about the Okular-devel mailing list