diff options
author | Manuj Vashist <manujvashist@gmail.com> | 2018-07-02 17:14:11 +0530 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2018-07-09 00:03:57 +0200 |
commit | 9546f6fec9c16c0440ef6db940aa704d2f8c6657 (patch) | |
tree | 955e7006b0fbfcf4f3574d0228f02e741b65e125 /sc/source/ui | |
parent | e300efd3a029672e24114914355c5c690fb725d5 (diff) |
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@googlemail.com>
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/dataprovider/datatransformation.cxx | 124 | ||||
-rw-r--r-- | sc/source/ui/inc/dataproviderdlg.hxx | 1 | ||||
-rw-r--r-- | sc/source/ui/inc/datatransformation.hxx | 4 | ||||
-rw-r--r-- | sc/source/ui/miscdlgs/dataproviderdlg.cxx | 79 |
4 files changed, 147 insertions, 61 deletions
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); |