sc/inc/table.hxx | 2 - sc/qa/uitest/data/tdf160104.ods |binary sc/qa/uitest/solver/solver.py | 57 +++++++++++++++++++++++++++++++++ sc/qa/unit/data/ods/SolverModel.ods |binary sc/qa/unit/ucalc_solver.cxx | 24 +++++++++++++ sc/source/core/data/SolverSettings.cxx | 3 + 6 files changed, 85 insertions(+), 1 deletion(-)
New commits: commit 2533960315607bf3e86ad014d2daa4bfa7e3fa59 Author: Rafael Lima <rafael.palma.l...@gmail.com> AuthorDate: Mon Apr 1 14:46:35 2024 +0100 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Apr 8 16:03:03 2024 +0200 tdf#160064 Hide named ranges/expressions of solver models Prior to this patch, all named ranges/expressions associated with solver models were visible by default, which clutters the UI with various names in the Manage Names dialog. Now all such named ranges/expressions are hidden by default, thus mimicking what MSO does. Change-Id: I79727b375c48527632c4967d174c61f99ff41050 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165621 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index f04b1fa0df7a..f578926535ae 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -1047,7 +1047,7 @@ public: const ScObjectHandling eObjectHandling = ScObjectHandling::RecalcPosMode); void SetRangeName(std::unique_ptr<ScRangeName> pNew); - ScRangeName* GetRangeName() const; + SC_DLLPUBLIC ScRangeName* GetRangeName() const; void PreprocessRangeNameUpdate( sc::EndListeningContext& rEndListenCxt, sc::CompileFormulaContext& rCompileCxt ); diff --git a/sc/qa/uitest/data/tdf160104.ods b/sc/qa/uitest/data/tdf160104.ods index a98340f80a50..ea8f23bb4791 100644 Binary files a/sc/qa/uitest/data/tdf160104.ods and b/sc/qa/uitest/data/tdf160104.ods differ diff --git a/sc/qa/uitest/solver/solver.py b/sc/qa/uitest/solver/solver.py index 2a164b90f6c5..ed8132b0f205 100644 --- a/sc/qa/uitest/solver/solver.py +++ b/sc/qa/uitest/solver/solver.py @@ -132,4 +132,61 @@ class solver(UITestCase): # Here isModified needs to be True because changes were made to the Solver dialog self.assertTrue(calc_doc.isModified()) + + # Tests whether all solver named ranges are hidden in the UI + def test_tdf160064(self): + # This test uses the same file from bug tdf#160104, so no need to check if the model is correct upon opening + with self.ui_test.load_file(get_url_for_data_file("tdf160104.ods")) as calc_doc: + # The Manage Names dialog must not contain any names + with self.ui_test.execute_dialog_through_command(".uno:DefineName") as xDialog: + xList = xDialog.getChild("names") + self.assertEqual('0', get_state_as_dict(xList)['Children']) + + # Makes a small change in the solver dialog by clicking the "Minimize" button + with self.ui_test.execute_modeless_dialog_through_command(".uno:SolverDialog", close_button="") as xDialog: + xMin = xDialog.getChild("min") + xMin.executeAction("CLICK", ()) + # Closes the dialog + xCloseBtn = xDialog.getChild("close") + xCloseBtn.executeAction("CLICK", ()) + + # Here the file has been modified and needs to be saved and reloaded + self.assertTrue(calc_doc.isModified()) + self.xUITest.executeCommand('.uno:Save') + self.xUITest.executeCommand('.uno:Reload') + + # Open the Solver dialog and check whether the model is loaded correctly + with self.ui_test.execute_modeless_dialog_through_command(".uno:SolverDialog", close_button="") as xDialog: + xTargetEdit = xDialog.getChild("targetedit") + xMin = xDialog.getChild("min") + xChangeEdit = xDialog.getChild("changeedit") + xRef1Edit = xDialog.getChild("ref1edit") + xVal1Edit = xDialog.getChild("val1edit") + xOp1List = xDialog.getChild("op1list") + xRef2Edit = xDialog.getChild("ref2edit") + xVal2Edit = xDialog.getChild("val2edit") + xOp2List = xDialog.getChild("op2list") + + # Checks whether the solver model was loaded correctly + self.assertEqual("$F$2", get_state_as_dict(xTargetEdit)["Text"]) + self.assertEqual("true", get_state_as_dict(xMin)["Checked"]) + self.assertEqual("$D$2:$D$11", get_state_as_dict(xChangeEdit)["Text"]) + self.assertEqual("$F$5", get_state_as_dict(xRef1Edit)["Text"]) + self.assertEqual("$F$8", get_state_as_dict(xVal1Edit)["Text"]) + self.assertEqual("≤", get_state_as_dict(xOp1List)["SelectEntryText"]) + self.assertEqual("$D$2:$D$11", get_state_as_dict(xRef2Edit)["Text"]) + self.assertEqual("", get_state_as_dict(xVal2Edit)["Text"]) + self.assertEqual("Binary", get_state_as_dict(xOp2List)["SelectEntryText"]) + + # Closes the dialog + xCloseBtn = xDialog.getChild("close") + xCloseBtn.executeAction("CLICK", ()) + + # Open the Manage Names dialog again; it must not contain any names + with self.ui_test.execute_dialog_through_command(".uno:DefineName") as xDialog: + xList = xDialog.getChild("names") + self.assertEqual('0', get_state_as_dict(xList)['Children']) + + + # vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sc/qa/unit/data/ods/SolverModel.ods b/sc/qa/unit/data/ods/SolverModel.ods new file mode 100644 index 000000000000..9ebfa69d4e44 Binary files /dev/null and b/sc/qa/unit/data/ods/SolverModel.ods differ diff --git a/sc/qa/unit/ucalc_solver.cxx b/sc/qa/unit/ucalc_solver.cxx index f7db19cad59a..06feb5347db4 100644 --- a/sc/qa/unit/ucalc_solver.cxx +++ b/sc/qa/unit/ucalc_solver.cxx @@ -216,4 +216,28 @@ CPPUNIT_TEST_FIXTURE(SolverTest, tdf156814) CPPUNIT_ASSERT_EQUAL(OUString("0"), aConstraints[2].aRightStr); } +// Tests if all named ranges and expressions are hidden in the existing model +CPPUNIT_TEST_FIXTURE(SolverTest, tdf160064) +{ + createScDoc("ods/SolverModel.ods"); + ScDocument* pDoc = getScDoc(); + + ScTable* pTable = pDoc->FetchTable(0); + ScRangeName* pNamedRanges = pTable->GetRangeName(); + ScRangeName::const_iterator it = pNamedRanges->begin(); + + // There are 34 hidden named ranges and expressions in the file + CPPUNIT_ASSERT_EQUAL(size_t(34), pNamedRanges->size()); + + // All named ranges and expressions are hidden in the file + while (it != pNamedRanges->end()) + { + OUString sName = it->first; + ScRangeData* pRangeData + = pNamedRanges->findByUpperName(ScGlobal::getCharClass().uppercase(sName)); + CPPUNIT_ASSERT(pRangeData->HasType(ScRangeData::Type::Hidden)); + it++; + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/source/core/data/SolverSettings.cxx b/sc/source/core/data/SolverSettings.cxx index 99bb6d9af2fc..1320d470efcf 100644 --- a/sc/source/core/data/SolverSettings.cxx +++ b/sc/source/core/data/SolverSettings.cxx @@ -401,6 +401,7 @@ void SolverSettings::WriteConstraintPart(ConstraintPart ePart, tools::Long nInde OUString sRange = m_aConstraintParts[ePart] + OUString::number(nIndex); ScRangeData* pNewEntry = new ScRangeData(m_rDoc, sRange, sValue); + pNewEntry->AddType(ScRangeData::Type::Hidden); m_pRangeName->insert(pNewEntry); } @@ -615,6 +616,7 @@ void SolverSettings::WriteParamValue(SolverParameter eParam, OUString sValue, bo assert(iter != m_mNamedRanges.end()); OUString sRange = iter->second; ScRangeData* pNewEntry = new ScRangeData(m_rDoc, sRange, sValue); + pNewEntry->AddType(ScRangeData::Type::Hidden); m_pRangeName->insert(pNewEntry); } @@ -631,6 +633,7 @@ void SolverSettings::WriteDoubleParamValue(SolverParameter eParam, std::u16strin fValue, rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, ScGlobal::getLocaleData().getNumDecimalSep()[0], true); ScRangeData* pNewEntry = new ScRangeData(m_rDoc, sRange, sLocalizedValue); + pNewEntry->AddType(ScRangeData::Type::Hidden); m_pRangeName->insert(pNewEntry); }