1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
/* This file is part of the KDE project
* SPDX-FileCopyrightText: 2006-2009 Thomas Zander <zander@kde.org>
* SPDX-FileCopyrightText: 2012 C. Boemann <cbo@boemann.dk>
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KOTEXTRANGEMANAGER_H
#define KOTEXTRANGEMANAGER_H
#include "KoAnnotationManager.h"
#include "KoBookmarkManager.h"
#include "KoTextRange.h"
#include "kotext_export.h"
// Qt
#include <QHash>
#include <QMetaType>
#include <QSet>
#include <QTextCursor>
/**
* A container to register all the text ranges with.
*/
class KOTEXT_EXPORT KoTextRangeManager : public QObject
{
Q_OBJECT
public:
/// Constructor
explicit KoTextRangeManager(QObject *parent = nullptr);
~KoTextRangeManager() override;
QList<KoTextRange *> textRanges() const;
QList<KoTextRange *> textRanges(const QTextDocument *doc) const;
void finalizeTextRanges();
/**
* Insert a new text range into the manager.
* @param object the text range to be inserted.
*/
void insert(KoTextRange *object);
/**
* Remove a text range from this manager.
* @param range the text range to be removed
*/
void remove(KoTextRange *range);
/**
* Return the bookmark manager.
*/
const KoBookmarkManager *bookmarkManager() const;
/**
* Return the annotation manager.
*/
const KoAnnotationManager *annotationManager() const;
/**
* Return a multi hash of KoTextRange that have start or end points between first and last
* If the text range is a selection then the opposite end has to be within matchFirst and
* matchLast.
* Single position text ranges is only added once to the hash
*/
QMultiHash<int, KoTextRange *> textRangesChangingWithin(const QTextDocument *, int first, int last, int matchFirst, int matchLast) const;
QMultiHash<int, KoTextRange *>
textRangesChangingWithin(const QTextDocument *, QList<const QMetaObject *> types, int first, int last, int matchFirst, int matchLast) const;
template<class T>
T *createAndLoadOdf(const QTextCursor &cursor, const KoXmlElement &element, KoShapeLoadingContext &context)
{
T *object = new T(cursor.document(), cursor.position());
object->setManager(this);
if (!object->loadOdf(element, context)) {
delete (object);
return nullptr;
}
insert(object);
return object;
}
private:
class KoTextRangeManagerPrivate;
KoTextRangeManagerPrivate *d;
KoBookmarkManager m_bookmarkManager;
KoAnnotationManager m_annotationManager;
};
Q_DECLARE_METATYPE(KoTextRangeManager *)
#endif
|