LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/chart2/source/controller/main - ChartController_Insert.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 403 0.2 %
Date: 2013-07-09 Functions: 2 38 5.3 %
Legend: Lines: hit not hit

          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             : 
      20             : #include "ChartController.hxx"
      21             : 
      22             : #include "dlg_InsertAxis_Grid.hxx"
      23             : #include "dlg_InsertDataLabel.hxx"
      24             : #include "dlg_InsertLegend.hxx"
      25             : #include "dlg_InsertErrorBars.hxx"
      26             : #include "dlg_InsertTitle.hxx"
      27             : #include "dlg_ObjectProperties.hxx"
      28             : 
      29             : #include "ChartWindow.hxx"
      30             : #include "ChartModelHelper.hxx"
      31             : #include "AxisHelper.hxx"
      32             : #include "TitleHelper.hxx"
      33             : #include "DiagramHelper.hxx"
      34             : #include "macros.hxx"
      35             : #include "chartview/DrawModelWrapper.hxx"
      36             : #include "NumberFormatterWrapper.hxx"
      37             : #include "ViewElementListProvider.hxx"
      38             : #include "MultipleChartConverters.hxx"
      39             : #include "ControllerLockGuard.hxx"
      40             : #include "UndoGuard.hxx"
      41             : #include "ResId.hxx"
      42             : #include "Strings.hrc"
      43             : #include "ReferenceSizeProvider.hxx"
      44             : #include "ObjectIdentifier.hxx"
      45             : #include "RegressionCurveHelper.hxx"
      46             : #include "RegressionCurveItemConverter.hxx"
      47             : #include "StatisticsHelper.hxx"
      48             : #include "ErrorBarItemConverter.hxx"
      49             : #include "MultipleItemConverter.hxx"
      50             : #include "DataSeriesHelper.hxx"
      51             : #include "ObjectNameProvider.hxx"
      52             : #include "LegendHelper.hxx"
      53             : 
      54             : #include <com/sun/star/chart2/XRegressionCurve.hpp>
      55             : #include <com/sun/star/chart/ErrorBarStyle.hpp>
      56             : #include <svx/ActionDescriptionProvider.hxx>
      57             : 
      58             : //--------------------------------------
      59             : 
      60             : // header for define RET_OK
      61             : #include <vcl/msgbox.hxx>
      62             : // header for class OUStringBuffer
      63             : #include <rtl/ustrbuf.hxx>
      64             : // header for class Application
      65             : #include <vcl/svapp.hxx>
      66             : // header for class ::vos::OGuard
      67             : #include <osl/mutex.hxx>
      68             : 
      69             : 
      70             : using namespace ::com::sun::star;
      71             : using namespace ::com::sun::star::chart2;
      72             : using ::com::sun::star::uno::Reference;
      73             : using ::com::sun::star::uno::Sequence;
      74             : 
      75             : //.............................................................................
      76             : 
      77             : namespace
      78             : {
      79           0 : struct lcl_InsertMeanValueLine
      80             : {
      81             : public:
      82           0 :     lcl_InsertMeanValueLine( const uno::Reference< uno::XComponentContext > & xContext ) :
      83           0 :             m_xContext( xContext )
      84           0 :     {}
      85             : 
      86           0 :     void operator()( const uno::Reference< chart2::XDataSeries > & xSeries )
      87             :     {
      88             :         uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
      89           0 :             xSeries, uno::UNO_QUERY );
      90           0 :         if( xRegCurveCnt.is())
      91             :         {
      92             :             ::chart::RegressionCurveHelper::addMeanValueLine(
      93           0 :                 xRegCurveCnt, m_xContext, uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ));
      94           0 :         }
      95           0 :     }
      96             : 
      97             : private:
      98             :     uno::Reference< uno::XComponentContext > m_xContext;
      99             : };
     100             : 
     101             : } // anonymous namespace
     102             : 
     103             : //.............................................................................
     104             : namespace chart
     105             : {
     106             : //.............................................................................
     107             : 
     108           0 : void ChartController::executeDispatch_InsertAxes()
     109             : {
     110             :     UndoGuard aUndoGuard(
     111             :         ActionDescriptionProvider::createDescription(
     112             :             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AXES ))),
     113           0 :         m_xUndoManager );
     114             : 
     115             :     try
     116             :     {
     117           0 :         InsertAxisOrGridDialogData aDialogInput;
     118           0 :         uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel());
     119           0 :         AxisHelper::getAxisOrGridExcistence( aDialogInput.aExistenceList, xDiagram, sal_True );
     120           0 :         AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram, sal_True );
     121             : 
     122           0 :         SolarMutexGuard aGuard;
     123           0 :         SchAxisDlg aDlg( m_pChartWindow, aDialogInput );
     124           0 :         if( aDlg.Execute() == RET_OK )
     125             :         {
     126             :             // lock controllers till end of block
     127           0 :             ControllerLockGuard aCLGuard( getModel() );
     128             : 
     129           0 :             InsertAxisOrGridDialogData aDialogOutput;
     130           0 :             aDlg.getResult( aDialogOutput );
     131             :             ::std::auto_ptr< ReferenceSizeProvider > mpRefSizeProvider(
     132           0 :                 impl_createReferenceSizeProvider());
     133             :             bool bChanged = AxisHelper::changeVisibilityOfAxes( xDiagram
     134             :                 , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, m_xCC
     135           0 :                 , mpRefSizeProvider.get() );
     136           0 :             if( bChanged )
     137           0 :                 aUndoGuard.commit();
     138           0 :         }
     139             :     }
     140           0 :     catch(const uno::RuntimeException& e)
     141             :     {
     142             :         ASSERT_EXCEPTION( e );
     143           0 :     }
     144           0 : }
     145             : 
     146           0 : void ChartController::executeDispatch_InsertGrid()
     147             : {
     148             :     UndoGuard aUndoGuard(
     149             :         ActionDescriptionProvider::createDescription(
     150             :             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRIDS ))),
     151           0 :         m_xUndoManager );
     152             : 
     153             :     try
     154             :     {
     155           0 :         InsertAxisOrGridDialogData aDialogInput;
     156           0 :         uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel());
     157           0 :         AxisHelper::getAxisOrGridExcistence( aDialogInput.aExistenceList, xDiagram, sal_False );
     158           0 :         AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram, sal_False );
     159             : 
     160           0 :         SolarMutexGuard aGuard;
     161           0 :         SchGridDlg aDlg( m_pChartWindow, aDialogInput );//aItemSet, b3D, bNet, bSecondaryX, bSecondaryY );
     162           0 :         if( aDlg.Execute() == RET_OK )
     163             :         {
     164             :             // lock controllers till end of block
     165           0 :             ControllerLockGuard aCLGuard( getModel() );
     166           0 :             InsertAxisOrGridDialogData aDialogOutput;
     167           0 :             aDlg.getResult( aDialogOutput );
     168             :             bool bChanged = AxisHelper::changeVisibilityOfGrids( xDiagram
     169           0 :                 , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, m_xCC );
     170           0 :             if( bChanged )
     171           0 :                 aUndoGuard.commit();
     172           0 :         }
     173             :     }
     174           0 :     catch(const uno::RuntimeException& e)
     175             :     {
     176             :         ASSERT_EXCEPTION( e );
     177           0 :     }
     178           0 : }
     179             : 
     180             : //-----------------------------------------------------------------------------
     181             : //-----------------------------------------------------------------------------
     182             : 
     183           0 : void ChartController::executeDispatch_InsertTitles()
     184             : {
     185             :     UndoGuard aUndoGuard(
     186             :         ActionDescriptionProvider::createDescription(
     187             :             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_TITLES ))),
     188           0 :         m_xUndoManager );
     189             : 
     190             :     try
     191             :     {
     192           0 :         TitleDialogData aDialogInput;
     193           0 :         aDialogInput.readFromModel( getModel() );
     194             : 
     195           0 :         SolarMutexGuard aGuard;
     196           0 :         SchTitleDlg aDlg( m_pChartWindow, aDialogInput );
     197           0 :         if( aDlg.Execute() == RET_OK )
     198             :         {
     199             :             // lock controllers till end of block
     200           0 :             ControllerLockGuard aCLGuard( getModel() );
     201           0 :             TitleDialogData aDialogOutput( impl_createReferenceSizeProvider());
     202           0 :             aDlg.getResult( aDialogOutput );
     203           0 :             bool bChanged = aDialogOutput.writeDifferenceToModel( getModel(), m_xCC, &aDialogInput );
     204           0 :             if( bChanged )
     205           0 :                 aUndoGuard.commit();
     206           0 :         }
     207             :     }
     208           0 :     catch(const uno::RuntimeException& e)
     209             :     {
     210             :         ASSERT_EXCEPTION( e );
     211           0 :     }
     212           0 : }
     213             : 
     214           0 : void ChartController::executeDispatch_DeleteLegend()
     215             : {
     216             :     UndoGuard aUndoGuard(
     217             :         ActionDescriptionProvider::createDescription(
     218             :             ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_LEGEND ))),
     219           0 :         m_xUndoManager );
     220             : 
     221           0 :     LegendHelper::hideLegend( getModel() );
     222           0 :     aUndoGuard.commit();
     223           0 : }
     224             : 
     225           0 : void ChartController::executeDispatch_InsertLegend()
     226             : {
     227             :     UndoGuard aUndoGuard(
     228             :         ActionDescriptionProvider::createDescription(
     229             :             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_LEGEND ))),
     230           0 :         m_xUndoManager );
     231             : 
     232           0 :     Reference< chart2::XLegend > xLegend = LegendHelper::showLegend( getModel(), m_xCC );
     233           0 :     aUndoGuard.commit();
     234           0 : }
     235             : 
     236           0 : void ChartController::executeDispatch_OpenLegendDialog()
     237             : {
     238             :     UndoGuard aUndoGuard(
     239             :         ActionDescriptionProvider::createDescription(
     240             :             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_LEGEND ))),
     241           0 :         m_xUndoManager );
     242             : 
     243             :     try
     244             :     {
     245             :         //prepare and open dialog
     246           0 :         SolarMutexGuard aGuard;
     247           0 :         SchLegendDlg aDlg( m_pChartWindow, m_xCC );
     248           0 :         aDlg.init( getModel() );
     249           0 :         if( aDlg.Execute() == RET_OK )
     250             :         {
     251             :             // lock controllers till end of block
     252           0 :             ControllerLockGuard aCLGuard( getModel() );
     253           0 :             bool bChanged = aDlg.writeToModel( getModel() );
     254           0 :             if( bChanged )
     255           0 :                 aUndoGuard.commit();
     256           0 :         }
     257             :     }
     258           0 :     catch(const uno::RuntimeException& e)
     259             :     {
     260             :         ASSERT_EXCEPTION( e );
     261           0 :     }
     262           0 : }
     263             : 
     264             : //-----------------------------------------------------------------------------
     265             : //-----------------------------------------------------------------------------
     266             : 
     267           0 : void ChartController::executeDispatch_InsertMenu_DataLabels()
     268             : {
     269             :     UndoGuard aUndoGuard(
     270             :         ActionDescriptionProvider::createDescription(
     271             :             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_DATALABELS ))),
     272           0 :         m_xUndoManager );
     273             : 
     274             :     //if a series is selected insert labels for that series only:
     275             :     uno::Reference< chart2::XDataSeries > xSeries(
     276           0 :         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()), uno::UNO_QUERY );
     277           0 :     if( xSeries.is() )
     278             :     {
     279             :         // add labels
     280           0 :         DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries );
     281             : 
     282           0 :         OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) + "=" );
     283             :         OUString aObjectCID = ObjectIdentifier::createClassifiedIdentifierForParticles(
     284           0 :             ObjectIdentifier::getSeriesParticleFromCID(m_aSelection.getSelectedCID()), aChildParticle );
     285             : 
     286           0 :         bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, true );
     287           0 :         if( bSuccess )
     288           0 :             aUndoGuard.commit();
     289           0 :         return;
     290             :     }
     291             : 
     292             :     try
     293             :     {
     294             :         wrapper::AllDataLabelItemConverter aItemConverter(
     295           0 :             getModel(),
     296           0 :             m_pDrawModelWrapper->GetItemPool(),
     297           0 :             m_pDrawModelWrapper->getSdrModel(),
     298           0 :             uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
     299           0 :         SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
     300           0 :         aItemConverter.FillItemSet( aItemSet );
     301             : 
     302             :         //prepare and open dialog
     303           0 :         SolarMutexGuard aGuard;
     304             : 
     305             :         //get number formatter
     306           0 :         uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( getModel(), uno::UNO_QUERY );
     307           0 :         NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
     308           0 :         SvNumberFormatter* pNumberFormatter = aNumberFormatterWrapper.getSvNumberFormatter();
     309             : 
     310           0 :         DataLabelsDialog aDlg( m_pChartWindow, aItemSet, pNumberFormatter);
     311             : 
     312           0 :         if( aDlg.Execute() == RET_OK )
     313             :         {
     314           0 :             SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
     315           0 :             aDlg.FillItemSet( aOutItemSet );
     316             :             // lock controllers till end of block
     317           0 :             ControllerLockGuard aCLGuard( getModel() );
     318           0 :             bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
     319           0 :             if( bChanged )
     320           0 :                 aUndoGuard.commit();
     321           0 :         }
     322             :     }
     323           0 :     catch(const uno::RuntimeException& e)
     324             :     {
     325             :         ASSERT_EXCEPTION( e );
     326           0 :     }
     327             : }
     328             : 
     329           0 : void ChartController::executeDispatch_InsertMeanValue()
     330             : {
     331             :     UndoGuard aUndoGuard(
     332             :         ActionDescriptionProvider::createDescription(
     333             :             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AVERAGE_LINE ))),
     334           0 :         m_xUndoManager );
     335             :     lcl_InsertMeanValueLine( m_xCC ).operator()(
     336           0 :         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ));
     337           0 :     aUndoGuard.commit();
     338           0 : }
     339             : 
     340           0 : void ChartController::executeDispatch_InsertMenu_MeanValues()
     341             : {
     342             :     UndoGuard aUndoGuard(
     343             :         ActionDescriptionProvider::createDescription(
     344             :             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AVERAGE_LINE ))),
     345           0 :         m_xUndoManager );
     346             : 
     347             :     uno::Reference< chart2::XDataSeries > xSeries(
     348           0 :         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
     349           0 :     if( xSeries.is() )
     350             :     {
     351             :         //if a series is selected insert mean value only for that series:
     352           0 :         lcl_InsertMeanValueLine( m_xCC ).operator()(xSeries);
     353             :     }
     354             :     else
     355             :     {
     356             :         ::std::vector< uno::Reference< chart2::XDataSeries > > aSeries(
     357           0 :             DiagramHelper::getDataSeriesFromDiagram( ChartModelHelper::findDiagram( getModel() )));
     358           0 :         ::std::for_each( aSeries.begin(), aSeries.end(), lcl_InsertMeanValueLine( m_xCC ));
     359             :     }
     360           0 :     aUndoGuard.commit();
     361           0 : }
     362             : 
     363           0 : void ChartController::executeDispatch_InsertMenu_Trendlines()
     364             : {
     365           0 :     OUString aCID = m_aSelection.getSelectedCID();
     366             : 
     367             :     uno::Reference< chart2::XDataSeries > xSeries(
     368           0 :         ObjectIdentifier::getDataSeriesForCID( aCID, getModel() ), uno::UNO_QUERY );
     369             : 
     370           0 :     if( !xSeries.is() )
     371           0 :         return;
     372             : 
     373           0 :     executeDispatch_InsertTrendline();
     374             : }
     375             : 
     376           0 : void ChartController::executeDispatch_InsertTrendline()
     377             : {
     378             :     uno::Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer(
     379           0 :         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()), uno::UNO_QUERY );
     380             : 
     381           0 :     if( !xRegressionCurveContainer.is() )
     382           0 :         return;
     383             : 
     384             :     UndoLiveUpdateGuard aUndoGuard(
     385             :         ActionDescriptionProvider::createDescription(
     386             :             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE ))),
     387           0 :         m_xUndoManager );
     388             : 
     389             :     uno::Reference< chart2::XRegressionCurve > xCurve =
     390             :         RegressionCurveHelper::addRegressionCurve(
     391             :             RegressionCurveHelper::REGRESSION_TYPE_LINEAR,
     392             :             xRegressionCurveContainer,
     393           0 :             m_xCC );
     394             : 
     395           0 :     uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
     396             : 
     397           0 :     if( !xProperties.is())
     398           0 :         return;
     399             : 
     400             :     wrapper::RegressionCurveItemConverter aItemConverter(
     401           0 :         xProperties, xRegressionCurveContainer, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
     402           0 :         m_pDrawModelWrapper->getSdrModel(),
     403           0 :         uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
     404             : 
     405             :     // open dialog
     406           0 :     SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
     407           0 :     aItemConverter.FillItemSet( aItemSet );
     408             :     ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter(
     409             :         ObjectIdentifier::createDataCurveCID(
     410             :             ObjectIdentifier::getSeriesParticleFromCID( m_aSelection.getSelectedCID()),
     411           0 :             RegressionCurveHelper::getRegressionCurveIndex( xRegressionCurveContainer, xCurve ), false ));
     412           0 :     aDialogParameter.init( getModel() );
     413           0 :     ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
     414           0 :     SolarMutexGuard aGuard;
     415             :     SchAttribTabDlg aDialog( m_pChartWindow, &aItemSet, &aDialogParameter, &aViewElementListProvider,
     416           0 :                           uno::Reference< util::XNumberFormatsSupplier >( getModel(), uno::UNO_QUERY ));
     417             : 
     418             :     // note: when a user pressed "OK" but didn't change any settings in the
     419             :     // dialog, the SfxTabDialog returns "Cancel"
     420           0 :     if( aDialog.Execute() == RET_OK || aDialog.DialogWasClosedWithOK())
     421             :     {
     422           0 :         const SfxItemSet* pOutItemSet = aDialog.GetOutputItemSet();
     423           0 :         if( pOutItemSet )
     424             :         {
     425           0 :             ControllerLockGuard aCLGuard( getModel() );
     426           0 :             aItemConverter.ApplyItemSet( *pOutItemSet );
     427             :         }
     428           0 :         aUndoGuard.commit();
     429           0 :     }
     430             : }
     431             : 
     432           0 : void ChartController::executeDispatch_InsertErrorBars( bool bYError )
     433             : {
     434           0 :     ObjectType objType = bYError ? OBJECTTYPE_DATA_ERRORS_Y : OBJECTTYPE_DATA_ERRORS_X;
     435             : 
     436             :     //if a series is selected insert error bars for that series only:
     437             :     uno::Reference< chart2::XDataSeries > xSeries(
     438           0 :         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
     439             : 
     440           0 :     if( xSeries.is())
     441             :     {
     442             :         UndoLiveUpdateGuard aUndoGuard(
     443             :             ActionDescriptionProvider::createDescription(
     444             :                 ActionDescriptionProvider::INSERT,
     445             :                 String( SchResId( bYError ? STR_OBJECT_ERROR_BARS_Y : STR_OBJECT_ERROR_BARS_X ))),
     446           0 :             m_xUndoManager );
     447             : 
     448             :         // add error bars with standard deviation
     449             :         uno::Reference< beans::XPropertySet > xErrorBarProp(
     450             :             StatisticsHelper::addErrorBars( xSeries, m_xCC,
     451             :                                             ::com::sun::star::chart::ErrorBarStyle::STANDARD_DEVIATION,
     452           0 :                                             bYError));
     453             : 
     454             :         // get an appropriate item converter
     455             :         wrapper::ErrorBarItemConverter aItemConverter(
     456           0 :             getModel(), xErrorBarProp, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
     457           0 :             m_pDrawModelWrapper->getSdrModel(),
     458           0 :             uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
     459             : 
     460             :         // open dialog
     461           0 :         SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
     462           0 :         aItemSet.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE,bYError));
     463           0 :         aItemConverter.FillItemSet( aItemSet );
     464             :         ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter(
     465             :             ObjectIdentifier::createClassifiedIdentifierWithParent(
     466           0 :                 objType, OUString(), m_aSelection.getSelectedCID()));
     467           0 :         aDialogParameter.init( getModel() );
     468           0 :         ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
     469           0 :         SolarMutexGuard aGuard;
     470             :         SchAttribTabDlg aDlg( m_pChartWindow, &aItemSet, &aDialogParameter, &aViewElementListProvider,
     471           0 :                               uno::Reference< util::XNumberFormatsSupplier >( getModel(), uno::UNO_QUERY ));
     472             :         aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
     473           0 :             InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(),
     474           0 :                                                                              m_xChartView, m_aSelection.getSelectedCID()));
     475             : 
     476             :         // note: when a user pressed "OK" but didn't change any settings in the
     477             :         // dialog, the SfxTabDialog returns "Cancel"
     478           0 :         if( aDlg.Execute() == RET_OK || aDlg.DialogWasClosedWithOK())
     479             :         {
     480           0 :             const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
     481           0 :             if( pOutItemSet )
     482             :             {
     483           0 :                 ControllerLockGuard aCLGuard( getModel() );
     484           0 :                 aItemConverter.ApplyItemSet( *pOutItemSet );
     485             :             }
     486           0 :             aUndoGuard.commit();
     487           0 :         }
     488             :     }
     489             :     else
     490             :     {
     491             :         //if no series is selected insert error bars for all series
     492             :         UndoGuard aUndoGuard(
     493             :             ActionDescriptionProvider::createDescription(
     494             :                 ActionDescriptionProvider::INSERT,
     495             :                 ObjectNameProvider::getName_ObjectForAllSeries( objType ) ),
     496           0 :             m_xUndoManager );
     497             : 
     498             :         try
     499             :         {
     500             :             wrapper::AllSeriesStatisticsConverter aItemConverter(
     501           0 :                 getModel(), m_pDrawModelWrapper->GetItemPool() );
     502           0 :             SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
     503           0 :             aItemConverter.FillItemSet( aItemSet );
     504             : 
     505             :             //prepare and open dialog
     506           0 :             SolarMutexGuard aGuard;
     507             :             InsertErrorBarsDialog aDlg(
     508             :                 m_pChartWindow, aItemSet,
     509           0 :                 uno::Reference< chart2::XChartDocument >( getModel(), uno::UNO_QUERY ),
     510           0 :                 bYError ? ErrorBarResources::ERROR_BAR_Y : ErrorBarResources::ERROR_BAR_X);
     511             : 
     512             :             aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
     513           0 :                 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, OUString() ) );
     514             : 
     515           0 :             if( aDlg.Execute() == RET_OK )
     516             :             {
     517           0 :                 SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
     518           0 :                 aDlg.FillItemSet( aOutItemSet );
     519             : 
     520             :                 // lock controllers till end of block
     521           0 :                 ControllerLockGuard aCLGuard( getModel() );
     522           0 :                 bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
     523           0 :                 if( bChanged )
     524           0 :                     aUndoGuard.commit();
     525           0 :             }
     526             :         }
     527           0 :         catch(const uno::RuntimeException& e)
     528             :         {
     529             :             ASSERT_EXCEPTION( e );
     530           0 :         }
     531           0 :     }
     532           0 : }
     533             : 
     534           0 : void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 )
     535             : {
     536             :     uno::Reference< chart2::XRegressionCurve > xRegCurve(
     537           0 :         ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
     538           0 :     if( !xRegCurve.is() )
     539             :     {
     540             :         uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
     541           0 :             ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
     542           0 :         xRegCurve.set( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) );
     543             :     }
     544           0 :     if( xRegCurve.is())
     545             :     {
     546           0 :         uno::Reference< beans::XPropertySet > xEqProp( xRegCurve->getEquationProperties());
     547           0 :         if( xEqProp.is())
     548             :         {
     549             :             // using assignment for broken gcc 3.3
     550             :             UndoGuard aUndoGuard = UndoGuard(
     551             :                 ActionDescriptionProvider::createDescription(
     552             :                     ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
     553           0 :                 m_xUndoManager );
     554           0 :             xEqProp->setPropertyValue( "ShowEquation", uno::makeAny( true ));
     555           0 :             xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( bInsertR2 ));
     556           0 :             aUndoGuard.commit();
     557           0 :         }
     558           0 :     }
     559           0 : }
     560             : 
     561           0 : void ChartController::executeDispatch_InsertR2Value()
     562             : {
     563             :     uno::Reference< beans::XPropertySet > xEqProp(
     564           0 :         ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
     565           0 :     if( xEqProp.is())
     566             :     {
     567             :         UndoGuard aUndoGuard = UndoGuard(
     568             :             ActionDescriptionProvider::createDescription(
     569             :                 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
     570           0 :             m_xUndoManager );
     571           0 :         xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( true ));
     572           0 :         aUndoGuard.commit();
     573           0 :     }
     574           0 : }
     575             : 
     576           0 : void ChartController::executeDispatch_DeleteR2Value()
     577             : {
     578             :     uno::Reference< beans::XPropertySet > xEqProp(
     579           0 :         ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
     580           0 :     if( xEqProp.is())
     581             :     {
     582             :         UndoGuard aUndoGuard = UndoGuard(
     583             :             ActionDescriptionProvider::createDescription(
     584             :                 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
     585           0 :             m_xUndoManager );
     586           0 :         xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::makeAny( false ));
     587           0 :         aUndoGuard.commit();
     588           0 :     }
     589           0 : }
     590             : 
     591           0 : void ChartController::executeDispatch_DeleteMeanValue()
     592             : {
     593             :     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
     594           0 :         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
     595           0 :     if( xRegCurveCnt.is())
     596             :     {
     597             :         UndoGuard aUndoGuard(
     598             :             ActionDescriptionProvider::createDescription(
     599             :                 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_AVERAGE_LINE ))),
     600           0 :             m_xUndoManager );
     601           0 :         RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt );
     602           0 :         aUndoGuard.commit();
     603           0 :     }
     604           0 : }
     605             : 
     606           0 : void ChartController::executeDispatch_DeleteTrendline()
     607             : {
     608             :     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
     609           0 :         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
     610           0 :     if( xRegCurveCnt.is())
     611             :     {
     612             :         UndoGuard aUndoGuard(
     613             :             ActionDescriptionProvider::createDescription(
     614             :                 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE ))),
     615           0 :             m_xUndoManager );
     616           0 :         RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt );
     617           0 :         aUndoGuard.commit();
     618           0 :     }
     619           0 : }
     620             : 
     621           0 : void ChartController::executeDispatch_DeleteTrendlineEquation()
     622             : {
     623             :     uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
     624           0 :         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
     625           0 :     if( xRegCurveCnt.is())
     626             :     {
     627             :         UndoGuard aUndoGuard(
     628             :             ActionDescriptionProvider::createDescription(
     629             :                 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
     630           0 :             m_xUndoManager );
     631           0 :         RegressionCurveHelper::removeEquations( xRegCurveCnt );
     632           0 :         aUndoGuard.commit();
     633           0 :     }
     634           0 : }
     635             : 
     636           0 : void ChartController::executeDispatch_DeleteErrorBars( bool bYError )
     637             : {
     638             :     uno::Reference< chart2::XDataSeries > xDataSeries(
     639           0 :         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ));
     640           0 :     if( xDataSeries.is())
     641             :     {
     642             :         UndoGuard aUndoGuard(
     643             :             ActionDescriptionProvider::createDescription(
     644             :                 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE ))),
     645           0 :             m_xUndoManager );
     646           0 :         StatisticsHelper::removeErrorBars( xDataSeries, bYError );
     647           0 :         aUndoGuard.commit();
     648           0 :     }
     649           0 : }
     650             : 
     651           0 : void ChartController::executeDispatch_InsertDataLabels()
     652             : {
     653             :     uno::Reference< chart2::XDataSeries > xSeries(
     654           0 :         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
     655           0 :     if( xSeries.is() )
     656             :     {
     657             :         UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::INSERT,
     658             :             String( SchResId( STR_OBJECT_DATALABELS ))),
     659           0 :             m_xUndoManager );
     660           0 :         DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries );
     661           0 :         aUndoGuard.commit();
     662           0 :     }
     663           0 : }
     664             : 
     665           0 : void ChartController::executeDispatch_InsertDataLabel()
     666             : {
     667             :     UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::INSERT,
     668             :         String( SchResId( STR_OBJECT_LABEL ))),
     669           0 :         m_xUndoManager );
     670           0 :     DataSeriesHelper::insertDataLabelToPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) );
     671           0 :     aUndoGuard.commit();
     672           0 : }
     673             : 
     674           0 : void ChartController::executeDispatch_DeleteDataLabels()
     675             : {
     676             :     uno::Reference< chart2::XDataSeries > xSeries(
     677           0 :         ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
     678           0 :     if( xSeries.is() )
     679             :     {
     680             :         UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::DELETE,
     681             :             String( SchResId( STR_OBJECT_DATALABELS ))),
     682           0 :             m_xUndoManager );
     683           0 :         DataSeriesHelper::deleteDataLabelsFromSeriesAndAllPoints( xSeries );
     684           0 :         aUndoGuard.commit();
     685           0 :     }
     686           0 : }
     687             : 
     688           0 : void ChartController::executeDispatch_DeleteDataLabel()
     689             : {
     690             :     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::DELETE,
     691             :         String( SchResId( STR_OBJECT_LABEL ))),
     692           0 :         m_xUndoManager );
     693           0 :     DataSeriesHelper::deleteDataLabelsFromPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) );
     694           0 :     aUndoGuard.commit();
     695           0 : }
     696             : 
     697           0 : void ChartController::executeDispatch_ResetAllDataPoints()
     698             : {
     699             :     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::FORMAT,
     700             :         String( SchResId( STR_OBJECT_DATAPOINTS ))),
     701           0 :         m_xUndoManager );
     702           0 :     uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
     703           0 :     if( xSeries.is() )
     704           0 :         xSeries->resetAllDataPoints();
     705           0 :     aUndoGuard.commit();
     706           0 : }
     707           0 : void ChartController::executeDispatch_ResetDataPoint()
     708             : {
     709             :     UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::FORMAT,
     710             :         String( SchResId( STR_OBJECT_DATAPOINT ))),
     711           0 :         m_xUndoManager );
     712           0 :     uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
     713           0 :     if( xSeries.is() )
     714             :     {
     715           0 :         sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( m_aSelection.getSelectedCID() );
     716           0 :         xSeries->resetDataPoint( nPointIndex );
     717             :     }
     718           0 :     aUndoGuard.commit();
     719           0 : }
     720             : 
     721           0 : void ChartController::executeDispatch_InsertAxisTitle()
     722             : {
     723             :     try
     724             :     {
     725           0 :         uno::Reference< XTitle > xTitle;
     726             :         {
     727             :             UndoGuard aUndoGuard(
     728             :             ActionDescriptionProvider::createDescription(
     729             :                 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_TITLE ))),
     730           0 :             m_xUndoManager );
     731             : 
     732           0 :             Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
     733           0 :             sal_Int32 nDimensionIndex = -1;
     734           0 :             sal_Int32 nCooSysIndex = -1;
     735           0 :             sal_Int32 nAxisIndex = -1;
     736           0 :             AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram(getModel()), nCooSysIndex, nDimensionIndex, nAxisIndex );
     737             : 
     738           0 :             TitleHelper::eTitleType eTitleType = TitleHelper::X_AXIS_TITLE;
     739           0 :             if( nDimensionIndex==0 )
     740           0 :                 eTitleType = nAxisIndex==0 ? TitleHelper::X_AXIS_TITLE : TitleHelper::SECONDARY_X_AXIS_TITLE;
     741           0 :             else if( nDimensionIndex==1 )
     742           0 :                 eTitleType = nAxisIndex==0 ? TitleHelper::Y_AXIS_TITLE : TitleHelper::SECONDARY_Y_AXIS_TITLE;
     743             :             else
     744           0 :                 eTitleType = TitleHelper::Z_AXIS_TITLE;
     745             : 
     746           0 :             ::std::auto_ptr< ReferenceSizeProvider > apRefSizeProvider( impl_createReferenceSizeProvider());
     747           0 :             xTitle = TitleHelper::createTitle( eTitleType, ObjectNameProvider::getTitleNameByType(eTitleType), getModel(), m_xCC, apRefSizeProvider.get() );
     748           0 :             aUndoGuard.commit();
     749           0 :         }
     750             :     }
     751           0 :     catch(const uno::RuntimeException& e)
     752             :     {
     753             :         ASSERT_EXCEPTION( e );
     754             :     }
     755           0 : }
     756             : 
     757           0 : void ChartController::executeDispatch_InsertAxis()
     758             : {
     759             :     UndoGuard aUndoGuard(
     760             :         ActionDescriptionProvider::createDescription(
     761             :             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AXIS ))),
     762           0 :         m_xUndoManager );
     763             : 
     764             :     try
     765             :     {
     766           0 :         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
     767           0 :         if( xAxis.is() )
     768             :         {
     769           0 :             AxisHelper::makeAxisVisible( xAxis );
     770           0 :             aUndoGuard.commit();
     771           0 :         }
     772             :     }
     773           0 :     catch(const uno::RuntimeException& e)
     774             :     {
     775             :         ASSERT_EXCEPTION( e );
     776           0 :     }
     777           0 : }
     778             : 
     779           0 : void ChartController::executeDispatch_DeleteAxis()
     780             : {
     781             :     UndoGuard aUndoGuard(
     782             :         ActionDescriptionProvider::createDescription(
     783             :             ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_AXIS ))),
     784           0 :         m_xUndoManager );
     785             : 
     786             :     try
     787             :     {
     788           0 :         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
     789           0 :         if( xAxis.is() )
     790             :         {
     791           0 :             AxisHelper::makeAxisInvisible( xAxis );
     792           0 :             aUndoGuard.commit();
     793           0 :         }
     794             :     }
     795           0 :     catch(const uno::RuntimeException& e)
     796             :     {
     797             :         ASSERT_EXCEPTION( e );
     798           0 :     }
     799           0 : }
     800             : 
     801           0 : void ChartController::executeDispatch_InsertMajorGrid()
     802             : {
     803             :     UndoGuard aUndoGuard(
     804             :         ActionDescriptionProvider::createDescription(
     805             :             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRID ))),
     806           0 :         m_xUndoManager );
     807             : 
     808             :     try
     809             :     {
     810           0 :         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
     811           0 :         if( xAxis.is() )
     812             :         {
     813           0 :             AxisHelper::makeGridVisible( xAxis->getGridProperties() );
     814           0 :             aUndoGuard.commit();
     815           0 :         }
     816             :     }
     817           0 :     catch(const uno::RuntimeException& e)
     818             :     {
     819             :         ASSERT_EXCEPTION( e );
     820           0 :     }
     821           0 : }
     822             : 
     823           0 : void ChartController::executeDispatch_DeleteMajorGrid()
     824             : {
     825             :     UndoGuard aUndoGuard(
     826             :         ActionDescriptionProvider::createDescription(
     827             :             ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_GRID ))),
     828           0 :         m_xUndoManager );
     829             : 
     830             :     try
     831             :     {
     832           0 :         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
     833           0 :         if( xAxis.is() )
     834             :         {
     835           0 :             AxisHelper::makeGridInvisible( xAxis->getGridProperties() );
     836           0 :             aUndoGuard.commit();
     837           0 :         }
     838             :     }
     839           0 :     catch(const uno::RuntimeException& e)
     840             :     {
     841             :         ASSERT_EXCEPTION( e );
     842           0 :     }
     843           0 : }
     844             : 
     845           0 : void ChartController::executeDispatch_InsertMinorGrid()
     846             : {
     847             :     UndoGuard aUndoGuard(
     848             :         ActionDescriptionProvider::createDescription(
     849             :             ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRID ))),
     850           0 :         m_xUndoManager );
     851             : 
     852             :     try
     853             :     {
     854           0 :         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
     855           0 :         if( xAxis.is() )
     856             :         {
     857           0 :             Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
     858           0 :             for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
     859           0 :                 AxisHelper::makeGridVisible( aSubGrids[nN] );
     860           0 :             aUndoGuard.commit();
     861           0 :         }
     862             :     }
     863           0 :     catch(const uno::RuntimeException& e)
     864             :     {
     865             :         ASSERT_EXCEPTION( e );
     866           0 :     }
     867           0 : }
     868             : 
     869           0 : void ChartController::executeDispatch_DeleteMinorGrid()
     870             : {
     871             :     UndoGuard aUndoGuard(
     872             :         ActionDescriptionProvider::createDescription(
     873             :             ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_GRID ))),
     874           0 :         m_xUndoManager );
     875             : 
     876             :     try
     877             :     {
     878           0 :         Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
     879           0 :         if( xAxis.is() )
     880             :         {
     881           0 :             Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
     882           0 :             for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
     883           0 :                 AxisHelper::makeGridInvisible( aSubGrids[nN] );
     884           0 :             aUndoGuard.commit();
     885           0 :         }
     886             :     }
     887           0 :     catch(const uno::RuntimeException& e)
     888             :     {
     889             :         ASSERT_EXCEPTION( e );
     890           0 :     }
     891           0 : }
     892             : 
     893             : //.............................................................................
     894          33 : } //namespace chart
     895             : //.............................................................................
     896             : 
     897             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10