LibreOffice Module chart2 (master) 1
NetChartTypeTemplate.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
22#include "NetChartType.hxx"
23#include <Diagram.hxx>
24#include <DiagramHelper.hxx>
25#include <DataSeries.hxx>
26#include <DataSeriesHelper.hxx>
27#include <ChartType.hxx>
28#include <com/sun/star/chart2/SymbolStyle.hpp>
29#include <com/sun/star/chart2/Symbol.hpp>
30#include <com/sun/star/drawing/LineStyle.hpp>
31#include <com/sun/star/uno/XComponentContext.hpp>
33
34using namespace ::com::sun::star;
35
36using ::com::sun::star::uno::Reference;
37
38namespace chart
39{
40
43 const OUString & rServiceName,
44 StackMode eStackMode,
45 bool bSymbols,
46 bool bHasLines ,
47 bool bHasFilledArea ) :
48 ChartTypeTemplate( xContext, rServiceName ),
49 m_eStackMode( eStackMode ),
50 m_bHasSymbols( bSymbols ),
51 m_bHasLines( bHasLines ),
52 m_bHasFilledArea( bHasFilledArea )
53{}
54
56{}
57
58StackMode NetChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
59{
60 return m_eStackMode;
61}
62
64 const rtl::Reference< DataSeries >& xSeries,
65 ::sal_Int32 nChartTypeIndex,
66 ::sal_Int32 nSeriesIndex,
67 ::sal_Int32 nSeriesCount )
68{
69 ChartTypeTemplate::applyStyle2( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
70
71 try
72 {
76 }
77 catch( const uno::Exception & )
78 {
80 }
81}
82
83// ____ ChartTypeTemplate ____
86 bool bAdaptProperties )
87{
88 bool bResult = ChartTypeTemplate::matchesTemplate2( xDiagram, bAdaptProperties );
89
90 if( bResult )
91 {
92 //filled net chart?:
94 return true;
95
96 // check symbol-style
97 // for a template with symbols it is ok, if there is at least one series
98 // with symbols, otherwise an unknown template is too easy to achieve
99 bool bSymbolFound = false;
100 bool bLineFound = false;
101
102 std::vector< rtl::Reference< DataSeries > > aSeriesVec =
103 xDiagram->getDataSeries();
104
105 for (auto const& series : aSeriesVec)
106 {
107 try
108 {
109 chart2::Symbol aSymbProp;
110 drawing::LineStyle eLineStyle;
111
112 bool bCurrentHasSymbol = (series->getPropertyValue( "Symbol") >>= aSymbProp) &&
113 (aSymbProp.Style != chart2::SymbolStyle_NONE);
114
115 if( bCurrentHasSymbol )
116 bSymbolFound = true;
117
118 if( bCurrentHasSymbol && (!m_bHasSymbols) )
119 {
120 bResult = false;
121 break;
122 }
123
124 bool bCurrentHasLine = (series->getPropertyValue( "LineStyle") >>= eLineStyle) &&
125 ( eLineStyle != drawing::LineStyle_NONE );
126
127 if( bCurrentHasLine )
128 bLineFound = true;
129
130 if( bCurrentHasLine && (!m_bHasLines) )
131 {
132 bResult = false;
133 break;
134 }
135 }
136 catch( const uno::Exception & )
137 {
138 DBG_UNHANDLED_EXCEPTION("chart2");
139 }
140 }
141
142 if(bResult)
143 {
144 if( !bLineFound && m_bHasLines && bSymbolFound )
145 bResult = false;
146 else if( !bSymbolFound && m_bHasSymbols && bLineFound )
147 bResult = false;
148 else if( !bLineFound && !bSymbolFound )
149 return m_bHasLines && m_bHasSymbols;
150 }
151 }
152
153 return bResult;
154}
155
157{
158 if( m_bHasFilledArea )
159 return new FilledNetChartType();
160 else
161 return new NetChartType();
162}
163
165 const std::vector< rtl::Reference< ChartType > >& aFormerlyUsedChartTypes )
166{
168 ChartTypeTemplate::copyPropertiesFromOldToNewCoordinateSystem( aFormerlyUsedChartTypes, xResult );
169 return xResult;
170}
171
172} // namespace chart
173
174/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StackMode m_eStackMode
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 applyStyle2(const rtl::Reference< ::chart::DataSeries > &xSeries, ::sal_Int32 nChartTypeGroupIndex, ::sal_Int32 nSeriesIndex, ::sal_Int32 nSeriesCount) override
virtual bool matchesTemplate2(const rtl::Reference< ::chart::Diagram > &xDiagram, bool bAdaptProperties) override
virtual rtl::Reference< ::chart::ChartType > getChartTypeForIndex(sal_Int32 nChartTypeIndex) override
NetChartTypeTemplate(css::uno::Reference< css::uno::XComponentContext > const &xContext, const OUString &rServiceName, StackMode eStackMode, bool bSymbols, bool bHasLines=true, bool bHasFilledArea=false)
virtual StackMode getStackMode(sal_Int32 nChartTypeIndex) const override
returns StackMode::NONE by default.
virtual ~NetChartTypeTemplate() override
virtual rtl::Reference< ::chart::ChartType > getChartTypeForNewSeries2(const std::vector< rtl::Reference< ::chart::ChartType > > &aFormerlyUsedChartTypes) override
#define DBG_UNHANDLED_EXCEPTION(...)
OOO_DLLPUBLIC_CHARTTOOLS void switchLinesOnOrOff(const rtl::Reference< ::chart::DataSeries > &xSeries, bool bLinesOn)
OOO_DLLPUBLIC_CHARTTOOLS void makeLinesThickOrThin(const rtl::Reference< ::chart::DataSeries > &xSeries, bool bThick)
OOO_DLLPUBLIC_CHARTTOOLS void switchSymbolsOnOrOff(const rtl::Reference< ::chart::DataSeries > &xSeries, bool bSymbolsOn, sal_Int32 nSeriesIndex)