kspread
CalculationSettings.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "CalculationSettings.h"
00033
00034 #include "Localization.h"
00035
00036 #include <KoXmlNS.h>
00037
00038 #include <kdebug.h>
00039
00040 using namespace KSpread;
00041
00042 class CalculationSettings::Private
00043 {
00044 public:
00045 KLocale* locale;
00046 bool caseSensitiveComparisons : 1;
00047 bool precisionAsShown : 1;
00048 bool wholeCellSearchCriteria : 1;
00049 bool automaticFindLabels : 1;
00050 bool useRegularExpressions : 1;
00051 int refYear;
00052 QDate refDate;
00053
00054
00055 int precision;
00056 QString fileName;
00057 };
00058
00059
00060
00061
00062
00063
00064
00065 CalculationSettings::CalculationSettings()
00066 : d(new Private)
00067 {
00068 d->locale = new Localization();
00069 d->caseSensitiveComparisons = true;
00070 d->precisionAsShown = false;
00071 d->wholeCellSearchCriteria = true;
00072 d->automaticFindLabels = true;
00073 d->useRegularExpressions = true;
00074 d->refYear = 1930;
00075 d->refDate = QDate( 1899, 12, 30 );
00076 d->precision = 8;
00077 }
00078
00079 CalculationSettings::~CalculationSettings()
00080 {
00081 delete d->locale;
00082 delete d;
00083 }
00084
00085 void CalculationSettings::loadOdf(const KoXmlElement& body)
00086 {
00087 KoXmlNode settings = KoXml::namedItemNS( body, KoXmlNS::table, "calculation-settings" );
00088 kDebug() <<"Calculation settings found?"<< !settings.isNull();
00089 if ( !settings.isNull() )
00090 {
00091 KoXmlElement element = settings.toElement();
00092 if ( element.hasAttributeNS( KoXmlNS::table, "case-sensitive" ) )
00093 {
00094 d->caseSensitiveComparisons = true;
00095 QString value = element.attributeNS( KoXmlNS::table, "case-sensitive", "true" );
00096 if ( value == "false" )
00097 d->caseSensitiveComparisons = false;
00098 }
00099 else if ( element.hasAttributeNS( KoXmlNS::table, "precision-as-shown" ) )
00100 {
00101 d->precisionAsShown = false;
00102 QString value = element.attributeNS( KoXmlNS::table, "precision-as-shown", "false" );
00103 if ( value == "true" )
00104 d->precisionAsShown = true;
00105 }
00106 else if ( element.hasAttributeNS( KoXmlNS::table, "search-criteria-must-apply-to-whole-cell" ) )
00107 {
00108 d->wholeCellSearchCriteria = true;
00109 QString value = element.attributeNS( KoXmlNS::table, "search-criteria-must-apply-to-whole-cell", "true" );
00110 if ( value == "false" )
00111 d->wholeCellSearchCriteria = false;
00112 }
00113 else if ( element.hasAttributeNS( KoXmlNS::table, "automatic-find-labels" ) )
00114 {
00115 d->automaticFindLabels = true;
00116 QString value = element.attributeNS( KoXmlNS::table, "automatic-find-labels", "true" );
00117 if ( value == "false" )
00118 d->automaticFindLabels = false;
00119 }
00120 else if ( element.hasAttributeNS( KoXmlNS::table, "use-regular-expressions" ) )
00121 {
00122 d->useRegularExpressions = true;
00123 QString value = element.attributeNS( KoXmlNS::table, "use-regular-expressions", "true" );
00124 if ( value == "false" )
00125 d->useRegularExpressions = false;
00126 }
00127 else if ( element.hasAttributeNS( KoXmlNS::table, "null-year" ) )
00128 {
00129 d->refYear = 1930;
00130 QString value = element.attributeNS( KoXmlNS::table, "null-year", "1930" );
00131 if ( value == "false" )
00132 d->refYear = false;
00133 }
00134
00135 forEachElement( element, settings )
00136 {
00137 if ( element.namespaceURI() != KoXmlNS::table )
00138 continue;
00139 else if ( element.tagName() == "null-date" )
00140 {
00141 d->refDate = QDate( 1899, 12, 30 );
00142 QString valueType = element.attributeNS( KoXmlNS::table, "value-type", "date" );
00143 if( valueType == "date" )
00144 {
00145 QString value = element.attributeNS( KoXmlNS::table, "date-value", "1899-12-30" );
00146 QDate date = QDate::fromString( value, Qt::ISODate );
00147 if ( date.isValid() )
00148 d->refDate = date;
00149 }
00150 else
00151 {
00152 kDebug() <<"CalculationSettings: Error on loading null date."
00153 << "Value type """ << valueType << """ not handled"
00154 << ", falling back to default." << endl;
00155
00156 }
00157 }
00158 else if ( element.tagName() == "iteration" )
00159 {
00160
00161 }
00162 }
00163 }
00164 }
00165
00166 bool CalculationSettings::saveOdf(KoXmlWriter &settingsWriter) const
00167 {
00168 return true;
00169 }
00170
00171 KLocale* CalculationSettings::locale() const
00172 {
00173 return d->locale;
00174 }
00175
00176 void CalculationSettings::setReferenceYear( int year )
00177 {
00178 if ( year < 100)
00179 d->refYear = 1900 + year;
00180 else
00181 d->refYear = year;
00182 }
00183
00184 int CalculationSettings::referenceYear() const
00185 {
00186 return d->refYear;
00187 }
00188
00189 void CalculationSettings::setReferenceDate( const QDate& date )
00190 {
00191 if ( !date.isValid() ) return;
00192 d->refDate.setDate( date.year(), date.month(), date.day() );
00193 }
00194
00195 QDate CalculationSettings::referenceDate() const
00196 {
00197 return d->refDate;
00198 }
00199
00200 void CalculationSettings::setDefaultDecimalPrecision( int precision )
00201 {
00202 d->precision = ( precision < 0 ) ? 8 : precision;
00203 }
00204
00205 int CalculationSettings::defaultDecimalPrecision() const
00206 {
00207 return d->precision;
00208 }
00209
00210 void CalculationSettings::setFileName(const QString& fileName)
00211 {
00212 d->fileName = fileName;
00213 }
00214
00215 const QString& CalculationSettings::fileName() const
00216 {
00217 return d->fileName;
00218 }
|