tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / inc / optsolver.hxx
blob35570f7d09d4326c88225bf84d65505d50341603
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <address.hxx>
23 #include "anyrefdg.hxx"
24 #include "docsh.hxx"
25 #include <SolverSettings.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <com/sun/star/table/CellAddress.hpp>
29 #include <string_view>
30 #include <vector>
32 namespace com::sun::star {
33 namespace beans { struct PropertyValue; }
36 class ScCursorRefEdit : public formula::RefEdit
38 Link<ScCursorRefEdit&,void> maCursorUpLink;
39 Link<ScCursorRefEdit&,void> maCursorDownLink;
41 public:
42 ScCursorRefEdit(std::unique_ptr<weld::Entry> xEntry);
43 void SetCursorLinks( const Link<ScCursorRefEdit&,void>& rUp, const Link<ScCursorRefEdit&,void>& rDown );
45 protected:
46 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
49 class ScSolverOptionsDialog;
51 class ScOptSolverDlg : public ScAnyRefDlgController
53 public:
54 ScOptSolverDlg( SfxBindings* pB, SfxChildWindow* pCW, weld::Window* pParent,
55 ScDocShell* pDocSh, const ScAddress& aCursorPos );
56 virtual ~ScOptSolverDlg() override;
58 virtual void SetReference( const ScRange& rRef, ScDocument& rDoc ) override;
59 virtual bool IsRefInputMode() const override;
60 virtual void SetActive() override;
61 virtual void Close() override;
63 private:
64 OUString maInputError;
65 OUString maConditionError;
67 ScDocShell* mpDocShell;
68 ScDocument& mrDoc;
69 const SCTAB mnCurTab;
70 bool mbDlgLostFocus;
72 std::vector<sc::ModelConstraint> m_aConditions;
73 tools::Long nScrollPos;
75 css::uno::Sequence<OUString> maImplNames;
76 css::uno::Sequence<OUString> maDescriptions;
77 OUString maEngine;
78 css::uno::Sequence<css::beans::PropertyValue> maProperties;
80 static const sal_uInt16 EDIT_ROW_COUNT = 4;
81 ScCursorRefEdit* mpLeftEdit[EDIT_ROW_COUNT];
82 formula::RefButton* mpLeftButton[EDIT_ROW_COUNT];
83 ScCursorRefEdit* mpRightEdit[EDIT_ROW_COUNT];
84 formula::RefButton* mpRightButton[EDIT_ROW_COUNT];
85 weld::ComboBox* mpOperator[EDIT_ROW_COUNT];
86 weld::Button* mpDelButton[EDIT_ROW_COUNT];
88 formula::RefEdit* mpEdActive;
90 std::unique_ptr<weld::Label> m_xFtObjectiveCell;
91 std::unique_ptr<formula::RefEdit> m_xEdObjectiveCell;
92 std::unique_ptr<formula::RefButton> m_xRBObjectiveCell;
94 std::unique_ptr<weld::RadioButton> m_xRbMax;
95 std::unique_ptr<weld::RadioButton> m_xRbMin;
96 std::unique_ptr<weld::RadioButton> m_xRbValue;
97 std::unique_ptr<formula::RefEdit> m_xEdTargetValue;
98 std::unique_ptr<formula::RefButton> m_xRBTargetValue;
100 std::unique_ptr<weld::Label> m_xFtVariableCells;
101 std::unique_ptr<formula::RefEdit> m_xEdVariableCells;
102 std::unique_ptr<formula::RefButton> m_xRBVariableCells;
104 std::unique_ptr<weld::Label> m_xFtCellRef; // labels are together with controls for the first row
105 std::unique_ptr<ScCursorRefEdit> m_xEdLeft1;
106 std::unique_ptr<formula::RefButton> m_xRBLeft1;
107 std::unique_ptr<weld::ComboBox> m_xLbOp1;
108 std::unique_ptr<weld::Label> m_xFtConstraint;
109 std::unique_ptr<ScCursorRefEdit> m_xEdRight1;
110 std::unique_ptr<formula::RefButton> m_xRBRight1;
111 std::unique_ptr<weld::Button> m_xBtnDel1;
113 std::unique_ptr<ScCursorRefEdit> m_xEdLeft2;
114 std::unique_ptr<formula::RefButton> m_xRBLeft2;
115 std::unique_ptr<weld::ComboBox> m_xLbOp2;
116 std::unique_ptr<ScCursorRefEdit> m_xEdRight2;
117 std::unique_ptr<formula::RefButton> m_xRBRight2;
118 std::unique_ptr<weld::Button> m_xBtnDel2;
120 std::unique_ptr<ScCursorRefEdit> m_xEdLeft3;
121 std::unique_ptr<formula::RefButton> m_xRBLeft3;
122 std::unique_ptr<weld::ComboBox> m_xLbOp3;
123 std::unique_ptr<ScCursorRefEdit> m_xEdRight3;
124 std::unique_ptr<formula::RefButton> m_xRBRight3;
125 std::unique_ptr<weld::Button> m_xBtnDel3;
127 std::unique_ptr<ScCursorRefEdit> m_xEdLeft4;
128 std::unique_ptr<formula::RefButton> m_xRBLeft4;
129 std::unique_ptr<weld::ComboBox> m_xLbOp4;
130 std::unique_ptr<ScCursorRefEdit> m_xEdRight4;
131 std::unique_ptr<formula::RefButton> m_xRBRight4;
132 std::unique_ptr<weld::Button> m_xBtnDel4;
134 std::unique_ptr<weld::ScrolledWindow> m_xScrollBar;
136 std::unique_ptr<weld::Button> m_xBtnOpt;
137 std::unique_ptr<weld::Button> m_xBtnClose;
138 std::unique_ptr<weld::Button> m_xBtnSolve;
139 std::unique_ptr<weld::Button> m_xBtnResetAll;
141 std::unique_ptr<weld::Label> m_xResultFT;
142 std::unique_ptr<weld::Widget> m_xContents;
144 std::shared_ptr<ScSolverOptionsDialog> m_xOptDlg;
145 std::shared_ptr<sc::SolverSettings> m_pSolverSettings;
147 void Init(const ScAddress& rCursorPos);
148 bool CallSolver();
149 void ReadConditions();
150 void ShowConditions();
151 void EnableButtons();
152 bool ParseRef( ScRange& rRange, const OUString& rInput, bool bAllowRange );
153 bool FindTimeout( sal_Int32& rTimeout );
154 void ShowError( bool bCondition, formula::RefEdit* pFocus );
155 void LoadSolverSettings();
156 void SaveSolverSettings();
157 bool IsEngineAvailable(std::u16string_view sEngineName);
159 static sc::ConstraintOperator OperatorIndexToConstraintOperator(sal_Int32 nIndex);
161 // Return the string representation of a css::table::CellAddress
162 OUString GetCellStrAddress(css::table::CellAddress aUnoAddress);
164 DECL_LINK( BtnHdl, weld::Button&, void );
165 DECL_LINK( DelBtnHdl, weld::Button&, void );
166 DECL_LINK( GetEditFocusHdl, formula::RefEdit&, void );
167 DECL_LINK( GetButtonFocusHdl, formula::RefButton&, void );
168 DECL_LINK( GetFocusHdl, weld::Widget&, void );
169 DECL_LINK( LoseEditFocusHdl, formula::RefEdit&, void );
170 DECL_LINK( LoseButtonFocusHdl, formula::RefButton&, void );
171 DECL_LINK( ScrollHdl, weld::ScrolledWindow&, void);
172 DECL_LINK( CursorUpHdl, ScCursorRefEdit&, void );
173 DECL_LINK( CursorDownHdl, ScCursorRefEdit&, void );
174 DECL_LINK( CondModifyHdl, formula::RefEdit&, void );
175 DECL_LINK( TargetModifyHdl, formula::RefEdit&, void );
176 DECL_LINK( SelectHdl, weld::ComboBox&, void );
179 class ScSolverProgressDialog : public weld::GenericDialogController
181 std::unique_ptr<weld::Label> m_xFtTime;
183 public:
184 ScSolverProgressDialog(weld::Window* pParent);
185 virtual ~ScSolverProgressDialog() override;
187 void HideTimeLimit();
188 void SetTimeLimit( sal_Int32 nSeconds );
191 class ScSolverNoSolutionDialog : public weld::GenericDialogController
193 std::unique_ptr<weld::Label> m_xFtErrorText;
195 public:
196 ScSolverNoSolutionDialog(weld::Window* pParent, const OUString& rErrorText);
197 virtual ~ScSolverNoSolutionDialog() override;
200 class ScSolverSuccessDialog : public weld::GenericDialogController
202 std::unique_ptr<weld::Label> m_xFtResult;
203 std::unique_ptr<weld::Button> m_xBtnOk;
204 std::unique_ptr<weld::Button> m_xBtnCancel;
206 DECL_LINK(ClickHdl, weld::Button&, void);
208 public:
209 ScSolverSuccessDialog(weld::Window* pParent, std::u16string_view rSolution);
210 virtual ~ScSolverSuccessDialog() override;
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */