1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include "HistogramChartTypeTemplate.hxx"
11 #include "HistogramChartType.hxx"
12 #include "HistogramDataInterpreter.hxx"
13 #include <Diagram.hxx>
14 #include <DataSeries.hxx>
15 #include <DataSeriesHelper.hxx>
16 #include <PropertyHelper.hxx>
17 #include <com/sun/star/beans/PropertyAttribute.hpp>
18 #include <com/sun/star/drawing/LineStyle.hpp>
19 #include <com/sun/star/chart2/DataPointGeometry3D.hpp>
20 #include <com/sun/star/uno/XComponentContext.hpp>
21 #include <comphelper/diagnose_ex.hxx>
25 using namespace ::com::sun::star
;
27 using ::com::sun::star::uno::Reference
;
28 using ::com::sun::star::uno::Sequence
;
29 using ::com::sun::star::beans::Property
;
35 PROP_HISTOGRAM_TEMPLATE_DIMENSION
,
38 void lcl_AddPropertiesToVector(std::vector
<Property
>& rOutProperties
)
40 rOutProperties
.emplace_back(
41 "Dimension", PROP_HISTOGRAM_TEMPLATE_DIMENSION
, cppu::UnoType
<sal_Int32
>::get(),
42 beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEDEFAULT
);
45 ::cppu::OPropertyArrayHelper
& StaticHistogramChartTypeTemplateInfoHelper()
47 static ::cppu::OPropertyArrayHelper aPropHelper
= []() {
48 std::vector
<css::beans::Property
> aProperties
;
49 lcl_AddPropertiesToVector(aProperties
);
51 std::sort(aProperties
.begin(), aProperties
.end(), ::chart::PropertyNameLess());
53 return comphelper::containerToSequence(aProperties
);
58 } // anonymous namespace
62 HistogramChartTypeTemplate::HistogramChartTypeTemplate(
63 Reference
<uno::XComponentContext
> const& xContext
, const OUString
& rServiceName
,
65 : ChartTypeTemplate(xContext
, rServiceName
)
66 , m_eStackMode(eStackMode
)
71 sal_Int32
HistogramChartTypeTemplate::getDimension() const { return m_nDim
; }
73 StackMode
HistogramChartTypeTemplate::getStackMode(sal_Int32
/* nChartTypeIndex */) const
78 rtl::Reference
<ChartType
>
79 HistogramChartTypeTemplate::getChartTypeForIndex(sal_Int32
/*nChartTypeIndex*/)
81 return new HistogramChartType();
84 rtl::Reference
<ChartType
> HistogramChartTypeTemplate::getChartTypeForNewSeries2(
85 const std::vector
<rtl::Reference
<ChartType
>>& aFormerlyUsedChartTypes
)
87 rtl::Reference
<ChartType
> xResult(getChartTypeForIndex(0));
88 ChartTypeTemplate::copyPropertiesFromOldToNewCoordinateSystem(aFormerlyUsedChartTypes
, xResult
);
92 // ____ OPropertySet ____
93 void HistogramChartTypeTemplate::GetDefaultValue(sal_Int32 nHandle
, uno::Any
& rAny
) const
95 static ::chart::tPropertyValueMap aStaticDefaults
= []() {
96 ::chart::tPropertyValueMap aTmp
;
97 ::chart::PropertyHelper::setPropertyValueDefault
<sal_Int32
>(
98 aTmp
, PROP_HISTOGRAM_TEMPLATE_DIMENSION
, 2);
101 tPropertyValueMap::const_iterator
aFound(aStaticDefaults
.find(nHandle
));
102 if (aFound
== aStaticDefaults
.end())
105 rAny
= (*aFound
).second
;
108 ::cppu::IPropertyArrayHelper
& SAL_CALL
HistogramChartTypeTemplate::getInfoHelper()
110 return StaticHistogramChartTypeTemplateInfoHelper();
113 // ____ XPropertySet ____
114 Reference
<beans::XPropertySetInfo
> SAL_CALL
HistogramChartTypeTemplate::getPropertySetInfo()
116 static uno::Reference
<beans::XPropertySetInfo
> xPropertySetInfo(
117 ::cppu::OPropertySetHelper::createPropertySetInfo(
118 StaticHistogramChartTypeTemplateInfoHelper()));
119 return xPropertySetInfo
;
122 void HistogramChartTypeTemplate::applyStyle2(const rtl::Reference
<DataSeries
>& xSeries
,
123 ::sal_Int32 nChartTypeIndex
, ::sal_Int32 nSeriesIndex
,
124 ::sal_Int32 nSeriesCount
)
126 ChartTypeTemplate::applyStyle2(xSeries
, nChartTypeIndex
, nSeriesIndex
, nSeriesCount
);
127 DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints(xSeries
, "BorderStyle",
128 uno::Any(drawing::LineStyle_NONE
));
131 void HistogramChartTypeTemplate::resetStyles2(const rtl::Reference
<::chart::Diagram
>& xDiagram
)
133 ChartTypeTemplate::resetStyles2(xDiagram
);
134 std::vector
<rtl::Reference
<DataSeries
>> aSeriesVec(xDiagram
->getDataSeries());
135 uno::Any
aLineStyleAny(drawing::LineStyle_NONE
);
136 for (auto const& series
: aSeriesVec
)
138 if (series
->getPropertyValue("BorderStyle") == aLineStyleAny
)
140 series
->setPropertyToDefault("BorderStyle");
144 xDiagram
->setVertical(false);
147 rtl::Reference
<DataInterpreter
> HistogramChartTypeTemplate::getDataInterpreter2()
149 if (!m_xDataInterpreter
.is())
150 m_xDataInterpreter
.set(new HistogramDataInterpreter
);
152 return m_xDataInterpreter
;
155 IMPLEMENT_FORWARD_XINTERFACE2(HistogramChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
156 IMPLEMENT_FORWARD_XTYPEPROVIDER2(HistogramChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */