File indexing completed on 2024-05-26 16:15:25
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_KoRdfSemanticItemViewSite_h__ 0021 #define __rdf_KoRdfSemanticItemViewSite_h__ 0022 0023 #include "kordf_export.h" 0024 #include "RdfForward.h" 0025 // Soprano 0026 #include <Soprano/Soprano> 0027 0028 class KoCanvasBase; 0029 class KoCanvasResourceManager; 0030 0031 class KoRdfSemanticItemViewSitePrivate; 0032 0033 0034 /** 0035 * @short Handling a specific reference to a semantic item in the document text. 0036 * @author Ben Martin <ben.martin@kogmbh.com> 0037 * 0038 * There can be many references to a single RdfSemanticItem in a 0039 * document. RdfSemanticItem is the model, this is the view/controller. 0040 * 0041 * For example: 0042 * foaf pkg:idref frodo1 0043 * foaf pkg:idref frodo2 0044 * 0045 * the foaf/contact data is the KoRdfSemanticItem (model) and each 0046 * xml:id frodo1 and frodo2 are KoRdfSemanticItemViewSite instances. 0047 * This class allows different stylesheets to present different 0048 * formatting for each presentation of the same KoRdfSemanticItem 0049 * (model). 0050 */ 0051 class KORDF_EXPORT KoRdfSemanticItemViewSite 0052 { 0053 KoRdfSemanticItemViewSitePrivate * const d; 0054 public: 0055 /** 0056 * Performing actions on a specific reference to a semantic item in the document. 0057 */ 0058 KoRdfSemanticItemViewSite(hKoRdfSemanticItem si, const QString &xmlid); 0059 ~KoRdfSemanticItemViewSite(); 0060 0061 /** 0062 * The stylesheet that has been set for this view site 0063 */ 0064 hKoSemanticStylesheet stylesheet() const; 0065 0066 /** 0067 * If there is a stylesheet set for this view site it is forgotten 0068 * and the reference can be freely edited by the user 0069 */ 0070 void disassociateStylesheet(); 0071 0072 /** 0073 * Apply a stylesheet for the semantic item. 0074 * Note that the setting is remembered for this site too. 0075 * 0076 * The application can be done separately using the setStylesheetWithoutReflow() 0077 * and reflowUsingCurrentStylesheet() methods. Performing the stylesheet 0078 * application in two parts is convenient if you are applying a stylesheet to many 0079 * semantic items at once, or to all the locations in the document which reference 0080 * a single semantic item. 0081 * 0082 * @see setStylesheetWithoutReflow() 0083 * @see reflowUsingCurrentStylesheet() 0084 */ 0085 void applyStylesheet(KoTextEditor *editor, hKoSemanticStylesheet ss); 0086 /** 0087 * Remember that a specific stylesheet should be applied for this 0088 * semantic item. No reflow of the document is performed and thus 0089 * no layout or user visible changes occur. 0090 * 0091 * @see applyStylesheet() 0092 */ 0093 void setStylesheetWithoutReflow(hKoSemanticStylesheet ss); 0094 0095 /** 0096 * Reflow the text that shows the user this semantic item in the 0097 * document. 0098 * 0099 * @see applyStylesheet() 0100 */ 0101 void reflowUsingCurrentStylesheet(KoTextEditor *editor); 0102 0103 /** 0104 * Select this view of the semantic item in the document. 0105 */ 0106 void select(KoCanvasBase *canvas); 0107 0108 private: 0109 0110 /** 0111 * This is similar to the linkingSubject() used by KoRdfSemanticItem 0112 * in that you have: 0113 * linkingSubject() common#idref xml:id 0114 * but metadata about the site at xml:id is stored as properties 0115 * off the KoRdfSemanticItemViewSite::linkingSubject() subject. 0116 * 0117 * The difference between this linkingSubject() and KoRdfSemanticItem 0118 * is that this is for Rdf describing a single xml:id site in the document, 0119 * the KoRdfSemanticItem::linkingSubject() is the model that can be referenced 0120 * by many xml:id sites. 0121 */ 0122 Soprano::Node linkingSubject() const; 0123 0124 /** 0125 * Convenience method to get a specific property from the Rdf 0126 * model. There should be either zero or only one value for X in 0127 * the triple: 0128 * 0129 * linkingSubject(), prop, X 0130 * 0131 * if the property does not exist defval is returned. 0132 */ 0133 QString getProperty(const QString &prop, const QString &defval) const; 0134 /** 0135 * Set the single value for the Rdf predicate prop. 0136 * @see getProperty() 0137 */ 0138 void setProperty(const QString &prop, const QString &v); 0139 0140 /** 0141 * Convenience method to select from startpos to endpos in the 0142 * document 0143 */ 0144 void selectRange(KoCanvasResourceManager *provider, int startpos, int endpos); 0145 0146 }; 0147 0148 #endif 0149