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

Generated by: LCOV version 1.10