sc/inc/document.hxx | 21 ++++++++++++++++++--- sc/source/ui/miscdlgs/solvrdlg.cxx | 24 +++++++++++++++++++++++- 2 files changed, 41 insertions(+), 4 deletions(-)
New commits: commit daedc81fa22690ce1a08b477a52360f05e4f5ed9 Author: Rafael Lima <rafael.palma.l...@gmail.com> AuthorDate: Tue Jun 11 11:19:40 2024 -0300 Commit: Rafael Lima <rafael.palma.l...@gmail.com> CommitDate: Thu Jun 13 01:46:50 2024 +0200 tdf#161462 Remember Goal Seek settings Each time the user opens the Goal Seek dialogs, all settings are reset. This patch makes these settings be remembered during the same session. Change-Id: I60a121b4001f4666ee25ab807fdc3860cf798296 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168683 Tested-by: Jenkins Reviewed-by: Heiko Tietze <heiko.tie...@documentfoundation.org> diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 4dbce67d2928..cc714491e6d9 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -319,6 +319,15 @@ enum ScMutationGuardFlags CORE = 0x0001, /// Core calc data structures should not be mutated }; +// Stores settings used in the Goal Seek +struct ScGoalSeekSettings +{ + bool bDefined = false; + ScAddress aFormulaCell; + ScAddress aVariableCell; + OUString sTargetValue; +}; + typedef std::unique_ptr<ScTable, o3tl::default_delete<ScTable>> ScTableUniquePtr; class ScDocument @@ -453,6 +462,9 @@ private: css::uno::Reference< css::script::vba::XVBAEventProcessor > mxVbaEvents; + + // Stores Goal Seek settings + ScGoalSeekSettings maGoalSeekSettings; public: /// list of ScInterpreterTableOpParams currently in use std::vector<ScInterpreterTableOpParams*> m_TableOpList; @@ -1967,9 +1979,12 @@ public: void GetSearchAndReplaceStart( const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow ); - bool Solver( SCCOL nFCol, SCROW nFRow, SCTAB nFTab, - SCCOL nVCol, SCROW nVRow, SCTAB nVTab, - const OUString& sValStr, double& nX); + // Goal Seek solver + bool Solver( SCCOL nFCol, SCROW nFRow, SCTAB nFTab, + SCCOL nVCol, SCROW nVRow, SCTAB nVTab, + const OUString& sValStr, double& nX); + ScGoalSeekSettings GetGoalSeekSettings() { return maGoalSeekSettings; } + void SetGoalSeekSettings(ScGoalSeekSettings aNewSettings) { maGoalSeekSettings = aNewSettings; } SC_DLLPUBLIC void ApplySelectionPattern( const ScPatternAttr& rAttr, const ScMarkData& rMark, ScEditDataArray* pDataArray = nullptr, bool* pIsChanged = nullptr ); diff --git a/sc/source/ui/miscdlgs/solvrdlg.cxx b/sc/source/ui/miscdlgs/solvrdlg.cxx index 824f4bfad752..4f1b38f1f857 100644 --- a/sc/source/ui/miscdlgs/solvrdlg.cxx +++ b/sc/source/ui/miscdlgs/solvrdlg.cxx @@ -95,7 +95,21 @@ void ScSolverDlg::Init() OUString aStr(theFormulaCell.Format(ScRefFlags::ADDR_ABS, nullptr, pDoc->GetAddressConvention())); - m_xEdFormulaCell->SetText( aStr ); + // If Goal Seek settings are stored in the document, restore them + ScGoalSeekSettings aSettings = pDoc->GetGoalSeekSettings(); + if (aSettings.bDefined) + { + OUString sFormulaString(aSettings.aFormulaCell.Format(ScRefFlags::ADDR_ABS, nullptr, pDoc->GetAddressConvention())); + OUString sVariableString(aSettings.aVariableCell.Format(ScRefFlags::ADDR_ABS, nullptr, pDoc->GetAddressConvention())); + m_xEdFormulaCell->SetText(sFormulaString); + m_xEdVariableCell->SetText(sVariableString); + m_xEdTargetVal->set_text(aSettings.sTargetValue); + } + else + { + m_xEdFormulaCell->SetText( aStr ); + } + m_xEdFormulaCell->GrabFocus(); m_pEdActive = m_xEdFormulaCell.get(); } @@ -201,6 +215,14 @@ IMPL_LINK(ScSolverDlg, BtnHdl, weld::Button&, rBtn, void) ScRefFlags nRes1 = theFormulaCell .Parse( m_xEdFormulaCell->GetText(), *pDoc, eConv ); ScRefFlags nRes2 = theVariableCell.Parse( m_xEdVariableCell->GetText(), *pDoc, eConv ); + // Remember Goal Seek settings for the next time the dialog opens + ScGoalSeekSettings aSettings; + aSettings.bDefined = true; + aSettings.aFormulaCell = theFormulaCell; + aSettings.aVariableCell = theVariableCell; + aSettings.sTargetValue = theTargetValStr; + pDoc->SetGoalSeekSettings(aSettings); + if ( (nRes1 & ScRefFlags::VALID) == ScRefFlags::VALID ) { if ( (nRes2 & ScRefFlags::VALID) == ScRefFlags::VALID )