LibreOffice Module chart2 (master) 1
BarChartTypeTemplate.cxx
Go to the documentation of this file.
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
21#include "ColumnChartType.hxx"
22#include <Diagram.hxx>
23#include <DiagramHelper.hxx>
24#include <DataSeries.hxx>
25#include <DataSeriesHelper.hxx>
26#include <PropertyHelper.hxx>
27#include <com/sun/star/beans/PropertyAttribute.hpp>
28#include <com/sun/star/drawing/LineStyle.hpp>
29#include <com/sun/star/chart2/DataPointGeometry3D.hpp>
30#include <com/sun/star/uno/XComponentContext.hpp>
32
33#include <algorithm>
34
35using namespace ::com::sun::star;
36
37using ::com::sun::star::uno::Reference;
38using ::com::sun::star::uno::Sequence;
39using ::com::sun::star::beans::Property;
40
41namespace
42{
43
44enum
45{
46 PROP_BAR_TEMPLATE_DIMENSION,
47 PROP_BAR_TEMPLATE_GEOMETRY3D
48};
49
50void lcl_AddPropertiesToVector(
51 std::vector< Property > & rOutProperties )
52{
53 rOutProperties.emplace_back( "Dimension",
54 PROP_BAR_TEMPLATE_DIMENSION,
56 beans::PropertyAttribute::BOUND
57 | beans::PropertyAttribute::MAYBEDEFAULT );
58 rOutProperties.emplace_back( "Geometry3D",
59 PROP_BAR_TEMPLATE_GEOMETRY3D,
61 beans::PropertyAttribute::BOUND
62 | beans::PropertyAttribute::MAYBEDEFAULT );
63}
64
65::cppu::OPropertyArrayHelper& StaticBarChartTypeTemplateInfoHelper()
66{
67 static ::cppu::OPropertyArrayHelper aPropHelper = []()
68 {
69 std::vector< css::beans::Property > aProperties;
70 lcl_AddPropertiesToVector( aProperties );
71
72 std::sort( aProperties.begin(), aProperties.end(),
74
75 return comphelper::containerToSequence( aProperties );
76 }();
77 return aPropHelper;
78};
79
80} // anonymous namespace
81
82namespace chart
83{
84
87 uno::XComponentContext > const & xContext,
88 const OUString & rServiceName,
89 StackMode eStackMode,
90 BarDirection eDirection,
91 sal_Int32 nDim /* = 2 */ ) :
92 ChartTypeTemplate( xContext, rServiceName ),
93 m_eStackMode( eStackMode ),
94 m_eBarDirection( eDirection ),
95 m_nDim( nDim )
96{}
97
99{}
100
102{
103 return m_nDim;
104}
105
106StackMode BarChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
107{
108 return m_eStackMode;
109}
110
112{
113 return (m_eBarDirection == HORIZONTAL);
114}
115
116// ____ ChartTypeTemplate ____
119 bool bAdaptProperties )
120{
121 bool bResult = ChartTypeTemplate::matchesTemplate2( xDiagram, bAdaptProperties );
122
123 //check BarDirection
124 if( bResult )
125 {
126 bool bFound = false;
127 bool bAmbiguous = false;
128 bool bVertical = xDiagram->getVertical( bFound, bAmbiguous );
130 bResult = bVertical;
131 else if( m_eBarDirection == VERTICAL )
132 bResult = !bVertical;
133 }
134
135 // adapt solid-type of template according to values in series
136 if( bAdaptProperties &&
137 bResult &&
138 getDimension() == 3 )
139 {
140
141 bool bGeomFound = false, bGeomAmbiguous = false;
142 sal_Int32 aCommonGeom = xDiagram->getGeometry3D( bGeomFound, bGeomAmbiguous );
143
144 if( !bGeomAmbiguous )
145 {
147 PROP_BAR_TEMPLATE_GEOMETRY3D, uno::Any( aCommonGeom ));
148 }
149 }
150
151 return bResult;
152}
153
155{
156 return new ColumnChartType();
157}
158
160 const std::vector< rtl::Reference< ChartType > >& aFormerlyUsedChartTypes )
161{
163 ChartTypeTemplate::copyPropertiesFromOldToNewCoordinateSystem( aFormerlyUsedChartTypes, xResult );
164 return xResult;
165}
166
167// ____ OPropertySet ____
168void BarChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
169{
170 static ::chart::tPropertyValueMap aStaticDefaults = []()
171 {
173 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aTmp, PROP_BAR_TEMPLATE_DIMENSION, 2 );
174 ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_BAR_TEMPLATE_GEOMETRY3D, ::chart2::DataPointGeometry3D::CUBOID );
175 return aTmp;
176 }();
177 tPropertyValueMap::const_iterator aFound( aStaticDefaults.find( nHandle ) );
178 if( aFound == aStaticDefaults.end() )
179 rAny.clear();
180 else
181 rAny = (*aFound).second;
182}
183
185{
186 return StaticBarChartTypeTemplateInfoHelper();
187}
188
189// ____ XPropertySet ____
191{
192 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
193 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticBarChartTypeTemplateInfoHelper() ) );
194 return xPropertySetInfo;
195}
196
198 const rtl::Reference< DataSeries >& xSeries,
199 ::sal_Int32 nChartTypeIndex,
200 ::sal_Int32 nSeriesIndex,
201 ::sal_Int32 nSeriesCount )
202{
203 ChartTypeTemplate::applyStyle2( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
204 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "BorderStyle", uno::Any( drawing::LineStyle_NONE ) );
205 if( getDimension() != 3 )
206 return;
207
208 try
209 {
210 //apply Geometry3D
211 uno::Any aAGeometry3D;
212 getFastPropertyValue( aAGeometry3D, PROP_BAR_TEMPLATE_GEOMETRY3D );
213 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, "Geometry3D", aAGeometry3D );
214 }
215 catch( const uno::Exception & )
216 {
217 DBG_UNHANDLED_EXCEPTION("chart2");
218 }
219}
220
222 const rtl::Reference< ::chart::Diagram >& xDiagram )
223{
225 std::vector< rtl::Reference< DataSeries > > aSeriesVec(
226 xDiagram->getDataSeries());
227 uno::Any aLineStyleAny( drawing::LineStyle_NONE );
228 for (auto const& series : aSeriesVec)
229 {
230 if( getDimension() == 3 )
231 series->setPropertyToDefault( "Geometry3D");
232 if( series->getPropertyValue( "BorderStyle") == aLineStyleAny )
233 {
234 series->setPropertyToDefault( "BorderStyle");
235 }
236 }
237
238 xDiagram->setVertical( false );
239}
240
242 const rtl::Reference< ::chart::Diagram > & xDiagram )
243{
245
246 xDiagram->setVertical( m_eBarDirection == HORIZONTAL );
247}
248
251
252} // namespace chart
253
254/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StackMode m_eStackMode
PropertiesInfo aProperties
virtual bool matchesTemplate2(const rtl::Reference< ::chart::Diagram > &xDiagram, bool bAdaptProperties) override
virtual ~BarChartTypeTemplate() override
virtual rtl::Reference< ::chart::ChartType > getChartTypeForNewSeries2(const std::vector< rtl::Reference< ::chart::ChartType > > &aFormerlyUsedChartTypes) override
virtual void createCoordinateSystems(const rtl::Reference< ::chart::Diagram > &xDiagram) override
Creates a 2d or 3d cartesian coordinate system with mathematically oriented, linear scales with auto-...
virtual void GetDefaultValue(sal_Int32 nHandle, css::uno::Any &rAny) const override
merge XInterface implementations
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void resetStyles2(const rtl::Reference< ::chart::Diagram > &xDiagram) override
virtual sal_Int32 getDimension() const override
returns 2 by default. Supported are 2 and 3
virtual void applyStyle2(const rtl::Reference< ::chart::DataSeries > &xSeries, ::sal_Int32 nChartTypeGroupIndex, ::sal_Int32 nSeriesIndex, ::sal_Int32 nSeriesCount) override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
The InfoHelper table contains all property names and types of this object.
virtual bool isSwapXAndY() const override
BarChartTypeTemplate(css::uno::Reference< css::uno::XComponentContext > const &xContext, const OUString &rServiceName, StackMode eStackMode, BarDirection eDirection, sal_Int32 nDim=2)
virtual rtl::Reference< ::chart::ChartType > getChartTypeForIndex(sal_Int32 nChartTypeIndex) override
virtual StackMode getStackMode(sal_Int32 nChartTypeIndex) const override
returns StackMode::NONE by default.
For creating diagrams and modifying existing diagrams.
virtual bool matchesTemplate2(const rtl::Reference< ::chart::Diagram > &xDiagram, bool bAdaptProperties)
static void copyPropertiesFromOldToNewCoordinateSystem(const std::vector< rtl::Reference< ChartType > > &rOldChartTypesSeq, const rtl::Reference< ChartType > &xNewChartType)
virtual void applyStyle2(const rtl::Reference< ::chart::DataSeries > &xSeries, ::sal_Int32 nChartTypeIndex, ::sal_Int32 nSeriesIndex, ::sal_Int32 nSeriesCount)
virtual void createCoordinateSystems(const rtl::Reference< ::chart::Diagram > &xDiagram)
Creates a 2d or 3d cartesian coordinate system with mathematically oriented, linear scales with auto-...
virtual void resetStyles2(const rtl::Reference< ::chart::Diagram > &xDiagram)
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
The same as getFastPropertyValue, but return the value through rValue and nHandle is always valid.
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
The same as setFastPropertyValue; nHandle is always valid.
#define DBG_UNHANDLED_EXCEPTION(...)
OOO_DLLPUBLIC_CHARTTOOLS void setPropertyAlsoToAllAttributedDataPoints(const rtl::Reference< ::chart::DataSeries > &xSeries, const OUString &rPropertyName, const css::uno::Any &rPropertyValue)
void setPropertyValueDefault(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Calls setPropertyValue() but asserts that the given property hasn't been set before.
std::unordered_map< tPropertyValueMapKey, css::uno::Any > tPropertyValueMap
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
sal_Int32 nHandle