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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Jul 27 23:04:51 UTC 2018


 sc/qa/unit/datatransformation_test.cxx           |   19 ++++++++
 sc/source/ui/dataprovider/datatransformation.cxx |   49 +++++++++++++++++++++++
 sc/source/ui/inc/datatransformation.hxx          |   16 +++++++
 3 files changed, 83 insertions(+), 1 deletion(-)

New commits:
commit 0c350906b1d6dc27383619dd3338fe28768f1c2e
Author:     Vikas <vikasmahato0 at gmail.com>
AuthorDate: Tue Jul 24 21:36:07 2018 +0530
Commit:     Markus Mohrhard <markus.mohrhard at googlemail.com>
CommitDate: Sat Jul 28 01:04:24 2018 +0200

    Added ReplaceNullTransformation
    
    Change-Id: Ic233a9d13312568ac7f25f919d85ca776a47df88
    Reviewed-on: https://gerrit.libreoffice.org/58151
    Tested-by: Jenkins
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sc/qa/unit/datatransformation_test.cxx b/sc/qa/unit/datatransformation_test.cxx
index 00b6b69d4946..06d82181657c 100644
--- a/sc/qa/unit/datatransformation_test.cxx
+++ b/sc/qa/unit/datatransformation_test.cxx
@@ -51,6 +51,7 @@ public:
     void testNumberEven();
     void testNumberOdd();
     void testNumberSign();
+    void testReplaceNull();
 
     CPPUNIT_TEST_SUITE(ScDataTransformationTest);
     CPPUNIT_TEST(testColumnRemove);
@@ -76,6 +77,7 @@ public:
     CPPUNIT_TEST(testNumberEven);
     CPPUNIT_TEST(testNumberOdd);
     CPPUNIT_TEST(testNumberSign);
+    CPPUNIT_TEST(testReplaceNull);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -486,6 +488,23 @@ void ScDataTransformationTest::testNumberSign()
     CPPUNIT_ASSERT_EQUAL(-1.0, m_pDoc->GetValue(2, 3, 0));
 }
 
+void ScDataTransformationTest::testReplaceNull()
+{
+    m_pDoc->SetString(2, 0, 0, "Berlin");
+    m_pDoc->SetString(2, 1, 0, "");
+    m_pDoc->SetString(2, 2, 0, "");
+    m_pDoc->SetString(2, 3, 0, "Peking");
+
+    sc::ReplaceNullTransformation aTransform({2}, "Empty");
+    aTransform.Transform(*m_pDoc);
+
+    CPPUNIT_ASSERT_EQUAL(OUString("Berlin"), m_pDoc->GetString(2, 0, 0));
+    CPPUNIT_ASSERT_EQUAL(OUString("Empty"), m_pDoc->GetString(2, 1, 0));
+    CPPUNIT_ASSERT_EQUAL(OUString("Empty"), m_pDoc->GetString(2, 2, 0));
+    CPPUNIT_ASSERT_EQUAL(OUString("Peking"), m_pDoc->GetString(2, 3, 0));
+
+}
+
 ScDataTransformationTest::ScDataTransformationTest() :
     ScBootstrapFixture( "sc/qa/unit/data/dataprovider" ),
     m_pDoc(nullptr)
diff --git a/sc/source/ui/dataprovider/datatransformation.cxx b/sc/source/ui/dataprovider/datatransformation.cxx
index 53d6745cb689..9efe3ed447e9 100644
--- a/sc/source/ui/dataprovider/datatransformation.cxx
+++ b/sc/source/ui/dataprovider/datatransformation.cxx
@@ -648,6 +648,55 @@ std::set<SCCOL> NumberTransformation::getColumn() const
 {
     return mnCol;
 }
+
+ReplaceNullTransformation::ReplaceNullTransformation(const std::set<SCCOL> nCol, const OUString sReplaceWith):
+    mnCol(nCol),
+    msReplaceWith(sReplaceWith)
+{
+}
+
+void ReplaceNullTransformation::Transform(ScDocument& rDoc) const
+{
+    if (mnCol.empty())
+        return;
+
+    SCROW nEndRow = 0;
+    for(auto& rCol : mnCol)
+    {
+        nEndRow = getLastRow(rDoc, rCol);
+    }
+
+    for(auto& rCol : mnCol)
+    {
+        for (SCROW nRow = 0; nRow < nEndRow; ++nRow)
+        {
+            CellType eType;
+            rDoc.GetCellType(rCol, nRow, 0, eType);
+            if (eType == CELLTYPE_NONE)
+            {
+               // OUString aStr = rDoc.GetString(rCol, nRow, 0);
+               // if (aStr == "" || aStr.isEmpty())
+                    rDoc.SetString(rCol, nRow, 0, msReplaceWith);
+            }
+        }
+    }
+
+}
+
+std::set<SCCOL> ReplaceNullTransformation::getColumn() const
+{
+    return mnCol;
+}
+
+OUString ReplaceNullTransformation::getReplaceString() const
+{
+    return msReplaceWith;
+}
+
+TransformationType ReplaceNullTransformation::getTransformationType() const
+{
+     return TransformationType::REMOVE_NULL_TRANSFORMATION;
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/datatransformation.hxx b/sc/source/ui/inc/datatransformation.hxx
index 0096e0c5a623..48651699a4ef 100644
--- a/sc/source/ui/inc/datatransformation.hxx
+++ b/sc/source/ui/inc/datatransformation.hxx
@@ -29,7 +29,8 @@ enum class TransformationType
     SORT_TRANSFORMATION,
     TEXT_TRANSFORMATION,
     AGGREGATE_FUNCTION,
-    NUMBER_TRANSFORMATION
+    NUMBER_TRANSFORMATION,
+    REMOVE_NULL_TRANSFORMATION
 };
 
 enum class TEXT_TRANSFORM_TYPE { TO_LOWER, TO_UPPER, CAPITALIZE, TRIM };
@@ -148,6 +149,19 @@ class SC_DLLPUBLIC NumberTransformation : public DataTransformation
     std::set<SCCOL> getColumn() const;
 };
 
+class SC_DLLPUBLIC ReplaceNullTransformation : public DataTransformation
+{
+    std::set<SCCOL> mnCol;
+    OUString msReplaceWith;
+
+    public:
+    ReplaceNullTransformation(const std::set<SCCOL> nCol, const OUString sReplaceWith);
+    virtual void Transform(ScDocument& rDoc) const override;
+    virtual TransformationType getTransformationType() const override;
+    std::set<SCCOL> getColumn() const;
+    OUString getReplaceString() const;
+};
+
 }
 
 #endif


More information about the Libreoffice-commits mailing list