tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / controller / inc / ItemConverter.hxx
blob031a633c22d8e6616b5f6b74a514833822861f04
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 #pragma once
21 #include <unotools/eventlisteneradapter.hxx>
22 #include <svl/itemset.hxx>
24 #include <utility>
26 namespace com::sun::star::beans { class XPropertySet; }
27 namespace com::sun::star::beans { class XPropertySetInfo; }
29 namespace chart::wrapper {
32 /** This class serves for conversion between properties of an XPropertySet and
33 SfxItems in SfxItemSets.
35 With this helper classes, you can feed dialogs with XPropertySets and let
36 those modify by the dialogs.
38 You must implement GetWhichPairs() such that an SfxItemSet created with
39 CreateEmptyItemSet() is able to hold all items that may be mapped.
41 You also have to implement GetItemProperty(), in order to return the
42 property name for a given which-id together with the corresponding member-id
43 that has to be used for conversion in QueryValue/PutValue.
45 FillSpecialItem and ApplySpecialItem may be used for special handling of
46 individual item, e.g. if you need member-ids in QueryValue/PutValue
48 A typical use could be the following:
50 ::comphelper::ChartTypeItemConverter aItemConverter( xPropertySet, GetItemPool() );
51 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
52 aItemConverter.FillItemSet( aItemSet );
53 bool bChanged = false;
55 MyDialog aDlg( aItemSet );
56 if( aDlg.Execute() == RET_OK )
58 const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
59 if( pOutItemSet )
60 bChanged = aItemConverter.ApplyItemSet( *pOutItemSet );
63 if( bChanged )
65 [ apply model changes to view ]
68 class ItemConverter :
69 public ::utl::OEventListenerAdapter
71 public:
72 /** Construct an item converter that uses the given property set for
73 reading/writing converted items
75 ItemConverter(
76 css::uno::Reference< css::beans::XPropertySet > xPropertySet ,
77 SfxItemPool& rItemPool );
78 virtual ~ItemConverter() override;
80 typedef sal_uInt16 tWhichIdType;
81 typedef OUString tPropertyNameType;
82 typedef sal_uInt8 tMemberIdType;
84 typedef std::pair< tPropertyNameType, tMemberIdType > tPropertyNameWithMemberId;
86 /** applies all properties that can be mapped to items into the given item
87 set.
89 Call this method before opening a dialog.
91 @param rOutItemSet
92 the SfxItemSet is filled with all items that are a result of a
93 conversion from a property of the internal XPropertySet.
95 virtual void FillItemSet( SfxItemSet & rOutItemSet ) const;
97 /** applies all properties that are results of a conversion from all items
98 in rItemSet to the internal XPropertySet.
100 Call this method after a dialog was closed with OK
102 @return true, if any properties have been changed, false otherwise.
104 virtual bool ApplyItemSet( const SfxItemSet & rItemSet );
106 /** creates an empty item set using the given pool or a common pool if empty
107 (see GetItemPool) and allowing all items given in the ranges returned by
108 GetWhichPairs.
110 SfxItemSet CreateEmptyItemSet() const;
112 /** Invalidates all items in rDestSet, that are set (state SfxItemState::SET) in
113 both item sets (rDestSet and rSourceSet) and have differing content.
115 static void InvalidateUnequalItems( SfxItemSet &rDestSet, const SfxItemSet &rSourceSet );
117 protected:
119 /** implement this method to provide an array of which-ranges
121 virtual const WhichRangesContainer& GetWhichPairs() const = 0;
123 /** implement this method to return a Property object for a given which id.
125 @param rOutProperty
126 If true is returned, this contains the property name and the
127 corresponding Member-Id.
129 @return true, if the item can be mapped to a property.
131 virtual bool GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const = 0;
133 /** for items that can not be mapped directly to a property.
135 This method is called from FillItemSet(), if GetItemProperty() returns
136 false.
138 The default implementation does nothing except showing an assertion
140 @throws css::uno::Exception
142 virtual void FillSpecialItem( sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const;
144 /** for items that can not be mapped directly to a property.
146 This method is called from ApplyItemSet(), if GetItemProperty() returns
147 false.
149 The default implementation returns just false and shows an assertion
151 @return true if the item changed a property, false otherwise.
153 @throws css::uno::Exception
155 virtual bool ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet & rItemSet );
157 /// Returns the pool
158 SfxItemPool & GetItemPool() const { return m_rItemPool;}
160 /** Returns the XPropertySet that was given in the CTOR and is used to apply
161 items in ApplyItemSet().
163 const css::uno::Reference< css::beans::XPropertySet >& GetPropertySet() const { return m_xPropertySet;}
165 // ____ ::utl::OEventListenerAdapter ____
166 virtual void _disposing( const css::lang::EventObject& rSource ) override;
168 protected:
169 /** sets a new property set, that you get with GetPropertySet(). It should
170 not be necessary to use this method. It is introduced to allow changing
171 the regression type of a regression curve which changes the object
172 identity.
174 void resetPropertySet( const css::uno::Reference< css::beans::XPropertySet > & xPropSet );
176 private:
177 css::uno::Reference< css::beans::XPropertySet > m_xPropertySet;
178 css::uno::Reference< css::beans::XPropertySetInfo > m_xPropertySetInfo;
180 SfxItemPool& m_rItemPool;
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */