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

0001 /* This file is part of the KDE project
0002    Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003    Copyright 2007 Thorsten Zachmann <zachmann@kde.org>
0004    Copyright 2005-2006 Inge Wallin <inge@lysator.liu.se>
0005    Copyright 2004 Ariya Hidayat <ariya@kde.org>
0006    Copyright 2002-2003 Norbert Andres <nandres@web.de>
0007    Copyright 2000-2002 Laurent Montel <montel@kde.org>
0008    Copyright 2002 John Dailey <dailey@vt.edu>
0009    Copyright 2002 Phillip Mueller <philipp.mueller@gmx.de>
0010    Copyright 2000 Werner Trobin <trobin@kde.org>
0011    Copyright 1999-2000 Simon Hausmann <hausmann@kde.org>
0012    Copyright 1999 David Faure <faure@kde.org>
0013    Copyright 1998-2000 Torben Weis <weis@kde.org>
0014 
0015    This library is free software; you can redistribute it and/or
0016    modify it under the terms of the GNU Library General Public
0017    License as published by the Free Software Foundation; either
0018    version 2 of the License, or (at your option) any later version.
0019 
0020    This library is distributed in the hope that it will be useful,
0021    but WITHOUT ANY WARRANTY; without even the implied warranty of
0022    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0023    Library General Public License for more details.
0024 
0025    You should have received a copy of the GNU Library General Public License
0026    along with this library; see the file COPYING.LIB.  If not, write to
0027    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0028    Boston, MA 02110-1301, USA.
0029 */
0030 
0031 // Local
0032 #include "CalculationSettings.h"
0033 
0034 #include "Localization.h"
0035 #include "SheetsDebug.h"
0036 
0037 using namespace Calligra::Sheets;
0038 
0039 class Q_DECL_HIDDEN CalculationSettings::Private
0040 {
0041 public:
0042     KLocale* locale;
0043     bool caseSensitiveComparisons : 1;
0044     bool precisionAsShown         : 1;
0045     bool wholeCellSearchCriteria  : 1;
0046     bool automaticFindLabels      : 1;
0047     bool useRegularExpressions    : 1;
0048     bool useWildcards             : 1;
0049     bool automaticCalculation     : 1;
0050     int refYear; // the reference year two-digit years are relative to
0051     QDate refDate; // the reference date all dates are relative to
0052     // The precision used for decimal numbers, if the default cell style's
0053     // precision is set to arbitrary.
0054     int precision;
0055     QString fileName;
0056 };
0057 
0058 /*****************************************************************************
0059  *
0060  * CalculationSettings
0061  *
0062  *****************************************************************************/
0063 
0064 CalculationSettings::CalculationSettings()
0065         : d(new Private)
0066 {
0067     d->locale = new Localization();
0068     d->caseSensitiveComparisons = true;
0069     d->precisionAsShown         = false;
0070     d->wholeCellSearchCriteria  = true;
0071     d->automaticFindLabels      = true;
0072     d->useRegularExpressions    = true;
0073     d->useWildcards             = false;
0074     d->automaticCalculation     = true;
0075     d->refYear = 1930;
0076     d->refDate = QDate(1899, 12, 30);
0077     d->precision = -1;
0078 }
0079 
0080 CalculationSettings::~CalculationSettings()
0081 {
0082     delete d->locale;
0083     delete d;
0084 }
0085 
0086 KLocale* CalculationSettings::locale() const
0087 {
0088     return d->locale;
0089 }
0090 
0091 void CalculationSettings::setReferenceYear(int year)
0092 {
0093     d->refYear = year;
0094 }
0095 
0096 int CalculationSettings::referenceYear() const
0097 {
0098     return d->refYear;
0099 }
0100 
0101 void CalculationSettings::setReferenceDate(const QDate& date)
0102 {
0103     if (!date.isValid()) return;
0104     d->refDate.setDate(date.year(), date.month(), date.day());
0105 }
0106 
0107 QDate CalculationSettings::referenceDate() const
0108 {
0109     return d->refDate;
0110 }
0111 
0112 void CalculationSettings::setPrecisionAsShown(bool enable)
0113 {
0114     d->precisionAsShown = enable;
0115 }
0116 
0117 bool CalculationSettings::precisionAsShown() const
0118 {
0119     return d->precisionAsShown;
0120 }
0121 
0122 void CalculationSettings::setDefaultDecimalPrecision(int precision)
0123 {
0124     d->precision = precision;
0125 }
0126 
0127 int CalculationSettings::defaultDecimalPrecision() const
0128 {
0129     return d->precision;
0130 }
0131 
0132 void CalculationSettings::setFileName(const QString& fileName)
0133 {
0134     d->fileName = fileName;
0135 }
0136 
0137 const QString& CalculationSettings::fileName() const
0138 {
0139     return d->fileName;
0140 }
0141 
0142 void CalculationSettings::setAutoCalculationEnabled(bool enable)
0143 {
0144     d->automaticCalculation = enable;
0145 }
0146 
0147 bool CalculationSettings::isAutoCalculationEnabled() const
0148 {
0149     return d->automaticCalculation;
0150 }
0151 
0152 void CalculationSettings::setAutomaticFindLabels(bool enabled)
0153 {
0154     d->automaticFindLabels = enabled;
0155 }
0156 
0157 bool CalculationSettings::automaticFindLabels() const
0158 {
0159     return d->automaticFindLabels;
0160 }
0161 
0162 void CalculationSettings::setCaseSensitiveComparisons(Qt::CaseSensitivity caseSensitive)
0163 {
0164     d->caseSensitiveComparisons = caseSensitive == Qt::CaseSensitive;
0165 }
0166 
0167 Qt::CaseSensitivity CalculationSettings::caseSensitiveComparisons() const
0168 {
0169     return d->caseSensitiveComparisons ? Qt::CaseSensitive : Qt::CaseInsensitive;
0170 }
0171 
0172 void CalculationSettings::setWholeCellSearchCriteria(bool enabled)
0173 {
0174     d->wholeCellSearchCriteria = enabled;
0175 }
0176 
0177 bool CalculationSettings::wholeCellSearchCriteria() const
0178 {
0179     return d->wholeCellSearchCriteria;
0180 }
0181 
0182 void CalculationSettings::setUseRegularExpressions(bool enabled)
0183 {
0184     d->useRegularExpressions = enabled;
0185 }
0186 
0187 bool CalculationSettings::useRegularExpressions() const
0188 {
0189     return d->useRegularExpressions;
0190 }
0191 
0192 void CalculationSettings::setUseWildcards(bool enabled)
0193 {
0194     d->useWildcards = enabled;
0195 }
0196 
0197 bool CalculationSettings::useWildcards() const
0198 {
0199     return d->useWildcards;
0200 }