File indexing completed on 2024-04-28 16:21:34
0001 /* This file is part of the KDE project 0002 Copyright 2006,2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net> 0003 Copyright 1998,1999 Torben Weis <weis@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 CALLIGRA_SHEETS_UTIL 0022 #define CALLIGRA_SHEETS_UTIL 0023 0024 #include <QString> 0025 #include <QRect> 0026 0027 #include <KoXmlReader.h> 0028 0029 #include "sheets_odf_export.h" 0030 #include "Global.h" 0031 #include "Value.h" 0032 0033 class QFont; 0034 class QPen; 0035 class QDomElement; 0036 class QDomDocument; 0037 0038 class KLocale; 0039 0040 bool util_isPointValid(const QPoint& point); 0041 bool util_isRectValid(const QRect& rect); 0042 0043 namespace Calligra 0044 { 0045 namespace Sheets 0046 { 0047 class Cell; 0048 class Sheet; 0049 0050 namespace Util 0051 { 0052 /** 0053 * Call this function to decode the text of a column label to an integer, 0054 * e.g. 1 for A and 27 for AA. 0055 * Converted are all characters matching [A-Za-z]+ regular expression, the rest is ignored. 0056 * 0 is returned if no characters match. 0057 */ 0058 CALLIGRA_SHEETS_ODF_EXPORT int decodeColumnLabelText(const QString &labelText); 0059 0060 /** 0061 * Call this function to decode the text of a row label to an integer, 0062 * e.g. B7 is translated to 7. 0063 */ 0064 CALLIGRA_SHEETS_ODF_EXPORT int decodeRowLabelText(const QString &labelText); 0065 0066 /** 0067 * Call this function to encode an integer to the text of the column label 0068 * i.e. 27->AA 0069 */ 0070 CALLIGRA_SHEETS_ODF_EXPORT QString encodeColumnLabelText(int column); 0071 0072 /** 0073 * Returns true if the given text is a cell-reference. 0074 * 0075 * This is an optimized version of QRegExp("^(\\$?)([a-zA-Z]+)(\\$?)([0-9]+)$") 0076 * to check if the given string is a cell-reference like $A$1 or D17. Note 0077 * that this will return false for cell-ranges like A1:B2 or cell-references 0078 * given with sheet-name like Sheet1:A1. 0079 * 0080 * @param text The text to check 0081 * @param startPos The position in the string where we should start to check 0082 */ 0083 CALLIGRA_SHEETS_ODF_EXPORT bool isCellReference(const QString &text, int startPos = 0); 0084 0085 /** 0086 * Generate and return the ODF formula for this cell (\p thisRow, \p thisColumn) based on the formula in the 0087 * defined cell (\p referencedRow, \p referencedColumn ). 0088 */ 0089 CALLIGRA_SHEETS_ODF_EXPORT QString adjustFormulaReference(const QString& formula, int referencedRow, int referencedColumn, int thisRow, int thisColumn); 0090 0091 //Return true when it's a reference to cell from sheet. 0092 CALLIGRA_SHEETS_ODF_EXPORT bool localReferenceAnchor(const QString &_ref); 0093 0094 // TODO Stefan: used nowhere 0095 int penCompare(QPen const & pen1, QPen const & pen2); 0096 } 0097 0098 /** 0099 * \ingroup NativeFormat 0100 * This namespace collects methods related to old KSpread file format 0101 * encoding/decoding. 0102 */ 0103 namespace NativeFormat 0104 { 0105 /** 0106 * \ingroup NativeFormat 0107 */ 0108 QDomElement createElement(const QString & tagName, const QFont & font, QDomDocument & doc); 0109 0110 /** 0111 * \ingroup NativeFormat 0112 */ 0113 QDomElement createElement(const QString & tagname, const QPen & pen, QDomDocument & doc); 0114 0115 /** 0116 * \ingroup NativeFormat 0117 */ 0118 QFont toFont(KoXmlElement & element); 0119 0120 /** 0121 * \ingroup NativeFormat 0122 */ 0123 QPen toPen(KoXmlElement & element); 0124 } 0125 0126 /** 0127 * \ingroup OpenDocument 0128 * This namespace collects methods related to OpenDocument 0129 * encoding/decoding. 0130 */ 0131 namespace Odf 0132 { 0133 /** 0134 * \ingroup OpenDocument 0135 * Converts an OpenDocument representation of a formula to a localized formula. 0136 * @param expression_ The expression to convert from OpenDocument format. 0137 * @param locale The locale to which the expression should be converted. 0138 * @param namespacePrefix The namespace prefix. 0139 * \note Use Odf::loadRegion() for plain cell references. 0140 */ 0141 // TODO check visibility 0142 CALLIGRA_SHEETS_ODF_EXPORT QString decodeFormula(const QString& expression_, const KLocale *locale = 0, const QString &namespacePrefix = QString()); 0143 0144 /** 0145 * \ingroup OpenDocument 0146 * Converts a localized formula to an OpenDocument representation of a formula. 0147 * @param expr The expression to convert to OpenDocument format. 0148 * @param locale The locale from which the expression should be converted. 0149 * \note Use Region::saveOdf() for plain cell references. 0150 */ 0151 CALLIGRA_SHEETS_ODF_EXPORT QString encodeFormula(const QString& expr, const KLocale* locale = 0); 0152 0153 /** 0154 * \ingroup OpenDocument 0155 */ 0156 CALLIGRA_SHEETS_ODF_EXPORT QString convertRefToRange(const QString & sheet, const QRect & rect); 0157 0158 /** 0159 * \ingroup OpenDocument 0160 */ 0161 CALLIGRA_SHEETS_ODF_EXPORT QString convertRefToBase(const QString & sheet, const QRect & rect); 0162 0163 /** 0164 * \ingroup OpenDocument 0165 */ 0166 CALLIGRA_SHEETS_ODF_EXPORT QString convertRangeToRef(const QString & sheetName, const QRect & _area); 0167 } 0168 0169 namespace MSOOXML 0170 { 0171 /** 0172 * Convert the MSOOXML \p formula into a ODF formula and return that ODF formula. 0173 */ 0174 CALLIGRA_SHEETS_ODF_EXPORT QString convertFormula(const QString& formula); 0175 } 0176 0177 } // namespace Sheets 0178 } // namespace Calligra 0179 0180 #endif // CALLIGRA_SHEETS_UTIL