1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 #include "ChartController.hxx"
27
28 #include "dlg_InsertAxis_Grid.hxx"
29 #include "dlg_InsertDataLabel.hxx"
30 #include "dlg_InsertLegend.hxx"
31 #include "dlg_InsertTrendline.hxx"
32 #include "dlg_InsertErrorBars.hxx"
33 #include "dlg_InsertTitle.hxx"
34 #include "dlg_ObjectProperties.hxx"
35
36 #include "ChartWindow.hxx"
37 #include "ChartModelHelper.hxx"
38 #include "AxisHelper.hxx"
39 #include "TitleHelper.hxx"
40 #include "DiagramHelper.hxx"
41 #include "macros.hxx"
42 #include "chartview/DrawModelWrapper.hxx"
43 #include "NumberFormatterWrapper.hxx"
44 #include "ViewElementListProvider.hxx"
45 #include "MultipleChartConverters.hxx"
46 #include "ControllerLockGuard.hxx"
47 #include "UndoGuard.hxx"
48 #include "ResId.hxx"
49 #include "Strings.hrc"
50 #include "ReferenceSizeProvider.hxx"
51 #include "ObjectIdentifier.hxx"
52 #include "RegressionCurveHelper.hxx"
53 #include "RegressionCurveItemConverter.hxx"
54 #include "StatisticsHelper.hxx"
55 #include "ErrorBarItemConverter.hxx"
56 #include "MultipleItemConverter.hxx"
57 #include "DataSeriesHelper.hxx"
58 #include "ObjectNameProvider.hxx"
59 #include "LegendHelper.hxx"
60
61 #include <com/sun/star/chart2/XRegressionCurve.hpp>
62 #include <com/sun/star/chart/ErrorBarStyle.hpp>
63 #include <svx/ActionDescriptionProvider.hxx>
64
65 //--------------------------------------
66
67 // header for define RET_OK
68 #include <vcl/msgbox.hxx>
69 // header for class OUStringBuffer
70 #include <rtl/ustrbuf.hxx>
71 // header for class Application
72 #include <vcl/svapp.hxx>
73 // header for class ::vos::OGuard
74 #include <vos/mutex.hxx>
75
76
77 using namespace ::com::sun::star;
78 using namespace ::com::sun::star::chart2;
79 using ::com::sun::star::uno::Reference;
80 using ::com::sun::star::uno::Sequence;
81 using ::rtl::OUString;
82
83 //.............................................................................
84
85 namespace
86 {
87 struct lcl_InsertMeanValueLine
88 {
89 public:
lcl_InsertMeanValueLine__anone5f884bb0111::lcl_InsertMeanValueLine90 lcl_InsertMeanValueLine( const uno::Reference< uno::XComponentContext > & xContext ) :
91 m_xContext( xContext )
92 {}
93
operator ()__anone5f884bb0111::lcl_InsertMeanValueLine94 void operator()( const uno::Reference< chart2::XDataSeries > & xSeries )
95 {
96 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
97 xSeries, uno::UNO_QUERY );
98 if( xRegCurveCnt.is())
99 {
100 ::chart::RegressionCurveHelper::addMeanValueLine(
101 xRegCurveCnt, m_xContext, uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ));
102 }
103 }
104
105 private:
106 uno::Reference< uno::XComponentContext > m_xContext;
107 };
108
109 } // anonymous namespace
110
111 //.............................................................................
112 namespace chart
113 {
114 //.............................................................................
115
executeDispatch_InsertAxes()116 void ChartController::executeDispatch_InsertAxes()
117 {
118 UndoGuard aUndoGuard(
119 ActionDescriptionProvider::createDescription(
120 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AXES ))),
121 m_xUndoManager );
122
123 try
124 {
125 InsertAxisOrGridDialogData aDialogInput;
126 uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel());
127 AxisHelper::getAxisOrGridExcistence( aDialogInput.aExistenceList, xDiagram, sal_True );
128 AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram, sal_True );
129
130 ::vos::OGuard aGuard( Application::GetSolarMutex());
131 SchAxisDlg aDlg( m_pChartWindow, aDialogInput );
132 if( aDlg.Execute() == RET_OK )
133 {
134 // lock controllers till end of block
135 ControllerLockGuard aCLGuard( getModel() );
136
137 InsertAxisOrGridDialogData aDialogOutput;
138 aDlg.getResult( aDialogOutput );
139 ::std::auto_ptr< ReferenceSizeProvider > mpRefSizeProvider(
140 impl_createReferenceSizeProvider());
141 bool bChanged = AxisHelper::changeVisibilityOfAxes( xDiagram
142 , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, m_xCC
143 , mpRefSizeProvider.get() );
144 if( bChanged )
145 aUndoGuard.commit();
146 }
147 }
148 catch( uno::RuntimeException& e)
149 {
150 ASSERT_EXCEPTION( e );
151 }
152 }
153
executeDispatch_InsertGrid()154 void ChartController::executeDispatch_InsertGrid()
155 {
156 UndoGuard aUndoGuard(
157 ActionDescriptionProvider::createDescription(
158 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRIDS ))),
159 m_xUndoManager );
160
161 try
162 {
163 InsertAxisOrGridDialogData aDialogInput;
164 uno::Reference< XDiagram > xDiagram = ChartModelHelper::findDiagram(getModel());
165 AxisHelper::getAxisOrGridExcistence( aDialogInput.aExistenceList, xDiagram, sal_False );
166 AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram, sal_False );
167
168 ::vos::OGuard aGuard( Application::GetSolarMutex());
169 SchGridDlg aDlg( m_pChartWindow, aDialogInput );//aItemSet, b3D, bNet, bSecondaryX, bSecondaryY );
170 if( aDlg.Execute() == RET_OK )
171 {
172 // lock controllers till end of block
173 ControllerLockGuard aCLGuard( getModel() );
174 InsertAxisOrGridDialogData aDialogOutput;
175 aDlg.getResult( aDialogOutput );
176 bool bChanged = AxisHelper::changeVisibilityOfGrids( xDiagram
177 , aDialogInput.aExistenceList, aDialogOutput.aExistenceList, m_xCC );
178 if( bChanged )
179 aUndoGuard.commit();
180 }
181 }
182 catch( uno::RuntimeException& e)
183 {
184 ASSERT_EXCEPTION( e );
185 }
186 }
187
188 //-----------------------------------------------------------------------------
189 //-----------------------------------------------------------------------------
190
executeDispatch_InsertTitles()191 void ChartController::executeDispatch_InsertTitles()
192 {
193 UndoGuard aUndoGuard(
194 ActionDescriptionProvider::createDescription(
195 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_TITLES ))),
196 m_xUndoManager );
197
198 try
199 {
200 TitleDialogData aDialogInput;
201 aDialogInput.readFromModel( getModel() );
202
203 ::vos::OGuard aGuard( Application::GetSolarMutex());
204 SchTitleDlg aDlg( m_pChartWindow, aDialogInput );
205 if( aDlg.Execute() == RET_OK )
206 {
207 // lock controllers till end of block
208 ControllerLockGuard aCLGuard( getModel() );
209 TitleDialogData aDialogOutput( impl_createReferenceSizeProvider());
210 aDlg.getResult( aDialogOutput );
211 bool bChanged = aDialogOutput.writeDifferenceToModel( getModel(), m_xCC, &aDialogInput );
212 if( bChanged )
213 aUndoGuard.commit();
214 }
215 }
216 catch( uno::RuntimeException& e)
217 {
218 ASSERT_EXCEPTION( e );
219 }
220 }
221
executeDispatch_DeleteLegend()222 void ChartController::executeDispatch_DeleteLegend()
223 {
224 UndoGuard aUndoGuard(
225 ActionDescriptionProvider::createDescription(
226 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_LEGEND ))),
227 m_xUndoManager );
228
229 LegendHelper::hideLegend( getModel() );
230 aUndoGuard.commit();
231 }
232
executeDispatch_InsertLegend()233 void ChartController::executeDispatch_InsertLegend()
234 {
235 UndoGuard aUndoGuard(
236 ActionDescriptionProvider::createDescription(
237 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_LEGEND ))),
238 m_xUndoManager );
239
240 Reference< chart2::XLegend > xLegend = LegendHelper::showLegend( getModel(), m_xCC );
241 aUndoGuard.commit();
242 }
243
executeDispatch_OpenLegendDialog()244 void ChartController::executeDispatch_OpenLegendDialog()
245 {
246 UndoGuard aUndoGuard(
247 ActionDescriptionProvider::createDescription(
248 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_LEGEND ))),
249 m_xUndoManager );
250
251 try
252 {
253 //prepare and open dialog
254 ::vos::OGuard aGuard( Application::GetSolarMutex());
255 SchLegendDlg aDlg( m_pChartWindow, m_xCC );
256 aDlg.init( getModel() );
257 if( aDlg.Execute() == RET_OK )
258 {
259 // lock controllers till end of block
260 ControllerLockGuard aCLGuard( getModel() );
261 bool bChanged = aDlg.writeToModel( getModel() );
262 if( bChanged )
263 aUndoGuard.commit();
264 }
265 }
266 catch( uno::RuntimeException& e)
267 {
268 ASSERT_EXCEPTION( e );
269 }
270 }
271
272 //-----------------------------------------------------------------------------
273 //-----------------------------------------------------------------------------
274
executeDispatch_InsertMenu_DataLabels()275 void ChartController::executeDispatch_InsertMenu_DataLabels()
276 {
277 UndoGuard aUndoGuard(
278 ActionDescriptionProvider::createDescription(
279 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_DATALABELS ))),
280 m_xUndoManager );
281
282 //if a series is selected insert labels for that series only:
283 uno::Reference< chart2::XDataSeries > xSeries(
284 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()), uno::UNO_QUERY );
285 if( xSeries.is() )
286 {
287 // add labels
288 DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries );
289
290 rtl::OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) );
291 aChildParticle+=(C2U("="));
292 rtl::OUString aObjectCID = ObjectIdentifier::createClassifiedIdentifierForParticles(
293 ObjectIdentifier::getSeriesParticleFromCID(m_aSelection.getSelectedCID()), aChildParticle );
294
295 bool bSuccess = ChartController::executeDlg_ObjectProperties_withoutUndoGuard( aObjectCID, true );
296 if( bSuccess )
297 aUndoGuard.commit();
298 return;
299 }
300
301 try
302 {
303 wrapper::AllDataLabelItemConverter aItemConverter(
304 getModel(),
305 m_pDrawModelWrapper->GetItemPool(),
306 m_pDrawModelWrapper->getSdrModel(),
307 uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
308 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
309 aItemConverter.FillItemSet( aItemSet );
310
311 //prepare and open dialog
312 ::vos::OGuard aGuard( Application::GetSolarMutex());
313
314 //get number formatter
315 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( getModel(), uno::UNO_QUERY );
316 NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
317 SvNumberFormatter* pNumberFormatter = aNumberFormatterWrapper.getSvNumberFormatter();
318
319 DataLabelsDialog aDlg( m_pChartWindow, aItemSet, pNumberFormatter);
320
321 if( aDlg.Execute() == RET_OK )
322 {
323 SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
324 aDlg.FillItemSet( aOutItemSet );
325 // lock controllers till end of block
326 ControllerLockGuard aCLGuard( getModel() );
327 bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
328 if( bChanged )
329 aUndoGuard.commit();
330 }
331 }
332 catch( uno::RuntimeException& e)
333 {
334 ASSERT_EXCEPTION( e );
335 }
336 }
337
executeDispatch_InsertMenu_YErrorBars()338 void ChartController::executeDispatch_InsertMenu_YErrorBars()
339 {
340 //if a series is selected insert error bars for that series only:
341 uno::Reference< chart2::XDataSeries > xSeries(
342 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
343 if( xSeries.is())
344 {
345 executeDispatch_InsertYErrorBars();
346 return;
347 }
348
349 //if no series is selected insert error bars for all series
350 UndoGuard aUndoGuard(
351 ActionDescriptionProvider::createDescription(
352 ActionDescriptionProvider::INSERT, ObjectNameProvider::getName_ObjectForAllSeries( OBJECTTYPE_DATA_ERRORS ) ),
353 m_xUndoManager );
354
355 try
356 {
357 wrapper::AllSeriesStatisticsConverter aItemConverter(
358 getModel(), m_pDrawModelWrapper->GetItemPool() );
359 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
360 aItemConverter.FillItemSet( aItemSet );
361
362 //prepare and open dialog
363 ::vos::OGuard aGuard( Application::GetSolarMutex());
364 InsertErrorBarsDialog aDlg(
365 m_pChartWindow, aItemSet,
366 uno::Reference< chart2::XChartDocument >( getModel(), uno::UNO_QUERY ));
367 aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
368 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, rtl::OUString() ) );
369
370 if( aDlg.Execute() == RET_OK )
371 {
372 SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
373 aDlg.FillItemSet( aOutItemSet );
374
375 // lock controllers till end of block
376 ControllerLockGuard aCLGuard( getModel() );
377 bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
378 if( bChanged )
379 aUndoGuard.commit();
380 }
381 }
382 catch( uno::RuntimeException& e)
383 {
384 ASSERT_EXCEPTION( e );
385 }
386 }
387
executeDispatch_InsertMeanValue()388 void ChartController::executeDispatch_InsertMeanValue()
389 {
390 UndoGuard aUndoGuard(
391 ActionDescriptionProvider::createDescription(
392 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AVERAGE_LINE ))),
393 m_xUndoManager );
394 lcl_InsertMeanValueLine( m_xCC ).operator()(
395 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ));
396 aUndoGuard.commit();
397 }
398
executeDispatch_InsertMenu_MeanValues()399 void ChartController::executeDispatch_InsertMenu_MeanValues()
400 {
401 UndoGuard aUndoGuard(
402 ActionDescriptionProvider::createDescription(
403 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AVERAGE_LINE ))),
404 m_xUndoManager );
405
406 uno::Reference< chart2::XDataSeries > xSeries(
407 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
408 if( xSeries.is() )
409 {
410 //if a series is selected insert mean value only for that series:
411 lcl_InsertMeanValueLine( m_xCC ).operator()(xSeries);
412 }
413 else
414 {
415 ::std::vector< uno::Reference< chart2::XDataSeries > > aSeries(
416 DiagramHelper::getDataSeriesFromDiagram( ChartModelHelper::findDiagram( getModel() )));
417 ::std::for_each( aSeries.begin(), aSeries.end(), lcl_InsertMeanValueLine( m_xCC ));
418 }
419 aUndoGuard.commit();
420 }
421
executeDispatch_InsertMenu_Trendlines()422 void ChartController::executeDispatch_InsertMenu_Trendlines()
423 {
424 //if a series is selected insert only for that series:
425 uno::Reference< chart2::XDataSeries > xSeries(
426 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
427 if( xSeries.is())
428 {
429 executeDispatch_InsertTrendline();
430 return;
431 }
432
433 UndoGuard aUndoGuard(
434 ActionDescriptionProvider::createDescription(
435 ActionDescriptionProvider::INSERT, ObjectNameProvider::getName_ObjectForAllSeries( OBJECTTYPE_DATA_CURVE ) ),
436 m_xUndoManager );
437
438 try
439 {
440 wrapper::AllSeriesStatisticsConverter aItemConverter(
441 getModel(), m_pDrawModelWrapper->GetItemPool() );
442 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
443 aItemConverter.FillItemSet( aItemSet );
444
445 //prepare and open dialog
446 ::vos::OGuard aGuard( Application::GetSolarMutex());
447 InsertTrendlineDialog aDlg( m_pChartWindow, aItemSet );
448 aDlg.adjustSize();
449
450 if( aDlg.Execute() == RET_OK )
451 {
452 SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
453 aDlg.FillItemSet( aOutItemSet );
454
455 // lock controllers till end of block
456 ControllerLockGuard aCLGuard( getModel() );
457 bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
458 if( bChanged )
459 aUndoGuard.commit();
460 }
461 }
462 catch( uno::RuntimeException& e)
463 {
464 ASSERT_EXCEPTION( e );
465 }
466 }
467
executeDispatch_InsertTrendline()468 void ChartController::executeDispatch_InsertTrendline()
469 {
470 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
471 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel()), uno::UNO_QUERY );
472 if( xRegCurveCnt.is())
473 {
474 UndoLiveUpdateGuard aUndoGuard(
475 ActionDescriptionProvider::createDescription(
476 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE ))),
477 m_xUndoManager );
478
479 // add a linear curve
480 RegressionCurveHelper::addRegressionCurve(
481 RegressionCurveHelper::REGRESSION_TYPE_LINEAR, xRegCurveCnt, m_xCC );
482
483 // get an appropriate item converter
484 uno::Reference< chart2::XRegressionCurve > xCurve(
485 RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ));
486 uno::Reference< beans::XPropertySet > xCurveProp( xCurve, uno::UNO_QUERY );
487 if( !xCurveProp.is())
488 return;
489 wrapper::RegressionCurveItemConverter aItemConverter(
490 xCurveProp, xRegCurveCnt, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
491 m_pDrawModelWrapper->getSdrModel(),
492 uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
493
494 // open dialog
495 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
496 aItemConverter.FillItemSet( aItemSet );
497 ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter(
498 ObjectIdentifier::createDataCurveCID(
499 ObjectIdentifier::getSeriesParticleFromCID( m_aSelection.getSelectedCID()),
500 RegressionCurveHelper::getRegressionCurveIndex( xRegCurveCnt, xCurve ), false ));
501 aDialogParameter.init( getModel() );
502 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
503 ::vos::OGuard aGuard( Application::GetSolarMutex());
504 SchAttribTabDlg aDlg( m_pChartWindow, &aItemSet, &aDialogParameter, &aViewElementListProvider,
505 uno::Reference< util::XNumberFormatsSupplier >( getModel(), uno::UNO_QUERY ));
506
507 // note: when a user pressed "OK" but didn't change any settings in the
508 // dialog, the SfxTabDialog returns "Cancel"
509 if( aDlg.Execute() == RET_OK || aDlg.DialogWasClosedWithOK())
510 {
511 const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
512 if( pOutItemSet )
513 {
514 ControllerLockGuard aCLGuard( getModel() );
515 aItemConverter.ApplyItemSet( *pOutItemSet );
516 }
517 aUndoGuard.commit();
518 }
519 }
520 }
521
executeDispatch_InsertYErrorBars()522 void ChartController::executeDispatch_InsertYErrorBars()
523 {
524 uno::Reference< chart2::XDataSeries > xSeries(
525 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
526 if( xSeries.is())
527 {
528 UndoLiveUpdateGuard aUndoGuard(
529 ActionDescriptionProvider::createDescription(
530 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_ERROR_BARS ))),
531 m_xUndoManager );
532
533 // add error bars with standard deviation
534 uno::Reference< beans::XPropertySet > xErrorBarProp(
535 StatisticsHelper::addErrorBars( xSeries, m_xCC, ::com::sun::star::chart::ErrorBarStyle::STANDARD_DEVIATION ));
536
537 // get an appropriate item converter
538 wrapper::ErrorBarItemConverter aItemConverter(
539 getModel(), xErrorBarProp, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
540 m_pDrawModelWrapper->getSdrModel(),
541 uno::Reference< lang::XMultiServiceFactory >( getModel(), uno::UNO_QUERY ));
542
543 // open dialog
544 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
545 aItemConverter.FillItemSet( aItemSet );
546 ObjectPropertiesDialogParameter aDialogParameter = ObjectPropertiesDialogParameter(
547 ObjectIdentifier::createClassifiedIdentifierWithParent(
548 OBJECTTYPE_DATA_ERRORS, ::rtl::OUString(), m_aSelection.getSelectedCID()));
549 aDialogParameter.init( getModel() );
550 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
551 ::vos::OGuard aGuard( Application::GetSolarMutex());
552 SchAttribTabDlg aDlg( m_pChartWindow, &aItemSet, &aDialogParameter, &aViewElementListProvider,
553 uno::Reference< util::XNumberFormatsSupplier >( getModel(), uno::UNO_QUERY ));
554 aDlg.SetAxisMinorStepWidthForErrorBarDecimals(
555 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getModel(), m_xChartView, m_aSelection.getSelectedCID()));
556
557 // note: when a user pressed "OK" but didn't change any settings in the
558 // dialog, the SfxTabDialog returns "Cancel"
559 if( aDlg.Execute() == RET_OK || aDlg.DialogWasClosedWithOK())
560 {
561 const SfxItemSet* pOutItemSet = aDlg.GetOutputItemSet();
562 if( pOutItemSet )
563 {
564 ControllerLockGuard aCLGuard( getModel() );
565 aItemConverter.ApplyItemSet( *pOutItemSet );
566 }
567 aUndoGuard.commit();
568 }
569 }
570 }
571
executeDispatch_InsertTrendlineEquation(bool bInsertR2)572 void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 )
573 {
574 uno::Reference< chart2::XRegressionCurve > xRegCurve(
575 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
576 if( !xRegCurve.is() )
577 {
578 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
579 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
580 xRegCurve.set( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) );
581 }
582 if( xRegCurve.is())
583 {
584 uno::Reference< beans::XPropertySet > xEqProp( xRegCurve->getEquationProperties());
585 if( xEqProp.is())
586 {
587 // using assignment for broken gcc 3.3
588 UndoGuard aUndoGuard = UndoGuard(
589 ActionDescriptionProvider::createDescription(
590 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
591 m_xUndoManager );
592 xEqProp->setPropertyValue( C2U("ShowEquation"), uno::makeAny( true ));
593 xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( bInsertR2 ));
594 aUndoGuard.commit();
595 }
596 }
597 }
598
executeDispatch_InsertR2Value()599 void ChartController::executeDispatch_InsertR2Value()
600 {
601 uno::Reference< beans::XPropertySet > xEqProp(
602 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
603 if( xEqProp.is())
604 {
605 UndoGuard aUndoGuard = UndoGuard(
606 ActionDescriptionProvider::createDescription(
607 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
608 m_xUndoManager );
609 xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( true ));
610 aUndoGuard.commit();
611 }
612 }
613
executeDispatch_DeleteR2Value()614 void ChartController::executeDispatch_DeleteR2Value()
615 {
616 uno::Reference< beans::XPropertySet > xEqProp(
617 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
618 if( xEqProp.is())
619 {
620 UndoGuard aUndoGuard = UndoGuard(
621 ActionDescriptionProvider::createDescription(
622 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
623 m_xUndoManager );
624 xEqProp->setPropertyValue( C2U("ShowCorrelationCoefficient"), uno::makeAny( false ));
625 aUndoGuard.commit();
626 }
627 }
628
executeDispatch_DeleteMeanValue()629 void ChartController::executeDispatch_DeleteMeanValue()
630 {
631 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
632 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
633 if( xRegCurveCnt.is())
634 {
635 UndoGuard aUndoGuard(
636 ActionDescriptionProvider::createDescription(
637 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_AVERAGE_LINE ))),
638 m_xUndoManager );
639 RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt );
640 aUndoGuard.commit();
641 }
642 }
643
executeDispatch_DeleteTrendline()644 void ChartController::executeDispatch_DeleteTrendline()
645 {
646 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
647 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
648 if( xRegCurveCnt.is())
649 {
650 UndoGuard aUndoGuard(
651 ActionDescriptionProvider::createDescription(
652 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE ))),
653 m_xUndoManager );
654 RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt );
655 aUndoGuard.commit();
656 }
657 }
658
executeDispatch_DeleteTrendlineEquation()659 void ChartController::executeDispatch_DeleteTrendlineEquation()
660 {
661 uno::Reference< chart2::XRegressionCurveContainer > xRegCurveCnt(
662 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
663 if( xRegCurveCnt.is())
664 {
665 UndoGuard aUndoGuard(
666 ActionDescriptionProvider::createDescription(
667 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE_EQUATION ))),
668 m_xUndoManager );
669 RegressionCurveHelper::removeEquations( xRegCurveCnt );
670 aUndoGuard.commit();
671 }
672 }
673
executeDispatch_DeleteYErrorBars()674 void ChartController::executeDispatch_DeleteYErrorBars()
675 {
676 uno::Reference< chart2::XDataSeries > xDataSeries(
677 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ));
678 if( xDataSeries.is())
679 {
680 UndoGuard aUndoGuard(
681 ActionDescriptionProvider::createDescription(
682 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_CURVE ))),
683 m_xUndoManager );
684 StatisticsHelper::removeErrorBars( xDataSeries );
685 aUndoGuard.commit();
686 }
687 }
688
executeDispatch_InsertDataLabels()689 void ChartController::executeDispatch_InsertDataLabels()
690 {
691 uno::Reference< chart2::XDataSeries > xSeries(
692 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
693 if( xSeries.is() )
694 {
695 UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::INSERT,
696 String( SchResId( STR_OBJECT_DATALABELS ))),
697 m_xUndoManager );
698 DataSeriesHelper::insertDataLabelsToSeriesAndAllPoints( xSeries );
699 aUndoGuard.commit();
700 }
701 }
702
executeDispatch_InsertDataLabel()703 void ChartController::executeDispatch_InsertDataLabel()
704 {
705 UndoGuard aUndoGuard = UndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::INSERT,
706 String( SchResId( STR_OBJECT_LABEL ))),
707 m_xUndoManager );
708 DataSeriesHelper::insertDataLabelToPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) );
709 aUndoGuard.commit();
710 }
711
executeDispatch_DeleteDataLabels()712 void ChartController::executeDispatch_DeleteDataLabels()
713 {
714 uno::Reference< chart2::XDataSeries > xSeries(
715 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
716 if( xSeries.is() )
717 {
718 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::DELETE,
719 String( SchResId( STR_OBJECT_DATALABELS ))),
720 m_xUndoManager );
721 DataSeriesHelper::deleteDataLabelsFromSeriesAndAllPoints( xSeries );
722 aUndoGuard.commit();
723 }
724 }
725
executeDispatch_DeleteDataLabel()726 void ChartController::executeDispatch_DeleteDataLabel()
727 {
728 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::DELETE,
729 String( SchResId( STR_OBJECT_LABEL ))),
730 m_xUndoManager );
731 DataSeriesHelper::deleteDataLabelsFromPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getModel() ) );
732 aUndoGuard.commit();
733 }
734
executeDispatch_ResetAllDataPoints()735 void ChartController::executeDispatch_ResetAllDataPoints()
736 {
737 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::FORMAT,
738 String( SchResId( STR_OBJECT_DATAPOINTS ))),
739 m_xUndoManager );
740 uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
741 if( xSeries.is() )
742 xSeries->resetAllDataPoints();
743 aUndoGuard.commit();
744 }
executeDispatch_ResetDataPoint()745 void ChartController::executeDispatch_ResetDataPoint()
746 {
747 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::FORMAT,
748 String( SchResId( STR_OBJECT_DATAPOINT ))),
749 m_xUndoManager );
750 uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getModel() ), uno::UNO_QUERY );
751 if( xSeries.is() )
752 {
753 sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( m_aSelection.getSelectedCID() );
754 xSeries->resetDataPoint( nPointIndex );
755 }
756 aUndoGuard.commit();
757 }
758
executeDispatch_InsertAxisTitle()759 void ChartController::executeDispatch_InsertAxisTitle()
760 {
761 try
762 {
763 uno::Reference< XTitle > xTitle;
764 {
765 UndoGuard aUndoGuard(
766 ActionDescriptionProvider::createDescription(
767 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_TITLE ))),
768 m_xUndoManager );
769
770 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
771 sal_Int32 nDimensionIndex = -1;
772 sal_Int32 nCooSysIndex = -1;
773 sal_Int32 nAxisIndex = -1;
774 AxisHelper::getIndicesForAxis( xAxis, ChartModelHelper::findDiagram(getModel()), nCooSysIndex, nDimensionIndex, nAxisIndex );
775
776 TitleHelper::eTitleType eTitleType = TitleHelper::X_AXIS_TITLE;
777 if( nDimensionIndex==0 )
778 eTitleType = nAxisIndex==0 ? TitleHelper::X_AXIS_TITLE : TitleHelper::SECONDARY_X_AXIS_TITLE;
779 else if( nDimensionIndex==1 )
780 eTitleType = nAxisIndex==0 ? TitleHelper::Y_AXIS_TITLE : TitleHelper::SECONDARY_Y_AXIS_TITLE;
781 else
782 eTitleType = TitleHelper::Z_AXIS_TITLE;
783
784 ::std::auto_ptr< ReferenceSizeProvider > apRefSizeProvider( impl_createReferenceSizeProvider());
785 xTitle = TitleHelper::createTitle( eTitleType, ObjectNameProvider::getTitleNameByType(eTitleType), getModel(), m_xCC, apRefSizeProvider.get() );
786 aUndoGuard.commit();
787 }
788
789 /*
790 if( xTitle.is() )
791 {
792 OUString aTitleCID = ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, getModel() );
793 select( uno::makeAny(aTitleCID) );
794 executeDispatch_EditText();
795 }
796 */
797 }
798 catch( uno::RuntimeException& e)
799 {
800 ASSERT_EXCEPTION( e );
801 }
802 }
803
executeDispatch_InsertAxis()804 void ChartController::executeDispatch_InsertAxis()
805 {
806 UndoGuard aUndoGuard(
807 ActionDescriptionProvider::createDescription(
808 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_AXIS ))),
809 m_xUndoManager );
810
811 try
812 {
813 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
814 if( xAxis.is() )
815 {
816 AxisHelper::makeAxisVisible( xAxis );
817 aUndoGuard.commit();
818 }
819 }
820 catch( uno::RuntimeException& e)
821 {
822 ASSERT_EXCEPTION( e );
823 }
824 }
825
executeDispatch_DeleteAxis()826 void ChartController::executeDispatch_DeleteAxis()
827 {
828 UndoGuard aUndoGuard(
829 ActionDescriptionProvider::createDescription(
830 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_AXIS ))),
831 m_xUndoManager );
832
833 try
834 {
835 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
836 if( xAxis.is() )
837 {
838 AxisHelper::makeAxisInvisible( xAxis );
839 aUndoGuard.commit();
840 }
841 }
842 catch( uno::RuntimeException& e)
843 {
844 ASSERT_EXCEPTION( e );
845 }
846 }
847
executeDispatch_InsertMajorGrid()848 void ChartController::executeDispatch_InsertMajorGrid()
849 {
850 UndoGuard aUndoGuard(
851 ActionDescriptionProvider::createDescription(
852 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRID ))),
853 m_xUndoManager );
854
855 try
856 {
857 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
858 if( xAxis.is() )
859 {
860 AxisHelper::makeGridVisible( xAxis->getGridProperties() );
861 aUndoGuard.commit();
862 }
863 }
864 catch( uno::RuntimeException& e)
865 {
866 ASSERT_EXCEPTION( e );
867 }
868 }
869
executeDispatch_DeleteMajorGrid()870 void ChartController::executeDispatch_DeleteMajorGrid()
871 {
872 UndoGuard aUndoGuard(
873 ActionDescriptionProvider::createDescription(
874 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_GRID ))),
875 m_xUndoManager );
876
877 try
878 {
879 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
880 if( xAxis.is() )
881 {
882 AxisHelper::makeGridInvisible( xAxis->getGridProperties() );
883 aUndoGuard.commit();
884 }
885 }
886 catch( uno::RuntimeException& e)
887 {
888 ASSERT_EXCEPTION( e );
889 }
890 }
891
executeDispatch_InsertMinorGrid()892 void ChartController::executeDispatch_InsertMinorGrid()
893 {
894 UndoGuard aUndoGuard(
895 ActionDescriptionProvider::createDescription(
896 ActionDescriptionProvider::INSERT, String( SchResId( STR_OBJECT_GRID ))),
897 m_xUndoManager );
898
899 try
900 {
901 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
902 if( xAxis.is() )
903 {
904 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
905 for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
906 AxisHelper::makeGridVisible( aSubGrids[nN] );
907 aUndoGuard.commit();
908 }
909 }
910 catch( uno::RuntimeException& e)
911 {
912 ASSERT_EXCEPTION( e );
913 }
914 }
915
executeDispatch_DeleteMinorGrid()916 void ChartController::executeDispatch_DeleteMinorGrid()
917 {
918 UndoGuard aUndoGuard(
919 ActionDescriptionProvider::createDescription(
920 ActionDescriptionProvider::DELETE, String( SchResId( STR_OBJECT_GRID ))),
921 m_xUndoManager );
922
923 try
924 {
925 Reference< XAxis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getModel() );
926 if( xAxis.is() )
927 {
928 Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );
929 for( sal_Int32 nN=0; nN<aSubGrids.getLength(); nN++)
930 AxisHelper::makeGridInvisible( aSubGrids[nN] );
931 aUndoGuard.commit();
932 }
933 }
934 catch( uno::RuntimeException& e)
935 {
936 ASSERT_EXCEPTION( e );
937 }
938 }
939
940 //.............................................................................
941 } //namespace chart
942 //.............................................................................
943