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::Label> m_xFtOperator;
149 std::unique_ptr<weld::ComboBox> m_xLbOp1;
150 std::unique_ptr<weld::Label> m_xFtConstraint;
151 std::unique_ptr<ScCursorRefEdit> m_xEdRight1;
152 std::unique_ptr<formula::RefButton> m_xRBRight1;
153 std::unique_ptr<weld::Button> m_xBtnDel1;
154
155 std::unique_ptr<ScCursorRefEdit> m_xEdLeft2;
156 std::unique_ptr<formula::RefButton> m_xRBLeft2;
157 std::unique_ptr<weld::ComboBox> m_xLbOp2;
158 std::unique_ptr<ScCursorRefEdit> m_xEdRight2;
159 std::unique_ptr<formula::RefButton> m_xRBRight2;
160 std::unique_ptr<weld::Button> m_xBtnDel2;
161
162 std::unique_ptr<ScCursorRefEdit> m_xEdLeft3;
163 std::unique_ptr<formula::RefButton> m_xRBLeft3;
164 std::unique_ptr<weld::ComboBox> m_xLbOp3;
165 std::unique_ptr<ScCursorRefEdit> m_xEdRight3;
166 std::unique_ptr<formula::RefButton> m_xRBRight3;
167 std::unique_ptr<weld::Button> m_xBtnDel3;
168
169 std::unique_ptr<ScCursorRefEdit> m_xEdLeft4;
170 std::unique_ptr<formula::RefButton> m_xRBLeft4;
171 std::unique_ptr<weld::ComboBox> m_xLbOp4;
172 std::unique_ptr<ScCursorRefEdit> m_xEdRight4;
173 std::unique_ptr<formula::RefButton> m_xRBRight4;
174 std::unique_ptr<weld::Button> m_xBtnDel4;
175
176 std::unique_ptr<weld::ScrolledWindow> m_xScrollBar;
177
178 std::unique_ptr<weld::Button> m_xBtnOpt;
179 std::unique_ptr<weld::Button> m_xBtnClose;
180 std::unique_ptr<weld::Button> m_xBtnSolve;
181 std::unique_ptr<weld::Button> m_xBtnResetAll;
182
183 std::unique_ptr<weld::Label> m_xResultFT;
184 std::unique_ptr<weld::Widget> m_xContents;
185
186 std::shared_ptr<ScSolverOptionsDialog> m_xOptDlg;
187
188 void Init(const ScAddress& rCursorPos);
189 bool CallSolver();
190 void ReadConditions();
191 void ShowConditions();
192 void EnableButtons();
193 bool ParseRef( ScRange& rRange, const OUString& rInput, bool bAllowRange );
194 bool FindTimeout( sal_Int32& rTimeout );
195 void ShowError( bool bCondition, formula::RefEdit* pFocus );
196
197 DECL_LINK( BtnHdl, weld::Button&, void );
198 DECL_LINK( DelBtnHdl, weld::Button&, void );
199 DECL_LINK( GetEditFocusHdl, formula::RefEdit&, void );
200 DECL_LINK( GetButtonFocusHdl, formula::RefButton&, void );
201 DECL_LINK( GetFocusHdl, weld::Widget&, void );
202 DECL_LINK( LoseEditFocusHdl, formula::RefEdit&, void );
203 DECL_LINK( LoseButtonFocusHdl, formula::RefButton&, void );
204 DECL_LINK( ScrollHdl, weld::ScrolledWindow&, void);
205 DECL_LINK( CursorUpHdl, ScCursorRefEdit&, void );
206 DECL_LINK( CursorDownHdl, ScCursorRefEdit&, void );
207 DECL_LINK( CondModifyHdl, formula::RefEdit&, void );
208 DECL_LINK( TargetModifyHdl, formula::RefEdit&, void );
209 DECL_LINK( SelectHdl, weld::ComboBox&, void );
210};
211
213{
214 std::unique_ptr<weld::Label> m_xFtTime;
215
216public:
218 virtual ~ScSolverProgressDialog() override;
219
220 void HideTimeLimit();
221 void SetTimeLimit( sal_Int32 nSeconds );
222};
223
225{
226 std::unique_ptr<weld::Label> m_xFtErrorText;
227
228public:
229 ScSolverNoSolutionDialog(weld::Window* pParent, const OUString& rErrorText);
230 virtual ~ScSolverNoSolutionDialog() override;
231};
232
234{
235 std::unique_ptr<weld::Label> m_xFtResult;
236 std::unique_ptr<weld::Button> m_xBtnOk;
237 std::unique_ptr<weld::Button> m_xBtnCancel;
238
239 DECL_LINK(ClickHdl, weld::Button&, void);
240
241public:
242 ScSolverSuccessDialog(weld::Window* pParent, std::u16string_view rSolution);
243 virtual ~ScSolverSuccessDialog() override;
244};
245
246/* 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::unique_ptr< weld::Label > m_xFtOperator
Definition: optsolver.hxx:148
std::vector< ScOptConditionRow > maConditions
Definition: optsolver.hxx:113
bool CallSolver()
Definition: optsolver.cxx:814
std::unique_ptr< weld::Widget > m_xContents
Definition: optsolver.hxx:184
std::unique_ptr< formula::RefButton > m_xRBRight3
Definition: optsolver.hxx:166
std::unique_ptr< formula::RefButton > m_xRBRight1
Definition: optsolver.hxx:152
void Init(const ScAddress &rCursorPos)
Definition: optsolver.cxx:268
std::unique_ptr< ScCursorRefEdit > m_xEdLeft4
Definition: optsolver.hxx:169
virtual ~ScOptSolverDlg() override
Definition: optsolver.cxx:264
css::uno::Sequence< OUString > maDescriptions
Definition: optsolver.hxx:117
std::unique_ptr< ScCursorRefEdit > m_xEdLeft2
Definition: optsolver.hxx:155
DECL_LINK(SelectHdl, weld::ComboBox &, void)
void ShowError(bool bCondition, formula::RefEdit *pFocus)
Definition: optsolver.cxx:765
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:181
std::unique_ptr< ScCursorRefEdit > m_xEdLeft3
Definition: optsolver.hxx:162
std::unique_ptr< formula::RefButton > m_xRBRight2
Definition: optsolver.hxx:159
std::unique_ptr< weld::Button > m_xBtnClose
Definition: optsolver.hxx:179
bool ParseRef(ScRange &rRange, const OUString &rInput, bool bAllowRange)
Definition: optsolver.cxx:779
ScDocument & mrDoc
Definition: optsolver.hxx:109
formula::RefEdit * mpEdActive
Definition: optsolver.hxx:129
std::unique_ptr< weld::ComboBox > m_xLbOp2
Definition: optsolver.hxx:157
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:160
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:797
std::unique_ptr< formula::RefButton > m_xRBLeft1
Definition: optsolver.hxx:147
std::unique_ptr< weld::Button > m_xBtnDel3
Definition: optsolver.hxx:167
virtual void SetActive() override
Definition: optsolver.cxx:436
std::unique_ptr< weld::ComboBox > m_xLbOp1
Definition: optsolver.hxx:149
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:174
std::shared_ptr< ScSolverOptionsDialog > m_xOptDlg
Definition: optsolver.hxx:186
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:502
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:428
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:171
std::unique_ptr< weld::ScrolledWindow > m_xScrollBar
Definition: optsolver.hxx:176
std::unique_ptr< weld::ComboBox > m_xLbOp3
Definition: optsolver.hxx:164
formula::RefButton * mpLeftButton[EDIT_ROW_COUNT]
Definition: optsolver.hxx:123
void ReadConditions()
Definition: optsolver.cxx:371
DECL_LINK(DelBtnHdl, weld::Button &, void)
std::unique_ptr< formula::RefButton > m_xRBLeft4
Definition: optsolver.hxx:170
std::unique_ptr< formula::RefButton > m_xRBLeft2
Definition: optsolver.hxx:156
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:173
std::unique_ptr< weld::Label > m_xResultFT
Definition: optsolver.hxx:183
std::unique_ptr< ScCursorRefEdit > m_xEdRight3
Definition: optsolver.hxx:165
weld::Button * mpDelButton[EDIT_ROW_COUNT]
Definition: optsolver.hxx:127
virtual void SetReference(const ScRange &rRef, ScDocument &rDoc) override
Definition: optsolver.cxx:451
std::unique_ptr< weld::Button > m_xBtnOpt
Definition: optsolver.hxx:178
DECL_LINK(BtnHdl, weld::Button &, void)
DECL_LINK(GetButtonFocusHdl, formula::RefButton &, void)
std::unique_ptr< ScCursorRefEdit > m_xEdRight4
Definition: optsolver.hxx:172
std::unique_ptr< weld::Label > m_xFtObjectiveCell
Definition: optsolver.hxx:131
void EnableButtons()
Definition: optsolver.cxx:419
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:158
std::unique_ptr< formula::RefButton > m_xRBVariableCells
Definition: optsolver.hxx:143
std::unique_ptr< weld::Button > m_xBtnSolve
Definition: optsolver.hxx:180
std::unique_ptr< formula::RefButton > m_xRBLeft3
Definition: optsolver.hxx:163
std::unique_ptr< weld::Label > m_xFtConstraint
Definition: optsolver.hxx:150
std::unique_ptr< weld::Button > m_xBtnDel1
Definition: optsolver.hxx:153
std::unique_ptr< ScCursorRefEdit > m_xEdRight1
Definition: optsolver.hxx:151
void ShowConditions()
Definition: optsolver.cxx:395
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:226
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:214
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:235
std::unique_ptr< weld::Button > m_xBtnCancel
Definition: optsolver.hxx:237
DECL_LINK(ClickHdl, weld::Button &, void)
std::unique_ptr< weld::Button > m_xBtnOk
Definition: optsolver.hxx:236
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