1 /* This file is part of the KDE project
2  * Copyright (C) 2007 Fredy Yanardi <fyanardi@gmail.com>
3  * Copyright (C) 2012 Inge Wallin <inge@lysator.liu.se>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef KOANNOTATIONMANAGER_H
22 #define KOANNOTATIONMANAGER_H
23 
24 #include "kritatext_export.h"
25 
26 #include <QObject>
27 #include <QList>
28 
29 class KoAnnotation;
30 class KoAnnotationManagerPrivate;
31 
32 /**
33  * A manager for all annotations in a document. Every annotation is identified by a unique name.
34  * Note that only SinglePosition and StartAnnotation annotations can be retrieved from this
35  * manager. An end annotation should be retrieved from it's parent (StartAnnotation) using
36  * KoAnnotation::endAnnotation()
37  * This class also maintains a list of annotation names so that it can be easily used to
38  * show all available annotation.
39  */
40 class KRITATEXT_EXPORT KoAnnotationManager : public QObject
41 {
42     Q_OBJECT
43 public:
44     /// constructor
45     KoAnnotationManager();
46     ~KoAnnotationManager() override;
47 
48     /// @return an annotation with the specified name, or 0 if there is none
49     KoAnnotation *annotation(const QString &name) const;
50 
51     /// @return a list of QString containing all annotation names
52     QList<QString> annotationNameList() const;
53 
54 public Q_SLOTS:
55     /**
56      * Insert a new annotation to this manager. The name of the annotation
57      * will be set to @p name, no matter what name has been set on
58      * it.
59      * @param name the name of the annotation
60      * @param annotation the annotation object to insert
61      */
62     void insert(const QString &name, KoAnnotation *annotation);
63 
64     /**
65      * Remove an annotation from this manager.
66      * @param name the name of the annotation to remove
67      */
68     void remove(const QString &name);
69 
70     /**
71      * Rename an annotation
72      * @param oldName the old name of the annotation
73      * @param newName the new name of the annotation
74      */
75     void rename(const QString &oldName, const QString &newName);
76 
77 private:
78     KoAnnotationManagerPrivate * const d;
79 };
80 
81 #endif
82