diff options
5 files changed, 126 insertions, 124 deletions
diff --git a/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx b/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx index 9c4f1bfc5416..6e9e8b1bf5cb 100644 --- a/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx +++ b/chart2/source/controller/itemsetwrapper/RegressionCurveItemConverter.cxx @@ -76,8 +76,8 @@ namespace wrapper { RegressionCurveItemConverter::RegressionCurveItemConverter( - const uno::Reference< beans::XPropertySet > & rPropertySet, - const uno::Reference< chart2::XRegressionCurveContainer > & xRegCurveCnt, + const uno::Reference< beans::XPropertySet >& rPropertySet, + const uno::Reference< chart2::XRegressionCurveContainer >& xContainer, SfxItemPool& rItemPool, SdrModel& rDrawModel, const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory ) : @@ -86,7 +86,7 @@ RegressionCurveItemConverter::RegressionCurveItemConverter( rPropertySet, rItemPool, rDrawModel, xNamedPropertyContainerFactory, GraphicPropertyItemConverter::LINE_PROPERTIES )), - m_xCurveContainer( xRegCurveCnt ) + m_xCurveContainer( xContainer ) {} RegressionCurveItemConverter::~RegressionCurveItemConverter() @@ -146,11 +146,13 @@ bool RegressionCurveItemConverter::ApplySpecialItem( // for which this converter was created. Not optimal, but // currently the only way to handle the type in the // regression curve properties dialog - RegressionCurveHelper::changeRegressionCurveType( - lcl_convertRegressionType( eNewRegress ), - m_xCurveContainer, - xCurve, - uno::Reference< uno::XComponentContext >()); + xCurve = RegressionCurveHelper::changeRegressionCurveType( + lcl_convertRegressionType( eNewRegress ), + m_xCurveContainer, + xCurve, + uno::Reference< uno::XComponentContext >()); + uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); + resetPropertySet( xProperties ); bChanged = true; } } @@ -167,9 +169,9 @@ bool RegressionCurveItemConverter::ApplySpecialItem( uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); OSL_ASSERT( xProperties.is()); - sal_Int32 aOldDegree = 1; if( xProperties.is() ) { + sal_Int32 aOldDegree = 2; xProperties->getPropertyValue( "PolynomialDegree" ) >>= aOldDegree; if (aOldDegree != aDegree) { @@ -191,9 +193,9 @@ bool RegressionCurveItemConverter::ApplySpecialItem( uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); OSL_ASSERT( xProperties.is()); - sal_Int32 aOldPeriod = 2; if( xProperties.is() ) { + sal_Int32 aOldPeriod = 2; xProperties->getPropertyValue( "MovingAveragePeriod" ) >>= aOldPeriod; if (aOldPeriod != aPeriod) { @@ -215,9 +217,9 @@ bool RegressionCurveItemConverter::ApplySpecialItem( uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); OSL_ASSERT( xProperties.is()); - double aOldValue = 0.0; if( xProperties.is() ) { + double aOldValue = 0.0; xProperties->getPropertyValue( "ExtrapolateForward" ) >>= aOldValue; if (aOldValue != aValue) { @@ -239,9 +241,9 @@ bool RegressionCurveItemConverter::ApplySpecialItem( uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); OSL_ASSERT( xProperties.is()); - double aOldValue = 0.0; if( xProperties.is() ) { + double aOldValue = 0.0; xProperties->getPropertyValue( "ExtrapolateBackward" ) >>= aOldValue; if (aOldValue != aValue) { @@ -263,9 +265,9 @@ bool RegressionCurveItemConverter::ApplySpecialItem( uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); OSL_ASSERT( xProperties.is()); - sal_Bool bOldValue = false; if( xProperties.is() ) { + sal_Bool bOldValue = false; xProperties->getPropertyValue( "ForceIntercept" ) >>= bOldValue; if (bOldValue != bNewValue) { @@ -287,9 +289,9 @@ bool RegressionCurveItemConverter::ApplySpecialItem( uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); OSL_ASSERT( xProperties.is()); - double aOldValue = 0.0; if( xProperties.is() ) { + double aOldValue = 0.0; xProperties->getPropertyValue( "InterceptValue" ) >>= aOldValue; if (aOldValue != aValue) { diff --git a/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx b/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx index 2a8ebc8e76fd..c3d71356a4e7 100644 --- a/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx +++ b/chart2/source/controller/itemsetwrapper/StatisticsItemConverter.cxx @@ -415,33 +415,35 @@ bool StatisticsItemConverter::ApplySpecialItem( static_cast< const SvxChartRegressItem& >( rItemSet.Get( nWhichId )).GetValue(); - uno::Reference< chart2::XRegressionCurve > xRegressionCurve( GetPropertySet(), uno::UNO_QUERY ); - uno::Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer( GetPropertySet(), uno::UNO_QUERY ); + uno::Reference< chart2::XRegressionCurve > xCurve( GetPropertySet(), uno::UNO_QUERY ); + uno::Reference< chart2::XRegressionCurveContainer > xContainer( GetPropertySet(), uno::UNO_QUERY ); if( eRegress == CHREGRESS_NONE ) { - if ( xRegressionCurve.is() ) + if ( xContainer.is() ) { - xRegressionCurveContainer->removeRegressionCurve( xRegressionCurve ); + xContainer->removeRegressionCurve( xCurve ); bChanged = true; } } else { - if ( xRegressionCurve.is() ) + if ( xCurve.is() ) { SvxChartRegress eOldRegress( static_cast< SvxChartRegress >( static_cast< sal_Int32 >( - RegressionCurveHelper::getRegressionType( xRegressionCurve )))); + RegressionCurveHelper::getRegressionType( xCurve )))); if( eOldRegress != eRegress ) { - RegressionCurveHelper::changeRegressionCurveType( - lcl_convertRegressionType( eRegress ), - xRegressionCurveContainer, - xRegressionCurve, - uno::Reference< uno::XComponentContext >()); + xCurve = RegressionCurveHelper::changeRegressionCurveType( + lcl_convertRegressionType( eRegress ), + xContainer, + xCurve, + uno::Reference< uno::XComponentContext >()); + uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); + resetPropertySet( xProperties ); bChanged = true; } } diff --git a/chart2/source/controller/main/ChartController_Insert.cxx b/chart2/source/controller/main/ChartController_Insert.cxx index 6461a8a9aff1..86123f808fff 100644 --- a/chart2/source/controller/main/ChartController_Insert.cxx +++ b/chart2/source/controller/main/ChartController_Insert.cxx @@ -409,55 +409,59 @@ void ChartController::executeDispatch_InsertMenu_Trendlines() void ChartController::executeDispatch_InsertTrendline() { - uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt( + uno::Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()), uno::UNO_QUERY ); - if( xRegCurveCnt.is()) - { - UndoLiveUpdateGuard aUndoGuard( - ActionDescriptionProvider::createDescription( - ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE ))), - m_xUndoManager ); - // add a linear curve + if( !xRegressionCurveContainer.is() ) + return; + + UndoLiveUpdateGuard aUndoGuard( + ActionDescriptionProvider::createDescription( + ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE ))), + m_xUndoManager ); + + // add a linear curve + uno::Reference< chart2::XRegressionCurve > xCurve = RegressionCurveHelper::addRegressionCurve( - RegressionCurveHelper::REGRESSION_TYPE_LINEAR, xRegCurveCnt, m_xCC ); + RegressionCurveHelper::REGRESSION_TYPE_LINEAR, + xRegressionCurveContainer, + m_xCC ); - // get an appropriate item converter - uno::Reference< chart2::XRegressionCurve > xCurve( - RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt )); - uno::Reference< beans::XPropertySet > xCurveProp( xCurve, uno::UNO_QUERY ); - if( !xCurveProp.is()) - return; - wrapper::RegressionCurveItemConverter aItemConverter( - xCurveProp, xRegCurveCnt, m_pDrawModelWrapper->getSdrModel().GetItemPool(), - m_pDrawModelWrapper->getSdrModel(), - uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY )); + // get an appropriate item converter + uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY ); - // open dialog - SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet(); - aItemConverter.FillItemSet( aItemSet ); - ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter( - ObjectIdentifier::createDataCurveCID( - ObjectIdentifier::getSeriesParticleFromCID( m_aSelection.getSelectedCID()), - RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt, xCurve ), false )); - aDialogParameter.init( getModel() ); - ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get()); - SolarMutexGuard aGuard; - SchAttribTabDlg aDialog( m_pChartWindow, &aItemSet, &aDialogParameter, &aViewElementListProvider, - uno::Reference< util::XNumberFormatsSupplier >( getModel(), uno::UNO_QUERY )); + if( !xProperties.is()) + return; - // note: when a user pressed "OK" but didn't change any settings in the - // dialog, the SfxTabDialog returns "Cancel" - if( aDialog.Execute() == RET_OK || aDialog.DialogWasClosedWithOK()) + wrapper::RegressionCurveItemConverter aItemConverter( + xProperties, xRegressionCurveContainer, m_pDrawModelWrapper->getSdrModel().GetItemPool(), + m_pDrawModelWrapper->getSdrModel(), + uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY )); + + // open dialog + SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet(); + aItemConverter.FillItemSet( aItemSet ); + ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter( + ObjectIdentifier::createDataCurveCID( + ObjectIdentifier::getSeriesParticleFromCID( m_aSelection.getSelectedCID()), + RegressionCurveHelper::getRegressionCurveIndex( xRegressionCurveContainer, xCurve ), false )); + aDialogParameter.init( getModel() ); + ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get()); + SolarMutexGuard aGuard; + SchAttribTabDlg aDialog( m_pChartWindow, &aItemSet, &aDialogParameter, &aViewElementListProvider, + uno::Reference< util::XNumberFormatsSupplier >( getModel(), uno::UNO_QUERY )); + + // note: when a user pressed "OK" but didn't change any settings in the + // dialog, the SfxTabDialog returns "Cancel" + if( aDialog.Execute() == RET_OK || aDialog.DialogWasClosedWithOK()) + { + const SfxItemSet* pOutItemSet = aDialog.GetOutputItemSet(); + if( pOutItemSet ) { - const SfxItemSet* pOutItemSet = aDialog.GetOutputItemSet(); - if( pOutItemSet ) - { - ControllerLockGuard aCLGuard( getModel() ); - aItemConverter.ApplyItemSet( *pOutItemSet ); - } - aUndoGuard.commit(); + ControllerLockGuard aCLGuard( getModel() ); + aItemConverter.ApplyItemSet( *pOutItemSet ); } + aUndoGuard.commit(); } } diff --git a/chart2/source/inc/RegressionCurveHelper.hxx b/chart2/source/inc/RegressionCurveHelper.hxx index 5f209dd00145..4efa6f46aabf 100644 --- a/chart2/source/inc/RegressionCurveHelper.hxx +++ b/chart2/source/inc/RegressionCurveHelper.hxx @@ -101,73 +101,64 @@ public: /** Returns the first regression curve found that is not of type mean-value line */ - static ::com::sun::star::uno::Reference< - ::com::sun::star::chart2::XRegressionCurve > + static com::sun::star::uno::Reference<com::sun::star::chart2::XRegressionCurve > getFirstCurveNotMeanValueLine( - const ::com::sun::star::uno::Reference< - ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); + const com::sun::star::uno::Reference< + com::sun::star::chart2::XRegressionCurveContainer >& xCurveContainer ); /** Returns the type of the first regression curve found that is not of type mean-value line */ static tRegressionType getFirstRegressTypeNotMeanValueLine( - const ::com::sun::star::uno::Reference< - ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); + const com::sun::star::uno::Reference< + com::sun::star::chart2::XRegressionCurveContainer >& xCurveContainer ); static tRegressionType getRegressionType( - const ::com::sun::star::uno::Reference< - ::com::sun::star::chart2::XRegressionCurve > & xCurve ); + const com::sun::star::uno::Reference< + com::sun::star::chart2::XRegressionCurve >& xCurve ); /** @param xPropertySource is taken as source to copy all properties from if not null @param xEquationProperties is set at the new regression curve as equation properties if not null */ - static void addRegressionCurve( tRegressionType eType, - ::com::sun::star::uno::Reference< - ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt, - const ::com::sun::star::uno::Reference< - ::com::sun::star::uno::XComponentContext > & xContext, - const ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XPropertySet >& xPropertySource = - ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XPropertySet >(), - const ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XPropertySet >& xEquationProperties = - ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XPropertySet >() - ); + static com::sun::star::uno::Reference< com::sun::star::chart2::XRegressionCurve > + addRegressionCurve( + tRegressionType eType, + com::sun::star::uno::Reference< + com::sun::star::chart2::XRegressionCurveContainer >& xCurveContainer, + const com::sun::star::uno::Reference< + com::sun::star::uno::XComponentContext >& xContext, + const com::sun::star::uno::Reference< + com::sun::star::beans::XPropertySet >& xPropertySource = + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >(), + const com::sun::star::uno::Reference< + com::sun::star::beans::XPropertySet >& xEquationProperties = + com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet >() ); static bool removeAllExceptMeanValueLine( - ::com::sun::star::uno::Reference< - ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); + com::sun::star::uno::Reference< + com::sun::star::chart2::XRegressionCurveContainer >& xCurveContainer ); static void removeEquations( - ::com::sun::star::uno::Reference< - ::com::sun::star::chart2::XRegressionCurveContainer > & xRegCnt ); - - /** adds the given regression curve if there was none before. If there are - regression curves, the first one is replaced by the one given by the - type. All remaining curves are remnoved. - - <p>This function ignores mean-value lines.</p> - */ - static void changeRegressionCurveType( - tRegressionType eType, - com::sun::star::uno::Reference< - com::sun::star::chart2::XRegressionCurveContainer > & xRegressionCurveContainer, com::sun::star::uno::Reference< - com::sun::star::chart2::XRegressionCurve > & xRegressionCurve, - const com::sun::star::uno::Reference< - com::sun::star::uno::XComponentContext > & xContext ); + com::sun::star::chart2::XRegressionCurveContainer >& xCurveContainer ); + + static com::sun::star::uno::Reference< com::sun::star::chart2::XRegressionCurve > + changeRegressionCurveType( + tRegressionType eType, + com::sun::star::uno::Reference< + com::sun::star::chart2::XRegressionCurveContainer > & xRegressionCurveContainer, + com::sun::star::uno::Reference< + com::sun::star::chart2::XRegressionCurve > & xRegressionCurve, + const com::sun::star::uno::Reference< + com::sun::star::uno::XComponentContext > & xContext ); // ------------------------------------------------------------ /// returns a calculator object for regression curves (used by the view) - static ::com::sun::star::uno::Reference< - ::com::sun::star::chart2::XRegressionCurveCalculator > - createRegressionCurveCalculatorByServiceName( - OUString aServiceName ); + static com::sun::star::uno::Reference< com::sun::star::chart2::XRegressionCurveCalculator > + createRegressionCurveCalculatorByServiceName( OUString aServiceName ); /** recalculates the regression parameters according to the data given in the data source. diff --git a/chart2/source/tools/RegressionCurveHelper.cxx b/chart2/source/tools/RegressionCurveHelper.cxx index 976d12506837..551541befa44 100644 --- a/chart2/source/tools/RegressionCurveHelper.cxx +++ b/chart2/source/tools/RegressionCurveHelper.cxx @@ -355,23 +355,24 @@ void RegressionCurveHelper::removeMeanValueLine( } } -void RegressionCurveHelper::addRegressionCurve( +uno::Reference< chart2::XRegressionCurve > RegressionCurveHelper::addRegressionCurve( tRegressionType eType, - uno::Reference< XRegressionCurveContainer > & xRegCnt, - const uno::Reference< XComponentContext > & /* xContext */, + uno::Reference< XRegressionCurveContainer >& xRegressionCurveContainer, + const uno::Reference< XComponentContext >& /* xContext */, const uno::Reference< beans::XPropertySet >& xPropertySource, const uno::Reference< beans::XPropertySet >& xEquationProperties ) { - if( !xRegCnt.is() ) - return; + uno::Reference< chart2::XRegressionCurve > xCurve; + + if( !xRegressionCurveContainer.is() ) + return xCurve; if( eType == REGRESSION_TYPE_NONE ) { OSL_FAIL("don't create a regression curve of type none"); - return; + return xCurve; } - uno::Reference< chart2::XRegressionCurve > xCurve; OUString aServiceName( lcl_getServiceNameForType( eType )); if( !aServiceName.isEmpty()) { @@ -389,17 +390,18 @@ void RegressionCurveHelper::addRegressionCurve( comphelper::copyProperties( xPropertySource, xProperties ); else { - uno::Reference< XPropertySet > xSeriesProp( xRegCnt, uno::UNO_QUERY ); + uno::Reference< XPropertySet > xSeriesProp( xRegressionCurveContainer, uno::UNO_QUERY ); if( xSeriesProp.is()) { xProperties->setPropertyValue( "LineColor", xSeriesProp->getPropertyValue( "Color")); } -// xProp->setPropertyValue( "LineWidth", uno::makeAny( sal_Int32( 100 ))); } } } - xRegCnt->addRegressionCurve( xCurve ); + xRegressionCurveContainer->addRegressionCurve( xCurve ); + + return xCurve; } /** removes all regression curves that are not of type mean value @@ -472,14 +474,14 @@ void RegressionCurveHelper::removeEquations( } } -void RegressionCurveHelper::changeRegressionCurveType( +uno::Reference< XRegressionCurve > RegressionCurveHelper::changeRegressionCurveType( tRegressionType eType, uno::Reference< XRegressionCurveContainer > & xRegressionCurveContainer, uno::Reference< XRegressionCurve > & xRegressionCurve, const uno::Reference< XComponentContext > & xContext ) { xRegressionCurveContainer->removeRegressionCurve( xRegressionCurve ); - RegressionCurveHelper::addRegressionCurve( + return RegressionCurveHelper::addRegressionCurve( eType, xRegressionCurveContainer, xContext, @@ -672,13 +674,14 @@ void RegressionCurveHelper::resetEquationPosition( } sal_Int32 RegressionCurveHelper::getRegressionCurveIndex( - const Reference< chart2::XRegressionCurveContainer > & xContainer, - const Reference< chart2::XRegressionCurve > & xCurve ) + const Reference< chart2::XRegressionCurveContainer >& xContainer, + const Reference< chart2::XRegressionCurve >& xCurve ) { if( xContainer.is()) { uno::Sequence< uno::Reference< XRegressionCurve > > aCurves( xContainer->getRegressionCurves()); + for( sal_Int32 i = 0; i < aCurves.getLength(); ++i ) { if( xCurve == aCurves[i] ) |