[Libreoffice-commits] core.git: include/xmloff sc/source xmloff/source

Vikas vikasmahato0 at gmail.com
Mon Jul 2 21:43:21 UTC 2018


 include/xmloff/xmltoken.hxx                      |    8 ++
 sc/source/filter/xml/xmlexprt.cxx                |   81 +++++++++++++++++++++++
 sc/source/filter/xml/xmlexprt.hxx                |    3 
 sc/source/ui/dataprovider/datatransformation.cxx |   50 ++++++++++++++
 sc/source/ui/inc/datatransformation.hxx          |   22 +++++-
 xmloff/source/core/xmltoken.cxx                  |    7 +
 xmloff/source/token/tokens.txt                   |    7 +
 7 files changed, 176 insertions(+), 2 deletions(-)

New commits:
commit cb875f3ef1aa14b931131c4c0ddc595e3841273d
Author: Vikas <vikasmahato0 at gmail.com>
Date:   Fri Jun 29 13:52:02 2018 +0530

    Export data transformations to odf
    
    Change-Id: Ie36aef4a4ee550a1bb5407305f13726d55eeea58
    Reviewed-on: https://gerrit.libreoffice.org/56665
    Tested-by: Jenkins
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx
index 5a1cd6157887..862741d0a0eb 100644
--- a/include/xmloff/xmltoken.hxx
+++ b/include/xmloff/xmltoken.hxx
@@ -3278,6 +3278,14 @@ namespace xmloff { namespace token {
         XML_DATA_MAPPINGS,
         XML_DATA_MAPPING,
         XML_DATA_FREQUENCY,
+        XML_DATA_TRANSFORMATIONS,
+        XML_COLUMN_REMOVE_TRANSFORMATION,
+        XML_COLUMN_SPLIT_TRANSFORMATION,
+        XML_COLUMN_MERGE_TRANSFORMATION,
+        XML_COLUMN_SORT_TRANSFORMATION,
+        XML_SORT_PARAM,
+        XML_MERGE_STRING,
+        //Already defined XML_SEPARATOR,
 
         // regina, ODF1.2 additional symbols in charts
         XML_STAR,
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index bcfe73fe22d8..58d0e197b975 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -159,6 +159,8 @@
 #include <vector>
 #include <vbahelper/vbaaccesshelper.hxx>
 
+
+
 //! not found in unonames.hxx
 #define SC_LAYERID "LayerID"
 
@@ -4061,6 +4063,7 @@ void ScXMLExport::WriteExternalDataMapping()
 
     sc::ExternalDataMapper& rDataMapper = pDoc->GetExternalDataMapper();
     auto& rDataSources = rDataMapper.getDataSources();
+
     if (!rDataSources.empty())
     {
         SvXMLElementExport aMappings(*this, XML_NAMESPACE_CALC_EXT, XML_DATA_MAPPINGS, true, true);
@@ -4071,11 +4074,89 @@ void ScXMLExport::WriteExternalDataMapping()
             AddAttribute(XML_NAMESPACE_CALC_EXT, XML_DATA_FREQUENCY, OUString::number(itr.getUpdateFrequency()));
             AddAttribute(XML_NAMESPACE_CALC_EXT, XML_ID, itr.getID());
             AddAttribute(XML_NAMESPACE_CALC_EXT, XML_DATABASE_NAME, itr.getDBName());
+
+            // Add the data transformations
+            WriteExternalDataTransformations(itr.getDataTransformation());
+
             SvXMLElementExport aMapping(*this, XML_NAMESPACE_CALC_EXT, XML_DATA_MAPPING, true, true);
         }
     }
 }
 
+void ScXMLExport::WriteExternalDataTransformations(const std::vector<std::shared_ptr<sc::DataTransformation>>& aDataTransformations)
+{
+    SvXMLElementExport aTransformations(*this, XML_NAMESPACE_CALC_EXT, XML_DATA_TRANSFORMATIONS, true, true);
+    for (auto& itr : aDataTransformations)
+    {
+        sc::TransformationType aTransformationType = itr->getTransformationType();
+
+        switch(aTransformationType)
+        {
+            case sc::TransformationType::DELETE_TRANSFORMATION:
+            {
+                // Delete Columns Transformation
+                std::shared_ptr<sc::ColumnRemoveTransformation> aDeleteTransformation = std::dynamic_pointer_cast<sc::ColumnRemoveTransformation>(itr);
+                std::set<SCCOL> aColumns = aDeleteTransformation->getColumns();
+                SvXMLElementExport aTransformation(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN_REMOVE_TRANSFORMATION, true, true);
+                for(auto& col : aColumns)
+                {
+                    // Add Columns
+                    AddAttribute(XML_NAMESPACE_CALC_EXT, XML_COLUMN, OUString::number(col));
+                    SvXMLElementExport aCol(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN, true, true);
+                }
+            }
+            break;
+            case sc::TransformationType::SPLIT_TRANSFORMATION:
+            {
+                std::shared_ptr<sc::SplitColumnTransformation> aSplitTransformation = std::dynamic_pointer_cast<sc::SplitColumnTransformation>(itr);
+
+                AddAttribute(XML_NAMESPACE_CALC_EXT, XML_COLUMN, OUString::number(aSplitTransformation->getColumn()));
+                AddAttribute(XML_NAMESPACE_CALC_EXT, XML_SEPARATOR, OUString::number(aSplitTransformation->getSeparator()));
+                SvXMLElementExport aTransformation(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN_SPLIT_TRANSFORMATION, true, true);
+            }
+            break;
+            case sc::TransformationType::MERGE_TRANSFORMATION:
+            {
+                // Merge Transformation
+                std::shared_ptr<sc::MergeColumnTransformation> aMergeTransformation = std::dynamic_pointer_cast<sc::MergeColumnTransformation>(itr);
+                std::set<SCCOL> aColumns = aMergeTransformation->getColumns();
+
+                AddAttribute(XML_NAMESPACE_CALC_EXT, XML_MERGE_STRING, aMergeTransformation->getMergeString());
+                SvXMLElementExport aTransformation(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN_MERGE_TRANSFORMATION, true, true);
+
+                for(auto& col : aColumns)
+                {
+                    // Columns
+                    AddAttribute(XML_NAMESPACE_CALC_EXT, XML_COLUMN, OUString::number(col));
+                    SvXMLElementExport aCol(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN, true, true);
+                }
+            }
+            break;
+            case sc::TransformationType::SORT_TRANSFORMATION:
+            {
+                // Sort Transformation
+                std::shared_ptr<sc::SortTransformation> aSortTransformation = std::dynamic_pointer_cast<sc::SortTransformation>(itr);
+                ScSortParam aSortParam = aSortTransformation->getSortParam();
+                const sc::DocumentLinkManager& rMgr = pDoc->GetDocLinkManager();
+                const sc::DataStream* pStrm = rMgr.getDataStream();
+                if (!pStrm)
+                    // No data stream.
+                    return;
+
+                // Streamed range
+                ScRange aRange = pStrm->GetRange();
+
+                SvXMLElementExport aTransformation(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN_SORT_TRANSFORMATION, true, true);
+
+                writeSort(*this, aSortParam, aRange, pDoc);
+            }
+            break;
+            default:
+            break;
+        }
+    }
+}
+
 void ScXMLExport::WriteDataStream()
 {
     if (!pDoc)
diff --git a/sc/source/filter/xml/xmlexprt.hxx b/sc/source/filter/xml/xmlexprt.hxx
index 6107aa86d102..e0eeea036dc7 100644
--- a/sc/source/filter/xml/xmlexprt.hxx
+++ b/sc/source/filter/xml/xmlexprt.hxx
@@ -30,6 +30,8 @@
 #include <memory>
 #include <unordered_map>
 
+#include <datatransformation.hxx>
+
 
 namespace com { namespace sun { namespace star {
     namespace beans { class XPropertySet; }
@@ -196,6 +198,7 @@ class ScXMLExport : public SvXMLExport
     void WriteLabelRanges( const css::uno::Reference< css::container::XIndexAccess >& xRangesIAccess, bool bColumn );
     void WriteNamedExpressions();
     void WriteExternalDataMapping();
+    void WriteExternalDataTransformations(const std::vector<std::shared_ptr<sc::DataTransformation>>& aDataTransformations);
     void WriteDataStream();
     void WriteNamedRange(ScRangeName* pRangeName);
     void ExportConditionalFormat(SCTAB nTab);
diff --git a/sc/source/ui/dataprovider/datatransformation.cxx b/sc/source/ui/dataprovider/datatransformation.cxx
index bbb9bd068c7f..09370a8e82c7 100644
--- a/sc/source/ui/dataprovider/datatransformation.cxx
+++ b/sc/source/ui/dataprovider/datatransformation.cxx
@@ -43,6 +43,16 @@ void ColumnRemoveTransformation::Transform(ScDocument& rDoc) const
     }
 }
 
+TransformationType ColumnRemoveTransformation::getTransformationType() const
+{
+    return TransformationType::DELETE_TRANSFORMATION;
+}
+
+std::set<SCCOL> ColumnRemoveTransformation::getColumns() const
+{
+    return maColumns;
+}
+
 SplitColumnTransformation::SplitColumnTransformation(SCCOL nCol, sal_Unicode cSeparator):
     mnCol(nCol),
     mcSeparator(cSeparator)
@@ -71,6 +81,21 @@ void SplitColumnTransformation::Transform(ScDocument& rDoc) const
     }
 }
 
+TransformationType SplitColumnTransformation::getTransformationType() const
+{
+    return TransformationType::SPLIT_TRANSFORMATION;
+}
+
+SCCOL SplitColumnTransformation::getColumn() const
+{
+    return mnCol;
+}
+
+sal_Unicode SplitColumnTransformation::getSeparator() const
+{
+    return mcSeparator;
+}
+
 MergeColumnTransformation::MergeColumnTransformation(const std::set<SCCOL>& rColumns, const OUString& rMergeString):
     maColumns(rColumns),
     maMergeString(rMergeString)
@@ -113,6 +138,21 @@ void MergeColumnTransformation::Transform(ScDocument& rDoc) const
     }
 }
 
+TransformationType MergeColumnTransformation::getTransformationType() const
+{
+    return TransformationType::MERGE_TRANSFORMATION;
+}
+
+OUString MergeColumnTransformation::getMergeString() const
+{
+    return maMergeString;
+}
+
+std::set<SCCOL> MergeColumnTransformation::getColumns() const
+{
+    return maColumns;
+}
+
 SortTransformation::SortTransformation(const ScSortParam& rSortParam):
     maSortParam(rSortParam)
 {
@@ -123,6 +163,16 @@ void SortTransformation::Transform(ScDocument& rDoc) const
     rDoc.Sort(0, maSortParam, false, false, nullptr, nullptr);
 }
 
+TransformationType SortTransformation::getTransformationType() const
+{
+    return TransformationType::SORT_TRANSFORMATION;
+}
+
+ScSortParam SortTransformation::getSortParam() const
+{
+    return maSortParam;
+}
+
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/datatransformation.hxx b/sc/source/ui/inc/datatransformation.hxx
index 251397ca8304..8dbae9600384 100644
--- a/sc/source/ui/inc/datatransformation.hxx
+++ b/sc/source/ui/inc/datatransformation.hxx
@@ -21,6 +21,14 @@ class ScDocument;
 
 namespace sc {
 
+enum class TransformationType
+{
+    MERGE_TRANSFORMATION,
+    SPLIT_TRANSFORMATION,
+    DELETE_TRANSFORMATION,
+    SORT_TRANSFORMATION
+};
+
 class SC_DLLPUBLIC DataTransformation
 {
 protected:
@@ -32,6 +40,8 @@ public:
 
     virtual void Transform(ScDocument& rDoc) const = 0;
 
+    virtual TransformationType getTransformationType() const = 0;
+
 };
 
 class SC_DLLPUBLIC ColumnRemoveTransformation : public DataTransformation
@@ -42,8 +52,9 @@ public:
 
     ColumnRemoveTransformation(const std::set<SCCOL>& rColumns);
     virtual ~ColumnRemoveTransformation() override;
-
     virtual void Transform(ScDocument& rDoc) const override;
+    virtual TransformationType getTransformationType() const override;
+    std::set<SCCOL> getColumns() const;
 };
 
 class SC_DLLPUBLIC SplitColumnTransformation : public DataTransformation
@@ -55,6 +66,9 @@ public:
 
     SplitColumnTransformation(SCCOL nCol, sal_Unicode cSeparator);
     virtual void Transform(ScDocument& rDoc) const override;
+    virtual TransformationType getTransformationType() const override;
+    SCCOL getColumn() const;
+    sal_Unicode getSeparator() const;
 };
 
 class SC_DLLPUBLIC MergeColumnTransformation : public DataTransformation
@@ -66,6 +80,9 @@ public:
 
     MergeColumnTransformation(const std::set<SCCOL>& rColumns, const OUString& rMergeString);
     virtual void Transform(ScDocument& rDoc) const  override;
+    virtual TransformationType getTransformationType() const override;
+    OUString getMergeString() const;
+    std::set<SCCOL> getColumns() const;
 };
 
 class SC_DLLPUBLIC SortTransformation : public DataTransformation
@@ -74,8 +91,9 @@ class SC_DLLPUBLIC SortTransformation : public DataTransformation
 public:
 
     SortTransformation(const ScSortParam& rParam);
-
     virtual void Transform(ScDocument& rDoc) const override;
+    virtual TransformationType getTransformationType() const override;
+    ScSortParam getSortParam() const;
 };
 
 }
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index d9e221bf34b2..f32309b3e1a1 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -3274,6 +3274,13 @@ namespace xmloff { namespace token {
         TOKEN( "data-mappings", XML_DATA_MAPPINGS),
         TOKEN( "data-mapping", XML_DATA_MAPPING),
         TOKEN( "frequency", XML_DATA_FREQUENCY),
+        TOKEN( "data-transformations", XML_DATA_TRANSFORMATIONS),
+        TOKEN( "column-remove-transformation", XML_COLUMN_REMOVE_TRANSFORMATION),
+        TOKEN( "column-split-transformation", XML_COLUMN_SPLIT_TRANSFORMATION),
+        TOKEN( "column-merge-transformation", XML_COLUMN_MERGE_TRANSFORMATION),
+        TOKEN( "column-sort-transformation", XML_COLUMN_SORT_TRANSFORMATION),
+        TOKEN( "sort-param", XML_SORT_PARAM ),
+        TOKEN( "merge-string", XML_MERGE_STRING ),
 
         // regina, ODF1.2 additional symbols in charts
         TOKEN( "star",                         XML_STAR ),
diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt
index 095b21a8c46f..63e8b99015ab 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -3055,6 +3055,13 @@ provider
 data-mappings
 data-mapping
 frequency
+data-transformations
+column-remove-transformation
+column-split-transformation
+column-merge-transformation
+column-sort-transformation
+sort-param
+merge-string
 star
 asterisk
 horizontal-bar


More information about the Libreoffice-commits mailing list