From d0aca687f654eff81b86540007e7c8606ab00e1f Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Thu, 8 Feb 2018 22:46:59 +0100 Subject: init the selected columns in data transformations dialog Change-Id: Ie1d9213ba4f0d88e09a368fa778c77de3e89492f Reviewed-on: https://gerrit.libreoffice.org/49458 Tested-by: Jenkins Reviewed-by: Markus Mohrhard --- sc/source/ui/miscdlgs/dataproviderdlg.cxx | 79 ++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 11 deletions(-) (limited to 'sc/source/ui/miscdlgs/dataproviderdlg.cxx') diff --git a/sc/source/ui/miscdlgs/dataproviderdlg.cxx b/sc/source/ui/miscdlgs/dataproviderdlg.cxx index 11fa52ee2927..78953cb3d4fd 100644 --- a/sc/source/ui/miscdlgs/dataproviderdlg.cxx +++ b/sc/source/ui/miscdlgs/dataproviderdlg.cxx @@ -13,6 +13,8 @@ #include #include +#include + #include constexpr int MENU_START = 0; @@ -202,7 +204,6 @@ IMPL_LINK_NOARG(ScDataProviderBaseControl, ApplyBtnHdl, Button*, void) maImportCallback.Call(this); } - namespace { struct MenuData @@ -275,9 +276,10 @@ class ScSplitColumnTransformationControl : public ScDataTransformationBaseContro private: VclPtr maSeparator; VclPtr maNumColumns; + SCCOL mnCol; public: - ScSplitColumnTransformationControl(vcl::Window* pParent); + ScSplitColumnTransformationControl(vcl::Window* pParent, SCCOL nCol); ~ScSplitColumnTransformationControl() override; virtual void dispose() override; @@ -285,8 +287,9 @@ public: virtual std::shared_ptr getTransformation() override; }; -ScSplitColumnTransformationControl::ScSplitColumnTransformationControl(vcl::Window* pParent): - ScDataTransformationBaseControl(pParent, "modules/scalc/ui/splitcolumnentry.ui") +ScSplitColumnTransformationControl::ScSplitColumnTransformationControl(vcl::Window* pParent, SCCOL nCol): + ScDataTransformationBaseControl(pParent, "modules/scalc/ui/splitcolumnentry.ui"), + mnCol(nCol) { get(maSeparator, "ed_separator"); get(maNumColumns, "num_cols"); @@ -307,28 +310,76 @@ void ScSplitColumnTransformationControl::dispose() std::shared_ptr ScSplitColumnTransformationControl::getTransformation() { - return std::make_shared(0, ','); + OUString aSeparator = maSeparator->GetText(); + sal_Unicode cSeparator = aSeparator.isEmpty() ? ',' : aSeparator[0]; + return std::make_shared(mnCol, cSeparator); } class ScMergeColumnTransformationControl : public ScDataTransformationBaseControl { private: + VclPtr mpSeparator; + VclPtr mpEdColumns; + public: - ScMergeColumnTransformationControl(vcl::Window* pParent); + ScMergeColumnTransformationControl(vcl::Window* pParent, SCCOL nStartCol, SCCOL nEndCol); + ~ScMergeColumnTransformationControl() override; + + virtual void dispose() override; virtual std::shared_ptr getTransformation() override; }; -ScMergeColumnTransformationControl::ScMergeColumnTransformationControl(vcl::Window* pParent): +ScMergeColumnTransformationControl::ScMergeColumnTransformationControl(vcl::Window* pParent, SCCOL nStartCol, SCCOL nEndCol): ScDataTransformationBaseControl(pParent, "modules/scalc/ui/mergecolumnentry.ui") { + get(mpSeparator, "ed_separator"); + get(mpEdColumns, "ed_columns"); + + OUStringBuffer aBuffer; + + // map from zero based to one based column numbers + aBuffer.append(OUString::number(nStartCol + 1)); + for ( SCCOL nCol = nStartCol + 1; nCol <= nEndCol; ++nCol) + { + aBuffer.append(";").append(OUString::number(nCol + 1)); + } + + mpEdColumns->SetText(aBuffer.makeStringAndClear()); +} + +ScMergeColumnTransformationControl::~ScMergeColumnTransformationControl() +{ + disposeOnce(); +} + +void ScMergeColumnTransformationControl::dispose() +{ + mpSeparator.clear(); + mpEdColumns.clear(); + + ScDataTransformationBaseControl::dispose(); } std::shared_ptr ScMergeColumnTransformationControl::getTransformation() { - std::set maColumns = {0, 1}; - return std::make_shared(maColumns, ","); + OUString aColumnString = mpEdColumns->GetText(); + std::vector aSplitColumns = comphelper::string::split(aColumnString, ';'); + std::set aMergedColumns; + 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 + aMergedColumns.insert(nCol - 1); + } + return std::make_shared(aMergedColumns, mpSeparator->GetText()); } } @@ -454,13 +505,19 @@ void ScDataProviderDlg::deleteColumn() void ScDataProviderDlg::splitColumn() { - VclPtr pSplitColumnEntry = VclPtr::Create(mpList); + SCCOL nStartCol = -1; + SCCOL nEndCol = -1; + mpTable->getColRange(nStartCol, nEndCol); + VclPtr pSplitColumnEntry = VclPtr::Create(mpList, nStartCol); mpList->addEntry(pSplitColumnEntry); } void ScDataProviderDlg::mergeColumns() { - VclPtr pMergeColumnEntry = VclPtr::Create(mpList); + SCCOL nStartCol = -1; + SCCOL nEndCol = -1; + mpTable->getColRange(nStartCol, nEndCol); + VclPtr pMergeColumnEntry = VclPtr::Create(mpList, nStartCol, nEndCol); mpList->addEntry(pMergeColumnEntry); } -- cgit