Warning, file /office/calligra/libs/text/KoTextInlineRdf.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 Copyright (C) 2010 KO GmbH <ben.martin@kogmbh.com> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef KO_TEXT_INLINE_RDF_H 0021 #define KO_TEXT_INLINE_RDF_H 0022 0023 #include "kotext_export.h" 0024 // komain 0025 #include <KoXmlReaderForward.h> 0026 #include <KoElementReference.h> 0027 // Qt 0028 #include <QPair> 0029 #include <QMetaType> 0030 #include <QObject> 0031 0032 class KoXmlWriter; 0033 class KoShapeSavingContext; 0034 class KoBookmark; 0035 class KoAnnotation; 0036 class KoTextMeta; 0037 class KoTextEditor; 0038 class KoSection; 0039 0040 class QTextDocument; 0041 class QTextCursor; 0042 class QTextFormat; 0043 class QTextBlock; 0044 class QTextTableCell; 0045 0046 /** 0047 * @short Store information from xhtml:property etc which are for inline Rdf 0048 * 0049 * @author Ben Martin <ben.martin@kogmbh.com> 0050 * @see KoDocumentRdf 0051 * 0052 * The easiest way to handle inline Rdf from content.xml is to attach these 0053 * objects to the document's C++ objects. As you can see from the constructors 0054 * there are methods which can attach to bookmarks, textmeta, table cells etc. 0055 * 0056 * The main reason why the inlineRdf wants these document objects 0057 * passed in is so that object() can work out what the current value 0058 * is from the document. For example, when a KoTextInlineRdf is 0059 * attached to a bookmark-start, then when object() is called the 0060 * bookmark is inspected to find out the value currently between 0061 * bookmark-start and bookmark-end. 0062 * 0063 * The xmlId() method returns the xml:id that was associated with the 0064 * inline Rdf if there was one. For example, 0065 * <bookmark-start xml:id="foo" xhtml:property="uri:baba" ...> 0066 * the KoTextInlineRdf object will be attached to the KoBookmark 0067 * for the bookmark-start location and xmlId() will return foo. 0068 * 0069 * You can convert one of these to a Soprano::Statement using 0070 * KoDocumentRdf::toStatement(). 0071 * 0072 * The attach() and tryToGetInlineRdf() are used by the ODF load and 0073 * save codepaths respectively. They associate an inlineRdf object 0074 * with the cursor and fetch back the inline Rdf if one is associated 0075 * with a text block. 0076 * 0077 * FIXME: createXmlId() should consult with the Calligra codebase when 0078 * generating new xml:id values during save. 0079 */ 0080 class KOTEXT_EXPORT KoTextInlineRdf : public QObject 0081 { 0082 Q_OBJECT 0083 0084 public: 0085 KoTextInlineRdf(const QTextDocument *doc, const QTextBlock &b); 0086 KoTextInlineRdf(const QTextDocument *doc, KoBookmark *b); 0087 KoTextInlineRdf(const QTextDocument *doc, KoAnnotation *b); 0088 KoTextInlineRdf(const QTextDocument *doc, KoTextMeta *b); 0089 KoTextInlineRdf(const QTextDocument *doc, const QTextTableCell &b); 0090 KoTextInlineRdf(const QTextDocument *doc, KoSection *s); 0091 0092 ~KoTextInlineRdf() override; 0093 0094 /** 0095 * The attach() and tryToGetInlineRdf() are used by the ODF load and 0096 * save codepaths respectively. They associate an inlineRdf object 0097 * with the cursor and fetch back the inline Rdf if one is associated 0098 * with a text block. 0099 */ 0100 static KoTextInlineRdf *tryToGetInlineRdf(QTextCursor &cursor); 0101 static KoTextInlineRdf *tryToGetInlineRdf(const QTextFormat &tf); 0102 static KoTextInlineRdf *tryToGetInlineRdf(KoTextEditor *handler); 0103 /** 0104 * The attach() and tryToGetInlineRdf() are used by the ODF load and 0105 * save codepaths respectively. They associate an inlineRdf object 0106 * with the cursor and fetch back the inline Rdf if one is associated 0107 * with a text block. 0108 */ 0109 static void attach(KoTextInlineRdf *inlineRdf, QTextCursor &cursor); 0110 0111 bool loadOdf(const KoXmlElement &element); 0112 bool saveOdf(KoShapeSavingContext &context, KoXmlWriter *writer, KoElementReference id = KoElementReference()) const; 0113 0114 /** 0115 * Get the RDF subject for this inline RDF 0116 */ 0117 QString subject() const; 0118 /** 0119 * Get the RDF predicate for this inline RDF 0120 */ 0121 QString predicate() const; 0122 /** 0123 * Get the RDF object for this inline RDF 0124 */ 0125 QString object() const; 0126 /** 0127 * Get the type of RDF node (bnode, literal, uri etc) for this inline RDF 0128 */ 0129 int sopranoObjectType() const; 0130 0131 /** 0132 * Because RDF is linked to the xml id attribute of elements in 0133 * content.xml the xml:id attribute that was read from the 0134 * content.xml file is available here 0135 */ 0136 QString xmlId() const; 0137 0138 /** 0139 * Find the start and end position of this inline RDF object in the 0140 * document. 0141 */ 0142 QPair<int, int> findExtent() const; 0143 0144 0145 /** 0146 * Update the xml:id, using during cut and paste as well as document save. 0147 */ 0148 void setXmlId(const QString &id); 0149 0150 /** 0151 * Create a new and unique xml:id 0152 */ 0153 static QString createXmlId(); 0154 0155 private: 0156 0157 friend class KoRdfSemanticItem; 0158 friend class KoDocumentRdf; 0159 0160 class Private; 0161 Private* const d; 0162 }; 0163 0164 Q_DECLARE_METATYPE(KoTextInlineRdf*) 0165 #endif