[Libreoffice-commits] core.git: sc/source sc/uiconfig sc/UIConfig_scalc.mk

tushar (via logerrit) logerrit at kemper.freedesktop.org
Wed Jul 7 08:08:05 UTC 2021


 sc/UIConfig_scalc.mk                             |    1 
 sc/source/ui/dataprovider/datatransformation.cxx |   46 +++++++++++
 sc/source/ui/inc/dataproviderdlg.hxx             |    2 
 sc/source/ui/inc/datatransformation.hxx          |   18 ++++
 sc/source/ui/miscdlgs/dataproviderdlg.cxx        |   55 +++++++++++++
 sc/uiconfig/scalc/ui/findreplaceentry.ui         |   94 +++++++++++++++++++++++
 6 files changed, 214 insertions(+), 2 deletions(-)

New commits:
commit 1f88af544ffe17c58806a6b947803e1a2b3db378
Author:     tushar <tusharrai282 at gmail.com>
AuthorDate: Sun Jul 4 01:08:21 2021 +0530
Commit:     Markus Mohrhard <markus.mohrhard at googlemail.com>
CommitDate: Wed Jul 7 10:07:33 2021 +0200

    Added Find and Replace Transformation .
    
    Change-Id: I6ba0cd27bfd8b90923fb35d019fe0223bc9f07f8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118384
    Reviewed-by: Heiko Tietze <heiko.tietze at documentfoundation.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    Tested-by: Jenkins

diff --git a/sc/UIConfig_scalc.mk b/sc/UIConfig_scalc.mk
index 705aee221cbf..e19172e49bd3 100644
--- a/sc/UIConfig_scalc.mk
+++ b/sc/UIConfig_scalc.mk
@@ -169,6 +169,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/scalc,\
 	sc/uiconfig/scalc/ui/numbertransformationentry \
 	sc/uiconfig/scalc/ui/replacenulltransformationentry \
 	sc/uiconfig/scalc/ui/datetimetransformationentry \
+	sc/uiconfig/scalc/ui/findreplaceentry \
 	sc/uiconfig/scalc/ui/movecopysheet \
 	sc/uiconfig/scalc/ui/movingaveragedialog \
 	sc/uiconfig/scalc/ui/multipleoperationsdialog \
diff --git a/sc/source/ui/dataprovider/datatransformation.cxx b/sc/source/ui/dataprovider/datatransformation.cxx
index dfdc72375cb1..7e9d51fdc004 100644
--- a/sc/source/ui/dataprovider/datatransformation.cxx
+++ b/sc/source/ui/dataprovider/datatransformation.cxx
@@ -1170,6 +1170,52 @@ const std::set<SCCOL>& DateTimeTransformation::getColumn() const
     return mnCol;
 }
 
+FindReplaceTransformation::FindReplaceTransformation(SCCOL nCol, const OUString& aFindString, const OUString& aReplaceString)
+    : mnCol(nCol)
+    , maFindString(aFindString)
+    , maReplaceString(aReplaceString)
+{
+}
+
+void FindReplaceTransformation::Transform(ScDocument& rDoc) const
+{
+    if (mnCol == -1)
+        return;
+
+    SCROW nEndRow = getLastRow(rDoc, mnCol);
+    for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
+    {
+        CellType eType;
+        rDoc.GetCellType(mnCol, nRow, 0, eType);
+        if (eType != CELLTYPE_NONE)
+        {
+            OUString aStr = rDoc.GetString(mnCol, nRow, 0);
+            if (aStr == maFindString)
+                rDoc.SetString(mnCol, nRow, 0, maReplaceString);
+        }
+    }
+}
+
+TransformationType FindReplaceTransformation::getTransformationType() const
+{
+    return TransformationType::FINDREPLACE_TRANSFORMATION;
+}
+
+SCCOL FindReplaceTransformation::getColumn() const
+{
+    return mnCol;
+}
+
+const OUString& FindReplaceTransformation::getFindString() const
+{
+    return maFindString;
+}
+
+const OUString& FindReplaceTransformation::getReplaceString() const
+{
+    return maReplaceString;
+}
+
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/dataproviderdlg.hxx b/sc/source/ui/inc/dataproviderdlg.hxx
index 582df71e5c22..5f275eace855 100644
--- a/sc/source/ui/inc/dataproviderdlg.hxx
+++ b/sc/source/ui/inc/dataproviderdlg.hxx
@@ -85,6 +85,8 @@ public:
     void deletefromList(sal_uInt32 nIndex);
     void replaceNullTransformation();
     void dateTimeTransformation();
+    void findReplaceTransformation();
+
     void updateApplyBtn(bool bValidConfig);
     void isValid();
 
diff --git a/sc/source/ui/inc/datatransformation.hxx b/sc/source/ui/inc/datatransformation.hxx
index d5b19912e328..5c0741553f64 100644
--- a/sc/source/ui/inc/datatransformation.hxx
+++ b/sc/source/ui/inc/datatransformation.hxx
@@ -30,7 +30,8 @@ enum class TransformationType
     AGGREGATE_FUNCTION,
     NUMBER_TRANSFORMATION,
     REMOVE_NULL_TRANSFORMATION,
-    DATETIME_TRANSFORMATION
+    DATETIME_TRANSFORMATION,
+    FINDREPLACE_TRANSFORMATION
 };
 
 enum class TEXT_TRANSFORM_TYPE { TO_LOWER, TO_UPPER, CAPITALIZE, TRIM };
@@ -181,6 +182,21 @@ class SC_DLLPUBLIC DateTimeTransformation : public DataTransformation
         const std::set<SCCOL>& getColumn() const;
 };
 
+class SC_DLLPUBLIC FindReplaceTransformation : public DataTransformation
+{
+    SCCOL mnCol;
+    OUString maFindString;
+    OUString maReplaceString;
+
+    public:
+        FindReplaceTransformation(SCCOL nCol, const OUString& aFindString, const OUString& aReplaceString);
+        virtual void Transform(ScDocument& rDoc) const override;
+        virtual TransformationType getTransformationType() const override;
+        SCCOL getColumn() const;
+        const OUString & getFindString() const;
+        const OUString & getReplaceString() const;
+};
+
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/miscdlgs/dataproviderdlg.cxx b/sc/source/ui/miscdlgs/dataproviderdlg.cxx
index 757ea7634778..40186b65ccd4 100644
--- a/sc/source/ui/miscdlgs/dataproviderdlg.cxx
+++ b/sc/source/ui/miscdlgs/dataproviderdlg.cxx
@@ -71,7 +71,8 @@ MenuData aTransformationData[] = {
     { "Aggregate Functions", &ScDataProviderDlg::aggregateFunction},
     { "Number Transformations", &ScDataProviderDlg::numberTransformation },
     { "Replace Null Transformations", &ScDataProviderDlg::replaceNullTransformation },
-    { "Date & Time Transformations", &ScDataProviderDlg::dateTimeTransformation }
+    { "Date & Time Transformations", &ScDataProviderDlg::dateTimeTransformation },
+    { "Find Replace Transformation", &ScDataProviderDlg::findReplaceTransformation},
 };
 
 class ScDeleteColumnTransformationControl : public ScDataTransformationBaseControl
@@ -613,6 +614,47 @@ std::shared_ptr<sc::DataTransformation> ScDateTimeTransformation::getTransformat
     return nullptr;
 }
 
+class ScFindReplaceTransformation : public ScDataTransformationBaseControl
+{
+private:
+    std::unique_ptr<weld::Entry> mxFindString;
+    std::unique_ptr<weld::Entry> mxReplaceString;
+    std::unique_ptr<weld::Entry> mxEdColumns;
+    std::unique_ptr<weld::Button> mxDelete;
+    std::function<void(sal_uInt32&)> maDeleteTransformation;
+    const ScDocument* mpDoc;
+
+public:
+    ScFindReplaceTransformation(const ScDocument* pDoc, weld::Container* pParent, sal_uInt32 nIndex, std::function<void(sal_uInt32&)> aDeleteTransformation);
+
+    virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
+    DECL_LINK(DeleteHdl, weld::Button&, void);
+};
+
+ScFindReplaceTransformation::ScFindReplaceTransformation(
+    const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex,
+    std::function<void(sal_uInt32&)> aDeleteTransformation)
+    : ScDataTransformationBaseControl(pParent, "modules/scalc/ui/findreplaceentry.ui", nIndex)
+    , mxFindString(mxBuilder->weld_entry("ed_find"))
+    , mxReplaceString(mxBuilder->weld_entry("ed_replace"))
+    , mxEdColumns(mxBuilder->weld_entry("ed_columns"))
+    , mxDelete(mxBuilder->weld_button("ed_delete"))
+    , maDeleteTransformation(std::move(aDeleteTransformation))
+    , mpDoc(pDoc)
+{
+    mxDelete->connect_clicked(LINK(this, ScFindReplaceTransformation, DeleteHdl));
+}
+
+std::shared_ptr<sc::DataTransformation> ScFindReplaceTransformation::getTransformation()
+{
+    OUString aColStr = mxEdColumns->get_text();
+    SCCOL aColumn = -1;
+    sal_Int32 nCol = aColStr.toInt32();
+    if (nCol > 0 && nCol <= mpDoc->MaxCol())
+        aColumn = nCol - 1;
+    return std::make_shared<sc::FindReplaceTransformation>(aColumn, mxFindString->get_text(), mxReplaceString->get_text());
+}
+
 }
 
 ScDataProviderDlg::ScDataProviderDlg(weld::Window* pParent, std::shared_ptr<ScDocument> pDoc,
@@ -847,6 +889,12 @@ void ScDataProviderDlg::dateTimeTransformation()
     maControls.emplace_back(std::make_unique<ScDateTimeTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
 }
 
+void ScDataProviderDlg::findReplaceTransformation()
+{
+    std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList, this, std::placeholders::_1);
+    maControls.emplace_back(std::make_unique<ScFindReplaceTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
+}
+
 namespace {
 
 bool hasDBName(const OUString& rName, ScDBCollection* pDBCollection)
@@ -936,4 +984,9 @@ IMPL_LINK_NOARG(ScDateTimeTransformation, DeleteHdl, weld::Button&, void)
 {
    maDeleteTransformation(mnIndex);
 }
+
+IMPL_LINK_NOARG(ScFindReplaceTransformation, DeleteHdl, weld::Button&, void)
+{
+   maDeleteTransformation(mnIndex);
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/uiconfig/scalc/ui/findreplaceentry.ui b/sc/uiconfig/scalc/ui/findreplaceentry.ui
new file mode 100644
index 000000000000..1171b789dfbc
--- /dev/null
+++ b/sc/uiconfig/scalc/ui/findreplaceentry.ui
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.2 -->
+<interface domain="sc">
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkGrid" id="grid">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="margin_end">6</property>
+    <property name="border_width">6</property>
+    <property name="row_spacing">6</property>
+    <property name="column_spacing">12</property>
+    <child>
+      <object class="GtkSeparator">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+        <property name="width">4</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="label1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">start</property>
+        <property name="label" translatable="yes" context="findreplace|label_action">Find Replace Action</property>
+        <property name="use_underline">True</property>
+        <property name="mnemonic_widget">ed_find</property>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">1</property>
+        <property name="width">4</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkEntry" id="ed_find">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="hexpand">True</property>
+        <property name="width_chars">7</property>
+        <property name="truncate_multiline">True</property>
+        <property name="placeholder_text" translatable="yes" context="findreplace|find">Find</property>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">2</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkEntry" id="ed_replace">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="hexpand">True</property>
+        <property name="width_chars">7</property>
+        <property name="truncate_multiline">True</property>
+        <property name="placeholder_text" translatable="yes" context="findreplace|replace">Replace With</property>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="top_attach">2</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkEntry" id="ed_columns">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="hexpand">True</property>
+        <property name="width_chars">6</property>
+        <property name="truncate_multiline">True</property>
+        <property name="placeholder_text" translatable="yes" context="findreplace|columns">Column</property>
+      </object>
+      <packing>
+        <property name="left_attach">2</property>
+        <property name="top_attach">2</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButton" id="ed_delete">
+        <property name="label" translatable="yes" context="findreplace|delete">Delete</property>
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="receives_default">False</property>
+        <property name="halign">end</property>
+      </object>
+      <packing>
+        <property name="left_attach">3</property>
+        <property name="top_attach">2</property>
+      </packing>
+    </child>
+  </object>
+</interface>


More information about the Libreoffice-commits mailing list