Debian Codegraph @

chart2/source/controller/itemsetwrapper/RegressionEquationItemConverter.cxx

raw
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 #include <RegressionEquationItemConverter.hxx>
21 #include "SchWhichPairs.hxx"
22 #include <ItemPropertyMap.hxx>
23 #include <GraphicPropertyItemConverter.hxx>
24 #include <CharacterPropertyItemConverter.hxx>
25 #include <ChartModel.hxx>
26 #include <unonames.hxx>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28
29 #include <svl/intitem.hxx>
30
31 #include <memory>
32
33 using namespace ::com::sun::star;
34
35 namespace chart::wrapper {
36
37 namespace {
38
39 ItemPropertyMapType & lcl_GetEquationPropertyMap()
40 {
41 static ItemPropertyMapType aEquationPropertyMap;
42
43 return aEquationPropertyMap;
44 };
45
46 } // anonymous namespace
47
48 RegressionEquationItemConverter::RegressionEquationItemConverter(
49 const css::uno::Reference< css::beans::XPropertySet > & rPropertySet,
50 SfxItemPool& rItemPool,
51 SdrModel& rDrawModel,
52 const rtl::Reference< ChartModel > & xChartModel,
53 const std::optional<awt::Size>& pRefSize ) :
54 ItemConverter( rPropertySet, rItemPool )
55 {
56 m_aConverters.emplace_back( new GraphicPropertyItemConverter(
57 rPropertySet, rItemPool, rDrawModel,
58 xChartModel,
59 GraphicObjectType::LineAndFillProperties ));
60
61 m_aConverters.emplace_back(
62 new CharacterPropertyItemConverter(rPropertySet, rItemPool, pRefSize, u"ReferencePageSize"_ustr));
63 }
64
65 RegressionEquationItemConverter::~RegressionEquationItemConverter()
66 {
67 }
68
69 void RegressionEquationItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
70 {
71 for( const auto& pConv : m_aConverters )
72 pConv->FillItemSet( rOutItemSet );
73
74 // own items
75 ItemConverter::FillItemSet( rOutItemSet );
76 }
77
78 bool RegressionEquationItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
79 {
80 bool bResult = false;
81
82 for( const auto& pConv : m_aConverters )
83 bResult = pConv->ApplyItemSet( rItemSet );
84
85 // own items
86 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
87 }
88
89 const WhichRangesContainer& RegressionEquationItemConverter::GetWhichPairs() const
90 {
91 // must span all used items!
92 return nRegEquationWhichPairs;
93 }
94
95 bool RegressionEquationItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
96 {
97 ItemPropertyMapType & rMap( lcl_GetEquationPropertyMap());
98 ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
99
100 if( aIt == rMap.end())
101 return false;
102
103 rOutProperty =(*aIt).second;
104 return true;
105 }
106
107 bool RegressionEquationItemConverter::ApplySpecialItem(
108 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
109 {
110 bool bChanged = false;
111
112 switch( nWhichId )
113 {
114 case SID_ATTR_NUMBERFORMAT_VALUE:
115 {
116 uno::Any aValue( static_cast< sal_Int32 >(
117 static_cast< const SfxUInt32Item & >(
118 rItemSet.Get( nWhichId )).GetValue()));
119 if (GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT) != aValue)
120 {
121 GetPropertySet()->setPropertyValue(CHART_UNONAME_NUMFMT, aValue);
122 bChanged = true;
123 }
124 }
125 break;
126 }
127
128 return bChanged;
129 }
130
131 void RegressionEquationItemConverter::FillSpecialItem(
132 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
133 {
134 switch( nWhichId )
135 {
136 case SID_ATTR_NUMBERFORMAT_VALUE:
137 {
138 sal_Int32 nFormatKey = 0;
139 if (GetPropertySet()->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nFormatKey)
140 {
141 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
142 }
143 }
144 break;
145 }
146 }
147
148 }
149
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */