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_InsertDataTable.hxx>
29 #include <dlg_ObjectProperties.hxx>
32 #include <AxisHelper.hxx>
33 #include <TitleHelper.hxx>
34 #include <DataSeries.hxx>
35 #include <Diagram.hxx>
36 #include <GridProperties.hxx>
37 #include <chartview/DrawModelWrapper.hxx>
38 #include <chartview/ChartSfxItemIds.hxx>
39 #include <NumberFormatterWrapper.hxx>
40 #include <ViewElementListProvider.hxx>
41 #include <MultipleChartConverters.hxx>
42 #include <ControllerLockGuard.hxx>
43 #include "UndoGuard.hxx"
45 #include <strings.hrc>
46 #include <ReferenceSizeProvider.hxx>
47 #include <ObjectIdentifier.hxx>
48 #include <RegressionCurveHelper.hxx>
49 #include <RegressionCurveItemConverter.hxx>
50 #include <StatisticsHelper.hxx>
51 #include <ErrorBarItemConverter.hxx>
52 #include <DataSeriesHelper.hxx>
53 #include <ObjectNameProvider.hxx>
55 #include <LegendHelper.hxx>
56 #include <DataTable.hxx>
57 #include <RegressionCurveModel.hxx>
59 #include <com/sun/star/chart2/XRegressionCurve.hpp>
60 #include <com/sun/star/chart/ErrorBarStyle.hpp>
61 #include <com/sun/star/beans/XPropertySet.hpp>
62 #include <svx/ActionDescriptionProvider.hxx>
64 #include <comphelper/diagnose_ex.hxx>
65 #include <vcl/svapp.hxx>
67 using namespace ::com::sun::star
;
68 using namespace ::com::sun::star::chart2
;
69 using ::com::sun::star::uno::Reference
;
74 void lcl_InsertMeanValueLine( const rtl::Reference
< ::chart::DataSeries
> & xSeries
)
78 ::chart::RegressionCurveHelper::addMeanValueLine(
83 } // anonymous namespace
88 void ChartController::executeDispatch_InsertAxes()
90 auto xUndoGuard
= std::make_shared
<UndoGuard
>(
91 ActionDescriptionProvider::createDescription(
92 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_AXES
)),
97 auto xDialogInput
= std::make_shared
<InsertAxisOrGridDialogData
>();
98 rtl::Reference
< Diagram
> xDiagram
= getFirstDiagram();
99 AxisHelper::getAxisOrGridExistence( xDialogInput
->aExistenceList
, xDiagram
);
100 AxisHelper::getAxisOrGridPossibilities( xDialogInput
->aPossibilityList
, xDiagram
);
102 SolarMutexGuard aGuard
;
103 auto aDlg
= std::make_shared
<SchAxisDlg
>(GetChartFrame(), *xDialogInput
);
104 weld::DialogController::runAsync(aDlg
, [this, aDlg
, xDialogInput
=std::move(xDialogInput
),
105 xUndoGuard
=std::move(xUndoGuard
)](int nResult
) {
106 if ( nResult
== RET_OK
)
108 // lock controllers till end of block
109 ControllerLockGuardUNO
aCLGuard( getChartModel() );
111 InsertAxisOrGridDialogData aDialogOutput
;
112 aDlg
->getResult(aDialogOutput
);
113 ReferenceSizeProvider
aRefSizeProvider(impl_createReferenceSizeProvider());
114 bool bChanged
= AxisHelper::changeVisibilityOfAxes( getFirstDiagram()
115 , xDialogInput
->aExistenceList
, aDialogOutput
.aExistenceList
, m_xCC
116 , &aRefSizeProvider
);
118 xUndoGuard
->commit();
122 catch(const uno::RuntimeException
&)
124 TOOLS_WARN_EXCEPTION("chart2", "" );
128 void ChartController::executeDispatch_InsertGrid()
130 UndoGuard
aUndoGuard(
131 ActionDescriptionProvider::createDescription(
132 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_GRIDS
)),
137 InsertAxisOrGridDialogData aDialogInput
;
138 rtl::Reference
< Diagram
> xDiagram
= getFirstDiagram();
139 AxisHelper::getAxisOrGridExistence( aDialogInput
.aExistenceList
, xDiagram
, false );
140 AxisHelper::getAxisOrGridPossibilities( aDialogInput
.aPossibilityList
, xDiagram
, false );
142 SolarMutexGuard aGuard
;
143 SchGridDlg
aDlg(GetChartFrame(), aDialogInput
);//aItemSet, b3D, bNet, bSecondaryX, bSecondaryY );
144 if (aDlg
.run() == RET_OK
)
146 // lock controllers till end of block
147 ControllerLockGuardUNO
aCLGuard( getChartModel() );
148 InsertAxisOrGridDialogData aDialogOutput
;
149 aDlg
.getResult( aDialogOutput
);
150 bool bChanged
= AxisHelper::changeVisibilityOfGrids( xDiagram
151 , aDialogInput
.aExistenceList
, aDialogOutput
.aExistenceList
);
156 catch(const uno::RuntimeException
&)
158 TOOLS_WARN_EXCEPTION("chart2", "" );
162 void ChartController::executeDispatch_OpenInsertDataTableDialog()
164 SolarMutexGuard aGuard
;
166 auto aUndoDescription
= ActionDescriptionProvider::createDescription(ActionDescriptionProvider::ActionType::Insert
, SchResId(STR_DATA_TABLE
));
167 UndoGuard
aUndoGuard(aUndoDescription
, m_xUndoManager
);
169 rtl::Reference
<Diagram
> xDiagram
= getFirstDiagram();
171 InsertDataTableDialog
aDialog(GetChartFrame());
174 DataTableDialogData aData
;
175 auto xDataTable
= xDiagram
->getDataTable();
176 aData
.mbShow
= xDataTable
.is();
179 uno::Reference
<beans::XPropertySet
> xProperties(xDataTable
, uno::UNO_QUERY
);
181 uno::Any aAny
= xProperties
->getPropertyValue(u
"HBorder"_ustr
);
182 if (aAny
.has
<bool>())
183 aData
.mbHorizontalBorders
= aAny
.get
<bool>();
185 aAny
= xProperties
->getPropertyValue(u
"VBorder"_ustr
);
186 if (aAny
.has
<bool>())
187 aData
.mbVerticalBorders
= aAny
.get
<bool>();
189 aAny
= xProperties
->getPropertyValue(u
"Outline"_ustr
);
190 if (aAny
.has
<bool>())
191 aData
.mbOutline
= aAny
.get
<bool>();
193 aAny
= xProperties
->getPropertyValue(u
"Keys"_ustr
);
194 if (aAny
.has
<bool>())
195 aData
.mbKeys
= aAny
.get
<bool>();
201 if (aDialog
.run() == RET_OK
)
203 bool bChanged
= false;
205 auto& rDialogData
= aDialog
.getDataTableDialogData();
206 auto xDataTable
= xDiagram
->getDataTable();
207 if (!rDialogData
.mbShow
&& xDataTable
.is())
209 xDiagram
->setDataTable(uno::Reference
<chart2::XDataTable
>());
212 else if (rDialogData
.mbShow
&& !xDataTable
.is())
214 uno::Reference
<chart2::XDataTable
> xNewDataTable(new DataTable
);
215 if (xNewDataTable
.is())
217 xDiagram
->setDataTable(xNewDataTable
);
222 // Set the properties
223 xDataTable
= xDiagram
->getDataTable();
224 if (rDialogData
.mbShow
&& xDataTable
.is())
226 uno::Reference
<beans::XPropertySet
> xProperties(xDataTable
, uno::UNO_QUERY
);
227 xProperties
->setPropertyValue(u
"HBorder"_ustr
, uno::Any(rDialogData
.mbHorizontalBorders
));
228 xProperties
->setPropertyValue(u
"VBorder"_ustr
, uno::Any(rDialogData
.mbVerticalBorders
));
229 xProperties
->setPropertyValue(u
"Outline"_ustr
, uno::Any(rDialogData
.mbOutline
));
230 xProperties
->setPropertyValue(u
"Keys"_ustr
, uno::Any(rDialogData
.mbKeys
));
239 /** Create and insert a data table to the chart */
240 void ChartController::executeDispatch_InsertDataTable()
242 auto aUndoDescription
= ActionDescriptionProvider::createDescription(ActionDescriptionProvider::ActionType::Insert
, SchResId(STR_DATA_TABLE
));
243 UndoGuard
aUndoGuard(aUndoDescription
, m_xUndoManager
);
246 rtl::Reference
<Diagram
> xDiagram
= getFirstDiagram();
247 auto xDataTable
= xDiagram
->getDataTable();
248 if (!xDataTable
.is())
250 uno::Reference
<chart2::XDataTable
> xNewDataTable(new DataTable
);
251 if (xNewDataTable
.is())
253 xDiagram
->setDataTable(xNewDataTable
);
259 /** Delete a data table from the chart */
260 void ChartController::executeDispatch_DeleteDataTable()
262 auto aUndoDescription
= ActionDescriptionProvider::createDescription(ActionDescriptionProvider::ActionType::Delete
, SchResId(STR_DATA_TABLE
));
263 UndoGuard
aUndoGuard(aUndoDescription
, m_xUndoManager
);
265 rtl::Reference
<Diagram
> xDiagram
= getFirstDiagram();
266 auto xDataTable
= xDiagram
->getDataTable();
269 // insert a empty data table reference
270 xDiagram
->setDataTable(uno::Reference
<chart2::XDataTable
>());
275 void ChartController::executeDispatch_InsertTitles()
277 auto xUndoGuard
= std::make_shared
<UndoGuard
>(
278 ActionDescriptionProvider::createDescription(
279 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_TITLES
)),
284 auto xDialogInput
= std::make_shared
<TitleDialogData
>();
285 xDialogInput
->readFromModel( getChartModel() );
287 SolarMutexGuard aGuard
;
288 auto aDlg
= std::make_shared
<SchTitleDlg
>(GetChartFrame(), *xDialogInput
);
289 weld::DialogController::runAsync(aDlg
, [this, aDlg
, xDialogInput
=std::move(xDialogInput
),
290 xUndoGuard
=std::move(xUndoGuard
)](int nResult
){
291 if ( nResult
== RET_OK
)
293 // lock controllers till end of block
294 ControllerLockGuardUNO
aCLGuard( getChartModel() );
295 TitleDialogData
aDialogOutput( impl_createReferenceSizeProvider() );
296 aDlg
->getResult( aDialogOutput
);
297 bool bChanged
= aDialogOutput
.writeDifferenceToModel( getChartModel(), m_xCC
, xDialogInput
.get() );
299 xUndoGuard
->commit();
303 catch(const uno::RuntimeException
&)
305 TOOLS_WARN_EXCEPTION("chart2", "" );
309 void ChartController::executeDispatch_DeleteLegend()
311 UndoGuard
aUndoGuard(
312 ActionDescriptionProvider::createDescription(
313 ActionDescriptionProvider::ActionType::Delete
, SchResId( STR_OBJECT_LEGEND
)),
316 LegendHelper::hideLegend(*getChartModel());
320 void ChartController::executeDispatch_InsertLegend()
322 UndoGuard
aUndoGuard(
323 ActionDescriptionProvider::createDescription(
324 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_LEGEND
)),
327 LegendHelper::showLegend(*getChartModel(), m_xCC
);
331 void ChartController::executeDispatch_OpenLegendDialog()
333 UndoGuard
aUndoGuard(
334 ActionDescriptionProvider::createDescription(
335 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_LEGEND
)),
340 //prepare and open dialog
341 SolarMutexGuard aGuard
;
342 SchLegendDlg
aDlg(GetChartFrame(), m_xCC
);
343 aDlg
.init( getChartModel() );
344 if (aDlg
.run() == RET_OK
)
346 // lock controllers till end of block
347 ControllerLockGuardUNO
aCLGuard( getChartModel() );
348 aDlg
.writeToModel( getChartModel() );
352 catch(const uno::RuntimeException
&)
354 TOOLS_WARN_EXCEPTION("chart2", "" );
358 void ChartController::executeDispatch_InsertMenu_DataLabels()
360 std::shared_ptr
<UndoGuard
> aUndoGuard
= std::make_shared
<UndoGuard
>(
361 ActionDescriptionProvider::createDescription(
362 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_DATALABELS
)),
365 //if a series is selected insert labels for that series only:
366 rtl::Reference
< DataSeries
> xSeries
=
367 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getChartModel());
371 DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries
);
373 OUString
aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS
) + "=" );
374 OUString aObjectCID
= ObjectIdentifier::createClassifiedIdentifierForParticles(
375 ObjectIdentifier::getSeriesParticleFromCID(m_aSelection
.getSelectedCID()), aChildParticle
);
377 ChartController::executeDlg_ObjectProperties_withUndoGuard( aUndoGuard
, aObjectCID
, true );
382 wrapper::AllDataLabelItemConverter
aItemConverter(
384 m_pDrawModelWrapper
->GetItemPool(),
385 m_pDrawModelWrapper
->getSdrModel(),
387 SfxItemSet aItemSet
= aItemConverter
.CreateEmptyItemSet();
388 aItemConverter
.FillItemSet( aItemSet
);
390 //prepare and open dialog
391 SolarMutexGuard aGuard
;
393 //get number formatter
394 NumberFormatterWrapper
aNumberFormatterWrapper( getChartModel() );
395 SvNumberFormatter
* pNumberFormatter
= aNumberFormatterWrapper
.getSvNumberFormatter();
397 DataLabelsDialog
aDlg(GetChartFrame(), aItemSet
, pNumberFormatter
);
399 if (aDlg
.run() == RET_OK
)
401 SfxItemSet aOutItemSet
= aItemConverter
.CreateEmptyItemSet();
402 aDlg
.FillItemSet(aOutItemSet
);
403 // lock controllers till end of block
404 ControllerLockGuardUNO
aCLGuard( getChartModel() );
405 bool bChanged
= aItemConverter
.ApplyItemSet( aOutItemSet
);//model should be changed now
407 aUndoGuard
->commit();
410 catch(const uno::RuntimeException
&)
412 TOOLS_WARN_EXCEPTION("chart2", "" );
416 void ChartController::executeDispatch_InsertMeanValue()
418 UndoGuard
aUndoGuard(
419 ActionDescriptionProvider::createDescription(
420 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_AVERAGE_LINE
)),
422 lcl_InsertMeanValueLine( ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(),
427 void ChartController::executeDispatch_InsertMenu_MeanValues()
429 UndoGuard
aUndoGuard(
430 ActionDescriptionProvider::createDescription(
431 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_AVERAGE_LINE
)),
434 rtl::Reference
< DataSeries
> xSeries
=
435 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getChartModel() );
438 //if a series is selected insert mean value only for that series:
439 lcl_InsertMeanValueLine( xSeries
);
441 else if (rtl::Reference
<Diagram
> xDiagram
= getFirstDiagram())
443 std::vector
< rtl::Reference
< DataSeries
> > aSeries
=
444 xDiagram
->getDataSeries();
446 for( const auto& xSrs
: aSeries
)
447 lcl_InsertMeanValueLine( xSrs
);
452 void ChartController::executeDispatch_InsertMenu_Trendlines()
454 OUString aCID
= m_aSelection
.getSelectedCID();
456 rtl::Reference
< DataSeries
> xSeries
=
457 ObjectIdentifier::getDataSeriesForCID( aCID
, getChartModel() );
462 executeDispatch_InsertTrendline();
465 void ChartController::executeDispatch_InsertTrendline()
467 rtl::Reference
< DataSeries
> xRegressionCurveContainer
=
468 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getChartModel());
470 if( !xRegressionCurveContainer
.is() )
473 auto xUndoGuard
= std::make_shared
<UndoLiveUpdateGuard
>(
474 ActionDescriptionProvider::createDescription(
475 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_CURVE
)),
478 rtl::Reference
< RegressionCurveModel
> xCurve
=
479 RegressionCurveHelper::addRegressionCurve(
480 SvxChartRegress::Linear
,
481 xRegressionCurveContainer
);
486 auto aItemConverter
= std::make_shared
<wrapper::RegressionCurveItemConverter
>(
487 xCurve
, xRegressionCurveContainer
, m_pDrawModelWrapper
->getSdrModel().GetItemPool(),
488 m_pDrawModelWrapper
->getSdrModel(),
492 SfxItemSet aItemSet
= aItemConverter
->CreateEmptyItemSet();
493 aItemConverter
->FillItemSet( aItemSet
);
494 ObjectPropertiesDialogParameter
aDialogParameter(
495 ObjectIdentifier::createDataCurveCID(
496 ObjectIdentifier::getSeriesParticleFromCID( m_aSelection
.getSelectedCID()),
497 RegressionCurveHelper::getRegressionCurveIndex( xRegressionCurveContainer
, xCurve
), false ));
498 aDialogParameter
.init( getChartModel() );
499 ViewElementListProvider
aViewElementListProvider( m_pDrawModelWrapper
.get());
500 SolarMutexGuard aGuard
;
501 auto aDialog
= std::make_shared
<SchAttribTabDlg
>(GetChartFrame(), &aItemSet
, &aDialogParameter
,
502 &aViewElementListProvider
, getChartModel());
504 // note: when a user pressed "OK" but didn't change any settings in the
505 // dialog, the SfxTabDialog returns "Cancel"
506 SfxTabDialogController::runAsync(aDialog
, [this, aDialog
, aItemConverter
= std::move(aItemConverter
),
507 xUndoGuard
=std::move(xUndoGuard
)](int nResult
) {
508 if ( nResult
== RET_OK
|| aDialog
->DialogWasClosedWithOK() )
510 const SfxItemSet
* pOutItemSet
= aDialog
->GetOutputItemSet();
513 ControllerLockGuardUNO
aCLGuard( getChartModel() );
514 aItemConverter
->ApplyItemSet( *pOutItemSet
);
516 xUndoGuard
->commit();
521 void ChartController::executeDispatch_InsertErrorBars( bool bYError
)
523 ObjectType objType
= bYError
? OBJECTTYPE_DATA_ERRORS_Y
: OBJECTTYPE_DATA_ERRORS_X
;
525 //if a series is selected insert error bars for that series only:
526 rtl::Reference
< DataSeries
> xSeries
=
527 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getChartModel() );
531 auto xUndoGuard
= std::make_shared
<UndoLiveUpdateGuard
>(
532 ActionDescriptionProvider::createDescription(
533 ActionDescriptionProvider::ActionType::Insert
,
534 SchResId( bYError
? STR_OBJECT_ERROR_BARS_Y
: STR_OBJECT_ERROR_BARS_X
)),
537 // add error bars with standard deviation
538 uno::Reference
< beans::XPropertySet
> xErrorBarProp(
539 StatisticsHelper::addErrorBars( xSeries
,
540 css::chart::ErrorBarStyle::STANDARD_DEVIATION
,
543 // get an appropriate item converter
544 auto aItemConverter
= std::make_shared
<wrapper::ErrorBarItemConverter
> (
545 getChartModel(), xErrorBarProp
, m_pDrawModelWrapper
->getSdrModel().GetItemPool(),
546 m_pDrawModelWrapper
->getSdrModel(),
550 SfxItemSet aItemSet
= aItemConverter
->CreateEmptyItemSet();
551 aItemSet
.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE
,bYError
));
552 aItemConverter
->FillItemSet( aItemSet
);
553 ObjectPropertiesDialogParameter
aDialogParameter(
554 ObjectIdentifier::createClassifiedIdentifierWithParent(
555 objType
, u
"", m_aSelection
.getSelectedCID()));
556 aDialogParameter
.init( getChartModel() );
557 ViewElementListProvider
aViewElementListProvider( m_pDrawModelWrapper
.get());
558 SolarMutexGuard aGuard
;
559 auto aDlg
= std::make_shared
<SchAttribTabDlg
>(
560 GetChartFrame(), &aItemSet
, &aDialogParameter
,
561 &aViewElementListProvider
,
563 aDlg
->SetAxisMinorStepWidthForErrorBarDecimals(
564 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getChartModel(),
565 m_xChartView
, m_aSelection
.getSelectedCID()));
567 // note: when a user pressed "OK" but didn't change any settings in the
568 // dialog, the SfxTabDialog returns "Cancel"
569 SfxTabDialogController::runAsync(aDlg
, [this, aDlg
, aItemConverter
=std::move(aItemConverter
),
570 xUndoGuard
=std::move(xUndoGuard
)](int nResult
) {
571 if ( nResult
== RET_OK
|| aDlg
->DialogWasClosedWithOK() )
573 const SfxItemSet
* pOutItemSet
= aDlg
->GetOutputItemSet();
576 ControllerLockGuardUNO
aCLGuard( getChartModel() );
577 aItemConverter
->ApplyItemSet( *pOutItemSet
);
579 xUndoGuard
->commit();
585 //if no series is selected insert error bars for all series
586 auto xUndoGuard
= std::make_shared
<UndoGuard
>(
587 ActionDescriptionProvider::createDescription(
588 ActionDescriptionProvider::ActionType::Insert
,
589 ObjectNameProvider::getName_ObjectForAllSeries( objType
) ),
594 auto xItemConverter
= std::make_shared
<wrapper::AllSeriesStatisticsConverter
>(
595 getChartModel(), m_pDrawModelWrapper
->GetItemPool() );
596 SfxItemSet aItemSet
= xItemConverter
->CreateEmptyItemSet();
597 xItemConverter
->FillItemSet( aItemSet
);
599 //prepare and open dialog
600 SolarMutexGuard aGuard
;
601 auto aDlg
= std::make_shared
<InsertErrorBarsDialog
>(
602 GetChartFrame(), aItemSet
,
604 bYError
? ErrorBarResources::ERROR_BAR_Y
: ErrorBarResources::ERROR_BAR_X
);
606 aDlg
->SetAxisMinorStepWidthForErrorBarDecimals(
607 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getChartModel(), m_xChartView
, u
"" ) );
609 weld::DialogController::runAsync(aDlg
, [this, aDlg
, xItemConverter
=std::move(xItemConverter
),
610 xUndoGuard
=std::move(xUndoGuard
)](int nResult
) {
611 if ( nResult
== RET_OK
)
613 SfxItemSet aOutItemSet
= xItemConverter
->CreateEmptyItemSet();
614 aDlg
->FillItemSet( aOutItemSet
);
616 // lock controllers till end of block
617 ControllerLockGuardUNO
aCLGuard( getChartModel() );
618 bool bChanged
= xItemConverter
->ApplyItemSet( aOutItemSet
);//model should be changed now
620 xUndoGuard
->commit();
624 catch(const uno::RuntimeException
&)
626 TOOLS_WARN_EXCEPTION("chart2", "" );
631 void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2
)
633 uno::Reference
< chart2::XRegressionCurve
> xRegCurve(
634 ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), getChartModel() ), uno::UNO_QUERY
);
635 if( !xRegCurve
.is() )
637 rtl::Reference
< DataSeries
> xRegCurveCnt
=
638 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getChartModel() );
639 xRegCurve
.set( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt
) );
644 uno::Reference
< beans::XPropertySet
> xEqProp( xRegCurve
->getEquationProperties());
647 UndoGuard
aUndoGuard(
648 ActionDescriptionProvider::createDescription(
649 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_CURVE_EQUATION
)),
651 xEqProp
->setPropertyValue( u
"ShowEquation"_ustr
, uno::Any( true ));
652 xEqProp
->setPropertyValue( u
"XName"_ustr
, uno::Any( u
"x"_ustr
));
653 xEqProp
->setPropertyValue( u
"YName"_ustr
, uno::Any( u
"f(x)"_ustr
));
654 xEqProp
->setPropertyValue( u
"ShowCorrelationCoefficient"_ustr
, uno::Any( bInsertR2
));
659 void ChartController::executeDispatch_InsertR2Value()
661 uno::Reference
< beans::XPropertySet
> xEqProp
=
662 ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), getChartModel() );
665 UndoGuard
aUndoGuard(
666 ActionDescriptionProvider::createDescription(
667 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_CURVE_EQUATION
)),
669 xEqProp
->setPropertyValue( u
"ShowCorrelationCoefficient"_ustr
, uno::Any( true ));
674 void ChartController::executeDispatch_DeleteR2Value()
676 uno::Reference
< beans::XPropertySet
> xEqProp
=
677 ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), getChartModel() );
680 UndoGuard
aUndoGuard(
681 ActionDescriptionProvider::createDescription(
682 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_CURVE_EQUATION
)),
684 xEqProp
->setPropertyValue( u
"ShowCorrelationCoefficient"_ustr
, uno::Any( false ));
689 void ChartController::executeDispatch_DeleteMeanValue()
691 rtl::Reference
< DataSeries
> xRegCurveCnt
=
692 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getChartModel() );
693 if( xRegCurveCnt
.is())
695 UndoGuard
aUndoGuard(
696 ActionDescriptionProvider::createDescription(
697 ActionDescriptionProvider::ActionType::Delete
, SchResId( STR_OBJECT_AVERAGE_LINE
)),
699 RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt
);
704 void ChartController::executeDispatch_DeleteTrendline()
706 rtl::Reference
< DataSeries
> xRegCurveCnt
=
707 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getChartModel() );
708 if( xRegCurveCnt
.is())
710 UndoGuard
aUndoGuard(
711 ActionDescriptionProvider::createDescription(
712 ActionDescriptionProvider::ActionType::Delete
, SchResId( STR_OBJECT_CURVE
)),
714 RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt
);
719 void ChartController::executeDispatch_DeleteTrendlineEquation()
721 rtl::Reference
< DataSeries
> xRegCurveCnt
=
722 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getChartModel() );
723 if( xRegCurveCnt
.is())
725 UndoGuard
aUndoGuard(
726 ActionDescriptionProvider::createDescription(
727 ActionDescriptionProvider::ActionType::Delete
, SchResId( STR_OBJECT_CURVE_EQUATION
)),
729 RegressionCurveHelper::removeEquations( xRegCurveCnt
);
734 void ChartController::executeDispatch_DeleteErrorBars( bool bYError
)
736 rtl::Reference
< DataSeries
> xDataSeries
=
737 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getChartModel() );
738 if( xDataSeries
.is())
740 UndoGuard
aUndoGuard(
741 ActionDescriptionProvider::createDescription(
742 ActionDescriptionProvider::ActionType::Delete
, SchResId( STR_OBJECT_CURVE
)),
744 StatisticsHelper::removeErrorBars( xDataSeries
, bYError
);
749 void ChartController::executeDispatch_InsertDataLabels()
751 rtl::Reference
< DataSeries
> xSeries
=
752 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getChartModel() );
755 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert
,
756 SchResId( STR_OBJECT_DATALABELS
)),
758 DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries
);
763 void ChartController::executeDispatch_InsertDataLabel()
765 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert
,
766 SchResId( STR_OBJECT_LABEL
)),
768 DataSeriesHelper::insertDataLabelToPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), getChartModel() ) );
772 void ChartController::executeDispatch_DeleteDataLabels()
774 rtl::Reference
< DataSeries
> xSeries
=
775 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getChartModel() );
778 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete
,
779 SchResId( STR_OBJECT_DATALABELS
)),
781 DataSeriesHelper::deleteDataLabelsFromSeriesAndAllPoints( xSeries
);
786 void ChartController::executeDispatch_DeleteDataLabel()
788 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete
,
789 SchResId( STR_OBJECT_LABEL
)),
791 DataSeriesHelper::deleteDataLabelsFromPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), getChartModel() ) );
795 void ChartController::executeDispatch_ResetAllDataPoints()
797 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Format
,
798 SchResId( STR_OBJECT_DATAPOINTS
)),
800 rtl::Reference
< DataSeries
> xSeries
= ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getChartModel() );
802 xSeries
->resetAllDataPoints();
805 void ChartController::executeDispatch_ResetDataPoint()
807 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Format
,
808 SchResId( STR_OBJECT_DATAPOINT
)),
810 rtl::Reference
< DataSeries
> xSeries
= ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), getChartModel() );
813 sal_Int32 nPointIndex
= ObjectIdentifier::getIndexFromParticleOrCID( m_aSelection
.getSelectedCID() );
814 xSeries
->resetDataPoint( nPointIndex
);
819 void ChartController::executeDispatch_InsertAxisTitle()
823 rtl::Reference
< Title
> xTitle
;
825 UndoGuard
aUndoGuard(
826 ActionDescriptionProvider::createDescription(
827 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_TITLE
)),
830 rtl::Reference
< Axis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), getChartModel() );
831 sal_Int32 nDimensionIndex
= -1;
832 sal_Int32 nCooSysIndex
= -1;
833 sal_Int32 nAxisIndex
= -1;
834 AxisHelper::getIndicesForAxis( xAxis
, getFirstDiagram(), nCooSysIndex
, nDimensionIndex
, nAxisIndex
);
836 TitleHelper::eTitleType eTitleType
= TitleHelper::X_AXIS_TITLE
;
837 if( nDimensionIndex
==0 )
838 eTitleType
= nAxisIndex
==0 ? TitleHelper::X_AXIS_TITLE
: TitleHelper::SECONDARY_X_AXIS_TITLE
;
839 else if( nDimensionIndex
==1 )
840 eTitleType
= nAxisIndex
==0 ? TitleHelper::Y_AXIS_TITLE
: TitleHelper::SECONDARY_Y_AXIS_TITLE
;
842 eTitleType
= TitleHelper::Z_AXIS_TITLE
;
844 ReferenceSizeProvider
aRefSizeProvider( impl_createReferenceSizeProvider());
845 xTitle
= TitleHelper::createTitle( eTitleType
, ObjectNameProvider::getTitleNameByType(eTitleType
), getChartModel(), m_xCC
, &aRefSizeProvider
);
849 catch(const uno::RuntimeException
&)
851 TOOLS_WARN_EXCEPTION("chart2", "" );
855 void ChartController::executeDispatch_InsertAxis()
857 UndoGuard
aUndoGuard(
858 ActionDescriptionProvider::createDescription(
859 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_AXIS
)),
864 rtl::Reference
< Axis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), getChartModel() );
867 AxisHelper::makeAxisVisible( xAxis
);
871 catch(const uno::RuntimeException
&)
873 TOOLS_WARN_EXCEPTION("chart2", "" );
877 void ChartController::executeDispatch_DeleteAxis()
879 UndoGuard
aUndoGuard(
880 ActionDescriptionProvider::createDescription(
881 ActionDescriptionProvider::ActionType::Delete
, SchResId( STR_OBJECT_AXIS
)),
886 rtl::Reference
< Axis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), getChartModel() );
889 AxisHelper::makeAxisInvisible( xAxis
);
893 catch(const uno::RuntimeException
&)
895 TOOLS_WARN_EXCEPTION("chart2", "" );
899 void ChartController::executeDispatch_InsertMajorGrid()
901 UndoGuard
aUndoGuard(
902 ActionDescriptionProvider::createDescription(
903 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_GRID
)),
908 rtl::Reference
< Axis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), getChartModel() );
911 AxisHelper::makeGridVisible( xAxis
->getGridProperties2() );
915 catch(const uno::RuntimeException
&)
917 TOOLS_WARN_EXCEPTION("chart2", "" );
921 void ChartController::executeDispatch_DeleteMajorGrid()
923 UndoGuard
aUndoGuard(
924 ActionDescriptionProvider::createDescription(
925 ActionDescriptionProvider::ActionType::Delete
, SchResId( STR_OBJECT_GRID
)),
930 rtl::Reference
< Axis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), getChartModel() );
933 AxisHelper::makeGridInvisible( xAxis
->getGridProperties2() );
937 catch(const uno::RuntimeException
&)
939 TOOLS_WARN_EXCEPTION("chart2", "" );
943 void ChartController::executeDispatch_InsertMinorGrid()
945 UndoGuard
aUndoGuard(
946 ActionDescriptionProvider::createDescription(
947 ActionDescriptionProvider::ActionType::Insert
, SchResId( STR_OBJECT_GRID
)),
952 rtl::Reference
< Axis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), getChartModel() );
955 std::vector
< rtl::Reference
< ::chart::GridProperties
> > aSubGrids( xAxis
->getSubGridProperties2() );
956 for( rtl::Reference
< GridProperties
> const & props
: aSubGrids
)
957 AxisHelper::makeGridVisible( props
);
961 catch(const uno::RuntimeException
&)
963 TOOLS_WARN_EXCEPTION("chart2", "" );
967 void ChartController::executeDispatch_DeleteMinorGrid()
969 UndoGuard
aUndoGuard(
970 ActionDescriptionProvider::createDescription(
971 ActionDescriptionProvider::ActionType::Delete
, SchResId(STR_OBJECT_GRID
)),
976 rtl::Reference
< Axis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), getChartModel() );
979 std::vector
< rtl::Reference
< ::chart::GridProperties
> > aSubGrids( xAxis
->getSubGridProperties2() );
980 for( rtl::Reference
< ::chart::GridProperties
> const & props
: aSubGrids
)
981 AxisHelper::makeGridInvisible( props
);
985 catch(const uno::RuntimeException
&)
987 TOOLS_WARN_EXCEPTION("chart2", "" );
993 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */