Files
libreoffice/xmloff/source/chart/SchXMLSeriesHelper.cxx
Gabor Kelemen f0e0fb71fc tdf#42949 Fix IWYU warnings in xmloff/source/[c-m]*/*cxx
Also checked xmloff/qa

Found with bin/find-unneeded-includes
Only removal proposals are dealt with here.

Change-Id: I843917d255f841066ace8d944aa1d00f1b718108
Reviewed-on: https://gerrit.libreoffice.org/79773
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
2019-09-30 10:03:30 +02:00

225 lines
8.4 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <xmloff/SchXMLSeriesHelper.hxx>
#include <com/sun/star/chart2/XChartDocument.hpp>
#include <com/sun/star/chart2/XChartTypeContainer.hpp>
#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
#include <com/sun/star/chart2/XDataSeriesContainer.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <sal/log.hxx>
#include <tools/diagnose_ex.h>
using namespace ::com::sun::star;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Sequence;
::std::vector< Reference< chart2::XDataSeries > >
SchXMLSeriesHelper::getDataSeriesFromDiagram(
const Reference< chart2::XDiagram > & xDiagram )
{
::std::vector< Reference< chart2::XDataSeries > > aResult;
try
{
Reference< chart2::XCoordinateSystemContainer > xCooSysCnt(
xDiagram, uno::UNO_QUERY_THROW );
const Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq(
xCooSysCnt->getCoordinateSystems());
for( const auto& rCooSys : aCooSysSeq )
{
Reference< chart2::XChartTypeContainer > xCTCnt( rCooSys, uno::UNO_QUERY_THROW );
const Sequence< Reference< chart2::XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
for( const auto& rChartType : aChartTypeSeq )
{
Reference< chart2::XDataSeriesContainer > xDSCnt( rChartType, uno::UNO_QUERY_THROW );
Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() );
::std::copy( aSeriesSeq.begin(), aSeriesSeq.end(),
::std::back_inserter( aResult ));
}
}
}
catch( const uno::Exception & )
{
DBG_UNHANDLED_EXCEPTION("xmloff.chart");
}
return aResult;
}
::std::map< Reference< chart2::XDataSeries >, sal_Int32 > SchXMLSeriesHelper::getDataSeriesIndexMapFromDiagram(
const Reference< chart2::XDiagram > & xDiagram )
{
::std::map< Reference< chart2::XDataSeries >, sal_Int32 > aRet;
sal_Int32 nIndex=0;
::std::vector< Reference< chart2::XDataSeries > > aSeriesVector( SchXMLSeriesHelper::getDataSeriesFromDiagram( xDiagram ));
for( const Reference< chart2::XDataSeries >& xSeries : aSeriesVector )
{
if( xSeries.is() )
{
if( aRet.end() == aRet.find(xSeries) )
aRet[xSeries]=nIndex;
}
nIndex++;
}
return aRet;
}
namespace {
uno::Reference< chart2::XChartType > lcl_getChartTypeOfSeries(
const uno::Reference< chart2::XDiagram >& xDiagram
, const Reference< chart2::XDataSeries >& xSeries )
{
if(!xDiagram.is())
return nullptr;
//iterate through the model to find the given xSeries
//the found parent indicates the charttype
//iterate through all coordinate systems
uno::Reference< chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
if( !xCooSysContainer.is())
return nullptr;
const uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
for( const auto& xCooSys : aCooSysList )
{
//iterate through all chart types in the current coordinate system
uno::Reference< chart2::XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
SAL_WARN_IF( !xChartTypeContainer.is(), "xmloff.chart", "xChartTypeContainer is NULL");
if( !xChartTypeContainer.is() )
continue;
const uno::Sequence< uno::Reference< chart2::XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
for( const auto& xChartType : aChartTypeList )
{
//iterate through all series in this chart type
uno::Reference< chart2::XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY );
SAL_WARN_IF( !xDataSeriesContainer.is(), "xmloff.chart", "xDataSeriesContainer is NULL");
if( !xDataSeriesContainer.is() )
continue;
uno::Sequence< uno::Reference< chart2::XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() );
if (std::find(aSeriesList.begin(), aSeriesList.end(), xSeries) != aSeriesList.end())
return xChartType;
}
}
return nullptr;
}
}
bool SchXMLSeriesHelper::isCandleStickSeries(
const Reference< chart2::XDataSeries >& xSeries
, const Reference< frame::XModel >& xChartModel )
{
bool bRet = false;
uno::Reference< chart2::XChartDocument > xNewDoc( xChartModel, uno::UNO_QUERY );
if( xNewDoc.is() )
{
uno::Reference< chart2::XDiagram > xNewDiagram( xNewDoc->getFirstDiagram() );
if( xNewDiagram.is() )
{
uno::Reference< chart2::XChartType > xChartType( lcl_getChartTypeOfSeries(
xNewDiagram, xSeries ) );
if( xChartType.is() )
{
OUString aServiceName( xChartType->getChartType() );
if( aServiceName == "com.sun.star.chart2.CandleStickChartType" )
bRet = true;
}
}
}
return bRet;
}
//static
uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPISeriesPropertySet(
const uno::Reference< chart2::XDataSeries >& xSeries
, const uno::Reference< frame::XModel >& xChartModel )
{
uno::Reference< beans::XPropertySet > xRet;
if( xSeries.is() )
{
try
{
uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY );
if( xFactory.is() )
{
xRet.set( xFactory->createInstance( "com.sun.star.comp.chart2.DataSeriesWrapper" ), uno::UNO_QUERY );
Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY );
if(xInit.is())
{
Sequence< uno::Any > aArguments(1);
aArguments[0] <<= xSeries;
xInit->initialize(aArguments);
}
}
}
catch( const uno::Exception & )
{
TOOLS_INFO_EXCEPTION("xmloff.chart", "Exception caught SchXMLSeriesHelper::createOldAPISeriesPropertySet" );
}
}
return xRet;
}
//static
uno::Reference< beans::XPropertySet > SchXMLSeriesHelper::createOldAPIDataPointPropertySet(
const uno::Reference< chart2::XDataSeries >& xSeries
, sal_Int32 nPointIndex
, const uno::Reference< frame::XModel >& xChartModel )
{
uno::Reference< beans::XPropertySet > xRet;
if( xSeries.is() )
{
try
{
uno::Reference< lang::XMultiServiceFactory > xFactory( xChartModel, uno::UNO_QUERY );
if( xFactory.is() )
{
xRet.set( xFactory->createInstance( "com.sun.star.comp.chart2.DataSeriesWrapper" ), uno::UNO_QUERY );
Reference< lang::XInitialization > xInit( xRet, uno::UNO_QUERY );
if(xInit.is())
{
Sequence< uno::Any > aArguments(2);
aArguments[0] <<= xSeries;
aArguments[1] <<= nPointIndex;
xInit->initialize(aArguments);
}
}
}
catch( const uno::Exception & )
{
TOOLS_INFO_EXCEPTION("xmloff.chart", "Exception caught SchXMLSeriesHelper::createOldAPIDataPointPropertySet" );
}
}
return xRet;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */