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"
22 #include "PolarCoordinateSystem.hxx"
23 #include "DiagramHelper.hxx"
24 #include "servicenames_charttypes.hxx"
25 #include "DataSeriesHelper.hxx"
26 #include <com/sun/star/chart2/SymbolStyle.hpp>
27 #include <com/sun/star/chart2/Symbol.hpp>
28 #include <com/sun/star/drawing/LineStyle.hpp>
30 using namespace ::com::sun::star
;
32 using ::com::sun::star::uno::Reference
;
33 using ::com::sun::star::uno::Sequence
;
34 using ::com::sun::star::uno::Any
;
35 using ::osl::MutexGuard
;
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 SAL_CALL
NetChartTypeTemplate::applyStyle(
63 const Reference
< chart2::XDataSeries
>& xSeries
,
64 ::sal_Int32 nChartTypeIndex
,
65 ::sal_Int32 nSeriesIndex
,
66 ::sal_Int32 nSeriesCount
)
67 throw (uno::RuntimeException
, std::exception
)
69 ChartTypeTemplate::applyStyle( xSeries
, nChartTypeIndex
, nSeriesIndex
, nSeriesCount
);
73 Reference
< beans::XPropertySet
> xProp( xSeries
, uno::UNO_QUERY_THROW
);
75 DataSeriesHelper::switchSymbolsOnOrOff( xProp
, m_bHasSymbols
, nSeriesIndex
);
76 DataSeriesHelper::switchLinesOnOrOff( xProp
, m_bHasLines
);
77 DataSeriesHelper::makeLinesThickOrThin( xProp
, true );
79 catch( const uno::Exception
& ex
)
81 ASSERT_EXCEPTION( ex
);
85 // ____ XChartTypeTemplate ____
86 sal_Bool SAL_CALL
NetChartTypeTemplate::matchesTemplate(
87 const Reference
< chart2::XDiagram
>& xDiagram
,
88 sal_Bool bAdaptProperties
)
89 throw (uno::RuntimeException
, std::exception
)
91 bool bResult
= ChartTypeTemplate::matchesTemplate( xDiagram
, bAdaptProperties
);
93 uno::Reference
< beans::XPropertySet
> xChartTypeProp(
94 DiagramHelper::getChartTypeByIndex( xDiagram
, 0 ), uno::UNO_QUERY_THROW
);
99 if( m_bHasFilledArea
)
102 // check symbol-style
103 // for a template with symbols it is ok, if there is at least one series
104 // with symbols, otherwise an unknown template is too easy to achieve
105 bool bSymbolFound
= false;
106 bool bLineFound
= false;
108 ::std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVec(
109 DiagramHelper::getDataSeriesFromDiagram( xDiagram
));
111 for( ::std::vector
< Reference
< chart2::XDataSeries
> >::const_iterator aIt
=
112 aSeriesVec
.begin(); aIt
!= aSeriesVec
.end(); ++aIt
)
116 chart2::Symbol aSymbProp
;
117 drawing::LineStyle eLineStyle
;
118 Reference
< beans::XPropertySet
> xProp( *aIt
, uno::UNO_QUERY_THROW
);
120 bool bCurrentHasSymbol
= (xProp
->getPropertyValue( "Symbol") >>= aSymbProp
) &&
121 (aSymbProp
.Style
!= chart2::SymbolStyle_NONE
);
123 if( bCurrentHasSymbol
)
126 if( bCurrentHasSymbol
&& (!m_bHasSymbols
) )
132 bool bCurrentHasLine
= (xProp
->getPropertyValue( "LineStyle") >>= eLineStyle
) &&
133 ( eLineStyle
!= drawing::LineStyle_NONE
);
135 if( bCurrentHasLine
)
138 if( bCurrentHasLine
&& (!m_bHasLines
) )
144 catch( const uno::Exception
& ex
)
146 ASSERT_EXCEPTION( ex
);
152 if( !bLineFound
&& m_bHasLines
&& bSymbolFound
)
154 else if( !bSymbolFound
&& m_bHasSymbols
&& bLineFound
)
156 else if( !bLineFound
&& !bSymbolFound
)
157 return m_bHasLines
&& m_bHasSymbols
;
164 Reference
< chart2::XChartType
> NetChartTypeTemplate::getChartTypeForIndex( sal_Int32
/*nChartTypeIndex*/ )
166 Reference
< chart2::XChartType
> xResult
;
170 Reference
< lang::XMultiServiceFactory
> xFact(
171 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW
);
173 if( m_bHasFilledArea
)
174 xResult
.set( xFact
->createInstance(
175 CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET
), uno::UNO_QUERY_THROW
);
177 xResult
.set( xFact
->createInstance(
178 CHART2_SERVICE_NAME_CHARTTYPE_NET
), uno::UNO_QUERY_THROW
);
180 catch( const uno::Exception
& ex
)
182 ASSERT_EXCEPTION( ex
);
188 Reference
< chart2::XChartType
> SAL_CALL
NetChartTypeTemplate::getChartTypeForNewSeries(
189 const uno::Sequence
< Reference
< chart2::XChartType
> >& aFormerlyUsedChartTypes
)
190 throw (uno::RuntimeException
, std::exception
)
192 Reference
< chart2::XChartType
> xResult( getChartTypeForIndex( 0 ) );
193 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes
, xResult
);
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */