Debian Codegraph @

chart2/source/controller/main/ChartController_Insert.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <memory>
21 #include <ChartController.hxx>
22
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>
30
31 #include <Axis.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"
44 #include <ResId.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>
54 #include <Legend.hxx>
55 #include <LegendHelper.hxx>
56 #include <DataTable.hxx>
57 #include <RegressionCurveModel.hxx>
58
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>
63
64 #include <comphelper/diagnose_ex.hxx>
65 #include <vcl/svapp.hxx>
66
67 using namespace ::com::sun::star;
68 using namespace ::com::sun::star::chart2;
69 using ::com::sun::star::uno::Reference;
70
71 namespace
72 {
73
74 void lcl_InsertMeanValueLine( const rtl::Reference< ::chart::DataSeries > & xSeries )
75 {
76 if( xSeries.is())
77 {
78 ::chart::RegressionCurveHelper::addMeanValueLine(
79 xSeries, xSeries);
80 }
81 }
82
83 } // anonymous namespace
84
85 namespace chart
86 {
87
88 void ChartController::executeDispatch_InsertAxes()
89 {
90 auto xUndoGuard = std::make_shared<UndoGuard>(
91 ActionDescriptionProvider::createDescription(
92 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AXES )),
93 m_xUndoManager );
94
95 try
96 {
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 );
101
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 )
107 {
108 // lock controllers till end of block
109 ControllerLockGuardUNO aCLGuard( getChartModel() );
110
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 );
117 if( bChanged )
118 xUndoGuard->commit();
119 }
120 });
121 }
122 catch(const uno::RuntimeException&)
123 {
124 TOOLS_WARN_EXCEPTION("chart2", "" );
125 }
126 }
127
128 void ChartController::executeDispatch_InsertGrid()
129 {
130 UndoGuard aUndoGuard(
131 ActionDescriptionProvider::createDescription(
132 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_GRIDS )),
133 m_xUndoManager );
134
135 try
136 {
137 InsertAxisOrGridDialogData aDialogInput;
138 rtl::Reference< Diagram > xDiagram = getFirstDiagram();
139 AxisHelper::getAxisOrGridExistence( aDialogInput.aExistenceList, xDiagram, false );
140 AxisHelper::getAxisOrGridPossibilities( aDialogInput.aPossibilityList, xDiagram, false );
141
142 SolarMutexGuard aGuard;
143 SchGridDlg aDlg(GetChartFrame(), aDialogInput);//aItemSet, b3D, bNet, bSecondaryX, bSecondaryY );
144 if (aDlg.run() == RET_OK)
145 {
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 );
152 if( bChanged )
153 aUndoGuard.commit();
154 }
155 }
156 catch(const uno::RuntimeException&)
157 {
158 TOOLS_WARN_EXCEPTION("chart2", "" );
159 }
160 }
161
162 void ChartController::executeDispatch_OpenInsertDataTableDialog()
163 {
164 SolarMutexGuard aGuard;
165
166 auto aUndoDescription = ActionDescriptionProvider::createDescription(ActionDescriptionProvider::ActionType::Insert, SchResId(STR_DATA_TABLE));
167 UndoGuard aUndoGuard(aUndoDescription, m_xUndoManager);
168
169 rtl::Reference<Diagram> xDiagram = getFirstDiagram();
170
171 InsertDataTableDialog aDialog(GetChartFrame());
172 {
173 // init values
174 DataTableDialogData aData;
175 auto xDataTable = xDiagram->getDataTable();
176 aData.mbShow = xDataTable.is();
177 if (xDataTable.is())
178 {
179 uno::Reference<beans::XPropertySet> xProperties(xDataTable, uno::UNO_QUERY);
180
181 uno::Any aAny = xProperties->getPropertyValue(u"HBorder"_ustr);
182 if (aAny.has<bool>())
183 aData.mbHorizontalBorders = aAny.get<bool>();
184
185 aAny = xProperties->getPropertyValue(u"VBorder"_ustr);
186 if (aAny.has<bool>())
187 aData.mbVerticalBorders = aAny.get<bool>();
188
189 aAny = xProperties->getPropertyValue(u"Outline"_ustr);
190 if (aAny.has<bool>())
191 aData.mbOutline = aAny.get<bool>();
192
193 aAny = xProperties->getPropertyValue(u"Keys"_ustr);
194 if (aAny.has<bool>())
195 aData.mbKeys = aAny.get<bool>();
196 }
197 aDialog.init(aData);
198 }
199
200 // show the dialog
201 if (aDialog.run() == RET_OK)
202 {
203 bool bChanged = false;
204
205 auto& rDialogData = aDialog.getDataTableDialogData();
206 auto xDataTable = xDiagram->getDataTable();
207 if (!rDialogData.mbShow && xDataTable.is())
208 {
209 xDiagram->setDataTable(uno::Reference<chart2::XDataTable>());
210 bChanged = true;
211 }
212 else if (rDialogData.mbShow && !xDataTable.is())
213 {
214 uno::Reference<chart2::XDataTable> xNewDataTable(new DataTable);
215 if (xNewDataTable.is())
216 {
217 xDiagram->setDataTable(xNewDataTable);
218 bChanged = true;
219 }
220 }
221
222 // Set the properties
223 xDataTable = xDiagram->getDataTable();
224 if (rDialogData.mbShow && xDataTable.is())
225 {
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));
231 bChanged = true;
232 }
233
234 if (bChanged)
235 aUndoGuard.commit();
236 }
237 }
238
239 /** Create and insert a data table to the chart */
240 void ChartController::executeDispatch_InsertDataTable()
241 {
242 auto aUndoDescription = ActionDescriptionProvider::createDescription(ActionDescriptionProvider::ActionType::Insert, SchResId(STR_DATA_TABLE));
243 UndoGuard aUndoGuard(aUndoDescription, m_xUndoManager);
244
245
246 rtl::Reference<Diagram> xDiagram = getFirstDiagram();
247 auto xDataTable = xDiagram->getDataTable();
248 if (!xDataTable.is())
249 {
250 uno::Reference<chart2::XDataTable> xNewDataTable(new DataTable);
251 if (xNewDataTable.is())
252 {
253 xDiagram->setDataTable(xNewDataTable);
254 aUndoGuard.commit();
255 }
256 }
257 }
258
259 /** Delete a data table from the chart */
260 void ChartController::executeDispatch_DeleteDataTable()
261 {
262 auto aUndoDescription = ActionDescriptionProvider::createDescription(ActionDescriptionProvider::ActionType::Delete, SchResId(STR_DATA_TABLE));
263 UndoGuard aUndoGuard(aUndoDescription, m_xUndoManager);
264
265 rtl::Reference<Diagram> xDiagram = getFirstDiagram();
266 auto xDataTable = xDiagram->getDataTable();
267 if (xDataTable.is())
268 {
269 // insert a empty data table reference
270 xDiagram->setDataTable(uno::Reference<chart2::XDataTable>());
271 aUndoGuard.commit();
272 }
273 }
274
275 void ChartController::executeDispatch_InsertTitles()
276 {
277 auto xUndoGuard = std::make_shared<UndoGuard>(
278 ActionDescriptionProvider::createDescription(
279 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_TITLES )),
280 m_xUndoManager );
281
282 try
283 {
284 auto xDialogInput = std::make_shared<TitleDialogData>();
285 xDialogInput->readFromModel( getChartModel() );
286
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 )
292 {
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() );
298 if( bChanged )
299 xUndoGuard->commit();
300 }
301 });
302 }
303 catch(const uno::RuntimeException&)
304 {
305 TOOLS_WARN_EXCEPTION("chart2", "" );
306 }
307 }
308
309 void ChartController::executeDispatch_DeleteLegend()
310 {
311 UndoGuard aUndoGuard(
312 ActionDescriptionProvider::createDescription(
313 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_LEGEND )),
314 m_xUndoManager );
315
316 LegendHelper::hideLegend(*getChartModel());
317 aUndoGuard.commit();
318 }
319
320 void ChartController::executeDispatch_InsertLegend()
321 {
322 UndoGuard aUndoGuard(
323 ActionDescriptionProvider::createDescription(
324 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_LEGEND )),
325 m_xUndoManager );
326
327 LegendHelper::showLegend(*getChartModel(), m_xCC);
328 aUndoGuard.commit();
329 }
330
331 void ChartController::executeDispatch_OpenLegendDialog()
332 {
333 UndoGuard aUndoGuard(
334 ActionDescriptionProvider::createDescription(
335 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_LEGEND )),
336 m_xUndoManager );
337
338 try
339 {
340 //prepare and open dialog
341 SolarMutexGuard aGuard;
342 SchLegendDlg aDlg(GetChartFrame(), m_xCC);
343 aDlg.init( getChartModel() );
344 if (aDlg.run() == RET_OK)
345 {
346 // lock controllers till end of block
347 ControllerLockGuardUNO aCLGuard( getChartModel() );
348 aDlg.writeToModel( getChartModel() );
349 aUndoGuard.commit();
350 }
351 }
352 catch(const uno::RuntimeException&)
353 {
354 TOOLS_WARN_EXCEPTION("chart2", "" );
355 }
356 }
357
358 void ChartController::executeDispatch_InsertMenu_DataLabels()
359 {
360 std::shared_ptr<UndoGuard> aUndoGuard = std::make_shared<UndoGuard>(
361 ActionDescriptionProvider::createDescription(
362 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_DATALABELS )),
363 m_xUndoManager );
364
365 //if a series is selected insert labels for that series only:
366 rtl::Reference< DataSeries > xSeries =
367 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel());
368 if( xSeries.is() )
369 {
370 // add labels
371 xSeries->insertDataLabelsToSeriesAndAllPoints();
372
373 OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) + "=" );
374 OUString aObjectCID = ObjectIdentifier::createClassifiedIdentifierForParticles(
375 ObjectIdentifier::getSeriesParticleFromCID(m_aSelection.getSelectedCID()), aChildParticle );
376
377 ChartController::executeDlg_ObjectProperties_withUndoGuard(std::move(aUndoGuard), aObjectCID, true );
378 return;
379 }
380 try
381 {
382 wrapper::AllDataLabelItemConverter aItemConverter(
383 getChartModel(),
384 m_pDrawModelWrapper->GetItemPool(),
385 m_pDrawModelWrapper->getSdrModel() );
386 SfxItemSet aItemSet = aItemConverter.CreateEmptyItemSet();
387 aItemConverter.FillItemSet( aItemSet );
388
389 //prepare and open dialog
390 SolarMutexGuard aGuard;
391
392 //get number formatter
393 NumberFormatterWrapper aNumberFormatterWrapper( getChartModel() );
394 SvNumberFormatter* pNumberFormatter = aNumberFormatterWrapper.getSvNumberFormatter();
395
396 DataLabelsDialog aDlg(GetChartFrame(), aItemSet, pNumberFormatter);
397
398 if (aDlg.run() == RET_OK)
399 {
400 SfxItemSet aOutItemSet = aItemConverter.CreateEmptyItemSet();
401 aDlg.FillItemSet(aOutItemSet);
402 // lock controllers till end of block
403 ControllerLockGuardUNO aCLGuard( getChartModel() );
404 bool bChanged = aItemConverter.ApplyItemSet( aOutItemSet );//model should be changed now
405 if( bChanged )
406 aUndoGuard->commit();
407 }
408 }
409 catch(const uno::RuntimeException&)
410 {
411 TOOLS_WARN_EXCEPTION("chart2", "" );
412 }
413 }
414
415 void ChartController::executeDispatch_InsertMeanValue()
416 {
417 UndoGuard aUndoGuard(
418 ActionDescriptionProvider::createDescription(
419 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AVERAGE_LINE )),
420 m_xUndoManager );
421 lcl_InsertMeanValueLine( ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(),
422 getChartModel() ) );
423 aUndoGuard.commit();
424 }
425
426 void ChartController::executeDispatch_InsertMenu_MeanValues()
427 {
428 UndoGuard aUndoGuard(
429 ActionDescriptionProvider::createDescription(
430 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AVERAGE_LINE )),
431 m_xUndoManager );
432
433 rtl::Reference< DataSeries > xSeries =
434 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() );
435 if( xSeries.is() )
436 {
437 //if a series is selected insert mean value only for that series:
438 lcl_InsertMeanValueLine( xSeries );
439 }
440 else if (rtl::Reference<Diagram> xDiagram = getFirstDiagram())
441 {
442 std::vector< rtl::Reference< DataSeries > > aSeries =
443 xDiagram->getDataSeries();
444
445 for( const auto& xSrs : aSeries )
446 lcl_InsertMeanValueLine( xSrs );
447 }
448 aUndoGuard.commit();
449 }
450
451 void ChartController::executeDispatch_InsertMenu_Trendlines()
452 {
453 OUString aCID = m_aSelection.getSelectedCID();
454
455 rtl::Reference< DataSeries > xSeries =
456 ObjectIdentifier::getDataSeriesForCID( aCID, getChartModel() );
457
458 if( !xSeries.is() )
459 return;
460
461 executeDispatch_InsertTrendline();
462 }
463
464 void ChartController::executeDispatch_InsertTrendline()
465 {
466 rtl::Reference<ChartModel> xChartModel = getChartModel();
467
468 rtl::Reference< DataSeries > xRegressionCurveContainer =
469 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), xChartModel);
470
471 if( !xRegressionCurveContainer.is() )
472 return;
473
474 auto xUndoGuard = std::make_shared<UndoLiveUpdateGuard>(
475 ActionDescriptionProvider::createDescription(
476 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE )),
477 m_xUndoManager );
478
479 rtl::Reference< RegressionCurveModel > xCurve =
480 RegressionCurveHelper::addRegressionCurve(
481 SvxChartRegress::Linear,
482 xRegressionCurveContainer );
483
484 if( !xCurve.is())
485 return;
486
487 auto aItemConverter = std::make_shared<wrapper::RegressionCurveItemConverter>(
488 xCurve, xRegressionCurveContainer, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
489 m_pDrawModelWrapper->getSdrModel(),
490 xChartModel );
491
492 // open dialog
493 SfxItemSet aItemSet = aItemConverter->CreateEmptyItemSet();
494 aItemConverter->FillItemSet( aItemSet );
495 ObjectPropertiesDialogParameter aDialogParameter(
496 ObjectIdentifier::createDataCurveCID(
497 ObjectIdentifier::getSeriesParticleFromCID( m_aSelection.getSelectedCID()),
498 RegressionCurveHelper::getRegressionCurveIndex( xRegressionCurveContainer, xCurve ), false ));
499 aDialogParameter.init( xChartModel );
500 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
501 SolarMutexGuard aGuard;
502 auto aDialog = std::make_shared<SchAttribTabDlg>(GetChartFrame(), &aItemSet, aDialogParameter,
503 &aViewElementListProvider, xChartModel);
504
505 // note: when a user pressed "OK" but didn't change any settings in the
506 // dialog, the SfxTabDialog returns "Cancel"
507 SfxTabDialogController::runAsync(aDialog, [aDialog, aItemConverter = std::move(aItemConverter),
508 xUndoGuard=std::move(xUndoGuard),
509 xChartModel=std::move(xChartModel)](int nResult) {
510 if ( nResult == RET_OK || aDialog->DialogWasClosedWithOK() )
511 {
512 const SfxItemSet* pOutItemSet = aDialog->GetOutputItemSet();
513 if( pOutItemSet )
514 {
515 ControllerLockGuardUNO aCLGuard( xChartModel );
516 aItemConverter->ApplyItemSet( *pOutItemSet );
517 }
518 xUndoGuard->commit();
519 }
520 });
521 }
522
523 void ChartController::executeDispatch_InsertErrorBars( bool bYError )
524 {
525 ObjectType objType = bYError ? OBJECTTYPE_DATA_ERRORS_Y : OBJECTTYPE_DATA_ERRORS_X;
526
527 //if a series is selected insert error bars for that series only:
528 rtl::Reference< DataSeries > xSeries =
529 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() );
530
531 if( xSeries.is())
532 {
533 auto xUndoGuard = std::make_shared<UndoLiveUpdateGuard>(
534 ActionDescriptionProvider::createDescription(
535 ActionDescriptionProvider::ActionType::Insert,
536 SchResId( bYError ? STR_OBJECT_ERROR_BARS_Y : STR_OBJECT_ERROR_BARS_X )),
537 m_xUndoManager );
538
539 // add error bars with standard deviation
540 uno::Reference< beans::XPropertySet > xErrorBarProp(
541 StatisticsHelper::addErrorBars( xSeries,
542 css::chart::ErrorBarStyle::STANDARD_DEVIATION,
543 bYError));
544
545 // get an appropriate item converter
546 auto aItemConverter = std::make_shared<wrapper::ErrorBarItemConverter> (
547 getChartModel(), xErrorBarProp, m_pDrawModelWrapper->getSdrModel().GetItemPool(),
548 m_pDrawModelWrapper->getSdrModel() );
549
550 // open dialog
551 SfxItemSet aItemSet = aItemConverter->CreateEmptyItemSet();
552 aItemSet.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE,bYError));
553 aItemConverter->FillItemSet( aItemSet );
554 ObjectPropertiesDialogParameter aDialogParameter(
555 ObjectIdentifier::createClassifiedIdentifierWithParent(
556 objType, u"", m_aSelection.getSelectedCID()));
557 aDialogParameter.init( getChartModel() );
558 ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get());
559 SolarMutexGuard aGuard;
560 auto aDlg = std::make_shared<SchAttribTabDlg>(
561 GetChartFrame(), &aItemSet, aDialogParameter,
562 &aViewElementListProvider,
563 getChartModel() );
564 aDlg->SetAxisMinorStepWidthForErrorBarDecimals(
565 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getChartModel(),
566 m_xChartView, m_aSelection.getSelectedCID()));
567
568 // note: when a user pressed "OK" but didn't change any settings in the
569 // dialog, the SfxTabDialog returns "Cancel"
570 SfxTabDialogController::runAsync(aDlg, [this, aDlg, aItemConverter=std::move(aItemConverter),
571 xUndoGuard=std::move(xUndoGuard)](int nResult) {
572 if ( nResult == RET_OK || aDlg->DialogWasClosedWithOK() )
573 {
574 const SfxItemSet* pOutItemSet = aDlg->GetOutputItemSet();
575 if( pOutItemSet )
576 {
577 ControllerLockGuardUNO aCLGuard( getChartModel() );
578 aItemConverter->ApplyItemSet( *pOutItemSet );
579 }
580 xUndoGuard->commit();
581 }
582 });
583 }
584 else
585 {
586 //if no series is selected insert error bars for all series
587 auto xUndoGuard = std::make_shared<UndoGuard>(
588 ActionDescriptionProvider::createDescription(
589 ActionDescriptionProvider::ActionType::Insert,
590 ObjectNameProvider::getName_ObjectForAllSeries( objType ) ),
591 m_xUndoManager );
592
593 try
594 {
595 auto xItemConverter = std::make_shared<wrapper::AllSeriesStatisticsConverter>(
596 getChartModel(), m_pDrawModelWrapper->GetItemPool() );
597 SfxItemSet aItemSet = xItemConverter->CreateEmptyItemSet();
598 xItemConverter->FillItemSet( aItemSet );
599
600 //prepare and open dialog
601 SolarMutexGuard aGuard;
602 auto aDlg = std::make_shared<InsertErrorBarsDialog>(
603 GetChartFrame(), aItemSet,
604 getChartModel(),
605 bYError ? ErrorBarResources::ERROR_BAR_Y : ErrorBarResources::ERROR_BAR_X);
606
607 aDlg->SetAxisMinorStepWidthForErrorBarDecimals(
608 InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( getChartModel(), m_xChartView, u"" ) );
609
610 weld::DialogController::runAsync(aDlg, [this, aDlg, xItemConverter=std::move(xItemConverter),
611 xUndoGuard=std::move(xUndoGuard)](int nResult) {
612 if ( nResult == RET_OK )
613 {
614 SfxItemSet aOutItemSet = xItemConverter->CreateEmptyItemSet();
615 aDlg->FillItemSet( aOutItemSet );
616
617 // lock controllers till end of block
618 ControllerLockGuardUNO aCLGuard( getChartModel() );
619 bool bChanged = xItemConverter->ApplyItemSet( aOutItemSet );//model should be changed now
620 if( bChanged )
621 xUndoGuard->commit();
622 }
623 });
624 }
625 catch(const uno::RuntimeException&)
626 {
627 TOOLS_WARN_EXCEPTION("chart2", "" );
628 }
629 }
630 }
631
632 void ChartController::executeDispatch_InsertTrendlineEquation( bool bInsertR2 )
633 {
634 uno::Reference< chart2::XRegressionCurve > xRegCurve(
635 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getChartModel() ), uno::UNO_QUERY );
636 if( !xRegCurve.is() )
637 {
638 rtl::Reference< DataSeries > xRegCurveCnt =
639 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() );
640 xRegCurve.set( RegressionCurveHelper::getFirstCurveNotMeanValueLine( xRegCurveCnt ) );
641 }
642 if( !xRegCurve.is())
643 return;
644
645 uno::Reference< beans::XPropertySet > xEqProp( xRegCurve->getEquationProperties());
646 if( xEqProp.is())
647 {
648 UndoGuard aUndoGuard(
649 ActionDescriptionProvider::createDescription(
650 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )),
651 m_xUndoManager );
652 xEqProp->setPropertyValue( u"ShowEquation"_ustr, uno::Any( true ));
653 xEqProp->setPropertyValue( u"XName"_ustr, uno::Any( u"x"_ustr ));
654 xEqProp->setPropertyValue( u"YName"_ustr, uno::Any( u"f(x)"_ustr ));
655 xEqProp->setPropertyValue( u"ShowCorrelationCoefficient"_ustr, uno::Any( bInsertR2 ));
656 aUndoGuard.commit();
657 }
658 }
659
660 void ChartController::executeDispatch_InsertR2Value()
661 {
662 uno::Reference< beans::XPropertySet > xEqProp =
663 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getChartModel() );
664 if( xEqProp.is())
665 {
666 UndoGuard aUndoGuard(
667 ActionDescriptionProvider::createDescription(
668 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )),
669 m_xUndoManager );
670 xEqProp->setPropertyValue( u"ShowCorrelationCoefficient"_ustr, uno::Any( true ));
671 aUndoGuard.commit();
672 }
673 }
674
675 void ChartController::executeDispatch_DeleteR2Value()
676 {
677 uno::Reference< beans::XPropertySet > xEqProp =
678 ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getChartModel() );
679 if( xEqProp.is())
680 {
681 UndoGuard aUndoGuard(
682 ActionDescriptionProvider::createDescription(
683 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_CURVE_EQUATION )),
684 m_xUndoManager );
685 xEqProp->setPropertyValue( u"ShowCorrelationCoefficient"_ustr, uno::Any( false ));
686 aUndoGuard.commit();
687 }
688 }
689
690 void ChartController::executeDispatch_DeleteMeanValue()
691 {
692 rtl::Reference< DataSeries > xRegCurveCnt =
693 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() );
694 if( xRegCurveCnt.is())
695 {
696 UndoGuard aUndoGuard(
697 ActionDescriptionProvider::createDescription(
698 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_AVERAGE_LINE )),
699 m_xUndoManager );
700 RegressionCurveHelper::removeMeanValueLine( xRegCurveCnt );
701 aUndoGuard.commit();
702 }
703 }
704
705 void ChartController::executeDispatch_DeleteTrendline()
706 {
707 rtl::Reference< DataSeries > xRegCurveCnt =
708 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() );
709 if( xRegCurveCnt.is())
710 {
711 UndoGuard aUndoGuard(
712 ActionDescriptionProvider::createDescription(
713 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE )),
714 m_xUndoManager );
715 RegressionCurveHelper::removeAllExceptMeanValueLine( xRegCurveCnt );
716 aUndoGuard.commit();
717 }
718 }
719
720 void ChartController::executeDispatch_DeleteTrendlineEquation()
721 {
722 rtl::Reference< DataSeries > xRegCurveCnt =
723 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() );
724 if( xRegCurveCnt.is())
725 {
726 UndoGuard aUndoGuard(
727 ActionDescriptionProvider::createDescription(
728 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE_EQUATION )),
729 m_xUndoManager );
730 RegressionCurveHelper::removeEquations( xRegCurveCnt );
731 aUndoGuard.commit();
732 }
733 }
734
735 void ChartController::executeDispatch_DeleteErrorBars( bool bYError )
736 {
737 rtl::Reference< DataSeries > xDataSeries =
738 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() );
739 if( xDataSeries.is())
740 {
741 UndoGuard aUndoGuard(
742 ActionDescriptionProvider::createDescription(
743 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_CURVE )),
744 m_xUndoManager );
745 StatisticsHelper::removeErrorBars( xDataSeries, bYError );
746 aUndoGuard.commit();
747 }
748 }
749
750 void ChartController::executeDispatch_InsertDataLabels()
751 {
752 rtl::Reference< DataSeries > xSeries =
753 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() );
754 if( xSeries.is() )
755 {
756 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert,
757 SchResId( STR_OBJECT_DATALABELS )),
758 m_xUndoManager );
759 xSeries->insertDataLabelsToSeriesAndAllPoints();
760 aUndoGuard.commit();
761 }
762 }
763
764 void ChartController::executeDispatch_InsertDataLabel()
765 {
766 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Insert,
767 SchResId( STR_OBJECT_LABEL )),
768 m_xUndoManager );
769 DataSeriesHelper::insertDataLabelToPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getChartModel() ) );
770 aUndoGuard.commit();
771 }
772
773 void ChartController::executeDispatch_DeleteDataLabels()
774 {
775 rtl::Reference< DataSeries > xSeries =
776 ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() );
777 if( xSeries.is() )
778 {
779 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete,
780 SchResId( STR_OBJECT_DATALABELS )),
781 m_xUndoManager );
782 xSeries->deleteDataLabelsFromSeriesAndAllPoints();
783 aUndoGuard.commit();
784 }
785 }
786
787 void ChartController::executeDispatch_DeleteDataLabel()
788 {
789 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Delete,
790 SchResId( STR_OBJECT_LABEL )),
791 m_xUndoManager );
792 DataSeriesHelper::deleteDataLabelsFromPoint( ObjectIdentifier::getObjectPropertySet( m_aSelection.getSelectedCID(), getChartModel() ) );
793 aUndoGuard.commit();
794 }
795
796 void ChartController::executeDispatch_ResetAllDataPoints()
797 {
798 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Format,
799 SchResId( STR_OBJECT_DATAPOINTS )),
800 m_xUndoManager );
801 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() );
802 if( xSeries.is() )
803 xSeries->resetAllDataPoints();
804 aUndoGuard.commit();
805 }
806 void ChartController::executeDispatch_ResetDataPoint()
807 {
808 UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::ActionType::Format,
809 SchResId( STR_OBJECT_DATAPOINT )),
810 m_xUndoManager );
811 rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( m_aSelection.getSelectedCID(), getChartModel() );
812 if( xSeries.is() )
813 {
814 sal_Int32 nPointIndex = ObjectIdentifier::getIndexFromParticleOrCID( m_aSelection.getSelectedCID() );
815 xSeries->resetDataPoint( nPointIndex );
816 }
817 aUndoGuard.commit();
818 }
819
820 void ChartController::executeDispatch_InsertAxisTitle()
821 {
822 try
823 {
824 rtl::Reference< Title > xTitle;
825 {
826 UndoGuard aUndoGuard(
827 ActionDescriptionProvider::createDescription(
828 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_TITLE )),
829 m_xUndoManager );
830
831 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() );
832 sal_Int32 nDimensionIndex = -1;
833 sal_Int32 nCooSysIndex = -1;
834 sal_Int32 nAxisIndex = -1;
835 AxisHelper::getIndicesForAxis( xAxis, getFirstDiagram(), nCooSysIndex, nDimensionIndex, nAxisIndex );
836
837 TitleHelper::eTitleType eTitleType = TitleHelper::X_AXIS_TITLE;
838 if( nDimensionIndex==0 )
839 eTitleType = nAxisIndex==0 ? TitleHelper::X_AXIS_TITLE : TitleHelper::SECONDARY_X_AXIS_TITLE;
840 else if( nDimensionIndex==1 )
841 eTitleType = nAxisIndex==0 ? TitleHelper::Y_AXIS_TITLE : TitleHelper::SECONDARY_Y_AXIS_TITLE;
842 else
843 eTitleType = TitleHelper::Z_AXIS_TITLE;
844
845 ReferenceSizeProvider aRefSizeProvider( impl_createReferenceSizeProvider());
846 xTitle = TitleHelper::createTitle( eTitleType, ObjectNameProvider::getTitleNameByType(eTitleType), getChartModel(), m_xCC, &aRefSizeProvider );
847 aUndoGuard.commit();
848 }
849 }
850 catch(const uno::RuntimeException&)
851 {
852 TOOLS_WARN_EXCEPTION("chart2", "" );
853 }
854 }
855
856 void ChartController::executeDispatch_InsertAxis()
857 {
858 UndoGuard aUndoGuard(
859 ActionDescriptionProvider::createDescription(
860 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_AXIS )),
861 m_xUndoManager );
862
863 try
864 {
865 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() );
866 if( xAxis.is() )
867 {
868 AxisHelper::makeAxisVisible( xAxis );
869 aUndoGuard.commit();
870 }
871 }
872 catch(const uno::RuntimeException&)
873 {
874 TOOLS_WARN_EXCEPTION("chart2", "" );
875 }
876 }
877
878 void ChartController::executeDispatch_DeleteAxis()
879 {
880 UndoGuard aUndoGuard(
881 ActionDescriptionProvider::createDescription(
882 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_AXIS )),
883 m_xUndoManager );
884
885 try
886 {
887 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() );
888 if( xAxis.is() )
889 {
890 AxisHelper::makeAxisInvisible( xAxis );
891 aUndoGuard.commit();
892 }
893 }
894 catch(const uno::RuntimeException&)
895 {
896 TOOLS_WARN_EXCEPTION("chart2", "" );
897 }
898 }
899
900 void ChartController::executeDispatch_InsertMajorGrid()
901 {
902 UndoGuard aUndoGuard(
903 ActionDescriptionProvider::createDescription(
904 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_GRID )),
905 m_xUndoManager );
906
907 try
908 {
909 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() );
910 if( xAxis.is() )
911 {
912 AxisHelper::makeGridVisible( xAxis->getGridProperties2() );
913 aUndoGuard.commit();
914 }
915 }
916 catch(const uno::RuntimeException&)
917 {
918 TOOLS_WARN_EXCEPTION("chart2", "" );
919 }
920 }
921
922 void ChartController::executeDispatch_DeleteMajorGrid()
923 {
924 UndoGuard aUndoGuard(
925 ActionDescriptionProvider::createDescription(
926 ActionDescriptionProvider::ActionType::Delete, SchResId( STR_OBJECT_GRID )),
927 m_xUndoManager );
928
929 try
930 {
931 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() );
932 if( xAxis.is() )
933 {
934 AxisHelper::makeGridInvisible( xAxis->getGridProperties2() );
935 aUndoGuard.commit();
936 }
937 }
938 catch(const uno::RuntimeException&)
939 {
940 TOOLS_WARN_EXCEPTION("chart2", "" );
941 }
942 }
943
944 void ChartController::executeDispatch_InsertMinorGrid()
945 {
946 UndoGuard aUndoGuard(
947 ActionDescriptionProvider::createDescription(
948 ActionDescriptionProvider::ActionType::Insert, SchResId( STR_OBJECT_GRID )),
949 m_xUndoManager );
950
951 try
952 {
953 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() );
954 if( xAxis.is() )
955 {
956 std::vector< rtl::Reference< ::chart::GridProperties > > aSubGrids( xAxis->getSubGridProperties2() );
957 for( rtl::Reference< GridProperties > const & props : aSubGrids)
958 AxisHelper::makeGridVisible( props );
959 aUndoGuard.commit();
960 }
961 }
962 catch(const uno::RuntimeException&)
963 {
964 TOOLS_WARN_EXCEPTION("chart2", "" );
965 }
966 }
967
968 void ChartController::executeDispatch_DeleteMinorGrid()
969 {
970 UndoGuard aUndoGuard(
971 ActionDescriptionProvider::createDescription(
972 ActionDescriptionProvider::ActionType::Delete, SchResId(STR_OBJECT_GRID)),
973 m_xUndoManager );
974
975 try
976 {
977 rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( m_aSelection.getSelectedCID(), getChartModel() );
978 if( xAxis.is() )
979 {
980 std::vector< rtl::Reference< ::chart::GridProperties > > aSubGrids( xAxis->getSubGridProperties2() );
981 for( rtl::Reference< ::chart::GridProperties > const & props : aSubGrids)
982 AxisHelper::makeGridInvisible( props );
983 aUndoGuard.commit();
984 }
985 }
986 catch(const uno::RuntimeException&)
987 {
988 TOOLS_WARN_EXCEPTION("chart2", "" );
989 }
990 }
991
992 } //namespace chart
993
994 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */