1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "ColumnLineChartTypeTemplate.hxx"
21 #include "ColumnChartType.hxx"
22 #include "LineChartType.hxx"
23 #include <CommonConverters.hxx>
24 #include <BaseCoordinateSystem.hxx>
25 #include <Diagram.hxx>
26 #include <DiagramHelper.hxx>
27 #include <DataSeries.hxx>
28 #include <DataSeriesHelper.hxx>
29 #include <servicenames_charttypes.hxx>
30 #include "ColumnLineDataInterpreter.hxx"
31 #include <PropertyHelper.hxx>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <com/sun/star/drawing/LineStyle.hpp>
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include <comphelper/diagnose_ex.hxx>
39 using namespace ::com::sun::star
;
41 using ::com::sun::star::uno::Reference
;
42 using ::com::sun::star::uno::Sequence
;
43 using ::com::sun::star::beans::Property
;
50 PROP_COL_LINE_NUMBER_OF_LINES
53 ::chart::tPropertyValueMap
& StaticColumnLineChartTypeTemplateDefaults()
55 static ::chart::tPropertyValueMap aStaticDefaults
=
58 ::chart::tPropertyValueMap aOutMap
;
59 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( aOutMap
, PROP_COL_LINE_NUMBER_OF_LINES
, 1 );
62 return aStaticDefaults
;
65 ::cppu::OPropertyArrayHelper
& StaticColumnLineChartTypeTemplateInfoHelper()
67 static ::cppu::OPropertyArrayHelper
aPropHelper(
70 std::vector
< css::beans::Property
> aProperties
{
71 { u
"NumberOfLines"_ustr
,
72 PROP_COL_LINE_NUMBER_OF_LINES
,
73 cppu::UnoType
<sal_Int32
>::get(),
74 beans::PropertyAttribute::BOUND
75 | beans::PropertyAttribute::MAYBEDEFAULT
} };
77 std::sort( aProperties
.begin(), aProperties
.end(),
78 ::chart::PropertyNameLess() );
80 return comphelper::containerToSequence( aProperties
);
85 uno::Reference
< beans::XPropertySetInfo
>& StaticColumnLineChartTypeTemplateInfo()
87 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
88 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticColumnLineChartTypeTemplateInfoHelper() ) );
89 return xPropertySetInfo
;
92 } // anonymous namespace
97 ColumnLineChartTypeTemplate::ColumnLineChartTypeTemplate(
99 uno::XComponentContext
> const & xContext
,
100 const OUString
& rServiceName
,
101 StackMode eStackMode
,
102 sal_Int32 nNumberOfLines
) :
103 ChartTypeTemplate( xContext
, rServiceName
),
104 m_eStackMode( eStackMode
)
106 setFastPropertyValue_NoBroadcast( PROP_COL_LINE_NUMBER_OF_LINES
, uno::Any( nNumberOfLines
));
109 ColumnLineChartTypeTemplate::~ColumnLineChartTypeTemplate()
112 // ____ OPropertySet ____
113 void ColumnLineChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle
, uno::Any
& rAny
) const
115 const tPropertyValueMap
& rStaticDefaults
= StaticColumnLineChartTypeTemplateDefaults();
116 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
117 if( aFound
== rStaticDefaults
.end() )
120 rAny
= (*aFound
).second
;
123 ::cppu::IPropertyArrayHelper
& SAL_CALL
ColumnLineChartTypeTemplate::getInfoHelper()
125 return StaticColumnLineChartTypeTemplateInfoHelper();
128 // ____ XPropertySet ____
129 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
ColumnLineChartTypeTemplate::getPropertySetInfo()
131 return StaticColumnLineChartTypeTemplateInfo();
134 void ColumnLineChartTypeTemplate::createChartTypes(
135 const std::vector
< std::vector
< rtl::Reference
< DataSeries
> > > & aSeriesSeq
,
136 const std::vector
< rtl::Reference
< BaseCoordinateSystem
> > & rCoordSys
,
137 const std::vector
< rtl::Reference
< ChartType
> >& aOldChartTypesSeq
)
139 if( rCoordSys
.empty() )
144 const std::vector
< rtl::Reference
< DataSeries
> > aFlatSeriesSeq( FlattenSequence( aSeriesSeq
));
145 sal_Int32 nNumberOfSeries
= aFlatSeriesSeq
.size();
146 sal_Int32 nNumberOfLines
= 0;
147 sal_Int32 nNumberOfColumns
= 0;
149 getFastPropertyValue( PROP_COL_LINE_NUMBER_OF_LINES
) >>= nNumberOfLines
;
150 OSL_ENSURE( nNumberOfLines
>=0, "number of lines should be not negative" );
151 if( nNumberOfLines
< 0 )
154 if( nNumberOfLines
>= nNumberOfSeries
)
156 if( nNumberOfSeries
> 0 )
158 nNumberOfLines
= nNumberOfSeries
- 1;
159 nNumberOfColumns
= 1;
165 nNumberOfColumns
= nNumberOfSeries
- nNumberOfLines
;
169 rtl::Reference
< ChartType
> xCT
= new ColumnChartType();
171 ChartTypeTemplate::copyPropertiesFromOldToNewCoordinateSystem( aOldChartTypesSeq
, xCT
);
173 rCoordSys
[ 0 ]->setChartTypes( std::vector
{xCT
} );
175 if( nNumberOfColumns
> 0 )
177 std::vector
< rtl::Reference
< DataSeries
> > aColumnSeq( nNumberOfColumns
);
178 std::copy( aFlatSeriesSeq
.begin(),
179 aFlatSeriesSeq
.begin() + nNumberOfColumns
,
181 xCT
->setDataSeries( aColumnSeq
);
186 xCT
= new LineChartType();
187 rCoordSys
[ 0 ]->addChartType( xCT
);
189 if( nNumberOfLines
> 0 )
191 std::vector
< rtl::Reference
< DataSeries
> > aLineSeq( nNumberOfLines
);
192 std::copy( aFlatSeriesSeq
.begin() + nNumberOfColumns
,
193 aFlatSeriesSeq
.end(),
195 xCT
->setDataSeries( aLineSeq
);
198 catch( const uno::Exception
& )
200 DBG_UNHANDLED_EXCEPTION("chart2");
204 void ColumnLineChartTypeTemplate::applyStyle2(
205 const rtl::Reference
< DataSeries
>& xSeries
,
206 ::sal_Int32 nChartTypeIndex
,
207 ::sal_Int32 nSeriesIndex
,
208 ::sal_Int32 nSeriesCount
)
210 ChartTypeTemplate::applyStyle2( xSeries
, nChartTypeIndex
, nSeriesIndex
, nSeriesCount
);
212 if( nChartTypeIndex
==0 ) // columns
214 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries
, u
"BorderStyle"_ustr
, uno::Any( drawing::LineStyle_NONE
) );
216 else if( nChartTypeIndex
==1 ) // lines
218 DataSeriesHelper::switchLinesOnOrOff( xSeries
, true );
219 DataSeriesHelper::switchSymbolsOnOrOff( xSeries
, false, nSeriesIndex
);
220 DataSeriesHelper::makeLinesThickOrThin( xSeries
, true );
224 StackMode
ColumnLineChartTypeTemplate::getStackMode( sal_Int32 nChartTypeIndex
) const
226 if( nChartTypeIndex
== 0 )
228 return StackMode::NONE
;
231 // ____ XChartTypeTemplate ____
232 bool ColumnLineChartTypeTemplate::matchesTemplate2(
233 const rtl::Reference
< ::chart::Diagram
>& xDiagram
,
234 bool bAdaptProperties
)
236 bool bResult
= false;
243 rtl::Reference
< ChartType
> xColumnChartType
;
244 rtl::Reference
< BaseCoordinateSystem
> xColumnChartCooSys
;
245 rtl::Reference
< ChartType
> xLineChartType
;
246 sal_Int32 nNumberOfChartTypes
= 0;
248 for( rtl::Reference
< BaseCoordinateSystem
> const & coords
: xDiagram
->getBaseCoordinateSystems() )
250 const std::vector
< rtl::Reference
< ChartType
> > aChartTypeSeq( coords
->getChartTypes2());
251 for( rtl::Reference
< ChartType
> const & chartType
: aChartTypeSeq
)
253 ++nNumberOfChartTypes
;
254 if( nNumberOfChartTypes
> 2 )
256 OUString aCTService
= chartType
->getChartType();
257 if( aCTService
== CHART2_SERVICE_NAME_CHARTTYPE_COLUMN
)
259 xColumnChartType
= chartType
;
260 xColumnChartCooSys
= coords
;
262 else if( aCTService
== CHART2_SERVICE_NAME_CHARTTYPE_LINE
)
263 xLineChartType
= chartType
;
265 if( nNumberOfChartTypes
> 2 )
269 if( nNumberOfChartTypes
== 2 &&
270 xColumnChartType
.is() &&
273 OSL_ASSERT( xColumnChartCooSys
.is());
275 // check stackmode of bars
276 bResult
= (xColumnChartCooSys
->getDimension() == getDimension());
280 bool bAmbiguous
=false;
281 bResult
= ( DiagramHelper::getStackModeFromChartType(
282 xColumnChartType
, bFound
, bAmbiguous
,
284 == getStackMode( 0 ) );
286 if( bResult
&& bAdaptProperties
)
288 if( xLineChartType
.is() )
290 sal_Int32 nNumberOfLines
= xLineChartType
->getDataSeries().getLength();
291 setFastPropertyValue_NoBroadcast( PROP_COL_LINE_NUMBER_OF_LINES
, uno::Any( nNumberOfLines
));
297 catch( const uno::Exception
& )
299 DBG_UNHANDLED_EXCEPTION("chart2");
305 rtl::Reference
< ChartType
> ColumnLineChartTypeTemplate::getChartTypeForIndex( sal_Int32 nChartTypeIndex
)
307 if( nChartTypeIndex
== 0 )
308 return new ColumnChartType();
310 return new LineChartType();
313 rtl::Reference
< ChartType
> ColumnLineChartTypeTemplate::getChartTypeForNewSeries2(
314 const std::vector
< rtl::Reference
< ChartType
> >& aFormerlyUsedChartTypes
)
316 rtl::Reference
< ChartType
> xResult
;
320 xResult
= new LineChartType();
321 ChartTypeTemplate::copyPropertiesFromOldToNewCoordinateSystem( aFormerlyUsedChartTypes
, xResult
);
323 catch( const uno::Exception
& )
325 DBG_UNHANDLED_EXCEPTION("chart2");
331 rtl::Reference
< DataInterpreter
> ColumnLineChartTypeTemplate::getDataInterpreter2()
333 if( ! m_xDataInterpreter
.is())
335 sal_Int32 nNumberOfLines
= 1;
336 getFastPropertyValue( PROP_COL_LINE_NUMBER_OF_LINES
) >>= nNumberOfLines
;
337 m_xDataInterpreter
= new ColumnLineDataInterpreter( nNumberOfLines
);
342 OSL_FAIL( "number of lines may not be valid anymore in the datainterpreter" );
346 return m_xDataInterpreter
;
349 IMPLEMENT_FORWARD_XINTERFACE2( ColumnLineChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
350 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ColumnLineChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */