Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / RegressionEquationItemConverter.cxx
blob22fc379b2a2cd7e7d10ea24544e287c97f218664
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 <RegressionEquationItemConverter.hxx>
21 #include "SchWhichPairs.hxx"
22 #include <ItemPropertyMap.hxx>
23 #include <GraphicPropertyItemConverter.hxx>
24 #include <CharacterPropertyItemConverter.hxx>
25 #include <unonames.hxx>
26 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <svl/intitem.hxx>
30 #include <memory>
32 using namespace ::com::sun::star;
34 namespace chart::wrapper {
36 namespace {
38 ItemPropertyMapType & lcl_GetEquationPropertyMap()
40 static ItemPropertyMapType aEquationPropertyMap;
42 return aEquationPropertyMap;
45 } // anonymous namespace
47 RegressionEquationItemConverter::RegressionEquationItemConverter(
48 const css::uno::Reference< css::beans::XPropertySet > & rPropertySet,
49 SfxItemPool& rItemPool,
50 SdrModel& rDrawModel,
51 const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
52 const awt::Size* pRefSize ) :
53 ItemConverter( rPropertySet, rItemPool )
55 m_aConverters.emplace_back( new GraphicPropertyItemConverter(
56 rPropertySet, rItemPool, rDrawModel,
57 xNamedPropertyContainerFactory,
58 GraphicObjectType::LineAndFillProperties ));
60 m_aConverters.emplace_back(
61 new CharacterPropertyItemConverter(rPropertySet, rItemPool, pRefSize, "ReferencePageSize"));
64 RegressionEquationItemConverter::~RegressionEquationItemConverter()
68 void RegressionEquationItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
70 for( const auto& pConv : m_aConverters )
71 pConv->FillItemSet( rOutItemSet );
73 // own items
74 ItemConverter::FillItemSet( rOutItemSet );
77 bool RegressionEquationItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
79 bool bResult = false;
81 for( const auto& pConv : m_aConverters )
82 bResult = pConv->ApplyItemSet( rItemSet );
84 // own items
85 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
88 const WhichRangesContainer& RegressionEquationItemConverter::GetWhichPairs() const
90 // must span all used items!
91 return nRegEquationWhichPairs;
94 bool RegressionEquationItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
96 ItemPropertyMapType & rMap( lcl_GetEquationPropertyMap());
97 ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
99 if( aIt == rMap.end())
100 return false;
102 rOutProperty =(*aIt).second;
103 return true;
106 bool RegressionEquationItemConverter::ApplySpecialItem(
107 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
109 bool bChanged = false;
111 switch( nWhichId )
113 case SID_ATTR_NUMBERFORMAT_VALUE:
115 uno::Any aValue( static_cast< sal_Int32 >(
116 static_cast< const SfxUInt32Item & >(
117 rItemSet.Get( nWhichId )).GetValue()));
118 if (GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT) != aValue)
120 GetPropertySet()->setPropertyValue(CHART_UNONAME_NUMFMT, aValue);
121 bChanged = true;
124 break;
127 return bChanged;
130 void RegressionEquationItemConverter::FillSpecialItem(
131 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
133 switch( nWhichId )
135 case SID_ATTR_NUMBERFORMAT_VALUE:
137 sal_Int32 nFormatKey = 0;
138 if (GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nFormatKey)
140 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
143 break;
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */