Line data Source code
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 : #ifndef INCLUDED_CHART2_SOURCE_MODEL_TEMPLATE_CHARTTYPETEMPLATE_HXX
20 : #define INCLUDED_CHART2_SOURCE_MODEL_TEMPLATE_CHARTTYPETEMPLATE_HXX
21 :
22 : #include <cppuhelper/implbase2.hxx>
23 : #include "ServiceMacros.hxx"
24 : #include "DataInterpreter.hxx"
25 : #include "StackMode.hxx"
26 : #include <com/sun/star/uno/XComponentContext.hpp>
27 : #include <com/sun/star/chart2/XChartTypeTemplate.hpp>
28 : #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
29 : #include <com/sun/star/chart2/XLegend.hpp>
30 : #include <com/sun/star/lang/XServiceName.hpp>
31 : #include <com/sun/star/chart2/XChartType.hpp>
32 : #include <com/sun/star/chart2/XDataSeries.hpp>
33 :
34 : #include <utility>
35 :
36 : namespace chart
37 : {
38 :
39 : /** For creating diagrams and modifying existing diagrams. A base class that
40 : implements XChartTypeTemplate and offers some tooling for classes that
41 : derive from this class.
42 :
43 : createDiagramByDataSource
44 :
45 : This does the following steps using some virtual helper-methods, that may be
46 : overloaded by derived classes:
47 :
48 : * creates an XDiagram via service-factory.
49 :
50 : * convert the given XDataSource to a sequence of XDataSeries using the
51 : method createDataSeries(). In this class the DataInterpreter helper class
52 : is used to create a standard interpretation (just y-values).
53 :
54 : * call applyDefaultStyle() for all XDataSeries in order to apply default
55 : styles. In this class the series get the system-wide default colors as
56 : "Color" property.
57 :
58 : * call applyStyle() for applying chart-type specific styles to all series.
59 : The default implementation is empty.
60 :
61 : * call createCoordinateSystems() and apply them to the diagram. As
62 : default one cartesian system with Scales using a linear Scaling is
63 : created.
64 :
65 : * createChartTypes() is called in order to define the structure of the
66 : diagram. For details see comment of this function. As default this
67 : method creates a tree where all series appear in one branch with the chart
68 : type determined by getChartTypeForNewSeries(). The stacking is determined
69 : via the method getStackMode().
70 :
71 : * create an XLegend via the global service factory, set it at the diagram.
72 : */
73 : class ChartTypeTemplate : public ::cppu::WeakImplHelper2<
74 : ::com::sun::star::chart2::XChartTypeTemplate,
75 : ::com::sun::star::lang::XServiceName >
76 : {
77 : public:
78 : explicit ChartTypeTemplate(
79 : ::com::sun::star::uno::Reference<
80 : ::com::sun::star::uno::XComponentContext > const & xContext,
81 : const OUString & rServiceName );
82 : virtual ~ChartTypeTemplate();
83 :
84 : /// establish methods for factory instatiation
85 : // APPHELPER_SERVICE_FACTORY_HELPER( ChartTypeTemplate )
86 :
87 : protected:
88 : // ____ XChartTypeTemplate ____
89 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram > SAL_CALL createDiagramByDataSource(
90 : const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xDataSource,
91 : const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
92 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
93 : /// denotes if the chart needs categories at the first scale
94 : virtual sal_Bool SAL_CALL supportsCategories()
95 : throw (css::uno::RuntimeException, ::std::exception) SAL_OVERRIDE;
96 :
97 : virtual void SAL_CALL changeDiagram(
98 : const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram )
99 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
100 : virtual void SAL_CALL changeDiagramData(
101 : const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram,
102 : const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xDataSource,
103 : const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
104 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
105 : virtual sal_Bool SAL_CALL matchesTemplate(
106 : const ::com::sun::star::uno::Reference<
107 : ::com::sun::star::chart2::XDiagram >& xDiagram,
108 : sal_Bool bAdaptProperties )
109 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
110 : // still abstract: getChartTypeForNewSeries()
111 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataInterpreter > SAL_CALL getDataInterpreter()
112 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
113 : virtual void SAL_CALL applyStyle(
114 : const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries,
115 : ::sal_Int32 nChartTypeIndex,
116 : ::sal_Int32 nSeriesIndex,
117 : ::sal_Int32 nSeriesCount )
118 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
119 : virtual void SAL_CALL resetStyles(
120 : const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram )
121 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
122 :
123 : virtual void SAL_CALL applyStyles(
124 : const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram )
125 : throw (::com::sun::star::uno::RuntimeException);
126 :
127 : // ____ XServiceName ____
128 : virtual OUString SAL_CALL getServiceName()
129 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
130 :
131 : // Methods to overload for automatic creation
132 :
133 : /// returns 2 by default. Supported are 2 and 3
134 : virtual sal_Int32 getDimension() const;
135 :
136 : /** returns StackMode_NONE by default. This is a global flag used for all
137 : series of a specific chart type. If percent stacking is supported, the
138 : percent stacking mode is retrieved from the first chart type (index 0)
139 :
140 : @param nChartTypeIndex denotes the index of the charttype in means
141 : defined by the template creation order, i.e., 0 means the first
142 : chart type that a template creates.
143 : */
144 : virtual StackMode getStackMode( sal_Int32 nChartTypeIndex ) const;
145 :
146 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >
147 : getChartTypeForIndex( sal_Int32 nChartTypeIndex ) = 0;
148 :
149 : virtual bool isSwapXAndY() const;
150 :
151 : // Methods for creating the diagram piecewise
152 :
153 : /** Allows derived classes to manipulate the diagramas whole, like changing
154 : the wall color. The default implementation is empty. It is called by
155 : FillDiagram which is called by createDiagramByDataSource and
156 : changeDiagram
157 : */
158 : virtual void adaptDiagram(
159 : const ::com::sun::star::uno::Reference<
160 : ::com::sun::star::chart2::XDiagram > & xDiagram );
161 :
162 : /** Creates a 2d or 3d cartesian coordinate system with mathematically
163 : oriented, linear scales with auto-min/max. If the given
164 : CoordinateSystemContainer is not empty, those coordinate system should
165 : be reused.
166 :
167 : <p>The dimension depends on the value returned by getDimension().</p>
168 : */
169 : virtual void createCoordinateSystems(
170 : const ::com::sun::star::uno::Reference<
171 : ::com::sun::star::chart2::XCoordinateSystemContainer > & xOutCooSysCnt );
172 :
173 : /** Sets categories at the scales of dimension 0 and the percent stacking at
174 : the scales of dimension 1 of all given coordinate systems.
175 :
176 : <p>Called by FillDiagram.</p>
177 : */
178 : virtual void adaptScales(
179 : const ::com::sun::star::uno::Sequence<
180 : ::com::sun::star::uno::Reference<
181 : ::com::sun::star::chart2::XCoordinateSystem > > & aCooSysSeq,
182 : const ::com::sun::star::uno::Reference<
183 : ::com::sun::star::chart2::data::XLabeledDataSequence > & xCategories );
184 :
185 : /** create a data series tree, that fits the requirements of the chart type.
186 :
187 : <p>As default, this creates a tree with the following structure:</p>
188 :
189 : <pre>
190 : root
191 : |
192 : +-- chart type (determined by getChartTypeForNewSeries())
193 : |
194 : +-- category (DiscreteStackableScaleGroup using scale 0)
195 : |
196 : +-- values (ContinuousStackableScaleGroup using scale 1)
197 : |
198 : +-- series 0
199 : |
200 : +-- series 1
201 : |
202 : ...
203 : |
204 : +.. series n-1
205 : </pre>
206 :
207 : <p>If there are less than two scales available the returned tree is
208 : empty.</p>
209 : */
210 : virtual void createChartTypes(
211 : const ::com::sun::star::uno::Sequence<
212 : ::com::sun::star::uno::Sequence<
213 : ::com::sun::star::uno::Reference<
214 : ::com::sun::star::chart2::XDataSeries > > > & aSeriesSeq,
215 : const ::com::sun::star::uno::Sequence<
216 : ::com::sun::star::uno::Reference<
217 : ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys,
218 : const ::com::sun::star::uno::Sequence<
219 : ::com::sun::star::uno::Reference<
220 : ::com::sun::star::chart2::XChartType > > & aOldChartTypesSeq
221 : );
222 :
223 : /** create axes and add them to the given container. If there are already
224 : compatible axes in the container these should be maintained.
225 :
226 : <p>As default, this method creates as many axes as there are dimensions
227 : in the given first coordinate system. Each of the axis
228 : represents one of the dimensions of the coordinate systems. If there are series
229 : requesting asecondary axes a secondary y axes is added</p>
230 : */
231 : virtual void createAxes(
232 : const ::com::sun::star::uno::Sequence<
233 : ::com::sun::star::uno::Reference<
234 : ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys );
235 :
236 : /** Give the number of requested axis per dimension here. Default is one
237 : axis for each dimension
238 : */
239 : virtual sal_Int32 getAxisCountByDimension( sal_Int32 nDimension );
240 :
241 : /** adapt properties of exsisting axes and remove superfluous axes
242 : */
243 : virtual void adaptAxes(
244 : const ::com::sun::star::uno::Sequence<
245 : ::com::sun::star::uno::Reference<
246 : ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys );
247 :
248 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
249 157346 : GetComponentContext() const { return m_xContext;}
250 :
251 : static void copyPropertiesFromOldToNewCoordianteSystem(
252 : const ::com::sun::star::uno::Sequence<
253 : ::com::sun::star::uno::Reference<
254 : ::com::sun::star::chart2::XChartType > > & rOldChartTypesSeq,
255 : const ::com::sun::star::uno::Reference<
256 : ::com::sun::star::chart2::XChartType > & xNewChartType );
257 :
258 : protected:
259 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
260 : m_xContext;
261 : mutable ::com::sun::star::uno::Reference<
262 : ::com::sun::star::chart2::XDataInterpreter > m_xDataInterpreter;
263 :
264 : private:
265 : const OUString m_aServiceName;
266 :
267 : private:
268 : /** modifies the given diagram
269 : */
270 : void FillDiagram( const ::com::sun::star::uno::Reference<
271 : ::com::sun::star::chart2::XDiagram > & xDiagram,
272 : const ::com::sun::star::uno::Sequence<
273 : ::com::sun::star::uno::Sequence<
274 : ::com::sun::star::uno::Reference<
275 : ::com::sun::star::chart2::XDataSeries > > > & aSeriesSeq,
276 : ::com::sun::star::uno::Reference<
277 : ::com::sun::star::chart2::data::XLabeledDataSequence > xCategories,
278 : const ::com::sun::star::uno::Sequence<
279 : ::com::sun::star::uno::Reference<
280 : ::com::sun::star::chart2::XChartType > > & aOldChartTypesSeq,
281 : bool bCreate );
282 : };
283 :
284 : } // namespace chart
285 :
286 : // INCLUDED_CHART2_SOURCE_MODEL_TEMPLATE_CHARTTYPETEMPLATE_HXX
287 : #endif
288 :
289 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|