| 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 <ChartController.hxx> |
| 21 |
#include <ChartView.hxx> |
| 22 |
#include <chartview/DrawModelWrapper.hxx> |
| 23 |
#include <chartview/ChartSfxItemIds.hxx> |
| 24 |
#include <ObjectIdentifier.hxx> |
| 25 |
#include <chartview/ExplicitScaleValues.hxx> |
| 26 |
#include <dlg_ObjectProperties.hxx> |
| 27 |
#include <dlg_View3D.hxx> |
| 28 |
#include <dlg_InsertErrorBars.hxx> |
| 29 |
#include <ViewElementListProvider.hxx> |
| 30 |
#include <DataPointItemConverter.hxx> |
| 31 |
#include <TextLabelItemConverter.hxx> |
| 32 |
#include <AxisItemConverter.hxx> |
| 33 |
#include <MultipleChartConverters.hxx> |
| 34 |
#include <TitleItemConverter.hxx> |
| 35 |
#include <LegendItemConverter.hxx> |
| 36 |
#include <DataTableItemConverter.hxx> |
| 37 |
#include <RegressionCurveItemConverter.hxx> |
| 38 |
#include <RegressionEquationItemConverter.hxx> |
| 39 |
#include <ErrorBarItemConverter.hxx> |
| 40 |
#include <Axis.hxx> |
| 41 |
#include <AxisHelper.hxx> |
| 42 |
#include <TitleHelper.hxx> |
| 43 |
#include <ChartType.hxx> |
| 44 |
#include <ChartModel.hxx> |
| 45 |
#include <DataSeries.hxx> |
| 46 |
#include <DataSeriesProperties.hxx> |
| 47 |
#include <Diagram.hxx> |
| 48 |
#include <ControllerLockGuard.hxx> |
| 49 |
#include "UndoGuard.hxx" |
| 50 |
#include <ObjectNameProvider.hxx> |
| 51 |
#include <ResId.hxx> |
| 52 |
#include <strings.hrc> |
| 53 |
#include <ReferenceSizeProvider.hxx> |
| 54 |
#include <RegressionCurveHelper.hxx> |
| 55 |
#include <RegressionCurveModel.hxx> |
| 56 |
#include <o3tl/string_view.hxx> |
| 57 |
#include <com/sun/star/util/CloseVetoException.hpp> |
| 58 |
|
| 59 |
#include <memory> |
| 60 |
|
| 61 |
#include <vcl/svapp.hxx> |
| 62 |
#include <svx/ActionDescriptionProvider.hxx> |
| 63 |
#include <comphelper/diagnose_ex.hxx> |
| 64 |
|
| 65 |
namespace chart |
| 66 |
{ |
| 67 |
using namespace ::com::sun::star; |
| 68 |
using namespace ::com::sun::star::chart2; |
| 69 |
using namespace ::chart::DataSeriesProperties; |
| 70 |
using ::com::sun::star::uno::Reference; |
| 71 |
|
| 72 |
namespace |
| 73 |
{ |
| 74 |
|
| 75 |
wrapper::ItemConverter* createItemConverter( |
| 76 |
std::u16string_view aObjectCID, const rtl::Reference<::chart::ChartModel>& xChartModel, |
| 77 |
const uno::Reference<uno::XComponentContext>& xContext, SdrModel& rDrawModel, |
| 78 |
ChartView* pExplicitValueProvider, ReferenceSizeProvider const * pRefSizeProvider ) |
| 79 |
{ |
| 80 |
wrapper::ItemConverter* pItemConverter=nullptr; |
| 81 |
|
| 82 |
//get type of selected object |
| 83 |
ObjectType eObjectType = ObjectIdentifier::getObjectType( aObjectCID ); |
| 84 |
if( eObjectType==OBJECTTYPE_UNKNOWN ) |
| 85 |
{ |
| 86 |
OSL_FAIL("unknown ObjectType"); |
| 87 |
return nullptr; |
| 88 |
} |
| 89 |
|
| 90 |
std::u16string_view aParticleID = ObjectIdentifier::getParticleID( aObjectCID ); |
| 91 |
bool bAffectsMultipleObjects = aParticleID == u"ALLELEMENTS"; |
| 92 |
if( !bAffectsMultipleObjects ) |
| 93 |
{ |
| 94 |
uno::Reference< beans::XPropertySet > xObjectProperties = |
| 95 |
ObjectIdentifier::getObjectPropertySet( aObjectCID, xChartModel ); |
| 96 |
if(!xObjectProperties.is()) |
| 97 |
return nullptr; |
| 98 |
//create itemconverter for a single object |
| 99 |
switch(eObjectType) |
| 100 |
{ |
| 101 |
case OBJECTTYPE_DATA_STOCK_LOSS: |
| 102 |
case OBJECTTYPE_DATA_STOCK_GAIN: |
| 103 |
case OBJECTTYPE_DIAGRAM_WALL: |
| 104 |
case OBJECTTYPE_DIAGRAM_FLOOR: |
| 105 |
case OBJECTTYPE_PAGE: |
| 106 |
pItemConverter = new wrapper::GraphicPropertyItemConverter( |
| 107 |
xObjectProperties, rDrawModel.GetItemPool(), |
| 108 |
rDrawModel, xChartModel, |
| 109 |
wrapper::GraphicObjectType::LineAndFillProperties ); |
| 110 |
break; |
| 111 |
case OBJECTTYPE_TITLE: |
| 112 |
{ |
| 113 |
std::optional<awt::Size> pRefSize; |
| 114 |
if (pRefSizeProvider) |
| 115 |
pRefSize.emplace(pRefSizeProvider->getPageSize()); |
| 116 |
|
| 117 |
pItemConverter = new wrapper::TitleItemConverter( |
| 118 |
xObjectProperties, rDrawModel.GetItemPool(), rDrawModel, |
| 119 |
xChartModel, |
| 120 |
pRefSize); |
| 121 |
} |
| 122 |
break; |
| 123 |
case OBJECTTYPE_LEGEND: |
| 124 |
{ |
| 125 |
std::optional<awt::Size> pRefSize; |
| 126 |
if (pRefSizeProvider) |
| 127 |
pRefSize.emplace( pRefSizeProvider->getPageSize() ); |
| 128 |
|
| 129 |
pItemConverter = new wrapper::LegendItemConverter( |
| 130 |
xObjectProperties, rDrawModel.GetItemPool(), rDrawModel, |
| 131 |
xChartModel, |
| 132 |
pRefSize); |
| 133 |
} |
| 134 |
break; |
| 135 |
case OBJECTTYPE_LEGEND_ENTRY: |
| 136 |
break; |
| 137 |
case OBJECTTYPE_DIAGRAM: |
| 138 |
break; |
| 139 |
case OBJECTTYPE_AXIS: |
| 140 |
{ |
| 141 |
std::optional<awt::Size> pRefSize; |
| 142 |
if (pRefSizeProvider) |
| 143 |
pRefSize.emplace( pRefSizeProvider->getPageSize() ); |
| 144 |
|
| 145 |
// the second property set contains the property CoordinateOrigin |
| 146 |
// nOriginIndex is the index of the corresponding index of the |
| 147 |
// origin (x=0, y=1, z=2) |
| 148 |
|
| 149 |
ExplicitScaleData aExplicitScale; |
| 150 |
ExplicitIncrementData aExplicitIncrement; |
| 151 |
if( pExplicitValueProvider ) |
| 152 |
pExplicitValueProvider->getExplicitValuesForAxis( |
| 153 |
dynamic_cast< Axis* >( xObjectProperties.get() ), |
| 154 |
aExplicitScale, aExplicitIncrement ); |
| 155 |
|
| 156 |
pItemConverter = new wrapper::AxisItemConverter( |
| 157 |
xObjectProperties, rDrawModel.GetItemPool(), |
| 158 |
rDrawModel, |
| 159 |
xChartModel, |
| 160 |
&aExplicitScale, &aExplicitIncrement, |
| 161 |
pRefSize ); |
| 162 |
} |
| 163 |
break; |
| 164 |
case OBJECTTYPE_AXIS_UNITLABEL: |
| 165 |
break; |
| 166 |
case OBJECTTYPE_DATA_LABELS: |
| 167 |
case OBJECTTYPE_DATA_LABEL: |
| 168 |
{ |
| 169 |
std::optional<awt::Size> pRefSize; |
| 170 |
if (pRefSizeProvider) |
| 171 |
pRefSize.emplace( pRefSizeProvider->getPageSize() ); |
| 172 |
|
| 173 |
rtl::Reference<DataSeries> xSeries = ObjectIdentifier::getDataSeriesForCID(aObjectCID, xChartModel); |
| 174 |
|
| 175 |
bool bDataSeries = eObjectType == OBJECTTYPE_DATA_LABELS; |
| 176 |
|
| 177 |
sal_Int32 nNumberFormat = xSeries->getExplicitNumberFormatKeyForDataLabel(); |
| 178 |
sal_Int32 nPercentNumberFormat = ChartView::getExplicitPercentageNumberFormatKeyForDataLabel( |
| 179 |
xObjectProperties, xChartModel); |
| 180 |
|
| 181 |
pItemConverter = new wrapper::TextLabelItemConverter( |
| 182 |
xChartModel, xObjectProperties, xSeries, |
| 183 |
rDrawModel.GetItemPool(), pRefSize, bDataSeries, |
| 184 |
nNumberFormat, nPercentNumberFormat); |
| 185 |
} |
| 186 |
break; |
| 187 |
case OBJECTTYPE_DATA_SERIES: |
| 188 |
case OBJECTTYPE_DATA_POINT: |
| 189 |
{ |
| 190 |
std::optional<awt::Size> pRefSize; |
| 191 |
if (pRefSizeProvider) |
| 192 |
pRefSize.emplace( pRefSizeProvider->getPageSize() ); |
| 193 |
|
| 194 |
wrapper::GraphicObjectType eMapTo = |
| 195 |
wrapper::GraphicObjectType::FilledDataPoint; |
| 196 |
|
| 197 |
rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel ); |
| 198 |
rtl::Reference< ChartType > xChartType = xChartModel->getChartTypeOfSeries( xSeries ); |
| 199 |
|
| 200 |
rtl::Reference< Diagram > xDiagram = xChartModel->getFirstChartDiagram(); |
| 201 |
sal_Int32 nDimensionCount = xDiagram->getDimension(); |
| 202 |
if (xChartType.is() && !xChartType->isSupportingAreaProperties(nDimensionCount)) |
| 203 |
eMapTo = wrapper::GraphicObjectType::LineDataPoint; |
| 204 |
|
| 205 |
bool bDataSeries = eObjectType == OBJECTTYPE_DATA_SERIES; |
| 206 |
|
| 207 |
//special color for pie chart: |
| 208 |
bool bUseSpecialFillColor = false; |
| 209 |
sal_Int32 nSpecialFillColor =0; |
| 210 |
sal_Int32 nPointIndex = -1; /*-1 for whole series*/ |
| 211 |
if(!bDataSeries) |
| 212 |
{ |
| 213 |
nPointIndex = o3tl::toInt32(aParticleID); |
| 214 |
bool bVaryColorsByPoint = false; |
| 215 |
if( xSeries.is() && |
| 216 |
// "VaryColorsByPoint" |
| 217 |
(xSeries->getFastPropertyValue(PROP_DATASERIES_VARY_COLORS_BY_POINT) >>= bVaryColorsByPoint) && |
| 218 |
bVaryColorsByPoint ) |
| 219 |
{ |
| 220 |
if( !xSeries->hasPointOwnColor( nPointIndex, xObjectProperties ) ) |
| 221 |
{ |
| 222 |
bUseSpecialFillColor = true; |
| 223 |
OSL_ASSERT( xDiagram.is()); |
| 224 |
uno::Reference< XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme() ); |
| 225 |
if( xColorScheme.is()) |
| 226 |
nSpecialFillColor = xColorScheme->getColorByIndex( nPointIndex ); |
| 227 |
} |
| 228 |
} |
| 229 |
} |
| 230 |
sal_Int32 nNumberFormat=xSeries->getExplicitNumberFormatKeyForDataLabel(); |
| 231 |
sal_Int32 nPercentNumberFormat=ChartView::getExplicitPercentageNumberFormatKeyForDataLabel( |
| 232 |
xObjectProperties, xChartModel); |
| 233 |
|
| 234 |
pItemConverter = new wrapper::DataPointItemConverter( xChartModel, xContext, |
| 235 |
xObjectProperties, xSeries, rDrawModel.GetItemPool(), rDrawModel, |
| 236 |
eMapTo, pRefSize, bDataSeries, bUseSpecialFillColor, nSpecialFillColor, true, |
| 237 |
nNumberFormat, nPercentNumberFormat, nPointIndex ); |
| 238 |
break; |
| 239 |
} |
| 240 |
case OBJECTTYPE_GRID: |
| 241 |
case OBJECTTYPE_SUBGRID: |
| 242 |
case OBJECTTYPE_DATA_AVERAGE_LINE: |
| 243 |
pItemConverter = new wrapper::GraphicPropertyItemConverter( |
| 244 |
xObjectProperties, rDrawModel.GetItemPool(), |
| 245 |
rDrawModel, xChartModel, |
| 246 |
wrapper::GraphicObjectType::LineProperties ); |
| 247 |
break; |
| 248 |
|
| 249 |
case OBJECTTYPE_DATA_ERRORS_X: |
| 250 |
case OBJECTTYPE_DATA_ERRORS_Y: |
| 251 |
case OBJECTTYPE_DATA_ERRORS_Z: |
| 252 |
pItemConverter = new wrapper::ErrorBarItemConverter( |
| 253 |
xChartModel, xObjectProperties, rDrawModel.GetItemPool(), |
| 254 |
rDrawModel ); |
| 255 |
break; |
| 256 |
|
| 257 |
case OBJECTTYPE_DATA_CURVE: |
| 258 |
pItemConverter = new wrapper::RegressionCurveItemConverter( |
| 259 |
xObjectProperties, |
| 260 |
ObjectIdentifier::getDataSeriesForCID( aObjectCID, xChartModel ), |
| 261 |
rDrawModel.GetItemPool(), rDrawModel, |
| 262 |
xChartModel); |
| 263 |
break; |
| 264 |
case OBJECTTYPE_DATA_CURVE_EQUATION: |
| 265 |
{ |
| 266 |
std::optional<awt::Size> pRefSize; |
| 267 |
if (pRefSizeProvider) |
| 268 |
pRefSize.emplace(pRefSizeProvider->getPageSize()); |
| 269 |
|
| 270 |
pItemConverter = new wrapper::RegressionEquationItemConverter( |
| 271 |
xObjectProperties, rDrawModel.GetItemPool(), rDrawModel, |
| 272 |
xChartModel, |
| 273 |
pRefSize); |
| 274 |
break; |
| 275 |
} |
| 276 |
case OBJECTTYPE_DATA_STOCK_RANGE: |
| 277 |
break; |
| 278 |
case OBJECTTYPE_DATA_TABLE: |
| 279 |
{ |
| 280 |
pItemConverter = new wrapper::DataTableItemConverter( |
| 281 |
xObjectProperties, rDrawModel.GetItemPool(), |
| 282 |
rDrawModel, xChartModel); |
| 283 |
} |
| 284 |
break; |
| 285 |
default: //OBJECTTYPE_UNKNOWN |
| 286 |
break; |
| 287 |
} |
| 288 |
} |
| 289 |
else |
| 290 |
{ |
| 291 |
//create itemconverter for all objects of given type |
| 292 |
switch(eObjectType) |
| 293 |
{ |
| 294 |
case OBJECTTYPE_TITLE: |
| 295 |
pItemConverter = new wrapper::AllTitleItemConverter( xChartModel, rDrawModel.GetItemPool(), |
| 296 |
rDrawModel ); |
| 297 |
break; |
| 298 |
case OBJECTTYPE_AXIS: |
| 299 |
{ |
| 300 |
std::optional<awt::Size> pRefSize; |
| 301 |
if (pRefSizeProvider) |
| 302 |
pRefSize.emplace( pRefSizeProvider->getPageSize() ); |
| 303 |
|
| 304 |
pItemConverter = new wrapper::AllAxisItemConverter( |
| 305 |
xChartModel, rDrawModel.GetItemPool(), |
| 306 |
rDrawModel, pRefSize ); |
| 307 |
} |
| 308 |
break; |
| 309 |
case OBJECTTYPE_GRID: |
| 310 |
case OBJECTTYPE_SUBGRID: |
| 311 |
pItemConverter = new wrapper::AllGridItemConverter( xChartModel, rDrawModel.GetItemPool(), |
| 312 |
rDrawModel ); |
| 313 |
break; |
| 314 |
default: //for this type it is not supported to change all elements at once |
| 315 |
break; |
| 316 |
} |
| 317 |
|
| 318 |
} |
| 319 |
return pItemConverter; |
| 320 |
} |
| 321 |
|
| 322 |
OUString lcl_getTitleCIDForCommand( std::string_view rDispatchCommand, const rtl::Reference<::chart::ChartModel> & xChartModel ) |
| 323 |
{ |
| 324 |
if( rDispatchCommand == "AllTitles") |
| 325 |
return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_TITLE, u"ALLELEMENTS" ); |
| 326 |
|
| 327 |
TitleHelper::eTitleType nTitleType( TitleHelper::MAIN_TITLE ); |
| 328 |
if( rDispatchCommand == "SubTitle" ) |
| 329 |
nTitleType = TitleHelper::SUB_TITLE; |
| 330 |
else if( rDispatchCommand == "XTitle" ) |
| 331 |
nTitleType = TitleHelper::X_AXIS_TITLE; |
| 332 |
else if( rDispatchCommand == "YTitle" ) |
| 333 |
nTitleType = TitleHelper::Y_AXIS_TITLE; |
| 334 |
else if( rDispatchCommand == "ZTitle" ) |
| 335 |
nTitleType = TitleHelper::Z_AXIS_TITLE; |
| 336 |
else if( rDispatchCommand == "SecondaryXTitle" ) |
| 337 |
nTitleType = TitleHelper::SECONDARY_X_AXIS_TITLE; |
| 338 |
else if( rDispatchCommand == "SecondaryYTitle" ) |
| 339 |
nTitleType = TitleHelper::SECONDARY_Y_AXIS_TITLE; |
| 340 |
|
| 341 |
rtl::Reference< Title > xTitle( TitleHelper::getTitle( nTitleType, xChartModel ) ); |
| 342 |
return ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, xChartModel ); |
| 343 |
} |
| 344 |
|
| 345 |
OUString lcl_getAxisCIDForCommand( std::string_view rDispatchCommand, const rtl::Reference<::chart::ChartModel>& xChartModel ) |
| 346 |
{ |
| 347 |
if( rDispatchCommand == "DiagramAxisAll") |
| 348 |
return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_AXIS, u"ALLELEMENTS" ); |
| 349 |
|
| 350 |
sal_Int32 nDimensionIndex=0; |
| 351 |
bool bMainAxis=true; |
| 352 |
if( rDispatchCommand == "DiagramAxisX") |
| 353 |
{ |
| 354 |
nDimensionIndex=0; bMainAxis=true; |
| 355 |
} |
| 356 |
else if( rDispatchCommand == "DiagramAxisY") |
| 357 |
{ |
| 358 |
nDimensionIndex=1; bMainAxis=true; |
| 359 |
} |
| 360 |
else if( rDispatchCommand == "DiagramAxisZ") |
| 361 |
{ |
| 362 |
nDimensionIndex=2; bMainAxis=true; |
| 363 |
} |
| 364 |
else if( rDispatchCommand == "DiagramAxisA") |
| 365 |
{ |
| 366 |
nDimensionIndex=0; bMainAxis=false; |
| 367 |
} |
| 368 |
else if( rDispatchCommand == "DiagramAxisB") |
| 369 |
{ |
| 370 |
nDimensionIndex=1; bMainAxis=false; |
| 371 |
} |
| 372 |
|
| 373 |
rtl::Reference< Diagram > xDiagram = xChartModel->getFirstChartDiagram(); |
| 374 |
rtl::Reference< Axis > xAxis = AxisHelper::getAxis( nDimensionIndex, bMainAxis, xDiagram ); |
| 375 |
return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, xChartModel ); |
| 376 |
} |
| 377 |
|
| 378 |
OUString lcl_getGridCIDForCommand( std::string_view rDispatchCommand, const rtl::Reference<::chart::ChartModel>& xChartModel ) |
| 379 |
{ |
| 380 |
rtl::Reference< Diagram > xDiagram = xChartModel->getFirstChartDiagram(); |
| 381 |
|
| 382 |
if( rDispatchCommand == "DiagramGridAll") |
| 383 |
return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_GRID, u"ALLELEMENTS" ); |
| 384 |
|
| 385 |
sal_Int32 nDimensionIndex=0; |
| 386 |
bool bMainGrid=true; |
| 387 |
|
| 388 |
//x and y is swapped in the commands |
| 389 |
|
| 390 |
if( rDispatchCommand == "DiagramGridYMain") |
| 391 |
{ |
| 392 |
nDimensionIndex=0; bMainGrid=true; |
| 393 |
} |
| 394 |
else if( rDispatchCommand == "DiagramGridXMain") |
| 395 |
{ |
| 396 |
nDimensionIndex=1; bMainGrid=true; |
| 397 |
} |
| 398 |
else if( rDispatchCommand == "DiagramGridZMain") |
| 399 |
{ |
| 400 |
nDimensionIndex=2; bMainGrid=true; |
| 401 |
} |
| 402 |
else if( rDispatchCommand == "DiagramGridYHelp") |
| 403 |
{ |
| 404 |
nDimensionIndex=0; bMainGrid=false; |
| 405 |
} |
| 406 |
else if( rDispatchCommand == "DiagramGridXHelp") |
| 407 |
{ |
| 408 |
nDimensionIndex=1; bMainGrid=false; |
| 409 |
} |
| 410 |
else if( rDispatchCommand == "DiagramGridZHelp") |
| 411 |
{ |
| 412 |
nDimensionIndex=2; bMainGrid=false; |
| 413 |
} |
| 414 |
|
| 415 |
rtl::Reference< Axis > xAxis = AxisHelper::getAxis( nDimensionIndex, true/*bMainAxis*/, xDiagram ); |
| 416 |
|
| 417 |
sal_Int32 nSubGridIndex= bMainGrid ? -1 : 0; |
| 418 |
OUString aCID( ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, nSubGridIndex ) ); |
| 419 |
return aCID; |
| 420 |
} |
| 421 |
|
| 422 |
OUString lcl_getErrorCIDForCommand( const ObjectType eDispatchType, const ObjectType &eSelectedType, const OUString &rSelectedCID) |
| 423 |
{ |
| 424 |
if( eSelectedType == eDispatchType ) |
| 425 |
return rSelectedCID; |
| 426 |
|
| 427 |
return ObjectIdentifier::createClassifiedIdentifierWithParent( eDispatchType, u"", rSelectedCID ); |
| 428 |
} |
| 429 |
|
| 430 |
OUString lcl_getObjectCIDForCommand( std::string_view rDispatchCommand, const rtl::Reference<::chart::ChartModel> & xChartDocument, const OUString& rSelectedCID ) |
| 431 |
{ |
| 432 |
ObjectType eObjectType = OBJECTTYPE_UNKNOWN; |
| 433 |
|
| 434 |
const ObjectType eSelectedType = ObjectIdentifier::getObjectType( rSelectedCID ); |
| 435 |
rtl::Reference< DataSeries > xSeries = ObjectIdentifier::getDataSeriesForCID( rSelectedCID, xChartDocument ); |
| 436 |
|
| 437 |
//legend |
| 438 |
if( rDispatchCommand == "Legend" || rDispatchCommand == "FormatLegend" ) |
| 439 |
{ |
| 440 |
eObjectType = OBJECTTYPE_LEGEND; |
| 441 |
//@todo set particular aParticleID if we have more than one legend |
| 442 |
} |
| 443 |
//wall floor area |
| 444 |
else if( rDispatchCommand == "DiagramWall" || rDispatchCommand == "FormatWall" ) |
| 445 |
{ |
| 446 |
//OBJECTTYPE_DIAGRAM; |
| 447 |
eObjectType = OBJECTTYPE_DIAGRAM_WALL; |
| 448 |
//@todo set particular aParticleID if we have more than one diagram |
| 449 |
} |
| 450 |
else if( rDispatchCommand == "DiagramFloor" || rDispatchCommand == "FormatFloor" ) |
| 451 |
{ |
| 452 |
eObjectType = OBJECTTYPE_DIAGRAM_FLOOR; |
| 453 |
//@todo set particular aParticleID if we have more than one diagram |
| 454 |
} |
| 455 |
else if( rDispatchCommand == "DiagramArea" || rDispatchCommand == "FormatChartArea" ) |
| 456 |
{ |
| 457 |
eObjectType = OBJECTTYPE_PAGE; |
| 458 |
} |
| 459 |
//title |
| 460 |
else if( rDispatchCommand == "MainTitle" |
| 461 |
|| rDispatchCommand == "SubTitle" |
| 462 |
|| rDispatchCommand == "XTitle" |
| 463 |
|| rDispatchCommand == "YTitle" |
| 464 |
|| rDispatchCommand == "ZTitle" |
| 465 |
|| rDispatchCommand == "SecondaryXTitle" |
| 466 |
|| rDispatchCommand == "SecondaryYTitle" |
| 467 |
|| rDispatchCommand == "AllTitles" |
| 468 |
) |
| 469 |
{ |
| 470 |
return lcl_getTitleCIDForCommand( rDispatchCommand, xChartDocument ); |
| 471 |
} |
| 472 |
//axis |
| 473 |
else if( rDispatchCommand == "DiagramAxisX" |
| 474 |
|| rDispatchCommand == "DiagramAxisY" |
| 475 |
|| rDispatchCommand == "DiagramAxisZ" |
| 476 |
|| rDispatchCommand == "DiagramAxisA" |
| 477 |
|| rDispatchCommand == "DiagramAxisB" |
| 478 |
|| rDispatchCommand == "DiagramAxisAll" |
| 479 |
) |
| 480 |
{ |
| 481 |
return lcl_getAxisCIDForCommand( rDispatchCommand, xChartDocument ); |
| 482 |
} |
| 483 |
//grid |
| 484 |
else if( rDispatchCommand == "DiagramGridYMain" |
| 485 |
|| rDispatchCommand == "DiagramGridXMain" |
| 486 |
|| rDispatchCommand == "DiagramGridZMain" |
| 487 |
|| rDispatchCommand == "DiagramGridYHelp" |
| 488 |
|| rDispatchCommand == "DiagramGridXHelp" |
| 489 |
|| rDispatchCommand == "DiagramGridZHelp" |
| 490 |
|| rDispatchCommand == "DiagramGridAll" |
| 491 |
) |
| 492 |
{ |
| 493 |
return lcl_getGridCIDForCommand( rDispatchCommand, xChartDocument ); |
| 494 |
} |
| 495 |
//data series |
| 496 |
else if( rDispatchCommand == "FormatDataSeries" ) |
| 497 |
{ |
| 498 |
if( eSelectedType == OBJECTTYPE_DATA_SERIES ) |
| 499 |
return rSelectedCID; |
| 500 |
else |
| 501 |
return ObjectIdentifier::createClassifiedIdentifier( |
| 502 |
OBJECTTYPE_DATA_SERIES, ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ) ); |
| 503 |
} |
| 504 |
//data point |
| 505 |
else if( rDispatchCommand == "FormatDataPoint" ) |
| 506 |
{ |
| 507 |
return rSelectedCID; |
| 508 |
} |
| 509 |
//data labels |
| 510 |
else if( rDispatchCommand == "FormatDataLabels" ) |
| 511 |
{ |
| 512 |
if( eSelectedType == OBJECTTYPE_DATA_LABELS ) |
| 513 |
return rSelectedCID; |
| 514 |
else |
| 515 |
return ObjectIdentifier::createClassifiedIdentifierWithParent( |
| 516 |
OBJECTTYPE_DATA_LABELS, u"", rSelectedCID ); |
| 517 |
} |
| 518 |
//data labels |
| 519 |
else if( rDispatchCommand == "FormatDataLabel" ) |
| 520 |
{ |
| 521 |
if( eSelectedType == OBJECTTYPE_DATA_LABEL ) |
| 522 |
return rSelectedCID; |
| 523 |
else |
| 524 |
{ |
| 525 |
sal_Int32 nPointIndex = o3tl::toInt32(ObjectIdentifier::getParticleID( rSelectedCID )); |
| 526 |
if( nPointIndex>=0 ) |
| 527 |
{ |
| 528 |
OUString aSeriesParticle = ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ); |
| 529 |
OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) + "=" ); |
| 530 |
OUString aLabelsCID = ObjectIdentifier::createClassifiedIdentifierForParticles( aSeriesParticle, aChildParticle ); |
| 531 |
OUString aLabelCID_Stub = ObjectIdentifier::createClassifiedIdentifierWithParent( |
| 532 |
OBJECTTYPE_DATA_LABEL, u"", aLabelsCID ); |
| 533 |
|
| 534 |
return ObjectIdentifier::createPointCID( aLabelCID_Stub, nPointIndex ); |
| 535 |
} |
| 536 |
} |
| 537 |
} |
| 538 |
//mean value line |
| 539 |
else if( rDispatchCommand == "FormatMeanValue" ) |
| 540 |
{ |
| 541 |
if( eSelectedType == OBJECTTYPE_DATA_AVERAGE_LINE ) |
| 542 |
return rSelectedCID; |
| 543 |
else |
| 544 |
return ObjectIdentifier::createDataCurveCID( |
| 545 |
ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ), |
| 546 |
RegressionCurveHelper::getRegressionCurveIndex( xSeries, |
| 547 |
RegressionCurveHelper::getMeanValueLine( xSeries ) ), true ); |
| 548 |
} |
| 549 |
//trend line |
| 550 |
else if( rDispatchCommand == "FormatTrendline" ) |
| 551 |
{ |
| 552 |
if( eSelectedType == OBJECTTYPE_DATA_CURVE ) |
| 553 |
return rSelectedCID; |
| 554 |
else |
| 555 |
return ObjectIdentifier::createDataCurveCID( |
| 556 |
ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ), |
| 557 |
RegressionCurveHelper::getRegressionCurveIndex( xSeries, |
| 558 |
RegressionCurveHelper::getFirstCurveNotMeanValueLine( xSeries ) ), false ); |
| 559 |
} |
| 560 |
//trend line equation |
| 561 |
else if( rDispatchCommand == "FormatTrendlineEquation" ) |
| 562 |
{ |
| 563 |
if( eSelectedType == OBJECTTYPE_DATA_CURVE_EQUATION ) |
| 564 |
return rSelectedCID; |
| 565 |
else |
| 566 |
return ObjectIdentifier::createDataCurveEquationCID( |
| 567 |
ObjectIdentifier::getSeriesParticleFromCID( rSelectedCID ), |
| 568 |
RegressionCurveHelper::getRegressionCurveIndex( xSeries, |
| 569 |
RegressionCurveHelper::getFirstCurveNotMeanValueLine( xSeries ) ) ); |
| 570 |
} |
| 571 |
// y error bars |
| 572 |
else if( rDispatchCommand == "FormatXErrorBars" ) |
| 573 |
{ |
| 574 |
return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_X, eSelectedType, rSelectedCID ); |
| 575 |
} |
| 576 |
// y error bars |
| 577 |
else if( rDispatchCommand == "FormatYErrorBars" ) |
| 578 |
{ |
| 579 |
return lcl_getErrorCIDForCommand(OBJECTTYPE_DATA_ERRORS_Y, eSelectedType, rSelectedCID ); |
| 580 |
} |
| 581 |
// axis |
| 582 |
else if( rDispatchCommand == "FormatAxis" ) |
| 583 |
{ |
| 584 |
if( eSelectedType == OBJECTTYPE_AXIS ) |
| 585 |
return rSelectedCID; |
| 586 |
else |
| 587 |
{ |
| 588 |
rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartDocument ); |
| 589 |
return ObjectIdentifier::createClassifiedIdentifierForObject( xAxis , xChartDocument ); |
| 590 |
} |
| 591 |
} |
| 592 |
// major grid |
| 593 |
else if( rDispatchCommand == "FormatMajorGrid" ) |
| 594 |
{ |
| 595 |
if( eSelectedType == OBJECTTYPE_GRID ) |
| 596 |
return rSelectedCID; |
| 597 |
else |
| 598 |
{ |
| 599 |
rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartDocument ); |
| 600 |
return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartDocument ); |
| 601 |
} |
| 602 |
|
| 603 |
} |
| 604 |
// minor grid |
| 605 |
else if( rDispatchCommand == "FormatMinorGrid" ) |
| 606 |
{ |
| 607 |
if( eSelectedType == OBJECTTYPE_SUBGRID ) |
| 608 |
return rSelectedCID; |
| 609 |
else |
| 610 |
{ |
| 611 |
rtl::Reference< Axis > xAxis = ObjectIdentifier::getAxisForCID( rSelectedCID, xChartDocument ); |
| 612 |
return ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartDocument, 0 /*sub grid index*/ ); |
| 613 |
} |
| 614 |
} |
| 615 |
// title |
| 616 |
else if( rDispatchCommand == "FormatTitle" ) |
| 617 |
{ |
| 618 |
if( eSelectedType == OBJECTTYPE_TITLE ) |
| 619 |
return rSelectedCID; |
| 620 |
} |
| 621 |
// stock loss |
| 622 |
else if( rDispatchCommand == "FormatStockLoss" ) |
| 623 |
{ |
| 624 |
if( eSelectedType == OBJECTTYPE_DATA_STOCK_LOSS ) |
| 625 |
return rSelectedCID; |
| 626 |
else |
| 627 |
return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_LOSS, u""); |
| 628 |
} |
| 629 |
// stock gain |
| 630 |
else if( rDispatchCommand == "FormatStockGain" ) |
| 631 |
{ |
| 632 |
if( eSelectedType == OBJECTTYPE_DATA_STOCK_GAIN ) |
| 633 |
return rSelectedCID; |
| 634 |
else |
| 635 |
return ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DATA_STOCK_GAIN, u"" ); |
| 636 |
} |
| 637 |
|
| 638 |
return ObjectIdentifier::createClassifiedIdentifier( |
| 639 |
eObjectType, |
| 640 |
u"" ); // aParticleID |
| 641 |
} |
| 642 |
|
| 643 |
} |
| 644 |
// anonymous namespace |
| 645 |
|
| 646 |
void ChartController::executeDispatch_FormatObject(std::u16string_view rDispatchCommand) |
| 647 |
{ |
| 648 |
rtl::Reference<::chart::ChartModel> xChartDocument( getChartModel() ); |
| 649 |
OString aCommand( OUStringToOString( rDispatchCommand, RTL_TEXTENCODING_ASCII_US ) ); |
| 650 |
OUString rObjectCID = lcl_getObjectCIDForCommand( aCommand, xChartDocument, m_aSelection.getSelectedCID() ); |
| 651 |
executeDlg_ObjectProperties( rObjectCID ); |
| 652 |
} |
| 653 |
|
| 654 |
void ChartController::executeDispatch_ObjectProperties() |
| 655 |
{ |
| 656 |
executeDlg_ObjectProperties( m_aSelection.getSelectedCID() ); |
| 657 |
} |
| 658 |
|
| 659 |
namespace |
| 660 |
{ |
| 661 |
|
| 662 |
OUString lcl_getFormatCIDforSelectedCID( const OUString& rSelectedCID ) |
| 663 |
{ |
| 664 |
OUString aFormatCID(rSelectedCID); |
| 665 |
|
| 666 |
//get type of selected object |
| 667 |
ObjectType eObjectType = ObjectIdentifier::getObjectType( aFormatCID ); |
| 668 |
|
| 669 |
// some legend entries are handled as if they were data series |
| 670 |
if( eObjectType==OBJECTTYPE_LEGEND_ENTRY ) |
| 671 |
{ |
| 672 |
std::u16string_view aParentParticle( ObjectIdentifier::getFullParentParticle( rSelectedCID ) ); |
| 673 |
aFormatCID = ObjectIdentifier::createClassifiedIdentifierForParticle( aParentParticle ); |
| 674 |
} |
| 675 |
|
| 676 |
// treat diagram as wall |
| 677 |
if( eObjectType==OBJECTTYPE_DIAGRAM ) |
| 678 |
aFormatCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, u"" ); |
| 679 |
|
| 680 |
return aFormatCID; |
| 681 |
} |
| 682 |
|
| 683 |
}//end anonymous namespace |
| 684 |
|
| 685 |
void ChartController::executeDlg_ObjectProperties( const OUString& rSelectedObjectCID ) |
| 686 |
{ |
| 687 |
OUString aObjectCID = lcl_getFormatCIDforSelectedCID( rSelectedObjectCID ); |
| 688 |
|
| 689 |
auto xUndoGuard = std::make_shared<UndoGuard>( |
| 690 |
ActionDescriptionProvider::createDescription( |
| 691 |
ActionDescriptionProvider::ActionType::Format, |
| 692 |
ObjectNameProvider::getName( ObjectIdentifier::getObjectType( aObjectCID ))), |
| 693 |
m_xUndoManager ); |
| 694 |
|
| 695 |
ChartController::executeDlg_ObjectProperties_withUndoGuard(std::move(xUndoGuard), aObjectCID, false ); |
| 696 |
} |
| 697 |
|
| 698 |
void ChartController::executeDlg_ObjectProperties_withUndoGuard( |
| 699 |
std::shared_ptr<UndoGuard> xUndoGuard, const OUString& rObjectCID, bool bSuccessOnUnchanged ) |
| 700 |
{ |
| 701 |
//return true if the properties were changed successfully |
| 702 |
if( rObjectCID.isEmpty() ) |
| 703 |
{ |
| 704 |
return; |
| 705 |
} |
| 706 |
try |
| 707 |
{ |
| 708 |
//get type of object |
| 709 |
ObjectType eObjectType = ObjectIdentifier::getObjectType( rObjectCID ); |
| 710 |
if( eObjectType==OBJECTTYPE_UNKNOWN ) |
| 711 |
{ |
| 712 |
return; |
| 713 |
} |
| 714 |
if( eObjectType==OBJECTTYPE_DIAGRAM_WALL || eObjectType==OBJECTTYPE_DIAGRAM_FLOOR ) |
| 715 |
{ |
| 716 |
if( !getFirstDiagram()->isSupportingFloorAndWall() ) |
| 717 |
return; |
| 718 |
} |
| 719 |
|
| 720 |
//convert properties to ItemSet |
| 721 |
|
| 722 |
ReferenceSizeProvider aRefSizeProv(impl_createReferenceSizeProvider()); |
| 723 |
|
| 724 |
rtl::Reference<::chart::ChartModel> xChartDoc(getChartModel()); |
| 725 |
|
| 726 |
std::shared_ptr<wrapper::ItemConverter> pItemConverter( |
| 727 |
createItemConverter( rObjectCID, xChartDoc, m_xCC, |
| 728 |
m_pDrawModelWrapper->getSdrModel(), |
| 729 |
m_xChartView.get(), |
| 730 |
&aRefSizeProv)); |
| 731 |
|
| 732 |
if (!pItemConverter) |
| 733 |
return; |
| 734 |
|
| 735 |
SfxItemSet aItemSet = pItemConverter->CreateEmptyItemSet(); |
| 736 |
|
| 737 |
if ( eObjectType == OBJECTTYPE_DATA_ERRORS_X || eObjectType == OBJECTTYPE_DATA_ERRORS_Y ) |
| 738 |
aItemSet.Put(SfxBoolItem(SCHATTR_STAT_ERRORBAR_TYPE, eObjectType == OBJECTTYPE_DATA_ERRORS_Y )); |
| 739 |
|
| 740 |
pItemConverter->FillItemSet(aItemSet); |
| 741 |
|
| 742 |
//prepare dialog |
| 743 |
ObjectPropertiesDialogParameter aDialogParameter( rObjectCID ); |
| 744 |
aDialogParameter.init(xChartDoc); |
| 745 |
ViewElementListProvider aViewElementListProvider( m_pDrawModelWrapper.get() ); |
| 746 |
|
| 747 |
SolarMutexGuard aGuard; |
| 748 |
std::shared_ptr<SchAttribTabDlg> aDlgPtr = std::make_shared<SchAttribTabDlg>( |
| 749 |
GetChartFrame(), &aItemSet, aDialogParameter, |
| 750 |
&aViewElementListProvider, |
| 751 |
xChartDoc); |
| 752 |
|
| 753 |
if(aDialogParameter.HasSymbolProperties()) |
| 754 |
{ |
| 755 |
uno::Reference< beans::XPropertySet > xObjectProperties = |
| 756 |
ObjectIdentifier::getObjectPropertySet( rObjectCID, xChartDoc ); |
| 757 |
wrapper::DataPointItemConverter aSymbolItemConverter( xChartDoc, m_xCC |
| 758 |
, xObjectProperties, ObjectIdentifier::getDataSeriesForCID( rObjectCID, xChartDoc ) |
| 759 |
, m_pDrawModelWrapper->getSdrModel().GetItemPool() |
| 760 |
, m_pDrawModelWrapper->getSdrModel() |
| 761 |
, wrapper::GraphicObjectType::FilledDataPoint ); |
| 762 |
|
| 763 |
SfxItemSet aSymbolShapeProperties(aSymbolItemConverter.CreateEmptyItemSet() ); |
| 764 |
aSymbolItemConverter.FillItemSet( aSymbolShapeProperties ); |
| 765 |
|
| 766 |
sal_Int32 const nStandardSymbol=0;//@todo get from somewhere |
| 767 |
std::optional<Graphic> oAutoSymbolGraphic(std::in_place, aViewElementListProvider.GetSymbolGraphic( nStandardSymbol, &aSymbolShapeProperties ) ); |
| 768 |
// note: the dialog takes the ownership of pSymbolShapeProperties and pAutoSymbolGraphic |
| 769 |
aDlgPtr->setSymbolInformation( std::move(aSymbolShapeProperties), std::move(oAutoSymbolGraphic) ); |
| 770 |
} |
| 771 |
if( aDialogParameter.HasStatisticProperties() ) |
| 772 |
{ |
| 773 |
aDlgPtr->SetAxisMinorStepWidthForErrorBarDecimals( |
| 774 |
InsertErrorBarsDialog::getAxisMinorStepWidthForErrorBarDecimals( xChartDoc, m_xChartView, rObjectCID ) ); |
| 775 |
} |
| 776 |
|
| 777 |
//open the dialog |
| 778 |
SfxTabDialogController::runAsync(aDlgPtr, [aDlgPtr, xChartDoc, pItemConverter=std::move(pItemConverter), |
| 779 |
bSuccessOnUnchanged, xUndoGuard=std::move(xUndoGuard)] (int nResult) |
| 780 |
{ |
| 781 |
if (nResult == RET_OK || (bSuccessOnUnchanged && aDlgPtr->DialogWasClosedWithOK())) { |
| 782 |
const SfxItemSet* pOutItemSet = aDlgPtr->GetOutputItemSet(); |
| 783 |
if(pOutItemSet) { |
| 784 |
ControllerLockGuardUNO aCLGuard(xChartDoc); |
| 785 |
(void)pItemConverter->ApplyItemSet(*pOutItemSet); //model should be changed now |
| 786 |
xUndoGuard->commit(); |
| 787 |
} |
| 788 |
} |
| 789 |
}); |
| 790 |
} |
| 791 |
catch( const util::CloseVetoException& ) |
| 792 |
{ |
| 793 |
} |
| 794 |
catch( const uno::RuntimeException& ) |
| 795 |
{ |
| 796 |
} |
| 797 |
} |
| 798 |
|
| 799 |
void ChartController::executeDispatch_View3D() |
| 800 |
{ |
| 801 |
try |
| 802 |
{ |
| 803 |
UndoLiveUpdateGuard aUndoGuard( |
| 804 |
SchResId( STR_ACTION_EDIT_3D_VIEW ), |
| 805 |
m_xUndoManager ); |
| 806 |
|
| 807 |
//open dialog |
| 808 |
SolarMutexGuard aSolarGuard; |
| 809 |
View3DDialog aDlg(GetChartFrame(), getChartModel()); |
| 810 |
if (aDlg.run() == RET_OK) |
| 811 |
aUndoGuard.commit(); |
| 812 |
} |
| 813 |
catch(const uno::RuntimeException&) |
| 814 |
{ |
| 815 |
TOOLS_WARN_EXCEPTION("chart2", "" ); |
| 816 |
} |
| 817 |
} |
| 818 |
|
| 819 |
} //namespace chart |
| 820 |
|
| 821 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |