1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChartController_Insert.cxx,v $
10 * $Revision: 1.16.44.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "ChartController.hxx"
35 #include "dlg_InsertAxis_Grid.hxx"
36 #include "dlg_InsertDataLabel.hxx"
37 #include "dlg_InsertLegend.hxx"
38 #include "dlg_InsertTrendline.hxx"
39 #include "dlg_InsertErrorBars.hxx"
40 #include "dlg_InsertTitle.hxx"
41 #include "dlg_ObjectProperties.hxx"
43 #include "ChartWindow.hxx"
44 #include "ChartModelHelper.hxx"
45 #include "AxisHelper.hxx"
46 #include "TitleHelper.hxx"
47 #include "DiagramHelper.hxx"
49 #include "chartview/DrawModelWrapper.hxx"
50 #include "chartview/NumberFormatterWrapper.hxx"
51 #include "ViewElementListProvider.hxx"
52 #include "MultipleChartConverters.hxx"
53 #include "ControllerLockGuard.hxx"
54 #include "UndoGuard.hxx"
56 #include "Strings.hrc"
57 #include "ReferenceSizeProvider.hxx"
58 #include "ObjectIdentifier.hxx"
59 #include "RegressionCurveHelper.hxx"
60 #include "RegressionCurveItemConverter.hxx"
61 #include "StatisticsHelper.hxx"
62 #include "ErrorBarItemConverter.hxx"
63 #include "MultipleItemConverter.hxx"
64 #include "DataSeriesHelper.hxx"
65 #include "ObjectNameProvider.hxx"
66 #include "LegendHelper.hxx"
68 #include <com/sun/star/chart2/XRegressionCurve.hpp>
69 #include <com/sun/star/chart/ErrorBarStyle.hpp>
70 #include <svx/ActionDescriptionProvider.hxx>
72 //--------------------------------------
74 // header for define RET_OK
75 #include <vcl/msgbox.hxx>
76 // header for class OUStringBuffer
77 #include <rtl/ustrbuf.hxx>
78 // header for class Application
79 #include <vcl/svapp.hxx>
80 // header for class ::vos::OGuard
81 #include <vos/mutex.hxx>
84 using namespace ::com::sun::star
;
85 using namespace ::com::sun::star::chart2
;
86 using ::com::sun::star::uno::Reference
;
87 using ::com::sun::star::uno::Sequence
;
88 using ::rtl::OUString
;
90 //.............................................................................
94 struct lcl_InsertMeanValueLine
97 lcl_InsertMeanValueLine( const uno::Reference
< uno::XComponentContext
> & xContext
) :
98 m_xContext( xContext
)
101 void operator()( const uno::Reference
< chart2::XDataSeries
> & xSeries
)
103 uno::Reference
< chart2::XRegressionCurveContainer
> xRegCurveCnt(
104 xSeries
, uno::UNO_QUERY
);
105 if( xRegCurveCnt
.is())
107 ::chart::RegressionCurveHelper::addMeanValueLine(
108 xRegCurveCnt
, m_xContext
, uno::Reference
< beans::XPropertySet
>( xSeries
, uno::UNO_QUERY
));
113 uno::Reference
< uno::XComponentContext
> m_xContext
;
116 } // anonymous namespace
118 //.............................................................................
121 //.............................................................................
123 void ChartController::executeDispatch_InsertAxes()
125 UndoGuard
aUndoGuard(
126 ActionDescriptionProvider::createDescription(
127 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_AXES
)))),
128 m_xUndoManager
, m_aModel
->getModel() );
132 InsertAxisOrGridDialogData aDialogInput
;
133 uno::Reference
< XDiagram
> xDiagram
= ChartModelHelper::findDiagram(m_aModel
->getModel());
134 AxisHelper::getAxisOrGridExcistence( aDialogInput
.aExistenceList
, xDiagram
, sal_True
);
135 AxisHelper::getAxisOrGridPossibilities( aDialogInput
.aPossibilityList
, xDiagram
, sal_True
);
137 ::vos::OGuard
aGuard( Application::GetSolarMutex());
138 SchAxisDlg
aDlg( m_pChartWindow
, aDialogInput
);
139 if( aDlg
.Execute() == RET_OK
)
141 // lock controllers till end of block
142 ControllerLockGuard
aCLGuard( m_aModel
->getModel());
144 InsertAxisOrGridDialogData aDialogOutput
;
145 aDlg
.getResult( aDialogOutput
);
146 ::std::auto_ptr
< ReferenceSizeProvider
> mpRefSizeProvider(
147 impl_createReferenceSizeProvider());
148 bool bChanged
= AxisHelper::changeVisibilityOfAxes( xDiagram
149 , aDialogInput
.aExistenceList
, aDialogOutput
.aExistenceList
, m_xCC
150 , mpRefSizeProvider
.get() );
152 aUndoGuard
.commitAction();
155 catch( uno::RuntimeException
& e
)
157 ASSERT_EXCEPTION( e
);
161 void ChartController::executeDispatch_InsertGrid()
163 UndoGuard
aUndoGuard(
164 ActionDescriptionProvider::createDescription(
165 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_GRIDS
)))),
166 m_xUndoManager
, m_aModel
->getModel() );
170 InsertAxisOrGridDialogData aDialogInput
;
171 uno::Reference
< XDiagram
> xDiagram
= ChartModelHelper::findDiagram(m_aModel
->getModel());
172 AxisHelper::getAxisOrGridExcistence( aDialogInput
.aExistenceList
, xDiagram
, sal_False
);
173 AxisHelper::getAxisOrGridPossibilities( aDialogInput
.aPossibilityList
, xDiagram
, sal_False
);
175 ::vos::OGuard
aGuard( Application::GetSolarMutex());
176 SchGridDlg
aDlg( m_pChartWindow
, aDialogInput
);//aItemSet, b3D, bNet, bSecondaryX, bSecondaryY );
177 if( aDlg
.Execute() == RET_OK
)
179 // lock controllers till end of block
180 ControllerLockGuard
aCLGuard( m_aModel
->getModel());
181 InsertAxisOrGridDialogData aDialogOutput
;
182 aDlg
.getResult( aDialogOutput
);
183 bool bChanged
= AxisHelper::changeVisibilityOfGrids( xDiagram
184 , aDialogInput
.aExistenceList
, aDialogOutput
.aExistenceList
, m_xCC
);
186 aUndoGuard
.commitAction();
189 catch( uno::RuntimeException
& e
)
191 ASSERT_EXCEPTION( e
);
195 //-----------------------------------------------------------------------------
196 //-----------------------------------------------------------------------------
198 void ChartController::executeDispatch_InsertTitles()
200 UndoGuard
aUndoGuard(
201 ActionDescriptionProvider::createDescription(
202 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_TITLES
)))),
203 m_xUndoManager
, m_aModel
->getModel() );
207 TitleDialogData aDialogInput
;
208 aDialogInput
.readFromModel( m_aModel
->getModel() );
210 ::vos::OGuard
aGuard( Application::GetSolarMutex());
211 SchTitleDlg
aDlg( m_pChartWindow
, aDialogInput
);
212 if( aDlg
.Execute() == RET_OK
)
214 // lock controllers till end of block
215 ControllerLockGuard
aCLGuard( m_aModel
->getModel());
216 TitleDialogData
aDialogOutput( impl_createReferenceSizeProvider());
217 aDlg
.getResult( aDialogOutput
);
218 bool bChanged
= aDialogOutput
.writeDifferenceToModel( m_aModel
->getModel(), m_xCC
, &aDialogInput
);
220 aUndoGuard
.commitAction();
223 catch( uno::RuntimeException
& e
)
225 ASSERT_EXCEPTION( e
);
229 void ChartController::executeDispatch_DeleteLegend()
231 UndoGuard
aUndoGuard(
232 ActionDescriptionProvider::createDescription(
233 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( SchResId( STR_OBJECT_LEGEND
)))),
234 m_xUndoManager
, m_aModel
->getModel() );
236 LegendHelper::hideLegend( m_aModel
->getModel() );
237 aUndoGuard
.commitAction();
240 void ChartController::executeDispatch_InsertLegend()
242 UndoGuard
aUndoGuard(
243 ActionDescriptionProvider::createDescription(
244 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_LEGEND
)))),
245 m_xUndoManager
, m_aModel
->getModel() );
247 Reference
< chart2::XLegend
> xLegend
= LegendHelper::showLegend( m_aModel
->getModel(), m_xCC
);
248 aUndoGuard
.commitAction();
251 void ChartController::executeDispatch_OpenLegendDialog()
253 UndoGuard
aUndoGuard(
254 ActionDescriptionProvider::createDescription(
255 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_LEGEND
)))),
256 m_xUndoManager
, m_aModel
->getModel() );
260 //prepare and open dialog
261 ::vos::OGuard
aGuard( Application::GetSolarMutex());
262 SchLegendDlg
aDlg( m_pChartWindow
, m_xCC
);
263 aDlg
.init( m_aModel
->getModel() );
264 if( aDlg
.Execute() == RET_OK
)
266 // lock controllers till end of block
267 ControllerLockGuard
aCLGuard( m_aModel
->getModel() );
268 bool bChanged
= aDlg
.writeToModel( m_aModel
->getModel() );
270 aUndoGuard
.commitAction();
273 catch( uno::RuntimeException
& e
)
275 ASSERT_EXCEPTION( e
);
279 //-----------------------------------------------------------------------------
280 //-----------------------------------------------------------------------------
282 void ChartController::executeDispatch_InsertMenu_DataLabels()
284 UndoGuard
aUndoGuard(
285 ActionDescriptionProvider::createDescription(
286 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_DATALABELS
)))),
287 m_xUndoManager
, m_aModel
->getModel() );
289 //if a series is selected insert labels for that series only:
290 uno::Reference
< chart2::XDataSeries
> xSeries(
291 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
295 DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries
);
297 rtl::OUString
aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS
) );
298 aChildParticle
+=(C2U("="));
299 rtl::OUString aObjectCID
= ObjectIdentifier::createClassifiedIdentifierForParticles(
300 ObjectIdentifier::getSeriesParticleFromCID(m_aSelection
.getSelectedCID()), aChildParticle
);
302 bool bSuccess
= ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID
, true );
304 aUndoGuard
.commitAction();
310 wrapper::AllDataLabelItemConverter
aItemConverter(
311 m_aModel
->getModel(),
312 m_pDrawModelWrapper
->GetItemPool(),
313 m_pDrawModelWrapper
->getSdrModel(),
314 uno::Reference
< lang::XMultiServiceFactory
>( m_aModel
->getModel(), uno::UNO_QUERY
));
315 SfxItemSet aItemSet
= aItemConverter
.CreateEmptyItemSet();
316 aItemConverter
.FillItemSet( aItemSet
);
318 //prepare and open dialog
319 ::vos::OGuard
aGuard( Application::GetSolarMutex());
321 //get number formatter
322 uno::Reference
< util::XNumberFormatsSupplier
> xNumberFormatsSupplier( m_aModel
->getModel(), uno::UNO_QUERY
);
323 NumberFormatterWrapper
aNumberFormatterWrapper( xNumberFormatsSupplier
);
324 SvNumberFormatter
* pNumberFormatter
= aNumberFormatterWrapper
.getSvNumberFormatter();
326 DataLabelsDialog
aDlg( m_pChartWindow
, aItemSet
, pNumberFormatter
);
328 if( aDlg
.Execute() == RET_OK
)
330 SfxItemSet aOutItemSet
= aItemConverter
.CreateEmptyItemSet();
331 aDlg
.FillItemSet( aOutItemSet
);
332 // lock controllers till end of block
333 ControllerLockGuard
aCLGuard( m_aModel
->getModel());
334 bool bChanged
= aItemConverter
.ApplyItemSet( aOutItemSet
);//model should be changed now
336 aUndoGuard
.commitAction();
339 catch( uno::RuntimeException
& e
)
341 ASSERT_EXCEPTION( e
);
345 void ChartController::executeDispatch_InsertMenu_YErrorBars()
347 //if a series is selected insert error bars for that series only:
348 uno::Reference
< chart2::XDataSeries
> xSeries(
349 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
352 executeDispatch_InsertYErrorBars();
356 //if no series is selected insert error bars for all series
357 UndoGuard
aUndoGuard(
358 ActionDescriptionProvider::createDescription(
359 ActionDescriptionProvider::INSERT
, ObjectNameProvider::getName_ObjectForAllSeries( OBJECTTYPE_DATA_ERRORS
) ),
360 m_xUndoManager
, m_aModel
->getModel() );
364 wrapper::AllSeriesStatisticsConverter
aItemConverter(
365 m_aModel
->getModel(), m_pDrawModelWrapper
->GetItemPool() );
366 SfxItemSet aItemSet
= aItemConverter
.CreateEmptyItemSet();
367 aItemConverter
.FillItemSet( aItemSet
);
369 //prepare and open dialog
370 ::vos::OGuard
aGuard( Application::GetSolarMutex());
371 InsertErrorBarsDialog
aDlg(
372 m_pChartWindow
, aItemSet
,
373 uno::Reference
< chart2::XChartDocument
>( m_aModel
->getModel(), uno::UNO_QUERY
));
374 aDlg
.SetAxisMinorStepWidthForErrorBarDecimals(
375 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( m_aModel
->getModel(), m_xChartView
, rtl::OUString() ) );
377 if( aDlg
.Execute() == RET_OK
)
379 SfxItemSet aOutItemSet
= aItemConverter
.CreateEmptyItemSet();
380 aDlg
.FillItemSet( aOutItemSet
);
382 // lock controllers till end of block
383 ControllerLockGuard
aCLGuard( m_aModel
->getModel());
384 bool bChanged
= aItemConverter
.ApplyItemSet( aOutItemSet
);//model should be changed now
386 aUndoGuard
.commitAction();
389 catch( uno::RuntimeException
& e
)
391 ASSERT_EXCEPTION( e
);
395 void ChartController::executeDispatch_InsertMeanValue()
397 UndoGuard
aUndoGuard(
398 ActionDescriptionProvider::createDescription(
399 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_AVERAGE_LINE
)))),
400 m_xUndoManager
, m_aModel
->getModel());
401 lcl_InsertMeanValueLine( m_xCC
).operator()(
402 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()));
403 aUndoGuard
.commitAction();
406 void ChartController::executeDispatch_InsertMenu_MeanValues()
408 UndoGuard
aUndoGuard(
409 ActionDescriptionProvider::createDescription(
410 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_AVERAGE_LINE
)))),
411 m_xUndoManager
, m_aModel
->getModel() );
413 uno::Reference
< chart2::XDataSeries
> xSeries(
414 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
417 //if a series is selected insert mean value only for that series:
418 lcl_InsertMeanValueLine( m_xCC
).operator()(xSeries
);
422 ::std::vector
< uno::Reference
< chart2::XDataSeries
> > aSeries(
423 DiagramHelper::getDataSeriesFromDiagram( ChartModelHelper::findDiagram( m_aModel
->getModel())));
424 ::std::for_each( aSeries
.begin(), aSeries
.end(), lcl_InsertMeanValueLine( m_xCC
));
426 aUndoGuard
.commitAction();
429 void ChartController::executeDispatch_InsertMenu_Trendlines()
431 //if a series is selected insert only for that series:
432 uno::Reference
< chart2::XDataSeries
> xSeries(
433 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
436 executeDispatch_InsertTrendline();
440 UndoGuard
aUndoGuard(
441 ActionDescriptionProvider::createDescription(
442 ActionDescriptionProvider::INSERT
, ObjectNameProvider::getName_ObjectForAllSeries( OBJECTTYPE_DATA_CURVE
) ),
443 m_xUndoManager
, m_aModel
->getModel() );
447 wrapper::AllSeriesStatisticsConverter
aItemConverter(
448 m_aModel
->getModel(), m_pDrawModelWrapper
->GetItemPool() );
449 SfxItemSet aItemSet
= aItemConverter
.CreateEmptyItemSet();
450 aItemConverter
.FillItemSet( aItemSet
);
452 //prepare and open dialog
453 ::vos::OGuard
aGuard( Application::GetSolarMutex());
454 InsertTrendlineDialog
aDlg( m_pChartWindow
, aItemSet
);
457 if( aDlg
.Execute() == RET_OK
)
459 SfxItemSet aOutItemSet
= aItemConverter
.CreateEmptyItemSet();
460 aDlg
.FillItemSet( aOutItemSet
);
462 // lock controllers till end of block
463 ControllerLockGuard
aCLGuard( m_aModel
->getModel());
464 bool bChanged
= aItemConverter
.ApplyItemSet( aOutItemSet
);//model should be changed now
466 aUndoGuard
.commitAction();
469 catch( uno::RuntimeException
& e
)
471 ASSERT_EXCEPTION( e
);
475 void ChartController::executeDispatch_InsertTrendline()
477 uno::Reference
< chart2::XRegressionCurveContainer
> xRegCurveCnt(
478 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
479 if( xRegCurveCnt
.is())
481 UndoLiveUpdateGuard
aUndoGuard(
482 ActionDescriptionProvider::createDescription(
483 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE
)))),
484 m_xUndoManager
, m_aModel
->getModel() );
486 // add a linear curve
487 RegressionCurveHelper::addRegressionCurve(
488 RegressionCurveHelper::REGRESSION_TYPE_LINEAR
, xRegCurveCnt
, m_xCC
);
490 // get an appropriate item converter
491 uno::Reference
< chart2::XRegressionCurve
> xCurve(
492 RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt
));
493 uno::Reference
< beans::XPropertySet
> xCurveProp( xCurve
, uno::UNO_QUERY
);
494 if( !xCurveProp
.is())
496 wrapper::RegressionCurveItemConverter
aItemConverter(
497 xCurveProp
, xRegCurveCnt
, m_pDrawModelWrapper
->getSdrModel().GetItemPool(),
498 m_pDrawModelWrapper
->getSdrModel(),
499 uno::Reference
< lang::XMultiServiceFactory
>( m_aModel
->getModel(), uno::UNO_QUERY
));
502 SfxItemSet aItemSet
= aItemConverter
.CreateEmptyItemSet();
503 aItemConverter
.FillItemSet( aItemSet
);
504 ObjectPropertiesDialogParameter aDialogParameter
= ObjectPropertiesDialogParameter(
505 ObjectIdentifier::createDataCurveCID(
506 ObjectIdentifier::getSeriesParticleFromCID( m_aSelection
.getSelectedCID()),
507 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt
, xCurve
), false ));
508 aDialogParameter
.init( m_aModel
->getModel() );
509 ViewElementListProvider
aViewElementListProvider( m_pDrawModelWrapper
.get());
510 ::vos::OGuard
aGuard( Application::GetSolarMutex());
511 SchAttribTabDlg
aDlg( m_pChartWindow
, &aItemSet
, &aDialogParameter
, &aViewElementListProvider
,
512 uno::Reference
< util::XNumberFormatsSupplier
>( m_aModel
->getModel(), uno::UNO_QUERY
));
514 // note: when a user pressed "OK" but didn't change any settings in the
515 // dialog, the SfxTabDialog returns "Cancel"
516 if( aDlg
.Execute() == RET_OK
|| aDlg
.DialogWasClosedWithOK())
518 const SfxItemSet
* pOutItemSet
= aDlg
.GetOutputItemSet();
521 ControllerLockGuard
aCLGuard( m_aModel
->getModel());
522 aItemConverter
.ApplyItemSet( *pOutItemSet
);
524 aUndoGuard
.commitAction();
529 void ChartController::executeDispatch_InsertYErrorBars()
531 uno::Reference
< chart2::XDataSeries
> xSeries(
532 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
535 UndoLiveUpdateGuard
aUndoGuard(
536 ActionDescriptionProvider::createDescription(
537 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_ERROR_BARS
)))),
538 m_xUndoManager
, m_aModel
->getModel() );
540 // add error bars with standard deviation
541 uno::Reference
< beans::XPropertySet
> xErrorBarProp(
542 StatisticsHelper::addErrorBars( xSeries
, m_xCC
, ::com::sun::star::chart::ErrorBarStyle::STANDARD_DEVIATION
));
544 // get an appropriate item converter
545 wrapper::ErrorBarItemConverter
aItemConverter(
546 m_aModel
->getModel(), xErrorBarProp
, m_pDrawModelWrapper
->getSdrModel().GetItemPool(),
547 m_pDrawModelWrapper
->getSdrModel(),
548 uno::Reference
< lang::XMultiServiceFactory
>( m_aModel
->getModel(), uno::UNO_QUERY
));
551 SfxItemSet aItemSet
= aItemConverter
.CreateEmptyItemSet();
552 aItemConverter
.FillItemSet( aItemSet
);
553 ObjectPropertiesDialogParameter aDialogParameter
= ObjectPropertiesDialogParameter(
554 ObjectIdentifier::createClassifiedIdentifierWithParent(
555 OBJECTTYPE_DATA_ERRORS
, ::rtl::OUString(), m_aSelection
.getSelectedCID()));
556 aDialogParameter
.init( m_aModel
->getModel() );
557 ViewElementListProvider
aViewElementListProvider( m_pDrawModelWrapper
.get());
558 ::vos::OGuard
aGuard( Application::GetSolarMutex());
559 SchAttribTabDlg
aDlg( m_pChartWindow
, &aItemSet
, &aDialogParameter
, &aViewElementListProvider
,
560 uno::Reference
< util::XNumberFormatsSupplier
>( m_aModel
->getModel(), uno::UNO_QUERY
));
561 aDlg
.SetAxisMinorStepWidthForErrorBarDecimals(
562 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( m_aModel
->getModel(), m_xChartView
, m_aSelection
.getSelectedCID()));
564 // note: when a user pressed "OK" but didn't change any settings in the
565 // dialog, the SfxTabDialog returns "Cancel"
566 if( aDlg
.Execute() == RET_OK
|| aDlg
.DialogWasClosedWithOK())
568 const SfxItemSet
* pOutItemSet
= aDlg
.GetOutputItemSet();
571 ControllerLockGuard
aCLGuard( m_aModel
->getModel());
572 aItemConverter
.ApplyItemSet( *pOutItemSet
);
574 aUndoGuard
.commitAction();
579 void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2
)
581 uno::Reference
< chart2::XRegressionCurve
> xRegCurve(
582 ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
583 if( !xRegCurve
.is() )
585 uno::Reference
< chart2::XRegressionCurveContainer
> xRegCurveCnt(
586 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
587 xRegCurve
.set( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt
) );
591 uno::Reference
< beans::XPropertySet
> xEqProp( xRegCurve
->getEquationProperties());
594 // using assignment for broken gcc 3.3
595 UndoGuard aUndoGuard
= UndoGuard(
596 ActionDescriptionProvider::createDescription(
597 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE_EQUATION
)))),
598 m_xUndoManager
, m_aModel
->getModel() );
599 xEqProp
->setPropertyValue( C2U("ShowEquation"), uno::makeAny( true ));
600 xEqProp
->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( bInsertR2
));
601 aUndoGuard
.commitAction();
606 void ChartController::executeDispatch_InsertR2Value()
608 uno::Reference
< beans::XPropertySet
> xEqProp(
609 ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
612 UndoGuard aUndoGuard
= UndoGuard(
613 ActionDescriptionProvider::createDescription(
614 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE_EQUATION
)))),
615 m_xUndoManager
, m_aModel
->getModel() );
616 xEqProp
->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( true ));
617 aUndoGuard
.commitAction();
621 void ChartController::executeDispatch_DeleteR2Value()
623 uno::Reference
< beans::XPropertySet
> xEqProp(
624 ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
627 UndoGuard aUndoGuard
= UndoGuard(
628 ActionDescriptionProvider::createDescription(
629 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE_EQUATION
)))),
630 m_xUndoManager
, m_aModel
->getModel() );
631 xEqProp
->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( false ));
632 aUndoGuard
.commitAction();
636 void ChartController::executeDispatch_DeleteMeanValue()
638 uno::Reference
< chart2::XRegressionCurveContainer
> xRegCurveCnt(
639 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
640 if( xRegCurveCnt
.is())
642 UndoGuard
aUndoGuard(
643 ActionDescriptionProvider::createDescription(
644 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( SchResId( STR_OBJECT_AVERAGE_LINE
)))),
645 m_xUndoManager
, m_aModel
->getModel());
646 RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt
);
647 aUndoGuard
.commitAction();
651 void ChartController::executeDispatch_DeleteTrendline()
653 uno::Reference
< chart2::XRegressionCurveContainer
> xRegCurveCnt(
654 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
655 if( xRegCurveCnt
.is())
657 UndoGuard
aUndoGuard(
658 ActionDescriptionProvider::createDescription(
659 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE
)))),
660 m_xUndoManager
, m_aModel
->getModel());
661 RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt
);
662 aUndoGuard
.commitAction();
666 void ChartController::executeDispatch_DeleteTrendlineEquation()
668 uno::Reference
< chart2::XRegressionCurveContainer
> xRegCurveCnt(
669 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
670 if( xRegCurveCnt
.is())
672 UndoGuard
aUndoGuard(
673 ActionDescriptionProvider::createDescription(
674 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE_EQUATION
)))),
675 m_xUndoManager
, m_aModel
->getModel());
676 RegressionCurveHelper::removeEquations( xRegCurveCnt
);
677 aUndoGuard
.commitAction();
681 void ChartController::executeDispatch_DeleteYErrorBars()
683 uno::Reference
< chart2::XDataSeries
> xDataSeries(
684 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()));
685 if( xDataSeries
.is())
687 UndoGuard
aUndoGuard(
688 ActionDescriptionProvider::createDescription(
689 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( SchResId( STR_OBJECT_CURVE
)))),
690 m_xUndoManager
, m_aModel
->getModel());
691 StatisticsHelper::removeErrorBars( xDataSeries
);
692 aUndoGuard
.commitAction();
696 void ChartController::executeDispatch_InsertDataLabels()
698 uno::Reference
< chart2::XDataSeries
> xSeries(
699 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
702 UndoGuard aUndoGuard
= UndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::INSERT
,
703 ::rtl::OUString( String( SchResId( STR_OBJECT_DATALABELS
)))),
704 m_xUndoManager
, m_aModel
->getModel() );
705 DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries
);
706 aUndoGuard
.commitAction();
710 void ChartController::executeDispatch_InsertDataLabel()
712 UndoGuard aUndoGuard
= UndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::INSERT
,
713 ::rtl::OUString( String( SchResId( STR_OBJECT_LABEL
)))),
714 m_xUndoManager
, m_aModel
->getModel() );
715 DataSeriesHelper::insertDataLabelToPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), m_aModel
->getModel() ) );
716 aUndoGuard
.commitAction();
719 void ChartController::executeDispatch_DeleteDataLabels()
721 uno::Reference
< chart2::XDataSeries
> xSeries(
722 ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
725 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::DELETE
,
726 ::rtl::OUString( String( SchResId( STR_OBJECT_DATALABELS
)))),
727 m_xUndoManager
, m_aModel
->getModel());
728 DataSeriesHelper::deleteDataLabelsFromSeriesAndAllPoints( xSeries
);
729 aUndoGuard
.commitAction();
733 void ChartController::executeDispatch_DeleteDataLabel()
735 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::DELETE
,
736 ::rtl::OUString( String( SchResId( STR_OBJECT_LABEL
)))),
737 m_xUndoManager
, m_aModel
->getModel());
738 DataSeriesHelper::deleteDataLabelsFromPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection
.getSelectedCID(), m_aModel
->getModel() ) );
739 aUndoGuard
.commitAction();
742 void ChartController::executeDispatch_ResetAllDataPoints()
744 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::FORMAT
,
745 ::rtl::OUString( String( SchResId( STR_OBJECT_DATAPOINTS
)))),
746 m_xUndoManager
, m_aModel
->getModel());
747 uno::Reference
< chart2::XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
749 xSeries
->resetAllDataPoints();
750 aUndoGuard
.commitAction();
752 void ChartController::executeDispatch_ResetDataPoint()
754 UndoGuard
aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::FORMAT
,
755 ::rtl::OUString( String( SchResId( STR_OBJECT_DATAPOINT
)))),
756 m_xUndoManager
, m_aModel
->getModel());
757 uno::Reference
< chart2::XDataSeries
> xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel()), uno::UNO_QUERY
);
760 sal_Int32 nPointIndex
= ObjectIdentifier::getIndexFromParticleOrCID( m_aSelection
.getSelectedCID() );
761 xSeries
->resetDataPoint( nPointIndex
);
763 aUndoGuard
.commitAction();
766 void ChartController::executeDispatch_InsertAxisTitle()
770 uno::Reference
< XTitle
> xTitle
;
772 UndoGuard
aUndoGuard(
773 ActionDescriptionProvider::createDescription(
774 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_TITLE
)))),
775 m_xUndoManager
, m_aModel
->getModel() );
777 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel() );
778 sal_Int32 nDimensionIndex
= -1;
779 sal_Int32 nCooSysIndex
= -1;
780 sal_Int32 nAxisIndex
= -1;
781 AxisHelper::getIndicesForAxis( xAxis
, ChartModelHelper::findDiagram(m_aModel
->getModel()), nCooSysIndex
, nDimensionIndex
, nAxisIndex
);
783 TitleHelper::eTitleType eTitleType
= TitleHelper::X_AXIS_TITLE
;
784 if( nDimensionIndex
==0 )
785 eTitleType
= nAxisIndex
==0 ? TitleHelper::X_AXIS_TITLE
: TitleHelper::SECONDARY_X_AXIS_TITLE
;
786 else if( nDimensionIndex
==1 )
787 eTitleType
= nAxisIndex
==0 ? TitleHelper::Y_AXIS_TITLE
: TitleHelper::SECONDARY_Y_AXIS_TITLE
;
789 eTitleType
= TitleHelper::Z_AXIS_TITLE
;
791 ::std::auto_ptr
< ReferenceSizeProvider
> apRefSizeProvider( impl_createReferenceSizeProvider());
792 xTitle
= TitleHelper::createTitle( eTitleType
, ObjectNameProvider::getTitleNameByType(eTitleType
), m_aModel
->getModel(), m_xCC
, apRefSizeProvider
.get() );
793 aUndoGuard
.commitAction();
799 OUString aTitleCID = ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_aModel->getModel() );
800 select( uno::makeAny(aTitleCID) );
801 executeDispatch_EditText();
805 catch( uno::RuntimeException
& e
)
807 ASSERT_EXCEPTION( e
);
811 void ChartController::executeDispatch_InsertAxis()
813 UndoGuard
aUndoGuard(
814 ActionDescriptionProvider::createDescription(
815 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_AXIS
)))),
816 m_xUndoManager
, m_aModel
->getModel() );
820 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel() );
823 AxisHelper::makeAxisVisible( xAxis
);
824 aUndoGuard
.commitAction();
827 catch( uno::RuntimeException
& e
)
829 ASSERT_EXCEPTION( e
);
833 void ChartController::executeDispatch_DeleteAxis()
835 UndoGuard
aUndoGuard(
836 ActionDescriptionProvider::createDescription(
837 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( SchResId( STR_OBJECT_AXIS
)))),
838 m_xUndoManager
, m_aModel
->getModel() );
842 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel() );
845 AxisHelper::makeAxisInvisible( xAxis
);
846 aUndoGuard
.commitAction();
849 catch( uno::RuntimeException
& e
)
851 ASSERT_EXCEPTION( e
);
855 void ChartController::executeDispatch_InsertMajorGrid()
857 UndoGuard
aUndoGuard(
858 ActionDescriptionProvider::createDescription(
859 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_GRID
)))),
860 m_xUndoManager
, m_aModel
->getModel() );
864 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel() );
867 AxisHelper::makeGridVisible( xAxis
->getGridProperties() );
868 aUndoGuard
.commitAction();
871 catch( uno::RuntimeException
& e
)
873 ASSERT_EXCEPTION( e
);
877 void ChartController::executeDispatch_DeleteMajorGrid()
879 UndoGuard
aUndoGuard(
880 ActionDescriptionProvider::createDescription(
881 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( SchResId( STR_OBJECT_GRID
)))),
882 m_xUndoManager
, m_aModel
->getModel() );
886 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel() );
889 AxisHelper::makeGridInvisible( xAxis
->getGridProperties() );
890 aUndoGuard
.commitAction();
893 catch( uno::RuntimeException
& e
)
895 ASSERT_EXCEPTION( e
);
899 void ChartController::executeDispatch_InsertMinorGrid()
901 UndoGuard
aUndoGuard(
902 ActionDescriptionProvider::createDescription(
903 ActionDescriptionProvider::INSERT
, ::rtl::OUString( String( SchResId( STR_OBJECT_GRID
)))),
904 m_xUndoManager
, m_aModel
->getModel() );
908 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel() );
911 Sequence
< Reference
< beans::XPropertySet
> > aSubGrids( xAxis
->getSubGridProperties() );
912 for( sal_Int32 nN
=0; nN
<aSubGrids
.getLength(); nN
++)
913 AxisHelper::makeGridVisible( aSubGrids
[nN
] );
914 aUndoGuard
.commitAction();
917 catch( uno::RuntimeException
& e
)
919 ASSERT_EXCEPTION( e
);
923 void ChartController::executeDispatch_DeleteMinorGrid()
925 UndoGuard
aUndoGuard(
926 ActionDescriptionProvider::createDescription(
927 ActionDescriptionProvider::DELETE
, ::rtl::OUString( String( SchResId( STR_OBJECT_GRID
)))),
928 m_xUndoManager
, m_aModel
->getModel() );
932 Reference
< XAxis
> xAxis
= ObjectIdentifier::getAxisForCID( m_aSelection
.getSelectedCID(), m_aModel
->getModel() );
935 Sequence
< Reference
< beans::XPropertySet
> > aSubGrids( xAxis
->getSubGridProperties() );
936 for( sal_Int32 nN
=0; nN
<aSubGrids
.getLength(); nN
++)
937 AxisHelper::makeGridInvisible( aSubGrids
[nN
] );
938 aUndoGuard
.commitAction();
941 catch( uno::RuntimeException
& e
)
943 ASSERT_EXCEPTION( e
);
947 //.............................................................................
949 //.............................................................................