LibreOffice Module chart2 (master) 1
TitleItemConverter.cxx
Go to the documentation of this file.
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
21#include "SchWhichPairs.hxx"
22#include <ItemPropertyMap.hxx>
26#include <svx/sdangitm.hxx>
27#include <rtl/math.hxx>
28
29#include <com/sun/star/chart2/XTitle.hpp>
30#include <com/sun/star/beans/XPropertySet.hpp>
31
32#include <memory>
33
34using namespace ::com::sun::star;
35
36namespace chart::wrapper {
37
38namespace {
39
40ItemPropertyMapType & lcl_GetTitlePropertyMap()
41{
42 static ItemPropertyMapType aTitlePropertyMap{
43 {SCHATTR_TEXT_STACKED, {"StackCharacters", 0}}};
44 return aTitlePropertyMap;
45};
46
47class FormattedStringsConverter : public MultipleItemConverter
48{
49public:
50 FormattedStringsConverter(
51 const uno::Sequence< uno::Reference< chart2::XFormattedString > > & aStrings,
52 SfxItemPool & rItemPool,
53 const awt::Size* pRefSize,
54 const uno::Reference< beans::XPropertySet > & xParentProp );
55
56protected:
57 virtual const WhichRangesContainer& GetWhichPairs() const override;
58};
59
60} // anonymous namespace
61
62FormattedStringsConverter::FormattedStringsConverter(
63 const uno::Sequence< uno::Reference< chart2::XFormattedString > > & aStrings,
64 SfxItemPool & rItemPool,
65 const awt::Size* pRefSize,
66 const uno::Reference< beans::XPropertySet > & xParentProp ) :
67 MultipleItemConverter( rItemPool )
68{
69 bool bHasRefSize = (pRefSize && xParentProp.is());
70 for( uno::Reference< chart2::XFormattedString > const & formattedStr : aStrings )
71 {
72 uno::Reference< beans::XPropertySet > xProp( formattedStr, uno::UNO_QUERY );
73 if( xProp.is())
74 {
75 if( bHasRefSize )
76 m_aConverters.emplace_back(
77 new CharacterPropertyItemConverter(
78 xProp, rItemPool, pRefSize, "ReferencePageSize", xParentProp));
79 else
80 m_aConverters.emplace_back( new CharacterPropertyItemConverter( xProp, rItemPool ));
81 }
82 }
83}
84
85const WhichRangesContainer& FormattedStringsConverter::GetWhichPairs() const
86{
88}
89
90TitleItemConverter::TitleItemConverter(
91 const uno::Reference<beans::XPropertySet> & rPropertySet,
92 SfxItemPool& rItemPool,
93 SdrModel& rDrawModel,
94 const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
95 const awt::Size* pRefSize ) :
96 ItemConverter( rPropertySet, rItemPool )
97{
99 rPropertySet, rItemPool, rDrawModel,
100 xNamedPropertyContainerFactory,
102
103 // CharacterProperties are not at the title but at its contained XFormattedString objects
104 // take the first formatted string in the sequence
105 uno::Reference< chart2::XTitle > xTitle( rPropertySet, uno::UNO_QUERY );
106 if( xTitle.is())
107 {
108 uno::Sequence< uno::Reference< chart2::XFormattedString > > aStringSeq( xTitle->getText());
109 if( aStringSeq.hasElements() )
110 {
111 m_aConverters.emplace_back(
112 new FormattedStringsConverter( aStringSeq, rItemPool, pRefSize, rPropertySet ));
113 }
114 }
115}
116
118{
119}
120
122{
123 for( const auto& pConv : m_aConverters )
124 pConv->FillItemSet( rOutItemSet );
125
126 // own items
127 ItemConverter::FillItemSet( rOutItemSet );
128}
129
131{
132 bool bResult = false;
133
134 for( const auto& pConv : m_aConverters )
135 bResult = pConv->ApplyItemSet( rItemSet ) || bResult;
136
137 // own items
138 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
139}
140
142{
143 // must span all used items!
144 return nTitleWhichPairs;
145}
146
148{
149 ItemPropertyMapType & rMap( lcl_GetTitlePropertyMap());
150 ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
151
152 if( aIt == rMap.end())
153 return false;
154
155 rOutProperty =(*aIt).second;
156 return true;
157}
158
160 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
161{
162 bool bChanged = false;
163
164 switch( nWhichId )
165 {
167 {
168 // convert int to double (divided by 100)
169 double fVal = static_cast< double >(
170 static_cast< const SdrAngleItem & >(
171 rItemSet.Get( nWhichId )).GetValue().get()) / 100.0;
172 double fOldVal = 0.0;
173 bool bPropExisted =
174 ( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fOldVal );
175
176 if( ! bPropExisted || fOldVal != fVal )
177 {
178 GetPropertySet()->setPropertyValue( "TextRotation" , uno::Any( fVal ));
179 bChanged = true;
180 }
181 }
182 break;
183 }
184
185 return bChanged;
186}
187
189 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
190{
191 switch( nWhichId )
192 {
194 {
195 // convert double to int (times 100)
196 double fVal = 0;
197
198 if( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fVal )
199 {
200 rOutItemSet.Put( SdrAngleItem( SCHATTR_TEXT_DEGREES, Degree100(static_cast< sal_Int32 >(
201 ::rtl::math::round( fVal * 100.0 ) ) )));
202 }
203 }
204 break;
205 }
206}
207
208} // namespace chart::wrapper
209
210/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr TypedWhichId< SfxBoolItem > SCHATTR_TEXT_STACKED(SCHATTR_TEXT_START+1)
constexpr TypedWhichId< SdrAngleItem > SCHATTR_TEXT_DEGREES(SCHATTR_TEXT_START)
const WhichRangesContainer nCharacterPropertyWhichPairs(svl::Items< EE_ITEMS_START, EE_ITEMS_END, SID_CHAR_DLG_PREVIEW_STRING, SID_CHAR_DLG_PREVIEW_STRING >)
const WhichRangesContainer nTitleWhichPairs(svl::Items< SCHATTR_TEXT_START, SCHATTR_TEXT_END, XATTR_LINE_FIRST, XATTR_LINE_LAST, XATTR_FILL_FIRST, XATTR_FILL_LAST, SDRATTR_SHADOW_FIRST, SDRATTR_SHADOW_LAST, EE_ITEMS_START, EE_ITEMS_END, SID_CHAR_DLG_PREVIEW_STRING, SID_CHAR_DLG_PREVIEW_STRING >)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
This class serves for conversion between properties of an XPropertySet and SfxItems in SfxItemSets.
virtual void FillItemSet(SfxItemSet &rOutItemSet) const
applies all properties that can be mapped to items into the given item set.
std::pair< tPropertyNameType, tMemberIdType > tPropertyNameWithMemberId
const css::uno::Reference< css::beans::XPropertySet > & GetPropertySet() const
Returns the XPropertySet that was given in the CTOR and is used to apply items in ApplyItemSet().
virtual bool ApplyItemSet(const SfxItemSet &rItemSet)
applies all properties that are results of a conversion from all items in rItemSet to the internal XP...
virtual bool ApplyItemSet(const SfxItemSet &rItemSet) override
applies all properties that are results of a conversion from all items in rItemSet to the internal XP...
std::vector< std::unique_ptr< ItemConverter > > m_aConverters
virtual bool GetItemProperty(tWhichIdType nWhichId, tPropertyNameWithMemberId &rOutProperty) const override
implement this method to return a Property object for a given which id.
virtual void FillItemSet(SfxItemSet &rOutItemSet) const override
applies all properties that can be mapped to items into the given item set.
virtual bool ApplySpecialItem(sal_uInt16 nWhichId, const SfxItemSet &rItemSet) override
for items that can not be mapped directly to a property.
virtual const WhichRangesContainer & GetWhichPairs() const override
implement this method to provide an array of which-ranges
virtual void FillSpecialItem(sal_uInt16 nWhichId, SfxItemSet &rOutItemSet) const override
for items that can not be mapped directly to a property.
std::map< ItemConverter::tWhichIdType, std::pair< ItemConverter::tPropertyNameType, ItemConverter::tMemberIdType > > ItemPropertyMapType
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
const char GetValue[]