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 "BarChartTypeTemplate.hxx"
21 #include "ColumnChartType.hxx"
22 #include <Diagram.hxx>
23 #include <DataSeries.hxx>
24 #include <DataSeriesHelper.hxx>
25 #include <PropertyHelper.hxx>
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <com/sun/star/drawing/LineStyle.hpp>
28 #include <com/sun/star/chart2/DataPointGeometry3D.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <comphelper/diagnose_ex.hxx>
34 using namespace ::com::sun::star
;
36 using ::com::sun::star::uno::Reference
;
37 using ::com::sun::star::uno::Sequence
;
38 using ::com::sun::star::beans::Property
;
45 PROP_BAR_TEMPLATE_DIMENSION
,
46 PROP_BAR_TEMPLATE_GEOMETRY3D
49 void lcl_AddPropertiesToVector(
50 std::vector
< Property
> & rOutProperties
)
52 rOutProperties
.emplace_back( "Dimension",
53 PROP_BAR_TEMPLATE_DIMENSION
,
54 cppu::UnoType
<sal_Int32
>::get(),
55 beans::PropertyAttribute::BOUND
56 | beans::PropertyAttribute::MAYBEDEFAULT
);
57 rOutProperties
.emplace_back( "Geometry3D",
58 PROP_BAR_TEMPLATE_GEOMETRY3D
,
59 cppu::UnoType
<sal_Int32
>::get(),
60 beans::PropertyAttribute::BOUND
61 | beans::PropertyAttribute::MAYBEDEFAULT
);
64 ::cppu::OPropertyArrayHelper
& StaticBarChartTypeTemplateInfoHelper()
66 static ::cppu::OPropertyArrayHelper aPropHelper
= []()
68 std::vector
< css::beans::Property
> aProperties
;
69 lcl_AddPropertiesToVector( aProperties
);
71 std::sort( aProperties
.begin(), aProperties
.end(),
72 ::chart::PropertyNameLess() );
74 return comphelper::containerToSequence( aProperties
);
79 } // anonymous namespace
84 BarChartTypeTemplate::BarChartTypeTemplate(
86 uno::XComponentContext
> const & xContext
,
87 const OUString
& rServiceName
,
89 BarDirection eDirection
,
90 sal_Int32 nDim
/* = 2 */ ) :
91 ChartTypeTemplate( xContext
, rServiceName
),
92 m_eStackMode( eStackMode
),
93 m_eBarDirection( eDirection
),
97 BarChartTypeTemplate::~BarChartTypeTemplate()
100 sal_Int32
BarChartTypeTemplate::getDimension() const
105 StackMode
BarChartTypeTemplate::getStackMode( sal_Int32
/* nChartTypeIndex */ ) const
110 bool BarChartTypeTemplate::isSwapXAndY() const
112 return (m_eBarDirection
== HORIZONTAL
);
115 // ____ ChartTypeTemplate ____
116 bool BarChartTypeTemplate::matchesTemplate2(
117 const rtl::Reference
< ::chart::Diagram
>& xDiagram
,
118 bool bAdaptProperties
)
120 bool bResult
= ChartTypeTemplate::matchesTemplate2( xDiagram
, bAdaptProperties
);
126 bool bAmbiguous
= false;
127 bool bVertical
= xDiagram
->getVertical( bFound
, bAmbiguous
);
128 if( m_eBarDirection
== HORIZONTAL
)
130 else if( m_eBarDirection
== VERTICAL
)
131 bResult
= !bVertical
;
134 // adapt solid-type of template according to values in series
135 if( bAdaptProperties
&&
137 getDimension() == 3 )
140 bool bGeomFound
= false, bGeomAmbiguous
= false;
141 sal_Int32 aCommonGeom
= xDiagram
->getGeometry3D( bGeomFound
, bGeomAmbiguous
);
143 if( !bGeomAmbiguous
)
145 setFastPropertyValue_NoBroadcast(
146 PROP_BAR_TEMPLATE_GEOMETRY3D
, uno::Any( aCommonGeom
));
153 rtl::Reference
< ChartType
> BarChartTypeTemplate::getChartTypeForIndex( sal_Int32
/*nChartTypeIndex*/ )
155 return new ColumnChartType();
158 rtl::Reference
< ChartType
> BarChartTypeTemplate::getChartTypeForNewSeries2(
159 const std::vector
< rtl::Reference
< ChartType
> >& aFormerlyUsedChartTypes
)
161 rtl::Reference
< ChartType
> xResult( getChartTypeForIndex( 0 ) );
162 ChartTypeTemplate::copyPropertiesFromOldToNewCoordinateSystem( aFormerlyUsedChartTypes
, xResult
);
166 // ____ OPropertySet ____
167 void BarChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle
, uno::Any
& rAny
) const
169 static ::chart::tPropertyValueMap aStaticDefaults
= []()
171 ::chart::tPropertyValueMap aTmp
;
172 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( aTmp
, PROP_BAR_TEMPLATE_DIMENSION
, 2 );
173 ::chart::PropertyHelper::setPropertyValueDefault( aTmp
, PROP_BAR_TEMPLATE_GEOMETRY3D
, ::chart2::DataPointGeometry3D::CUBOID
);
176 tPropertyValueMap::const_iterator
aFound( aStaticDefaults
.find( nHandle
) );
177 if( aFound
== aStaticDefaults
.end() )
180 rAny
= (*aFound
).second
;
183 ::cppu::IPropertyArrayHelper
& SAL_CALL
BarChartTypeTemplate::getInfoHelper()
185 return StaticBarChartTypeTemplateInfoHelper();
188 // ____ XPropertySet ____
189 Reference
< beans::XPropertySetInfo
> SAL_CALL
BarChartTypeTemplate::getPropertySetInfo()
191 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
192 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticBarChartTypeTemplateInfoHelper() ) );
193 return xPropertySetInfo
;
196 void BarChartTypeTemplate::applyStyle2(
197 const rtl::Reference
< DataSeries
>& xSeries
,
198 ::sal_Int32 nChartTypeIndex
,
199 ::sal_Int32 nSeriesIndex
,
200 ::sal_Int32 nSeriesCount
)
202 ChartTypeTemplate::applyStyle2( xSeries
, nChartTypeIndex
, nSeriesIndex
, nSeriesCount
);
203 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries
, u
"BorderStyle"_ustr
, uno::Any( drawing::LineStyle_NONE
) );
204 if( getDimension() != 3 )
210 uno::Any aAGeometry3D
;
211 getFastPropertyValue( aAGeometry3D
, PROP_BAR_TEMPLATE_GEOMETRY3D
);
212 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries
, u
"Geometry3D"_ustr
, aAGeometry3D
);
214 catch( const uno::Exception
& )
216 DBG_UNHANDLED_EXCEPTION("chart2");
220 void BarChartTypeTemplate::resetStyles2(
221 const rtl::Reference
< ::chart::Diagram
>& xDiagram
)
223 ChartTypeTemplate::resetStyles2( xDiagram
);
224 std::vector
< rtl::Reference
< DataSeries
> > aSeriesVec(
225 xDiagram
->getDataSeries());
226 uno::Any
aLineStyleAny( drawing::LineStyle_NONE
);
227 for (auto const& series
: aSeriesVec
)
229 if( getDimension() == 3 )
230 series
->setPropertyToDefault( u
"Geometry3D"_ustr
);
231 if( series
->getPropertyValue( u
"BorderStyle"_ustr
) == aLineStyleAny
)
233 series
->setPropertyToDefault( u
"BorderStyle"_ustr
);
237 xDiagram
->setVertical( false );
240 void BarChartTypeTemplate::createCoordinateSystems(
241 const rtl::Reference
< ::chart::Diagram
> & xDiagram
)
243 ChartTypeTemplate::createCoordinateSystems( xDiagram
);
245 xDiagram
->setVertical( m_eBarDirection
== HORIZONTAL
);
248 IMPLEMENT_FORWARD_XINTERFACE2( BarChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
249 IMPLEMENT_FORWARD_XTYPEPROVIDER2( BarChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */