tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sccomp / source / solver / SolverComponent.cxx
bloba06b65f4c46a24a987c64517da23b72893045c03
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 #include "SolverComponent.hxx"
21 #include <strings.hrc>
23 #include <com/sun/star/container/XIndexAccess.hpp>
24 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
25 #include <com/sun/star/sheet/XSpreadsheet.hpp>
26 #include <com/sun/star/table/CellAddress.hpp>
28 #include <cppuhelper/supportsservice.hxx>
30 #include <unotools/resmgr.hxx>
32 using namespace com::sun::star;
35 constexpr OUStringLiteral STR_NONNEGATIVE = u"NonNegative";
36 constexpr OUStringLiteral STR_INTEGER = u"Integer";
37 constexpr OUStringLiteral STR_TIMEOUT = u"Timeout";
38 constexpr OUStringLiteral STR_EPSILONLEVEL = u"EpsilonLevel";
39 constexpr OUStringLiteral STR_LIMITBBDEPTH = u"LimitBBDepth";
40 constexpr OUStringLiteral STR_GEN_SENSITIVITY = u"GenSensitivityReport";
41 constexpr OUStringLiteral STR_SENSITIVITY_REPORT = u"SensitivityReport";
44 // Resources from tools are used for translated strings
46 OUString SolverComponent::GetResourceString(TranslateId aId)
48 return Translate::get(aId, Translate::Create("scc"));
51 size_t ScSolverCellHash::operator()( const css::table::CellAddress& rAddress ) const
53 return ( rAddress.Sheet << 24 ) | ( rAddress.Column << 16 ) | rAddress.Row;
56 bool ScSolverCellEqual::operator()( const css::table::CellAddress& rAddr1, const css::table::CellAddress& rAddr2 ) const
58 return AddressEqual( rAddr1, rAddr2 );
61 namespace
63 enum
65 PROP_NONNEGATIVE,
66 PROP_INTEGER,
67 PROP_TIMEOUT,
68 PROP_EPSILONLEVEL,
69 PROP_LIMITBBDEPTH,
70 PROP_GEN_SENSITIVITY,
71 PROP_SENSITIVITY_REPORT
75 uno::Reference<table::XCell> SolverComponent::GetCell( const uno::Reference<sheet::XSpreadsheetDocument>& xDoc,
76 const table::CellAddress& rPos )
78 uno::Reference<container::XIndexAccess> xSheets( xDoc->getSheets(), uno::UNO_QUERY );
79 uno::Reference<sheet::XSpreadsheet> xSheet( xSheets->getByIndex( rPos.Sheet ), uno::UNO_QUERY );
80 return xSheet->getCellByPosition( rPos.Column, rPos.Row );
83 void SolverComponent::SetValue( const uno::Reference<sheet::XSpreadsheetDocument>& xDoc,
84 const table::CellAddress& rPos, double fValue )
86 SolverComponent::GetCell( xDoc, rPos )->setValue( fValue );
89 double SolverComponent::GetValue( const uno::Reference<sheet::XSpreadsheetDocument>& xDoc,
90 const table::CellAddress& rPos )
92 return SolverComponent::GetCell( xDoc, rPos )->getValue();
95 SolverComponent::SolverComponent() :
96 mbMaximize( true ),
97 mbNonNegative( false ),
98 mbInteger( false ),
99 mnTimeout( 100 ),
100 mnEpsilonLevel( 0 ),
101 mbLimitBBDepth( true ),
102 mbGenSensitivity(false),
103 mbSuccess( false ),
104 mfResultValue( 0.0 )
106 // for XPropertySet implementation:
107 registerProperty(STR_NONNEGATIVE, PROP_NONNEGATIVE, 0, &mbNonNegative, cppu::UnoType<decltype(mbNonNegative)>::get());
108 registerProperty(STR_INTEGER, PROP_INTEGER, 0, &mbInteger, cppu::UnoType<decltype(mbInteger)>::get());
109 registerProperty(STR_TIMEOUT, PROP_TIMEOUT, 0, &mnTimeout, cppu::UnoType<decltype(mnTimeout)>::get());
110 registerProperty(STR_EPSILONLEVEL, PROP_EPSILONLEVEL, 0, &mnEpsilonLevel, cppu::UnoType<decltype(mnEpsilonLevel)>::get());
111 registerProperty(STR_LIMITBBDEPTH, PROP_LIMITBBDEPTH, 0, &mbLimitBBDepth, cppu::UnoType<decltype(mbLimitBBDepth)>::get());
112 registerProperty(STR_GEN_SENSITIVITY, PROP_GEN_SENSITIVITY, 0, &mbGenSensitivity, cppu::UnoType<decltype(mbGenSensitivity)>::get());
114 // Sensitivity report
115 registerProperty(STR_SENSITIVITY_REPORT, PROP_SENSITIVITY_REPORT, 0, &m_aSensitivityReport, cppu::UnoType<decltype(m_aSensitivityReport)>::get());
118 SolverComponent::~SolverComponent()
122 IMPLEMENT_FORWARD_XINTERFACE2( SolverComponent, SolverComponent_Base, comphelper::OPropertyContainer2 )
123 IMPLEMENT_FORWARD_XTYPEPROVIDER2( SolverComponent, SolverComponent_Base, comphelper::OPropertyContainer2 )
125 cppu::IPropertyArrayHelper* SolverComponent::createArrayHelper() const
127 uno::Sequence<beans::Property> aProps;
128 describeProperties( aProps );
129 return new cppu::OPropertyArrayHelper( aProps );
132 cppu::IPropertyArrayHelper& SolverComponent::getInfoHelper()
134 return *getArrayHelper();
137 uno::Reference<beans::XPropertySetInfo> SAL_CALL SolverComponent::getPropertySetInfo()
139 return createPropertySetInfo( getInfoHelper() );
142 // XSolverDescription
144 OUString SAL_CALL SolverComponent::getStatusDescription()
146 return maStatus;
149 OUString SAL_CALL SolverComponent::getPropertyDescription( const OUString& rPropertyName )
151 TranslateId pResId;
152 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
153 switch (nHandle)
155 case PROP_NONNEGATIVE:
156 pResId = RID_PROPERTY_NONNEGATIVE;
157 break;
158 case PROP_INTEGER:
159 pResId = RID_PROPERTY_INTEGER;
160 break;
161 case PROP_TIMEOUT:
162 pResId = RID_PROPERTY_TIMEOUT;
163 break;
164 case PROP_EPSILONLEVEL:
165 pResId = RID_PROPERTY_EPSILONLEVEL;
166 break;
167 case PROP_LIMITBBDEPTH:
168 pResId = RID_PROPERTY_LIMITBBDEPTH;
169 break;
170 case PROP_GEN_SENSITIVITY:
171 pResId = RID_PROPERTY_SENSITIVITY;
172 break;
173 default:
175 // unknown - leave empty
178 OUString aRet;
179 if (pResId)
180 aRet = SolverComponent::GetResourceString(pResId);
181 return aRet;
184 // XSolver: settings
186 uno::Reference<sheet::XSpreadsheetDocument> SAL_CALL SolverComponent::getDocument()
188 return mxDoc;
191 void SAL_CALL SolverComponent::setDocument( const uno::Reference<sheet::XSpreadsheetDocument>& _document )
193 mxDoc = _document;
196 table::CellAddress SAL_CALL SolverComponent::getObjective()
198 return maObjective;
201 void SAL_CALL SolverComponent::setObjective( const table::CellAddress& _objective )
203 maObjective = _objective;
206 uno::Sequence<table::CellAddress> SAL_CALL SolverComponent::getVariables()
208 return maVariables;
211 void SAL_CALL SolverComponent::setVariables( const uno::Sequence<table::CellAddress>& _variables )
213 maVariables = _variables;
216 uno::Sequence<sheet::SolverConstraint> SAL_CALL SolverComponent::getConstraints()
218 return maConstraints;
221 void SAL_CALL SolverComponent::setConstraints( const uno::Sequence<sheet::SolverConstraint>& _constraints )
223 maConstraints = _constraints;
226 sal_Bool SAL_CALL SolverComponent::getMaximize()
228 return mbMaximize;
231 void SAL_CALL SolverComponent::setMaximize( sal_Bool _maximize )
233 mbMaximize = _maximize;
236 // XSolver: get results
238 sal_Bool SAL_CALL SolverComponent::getSuccess()
240 return mbSuccess;
243 double SAL_CALL SolverComponent::getResultValue()
245 return mfResultValue;
248 uno::Sequence<double> SAL_CALL SolverComponent::getSolution()
250 return maSolution;
253 // XServiceInfo
255 sal_Bool SAL_CALL SolverComponent::supportsService( const OUString& rServiceName )
257 return cppu::supportsService(this, rServiceName);
260 uno::Sequence<OUString> SAL_CALL SolverComponent::getSupportedServiceNames()
262 return { u"com.sun.star.sheet.Solver"_ustr };
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */