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

tushar (via logerrit) logerrit at kemper.freedesktop.org
Mon Aug 30 07:29:48 UTC 2021


 sc/UIConfig_scalc.mk                             |    1 
 sc/source/filter/ftools/ftools.cxx               |   14 ++--
 sc/source/filter/inc/ftools.hxx                  |    2 
 sc/source/filter/inc/lotimpop.hxx                |    2 
 sc/source/filter/lotus/lotform.cxx               |   17 ++--
 sc/source/ui/dataprovider/datatransformation.cxx |   47 +++++++++++++
 sc/source/ui/inc/dataproviderdlg.hxx             |    1 
 sc/source/ui/inc/datatransformation.hxx          |   15 ++++
 sc/source/ui/miscdlgs/dataproviderdlg.cxx        |   56 ++++++++++++++++
 sc/uiconfig/scalc/ui/swaprowsentry.ui            |   80 +++++++++++++++++++++++
 10 files changed, 219 insertions(+), 16 deletions(-)

New commits:
commit a0b836f73f249138a231f01c1d0289a9b67dc62d
Author:     tushar <tusharrai282 at gmail.com>
AuthorDate: Tue Aug 17 01:30:00 2021 +0530
Commit:     Heiko Tietze <heiko.tietze at documentfoundation.org>
CommitDate: Mon Aug 30 09:29:21 2021 +0200

    Add Swap Rows Transformation.
    
    Entries of given rows are swapped after applying transformation.
    
    Change-Id: Iac9da1b15781656b4127bf74f6a95e8cb82fa3d0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120556
    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 114be7d8f602..ce625df9f301 100644
--- a/sc/UIConfig_scalc.mk
+++ b/sc/UIConfig_scalc.mk
@@ -171,6 +171,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/scalc,\
 	sc/uiconfig/scalc/ui/datetimetransformationentry \
 	sc/uiconfig/scalc/ui/findreplaceentry \
 	sc/uiconfig/scalc/ui/deleterowentry \
+	sc/uiconfig/scalc/ui/swaprowsentry \
 	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 e1013baa1e47..004c82a3c024 100644
--- a/sc/source/ui/dataprovider/datatransformation.cxx
+++ b/sc/source/ui/dataprovider/datatransformation.cxx
@@ -1261,6 +1261,53 @@ const OUString& DeleteRowTransformation::getFindString() const
     return maFindString;
 }
 
+SwapRowsTransformation::SwapRowsTransformation(SCROW mRow, SCROW nRow)
+    : mxRow(mRow)
+    , nxRow(nRow)
+{
+}
+
+void SwapRowsTransformation::Transform(ScDocument& rDoc) const
+{
+    if (mxRow == -1 || nxRow == -1)
+        return;
+
+    for (SCCOL nCol = 0; nCol <= rDoc.MaxCol(); ++nCol)
+    {
+        CellType aType;
+        rDoc.GetCellType(nCol, mxRow, 0, aType);
+        if (aType == CELLTYPE_STRING)
+        {
+            OUString aStr = rDoc.GetString(nCol, mxRow, 0);
+            OUString bStr = rDoc.GetString(nCol, nxRow, 0);
+            rDoc.SetString(nCol, mxRow, 0, bStr);
+            rDoc.SetString(nCol, nxRow, 0, aStr);
+        }
+        else if (aType == CELLTYPE_VALUE)
+        {
+            double aVal = rDoc.GetValue(nCol, mxRow, 0);
+            double bVal = rDoc.GetValue(nCol, nxRow, 0);
+            rDoc.SetValue(nCol, mxRow, 0, bVal);
+            rDoc.SetValue(nCol, nxRow, 0, aVal);
+        }
+    }
+}
+
+TransformationType SwapRowsTransformation::getTransformationType() const
+{
+    return TransformationType::SWAPROWS_TRANSFORMATION;
+}
+
+SCROW SwapRowsTransformation::getFirstRow() const
+{
+    return mxRow;
+}
+
+SCROW SwapRowsTransformation::getSecondRow() const
+{
+    return nxRow;
+}
+
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/dataproviderdlg.hxx b/sc/source/ui/inc/dataproviderdlg.hxx
index ec054d283149..127b6361abbd 100644
--- a/sc/source/ui/inc/dataproviderdlg.hxx
+++ b/sc/source/ui/inc/dataproviderdlg.hxx
@@ -87,6 +87,7 @@ public:
     void dateTimeTransformation();
     void findReplaceTransformation();
     void deleteRowTransformation();
+    void swapRowsTransformation();
 
     void updateApplyBtn(bool bValidConfig);
     void isValid();
diff --git a/sc/source/ui/inc/datatransformation.hxx b/sc/source/ui/inc/datatransformation.hxx
index e5bf96690da0..d575be4c4785 100644
--- a/sc/source/ui/inc/datatransformation.hxx
+++ b/sc/source/ui/inc/datatransformation.hxx
@@ -32,7 +32,8 @@ enum class TransformationType
     REMOVE_NULL_TRANSFORMATION,
     DATETIME_TRANSFORMATION,
     FINDREPLACE_TRANSFORMATION,
-    DELETEROW_TRANSFORMATION
+    DELETEROW_TRANSFORMATION,
+    SWAPROWS_TRANSFORMATION
 };
 
 enum class TEXT_TRANSFORM_TYPE { TO_LOWER, TO_UPPER, CAPITALIZE, TRIM };
@@ -211,6 +212,18 @@ class DeleteRowTransformation : public DataTransformation
         const OUString & getFindString() const;
 };
 
+class SC_DLLPUBLIC SwapRowsTransformation : public DataTransformation
+{
+    SCROW mxRow, nxRow;
+
+    public:
+        SwapRowsTransformation(SCROW mRow, SCROW nRow);
+        virtual void Transform(ScDocument& rDoc) const override;
+        virtual TransformationType getTransformationType() const override;
+        SCROW getFirstRow() const;
+        SCROW getSecondRow() 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 8c11a831ebb3..5bef01c62180 100644
--- a/sc/source/ui/miscdlgs/dataproviderdlg.cxx
+++ b/sc/source/ui/miscdlgs/dataproviderdlg.cxx
@@ -65,6 +65,7 @@ struct MenuData
 MenuData aTransformationData[] = {
     { "Delete Column", &ScDataProviderDlg::deleteColumn },
     { "Delete Row", &ScDataProviderDlg::deleteRowTransformation},
+    { "Swap Rows", &ScDataProviderDlg::swapRowsTransformation},
     { "Split Column", &ScDataProviderDlg::splitColumn },
     { "Merge Columns", &ScDataProviderDlg::mergeColumns },
     { "Text Transformation", &ScDataProviderDlg::textTransformation },
@@ -695,6 +696,50 @@ std::shared_ptr<sc::DataTransformation> ScDeleteRowTransformation::getTransforma
     return std::make_shared<sc::DeleteRowTransformation>(aColumn, mxFindString->get_text());
 }
 
+class ScSwapRowsTransformation : public ScDataTransformationBaseControl
+{
+private:
+    std::unique_ptr<weld::Entry> mxRow;
+    std::unique_ptr<weld::Entry> nxRow;
+    std::unique_ptr<weld::Button> mxDelete;
+    std::function<void(sal_uInt32&)> maDeleteTransformation;
+    const ScDocument* mpDoc;
+
+public:
+    ScSwapRowsTransformation(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);
+};
+
+ScSwapRowsTransformation::ScSwapRowsTransformation(
+    const ScDocument *pDoc, weld::Container* pParent, sal_uInt32 nIndex,
+    std::function<void(sal_uInt32&)> aDeleteTransformation)
+    : ScDataTransformationBaseControl(pParent, "modules/scalc/ui/swaprowsentry.ui", nIndex)
+    , mxRow(mxBuilder->weld_entry("ed_row1"))
+    , nxRow(mxBuilder->weld_entry("ed_row2"))
+    , mxDelete(mxBuilder->weld_button("ed_delete"))
+    , maDeleteTransformation(std::move(aDeleteTransformation))
+    , mpDoc(pDoc)
+{
+    mxDelete->connect_clicked(LINK(this, ScSwapRowsTransformation, DeleteHdl));
+}
+
+std::shared_ptr<sc::DataTransformation> ScSwapRowsTransformation::getTransformation()
+{
+    OUString aRowStr = mxRow->get_text();
+    OUString bRowStr = nxRow->get_text();
+    SCROW aRow = -1;
+    SCROW bRow = -1;
+    sal_Int32 mRow = aRowStr.toInt32();
+    sal_Int32 nRow = bRowStr.toInt32();
+    if (mRow > 0 && mRow <= mpDoc->MaxRow())
+        aRow = mRow - 1;
+    if (nRow > 0 && nRow <= mpDoc->MaxRow())
+        bRow = nRow - 1;
+    return std::make_shared<sc::SwapRowsTransformation>(aRow, bRow);
+}
+
 }
 
 ScDataProviderDlg::ScDataProviderDlg(weld::Window* pParent, std::shared_ptr<ScDocument> pDoc,
@@ -942,6 +987,12 @@ void ScDataProviderDlg::deleteRowTransformation()
     maControls.emplace_back(std::make_unique<ScDeleteRowTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
 }
 
+void ScDataProviderDlg::swapRowsTransformation()
+{
+    std::function<void(sal_uInt32&)> adeleteTransformation = std::bind(&ScDataProviderDlg::deletefromList, this, std::placeholders::_1);
+    maControls.emplace_back(std::make_unique<ScSwapRowsTransformation>(mxDoc.get(), mxTransformationList.get(), mnIndex++, adeleteTransformation));
+}
+
 namespace {
 
 bool hasDBName(const OUString& rName, ScDBCollection* pDBCollection)
@@ -1038,6 +1089,11 @@ IMPL_LINK_NOARG(ScFindReplaceTransformation, DeleteHdl, weld::Button&, void)
 }
 
 IMPL_LINK_NOARG(ScDeleteRowTransformation, DeleteHdl, weld::Button&, void)
+{
+    maDeleteTransformation(mnIndex);
+}
+
+IMPL_LINK_NOARG(ScSwapRowsTransformation, DeleteHdl, weld::Button&, void)
 {
    maDeleteTransformation(mnIndex);
 }
diff --git a/sc/uiconfig/scalc/ui/swaprowsentry.ui b/sc/uiconfig/scalc/ui/swaprowsentry.ui
new file mode 100644
index 000000000000..397d3b30af5c
--- /dev/null
+++ b/sc/uiconfig/scalc/ui/swaprowsentry.ui
@@ -0,0 +1,80 @@
+<?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">3</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="swaprows|action">Swap Rows Action</property>
+        <property name="use_underline">True</property>
+        <property name="mnemonic_widget">ed_row1</property>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">1</property>
+        <property name="width">3</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkEntry" id="ed_row1">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="hexpand">True</property>
+        <property name="width_chars">10</property>
+        <property name="truncate_multiline">True</property>
+        <property name="placeholder_text" translatable="yes" context="swaprows|row1">First Row</property>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">2</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkEntry" id="ed_row2">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="hexpand">True</property>
+        <property name="width_chars">10</property>
+        <property name="truncate_multiline">True</property>
+        <property name="placeholder_text" translatable="yes" context="swaprows|row2">Second Row</property>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="top_attach">2</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButton" id="ed_delete">
+        <property name="label" translatable="yes" context="swaprows|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">2</property>
+        <property name="top_attach">2</property>
+      </packing>
+    </child>
+  </object>
+</interface>
commit fa39da583f6b2daee860859cdca69cf174b2b55f
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Sun Aug 29 21:07:17 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Mon Aug 30 09:29:14 2021 +0200

    ofz: MemorySanitizer: use-of-uninitialized-value
    
    Change-Id: I941bb60c1d06189491964004fb98d0d21fc75c49
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121237
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sc/source/filter/ftools/ftools.cxx b/sc/source/filter/ftools/ftools.cxx
index ccac6ecc49e1..d82b84a2eb60 100644
--- a/sc/source/filter/ftools/ftools.cxx
+++ b/sc/source/filter/ftools/ftools.cxx
@@ -38,13 +38,15 @@
 
 // ScFilterTools::ReadLongDouble()
 
-double ScfTools::ReadLongDouble( SvStream& rStrm )
+void ScfTools::ReadLongDouble(SvStream& rStrm, double& fResult)
 
 #ifdef __SIMPLE_FUNC                // for <=VC 1.5
 {
     long double fRet;
-    rStrm.Read( &fRet, 10 );
-    return static_cast< double >( fRet );
+    bool bOk = 10 == rStrm.Read(&fRet, 10);
+    if (!bOk)
+        return;
+    fResult = static_cast<double>(fRet);
 }
 #undef __SIMPLE_FUNC
 
@@ -67,7 +69,9 @@ SEEEEEEE EEEEEEEE IMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM
     long double lfFactor = 256.0;
     sal_uInt8 pDouble10[ 10 ];
 
-    rStrm.ReadBytes(pDouble10, 10);            // Intel-10 in pDouble10
+    bool bOk = 10 == rStrm.ReadBytes(pDouble10, 10);            // Intel-10 in pDouble10
+    if (!bOk)
+        return;
 
     lfDouble  = static_cast< long double >( pDouble10[ 7 ] );   // Byte 7
     lfDouble *= lfFactor;
@@ -102,7 +106,7 @@ SEEEEEEE EEEEEEEE IMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM
     if( pDouble10[ 9 ] & 0x80 )
         lfDouble *= static_cast< long double >( -1.0 );
 
-    return static_cast< double >( lfDouble );
+    fResult = static_cast<double>(lfDouble);
 }
 #endif
 
diff --git a/sc/source/filter/inc/ftools.hxx b/sc/source/filter/inc/ftools.hxx
index b02d47d4981f..caeeef4598c6 100644
--- a/sc/source/filter/inc/ftools.hxx
+++ b/sc/source/filter/inc/ftools.hxx
@@ -128,7 +128,7 @@ public:
 // *** common methods *** -----------------------------------------------------
 
     /** Reads a 10-byte-long-double and converts it to double. */
-    static double       ReadLongDouble( SvStream& rStrm );
+    static void ReadLongDouble(SvStream& rStrm, double& fResult);
     /** Returns system text encoding for byte string conversion. */
     static rtl_TextEncoding GetSystemTextEncoding();
     /** Returns a string representing the hexadecimal value of nValue. */
diff --git a/sc/source/filter/inc/lotimpop.hxx b/sc/source/filter/inc/lotimpop.hxx
index 5bc90a47d1f0..916cbda11a89 100644
--- a/sc/source/filter/inc/lotimpop.hxx
+++ b/sc/source/filter/inc/lotimpop.hxx
@@ -120,7 +120,7 @@ inline void ImportLotus::Read( sal_Int16& r )
 
 inline void ImportLotus::Read( double& r )
 {
-    r = ScfTools::ReadLongDouble( *pIn );
+    ScfTools::ReadLongDouble(*pIn, r);
 }
 
 inline void ImportLotus::Read( LotAttrWK3& r )
diff --git a/sc/source/filter/lotus/lotform.cxx b/sc/source/filter/lotus/lotform.cxx
index 48882d71bee9..61a83e42fbe4 100644
--- a/sc/source/filter/lotus/lotform.cxx
+++ b/sc/source/filter/lotus/lotform.cxx
@@ -626,14 +626,15 @@ void LotusToSc::Convert( std::unique_ptr<ScTokenArray>& rpErg, sal_Int32& rRest
             }
                 break;
             case FT_Const10Float:
-                    if ( bWK123 )
-                    {
-                            double fValue;
-                            Read( fValue );
-                            aStack << aPool.Store( fValue );
-                    }
-                    else aStack << aPool.Store( ScfTools::ReadLongDouble( aIn ) );
-                    break;
+            {
+                double fValue;
+                if (bWK123)
+                    Read(fValue);
+                else
+                    ScfTools::ReadLongDouble(aIn, fValue);
+                aStack << aPool.Store(fValue);
+                break;
+            }
             case FT_Snum:
                 if ( bWK123 )
                 {


More information about the Libreoffice-commits mailing list