Bump for 3.6-28
[LibreOffice.git] / chart2 / source / controller / main / ChartController_Insert.cxx
blob93a793fce81900e8313c3a9ae7480a7bf3e13cc4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "ChartController.hxx"
31 #include "dlg_InsertAxis_Grid.hxx"
32 #include "dlg_InsertDataLabel.hxx"
33 #include "dlg_InsertLegend.hxx"
34 #include "dlg_InsertTrendline.hxx"
35 #include "dlg_InsertErrorBars.hxx"
36 #include "dlg_InsertTitle.hxx"
37 #include "dlg_ObjectProperties.hxx"
39 #include "ChartWindow.hxx"
40 #include "ChartModelHelper.hxx"
41 #include "AxisHelper.hxx"
42 #include "TitleHelper.hxx"
43 #include "DiagramHelper.hxx"
44 #include "macros.hxx"
45 #include "chartview/DrawModelWrapper.hxx"
46 #include "NumberFormatterWrapper.hxx"
47 #include "ViewElementListProvider.hxx"
48 #include "MultipleChartConverters.hxx"
49 #include "ControllerLockGuard.hxx"
50 #include "UndoGuard.hxx"
51 #include "ResId.hxx"
52 #include "Strings.hrc"
53 #include "ReferenceSizeProvider.hxx"
54 #include "ObjectIdentifier.hxx"
55 #include "RegressionCurveHelper.hxx"
56 #include "RegressionCurveItemConverter.hxx"
57 #include "StatisticsHelper.hxx"
58 #include "ErrorBarItemConverter.hxx"
59 #include "MultipleItemConverter.hxx"
60 #include "DataSeriesHelper.hxx"
61 #include "ObjectNameProvider.hxx"
62 #include "LegendHelper.hxx"
64 #include <com/sun/star/chart2/XRegressionCurve.hpp>
65 #include <com/sun/star/chart/ErrorBarStyle.hpp>
66 #include <svx/ActionDescriptionProvider.hxx>
68 //--------------------------------------
70 // header for define RET_OK
71 #include <vcl/msgbox.hxx>
72 // header for class OUStringBuffer
73 #include <rtl/ustrbuf.hxx>
74 // header for class Application
75 #include <vcl/svapp.hxx>
76 // header for class ::vos::OGuard
77 #include <osl/mutex.hxx>
80 using namespace ::com::sun::star;
81 using namespace ::com::sun::star::chart2;
82 using ::com::sun::star::uno::Reference;
83 using ::com::sun::star::uno::Sequence;
84 using ::rtl::OUString;
86 //.............................................................................
88 namespace
90 struct lcl_InsertMeanValueLine
92 public:
93 lcl_InsertMeanValueLine( const uno::Reference< uno::XComponentContext > & xContext ) :
94 m_xContext( xContext )
97 void operator()( const uno::Reference< chart2::XDataSeries > & xSeries )
99 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
100 xSeries, uno::UNO_QUERY );
101 if( xRegCurveCnt.is())
103 ::chart::RegressionCurveHelper::addMeanValueLine(
104 xRegCurveCnt, m_xContext, uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ));
108 private:
109 uno::Reference< uno::XComponentContext > m_xContext;
112 } // anonymous namespace
114 //.............................................................................
115 namespace chart
117 //.............................................................................
119 void ChartController::executeDispatch_InsertAxes()
121 UndoGuard aUndoGuard(
122 ActionDescriptionProvider::createDescription(
123 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AXES ))),
124 m_xUndoManager );
128 InsertAxisOrGridDialogData aDialogInput;
129 uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel());
130 AxisHelper::getAxisOrGridExcistence( aDialogInput.aExistenceList, xDiagram, sal_True );
131 AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram, sal_True );
133 SolarMutexGuard aGuard;
134 SchAxisDlg aDlg( m_pChartWindow, aDialogInput );
135 if( aDlg.Execute() == RET_OK )
137 // lock controllers till end of block
138 ControllerLockGuard aCLGuard( getModel() );
140 InsertAxisOrGridDialogData aDialogOutput;
141 aDlg.getResult( aDialogOutput );
142 ::std::auto_ptr< ReferenceSizeProvider > mpRefSizeProvider(
143 impl_createReferenceSizeProvider());
144 bool bChanged = AxisHelper::changeVisibilityOfAxes( xDiagram
145 , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, m_xCC
146 , mpRefSizeProvider.get() );
147 if( bChanged )
148 aUndoGuard.commit();
151 catch(const uno::RuntimeException& e)
153 ASSERT_EXCEPTION( e );
157 void ChartController::executeDispatch_InsertGrid()
159 UndoGuard aUndoGuard(
160 ActionDescriptionProvider::createDescription(
161 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRIDS ))),
162 m_xUndoManager );
166 InsertAxisOrGridDialogData aDialogInput;
167 uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel());
168 AxisHelper::getAxisOrGridExcistence( aDialogInput.aExistenceList, xDiagram, sal_False );
169 AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram, sal_False );
171 SolarMutexGuard aGuard;
172 SchGridDlg aDlg( m_pChartWindow, aDialogInput );//aItemSet, b3D, bNet, bSecondaryX, bSecondaryY );
173 if( aDlg.Execute() == RET_OK )
175 // lock controllers till end of block
176 ControllerLockGuard aCLGuard( getModel() );
177 InsertAxisOrGridDialogData aDialogOutput;
178 aDlg.getResult( aDialogOutput );
179 bool bChanged = AxisHelper::changeVisibilityOfGrids( xDiagram
180 , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, m_xCC );
181 if( bChanged )
182 aUndoGuard.commit();
185 catch(const uno::RuntimeException& e)
187 ASSERT_EXCEPTION( e );
191 //-----------------------------------------------------------------------------
192 //-----------------------------------------------------------------------------
194 void ChartController::executeDispatch_InsertTitles()
196 UndoGuard aUndoGuard(
197 ActionDescriptionProvider::createDescription(
198 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_TITLES ))),
199 m_xUndoManager );
203 TitleDialogData aDialogInput;
204 aDialogInput.readFromModel( getModel() );
206 SolarMutexGuard aGuard;
207 SchTitleDlg aDlg( m_pChartWindow, aDialogInput );
208 if( aDlg.Execute() == RET_OK )
210 // lock controllers till end of block
211 ControllerLockGuard aCLGuard( getModel() );
212 TitleDialogData aDialogOutput( impl_createReferenceSizeProvider());
213 aDlg.getResult( aDialogOutput );
214 bool bChanged = aDialogOutput.writeDifferenceToModel( getModel(), m_xCC, &aDialogInput );
215 if( bChanged )
216 aUndoGuard.commit();
219 catch(const uno::RuntimeException& e)
221 ASSERT_EXCEPTION( e );
225 void ChartController::executeDispatch_DeleteLegend()
227 UndoGuard aUndoGuard(
228 ActionDescriptionProvider::createDescription(
229 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_LEGEND ))),
230 m_xUndoManager );
232 LegendHelper::hideLegend( getModel() );
233 aUndoGuard.commit();
236 void ChartController::executeDispatch_InsertLegend()
238 UndoGuard aUndoGuard(
239 ActionDescriptionProvider::createDescription(
240 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_LEGEND ))),
241 m_xUndoManager );
243 Reference< chart2::XLegend > xLegend = LegendHelper::showLegend( getModel(), m_xCC );
244 aUndoGuard.commit();
247 void ChartController::executeDispatch_OpenLegendDialog()
249 UndoGuard aUndoGuard(
250 ActionDescriptionProvider::createDescription(
251 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_LEGEND ))),
252 m_xUndoManager );
256 //prepare and open dialog
257 SolarMutexGuard aGuard;
258 SchLegendDlg aDlg( m_pChartWindow, m_xCC );
259 aDlg.init( getModel() );
260 if( aDlg.Execute() == RET_OK )
262 // lock controllers till end of block
263 ControllerLockGuard aCLGuard( getModel() );
264 bool bChanged = aDlg.writeToModel( getModel() );
265 if( bChanged )
266 aUndoGuard.commit();
269 catch(const uno::RuntimeException& e)
271 ASSERT_EXCEPTION( e );
275 //-----------------------------------------------------------------------------
276 //-----------------------------------------------------------------------------
278 void ChartController::executeDispatch_InsertMenu_DataLabels()
280 UndoGuard aUndoGuard(
281 ActionDescriptionProvider::createDescription(
282 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_DATALABELS ))),
283 m_xUndoManager );
285 //if a series is selected insert labels for that series only:
286 uno::Reference< chart2::XDataSeries > xSeries(
287 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()), uno::UNO_QUERY );
288 if( xSeries.is() )
290 // add labels
291 DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries );
293 rtl::OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) );
294 aChildParticle+=(C2U("="));
295 rtl::OUString aObjectCID = ObjectIdentifier::createClassifiedIdentifierForParticles(
296 ObjectIdentifier::getSeriesParticleFromCID(m_aSelection.getSelectedCID()), aChildParticle );
298 bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, true );
299 if( bSuccess )
300 aUndoGuard.commit();
301 return;
306 wrapper::AllDataLabelItemConverter aItemConverter(
307 getModel(),
308 m_pDrawModelWrapper->GetItemPool(),
309 m_pDrawModelWrapper->getSdrModel(),
310 uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
311 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
312 aItemConverter.FillItemSet( aItemSet );
314 //prepare and open dialog
315 SolarMutexGuard aGuard;
317 //get number formatter
318 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( getModel(), uno::UNO_QUERY );
319 NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
320 SvNumberFormatter* pNumberFormatter = aNumberFormatterWrapper.getSvNumberFormatter();
322 DataLabelsDialog aDlg( m_pChartWindow, aItemSet, pNumberFormatter);
324 if( aDlg.Execute() == RET_OK )
326 SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
327 aDlg.FillItemSet( aOutItemSet );
328 // lock controllers till end of block
329 ControllerLockGuard aCLGuard( getModel() );
330 bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
331 if( bChanged )
332 aUndoGuard.commit();
335 catch(const uno::RuntimeException& e)
337 ASSERT_EXCEPTION( e );
341 void ChartController::executeDispatch_InsertMeanValue()
343 UndoGuard aUndoGuard(
344 ActionDescriptionProvider::createDescription(
345 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AVERAGE_LINE ))),
346 m_xUndoManager );
347 lcl_InsertMeanValueLine( m_xCC ).operator()(
348 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ));
349 aUndoGuard.commit();
352 void ChartController::executeDispatch_InsertMenu_MeanValues()
354 UndoGuard aUndoGuard(
355 ActionDescriptionProvider::createDescription(
356 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AVERAGE_LINE ))),
357 m_xUndoManager );
359 uno::Reference< chart2::XDataSeries > xSeries(
360 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
361 if( xSeries.is() )
363 //if a series is selected insert mean value only for that series:
364 lcl_InsertMeanValueLine( m_xCC ).operator()(xSeries);
366 else
368 ::std::vector< uno::Reference< chart2::XDataSeries > > aSeries(
369 DiagramHelper::getDataSeriesFromDiagram( ChartModelHelper::findDiagram( getModel() )));
370 ::std::for_each( aSeries.begin(), aSeries.end(), lcl_InsertMeanValueLine( m_xCC ));
372 aUndoGuard.commit();
375 void ChartController::executeDispatch_InsertMenu_Trendlines()
377 //if a series is selected insert only for that series:
378 uno::Reference< chart2::XDataSeries > xSeries(
379 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
380 if( xSeries.is())
382 executeDispatch_InsertTrendline();
383 return;
386 UndoGuard aUndoGuard(
387 ActionDescriptionProvider::createDescription(
388 ActionDescriptionProvider::INSERT, ObjectNameProvider::getName_ObjectForAllSeries( OBJECTTYPE_DATA_CURVE ) ),
389 m_xUndoManager );
393 wrapper::AllSeriesStatisticsConverter aItemConverter(
394 getModel(), m_pDrawModelWrapper->GetItemPool() );
395 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
396 aItemConverter.FillItemSet( aItemSet );
398 //prepare and open dialog
399 SolarMutexGuard aGuard;
400 InsertTrendlineDialog aDlg( m_pChartWindow, aItemSet );
401 aDlg.adjustSize();
403 if( aDlg.Execute() == RET_OK )
405 SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
406 aDlg.FillItemSet( aOutItemSet );
408 // lock controllers till end of block
409 ControllerLockGuard aCLGuard( getModel() );
410 bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
411 if( bChanged )
412 aUndoGuard.commit();
415 catch(const uno::RuntimeException& e)
417 ASSERT_EXCEPTION( e );
421 void ChartController::executeDispatch_InsertTrendline()
423 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
424 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()), uno::UNO_QUERY );
425 if( xRegCurveCnt.is())
427 UndoLiveUpdateGuard aUndoGuard(
428 ActionDescriptionProvider::createDescription(
429 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE ))),
430 m_xUndoManager );
432 // add a linear curve
433 RegressionCurveHelper::addRegressionCurve(
434 RegressionCurveHelper::REGRESSION_TYPE_LINEAR, xRegCurveCnt, m_xCC );
436 // get an appropriate item converter
437 uno::Reference< chart2::XRegressionCurve > xCurve(
438 RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ));
439 uno::Reference< beans::XPropertySet > xCurveProp( xCurve, uno::UNO_QUERY );
440 if( !xCurveProp.is())
441 return;
442 wrapper::RegressionCurveItemConverter aItemConverter(
443 xCurveProp, xRegCurveCnt, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
444 m_pDrawModelWrapper->getSdrModel(),
445 uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
447 // open dialog
448 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
449 aItemConverter.FillItemSet( aItemSet );
450 ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter(
451 ObjectIdentifier::createDataCurveCID(
452 ObjectIdentifier::getSeriesParticleFromCID( m_aSelection.getSelectedCID()),
453 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt, xCurve ), false ));
454 aDialogParameter.init( getModel() );
455 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
456 SolarMutexGuard aGuard;
457 SchAttribTabDlg aDlg( m_pChartWindow, &aItemSet, &aDialogParameter, &aViewElementListProvider,
458 uno::Reference< util::XNumberFormatsSupplier >( getModel(), uno::UNO_QUERY ));
460 // note: when a user pressed "OK" but didn't change any settings in the
461 // dialog, the SfxTabDialog returns "Cancel"
462 if( aDlg.Execute() == RET_OK || aDlg.DialogWasClosedWithOK())
464 const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
465 if( pOutItemSet )
467 ControllerLockGuard aCLGuard( getModel() );
468 aItemConverter.ApplyItemSet( *pOutItemSet );
470 aUndoGuard.commit();
475 void ChartController::executeDispatch_InsertErrorBars( bool bYError )
477 ObjectType objType = bYError ? OBJECTTYPE_DATA_ERRORS_Y : OBJECTTYPE_DATA_ERRORS_X;
479 //if a series is selected insert error bars for that series only:
480 uno::Reference< chart2::XDataSeries > xSeries(
481 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
483 if( xSeries.is())
485 UndoLiveUpdateGuard aUndoGuard(
486 ActionDescriptionProvider::createDescription(
487 ActionDescriptionProvider::INSERT,
488 String( SchResId( bYError ? STR_OBJECT_ERROR_BARS_Y : STR_OBJECT_ERROR_BARS_X ))),
489 m_xUndoManager );
491 // add error bars with standard deviation
492 uno::Reference< beans::XPropertySet > xErrorBarProp(
493 StatisticsHelper::addErrorBars( xSeries, m_xCC,
494 ::com::sun::star::chart::ErrorBarStyle::STANDARD_DEVIATION,
495 bYError));
497 // get an appropriate item converter
498 wrapper::ErrorBarItemConverter aItemConverter(
499 getModel(), xErrorBarProp, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
500 m_pDrawModelWrapper->getSdrModel(),
501 uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
503 // open dialog
504 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
505 aItemSet.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE,bYError));
506 aItemConverter.FillItemSet( aItemSet );
507 ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter(
508 ObjectIdentifier::createClassifiedIdentifierWithParent(
509 objType, ::rtl::OUString(), m_aSelection.getSelectedCID()));
510 aDialogParameter.init( getModel() );
511 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
512 SolarMutexGuard aGuard;
513 SchAttribTabDlg aDlg( m_pChartWindow, &aItemSet, &aDialogParameter, &aViewElementListProvider,
514 uno::Reference< util::XNumberFormatsSupplier >( getModel(), uno::UNO_QUERY ));
515 aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
516 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(),
517 m_xChartView, m_aSelection.getSelectedCID()));
519 // note: when a user pressed "OK" but didn't change any settings in the
520 // dialog, the SfxTabDialog returns "Cancel"
521 if( aDlg.Execute() == RET_OK || aDlg.DialogWasClosedWithOK())
523 const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
524 if( pOutItemSet )
526 ControllerLockGuard aCLGuard( getModel() );
527 aItemConverter.ApplyItemSet( *pOutItemSet );
529 aUndoGuard.commit();
532 else
534 //if no series is selected insert error bars for all series
535 UndoGuard aUndoGuard(
536 ActionDescriptionProvider::createDescription(
537 ActionDescriptionProvider::INSERT,
538 ObjectNameProvider::getName_ObjectForAllSeries( objType ) ),
539 m_xUndoManager );
543 wrapper::AllSeriesStatisticsConverter aItemConverter(
544 getModel(), m_pDrawModelWrapper->GetItemPool() );
545 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
546 aItemConverter.FillItemSet( aItemSet );
548 //prepare and open dialog
549 SolarMutexGuard aGuard;
550 InsertErrorBarsDialog aDlg(
551 m_pChartWindow, aItemSet,
552 uno::Reference< chart2::XChartDocument >( getModel(), uno::UNO_QUERY ),
553 bYError ? ErrorBarResources::ERROR_BAR_Y : ErrorBarResources::ERROR_BAR_X);
555 aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
556 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, rtl::OUString() ) );
558 if( aDlg.Execute() == RET_OK )
560 SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
561 aDlg.FillItemSet( aOutItemSet );
563 // lock controllers till end of block
564 ControllerLockGuard aCLGuard( getModel() );
565 bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
566 if( bChanged )
567 aUndoGuard.commit();
570 catch(const uno::RuntimeException& e)
572 ASSERT_EXCEPTION( e );
577 void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 )
579 uno::Reference< chart2::XRegressionCurve > xRegCurve(
580 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
581 if( !xRegCurve.is() )
583 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
584 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
585 xRegCurve.set( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) );
587 if( xRegCurve.is())
589 uno::Reference< beans::XPropertySet > xEqProp( xRegCurve->getEquationProperties());
590 if( xEqProp.is())
592 // using assignment for broken gcc 3.3
593 UndoGuard aUndoGuard = UndoGuard(
594 ActionDescriptionProvider::createDescription(
595 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
596 m_xUndoManager );
597 xEqProp->setPropertyValue( C2U("ShowEquation"), uno::makeAny( true ));
598 xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( bInsertR2 ));
599 aUndoGuard.commit();
604 void ChartController::executeDispatch_InsertR2Value()
606 uno::Reference< beans::XPropertySet > xEqProp(
607 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
608 if( xEqProp.is())
610 UndoGuard aUndoGuard = UndoGuard(
611 ActionDescriptionProvider::createDescription(
612 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
613 m_xUndoManager );
614 xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( true ));
615 aUndoGuard.commit();
619 void ChartController::executeDispatch_DeleteR2Value()
621 uno::Reference< beans::XPropertySet > xEqProp(
622 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
623 if( xEqProp.is())
625 UndoGuard aUndoGuard = UndoGuard(
626 ActionDescriptionProvider::createDescription(
627 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
628 m_xUndoManager );
629 xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( false ));
630 aUndoGuard.commit();
634 void ChartController::executeDispatch_DeleteMeanValue()
636 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
637 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
638 if( xRegCurveCnt.is())
640 UndoGuard aUndoGuard(
641 ActionDescriptionProvider::createDescription(
642 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_AVERAGE_LINE ))),
643 m_xUndoManager );
644 RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt );
645 aUndoGuard.commit();
649 void ChartController::executeDispatch_DeleteTrendline()
651 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
652 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
653 if( xRegCurveCnt.is())
655 UndoGuard aUndoGuard(
656 ActionDescriptionProvider::createDescription(
657 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE ))),
658 m_xUndoManager );
659 RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt );
660 aUndoGuard.commit();
664 void ChartController::executeDispatch_DeleteTrendlineEquation()
666 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
667 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
668 if( xRegCurveCnt.is())
670 UndoGuard aUndoGuard(
671 ActionDescriptionProvider::createDescription(
672 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
673 m_xUndoManager );
674 RegressionCurveHelper::removeEquations( xRegCurveCnt );
675 aUndoGuard.commit();
679 void ChartController::executeDispatch_DeleteErrorBars( bool bYError )
681 uno::Reference< chart2::XDataSeries > xDataSeries(
682 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ));
683 if( xDataSeries.is())
685 UndoGuard aUndoGuard(
686 ActionDescriptionProvider::createDescription(
687 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE ))),
688 m_xUndoManager );
689 StatisticsHelper::removeErrorBars( xDataSeries, bYError );
690 aUndoGuard.commit();
694 void ChartController::executeDispatch_InsertDataLabels()
696 uno::Reference< chart2::XDataSeries > xSeries(
697 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
698 if( xSeries.is() )
700 UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::INSERT,
701 String( SchResId( STR_OBJECT_DATALABELS ))),
702 m_xUndoManager );
703 DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries );
704 aUndoGuard.commit();
708 void ChartController::executeDispatch_InsertDataLabel()
710 UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::INSERT,
711 String( SchResId( STR_OBJECT_LABEL ))),
712 m_xUndoManager );
713 DataSeriesHelper::insertDataLabelToPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) );
714 aUndoGuard.commit();
717 void ChartController::executeDispatch_DeleteDataLabels()
719 uno::Reference< chart2::XDataSeries > xSeries(
720 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
721 if( xSeries.is() )
723 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::DELETE,
724 String( SchResId( STR_OBJECT_DATALABELS ))),
725 m_xUndoManager );
726 DataSeriesHelper::deleteDataLabelsFromSeriesAndAllPoints( xSeries );
727 aUndoGuard.commit();
731 void ChartController::executeDispatch_DeleteDataLabel()
733 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::DELETE,
734 String( SchResId( STR_OBJECT_LABEL ))),
735 m_xUndoManager );
736 DataSeriesHelper::deleteDataLabelsFromPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) );
737 aUndoGuard.commit();
740 void ChartController::executeDispatch_ResetAllDataPoints()
742 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::FORMAT,
743 String( SchResId( STR_OBJECT_DATAPOINTS ))),
744 m_xUndoManager );
745 uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
746 if( xSeries.is() )
747 xSeries->resetAllDataPoints();
748 aUndoGuard.commit();
750 void ChartController::executeDispatch_ResetDataPoint()
752 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::FORMAT,
753 String( SchResId( STR_OBJECT_DATAPOINT ))),
754 m_xUndoManager );
755 uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
756 if( xSeries.is() )
758 sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( m_aSelection.getSelectedCID() );
759 xSeries->resetDataPoint( nPointIndex );
761 aUndoGuard.commit();
764 void ChartController::executeDispatch_InsertAxisTitle()
768 uno::Reference< XTitle > xTitle;
770 UndoGuard aUndoGuard(
771 ActionDescriptionProvider::createDescription(
772 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_TITLE ))),
773 m_xUndoManager );
775 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
776 sal_Int32 nDimensionIndex = -1;
777 sal_Int32 nCooSysIndex = -1;
778 sal_Int32 nAxisIndex = -1;
779 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram(getModel()), nCooSysIndex, nDimensionIndex, nAxisIndex );
781 TitleHelper::eTitleType eTitleType = TitleHelper::X_AXIS_TITLE;
782 if( nDimensionIndex==0 )
783 eTitleType = nAxisIndex==0 ? TitleHelper::X_AXIS_TITLE : TitleHelper::SECONDARY_X_AXIS_TITLE;
784 else if( nDimensionIndex==1 )
785 eTitleType = nAxisIndex==0 ? TitleHelper::Y_AXIS_TITLE : TitleHelper::SECONDARY_Y_AXIS_TITLE;
786 else
787 eTitleType = TitleHelper::Z_AXIS_TITLE;
789 ::std::auto_ptr< ReferenceSizeProvider > apRefSizeProvider( impl_createReferenceSizeProvider());
790 xTitle = TitleHelper::createTitle( eTitleType, ObjectNameProvider::getTitleNameByType(eTitleType), getModel(), m_xCC, apRefSizeProvider.get() );
791 aUndoGuard.commit();
794 catch(const uno::RuntimeException& e)
796 ASSERT_EXCEPTION( e );
800 void ChartController::executeDispatch_InsertAxis()
802 UndoGuard aUndoGuard(
803 ActionDescriptionProvider::createDescription(
804 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AXIS ))),
805 m_xUndoManager );
809 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
810 if( xAxis.is() )
812 AxisHelper::makeAxisVisible( xAxis );
813 aUndoGuard.commit();
816 catch(const uno::RuntimeException& e)
818 ASSERT_EXCEPTION( e );
822 void ChartController::executeDispatch_DeleteAxis()
824 UndoGuard aUndoGuard(
825 ActionDescriptionProvider::createDescription(
826 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_AXIS ))),
827 m_xUndoManager );
831 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
832 if( xAxis.is() )
834 AxisHelper::makeAxisInvisible( xAxis );
835 aUndoGuard.commit();
838 catch(const uno::RuntimeException& e)
840 ASSERT_EXCEPTION( e );
844 void ChartController::executeDispatch_InsertMajorGrid()
846 UndoGuard aUndoGuard(
847 ActionDescriptionProvider::createDescription(
848 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRID ))),
849 m_xUndoManager );
853 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
854 if( xAxis.is() )
856 AxisHelper::makeGridVisible( xAxis->getGridProperties() );
857 aUndoGuard.commit();
860 catch(const uno::RuntimeException& e)
862 ASSERT_EXCEPTION( e );
866 void ChartController::executeDispatch_DeleteMajorGrid()
868 UndoGuard aUndoGuard(
869 ActionDescriptionProvider::createDescription(
870 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_GRID ))),
871 m_xUndoManager );
875 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
876 if( xAxis.is() )
878 AxisHelper::makeGridInvisible( xAxis->getGridProperties() );
879 aUndoGuard.commit();
882 catch(const uno::RuntimeException& e)
884 ASSERT_EXCEPTION( e );
888 void ChartController::executeDispatch_InsertMinorGrid()
890 UndoGuard aUndoGuard(
891 ActionDescriptionProvider::createDescription(
892 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRID ))),
893 m_xUndoManager );
897 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
898 if( xAxis.is() )
900 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
901 for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
902 AxisHelper::makeGridVisible( aSubGrids[nN] );
903 aUndoGuard.commit();
906 catch(const uno::RuntimeException& e)
908 ASSERT_EXCEPTION( e );
912 void ChartController::executeDispatch_DeleteMinorGrid()
914 UndoGuard aUndoGuard(
915 ActionDescriptionProvider::createDescription(
916 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_GRID ))),
917 m_xUndoManager );
921 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
922 if( xAxis.is() )
924 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
925 for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
926 AxisHelper::makeGridInvisible( aSubGrids[nN] );
927 aUndoGuard.commit();
930 catch(const uno::RuntimeException& e)
932 ASSERT_EXCEPTION( e );
936 //.............................................................................
937 } //namespace chart
938 //.............................................................................
940 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */