Warning, file /office/calligra/libs/rdf/KoRdfSemanticItem.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_KoRdfSemanticItem_h__ 0021 #define __rdf_KoRdfSemanticItem_h__ 0022 0023 #include "kordf_export.h" 0024 0025 #include <KoRdfBasicSemanticItem.h> 0026 #include <KoSemanticStylesheet.h> 0027 // Qt 0028 #include <QMimeData> 0029 0030 class KoCanvasBase; 0031 class KDateTime; 0032 class QTreeWidgetItem; 0033 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 KoRdfSemanticItem : public KoRdfBasicSemanticItem 0052 { 0053 Q_OBJECT 0054 0055 public: 0056 explicit KoRdfSemanticItem(QObject *parent); 0057 KoRdfSemanticItem(QObject *parent, const KoDocumentRdf *rdf); 0058 KoRdfSemanticItem(QObject *parent, const KoDocumentRdf *rdf, Soprano::QueryResultIterator &it); 0059 virtual ~KoRdfSemanticItem(); 0060 0061 static QList<hKoRdfSemanticItem> fromList(const QList< hKoRdfBasicSemanticItem > &lst); 0062 0063 protected: 0064 /** 0065 * The importFromData() method can use this method to finish an 0066 * import. Text is also inserted into the document to show the 0067 * user the new semantic object. The semanticObjectAdded signal is 0068 * emitted so that dockers have a chance to update themselves to 0069 * reflect the newly added SemanticItem in the document. 0070 * 0071 * This method uses createEditor() followed by 0072 * updateFromEditorData() to actually put the Rdf triples into the 0073 * store. So a subclass does not have to explicitly handle the 0074 * import if it can present a GUI to edit itself. The GUI is not 0075 * shown to the user. 0076 * 0077 */ 0078 virtual void importFromDataComplete(const QByteArray &ba, const KoDocumentRdf *rdf = 0, KoCanvasBase *host = 0); 0079 0080 friend class KoSemanticStylesheetsEditor; 0081 friend class KoSemanticStylesheet; 0082 virtual void setupStylesheetReplacementMapping(QMap<QString, QString> &m); 0083 0084 public: 0085 /** 0086 * Create a QTreeWidgetItem to display this SemanticItem. This 0087 * method should be used if you want to present a QTree of 0088 * SemanticItems because the returned widgetItem can also create a 0089 * menu and perform other actions for the SemanticItem. 0090 */ 0091 virtual KoRdfSemanticTreeWidgetItem *createQTreeWidgetItem(QTreeWidgetItem *parent = 0); 0092 0093 /** 0094 * Insert the SemanticItem into the document at the current cursor 0095 * position. The appearance of each semantic item is likely to be 0096 * different depending on the user's current formatting 0097 * preferences. For example, a contact might show one or more of 0098 * the person's names and their phone number. 0099 * 0100 * This method inserts markers and other book keeping and uses 0101 * the default stylesheet to insert a representation of the 0102 * SemanticItem. 0103 */ 0104 virtual void insert(KoCanvasBase *host); 0105 0106 /** 0107 * Export the SemanticItem to MimeData. This method is used by 0108 * Drag and Drop to allow the item to move to another application 0109 * or possibly onto the clipboard. Subclasses might like to use a 0110 * QTemporaryFile and call their exportToFile() method to export 0111 * themselves to MIME data. For maximum usability a plain text 0112 * representation should also be set with md->setText() so items 0113 * can be dragged to text editors and consoles. 0114 */ 0115 virtual void exportToMime(QMimeData *md) const; 0116 0117 /** 0118 * Export to a file in whatever format is the most useful for the 0119 * semantic item. Prompt for a filename if none is given. 0120 */ 0121 virtual void exportToFile(const QString &fileName = QString()) const = 0; 0122 0123 /** 0124 * Import the data in ba to the semantic item. This is used for 0125 * D&D Drop events to create a new semantic item. Subclasses 0126 * should set their internal state based on the data in 'ba' and 0127 * then call importFromDataComplete() at the end of the method to 0128 * update the Rdf and insert the semantic item into the document. 0129 * 0130 * This method calls also insert() which links the semanticItem with the 0131 * KoDocumentRdf object m_rdf. 0132 */ 0133 virtual void importFromData(const QByteArray &ba, const KoDocumentRdf *rdf = 0, KoCanvasBase *host = 0) = 0; 0134 0135 /** 0136 * A simple description of the semantic item that can be shown to the user 0137 */ 0138 virtual QString name() const = 0; 0139 0140 /** 0141 * Get the system semantic stylesheets that are supported for this 0142 * particular semantic item subclass. 0143 */ 0144 virtual QList<hKoSemanticStylesheet> stylesheets() const = 0; 0145 0146 /** 0147 * Get the user created/editable semantic stylesheets that are 0148 * supported for this particular semantic item subclass. 0149 */ 0150 QList<hKoSemanticStylesheet> userStylesheets() const; 0151 0152 /** 0153 * Unambiguiously find a stylesheet by its UUID. The sheet can 0154 * be either user or system as long as it has the uuid you want. 0155 */ 0156 hKoSemanticStylesheet findStylesheetByUuid(const QString &uuid) const; 0157 0158 /** 0159 * Find a user/system stylesheet by name. 0160 * sheetType is one of TYPE_SYSTEM/TYPE_USER. 0161 * n is the name of the stylesheet you want. 0162 */ 0163 hKoSemanticStylesheet findStylesheetByName(const QString &sheetType, const QString &n) const; 0164 /** 0165 * Find a user/system stylesheet by name. 0166 * ssl is either stylesheets() or userStylesheets() 0167 * n is the name of the stylesheet you want. 0168 */ 0169 hKoSemanticStylesheet findStylesheetByName(const QList<hKoSemanticStylesheet> &ssl, const QString &n) const; 0170 0171 /** 0172 * Get the default stylesheet for this subclass of Semantic Item. 0173 * 0174 * If you want to know which stylesheet is in use by a particular 0175 * reference to a semantic item, use KoRdfSemanticItemViewSite::stylesheet() 0176 * 0177 * @see KoRdfSemanticItemViewSite 0178 * @see KoRdfSemanticItemViewSite::stylesheet() 0179 */ 0180 hKoSemanticStylesheet defaultStylesheet() const; 0181 /** 0182 * Set the default stylesheet for this subclass of Semantic Item. 0183 * 0184 * If you want to set the stylesheet for a particular reference to a 0185 * semantic item, use KoRdfSemanticItemViewSite::applyStylesheet(). 0186 * @see KoRdfSemanticItemViewSite::applyStylesheet() 0187 */ 0188 void defaultStylesheet(hKoSemanticStylesheet ss); 0189 0190 /** 0191 * Create a new user stylesheet 0192 */ 0193 hKoSemanticStylesheet createUserStylesheet(const QString &name, const QString &templateString = QString()); 0194 0195 /** 0196 * Destroy a user stylesheet 0197 */ 0198 void destroyUserStylesheet(hKoSemanticStylesheet ss); 0199 0200 /** 0201 * Load the user stylesheets from the given Rdf model. They are 0202 * assumed to be in the format saved by saveUserStylesheets() 0203 * 0204 * @see saveUserStylesheets() 0205 */ 0206 void loadUserStylesheets(QSharedPointer<Soprano::Model> model); 0207 0208 /** 0209 * Save the user stylesheets to the Rdf model given. 0210 * 0211 * Stylesheets are saved as an Rdf list of stylesheet bnodes. If 0212 * there is already a list in the model it is removed first and 0213 * then the current collection of user stylesheets is added into 0214 * the Rdf model. Note that as the collection of user stylesheets 0215 * exists on a per subclass basis, this method saves the list to 0216 * the Rdf model using a list head that depends on which subclass 0217 * you are saving the user stylesheets of. As such, you should 0218 * save and load the user stylesheets for each class in 0219 * classNames(). 0220 * 0221 * @see loadUserStylesheets() 0222 * @see classNames() 0223 */ 0224 void saveUserStylesheets(QSharedPointer<Soprano::Model> model, const Soprano::Node &context) const; 0225 0226 protected: 0227 /** 0228 * Create a new system stylesheet 0229 */ 0230 hKoSemanticStylesheet createSystemStylesheet(const QString &uuid, const QString &name, const QString &templateString) const; 0231 0232 protected Q_SLOTS: 0233 /** 0234 * In case the stylesheets move to using a QMap<String,sheet> or 0235 * we want to know when a stylesheet has been renamed. 0236 */ 0237 void onUserStylesheetRenamed(hKoSemanticStylesheet ss, const QString &oldName, const QString &newName); 0238 }; 0239 0240 #endif //__rdf_KoRdfSemanticItem_h__