[Libreoffice-commits] .: sc/source xmloff/inc xmloff/source

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Fri May 25 17:10:53 PDT 2012


 sc/source/filter/xml/xmlcondformat.cxx |   38 ++++++++++++++++++++++++++++-----
 sc/source/filter/xml/xmlexprt.cxx      |   31 ++++++++++++++++++++++++++
 sc/source/filter/xml/xmlimprt.cxx      |    5 ++--
 sc/source/filter/xml/xmlimprt.hxx      |    3 +-
 xmloff/inc/xmloff/xmltoken.hxx         |    2 +
 xmloff/source/core/xmltoken.cxx        |    2 +
 6 files changed, 73 insertions(+), 8 deletions(-)

New commits:
commit de687872926d0c54beba38fc2c33368b3ca6d634
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat May 26 00:40:49 2012 +0200

    support remaining data bar attributes in odf import/export
    
    Change-Id: I6fdf7a6158002003938ee039152d582776aba5db

diff --git a/sc/source/filter/xml/xmlcondformat.cxx b/sc/source/filter/xml/xmlcondformat.cxx
index 3e3d3c4..d705394 100644
--- a/sc/source/filter/xml/xmlcondformat.cxx
+++ b/sc/source/filter/xml/xmlcondformat.cxx
@@ -180,6 +180,8 @@ ScXMLDataBarFormatContext::ScXMLDataBarFormatContext( ScXMLImport& rImport, sal_
     rtl::OUString sPositiveColor;
     rtl::OUString sNegativeColor;
     rtl::OUString sGradient;
+    rtl::OUString sAxisPosition;
+    rtl::OUString sShowValue;
 
     sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetDataBarAttrMap();
@@ -199,6 +201,15 @@ ScXMLDataBarFormatContext::ScXMLDataBarFormatContext( ScXMLImport& rImport, sal_
             case XML_TOK_DATABAR_GRADIENT:
                 sGradient = sValue;
                 break;
+            case XML_TOK_DATABAR_NEGATIVE_COLOR:
+                sNegativeColor = sValue;
+                break;
+            case XML_TOK_DATABAR_AXISPOSITION:
+                sAxisPosition = sValue;
+                break;
+            case XML_TOK_DATABAR_SHOWVALUE:
+                sShowValue = sValue;
+                break;
             default:
                 break;
         }
@@ -213,18 +224,30 @@ ScXMLDataBarFormatContext::ScXMLDataBarFormatContext( ScXMLImport& rImport, sal_
         sax::Converter::convertBool( bGradient, sGradient);
         mpFormatData->mbGradient = bGradient;
     }
+
     if(!sPositiveColor.isEmpty())
     {
         sal_Int32 nColor = 0;
         sax::Converter::convertColor( nColor, sPositiveColor );
         mpFormatData->maPositiveColor = Color(nColor);
     }
+
     if(!sNegativeColor.isEmpty())
     {
+        // we might check here for 0xff0000 and don't write it
         sal_Int32 nColor = 0;
-        sax::Converter::convertColor( nColor, sPositiveColor );
+        sax::Converter::convertColor( nColor, sNegativeColor );
         mpFormatData->mpNegativeColor.reset(new Color(nColor));
     }
+    else
+        mpFormatData->mbNeg = false;
+
+    if(!sShowValue.isEmpty())
+    {
+        bool bShowValue = true;
+        sax::Converter::convertBool( bShowValue, sShowValue );
+        mpFormatData->mbOnlyBar = !bShowValue;
+    }
 
     mpDataBarFormat->SetRange(rRange);
 }
@@ -264,7 +287,8 @@ void ScXMLDataBarFormatContext::EndElement()
 
 namespace {
 
-void setColorEntryType(const rtl::OUString& rType, ScColorScaleEntry* pEntry)
+void setColorEntryType(const rtl::OUString& rType, ScColorScaleEntry* pEntry, const rtl::OUString rFormula,
+        ScXMLImport& rImport)
 {
     if(rType == "minimum")
         pEntry->SetMin(true);
@@ -274,6 +298,11 @@ void setColorEntryType(const rtl::OUString& rType, ScColorScaleEntry* pEntry)
         pEntry->SetPercentile(true);
     else if(rType == "percent")
         pEntry->SetPercent(true);
+    else if(rType == "formula")
+    {
+        //position does not matter, only table is important
+        pEntry->SetFormula(rFormula, rImport.GetDocument(), ScAddress(0,0,rImport.GetTables().GetCurrentSheet()), formula::FormulaGrammar::GRAM_ODFF);
+    }
 
     //TODO: add formulas
 }
@@ -324,12 +353,11 @@ ScXMLColorScaleFormatEntryContext::ScXMLColorScaleFormatEntryContext( ScXMLImpor
     sax::Converter::convertColor(nColor, sColor);
     aColor = Color(nColor);
 
-    //TODO: formulas
     if(!sVal.isEmpty())
         sax::Converter::convertDouble(nVal, sVal);
 
     mpFormatEntry = new ScColorScaleEntry(nVal, aColor);
-    setColorEntryType(sType, mpFormatEntry);
+    setColorEntryType(sType, mpFormatEntry, sVal, GetScImport());
     pFormat->AddEntry(mpFormatEntry);
 }
 
@@ -373,7 +401,7 @@ ScXMLDataBarFormatEntryContext::ScXMLDataBarFormatEntryContext( ScXMLImport& rIm
         sax::Converter::convertDouble(nVal, sVal);
 
     ScColorScaleEntry* pEntry = new ScColorScaleEntry(nVal, Color());
-    setColorEntryType(sType, pEntry);
+    setColorEntryType(sType, pEntry, sVal, GetScImport());
     if(pData->mpLowerLimit)
     {
         pData->mpUpperLimit.reset(pEntry);
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 3aea14a..2f7c3fb 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -3885,6 +3885,37 @@ void ScXMLExport::ExportConditionalFormat(SCTAB nTab)
                     const ScDataBarFormatData* pFormatData = static_cast<const ScDataBarFormat&>(*itr).GetDataBarData();
                     if(!pFormatData->mbGradient)
                         AddAttribute(XML_NAMESPACE_CALC_EXT, XML_GRADIENT, XML_FALSE);
+                    if(pFormatData->mbOnlyBar)
+                        AddAttribute(XML_NAMESPACE_CALC_EXT, XML_SHOW_VALUE, XML_FALSE);
+
+                    if(pFormatData->mbNeg)
+                    {
+                        if(pFormatData->mpNegativeColor)
+                        {
+                            rtl::OUStringBuffer aBuffer;
+                            ::sax::Converter::convertColor(aBuffer, pFormatData->mpNegativeColor->GetColor());
+                            AddAttribute(XML_NAMESPACE_CALC_EXT, XML_NEGATIVE_COLOR, aBuffer.makeStringAndClear());
+                        }
+                        else
+                        {
+                            rtl::OUStringBuffer aBuffer;
+                            ::sax::Converter::convertColor(aBuffer, Color(COL_LIGHTRED).GetColor());
+                            AddAttribute(XML_NAMESPACE_CALC_EXT, XML_NEGATIVE_COLOR, aBuffer.makeStringAndClear());
+                        }
+                    }
+
+                    if(pFormatData->meAxisPosition != databar::AUTOMATIC)
+                    {
+                        if(pFormatData->meAxisPosition == databar::NONE)
+                        {
+                            AddAttribute(XML_NAMESPACE_CALC_EXT, XML_AXIS_POSITION, rtl::OUString("none"));
+                        }
+                        else
+                        {
+                            AddAttribute(XML_NAMESPACE_CALC_EXT, XML_AXIS_POSITION, rtl::OUString("middle"));
+                        }
+                    }
+
                     rtl::OUStringBuffer aBuffer;
                     ::sax::Converter::convertColor(aBuffer, pFormatData->maPositiveColor.GetColor());
                     AddAttribute(XML_NAMESPACE_CALC_EXT, XML_POSITIVE_COLOR, aBuffer.makeStringAndClear());
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index f689fcb..c2fb1fd 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -703,9 +703,10 @@ const SvXMLTokenMap& ScXMLImport::GetDataBarAttrMap()
         static SvXMLTokenMapEntry aDataBarAttrTokenMap[] =
         {
             { XML_NAMESPACE_CALC_EXT, XML_POSITIVE_COLOR, XML_TOK_DATABAR_POSITIVE_COLOR },
-            //{ XML_NAMESPACE_CALC_EXT, XML_NEGATIVE_COLOR, XML_TOK_DATABAR_NEGATIVE_COLOR },
+            { XML_NAMESPACE_CALC_EXT, XML_NEGATIVE_COLOR, XML_TOK_DATABAR_NEGATIVE_COLOR },
             { XML_NAMESPACE_CALC_EXT, XML_GRADIENT, XML_TOK_DATABAR_GRADIENT },
-            //{ XML_NAMESPACE_CALC_EXT, XML_AXIS_POSITION, XML_TOK_DATABAR_AXISPOSITION },
+            { XML_NAMESPACE_CALC_EXT, XML_AXIS_POSITION, XML_TOK_DATABAR_AXISPOSITION },
+            { XML_NAMESPACE_CALC_EXT, XML_SHOW_VALUE, XML_TOK_DATABAR_SHOWVALUE },
             XML_TOKEN_MAP_END
         };
 
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index 9743c69..b94752f 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -189,7 +189,8 @@ enum ScXMLDataBarAttrTokens
     XML_TOK_DATABAR_POSITIVE_COLOR,
     XML_TOK_DATABAR_NEGATIVE_COLOR,
     XML_TOK_DATABAR_GRADIENT,
-    XML_TOK_DATABAR_AXISPOSITION
+    XML_TOK_DATABAR_AXISPOSITION,
+    XML_TOK_DATABAR_SHOWVALUE
 };
 
 enum ScXMLDataBarEntryAttrTokens
diff --git a/xmloff/inc/xmloff/xmltoken.hxx b/xmloff/inc/xmloff/xmltoken.hxx
index d47a93b..3dc4b12 100644
--- a/xmloff/inc/xmloff/xmltoken.hxx
+++ b/xmloff/inc/xmloff/xmltoken.hxx
@@ -1240,6 +1240,7 @@ namespace xmloff { namespace token {
         XML_NAMED_EXPRESSIONS,
         XML_NAMED_RANGE,
         XML_NAVY,
+        XML_NEGATIVE_COLOR,
         XML_NEQ,
         XML_NEW,
         XML_NEXT,
@@ -1610,6 +1611,7 @@ namespace xmloff { namespace token {
         XML_SHOW_SHAPE,
         XML_SHOW_TEXT,
         XML_SHOW_UNIT,
+        XML_SHOW_VALUE,
         XML_SHOWS,
         XML_SIDE_BY_SIDE,
         XML_SILVER,
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index 759926a..90e46e3 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -1245,6 +1245,7 @@ namespace xmloff { namespace token {
         TOKEN( "named-expressions",               XML_NAMED_EXPRESSIONS ),
         TOKEN( "named-range",                     XML_NAMED_RANGE ),
         TOKEN( "navy",                            XML_NAVY ),
+        TOKEN( "negative-color",                   XML_NEGATIVE_COLOR ),
         TOKEN( "neq",                             XML_NEQ ),
         TOKEN( "new",                             XML_NEW ),
         TOKEN( "next",                            XML_NEXT ),
@@ -1615,6 +1616,7 @@ namespace xmloff { namespace token {
         TOKEN( "show-shape",                      XML_SHOW_SHAPE ),
         TOKEN( "show-text",                       XML_SHOW_TEXT ),
         TOKEN( "show-unit",                       XML_SHOW_UNIT ),
+        TOKEN( "show-value",                      XML_SHOW_VALUE ),
         TOKEN( "shows",                           XML_SHOWS ),
         TOKEN( "side-by-side",                    XML_SIDE_BY_SIDE ),
         TOKEN( "silver",                          XML_SILVER ),


More information about the Libreoffice-commits mailing list