Warning, file /office/calligra/libs/rdf/KoRdfBasicSemanticItem.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 __rdf_KoRdfBasicSemanticItem_h__ 0021 #define __rdf_KoRdfBasicSemanticItem_h__ 0022 0023 #include "kordf_export.h" 0024 0025 #include "RdfForward.h" 0026 // KF5 0027 #include <KDateTime> 0028 // Soprano 0029 #include <Soprano/Soprano> 0030 // Qt 0031 #include <QSharedData> 0032 0033 //TODO: rework this documentation 0034 /** 0035 * @short Base class for C++ objects which represent Rdf at a higher level. 0036 * @author Ben Martin <ben.martin@kogmbh.com> 0037 * 0038 * Base class for Semantic Items (semitems). A semantic item is 0039 * created from one or more Rdf triples and brings that related 0040 * information together into a C++ object. For example, for contact 0041 * information, many Rdf triples conforming to the FOAF specification 0042 * might be present. 0043 * 0044 * Code can call createQTreeWidgetItem() to create an item that can be 0045 * displayed to the user without needing to know about triples or Rdf. 0046 * 0047 * @see KoRdfSemanticTreeWidgetItem 0048 * @see KoDocumentRdf 0049 * 0050 */ 0051 class KORDF_EXPORT KoRdfBasicSemanticItem : public QObject, public QSharedData 0052 { 0053 Q_OBJECT 0054 0055 public: 0056 explicit KoRdfBasicSemanticItem(QObject *parent); 0057 KoRdfBasicSemanticItem(QObject *parent, const KoDocumentRdf *rdf); 0058 KoRdfBasicSemanticItem(QObject *parent, const KoDocumentRdf *rdf, Soprano::QueryResultIterator &it); 0059 virtual ~KoRdfBasicSemanticItem(); 0060 0061 0062 protected: 0063 /** 0064 * Create a bnode with a uuid 0065 */ 0066 Soprano::Node createNewUUIDNode() const; 0067 0068 public: 0069 /** 0070 * For an item like a contact, event, location, if there is a 0071 * subject, common#idref xml:id triple that can be used to link 0072 * into the document content, return that subject node here for 0073 * the common base class methods to use. 0074 * 0075 * For example, in the FOAF vocabulary the ?person node from the 0076 * SPARQL query fragment below will be the linkingSubject() 0077 * ?person rdf:type foaf:Person 0078 */ 0079 virtual Soprano::Node linkingSubject() const; 0080 0081 protected: 0082 /** 0083 * Return the graph context that contains this SematicItem's Rdf 0084 * statements. Used by the updateTriple()s to remove and add 0085 * updated information. The default is the manifest.rdf file. 0086 */ 0087 virtual Soprano::Node context() const; 0088 0089 /** 0090 * When a subclass wants to update a triple in the Rdf store 0091 * to reflect a change, for example, the phone number of a 0092 * contact, it should call here to set toModify = newValue. 0093 * 0094 * This is done both in the C++ objects and the Rdf model. 0095 * The Rdf will be changed from 0096 * linkingSubject() predString toModify 0097 * to 0098 * linkingSubject() predString newValue 0099 * 0100 * Note that rounding errors and other serialization issues that 0101 * crop up are handled by these methods, so you should try very 0102 * hard not to directly update the Soprano::Model outside these 0103 * methods. 0104 */ 0105 void updateTriple(QString &toModify, const QString &newValue, const QString &predString); 0106 void updateTriple(KDateTime &toModify, const KDateTime &newValue, const QString &predString); 0107 void updateTriple(double &toModify, double newValue, const QString &predString, const Soprano::Node &explicitLinkingSubject); 0108 0109 /** 0110 * Ensure the Rdf Type of the linkingSubject is what you want 0111 * After this method, the Rdf will have the following: 0112 * linkingSubject() rdf:type type 0113 */ 0114 void setRdfType(const QString &type); 0115 0116 public: 0117 /** 0118 * The document Rdf object that this semantic item is associated with. 0119 */ 0120 const KoDocumentRdf *documentRdf() const; 0121 0122 /** 0123 * A Semantic Item can appear multiple times in a document. For 0124 * example, the person Frodo can be referenced 20 times in a short 0125 * book review. This method gives all the xmlid values where the 0126 * semantic item is referenced in the document. 0127 * 0128 * The list of xmlid values can in turn be used by 0129 * KoDocumentRdf::findExtent() and findStatements() to inspect or 0130 * perform actions at the various places the semantic item appears 0131 * in the document. 0132 */ 0133 QStringList xmlIdList() const; 0134 0135 /** 0136 * Create a QWidget that can edit the SemanticItem. Note that the 0137 * widget will show the data and allow editing of it for the 0138 * SemanticItem, but to make changes permanent, the 0139 * updateFromEditorData() method must be used. A typical scenario 0140 * is to add the widget from createEditor to a dialog and when the 0141 * user affirms the dialog call updateFromEditorData() to update 0142 * the document. 0143 * 0144 * @see updateFromEditorData() 0145 */ 0146 virtual QWidget *createEditor(QWidget *parent) = 0; 0147 0148 /** 0149 * Update the SemanticItem from the edited dialog that was created using 0150 * createEditor. 0151 * 0152 * @see createEditor() 0153 */ 0154 virtual void updateFromEditorData() = 0; 0155 0156 /** 0157 * Name of the subclass as would be contained in classNames() 0158 */ 0159 virtual QString className() const = 0; 0160 0161 private: 0162 /** 0163 * The updateTriple() methods all call remove() then add() to 0164 * perform their work. These lower level functions accept 0165 * Soprano::LiteralValues to remove/add. Note that corner cases 0166 * like "double" values are explicitly handled by these methods. 0167 * For example, at times a double will undergo some rounding 0168 * during serialization, so you can not just call 0169 * Soprano::Model.removeStatement() because you have to take 0170 * rounding errors into account for the value you are intending to 0171 * remove. 0172 */ 0173 void updateTriple_remove(const Soprano::LiteralValue &toModify, 0174 const QString &predString, 0175 const Soprano::Node& explicitLinkingSubject); 0176 0177 /** 0178 * After updateTriple() calls remove() it can set toModify to the 0179 * new value and call this method to add the new value to the Rdf 0180 * store. 0181 */ 0182 void updateTriple_add(const Soprano::LiteralValue &toModify, 0183 const QString &predString, 0184 const Soprano::Node &explicitLinkingSubject); 0185 0186 protected: 0187 const KoDocumentRdf *m_rdf; //< For access to the Rdf model during CRUD operations 0188 Soprano::Node m_context; //< This determines the Rdf/XML file the Rdf is stored in (see context()) 0189 }; 0190 0191 #endif //__rdf_KoRdfBasicSemanticItem_h__