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 : 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;
38 :
39 :
40 : //= ConditionUpdater
41 :
42 :
43 0 : ConditionUpdater::ConditionUpdater()
44 : {
45 0 : }
46 :
47 :
48 0 : ConditionUpdater::~ConditionUpdater()
49 : {
50 0 : }
51 :
52 :
53 0 : void ConditionUpdater::notifyPropertyChange( const PropertyChangeEvent& _rEvent )
54 : {
55 0 : if ( !impl_lateInit_nothrow() )
56 0 : return;
57 :
58 0 : Reference< XReportControlModel > xRptControlModel( _rEvent.Source, UNO_QUERY );
59 0 : if ( xRptControlModel.is() && _rEvent.PropertyName == "DataField" )
60 : {
61 0 : OUString sOldDataSource, sNewDataSource;
62 0 : OSL_VERIFY( _rEvent.OldValue >>= sOldDataSource );
63 0 : OSL_VERIFY( _rEvent.NewValue >>= sNewDataSource );
64 0 : impl_adjustFormatConditions_nothrow( xRptControlModel, sOldDataSource, sNewDataSource );
65 0 : }
66 : }
67 :
68 :
69 0 : bool ConditionUpdater::impl_lateInit_nothrow()
70 : {
71 0 : if ( !m_aConditionalExpressions.empty() )
72 0 : return true;
73 :
74 0 : ConditionalExpressionFactory::getKnownConditionalExpressions( m_aConditionalExpressions );
75 0 : return true;
76 : }
77 :
78 :
79 0 : void ConditionUpdater::impl_adjustFormatConditions_nothrow( const Reference< XReportControlModel >& _rxRptControlModel,
80 : const OUString& _rOldDataSource, const OUString& _rNewDataSource )
81 : {
82 : try
83 : {
84 0 : ReportFormula aOldContentFormula( _rOldDataSource );
85 0 : OUString sOldUnprefixed( aOldContentFormula.getBracketedFieldOrExpression() );
86 0 : ReportFormula aNewContentFormula( _rNewDataSource );
87 0 : OUString sNewUnprefixed( aNewContentFormula.getBracketedFieldOrExpression() );
88 :
89 0 : sal_Int32 nCount( _rxRptControlModel->getCount() );
90 0 : Reference< XFormatCondition > xFormatCondition;
91 0 : OUString sFormulaExpression, sLHS, sRHS;
92 0 : for ( sal_Int32 i=0; i<nCount; ++i )
93 : {
94 0 : xFormatCondition.set( _rxRptControlModel->getByIndex( i ), UNO_QUERY_THROW );
95 0 : ReportFormula aFormula( xFormatCondition->getFormula() );
96 0 : sFormulaExpression = aFormula.getExpression();
97 :
98 0 : for ( ConditionalExpressions::const_iterator loop = m_aConditionalExpressions.begin();
99 0 : loop != m_aConditionalExpressions.end();
100 : ++loop
101 : )
102 : {
103 0 : if ( !loop->second->matchExpression( sFormulaExpression, sOldUnprefixed, sLHS, sRHS ) )
104 0 : continue;
105 :
106 : // the expression matches -> translate it to the new data source of the report control model
107 0 : sFormulaExpression = loop->second->assembleExpression( sNewUnprefixed, sLHS, sRHS );
108 0 : aFormula = ReportFormula( ReportFormula::Expression, sFormulaExpression );
109 0 : xFormatCondition->setFormula( aFormula.getCompleteFormula() );
110 0 : break;
111 : }
112 0 : }
113 : }
114 0 : catch( const Exception& )
115 : {
116 : DBG_UNHANDLED_EXCEPTION();
117 : }
118 0 : }
119 :
120 :
121 : } // namespace rptui
122 :
123 :
124 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|