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 "NetChartTypeTemplate.hxx"
21 #include "FilledNetChartType.hxx"
22 #include "NetChartType.hxx"
23 #include <Diagram.hxx>
24 #include <DataSeries.hxx>
25 #include <DataSeriesHelper.hxx>
26 #include <ChartType.hxx>
27 #include <com/sun/star/chart2/SymbolStyle.hpp>
28 #include <com/sun/star/chart2/Symbol.hpp>
29 #include <com/sun/star/drawing/LineStyle.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <comphelper/diagnose_ex.hxx>
33 using namespace ::com::sun::star
;
35 using ::com::sun::star::uno::Reference
;
40 NetChartTypeTemplate::NetChartTypeTemplate(
41 Reference
< uno::XComponentContext
> const & xContext
,
42 const OUString
& rServiceName
,
46 bool bHasFilledArea
) :
47 ChartTypeTemplate( xContext
, rServiceName
),
48 m_eStackMode( eStackMode
),
49 m_bHasSymbols( bSymbols
),
50 m_bHasLines( bHasLines
),
51 m_bHasFilledArea( bHasFilledArea
)
54 NetChartTypeTemplate::~NetChartTypeTemplate()
57 StackMode
NetChartTypeTemplate::getStackMode( sal_Int32
/* nChartTypeIndex */ ) const
62 void NetChartTypeTemplate::applyStyle2(
63 const rtl::Reference
< DataSeries
>& xSeries
,
64 ::sal_Int32 nChartTypeIndex
,
65 ::sal_Int32 nSeriesIndex
,
66 ::sal_Int32 nSeriesCount
)
68 ChartTypeTemplate::applyStyle2( xSeries
, nChartTypeIndex
, nSeriesIndex
, nSeriesCount
);
72 DataSeriesHelper::switchSymbolsOnOrOff( xSeries
, m_bHasSymbols
, nSeriesIndex
);
73 DataSeriesHelper::switchLinesOnOrOff( xSeries
, m_bHasLines
);
74 DataSeriesHelper::makeLinesThickOrThin( xSeries
, true );
76 catch( const uno::Exception
& )
78 DBG_UNHANDLED_EXCEPTION("chart2");
82 // ____ ChartTypeTemplate ____
83 bool NetChartTypeTemplate::matchesTemplate2(
84 const rtl::Reference
< ::chart::Diagram
>& xDiagram
,
85 bool bAdaptProperties
)
87 bool bResult
= ChartTypeTemplate::matchesTemplate2( xDiagram
, bAdaptProperties
);
92 if( m_bHasFilledArea
)
96 // for a template with symbols it is ok, if there is at least one series
97 // with symbols, otherwise an unknown template is too easy to achieve
98 bool bSymbolFound
= false;
99 bool bLineFound
= false;
101 std::vector
< rtl::Reference
< DataSeries
> > aSeriesVec
=
102 xDiagram
->getDataSeries();
104 for (auto const& series
: aSeriesVec
)
108 chart2::Symbol aSymbProp
;
109 drawing::LineStyle eLineStyle
;
111 bool bCurrentHasSymbol
= (series
->getPropertyValue( u
"Symbol"_ustr
) >>= aSymbProp
) &&
112 (aSymbProp
.Style
!= chart2::SymbolStyle_NONE
);
114 if( bCurrentHasSymbol
)
117 if( bCurrentHasSymbol
&& (!m_bHasSymbols
) )
123 bool bCurrentHasLine
= (series
->getPropertyValue( u
"LineStyle"_ustr
) >>= eLineStyle
) &&
124 ( eLineStyle
!= drawing::LineStyle_NONE
);
126 if( bCurrentHasLine
)
129 if( bCurrentHasLine
&& (!m_bHasLines
) )
135 catch( const uno::Exception
& )
137 DBG_UNHANDLED_EXCEPTION("chart2");
143 if( !bLineFound
&& m_bHasLines
&& bSymbolFound
)
145 else if( !bSymbolFound
&& m_bHasSymbols
&& bLineFound
)
147 else if( !bLineFound
&& !bSymbolFound
)
148 return m_bHasLines
&& m_bHasSymbols
;
155 rtl::Reference
< ChartType
> NetChartTypeTemplate::getChartTypeForIndex( sal_Int32
/*nChartTypeIndex*/ )
157 if( m_bHasFilledArea
)
158 return new FilledNetChartType();
160 return new NetChartType();
163 rtl::Reference
< ChartType
> NetChartTypeTemplate::getChartTypeForNewSeries2(
164 const std::vector
< rtl::Reference
< ChartType
> >& aFormerlyUsedChartTypes
)
166 rtl::Reference
< ChartType
> xResult( getChartTypeForIndex( 0 ) );
167 ChartTypeTemplate::copyPropertiesFromOldToNewCoordinateSystem( aFormerlyUsedChartTypes
, xResult
);
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */