1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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"
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
;
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
88 void ChartController::executeDispatch_InsertAxes()
91 ActionDescriptionProvider::createDescription(
92 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_AXES
)),
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() );
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
)),
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
);
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
)),
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
);
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
)),
198 ChartModel
& rModel
= dynamic_cast<ChartModel
&>(*getModel());
199 LegendHelper::hideLegend(rModel
);
203 void ChartController::executeDispatch_InsertLegend()
205 UndoGuard
aUndoGuard(
206 ActionDescriptionProvider::createDescription(
207 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_LEGEND
)),
210 ChartModel
& rModel
= dynamic_cast<ChartModel
&>(*getModel());
211 Reference
< chart2::XLegend
> xLegend
= LegendHelper::showLegend(rModel
, m_xCC
);
215 void ChartController::executeDispatch_OpenLegendDialog()
217 UndoGuard
aUndoGuard(
218 ActionDescriptionProvider::createDescription(
219 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_LEGEND
)),
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() );
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
)),
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());
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 );
269 wrapper::AllDataLabelItemConverter
aItemConverter(
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
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
)),
310 lcl_InsertMeanValueLine( ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(),
315 void ChartController::executeDispatch_InsertMenu_MeanValues()
317 UndoGuard
aUndoGuard(
318 ActionDescriptionProvider::createDescription(
319 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_AVERAGE_LINE
)),
322 uno::Reference
< chart2::XDataSeries
> xSeries
=
323 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getModel() );
326 //if a series is selected insert mean value only for that series:
327 lcl_InsertMeanValueLine( xSeries
);
331 std::vector
< uno::Reference
< chart2::XDataSeries
> > aSeries(
332 DiagramHelper::getDataSeriesFromDiagram( ChartModelHelper::findDiagram( getModel() )));
334 for( const auto& xSrs
: aSeries
)
335 lcl_InsertMeanValueLine( xSrs
);
340 void ChartController::executeDispatch_InsertMenu_Trendlines()
342 OUString aCID
= m_aSelection
.getSelectedCID();
344 uno::Reference
< chart2::XDataSeries
> xSeries
=
345 ObjectIdentifier::getDataSeriesForCID( aCID
, getModel() );
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() )
361 UndoLiveUpdateGuard
aUndoGuard(
362 ActionDescriptionProvider::createDescription(
363 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_CURVE
)),
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())
376 wrapper::RegressionCurveItemConverter
aItemConverter(
377 xProperties
, xRegressionCurveContainer
, m_pDrawModelWrapper
->getSdrModel().GetItemPool(),
378 m_pDrawModelWrapper
->getSdrModel(),
379 uno::Reference
< lang::XMultiServiceFactory
>( getModel(), uno::UNO_QUERY
));
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();
404 ControllerLockGuardUNO
aCLGuard( getModel() );
405 aItemConverter
.ApplyItemSet( *pOutItemSet
);
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() );
421 UndoLiveUpdateGuard
aUndoGuard(
422 ActionDescriptionProvider::createDescription(
423 ActionDescriptionProvider::ActionType::Insert
,
424 SchResId( bYError
? STR_OBJECT_ERROR_BARS_Y
: STR_OBJECT_ERROR_BARS_X
)),
427 // add error bars with standard deviation
428 uno::Reference
< beans::XPropertySet
> xErrorBarProp(
429 StatisticsHelper::addErrorBars( xSeries
,
430 css::chart::ErrorBarStyle::STANDARD_DEVIATION
,
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
));
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();
465 ControllerLockGuardUNO
aCLGuard( getModel() );
466 aItemConverter
.ApplyItemSet( *pOutItemSet
);
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
) ),
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
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
) );
528 uno::Reference
< beans::XPropertySet
> xEqProp( xRegCurve
->getEquationProperties());
531 UndoGuard
aUndoGuard(
532 ActionDescriptionProvider::createDescription(
533 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_CURVE_EQUATION
)),
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
));
544 void ChartController::executeDispatch_InsertR2Value()
546 uno::Reference
< beans::XPropertySet
> xEqProp
=
547 ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), getModel() );
550 UndoGuard
aUndoGuard(
551 ActionDescriptionProvider::createDescription(
552 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_CURVE_EQUATION
)),
554 xEqProp
->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( true ));
559 void ChartController::executeDispatch_DeleteR2Value()
561 uno::Reference
< beans::XPropertySet
> xEqProp
=
562 ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), getModel() );
565 UndoGuard
aUndoGuard(
566 ActionDescriptionProvider::createDescription(
567 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_CURVE_EQUATION
)),
569 xEqProp
->setPropertyValue( "ShowCorrelationCoefficient", uno::Any( false ));
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
)),
584 RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt
);
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
)),
599 RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt
);
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
)),
614 RegressionCurveHelper::removeEquations( xRegCurveCnt
);
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
)),
629 StatisticsHelper::removeErrorBars( xDataSeries
, bYError
);
634 void ChartController::executeDispatch_InsertDataLabels()
636 uno::Reference
< chart2::XDataSeries
> xSeries
=
637 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getModel() );
640 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert
,
641 SchResId( STR_OBJECT_DATALABELS
)),
643 DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries
);
648 void ChartController::executeDispatch_InsertDataLabel()
650 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert
,
651 SchResId( STR_OBJECT_LABEL
)),
653 DataSeriesHelper::insertDataLabelToPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), getModel() ) );
657 void ChartController::executeDispatch_DeleteDataLabels()
659 uno::Reference
< chart2::XDataSeries
> xSeries
=
660 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getModel() );
663 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete
,
664 SchResId( STR_OBJECT_DATALABELS
)),
666 DataSeriesHelper::deleteDataLabelsFromSeriesAndAllPoints( xSeries
);
671 void ChartController::executeDispatch_DeleteDataLabel()
673 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete
,
674 SchResId( STR_OBJECT_LABEL
)),
676 DataSeriesHelper::deleteDataLabelsFromPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), getModel() ) );
680 void ChartController::executeDispatch_ResetAllDataPoints()
682 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Format
,
683 SchResId( STR_OBJECT_DATAPOINTS
)),
685 uno::Reference
< chart2::XDataSeries
> xSeries
= ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getModel() );
687 xSeries
->resetAllDataPoints();
690 void ChartController::executeDispatch_ResetDataPoint()
692 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Format
,
693 SchResId( STR_OBJECT_DATAPOINT
)),
695 uno::Reference
< chart2::XDataSeries
> xSeries
= ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getModel() );
698 sal_Int32 nPointIndex
= ObjectIdentifier::getIndexFromParticleOrCID( m_aSelection
.getSelectedCID() );
699 xSeries
->resetDataPoint( nPointIndex
);
704 void ChartController::executeDispatch_InsertAxisTitle()
708 uno::Reference
< XTitle
> xTitle
;
710 UndoGuard
aUndoGuard(
711 ActionDescriptionProvider::createDescription(
712 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_TITLE
)),
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
;
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() );
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
)),
749 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), getModel() );
752 AxisHelper::makeAxisVisible( xAxis
);
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
)),
771 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), getModel() );
774 AxisHelper::makeAxisInvisible( xAxis
);
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
)),
793 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), getModel() );
796 AxisHelper::makeGridVisible( xAxis
->getGridProperties() );
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
)),
815 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), getModel() );
818 AxisHelper::makeGridInvisible( xAxis
->getGridProperties() );
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
)),
837 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), getModel() );
840 Sequence
< Reference
< beans::XPropertySet
> > aSubGrids( xAxis
->getSubGridProperties() );
841 for( sal_Int32 nN
=0; nN
<aSubGrids
.getLength(); nN
++)
842 AxisHelper::makeGridVisible( aSubGrids
[nN
] );
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
)),
861 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), getModel() );
864 Sequence
< Reference
< beans::XPropertySet
> > aSubGrids( xAxis
->getSubGridProperties() );
865 for( sal_Int32 nN
=0; nN
<aSubGrids
.getLength(); nN
++)
866 AxisHelper::makeGridInvisible( aSubGrids
[nN
] );
870 catch(const uno::RuntimeException
&)
872 TOOLS_WARN_EXCEPTION("chart2", "" );
878 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */