[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [calligra] /: Split out odf style loading/saving to the odf/ subdir
From: Tomas Mecir <mecirt () gmail ! com>
Date: 2016-03-06 17:21:11
Message-ID: E1accMh-0005vS-UH () scm ! kde ! org
[Download RAW message or body]
Git commit 6dfb7acdad4c76c6a3d3cb66d20f8217639d1e59 by Tomas Mecir.
Committed on 27/02/2016 at 18:31.
Pushed by mecir into branch 'master'.
Split out odf style loading/saving to the odf/ subdir
M +1 -1 filters/sheets/excel/import/ExcelImport.cpp
M +28 -1405 sheets/Style.cpp
M +5 -98 sheets/Style.h
M +9 -142 sheets/StyleManager.cpp
M +5 -30 sheets/StyleManager.h
M +3 -0 sheets/odf/SheetsOdf.h
M +3 -9 sheets/odf/SheetsOdfCell.cpp
M +1 -11 sheets/odf/SheetsOdfDoc.cpp
M +8 -28 sheets/odf/SheetsOdfMap.cpp
A +96 -0 sheets/odf/SheetsOdfPrivate.h [License: LGPL (v2+)]
M +1 -0 sheets/odf/SheetsOdfRegion.cpp
M +4 -25 sheets/odf/SheetsOdfSheet.cpp
M +1617 -0 sheets/odf/SheetsOdfStyle.cpp
http://commits.kde.org/calligra/6dfb7acdad4c76c6a3d3cb66d20f8217639d1e59
diff --git a/filters/sheets/excel/import/ExcelImport.cpp \
b/filters/sheets/excel/import/ExcelImport.cpp index c868756..5759b6f 100644
--- a/filters/sheets/excel/import/ExcelImport.cpp
+++ b/filters/sheets/excel/import/ExcelImport.cpp
@@ -1426,7 +1426,7 @@ void ExcelImport::Private::processNumberFormats()
Calligra::Sheets::Style& style = dataStyleCache[f->valueFormat()];
if (style.isEmpty()) {
Calligra::Sheets::Conditions conditions;
- style.loadOdfDataStyle(odfStyles, styleName, conditions, \
outputDoc->map()->styleManager(), outputDoc->map()->parser()); + \
Calligra::Sheets::Odf::loadDataStyle(&style, odfStyles, styleName, conditions, \
outputDoc->map()->styleManager(), outputDoc->map()->parser());
if (!conditions.isEmpty())
dataStyleConditions[f->valueFormat()] = conditions;
diff --git a/sheets/Style.cpp b/sheets/Style.cpp
index 74b8f2b..c53ee71 100644
--- a/sheets/Style.cpp
+++ b/sheets/Style.cpp
@@ -26,19 +26,9 @@
#include <QHash>
#include <QPen>
-#include <klocale.h>
-
-#include <KoGenStyles.h>
#include <KoGlobal.h>
-#include <KoOdfStylesReader.h>
-#include <KoOdfGraphicStyles.h>
-#include <KoStyleStack.h>
-#include <KoUnit.h>
-#include <KoXmlNS.h>
-#include <KoOdfWorkaround.h>
#include "SheetsDebug.h"
-#include "Condition.h"
#include "Currency.h"
#include "Global.h"
#include "StyleManager.h"
@@ -197,1352 +187,6 @@ bool Style::hasAttribute(Key key) const
return d->subStyles.contains(key);
}
-void Style::loadAttributes(const QList<SharedSubStyle>& subStyles)
-{
- d->subStyles.clear();
- for (int i = 0; i < subStyles.count(); ++i) {
- // already existing items are replaced
- d->subStyles.insert(subStyles[i]->type(), subStyles[i]);
- }
-}
-
-void Style::loadOdfStyle(KoOdfStylesReader& stylesReader, const KoXmlElement& \
element,
- Conditions& conditions, const StyleManager* styleManager,
- const ValueParser *parser)
-{
- // NOTE Stefan: Do not fill the style stack with the parent styles!
- KoStyleStack styleStack;
- styleStack.push(element);
-
- styleStack.setTypeProperties("table-cell");
- loadOdfTableCellProperties(stylesReader, styleStack);
-
- styleStack.setTypeProperties("text");
- loadOdfTextProperties(stylesReader, styleStack);
-
- styleStack.setTypeProperties("paragraph");
- loadOdfParagraphProperties(stylesReader, styleStack);
-
- KoXmlElement e;
- forEachElement(e, element) {
- if (e.namespaceURI() == KoXmlNS::style && e.localName() == "map")
- conditions.loadOdfConditions(e, parser, styleManager);
- }
-
- loadOdfDataStyle(stylesReader, element, conditions, styleManager, parser);
-}
-
-typedef QPair<QString,QString> StringPair;
-
-void Style::loadOdfDataStyle(KoOdfStylesReader& stylesReader, const KoXmlElement& \
element,
- Conditions& conditions, const StyleManager* \
styleManager,
- const ValueParser *parser)
-{
- QString str;
- if (element.hasAttributeNS(KoXmlNS::style, "data-style-name")) {
- const QString styleName = element.attributeNS(KoXmlNS::style, \
"data-style-name", QString());
- loadOdfDataStyle(stylesReader, styleName, conditions, styleManager, parser);
- }
-}
-
-void Style::loadOdfDataStyle(KoOdfStylesReader &stylesReader, const QString \
&styleName, Conditions &conditions, const StyleManager *styleManager, const \
ValueParser *parser)
-{
- if (stylesReader.dataFormats().contains(styleName)) {
- Style* theStyle = this;
-
- QPair<KoOdfNumberStyles::NumericStyleFormat, KoXmlElement*> dataStylePair = \
stylesReader.dataFormats()[styleName];
-
- const KoOdfNumberStyles::NumericStyleFormat& dataStyle = \
dataStylePair.first;
- const QList<QPair<QString,QString> > styleMaps = dataStyle.styleMaps;
- if(styleMaps.count() > 0) {
- theStyle = new Style();
- for (QList<QPair<QString,QString> >::const_iterator it = \
styleMaps.begin(); it != styleMaps.end(); ++it) {
- const Conditional c = conditions.loadOdfCondition(it->first, \
it->second, QString(), parser);
- if (styleManager->style(c.styleName) == 0) {
- CustomStyle* const s = new CustomStyle(c.styleName);
- s->loadOdfDataStyle(stylesReader, c.styleName, conditions, \
styleManager, parser);
- const_cast<StyleManager*>(styleManager)->insertStyle(s);
- }
- }
- }
-
- KoStyleStack styleStack;
- styleStack.push(*dataStylePair.second);
- styleStack.setTypeProperties("text");
- theStyle->loadOdfTextProperties(stylesReader, styleStack);
-
- QString tmp = dataStyle.prefix;
- if (!tmp.isEmpty()) {
- theStyle->setPrefix(tmp);
- }
- tmp = dataStyle.suffix;
- if (!tmp.isEmpty()) {
- theStyle->setPostfix(tmp);
- }
- // determine data formatting
- switch (dataStyle.type) {
- case KoOdfNumberStyles::Number:
- theStyle->setFormatType(Format::Number);
- if (!dataStyle.currencySymbol.isEmpty())
- theStyle->setCurrency(numberCurrency(dataStyle.currencySymbol));
- else
- theStyle->setCurrency(numberCurrency(dataStyle.formatStr));
- break;
- case KoOdfNumberStyles::Scientific:
- theStyle->setFormatType(Format::Scientific);
- break;
- case KoOdfNumberStyles::Currency:
- debugSheetsODF << " currency-symbol:" << dataStyle.currencySymbol;
- if (!dataStyle.currencySymbol.isEmpty())
- theStyle->setCurrency(numberCurrency(dataStyle.currencySymbol));
- else
- theStyle->setCurrency(numberCurrency(dataStyle.formatStr));
- break;
- case KoOdfNumberStyles::Percentage:
- theStyle->setFormatType(Format::Percentage);
- break;
- case KoOdfNumberStyles::Fraction:
- // determine format of fractions, dates and times by using the
- // formatting string
- tmp = dataStyle.formatStr;
- if (!tmp.isEmpty()) {
- theStyle->setFormatType(Style::fractionType(tmp));
- }
- break;
- case KoOdfNumberStyles::Date:
- // determine format of fractions, dates and times by using the
- // formatting string
- tmp = dataStyle.formatStr;
- if (!tmp.isEmpty()) {
- theStyle->setFormatType(Style::dateType(tmp));
- }
- break;
- case KoOdfNumberStyles::Time:
- // determine format of fractions, dates and times by using the
- // formatting string
- tmp = dataStyle.formatStr;
- if (!tmp.isEmpty()) {
- theStyle->setFormatType(Style::timeType(tmp));
- }
- break;
- case KoOdfNumberStyles::Boolean:
- theStyle->setFormatType(Format::Number);
- break;
- case KoOdfNumberStyles::Text:
- theStyle->setFormatType(Format::Text);
- break;
- }
-
- if (dataStyle.precision > -1) {
- // special handling for precision
- // The Style default (-1) and the storage default (0) differ.
- // The maximum is 10. Replace the Style value 0 with -11, which always \
results
- // in a storage value < 0 and is interpreted as Style value 0.
- int precision = dataStyle.precision;
- if (type() == AUTO && precision == 0)
- precision = -11;
- theStyle->setPrecision(precision);
- }
-
- theStyle->setThousandsSep(dataStyle.thousandsSep);
-
- theStyle->setCustomFormat(dataStyle.formatStr);
-
- if(styleMaps.count() > 0) {
- conditions.setDefaultStyle(*theStyle);
- delete theStyle;
- }
- }
-}
-
-QString encodePen(const QPen & pen)
-{
-// debugSheets<<"encodePen( const QPen & pen ) :"<<pen;
- // NOTE Stefan: QPen api docs:
- // A line width of zero indicates a cosmetic pen. This means
- // that the pen width is always drawn one pixel wide,
- // independent of the transformation set on the painter.
- QString s = QString("%1pt ").arg((pen.width() == 0) ? 1 : pen.width());
- switch (pen.style()) {
- case Qt::NoPen:
- return "none";
- case Qt::SolidLine:
- s += "solid";
- break;
- case Qt::DashLine:
- s += "dashed";
- break;
- case Qt::DotLine:
- s += "dotted";
- break;
- case Qt::DashDotLine:
- s += "dot-dash";
- break;
- case Qt::DashDotDotLine:
- s += "dot-dot-dash";
- break;
- default: break;
- }
- //debugSheets << " encodePen :" << s;
- if (pen.color().isValid()) {
- s += ' ' + Style::colorName(pen.color());
- }
- return s;
-}
-
-QPen decodePen(const QString &border)
-{
- QPen pen;
- //string like "0.088cm solid #800000"
- if (border.isEmpty() || border == "none" || border == "hidden") { // in fact no \
border
- pen.setStyle(Qt::NoPen);
- return pen;
- }
- //code from koborder, for the moment Calligra Sheets doesn't use koborder
- // ## isn't it faster to use QStringList::split than parse it 3 times?
- QString _width = border.section(' ', 0, 0);
- QByteArray _style = border.section(' ', 1, 1).toLatin1();
- QString _color = border.section(' ', 2, 2);
-
- pen.setWidth((int)(KoUnit::parseValue(_width, 1.0)));
-
- if (_style == "none")
- pen.setStyle(Qt::NoPen);
- else if (_style == "solid")
- pen.setStyle(Qt::SolidLine);
- else if (_style == "dashed")
- pen.setStyle(Qt::DashLine);
- else if (_style == "dotted")
- pen.setStyle(Qt::DotLine);
- else if (_style == "dot-dash")
- pen.setStyle(Qt::DashDotLine);
- else if (_style == "dot-dot-dash")
- pen.setStyle(Qt::DashDotDotLine);
- else
- debugSheets << " style undefined :" << _style;
-
- if (_color.isEmpty())
- pen.setColor(QColor());
- else
- pen.setColor(QColor(_color));
-
- return pen;
-}
-
-
-void Style::loadOdfParagraphProperties(KoOdfStylesReader& stylesReader, const \
KoStyleStack& styleStack)
-{
- Q_UNUSED(stylesReader);
- debugSheetsODF << "\t paragraph-properties";
- if (styleStack.hasProperty(KoXmlNS::fo, "text-align")) {
- QString str = styleStack.property(KoXmlNS::fo, "text-align");
- if (str == "center")
- setHAlign(Style::Center);
- else if (str == "end" || str=="right")
- setHAlign(Style::Right);
- else if (str == "start" || str=="left")
- setHAlign(Style::Left);
- else if (str == "justify")
- setHAlign(Style::Justified);
- else
- setHAlign(Style::HAlignUndefined);
- debugSheetsODF << "\t\t text-align:" << str;
- }
-
- if (styleStack.hasProperty(KoXmlNS::fo, "margin-left")) {
- //todo fix me
- setIndentation(KoUnit::parseValue(styleStack.property(KoXmlNS::fo, \
"margin-left"), 0.0));
- }
-}
-
-void Style::loadOdfTableCellProperties(KoOdfStylesReader& stylesReader, const \
KoStyleStack& styleStack)
-{
- QString str;
- if (styleStack.hasProperty(KoXmlNS::style, "vertical-align")) {
- str = styleStack.property(KoXmlNS::style, "vertical-align");
- if (str == "bottom")
- setVAlign(Style::Bottom);
- else if (str == "top")
- setVAlign(Style::Top);
- else if (str == "middle")
- setVAlign(Style::Middle);
- else
- setVAlign(Style::VAlignUndefined);
- }
- if (styleStack.property(KoXmlNS::calligra, "vertical-distributed") == \
"distributed") {
- if (valign() == Style::Top)
- setVAlign(Style::VJustified);
- else
- setVAlign(Style::VDistributed);
- }
- if (styleStack.hasProperty(KoXmlNS::fo, "background-color")) {
- str = styleStack.property(KoXmlNS::fo, "background-color");
- if (str == "transparent") {
- debugSheetsODF << "\t\t fo:background-color: transparent";
- setBackgroundColor(QColor());
- } else {
- QColor color(str);
- if (color.isValid()) {
- debugSheetsODF << "\t\t fo:background-color:" << color.name();
- setBackgroundColor(color);
- }
- }
- }
-
- if (styleStack.hasProperty(KoXmlNS::fo, "wrap-option") && \
(styleStack.property(KoXmlNS::fo, "wrap-option") == "wrap")) {
- setWrapText(true);
- }
- if (styleStack.hasProperty(KoXmlNS::style, "cell-protect")) {
- str = styleStack.property(KoXmlNS::style, "cell-protect");
-#ifndef NWORKAROUND_ODF_BUGS
- KoOdfWorkaround::fixBadFormulaHiddenForStyleCellProtect(str);
-#endif
- if (str == "none")
- setNotProtected(true);
- else if (str == "hidden-and-protected")
- setHideAll(true);
- else if (str == "protected formula-hidden" || str == "formula-hidden \
protected")
- setHideFormula(true);
- else if (str == "formula-hidden") {
- setNotProtected(true);
- setHideFormula(true);
- }
- }
- if (styleStack.hasProperty(KoXmlNS::style, "print-content") &&
- (styleStack.property(KoXmlNS::style, "print-content") == "false")) {
- setDontPrintText(true);
- }
- if (styleStack.hasProperty(KoXmlNS::style, "shrink-to-fit") &&
- (styleStack.property(KoXmlNS::style, "shrink-to-fit") == "true")) {
- setShrinkToFit(true);
- }
- if (styleStack.hasProperty(KoXmlNS::style, "direction") &&
- (styleStack.property(KoXmlNS::style, "direction") == "ttb")) {
- setVerticalText(true);
- }
- if (styleStack.hasProperty(KoXmlNS::style, "rotation-angle")) {
- bool ok;
- int a = styleStack.property(KoXmlNS::style, "rotation-angle").toInt(&ok);
- debugSheetsODF << " rotation-angle :" << a;
- if (a != 0) {
- setAngle(-a);
- }
- }
- if (styleStack.hasProperty(KoXmlNS::fo, "border")) {
- str = styleStack.property(KoXmlNS::fo, "border");
- QPen pen = decodePen(str);
- setLeftBorderPen(pen);
- setTopBorderPen(pen);
- setBottomBorderPen(pen);
- setRightBorderPen(pen);
- }
- if (styleStack.hasProperty(KoXmlNS::fo, "border-left")) {
- str = styleStack.property(KoXmlNS::fo, "border-left");
- setLeftBorderPen(decodePen(str));
- }
- if (styleStack.hasProperty(KoXmlNS::fo, "border-right")) {
- str = styleStack.property(KoXmlNS::fo, "border-right");
- setRightBorderPen(decodePen(str));
- }
- if (styleStack.hasProperty(KoXmlNS::fo, "border-top")) {
- str = styleStack.property(KoXmlNS::fo, "border-top");
- setTopBorderPen(decodePen(str));
- }
- if (styleStack.hasProperty(KoXmlNS::fo, "border-bottom")) {
- str = styleStack.property(KoXmlNS::fo, "border-bottom");
- setBottomBorderPen(decodePen(str));
- }
- if (styleStack.hasProperty(KoXmlNS::style, "diagonal-tl-br")) {
- str = styleStack.property(KoXmlNS::style, "diagonal-tl-br");
- setFallDiagonalPen(decodePen(str));
- }
- if (styleStack.hasProperty(KoXmlNS::style, "diagonal-bl-tr")) {
- str = styleStack.property(KoXmlNS::style, "diagonal-bl-tr");
- setGoUpDiagonalPen(decodePen(str));
- }
-
- if (styleStack.hasProperty(KoXmlNS::draw, "style-name") || \
styleStack.hasProperty(KoXmlNS::calligra, "fill-style-name")) {
- QString styleName = styleStack.hasProperty(KoXmlNS::calligra, \
"fill-style-name") ? styleStack.property(KoXmlNS::calligra, \
"fill-style-name")
- : styleStack.property(KoXmlNS::draw, "style-name");
- debugSheetsODF << " style name :" << styleName;
-
- const KoXmlElement * style = stylesReader.findStyle(styleName, "graphic");
- debugSheetsODF << " style :" << style;
- if (style) {
- KoStyleStack drawStyleStack;
- drawStyleStack.push(*style);
- drawStyleStack.setTypeProperties("graphic");
- if (drawStyleStack.hasProperty(KoXmlNS::draw, "fill")) {
- const QString fill = drawStyleStack.property(KoXmlNS::draw, "fill");
- debugSheetsODF << " load object gradient fill type :" << fill;
-
- if (fill == "solid" || fill == "hatch") {
- debugSheetsODF << " Style \
******************************************************";
- \
setBackgroundBrush(KoOdfGraphicStyles::loadOdfFillStyle(drawStyleStack, fill, \
stylesReader));
-
- } else
- debugSheetsODF << " fill style not supported into kspread :" << \
fill;
- }
- }
- }
-}
-
-void Style::loadOdfTextProperties(KoOdfStylesReader& stylesReader, const \
KoStyleStack& styleStack)
-{
- Q_UNUSED(stylesReader);
- // fo:font-size="13pt"
- // fo:font-style="italic"
- // style:text-underline="double"
- // style:text-underline-color="font-color"
- // fo:font-weight="bold"
- debugSheetsODF << "\t text-properties";
- if (styleStack.hasProperty(KoXmlNS::fo, "font-family")) {
- setFontFamily(styleStack.property(KoXmlNS::fo, "font-family")); // FIXME \
Stefan: sanity check
- debugSheetsODF << "\t\t fo:font-family:" << fontFamily();
- }
- if (styleStack.hasProperty(KoXmlNS::fo, "font-size")) {
- setFontSize((int) KoUnit::parseValue(styleStack.property(KoXmlNS::fo, \
"font-size"), 10.0)); // FIXME Stefan: fallback to default
- debugSheetsODF << "\t\t fo:font-size:" << fontSize();
- }
- if (styleStack.hasProperty(KoXmlNS::fo, "font-style")) {
- if (styleStack.property(KoXmlNS::fo, "font-style") == "italic") { // \
"normal", "oblique"
- setFontItalic(true);
- debugSheetsODF << "\t\t fo:font-style:" << "italic";
- }
- }
- if (styleStack.hasProperty(KoXmlNS::fo, "font-weight")) {
- if (styleStack.property(KoXmlNS::fo, "font-weight") == "bold") { // \
"normal", "100", "200", ...
- setFontBold(true);
- debugSheetsODF << "\t\t fo:font-weight:" << "bold";
- }
- }
- if (styleStack.hasProperty(KoXmlNS::style, "text-underline-style")) {
- if (styleStack.property(KoXmlNS::style, "text-underline-style") != "none") {
- setFontUnderline(true);
- debugSheetsODF << "\t\t style:text-underline-style:" << "solid \
(actually: !none)";
- }
- }
- if (styleStack.hasProperty(KoXmlNS::style, "text-underline-width")) {
- //TODO
- }
- if (styleStack.hasProperty(KoXmlNS::style, "text-underline-color")) {
- //TODO
- }
- if (styleStack.hasProperty(KoXmlNS::fo, "color")) {
- QColor color = QColor(styleStack.property(KoXmlNS::fo, "color"));
- if (color.isValid()) {
- setFontColor(color);
- debugSheetsODF << "\t\t fo:color:" << color.name();
- }
- }
- if (styleStack.hasProperty(KoXmlNS::style, "text-line-through-style")) {
- if (styleStack.property(KoXmlNS::style, "text-line-through-style") != "none"
- /*&& styleStack.property("text-line-through-style")=="solid"*/) {
- setFontStrikeOut(true);
- debugSheetsODF << "\t\t text-line-through-style:" << "solid (actually: \
!none)";
- }
- }
- if (styleStack.hasProperty(KoXmlNS::style, "font-name")) {
- QString fontName = styleStack.property(KoXmlNS::style, "font-name");
- debugSheetsODF << "\t\t style:font-name:" << fontName;
- const KoXmlElement * style = stylesReader.findStyle(fontName);
- // TODO: sanity check that it is a font-face style?
- debugSheetsODF << "\t\t\t style:" << style;
- if (style) {
- setFontFamily(style->attributeNS(KoXmlNS::svg, "font-family"));
- debugSheetsODF << "\t\t\t svg:font-family:" << fontFamily();
- }
- }
-}
-
-static QString convertDateFormat(const QString& date)
-{
- QString result = date;
- result.replace("%Y", "yyyy");
- result.replace("%y", "yy");
- result.replace("%n", "M");
- result.replace("%m", "MM");
- result.replace("%e", "d");
- result.replace("%d", "dd");
- result.replace("%b", "MMM");
- result.replace("%B", "MMMM");
- result.replace("%a", "ddd");
- result.replace("%A", "dddd");
- return result;
-}
-
-Format::Type Style::dateType(const QString &_f)
-{
- const QString dateFormatShort = \
convertDateFormat(KLocale::global()->dateFormatShort());
- const QString dateFormat = convertDateFormat(KLocale::global()->dateFormat());
- QString _format = _f;
- _format.replace(' ', '-');
-
- if (_format == "d-MMM-yy" || _format == "dd-MMM-yy")
- return Format::Date1;
- else if (_format == "dd-MMM-yyyy")
- return Format::Date2;
- else if (_format == "d-MM")
- return Format::Date3;
- else if (_format == "dd-MM") //TODO ???????
- return Format::Date4;
- else if (_format == "dd/MM/yy")
- return Format::Date5;
- else if (_format == "dd/MM/yyyy")
- return Format::Date6;
- else if (_format == "MMM-yy")
- return Format::Date7;
- else if (_format == "MMMM-yy")
- return Format::Date8;
- else if (_format == "MMMM-yyyy")
- return Format::Date9;
- else if (_format == "MMMMM-yy" || _format == "X-yy")
- return Format::Date10;
- else if (_format == "dd/MMM")
- return Format::Date11;
- else if (_format == "dd/MM")
- return Format::Date12;
- else if (_format == "dd/MMM/yyyy")
- return Format::Date13;
- else if (_format == "yyyy/MMM/dd")
- return Format::Date14;
- else if (_format == "yyyy-MMM-dd")
- return Format::Date15;
- else if (_format == "yyyy-MM-dd")
- return Format::Date16;
- else if (_format == "d MMMM yyyy")
- return Format::Date17;
- else if (_format == "MM/dd/yyyy")
- return Format::Date18;
- else if (_format == "MM/dd/yy")
- return Format::Date19;
- else if (_format == "MMM/dd/yy")
- return Format::Date20;
- else if (_format == "MMM/dd/yyyy")
- return Format::Date21;
- else if (_format == "MMM-yyyy")
- return Format::Date22;
- else if (_format == "yyyy")
- return Format::Date23;
- else if (_format == "yy")
- return Format::Date24;
- else if (_format == "yyyy/MM/dd")
- return Format::Date25;
- else if (_format == "yyyy/MMM/dd")
- return Format::Date26;
- else if (_format == "MMM/yy")
- return Format::Date27;
- else if (_format == "MMM/yyyy")
- return Format::Date28;
- else if (_format == "MMMM/yy")
- return Format::Date29;
- else if (_format == "MMMM/yyyy")
- return Format::Date30;
- else if (_format == "dd-MM")
- return Format::Date31;
- else if (_format == "MM/yy")
- return Format::Date32;
- else if (_format == "MM-yy")
- return Format::Date33;
- else if (QRegExp("^[d]+[\\s]*[d]{1,2}[\\s]+[M]{1,4}[\\s]+[y]{2,2}$").indexIn(_f) \
>= 0)
- return Format::Date34;
- else if (QRegExp("^[d]+[\\s]*[d]{1,2}[\\s]+[M]{1,}[\\s]+[y]{2,4}$").indexIn(_f) \
>= 0)
- return Format::Date35;
- else if (_format == dateFormatShort)
- return Format::ShortDate;
- else if (_format == dateFormat)
- return Format::TextDate;
- else {
- debugSheets << "Unhandled date format=" << _format;
- return Format::ShortDate;
- }
-}
-
-Format::Type Style::timeType(const QString &_format)
-{
- if (_format == "h:mm AP")
- return Format::Time1;
- else if (_format == "h:mm:ss AP")
- return Format::Time2;
- else if (_format == "hh \\h mm \\m\\i\\n ss \\s")
- return Format::Time3;
- else if (_format == "hh:mm")
- return Format::Time4;
- else if (_format == "hh:mm:ss")
- return Format::Time5;
- else if (_format == "m:ss")
- return Format::Time6;
- else if (_format == "h:mm:ss")
- return Format::Time7;
- else if (_format == "h:mm")
- return Format::Time8;
- else
- return Format::Time;
-}
-
-Currency Style::numberCurrency(const QString &_format)
-{
- // Look up if a prefix or postfix is in the currency table,
- // return the currency symbol to use for formatting purposes.
- if(!_format.isEmpty()) {
- QString f = QString(_format.at(0));
- Currency currStart = Currency(f);
- if (currStart.index() > 1)
- return currStart;
- f = QString(_format.at(_format.size()-1));
- Currency currEnd = Currency(f);
- if (currEnd.index() > 1)
- return currEnd;
- }
- return Currency(QString());
-}
-
-Format::Type Style::fractionType(const QString &_format)
-{
- if (_format.endsWith(QLatin1String("/2")))
- return Format::fraction_half;
- else if (_format.endsWith(QLatin1String("/4")))
- return Format::fraction_quarter;
- else if (_format.endsWith(QLatin1String("/8")))
- return Format::fraction_eighth;
- else if (_format.endsWith(QLatin1String("/16")))
- return Format::fraction_sixteenth;
- else if (_format.endsWith(QLatin1String("/10")))
- return Format::fraction_tenth;
- else if (_format.endsWith(QLatin1String("/100")))
- return Format::fraction_hundredth;
- else if (_format.endsWith(QLatin1String("/?")))
- return Format::fraction_one_digit;
- else if (_format.endsWith(QLatin1String("/??")))
- return Format::fraction_two_digits;
- else if (_format.endsWith(QLatin1String("/???")))
- return Format::fraction_three_digits;
- else
- return Format::fraction_three_digits;
-}
-
-QString Style::saveOdfStyleNumeric(KoGenStyle &style, KoGenStyles &mainStyles,
- Format::Type _style,
- const QString &_prefix, const QString &_postfix,
- int _precision, const QString& symbol,
- bool thousandsSep)
-{
-// debugSheetsODF ;
- QString styleName;
- QString valueType;
- switch (_style) {
- case Format::Number:
- styleName = saveOdfStyleNumericNumber(mainStyles, _style, _precision, \
_prefix, _postfix, thousandsSep);
- valueType = "float";
- break;
- case Format::Text:
- styleName = saveOdfStyleNumericText(mainStyles, _style, _precision, _prefix, \
_postfix);
- valueType = "string";
- break;
- case Format::Money:
- styleName = saveOdfStyleNumericMoney(mainStyles, _style, symbol, _precision, \
_prefix, _postfix);
- valueType = "currency";
- break;
- case Format::Percentage:
- styleName = saveOdfStyleNumericPercentage(mainStyles, _style, _precision, \
_prefix, _postfix);
- valueType = "percentage";
- break;
- case Format::Scientific:
- styleName = saveOdfStyleNumericScientific(mainStyles, _style, _prefix, \
_postfix, _precision, thousandsSep);
- valueType = "float";
- break;
- case Format::ShortDate:
- case Format::TextDate:
- styleName = saveOdfStyleNumericDate(mainStyles, _style, _prefix, _postfix);
- valueType = "date";
- break;
- case Format::Time:
- case Format::SecondeTime:
- case Format::Time1:
- case Format::Time2:
- case Format::Time3:
- case Format::Time4:
- case Format::Time5:
- case Format::Time6:
- case Format::Time7:
- case Format::Time8:
- styleName = saveOdfStyleNumericTime(mainStyles, _style, _prefix, _postfix);
- valueType = "time";
- break;
- case Format::fraction_half:
- case Format::fraction_quarter:
- case Format::fraction_eighth:
- case Format::fraction_sixteenth:
- case Format::fraction_tenth:
- case Format::fraction_hundredth:
- case Format::fraction_one_digit:
- case Format::fraction_two_digits:
- case Format::fraction_three_digits:
- styleName = saveOdfStyleNumericFraction(mainStyles, _style, _prefix, \
_postfix);
- valueType = "float";
- break;
- case Format::Date1:
- case Format::Date2:
- case Format::Date3:
- case Format::Date4:
- case Format::Date5:
- case Format::Date6:
- case Format::Date7:
- case Format::Date8:
- case Format::Date9:
- case Format::Date10:
- case Format::Date11:
- case Format::Date12:
- case Format::Date13:
- case Format::Date14:
- case Format::Date15:
- case Format::Date16:
- case Format::Date17:
- case Format::Date18:
- case Format::Date19:
- case Format::Date20:
- case Format::Date21:
- case Format::Date22:
- case Format::Date23:
- case Format::Date24:
- case Format::Date25:
- case Format::Date26:
- case Format::Date27:
- case Format::Date28:
- case Format::Date29:
- case Format::Date30:
- case Format::Date31:
- case Format::Date32:
- case Format::Date33:
- case Format::Date34:
- case Format::Date35:
- styleName = saveOdfStyleNumericDate(mainStyles, _style, _prefix, _postfix);
- valueType = "date";
- break;
- case Format::Custom:
- styleName = saveOdfStyleNumericCustom(mainStyles, _style, _prefix, \
_postfix);
- break;
- case Format::Generic:
- case Format::None:
- if (_precision > -1 || !_prefix.isEmpty() || !_postfix.isEmpty()) {
- styleName = saveOdfStyleNumericNumber(mainStyles, _style, _precision, \
_prefix, _postfix, thousandsSep);
- valueType = "float";
- }
- break;
- case Format::DateTime:
- default:
- ;
- }
- if (!styleName.isEmpty()) {
- style.addAttribute("style:data-style-name", styleName);
- }
- return styleName;
-}
-
-QString Style::saveOdfStyleNumericNumber(KoGenStyles& mainStyles, Format::Type \
/*_style*/, int _precision,
- const QString& _prefix, const QString& _postfix, bool thousandsSep)
-{
- QString format;
- if (_precision == -1)
- format = '0';
- else {
- QString tmp;
- for (int i = 0; i < _precision; i++) {
- tmp += '0';
- }
- format = "0." + tmp;
- }
- return KoOdfNumberStyles::saveOdfNumberStyle(mainStyles, format, _prefix, \
_postfix, thousandsSep);
-}
-
-QString Style::saveOdfStyleNumericText(KoGenStyles& /*mainStyles*/, Format::Type \
/*_style*/, int /*_precision*/,
- const QString& /*_prefix*/, const QString& \
/*_postfix*/)
-{
- return "";
-}
-
-QString Style::saveOdfStyleNumericMoney(KoGenStyles& mainStyles, Format::Type \
/*_style*/,
- const QString& symbol, int _precision,
- const QString& _prefix, const QString& \
_postfix)
-{
- QString format;
- if (_precision == -1)
- format = '0';
- else {
- QString tmp;
- for (int i = 0; i < _precision; i++) {
- tmp += '0';
- }
- format = "0." + tmp;
- }
- return KoOdfNumberStyles::saveOdfCurrencyStyle(mainStyles, format, symbol, \
_prefix, _postfix);
-}
-
-QString Style::saveOdfStyleNumericPercentage(KoGenStyles&mainStyles, Format::Type \
/*_style*/, int _precision,
- const QString& _prefix, const QString& _postfix)
-{
- //<number:percentage-style style:name="N106" style:family="data-style">
- //<number:number number:decimal-places="6" number:min-integer-digits="1"/>
- //<number:text>%</number:text>
- //</number:percentage-style>
- //TODO add decimal etc.
- QString format;
- if (_precision == -1)
- format = '0';
- else {
- QString tmp;
- for (int i = 0; i < _precision; i++) {
- tmp += '0';
- }
- format = "0." + tmp;
- }
- return KoOdfNumberStyles::saveOdfPercentageStyle(mainStyles, format, _prefix, \
_postfix);
-}
-
-
-QString Style::saveOdfStyleNumericScientific(KoGenStyles&mainStyles, Format::Type \
/*_style*/,
- const QString &_prefix, const QString &_suffix, int _precision, bool \
thousandsSep)
-{
- //<number:number-style style:name="N60" style:family="data-style">
- // <number:scientific-number number:decimal-places="2" \
number:min-integer-digits="1" number:min-exponent-digits="3"/>
- //</number:number-style>
- QString format;
- if (_precision == -1)
- format = "0E+00";
- else {
- QString tmp;
- for (int i = 0; i < _precision; i++) {
- tmp += '0';
- }
- format = "0." + tmp + "E+00";
- }
- return KoOdfNumberStyles::saveOdfScientificStyle(mainStyles, format, _prefix, \
_suffix, thousandsSep);
-}
-
-QString Style::saveOdfStyleNumericDate(KoGenStyles&mainStyles, Format::Type _style,
- const QString& _prefix, const QString& \
_postfix)
-{
- QString format;
- bool locale = false;
- switch (_style) {
- //TODO fixme use locale of Calligra Sheets and not kglobal
- case Format::ShortDate:
- format = KLocale::global()->dateFormatShort();
- locale = true;
- break;
- case Format::TextDate:
- format = KLocale::global()->dateFormat();
- locale = true;
- break;
- case Format::Date1:
- format = "dd-MMM-yy";
- break;
- case Format::Date2:
- format = "dd-MMM-yyyy";
- break;
- case Format::Date3:
- format = "dd-M";
- break;
- case Format::Date4:
- format = "dd-MM";
- break;
- case Format::Date5:
- format = "dd/MM/yy";
- break;
- case Format::Date6:
- format = "dd/MM/yyyy";
- break;
- case Format::Date7:
- format = "MMM-yy";
- break;
- case Format::Date8:
- format = "MMMM-yy";
- break;
- case Format::Date9:
- format = "MMMM-yyyy";
- break;
- case Format::Date10:
- format = "MMMMM-yy";
- break;
- case Format::Date11:
- format = "dd/MMM";
- break;
- case Format::Date12:
- format = "dd/MM";
- break;
- case Format::Date13:
- format = "dd/MMM/yyyy";
- break;
- case Format::Date14:
- format = "yyyy/MMM/dd";
- break;
- case Format::Date15:
- format = "yyyy-MMM-dd";
- break;
- case Format::Date16:
- format = "yyyy/MM/dd";
- break;
- case Format::Date17:
- format = "d MMMM yyyy";
- break;
- case Format::Date18:
- format = "MM/dd/yyyy";
- break;
- case Format::Date19:
- format = "MM/dd/yy";
- break;
- case Format::Date20:
- format = "MMM/dd/yy";
- break;
- case Format::Date21:
- format = "MMM/dd/yyyy";
- break;
- case Format::Date22:
- format = "MMM-yyyy";
- break;
- case Format::Date23:
- format = "yyyy";
- break;
- case Format::Date24:
- format = "yy";
- break;
- case Format::Date25:
- format = "yyyy/MM/dd";
- break;
- case Format::Date26:
- format = "yyyy/MMM/dd";
- break;
- case Format::Date27:
- format = "MMM/yy";
- break;
- case Format::Date28:
- format = "MMM/yyyy";
- break;
- case Format::Date29:
- format = "MMMM/yy";
- break;
- case Format::Date30:
- format = "MMMM/yyyy";
- break;
- case Format::Date31:
- format = "dd-MM";
- break;
- case Format::Date32:
- format = "MM/yy";
- break;
- case Format::Date33:
- format = "MM-yy";
- break;
- case Format::Date34:
- format = "ddd d MMM yyyy";
- break;
- case Format::Date35:
- format = "dddd d MMM yyyy";
- break;
- default:
- debugSheetsODF << "this date format is not defined ! :" << _style;
- break;
- }
- return KoOdfNumberStyles::saveOdfDateStyle(mainStyles, format, locale, _prefix, \
_postfix);
-}
-
-QString Style::saveOdfStyleNumericCustom(KoGenStyles& /*mainStyles*/, Format::Type \
/*_style*/,
- const QString& /*_prefix*/, const QString& /*_postfix*/)
-{
- //TODO
- //<number:date-style style:name="N50" style:family="data-style" \
number:automatic-order="true" number:format-source="language">
- //<number:month/>
- //<number:text>/</number:text>
- //<number:day/>
- //<number:text>/</number:text>
- //<number:year/>
- //<number:text> </number:text>
- //<number:hours number:style="long"/>
- //<number:text>:</number:text>
- //<number:minutes number:style="long"/>
- // <number:text> </number:text>
- //<number:am-pm/>
- //</number:date-style>
- return "";
-}
-
-QString Style::saveOdfStyleNumericTime(KoGenStyles& mainStyles, Format::Type _style,
- const QString& _prefix, const QString& \
_postfix)
-{
- //<number:time-style style:name="N42" style:family="data-style">
- //<number:hours number:style="long"/>
- //<number:text>:</number:text>
- //<number:minutes number:style="long"/>
- //<number:text> </number:text>
- //<number:am-pm/>
- //</number:time-style>
-
- QString format;
- bool locale = false;
- //TODO use format
- switch (_style) {
- case Format::Time: //TODO FIXME
- format = "hh:mm:ss";
- break;
- case Format::SecondeTime: //TODO FIXME
- format = "hh:mm";
- break;
- case Format::Time1:
- format = "h:mm AP";
- break;
- case Format::Time2:
- format = "h:mm:ss AP";
- break;
- case Format::Time3: // 9 h 01 min 28 s
- format = "hh \\h mm \\m\\i\\n ss \\s";
- break;
- case Format::Time4:
- format = "hh:mm";
- break;
- case Format::Time5:
- format = "hh:mm:ss";
- break;
- case Format::Time6:
- format = "m:ss";
- break;
- case Format::Time7:
- format = "h:mm:ss";
- break;
- case Format::Time8:
- format = "h:mm";
- break;
- default:
- debugSheetsODF << "time format not defined :" << _style;
- break;
- }
- return KoOdfNumberStyles::saveOdfTimeStyle(mainStyles, format, locale, _prefix, \
_postfix);
-}
-
-
-QString Style::saveOdfStyleNumericFraction(KoGenStyles &mainStyles, Format::Type \
formatType,
- const QString &_prefix, const QString &_suffix)
-{
- //<number:number-style style:name="N71" style:family="data-style">
- //<number:fraction number:min-integer-digits="0" number:min-numerator-digits="2" \
number:min-denominator-digits="2"/>
- //</number:number-style>
- QString format;
- switch (formatType) {
- case Format::fraction_half:
- format = "# ?/2";
- break;
- case Format::fraction_quarter:
- format = "# ?/4";
- break;
- case Format::fraction_eighth:
- format = "# ?/8";
- break;
- case Format::fraction_sixteenth:
- format = "# ?/16";
- break;
- case Format::fraction_tenth:
- format = "# ?/10";
- break;
- case Format::fraction_hundredth:
- format = "# ?/100";
- break;
- case Format::fraction_one_digit:
- format = "# ?/?";
- break;
- case Format::fraction_two_digits:
- format = "# \?\?/\?\?";
- break;
- case Format::fraction_three_digits:
- format = "# \?\?\?/\?\?\?";
- break;
- default:
- debugSheetsODF << " fraction format not defined :" << formatType;
- break;
- }
-
- return KoOdfNumberStyles::saveOdfFractionStyle(mainStyles, format, _prefix, \
_suffix);
-}
-
-QString Style::saveOdf(KoGenStyle& style, KoGenStyles& mainStyles,
- const StyleManager* manager) const
-{
- // list of substyles to store
- QSet<Key> keysToStore;
-
- if (isDefault()) {
- if (style.isEmpty()) {
- style = KoGenStyle(KoGenStyle::TableCellStyle, "table-cell");
- style.setDefaultStyle(true);
- // don't i18n'ize "Default" in this case
- return "Default"; // mainStyles.insert( style, "Default", \
KoGenStyles::DontAddNumberToName );
- }
- // no attributes to store here
- return mainStyles.insert(style, "ce");
- } else if (hasAttribute(NamedStyleKey)) {
- // it's not really the parent name in this case
- CustomStyle* namedStyle = manager->style(parentName());
- // remove substyles already present in named style
- if (namedStyle)
- keysToStore = difference(*namedStyle);
- // no differences and not an automatic style yet
- if (style.isEmpty() &&
- (keysToStore.count() == 0 ||
- (keysToStore.count() == 1 && keysToStore.toList().first() == \
NamedStyleKey))) {
- return manager->openDocumentName(parentName());
- }
- } else
- keysToStore = QSet<Key>::fromList(d->subStyles.keys());
-
- // Calligra::Sheets::Style is definitly an OASIS auto style,
- // but don't overwrite it, if it already exists
- if (style.isEmpty())
- style = KoGenStyle(KoGenStyle::TableCellAutoStyle, "table-cell");
-
- // doing the real work
- saveOdfStyle(keysToStore, style, mainStyles, manager);
- return mainStyles.insert(style, "ce");
-}
-
-void Style::saveOdfStyle(const QSet<Key>& keysToStore, KoGenStyle &style,
- KoGenStyles &mainStyles, const StyleManager* manager) const
-{
-#ifndef NDEBUG
- //if (type() == BUILTIN )
- // debugSheetsStyle <<"BUILTIN";
- //else if (type() == CUSTOM )
- // debugSheetsStyle <<"CUSTOM";
- //else if (type() == AUTO )
- // debugSheetsStyle <<"AUTO";
-#endif
-
- if (!isDefault() && hasAttribute(NamedStyleKey)) {
- const QString parentName = manager->openDocumentName(this->parentName());
- if (!parentName.isEmpty())
- style.addAttribute("style:parent-style-name", parentName);
- }
-
- if (keysToStore.contains(HorizontalAlignment)) {
- QString value;
- switch (halign()) {
- case Center:
- value = "center";
- break;
- case Right:
- value = "end";
- break;
- case Left:
- value = "start";
- break;
- case Justified:
- value = "justify";
- break;
- case HAlignUndefined:
- break;
- }
- if (!value.isEmpty()) {
- style.addProperty("style:text-align-source", "fix"); // \
table-cell-properties
- style.addProperty("fo:text-align", value, KoGenStyle::ParagraphType);
- }
- }
-
- if (keysToStore.contains(VerticalAlignment)) {
- QString value;
- switch (valign()) {
- case Top:
- case VJustified:
- value = "top";
- break;
- case Middle:
- case VDistributed:
- value = "middle";
- break;
- case Bottom:
- value = "bottom";
- break;
- case VAlignUndefined:
- default:
- break;
- }
- if (!value.isEmpty()) // sanity
- style.addProperty("style:vertical-align", value);
-
- if (valign() == VJustified || valign() == VDistributed)
- style.addProperty("calligra:vertical-distributed", "distributed");
- }
-
- if (keysToStore.contains(BackgroundColor) && backgroundColor().isValid())
- style.addProperty("fo:background-color", colorName(backgroundColor()));
-
- if (keysToStore.contains(MultiRow) && wrapText())
- style.addProperty("fo:wrap-option", "wrap");
-
- if (keysToStore.contains(VerticalText) && verticalText()) {
- style.addProperty("style:direction", "ttb");
- style.addProperty("style:rotation-angle", "0");
- style.addProperty("style:rotation-align", "none");
- }
-
- if (keysToStore.contains(ShrinkToFit) && shrinkToFit())
- style.addProperty("style:shrink-to-fit", "true");
-
-#if 0
- if (keysToStore.contains(FloatFormat))
- format.setAttribute("float", (int) floatFormat());
-
- if (keysToStore.contains(FloatColor))
- format.setAttribute("floatcolor", (int)floatColor());
-
- if (keysToStore.contains(CustomFormat) && !customFormat().isEmpty())
- format.setAttribute("custom", customFormat());
-
- if (keysToStore.contains(Format::Type) && formatType() == Money) {
- format.setAttribute("type", (int) currency().type);
- format.setAttribute("symbol", currency().symbol);
- }
-#endif
- if (keysToStore.contains(Angle) && angle() != 0) {
- style.addProperty("style:rotation-align", "none");
- style.addProperty("style:rotation-angle", QString::number(-1.0 * angle()));
- }
-
- if (keysToStore.contains(Indentation) && indentation() != 0.0) {
- style.addPropertyPt("fo:margin-left", indentation(), \
KoGenStyle::ParagraphType);
- //FIXME
- //if ( a == HAlignUndefined )
- //currentCellStyle.addProperty("fo:text-align", "start" );
- }
-
- if (keysToStore.contains(DontPrintText) && keysToStore.contains(DontPrintText))
- style.addProperty("style:print-content", "false");
-
- // protection
- bool hideAll = false;
- bool hideFormula = false;
- bool isNotProtected = false;
-
- if (keysToStore.contains(NotProtected))
- isNotProtected = notProtected();
-
- if (keysToStore.contains(HideAll))
- hideAll = this->hideAll();
-
- if (keysToStore.contains(HideFormula))
- hideFormula = this->hideFormula();
-
- if (hideAll)
- style.addProperty("style:cell-protect", "hidden-and-protected");
- else {
- if (isNotProtected && !hideFormula)
- style.addProperty("style:cell-protect", "none");
- else if (isNotProtected && hideFormula)
- style.addProperty("style:cell-protect", "formula-hidden");
- else if (hideFormula)
- style.addProperty("style:cell-protect", "protected formula-hidden");
- else if (keysToStore.contains(NotProtected) && !isNotProtected)
- // write out, only if it is explicitly set
- style.addProperty("style:cell-protect", "protected");
- }
-
- // borders
- // NOTE Stefan: QPen api docs:
- // A line width of zero indicates a cosmetic pen. This means
- // that the pen width is always drawn one pixel wide,
- // independent of the transformation set on the painter.
- if (keysToStore.contains(LeftPen) && keysToStore.contains(RightPen) &&
- keysToStore.contains(TopPen) && keysToStore.contains(BottomPen) &&
- (leftBorderPen() == topBorderPen()) &&
- (leftBorderPen() == rightBorderPen()) &&
- (leftBorderPen() == bottomBorderPen())) {
- if (leftBorderPen().style() != Qt::NoPen)
- style.addProperty("fo:border", encodePen(leftBorderPen()));
- } else {
- if (keysToStore.contains(LeftPen) && (leftBorderPen().style() != Qt::NoPen))
- style.addProperty("fo:border-left", encodePen(leftBorderPen()));
-
- if (keysToStore.contains(RightPen) && (rightBorderPen().style() != \
Qt::NoPen))
- style.addProperty("fo:border-right", encodePen(rightBorderPen()));
-
- if (keysToStore.contains(TopPen) && (topBorderPen().style() != Qt::NoPen))
- style.addProperty("fo:border-top", encodePen(topBorderPen()));
-
- if (keysToStore.contains(BottomPen) && (bottomBorderPen().style() != \
Qt::NoPen))
- style.addProperty("fo:border-bottom", encodePen(bottomBorderPen()));
- }
- if (keysToStore.contains(FallDiagonalPen) && (fallDiagonalPen().style() != \
Qt::NoPen)) {
- style.addProperty("style:diagonal-tl-br", encodePen(fallDiagonalPen()));
- }
- if (keysToStore.contains(GoUpDiagonalPen) && (goUpDiagonalPen().style() != \
Qt::NoPen)) {
- style.addProperty("style:diagonal-bl-tr", encodePen(goUpDiagonalPen()));
- }
-
- // font
- if (keysToStore.contains(FontFamily)) { // !fontFamily().isEmpty() == true
- style.addProperty("fo:font-family", fontFamily(), KoGenStyle::TextType);
- }
- if (keysToStore.contains(FontSize)) { // fontSize() != 0
- style.addPropertyPt("fo:font-size", fontSize(), KoGenStyle::TextType);
- }
-
- if (keysToStore.contains(FontBold) && bold())
- style.addProperty("fo:font-weight", "bold", KoGenStyle::TextType);
-
- if (keysToStore.contains(FontItalic) && italic())
- style.addProperty("fo:font-style", "italic", KoGenStyle::TextType);
-
- if (keysToStore.contains(FontUnderline) && underline()) {
- //style:text-underline-style="solid" style:text-underline-width="auto"
- style.addProperty("style:text-underline-style", "solid", \
KoGenStyle::TextType);
- //copy from oo-129
- style.addProperty("style:text-underline-width", "auto", \
KoGenStyle::TextType);
- style.addProperty("style:text-underline-color", "font-color", \
KoGenStyle::TextType);
- }
-
- if (keysToStore.contains(FontStrike) && strikeOut())
- style.addProperty("style:text-line-through-style", "solid", \
KoGenStyle::TextType);
-
- if (keysToStore.contains(FontColor) && fontColor().isValid()) { // always save
- style.addProperty("fo:color", colorName(fontColor()), KoGenStyle::TextType);
- }
-
- //I don't think there is a reason why the background brush should be saved if it \
is null,
- //but remove the check if it causes problems. -- Robert Knight \
<robertknight@gmail.com>
- if (keysToStore.contains(BackgroundBrush) && (backgroundBrush().style() != \
Qt::NoBrush)) {
- QString tmp = saveOdfBackgroundStyle(mainStyles, backgroundBrush());
- if (!tmp.isEmpty())
- style.addProperty("calligra:fill-style-name", tmp);
- }
-
- QString _prefix;
- QString _postfix;
- int _precision = -1;
- if (keysToStore.contains(Prefix) && !prefix().isEmpty())
- _prefix = prefix();
- if (keysToStore.contains(Postfix) && !postfix().isEmpty())
- _postfix = postfix();
- if (keysToStore.contains(Precision) && precision() != -1)
- _precision = precision();
- bool _thousandsSep = false;
- if (keysToStore.contains(ThousandsSep)) {
- _thousandsSep = thousandsSep();
- }
-
- QString currencyCode;
- if (keysToStore.contains(FormatTypeKey) && formatType() == Format::Money) {
- currencyCode = currency().code();
- }
-
- QString numericStyle = saveOdfStyleNumeric(style, mainStyles, formatType(),
- _prefix, _postfix, _precision,
- currencyCode, _thousandsSep);
- if (!numericStyle.isEmpty())
- style.addAttribute("style:data-style-name", numericStyle);
-}
-
-QString Style::saveOdfBackgroundStyle(KoGenStyles &mainStyles, const QBrush &brush)
-{
- KoGenStyle styleobjectauto = KoGenStyle(KoGenStyle::GraphicAutoStyle, \
"graphic");
- KoOdfGraphicStyles::saveOdfFillStyle(styleobjectauto, mainStyles, brush);
- return mainStyles.insert(styleobjectauto, "gr");
-}
void Style::saveXML(QDomDocument& doc, QDomElement& format, const StyleManager* \
styleManager) const {
@@ -2439,18 +1083,6 @@ void Style::clear()
d->subStyles.clear();
}
-QString Style::colorName(const QColor& color)
-{
- static QMap<QRgb, QString> map;
- QRgb rgb = color.rgb();
- if (!map.contains(rgb)) {
- map[rgb] = color.name();
- return map[rgb];
- } else {
- return map[rgb];
- }
-}
-
bool Style::compare(const SubStyle* one, const SubStyle* two)
{
if (!one || !two)
@@ -2628,6 +1260,24 @@ QTextCharFormat Style::asCharFormat() const
return format;
}
+QSet<Style::Key> Style::definedKeys(const StyleManager *styles) const
+{
+ QSet<Style::Key> keys;
+
+ if (isDefault()) return keys;
+
+ if (hasAttribute(Style::NamedStyleKey))
+ {
+ // it's not really the parent name in this case
+ CustomStyle* namedStyle = styles->style(parentName());
+ // remove substyles already present in named style
+ if (namedStyle) keys = difference(*namedStyle);
+ }
+ else
+ keys = QSet<Style::Key>::fromList(d->subStyles.keys());
+
+ return keys;
+}
QList<SharedSubStyle> Style::subStyles() const
{
@@ -2859,43 +1509,6 @@ void CustomStyle::setName(QString const & name)
d->name = name;
}
-QString CustomStyle::saveOdf(KoGenStyle& style, KoGenStyles &mainStyles,
- const StyleManager* manager) const
-{
- Q_ASSERT(!name().isEmpty());
- // default style does not need display name
- if (!isDefault())
- style.addAttribute("style:display-name", name());
-
- // doing the real work
- QSet<Key> keysToStore;
- for (int i = 0; i < subStyles().count(); ++i)
- keysToStore.insert(subStyles()[i].data()->type());
- saveOdfStyle(keysToStore, style, mainStyles, manager);
-
- if (isDefault()) {
- style.setDefaultStyle(true);
- // don't i18n'ize "Default" in this case
- return mainStyles.insert(style, "Default", \
KoGenStyles::DontAddNumberToName);
- }
-
- // this is a custom style
- return mainStyles.insert(style, "custom-style");
-}
-
-void CustomStyle::loadOdf(KoOdfStylesReader& stylesReader, const KoXmlElement& \
style,
- const QString& name, Conditions& conditions,
- const StyleManager* styleManager, const ValueParser \
*parser)
-{
- setName(name);
- if (style.hasAttributeNS(KoXmlNS::style, "parent-style-name"))
- setParentName(style.attributeNS(KoXmlNS::style, "parent-style-name", \
QString()));
-
- setType(CUSTOM);
-
- Style::loadOdfStyle(stylesReader, style, conditions, styleManager, parser);
-}
-
void CustomStyle::save(QDomDocument& doc, QDomElement& styles, const StyleManager* \
styleManager) {
if (name().isEmpty())
@@ -2941,3 +1554,13 @@ int CustomStyle::usage() const
{
return d->ref;
}
+
+QSet<Style::Key> CustomStyle::definedKeys(const StyleManager *) const
+{
+ QList<SharedSubStyle> subs = subStyles();
+ QSet<Style::Key> keys;
+ for (int i = 0; i < subs.count(); ++i)
+ keys.insert(subs[i].data()->type());
+ return keys;
+}
+
diff --git a/sheets/Style.h b/sheets/Style.h
index 6a6e688..2235cbc 100644
--- a/sheets/Style.h
+++ b/sheets/Style.h
@@ -32,11 +32,6 @@
#include "Format.h"
#include "Global.h"
-class KoGenStyle;
-class KoGenStyles;
-class KoOdfStylesReader;
-class KoStyleStack;
-
namespace Calligra
{
namespace Sheets
@@ -172,25 +167,9 @@ public:
bool loadXML(KoXmlElement& format, Paste::Mode pm = Paste::Normal);
void saveXML(QDomDocument& doc, QDomElement& format, const StyleManager* \
styleManager) const;
- void loadOdfStyle(KoOdfStylesReader& stylesReader, const KoXmlElement& element,
- Conditions& conditions, const StyleManager* styleManager,
- const ValueParser *parser);
- void loadOdfDataStyle(KoOdfStylesReader& stylesReader, const QString& \
dataStyleName,
- Conditions& conditions, const StyleManager* styleManager,
- const ValueParser *parser);
-
- /**
- * Saves an OASIS automatic style.
- * Reimplemented by CustomStyle for OASIS user styles.
- * \return the OASIS style's name
- */
- virtual QString saveOdf(KoGenStyle& style, KoGenStyles& mainStyles,
- const StyleManager* manager) const;
-
void clearAttribute(Key key);
bool hasAttribute(Key key) const;
- void loadAttributes(const QList<SharedSubStyle>& subStyles);
uint bottomPenValue() const;
@@ -241,20 +220,6 @@ public:
bool isDefault() const;
bool isEmpty() const;
-protected:
- /**
- * Helper function for saveOdf
- * Does the real work by determining the used attributes.
- */
- void saveOdfStyle(const QSet<Key>& subStyles, KoGenStyle &style,
- KoGenStyles &mainStyles, const StyleManager* manager) const;
-
- void loadOdfDataStyle(KoOdfStylesReader& stylesReader, const KoXmlElement& \
element,
- Conditions& conditions, const StyleManager* styleManager,
- const ValueParser *parser);
- void loadOdfParagraphProperties(KoOdfStylesReader& stylesReader, const \
KoStyleStack& element);
- void loadOdfTableCellProperties(KoOdfStylesReader& stylesReader, const \
KoStyleStack& element);
- void loadOdfTextProperties(KoOdfStylesReader& stylesReader, const KoStyleStack& \
element);
public:
void setHAlign(HAlign align);
@@ -296,49 +261,6 @@ public:
void setDefault();
void clear();
-
- // static functions
- //
- static Format::Type dateType(const QString&);
- static Format::Type timeType(const QString&);
- static Format::Type fractionType(const QString&);
- static Format::Type numberType(const QString&);
- static Currency numberCurrency(const QString&);
-
- /**
- * @return the name of the data style (number, currency, percentage, date,
- * boolean, text)
- */
- static QString saveOdfStyleNumeric(KoGenStyle &style, KoGenStyles &mainStyles, \
Format::Type _style,
- const QString &_prefix, const QString \
&_postfix, int _precision, const QString& symbol,
- bool thousandsSep);
- static QString saveOdfStyleNumericDate(KoGenStyles &mainStyles, Format::Type \
_style,
- const QString &_prefix, const QString \
&_suffix);
- static QString saveOdfStyleNumericFraction(KoGenStyles &mainStyles, Format::Type \
_style,
- const QString &_prefix, const QString &_suffix);
- static QString saveOdfStyleNumericTime(KoGenStyles& mainStyles, Format::Type \
_style,
- const QString &_prefix, const QString \
&_suffix);
- static QString saveOdfStyleNumericCustom(KoGenStyles&mainStyles, Format::Type \
_style,
- const QString &_prefix, const QString &_suffix);
- static QString saveOdfStyleNumericScientific(KoGenStyles&mainStyles, \
Format::Type _style,
- const QString &_prefix, const QString &_suffix, int _precision, bool \
thousandsSep);
- static QString saveOdfStyleNumericPercentage(KoGenStyles&mainStyles, \
Format::Type _style, int _precision,
- const QString &_prefix, const QString &_suffix);
- static QString saveOdfStyleNumericMoney(KoGenStyles&mainStyles, Format::Type \
_style,
- const QString& symbol, int _precision,
- const QString &_prefix, const QString \
&_suffix);
- static QString saveOdfStyleNumericText(KoGenStyles&mainStyles, Format::Type \
_style, int _precision,
- const QString &_prefix, const QString \
&_suffix);
- static QString saveOdfStyleNumericNumber(KoGenStyles&mainStyles, Format::Type \
_style, int _precision,
- const QString &_prefix, const QString &_suffix, bool thousandsSep);
- static QString saveOdfBackgroundStyle(KoGenStyles &mainStyles, const QBrush \
&brush);
-
- /**
- * Returns the name of a color. This is the same as returned by QColor::name, \
but an internal cache
- * is used to reduce the overhead when asking for the name of the same color.
- */
- static QString colorName(const QColor& color);
-
static bool compare(const SubStyle* one, const SubStyle* two);
@@ -365,6 +287,10 @@ public:
* Return the properties of this style that can be represented as a \
QTextCharFormat
*/
QTextCharFormat asCharFormat() const;
+
+ /** Defined style elements - used when saving the style */
+ virtual QSet<Style::Key> definedKeys(const StyleManager *) const;
+
protected:
QList<SharedSubStyle> subStyles() const;
@@ -411,26 +337,6 @@ public:
bool loadXML(KoXmlElement const & style, QString const & name);
void save(QDomDocument & doc, QDomElement & styles, const StyleManager* \
styleManager);
- /**
- * Loads the style properties from @p style .
- * Determines also the parent's name.
- * @param stylesReader map of all styles
- * @param style the DOM element defining the style
- * @param name the style's new name
- */
- void loadOdf(KoOdfStylesReader& stylesReader, const KoXmlElement& style,
- const QString& name, Conditions& conditions,
- const StyleManager* styleManager, const ValueParser *parser);
-
- /**
- * @reimp
- * Stores an OASIS user style.
- * @return the OASIS style's name
- */
- virtual QString saveOdf(KoGenStyle& style, KoGenStyles &mainStyles,
- const StyleManager* manager) const;
-
-
//bool operator==(const CustomStyle& other) const;
//inline bool operator!=(const CustomStyle& other) const {
// return !operator==(other);
@@ -441,6 +347,7 @@ public:
*/
int usage() const;
+ virtual QSet<Style::Key> definedKeys(const StyleManager *) const;
private:
friend class StyleManager;
diff --git a/sheets/StyleManager.cpp b/sheets/StyleManager.cpp
index 7bd76f4..6cccdf3 100644
--- a/sheets/StyleManager.cpp
+++ b/sheets/StyleManager.cpp
@@ -28,11 +28,6 @@
#include <KLocalizedString>
-#include <KoGenStyle.h>
-#include <KoOdfStylesReader.h>
-#include <KoXmlReader.h>
-#include <KoXmlNS.h>
-
#include "SheetsDebug.h"
#include "CalculationSettings.h"
#include "Condition.h"
@@ -52,105 +47,6 @@ StyleManager::~StyleManager()
qDeleteAll(m_styles);
}
-void StyleManager::saveOdf(KoGenStyles &mainStyles)
-{
- debugSheetsODF << "StyleManager: Saving default cell style";
- KoGenStyle defStyle = KoGenStyle(KoGenStyle::TableCellStyle, "table-cell");
- defaultStyle()->saveOdf(defStyle, mainStyles, this);
-
- m_oasisStyles.clear();
-
- CustomStyles::ConstIterator end = m_styles.constEnd();
- for (CustomStyles::ConstIterator it(m_styles.constBegin()); it != end; ++it) {
- debugSheetsODF << "StyleManager: Saving common cell style" << it.key();
- KoGenStyle customStyle = KoGenStyle(KoGenStyle::TableCellStyle, \
"table-cell");
- const QString oasisName = (*it)->saveOdf(customStyle, mainStyles, this);
- m_oasisStyles[(*it)->name()] = oasisName;
- }
-}
-
-void StyleManager::loadOdfStyleTemplate(KoOdfStylesReader& stylesReader, Map* map)
-{
- // reset the map of OpenDocument Styles
- m_oasisStyles.clear();
-
- // loading default style first
- const KoXmlElement* defStyle = stylesReader.defaultStyle("table-cell");
- if (defStyle) {
- debugSheetsODF << "StyleManager: Loading default cell style";
- Conditions conditions;
- defaultStyle()->loadOdf(stylesReader, *defStyle, "Default", conditions, \
this, map->parser());
- defaultStyle()->setType(Style::BUILTIN);
- if (map) {
- // Load the default precision to be used, if the (default) cell style
- // is set to arbitrary precision.
- KoXmlNode n = defStyle->firstChild();
- while (!n.isNull()) {
- if (n.isElement() &&
- n.namespaceURI() == KoXmlNS::style &&
- n.localName() == "table-cell-properties") {
- KoXmlElement e = n.toElement();
- if (n.toElement().hasAttributeNS(KoXmlNS::style, \
"decimal-places")) {
- bool ok;
- const int precision = \
n.toElement().attributeNS(KoXmlNS::style, \
"decimal-places").toInt(&ok);
- if (ok && precision > -1) {
- debugSheetsODF << "Default decimal precision:" << \
precision;
- \
map->calculationSettings()->setDefaultDecimalPrecision(precision);
- }
- }
- }
- n = n.nextSibling();
- }
- }
- } else
- resetDefaultStyle();
-
- QList<KoXmlElement*> \
customStyles(stylesReader.customStyles("table-cell").values());
- uint nStyles = customStyles.count();
- for (unsigned int item = 0; item < nStyles; item++) {
- KoXmlElement* styleElem = customStyles[item];
- if (!styleElem) continue;
-
- // assume the name assigned by the application
- const QString oasisName = styleElem->attributeNS(KoXmlNS::style, "name", \
QString());
-
- // then replace by user-visible one (if any)
- const QString name = styleElem->attributeNS(KoXmlNS::style, "display-name", \
oasisName);
- debugSheetsODF << " StyleManager: Loading common cell style:" << oasisName \
<< " (display name:" << name << ")";
-
- if (!name.isEmpty()) {
- // The style's parent name will be set in Style::loadOdf(..).
- // After all styles are loaded the pointer to the parent is set.
- CustomStyle * style = new CustomStyle(name);
-
- Conditions conditions;
- style->loadOdf(stylesReader, *styleElem, name, conditions, this, \
map->parser());
- // TODO Stefan: conditions
- insertStyle(style);
- // insert it into the map sorted the OpenDocument name
- m_oasisStyles[oasisName] = style->name();
- debugSheetsODF << "Style" << style->name() << ":" << style;
- }
- }
-
- // replace all OpenDocument internal parent names by Calligra Sheets' style \
names
- foreach(CustomStyle* style, m_styles) {
- if (!style->parentName().isNull()) {
- const QString parentOdfName = style->parentName();
- const CustomStyle* parentStyle = \
this->style(m_oasisStyles.value(parentOdfName));
- if (!parentStyle) {
- warnSheetsODF << parentOdfName << " not found.";
- continue;
- }
- style->setParentName(m_oasisStyles.value(parentOdfName));
- debugSheetsODF << style->name() << " (" << style << ") gets" << \
style->parentName() << " (" << parentOdfName << ") as parent.";
- } else {
- style->setParentName("Default");
- debugSheetsODF << style->name() << " (" << style << ") has" << \
style->parentName() << " as parent.";
- }
- }
-}
-
QDomElement StyleManager::save(QDomDocument & doc)
{
QDomElement styles = doc.createElement("styles");
@@ -249,6 +145,12 @@ void StyleManager::createBuiltinStyles()
m_styles[ header2->name()] = header2;
}
+// Mapping between Oasis and our styles. Only used in loading/saving.
+void StyleManager::defineOasisStyle(const QString &oasisName, const QString \
&styleName) +{
+ m_oasisStyles[oasisName] = styleName;
+}
+
CustomStyle * StyleManager::style(QString const & name) const
{
if (name.isEmpty())
@@ -355,11 +257,11 @@ void StyleManager::insertStyle(CustomStyle *style)
m_styles[name] = style;
}
-QStringList StyleManager::styleNames() const
+QStringList StyleManager::styleNames(bool includeDefault) const
{
QStringList list;
- list.push_back(i18n("Default"));
+ if (includeDefault) list.push_back(i18n("Default"));
CustomStyles::const_iterator iter = m_styles.begin();
CustomStyles::const_iterator end = m_styles.end();
@@ -373,43 +275,8 @@ QStringList StyleManager::styleNames() const
return list;
}
-Styles StyleManager::loadOdfAutoStyles(KoOdfStylesReader& stylesReader,
- QHash<QString, Conditions>& \
conditionalStyles,
- const ValueParser *parser)
+void StyleManager::clearOasisStyles()
{
- Styles autoStyles;
- foreach(KoXmlElement* element, stylesReader.autoStyles("table-cell")) {
- if (element->hasAttributeNS(KoXmlNS::style , "name")) {
- QString name = element->attributeNS(KoXmlNS::style , "name" , \
QString());
- debugSheetsODF << "StyleManager: Preloading automatic cell style:" << \
name;
- autoStyles.remove(name);
- Conditions conditions;
- autoStyles[name].loadOdfStyle(stylesReader, *(element), conditions, \
this, parser);
- if (!conditions.isEmpty()) {
- debugSheets << "\t\tCONDITIONS";
- conditionalStyles[name] = conditions;
- }
-
- if (element->hasAttributeNS(KoXmlNS::style, "parent-style-name")) {
- const QString parentOdfName = element->attributeNS(KoXmlNS::style, \
"parent-style-name", QString());
- const CustomStyle* parentStyle = \
style(m_oasisStyles.value(parentOdfName));
- if (!parentStyle) {
- warnSheetsODF << parentOdfName << " not found.";
- continue;
- }
- autoStyles[name].setParentName(parentStyle->name());
- debugSheetsODF << "\t parent-style-name:" << \
autoStyles[name].parentName();
- }
- }
- }
- return autoStyles;
-}
-
-void StyleManager::releaseUnusedAutoStyles(Styles autoStyles)
-{
- // Just clear the list. The styles are released, if not used.
- autoStyles.clear();
-
// Now, we can clear the map of styles sorted by OpenDocument name.
m_oasisStyles.clear();
}
diff --git a/sheets/StyleManager.h b/sheets/StyleManager.h
index 5b478d2..18b9a2f 100644
--- a/sheets/StyleManager.h
+++ b/sheets/StyleManager.h
@@ -29,9 +29,6 @@ class QDomElement;
class QDomDocument;
class QStringList;
-class KoGenStyles;
-class KoOdfStylesReader;
-
namespace Calligra
{
namespace Sheets
@@ -58,9 +55,6 @@ public:
QDomElement save(QDomDocument & doc);
bool loadXML(KoXmlElement const & styles);
- void saveOdf(KoGenStyles &mainStyles);
- void loadOdfStyleTemplate(KoOdfStylesReader& stylesReader, Map* map = 0);
-
CustomStyle * defaultStyle() const {
return m_defaultStyle;
}
@@ -84,36 +78,17 @@ public:
void takeStyle(CustomStyle * style);
void createBuiltinStyles();
- QStringList styleNames() const;
+ QStringList styleNames(bool includeDefault = true) const;
int count() const {
return m_styles.count();
}
- /**
- * Loads OpenDocument auto styles.
- * The auto styles are preloaded, because an auto style could be shared
- * among cells. So, preloading prevents a multiple loading of the same
- * auto style.
- * This method is called before the cell loading process.
- * @param stylesReader repository of styles
- * @return a hash of styles with the OpenDocument internal name as key
- */
- Styles loadOdfAutoStyles(KoOdfStylesReader& stylesReader,
- QHash<QString, Conditions>& conditionalStyles,
- const ValueParser *parser);
+ // Defines a temporary Oasis style alias.
+ void defineOasisStyle(const QString &oasisName, const QString &styleName);
- /**
- * Releases unused auto styles.
- * If there are auto styles, which are not used by any cell (uncommon case)
- * this method makes sure, that these get deleted.
- * This method is called after the cell loading porcess.
- * @param autoStyles a hash of styles with the OpenDocument internal name as
- * key
- * @see loadOdfAutoStyles
- */
- void releaseUnusedAutoStyles(Styles autoStyles);
+ void clearOasisStyles();
- /// OpenDocument name to internal name (on loading) or vice versa (on saving)
+ /// OpenDocument name to internal name (on loading) or vice versa (on saving)
QString openDocumentName(const QString&) const;
private:
diff --git a/sheets/odf/SheetsOdf.h b/sheets/odf/SheetsOdf.h
index 1f064c3..99ad10d 100644
--- a/sheets/odf/SheetsOdf.h
+++ b/sheets/odf/SheetsOdf.h
@@ -42,6 +42,7 @@
class QBuffer;
class KoOdfReadStore;
+class KoOdfStylesReader;
class KoShapeLoadingContext;
class KoShapeSavingContext;
class KoXmlElement;
@@ -74,6 +75,8 @@ namespace Odf {
CALLIGRA_SHEETS_ODF_EXPORT bool paste(QBuffer &buffer, Map *map);
+ // styles
+ CALLIGRA_SHEETS_ODF_EXPORT void loadDataStyle(Style *style, KoOdfStylesReader \
&stylesReader, const QString &styleName, Conditions &conditions, const StyleManager \
*styleManager, const ValueParser *parser);
// regions
CALLIGRA_SHEETS_ODF_EXPORT QString loadRegion(const QString& expression);
diff --git a/sheets/odf/SheetsOdfCell.cpp b/sheets/odf/SheetsOdfCell.cpp
index 6feb509..a680384 100644
--- a/sheets/odf/SheetsOdfCell.cpp
+++ b/sheets/odf/SheetsOdfCell.cpp
@@ -32,11 +32,11 @@
*/
#include "SheetsOdf.h"
+#include "SheetsOdfPrivate.h"
#include <KoGenStyles.h>
#include <KoParagraphStyle.h>
#include <KoShape.h>
-#include <KoShapeLoadingContext.h>
#include <KoShapeRegistry.h>
#include <KoStyleManager.h>
#include <KoTextDocument.h>
@@ -62,8 +62,6 @@
#include "ValueConverter.h"
#include "ValueFormatter.h"
#include "GenValidationStyle.h"
-#include "OdfLoadingContext.h"
-#include "OdfSavingContext.h"
#include "ShapeApplicationData.h"
#include <float.h>
@@ -75,10 +73,6 @@ namespace Sheets {
namespace Odf {
- bool loadCell(Cell *cell, const KoXmlElement& element, OdfLoadingContext& \
tableContext,
- const Styles& autoStyles, const QString& cellStyleName,
- QList<ShapeLoadingData>& shapeData);
- bool saveCell(Cell *cell, int &repeated, OdfSavingContext& tableContext);
// cell loading - helper functions
void loadCellText(Cell *cell, const KoXmlElement& parent, OdfLoadingContext& \
tableContext, const Styles& autoStyles, const QString& cellStyleName); @@ -893,8 \
+887,8 @@ QString Odf::saveCellStyle(Cell *cell, KoGenStyle ¤tCellStyle, \
KoGenStyles #warning use new odf
conditions.saveOdfConditions(currentCellStyle, \
cell->sheet()->map()->converter()); }
-#warning TODO new style odf
- return cell->style().saveOdf(currentCellStyle, mainStyles, \
cell->sheet()->map()->styleManager()); + Style style = cell->style();
+ return saveStyle(&style, currentCellStyle, mainStyles, \
cell->sheet()->map()->styleManager()); }
void Odf::saveCellValue(Cell *cell, KoXmlWriter &xmlWriter)
diff --git a/sheets/odf/SheetsOdfDoc.cpp b/sheets/odf/SheetsOdfDoc.cpp
index a99c24d..2901cb3 100644
--- a/sheets/odf/SheetsOdfDoc.cpp
+++ b/sheets/odf/SheetsOdfDoc.cpp
@@ -32,6 +32,7 @@
*/
#include "SheetsOdf.h"
+#include "SheetsOdfPrivate.h"
#include "DocBase.h"
#include "BindingModel.h"
@@ -42,12 +43,9 @@
#include "calligra_sheets_limits.h"
#include <KoGenStyles.h>
-#include <KoOasisSettings.h>
-#include <KoOdfLoadingContext.h>
#include <KoOdfReadStore.h>
#include <KoOdfWriteStore.h>
#include <KoProgressUpdater.h>
-#include <KoShapeSavingContext.h>
#include <KoStore.h>
#include <KoStoreDevice.h>
#include <KoUnit.h>
@@ -68,14 +66,6 @@ namespace Odf {
void loadDocSettings(DocBase *doc, const KoXmlDocument &settingsDoc);
void loadDocIgnoreList(DocBase *doc, const KoOasisSettings& settings);
void saveSettings(DocBase *doc, KoXmlWriter &settingsWriter);
-
- // these are in SheetsOdfMap
- bool loadMap(Map *map, const KoXmlElement& body, KoOdfLoadingContext& \
odfContext);
- void loadMapSettings(Map *map, const KoOasisSettings &settingsDoc);
- bool saveMap(Map *map, KoXmlWriter & xmlWriter, KoShapeSavingContext & \
savingContext);
-
- // this one is in SheetsOdfSheet
- void saveSheetSettings(Sheet *sheet, KoXmlWriter &settingsWriter);
};
diff --git a/sheets/odf/SheetsOdfMap.cpp b/sheets/odf/SheetsOdfMap.cpp
index a563a42..7afa463 100644
--- a/sheets/odf/SheetsOdfMap.cpp
+++ b/sheets/odf/SheetsOdfMap.cpp
@@ -32,14 +32,13 @@
*/
#include "SheetsOdf.h"
+#include "SheetsOdfPrivate.h"
#include "CalculationSettings.h"
#include "DocBase.h"
#include "LoadingInfo.h"
#include "Map.h"
#include "NamedAreaManager.h"
-#include "OdfLoadingContext.h"
-#include "OdfSavingContext.h"
#include "RowColumnFormat.h"
#include "Sheet.h"
#include "StyleManager.h"
@@ -49,10 +48,6 @@
#include <KoCharacterStyle.h>
#include <KoDocumentResourceManager.h>
#include <KoGenStyles.h>
-#include <KoOasisSettings.h>
-#include <KoOdfLoadingContext.h>
-#include <KoShapeLoadingContext.h>
-#include <KoShapeSavingContext.h>
#include <KoStyleManager.h>
#include <KoStyleStack.h>
#include <KoText.h>
@@ -69,17 +64,7 @@ namespace Calligra {
namespace Sheets {
namespace Odf {
- bool loadMap(Map *map, const KoXmlElement& body, KoOdfLoadingContext& \
odfContext);
- void loadMapSettings(Map *map, const KoOasisSettings &settingsDoc);
-
void fixupStyle(KoCharacterStyle* style);
-
- bool saveMap(Map *map, KoXmlWriter & xmlWriter, KoShapeSavingContext & \
savingContext);
-
- // these are in SheetsOdfSheet
- bool loadSheet(Sheet *sheet, const KoXmlElement& sheetElement, \
OdfLoadingContext& tableContext, const Styles& autoStyles, const QHash<QString, \
Conditions>& conditionalStyles);
- void loadSheetSettings(Sheet *sheet, const KoOasisSettings::NamedMap &settings);
- bool saveSheet(Sheet *sheet, OdfSavingContext& tableContext);
}
void Odf::fixupStyle(KoCharacterStyle* style)
@@ -115,8 +100,7 @@ bool Odf::loadMap(Map *map, const KoXmlElement& body, \
KoOdfLoadingContext& odfCo \
map->loadingInfo()->setFileFormat(LoadingInfo::OpenDocument);
//load in first
-#warning TODO new style odf
- map->styleManager()->loadOdfStyleTemplate(odfContext.stylesReader(), map);
+ loadStyleTemplate(map->styleManager(), odfContext.stylesReader(), map);
OdfLoadingContext tableContext(odfContext);
tableContext.validities = Validity::preloadValidities(body); // \
table:content-validations @@ -217,8 +201,7 @@ bool Odf::loadMap(Map *map, const \
KoXmlElement& body, KoOdfLoadingContext& odfCo
//pre-load auto styles
QHash<QString, Conditions> conditionalStyles;
-#warning TODO new style odf
- Styles autoStyles = \
map->styleManager()->loadOdfAutoStyles(odfContext.stylesReader(), + Styles \
autoStyles = loadAutoStyles(map->styleManager(), odfContext.stylesReader(), \
conditionalStyles, map->parser());
// load the sheet
@@ -253,7 +236,7 @@ bool Odf::loadMap(Map *map, const KoXmlElement& body, \
KoOdfLoadingContext& odfCo }
//delete any styles which were not used
- map->styleManager()->releaseUnusedAutoStyles(autoStyles);
+ map->styleManager()->clearOasisStyles();
// Load databases. This needs the sheets to be loaded.
#warning TODO new style odf
@@ -290,9 +273,8 @@ void Odf::loadMapSettings(Map *map, const KoOasisSettings \
&settings)
bool Odf::saveMap(Map *map, KoXmlWriter & xmlWriter, KoShapeSavingContext & \
savingContext) {
-#warning TODO new style odf
// Saving the custom cell styles including the default cell style.
- map->styleManager()->saveOdf(savingContext.mainStyles());
+ saveStyles(map->styleManager(), savingContext.mainStyles());
// Saving the default column style
KoGenStyle defaultColumnStyle(KoGenStyle::TableColumnStyle, "table-column");
@@ -345,8 +327,7 @@ bool Odf::loadTableShape(Sheet *sheet, const KoXmlElement \
&element, KoShapeLoadi Map *const map = sheet->map();
StyleManager *const styleManager = map->styleManager();
ValueParser *const parser = map->parser();
-#warning use new odf here
- Styles autoStyles = styleManager->loadOdfAutoStyles(odfContext.stylesReader(), \
conditionalStyles, parser); + Styles autoStyles = loadAutoStyles(styleManager, \
odfContext.stylesReader(), conditionalStyles, parser);
if (!element.attributeNS(KoXmlNS::table, "name", QString()).isEmpty()) {
sheet->setSheetName(element.attributeNS(KoXmlNS::table, "name", QString()), \
true); @@ -354,7 +335,7 @@ bool Odf::loadTableShape(Sheet *sheet, const KoXmlElement \
&element, KoShapeLoadi
bool result = loadSheet(sheet, element, tableContext, autoStyles, \
conditionalStyles);
// delete any styles which were not used
- sheet->map()->styleManager()->releaseUnusedAutoStyles(autoStyles);
+ sheet->map()->styleManager()->clearOasisStyles();
return result;
}
@@ -363,8 +344,7 @@ void Odf::saveTableShape(Sheet *sheet, KoShapeSavingContext \
&context) {
const Map* map = sheet->map();
// Saving the custom cell styles including the default cell style.
-#warning use new odf here
- map->styleManager()->saveOdf(context.mainStyles());
+ saveStyles(map->styleManager(), context.mainStyles());
// Saving the default column style
KoGenStyle defaultColumnStyle(KoGenStyle::TableColumnStyle, "table-column");
diff --git a/sheets/odf/SheetsOdfPrivate.h b/sheets/odf/SheetsOdfPrivate.h
new file mode 100644
index 0000000..14a63ce
--- /dev/null
+++ b/sheets/odf/SheetsOdfPrivate.h
@@ -0,0 +1,96 @@
+/* This file is part of the KDE project
+ Copyright 1998-2016 The Calligra Team <calligra-devel@kde.org>
+ Copyright 2016 Tomas Mecir <mecirt@gmail.com>
+ Copyright 2010 Marijn Kruisselbrink <mkruisselbrink@kde.org>
+ Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
+ Copyright 2007 Thorsten Zachmann <zachmann@kde.org>
+ Copyright 2005-2006 Inge Wallin <inge@lysator.liu.se>
+ Copyright 2004 Ariya Hidayat <ariya@kde.org>
+ Copyright 2002-2003 Norbert Andres <nandres@web.de>
+ Copyright 2000-2002 Laurent Montel <montel@kde.org>
+ Copyright 2002 John Dailey <dailey@vt.edu>
+ Copyright 2002 Phillip Mueller <philipp.mueller@gmx.de>
+ Copyright 2000 Werner Trobin <trobin@kde.org>
+ Copyright 1999-2000 Simon Hausmann <hausmann@kde.org>
+ Copyright 1999 David Faure <faure@kde.org>
+ Copyright 1998-2000 Torben Weis <weis@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef SHEETS_ODF_PRIVATE
+#define SHEETS_ODF_PRIVATE
+
+// This should only be included by files inside the odf/ subdir
+
+#include <KoOdfLoadingContext.h>
+#include <KoOasisSettings.h>
+#include <KoShapeLoadingContext.h>
+#include <KoShapeSavingContext.h>
+
+#include "OdfLoadingContext.h"
+#include "OdfSavingContext.h"
+
+namespace Calligra {
+namespace Sheets {
+
+namespace Odf {
+
+ // SheetsOdfMap
+ bool loadMap(Map *map, const KoXmlElement& body, KoOdfLoadingContext& \
odfContext); + void loadMapSettings(Map *map, const KoOasisSettings &settingsDoc);
+ bool saveMap(Map *map, KoXmlWriter & xmlWriter, KoShapeSavingContext & \
savingContext); +
+ // SheetsOdfSheet
+ bool loadSheet(Sheet *sheet, const KoXmlElement& sheetElement, \
OdfLoadingContext& tableContext, const Styles& autoStyles, const QHash<QString, \
Conditions>& conditionalStyles); + void loadSheetSettings(Sheet *sheet, const \
KoOasisSettings::NamedMap &settings); + bool saveSheet(Sheet *sheet, \
OdfSavingContext& tableContext); + void saveSheetSettings(Sheet *sheet, \
KoXmlWriter &settingsWriter); +
+ // SheetsOdfCell
+ bool loadCell(Cell *cell, const KoXmlElement& element, OdfLoadingContext& \
tableContext, + const Styles& autoStyles, const QString& cellStyleName,
+ QList<ShapeLoadingData>& shapeData);
+ bool saveCell(Cell *cell, int &repeated, OdfSavingContext& tableContext);
+
+ // SheetsOdfStyle
+
+ /**
+ * Loads OpenDocument auto styles.
+ * The auto styles are preloaded, because an auto style could be shared
+ * among cells. So, preloading prevents a multiple loading of the same
+ * auto style.
+ * This method is called before the cell loading process.
+ * @param stylesReader repository of styles
+ * @return a hash of styles with the OpenDocument internal name as key
+ */
+ Styles loadAutoStyles(StyleManager *styles, KoOdfStylesReader& stylesReader,
+ QHash<QString, Conditions>& conditionalStyles,
+ const ValueParser *parser);
+ void loadStyleTemplate(StyleManager *styles, KoOdfStylesReader& stylesReader, \
Map* map = 0); + void saveStyles(StyleManager *manager, KoGenStyles &mainStyles);
+ QString saveStyle(const Style *style, KoGenStyle& xmlstyle, KoGenStyles& \
mainStyles, + const StyleManager* manager);
+
+ void loadDataStyle(Style *style, KoOdfStylesReader& stylesReader, const \
KoXmlElement& element, + Conditions& conditions, const \
StyleManager* styleManager, + const ValueParser *parser);
+}
+
+}
+}
+
+#endif
diff --git a/sheets/odf/SheetsOdfRegion.cpp b/sheets/odf/SheetsOdfRegion.cpp
index b4a9156..3278de3 100644
--- a/sheets/odf/SheetsOdfRegion.cpp
+++ b/sheets/odf/SheetsOdfRegion.cpp
@@ -32,6 +32,7 @@
*/
#include "SheetsOdf.h"
+#include "SheetsOdfPrivate.h"
#include "Region.h"
// This file contains functionality to load/save regions
diff --git a/sheets/odf/SheetsOdfSheet.cpp b/sheets/odf/SheetsOdfSheet.cpp
index e1d7ad0..287aa76 100644
--- a/sheets/odf/SheetsOdfSheet.cpp
+++ b/sheets/odf/SheetsOdfSheet.cpp
@@ -32,16 +32,14 @@
*/
#include "SheetsOdf.h"
+#include "SheetsOdfPrivate.h"
#include <kcodecs.h>
#include <KoDocumentInfo.h>
#include <KoGenStyles.h>
-#include <KoOasisSettings.h>
#include <KoProgressUpdater.h>
#include <KoShape.h>
-#include <KoShapeLoadingContext.h>
-#include <KoShapeSavingContext.h>
#include <KoShapeRegistry.h>
#include "KoStore.h"
#include <KoStyleStack.h>
@@ -57,8 +55,6 @@
#include "HeaderFooter.h"
#include "LoadingInfo.h"
#include "Map.h"
-#include "OdfLoadingContext.h"
-#include "OdfSavingContext.h"
#include "PrintSettings.h"
#include "RowColumnFormat.h"
#include "RowFormatStorage.h"
@@ -98,10 +94,6 @@ private:
namespace Odf {
- // Sheet loading and saving
- bool loadSheet(Sheet *sheet, const KoXmlElement& sheetElement, \
OdfLoadingContext& tableContext, const Styles& autoStyles, const QHash<QString, \
Conditions>& conditionalStyles);
- bool saveSheet(Sheet *sheet, OdfSavingContext& tableContext);
-
// Sheet loading - helper functions
/**
* Inserts the styles contained in \p styleRegions into the style storage.
@@ -155,16 +147,6 @@ namespace Odf {
void addText(const QString & text, KoXmlWriter & writer);
void convertPart(Sheet *sheet, const QString & part, KoXmlWriter & xmlWriter);
bool compareRows(Sheet *sheet, int row1, int row2, int maxCols, \
OdfSavingContext& tableContext);
-
- // sheet settings
- void loadSheetSettings(Sheet *sheet, const KoOasisSettings::NamedMap &settings);
- void saveSheetSettings(Sheet *sheet, KoXmlWriter &settingsWriter);
-
- // Cell loading - in SheetsOdfCell
- bool loadCell(Cell *cell, const KoXmlElement& element, OdfLoadingContext& \
tableContext,
- const Styles& autoStyles, const QString& cellStyleName,
- QList<ShapeLoadingData>& shapeData);
- bool saveCell(Cell *cell, int &repeated, OdfSavingContext& tableContext);
}
// *************** Loading *****************
@@ -1216,8 +1198,7 @@ void Odf::saveColRowCell(Sheet *sheet, int maxCols, int \
maxRows, OdfSavingContex if (!column->isDefault() || !style.isDefault()) {
if (!style.isDefault()) {
KoGenStyle currentDefaultCellStyle; // the type is determined in \
saveOdfStyle
-#warning TODO new style odf
- const QString name = style.saveOdf(currentDefaultCellStyle, \
mainStyles, + const QString name = saveStyle(&style, \
currentDefaultCellStyle, mainStyles,
sheet->map()->styleManager());
xmlWriter.addAttribute("table:default-cell-style-name", name);
}
@@ -1299,8 +1280,7 @@ void Odf::saveColRowCell(Sheet *sheet, int maxCols, int \
maxRows, OdfSavingContex
xmlWriter.addAttribute("table:number-rows-repeated", repeated);
if (!style.isDefault()) {
KoGenStyle currentDefaultCellStyle; // the type is determined in \
saveCellStyle
-#warning TODO new style odf
- const QString name = style.saveOdf(currentDefaultCellStyle, \
mainStyles, + const QString name = saveStyle(&style, \
currentDefaultCellStyle, mainStyles,
sheet->map()->styleManager());
xmlWriter.addAttribute("table:default-cell-style-name", name);
}
@@ -1330,8 +1310,7 @@ void Odf::saveColRowCell(Sheet *sheet, int maxCols, int \
maxRows, OdfSavingContex } else { // row is not empty
if (!style.isDefault()) {
KoGenStyle currentDefaultCellStyle; // the type is determined in \
saveCellStyle
-#warning TODO new style odf
- const QString name = style.saveOdf(currentDefaultCellStyle, \
mainStyles, + const QString name = saveStyle(&style, \
currentDefaultCellStyle, mainStyles,
sheet->map()->styleManager());
xmlWriter.addAttribute("table:default-cell-style-name", name);
}
diff --git a/sheets/odf/SheetsOdfStyle.cpp b/sheets/odf/SheetsOdfStyle.cpp
index 7d86700..b01b35f 100644
--- a/sheets/odf/SheetsOdfStyle.cpp
+++ b/sheets/odf/SheetsOdfStyle.cpp
@@ -32,12 +32,1629 @@
*/
#include "SheetsOdf.h"
+#include "SheetsOdfPrivate.h"
+
+#include <klocale.h>
+
+#include <KoGenStyle.h>
+#include <KoGenStyles.h>
+#include <KoOdfStylesReader.h>
+#include <KoXmlReader.h>
+#include <KoXmlNS.h>
+#include <KoOdfGraphicStyles.h>
+#include <KoOdfWorkaround.h>
+#include <KoStyleStack.h>
+#include <KoUnit.h>
+#include <KoXmlNS.h>
+
+#include "CalculationSettings.h"
+#include "Condition.h"
+#include "Map.h"
+#include "StyleManager.h"
// This file contains functionality to load/save styles
namespace Calligra {
namespace Sheets {
+namespace Odf {
+
+ // Single style loading
+ void loadStyle(Style *style, KoOdfStylesReader& stylesReader, const \
KoXmlElement& element, + Conditions& conditions, const \
StyleManager* styleManager, + const ValueParser *parser);
+ void loadCustomStyle(CustomStyle *style, KoOdfStylesReader& stylesReader, const \
KoXmlElement& xmlstyle, + const QString& name, Conditions& \
conditions, + const StyleManager* styleManager, const \
ValueParser *parser); +
+ // Single style saving
+ void saveStyle(const Style *style, const QSet<Style::Key>& subStyles, KoGenStyle \
&xmlstyle, + KoGenStyles &mainStyles, const StyleManager* \
manager); + QString saveCustomStyle(CustomStyle *style, KoGenStyle& genstyle, \
KoGenStyles &mainStyles, + const StyleManager* manager);
+
+ void loadParagraphProperties(Style *style, KoOdfStylesReader& stylesReader, \
const KoStyleStack& styleStack); + void loadTableCellProperties(Style *style, \
KoOdfStylesReader& stylesReader, const KoStyleStack& styleStack); + void \
loadTextProperties(Style *style, KoOdfStylesReader& stylesReader, const KoStyleStack& \
styleStack); +
+ /**
+ * @return the name of the data style (number, currency, percentage, date,
+ * boolean, text)
+ */
+ QString saveStyleNumeric(KoGenStyle &style, KoGenStyles &mainStyles, \
Format::Type _style, + const QString &_prefix, \
const QString &_postfix, int _precision, const QString& symbol, + \
bool thousandsSep); + QString saveStyleNumericDate(KoGenStyles &mainStyles, \
Format::Type _style, + const QString \
&_prefix, const QString &_suffix); + QString saveStyleNumericFraction(KoGenStyles \
&mainStyles, Format::Type _style, + const QString &_prefix, const QString \
&_suffix); + QString saveStyleNumericTime(KoGenStyles& mainStyles, Format::Type \
_style, + const QString &_prefix, const \
QString &_suffix); + QString saveStyleNumericCustom(KoGenStyles&mainStyles, \
Format::Type _style, + const QString &_prefix, const QString &_suffix);
+ QString saveStyleNumericScientific(KoGenStyles&mainStyles, Format::Type _style,
+ const QString &_prefix, const QString &_suffix, int _precision, bool \
thousandsSep); + QString saveStyleNumericPercentage(KoGenStyles&mainStyles, \
Format::Type _style, int _precision, + const QString &_prefix, const \
QString &_suffix); + QString saveStyleNumericMoney(KoGenStyles&mainStyles, \
Format::Type _style, + const QString& \
symbol, int _precision, + const QString \
&_prefix, const QString &_suffix); + QString \
saveStyleNumericText(KoGenStyles&mainStyles, Format::Type _style, int _precision, + \
const QString &_prefix, const QString &_suffix); + QString \
saveStyleNumericNumber(KoGenStyles&mainStyles, Format::Type _style, int _precision, + \
const QString &_prefix, const QString &_suffix, bool thousandsSep); + QString \
saveBackgroundStyle(KoGenStyles &mainStyles, const QBrush &brush); +
+ // Helpers
+ Format::Type dateType(const QString&);
+ Format::Type timeType(const QString&);
+ Format::Type fractionType(const QString&);
+ Format::Type numberType(const QString&);
+ Currency numberCurrency(const QString&);
+ QPen decodePen(const QString &border);
+ QString encodePen(const QPen &pen);
+ /**
+ * Returns the name of a color. This is the same as returned by QColor::name, \
but an internal cache + * is used to reduce the overhead when asking for the name \
of the same color. + */
+ QString colorName(const QColor& color);
+}
+
+void Odf::loadStyleTemplate(StyleManager *styles, KoOdfStylesReader& stylesReader, \
Map* map) +{
+ // reset the map of OpenDocument Styles
+ styles->clearOasisStyles();
+ QHash<QString, QString> oasisStyles;
+
+ // loading default style first
+ const KoXmlElement* defStyle = stylesReader.defaultStyle("table-cell");
+ if (defStyle) {
+ debugSheetsODF << "StyleManager: Loading default cell style";
+ Conditions conditions;
+ loadCustomStyle(styles->defaultStyle(), stylesReader, *defStyle, "Default", \
conditions, styles, map->parser()); + \
styles->defaultStyle()->setType(Style::BUILTIN); + if (map) {
+ // Load the default precision to be used, if the (default) cell style
+ // is set to arbitrary precision.
+ KoXmlNode n = defStyle->firstChild();
+ while (!n.isNull()) {
+ if (n.isElement() &&
+ n.namespaceURI() == KoXmlNS::style &&
+ n.localName() == "table-cell-properties") {
+ KoXmlElement e = n.toElement();
+ if (n.toElement().hasAttributeNS(KoXmlNS::style, \
"decimal-places")) { + bool ok;
+ const int precision = \
n.toElement().attributeNS(KoXmlNS::style, "decimal-places").toInt(&ok); + \
if (ok && precision > -1) { + debugSheetsODF << "Default \
decimal precision:" << precision; + \
map->calculationSettings()->setDefaultDecimalPrecision(precision); + \
} + }
+ }
+ n = n.nextSibling();
+ }
+ }
+ } else
+ styles->resetDefaultStyle();
+
+ QList<KoXmlElement*> \
customStyles(stylesReader.customStyles("table-cell").values()); + uint nStyles = \
customStyles.count(); + for (unsigned int item = 0; item < nStyles; item++) {
+ KoXmlElement* styleElem = customStyles[item];
+ if (!styleElem) continue;
+
+ // assume the name assigned by the application
+ const QString oasisName = styleElem->attributeNS(KoXmlNS::style, "name", \
QString()); +
+ // then replace by user-visible one (if any)
+ const QString name = styleElem->attributeNS(KoXmlNS::style, "display-name", \
oasisName); + debugSheetsODF << " StyleManager: Loading common cell style:" << \
oasisName << " (display name:" << name << ")"; +
+ if (!name.isEmpty()) {
+ // The style's parent name will be set in loadStyle(..).
+ // After all styles are loaded the pointer to the parent is set.
+ CustomStyle * style = new CustomStyle(name);
+
+ Conditions conditions;
+ loadCustomStyle(style, stylesReader, *styleElem, name, conditions, \
styles, map->parser()); + // TODO Stefan: conditions
+ styles->insertStyle(style);
+ // insert it into the map sorted the OpenDocument name
+ styles->defineOasisStyle(oasisName, style->name()); // TODO: is this \
actually needed? + oasisStyles[oasisName] = style->name();
+ debugSheetsODF << "Style" << style->name() << ":" << style;
+ }
+ }
+
+ // replace all OpenDocument internal parent names by Calligra Sheets' style \
names + QStringList styleNames = styles->styleNames(false);
+
+ foreach (QString name, styleNames)
+ {
+ CustomStyle *style = styles->style (name);
+
+ if (!style->parentName().isNull()) {
+ const QString parentOdfName = style->parentName();
+ const CustomStyle* parentStyle = \
styles->style(oasisStyles.value(parentOdfName)); + if (!parentStyle) {
+ warnSheetsODF << parentOdfName << " not found.";
+ continue;
+ }
+ style->setParentName(oasisStyles.value(parentOdfName));
+ debugSheetsODF << style->name() << " (" << style << ") gets" << \
style->parentName() << " (" << parentOdfName << ") as parent."; + } else {
+ style->setParentName("Default");
+ debugSheetsODF << style->name() << " (" << style << ") has" << \
style->parentName() << " as parent."; + }
+ }
+}
+
+Styles Odf::loadAutoStyles(StyleManager *styles, KoOdfStylesReader& stylesReader,
+ QHash<QString, Conditions>& \
conditionalStyles, + const ValueParser *parser)
+{
+ Styles autoStyles;
+ foreach(KoXmlElement* element, stylesReader.autoStyles("table-cell")) {
+ if (element->hasAttributeNS(KoXmlNS::style , "name")) {
+ QString name = element->attributeNS(KoXmlNS::style , "name" , \
QString()); + debugSheetsODF << "StyleManager: Preloading automatic cell \
style:" << name; + autoStyles.remove(name);
+ Conditions conditions;
+ loadStyle(&autoStyles[name], stylesReader, *(element), conditions, \
styles, parser); + if (!conditions.isEmpty()) {
+ debugSheets << "\t\tCONDITIONS";
+ conditionalStyles[name] = conditions;
+ }
+
+ if (element->hasAttributeNS(KoXmlNS::style, "parent-style-name")) {
+ const QString parentOdfName = element->attributeNS(KoXmlNS::style, \
"parent-style-name", QString()); + const CustomStyle* parentStyle = \
styles->style(styles->openDocumentName(parentOdfName)); + if \
(!parentStyle) { + warnSheetsODF << parentOdfName << " not \
found."; + continue;
+ }
+ autoStyles[name].setParentName(parentStyle->name());
+ debugSheetsODF << "\t parent-style-name:" << \
autoStyles[name].parentName(); + }
+ }
+ }
+ return autoStyles;
+}
+
+void Odf::saveStyles(StyleManager *manager, KoGenStyles &mainStyles)
+{
+ debugSheetsODF << "StyleManager: Saving default cell style";
+ KoGenStyle defStyle = KoGenStyle(KoGenStyle::TableCellStyle, "table-cell");
+ saveStyle(manager->defaultStyle(), defStyle, mainStyles, manager);
+
+ manager->clearOasisStyles();
+ QStringList styleNames = manager->styleNames(false);
+
+ foreach (QString name, styleNames)
+ {
+ CustomStyle *style = manager->style (name);
+ debugSheetsODF << "StyleManager: Saving common cell style" << name;
+ KoGenStyle customStyle = KoGenStyle(KoGenStyle::TableCellStyle, \
"table-cell"); + const QString oasisName = saveCustomStyle(style, customStyle, \
mainStyles, manager); + manager->defineOasisStyle(style->name(), oasisName);
+ }
+}
+
+
+// Single style loading
+
+void Odf::loadStyle(Style *style, KoOdfStylesReader& stylesReader, const \
KoXmlElement& element, + Conditions& conditions, const StyleManager* \
styleManager, + const ValueParser *parser)
+{
+ // NOTE Stefan: Do not fill the style stack with the parent styles!
+ KoStyleStack styleStack;
+ styleStack.push(element);
+
+ styleStack.setTypeProperties("table-cell");
+ loadTableCellProperties(style, stylesReader, styleStack);
+
+ styleStack.setTypeProperties("text");
+ loadTextProperties(style, stylesReader, styleStack);
+
+ styleStack.setTypeProperties("paragraph");
+ loadParagraphProperties(style, stylesReader, styleStack);
+
+ KoXmlElement e;
+ forEachElement(e, element) {
+ if (e.namespaceURI() == KoXmlNS::style && e.localName() == "map")
+#warning TODO new odf
+ conditions.loadOdfConditions(e, parser, styleManager);
+ }
+
+ loadDataStyle(style, stylesReader, element, conditions, styleManager, parser);
+
+}
+
+void Odf::loadCustomStyle(CustomStyle *style, KoOdfStylesReader& stylesReader, const \
KoXmlElement& xmlstyle, + const QString& name, Conditions& \
conditions, + const StyleManager* styleManager, const \
ValueParser *parser) +{
+ style->setName(name);
+ if (xmlstyle.hasAttributeNS(KoXmlNS::style, "parent-style-name"))
+ style->setParentName(xmlstyle.attributeNS(KoXmlNS::style, \
"parent-style-name", QString())); +
+ style->setType(Style::CUSTOM);
+
+ loadStyle((Style*) style, stylesReader, xmlstyle, conditions, styleManager, \
parser); +}
+
+
+void Odf::loadDataStyle(Style *style, KoOdfStylesReader& stylesReader, const \
KoXmlElement& element, + Conditions& conditions, const \
StyleManager* styleManager, + const ValueParser *parser)
+{
+ QString str;
+ if (element.hasAttributeNS(KoXmlNS::style, "data-style-name")) {
+ const QString styleName = element.attributeNS(KoXmlNS::style, \
"data-style-name", QString()); + loadDataStyle(style, stylesReader, styleName, \
conditions, styleManager, parser); + }
+
+}
+
+void Odf::loadDataStyle(Style *style, KoOdfStylesReader &stylesReader, const QString \
&styleName, Conditions &conditions, const StyleManager *styleManager, const \
ValueParser *parser) +{
+ if (!stylesReader.dataFormats().contains(styleName)) return;
+
+ QPair<KoOdfNumberStyles::NumericStyleFormat, KoXmlElement*> dataStylePair = \
stylesReader.dataFormats()[styleName]; +
+ const KoOdfNumberStyles::NumericStyleFormat& dataStyle = dataStylePair.first;
+ const QList<QPair<QString,QString> > styleMaps = dataStyle.styleMaps;
+ if(styleMaps.count() > 0) {
+ style = new Style();
+ for (QList<QPair<QString,QString> >::const_iterator it = styleMaps.begin(); \
it != styleMaps.end(); ++it) { +#warning TODO new odf
+ const Conditional c = conditions.loadOdfCondition(it->first, it->second, \
QString(), parser); + if (styleManager->style(c.styleName) == 0) {
+ CustomStyle* s = new CustomStyle(c.styleName);
+ loadDataStyle(s, stylesReader, c.styleName, conditions, \
styleManager, parser); + \
const_cast<StyleManager*>(styleManager)->insertStyle(s); + }
+ }
+ }
+
+ KoStyleStack styleStack;
+ styleStack.push(*dataStylePair.second);
+ styleStack.setTypeProperties("text");
+ loadTextProperties(style, stylesReader, styleStack);
+
+ QString tmp = dataStyle.prefix;
+ if (!tmp.isEmpty()) {
+ style->setPrefix(tmp);
+ }
+ tmp = dataStyle.suffix;
+ if (!tmp.isEmpty()) {
+ style->setPostfix(tmp);
+ }
+ // determine data formatting
+ switch (dataStyle.type) {
+ case KoOdfNumberStyles::Number:
+ style->setFormatType(Format::Number);
+ if (!dataStyle.currencySymbol.isEmpty())
+ style->setCurrency(numberCurrency(dataStyle.currencySymbol));
+ else
+ style->setCurrency(numberCurrency(dataStyle.formatStr));
+ break;
+ case KoOdfNumberStyles::Scientific:
+ style->setFormatType(Format::Scientific);
+ break;
+ case KoOdfNumberStyles::Currency:
+ debugSheetsODF << " currency-symbol:" << dataStyle.currencySymbol;
+ if (!dataStyle.currencySymbol.isEmpty())
+ style->setCurrency(numberCurrency(dataStyle.currencySymbol));
+ else
+ style->setCurrency(numberCurrency(dataStyle.formatStr));
+ break;
+ case KoOdfNumberStyles::Percentage:
+ style->setFormatType(Format::Percentage);
+ break;
+ case KoOdfNumberStyles::Fraction:
+ // determine format of fractions, dates and times by using the
+ // formatting string
+ tmp = dataStyle.formatStr;
+ if (!tmp.isEmpty()) {
+ style->setFormatType(fractionType(tmp));
+ }
+ break;
+ case KoOdfNumberStyles::Date:
+ // determine format of fractions, dates and times by using the
+ // formatting string
+ tmp = dataStyle.formatStr;
+ if (!tmp.isEmpty()) {
+ style->setFormatType(dateType(tmp));
+ }
+ break;
+ case KoOdfNumberStyles::Time:
+ // determine format of fractions, dates and times by using the
+ // formatting string
+ tmp = dataStyle.formatStr;
+ if (!tmp.isEmpty()) {
+ style->setFormatType(timeType(tmp));
+ }
+ break;
+ case KoOdfNumberStyles::Boolean:
+ style->setFormatType(Format::Number);
+ break;
+ case KoOdfNumberStyles::Text:
+ style->setFormatType(Format::Text);
+ break;
+ }
+
+ if (dataStyle.precision > -1) {
+ // special handling for precision
+ // The Style default (-1) and the storage default (0) differ.
+ // The maximum is 10. Replace the Style value 0 with -11, which always \
results + // in a storage value < 0 and is interpreted as Style value 0.
+ int precision = dataStyle.precision;
+ if (style->type() == Style::AUTO && precision == 0)
+ precision = -11;
+ style->setPrecision(precision);
+ }
+
+ style->setThousandsSep(dataStyle.thousandsSep);
+
+ style->setCustomFormat(dataStyle.formatStr);
+
+ if(styleMaps.count() > 0) {
+ conditions.setDefaultStyle(*style);
+ delete style;
+ }
+}
+
+void Odf::loadParagraphProperties(Style *style, KoOdfStylesReader& stylesReader, \
const KoStyleStack& styleStack) +{
+ Q_UNUSED(stylesReader);
+ debugSheetsODF << "\t paragraph-properties";
+ if (styleStack.hasProperty(KoXmlNS::fo, "text-align")) {
+ QString str = styleStack.property(KoXmlNS::fo, "text-align");
+ if (str == "center")
+ style->setHAlign(Style::Center);
+ else if (str == "end" || str=="right")
+ style->setHAlign(Style::Right);
+ else if (str == "start" || str=="left")
+ style->setHAlign(Style::Left);
+ else if (str == "justify")
+ style->setHAlign(Style::Justified);
+ else
+ style->setHAlign(Style::HAlignUndefined);
+ debugSheetsODF << "\t\t text-align:" << str;
+ }
+
+ if (styleStack.hasProperty(KoXmlNS::fo, "margin-left")) {
+ //todo fix me
+ style->setIndentation(KoUnit::parseValue(styleStack.property(KoXmlNS::fo, \
"margin-left"), 0.0)); + }
+}
+
+void Odf::loadTableCellProperties(Style *style, KoOdfStylesReader& stylesReader, \
const KoStyleStack& styleStack) +{
+ QString str;
+ if (styleStack.hasProperty(KoXmlNS::style, "vertical-align")) {
+ str = styleStack.property(KoXmlNS::style, "vertical-align");
+ if (str == "bottom")
+ style->setVAlign(Style::Bottom);
+ else if (str == "top")
+ style->setVAlign(Style::Top);
+ else if (str == "middle")
+ style->setVAlign(Style::Middle);
+ else
+ style->setVAlign(Style::VAlignUndefined);
+ }
+ if (styleStack.property(KoXmlNS::calligra, "vertical-distributed") == \
"distributed") { + if (style->valign() == Style::Top)
+ style->setVAlign(Style::VJustified);
+ else
+ style->setVAlign(Style::VDistributed);
+ }
+ if (styleStack.hasProperty(KoXmlNS::fo, "background-color")) {
+ str = styleStack.property(KoXmlNS::fo, "background-color");
+ if (str == "transparent") {
+ debugSheetsODF << "\t\t fo:background-color: transparent";
+ style->setBackgroundColor(QColor());
+ } else {
+ QColor color(str);
+ if (color.isValid()) {
+ debugSheetsODF << "\t\t fo:background-color:" << color.name();
+ style->setBackgroundColor(color);
+ }
+ }
+ }
+
+ if (styleStack.hasProperty(KoXmlNS::fo, "wrap-option") && \
(styleStack.property(KoXmlNS::fo, "wrap-option") == "wrap")) { + \
style->setWrapText(true); + }
+ if (styleStack.hasProperty(KoXmlNS::style, "cell-protect")) {
+ str = styleStack.property(KoXmlNS::style, "cell-protect");
+#ifndef NWORKAROUND_ODF_BUGS
+ KoOdfWorkaround::fixBadFormulaHiddenForStyleCellProtect(str);
+#endif
+ if (str == "none")
+ style->setNotProtected(true);
+ else if (str == "hidden-and-protected")
+ style->setHideAll(true);
+ else if (str == "protected formula-hidden" || str == "formula-hidden \
protected") + style->setHideFormula(true);
+ else if (str == "formula-hidden") {
+ style->setNotProtected(true);
+ style->setHideFormula(true);
+ }
+ }
+ if (styleStack.hasProperty(KoXmlNS::style, "print-content") &&
+ (styleStack.property(KoXmlNS::style, "print-content") == "false")) {
+ style->setDontPrintText(true);
+ }
+ if (styleStack.hasProperty(KoXmlNS::style, "shrink-to-fit") &&
+ (styleStack.property(KoXmlNS::style, "shrink-to-fit") == "true")) {
+ style->setShrinkToFit(true);
+ }
+ if (styleStack.hasProperty(KoXmlNS::style, "direction") &&
+ (styleStack.property(KoXmlNS::style, "direction") == "ttb")) {
+ style->setVerticalText(true);
+ }
+ if (styleStack.hasProperty(KoXmlNS::style, "rotation-angle")) {
+ bool ok;
+ int a = styleStack.property(KoXmlNS::style, "rotation-angle").toInt(&ok);
+ debugSheetsODF << " rotation-angle :" << a;
+ if (a != 0) {
+ style->setAngle(-a);
+ }
+ }
+ if (styleStack.hasProperty(KoXmlNS::fo, "border")) {
+ str = styleStack.property(KoXmlNS::fo, "border");
+ QPen pen = decodePen(str);
+ style->setLeftBorderPen(pen);
+ style->setTopBorderPen(pen);
+ style->setBottomBorderPen(pen);
+ style->setRightBorderPen(pen);
+ }
+ if (styleStack.hasProperty(KoXmlNS::fo, "border-left")) {
+ str = styleStack.property(KoXmlNS::fo, "border-left");
+ style->setLeftBorderPen(decodePen(str));
+ }
+ if (styleStack.hasProperty(KoXmlNS::fo, "border-right")) {
+ str = styleStack.property(KoXmlNS::fo, "border-right");
+ style->setRightBorderPen(decodePen(str));
+ }
+ if (styleStack.hasProperty(KoXmlNS::fo, "border-top")) {
+ str = styleStack.property(KoXmlNS::fo, "border-top");
+ style->setTopBorderPen(decodePen(str));
+ }
+ if (styleStack.hasProperty(KoXmlNS::fo, "border-bottom")) {
+ str = styleStack.property(KoXmlNS::fo, "border-bottom");
+ style->setBottomBorderPen(decodePen(str));
+ }
+ if (styleStack.hasProperty(KoXmlNS::style, "diagonal-tl-br")) {
+ str = styleStack.property(KoXmlNS::style, "diagonal-tl-br");
+ style->setFallDiagonalPen(decodePen(str));
+ }
+ if (styleStack.hasProperty(KoXmlNS::style, "diagonal-bl-tr")) {
+ str = styleStack.property(KoXmlNS::style, "diagonal-bl-tr");
+ style->setGoUpDiagonalPen(decodePen(str));
+ }
+
+ if (styleStack.hasProperty(KoXmlNS::draw, "style-name") || \
styleStack.hasProperty(KoXmlNS::calligra, "fill-style-name")) { + QString \
styleName = styleStack.hasProperty(KoXmlNS::calligra, "fill-style-name") ? \
styleStack.property(KoXmlNS::calligra, "fill-style-name") + : \
styleStack.property(KoXmlNS::draw, "style-name"); + debugSheetsODF << " style \
name :" << styleName; +
+ const KoXmlElement *xmlstyle = stylesReader.findStyle(styleName, "graphic");
+ debugSheetsODF << " style :" << style;
+ if (xmlstyle) {
+ KoStyleStack drawStyleStack;
+ drawStyleStack.push(*xmlstyle);
+ drawStyleStack.setTypeProperties("graphic");
+ if (drawStyleStack.hasProperty(KoXmlNS::draw, "fill")) {
+ const QString fill = drawStyleStack.property(KoXmlNS::draw, "fill");
+ debugSheetsODF << " load object gradient fill type :" << fill;
+
+ if (fill == "solid" || fill == "hatch") {
+ debugSheetsODF << " Style \
******************************************************"; + \
style->setBackgroundBrush(KoOdfGraphicStyles::loadOdfFillStyle(drawStyleStack, fill, \
stylesReader)); +
+ } else
+ debugSheetsODF << " fill style not supported into sheets :" << \
fill; + }
+ }
+ }
+}
+
+void Odf::loadTextProperties(Style *style, KoOdfStylesReader& stylesReader, const \
KoStyleStack& styleStack) +{
+ Q_UNUSED(stylesReader);
+ // fo:font-size="13pt"
+ // fo:font-style="italic"
+ // style:text-underline="double"
+ // style:text-underline-color="font-color"
+ // fo:font-weight="bold"
+ debugSheetsODF << "\t text-properties";
+ if (styleStack.hasProperty(KoXmlNS::fo, "font-family")) {
+ style->setFontFamily(styleStack.property(KoXmlNS::fo, "font-family")); \
// FIXME Stefan: sanity check + debugSheetsODF << "\t\t fo:font-family:" << \
style->fontFamily(); + }
+ if (styleStack.hasProperty(KoXmlNS::fo, "font-size")) {
+ style->setFontSize((int) KoUnit::parseValue(styleStack.property(KoXmlNS::fo, \
"font-size"), 10.0)); // FIXME Stefan: fallback to default + \
debugSheetsODF << "\t\t fo:font-size:" << style->fontSize(); + }
+ if (styleStack.hasProperty(KoXmlNS::fo, "font-style")) {
+ if (styleStack.property(KoXmlNS::fo, "font-style") == "italic") { // \
"normal", "oblique" + style->setFontItalic(true);
+ debugSheetsODF << "\t\t fo:font-style:" << "italic";
+ }
+ }
+ if (styleStack.hasProperty(KoXmlNS::fo, "font-weight")) {
+ if (styleStack.property(KoXmlNS::fo, "font-weight") == "bold") { // \
"normal", "100", "200", ... + style->setFontBold(true);
+ debugSheetsODF << "\t\t fo:font-weight:" << "bold";
+ }
+ }
+ if (styleStack.hasProperty(KoXmlNS::style, "text-underline-style")) {
+ if (styleStack.property(KoXmlNS::style, "text-underline-style") != "none") {
+ style->setFontUnderline(true);
+ debugSheetsODF << "\t\t style:text-underline-style:" << "solid \
(actually: !none)"; + }
+ }
+ if (styleStack.hasProperty(KoXmlNS::style, "text-underline-width")) {
+ //TODO
+ }
+ if (styleStack.hasProperty(KoXmlNS::style, "text-underline-color")) {
+ //TODO
+ }
+ if (styleStack.hasProperty(KoXmlNS::fo, "color")) {
+ QColor color = QColor(styleStack.property(KoXmlNS::fo, "color"));
+ if (color.isValid()) {
+ style->setFontColor(color);
+ debugSheetsODF << "\t\t fo:color:" << color.name();
+ }
+ }
+ if (styleStack.hasProperty(KoXmlNS::style, "text-line-through-style")) {
+ if (styleStack.property(KoXmlNS::style, "text-line-through-style") != "none"
+ /*&& styleStack.property("text-line-through-style")=="solid"*/) {
+ style->setFontStrikeOut(true);
+ debugSheetsODF << "\t\t text-line-through-style:" << "solid (actually: \
!none)"; + }
+ }
+ if (styleStack.hasProperty(KoXmlNS::style, "font-name")) {
+ QString fontName = styleStack.property(KoXmlNS::style, "font-name");
+ debugSheetsODF << "\t\t style:font-name:" << fontName;
+ const KoXmlElement * xmlstyle = stylesReader.findStyle(fontName);
+ // TODO: sanity check that it is a font-face style?
+ debugSheetsODF << "\t\t\t style:" << xmlstyle;
+ if (style) {
+ style->setFontFamily(xmlstyle->attributeNS(KoXmlNS::svg, \
"font-family")); + debugSheetsODF << "\t\t\t svg:font-family:" << \
style->fontFamily(); + }
+ }
+}
+
+
+
+// Single style saving
+
+void Odf::saveStyle(const Style *style, const QSet<Style::Key>& keysToStore, \
KoGenStyle &xmlstyle, + KoGenStyles &mainStyles, const StyleManager* \
manager) +{
+#ifndef NDEBUG
+ //if (type() == BUILTIN )
+ // debugSheetsStyle <<"BUILTIN";
+ //else if (type() == CUSTOM )
+ // debugSheetsStyle <<"CUSTOM";
+ //else if (type() == AUTO )
+ // debugSheetsStyle <<"AUTO";
+#endif
+
+ if (!style->isDefault() && style->hasAttribute(Style::NamedStyleKey)) {
+ const QString parentName = manager->openDocumentName(style->parentName());
+ if (!parentName.isEmpty())
+ xmlstyle.addAttribute("style:parent-style-name", parentName);
+ }
+
+ if (keysToStore.contains(Style::HorizontalAlignment)) {
+ QString value;
+ switch (style->halign()) {
+ case Style::Center:
+ value = "center";
+ break;
+ case Style::Right:
+ value = "end";
+ break;
+ case Style::Left:
+ value = "start";
+ break;
+ case Style::Justified:
+ value = "justify";
+ break;
+ case Style::HAlignUndefined:
+ break;
+ }
+ if (!value.isEmpty()) {
+ xmlstyle.addProperty("style:text-align-source", "fix"); // \
table-cell-properties + xmlstyle.addProperty("fo:text-align", value, \
KoGenStyle::ParagraphType); + }
+ }
+
+ if (keysToStore.contains(Style::VerticalAlignment)) {
+ QString value;
+ switch (style->valign()) {
+ case Style::Top:
+ case Style::VJustified:
+ value = "top";
+ break;
+ case Style::Middle:
+ case Style::VDistributed:
+ value = "middle";
+ break;
+ case Style::Bottom:
+ value = "bottom";
+ break;
+ case Style::VAlignUndefined:
+ default:
+ break;
+ }
+ if (!value.isEmpty()) // sanity
+ xmlstyle.addProperty("style:vertical-align", value);
+
+ if (style->valign() == Style::VJustified || style->valign() == \
Style::VDistributed) + \
xmlstyle.addProperty("calligra:vertical-distributed", "distributed"); + }
+
+ if (keysToStore.contains(Style::BackgroundColor) && \
style->backgroundColor().isValid()) + \
xmlstyle.addProperty("fo:background-color", colorName(style->backgroundColor())); +
+ if (keysToStore.contains(Style::MultiRow) && style->wrapText())
+ xmlstyle.addProperty("fo:wrap-option", "wrap");
+
+ if (keysToStore.contains(Style::VerticalText) && style->verticalText()) {
+ xmlstyle.addProperty("style:direction", "ttb");
+ xmlstyle.addProperty("style:rotation-angle", "0");
+ xmlstyle.addProperty("style:rotation-align", "none");
+ }
+
+ if (keysToStore.contains(Style::ShrinkToFit) && style->shrinkToFit())
+ xmlstyle.addProperty("style:shrink-to-fit", "true");
+
+#if 0
+ if (keysToStore.contains(Style::FloatFormat))
+ format.setAttribute("float", (int) style->floatFormat());
+
+ if (keysToStore.contains(Style::FloatColor))
+ format.setAttribute("floatcolor", (int)style->floatColor());
+
+ if (keysToStore.contains(Style::CustomFormat) && \
!style->customFormat().isEmpty()) + format.setAttribute("custom", \
customFormat()); +
+ if (keysToStore.contains(Style::Format::Type) && style->formatType() == Money) {
+ format.setAttribute("type", (int) currency().type);
+ format.setAttribute("symbol", currency().symbol);
+ }
+#endif
+ if (keysToStore.contains(Style::Angle) && style->angle() != 0) {
+ xmlstyle.addProperty("style:rotation-align", "none");
+ xmlstyle.addProperty("style:rotation-angle", QString::number(-1.0 * \
style->angle())); + }
+
+ if (keysToStore.contains(Style::Indentation) && style->indentation() != 0.0) {
+ xmlstyle.addPropertyPt("fo:margin-left", style->indentation(), \
KoGenStyle::ParagraphType); + //FIXME
+ //if ( a == HAlignUndefined )
+ //currentCellStyle.addProperty("fo:text-align", "start" );
+ }
+
+ if (keysToStore.contains(Style::DontPrintText) && \
keysToStore.contains(Style::DontPrintText)) // huh? why twice? + \
xmlstyle.addProperty("style:print-content", "false"); +
+ // protection
+ bool hideAll = false;
+ bool hideFormula = false;
+ bool isNotProtected = false;
+
+ if (keysToStore.contains(Style::NotProtected))
+ isNotProtected = style->notProtected();
+
+ if (keysToStore.contains(Style::HideAll))
+ hideAll = style->hideAll();
+
+ if (keysToStore.contains(Style::HideFormula))
+ hideFormula = style->hideFormula();
+
+ if (hideAll)
+ xmlstyle.addProperty("style:cell-protect", "hidden-and-protected");
+ else {
+ if (isNotProtected && !hideFormula)
+ xmlstyle.addProperty("style:cell-protect", "none");
+ else if (isNotProtected && hideFormula)
+ xmlstyle.addProperty("style:cell-protect", "formula-hidden");
+ else if (hideFormula)
+ xmlstyle.addProperty("style:cell-protect", "protected formula-hidden");
+ else if (keysToStore.contains(Style::NotProtected) && !isNotProtected)
+ // write out, only if it is explicitly set
+ xmlstyle.addProperty("style:cell-protect", "protected");
+ }
+
+ // borders
+ // NOTE Stefan: QPen api docs:
+ // A line width of zero indicates a cosmetic pen. This means
+ // that the pen width is always drawn one pixel wide,
+ // independent of the transformation set on the painter.
+ if (keysToStore.contains(Style::LeftPen) && \
keysToStore.contains(Style::RightPen) && + \
keysToStore.contains(Style::TopPen) && keysToStore.contains(Style::BottomPen) && + \
(style->leftBorderPen() == style->topBorderPen()) && + \
(style->leftBorderPen() == style->rightBorderPen()) && + \
(style->leftBorderPen() == style->bottomBorderPen())) { + if \
(style->leftBorderPen().style() != Qt::NoPen) + \
xmlstyle.addProperty("fo:border", encodePen(style->leftBorderPen())); + } else {
+ if (keysToStore.contains(Style::LeftPen) && (style->leftBorderPen().style() \
!= Qt::NoPen)) + xmlstyle.addProperty("fo:border-left", \
encodePen(style->leftBorderPen())); +
+ if (keysToStore.contains(Style::RightPen) && \
(style->rightBorderPen().style() != Qt::NoPen)) + \
xmlstyle.addProperty("fo:border-right", encodePen(style->rightBorderPen())); +
+ if (keysToStore.contains(Style::TopPen) && (style->topBorderPen().style() != \
Qt::NoPen)) + xmlstyle.addProperty("fo:border-top", \
encodePen(style->topBorderPen())); +
+ if (keysToStore.contains(Style::BottomPen) && \
(style->bottomBorderPen().style() != Qt::NoPen)) + \
xmlstyle.addProperty("fo:border-bottom", encodePen(style->bottomBorderPen())); + }
+ if (keysToStore.contains(Style::FallDiagonalPen) && \
(style->fallDiagonalPen().style() != Qt::NoPen)) { + \
xmlstyle.addProperty("style:diagonal-tl-br", encodePen(style->fallDiagonalPen())); + \
} + if (keysToStore.contains(Style::GoUpDiagonalPen) && \
(style->goUpDiagonalPen().style() != Qt::NoPen)) { + \
xmlstyle.addProperty("style:diagonal-bl-tr", encodePen(style->goUpDiagonalPen())); + \
} +
+ // font
+ if (keysToStore.contains(Style::FontFamily)) { // !fontFamily().isEmpty() == \
true + xmlstyle.addProperty("fo:font-family", style->fontFamily(), \
KoGenStyle::TextType); + }
+ if (keysToStore.contains(Style::FontSize)) { // fontSize() != 0
+ xmlstyle.addPropertyPt("fo:font-size", style->fontSize(), \
KoGenStyle::TextType); + }
+
+ if (keysToStore.contains(Style::FontBold) && style->bold())
+ xmlstyle.addProperty("fo:font-weight", "bold", KoGenStyle::TextType);
+
+ if (keysToStore.contains(Style::FontItalic) && style->italic())
+ xmlstyle.addProperty("fo:font-style", "italic", KoGenStyle::TextType);
+
+ if (keysToStore.contains(Style::FontUnderline) && style->underline()) {
+ //style:text-underline-style="solid" style:text-underline-width="auto"
+ xmlstyle.addProperty("style:text-underline-style", "solid", \
KoGenStyle::TextType); + //copy from oo-129
+ xmlstyle.addProperty("style:text-underline-width", "auto", \
KoGenStyle::TextType); + xmlstyle.addProperty("style:text-underline-color", \
"font-color", KoGenStyle::TextType); + }
+
+ if (keysToStore.contains(Style::FontStrike) && style->strikeOut())
+ xmlstyle.addProperty("style:text-line-through-style", "solid", \
KoGenStyle::TextType); +
+ if (keysToStore.contains(Style::FontColor) && style->fontColor().isValid()) { \
// always save + xmlstyle.addProperty("fo:color", \
colorName(style->fontColor()), KoGenStyle::TextType); + }
+
+ //I don't think there is a reason why the background brush should be saved if it \
is null, + //but remove the check if it causes problems. -- Robert Knight \
<robertknight@gmail.com> + if (keysToStore.contains(Style::BackgroundBrush) && \
(style->backgroundBrush().style() != Qt::NoBrush)) { + QString tmp = \
saveBackgroundStyle(mainStyles, style->backgroundBrush()); + if \
(!tmp.isEmpty()) + xmlstyle.addProperty("calligra:fill-style-name", tmp);
+ }
+
+ QString _prefix;
+ QString _postfix;
+ int _precision = -1;
+ if (keysToStore.contains(Style::Prefix) && !style->prefix().isEmpty())
+ _prefix = style->prefix();
+ if (keysToStore.contains(Style::Postfix) && !style->postfix().isEmpty())
+ _postfix = style->postfix();
+ if (keysToStore.contains(Style::Precision) && style->precision() != -1)
+ _precision = style->precision();
+ bool _thousandsSep = false;
+ if (keysToStore.contains(Style::ThousandsSep)) {
+ _thousandsSep = style->thousandsSep();
+ }
+
+ QString currencyCode;
+ if (keysToStore.contains(Style::FormatTypeKey) && style->formatType() == \
Format::Money) { + currencyCode = style->currency().code();
+ }
+
+ QString numericStyle = saveStyleNumeric(xmlstyle, mainStyles, \
style->formatType(), + _prefix, _postfix, _precision,
+ currencyCode, _thousandsSep);
+ if (!numericStyle.isEmpty())
+ xmlstyle.addAttribute("style:data-style-name", numericStyle);
+}
+
+QString Odf::saveCustomStyle(CustomStyle *style, KoGenStyle& genstyle, KoGenStyles \
&mainStyles, + const StyleManager* manager)
+{
+ Q_ASSERT(!style->name().isEmpty());
+ // default style does not need display name
+ if (!style->isDefault())
+ genstyle.addAttribute("style:display-name", style->name());
+
+ // doing the real work
+ QSet<Style::Key> keysToStore = style->definedKeys(manager);
+ saveStyle(style, keysToStore, genstyle, mainStyles, manager);
+
+ if (style->isDefault()) {
+ genstyle.setDefaultStyle(true);
+ // don't i18n'ize "Default" in this case
+ return mainStyles.insert(genstyle, "Default", \
KoGenStyles::DontAddNumberToName); + }
+
+ // this is a custom style
+ return mainStyles.insert(genstyle, "custom-style");
+}
+
+QString Odf::saveStyle(const Style *style, KoGenStyle& xmlstyle, KoGenStyles& \
mainStyles, + const StyleManager* manager)
+{
+ // list of substyles to store
+ QSet<Style::Key> keysToStore = style->definedKeys(manager);
+
+ if (style->isDefault()) {
+ if (xmlstyle.isEmpty()) {
+ xmlstyle = KoGenStyle(KoGenStyle::TableCellStyle, "table-cell");
+ xmlstyle.setDefaultStyle(true);
+ // don't i18n'ize "Default" in this case
+ return "Default"; // mainStyles.insert( style, "Default", \
KoGenStyles::DontAddNumberToName ); + }
+ // no attributes to store here
+ return mainStyles.insert(xmlstyle, "ce");
+ } else if (style->hasAttribute(Style::NamedStyleKey)) {
+ // it's not really the parent name in this case
+
+ // no differences and not an automatic style yet?
+ if (xmlstyle.isEmpty() &&
+ (keysToStore.count() == 0 ||
+ (keysToStore.count() == 1 && keysToStore.toList().first() == \
Style::NamedStyleKey))) { + return \
manager->openDocumentName(style->parentName()); + }
+ }
+
+ // Calligra::Sheets::Style is definitly an OASIS auto style,
+ // but don't overwrite it, if it already exists
+ if (xmlstyle.isEmpty())
+ xmlstyle = KoGenStyle(KoGenStyle::TableCellAutoStyle, "table-cell");
+
+ // doing the real work
+ saveStyle(style, keysToStore, xmlstyle, mainStyles, manager);
+ return mainStyles.insert(xmlstyle, "ce");
+}
+
+QString Odf::saveBackgroundStyle(KoGenStyles &mainStyles, const QBrush &brush)
+{
+ KoGenStyle styleobjectauto = KoGenStyle(KoGenStyle::GraphicAutoStyle, \
"graphic"); + KoOdfGraphicStyles::saveOdfFillStyle(styleobjectauto, mainStyles, \
brush); + return mainStyles.insert(styleobjectauto, "gr");
+}
+
+QString Odf::saveStyleNumeric(KoGenStyle &style, KoGenStyles &mainStyles,
+ Format::Type _style,
+ const QString &_prefix, const QString &_postfix,
+ int _precision, const QString& symbol,
+ bool thousandsSep)
+{
+// debugSheetsODF ;
+ QString styleName;
+ QString valueType;
+ switch (_style) {
+ case Format::Number:
+ styleName = saveStyleNumericNumber(mainStyles, _style, _precision, _prefix, \
_postfix, thousandsSep); + valueType = "float";
+ break;
+ case Format::Text:
+ styleName = saveStyleNumericText(mainStyles, _style, _precision, _prefix, \
_postfix); + valueType = "string";
+ break;
+ case Format::Money:
+ styleName = saveStyleNumericMoney(mainStyles, _style, symbol, _precision, \
_prefix, _postfix); + valueType = "currency";
+ break;
+ case Format::Percentage:
+ styleName = saveStyleNumericPercentage(mainStyles, _style, _precision, \
_prefix, _postfix); + valueType = "percentage";
+ break;
+ case Format::Scientific:
+ styleName = saveStyleNumericScientific(mainStyles, _style, _prefix, \
_postfix, _precision, thousandsSep); + valueType = "float";
+ break;
+ case Format::ShortDate:
+ case Format::TextDate:
+ styleName = saveStyleNumericDate(mainStyles, _style, _prefix, _postfix);
+ valueType = "date";
+ break;
+ case Format::Time:
+ case Format::SecondeTime:
+ case Format::Time1:
+ case Format::Time2:
+ case Format::Time3:
+ case Format::Time4:
+ case Format::Time5:
+ case Format::Time6:
+ case Format::Time7:
+ case Format::Time8:
+ styleName = saveStyleNumericTime(mainStyles, _style, _prefix, _postfix);
+ valueType = "time";
+ break;
+ case Format::fraction_half:
+ case Format::fraction_quarter:
+ case Format::fraction_eighth:
+ case Format::fraction_sixteenth:
+ case Format::fraction_tenth:
+ case Format::fraction_hundredth:
+ case Format::fraction_one_digit:
+ case Format::fraction_two_digits:
+ case Format::fraction_three_digits:
+ styleName = saveStyleNumericFraction(mainStyles, _style, _prefix, _postfix);
+ valueType = "float";
+ break;
+ case Format::Date1:
+ case Format::Date2:
+ case Format::Date3:
+ case Format::Date4:
+ case Format::Date5:
+ case Format::Date6:
+ case Format::Date7:
+ case Format::Date8:
+ case Format::Date9:
+ case Format::Date10:
+ case Format::Date11:
+ case Format::Date12:
+ case Format::Date13:
+ case Format::Date14:
+ case Format::Date15:
+ case Format::Date16:
+ case Format::Date17:
+ case Format::Date18:
+ case Format::Date19:
+ case Format::Date20:
+ case Format::Date21:
+ case Format::Date22:
+ case Format::Date23:
+ case Format::Date24:
+ case Format::Date25:
+ case Format::Date26:
+ case Format::Date27:
+ case Format::Date28:
+ case Format::Date29:
+ case Format::Date30:
+ case Format::Date31:
+ case Format::Date32:
+ case Format::Date33:
+ case Format::Date34:
+ case Format::Date35:
+ styleName = saveStyleNumericDate(mainStyles, _style, _prefix, _postfix);
+ valueType = "date";
+ break;
+ case Format::Custom:
+ styleName = saveStyleNumericCustom(mainStyles, _style, _prefix, _postfix);
+ break;
+ case Format::Generic:
+ case Format::None:
+ if (_precision > -1 || !_prefix.isEmpty() || !_postfix.isEmpty()) {
+ styleName = saveStyleNumericNumber(mainStyles, _style, _precision, \
_prefix, _postfix, thousandsSep); + valueType = "float";
+ }
+ break;
+ case Format::DateTime:
+ default:
+ ;
+ }
+ if (!styleName.isEmpty()) {
+ style.addAttribute("style:data-style-name", styleName);
+ }
+ return styleName;
+}
+
+QString Odf::saveStyleNumericNumber(KoGenStyles& mainStyles, Format::Type \
/*_style*/, int _precision, + const QString& _prefix, const QString& _postfix, \
bool thousandsSep) +{
+ QString format;
+ if (_precision == -1)
+ format = '0';
+ else {
+ QString tmp;
+ for (int i = 0; i < _precision; i++) {
+ tmp += '0';
+ }
+ format = "0." + tmp;
+ }
+ return KoOdfNumberStyles::saveOdfNumberStyle(mainStyles, format, _prefix, \
_postfix, thousandsSep); +}
+
+QString Odf::saveStyleNumericText(KoGenStyles& /*mainStyles*/, Format::Type \
/*_style*/, int /*_precision*/, + const \
QString& /*_prefix*/, const QString& /*_postfix*/) +{
+ return "";
+}
+
+QString Odf::saveStyleNumericMoney(KoGenStyles& mainStyles, Format::Type /*_style*/,
+ const QString& symbol, int _precision,
+ const QString& _prefix, const QString& \
_postfix) +{
+ QString format;
+ if (_precision == -1)
+ format = '0';
+ else {
+ QString tmp;
+ for (int i = 0; i < _precision; i++) {
+ tmp += '0';
+ }
+ format = "0." + tmp;
+ }
+ return KoOdfNumberStyles::saveOdfCurrencyStyle(mainStyles, format, symbol, \
_prefix, _postfix); +}
+
+QString Odf::saveStyleNumericPercentage(KoGenStyles&mainStyles, Format::Type \
/*_style*/, int _precision, + const QString& _prefix, const QString& _postfix)
+{
+ //<number:percentage-style style:name="N106" style:family="data-style">
+ //<number:number number:decimal-places="6" number:min-integer-digits="1"/>
+ //<number:text>%</number:text>
+ //</number:percentage-style>
+ //TODO add decimal etc.
+ QString format;
+ if (_precision == -1)
+ format = '0';
+ else {
+ QString tmp;
+ for (int i = 0; i < _precision; i++) {
+ tmp += '0';
+ }
+ format = "0." + tmp;
+ }
+ return KoOdfNumberStyles::saveOdfPercentageStyle(mainStyles, format, _prefix, \
_postfix); +}
+
+
+QString Odf::saveStyleNumericScientific(KoGenStyles&mainStyles, Format::Type \
/*_style*/, + const QString &_prefix, const QString &_suffix, int _precision, \
bool thousandsSep) +{
+ //<number:number-style style:name="N60" style:family="data-style">
+ // <number:scientific-number number:decimal-places="2" \
number:min-integer-digits="1" number:min-exponent-digits="3"/> + \
//</number:number-style> + QString format;
+ if (_precision == -1)
+ format = "0E+00";
+ else {
+ QString tmp;
+ for (int i = 0; i < _precision; i++) {
+ tmp += '0';
+ }
+ format = "0." + tmp + "E+00";
+ }
+ return KoOdfNumberStyles::saveOdfScientificStyle(mainStyles, format, _prefix, \
_suffix, thousandsSep); +}
+
+QString Odf::saveStyleNumericDate(KoGenStyles&mainStyles, Format::Type _style,
+ const QString& _prefix, const QString& \
_postfix) +{
+ QString format;
+ bool locale = false;
+ switch (_style) {
+ //TODO fixme use locale of Calligra Sheets and not kglobal
+ case Format::ShortDate:
+ format = KLocale::global()->dateFormatShort();
+ locale = true;
+ break;
+ case Format::TextDate:
+ format = KLocale::global()->dateFormat();
+ locale = true;
+ break;
+ case Format::Date1:
+ format = "dd-MMM-yy";
+ break;
+ case Format::Date2:
+ format = "dd-MMM-yyyy";
+ break;
+ case Format::Date3:
+ format = "dd-M";
+ break;
+ case Format::Date4:
+ format = "dd-MM";
+ break;
+ case Format::Date5:
+ format = "dd/MM/yy";
+ break;
+ case Format::Date6:
+ format = "dd/MM/yyyy";
+ break;
+ case Format::Date7:
+ format = "MMM-yy";
+ break;
+ case Format::Date8:
+ format = "MMMM-yy";
+ break;
+ case Format::Date9:
+ format = "MMMM-yyyy";
+ break;
+ case Format::Date10:
+ format = "MMMMM-yy";
+ break;
+ case Format::Date11:
+ format = "dd/MMM";
+ break;
+ case Format::Date12:
+ format = "dd/MM";
+ break;
+ case Format::Date13:
+ format = "dd/MMM/yyyy";
+ break;
+ case Format::Date14:
+ format = "yyyy/MMM/dd";
+ break;
+ case Format::Date15:
+ format = "yyyy-MMM-dd";
+ break;
+ case Format::Date16:
+ format = "yyyy/MM/dd";
+ break;
+ case Format::Date17:
+ format = "d MMMM yyyy";
+ break;
+ case Format::Date18:
+ format = "MM/dd/yyyy";
+ break;
+ case Format::Date19:
+ format = "MM/dd/yy";
+ break;
+ case Format::Date20:
+ format = "MMM/dd/yy";
+ break;
+ case Format::Date21:
+ format = "MMM/dd/yyyy";
+ break;
+ case Format::Date22:
+ format = "MMM-yyyy";
+ break;
+ case Format::Date23:
+ format = "yyyy";
+ break;
+ case Format::Date24:
+ format = "yy";
+ break;
+ case Format::Date25:
+ format = "yyyy/MM/dd";
+ break;
+ case Format::Date26:
+ format = "yyyy/MMM/dd";
+ break;
+ case Format::Date27:
+ format = "MMM/yy";
+ break;
+ case Format::Date28:
+ format = "MMM/yyyy";
+ break;
+ case Format::Date29:
+ format = "MMMM/yy";
+ break;
+ case Format::Date30:
+ format = "MMMM/yyyy";
+ break;
+ case Format::Date31:
+ format = "dd-MM";
+ break;
+ case Format::Date32:
+ format = "MM/yy";
+ break;
+ case Format::Date33:
+ format = "MM-yy";
+ break;
+ case Format::Date34:
+ format = "ddd d MMM yyyy";
+ break;
+ case Format::Date35:
+ format = "dddd d MMM yyyy";
+ break;
+ default:
+ debugSheetsODF << "this date format is not defined ! :" << _style;
+ break;
+ }
+ return KoOdfNumberStyles::saveOdfDateStyle(mainStyles, format, locale, _prefix, \
_postfix); +}
+
+QString Odf::saveStyleNumericCustom(KoGenStyles& /*mainStyles*/, Format::Type \
/*_style*/, + const QString& /*_prefix*/, const QString& /*_postfix*/)
+{
+ //TODO
+ //<number:date-style style:name="N50" style:family="data-style" \
number:automatic-order="true" number:format-source="language"> + //<number:month/>
+ //<number:text>/</number:text>
+ //<number:day/>
+ //<number:text>/</number:text>
+ //<number:year/>
+ //<number:text> </number:text>
+ //<number:hours number:style="long"/>
+ //<number:text>:</number:text>
+ //<number:minutes number:style="long"/>
+ // <number:text> </number:text>
+ //<number:am-pm/>
+ //</number:date-style>
+ return "";
+}
+
+QString Odf::saveStyleNumericTime(KoGenStyles& mainStyles, Format::Type _style,
+ const QString& _prefix, const QString& \
_postfix) +{
+ //<number:time-style style:name="N42" style:family="data-style">
+ //<number:hours number:style="long"/>
+ //<number:text>:</number:text>
+ //<number:minutes number:style="long"/>
+ //<number:text> </number:text>
+ //<number:am-pm/>
+ //</number:time-style>
+
+ QString format;
+ bool locale = false;
+ //TODO use format
+ switch (_style) {
+ case Format::Time: //TODO FIXME
+ format = "hh:mm:ss";
+ break;
+ case Format::SecondeTime: //TODO FIXME
+ format = "hh:mm";
+ break;
+ case Format::Time1:
+ format = "h:mm AP";
+ break;
+ case Format::Time2:
+ format = "h:mm:ss AP";
+ break;
+ case Format::Time3: // 9 h 01 min 28 s
+ format = "hh \\h mm \\m\\i\\n ss \\s";
+ break;
+ case Format::Time4:
+ format = "hh:mm";
+ break;
+ case Format::Time5:
+ format = "hh:mm:ss";
+ break;
+ case Format::Time6:
+ format = "m:ss";
+ break;
+ case Format::Time7:
+ format = "h:mm:ss";
+ break;
+ case Format::Time8:
+ format = "h:mm";
+ break;
+ default:
+ debugSheetsODF << "time format not defined :" << _style;
+ break;
+ }
+ return KoOdfNumberStyles::saveOdfTimeStyle(mainStyles, format, locale, _prefix, \
_postfix); +}
+
+QString Odf::saveStyleNumericFraction(KoGenStyles &mainStyles, Format::Type \
formatType, + const QString &_prefix, const QString &_suffix)
+{
+ //<number:number-style style:name="N71" style:family="data-style">
+ //<number:fraction number:min-integer-digits="0" number:min-numerator-digits="2" \
number:min-denominator-digits="2"/> + //</number:number-style>
+ QString format;
+ switch (formatType) {
+ case Format::fraction_half:
+ format = "# ?/2";
+ break;
+ case Format::fraction_quarter:
+ format = "# ?/4";
+ break;
+ case Format::fraction_eighth:
+ format = "# ?/8";
+ break;
+ case Format::fraction_sixteenth:
+ format = "# ?/16";
+ break;
+ case Format::fraction_tenth:
+ format = "# ?/10";
+ break;
+ case Format::fraction_hundredth:
+ format = "# ?/100";
+ break;
+ case Format::fraction_one_digit:
+ format = "# ?/?";
+ break;
+ case Format::fraction_two_digits:
+ format = "# \?\?/\?\?";
+ break;
+ case Format::fraction_three_digits:
+ format = "# \?\?\?/\?\?\?";
+ break;
+ default:
+ debugSheetsODF << " fraction format not defined :" << formatType;
+ break;
+ }
+
+ return KoOdfNumberStyles::saveOdfFractionStyle(mainStyles, format, _prefix, \
_suffix); +}
+
+
+// Helpers
+
+static QString convertDateFormat(const QString& date)
+{
+ QString result = date;
+ result.replace("%Y", "yyyy");
+ result.replace("%y", "yy");
+ result.replace("%n", "M");
+ result.replace("%m", "MM");
+ result.replace("%e", "d");
+ result.replace("%d", "dd");
+ result.replace("%b", "MMM");
+ result.replace("%B", "MMMM");
+ result.replace("%a", "ddd");
+ result.replace("%A", "dddd");
+ return result;
+}
+
+Format::Type Odf::dateType(const QString &_f)
+{
+ const QString dateFormatShort = \
convertDateFormat(KLocale::global()->dateFormatShort()); + const QString \
dateFormat = convertDateFormat(KLocale::global()->dateFormat()); + QString _format \
= _f; + _format.replace(' ', '-');
+
+ if (_format == "d-MMM-yy" || _format == "dd-MMM-yy")
+ return Format::Date1;
+ else if (_format == "dd-MMM-yyyy")
+ return Format::Date2;
+ else if (_format == "d-MM")
+ return Format::Date3;
+ else if (_format == "dd-MM") //TODO ???????
+ return Format::Date4;
+ else if (_format == "dd/MM/yy")
+ return Format::Date5;
+ else if (_format == "dd/MM/yyyy")
+ return Format::Date6;
+ else if (_format == "MMM-yy")
+ return Format::Date7;
+ else if (_format == "MMMM-yy")
+ return Format::Date8;
+ else if (_format == "MMMM-yyyy")
+ return Format::Date9;
+ else if (_format == "MMMMM-yy" || _format == "X-yy")
+ return Format::Date10;
+ else if (_format == "dd/MMM")
+ return Format::Date11;
+ else if (_format == "dd/MM")
+ return Format::Date12;
+ else if (_format == "dd/MMM/yyyy")
+ return Format::Date13;
+ else if (_format == "yyyy/MMM/dd")
+ return Format::Date14;
+ else if (_format == "yyyy-MMM-dd")
+ return Format::Date15;
+ else if (_format == "yyyy-MM-dd")
+ return Format::Date16;
+ else if (_format == "d MMMM yyyy")
+ return Format::Date17;
+ else if (_format == "MM/dd/yyyy")
+ return Format::Date18;
+ else if (_format == "MM/dd/yy")
+ return Format::Date19;
+ else if (_format == "MMM/dd/yy")
+ return Format::Date20;
+ else if (_format == "MMM/dd/yyyy")
+ return Format::Date21;
+ else if (_format == "MMM-yyyy")
+ return Format::Date22;
+ else if (_format == "yyyy")
+ return Format::Date23;
+ else if (_format == "yy")
+ return Format::Date24;
+ else if (_format == "yyyy/MM/dd")
+ return Format::Date25;
+ else if (_format == "yyyy/MMM/dd")
+ return Format::Date26;
+ else if (_format == "MMM/yy")
+ return Format::Date27;
+ else if (_format == "MMM/yyyy")
+ return Format::Date28;
+ else if (_format == "MMMM/yy")
+ return Format::Date29;
+ else if (_format == "MMMM/yyyy")
+ return Format::Date30;
+ else if (_format == "dd-MM")
+ return Format::Date31;
+ else if (_format == "MM/yy")
+ return Format::Date32;
+ else if (_format == "MM-yy")
+ return Format::Date33;
+ else if (QRegExp("^[d]+[\\s]*[d]{1,2}[\\s]+[M]{1,4}[\\s]+[y]{2,2}$").indexIn(_f) \
>= 0) + return Format::Date34;
+ else if (QRegExp("^[d]+[\\s]*[d]{1,2}[\\s]+[M]{1,}[\\s]+[y]{2,4}$").indexIn(_f) \
>= 0) + return Format::Date35;
+ else if (_format == dateFormatShort)
+ return Format::ShortDate;
+ else if (_format == dateFormat)
+ return Format::TextDate;
+ else {
+ debugSheets << "Unhandled date format=" << _format;
+ return Format::ShortDate;
+ }
+}
+
+Format::Type Odf::timeType(const QString &_format)
+{
+ if (_format == "h:mm AP")
+ return Format::Time1;
+ else if (_format == "h:mm:ss AP")
+ return Format::Time2;
+ else if (_format == "hh \\h mm \\m\\i\\n ss \\s")
+ return Format::Time3;
+ else if (_format == "hh:mm")
+ return Format::Time4;
+ else if (_format == "hh:mm:ss")
+ return Format::Time5;
+ else if (_format == "m:ss")
+ return Format::Time6;
+ else if (_format == "h:mm:ss")
+ return Format::Time7;
+ else if (_format == "h:mm")
+ return Format::Time8;
+ else
+ return Format::Time;
+}
+
+Currency Odf::numberCurrency(const QString &_format)
+{
+ // Look up if a prefix or postfix is in the currency table,
+ // return the currency symbol to use for formatting purposes.
+ if(!_format.isEmpty()) {
+ QString f = QString(_format.at(0));
+ Currency currStart = Currency(f);
+ if (currStart.index() > 1)
+ return currStart;
+ f = QString(_format.at(_format.size()-1));
+ Currency currEnd = Currency(f);
+ if (currEnd.index() > 1)
+ return currEnd;
+ }
+ return Currency(QString());
+}
+
+Format::Type Odf::fractionType(const QString &_format)
+{
+ if (_format.endsWith(QLatin1String("/2")))
+ return Format::fraction_half;
+ else if (_format.endsWith(QLatin1String("/4")))
+ return Format::fraction_quarter;
+ else if (_format.endsWith(QLatin1String("/8")))
+ return Format::fraction_eighth;
+ else if (_format.endsWith(QLatin1String("/16")))
+ return Format::fraction_sixteenth;
+ else if (_format.endsWith(QLatin1String("/10")))
+ return Format::fraction_tenth;
+ else if (_format.endsWith(QLatin1String("/100")))
+ return Format::fraction_hundredth;
+ else if (_format.endsWith(QLatin1String("/?")))
+ return Format::fraction_one_digit;
+ else if (_format.endsWith(QLatin1String("/??")))
+ return Format::fraction_two_digits;
+ else if (_format.endsWith(QLatin1String("/???")))
+ return Format::fraction_three_digits;
+ else
+ return Format::fraction_three_digits;
+}
+
+QPen Odf::decodePen(const QString &border)
+{
+ QPen pen;
+ //string like "0.088cm solid #800000"
+ if (border.isEmpty() || border == "none" || border == "hidden") { // in fact no \
border + pen.setStyle(Qt::NoPen);
+ return pen;
+ }
+ //code from koborder, for the moment Calligra Sheets doesn't use koborder
+ // ## isn't it faster to use QStringList::split than parse it 3 times?
+ QString _width = border.section(' ', 0, 0);
+ QByteArray _style = border.section(' ', 1, 1).toLatin1();
+ QString _color = border.section(' ', 2, 2);
+
+ pen.setWidth((int)(KoUnit::parseValue(_width, 1.0)));
+
+ if (_style == "none")
+ pen.setStyle(Qt::NoPen);
+ else if (_style == "solid")
+ pen.setStyle(Qt::SolidLine);
+ else if (_style == "dashed")
+ pen.setStyle(Qt::DashLine);
+ else if (_style == "dotted")
+ pen.setStyle(Qt::DotLine);
+ else if (_style == "dot-dash")
+ pen.setStyle(Qt::DashDotLine);
+ else if (_style == "dot-dot-dash")
+ pen.setStyle(Qt::DashDotDotLine);
+ else
+ debugSheets << " style undefined :" << _style;
+
+ if (_color.isEmpty())
+ pen.setColor(QColor());
+ else
+ pen.setColor(QColor(_color));
+
+ return pen;
+}
+
+QString Odf::encodePen(const QPen & pen)
+{
+// debugSheets<<"encodePen( const QPen & pen ) :"<<pen;
+ // NOTE Stefan: QPen api docs:
+ // A line width of zero indicates a cosmetic pen. This means
+ // that the pen width is always drawn one pixel wide,
+ // independent of the transformation set on the painter.
+ QString s = QString("%1pt ").arg((pen.width() == 0) ? 1 : pen.width());
+ switch (pen.style()) {
+ case Qt::NoPen:
+ return "none";
+ case Qt::SolidLine:
+ s += "solid";
+ break;
+ case Qt::DashLine:
+ s += "dashed";
+ break;
+ case Qt::DotLine:
+ s += "dotted";
+ break;
+ case Qt::DashDotLine:
+ s += "dot-dash";
+ break;
+ case Qt::DashDotDotLine:
+ s += "dot-dot-dash";
+ break;
+ default: break;
+ }
+ //debugSheets << " encodePen :" << s;
+ if (pen.color().isValid()) {
+ s += ' ' + colorName(pen.color());
+ }
+ return s;
+}
+
+QString Odf::colorName(const QColor& color)
+{
+ static QMap<QRgb, QString> map;
+ QRgb rgb = color.rgb();
+ if (!map.contains(rgb)) {
+ map[rgb] = color.name();
+ return map[rgb];
+ } else {
+ return map[rgb];
+ }
+}
+
+
+
+
+
+
} // Sheets
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic