[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [calligra] sheets: Move calculation settings load/save to odf/
From: Tomas Mecir <mecirt () gmail ! com>
Date: 2016-03-06 17:21:12
Message-ID: E1accMi-0005vS-6G () scm ! kde ! org
[Download RAW message or body]
Git commit 8678af632b0e8ccfd62c499e1d5889ef60466958 by Tomas Mecir.
Committed on 27/02/2016 at 18:59.
Pushed by mecir into branch 'master'.
Move calculation settings load/save to odf/
M +0 -99 sheets/CalculationSettings.cpp
M +0 -14 sheets/CalculationSettings.h
M +95 -0 sheets/odf/SheetsOdfDoc.cpp
M +3 -7 sheets/odf/SheetsOdfMap.cpp
M +6 -0 sheets/odf/SheetsOdfPrivate.h
http://commits.kde.org/calligra/8678af632b0e8ccfd62c499e1d5889ef60466958
diff --git a/sheets/CalculationSettings.cpp b/sheets/CalculationSettings.cpp
index 6c101a7..1717c37 100644
--- a/sheets/CalculationSettings.cpp
+++ b/sheets/CalculationSettings.cpp
@@ -34,10 +34,6 @@
#include "Localization.h"
#include "SheetsDebug.h"
-#include <KoXmlNS.h>
-#include <KoXmlWriter.h>
-
-
using namespace Calligra::Sheets;
class Q_DECL_HIDDEN CalculationSettings::Private
@@ -87,101 +83,6 @@ CalculationSettings::~CalculationSettings()
delete d;
}
-void CalculationSettings::loadOdf(const KoXmlElement& body)
-{
- KoXmlNode settings = KoXml::namedItemNS(body, KoXmlNS::table, \
"calculation-settings");
- debugSheets << "Calculation settings found?" << !settings.isNull();
- if (!settings.isNull()) {
- KoXmlElement element = settings.toElement();
- if (element.hasAttributeNS(KoXmlNS::table, "case-sensitive")) {
- d->caseSensitiveComparisons = true;
- QString value = element.attributeNS(KoXmlNS::table, "case-sensitive", \
"true");
- if (value == "false")
- d->caseSensitiveComparisons = false;
- } else if (element.hasAttributeNS(KoXmlNS::table, "precision-as-shown")) {
- d->precisionAsShown = false;
- QString value = element.attributeNS(KoXmlNS::table, \
"precision-as-shown", "false");
- if (value == "true")
- d->precisionAsShown = true;
- } else if (element.hasAttributeNS(KoXmlNS::table, \
"search-criteria-must-apply-to-whole-cell")) {
- d->wholeCellSearchCriteria = true;
- QString value = element.attributeNS(KoXmlNS::table, \
"search-criteria-must-apply-to-whole-cell", "true");
- if (value == "false")
- d->wholeCellSearchCriteria = false;
- } else if (element.hasAttributeNS(KoXmlNS::table, "automatic-find-labels")) \
{
- d->automaticFindLabels = true;
- QString value = element.attributeNS(KoXmlNS::table, \
"automatic-find-labels", "true");
- if (value == "false")
- d->automaticFindLabels = false;
- } else if (element.hasAttributeNS(KoXmlNS::table, \
"use-regular-expressions")) {
- d->useRegularExpressions = true;
- QString value = element.attributeNS(KoXmlNS::table, \
"use-regular-expressions", "true");
- if (value == "false")
- d->useRegularExpressions = false;
- } else if (element.hasAttributeNS(KoXmlNS::table, "use-wildcards")) {
- d->useWildcards = false;
- QString value = element.attributeNS(KoXmlNS::table, "use-wildcards", \
"false");
- if (value == "true")
- d->useWildcards = true;
- } else if (element.hasAttributeNS(KoXmlNS::table, "null-year")) {
- d->refYear = 1930;
- QString value = element.attributeNS(KoXmlNS::table, "null-year", \
"1930");
- if (!value.isEmpty() && value != "1930") {
- bool ok;
- int refYear = value.toInt(&ok);
- if (ok)
- d->refYear = refYear;
- }
- }
-
- forEachElement(element, settings) {
- if (element.namespaceURI() != KoXmlNS::table)
- continue;
- else if (element.tagName() == "null-date") {
- d->refDate = QDate(1899, 12, 30);
- QString valueType = element.attributeNS(KoXmlNS::table, \
"value-type", "date");
- if (valueType == "date") {
- QString value = element.attributeNS(KoXmlNS::table, \
"date-value", "1899-12-30");
- QDate date = QDate::fromString(value, Qt::ISODate);
- if (date.isValid())
- d->refDate = date;
- } else {
- debugSheets << "CalculationSettings: Error on loading null \
date."
- << "Value type """ << valueType << """ not handled"
- << ", falling back to default." << endl;
- // NOTE Stefan: I don't know why different types are possible \
here!
- // sebsauer: because according to ODF-specs a zero null date can
- // mean QDate::currentDate(). Still unclear what a numeric value \
!=0
- // means through :-/
- }
- } else if (element.tagName() == "iteration") {
- // TODO
- }
- }
- }
-}
-
-bool CalculationSettings::saveOdf(KoXmlWriter &xmlWriter) const
-{
- xmlWriter.startElement("table:calculation-settings");
- if (!d->caseSensitiveComparisons)
- xmlWriter.addAttribute("table:case-sensitive", "false");
- if (d->precisionAsShown)
- xmlWriter.addAttribute("table:precision-as-shown", "true");
- if (!d->wholeCellSearchCriteria)
- xmlWriter.addAttribute("table:search-criteria-must-apply-to-whole-cell", \
"false");
- if (!d->automaticFindLabels)
- xmlWriter.addAttribute("table:automatic-find-labels", "false");
- if (!d->useRegularExpressions)
- xmlWriter.addAttribute("table:use-regular-expressions", "false");
- if (d->useWildcards)
- xmlWriter.addAttribute("table:use-wildcards", "true");
- if (d->refYear != 1930)
- xmlWriter.addAttribute("table:null-year", QString::number(d->refYear));
- xmlWriter.endElement();
- return true;
-}
-
KLocale* CalculationSettings::locale() const
{
return d->locale;
diff --git a/sheets/CalculationSettings.h b/sheets/CalculationSettings.h
index cc48ee8..585202f 100644
--- a/sheets/CalculationSettings.h
+++ b/sheets/CalculationSettings.h
@@ -32,14 +32,10 @@
#include "sheets_odf_export.h"
-#include <KoXmlReader.h>
-
#include <QDate>
class KLocale;
-class KoXmlWriter;
-
namespace Calligra
{
namespace Sheets
@@ -63,16 +59,6 @@ public:
~CalculationSettings();
/**
- * \ingroup OpenDocument
- */
- void loadOdf(const KoXmlElement& body);
-
- /**
- * \ingroup OpenDocument
- */
- bool saveOdf(KoXmlWriter &settingsWriter) const;
-
- /**
* A document could use a different localization as the KDE default.
* @return the KLocale associated with this document
*/
diff --git a/sheets/odf/SheetsOdfDoc.cpp b/sheets/odf/SheetsOdfDoc.cpp
index 2901cb3..cbc9612 100644
--- a/sheets/odf/SheetsOdfDoc.cpp
+++ b/sheets/odf/SheetsOdfDoc.cpp
@@ -316,6 +316,101 @@ bool Odf::paste(QBuffer &buffer, Map *map)
return result;
}
+void Odf::loadCalculationSettings(CalculationSettings *settings, const KoXmlElement& \
body) +{
+ KoXmlNode xmlsettings = KoXml::namedItemNS(body, KoXmlNS::table, \
"calculation-settings"); + debugSheets << "Calculation settings found?" << \
!xmlsettings.isNull(); + if (!xmlsettings.isNull()) {
+ KoXmlElement element = xmlsettings.toElement();
+ if (element.hasAttributeNS(KoXmlNS::table, "case-sensitive")) {
+ settings->setCaseSensitiveComparisons(Qt::CaseSensitive);
+ QString value = element.attributeNS(KoXmlNS::table, "case-sensitive", \
"true"); + if (value == "false")
+ settings->setCaseSensitiveComparisons(Qt::CaseInsensitive);
+ } else if (element.hasAttributeNS(KoXmlNS::table, "precision-as-shown")) {
+ settings->setPrecisionAsShown(false);
+ QString value = element.attributeNS(KoXmlNS::table, \
"precision-as-shown", "false"); + if (value == "true")
+ settings->setPrecisionAsShown(true);
+ } else if (element.hasAttributeNS(KoXmlNS::table, \
"search-criteria-must-apply-to-whole-cell")) { + \
settings->setWholeCellSearchCriteria(true); + QString value = \
element.attributeNS(KoXmlNS::table, "search-criteria-must-apply-to-whole-cell", \
"true"); + if (value == "false")
+ settings->setWholeCellSearchCriteria(false);
+ } else if (element.hasAttributeNS(KoXmlNS::table, "automatic-find-labels")) \
{ + settings->setAutomaticFindLabels(true);
+ QString value = element.attributeNS(KoXmlNS::table, \
"automatic-find-labels", "true"); + if (value == "false")
+ settings->setAutomaticFindLabels(false);
+ } else if (element.hasAttributeNS(KoXmlNS::table, \
"use-regular-expressions")) { + settings->setUseRegularExpressions(true);
+ QString value = element.attributeNS(KoXmlNS::table, \
"use-regular-expressions", "true"); + if (value == "false")
+ settings->setUseRegularExpressions(false);
+ } else if (element.hasAttributeNS(KoXmlNS::table, "use-wildcards")) {
+ settings->setUseWildcards(false);
+ QString value = element.attributeNS(KoXmlNS::table, "use-wildcards", \
"false"); + if (value == "true")
+ settings->setUseWildcards(true);
+ } else if (element.hasAttributeNS(KoXmlNS::table, "null-year")) {
+ settings->setReferenceYear(1930);
+ QString value = element.attributeNS(KoXmlNS::table, "null-year", \
"1930"); + if (!value.isEmpty() && value != "1930") {
+ bool ok;
+ int refYear = value.toInt(&ok);
+ if (ok)
+ settings->setReferenceYear(refYear);
+ }
+ }
+
+ forEachElement(element, xmlsettings) {
+ if (element.namespaceURI() != KoXmlNS::table)
+ continue;
+ else if (element.tagName() == "null-date") {
+ settings->setReferenceDate(QDate(1899, 12, 30));
+ QString valueType = element.attributeNS(KoXmlNS::table, \
"value-type", "date"); + if (valueType == "date") {
+ QString value = element.attributeNS(KoXmlNS::table, \
"date-value", "1899-12-30"); + QDate date = \
QDate::fromString(value, Qt::ISODate); + if (date.isValid())
+ settings->setReferenceDate(date);
+ } else {
+ debugSheets << "CalculationSettings: Error on loading null \
date." + << "Value type """ << valueType << """ not handled"
+ << ", falling back to default." << endl;
+ // NOTE Stefan: I don't know why different types are possible \
here! + // sebsauer: because according to ODF-specs a zero null \
date can + // mean QDate::currentDate(). Still unclear what a \
numeric value !=0 + // means through :-/
+ }
+ } else if (element.tagName() == "iteration") {
+ // TODO
+ }
+ }
+ }
+}
+
+bool Odf::saveCalculationSettings(const CalculationSettings *settings, KoXmlWriter \
&xmlWriter) +{
+ xmlWriter.startElement("table:calculation-settings");
+ if (!settings->caseSensitiveComparisons())
+ xmlWriter.addAttribute("table:case-sensitive", "false");
+ if (settings->precisionAsShown())
+ xmlWriter.addAttribute("table:precision-as-shown", "true");
+ if (!settings->wholeCellSearchCriteria())
+ xmlWriter.addAttribute("table:search-criteria-must-apply-to-whole-cell", \
"false"); + if (!settings->automaticFindLabels())
+ xmlWriter.addAttribute("table:automatic-find-labels", "false");
+ if (!settings->useRegularExpressions())
+ xmlWriter.addAttribute("table:use-regular-expressions", "false");
+ if (settings->useWildcards())
+ xmlWriter.addAttribute("table:use-wildcards", "true");
+ if (settings->referenceYear() != 1930)
+ xmlWriter.addAttribute("table:null-year", \
QString::number(settings->referenceYear())); + xmlWriter.endElement();
+ return true;
+}
+
diff --git a/sheets/odf/SheetsOdfMap.cpp b/sheets/odf/SheetsOdfMap.cpp
index 7afa463..884ddb0 100644
--- a/sheets/odf/SheetsOdfMap.cpp
+++ b/sheets/odf/SheetsOdfMap.cpp
@@ -158,8 +158,7 @@ bool Odf::loadMap(Map *map, const KoXmlElement& body, \
KoOdfLoadingContext& odfCo }
}
-#warning use new odf
- map->calculationSettings()->loadOdf(body); // table::calculation-settings
+ loadCalculationSettings(map->calculationSettings(), body); // \
table::calculation-settings if (body.hasAttributeNS(KoXmlNS::table, \
"structure-protected")) { loadProtection(map, body);
}
@@ -217,10 +216,8 @@ bool Odf::loadMap(Map *map, const KoXmlElement& body, \
KoOdfLoadingContext& odfCo
if (!sheetElement.attributeNS(KoXmlNS::table, "name", \
QString()).isEmpty()) {
QString name = sheetElement.attributeNS(KoXmlNS::table, "name", \
QString()); Sheet* sheet = map->findSheet(name);
- if (sheet) {
-#warning use new odf
+ if (sheet)
loadSheet(sheet, sheetElement, tableContext, autoStyles, \
conditionalStyles);
- }
}
}
}
@@ -288,8 +285,7 @@ bool Odf::saveMap(Map *map, KoXmlWriter & xmlWriter, \
KoShapeSavingContext & savi defaultRowStyle.setDefaultStyle(true);
savingContext.mainStyles().insert(defaultRowStyle, "Default", \
KoGenStyles::DontAddNumberToName);
-#warning TODO new style odf
- map->calculationSettings()->saveOdf(xmlWriter); // table::calculation-settings
+ saveCalculationSettings(map->calculationSettings(), xmlWriter); // \
table::calculation-settings
QByteArray password;
map->password(password);
diff --git a/sheets/odf/SheetsOdfPrivate.h b/sheets/odf/SheetsOdfPrivate.h
index 14a63ce..6a2ee7a 100644
--- a/sheets/odf/SheetsOdfPrivate.h
+++ b/sheets/odf/SheetsOdfPrivate.h
@@ -47,8 +47,14 @@
namespace Calligra {
namespace Sheets {
+class CalculationSettings;
+
namespace Odf {
+ // SheetsOdfDoc
+ void loadCalculationSettings(CalculationSettings *settings, const KoXmlElement& \
body); + bool saveCalculationSettings(const CalculationSettings *settings, \
KoXmlWriter &settingsWriter); +
// SheetsOdfMap
bool loadMap(Map *map, const KoXmlElement& body, KoOdfLoadingContext& \
odfContext); void loadMapSettings(Map *map, const KoOasisSettings &settingsDoc);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic