LibreOffice Module chart2 (master) 1
LegendItemConverter.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"
24#include <com/sun/star/chart2/LegendPosition.hpp>
25#include <com/sun/star/chart/ChartLegendExpansion.hpp>
26#include <com/sun/star/beans/XPropertySet.hpp>
27
28#include <svl/intitem.hxx>
29#include <svl/eitem.hxx>
31
32#include <memory>
33
34using namespace ::com::sun::star;
35
36namespace chart::wrapper
37{
38
40 const css::uno::Reference< css::beans::XPropertySet > & rPropertySet,
41 SfxItemPool& rItemPool,
42 SdrModel& rDrawModel,
43 const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
44 const awt::Size* pRefSize ) :
45 ItemConverter( rPropertySet, rItemPool )
46{
48 rPropertySet, rItemPool, rDrawModel, xNamedPropertyContainerFactory,
51 rPropertySet, rItemPool, pRefSize,
52 "ReferencePageSize" ));
53}
54
56{
57}
58
60{
61 for( const auto& pConv : m_aConverters )
62 pConv->FillItemSet( rOutItemSet );
63
64 // own items
65 ItemConverter::FillItemSet( rOutItemSet );
66}
67
69{
70 bool bResult = false;
71
72 for( const auto& pConv : m_aConverters )
73 bResult = pConv->ApplyItemSet( rItemSet ) || bResult;
74
75 // own items
76 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
77}
78
80{
81 // must span all used items!
82 return nLegendWhichPairs;
83}
84
86{
87 // No own (non-special) properties
88 return false;
89}
90
91bool LegendItemConverter::ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet& rInItemSet )
92{
93 bool bChanged = false;
94
95 switch( nWhichId )
96 {
98 {
99 if( const SfxBoolItem* pShowItem = rInItemSet.GetItemIfSet( SCHATTR_LEGEND_SHOW ) )
100 {
101 bool bShow = pShowItem->GetValue();
102 bool bWasShown = true;
103 if( ! (GetPropertySet()->getPropertyValue( "Show" ) >>= bWasShown) ||
104 ( bWasShown != bShow ))
105 {
106 GetPropertySet()->setPropertyValue( "Show" , uno::Any( bShow ));
107 bChanged = true;
108 }
109 }
110
111 }
112 break;
114 {
115 if( const SfxInt32Item* pPosItem = rInItemSet.GetItemIfSet( SCHATTR_LEGEND_POS ) )
116 {
117 chart2::LegendPosition eNewPos = static_cast<chart2::LegendPosition>(pPosItem->GetValue());
118
119 css::chart::ChartLegendExpansion eExpansion = css::chart::ChartLegendExpansion_HIGH;
120 switch( eNewPos )
121 {
122 case chart2::LegendPosition_LINE_START:
123 case chart2::LegendPosition_LINE_END:
124 eExpansion = css::chart::ChartLegendExpansion_HIGH;
125 break;
126 case chart2::LegendPosition_PAGE_START:
127 case chart2::LegendPosition_PAGE_END:
128 eExpansion = css::chart::ChartLegendExpansion_WIDE;
129 break;
130 default:
131 break;
132 }
133
134 try
135 {
136 chart2::LegendPosition eOldPos;
137 if( ! ( GetPropertySet()->getPropertyValue( "AnchorPosition" ) >>= eOldPos ) ||
138 ( eOldPos != eNewPos ))
139 {
140 GetPropertySet()->setPropertyValue( "AnchorPosition" , uno::Any( eNewPos ));
141 GetPropertySet()->setPropertyValue( "Expansion" , uno::Any( eExpansion ));
142 GetPropertySet()->setPropertyValue( "RelativePosition" , uno::Any());
143 bChanged = true;
144 }
145 }
146 catch( const uno::Exception & )
147 {
148 DBG_UNHANDLED_EXCEPTION("chart2");
149 }
150 }
151 }
152 break;
154 {
155 if(const SfxBoolItem* pNoOverlayItem = rInItemSet.GetItemIfSet(SCHATTR_LEGEND_NO_OVERLAY))
156 {
157 bool bOverlay = !pNoOverlayItem->GetValue();
158 bool bOldOverlay = false;
159 if(!(GetPropertySet()->getPropertyValue("Overlay") >>= bOldOverlay) ||
160 (bOldOverlay != bOverlay))
161 {
162 GetPropertySet()->setPropertyValue("Overlay", uno::Any(bOverlay));
163 bChanged = true;
164 }
165 }
166
167 }
168 break;
169 }
170
171 return bChanged;
172}
173
175 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
176{
177 switch( nWhichId )
178 {
180 {
181 bool bShow = true;
182 GetPropertySet()->getPropertyValue( "Show" ) >>= bShow;
183 rOutItemSet.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, bShow) );
184 }
185 break;
187 {
188 chart2::LegendPosition eLegendPos( chart2::LegendPosition_LINE_END );
189 GetPropertySet()->getPropertyValue( "AnchorPosition" ) >>= eLegendPos;
190 rOutItemSet.Put( SfxInt32Item(SCHATTR_LEGEND_POS, static_cast<sal_Int32>(eLegendPos) ) );
191 }
192 break;
194 {
195 bool bOverlay = false;
196 GetPropertySet()->getPropertyValue("Overlay") >>= bOverlay;
197 rOutItemSet.Put(SfxBoolItem(SCHATTR_LEGEND_NO_OVERLAY, !bOverlay));
198 }
199 break;
200 }
201}
202
203} // namespace chart::wrapper
204
205/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr TypedWhichId< SfxInt32Item > SCHATTR_LEGEND_POS(SCHATTR_LEGEND_START)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_LEGEND_SHOW(SCHATTR_LEGEND_START+1)
constexpr TypedWhichId< SfxBoolItem > SCHATTR_LEGEND_NO_OVERLAY(SCHATTR_LEGEND_START+2)
const WhichRangesContainer nLegendWhichPairs(svl::Items< SCHATTR_LEGEND_START, SCHATTR_LEGEND_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 T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
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...
LegendItemConverter(const css::uno::Reference< css::beans::XPropertySet > &rPropertySet, SfxItemPool &rItemPool, SdrModel &rDrawModel, const css::uno::Reference< css::lang::XMultiServiceFactory > &xNamedPropertyContainerFactory, const css::awt::Size *pRefSize)
virtual bool ApplySpecialItem(sal_uInt16 nWhichId, const SfxItemSet &rItemSet) override
for items that can not be mapped directly to a property.
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 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.
virtual void FillItemSet(SfxItemSet &rOutItemSet) const override
applies all properties that can be mapped to items into the given item set.
#define DBG_UNHANDLED_EXCEPTION(...)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)