LibreOffice Module chart2 (master) 1
ItemConverter.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
20#include <ItemConverter.hxx>
21#include <com/sun/star/lang/XComponent.hpp>
22#include <com/sun/star/beans/XPropertySet.hpp>
23#include <osl/diagnose.h>
24#include <svl/itempool.hxx>
25#include <svl/itemiter.hxx>
26#include <svl/whiter.hxx>
27#include <svx/svxids.hrc>
29#include <sal/log.hxx>
30#include <utility>
31
32using namespace ::com::sun::star;
33
34namespace chart::wrapper {
35
38 SfxItemPool& rItemPool ) :
39 m_xPropertySet(std::move( xPropertySet )),
40 m_rItemPool( rItemPool )
41{
43}
44
46{
48}
49
52{
53 if( !xPropSet.is())
54 return;
55
57 m_xPropertySet = xPropSet;
58 m_xPropertySetInfo = m_xPropertySet->getPropertySetInfo();
59
61 if( xComp.is())
62 {
63 // method of base class ::utl::OEventListenerAdapter
65 }
66}
67
69{
71}
72
73void ItemConverter::_disposing( const lang::EventObject& )
74{
75}
76
77void ItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
78{
79 const WhichRangesContainer& pRanges = rOutItemSet.GetRanges();
81 SfxItemPool & rPool = GetItemPool();
82
83 assert(!pRanges.empty());
84 OSL_ASSERT( m_xPropertySetInfo.is());
85 OSL_ASSERT( m_xPropertySet.is());
86
87 for(const auto& rPair : pRanges)
88 {
89 sal_uInt16 nBeg = rPair.first;
90 sal_uInt16 nEnd = rPair.second;
91
92 OSL_ASSERT( nBeg <= nEnd );
93 for( sal_uInt16 nWhich = nBeg; nWhich <= nEnd; ++nWhich )
94 {
95 if( GetItemProperty( nWhich, aProperty ))
96 {
97 // put the Property into the itemset
98 std::unique_ptr<SfxPoolItem> pItem(rPool.GetDefaultItem( nWhich ).Clone());
99
100 if( pItem )
101 {
102 try
103 {
104 if( pItem->PutValue( m_xPropertySet->getPropertyValue( aProperty.first ),
105 aProperty.second // nMemberId
106 ))
107 {
108 pItem->SetWhich(nWhich);
109 rOutItemSet.Put( std::move(pItem) );
110 }
111 }
112 catch( const beans::UnknownPropertyException & )
113 {
114 TOOLS_WARN_EXCEPTION( "chart2", "unknown Property: " << aProperty.first);
115 }
116 catch( const uno::Exception & )
117 {
118 DBG_UNHANDLED_EXCEPTION("chart2");
119 }
120 }
121 }
122 else
123 {
124 try
125 {
126 FillSpecialItem( nWhich, rOutItemSet );
127 }
128 catch( const uno::Exception & )
129 {
130 DBG_UNHANDLED_EXCEPTION("chart2");
131 }
132 }
133 }
134 }
135}
136
138 sal_uInt16 /*nWhichId*/, SfxItemSet & /*rOutItemSet*/ ) const
139{
140 OSL_FAIL( "ItemConverter: Unhandled special item found!" );
141}
142
144 sal_uInt16 /*nWhichId*/, const SfxItemSet & /*rItemSet*/ )
145{
146 OSL_FAIL( "ItemConverter: Unhandled special item found!" );
147 return false;
148}
149
151{
152 OSL_ASSERT( m_xPropertySet.is());
153
154 bool bItemsChanged = false;
155 SfxItemIter aIter( rItemSet );
157 uno::Any aValue;
158
159 for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
160 {
161 if( aIter.GetItemState( false ) == SfxItemState::SET )
162 {
163 if( GetItemProperty( pItem->Which(), aProperty ))
164 {
165 pItem->QueryValue( aValue, aProperty.second /* nMemberId */ );
166
167 try
168 {
169 if( aValue != m_xPropertySet->getPropertyValue( aProperty.first ))
170 {
171 m_xPropertySet->setPropertyValue( aProperty.first, aValue );
172 bItemsChanged = true;
173 }
174 }
175 catch( const beans::UnknownPropertyException & )
176 {
177 TOOLS_WARN_EXCEPTION( "chart2", "unknown Property: " << aProperty.first);
178 }
179 catch( const uno::Exception & )
180 {
181 TOOLS_WARN_EXCEPTION( "chart2", "" );
182 }
183 }
184 else
185 {
186 bItemsChanged = ApplySpecialItem( pItem->Which(), rItemSet ) || bItemsChanged;
187 }
188 }
189 }
190
191 return bItemsChanged;
192}
193
195{
196 SfxWhichIter aIter (rSourceSet);
197 sal_uInt16 nWhich = aIter.FirstWhich ();
198 const SfxPoolItem *pPoolItem = nullptr;
199
200 while (nWhich)
201 {
202 SfxItemState nSourceItemState = aIter.GetItemState(true, &pPoolItem);
203 if ((nSourceItemState == SfxItemState::SET) &&
204 (rDestSet.GetItemState(nWhich, true, &pPoolItem) == SfxItemState::SET))
205 {
206 if (rSourceSet.Get(nWhich) != rDestSet.Get(nWhich))
207 {
208 if( nWhich != SID_CHAR_DLG_PREVIEW_STRING )
209 {
210 rDestSet.InvalidateItem(nWhich);
211 }
212 }
213 }
214 else if( nSourceItemState == SfxItemState::DONTCARE )
215 rDestSet.InvalidateItem(nWhich);
216
217 nWhich = aIter.NextWhich ();
218 }
219}
220
221}
222
223/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SfxPoolItem * GetCurItem() const
const SfxPoolItem * NextItem()
SfxItemState GetItemState(bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
const WhichRangesContainer & GetRanges() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
void InvalidateItem(sal_uInt16 nWhich)
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
sal_uInt16 FirstWhich()
SfxItemState GetItemState(bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
sal_uInt16 NextWhich()
virtual const WhichRangesContainer & GetWhichPairs() const =0
implement this method to provide an array of which-ranges
void resetPropertySet(const css::uno::Reference< css::beans::XPropertySet > &xPropSet)
sets a new property set, that you get with GetPropertySet().
virtual void FillItemSet(SfxItemSet &rOutItemSet) const
applies all properties that can be mapped to items into the given item set.
css::uno::Reference< css::beans::XPropertySetInfo > m_xPropertySetInfo
virtual bool ApplySpecialItem(sal_uInt16 nWhichId, const SfxItemSet &rItemSet)
for items that can not be mapped directly to a property.
std::pair< tPropertyNameType, tMemberIdType > tPropertyNameWithMemberId
static void InvalidateUnequalItems(SfxItemSet &rDestSet, const SfxItemSet &rSourceSet)
Invalidates all items in rDestSet, that are set (state SfxItemState::SET) in both item sets (rDestSet...
css::uno::Reference< css::beans::XPropertySet > m_xPropertySet
SfxItemPool & GetItemPool() const
Returns the pool.
virtual void _disposing(const css::lang::EventObject &rSource) override
virtual bool GetItemProperty(tWhichIdType nWhichId, tPropertyNameWithMemberId &rOutProperty) const =0
implement this method to return a Property object for a given which id.
virtual bool ApplyItemSet(const SfxItemSet &rItemSet)
applies all properties that are results of a conversion from all items in rItemSet to the internal XP...
ItemConverter(css::uno::Reference< css::beans::XPropertySet > xPropertySet, SfxItemPool &rItemPool)
Construct an item converter that uses the given property set for reading/writing converted items.
virtual void FillSpecialItem(sal_uInt16 nWhichId, SfxItemSet &rOutItemSet) const
for items that can not be mapped directly to a property.
SfxItemSet CreateEmptyItemSet() const
creates an empty item set using the given pool or a common pool if empty (see GetItemPool) and allowi...
virtual ~ItemConverter() override
void startComponentListening(const css::uno::Reference< css::lang::XComponent > &_rxComp)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
SfxItemState
bool empty() const noexcept