File indexing completed on 2024-05-26 16:15:53
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2008 Girish Ramakrishnan <girish@forwardbias.in> 0003 * Copyright (C) 2009 Elvis Stansvik <elvstone@gmail.com> 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 KOTEXTDEBUG_H 0022 #define KOTEXTDEBUG_H 0023 0024 #include "kotext_export.h" 0025 0026 class QTextDocument; 0027 class QTextFrame; 0028 class QTextBlock; 0029 class QTextTable; 0030 class QTextTableCell; 0031 class QTextFragment; 0032 class QTextCharFormat; 0033 class QTextListFormat; 0034 class QTextTableFormat; 0035 class QTextTableCellFormat; 0036 class QTextFrameFormat; 0037 class QTextBlockFormat; 0038 class QTextStream; 0039 class KoParagraphStyle; 0040 class KoCharacterStyle; 0041 class KoTableStyle; 0042 class KoTableCellStyle; 0043 0044 #include <QMap> 0045 #include <QVariant> 0046 0047 /** 0048 * @brief KoText debugging class. 0049 * 0050 * This class provides a set of public static functions for debugging the structure of 0051 * QTextDocument text documents. The functions will dump the structure of the document 0052 * along with any formats in a human-friendly pseudo-XML format. 0053 * 0054 * To most top level function is dumpDocument(), which can be used to dump an entire 0055 * document. In addition to that, there's a set of functions for dumping certain 0056 * parts of a document , such as dumpFrame(), dumpBlock() et.c. 0057 * 0058 * For example, the following code 0059 * 0060 * @code 0061 * QTextDocument doc; 0062 * QTextCursor cursor(&doc); 0063 * cursor.insertText("Hello!\n"); 0064 * cursor.insertHtml("<b>World!</b>"); 0065 * 0066 * QTextStream out(stdout); 0067 * KoTextDebug::dumpDocument(&doc, out); 0068 * @endcode 0069 * 0070 * will result in this output: 0071 * 0072 * @verbatim 0073 * <pre> 0074 * <document defaultfont="Sans Serif,9,-1,5,50,0,0,0,0,0"> 0075 * <frame margin="4" top-margin="4" bottom-margin="4" left-margin="4" right-margin="4" border-style="Outset"> 0076 * <block type="char"> 0077 * <fragment type="char"> 0078 * |Hello!| 0079 * </fragment> 0080 * </block> 0081 * 0082 * <block type="char"> 0083 * <fragment type="char" font="weight 75"> 0084 * |World!| 0085 * </fragment> 0086 * </block> 0087 * </frame> 0088 * </document> 0089 * </pre> 0090 * @endverbatim 0091 * 0092 * @sa dumpDocument(), dumpFrame(), dumpBlock() 0093 */ 0094 class KOTEXT_EXPORT KoTextDebug 0095 { 0096 public: 0097 /** 0098 * Dump the structure of the specified document. 0099 * 0100 * @param document a pointer to the document that should be dumped. 0101 * @param out output stream to dump to. 0102 */ 0103 static void dumpDocument(const QTextDocument *document, QTextStream &out); 0104 0105 /** 0106 * Dump the structure of the specified frame. 0107 * 0108 * @sa frameAttributes() 0109 * 0110 * @param frame a pointer to the frame that should be dumped. 0111 * @param out output stream to dump to. 0112 */ 0113 static void dumpFrame(const QTextFrame *frame, QTextStream &out); 0114 0115 /** 0116 * Dump the structure of the specified block. 0117 * 0118 * @param block the block that should be dumped. 0119 * @param out output stream to dump to. 0120 */ 0121 static void dumpBlock(const QTextBlock &block, QTextStream &out); 0122 0123 /** 0124 * Dump the structure of the specified table. 0125 * 0126 * @sa tableAttributes() 0127 * 0128 * @param table a pointer to the table that should be dumped. 0129 * @param out output stream to dump to. 0130 */ 0131 static void dumpTable(const QTextTable *table, QTextStream &out); 0132 0133 /** 0134 * Dump the structure of the specified table cell. 0135 * 0136 * @sa tableCellAttributes() 0137 * 0138 * @param cell the cell that should be dumped. 0139 * @param out output stream to dump to. 0140 */ 0141 static void dumpTableCell(const QTextTableCell &cell, QTextStream &out); 0142 0143 /** 0144 * Dump the contents of the specified text fragment. 0145 * 0146 * @note { The fragment content will be enclosed in '|' characters. } 0147 * 0148 * @param fragment the fragment which's content should be dumped. 0149 * @param out output stream to dump to. 0150 */ 0151 static void dumpFragment(const QTextFragment &fragment, QTextStream &out); 0152 0153 /** 0154 * Get the properties of the given text character format. 0155 * 0156 * The returned string will be formatted in XML-like attribute list format: 0157 * 0158 * <pre>"key=value key2=value2 ..."</pre> 0159 * 0160 * @param format the text character format from which properties should be fetched. 0161 * @return the formatted attribute string. 0162 */ 0163 static QString textAttributes(const QTextCharFormat &format); 0164 0165 /** 0166 * Get the properties of the given character style. 0167 * 0168 * The returned string will be formatted in XML-like attribute list format: 0169 * 0170 * <pre>"key=value key2=value2 ..."</pre> 0171 * 0172 * @param style the character style from which properties should be fetched. 0173 * @return the formatted attribute string. 0174 */ 0175 static QString textAttributes(const KoCharacterStyle &style); 0176 0177 /** 0178 * Get the properties of the given text block format. 0179 * 0180 * The returned string will be formatted in XML-like attribute list format: 0181 * 0182 * <pre>"key=value key2=value2 ..."</pre> 0183 * 0184 * @param format the text block format from which properties should be fetched. 0185 * @return the formatted attribute string. 0186 */ 0187 static QString paraAttributes(const QTextBlockFormat &format); 0188 0189 /** 0190 * Get the properties of the given paragraph style. 0191 * 0192 * The returned string will be formatted in XML-like attribute list format: 0193 * 0194 * <pre>"key=value key2=value2 ..."</pre> 0195 * 0196 * @param style the paragraph style from which properties should be fetched. 0197 * @return the formatted attribute string. 0198 */ 0199 static QString paraAttributes(const KoParagraphStyle &style); 0200 0201 /** 0202 * Get the properties of the given list format. 0203 * 0204 * The returned string will be formatted in XML-like attribute list format: 0205 * 0206 * <pre>"key=value key2=value2 ..."</pre> 0207 * 0208 * @param format the list format from which properties should be fetched. 0209 * @return the formatted attribute string. 0210 */ 0211 static QString listAttributes(const QTextListFormat &format); 0212 0213 /** 0214 * Get the properties of the given table style. 0215 * 0216 * The returned string will be formatted in XML-like attribute list format: 0217 * 0218 * <pre>"key=value key2=value2 ..."</pre> 0219 * 0220 * @param tableStyle the table style from which properties should be fetched. 0221 * @return the formatted attribute string. 0222 */ 0223 static QString tableAttributes(const KoTableStyle &tableStyle); 0224 0225 /** 0226 * Get the properties of the given table format. 0227 * 0228 * The returned string will be formatted in XML-like attribute list format: 0229 * 0230 * <pre>"key=value key2=value2 ..."</pre> 0231 * 0232 * @param tableFormat the table format from which properties should be fetched. 0233 * @return the formatted attribute string. 0234 */ 0235 static QString tableAttributes(const QTextTableFormat &tableFormat); 0236 0237 /** 0238 * Get the properties of the given table cell style. 0239 * 0240 * The returned string will be formatted in XML-like attribute list format: 0241 * 0242 * <pre>"key=value key2=value2 ..."</pre> 0243 * 0244 * @param tableCellStyle the table cell style from which properties should be fetched. 0245 * @return the formatted attribute string. 0246 */ 0247 static QString tableCellAttributes(const KoTableCellStyle &tableCellStyle); 0248 0249 /** 0250 * Get the properties of the given table cell format. 0251 * 0252 * The returned string will be formatted in XML-like attribute list format: 0253 * 0254 * <pre>"key=value key2=value2 ..."</pre> 0255 * 0256 * @param tableCellFormat the table cell format from which properties should be fetched. 0257 * @return the formatted attribute string. 0258 */ 0259 static QString tableCellAttributes(const QTextTableCellFormat &tableCellFormat); 0260 0261 /** 0262 * Get the properties of the given text frame format. 0263 * 0264 * The returned string will be formatted in XML-like attribute list format: 0265 * 0266 * <pre>"key=value key2=value2 ..."</pre> 0267 * 0268 * @param frameFormat the text frame format from which properties should be fetched. 0269 * @return the formatted attribute string. 0270 */ 0271 static QString frameAttributes(const QTextFrameFormat &frameFormat); 0272 0273 /** 0274 * Get the inline object properties of the object with the given text character format. 0275 * 0276 * The returned string will be formatted in XML-like attribute list format: 0277 * 0278 * <pre>"key=value key2=value2 ..."</pre> 0279 * 0280 * @param textFormat the character format of the object from which properties should be fetched. 0281 * @return the formatted attribute string. 0282 */ 0283 static QString inlineObjectAttributes(const QTextCharFormat &textFormat); 0284 0285 private: 0286 KoTextDebug(); 0287 KoTextDebug(const KoTextDebug&); 0288 KoTextDebug operator=(const KoTextDebug&); 0289 0290 static const QTextDocument *document; /**< Pointer to the debugged document. */ 0291 static int depth; /**< Current indentation depth. */ 0292 static const int INDENT; /**< Indentation value. */ 0293 }; 0294 0295 #endif /* KOTEXTDEBUG_H */