File: KoTextInlineRdf.h

package info (click to toggle)
calligra 1%3A3.2.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 260,432 kB
  • sloc: cpp: 650,911; xml: 27,662; python: 6,044; perl: 2,724; yacc: 1,817; ansic: 1,325; sh: 1,277; lex: 1,107; ruby: 1,010; javascript: 495; makefile: 24
file content (165 lines) | stat: -rw-r--r-- 5,488 bytes parent folder | download | duplicates (2)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* This file is part of the KDE project
   Copyright (C) 2010 KO GmbH <ben.martin@kogmbh.com>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef KO_TEXT_INLINE_RDF_H
#define KO_TEXT_INLINE_RDF_H

#include "kotext_export.h"
// komain
#include <KoXmlReaderForward.h>
#include <KoElementReference.h>
// Qt
#include <QPair>
#include <QMetaType>
#include <QObject>

class KoXmlWriter;
class KoShapeSavingContext;
class KoBookmark;
class KoAnnotation;
class KoTextMeta;
class KoTextEditor;
class KoSection;

class QTextDocument;
class QTextCursor;
class QTextFormat;
class QTextBlock;
class QTextTableCell;

/**
 * @short Store information from xhtml:property etc which are for inline Rdf
 *
 * @author Ben Martin <ben.martin@kogmbh.com>
 * @see KoDocumentRdf
 *
 * The easiest way to handle inline Rdf from content.xml is to attach these
 * objects to the document's C++ objects. As you can see from the constructors
 * there are methods which can attach to bookmarks, textmeta, table cells etc.
 *
 * The main reason why the inlineRdf wants these document objects
 * passed in is so that object() can work out what the current value
 * is from the document. For example, when a KoTextInlineRdf is
 * attached to a bookmark-start, then when object() is called the
 * bookmark is inspected to find out the value currently between
 * bookmark-start and bookmark-end.
 *
 * The xmlId() method returns the xml:id that was associated with the
 * inline Rdf if there was one. For example,
 * <bookmark-start xml:id="foo" xhtml:property="uri:baba" ...>
 * the KoTextInlineRdf object will be attached to the KoBookmark
 * for the bookmark-start location and xmlId() will return foo.
 *
 * You can convert one of these to a Soprano::Statement using
 * KoDocumentRdf::toStatement().
 *
 * The attach() and tryToGetInlineRdf() are used by the ODF load and
 * save codepaths respectively. They associate an inlineRdf object
 * with the cursor and fetch back the inline Rdf if one is associated
 * with a text block.
 *
 * FIXME: createXmlId() should consult with the Calligra codebase when
 * generating new xml:id values during save.
 */
class KOTEXT_EXPORT KoTextInlineRdf : public QObject
{
    Q_OBJECT

public:
    KoTextInlineRdf(const QTextDocument *doc, const QTextBlock &b);
    KoTextInlineRdf(const QTextDocument *doc, KoBookmark *b);
    KoTextInlineRdf(const QTextDocument *doc, KoAnnotation *b);
    KoTextInlineRdf(const QTextDocument *doc, KoTextMeta *b);
    KoTextInlineRdf(const QTextDocument *doc, const QTextTableCell &b);
    KoTextInlineRdf(const QTextDocument *doc, KoSection *s);

    ~KoTextInlineRdf() override;

    /**
     * The attach() and tryToGetInlineRdf() are used by the ODF load and
     * save codepaths respectively. They associate an inlineRdf object
     * with the cursor and fetch back the inline Rdf if one is associated
     * with a text block.
     */
    static KoTextInlineRdf *tryToGetInlineRdf(QTextCursor &cursor);
    static KoTextInlineRdf *tryToGetInlineRdf(const QTextFormat &tf);
    static KoTextInlineRdf *tryToGetInlineRdf(KoTextEditor *handler);
    /**
     * The attach() and tryToGetInlineRdf() are used by the ODF load and
     * save codepaths respectively. They associate an inlineRdf object
     * with the cursor and fetch back the inline Rdf if one is associated
     * with a text block.
     */
    static void attach(KoTextInlineRdf *inlineRdf, QTextCursor &cursor);

    bool loadOdf(const KoXmlElement &element);
    bool saveOdf(KoShapeSavingContext &context, KoXmlWriter *writer, KoElementReference id = KoElementReference()) const;

    /**
     * Get the RDF subject for this inline RDF
     */
    QString subject() const;
    /**
     * Get the RDF predicate for this inline RDF
     */
    QString predicate() const;
    /**
     * Get the RDF object for this inline RDF
     */
    QString object() const;
    /**
     * Get the type of RDF node (bnode, literal, uri etc) for this inline RDF
     */
    int sopranoObjectType() const;

    /**
     * Because RDF is linked to the xml id attribute of elements in
     * content.xml the xml:id attribute that was read from the
     * content.xml file is available here
     */
    QString xmlId() const;

    /**
     * Find the start and end position of this inline RDF object in the
     * document.
     */
    QPair<int, int> findExtent() const;


    /**
     * Update the xml:id, using during cut and paste as well as document save.
     */
    void setXmlId(const QString &id);

    /**
     * Create a new and unique xml:id
     */
    static QString createXmlId();

private:

    friend class KoRdfSemanticItem;
    friend class KoDocumentRdf;

    class Private;
    Private* const d;
};

Q_DECLARE_METATYPE(KoTextInlineRdf*)
#endif