diff options
author | Manuj Vashist <manujvashist@gmail.com> | 2018-07-10 04:56:37 +0530 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2018-07-12 00:34:31 +0200 |
commit | 5ed11c2ba2b1897955e80d240815f79239b324c2 (patch) | |
tree | 2740da45f108cee9180c1490116dac65d9b25b1b /sc | |
parent | 8666f3670c8e32228cdaf59ee9b879a796bbb308 (diff) |
Added Number transformation in Data Provider Dlg
Change-Id: I9a2e1e16d7683d790826fdc772fbcfbcf8af9881
Reviewed-on: https://gerrit.libreoffice.org/57149
Tested-by: Jenkins
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/UIConfig_scalc.mk | 1 | ||||
-rw-r--r-- | sc/qa/unit/datatransformation_test.cxx | 24 | ||||
-rw-r--r-- | sc/source/ui/dataprovider/datatransformation.cxx | 313 | ||||
-rw-r--r-- | sc/source/ui/inc/dataproviderdlg.hxx | 1 | ||||
-rw-r--r-- | sc/source/ui/inc/datatransformation.hxx | 6 | ||||
-rw-r--r-- | sc/source/ui/miscdlgs/dataproviderdlg.cxx | 102 | ||||
-rw-r--r-- | sc/uiconfig/scalc/ui/numbertransformationentry.ui | 118 |
7 files changed, 394 insertions, 171 deletions
diff --git a/sc/UIConfig_scalc.mk b/sc/UIConfig_scalc.mk index 3b79d5d6b225..70d17e3ace35 100644 --- a/sc/UIConfig_scalc.mk +++ b/sc/UIConfig_scalc.mk @@ -159,6 +159,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/scalc,\ sc/uiconfig/scalc/ui/texttransformationentry \ sc/uiconfig/scalc/ui/sorttransformationentry \ sc/uiconfig/scalc/ui/aggregatefunctionentry \ + sc/uiconfig/scalc/ui/numbertransformationentry \ 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 baea46c694ad..00b6b69d4946 100644 --- a/sc/qa/unit/datatransformation_test.cxx +++ b/sc/qa/unit/datatransformation_test.cxx @@ -303,7 +303,7 @@ void ScDataTransformationTest::testNumberRound() m_pDoc->SetValue(2, 2, 0, 57453.651345687654345676); m_pDoc->SetValue(2, 3, 0, -453.22234567543); - sc::NumberTransformation aTransform(2, sc::NUMBER_TRANSFORM_TYPE::ROUND, 4); + sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::ROUND, 4); aTransform.Transform(*m_pDoc); CPPUNIT_ASSERT_EQUAL(2034.3425, m_pDoc->GetValue(2, 0, 0)); @@ -319,7 +319,7 @@ void ScDataTransformationTest::testNumberRoundUp() m_pDoc->SetValue(2, 2, 0, 57453.65); m_pDoc->SetValue(2, 3, 0, -453.22); - sc::NumberTransformation aTransform(2, sc::NUMBER_TRANSFORM_TYPE::ROUND_UP); + sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::ROUND_UP); aTransform.Transform(*m_pDoc); CPPUNIT_ASSERT_EQUAL(2035.0, m_pDoc->GetValue(2, 0, 0)); @@ -335,7 +335,7 @@ void ScDataTransformationTest::testNumberRoundDown() m_pDoc->SetValue(2, 2, 0, 57453.65); m_pDoc->SetValue(2, 3, 0, -453.22); - sc::NumberTransformation aTransform(2, sc::NUMBER_TRANSFORM_TYPE::ROUND_DOWN); + sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::ROUND_DOWN); aTransform.Transform(*m_pDoc); CPPUNIT_ASSERT_EQUAL(2034.0, m_pDoc->GetValue(2, 0, 0)); @@ -351,7 +351,7 @@ void ScDataTransformationTest::testNumberAbsolute() m_pDoc->SetValue(2, 2, 0, 57453.65); m_pDoc->SetValue(2, 3, 0, -453.22); - sc::NumberTransformation aTransform(2, sc::NUMBER_TRANSFORM_TYPE::ABSOLUTE); + sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::ABSOLUTE); aTransform.Transform(*m_pDoc); CPPUNIT_ASSERT_EQUAL(2034.34, m_pDoc->GetValue(2, 0, 0)); @@ -367,7 +367,7 @@ void ScDataTransformationTest::testNumberLogE() m_pDoc->SetValue(2, 2, 0, -9); m_pDoc->SetValue(2, 3, 0, 500); - sc::NumberTransformation aTransform(2, sc::NUMBER_TRANSFORM_TYPE::LOG_E); + sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::LOG_E); aTransform.Transform(*m_pDoc); CPPUNIT_ASSERT_DOUBLES_EQUAL(0, m_pDoc->GetValue(2, 0, 0), 1e-10); @@ -383,7 +383,7 @@ void ScDataTransformationTest::testNumberLog10() m_pDoc->SetValue(2, 2, 0, -9); m_pDoc->SetValue(2, 3, 0, 500); - sc::NumberTransformation aTransform(2, sc::NUMBER_TRANSFORM_TYPE::LOG_10); + sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::LOG_10); aTransform.Transform(*m_pDoc); CPPUNIT_ASSERT_DOUBLES_EQUAL(0, m_pDoc->GetValue(2, 0, 0), 1e-10); @@ -399,7 +399,7 @@ void ScDataTransformationTest::testNumberCube() m_pDoc->SetValue(2, 2, 0, 8); m_pDoc->SetValue(2, 3, 0, -8); - sc::NumberTransformation aTransform(2, sc::NUMBER_TRANSFORM_TYPE::CUBE); + sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::CUBE); aTransform.Transform(*m_pDoc); CPPUNIT_ASSERT_EQUAL(8.0, m_pDoc->GetValue(2, 0, 0)); @@ -415,7 +415,7 @@ void ScDataTransformationTest::testNumberSquare() m_pDoc->SetValue(2, 2, 0, 8); m_pDoc->SetValue(2, 3, 0, -8); - sc::NumberTransformation aTransform(2, sc::NUMBER_TRANSFORM_TYPE::SQUARE); + sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::SQUARE); aTransform.Transform(*m_pDoc); CPPUNIT_ASSERT_EQUAL(4.0, m_pDoc->GetValue(2, 0, 0)); @@ -430,7 +430,7 @@ void ScDataTransformationTest::testNumberSquareRoot() m_pDoc->SetValue(2, 1, 0, 4); m_pDoc->SetValue(2, 2, 0, 9); - sc::NumberTransformation aTransform(2, sc::NUMBER_TRANSFORM_TYPE::SQUARE_ROOT); + sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::SQUARE_ROOT); aTransform.Transform(*m_pDoc); CPPUNIT_ASSERT_DOUBLES_EQUAL(2.82842712475, m_pDoc->GetValue(2, 0, 0), 1e-10); @@ -445,7 +445,7 @@ void ScDataTransformationTest::testNumberEven() m_pDoc->SetValue(2, 2, 0, 57453.65); m_pDoc->SetValue(2, 3, 0, -453); - sc::NumberTransformation aTransform(2, sc::NUMBER_TRANSFORM_TYPE::IS_EVEN); + sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::IS_EVEN); aTransform.Transform(*m_pDoc); CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(2, 0, 0)); @@ -461,7 +461,7 @@ void ScDataTransformationTest::testNumberOdd() m_pDoc->SetValue(2, 2, 0, 57453.65); m_pDoc->SetValue(2, 3, 0, -453); - sc::NumberTransformation aTransform(2, sc::NUMBER_TRANSFORM_TYPE::IS_ODD); + sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::IS_ODD); aTransform.Transform(*m_pDoc); CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(2, 0, 0)); @@ -477,7 +477,7 @@ void ScDataTransformationTest::testNumberSign() m_pDoc->SetValue(2, 2, 0, 0); m_pDoc->SetValue(2, 3, 0, -453.22); - sc::NumberTransformation aTransform(2, sc::NUMBER_TRANSFORM_TYPE::SIGN); + sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::SIGN); aTransform.Transform(*m_pDoc); CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(2, 0, 0)); diff --git a/sc/source/ui/dataprovider/datatransformation.cxx b/sc/source/ui/dataprovider/datatransformation.cxx index aa14563985dd..0e2048d3dd43 100644 --- a/sc/source/ui/dataprovider/datatransformation.cxx +++ b/sc/source/ui/dataprovider/datatransformation.cxx @@ -394,14 +394,14 @@ std::set<SCCOL> AggregateFunction::getColumns() const return maColumns; } -NumberTransformation::NumberTransformation(SCCOL nCol, const NUMBER_TRANSFORM_TYPE rType): +NumberTransformation::NumberTransformation(const std::set<SCCOL> nCol, const NUMBER_TRANSFORM_TYPE rType): mnCol(nCol), maType(rType), maPrecision(-1) { } -NumberTransformation::NumberTransformation(SCCOL nCol,const NUMBER_TRANSFORM_TYPE rType, int nPrecision): +NumberTransformation::NumberTransformation(const std::set<SCCOL> nCol,const NUMBER_TRANSFORM_TYPE rType, int nPrecision): mnCol(nCol), maType(rType), maPrecision(nPrecision) @@ -410,216 +410,223 @@ NumberTransformation::NumberTransformation(SCCOL nCol,const NUMBER_TRANSFORM_TYP void NumberTransformation::Transform(ScDocument& rDoc) const { - SCROW nEndRow = getLastRow(rDoc, mnCol); + SCROW nEndRow = 0; + for(auto& rCol : mnCol) + { + nEndRow = getLastRow(rDoc, rCol); + } - switch (maType) + for(auto& rCol : mnCol) { - case NUMBER_TRANSFORM_TYPE::ROUND: + switch (maType) { - if(maPrecision > -1) + case NUMBER_TRANSFORM_TYPE::ROUND: { - for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) + if(maPrecision > -1) { - CellType eType; - rDoc.GetCellType(mnCol, nRow, 0, eType); - if (eType == CELLTYPE_VALUE) + for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) { - double nVal = rDoc.GetValue(mnCol, nRow, 0); - rDoc.SetValue(mnCol, nRow, 0, rtl::math::round(nVal, maPrecision)); + CellType eType; + rDoc.GetCellType(rCol, nRow, 0, eType); + if (eType == CELLTYPE_VALUE) + { + double nVal = rDoc.GetValue(rCol, nRow, 0); + rDoc.SetValue(rCol, nRow, 0, rtl::math::round(nVal, maPrecision)); + } } } } - } - break; - case NUMBER_TRANSFORM_TYPE::ROUND_UP: - { - for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) + break; + case NUMBER_TRANSFORM_TYPE::ROUND_UP: { - CellType eType; - rDoc.GetCellType(mnCol, nRow, 0, eType); - if (eType == CELLTYPE_VALUE) + for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) { - double nVal = rDoc.GetValue(mnCol, nRow, 0); - rDoc.SetValue(mnCol, nRow, 0, rtl::math::approxCeil(nVal)); + CellType eType; + rDoc.GetCellType(rCol, nRow, 0, eType); + if (eType == CELLTYPE_VALUE) + { + double nVal = rDoc.GetValue(rCol, nRow, 0); + rDoc.SetValue(rCol, nRow, 0, rtl::math::approxCeil(nVal)); + } } } - } - break; - case NUMBER_TRANSFORM_TYPE::ROUND_DOWN: - { - for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) + break; + case NUMBER_TRANSFORM_TYPE::ROUND_DOWN: { - CellType eType; - rDoc.GetCellType(mnCol, nRow, 0, eType); - if (eType == CELLTYPE_VALUE) + for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) { - double nVal = rDoc.GetValue(mnCol, nRow, 0); - rDoc.SetValue(mnCol, nRow, 0, rtl::math::approxFloor(nVal)); + CellType eType; + rDoc.GetCellType(rCol, nRow, 0, eType); + if (eType == CELLTYPE_VALUE) + { + double nVal = rDoc.GetValue(rCol, nRow, 0); + rDoc.SetValue(rCol, nRow, 0, rtl::math::approxFloor(nVal)); + } } } - } - break; - case NUMBER_TRANSFORM_TYPE::ABSOLUTE: - { - for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) + break; + case NUMBER_TRANSFORM_TYPE::ABSOLUTE: { - CellType eType; - rDoc.GetCellType(mnCol, nRow, 0, eType); - if (eType == CELLTYPE_VALUE) + for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) { - double nVal = rDoc.GetValue(mnCol, nRow, 0); - if(rtl::math::isSignBitSet(nVal)) - rDoc.SetValue(mnCol, nRow, 0, -1 * nVal); + CellType eType; + rDoc.GetCellType(rCol, nRow, 0, eType); + if (eType == CELLTYPE_VALUE) + { + double nVal = rDoc.GetValue(rCol, nRow, 0); + if(rtl::math::isSignBitSet(nVal)) + rDoc.SetValue(rCol, nRow, 0, -1 * nVal); + } } } - } - break; - case NUMBER_TRANSFORM_TYPE::LOG_E: - { - for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) + break; + case NUMBER_TRANSFORM_TYPE::LOG_E: { - CellType eType; - rDoc.GetCellType(mnCol, nRow, 0, eType); - if (eType == CELLTYPE_VALUE) + for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) { - double nVal = rDoc.GetValue(mnCol, nRow, 0); - if (nVal > 0) - { - rDoc.SetValue(mnCol, nRow, 0, rtl::math::log1p(nVal-1)); - } - else + CellType eType; + rDoc.GetCellType(rCol, nRow, 0, eType); + if (eType == CELLTYPE_VALUE) { - rDoc.SetString(mnCol, nRow, 0, OUString()); + double nVal = rDoc.GetValue(rCol, nRow, 0); + if (nVal > 0) + { + rDoc.SetValue(rCol, nRow, 0, rtl::math::log1p(nVal-1)); + } + else + { + rDoc.SetString(rCol, nRow, 0, OUString()); + } } } } - } - break; - case NUMBER_TRANSFORM_TYPE::LOG_10: - { - for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) + break; + case NUMBER_TRANSFORM_TYPE::LOG_10: { - CellType eType; - rDoc.GetCellType(mnCol, nRow, 0, eType); - if (eType == CELLTYPE_VALUE) + for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) { - double nVal = rDoc.GetValue(mnCol, nRow, 0); - if (nVal > 0) - { - rDoc.SetValue(mnCol, nRow, 0, log10(nVal)); - } - else + CellType eType; + rDoc.GetCellType(rCol, nRow, 0, eType); + if (eType == CELLTYPE_VALUE) { - rDoc.SetString(mnCol, nRow, 0, OUString()); + double nVal = rDoc.GetValue(rCol, nRow, 0); + if (nVal > 0) + { + rDoc.SetValue(rCol, nRow, 0, log10(nVal)); + } + else + { + rDoc.SetString(rCol, nRow, 0, OUString()); + } } } } - } - break; - case NUMBER_TRANSFORM_TYPE::CUBE: - { - for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) + break; + case NUMBER_TRANSFORM_TYPE::CUBE: { - CellType eType; - rDoc.GetCellType(mnCol, nRow, 0, eType); - if (eType == CELLTYPE_VALUE) + for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) { - double nVal = rDoc.GetValue(mnCol, nRow, 0); - rDoc.SetValue(mnCol, nRow, 0, nVal * nVal * nVal); + CellType eType; + rDoc.GetCellType(rCol, nRow, 0, eType); + if (eType == CELLTYPE_VALUE) + { + double nVal = rDoc.GetValue(rCol, nRow, 0); + rDoc.SetValue(rCol, nRow, 0, nVal * nVal * nVal); + } } } - } - break; - case NUMBER_TRANSFORM_TYPE::SQUARE: - { - for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) + break; + case NUMBER_TRANSFORM_TYPE::SQUARE: { - CellType eType; - rDoc.GetCellType(mnCol, nRow, 0, eType); - if (eType == CELLTYPE_VALUE) + for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) { - double nVal = rDoc.GetValue(mnCol, nRow, 0); - rDoc.SetValue(mnCol, nRow, 0, nVal * nVal); + CellType eType; + rDoc.GetCellType(rCol, nRow, 0, eType); + if (eType == CELLTYPE_VALUE) + { + double nVal = rDoc.GetValue(rCol, nRow, 0); + rDoc.SetValue(rCol, nRow, 0, nVal * nVal); + } } } - } - break; - case NUMBER_TRANSFORM_TYPE::SQUARE_ROOT: - { - for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) + break; + case NUMBER_TRANSFORM_TYPE::SQUARE_ROOT: { - CellType eType; - rDoc.GetCellType(mnCol, nRow, 0, eType); - if (eType == CELLTYPE_VALUE) + for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) { - double nVal = rDoc.GetValue(mnCol, nRow, 0); - if (!rtl::math::isSignBitSet(nVal)) - { - rDoc.SetValue(mnCol, nRow, 0, sqrt(nVal)); - } - else + CellType eType; + rDoc.GetCellType(rCol, nRow, 0, eType); + if (eType == CELLTYPE_VALUE) { - rDoc.SetString(mnCol, nRow, 0, OUString()); + double nVal = rDoc.GetValue(rCol, nRow, 0); + if (!rtl::math::isSignBitSet(nVal)) + { + rDoc.SetValue(rCol, nRow, 0, sqrt(nVal)); + } + else + { + rDoc.SetString(rCol, nRow, 0, OUString()); + } } } } - } - break; - case NUMBER_TRANSFORM_TYPE::IS_EVEN: - { - for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) + break; + case NUMBER_TRANSFORM_TYPE::IS_EVEN: { - CellType eType; - rDoc.GetCellType(mnCol, nRow, 0, eType); - if (eType == CELLTYPE_VALUE) + for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) { - double nVal = rDoc.GetValue(mnCol, nRow, 0); - if (fmod(nVal, 1) == 0 && fmod(nVal, 2) == 0) - rDoc.SetValue(mnCol, nRow, 0, 1); - else - rDoc.SetValue(mnCol, nRow, 0, 0); + CellType eType; + rDoc.GetCellType(rCol, nRow, 0, eType); + if (eType == CELLTYPE_VALUE) + { + double nVal = rDoc.GetValue(rCol, nRow, 0); + if (fmod(nVal, 1) == 0 && fmod(nVal, 2) == 0) + rDoc.SetValue(rCol, nRow, 0, 1); + else + rDoc.SetValue(rCol, nRow, 0, 0); + } } } - } - break; - case NUMBER_TRANSFORM_TYPE::IS_ODD: - { - for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) + break; + case NUMBER_TRANSFORM_TYPE::IS_ODD: { - CellType eType; - rDoc.GetCellType(mnCol, nRow, 0, eType); - if (eType == CELLTYPE_VALUE) + for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) { - double nVal = rDoc.GetValue(mnCol, nRow, 0); - if (fmod(nVal, 1) == 0 && fmod(nVal, 2) != 0) - rDoc.SetValue(mnCol, nRow, 0, 1); - else - rDoc.SetValue(mnCol, nRow, 0, 0); + CellType eType; + rDoc.GetCellType(rCol, nRow, 0, eType); + if (eType == CELLTYPE_VALUE) + { + double nVal = rDoc.GetValue(rCol, nRow, 0); + if (fmod(nVal, 1) == 0 && fmod(nVal, 2) != 0) + rDoc.SetValue(rCol, nRow, 0, 1); + else + rDoc.SetValue(rCol, nRow, 0, 0); + } } } - } - break; - case NUMBER_TRANSFORM_TYPE::SIGN: - { - for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) + break; + case NUMBER_TRANSFORM_TYPE::SIGN: { - CellType eType; - rDoc.GetCellType(mnCol, nRow, 0, eType); - if (eType == CELLTYPE_VALUE) + for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) { - double nVal = rDoc.GetValue(mnCol, nRow, 0); - if (nVal > 0) - rDoc.SetValue(mnCol, nRow, 0, 1); - else if (nVal < 0) - rDoc.SetValue(mnCol, nRow, 0, -1); - else - rDoc.SetValue(mnCol, nRow, 0, 0); + CellType eType; + rDoc.GetCellType(rCol, nRow, 0, eType); + if (eType == CELLTYPE_VALUE) + { + double nVal = rDoc.GetValue(rCol, nRow, 0); + if (nVal > 0) + rDoc.SetValue(rCol, nRow, 0, 1); + else if (nVal < 0) + rDoc.SetValue(rCol, nRow, 0, -1); + else + rDoc.SetValue(rCol, nRow, 0, 0); + } } } + break; + default: + break; } - break; - default: - break; } } @@ -644,4 +651,4 @@ SCCOL NumberTransformation::getColumn() const } } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file diff --git a/sc/source/ui/inc/dataproviderdlg.hxx b/sc/source/ui/inc/dataproviderdlg.hxx index d41d9a141604..14e5bb0953e0 100644 --- a/sc/source/ui/inc/dataproviderdlg.hxx +++ b/sc/source/ui/inc/dataproviderdlg.hxx @@ -64,6 +64,7 @@ public: void textTransformation(); void sortTransformation(); void aggregateFunction(); + void numberTransformation(); void import(ScDocument* pDoc, bool bInternal = false); }; diff --git a/sc/source/ui/inc/datatransformation.hxx b/sc/source/ui/inc/datatransformation.hxx index 0dea9fe8773f..71eb7406e5a4 100644 --- a/sc/source/ui/inc/datatransformation.hxx +++ b/sc/source/ui/inc/datatransformation.hxx @@ -134,13 +134,13 @@ class SC_DLLPUBLIC AggregateFunction : public DataTransformation class SC_DLLPUBLIC NumberTransformation : public DataTransformation { - SCCOL mnCol; + std::set<SCCOL> mnCol; NUMBER_TRANSFORM_TYPE maType; int maPrecision; public: - NumberTransformation(SCCOL nCol, const NUMBER_TRANSFORM_TYPE rType); - NumberTransformation(SCCOL nCol, const NUMBER_TRANSFORM_TYPE rType, int nPrecision); + NumberTransformation(const std::set<SCCOL> nCol, const NUMBER_TRANSFORM_TYPE rType); + NumberTransformation(const std::set<SCCOL> nCol, const NUMBER_TRANSFORM_TYPE rType, int nPrecision); virtual void Transform(ScDocument& rDoc) const override; virtual TransformationType getTransformationType() const override; NUMBER_TRANSFORM_TYPE getNumberTransfromationType() const; diff --git a/sc/source/ui/miscdlgs/dataproviderdlg.cxx b/sc/source/ui/miscdlgs/dataproviderdlg.cxx index e30b3505d3bd..c50ed0541a97 100644 --- a/sc/source/ui/miscdlgs/dataproviderdlg.cxx +++ b/sc/source/ui/miscdlgs/dataproviderdlg.cxx @@ -224,7 +224,8 @@ MenuData aColumnData[] = { { 2, "Merge Columns", &ScDataProviderDlg::mergeColumns }, { 3, "Text Transformation", &ScDataProviderDlg::textTransformation }, { 4, "Sort Columns", &ScDataProviderDlg::sortTransformation }, - { 5, "Aggregate Functions", &ScDataProviderDlg::aggregateFunction} + { 5, "Aggregate Functions", &ScDataProviderDlg::aggregateFunction}, + { 6, "Number Transformations", &ScDataProviderDlg::numberTransformation } }; class ScDataTransformationBaseControl : public VclContainer, @@ -634,7 +635,96 @@ std::shared_ptr<sc::DataTransformation> ScAggregateFunction::getTransformation() return nullptr; } - + +class ScNumberTransformation : public ScDataTransformationBaseControl +{ +private: + VclPtr<Edit> maColumnNums; + VclPtr<ListBox> maType; + +public: + + ScNumberTransformation(vcl::Window* pParent); + ~ScNumberTransformation() override; + + virtual void dispose() override; + + virtual std::shared_ptr<sc::DataTransformation> getTransformation() override; + +}; + +ScNumberTransformation::ScNumberTransformation(vcl::Window* pParent): + ScDataTransformationBaseControl(pParent,"modules/scalc/ui/numbertransformationentry.ui") +{ + get(maColumnNums, "ed_columns"); + get(maType, "ed_lst"); +} + +ScNumberTransformation::~ScNumberTransformation() +{ + disposeOnce(); +} + +void ScNumberTransformation::dispose() +{ + maColumnNums.clear(); + maType.clear(); + ScDataTransformationBaseControl::dispose(); +} + +std::shared_ptr<sc::DataTransformation> ScNumberTransformation::getTransformation() +{ + OUString aColumnString = maColumnNums->GetText(); + sal_Int32 nPos = maType->GetSelectedEntryPos(); + 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); + } + switch (nPos) + { + case 0: + return std::make_shared<sc::NumberTransformation>(aColumns,sc::NUMBER_TRANSFORM_TYPE::SIGN); + case 1: + return std::make_shared<sc::NumberTransformation>(aColumns,sc::NUMBER_TRANSFORM_TYPE::ROUND); + case 2: + return std::make_shared<sc::NumberTransformation>(aColumns,sc::NUMBER_TRANSFORM_TYPE::ROUND_UP); + case 3: + return std::make_shared<sc::NumberTransformation>(aColumns,sc::NUMBER_TRANSFORM_TYPE::ROUND_DOWN); + case 4: + return std::make_shared<sc::NumberTransformation>(aColumns,sc::NUMBER_TRANSFORM_TYPE::ABSOLUTE); + case 5: + return std::make_shared<sc::NumberTransformation>(aColumns,sc::NUMBER_TRANSFORM_TYPE::LOG_E); + case 6: + return std::make_shared<sc::NumberTransformation>(aColumns,sc::NUMBER_TRANSFORM_TYPE::LOG_10); + case 7: + return std::make_shared<sc::NumberTransformation>(aColumns,sc::NUMBER_TRANSFORM_TYPE::CUBE); + case 8: + return std::make_shared<sc::NumberTransformation>(aColumns,sc::NUMBER_TRANSFORM_TYPE::SQUARE); + case 9: + return std::make_shared<sc::NumberTransformation>(aColumns,sc::NUMBER_TRANSFORM_TYPE::SQUARE_ROOT); + case 10: + return std::make_shared<sc::NumberTransformation>(aColumns,sc::NUMBER_TRANSFORM_TYPE::EXPONENT); + case 11: + return std::make_shared<sc::NumberTransformation>(aColumns,sc::NUMBER_TRANSFORM_TYPE::IS_EVEN); + case 12: + return std::make_shared<sc::NumberTransformation>(aColumns,sc::NUMBER_TRANSFORM_TYPE::IS_ODD); + default: + assert(false); + } + + return nullptr; +} + } ScDataProviderDlg::ScDataProviderDlg(vcl::Window* pParent, std::shared_ptr<ScDocument> pDoc, ScDocument* pDocument): @@ -799,6 +889,12 @@ void ScDataProviderDlg::aggregateFunction() mpList->addEntry(pAggregateFuntionEntry); } +void ScDataProviderDlg::numberTransformation() +{ + VclPtr<ScNumberTransformation> pNumberTransformationEntry = VclPtr<ScNumberTransformation>::Create(mpList); + mpList->addEntry(pNumberTransformationEntry); +} + void ScDataProviderDlg::import(ScDocument* pDoc, bool bInternal) { sc::ExternalDataSource aSource = mpDataProviderCtrl->getDataSource(pDoc); @@ -824,4 +920,4 @@ void ScDataProviderDlg::import(ScDocument* pDoc, bool bInternal) mpTable->Invalidate(); } -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file diff --git a/sc/uiconfig/scalc/ui/numbertransformationentry.ui b/sc/uiconfig/scalc/ui/numbertransformationentry.ui new file mode 100644 index 000000000000..1b7761f3989a --- /dev/null +++ b/sc/uiconfig/scalc/ui/numbertransformationentry.ui @@ -0,0 +1,118 @@ +<?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="numbertransformationentry|name">Number Transformations</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="numbertransformationentry|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="numbertransformationentry|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="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="numbertransformationentry|sign">Sign</item> + <item id="1" translatable="yes" context="numbertransformationentry|round">Round</item> + <item id="2" translatable="yes" context="numbertransformationentry|roundup">Round Up</item> + <item id="3" translatable="yes" context="numbertransformationentry|rounddown">Round Down</item> + <item id="4" translatable="yes" context="numbertransformationentry|absolute">absolute Value</item> + <item id="5" translatable="yes" context="numbertransformationentry|loge">Log with base e</item> + <item id="6" translatable="yes" context="numbertransformationentry|log10">Log with base 10</item> + <item id="7" translatable="yes" context="numbertransformationentry|cube">Cube</item> + <item id="8" translatable="yes" context="numbertransformationentry|square">Square</item> + <item id="9" translatable="yes" context="numbertransformationentry|squareroot">Square Root</item> + <item id="10" translatable="yes" context="numbertransformationentry|exponent">Exponent</item> + <item id="11" translatable="yes" context="numbertransformationentry|iseven">Is Even</item> + <item id="12" translatable="yes" context="numbertransformationentry|isodd">Is Odd</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> + <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> + </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> |