| 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 "ChartDataWrapper.hxx" |
| 21 |
#include <DiagramHelper.hxx> |
| 22 |
#include <DataSourceHelper.hxx> |
| 23 |
#include <InternalDataProvider.hxx> |
| 24 |
#include <ControllerLockGuard.hxx> |
| 25 |
#include "Chart2ModelContact.hxx" |
| 26 |
#include <cppuhelper/supportsservice.hxx> |
| 27 |
#include <com/sun/star/chart/XChartDocument.hpp> |
| 28 |
|
| 29 |
#include <float.h> |
| 30 |
#include <cmath> |
| 31 |
#include <limits> |
| 32 |
#include <utility> |
| 33 |
#include <osl/diagnose.h> |
| 34 |
|
| 35 |
using namespace ::com::sun::star; |
| 36 |
using ::com::sun::star::uno::Reference; |
| 37 |
using ::com::sun::star::uno::Sequence; |
| 38 |
using ::com::sun::star::chart2::XAnyDescriptionAccess; |
| 39 |
using ::com::sun::star::chart::XComplexDescriptionAccess; |
| 40 |
using ::com::sun::star::chart::XChartData; |
| 41 |
using ::com::sun::star::chart::XChartDataArray; |
| 42 |
using ::com::sun::star::chart::XDateCategories; |
| 43 |
|
| 44 |
namespace |
| 45 |
{ |
| 46 |
|
| 47 |
uno::Sequence< uno::Sequence< double > > lcl_getNANInsteadDBL_MIN( const uno::Sequence< uno::Sequence< double > >& rData ) |
| 48 |
{ |
| 49 |
uno::Sequence< uno::Sequence< double > > aRet; |
| 50 |
const sal_Int32 nOuterSize = rData.getLength(); |
| 51 |
aRet.realloc( nOuterSize ); |
| 52 |
auto pRet = aRet.getArray(); |
| 53 |
for( sal_Int32 nOuter=0; nOuter<nOuterSize; ++nOuter ) |
| 54 |
{ |
| 55 |
sal_Int32 nInnerSize = rData[nOuter].getLength(); |
| 56 |
pRet[nOuter].realloc( nInnerSize ); |
| 57 |
auto pRet_nOuter = pRet[nOuter].getArray(); |
| 58 |
for( sal_Int32 nInner=0; nInner<nInnerSize; ++nInner ) |
| 59 |
{ |
| 60 |
pRet_nOuter[nInner] = rData[nOuter][nInner]; |
| 61 |
double& rValue = pRet_nOuter[nInner]; |
| 62 |
if( rValue == DBL_MIN ) |
| 63 |
rValue = std::numeric_limits<double>::quiet_NaN(); |
| 64 |
} |
| 65 |
} |
| 66 |
return aRet; |
| 67 |
} |
| 68 |
|
| 69 |
uno::Sequence< uno::Sequence< double > > lcl_getDBL_MINInsteadNAN( const uno::Sequence< uno::Sequence< double > >& rData ) |
| 70 |
{ |
| 71 |
uno::Sequence< uno::Sequence< double > > aRet; |
| 72 |
const sal_Int32 nOuterSize = rData.getLength(); |
| 73 |
aRet.realloc( nOuterSize ); |
| 74 |
auto pRet = aRet.getArray(); |
| 75 |
for( sal_Int32 nOuter=0; nOuter<nOuterSize; ++nOuter ) |
| 76 |
{ |
| 77 |
sal_Int32 nInnerSize = rData[nOuter].getLength(); |
| 78 |
pRet[nOuter].realloc( nInnerSize ); |
| 79 |
auto pRet_nOuter = pRet[nOuter].getArray(); |
| 80 |
for( sal_Int32 nInner=0; nInner<nInnerSize; ++nInner ) |
| 81 |
{ |
| 82 |
pRet_nOuter[nInner] = rData[nOuter][nInner]; |
| 83 |
double& rValue = pRet_nOuter[nInner]; |
| 84 |
if( std::isnan( rValue ) ) |
| 85 |
rValue = DBL_MIN; |
| 86 |
} |
| 87 |
} |
| 88 |
return aRet; |
| 89 |
} |
| 90 |
|
| 91 |
} // anonymous namespace |
| 92 |
|
| 93 |
namespace chart::wrapper |
| 94 |
{ |
| 95 |
|
| 96 |
struct lcl_Operator |
| 97 |
{ |
| 98 |
lcl_Operator() |
| 99 |
{ |
| 100 |
} |
| 101 |
virtual ~lcl_Operator() |
| 102 |
{ |
| 103 |
} |
| 104 |
virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) = 0; |
| 105 |
|
| 106 |
virtual bool setsCategories( bool /*bDataInColumns*/ ) |
| 107 |
{ |
| 108 |
return false; |
| 109 |
} |
| 110 |
}; |
| 111 |
|
| 112 |
namespace { |
| 113 |
|
| 114 |
struct lcl_AllOperator : public lcl_Operator |
| 115 |
{ |
| 116 |
explicit lcl_AllOperator( const Reference< XChartData >& xDataToApply ) |
| 117 |
: m_xDataToApply( xDataToApply ) |
| 118 |
{ |
| 119 |
} |
| 120 |
|
| 121 |
virtual bool setsCategories( bool /*bDataInColumns*/ ) override |
| 122 |
{ |
| 123 |
// Do not force creation of categories, when original has no categories |
| 124 |
if (auto pDataWrapper = dynamic_cast<const ChartDataWrapper*>(m_xDataToApply.get())) |
| 125 |
if (auto xChartModel = pDataWrapper->getChartModel()) |
| 126 |
if (auto xDiagram = xChartModel->getFirstChartDiagram()) |
| 127 |
return xDiagram->getCategories().is(); |
| 128 |
return true; |
| 129 |
} |
| 130 |
|
| 131 |
virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
| 132 |
{ |
| 133 |
if( !xDataAccess.is() ) |
| 134 |
return; |
| 135 |
|
| 136 |
Reference< XAnyDescriptionAccess > xNewAny( m_xDataToApply, uno::UNO_QUERY ); |
| 137 |
Reference< XComplexDescriptionAccess > xNewComplex( m_xDataToApply, uno::UNO_QUERY ); |
| 138 |
if( xNewAny.is() ) |
| 139 |
{ |
| 140 |
xDataAccess->setData( xNewAny->getData() ); |
| 141 |
xDataAccess->setComplexRowDescriptions( xNewAny->getComplexRowDescriptions() ); |
| 142 |
xDataAccess->setComplexColumnDescriptions( xNewAny->getComplexColumnDescriptions() ); |
| 143 |
} |
| 144 |
else if( xNewComplex.is() ) |
| 145 |
{ |
| 146 |
xDataAccess->setData( xNewComplex->getData() ); |
| 147 |
xDataAccess->setComplexRowDescriptions( xNewComplex->getComplexRowDescriptions() ); |
| 148 |
xDataAccess->setComplexColumnDescriptions( xNewComplex->getComplexColumnDescriptions() ); |
| 149 |
} |
| 150 |
else |
| 151 |
{ |
| 152 |
Reference< XChartDataArray > xNew( m_xDataToApply, uno::UNO_QUERY ); |
| 153 |
if( xNew.is() ) |
| 154 |
{ |
| 155 |
xDataAccess->setData( xNew->getData() ); |
| 156 |
xDataAccess->setRowDescriptions( xNew->getRowDescriptions() ); |
| 157 |
xDataAccess->setColumnDescriptions( xNew->getColumnDescriptions() ); |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
Reference< XChartData > m_xDataToApply; |
| 163 |
}; |
| 164 |
|
| 165 |
struct lcl_DataOperator : public lcl_Operator |
| 166 |
{ |
| 167 |
explicit lcl_DataOperator( const Sequence< Sequence< double > >& rData ) |
| 168 |
: m_rData( rData ) |
| 169 |
{ |
| 170 |
} |
| 171 |
|
| 172 |
virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
| 173 |
{ |
| 174 |
if( xDataAccess.is() ) |
| 175 |
xDataAccess->setData( lcl_getNANInsteadDBL_MIN( m_rData ) ); |
| 176 |
} |
| 177 |
|
| 178 |
const Sequence< Sequence< double > >& m_rData; |
| 179 |
}; |
| 180 |
|
| 181 |
struct lcl_RowDescriptionsOperator : public lcl_Operator |
| 182 |
{ |
| 183 |
lcl_RowDescriptionsOperator( const Sequence< OUString >& rRowDescriptions |
| 184 |
, rtl::Reference<::chart::ChartModel> xChartDoc ) |
| 185 |
: m_rRowDescriptions( rRowDescriptions ) |
| 186 |
, m_xChartDoc(std::move(xChartDoc)) |
| 187 |
, m_bDataInColumns(true) |
| 188 |
{ |
| 189 |
} |
| 190 |
|
| 191 |
virtual bool setsCategories( bool bDataInColumns ) override |
| 192 |
{ |
| 193 |
m_bDataInColumns = bDataInColumns; |
| 194 |
return bDataInColumns; |
| 195 |
} |
| 196 |
|
| 197 |
virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
| 198 |
{ |
| 199 |
if( xDataAccess.is() ) |
| 200 |
{ |
| 201 |
xDataAccess->setRowDescriptions( m_rRowDescriptions ); |
| 202 |
if( m_bDataInColumns ) |
| 203 |
DiagramHelper::switchToTextCategories( m_xChartDoc ); |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
const Sequence< OUString >& m_rRowDescriptions; |
| 208 |
rtl::Reference<::chart::ChartModel> m_xChartDoc; |
| 209 |
bool m_bDataInColumns; |
| 210 |
}; |
| 211 |
|
| 212 |
struct lcl_ComplexRowDescriptionsOperator : public lcl_Operator |
| 213 |
{ |
| 214 |
lcl_ComplexRowDescriptionsOperator( const Sequence< Sequence< OUString > >& rComplexRowDescriptions |
| 215 |
, rtl::Reference<::chart::ChartModel> xChartDoc ) |
| 216 |
: m_rComplexRowDescriptions( rComplexRowDescriptions ) |
| 217 |
, m_xChartDoc(std::move(xChartDoc)) |
| 218 |
, m_bDataInColumns(true) |
| 219 |
{ |
| 220 |
} |
| 221 |
|
| 222 |
virtual bool setsCategories( bool bDataInColumns ) override |
| 223 |
{ |
| 224 |
m_bDataInColumns = bDataInColumns; |
| 225 |
return bDataInColumns; |
| 226 |
} |
| 227 |
|
| 228 |
virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
| 229 |
{ |
| 230 |
if( xDataAccess.is() ) |
| 231 |
{ |
| 232 |
xDataAccess->setComplexRowDescriptions( m_rComplexRowDescriptions ); |
| 233 |
if( m_bDataInColumns ) |
| 234 |
DiagramHelper::switchToTextCategories( m_xChartDoc ); |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
const Sequence< Sequence< OUString > >& m_rComplexRowDescriptions; |
| 239 |
rtl::Reference<::chart::ChartModel> m_xChartDoc; |
| 240 |
bool m_bDataInColumns; |
| 241 |
}; |
| 242 |
|
| 243 |
struct lcl_AnyRowDescriptionsOperator : public lcl_Operator |
| 244 |
{ |
| 245 |
explicit lcl_AnyRowDescriptionsOperator( const Sequence< Sequence< uno::Any > >& rAnyRowDescriptions ) |
| 246 |
: m_rAnyRowDescriptions( rAnyRowDescriptions ) |
| 247 |
{ |
| 248 |
} |
| 249 |
|
| 250 |
virtual bool setsCategories( bool bDataInColumns ) override |
| 251 |
{ |
| 252 |
return bDataInColumns; |
| 253 |
} |
| 254 |
|
| 255 |
virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
| 256 |
{ |
| 257 |
if( xDataAccess.is() ) |
| 258 |
xDataAccess->setAnyRowDescriptions( m_rAnyRowDescriptions ); |
| 259 |
} |
| 260 |
|
| 261 |
const Sequence< Sequence< uno::Any > >& m_rAnyRowDescriptions; |
| 262 |
}; |
| 263 |
|
| 264 |
struct lcl_ColumnDescriptionsOperator : public lcl_Operator |
| 265 |
{ |
| 266 |
lcl_ColumnDescriptionsOperator( const Sequence< OUString >& rColumnDescriptions |
| 267 |
, rtl::Reference<::chart::ChartModel> xChartDoc ) |
| 268 |
: m_rColumnDescriptions( rColumnDescriptions ) |
| 269 |
, m_xChartDoc(std::move(xChartDoc)) |
| 270 |
, m_bDataInColumns(true) |
| 271 |
{ |
| 272 |
} |
| 273 |
|
| 274 |
virtual bool setsCategories( bool bDataInColumns ) override |
| 275 |
{ |
| 276 |
m_bDataInColumns = bDataInColumns; |
| 277 |
return !bDataInColumns; |
| 278 |
} |
| 279 |
|
| 280 |
virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
| 281 |
{ |
| 282 |
if( xDataAccess.is() ) |
| 283 |
{ |
| 284 |
xDataAccess->setColumnDescriptions( m_rColumnDescriptions ); |
| 285 |
if( !m_bDataInColumns ) |
| 286 |
DiagramHelper::switchToTextCategories( m_xChartDoc ); |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
const Sequence< OUString >& m_rColumnDescriptions; |
| 291 |
rtl::Reference<::chart::ChartModel> m_xChartDoc; |
| 292 |
bool m_bDataInColumns; |
| 293 |
}; |
| 294 |
|
| 295 |
struct lcl_ComplexColumnDescriptionsOperator : public lcl_Operator |
| 296 |
{ |
| 297 |
lcl_ComplexColumnDescriptionsOperator( const Sequence< Sequence< OUString > >& rComplexColumnDescriptions |
| 298 |
, rtl::Reference<::chart::ChartModel> xChartDoc ) |
| 299 |
: m_rComplexColumnDescriptions( rComplexColumnDescriptions ) |
| 300 |
, m_xChartDoc(std::move(xChartDoc)) |
| 301 |
, m_bDataInColumns(true) |
| 302 |
{ |
| 303 |
} |
| 304 |
|
| 305 |
virtual bool setsCategories( bool bDataInColumns ) override |
| 306 |
{ |
| 307 |
m_bDataInColumns = bDataInColumns; |
| 308 |
return !bDataInColumns; |
| 309 |
} |
| 310 |
|
| 311 |
virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
| 312 |
{ |
| 313 |
if( xDataAccess.is() ) |
| 314 |
{ |
| 315 |
xDataAccess->setComplexColumnDescriptions( m_rComplexColumnDescriptions ); |
| 316 |
if( !m_bDataInColumns ) |
| 317 |
DiagramHelper::switchToTextCategories( m_xChartDoc ); |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
const Sequence< Sequence< OUString > >& m_rComplexColumnDescriptions; |
| 322 |
rtl::Reference<::chart::ChartModel> m_xChartDoc; |
| 323 |
bool m_bDataInColumns; |
| 324 |
}; |
| 325 |
|
| 326 |
struct lcl_AnyColumnDescriptionsOperator : public lcl_Operator |
| 327 |
{ |
| 328 |
explicit lcl_AnyColumnDescriptionsOperator( const Sequence< Sequence< uno::Any > >& rAnyColumnDescriptions ) |
| 329 |
: m_rAnyColumnDescriptions( rAnyColumnDescriptions ) |
| 330 |
{ |
| 331 |
} |
| 332 |
|
| 333 |
virtual bool setsCategories( bool bDataInColumns ) override |
| 334 |
{ |
| 335 |
return bDataInColumns; |
| 336 |
} |
| 337 |
|
| 338 |
virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
| 339 |
{ |
| 340 |
if( xDataAccess.is() ) |
| 341 |
xDataAccess->setAnyColumnDescriptions( m_rAnyColumnDescriptions ); |
| 342 |
} |
| 343 |
|
| 344 |
const Sequence< Sequence< uno::Any > >& m_rAnyColumnDescriptions; |
| 345 |
}; |
| 346 |
|
| 347 |
struct lcl_DateCategoriesOperator : public lcl_Operator |
| 348 |
{ |
| 349 |
explicit lcl_DateCategoriesOperator( const Sequence< double >& rDates ) |
| 350 |
: m_rDates( rDates ) |
| 351 |
{ |
| 352 |
} |
| 353 |
|
| 354 |
virtual bool setsCategories( bool /*bDataInColumns*/ ) override |
| 355 |
{ |
| 356 |
return true; |
| 357 |
} |
| 358 |
|
| 359 |
virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) override |
| 360 |
{ |
| 361 |
Reference< XDateCategories > xDateCategories( xDataAccess, uno::UNO_QUERY ); |
| 362 |
if( xDateCategories.is() ) |
| 363 |
xDateCategories->setDateCategories( m_rDates ); |
| 364 |
} |
| 365 |
|
| 366 |
const Sequence< double >& m_rDates; |
| 367 |
}; |
| 368 |
|
| 369 |
} |
| 370 |
|
| 371 |
ChartDataWrapper::ChartDataWrapper(std::shared_ptr<Chart2ModelContact> spChart2ModelContact) |
| 372 |
: m_spChart2ModelContact(std::move(spChart2ModelContact)) |
| 373 |
{ |
| 374 |
osl_atomic_increment( &m_refCount ); |
| 375 |
initDataAccess(); |
| 376 |
osl_atomic_decrement( &m_refCount ); |
| 377 |
} |
| 378 |
|
| 379 |
ChartDataWrapper::ChartDataWrapper( std::shared_ptr<Chart2ModelContact> spChart2ModelContact, |
| 380 |
const Reference< XChartData >& xNewData ) : |
| 381 |
m_spChart2ModelContact(std::move( spChart2ModelContact )) |
| 382 |
{ |
| 383 |
osl_atomic_increment( &m_refCount ); |
| 384 |
lcl_AllOperator aOperator( xNewData ); |
| 385 |
applyData( aOperator ); |
| 386 |
osl_atomic_decrement( &m_refCount ); |
| 387 |
} |
| 388 |
|
| 389 |
ChartDataWrapper::~ChartDataWrapper() |
| 390 |
{ |
| 391 |
// @todo: implement XComponent and call this in dispose(). In the DTOR the |
| 392 |
// ref-count is 0, thus creating a stack reference to this calls the DTOR at |
| 393 |
// the end of the block recursively |
| 394 |
// uno::Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); |
| 395 |
// m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) ); |
| 396 |
} |
| 397 |
|
| 398 |
// ____ XChartDataArray (read)____ |
| 399 |
Sequence< Sequence< double > > SAL_CALL ChartDataWrapper::getData() |
| 400 |
{ |
| 401 |
initDataAccess(); |
| 402 |
if( m_xDataAccess.is() ) |
| 403 |
return lcl_getDBL_MINInsteadNAN( m_xDataAccess->getData() ); |
| 404 |
return Sequence< Sequence< double > >(); |
| 405 |
} |
| 406 |
Sequence< OUString > SAL_CALL ChartDataWrapper::getRowDescriptions() |
| 407 |
{ |
| 408 |
initDataAccess(); |
| 409 |
if( m_xDataAccess.is() ) |
| 410 |
return m_xDataAccess->getRowDescriptions(); |
| 411 |
return Sequence< OUString >(); |
| 412 |
} |
| 413 |
Sequence< OUString > SAL_CALL ChartDataWrapper::getColumnDescriptions() |
| 414 |
{ |
| 415 |
initDataAccess(); |
| 416 |
if( m_xDataAccess.is() ) |
| 417 |
return m_xDataAccess->getColumnDescriptions(); |
| 418 |
return Sequence< OUString > (); |
| 419 |
} |
| 420 |
|
| 421 |
// ____ XComplexDescriptionAccess (read) ____ |
| 422 |
Sequence< Sequence< OUString > > SAL_CALL ChartDataWrapper::getComplexRowDescriptions() |
| 423 |
{ |
| 424 |
initDataAccess(); |
| 425 |
if( m_xDataAccess.is() ) |
| 426 |
return m_xDataAccess->getComplexRowDescriptions(); |
| 427 |
return Sequence< Sequence< OUString > >(); |
| 428 |
} |
| 429 |
Sequence< Sequence< OUString > > SAL_CALL ChartDataWrapper::getComplexColumnDescriptions() |
| 430 |
{ |
| 431 |
initDataAccess(); |
| 432 |
if( m_xDataAccess.is() ) |
| 433 |
return m_xDataAccess->getComplexColumnDescriptions(); |
| 434 |
return Sequence< Sequence< OUString > >(); |
| 435 |
} |
| 436 |
|
| 437 |
// ____ XAnyDescriptionAccess (read) ____ |
| 438 |
Sequence< Sequence< uno::Any > > SAL_CALL ChartDataWrapper::getAnyRowDescriptions() |
| 439 |
{ |
| 440 |
initDataAccess(); |
| 441 |
if( m_xDataAccess.is() ) |
| 442 |
return m_xDataAccess->getAnyRowDescriptions(); |
| 443 |
return Sequence< Sequence< uno::Any > >(); |
| 444 |
} |
| 445 |
Sequence< Sequence< uno::Any > > SAL_CALL ChartDataWrapper::getAnyColumnDescriptions() |
| 446 |
{ |
| 447 |
initDataAccess(); |
| 448 |
if( m_xDataAccess.is() ) |
| 449 |
return m_xDataAccess->getAnyColumnDescriptions(); |
| 450 |
return Sequence< Sequence< uno::Any > >(); |
| 451 |
} |
| 452 |
|
| 453 |
// ____ XDateCategories (read) ____ |
| 454 |
Sequence< double > SAL_CALL ChartDataWrapper::getDateCategories() |
| 455 |
{ |
| 456 |
initDataAccess(); |
| 457 |
Reference< XDateCategories > xDateCategories( m_xDataAccess, uno::UNO_QUERY ); |
| 458 |
if( xDateCategories.is() ) |
| 459 |
return xDateCategories->getDateCategories(); |
| 460 |
return Sequence< double >(); |
| 461 |
} |
| 462 |
|
| 463 |
// ____ XChartDataArray (write)____ |
| 464 |
void SAL_CALL ChartDataWrapper::setData( const Sequence< Sequence< double > >& rData ) |
| 465 |
{ |
| 466 |
lcl_DataOperator aOperator( rData ); |
| 467 |
applyData( aOperator ); |
| 468 |
} |
| 469 |
void SAL_CALL ChartDataWrapper::setRowDescriptions( const Sequence< OUString >& rRowDescriptions ) |
| 470 |
{ |
| 471 |
lcl_RowDescriptionsOperator aOperator( rRowDescriptions, m_spChart2ModelContact->getDocumentModel() ); |
| 472 |
applyData( aOperator ); |
| 473 |
} |
| 474 |
void SAL_CALL ChartDataWrapper::setColumnDescriptions( const Sequence< OUString >& rColumnDescriptions ) |
| 475 |
{ |
| 476 |
lcl_ColumnDescriptionsOperator aOperator( rColumnDescriptions, m_spChart2ModelContact->getDocumentModel() ); |
| 477 |
applyData( aOperator ); |
| 478 |
} |
| 479 |
|
| 480 |
// ____ XComplexDescriptionAccess (write) ____ |
| 481 |
void SAL_CALL ChartDataWrapper::setComplexRowDescriptions( const Sequence< Sequence< OUString > >& rRowDescriptions ) |
| 482 |
{ |
| 483 |
lcl_ComplexRowDescriptionsOperator aOperator( rRowDescriptions, m_spChart2ModelContact->getDocumentModel() ); |
| 484 |
applyData( aOperator ); |
| 485 |
} |
| 486 |
void SAL_CALL ChartDataWrapper::setComplexColumnDescriptions( const Sequence< Sequence< OUString > >& rColumnDescriptions ) |
| 487 |
{ |
| 488 |
lcl_ComplexColumnDescriptionsOperator aOperator( rColumnDescriptions, m_spChart2ModelContact->getDocumentModel() ); |
| 489 |
applyData( aOperator ); |
| 490 |
} |
| 491 |
|
| 492 |
// ____ XAnyDescriptionAccess (write) ____ |
| 493 |
void SAL_CALL ChartDataWrapper::setAnyRowDescriptions( const Sequence< Sequence< uno::Any > >& rRowDescriptions ) |
| 494 |
{ |
| 495 |
lcl_AnyRowDescriptionsOperator aOperator( rRowDescriptions ); |
| 496 |
applyData( aOperator ); |
| 497 |
} |
| 498 |
void SAL_CALL ChartDataWrapper::setAnyColumnDescriptions( const Sequence< Sequence< uno::Any > >& rColumnDescriptions ) |
| 499 |
{ |
| 500 |
lcl_AnyColumnDescriptionsOperator aOperator( rColumnDescriptions ); |
| 501 |
applyData( aOperator ); |
| 502 |
} |
| 503 |
|
| 504 |
// ____ XDateCategories (write) ____ |
| 505 |
void SAL_CALL ChartDataWrapper::setDateCategories( const Sequence< double >& rDates ) |
| 506 |
{ |
| 507 |
rtl::Reference< ChartModel > xChartDoc( m_spChart2ModelContact->getDocumentModel() ); |
| 508 |
ControllerLockGuardUNO aCtrlLockGuard( xChartDoc ); |
| 509 |
lcl_DateCategoriesOperator aOperator( rDates ); |
| 510 |
applyData( aOperator ); |
| 511 |
DiagramHelper::switchToDateCategories( xChartDoc ); |
| 512 |
} |
| 513 |
|
| 514 |
// ____ XChartData (base of XChartDataArray) ____ |
| 515 |
void SAL_CALL ChartDataWrapper::addChartDataChangeEventListener( |
| 516 |
const uno::Reference< css::chart::XChartDataChangeEventListener >& aListener ) |
| 517 |
{ |
| 518 |
std::unique_lock g(m_aMutex); |
| 519 |
m_aEventListenerContainer.addInterface( g, aListener ); |
| 520 |
} |
| 521 |
|
| 522 |
void SAL_CALL ChartDataWrapper::removeChartDataChangeEventListener( |
| 523 |
const uno::Reference< css::chart::XChartDataChangeEventListener >& aListener ) |
| 524 |
{ |
| 525 |
std::unique_lock g(m_aMutex); |
| 526 |
m_aEventListenerContainer.removeInterface( g, aListener ); |
| 527 |
} |
| 528 |
|
| 529 |
double SAL_CALL ChartDataWrapper::getNotANumber() |
| 530 |
{ |
| 531 |
return DBL_MIN; |
| 532 |
} |
| 533 |
|
| 534 |
sal_Bool SAL_CALL ChartDataWrapper::isNotANumber( double nNumber ) |
| 535 |
{ |
| 536 |
return nNumber == DBL_MIN |
| 537 |
|| std::isnan( nNumber ) |
| 538 |
|| std::isinf( nNumber ); |
| 539 |
} |
| 540 |
|
| 541 |
// ____ XComponent ____ |
| 542 |
void SAL_CALL ChartDataWrapper::dispose() |
| 543 |
{ |
| 544 |
std::unique_lock g(m_aMutex); |
| 545 |
m_aEventListenerContainer.disposeAndClear( g, lang::EventObject( static_cast< ::cppu::OWeakObject* >( this ))); |
| 546 |
m_xDataAccess=nullptr; |
| 547 |
} |
| 548 |
|
| 549 |
void SAL_CALL ChartDataWrapper::addEventListener( |
| 550 |
const uno::Reference< lang::XEventListener > & xListener ) |
| 551 |
{ |
| 552 |
std::unique_lock g(m_aMutex); |
| 553 |
m_aEventListenerContainer.addInterface( g, xListener ); |
| 554 |
} |
| 555 |
|
| 556 |
void SAL_CALL ChartDataWrapper::removeEventListener( |
| 557 |
const uno::Reference< lang::XEventListener >& aListener ) |
| 558 |
{ |
| 559 |
std::unique_lock g(m_aMutex); |
| 560 |
m_aEventListenerContainer.removeInterface( g, aListener ); |
| 561 |
} |
| 562 |
|
| 563 |
// ____ XEventListener ____ |
| 564 |
void SAL_CALL ChartDataWrapper::disposing( const lang::EventObject& /* Source */ ) |
| 565 |
{ |
| 566 |
} |
| 567 |
|
| 568 |
void ChartDataWrapper::fireChartDataChangeEvent( css::chart::ChartDataChangeEvent& aEvent ) |
| 569 |
{ |
| 570 |
std::unique_lock g(m_aMutex); |
| 571 |
if( ! m_aEventListenerContainer.getLength(g) ) |
| 572 |
return; |
| 573 |
|
| 574 |
uno::Reference< uno::XInterface > xSrc( static_cast< cppu::OWeakObject* >( this )); |
| 575 |
OSL_ASSERT( xSrc.is()); |
| 576 |
if( xSrc.is() ) |
| 577 |
aEvent.Source = std::move(xSrc); |
| 578 |
|
| 579 |
m_aEventListenerContainer.forEach( g, |
| 580 |
[&aEvent](const uno::Reference<css::lang::XEventListener>& l) |
| 581 |
{ |
| 582 |
uno::Reference<css::chart::XChartDataChangeEventListener> cl(l, uno::UNO_QUERY); |
| 583 |
if (cl) |
| 584 |
cl->chartDataChanged(aEvent); |
| 585 |
}); |
| 586 |
} |
| 587 |
|
| 588 |
void ChartDataWrapper::switchToInternalDataProvider() |
| 589 |
{ |
| 590 |
//create an internal data provider that is connected to the model |
| 591 |
rtl::Reference< ChartModel > xChartDoc( m_spChart2ModelContact->getDocumentModel() ); |
| 592 |
if( xChartDoc.is() ) |
| 593 |
xChartDoc->createInternalDataProvider( true /*bCloneExistingData*/ ); |
| 594 |
initDataAccess(); |
| 595 |
} |
| 596 |
|
| 597 |
void ChartDataWrapper::initDataAccess() |
| 598 |
{ |
| 599 |
rtl::Reference< ChartModel > xChartDoc( m_spChart2ModelContact->getDocumentModel() ); |
| 600 |
if( !xChartDoc.is() ) |
| 601 |
return; |
| 602 |
if( xChartDoc->hasInternalDataProvider() ) |
| 603 |
m_xDataAccess.set( xChartDoc->getDataProvider(), uno::UNO_QUERY_THROW ); |
| 604 |
else |
| 605 |
{ |
| 606 |
//create a separate "internal data provider" that is not connected to the model |
| 607 |
rtl::Reference<InternalDataProvider> xInternal |
| 608 |
= new InternalDataProvider( xChartDoc, /*bConnectToModel*/false, /*bDefaultDataInColumns*/ true ); |
| 609 |
m_xDataAccess = xInternal; |
| 610 |
} |
| 611 |
} |
| 612 |
|
| 613 |
void ChartDataWrapper::applyData( lcl_Operator& rDataOperator ) |
| 614 |
{ |
| 615 |
//bool bSetValues, bool bSetRowDescriptions, bool bSetColumnDescriptions |
| 616 |
rtl::Reference< ChartModel > xChartDoc( m_spChart2ModelContact->getDocumentModel() ); |
| 617 |
if( !xChartDoc.is() ) |
| 618 |
return; |
| 619 |
|
| 620 |
// remember some diagram properties to reset later |
| 621 |
bool bStacked = false; |
| 622 |
bool bPercent = false; |
| 623 |
bool bDeep = false; |
| 624 |
uno::Reference< css::chart::XChartDocument > xOldDoc( static_cast<cppu::OWeakObject*>(xChartDoc.get()), uno::UNO_QUERY ); |
| 625 |
OSL_ASSERT( xOldDoc.is()); |
| 626 |
uno::Reference< beans::XPropertySet > xDiaProp( xOldDoc->getDiagram(), uno::UNO_QUERY ); |
| 627 |
if( xDiaProp.is()) |
| 628 |
{ |
| 629 |
xDiaProp->getPropertyValue(u"Stacked"_ustr) >>= bStacked; |
| 630 |
xDiaProp->getPropertyValue(u"Percent"_ustr) >>= bPercent; |
| 631 |
xDiaProp->getPropertyValue(u"Deep"_ustr) >>= bDeep; |
| 632 |
} |
| 633 |
|
| 634 |
//detect arguments for the new data source |
| 635 |
OUString aRangeString; |
| 636 |
bool bUseColumns = true; |
| 637 |
bool bFirstCellAsLabel = true; |
| 638 |
bool bHasCategories = true; |
| 639 |
uno::Sequence< sal_Int32 > aSequenceMapping; |
| 640 |
|
| 641 |
(void)DataSourceHelper::detectRangeSegmentation( |
| 642 |
xChartDoc, |
| 643 |
aRangeString, aSequenceMapping, bUseColumns, bFirstCellAsLabel, bHasCategories ); |
| 644 |
|
| 645 |
if( !bHasCategories && rDataOperator.setsCategories( bUseColumns ) ) |
| 646 |
bHasCategories = true; |
| 647 |
|
| 648 |
aRangeString = "all"; |
| 649 |
uno::Sequence< beans::PropertyValue > aArguments( DataSourceHelper::createArguments( |
| 650 |
aRangeString, aSequenceMapping, bUseColumns, bFirstCellAsLabel, bHasCategories ) ); |
| 651 |
|
| 652 |
// -- locked controllers |
| 653 |
ControllerLockGuardUNO aCtrlLockGuard( xChartDoc ); |
| 654 |
|
| 655 |
// create and attach new data source |
| 656 |
switchToInternalDataProvider(); |
| 657 |
rDataOperator.apply(m_xDataAccess); |
| 658 |
uno::Reference< chart2::data::XDataProvider > xDataProvider( xChartDoc->getDataProvider() ); |
| 659 |
OSL_ASSERT( xDataProvider.is() ); |
| 660 |
if( !xDataProvider.is() ) |
| 661 |
return; |
| 662 |
uno::Reference< chart2::data::XDataSource > xSource( xDataProvider->createDataSource( aArguments ) ); |
| 663 |
|
| 664 |
rtl::Reference< Diagram > xDia( xChartDoc->getFirstChartDiagram() ); |
| 665 |
if( xDia.is() ) |
| 666 |
xDia->setDiagramData( xSource, aArguments ); |
| 667 |
|
| 668 |
//correct stacking mode |
| 669 |
if( bStacked || bPercent || bDeep ) |
| 670 |
{ |
| 671 |
StackMode eStackMode = StackMode::YStacked; |
| 672 |
if( bDeep ) |
| 673 |
eStackMode = StackMode::ZStacked; |
| 674 |
else if( bPercent ) |
| 675 |
eStackMode = StackMode::YStackedPercent; |
| 676 |
xDia->setStackMode( eStackMode ); |
| 677 |
} |
| 678 |
|
| 679 |
// notify listeners |
| 680 |
css::chart::ChartDataChangeEvent aEvent( |
| 681 |
static_cast< ::cppu::OWeakObject* >( this ), |
| 682 |
css::chart::ChartDataChangeType_ALL, 0, 0, 0, 0 ); |
| 683 |
fireChartDataChangeEvent( aEvent ); |
| 684 |
// \-- locked controllers |
| 685 |
} |
| 686 |
|
| 687 |
OUString SAL_CALL ChartDataWrapper::getImplementationName() |
| 688 |
{ |
| 689 |
return u"com.sun.star.comp.chart.ChartData"_ustr; |
| 690 |
} |
| 691 |
|
| 692 |
sal_Bool SAL_CALL ChartDataWrapper::supportsService( const OUString& rServiceName ) |
| 693 |
{ |
| 694 |
return cppu::supportsService(this, rServiceName); |
| 695 |
} |
| 696 |
|
| 697 |
css::uno::Sequence< OUString > SAL_CALL ChartDataWrapper::getSupportedServiceNames() |
| 698 |
{ |
| 699 |
return { |
| 700 |
u"com.sun.star.chart.ChartDataArray"_ustr, |
| 701 |
u"com.sun.star.chart.ChartData"_ustr |
| 702 |
}; |
| 703 |
} |
| 704 |
|
| 705 |
rtl::Reference<ChartModel> ChartDataWrapper::getChartModel() const |
| 706 |
{ |
| 707 |
return m_spChart2ModelContact->getDocumentModel(); |
| 708 |
} |
| 709 |
|
| 710 |
} // namespace chart |
| 711 |
|
| 712 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |