LibreOffice Module reportdesign (master) 1
conditionupdater.cxx
Go to the documentation of this file.
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
25
26
27namespace 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
44 {
45 }
46
47
49 {
50 }
51
52
53 void ConditionUpdater::notifyPropertyChange( const PropertyChangeEvent& _rEvent )
54 {
56
57 Reference< XReportControlModel > xRptControlModel( _rEvent.Source, UNO_QUERY );
58 if ( xRptControlModel.is() && _rEvent.PropertyName == "DataField" )
59 {
60 OUString sOldDataSource, sNewDataSource;
61 OSL_VERIFY( _rEvent.OldValue >>= sOldDataSource );
62 OSL_VERIFY( _rEvent.NewValue >>= sNewDataSource );
63 impl_adjustFormatConditions_nothrow( xRptControlModel, sOldDataSource, sNewDataSource );
64 }
65 }
66
67
69 {
70 if ( !m_aConditionalExpressions.empty() )
71 return;
72
74 }
75
76
78 const OUString& _rOldDataSource, const OUString& _rNewDataSource )
79 {
80 try
81 {
82 ReportFormula aOldContentFormula( _rOldDataSource );
83 OUString sOldUnprefixed( aOldContentFormula.getBracketedFieldOrExpression() );
84 ReportFormula aNewContentFormula( _rNewDataSource );
85 OUString sNewUnprefixed( aNewContentFormula.getBracketedFieldOrExpression() );
86
87 sal_Int32 nCount( _rxRptControlModel->getCount() );
88 Reference< XFormatCondition > xFormatCondition;
89 OUString sFormulaExpression, sLHS, sRHS;
90 for ( sal_Int32 i=0; i<nCount; ++i )
91 {
92 xFormatCondition.set( _rxRptControlModel->getByIndex( i ), UNO_QUERY_THROW );
93 sFormulaExpression = ReportFormula(xFormatCondition->getFormula()).getExpression();
94
95 for (const auto& rEntry : m_aConditionalExpressions)
96 {
97 if ( !rEntry.second->matchExpression( sFormulaExpression, sOldUnprefixed, sLHS, sRHS ) )
98 continue;
99
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());
104 break;
105 }
106 }
107 }
108 catch( const Exception& )
109 {
110 DBG_UNHANDLED_EXCEPTION("reportdesign");
111 }
112 }
113
114
115} // namespace rptui
116
117
118/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void impl_lateInit_nothrow()
does late initializations, return whether or not successful
ConditionalExpressions m_aConditionalExpressions
void impl_adjustFormatConditions_nothrow(const css::uno::Reference< css::report::XReportControlModel > &_rxRptControlModel, const OUString &_rOldDataSource, const OUString &_rNewDataSource)
void notifyPropertyChange(const css::beans::PropertyChangeEvent &_rEvent)
notifies the object about the change of a property value, somewhere in the report definition
static size_t getKnownConditionalExpressions(ConditionalExpressions &_out_rCondExp)
fills the given map with all ConditionalExpressions which we know
OUString getBracketedFieldOrExpression() const
returns a bracketed field name of the formula denotes a field reference, or the undecorated expressio...
const OUString & getCompleteFormula() const
returns the complete formula represented by the object
OUString const & getExpression() const
convenience alias for getUndecoratedContent, which asserts (in a non-product build) when used on a fi...
int nCount
#define DBG_UNHANDLED_EXCEPTION(...)
@ Exception
int i