update emoji autocorrect entries from po-files
[LibreOffice.git] / reportdesign / source / core / misc / conditionupdater.cxx
blob131089c9de986079e8b1fca8eee48367525cc0af
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 #include "conditionupdater.hxx"
20 #include "reportformula.hxx"
22 #include <com/sun/star/report/XFormatCondition.hpp>
24 #include <tools/diagnose_ex.h>
27 namespace rptui
31 using ::com::sun::star::beans::PropertyChangeEvent;
32 using ::com::sun::star::uno::Reference;
33 using ::com::sun::star::report::XReportControlModel;
34 using ::com::sun::star::uno::UNO_QUERY;
35 using ::com::sun::star::report::XFormatCondition;
36 using ::com::sun::star::uno::UNO_QUERY_THROW;
37 using ::com::sun::star::uno::Exception;
40 //= ConditionUpdater
43 ConditionUpdater::ConditionUpdater()
48 ConditionUpdater::~ConditionUpdater()
53 void ConditionUpdater::notifyPropertyChange( const PropertyChangeEvent& _rEvent )
55 if ( !impl_lateInit_nothrow() )
56 return;
58 Reference< XReportControlModel > xRptControlModel( _rEvent.Source, UNO_QUERY );
59 if ( xRptControlModel.is() && _rEvent.PropertyName == "DataField" )
61 OUString sOldDataSource, sNewDataSource;
62 OSL_VERIFY( _rEvent.OldValue >>= sOldDataSource );
63 OSL_VERIFY( _rEvent.NewValue >>= sNewDataSource );
64 impl_adjustFormatConditions_nothrow( xRptControlModel, sOldDataSource, sNewDataSource );
69 bool ConditionUpdater::impl_lateInit_nothrow()
71 if ( !m_aConditionalExpressions.empty() )
72 return true;
74 ConditionalExpressionFactory::getKnownConditionalExpressions( m_aConditionalExpressions );
75 return true;
79 void ConditionUpdater::impl_adjustFormatConditions_nothrow( const Reference< XReportControlModel >& _rxRptControlModel,
80 const OUString& _rOldDataSource, const OUString& _rNewDataSource )
82 try
84 ReportFormula aOldContentFormula( _rOldDataSource );
85 OUString sOldUnprefixed( aOldContentFormula.getBracketedFieldOrExpression() );
86 ReportFormula aNewContentFormula( _rNewDataSource );
87 OUString sNewUnprefixed( aNewContentFormula.getBracketedFieldOrExpression() );
89 sal_Int32 nCount( _rxRptControlModel->getCount() );
90 Reference< XFormatCondition > xFormatCondition;
91 OUString sFormulaExpression, sLHS, sRHS;
92 for ( sal_Int32 i=0; i<nCount; ++i )
94 xFormatCondition.set( _rxRptControlModel->getByIndex( i ), UNO_QUERY_THROW );
95 ReportFormula aFormula( xFormatCondition->getFormula() );
96 sFormulaExpression = aFormula.getExpression();
98 for ( ConditionalExpressions::const_iterator loop = m_aConditionalExpressions.begin();
99 loop != m_aConditionalExpressions.end();
100 ++loop
103 if ( !loop->second->matchExpression( sFormulaExpression, sOldUnprefixed, sLHS, sRHS ) )
104 continue;
106 // the expression matches -> translate it to the new data source of the report control model
107 sFormulaExpression = loop->second->assembleExpression( sNewUnprefixed, sLHS, sRHS );
108 aFormula = ReportFormula( ReportFormula::Expression, sFormulaExpression );
109 xFormatCondition->setFormula( aFormula.getCompleteFormula() );
110 break;
114 catch( const Exception& )
116 DBG_UNHANDLED_EXCEPTION();
121 } // namespace rptui
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */