Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / main / ChartController_Insert.cxx
blobec45a22eae0ec2464d2d5252339fa7e9ba7a067f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <memory>
21 #include <ChartController.hxx>
23 #include <dlg_InsertAxis_Grid.hxx>
24 #include <dlg_InsertDataLabel.hxx>
25 #include <dlg_InsertLegend.hxx>
26 #include <dlg_InsertErrorBars.hxx>
27 #include <dlg_InsertTitle.hxx>
28 #include <dlg_ObjectProperties.hxx>
30 #include <ChartModel.hxx>
31 #include <ChartModelHelper.hxx>
32 #include <AxisHelper.hxx>
33 #include <TitleHelper.hxx>
34 #include <DiagramHelper.hxx>
35 #include <chartview/DrawModelWrapper.hxx>
36 #include <chartview/ChartSfxItemIds.hxx>
37 #include <NumberFormatterWrapper.hxx>
38 #include <ViewElementListProvider.hxx>
39 #include <MultipleChartConverters.hxx>
40 #include <ControllerLockGuard.hxx>
41 #include "UndoGuard.hxx"
42 #include <ResId.hxx>
43 #include <strings.hrc>
44 #include <ReferenceSizeProvider.hxx>
45 #include <ObjectIdentifier.hxx>
46 #include <RegressionCurveHelper.hxx>
47 #include <RegressionCurveItemConverter.hxx>
48 #include <StatisticsHelper.hxx>
49 #include <ErrorBarItemConverter.hxx>
50 #include <DataSeriesHelper.hxx>
51 #include <ObjectNameProvider.hxx>
52 #include <LegendHelper.hxx>
54 #include <com/sun/star/chart2/XRegressionCurve.hpp>
55 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
56 #include <com/sun/star/chart2/XChartDocument.hpp>
57 #include <com/sun/star/chart/ErrorBarStyle.hpp>
58 #include <svx/ActionDescriptionProvider.hxx>
60 #include <sal/log.hxx>
61 #include <tools/diagnose_ex.h>
62 #include <vcl/svapp.hxx>
64 using namespace ::com::sun::star;
65 using namespace ::com::sun::star::chart2;
66 using ::com::sun::star::uno::Reference;
67 using ::com::sun::star::uno::Sequence;
69 namespace
72 void lcl_InsertMeanValueLine( const uno::Reference< chart2::XDataSeries > & xSeries )
74 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
75 xSeries, uno::UNO_QUERY );
76 if( xRegCurveCnt.is())
78 ::chart::RegressionCurveHelper::addMeanValueLine(
79 xRegCurveCnt, uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ));
83 } // anonymous namespace
85 namespace chart
88 void ChartController::executeDispatch_InsertAxes()
90 UndoGuard aUndoGuard(
91 ActionDescriptionProvider::createDescription(
92 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AXES )),
93 m_xUndoManager );
95 try
97 InsertAxisOrGridDialogData aDialogInput;
98 uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel());
99 AxisHelper::getAxisOrGridExcistence( aDialogInput.aExistenceList, xDiagram );
100 AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram );
102 SolarMutexGuard aGuard;
103 SchAxisDlg aDlg(GetChartFrame(), aDialogInput);
104 if (aDlg.run() == RET_OK)
106 // lock controllers till end of block
107 ControllerLockGuardUNO aCLGuard( getModel() );
109 InsertAxisOrGridDialogData aDialogOutput;
110 aDlg.getResult(aDialogOutput);
111 std::unique_ptr< ReferenceSizeProvider > pRefSizeProvider(
112 impl_createReferenceSizeProvider());
113 bool bChanged = AxisHelper::changeVisibilityOfAxes( xDiagram
114 , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, m_xCC
115 , pRefSizeProvider.get() );
116 if( bChanged )
117 aUndoGuard.commit();
120 catch(const uno::RuntimeException&)
122 TOOLS_WARN_EXCEPTION("chart2", "" );
126 void ChartController::executeDispatch_InsertGrid()
128 UndoGuard aUndoGuard(
129 ActionDescriptionProvider::createDescription(
130 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_GRIDS )),
131 m_xUndoManager );
135 InsertAxisOrGridDialogData aDialogInput;
136 uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel());
137 AxisHelper::getAxisOrGridExcistence( aDialogInput.aExistenceList, xDiagram, false );
138 AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram, false );
140 SolarMutexGuard aGuard;
141 SchGridDlg aDlg(GetChartFrame(), aDialogInput);//aItemSet, b3D, bNet, bSecondaryX, bSecondaryY );
142 if (aDlg.run() == RET_OK)
144 // lock controllers till end of block
145 ControllerLockGuardUNO aCLGuard( getModel() );
146 InsertAxisOrGridDialogData aDialogOutput;
147 aDlg.getResult( aDialogOutput );
148 bool bChanged = AxisHelper::changeVisibilityOfGrids( xDiagram
149 , aDialogInput.aExistenceList, aDialogOutput.aExistenceList );
150 if( bChanged )
151 aUndoGuard.commit();
154 catch(const uno::RuntimeException&)
156 TOOLS_WARN_EXCEPTION("chart2", "" );
160 void ChartController::executeDispatch_InsertTitles()
162 UndoGuard aUndoGuard(
163 ActionDescriptionProvider::createDescription(
164 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_TITLES )),
165 m_xUndoManager );
169 TitleDialogData aDialogInput;
170 aDialogInput.readFromModel( getModel() );
172 SolarMutexGuard aGuard;
173 SchTitleDlg aDlg(GetChartFrame(), aDialogInput);
174 if (aDlg.run() == RET_OK)
176 // lock controllers till end of block
177 ControllerLockGuardUNO aCLGuard( getModel() );
178 TitleDialogData aDialogOutput(impl_createReferenceSizeProvider());
179 aDlg.getResult(aDialogOutput);
180 bool bChanged = aDialogOutput.writeDifferenceToModel( getModel(), m_xCC, &aDialogInput );
181 if( bChanged )
182 aUndoGuard.commit();
185 catch(const uno::RuntimeException&)
187 TOOLS_WARN_EXCEPTION("chart2", "" );
191 void ChartController::executeDispatch_DeleteLegend()
193 UndoGuard aUndoGuard(
194 ActionDescriptionProvider::createDescription(
195 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_LEGEND )),
196 m_xUndoManager );
198 ChartModel& rModel = dynamic_cast<ChartModel&>(*getModel());
199 LegendHelper::hideLegend(rModel);
200 aUndoGuard.commit();
203 void ChartController::executeDispatch_InsertLegend()
205 UndoGuard aUndoGuard(
206 ActionDescriptionProvider::createDescription(
207 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_LEGEND )),
208 m_xUndoManager );
210 ChartModel& rModel = dynamic_cast<ChartModel&>(*getModel());
211 Reference< chart2::XLegend > xLegend = LegendHelper::showLegend(rModel, m_xCC);
212 aUndoGuard.commit();
215 void ChartController::executeDispatch_OpenLegendDialog()
217 UndoGuard aUndoGuard(
218 ActionDescriptionProvider::createDescription(
219 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_LEGEND )),
220 m_xUndoManager );
224 //prepare and open dialog
225 SolarMutexGuard aGuard;
226 SchLegendDlg aDlg(GetChartFrame(), m_xCC);
227 aDlg.init( getModel() );
228 if (aDlg.run() == RET_OK)
230 // lock controllers till end of block
231 ControllerLockGuardUNO aCLGuard( getModel() );
232 aDlg.writeToModel( getModel() );
233 aUndoGuard.commit();
236 catch(const uno::RuntimeException&)
238 TOOLS_WARN_EXCEPTION("chart2", "" );
242 void ChartController::executeDispatch_InsertMenu_DataLabels()
244 UndoGuard aUndoGuard(
245 ActionDescriptionProvider::createDescription(
246 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_DATALABELS )),
247 m_xUndoManager );
249 //if a series is selected insert labels for that series only:
250 uno::Reference< chart2::XDataSeries > xSeries =
251 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel());
252 if( xSeries.is() )
254 // add labels
255 DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries );
257 OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) + "=" );
258 OUString aObjectCID = ObjectIdentifier::createClassifiedIdentifierForParticles(
259 ObjectIdentifier::getSeriesParticleFromCID(m_aSelection.getSelectedCID()), aChildParticle );
261 bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, true );
262 if( bSuccess )
263 aUndoGuard.commit();
264 return;
269 wrapper::AllDataLabelItemConverter aItemConverter(
270 getModel(),
271 m_pDrawModelWrapper->GetItemPool(),
272 m_pDrawModelWrapper->getSdrModel(),
273 uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
274 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
275 aItemConverter.FillItemSet( aItemSet );
277 //prepare and open dialog
278 SolarMutexGuard aGuard;
280 //get number formatter
281 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( getModel(), uno::UNO_QUERY );
282 NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
283 SvNumberFormatter* pNumberFormatter = aNumberFormatterWrapper.getSvNumberFormatter();
285 DataLabelsDialog aDlg(GetChartFrame(), aItemSet, pNumberFormatter);
287 if (aDlg.run() == RET_OK)
289 SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
290 aDlg.FillItemSet(aOutItemSet);
291 // lock controllers till end of block
292 ControllerLockGuardUNO aCLGuard( getModel() );
293 bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
294 if( bChanged )
295 aUndoGuard.commit();
298 catch(const uno::RuntimeException&)
300 TOOLS_WARN_EXCEPTION("chart2", "" );
304 void ChartController::executeDispatch_InsertMeanValue()
306 UndoGuard aUndoGuard(
307 ActionDescriptionProvider::createDescription(
308 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AVERAGE_LINE )),
309 m_xUndoManager );
310 lcl_InsertMeanValueLine( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(),
311 getModel() ) );
312 aUndoGuard.commit();
315 void ChartController::executeDispatch_InsertMenu_MeanValues()
317 UndoGuard aUndoGuard(
318 ActionDescriptionProvider::createDescription(
319 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AVERAGE_LINE )),
320 m_xUndoManager );
322 uno::Reference< chart2::XDataSeries > xSeries =
323 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() );
324 if( xSeries.is() )
326 //if a series is selected insert mean value only for that series:
327 lcl_InsertMeanValueLine( xSeries );
329 else
331 std::vector< uno::Reference< chart2::XDataSeries > > aSeries(
332 DiagramHelper::getDataSeriesFromDiagram( ChartModelHelper::findDiagram( getModel() )));
334 for( const auto& xSrs : aSeries )
335 lcl_InsertMeanValueLine( xSrs );
337 aUndoGuard.commit();
340 void ChartController::executeDispatch_InsertMenu_Trendlines()
342 OUString aCID = m_aSelection.getSelectedCID();
344 uno::Reference< chart2::XDataSeries > xSeries =
345 ObjectIdentifier::getDataSeriesForCID( aCID, getModel() );
347 if( !xSeries.is() )
348 return;
350 executeDispatch_InsertTrendline();
353 void ChartController::executeDispatch_InsertTrendline()
355 uno::Reference< chart2::XRegressionCurveContainer > xRegressionCurveContainer(
356 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()), uno::UNO_QUERY );
358 if( !xRegressionCurveContainer.is() )
359 return;
361 UndoLiveUpdateGuard aUndoGuard(
362 ActionDescriptionProvider::createDescription(
363 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE )),
364 m_xUndoManager );
366 uno::Reference< chart2::XRegressionCurve > xCurve =
367 RegressionCurveHelper::addRegressionCurve(
368 SvxChartRegress::Linear,
369 xRegressionCurveContainer );
371 uno::Reference< beans::XPropertySet > xProperties( xCurve, uno::UNO_QUERY );
373 if( !xProperties.is())
374 return;
376 wrapper::RegressionCurveItemConverter aItemConverter(
377 xProperties, xRegressionCurveContainer, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
378 m_pDrawModelWrapper->getSdrModel(),
379 uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
381 // open dialog
382 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
383 aItemConverter.FillItemSet( aItemSet );
384 ObjectPropertiesDialogParameter aDialogParameter(
385 ObjectIdentifier::createDataCurveCID(
386 ObjectIdentifier::getSeriesParticleFromCID( m_aSelection.getSelectedCID()),
387 RegressionCurveHelper::getRegressionCurveIndex( xRegressionCurveContainer, xCurve ), false ));
388 aDialogParameter.init( getModel() );
389 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
390 SolarMutexGuard aGuard;
391 SchAttribTabDlg aDialog(
392 GetChartFrame(), &aItemSet, &aDialogParameter,
393 &aViewElementListProvider,
394 uno::Reference< util::XNumberFormatsSupplier >(
395 getModel(), uno::UNO_QUERY ) );
397 // note: when a user pressed "OK" but didn't change any settings in the
398 // dialog, the SfxTabDialog returns "Cancel"
399 if( aDialog.run() == RET_OK || aDialog.DialogWasClosedWithOK())
401 const SfxItemSet* pOutItemSet = aDialog.GetOutputItemSet();
402 if( pOutItemSet )
404 ControllerLockGuardUNO aCLGuard( getModel() );
405 aItemConverter.ApplyItemSet( *pOutItemSet );
407 aUndoGuard.commit();
411 void ChartController::executeDispatch_InsertErrorBars( bool bYError )
413 ObjectType objType = bYError ? OBJECTTYPE_DATA_ERRORS_Y : OBJECTTYPE_DATA_ERRORS_X;
415 //if a series is selected insert error bars for that series only:
416 uno::Reference< chart2::XDataSeries > xSeries =
417 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() );
419 if( xSeries.is())
421 UndoLiveUpdateGuard aUndoGuard(
422 ActionDescriptionProvider::createDescription(
423 ActionDescriptionProvider::ActionType::Insert,
424 SchResId( bYError ? STR_OBJECT_ERROR_BARS_Y : STR_OBJECT_ERROR_BARS_X )),
425 m_xUndoManager );
427 // add error bars with standard deviation
428 uno::Reference< beans::XPropertySet > xErrorBarProp(
429 StatisticsHelper::addErrorBars( xSeries,
430 css::chart::ErrorBarStyle::STANDARD_DEVIATION,
431 bYError));
433 // get an appropriate item converter
434 wrapper::ErrorBarItemConverter aItemConverter(
435 getModel(), xErrorBarProp, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
436 m_pDrawModelWrapper->getSdrModel(),
437 uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
439 // open dialog
440 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
441 aItemSet.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE,bYError));
442 aItemConverter.FillItemSet( aItemSet );
443 ObjectPropertiesDialogParameter aDialogParameter(
444 ObjectIdentifier::createClassifiedIdentifierWithParent(
445 objType, OUString(), m_aSelection.getSelectedCID()));
446 aDialogParameter.init( getModel() );
447 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
448 SolarMutexGuard aGuard;
449 SchAttribTabDlg aDlg(
450 GetChartFrame(), &aItemSet, &aDialogParameter,
451 &aViewElementListProvider,
452 uno::Reference< util::XNumberFormatsSupplier >(
453 getModel(), uno::UNO_QUERY ) );
454 aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
455 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(),
456 m_xChartView, m_aSelection.getSelectedCID()));
458 // note: when a user pressed "OK" but didn't change any settings in the
459 // dialog, the SfxTabDialog returns "Cancel"
460 if (aDlg.run() == RET_OK || aDlg.DialogWasClosedWithOK())
462 const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
463 if( pOutItemSet )
465 ControllerLockGuardUNO aCLGuard( getModel() );
466 aItemConverter.ApplyItemSet( *pOutItemSet );
468 aUndoGuard.commit();
471 else
473 //if no series is selected insert error bars for all series
474 UndoGuard aUndoGuard(
475 ActionDescriptionProvider::createDescription(
476 ActionDescriptionProvider::ActionType::Insert,
477 ObjectNameProvider::getName_ObjectForAllSeries( objType ) ),
478 m_xUndoManager );
482 wrapper::AllSeriesStatisticsConverter aItemConverter(
483 getModel(), m_pDrawModelWrapper->GetItemPool() );
484 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
485 aItemConverter.FillItemSet( aItemSet );
487 //prepare and open dialog
488 SolarMutexGuard aGuard;
489 InsertErrorBarsDialog aDlg(
490 GetChartFrame(), aItemSet,
491 uno::Reference< chart2::XChartDocument >( getModel(), uno::UNO_QUERY ),
492 bYError ? ErrorBarResources::ERROR_BAR_Y : ErrorBarResources::ERROR_BAR_X);
494 aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
495 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, OUString() ) );
497 if (aDlg.run() == RET_OK)
499 SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
500 aDlg.FillItemSet( aOutItemSet );
502 // lock controllers till end of block
503 ControllerLockGuardUNO aCLGuard( getModel() );
504 bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
505 if( bChanged )
506 aUndoGuard.commit();
509 catch(const uno::RuntimeException&)
511 TOOLS_WARN_EXCEPTION("chart2", "" );
516 void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 )
518 uno::Reference< chart2::XRegressionCurve > xRegCurve(
519 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
520 if( !xRegCurve.is() )
522 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
523 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
524 xRegCurve.set( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) );
526 if( xRegCurve.is())
528 uno::Reference< beans::XPropertySet > xEqProp( xRegCurve->getEquationProperties());
529 if( xEqProp.is())
531 UndoGuard aUndoGuard(
532 ActionDescriptionProvider::createDescription(
533 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )),
534 m_xUndoManager );
535 xEqProp->setPropertyValue( "ShowEquation", uno::Any( true ));
536 xEqProp->setPropertyValue( "XName", uno::Any( OUString("x") ));
537 xEqProp->setPropertyValue( "YName", uno::Any( OUString("f(x)") ));
538 xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( bInsertR2 ));
539 aUndoGuard.commit();
544 void ChartController::executeDispatch_InsertR2Value()
546 uno::Reference< beans::XPropertySet > xEqProp =
547 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() );
548 if( xEqProp.is())
550 UndoGuard aUndoGuard(
551 ActionDescriptionProvider::createDescription(
552 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )),
553 m_xUndoManager );
554 xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( true ));
555 aUndoGuard.commit();
559 void ChartController::executeDispatch_DeleteR2Value()
561 uno::Reference< beans::XPropertySet > xEqProp =
562 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() );
563 if( xEqProp.is())
565 UndoGuard aUndoGuard(
566 ActionDescriptionProvider::createDescription(
567 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )),
568 m_xUndoManager );
569 xEqProp->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( false ));
570 aUndoGuard.commit();
574 void ChartController::executeDispatch_DeleteMeanValue()
576 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
577 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
578 if( xRegCurveCnt.is())
580 UndoGuard aUndoGuard(
581 ActionDescriptionProvider::createDescription(
582 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_AVERAGE_LINE )),
583 m_xUndoManager );
584 RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt );
585 aUndoGuard.commit();
589 void ChartController::executeDispatch_DeleteTrendline()
591 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
592 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
593 if( xRegCurveCnt.is())
595 UndoGuard aUndoGuard(
596 ActionDescriptionProvider::createDescription(
597 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE )),
598 m_xUndoManager );
599 RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt );
600 aUndoGuard.commit();
604 void ChartController::executeDispatch_DeleteTrendlineEquation()
606 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
607 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
608 if( xRegCurveCnt.is())
610 UndoGuard aUndoGuard(
611 ActionDescriptionProvider::createDescription(
612 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE_EQUATION )),
613 m_xUndoManager );
614 RegressionCurveHelper::removeEquations( xRegCurveCnt );
615 aUndoGuard.commit();
619 void ChartController::executeDispatch_DeleteErrorBars( bool bYError )
621 uno::Reference< chart2::XDataSeries > xDataSeries(
622 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ));
623 if( xDataSeries.is())
625 UndoGuard aUndoGuard(
626 ActionDescriptionProvider::createDescription(
627 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE )),
628 m_xUndoManager );
629 StatisticsHelper::removeErrorBars( xDataSeries, bYError );
630 aUndoGuard.commit();
634 void ChartController::executeDispatch_InsertDataLabels()
636 uno::Reference< chart2::XDataSeries > xSeries =
637 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() );
638 if( xSeries.is() )
640 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert,
641 SchResId( STR_OBJECT_DATALABELS )),
642 m_xUndoManager );
643 DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries );
644 aUndoGuard.commit();
648 void ChartController::executeDispatch_InsertDataLabel()
650 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert,
651 SchResId( STR_OBJECT_LABEL )),
652 m_xUndoManager );
653 DataSeriesHelper::insertDataLabelToPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) );
654 aUndoGuard.commit();
657 void ChartController::executeDispatch_DeleteDataLabels()
659 uno::Reference< chart2::XDataSeries > xSeries =
660 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() );
661 if( xSeries.is() )
663 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete,
664 SchResId( STR_OBJECT_DATALABELS )),
665 m_xUndoManager );
666 DataSeriesHelper::deleteDataLabelsFromSeriesAndAllPoints( xSeries );
667 aUndoGuard.commit();
671 void ChartController::executeDispatch_DeleteDataLabel()
673 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete,
674 SchResId( STR_OBJECT_LABEL )),
675 m_xUndoManager );
676 DataSeriesHelper::deleteDataLabelsFromPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) );
677 aUndoGuard.commit();
680 void ChartController::executeDispatch_ResetAllDataPoints()
682 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Format,
683 SchResId( STR_OBJECT_DATAPOINTS )),
684 m_xUndoManager );
685 uno::Reference< chart2::XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() );
686 if( xSeries.is() )
687 xSeries->resetAllDataPoints();
688 aUndoGuard.commit();
690 void ChartController::executeDispatch_ResetDataPoint()
692 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Format,
693 SchResId( STR_OBJECT_DATAPOINT )),
694 m_xUndoManager );
695 uno::Reference< chart2::XDataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() );
696 if( xSeries.is() )
698 sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( m_aSelection.getSelectedCID() );
699 xSeries->resetDataPoint( nPointIndex );
701 aUndoGuard.commit();
704 void ChartController::executeDispatch_InsertAxisTitle()
708 uno::Reference< XTitle > xTitle;
710 UndoGuard aUndoGuard(
711 ActionDescriptionProvider::createDescription(
712 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_TITLE )),
713 m_xUndoManager );
715 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
716 sal_Int32 nDimensionIndex = -1;
717 sal_Int32 nCooSysIndex = -1;
718 sal_Int32 nAxisIndex = -1;
719 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram(getModel()), nCooSysIndex, nDimensionIndex, nAxisIndex );
721 TitleHelper::eTitleType eTitleType = TitleHelper::X_AXIS_TITLE;
722 if( nDimensionIndex==0 )
723 eTitleType = nAxisIndex==0 ? TitleHelper::X_AXIS_TITLE : TitleHelper::SECONDARY_X_AXIS_TITLE;
724 else if( nDimensionIndex==1 )
725 eTitleType = nAxisIndex==0 ? TitleHelper::Y_AXIS_TITLE : TitleHelper::SECONDARY_Y_AXIS_TITLE;
726 else
727 eTitleType = TitleHelper::Z_AXIS_TITLE;
729 std::unique_ptr< ReferenceSizeProvider > apRefSizeProvider( impl_createReferenceSizeProvider());
730 xTitle = TitleHelper::createTitle( eTitleType, ObjectNameProvider::getTitleNameByType(eTitleType), getModel(), m_xCC, apRefSizeProvider.get() );
731 aUndoGuard.commit();
734 catch(const uno::RuntimeException&)
736 TOOLS_WARN_EXCEPTION("chart2", "" );
740 void ChartController::executeDispatch_InsertAxis()
742 UndoGuard aUndoGuard(
743 ActionDescriptionProvider::createDescription(
744 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AXIS )),
745 m_xUndoManager );
749 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
750 if( xAxis.is() )
752 AxisHelper::makeAxisVisible( xAxis );
753 aUndoGuard.commit();
756 catch(const uno::RuntimeException&)
758 TOOLS_WARN_EXCEPTION("chart2", "" );
762 void ChartController::executeDispatch_DeleteAxis()
764 UndoGuard aUndoGuard(
765 ActionDescriptionProvider::createDescription(
766 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_AXIS )),
767 m_xUndoManager );
771 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
772 if( xAxis.is() )
774 AxisHelper::makeAxisInvisible( xAxis );
775 aUndoGuard.commit();
778 catch(const uno::RuntimeException&)
780 TOOLS_WARN_EXCEPTION("chart2", "" );
784 void ChartController::executeDispatch_InsertMajorGrid()
786 UndoGuard aUndoGuard(
787 ActionDescriptionProvider::createDescription(
788 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_GRID )),
789 m_xUndoManager );
793 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
794 if( xAxis.is() )
796 AxisHelper::makeGridVisible( xAxis->getGridProperties() );
797 aUndoGuard.commit();
800 catch(const uno::RuntimeException&)
802 TOOLS_WARN_EXCEPTION("chart2", "" );
806 void ChartController::executeDispatch_DeleteMajorGrid()
808 UndoGuard aUndoGuard(
809 ActionDescriptionProvider::createDescription(
810 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_GRID )),
811 m_xUndoManager );
815 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
816 if( xAxis.is() )
818 AxisHelper::makeGridInvisible( xAxis->getGridProperties() );
819 aUndoGuard.commit();
822 catch(const uno::RuntimeException&)
824 TOOLS_WARN_EXCEPTION("chart2", "" );
828 void ChartController::executeDispatch_InsertMinorGrid()
830 UndoGuard aUndoGuard(
831 ActionDescriptionProvider::createDescription(
832 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_GRID )),
833 m_xUndoManager );
837 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
838 if( xAxis.is() )
840 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
841 for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
842 AxisHelper::makeGridVisible( aSubGrids[nN] );
843 aUndoGuard.commit();
846 catch(const uno::RuntimeException&)
848 TOOLS_WARN_EXCEPTION("chart2", "" );
852 void ChartController::executeDispatch_DeleteMinorGrid()
854 UndoGuard aUndoGuard(
855 ActionDescriptionProvider::createDescription(
856 ActionDescriptionProvider::ActionType::Delete, SchResId(STR_OBJECT_GRID)),
857 m_xUndoManager );
861 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
862 if( xAxis.is() )
864 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
865 for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
866 AxisHelper::makeGridInvisible( aSubGrids[nN] );
867 aUndoGuard.commit();
870 catch(const uno::RuntimeException&)
872 TOOLS_WARN_EXCEPTION("chart2", "" );
876 } //namespace chart
878 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */