LibreOffice Module sc (master)  1
optsolver.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_SC_SOURCE_UI_INC_OPTSOLVER_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_OPTSOLVER_HXX
22 
23 #include <address.hxx>
24 #include "anyrefdg.hxx"
25 #include "docsh.hxx"
26 #include <com/sun/star/uno/Sequence.hxx>
27 
28 #include <string_view>
29 #include <vector>
30 
31 namespace com::sun::star {
32  namespace beans { struct PropertyValue; }
33 }
34 
36 {
39 
40 public:
41  ScCursorRefEdit(std::unique_ptr<weld::Entry> xEntry);
43 
44 protected:
45  DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
46 };
47 
50 {
51  OUString aLeftStr;
52  sal_uInt16 nOperator;
53  OUString aRightStr;
54 
55  ScOptConditionRow() : nOperator(0) {}
56  bool IsDefault() const { return aLeftStr.isEmpty() && aRightStr.isEmpty() && nOperator == 0; }
57 };
58 
61 {
62  OUString maObjective;
63  bool mbMax;
64  bool mbMin;
65  bool mbValue;
66  OUString maTarget;
67  OUString maVariable;
68  std::vector<ScOptConditionRow> maConditions;
69  OUString maEngine;
70  css::uno::Sequence<css::beans::PropertyValue> maProperties;
71 
72 public:
73  ScOptSolverSave( const OUString& rObjective, bool bMax, bool bMin, bool bValue,
74  const OUString& rTarget, const OUString& rVariable,
75  const std::vector<ScOptConditionRow>& rConditions,
76  const OUString& rEngine,
77  const css::uno::Sequence<css::beans::PropertyValue>& rProperties );
78 
79  const OUString& GetObjective() const { return maObjective; }
80  bool GetMax() const { return mbMax; }
81  bool GetMin() const { return mbMin; }
82  bool GetValue() const { return mbValue; }
83  const OUString& GetTarget() const { return maTarget; }
84  const OUString& GetVariable() const { return maVariable; }
85  const std::vector<ScOptConditionRow>& GetConditions() const { return maConditions; }
86  const OUString& GetEngine() const { return maEngine; }
87  const css::uno::Sequence<css::beans::PropertyValue>& GetProperties() const
88  { return maProperties; }
89 };
90 
92 
94 {
95 public:
97  ScDocShell* pDocSh, const ScAddress& aCursorPos );
98  virtual ~ScOptSolverDlg() override;
99 
100  virtual void SetReference( const ScRange& rRef, ScDocument& rDoc ) override;
101  virtual bool IsRefInputMode() const override;
102  virtual void SetActive() override;
103  virtual void Close() override;
104 
105 private:
106  OUString maInputError;
108 
113 
114  std::vector<ScOptConditionRow> maConditions;
116 
117  css::uno::Sequence<OUString> maImplNames;
118  css::uno::Sequence<OUString> maDescriptions;
119  OUString maEngine;
120  css::uno::Sequence<css::beans::PropertyValue> maProperties;
121 
122  static const sal_uInt16 EDIT_ROW_COUNT = 4;
129 
131 
132  std::unique_ptr<weld::Label> m_xFtObjectiveCell;
133  std::unique_ptr<formula::RefEdit> m_xEdObjectiveCell;
134  std::unique_ptr<formula::RefButton> m_xRBObjectiveCell;
135 
136  std::unique_ptr<weld::RadioButton> m_xRbMax;
137  std::unique_ptr<weld::RadioButton> m_xRbMin;
138  std::unique_ptr<weld::RadioButton> m_xRbValue;
139  std::unique_ptr<formula::RefEdit> m_xEdTargetValue;
140  std::unique_ptr<formula::RefButton> m_xRBTargetValue;
141 
142  std::unique_ptr<weld::Label> m_xFtVariableCells;
143  std::unique_ptr<formula::RefEdit> m_xEdVariableCells;
144  std::unique_ptr<formula::RefButton> m_xRBVariableCells;
145 
146  std::unique_ptr<weld::Label> m_xFtCellRef; // labels are together with controls for the first row
147  std::unique_ptr<ScCursorRefEdit> m_xEdLeft1;
148  std::unique_ptr<formula::RefButton> m_xRBLeft1;
149  std::unique_ptr<weld::Label> m_xFtOperator;
150  std::unique_ptr<weld::ComboBox> m_xLbOp1;
151  std::unique_ptr<weld::Label> m_xFtConstraint;
152  std::unique_ptr<ScCursorRefEdit> m_xEdRight1;
153  std::unique_ptr<formula::RefButton> m_xRBRight1;
154  std::unique_ptr<weld::Button> m_xBtnDel1;
155 
156  std::unique_ptr<ScCursorRefEdit> m_xEdLeft2;
157  std::unique_ptr<formula::RefButton> m_xRBLeft2;
158  std::unique_ptr<weld::ComboBox> m_xLbOp2;
159  std::unique_ptr<ScCursorRefEdit> m_xEdRight2;
160  std::unique_ptr<formula::RefButton> m_xRBRight2;
161  std::unique_ptr<weld::Button> m_xBtnDel2;
162 
163  std::unique_ptr<ScCursorRefEdit> m_xEdLeft3;
164  std::unique_ptr<formula::RefButton> m_xRBLeft3;
165  std::unique_ptr<weld::ComboBox> m_xLbOp3;
166  std::unique_ptr<ScCursorRefEdit> m_xEdRight3;
167  std::unique_ptr<formula::RefButton> m_xRBRight3;
168  std::unique_ptr<weld::Button> m_xBtnDel3;
169 
170  std::unique_ptr<ScCursorRefEdit> m_xEdLeft4;
171  std::unique_ptr<formula::RefButton> m_xRBLeft4;
172  std::unique_ptr<weld::ComboBox> m_xLbOp4;
173  std::unique_ptr<ScCursorRefEdit> m_xEdRight4;
174  std::unique_ptr<formula::RefButton> m_xRBRight4;
175  std::unique_ptr<weld::Button> m_xBtnDel4;
176 
177  std::unique_ptr<weld::ScrolledWindow> m_xScrollBar;
178 
179  std::unique_ptr<weld::Button> m_xBtnOpt;
180  std::unique_ptr<weld::Button> m_xBtnClose;
181  std::unique_ptr<weld::Button> m_xBtnSolve;
182  std::unique_ptr<weld::Button> m_xBtnResetAll;
183 
184  std::unique_ptr<weld::Label> m_xResultFT;
185  std::unique_ptr<weld::Widget> m_xContents;
186 
187  std::shared_ptr<ScSolverOptionsDialog> m_xOptDlg;
188 
189  void Init(const ScAddress& rCursorPos);
190  bool CallSolver();
191  void ReadConditions();
192  void ShowConditions();
193  void EnableButtons();
194  bool ParseRef( ScRange& rRange, const OUString& rInput, bool bAllowRange );
195  bool FindTimeout( sal_Int32& rTimeout );
196  void ShowError( bool bCondition, formula::RefEdit* pFocus );
197 
198  DECL_LINK( BtnHdl, weld::Button&, void );
199  DECL_LINK( DelBtnHdl, weld::Button&, void );
200  DECL_LINK( GetEditFocusHdl, formula::RefEdit&, void );
201  DECL_LINK( GetButtonFocusHdl, formula::RefButton&, void );
202  DECL_LINK( GetFocusHdl, weld::Widget&, void );
203  DECL_LINK( LoseEditFocusHdl, formula::RefEdit&, void );
204  DECL_LINK( LoseButtonFocusHdl, formula::RefButton&, void );
205  DECL_LINK( ScrollHdl, weld::ScrolledWindow&, void);
206  DECL_LINK( CursorUpHdl, ScCursorRefEdit&, void );
207  DECL_LINK( CursorDownHdl, ScCursorRefEdit&, void );
208  DECL_LINK( CondModifyHdl, formula::RefEdit&, void );
209  DECL_LINK( TargetModifyHdl, formula::RefEdit&, void );
210  DECL_LINK( SelectHdl, weld::ComboBox&, void );
211 };
212 
214 {
215  std::unique_ptr<weld::Label> m_xFtTime;
216 
217 public:
219  virtual ~ScSolverProgressDialog() override;
220 
221  void HideTimeLimit();
222  void SetTimeLimit( sal_Int32 nSeconds );
223 };
224 
226 {
227  std::unique_ptr<weld::Label> m_xFtErrorText;
228 
229 public:
230  ScSolverNoSolutionDialog(weld::Window* pParent, const OUString& rErrorText);
231  virtual ~ScSolverNoSolutionDialog() override;
232 };
233 
235 {
236  std::unique_ptr<weld::Label> m_xFtResult;
237  std::unique_ptr<weld::Button> m_xBtnOk;
238  std::unique_ptr<weld::Button> m_xBtnCancel;
239 
240  DECL_LINK(ClickHdl, weld::Button&, void);
241 
242 public:
243  ScSolverSuccessDialog(weld::Window* pParent, std::u16string_view rSolution);
244  virtual ~ScSolverSuccessDialog() override;
245 };
246 
247 #endif
248 
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< formula::RefButton > m_xRBRight1
Definition: optsolver.hxx:153
std::unique_ptr< formula::RefEdit > m_xEdVariableCells
Definition: optsolver.hxx:143
OUString aLeftStr
Definition: optsolver.hxx:51
void SetTimeLimit(sal_Int32 nSeconds)
Definition: optsolver.cxx:63
ScDocShell * mpDocShell
Definition: optsolver.hxx:109
std::unique_ptr< weld::Label > m_xResultFT
Definition: optsolver.hxx:184
OUString maTarget
Definition: optsolver.hxx:66
std::unique_ptr< weld::Label > m_xFtErrorText
Definition: optsolver.hxx:227
virtual void SetActive() override
Definition: optsolver.cxx:435
std::unique_ptr< formula::RefButton > m_xRBRight4
Definition: optsolver.hxx:174
virtual void SetReference(const ScRange &rRef, ScDocument &rDoc) override
Definition: optsolver.cxx:450
static const sal_uInt16 EDIT_ROW_COUNT
Definition: optsolver.hxx:122
formula::RefButton * mpRightButton[EDIT_ROW_COUNT]
Definition: optsolver.hxx:126
ScCursorRefEdit(std::unique_ptr< weld::Entry > xEntry)
Definition: optsolver.cxx:105
std::unique_ptr< weld::ScrolledWindow > m_xScrollBar
Definition: optsolver.hxx:177
css::uno::Sequence< css::beans::PropertyValue > maProperties
Definition: optsolver.hxx:70
std::unique_ptr< ScCursorRefEdit > m_xEdLeft3
Definition: optsolver.hxx:163
std::unique_ptr< formula::RefButton > m_xRBLeft2
Definition: optsolver.hxx:157
std::unique_ptr< formula::RefButton > m_xRBLeft1
Definition: optsolver.hxx:148
long Long
const OUString & GetObjective() const
Definition: optsolver.hxx:79
virtual ~ScSolverSuccessDialog() override
Definition: optsolver.cxx:93
virtual ~ScOptSolverDlg() override
Definition: optsolver.cxx:263
const std::vector< ScOptConditionRow > & GetConditions() const
Definition: optsolver.hxx:85
css::uno::Sequence< OUString > maImplNames
Definition: optsolver.hxx:117
std::unique_ptr< weld::ComboBox > m_xLbOp2
Definition: optsolver.hxx:158
bool GetMin() const
Definition: optsolver.hxx:81
std::unique_ptr< weld::Label > m_xFtObjectiveCell
Definition: optsolver.hxx:132
Link< ScCursorRefEdit &, void > maCursorUpLink
Definition: optsolver.hxx:37
Link< ScCursorRefEdit &, void > maCursorDownLink
Definition: optsolver.hxx:38
bool IsDefault() const
Definition: optsolver.hxx:56
std::unique_ptr< formula::RefButton > m_xRBVariableCells
Definition: optsolver.hxx:144
ScOptSolverSave(const OUString &rObjective, bool bMax, bool bMin, bool bValue, const OUString &rTarget, const OUString &rVariable, const std::vector< ScOptConditionRow > &rConditions, const OUString &rEngine, const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
Definition: optsolver.cxx:134
OUString aRightStr
Definition: optsolver.hxx:53
const SCTAB mnCurTab
Definition: optsolver.hxx:111
std::unique_ptr< weld::RadioButton > m_xRbMin
Definition: optsolver.hxx:137
std::unique_ptr< ScCursorRefEdit > m_xEdLeft2
Definition: optsolver.hxx:156
std::unique_ptr< weld::Label > m_xFtOperator
Definition: optsolver.hxx:149
std::unique_ptr< weld::Button > m_xBtnOpt
Definition: optsolver.hxx:179
std::unique_ptr< formula::RefEdit > m_xEdObjectiveCell
Definition: optsolver.hxx:133
virtual bool IsRefInputMode() const override
Definition: optsolver.cxx:501
ScDocument & mrDoc
Definition: optsolver.hxx:110
std::unique_ptr< formula::RefButton > m_xRBLeft4
Definition: optsolver.hxx:171
std::unique_ptr< ScCursorRefEdit > m_xEdRight4
Definition: optsolver.hxx:173
OUString maEngine
Definition: optsolver.hxx:69
ScCursorRefEdit * mpRightEdit[EDIT_ROW_COUNT]
Definition: optsolver.hxx:125
css::uno::Sequence< OUString > maDescriptions
Definition: optsolver.hxx:118
sal_uInt16 nOperator
Definition: optsolver.hxx:52
std::vector< ScOptConditionRow > maConditions
Definition: optsolver.hxx:68
std::unique_ptr< weld::Button > m_xBtnSolve
Definition: optsolver.hxx:181
void ShowError(bool bCondition, formula::RefEdit *pFocus)
Definition: optsolver.cxx:763
std::unique_ptr< ScCursorRefEdit > m_xEdLeft1
Definition: optsolver.hxx:147
void Init(const ScAddress &rCursorPos)
Definition: optsolver.cxx:267
std::unique_ptr< weld::ComboBox > m_xLbOp4
Definition: optsolver.hxx:172
void ShowConditions()
Definition: optsolver.cxx:394
css::uno::Sequence< css::beans::PropertyValue > maProperties
Definition: optsolver.hxx:120
std::vector< ScOptConditionRow > maConditions
Definition: optsolver.hxx:114
bool GetMax() const
Definition: optsolver.hxx:80
std::unique_ptr< weld::RadioButton > m_xRbMax
Definition: optsolver.hxx:136
std::unique_ptr< formula::RefEdit > m_xEdTargetValue
Definition: optsolver.hxx:139
void ReadConditions()
Definition: optsolver.cxx:370
std::unique_ptr< weld::Widget > m_xContents
Definition: optsolver.hxx:185
DECL_LINK(ClickHdl, weld::Button &, void)
std::unique_ptr< weld::Button > m_xBtnDel1
Definition: optsolver.hxx:154
The dialog's content for a row, not yet parsed.
Definition: optsolver.hxx:49
std::unique_ptr< ScCursorRefEdit > m_xEdRight3
Definition: optsolver.hxx:166
std::unique_ptr< weld::Button > m_xBtnClose
Definition: optsolver.hxx:180
void SetCursorLinks(const Link< ScCursorRefEdit &, void > &rUp, const Link< ScCursorRefEdit &, void > &rDown)
Definition: optsolver.cxx:112
ScCursorRefEdit * mpLeftEdit[EDIT_ROW_COUNT]
Definition: optsolver.hxx:123
const OUString & GetTarget() const
Definition: optsolver.hxx:83
ScSolverNoSolutionDialog(weld::Window *pParent, const OUString &rErrorText)
Definition: optsolver.cxx:70
const OUString & GetEngine() const
Definition: optsolver.hxx:86
std::unique_ptr< weld::Label > m_xFtTime
Definition: optsolver.hxx:215
OUString maEngine
Definition: optsolver.hxx:119
ScSolverSuccessDialog(weld::Window *pParent, std::u16string_view rSolution)
Definition: optsolver.cxx:81
std::unique_ptr< weld::Button > m_xBtnResetAll
Definition: optsolver.hxx:182
std::unique_ptr< formula::RefButton > m_xRBTargetValue
Definition: optsolver.hxx:140
bool GetValue() const
Definition: optsolver.hxx:82
std::unique_ptr< weld::ComboBox > m_xLbOp3
Definition: optsolver.hxx:165
void EnableButtons()
Definition: optsolver.cxx:418
std::unique_ptr< weld::RadioButton > m_xRbValue
Definition: optsolver.hxx:138
OUString maVariable
Definition: optsolver.hxx:67
std::unique_ptr< weld::Label > m_xFtCellRef
Definition: optsolver.hxx:146
std::unique_ptr< formula::RefButton > m_xRBRight3
Definition: optsolver.hxx:167
exports com.sun.star. beans
ScOptSolverDlg(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, ScDocShell *pDocSh, const ScAddress &aCursorPos)
Definition: optsolver.cxx:151
std::unique_ptr< weld::Entry > xEntry
std::unique_ptr< weld::ComboBox > m_xLbOp1
Definition: optsolver.hxx:150
std::unique_ptr< weld::Button > m_xBtnDel2
Definition: optsolver.hxx:161
tools::Long nScrollPos
Definition: optsolver.hxx:115
bool FindTimeout(sal_Int32 &rTimeout)
Definition: optsolver.cxx:795
std::unique_ptr< weld::Label > m_xFtConstraint
Definition: optsolver.hxx:151
const OUString & GetVariable() const
Definition: optsolver.hxx:84
std::unique_ptr< formula::RefButton > m_xRBRight2
Definition: optsolver.hxx:160
All settings from the dialog, saved with the DocShell for the next call.
Definition: optsolver.hxx:60
weld::ComboBox * mpOperator[EDIT_ROW_COUNT]
Definition: optsolver.hxx:127
virtual ~ScSolverProgressDialog() override
Definition: optsolver.cxx:54
bool CallSolver()
Definition: optsolver.cxx:812
ScSolverProgressDialog(weld::Window *pParent)
Definition: optsolver.cxx:47
std::unique_ptr< weld::Label > m_xFtVariableCells
Definition: optsolver.hxx:142
weld::Button * mpDelButton[EDIT_ROW_COUNT]
Definition: optsolver.hxx:128
DECL_LINK(KeyInputHdl, const KeyEvent &, bool)
OUString maConditionError
Definition: optsolver.hxx:107
virtual void Close() override
Definition: optsolver.cxx:427
formula::RefEdit * mpEdActive
Definition: optsolver.hxx:130
DECL_LINK(BtnHdl, weld::Button &, void)
std::shared_ptr< ScSolverOptionsDialog > m_xOptDlg
Definition: optsolver.hxx:187
std::unique_ptr< ScCursorRefEdit > m_xEdRight1
Definition: optsolver.hxx:152
std::unique_ptr< weld::Button > m_xBtnDel4
Definition: optsolver.hxx:175
OUString maObjective
Definition: optsolver.hxx:62
OUString maInputError
Definition: optsolver.hxx:106
std::unique_ptr< formula::RefButton > m_xRBLeft3
Definition: optsolver.hxx:164
std::unique_ptr< ScCursorRefEdit > m_xEdLeft4
Definition: optsolver.hxx:170
bool ParseRef(ScRange &rRange, const OUString &rInput, bool bAllowRange)
Definition: optsolver.cxx:777
const css::uno::Sequence< css::beans::PropertyValue > & GetProperties() const
Definition: optsolver.hxx:87
std::unique_ptr< ScCursorRefEdit > m_xEdRight2
Definition: optsolver.hxx:159
virtual ~ScSolverNoSolutionDialog() override
Definition: optsolver.cxx:77
std::unique_ptr< weld::Button > m_xBtnCancel
Definition: optsolver.hxx:238
std::unique_ptr< formula::RefButton > m_xRBObjectiveCell
Definition: optsolver.hxx:134
std::unique_ptr< weld::Button > m_xBtnOk
Definition: optsolver.hxx:237
sal_Int16 SCTAB
Definition: types.hxx:23
std::unique_ptr< weld::Label > m_xFtResult
Definition: optsolver.hxx:236
formula::RefButton * mpLeftButton[EDIT_ROW_COUNT]
Definition: optsolver.hxx:124
std::unique_ptr< weld::Button > m_xBtnDel3
Definition: optsolver.hxx:168