Debian Codegraph @

chart2/source/controller/itemsetwrapper/TitleItemConverter.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 <TitleItemConverter.hxx>
21 #include "SchWhichPairs.hxx"
22 #include <ItemPropertyMap.hxx>
23 #include <GraphicPropertyItemConverter.hxx>
24 #include <CharacterPropertyItemConverter.hxx>
25 #include <MultipleItemConverter.hxx>
26 #include <ChartModel.hxx>
27 #include <svx/sdangitm.hxx>
28 #include <rtl/math.hxx>
29
30 #include <com/sun/star/chart2/XTitle.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32
33 #include <memory>
34
35 using namespace ::com::sun::star;
36
37 namespace chart::wrapper {
38
39 namespace {
40
41 ItemPropertyMapType & lcl_GetTitlePropertyMap()
42 {
43 static ItemPropertyMapType aTitlePropertyMap{
44 {SCHATTR_TEXT_STACKED, {"StackCharacters", 0}}};
45 return aTitlePropertyMap;
46 };
47
48 class FormattedStringsConverter : public MultipleItemConverter
49 {
50 public:
51 FormattedStringsConverter(
52 const uno::Sequence< uno::Reference< chart2::XFormattedString > > & aStrings,
53 SfxItemPool & rItemPool,
54 const std::optional<awt::Size>& pRefSize,
55 const uno::Reference< beans::XPropertySet > & xParentProp );
56
57 protected:
58 virtual const WhichRangesContainer& GetWhichPairs() const override;
59 };
60
61 } // anonymous namespace
62
63 FormattedStringsConverter::FormattedStringsConverter(
64 const uno::Sequence< uno::Reference< chart2::XFormattedString > > & aStrings,
65 SfxItemPool & rItemPool,
66 const std::optional<awt::Size>& pRefSize,
67 const uno::Reference< beans::XPropertySet > & xParentProp ) :
68 MultipleItemConverter( rItemPool )
69 {
70 bool bHasRefSize = (pRefSize && xParentProp.is());
71 for( uno::Reference< chart2::XFormattedString > const & formattedStr : aStrings )
72 {
73 uno::Reference< beans::XPropertySet > xProp( formattedStr, uno::UNO_QUERY );
74 if( xProp.is())
75 {
76 if( bHasRefSize )
77 m_aConverters.emplace_back(
78 new CharacterPropertyItemConverter(
79 xProp, rItemPool, pRefSize, u"ReferencePageSize"_ustr, xParentProp));
80 else
81 m_aConverters.emplace_back( new CharacterPropertyItemConverter( xProp, rItemPool ));
82 }
83 }
84 }
85
86 const WhichRangesContainer& FormattedStringsConverter::GetWhichPairs() const
87 {
88 return nCharacterPropertyWhichPairs;
89 }
90
91 TitleItemConverter::TitleItemConverter(
92 const uno::Reference<beans::XPropertySet> & rPropertySet,
93 SfxItemPool& rItemPool,
94 SdrModel& rDrawModel,
95 const rtl::Reference< ChartModel > & xChartModel,
96 const std::optional<awt::Size>& pRefSize ) :
97 ItemConverter( rPropertySet, rItemPool )
98 {
99 m_aConverters.emplace_back( new GraphicPropertyItemConverter(
100 rPropertySet, rItemPool, rDrawModel,
101 xChartModel,
102 GraphicObjectType::LineAndFillProperties ));
103
104 // CharacterProperties are not at the title but at its contained XFormattedString objects
105 // take the first formatted string in the sequence
106 uno::Reference< chart2::XTitle > xTitle( rPropertySet, uno::UNO_QUERY );
107 if( xTitle.is())
108 {
109 uno::Sequence< uno::Reference< chart2::XFormattedString > > aStringSeq( xTitle->getText());
110 if( aStringSeq.hasElements() )
111 {
112 m_aConverters.emplace_back(
113 new FormattedStringsConverter( aStringSeq, rItemPool, pRefSize, rPropertySet ));
114 }
115 }
116 }
117
118 TitleItemConverter::~TitleItemConverter()
119 {
120 }
121
122 void TitleItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
123 {
124 for( const auto& pConv : m_aConverters )
125 pConv->FillItemSet( rOutItemSet );
126
127 // own items
128 ItemConverter::FillItemSet( rOutItemSet );
129 }
130
131 bool TitleItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
132 {
133 bool bResult = false;
134
135 for( const auto& pConv : m_aConverters )
136 bResult = pConv->ApplyItemSet( rItemSet ) || bResult;
137
138 // own items
139 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
140 }
141
142 const WhichRangesContainer& TitleItemConverter::GetWhichPairs() const
143 {
144 // must span all used items!
145 return nTitleWhichPairs;
146 }
147
148 bool TitleItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
149 {
150 ItemPropertyMapType & rMap( lcl_GetTitlePropertyMap());
151 ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
152
153 if( aIt == rMap.end())
154 return false;
155
156 rOutProperty =(*aIt).second;
157 return true;
158 }
159
160 bool TitleItemConverter::ApplySpecialItem(
161 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
162 {
163 bool bChanged = false;
164
165 switch( nWhichId )
166 {
167 case SCHATTR_TEXT_DEGREES:
168 {
169 // convert int to double (divided by 100)
170 double fVal = static_cast< double >(
171 static_cast< const SdrAngleItem & >(
172 rItemSet.Get( nWhichId )).GetValue().get()) / 100.0;
173 double fOldVal = 0.0;
174 bool bPropExisted =
175 ( GetPropertySet()->getPropertyValue( u"TextRotation"_ustr ) >>= fOldVal );
176
177 if( ! bPropExisted || fOldVal != fVal )
178 {
179 GetPropertySet()->setPropertyValue( u"TextRotation"_ustr , uno::Any( fVal ));
180 bChanged = true;
181 }
182 }
183 break;
184 }
185
186 return bChanged;
187 }
188
189 void TitleItemConverter::FillSpecialItem(
190 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
191 {
192 switch( nWhichId )
193 {
194 case SCHATTR_TEXT_DEGREES:
195 {
196 // convert double to int (times 100)
197 double fVal = 0;
198
199 if( GetPropertySet()->getPropertyValue( u"TextRotation"_ustr ) >>= fVal )
200 {
201 rOutItemSet.Put( SdrAngleItem( SCHATTR_TEXT_DEGREES, Degree100(static_cast< sal_Int32 >(
202 ::rtl::math::round( fVal * 100.0 ) ) )));
203 }
204 }
205 break;
206 }
207 }
208
209 } // namespace chart::wrapper
210
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */