1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
;
43 ConditionUpdater::ConditionUpdater()
48 ConditionUpdater::~ConditionUpdater()
53 void ConditionUpdater::notifyPropertyChange( const PropertyChangeEvent
& _rEvent
)
55 impl_lateInit_nothrow();
57 Reference
< XReportControlModel
> xRptControlModel( _rEvent
.Source
, UNO_QUERY
);
58 if ( xRptControlModel
.is() && _rEvent
.PropertyName
== "DataField" )
60 OUString sOldDataSource
, sNewDataSource
;
61 OSL_VERIFY( _rEvent
.OldValue
>>= sOldDataSource
);
62 OSL_VERIFY( _rEvent
.NewValue
>>= sNewDataSource
);
63 impl_adjustFormatConditions_nothrow( xRptControlModel
, sOldDataSource
, sNewDataSource
);
68 void ConditionUpdater::impl_lateInit_nothrow()
70 if ( !m_aConditionalExpressions
.empty() )
73 ConditionalExpressionFactory::getKnownConditionalExpressions( m_aConditionalExpressions
);
77 void ConditionUpdater::impl_adjustFormatConditions_nothrow( const Reference
< XReportControlModel
>& _rxRptControlModel
,
78 const OUString
& _rOldDataSource
, const OUString
& _rNewDataSource
)
82 ReportFormula
aOldContentFormula( _rOldDataSource
);
83 OUString
sOldUnprefixed( aOldContentFormula
.getBracketedFieldOrExpression() );
84 ReportFormula
aNewContentFormula( _rNewDataSource
);
85 OUString
sNewUnprefixed( aNewContentFormula
.getBracketedFieldOrExpression() );
87 sal_Int32
nCount( _rxRptControlModel
->getCount() );
88 Reference
< XFormatCondition
> xFormatCondition
;
89 OUString sFormulaExpression
, sLHS
, sRHS
;
90 for ( sal_Int32 i
=0; i
<nCount
; ++i
)
92 xFormatCondition
.set( _rxRptControlModel
->getByIndex( i
), UNO_QUERY_THROW
);
93 sFormulaExpression
= ReportFormula(xFormatCondition
->getFormula()).getExpression();
95 for (const auto& rEntry
: m_aConditionalExpressions
)
97 if ( !rEntry
.second
->matchExpression( sFormulaExpression
, sOldUnprefixed
, sLHS
, sRHS
) )
100 // the expression matches -> translate it to the new data source of the report control model
101 sFormulaExpression
= rEntry
.second
->assembleExpression( sNewUnprefixed
, sLHS
, sRHS
);
102 ReportFormula
aFormula(ReportFormula(ReportFormula::Expression
, sFormulaExpression
));
103 xFormatCondition
->setFormula(aFormula
.getCompleteFormula());
108 catch( const Exception
& )
110 DBG_UNHANDLED_EXCEPTION("reportdesign");
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */