summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authortushar <tusharrai282@gmail.com>2021-08-17 01:30:00 +0530
committerHeiko Tietze <heiko.tietze@documentfoundation.org>2021-08-30 09:29:21 +0200
commita0b836f73f249138a231f01c1d0289a9b67dc62d (patch)
treecb48e25b77b2b6f06615223db885cb97cfee2249 /sc
parentfa39da583f6b2daee860859cdca69cf174b2b55f (diff)
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@googlemail.com> Tested-by: Jenkins
Diffstat (limited to 'sc')
-rw-r--r--sc/UIConfig_scalc.mk1
-rw-r--r--sc/source/ui/dataprovider/datatransformation.cxx47
-rw-r--r--sc/source/ui/inc/dataproviderdlg.hxx1
-rw-r--r--sc/source/ui/inc/datatransformation.hxx15
-rw-r--r--sc/source/ui/miscdlgs/dataproviderdlg.cxx56
-rw-r--r--sc/uiconfig/scalc/ui/swaprowsentry.ui80
6 files changed, 199 insertions, 1 deletions
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)
@@ -1039,6 +1090,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);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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>