Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / inc / ItemConverter.hxx
blobb8fa2614d6bf23b4d6ad8f395c6e3b70e601e7bf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_INC_ITEMCONVERTER_HXX
20 #define INCLUDED_CHART2_SOURCE_CONTROLLER_INC_ITEMCONVERTER_HXX
22 #include <unotools/eventlisteneradapter.hxx>
23 #include <svl/itemset.hxx>
25 #include <utility>
27 namespace com { namespace sun { namespace star { namespace beans { class XPropertySet; } } } }
28 namespace com { namespace sun { namespace star { namespace beans { class XPropertySetInfo; } } } }
30 namespace chart { namespace wrapper {
33 /** This class serves for conversion between properties of an XPropertySet and
34 SfxItems in SfxItemSets.
36 With this helper classes, you can feed dialogs with XPropertySets and let
37 those modify by the dialogs.
39 You must implement GetWhichPairs() such that an SfxItemSet created with
40 CreateEmptyItemSet() is able to hold all items that may be mapped.
42 You also have to implement GetItemProperty(), in order to return the
43 property name for a given which-id together with the corresponding member-id
44 that has to be used for conversion in QueryValue/PutValue.
46 FillSpecialItem and ApplySpecialItem may be used for special handling of
47 individual item, e.g. if you need member-ids in QueryValue/PutValue
49 A typical use could be the following:
51 ::comphelper::ChartTypeItemConverter aItemConverter( xPropertySet, GetItemPool() );
52 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
53 aItemConverter.FillItemSet( aItemSet );
54 bool bChanged = false;
56 MyDialog aDlg( aItemSet );
57 if( aDlg.Execute() == RET_OK )
59 const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
60 if( pOutItemSet )
61 bChanged = aItemConverter.ApplyItemSet( *pOutItemSet );
64 if( bChanged )
66 [ apply model changes to view ]
69 class ItemConverter :
70 public ::utl::OEventListenerAdapter
72 public:
73 /** Construct an item converter that uses the given property set for
74 reading/writing converted items
76 ItemConverter(
77 const css::uno::Reference< css::beans::XPropertySet > & rPropertySet ,
78 SfxItemPool& rItemPool );
79 virtual ~ItemConverter() override;
81 typedef sal_uInt16 tWhichIdType;
82 typedef OUString tPropertyNameType;
83 typedef sal_uInt8 tMemberIdType;
85 typedef std::pair< tPropertyNameType, tMemberIdType > tPropertyNameWithMemberId;
87 /** applies all properties that can be mapped to items into the given item
88 set.
90 Call this method before opening a dialog.
92 @param rOutItemSet
93 the SfxItemSet is filled with all items that are a result of a
94 conversion from a property of the internal XPropertySet.
96 virtual void FillItemSet( SfxItemSet & rOutItemSet ) const;
98 /** applies all properties that are results of a conversion from all items
99 in rItemSet to the internal XPropertySet.
101 Call this method after a dialog was closed with OK
103 @return true, if any properties have been changed, false otherwise.
105 virtual bool ApplyItemSet( const SfxItemSet & rItemSet );
107 /** creates an empty item set using the given pool or a common pool if empty
108 (see GetItemPool) and allowing all items given in the ranges returned by
109 GetWhichPairs.
111 SfxItemSet CreateEmptyItemSet() const;
113 /** Invalidates all items in rDestSet, that are set (state SfxItemState::SET) in
114 both item sets (rDestSet and rSourceSet) and have differing content.
116 static void InvalidateUnequalItems( SfxItemSet &rDestSet, const SfxItemSet &rSourceSet );
118 protected:
120 /** implement this method to provide an array of which-ranges of the form:
122 const sal_uInt16 aMyPairs[] =
124 from_1, to_1,
125 from_2, to_2,
127 from_n, to_n,
131 virtual const sal_uInt16 * GetWhichPairs() const = 0;
133 /** implement this method to return a Property object for a given which id.
135 @param rOutProperty
136 If true is returned, this contains the property name and the
137 corresponding Member-Id.
139 @return true, if the item can be mapped to a property.
141 virtual bool GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const = 0;
143 /** for items that can not be mapped directly to a property.
145 This method is called from FillItemSet(), if GetItemProperty() returns
146 false.
148 The default implementation does nothing except showing an assertion
150 @throws css::uno::Exception
152 virtual void FillSpecialItem( sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const;
154 /** for items that can not be mapped directly to a property.
156 This method is called from ApplyItemSet(), if GetItemProperty() returns
157 false.
159 The default implementation returns just false and shows an assertion
161 @return true if the item changed a property, false otherwise.
163 @throws css::uno::Exception
165 virtual bool ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet & rItemSet );
167 /// Returns the pool
168 SfxItemPool & GetItemPool() const { return m_rItemPool;}
170 /** Returns the XPropertySet that was given in the CTOR and is used to apply
171 items in ApplyItemSet().
173 const css::uno::Reference< css::beans::XPropertySet >& GetPropertySet() const { return m_xPropertySet;}
175 // ____ ::utl::OEventListenerAdapter ____
176 virtual void _disposing( const css::lang::EventObject& rSource ) override;
178 protected:
179 /** sets a new property set, that you get with GetPropertySet(). It should
180 not be necessary to use this method. It is introduced to allow changing
181 the regression type of a regression curve which changes the object
182 identity.
184 void resetPropertySet( const css::uno::Reference< css::beans::XPropertySet > & xPropSet );
186 private:
187 css::uno::Reference< css::beans::XPropertySet > m_xPropertySet;
188 css::uno::Reference< css::beans::XPropertySetInfo > m_xPropertySetInfo;
190 SfxItemPool& m_rItemPool;
195 // INCLUDED_CHART2_SOURCE_CONTROLLER_INC_ITEMCONVERTER_HXX
196 #endif
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */