LCOV - code coverage report
Current view: top level - chart2/source/controller/inc - ItemConverter.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 2 0.0 %
Date: 2014-11-03 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_INC_ITEMCONVERTER_HXX
      20             : #define INCLUDED_CHART2_SOURCE_CONTROLLER_INC_ITEMCONVERTER_HXX
      21             : 
      22             : #include <unotools/eventlisteneradapter.hxx>
      23             : #include <svl/itempool.hxx>
      24             : #include <svl/itemset.hxx>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : 
      27             : #include <utility>
      28             : 
      29             : namespace chart { namespace wrapper {
      30             : 
      31             : 
      32             : /** This class serves for conversion between properties of an XPropertySet and
      33             :     SfxItems in SfxItemSets.
      34             : 
      35             :     With this helper classes, you can feed dialogs with XPropertySets and let
      36             :     those modify by the dialogs.
      37             : 
      38             :     You must implement GetWhichPairs() such that an SfxItemSet created with
      39             :     CreateEmptyItemSet() is able to hold all items that may be mapped.
      40             : 
      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.
      44             : 
      45             :     FillSpecialItem and ApplySpecialItem may be used for special handling of
      46             :     individual item, e.g. if you need member-ids in QueryValue/PutValue
      47             : 
      48             :     A typical use could be the following:
      49             : 
      50             :     ::comphelper::ChartTypeItemConverter aItemConverter( xPropertySet, GetItemPool() );
      51             :     SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
      52             :     aItemConverter.FillItemSet( aItemSet );
      53             :     bool bChanged = false;
      54             : 
      55             :     MyDialog aDlg( aItemSet );
      56             :     if( aDlg.Execute() == RET_OK )
      57             :     {
      58             :         const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
      59             :         if( pOutItemSet )
      60             :             bChanged = aItemConverter.ApplyItemSet( *pOutItemSet );
      61             :     }
      62             : 
      63             :     if( bChanged )
      64             :     {
      65             :         [ apply model changes to view ]
      66             :     }
      67             :  */
      68             : class ItemConverter :
      69             :         public ::utl::OEventListenerAdapter
      70             : {
      71             : public:
      72             :     /** Construct an item converter that uses the given property set for
      73             :         reading/writing converted items
      74             :      */
      75             :     ItemConverter(
      76             :         const ::com::sun::star::uno::Reference<
      77             :             ::com::sun::star::beans::XPropertySet > & rPropertySet ,
      78             :             SfxItemPool& rItemPool );
      79             :     virtual ~ItemConverter();
      80             : 
      81             :     typedef sal_uInt16          tWhichIdType;
      82             :     typedef OUString tPropertyNameType;
      83             :     typedef sal_uInt8            tMemberIdType;
      84             : 
      85             :     typedef ::std::pair< tPropertyNameType, tMemberIdType > tPropertyNameWithMemberId;
      86             : 
      87             :     /** applies all properties that can be mapped to items into the given item
      88             :         set.
      89             : 
      90             :         Call this method before opening a dialog.
      91             : 
      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.
      95             :      */
      96             :     virtual void FillItemSet( SfxItemSet & rOutItemSet ) const;
      97             : 
      98             :     /** applies all properties that are results of a conversion from all items
      99             :         in rItemSet to the internal XPropertySet.
     100             : 
     101             :         Call this method after a dialog was closed with OK
     102             : 
     103             :         @return true, if any properties have been changed, false otherwise.
     104             :      */
     105             :     virtual bool ApplyItemSet( const SfxItemSet & rItemSet );
     106             : 
     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.
     110             :      */
     111             :     SfxItemSet CreateEmptyItemSet() const;
     112             : 
     113             :     /** Invalidates all items in rDestSet, that are set (state SfxItemState::SET) in
     114             :         both item sets (rDestSet and rSourceSet) and have differing content.
     115             :      */
     116             :     static void InvalidateUnequalItems( SfxItemSet &rDestSet, const SfxItemSet &rSourceSet );
     117             : 
     118             : protected:
     119             : 
     120             :     /** implement this method to provide an array of which-ranges of the form:
     121             : 
     122             :         const sal_uInt16 aMyPairs[] =
     123             :         {
     124             :             from_1, to_1,
     125             :             from_2, to_2,
     126             :             ...
     127             :             from_n, to_n,
     128             :             0
     129             :         };
     130             :     */
     131             :     virtual const sal_uInt16 * GetWhichPairs() const = 0;
     132             : 
     133             :     /** implement this method to return a Property object for a given which id.
     134             : 
     135             :         @param rOutProperty
     136             :             If true is returned, this contains the property name and the
     137             :             corresponding Member-Id.
     138             : 
     139             :         @return true, if the item can be mapped to a property.
     140             :      */
     141             :     virtual bool GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const = 0;
     142             : 
     143             :     /** for items that can not be mapped directly to a property.
     144             : 
     145             :         This method is called from FillItemSet(), if GetItemProperty() returns
     146             :         false.
     147             : 
     148             :         The default implementation does nothing except showing an assertion
     149             :      */
     150             :     virtual void FillSpecialItem( sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
     151             :         throw (css::uno::Exception, std::exception);
     152             : 
     153             :     /** for items that can not be mapped directly to a property.
     154             : 
     155             :         This method is called from ApplyItemSet(), if GetItemProperty() returns
     156             :         false.
     157             : 
     158             :         The default implementation returns just false and shows an assertion
     159             : 
     160             :         @return true if the item changed a property, false otherwise.
     161             :      */
     162             :     virtual bool ApplySpecialItem( sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
     163             :         throw( ::com::sun::star::uno::Exception );
     164             : 
     165             :     /// Returns the pool
     166           0 :     SfxItemPool & GetItemPool() const { return m_rItemPool;}
     167             : 
     168             :     /** Returns the XPropertySet that was given in the CTOR and is used to apply
     169             :         items in ApplyItemSet().
     170             :      */
     171             :     ::com::sun::star::uno::Reference<
     172           0 :         ::com::sun::star::beans::XPropertySet >  GetPropertySet() const { return m_xPropertySet;}
     173             : 
     174             :     // ____ ::utl::OEventListenerAdapter ____
     175             :     virtual void _disposing( const ::com::sun::star::lang::EventObject& rSource ) SAL_OVERRIDE;
     176             : 
     177             : protected:
     178             :     /** sets a new property set, that you get with GetPropertySet().  It should
     179             :         not be necessary to use this method.  It is introduced to allow changing
     180             :         the regression type of a regression curve which changes the object
     181             :         identity.
     182             :      */
     183             :     void resetPropertySet( const ::com::sun::star::uno::Reference<
     184             :                            ::com::sun::star::beans::XPropertySet > & xPropSet );
     185             : 
     186             : private:
     187             :     ::com::sun::star::uno::Reference<
     188             :         ::com::sun::star::beans::XPropertySet >     m_xPropertySet;
     189             :     ::com::sun::star::uno::Reference<
     190             :         ::com::sun::star::beans::XPropertySetInfo > m_xPropertySetInfo;
     191             : 
     192             :     SfxItemPool&                                    m_rItemPool;
     193             :     bool                                            m_bIsValid;
     194             : };
     195             : 
     196             : }}
     197             : 
     198             : // INCLUDED_CHART2_SOURCE_CONTROLLER_INC_ITEMCONVERTER_HXX
     199             : #endif
     200             : 
     201             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10