LCOV - code coverage report
Current view: top level - libreoffice/reportdesign/source/core/misc - conditionupdater.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 42 0.0 %
Date: 2012-12-27 Functions: 0 5 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             : #include "conditionupdater.hxx"
      20             : #include "reportformula.hxx"
      21             : 
      22             : #include <com/sun/star/report/XFormatCondition.hpp>
      23             : 
      24             : #include <tools/diagnose_ex.h>
      25             : 
      26             : //........................................................................
      27             : namespace rptui
      28             : {
      29             : //........................................................................
      30             : 
      31             :     /** === begin UNO using === **/
      32             :     using ::com::sun::star::beans::PropertyChangeEvent;
      33             :     using ::com::sun::star::uno::Reference;
      34             :     using ::com::sun::star::report::XReportControlModel;
      35             :     using ::com::sun::star::uno::UNO_QUERY;
      36             :     using ::com::sun::star::report::XFormatCondition;
      37             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      38             :     using ::com::sun::star::uno::Exception;
      39             :     /** === end UNO using === **/
      40             : 
      41             :     //====================================================================
      42             :     //= ConditionUpdater
      43             :     //====================================================================
      44             :     //--------------------------------------------------------------------
      45           0 :     ConditionUpdater::ConditionUpdater()
      46             :     {
      47           0 :     }
      48             : 
      49             :     //--------------------------------------------------------------------
      50           0 :     ConditionUpdater::~ConditionUpdater()
      51             :     {
      52           0 :     }
      53             : 
      54             :     //--------------------------------------------------------------------
      55           0 :     void ConditionUpdater::notifyPropertyChange( const PropertyChangeEvent& _rEvent )
      56             :     {
      57           0 :         if ( !impl_lateInit_nothrow() )
      58           0 :             return;
      59             : 
      60           0 :         Reference< XReportControlModel > xRptControlModel( _rEvent.Source, UNO_QUERY );
      61           0 :         if ( xRptControlModel.is() && _rEvent.PropertyName == "DataField" )
      62             :         {
      63           0 :             ::rtl::OUString sOldDataSource, sNewDataSource;
      64           0 :             OSL_VERIFY( _rEvent.OldValue >>= sOldDataSource );
      65           0 :             OSL_VERIFY( _rEvent.NewValue >>= sNewDataSource );
      66           0 :             impl_adjustFormatConditions_nothrow( xRptControlModel, sOldDataSource, sNewDataSource );
      67           0 :         }
      68             :     }
      69             : 
      70             :     //--------------------------------------------------------------------
      71           0 :     bool ConditionUpdater::impl_lateInit_nothrow()
      72             :     {
      73           0 :         if ( !m_aConditionalExpressions.empty() )
      74           0 :             return true;
      75             : 
      76           0 :         ConditionalExpressionFactory::getKnownConditionalExpressions( m_aConditionalExpressions );
      77           0 :         return true;
      78             :     }
      79             : 
      80             :     //--------------------------------------------------------------------
      81           0 :     void ConditionUpdater::impl_adjustFormatConditions_nothrow( const Reference< XReportControlModel >& _rxRptControlModel,
      82             :         const ::rtl::OUString& _rOldDataSource, const ::rtl::OUString& _rNewDataSource )
      83             :     {
      84             :         try
      85             :         {
      86           0 :             ReportFormula aOldContentFormula( _rOldDataSource );
      87           0 :             ::rtl::OUString sOldUnprefixed( aOldContentFormula.getBracketedFieldOrExpression() );
      88           0 :             ReportFormula aNewContentFormula( _rNewDataSource );
      89           0 :             ::rtl::OUString sNewUnprefixed( aNewContentFormula.getBracketedFieldOrExpression() );
      90             : 
      91           0 :             sal_Int32 nCount( _rxRptControlModel->getCount() );
      92           0 :             Reference< XFormatCondition > xFormatCondition;
      93           0 :             ::rtl::OUString sFormulaExpression, sLHS, sRHS;
      94           0 :             for ( sal_Int32 i=0; i<nCount; ++i )
      95             :             {
      96           0 :                 xFormatCondition.set( _rxRptControlModel->getByIndex( i ), UNO_QUERY_THROW );
      97           0 :                 ReportFormula aFormula( xFormatCondition->getFormula() );
      98           0 :                 sFormulaExpression = aFormula.getExpression();
      99             : 
     100           0 :                 for (   ConditionalExpressions::const_iterator loop = m_aConditionalExpressions.begin();
     101           0 :                         loop != m_aConditionalExpressions.end();
     102             :                         ++loop
     103             :                     )
     104             :                 {
     105           0 :                     if ( !loop->second->matchExpression( sFormulaExpression, sOldUnprefixed, sLHS, sRHS ) )
     106           0 :                         continue;
     107             : 
     108             :                     // the expression matches -> translate it to the new data source of the report control model
     109           0 :                     sFormulaExpression = loop->second->assembleExpression( sNewUnprefixed, sLHS, sRHS );
     110           0 :                     aFormula = ReportFormula( ReportFormula::Expression, sFormulaExpression );
     111           0 :                     xFormatCondition->setFormula( aFormula.getCompleteFormula() );
     112           0 :                     break;
     113             :                 }
     114           0 :             }
     115             :         }
     116           0 :         catch( const Exception& )
     117             :         {
     118             :             DBG_UNHANDLED_EXCEPTION();
     119             :         }
     120           0 :     }
     121             : 
     122             : //........................................................................
     123             : } // namespace rptui
     124             : //........................................................................
     125             : 
     126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10