tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / model / template / NetChartTypeTemplate.cxx
blob3be8633c329fb8874450165e09151814e8303344
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
37 namespace chart
40 NetChartTypeTemplate::NetChartTypeTemplate(
41 Reference< uno::XComponentContext > const & xContext,
42 const OUString & rServiceName,
43 StackMode eStackMode,
44 bool bSymbols,
45 bool bHasLines ,
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
59 return m_eStackMode;
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 );
70 try
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 );
89 if( bResult )
91 //filled net chart?:
92 if( m_bHasFilledArea )
93 return true;
95 // check symbol-style
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 )
115 bSymbolFound = true;
117 if( bCurrentHasSymbol && (!m_bHasSymbols) )
119 bResult = false;
120 break;
123 bool bCurrentHasLine = (series->getPropertyValue( u"LineStyle"_ustr) >>= eLineStyle) &&
124 ( eLineStyle != drawing::LineStyle_NONE );
126 if( bCurrentHasLine )
127 bLineFound = true;
129 if( bCurrentHasLine && (!m_bHasLines) )
131 bResult = false;
132 break;
135 catch( const uno::Exception & )
137 DBG_UNHANDLED_EXCEPTION("chart2");
141 if(bResult)
143 if( !bLineFound && m_bHasLines && bSymbolFound )
144 bResult = false;
145 else if( !bSymbolFound && m_bHasSymbols && bLineFound )
146 bResult = false;
147 else if( !bLineFound && !bSymbolFound )
148 return m_bHasLines && m_bHasSymbols;
152 return bResult;
155 rtl::Reference< ChartType > NetChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
157 if( m_bHasFilledArea )
158 return new FilledNetChartType();
159 else
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 );
168 return xResult;
171 } // namespace chart
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */