[Libreoffice-commits] core.git: sc/qa sc/source sc/uiconfig sc/UIConfig_scalc.mk
Manuj Vashist
manujvashist at gmail.com
Sun Jul 8 22:04:19 UTC 2018
sc/UIConfig_scalc.mk | 1
sc/qa/unit/datatransformation_test.cxx | 8 -
sc/source/ui/dataprovider/datatransformation.cxx | 124 ++++++++++++-----------
sc/source/ui/inc/dataproviderdlg.hxx | 1
sc/source/ui/inc/datatransformation.hxx | 4
sc/source/ui/miscdlgs/dataproviderdlg.cxx | 79 ++++++++++++++
sc/uiconfig/scalc/ui/texttransformationentry.ui | 109 ++++++++++++++++++++
7 files changed, 261 insertions(+), 65 deletions(-)
New commits:
commit 9546f6fec9c16c0440ef6db940aa704d2f8c6657
Author: Manuj Vashist <manujvashist at gmail.com>
Date: Mon Jul 2 17:14:11 2018 +0530
added Text transformation in data provider dlg
Change-Id: I69d8aae9289ad6d1cbdf92307c16299a533fcd56
Reviewed-on: https://gerrit.libreoffice.org/56807
Tested-by: Jenkins
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/sc/UIConfig_scalc.mk b/sc/UIConfig_scalc.mk
index 6eb7c34d49f9..498540b645fb 100644
--- a/sc/UIConfig_scalc.mk
+++ b/sc/UIConfig_scalc.mk
@@ -156,6 +156,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/scalc,\
sc/uiconfig/scalc/ui/managenamesdialog \
sc/uiconfig/scalc/ui/mergecellsdialog \
sc/uiconfig/scalc/ui/mergecolumnentry \
+ sc/uiconfig/scalc/ui/texttransformationentry \
sc/uiconfig/scalc/ui/movecopysheet \
sc/uiconfig/scalc/ui/movingaveragedialog \
sc/uiconfig/scalc/ui/multipleoperationsdialog \
diff --git a/sc/qa/unit/datatransformation_test.cxx b/sc/qa/unit/datatransformation_test.cxx
index 3546104fdbee..baea46c694ad 100644
--- a/sc/qa/unit/datatransformation_test.cxx
+++ b/sc/qa/unit/datatransformation_test.cxx
@@ -170,7 +170,7 @@ void ScDataTransformationTest::testTextToLower()
m_pDoc->SetString(2, 2, 0, "Paris");
m_pDoc->SetString(2, 3, 0, "Peking");
- sc::TextTransformation aTransform(2, sc::TEXT_TRANSFORM_TYPE::TO_LOWER);
+ sc::TextTransformation aTransform({2}, sc::TEXT_TRANSFORM_TYPE::TO_LOWER);
aTransform.Transform(*m_pDoc);
CPPUNIT_ASSERT_EQUAL(OUString("berlin"), m_pDoc->GetString(2, 0, 0));
@@ -186,7 +186,7 @@ void ScDataTransformationTest::testTextToUpper()
m_pDoc->SetString(2, 2, 0, "Paris");
m_pDoc->SetString(2, 3, 0, "Peking");
- sc::TextTransformation aTransform(2, sc::TEXT_TRANSFORM_TYPE::TO_UPPER);
+ sc::TextTransformation aTransform({2}, sc::TEXT_TRANSFORM_TYPE::TO_UPPER);
aTransform.Transform(*m_pDoc);
CPPUNIT_ASSERT_EQUAL(OUString("BERLIN"), m_pDoc->GetString(2, 0, 0));
@@ -202,7 +202,7 @@ void ScDataTransformationTest::testTextCapitalize()
m_pDoc->SetString(2, 2, 0, "si tu la ves");
m_pDoc->SetString(2, 3, 0, "cUaNdO mE EnAmOro");
- sc::TextTransformation aTransform(2, sc::TEXT_TRANSFORM_TYPE::CAPITALIZE);
+ sc::TextTransformation aTransform({2}, sc::TEXT_TRANSFORM_TYPE::CAPITALIZE);
aTransform.Transform(*m_pDoc);
CPPUNIT_ASSERT_EQUAL(OUString("Hello World"), m_pDoc->GetString(2, 0, 0));
@@ -217,7 +217,7 @@ void ScDataTransformationTest::testTextTrim()
m_pDoc->SetString(2, 1, 0, "Brussels ");
m_pDoc->SetString(2, 2, 0, " Paris ");
- sc::TextTransformation aTransform(2, sc::TEXT_TRANSFORM_TYPE::TRIM);
+ sc::TextTransformation aTransform({2}, sc::TEXT_TRANSFORM_TYPE::TRIM);
aTransform.Transform(*m_pDoc);
CPPUNIT_ASSERT_EQUAL(OUString("Berlin"), m_pDoc->GetString(2, 0, 0));
diff --git a/sc/source/ui/dataprovider/datatransformation.cxx b/sc/source/ui/dataprovider/datatransformation.cxx
index a1eae17c0df9..75e84a23c2ef 100644
--- a/sc/source/ui/dataprovider/datatransformation.cxx
+++ b/sc/source/ui/dataprovider/datatransformation.cxx
@@ -176,7 +176,7 @@ const ScSortParam & SortTransformation::getSortParam() const
return maSortParam;
}
-TextTransformation::TextTransformation(SCCOL nCol, const TEXT_TRANSFORM_TYPE rType):
+TextTransformation::TextTransformation(const std::set<SCCOL>& nCol, const TEXT_TRANSFORM_TYPE rType):
mnCol(nCol),
maType(rType)
{
@@ -184,85 +184,91 @@ TextTransformation::TextTransformation(SCCOL nCol, const TEXT_TRANSFORM_TYPE rTy
void TextTransformation::Transform(ScDocument& rDoc) const
{
- SCROW nEndRow = getLastRow(rDoc, mnCol);
-
- switch (maType)
+ SCROW nEndRow = 0;
+ for(auto& rCol : mnCol)
{
- case TEXT_TRANSFORM_TYPE::TO_LOWER:
+ nEndRow = getLastRow(rDoc, rCol);
+ }
+ for(auto& rCol : mnCol)
+ {
+ switch (maType)
{
- for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
+ case TEXT_TRANSFORM_TYPE::TO_LOWER:
{
- CellType eType;
- rDoc.GetCellType(mnCol, nRow, 0, eType);
- if (eType == CELLTYPE_STRING)
+ for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
- OUString aStr = rDoc.GetString(mnCol, nRow, 0);
- rDoc.SetString(mnCol, nRow, 0, ScGlobal::pCharClass->lowercase(aStr));
+ CellType eType;
+ rDoc.GetCellType(rCol, nRow, 0, eType);
+ if (eType == CELLTYPE_STRING)
+ {
+ OUString aStr = rDoc.GetString(rCol, nRow, 0);
+ rDoc.SetString(rCol, nRow, 0, ScGlobal::pCharClass->lowercase(aStr));
+ }
}
}
- }
- break;
- case TEXT_TRANSFORM_TYPE::TO_UPPER:
- {
- for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
+ break;
+ case TEXT_TRANSFORM_TYPE::TO_UPPER:
{
- CellType eType;
- rDoc.GetCellType(mnCol, nRow, 0, eType);
- if (eType == CELLTYPE_STRING)
+ for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
- OUString aStr = rDoc.GetString(mnCol, nRow, 0);
- rDoc.SetString(mnCol, nRow, 0, ScGlobal::pCharClass->uppercase(aStr));
+ CellType eType;
+ rDoc.GetCellType(rCol, nRow, 0, eType);
+ if (eType == CELLTYPE_STRING)
+ {
+ OUString aStr = rDoc.GetString(rCol, nRow, 0);
+ rDoc.SetString(rCol, nRow, 0, ScGlobal::pCharClass->uppercase(aStr));
+ }
}
}
- }
- break;
- case TEXT_TRANSFORM_TYPE::CAPITALIZE:
- {
- sal_Unicode separator = sal_Unicode(U' ');
- for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
+ break;
+ case TEXT_TRANSFORM_TYPE::CAPITALIZE:
{
- CellType eType;
- rDoc.GetCellType(mnCol, nRow, 0, eType);
- if (eType == CELLTYPE_STRING)
+ sal_Unicode separator = sal_Unicode(U' ');
+ for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
- OUString aStr = rDoc.GetString(mnCol, nRow, 0);
-
- sal_Int32 length = aStr.getLength();
-
- if(length != 0)
- aStr = aStr.replaceAt(0, 1, ScGlobal::pCharClass->uppercase(OUString(aStr[0])));
-
- for (sal_Int32 i = 1; i < length; i++){
- if (aStr[i-1] == separator)
- {
- aStr = aStr.replaceAt(i, 1, ScGlobal::pCharClass->uppercase(OUString(aStr[i])));
- }
- else
- {
- aStr = aStr.replaceAt(i, 1, ScGlobal::pCharClass->lowercase(OUString(aStr[i])));
+ CellType eType;
+ rDoc.GetCellType(rCol, nRow, 0, eType);
+ if (eType == CELLTYPE_STRING)
+ {
+ OUString aStr = rDoc.GetString(rCol, nRow, 0);
+
+ sal_Int32 length = aStr.getLength();
+
+ if(length != 0)
+ aStr = aStr.replaceAt(0, 1, ScGlobal::pCharClass->uppercase(OUString(aStr[0])));
+
+ for (sal_Int32 i = 1; i < length; i++){
+ if (aStr[i-1] == separator)
+ {
+ aStr = aStr.replaceAt(i, 1, ScGlobal::pCharClass->uppercase(OUString(aStr[i])));
+ }
+ else
+ {
+ aStr = aStr.replaceAt(i, 1, ScGlobal::pCharClass->lowercase(OUString(aStr[i])));
+ }
}
+ rDoc.SetString(rCol, nRow, 0, aStr);
}
- rDoc.SetString(mnCol, nRow, 0, aStr);
}
}
- }
- break;
- case TEXT_TRANSFORM_TYPE::TRIM:
- {
- for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
+ break;
+ case TEXT_TRANSFORM_TYPE::TRIM:
{
- CellType eType;
- rDoc.GetCellType(mnCol, nRow, 0, eType);
- if (eType == CELLTYPE_STRING)
+ for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
{
- OUString aStr = rDoc.GetString(mnCol, nRow, 0);
- rDoc.SetString(mnCol, nRow, 0, aStr.trim());
+ CellType eType;
+ rDoc.GetCellType(rCol, nRow, 0, eType);
+ if (eType == CELLTYPE_STRING)
+ {
+ OUString aStr = rDoc.GetString(rCol, nRow, 0);
+ rDoc.SetString(rCol, nRow, 0, aStr.trim());
+ }
}
}
+ break;
+ default:
+ break;
}
- break;
- default:
- break;
}
}
diff --git a/sc/source/ui/inc/dataproviderdlg.hxx b/sc/source/ui/inc/dataproviderdlg.hxx
index 5b5c444d13d8..cd3f681754f0 100644
--- a/sc/source/ui/inc/dataproviderdlg.hxx
+++ b/sc/source/ui/inc/dataproviderdlg.hxx
@@ -61,6 +61,7 @@ public:
void deleteColumn();
void splitColumn();
void mergeColumns();
+ void textTransformation();
void import(ScDocument* pDoc, bool bInternal = false);
};
diff --git a/sc/source/ui/inc/datatransformation.hxx b/sc/source/ui/inc/datatransformation.hxx
index 611f108abb54..3266ce456b9b 100644
--- a/sc/source/ui/inc/datatransformation.hxx
+++ b/sc/source/ui/inc/datatransformation.hxx
@@ -108,11 +108,11 @@ public:
class SC_DLLPUBLIC TextTransformation : public DataTransformation
{
- SCCOL mnCol;
+ std::set<SCCOL> mnCol;
TEXT_TRANSFORM_TYPE maType;
public:
- TextTransformation(SCCOL nCol, const TEXT_TRANSFORM_TYPE rType);
+ TextTransformation(const std::set<SCCOL>& nCol, const TEXT_TRANSFORM_TYPE rType);
virtual void Transform(ScDocument& rDoc) const override;
virtual TransformationType getTransformationType() const override;
};
diff --git a/sc/source/ui/miscdlgs/dataproviderdlg.cxx b/sc/source/ui/miscdlgs/dataproviderdlg.cxx
index a867b419aa7e..c2ce2f6d4e4f 100644
--- a/sc/source/ui/miscdlgs/dataproviderdlg.cxx
+++ b/sc/source/ui/miscdlgs/dataproviderdlg.cxx
@@ -222,6 +222,7 @@ MenuData aColumnData[] = {
{ 0, "Delete Column", &ScDataProviderDlg::deleteColumn },
{ 1, "Split Column", &ScDataProviderDlg::splitColumn },
{ 2, "Merge Columns", &ScDataProviderDlg::mergeColumns },
+ { 3, "Text Transformation", &ScDataProviderDlg::textTransformation }
};
class ScDataTransformationBaseControl : public VclContainer,
@@ -435,6 +436,78 @@ std::shared_ptr<sc::DataTransformation> ScMergeColumnTransformationControl::getT
return std::make_shared<sc::MergeColumnTransformation>(aMergedColumns, mpSeparator->GetText());
}
+class ScColumnTextTransformation : public ScDataTransformationBaseControl
+{
+private:
+ VclPtr<Edit> maColumnNums;
+ VclPtr<ListBox> maType;
+
+public:
+
+ ScColumnTextTransformation(vcl::Window* pParent);
+ ~ScColumnTextTransformation() override;
+
+ virtual void dispose() override;
+
+ virtual std::shared_ptr<sc::DataTransformation> getTransformation() override;
+
+};
+
+ScColumnTextTransformation::ScColumnTextTransformation(vcl::Window* pParent):
+ ScDataTransformationBaseControl(pParent,"modules/scalc/ui/texttransformationentry.ui")
+{
+ get(maColumnNums, "ed_columns");
+ get(maType, "ed_lst");
+}
+
+ScColumnTextTransformation::~ScColumnTextTransformation()
+{
+ disposeOnce();
+}
+
+void ScColumnTextTransformation::dispose()
+{
+ maColumnNums.clear();
+ maType.clear();
+ ScDataTransformationBaseControl::dispose();
+}
+
+std::shared_ptr<sc::DataTransformation> ScColumnTextTransformation::getTransformation()
+{
+ OUString aColumnString = maColumnNums->GetText();
+ std::vector<OUString> aSplitColumns = comphelper::string::split(aColumnString, ';');
+ std::set<SCCOL> aColumns;
+ for (auto& rColStr : aSplitColumns)
+ {
+ sal_Int32 nCol = rColStr.toInt32();
+ if (nCol <= 0)
+ continue;
+
+ if (nCol > MAXCOL)
+ continue;
+
+ // translate from 1-based column notations to internal Calc one
+ aColumns.insert(nCol - 1);
+ }
+
+ sal_Int32 nPos = maType->GetSelectedEntryPos();
+ switch (nPos)
+ {
+ case 0:
+ return std::make_shared<sc::TextTransformation>(aColumns,sc::TEXT_TRANSFORM_TYPE::TO_LOWER);
+ case 1:
+ return std::make_shared<sc::TextTransformation>(aColumns,sc::TEXT_TRANSFORM_TYPE::TO_UPPER);
+ case 2:
+ return std::make_shared<sc::TextTransformation>(aColumns,sc::TEXT_TRANSFORM_TYPE::CAPITALIZE);
+ case 3:
+ return std::make_shared<sc::TextTransformation>(aColumns,sc::TEXT_TRANSFORM_TYPE::TRIM);
+ default:
+ assert(false);
+ }
+
+ return nullptr;
+}
+
}
ScDataProviderDlg::ScDataProviderDlg(vcl::Window* pParent, std::shared_ptr<ScDocument> pDoc, ScDocument* pDocument):
@@ -581,6 +654,12 @@ void ScDataProviderDlg::mergeColumns()
mpList->addEntry(pMergeColumnEntry);
}
+void ScDataProviderDlg::textTransformation()
+{
+ VclPtr<ScColumnTextTransformation> pTextTransforamtionEntry = VclPtr<ScColumnTextTransformation>::Create(mpList);
+ mpList->addEntry(pTextTransforamtionEntry);
+}
+
void ScDataProviderDlg::import(ScDocument* pDoc, bool bInternal)
{
sc::ExternalDataSource aSource = mpDataProviderCtrl->getDataSource(pDoc);
diff --git a/sc/uiconfig/scalc/ui/texttransformationentry.ui b/sc/uiconfig/scalc/ui/texttransformationentry.ui
new file mode 100644
index 000000000000..0724de2a9419
--- /dev/null
+++ b/sc/uiconfig/scalc/ui/texttransformationentry.ui
@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.2 -->
+<interface domain="sc">
+ <requires lib="gtk+" version="3.18"/>
+ <object class="GtkGrid" id="grid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="border_width">6</property>
+ <property name="row_spacing">6</property>
+ <property name="column_spacing">12</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes" context="texttransformationentry|name">Text Transformation</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="grid_details">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes" context="texttransformationentry|type">Type:</property>
+ <accessibility>
+ <relation type="label-for" target="ed_lst"/>
+ </accessibility>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes" context="texttransformationentry|columns">Columns:</property>
+ <accessibility>
+ <relation type="label-for" target="ed_columns"/>
+ </accessibility>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="ed_columns">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <accessibility>
+ <relation type="labelled-by" target="label2"/>
+ </accessibility>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBoxText" id="ed_lst">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="active">0</property>
+ <property name="active_id">0</property>
+ <items>
+ <item id="0" translatable="yes" context="texttransformation_type|tolower">To Lower</item>
+ <item id="1" translatable="yes" context="texttransformation_type|toupper">To Upper</item>
+ <item id="2" translatable="yes" context="texttransformation_type|capitalize">Capitalize</item>
+ <item id="3" translatable="yes" context="texttransformation_type|trim">Trim</item>
+ </items>
+ <accessibility>
+ <relation type="labelled-by" target="label1"/>
+ </accessibility>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ </object>
+</interface>
More information about the Libreoffice-commits
mailing list