Warning, file /office/calligra/libs/odf/KoStyleStack.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) 2003 Lukas Tinkl <lukas@kde.org> 0003 Copyright (c) 2003 David Faure <faure@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef KOSTYLESTACK_H 0022 #define KOSTYLESTACK_H 0023 0024 0025 #include <QList> 0026 #include <QStack> 0027 #include <QPair> 0028 0029 #include "koodf_export.h" 0030 #include <KoXmlReader.h> 0031 0032 /** 0033 * @brief This class implements a stack for the different styles of an object. 0034 * 0035 * There can be several styles that are valid for one object. For example 0036 * a textobject on a page has styles 'pr3' and 'P7' and a paragraph in 0037 * that textobject has styles 'P1' and 'T3'. And some styles even have 0038 * parent-styles... 0039 * 0040 * If you want to know if there is, for example, the attribute 'fo:font-family' 0041 * for this paragraph, you have to look into style 'T3', 'P1', 'P7' and 'pr3'. 0042 * When you find this attribute in one style you have to stop processing the list 0043 * and take the found attribute for this object. 0044 * 0045 * This is what this class does. You can push styles on the stack while walking 0046 * through the xml-tree to your object and then ask the stack if any of the styles 0047 * provides a certain attribute. The stack will search from top to bottom, i.e. 0048 * in our example from 'T3' to 'pr3' and return the first occurrence of the wanted 0049 * attribute. 0050 * 0051 * So this is some sort of inheritance where the styles on top of the stack overwrite 0052 * the same attribute of a lower style on the stack. 0053 * 0054 * In general though, you wouldn't use push/pop directly, but KoOdfLoadingContext::fillStyleStack 0055 * or KoOdfLoadingContext::addStyles to automatically push a style and all its 0056 * parent styles onto the stack. 0057 */ 0058 class KOODF_EXPORT KoStyleStack 0059 { 0060 public: 0061 /** 0062 * Create a OASIS style stack 0063 */ 0064 KoStyleStack(); 0065 /** 0066 * Create a style stack based on other namespaces than OASIS - used for OOo-1.1 import. 0067 */ 0068 explicit KoStyleStack(const char* styleNSURI, const char* foNSURI); 0069 virtual ~KoStyleStack(); 0070 0071 /** 0072 * Clears the complete stack. 0073 */ 0074 void clear(); 0075 0076 /** 0077 * Save the current state of the stack. Any items added between 0078 * this call and its corresponding restore() will be removed when calling restore(). 0079 */ 0080 void save(); 0081 0082 /** 0083 * Restore the stack to the state it was at the corresponding save() call. 0084 */ 0085 void restore(); 0086 0087 /** 0088 * Removes the style on top of the stack. 0089 */ 0090 void pop(); 0091 0092 /** 0093 * Pushes the new style onto the stack. 0094 */ 0095 void push(const KoXmlElement& style); 0096 0097 /** 0098 * Check if any of the styles on the stack has an attribute called 'localName' 0099 */ 0100 bool hasProperty(const QString &nsURI, const QString &localName) const; 0101 0102 /** 0103 * Check if any of the styles on the stack has an attribute called 'localname'-'detail' 0104 * where detail is e.g. left, right, top or bottom. 0105 * This allows to also find 'name' alone (e.g. padding implies padding-left, padding-right etc.) 0106 */ 0107 bool hasProperty(const QString &nsURI, const QString &localName, const QString &detail) const; 0108 0109 /** 0110 * Search for the attribute called 'localName', starting on top of the stack, 0111 * and return it. 0112 */ 0113 QString property(const QString &nsURI, const QString &localName) const; 0114 0115 /** 0116 * Search for the attribute called 'localName'-'detail', starting on top of the stack, 0117 * and return it, where detail is e.g. left, right, top or bottom. 0118 * This allows to also find 'name' alone (e.g. padding implies padding-left, padding-right etc.) 0119 */ 0120 QString property(const QString &nsURI, const QString &localName, const QString &detail) const; 0121 0122 /** 0123 * Check if any of the styles on the stack has a child element called 'localName' in the namespace 'nsURI'. 0124 */ 0125 bool hasChildNode(const QString &nsURI, const QString &localName) const; 0126 0127 /** 0128 * Search for a child element which has a child element called 'localName' 0129 * in the namespace 'nsURI' starting on top of the stack, 0130 * and return it. 0131 */ 0132 KoXmlElement childNode(const QString &nsURI, const QString &localName) const; 0133 0134 /** 0135 * Special case for the current font size, due to special handling of fo:font-size="115%". 0136 * First item in the returned value contains the font point size and the second the got percent. 0137 */ 0138 QPair<qreal,qreal> fontSize(const qreal defaultFontPointSize = 12.0) const; 0139 0140 /** 0141 * Return the name of the style specified by the user, 0142 * i.e. not an auto style. 0143 * This is used to know e.g. which user-style is associated with the current paragraph. 0144 * There could be none though. 0145 */ 0146 QString userStyleName(const QString& family) const; 0147 0148 /** 0149 * Return the display name of the style specified by the user, 0150 * i.e. not an auto style 0151 */ 0152 QString userStyleDisplayName(const QString& family) const; 0153 0154 /** 0155 * Set the type of properties that will be looked for. 0156 * For instance setTypeProperties("paragraph") will make hasAttribute() and attribute() 0157 * look into "paragraph-properties". 0158 * If @p typeProperties is 0, the stylestack is reset to look for "properties" 0159 * as it does by default. 0160 */ 0161 void setTypeProperties(const char* typeProperties); 0162 0163 /** 0164 * Overloaded method to also set backup properties to search in 0165 * 0166 * If the list is graphic, paragraph it will search first in graphic-properties and then in paragraph-properties 0167 */ 0168 void setTypeProperties(const QList<QString> &typeProperties); 0169 0170 private: 0171 bool isUserStyle(const KoXmlElement& e, const QString& family) const; 0172 0173 inline bool hasProperty(const QString &nsURI, const QString &localName, const QString *detail) const; 0174 0175 inline QString property(const QString &nsURI, const QString &localName, const QString *detail) const; 0176 0177 /// For save/restore: stack of "marks". Each mark is an index in m_stack. 0178 QStack<int> m_marks; 0179 0180 /** 0181 * We use QValueList instead of QValueStack because we need access to all styles 0182 * not only the top one. 0183 */ 0184 QList<KoXmlElement> m_stack; 0185 0186 QList<QString> m_propertiesTagNames; 0187 0188 QString m_styleNSURI; 0189 QString m_foNSURI; 0190 0191 class KoStyleStackPrivate; 0192 KoStyleStackPrivate * const d; 0193 0194 // forbidden 0195 void operator=(const KoStyleStack&); 0196 KoStyleStack(const KoStyleStack&); 0197 }; 0198 0199 #endif /* KOSTYLESTACK_H */