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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sun Jan 27 11:43:59 PST 2013


 sc/source/filter/xml/xmlcondformat.cxx |   75 +++++++++++++++++++++++++++++++++
 sc/source/filter/xml/xmlcondformat.hxx |   14 ++++++
 sc/source/filter/xml/xmlexprt.cxx      |   43 ++++++++++++++++++
 sc/source/filter/xml/xmlimprt.cxx      |   20 ++++++++
 sc/source/filter/xml/xmlimprt.hxx      |   11 ++++
 xmloff/inc/xmloff/xmltoken.hxx         |    1 
 xmloff/source/core/xmltoken.cxx        |    1 
 7 files changed, 164 insertions(+), 1 deletion(-)

New commits:
commit e820c249a4280fb38cf0ef7664006707382a687e
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Nov 16 15:08:40 2012 +0100

    implement conditional date format import/export for ODF
    
    Change-Id: I11d5583c994d84fe1163c6158c0794ea1d879f2e

diff --git a/sc/source/filter/xml/xmlcondformat.cxx b/sc/source/filter/xml/xmlcondformat.cxx
index 571426c..64e9d2a 100644
--- a/sc/source/filter/xml/xmlcondformat.cxx
+++ b/sc/source/filter/xml/xmlcondformat.cxx
@@ -131,6 +131,9 @@ SvXMLImportContext* ScXMLConditionalFormatContext::CreateChildContext( sal_uInt1
         case XML_TOK_CONDFORMAT_ICONSET:
             pContext = new ScXMLIconSetFormatContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat );
             break;
+        case XML_TOK_CONDFORMAT_DATE:
+            pContext = new ScXMLDateContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat );
+            break;
         default:
             break;
     }
@@ -703,4 +706,76 @@ ScXMLFormattingEntryContext::ScXMLFormattingEntryContext( ScXMLImport& rImport,
     setColorEntryType(sType, pColorScaleEntry, sVal, GetScImport());
 }
 
+namespace {
+
+condformat::ScCondFormatDateType getDateFromString(const rtl::OUString& rString)
+{
+    if(rString == "today")
+        return condformat::TODAY;
+    else if(rString == "yesterday")
+        return condformat::YESTERDAY;
+    else if(rString == "tomorrow")
+        return condformat::TOMORROW;
+    else if(rString == "last-7-days")
+        return condformat::LAST7DAYS;
+    else if(rString == "this-week")
+        return condformat::THISWEEK;
+    else if(rString == "last-week")
+        return condformat::LASTWEEK;
+    else if(rString == "next-week")
+        return condformat::NEXTWEEK;
+    else if(rString == "this-month")
+        return condformat::THISMONTH;
+    else if(rString == "last-month")
+        return condformat::LASTMONTH;
+    else if(rString == "next-month")
+        return condformat::NEXTMONTH;
+    else if(rString == "this-year")
+        return condformat::THISYEAR;
+    else if(rString == "last-year")
+        return condformat::LASTYEAR;
+    else if(rString == "next-year")
+        return condformat::NEXTYEAR;
+
+    SAL_WARN("sc", "unknown date type: " << rString);
+    return condformat::TODAY;
+}
+
+}
+
+ScXMLDateContext::ScXMLDateContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
+                        const ::rtl::OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
+                        ScConditionalFormat* pFormat ):
+    SvXMLImportContext( rImport, nPrfx, rLName )
+{
+    rtl::OUString sDateType, sStyle;
+    sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
+    const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetCondDateAttrMap();
+    for( sal_Int16 i=0; i < nAttrCount; ++i )
+    {
+        const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
+        rtl::OUString aLocalName;
+        sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName(
+                    sAttrName, &aLocalName ));
+        const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
+
+        switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
+        {
+            case XML_TOK_COND_DATE_VALUE:
+                sDateType = sValue;
+                break;
+            case XML_TOK_COND_DATE_STYLE:
+                sStyle = sValue;
+            default:
+                break;
+        }
+    }
+
+    ScCondDateFormatEntry* pFormatEntry = new ScCondDateFormatEntry(GetScImport().GetDocument());
+    pFormatEntry->SetStyleName(sStyle);
+    pFormatEntry->SetDateType(getDateFromString(sDateType));
+    pFormat->AddEntry(pFormatEntry);
+
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/xmlcondformat.hxx b/sc/source/filter/xml/xmlcondformat.hxx
index 0ace1eb..1b64cd5 100644
--- a/sc/source/filter/xml/xmlcondformat.hxx
+++ b/sc/source/filter/xml/xmlcondformat.hxx
@@ -194,4 +194,18 @@ public:
     virtual ~ScXMLCondContext() {}
 };
 
+class ScXMLDateContext : public SvXMLImportContext
+{
+    const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
+    ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
+public:
+    ScXMLDateContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
+                        const ::rtl::OUString& rLName,
+                        const ::com::sun::star::uno::Reference<
+                                        ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
+                        ScConditionalFormat* pFormat);
+
+    virtual ~ScXMLDateContext() {}
+};
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index a0b53b8..5782dbc 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -3820,6 +3820,41 @@ rtl::OUString getIconSetName(ScIconSetType eType)
     return rtl::OUString::createFromAscii(pName);
 }
 
+rtl::OUString getDateStringForType(condformat::ScCondFormatDateType eType)
+{
+    switch(eType)
+    {
+        case condformat::TODAY:
+            return rtl::OUString("today");
+        case condformat::YESTERDAY:
+            return rtl::OUString("yesterday");
+        case condformat::TOMORROW:
+            return rtl::OUString("tomorrow");
+        case condformat::LAST7DAYS:
+            return rtl::OUString("last-7-days");
+        case condformat::THISWEEK:
+            return rtl::OUString("this-week");
+        case condformat::LASTWEEK:
+            return rtl::OUString("last-week");
+        case condformat::NEXTWEEK:
+            return rtl::OUString("next-week");
+        case condformat::THISMONTH:
+            return rtl::OUString("this-month");
+        case condformat::LASTMONTH:
+            return rtl::OUString("last-month");
+        case condformat::NEXTMONTH:
+            return rtl::OUString("next-month");
+        case condformat::THISYEAR:
+            return rtl::OUString("this-year");
+        case condformat::LASTYEAR:
+            return rtl::OUString("last-year");
+        case condformat::NEXTYEAR:
+            return rtl::OUString("next-year");
+    }
+
+    return rtl::OUString();
+}
+
 }
 
 void ScXMLExport::ExportConditionalFormat(SCTAB nTab)
@@ -4076,6 +4111,14 @@ void ScXMLExport::ExportConditionalFormat(SCTAB nTab)
                             SvXMLElementExport aElementColorScaleEntry(*this, XML_NAMESPACE_CALC_EXT, XML_FORMATTING_ENTRY, true, true);
                         }
                     }
+                    else if(pFormatEntry->GetType() == condformat::DATE)
+                    {
+                        const ScCondDateFormatEntry& mrDateFormat = static_cast<const ScCondDateFormatEntry&>(*pFormatEntry);
+                        rtl::OUString aDateType = getDateStringForType(mrDateFormat.GetDateType());
+                        AddAttribute( XML_NAMESPACE_CALC_EXT, XML_STYLE, mrDateFormat.GetStyleName());
+                        AddAttribute( XML_NAMESPACE_CALC_EXT, XML_DATE, aDateType);
+                        SvXMLElementExport aElementDateFormat(*this, XML_NAMESPACE_CALC_EXT, XML_DATE_IS, true, true);
+                    }
                 }
             }
         }
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index 717d0ee..dd9d155 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -611,6 +611,7 @@ const SvXMLTokenMap& ScXMLImport::GetCondFormatTokenMap()
             { XML_NAMESPACE_CALC_EXT, XML_DATA_BAR, XML_TOK_CONDFORMAT_DATABAR },
             { XML_NAMESPACE_CALC_EXT, XML_CONDITION, XML_TOK_CONDFORMAT_CONDITION },
             { XML_NAMESPACE_CALC_EXT, XML_ICON_SET, XML_TOK_CONDFORMAT_ICONSET },
+            { XML_NAMESPACE_CALC_EXT, XML_DATE_IS, XML_TOK_CONDFORMAT_DATE },
             XML_TOKEN_MAP_END
         };
 
@@ -636,6 +637,23 @@ const SvXMLTokenMap& ScXMLImport::GetCondFormatAttrMap()
     return *pCondFormatAttrMap;
 }
 
+const SvXMLTokenMap& ScXMLImport::GetCondDateAttrMap()
+{
+    if( !pCondDateAttrMap )
+    {
+        static SvXMLTokenMapEntry aCondDateAttrTokenMap[] =
+        {
+            { XML_NAMESPACE_CALC_EXT, XML_DATE, XML_TOK_COND_DATE_VALUE },
+            { XML_NAMESPACE_CALC_EXT, XML_STYLE, XML_TOK_COND_DATE_STYLE },
+            XML_TOKEN_MAP_END
+        };
+
+        pCondDateAttrMap = new SvXMLTokenMap( aCondDateAttrTokenMap );
+    }
+
+    return *pCondDateAttrMap;
+}
+
 const SvXMLTokenMap& ScXMLImport::GetConditionAttrMap()
 {
     if( !pConditionAttrMap )
@@ -1879,6 +1897,7 @@ ScXMLImport::ScXMLImport(
     pCondFormatsTokenMap( 0 ),
     pCondFormatTokenMap( 0 ),
     pCondFormatAttrMap( 0 ),
+    pCondDateAttrMap( 0 ),
     pConditionAttrMap( 0 ),
     pColorScaleTokenMap( 0 ),
     pColorScaleEntryAttrTokenMap( 0 ),
@@ -2017,6 +2036,7 @@ ScXMLImport::~ScXMLImport() throw()
     delete pCondFormatsTokenMap;
     delete pCondFormatTokenMap;
     delete pCondFormatAttrMap;
+    delete pCondDateAttrMap;
     delete pConditionAttrMap;
     delete pColorScaleTokenMap;
     delete pColorScaleEntryAttrTokenMap;
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index ee5708f..532d83a 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -154,7 +154,8 @@ enum ScXMLCondFormatTokens
     XML_TOK_CONDFORMAT_COLORSCALE,
     XML_TOK_CONDFORMAT_DATABAR,
     XML_TOK_CONDFORMAT_CONDITION,
-    XML_TOK_CONDFORMAT_ICONSET
+    XML_TOK_CONDFORMAT_ICONSET,
+    XML_TOK_CONDFORMAT_DATE
 };
 
 enum ScXMLCondFormatAttrTokens
@@ -162,6 +163,12 @@ enum ScXMLCondFormatAttrTokens
     XML_TOK_CONDFORMAT_TARGET_RANGE
 };
 
+enum ScXMLCondDateAttrTokens
+{
+    XML_TOK_COND_DATE_VALUE,
+    XML_TOK_COND_DATE_STYLE
+};
+
 enum ScXMLConditionAttrTokens
 {
     XML_TOK_CONDITION_VALUE,
@@ -775,6 +782,7 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable
     SvXMLTokenMap           *pCondFormatsTokenMap;
     SvXMLTokenMap           *pCondFormatTokenMap;
     SvXMLTokenMap           *pCondFormatAttrMap;
+    SvXMLTokenMap           *pCondDateAttrMap;
     SvXMLTokenMap           *pConditionAttrMap;
     SvXMLTokenMap           *pColorScaleTokenMap;
     SvXMLTokenMap           *pColorScaleEntryAttrTokenMap;
@@ -939,6 +947,7 @@ public:
     const SvXMLTokenMap& GetCondFormatsTokenMap();
     const SvXMLTokenMap& GetCondFormatTokenMap();
     const SvXMLTokenMap& GetCondFormatAttrMap();
+    const SvXMLTokenMap& GetCondDateAttrMap();
     const SvXMLTokenMap& GetConditionAttrMap();
     const SvXMLTokenMap& GetColorScaleTokenMap();
     const SvXMLTokenMap& GetColorScaleEntryAttrMap();
diff --git a/xmloff/inc/xmloff/xmltoken.hxx b/xmloff/inc/xmloff/xmltoken.hxx
index 1492d24..238d0c3 100644
--- a/xmloff/inc/xmloff/xmltoken.hxx
+++ b/xmloff/inc/xmloff/xmltoken.hxx
@@ -560,6 +560,7 @@ namespace xmloff { namespace token {
         XML_DATABASE_SOURCE_SQL,
         XML_DATABASE_SOURCE_TABLE,
         XML_DATE,
+        XML_DATE_IS,
         XML_DATE_ADJUST,
         XML_DATE_STYLE,
         XML_DATE_TIME,
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index 670596f..6a28cfc 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -564,6 +564,7 @@ namespace xmloff { namespace token {
         TOKEN( "database-source-sql",             XML_DATABASE_SOURCE_SQL ),
         TOKEN( "database-source-table",           XML_DATABASE_SOURCE_TABLE ),
         TOKEN( "date",                            XML_DATE ),
+        TOKEN( "date-is",                         XML_DATE_IS ),
         TOKEN( "date-adjust",                     XML_DATE_ADJUST ),
         TOKEN( "date-style",                      XML_DATE_STYLE ),
         TOKEN( "date-time",                       XML_DATE_TIME ),


More information about the Libreoffice-commits mailing list