From e182f47cba339bb267340d676a3f91ef20771189 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sun, 13 Apr 2008 13:45:32 +0000 Subject: [PATCH] Add the possibility to store in an Annotation a "native id" of the annotation itself. What it represents is totally in the hands of the various generators. Add a function hook to cleanup the annotation data (the "native id", basically). svn path=/trunk/KDE/kdegraphics/okular/; revision=796378 --- core/annotations.cpp | 23 ++++++++++++++++++++++- core/annotations.h | 40 ++++++++++++++++++++++++++++++++++++++++ core/annotations_p.h | 4 ++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/core/annotations.cpp b/core/annotations.cpp index cbb36db88..6a06752a6 100644 --- a/core/annotations.cpp +++ b/core/annotations.cpp @@ -428,7 +428,7 @@ Annotation::RevisionType Annotation::Revision::type() const AnnotationPrivate::AnnotationPrivate() - : m_page( 0 ), m_flags( 0 ) + : m_page( 0 ), m_flags( 0 ), m_disposeFunc( 0 ) { } @@ -554,6 +554,9 @@ Annotation::Annotation( AnnotationPrivate &dd, const QDomNode & annNode ) Annotation::~Annotation() { + if ( d_ptr->m_disposeFunc ) + d_ptr->m_disposeFunc( this ); + delete d_ptr; } @@ -699,6 +702,24 @@ const QLinkedList< Annotation::Revision > & Annotation::revisions() const return d->m_revisions; } +void Annotation::setNativeId( const QVariant &id ) +{ + Q_D( Annotation ); + d->m_nativeId = id; +} + +QVariant Annotation::nativeId() const +{ + Q_D( const Annotation ); + return d->m_nativeId; +} + +void Annotation::setDisposeDataFunction( DisposeDataFunction func ) +{ + Q_D( Annotation ); + d->m_disposeFunc = func; +} + void Annotation::store( QDomNode & annNode, QDomDocument & document ) const { Q_D( const Annotation ); diff --git a/core/annotations.h b/core/annotations.h index 3ef54ed67..9cb562636 100644 --- a/core/annotations.h +++ b/core/annotations.h @@ -166,6 +166,16 @@ class OKULAR_EXPORT Annotation Completed = 64 ///< Has been completed }; + /** + * A function to be called when the annotation is destroyed. + * + * @warning the function must *not* call any virtual function, + * nor subcast. + * + * @since 0.7 (KDE 4.1) + */ + typedef void ( * DisposeDataFunction )( const Okular::Annotation * ); + /** * Destroys the annotation. */ @@ -567,6 +577,36 @@ class OKULAR_EXPORT Annotation */ const QLinkedList< Revision > & revisions() const; + /** + * Sets the "native" @p id of the annotation. + * + * This is for use of the Generator, that can optionally store an + * handle (a pointer, an identifier, etc) of the "native" annotation + * object, if any. + * + * @note Okular makes no use of this + * + * @since 0.7 (KDE 4.1) + */ + void setNativeId( const QVariant &id ); + + /** + * Returns the "native" id of the annotation. + * + * @since 0.7 (KDE 4.1) + */ + QVariant nativeId() const; + + /** + * Sets a function to be called when the annotation is destroyed. + * + * @warning the function must *not* call any virtual function, + * nor subcast. + * + * @since 0.7 (KDE 4.1) + */ + void setDisposeDataFunction( DisposeDataFunction func ); + /** * Returns the sub type of the annotation. */ diff --git a/core/annotations_p.h b/core/annotations_p.h index 2323c16b9..d37a59cc8 100644 --- a/core/annotations_p.h +++ b/core/annotations_p.h @@ -16,6 +16,7 @@ // qt/kde includes #include #include +#include #include class QMatrix; @@ -57,6 +58,9 @@ class AnnotationPrivate Okular::Annotation::Style m_style; Okular::Annotation::Window m_window; QLinkedList< Okular::Annotation::Revision > m_revisions; + + Annotation::DisposeDataFunction m_disposeFunc; + QVariant m_nativeId; }; }