File indexing completed on 2024-04-28 16:21:21

0001 /* This file is part of the KDE project
0002    Copyright 2000-2006 The KSpread Team <calligra-devel@kde.org>
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_CURRENCY
0022 #define CALLIGRA_SHEETS_CURRENCY
0023 
0024 #include <QHash>
0025 #include <QMetaType>
0026 #include <QString>
0027 
0028 #include "sheets_odf_export.h"
0029 
0030 namespace Calligra
0031 {
0032 namespace Sheets
0033 {
0034 
0035 /**
0036  * \ingroup Style
0037  * \class Currency
0038  * Currency format information.
0039  */
0040 class CALLIGRA_SHEETS_ODF_EXPORT Currency
0041 {
0042 public:
0043     enum Format { Native, Gnumeric, OpenCalc, ApplixSpread, GobeProductiveSpread, HancomSheet };
0044 
0045     /**
0046      * Constructor.
0047      * Creates a currency corresponding to the given currency table index.
0048      * If \p index is omitted or zero, a currency with the locale default
0049      * currency unit is created.
0050      */
0051     explicit Currency(int index = 0);
0052 
0053     /**
0054      * Constructor.
0055      * Creates a currency corresponding to \p code .
0056      * Looks up the index.
0057      * If the code is found more than once: saved without country info.
0058      * If the code is not found, \p code is handled as custom unit.
0059      * \param code the code, e.g. EUR, USD,..
0060      * \param format the format, e.g. the code in Gnumeric format is [$EUR]
0061      */
0062     explicit Currency(QString const & code, Format format = Native);
0063 
0064     /**
0065      * Destructor.
0066      */
0067     ~Currency();
0068 
0069 
0070     bool operator==(Currency const & other) const;
0071     inline bool operator!=(Currency const & other) const {
0072         return !operator==(other);
0073     }
0074 
0075     QString code(Format format = Native) const;
0076     QString country() const;
0077     QString name() const;
0078     QString symbol() const;
0079     int     index() const;
0080 
0081     static QString chooseString(int type, bool & ok);
0082 
0083 private:
0084     int     m_index;
0085     QString m_code;
0086 };
0087 
0088 static inline uint qHash(const Currency& cur) {
0089     return ::qHash(cur.code());
0090 }
0091 
0092 } // namespace Sheets
0093 } // namespace Calligra
0094 
0095 Q_DECLARE_METATYPE(Calligra::Sheets::Currency)
0096 
0097 #endif