unoxml: port testXNamedNodeMap_AttributesMap from java to c++
[libreoffice.git] / chart2 / source / inc / ChartTypeTemplate.hxx
blobffd7cca265991007501dc4c97cce9f8e7d49a922
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 .
19 #pragma once
21 #include <cppuhelper/implbase.hxx>
22 #include "DataInterpreter.hxx"
23 #include "StackMode.hxx"
24 #include <com/sun/star/chart2/XChartTypeTemplate.hpp>
25 #include <com/sun/star/lang/XServiceName.hpp>
26 #include "charttoolsdllapi.hxx"
27 #include <rtl/ref.hxx>
28 #include <vector>
30 namespace com::sun::star::beans { struct PropertyValue; }
31 namespace com::sun::star::chart2 { class XChartType; }
32 namespace com::sun::star::chart2 { class XCoordinateSystem; }
33 namespace com::sun::star::chart2 { class XCoordinateSystemContainer; }
34 namespace com::sun::star::chart2 { class XDataSeries; }
35 namespace com::sun::star::chart2 { class XDiagram; }
36 namespace com::sun::star::chart2::data { class XDataSource; }
37 namespace com::sun::star::chart2::data { class XLabeledDataSequence; }
38 namespace com::sun::star::uno { class XComponentContext; }
40 namespace chart
42 class BaseCoordinateSystem;
43 class ChartType;
44 class DataSeries;
45 class Diagram;
46 class LabeledDataSequence;
48 /** For creating diagrams and modifying existing diagrams. A base class that
49 implements XChartTypeTemplate and offers some tooling for classes that
50 derive from this class.
52 createDiagramByDataSource
54 This does the following steps using some virtual helper-methods, that may be
55 overridden by derived classes:
57 * creates an XDiagram via service-factory.
59 * convert the given XDataSource to a sequence of XDataSeries using the
60 method createDataSeries(). In this class the DataInterpreter helper class
61 is used to create a standard interpretation (just y-values).
63 * call applyDefaultStyle() for all XDataSeries in order to apply default
64 styles. In this class the series get the system-wide default colors as
65 "Color" property.
67 * call applyStyle() for applying chart-type specific styles to all series.
68 The default implementation is empty.
70 * call createCoordinateSystems() and apply them to the diagram. As
71 default one cartesian system with Scales using a linear Scaling is
72 created.
74 * createChartTypes() is called in order to define the structure of the
75 diagram. For details see comment of this function. As default this
76 method creates a tree where all series appear in one branch with the chart
77 type determined by getChartTypeForNewSeries(). The stacking is determined
78 via the method getStackMode().
80 * create an XLegend via the global service factory, set it at the diagram.
82 class UNLESS_MERGELIBS(OOO_DLLPUBLIC_CHARTTOOLS) ChartTypeTemplate : public ::cppu::WeakImplHelper<
83 css::chart2::XChartTypeTemplate,
84 css::lang::XServiceName >
86 public:
87 explicit ChartTypeTemplate( css::uno::Reference< css::uno::XComponentContext > const & xContext,
88 OUString aServiceName );
89 virtual ~ChartTypeTemplate() override;
91 rtl::Reference< ::chart::Diagram > createDiagramByDataSource2(
92 const css::uno::Reference< css::chart2::data::XDataSource >& xDataSource,
93 const css::uno::Sequence< css::beans::PropertyValue >& aArguments );
95 // ____ XChartTypeTemplate ____
96 virtual css::uno::Reference< css::chart2::XDiagram > SAL_CALL createDiagramByDataSource(
97 const css::uno::Reference< css::chart2::data::XDataSource >& xDataSource,
98 const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override final;
99 /// denotes if the chart needs categories at the first scale
100 virtual sal_Bool SAL_CALL supportsCategories() override;
101 virtual void SAL_CALL changeDiagram(
102 const css::uno::Reference< css::chart2::XDiagram >& xDiagram ) override final;
103 virtual void SAL_CALL changeDiagramData(
104 const css::uno::Reference< css::chart2::XDiagram >& xDiagram,
105 const css::uno::Reference< css::chart2::data::XDataSource >& xDataSource,
106 const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override final;
107 virtual sal_Bool SAL_CALL matchesTemplate(
108 const css::uno::Reference< css::chart2::XDiagram >& xDiagram,
109 sal_Bool bAdaptProperties ) override final;
110 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getDataInterpreter() override final;
111 virtual css::uno::Reference< ::css::chart2::XChartType > SAL_CALL getChartTypeForNewSeries(
112 const css::uno::Sequence< css::uno::Reference< css::chart2::XChartType > >& aFormerlyUsedChartTypes ) override final;
113 virtual void SAL_CALL applyStyle(
114 const css::uno::Reference< css::chart2::XDataSeries >& xSeries,
115 ::sal_Int32 nChartTypeIndex,
116 ::sal_Int32 nSeriesIndex,
117 ::sal_Int32 nSeriesCount ) override final;
118 virtual void SAL_CALL resetStyles(
119 const css::uno::Reference< css::chart2::XDiagram >& xDiagram ) override final;
121 void changeDiagram(
122 const rtl::Reference< ::chart::Diagram >& xDiagram );
123 void changeDiagramData(
124 const rtl::Reference< ::chart::Diagram >& xDiagram,
125 const css::uno::Reference< css::chart2::data::XDataSource >& xDataSource,
126 const css::uno::Sequence< css::beans::PropertyValue >& aArguments );
127 virtual bool matchesTemplate2(
128 const rtl::Reference< ::chart::Diagram >& xDiagram,
129 bool bAdaptProperties );
130 virtual rtl::Reference< ::chart::ChartType >
131 getChartTypeForNewSeries2( const std::vector<
132 rtl::Reference< ::chart::ChartType > >& aFormerlyUsedChartTypes ) = 0;
133 virtual rtl::Reference< ::chart::DataInterpreter > getDataInterpreter2();
134 virtual void applyStyle2(
135 const rtl::Reference< ::chart::DataSeries >& xSeries,
136 ::sal_Int32 nChartTypeIndex,
137 ::sal_Int32 nSeriesIndex,
138 ::sal_Int32 nSeriesCount );
139 virtual void resetStyles2(
140 const rtl::Reference< ::chart::Diagram >& xDiagram );
142 /// @throws css::uno::RuntimeException
143 void applyStyles(
144 const rtl::Reference< ::chart::Diagram >& xDiagram );
146 // ____ XServiceName ____
147 virtual OUString SAL_CALL getServiceName() override;
149 // Methods to override for automatic creation
151 /// returns 2 by default. Supported are 2 and 3
152 virtual sal_Int32 getDimension() const;
154 /** returns StackMode::NONE by default. This is a global flag used for all
155 series of a specific chart type. If percent stacking is supported, the
156 percent stacking mode is retrieved from the first chart type (index 0)
158 @param nChartTypeIndex denotes the index of the charttype in means
159 defined by the template creation order, i.e., 0 means the first
160 chart type that a template creates.
162 virtual StackMode getStackMode( sal_Int32 nChartTypeIndex ) const;
164 virtual rtl::Reference< ::chart::ChartType >
165 getChartTypeForIndex( sal_Int32 nChartTypeIndex ) = 0;
167 virtual bool isSwapXAndY() const;
169 // Methods for creating the diagram piecewise
171 /** Allows derived classes to manipulate the diagrams whole, like changing
172 the wall color. The default implementation is empty. It is called by
173 FillDiagram which is called by createDiagramByDataSource and
174 changeDiagram
176 virtual void adaptDiagram(
177 const rtl::Reference< ::chart::Diagram > & xDiagram );
179 /** Creates a 2d or 3d cartesian coordinate system with mathematically
180 oriented, linear scales with auto-min/max. If the given
181 CoordinateSystemContainer is not empty, those coordinate system should
182 be reused.
184 <p>The dimension depends on the value returned by getDimension().</p>
186 virtual void createCoordinateSystems(
187 const rtl::Reference< ::chart::Diagram > & xDiagram );
189 /** Sets categories at the scales of dimension 0 and the percent stacking at
190 the scales of dimension 1 of all given coordinate systems.
192 <p>Called by FillDiagram.</p>
194 virtual void adaptScales(
195 const std::vector< rtl::Reference< ::chart::BaseCoordinateSystem > > & aCooSysSeq,
196 const css::uno::Reference< css::chart2::data::XLabeledDataSequence > & xCategories );
198 /** create a data series tree, that fits the requirements of the chart type.
200 <p>As default, this creates a tree with the following structure:</p>
202 <pre>
203 root
205 +-- chart type (determined by getChartTypeForNewSeries())
207 +-- category (DiscreteStackableScaleGroup using scale 0)
209 +-- values (ContinuousStackableScaleGroup using scale 1)
211 +-- series 0
213 +-- series 1
217 +.. series n-1
218 </pre>
220 <p>If there are less than two scales available the returned tree is
221 empty.</p>
223 virtual void createChartTypes(
224 const std::vector<
225 std::vector<
226 rtl::Reference<
227 ::chart::DataSeries > > > & aSeriesSeq,
228 const std::vector<
229 rtl::Reference<
230 ::chart::BaseCoordinateSystem > > & rCoordSys,
231 const std::vector< rtl::Reference< ChartType > > & aOldChartTypesSeq
234 /** create axes and add them to the given container. If there are already
235 compatible axes in the container these should be maintained.
237 <p>As default, this method creates as many axes as there are dimensions
238 in the given first coordinate system. Each of the axis
239 represents one of the dimensions of the coordinate systems. If there are series
240 requesting a secondary axes a secondary y axes is added</p>
242 void createAxes(
243 const std::vector< rtl::Reference< ::chart::BaseCoordinateSystem > > & rCoordSys );
245 /** Give the number of requested axis per dimension here. Default is one
246 axis for each dimension
248 virtual sal_Int32 getAxisCountByDimension( sal_Int32 nDimension );
250 /** adapt properties of existing axes and remove superfluous axes
252 virtual void adaptAxes(
253 const std::vector< rtl::Reference< ::chart::BaseCoordinateSystem > > & rCoordSys );
255 const css::uno::Reference< css::uno::XComponentContext >&
256 GetComponentContext() const { return m_xContext;}
258 static void copyPropertiesFromOldToNewCoordinateSystem(
259 const std::vector< rtl::Reference< ChartType > > & rOldChartTypesSeq,
260 const rtl::Reference< ChartType > & xNewChartType );
262 protected:
263 css::uno::Reference< css::uno::XComponentContext > m_xContext;
264 mutable rtl::Reference< ::chart::DataInterpreter > m_xDataInterpreter;
266 private:
267 const OUString m_aServiceName;
269 private:
270 /** modifies the given diagram
272 void FillDiagram( const rtl::Reference< ::chart::Diagram >& xDiagram,
273 const std::vector<
274 std::vector<
275 rtl::Reference<
276 ::chart::DataSeries > > > & aSeriesSeq,
277 const css::uno::Reference< css::chart2::data::XLabeledDataSequence >& xCategories,
278 const std::vector< rtl::Reference< ChartType > > & aOldChartTypesSeq);
281 } // namespace chart
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */