2010-10-12 15:59:03 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-10-01 16:08:38 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2017-10-23 22:34:20 +02:00
|
|
|
#include <conditionupdater.hxx>
|
|
|
|
#include <reportformula.hxx>
|
2007-08-02 13:31:20 +00:00
|
|
|
|
|
|
|
#include <com/sun/star/report/XFormatCondition.hpp>
|
|
|
|
|
|
|
|
#include <tools/diagnose_ex.h>
|
|
|
|
|
2014-02-25 19:49:46 +01:00
|
|
|
|
2007-08-02 13:31:20 +00:00
|
|
|
namespace rptui
|
|
|
|
{
|
2014-02-25 19:49:46 +01:00
|
|
|
|
2007-08-02 13:31:20 +00:00
|
|
|
|
|
|
|
using ::com::sun::star::beans::PropertyChangeEvent;
|
|
|
|
using ::com::sun::star::uno::Reference;
|
|
|
|
using ::com::sun::star::report::XReportControlModel;
|
|
|
|
using ::com::sun::star::uno::UNO_QUERY;
|
|
|
|
using ::com::sun::star::report::XFormatCondition;
|
|
|
|
using ::com::sun::star::uno::UNO_QUERY_THROW;
|
|
|
|
using ::com::sun::star::uno::Exception;
|
|
|
|
|
2014-02-25 19:49:46 +01:00
|
|
|
|
2007-08-02 13:31:20 +00:00
|
|
|
//= ConditionUpdater
|
2014-02-25 19:49:46 +01:00
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-08-02 13:31:20 +00:00
|
|
|
ConditionUpdater::ConditionUpdater()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-08-02 13:31:20 +00:00
|
|
|
ConditionUpdater::~ConditionUpdater()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-08-02 13:31:20 +00:00
|
|
|
void ConditionUpdater::notifyPropertyChange( const PropertyChangeEvent& _rEvent )
|
|
|
|
{
|
|
|
|
if ( !impl_lateInit_nothrow() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Reference< XReportControlModel > xRptControlModel( _rEvent.Source, UNO_QUERY );
|
2012-04-06 19:49:53 +02:00
|
|
|
if ( xRptControlModel.is() && _rEvent.PropertyName == "DataField" )
|
2007-08-02 13:31:20 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sOldDataSource, sNewDataSource;
|
2007-08-02 13:31:20 +00:00
|
|
|
OSL_VERIFY( _rEvent.OldValue >>= sOldDataSource );
|
|
|
|
OSL_VERIFY( _rEvent.NewValue >>= sNewDataSource );
|
|
|
|
impl_adjustFormatConditions_nothrow( xRptControlModel, sOldDataSource, sNewDataSource );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-08-02 13:31:20 +00:00
|
|
|
bool ConditionUpdater::impl_lateInit_nothrow()
|
|
|
|
{
|
|
|
|
if ( !m_aConditionalExpressions.empty() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
ConditionalExpressionFactory::getKnownConditionalExpressions( m_aConditionalExpressions );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-08-02 13:31:20 +00:00
|
|
|
void ConditionUpdater::impl_adjustFormatConditions_nothrow( const Reference< XReportControlModel >& _rxRptControlModel,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& _rOldDataSource, const OUString& _rNewDataSource )
|
2007-08-02 13:31:20 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ReportFormula aOldContentFormula( _rOldDataSource );
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sOldUnprefixed( aOldContentFormula.getBracketedFieldOrExpression() );
|
2007-08-02 13:31:20 +00:00
|
|
|
ReportFormula aNewContentFormula( _rNewDataSource );
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sNewUnprefixed( aNewContentFormula.getBracketedFieldOrExpression() );
|
2007-08-02 13:31:20 +00:00
|
|
|
|
|
|
|
sal_Int32 nCount( _rxRptControlModel->getCount() );
|
|
|
|
Reference< XFormatCondition > xFormatCondition;
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sFormulaExpression, sLHS, sRHS;
|
2007-08-02 13:31:20 +00:00
|
|
|
for ( sal_Int32 i=0; i<nCount; ++i )
|
|
|
|
{
|
|
|
|
xFormatCondition.set( _rxRptControlModel->getByIndex( i ), UNO_QUERY_THROW );
|
2016-09-29 21:17:10 +01:00
|
|
|
sFormulaExpression = ReportFormula(xFormatCondition->getFormula()).getExpression();
|
2007-08-02 13:31:20 +00:00
|
|
|
|
|
|
|
for ( ConditionalExpressions::const_iterator loop = m_aConditionalExpressions.begin();
|
|
|
|
loop != m_aConditionalExpressions.end();
|
|
|
|
++loop
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if ( !loop->second->matchExpression( sFormulaExpression, sOldUnprefixed, sLHS, sRHS ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// the expression matches -> translate it to the new data source of the report control model
|
|
|
|
sFormulaExpression = loop->second->assembleExpression( sNewUnprefixed, sLHS, sRHS );
|
2016-09-29 21:17:10 +01:00
|
|
|
ReportFormula aFormula(ReportFormula(ReportFormula::Expression, sFormulaExpression));
|
|
|
|
xFormatCondition->setFormula(aFormula.getCompleteFormula());
|
2007-08-02 13:31:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( const Exception& )
|
|
|
|
{
|
|
|
|
DBG_UNHANDLED_EXCEPTION();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-25 19:49:46 +01:00
|
|
|
|
2007-08-02 13:31:20 +00:00
|
|
|
} // namespace rptui
|
2014-02-25 19:49:46 +01:00
|
|
|
|
2010-10-12 15:59:03 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|