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#pragma once
21
22#include <address.hxx>
23#include "anyrefdg.hxx"
24#include "docsh.hxx"
25#include <com/sun/star/uno/Sequence.hxx>
26
27#include <string_view>
28#include <vector>
29
30namespace com::sun::star {
31 namespace beans { struct PropertyValue; }
32}
33
35{
38
39public:
40 ScCursorRefEdit(std::unique_ptr<weld::Entry> xEntry);
42
43protected:
44 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
45};
46
49{
50 OUString aLeftStr;
51 sal_uInt16 nOperator;
52 OUString aRightStr;
53
55 bool IsDefault() const { return aLeftStr.isEmpty() && aRightStr.isEmpty() && nOperator == 0; }
56};
57
60{
61 OUString maObjective;
62 bool mbMax;
63 bool mbMin;
64 bool mbValue;
65 OUString maTarget;
66 OUString maVariable;
67 std::vector<ScOptConditionRow> maConditions;
68 OUString maEngine;
69 css::uno::Sequence<css::beans::PropertyValue> maProperties;
70
71public:
72 ScOptSolverSave( OUString aObjective, bool bMax, bool bMin, bool bValue,
73 OUString aTarget, OUString aVariable,
74 std::vector<ScOptConditionRow>&& rConditions,
75 OUString aEngine,
76 const css::uno::Sequence<css::beans::PropertyValue>& rProperties );
77
78 const OUString& GetObjective() const { return maObjective; }
79 bool GetMax() const { return mbMax; }
80 bool GetMin() const { return mbMin; }
81 bool GetValue() const { return mbValue; }
82 const OUString& GetTarget() const { return maTarget; }
83 const OUString& GetVariable() const { return maVariable; }
84 const std::vector<ScOptConditionRow>& GetConditions() const { return maConditions; }
85 const OUString& GetEngine() const { return maEngine; }
86 const css::uno::Sequence<css::beans::PropertyValue>& GetProperties() const
87 { return maProperties; }
88};
89
91
93{
94public:
96 ScDocShell* pDocSh, const ScAddress& aCursorPos );
97 virtual ~ScOptSolverDlg() override;
98
99 virtual void SetReference( const ScRange& rRef, ScDocument& rDoc ) override;
100 virtual bool IsRefInputMode() const override;
101 virtual void SetActive() override;
102 virtual void Close() override;
103
104private:
105 OUString maInputError;
107
112
113 std::vector<ScOptConditionRow> maConditions;
115
116 css::uno::Sequence<OUString> maImplNames;
117 css::uno::Sequence<OUString> maDescriptions;
118 OUString maEngine;
119 css::uno::Sequence<css::beans::PropertyValue> maProperties;
120
121 static const sal_uInt16 EDIT_ROW_COUNT = 4;
128
130
131 std::unique_ptr<weld::Label> m_xFtObjectiveCell;
132 std::unique_ptr<formula::RefEdit> m_xEdObjectiveCell;
133 std::unique_ptr<formula::RefButton> m_xRBObjectiveCell;
134
135 std::unique_ptr<weld::RadioButton> m_xRbMax;
136 std::unique_ptr<weld::RadioButton> m_xRbMin;
137 std::unique_ptr<weld::RadioButton> m_xRbValue;
138 std::unique_ptr<formula::RefEdit> m_xEdTargetValue;
139 std::unique_ptr<formula::RefButton> m_xRBTargetValue;
140
141 std::unique_ptr<weld::Label> m_xFtVariableCells;
142 std::unique_ptr<formula::RefEdit> m_xEdVariableCells;
143 std::unique_ptr<formula::RefButton> m_xRBVariableCells;
144
145 std::unique_ptr<weld::Label> m_xFtCellRef; // labels are together with controls for the first row
146 std::unique_ptr<ScCursorRefEdit> m_xEdLeft1;
147 std::unique_ptr<formula::RefButton> m_xRBLeft1;
148 std::unique_ptr<weld::ComboBox> m_xLbOp1;
149 std::unique_ptr<weld::Label> m_xFtConstraint;
150 std::unique_ptr<ScCursorRefEdit> m_xEdRight1;
151 std::unique_ptr<formula::RefButton> m_xRBRight1;
152 std::unique_ptr<weld::Button> m_xBtnDel1;
153
154 std::unique_ptr<ScCursorRefEdit> m_xEdLeft2;
155 std::unique_ptr<formula::RefButton> m_xRBLeft2;
156 std::unique_ptr<weld::ComboBox> m_xLbOp2;
157 std::unique_ptr<ScCursorRefEdit> m_xEdRight2;
158 std::unique_ptr<formula::RefButton> m_xRBRight2;
159 std::unique_ptr<weld::Button> m_xBtnDel2;
160
161 std::unique_ptr<ScCursorRefEdit> m_xEdLeft3;
162 std::unique_ptr<formula::RefButton> m_xRBLeft3;
163 std::unique_ptr<weld::ComboBox> m_xLbOp3;
164 std::unique_ptr<ScCursorRefEdit> m_xEdRight3;
165 std::unique_ptr<formula::RefButton> m_xRBRight3;
166 std::unique_ptr<weld::Button> m_xBtnDel3;
167
168 std::unique_ptr<ScCursorRefEdit> m_xEdLeft4;
169 std::unique_ptr<formula::RefButton> m_xRBLeft4;
170 std::unique_ptr<weld::ComboBox> m_xLbOp4;
171 std::unique_ptr<ScCursorRefEdit> m_xEdRight4;
172 std::unique_ptr<formula::RefButton> m_xRBRight4;
173 std::unique_ptr<weld::Button> m_xBtnDel4;
174
175 std::unique_ptr<weld::ScrolledWindow> m_xScrollBar;
176
177 std::unique_ptr<weld::Button> m_xBtnOpt;
178 std::unique_ptr<weld::Button> m_xBtnClose;
179 std::unique_ptr<weld::Button> m_xBtnSolve;
180 std::unique_ptr<weld::Button> m_xBtnResetAll;
181
182 std::unique_ptr<weld::Label> m_xResultFT;
183 std::unique_ptr<weld::Widget> m_xContents;
184
185 std::shared_ptr<ScSolverOptionsDialog> m_xOptDlg;
186
187 void Init(const ScAddress& rCursorPos);
188 bool CallSolver();
189 void ReadConditions();
190 void ShowConditions();
191 void EnableButtons();
192 bool ParseRef( ScRange& rRange, const OUString& rInput, bool bAllowRange );
193 bool FindTimeout( sal_Int32& rTimeout );
194 void ShowError( bool bCondition, formula::RefEdit* pFocus );
195
196 DECL_LINK( BtnHdl, weld::Button&, void );
197 DECL_LINK( DelBtnHdl, weld::Button&, void );
198 DECL_LINK( GetEditFocusHdl, formula::RefEdit&, void );
199 DECL_LINK( GetButtonFocusHdl, formula::RefButton&, void );
200 DECL_LINK( GetFocusHdl, weld::Widget&, void );
201 DECL_LINK( LoseEditFocusHdl, formula::RefEdit&, void );
202 DECL_LINK( LoseButtonFocusHdl, formula::RefButton&, void );
203 DECL_LINK( ScrollHdl, weld::ScrolledWindow&, void);
204 DECL_LINK( CursorUpHdl, ScCursorRefEdit&, void );
205 DECL_LINK( CursorDownHdl, ScCursorRefEdit&, void );
206 DECL_LINK( CondModifyHdl, formula::RefEdit&, void );
207 DECL_LINK( TargetModifyHdl, formula::RefEdit&, void );
208 DECL_LINK( SelectHdl, weld::ComboBox&, void );
209};
210
212{
213 std::unique_ptr<weld::Label> m_xFtTime;
214
215public:
217 virtual ~ScSolverProgressDialog() override;
218
219 void HideTimeLimit();
220 void SetTimeLimit( sal_Int32 nSeconds );
221};
222
224{
225 std::unique_ptr<weld::Label> m_xFtErrorText;
226
227public:
228 ScSolverNoSolutionDialog(weld::Window* pParent, const OUString& rErrorText);
229 virtual ~ScSolverNoSolutionDialog() override;
230};
231
233{
234 std::unique_ptr<weld::Label> m_xFtResult;
235 std::unique_ptr<weld::Button> m_xBtnOk;
236 std::unique_ptr<weld::Button> m_xBtnCancel;
237
238 DECL_LINK(ClickHdl, weld::Button&, void);
239
240public:
241 ScSolverSuccessDialog(weld::Window* pParent, std::u16string_view rSolution);
242 virtual ~ScSolverSuccessDialog() override;
243};
244
245/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetCursorLinks(const Link< ScCursorRefEdit &, void > &rUp, const Link< ScCursorRefEdit &, void > &rDown)
Definition: optsolver.cxx:113
Link< ScCursorRefEdit &, void > maCursorDownLink
Definition: optsolver.hxx:37
DECL_LINK(KeyInputHdl, const KeyEvent &, bool)
ScCursorRefEdit(std::unique_ptr< weld::Entry > xEntry)
Definition: optsolver.cxx:106
Link< ScCursorRefEdit &, void > maCursorUpLink
Definition: optsolver.hxx:36
std::vector< ScOptConditionRow > maConditions
Definition: optsolver.hxx:113
bool CallSolver()
Definition: optsolver.cxx:813
std::unique_ptr< weld::Widget > m_xContents
Definition: optsolver.hxx:183
std::unique_ptr< formula::RefButton > m_xRBRight3
Definition: optsolver.hxx:165
std::unique_ptr< formula::RefButton > m_xRBRight1
Definition: optsolver.hxx:151
void Init(const ScAddress &rCursorPos)
Definition: optsolver.cxx:267
std::unique_ptr< ScCursorRefEdit > m_xEdLeft4
Definition: optsolver.hxx:168
virtual ~ScOptSolverDlg() override
Definition: optsolver.cxx:263
css::uno::Sequence< OUString > maDescriptions
Definition: optsolver.hxx:117
std::unique_ptr< ScCursorRefEdit > m_xEdLeft2
Definition: optsolver.hxx:154
DECL_LINK(SelectHdl, weld::ComboBox &, void)
void ShowError(bool bCondition, formula::RefEdit *pFocus)
Definition: optsolver.cxx:764
std::unique_ptr< weld::RadioButton > m_xRbValue
Definition: optsolver.hxx:137
std::unique_ptr< weld::RadioButton > m_xRbMin
Definition: optsolver.hxx:136
DECL_LINK(LoseButtonFocusHdl, formula::RefButton &, void)
std::unique_ptr< formula::RefButton > m_xRBTargetValue
Definition: optsolver.hxx:139
weld::ComboBox * mpOperator[EDIT_ROW_COUNT]
Definition: optsolver.hxx:126
tools::Long nScrollPos
Definition: optsolver.hxx:114
std::unique_ptr< weld::Button > m_xBtnResetAll
Definition: optsolver.hxx:180
std::unique_ptr< ScCursorRefEdit > m_xEdLeft3
Definition: optsolver.hxx:161
std::unique_ptr< formula::RefButton > m_xRBRight2
Definition: optsolver.hxx:158
std::unique_ptr< weld::Button > m_xBtnClose
Definition: optsolver.hxx:178
bool ParseRef(ScRange &rRange, const OUString &rInput, bool bAllowRange)
Definition: optsolver.cxx:778
ScDocument & mrDoc
Definition: optsolver.hxx:109
formula::RefEdit * mpEdActive
Definition: optsolver.hxx:129
std::unique_ptr< weld::ComboBox > m_xLbOp2
Definition: optsolver.hxx:156
std::unique_ptr< weld::RadioButton > m_xRbMax
Definition: optsolver.hxx:135
static const sal_uInt16 EDIT_ROW_COUNT
Definition: optsolver.hxx:121
std::unique_ptr< weld::Button > m_xBtnDel2
Definition: optsolver.hxx:159
std::unique_ptr< formula::RefEdit > m_xEdVariableCells
Definition: optsolver.hxx:142
std::unique_ptr< formula::RefEdit > m_xEdObjectiveCell
Definition: optsolver.hxx:132
bool FindTimeout(sal_Int32 &rTimeout)
Definition: optsolver.cxx:796
std::unique_ptr< formula::RefButton > m_xRBLeft1
Definition: optsolver.hxx:147
std::unique_ptr< weld::Button > m_xBtnDel3
Definition: optsolver.hxx:166
virtual void SetActive() override
Definition: optsolver.cxx:435
std::unique_ptr< weld::ComboBox > m_xLbOp1
Definition: optsolver.hxx:148
ScDocShell * mpDocShell
Definition: optsolver.hxx:108
ScCursorRefEdit * mpRightEdit[EDIT_ROW_COUNT]
Definition: optsolver.hxx:124
std::unique_ptr< weld::Button > m_xBtnDel4
Definition: optsolver.hxx:173
std::shared_ptr< ScSolverOptionsDialog > m_xOptDlg
Definition: optsolver.hxx:185
ScOptSolverDlg(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, ScDocShell *pDocSh, const ScAddress &aCursorPos)
Definition: optsolver.cxx:152
virtual bool IsRefInputMode() const override
Definition: optsolver.cxx:501
OUString maConditionError
Definition: optsolver.hxx:106
DECL_LINK(GetFocusHdl, weld::Widget &, void)
DECL_LINK(LoseEditFocusHdl, formula::RefEdit &, void)
std::unique_ptr< formula::RefEdit > m_xEdTargetValue
Definition: optsolver.hxx:138
css::uno::Sequence< OUString > maImplNames
Definition: optsolver.hxx:116
DECL_LINK(GetEditFocusHdl, formula::RefEdit &, void)
virtual void Close() override
Definition: optsolver.cxx:427
std::unique_ptr< weld::Label > m_xFtVariableCells
Definition: optsolver.hxx:141
const SCTAB mnCurTab
Definition: optsolver.hxx:110
std::unique_ptr< weld::ComboBox > m_xLbOp4
Definition: optsolver.hxx:170
std::unique_ptr< weld::ScrolledWindow > m_xScrollBar
Definition: optsolver.hxx:175
std::unique_ptr< weld::ComboBox > m_xLbOp3
Definition: optsolver.hxx:163
formula::RefButton * mpLeftButton[EDIT_ROW_COUNT]
Definition: optsolver.hxx:123
void ReadConditions()
Definition: optsolver.cxx:370
DECL_LINK(DelBtnHdl, weld::Button &, void)
std::unique_ptr< formula::RefButton > m_xRBLeft4
Definition: optsolver.hxx:169
std::unique_ptr< formula::RefButton > m_xRBLeft2
Definition: optsolver.hxx:155
OUString maInputError
Definition: optsolver.hxx:105
ScCursorRefEdit * mpLeftEdit[EDIT_ROW_COUNT]
Definition: optsolver.hxx:122
std::unique_ptr< formula::RefButton > m_xRBRight4
Definition: optsolver.hxx:172
std::unique_ptr< weld::Label > m_xResultFT
Definition: optsolver.hxx:182
std::unique_ptr< ScCursorRefEdit > m_xEdRight3
Definition: optsolver.hxx:164
weld::Button * mpDelButton[EDIT_ROW_COUNT]
Definition: optsolver.hxx:127
virtual void SetReference(const ScRange &rRef, ScDocument &rDoc) override
Definition: optsolver.cxx:450
std::unique_ptr< weld::Button > m_xBtnOpt
Definition: optsolver.hxx:177
DECL_LINK(BtnHdl, weld::Button &, void)
DECL_LINK(GetButtonFocusHdl, formula::RefButton &, void)
std::unique_ptr< ScCursorRefEdit > m_xEdRight4
Definition: optsolver.hxx:171
std::unique_ptr< weld::Label > m_xFtObjectiveCell
Definition: optsolver.hxx:131
void EnableButtons()
Definition: optsolver.cxx:418
DECL_LINK(TargetModifyHdl, formula::RefEdit &, void)
std::unique_ptr< formula::RefButton > m_xRBObjectiveCell
Definition: optsolver.hxx:133
std::unique_ptr< ScCursorRefEdit > m_xEdRight2
Definition: optsolver.hxx:157
std::unique_ptr< formula::RefButton > m_xRBVariableCells
Definition: optsolver.hxx:143
std::unique_ptr< weld::Button > m_xBtnSolve
Definition: optsolver.hxx:179
std::unique_ptr< formula::RefButton > m_xRBLeft3
Definition: optsolver.hxx:162
std::unique_ptr< weld::Label > m_xFtConstraint
Definition: optsolver.hxx:149
std::unique_ptr< weld::Button > m_xBtnDel1
Definition: optsolver.hxx:152
std::unique_ptr< ScCursorRefEdit > m_xEdRight1
Definition: optsolver.hxx:150
void ShowConditions()
Definition: optsolver.cxx:394
DECL_LINK(CursorUpHdl, ScCursorRefEdit &, void)
DECL_LINK(CondModifyHdl, formula::RefEdit &, void)
DECL_LINK(CursorDownHdl, ScCursorRefEdit &, void)
formula::RefButton * mpRightButton[EDIT_ROW_COUNT]
Definition: optsolver.hxx:125
OUString maEngine
Definition: optsolver.hxx:118
css::uno::Sequence< css::beans::PropertyValue > maProperties
Definition: optsolver.hxx:119
DECL_LINK(ScrollHdl, weld::ScrolledWindow &, void)
std::unique_ptr< weld::Label > m_xFtCellRef
Definition: optsolver.hxx:145
std::unique_ptr< ScCursorRefEdit > m_xEdLeft1
Definition: optsolver.hxx:146
All settings from the dialog, saved with the DocShell for the next call.
Definition: optsolver.hxx:60
bool GetMin() const
Definition: optsolver.hxx:80
OUString maObjective
Definition: optsolver.hxx:61
const OUString & GetEngine() const
Definition: optsolver.hxx:85
std::vector< ScOptConditionRow > maConditions
Definition: optsolver.hxx:67
ScOptSolverSave(OUString aObjective, bool bMax, bool bMin, bool bValue, OUString aTarget, OUString aVariable, std::vector< ScOptConditionRow > &&rConditions, OUString aEngine, const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
Definition: optsolver.cxx:135
bool GetValue() const
Definition: optsolver.hxx:81
OUString maTarget
Definition: optsolver.hxx:65
const OUString & GetObjective() const
Definition: optsolver.hxx:78
OUString maVariable
Definition: optsolver.hxx:66
OUString maEngine
Definition: optsolver.hxx:68
const OUString & GetVariable() const
Definition: optsolver.hxx:83
css::uno::Sequence< css::beans::PropertyValue > maProperties
Definition: optsolver.hxx:69
const OUString & GetTarget() const
Definition: optsolver.hxx:82
bool GetMax() const
Definition: optsolver.hxx:79
const css::uno::Sequence< css::beans::PropertyValue > & GetProperties() const
Definition: optsolver.hxx:86
const std::vector< ScOptConditionRow > & GetConditions() const
Definition: optsolver.hxx:84
std::unique_ptr< weld::Label > m_xFtErrorText
Definition: optsolver.hxx:225
ScSolverNoSolutionDialog(weld::Window *pParent, const OUString &rErrorText)
Definition: optsolver.cxx:71
virtual ~ScSolverNoSolutionDialog() override
Definition: optsolver.cxx:78
virtual ~ScSolverProgressDialog() override
Definition: optsolver.cxx:55
std::unique_ptr< weld::Label > m_xFtTime
Definition: optsolver.hxx:213
ScSolverProgressDialog(weld::Window *pParent)
Definition: optsolver.cxx:48
void SetTimeLimit(sal_Int32 nSeconds)
Definition: optsolver.cxx:64
virtual ~ScSolverSuccessDialog() override
Definition: optsolver.cxx:94
ScSolverSuccessDialog(weld::Window *pParent, std::u16string_view rSolution)
Definition: optsolver.cxx:82
std::unique_ptr< weld::Label > m_xFtResult
Definition: optsolver.hxx:234
std::unique_ptr< weld::Button > m_xBtnCancel
Definition: optsolver.hxx:236
DECL_LINK(ClickHdl, weld::Button &, void)
std::unique_ptr< weld::Button > m_xBtnOk
Definition: optsolver.hxx:235
std::unique_ptr< weld::Entry > xEntry
long Long
The dialog's content for a row, not yet parsed.
Definition: optsolver.hxx:49
bool IsDefault() const
Definition: optsolver.hxx:55
OUString aLeftStr
Definition: optsolver.hxx:50
sal_uInt16 nOperator
Definition: optsolver.hxx:51
OUString aRightStr
Definition: optsolver.hxx:52
sal_Int16 SCTAB
Definition: types.hxx:22