LibreOffice Module chart2 (master) 1
Chart2ModelContact.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
21#include <ChartModelHelper.hxx>
22#include <Legend.hxx>
23#include <LegendHelper.hxx>
24#include <CommonConverters.hxx>
25#include <servicenames.hxx>
26#include <ObjectIdentifier.hxx>
29#include <Axis.hxx>
30#include <AxisHelper.hxx>
31#include <ChartView.hxx>
32#include <DiagramHelper.hxx>
34
35#include <ChartModel.hxx>
36
37#include <com/sun/star/chart2/XDataSeries.hpp>
39
40using namespace ::com::sun::star;
41using namespace ::com::sun::star::chart2;
42
43using ::com::sun::star::uno::Reference;
44
45namespace chart::wrapper
46{
47
49 const Reference< uno::XComponentContext > & xContext ) :
50 m_xContext( xContext ),
51 m_xChartModel( nullptr )
52{
53}
54
56{
57 clear();
58}
59
60void Chart2ModelContact::setDocumentModel( ChartModel* pChartModel )
61{
62 clear();
63 m_xChartModel = pChartModel;
64 if( !pChartModel )
65 return;
66
67 uno::Reference< container::XNameContainer > xDashTable( pChartModel->createInstance("com.sun.star.drawing.DashTable"), uno::UNO_QUERY );
68 uno::Reference< container::XNameContainer > xGradientTable( pChartModel->createInstance("com.sun.star.drawing.GradientTable"), uno::UNO_QUERY );
69 uno::Reference< container::XNameContainer > xHatchTable( pChartModel->createInstance("com.sun.star.drawing.HatchTable"), uno::UNO_QUERY );
70 uno::Reference< container::XNameContainer > xBitmapTable( pChartModel->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY );
71 uno::Reference< container::XNameContainer > xTransparencyGradientTable( pChartModel->createInstance("com.sun.star.drawing.TransparencyGradientTable"), uno::UNO_QUERY );
72 m_aTableMap["LineDashName"] = xDashTable;
73 m_aTableMap["FillGradientName"] = xGradientTable;
74 m_aTableMap["FillHatchName"] = xHatchTable;
75 m_aTableMap["FillBitmapName"] = xBitmapTable;
76 m_aTableMap["FillTransparenceGradientName"] = xTransparencyGradientTable;
77}
78
80{
81 m_xChartModel.clear();
82 m_xChartView.clear();
83}
84
86{
87 return m_xChartModel;
88}
89
91{
92 try
93 {
95 if( xChartModel)
96 return xChartModel->getFirstChartDiagram();
97 }
98 catch( const uno::Exception & )
99 {
100 DBG_UNHANDLED_EXCEPTION("chart2");
101 }
102 return nullptr;
103}
104
106{
107 if(!m_xChartView.is())
108 {
109 // get the chart view
111 if( xChartModel )
112 {
113 auto xInstance = xChartModel->createInstance( CHART_VIEW_SERVICE_NAME );
114 auto pChartView = dynamic_cast<ChartView*>(xInstance.get());
115 assert(!xInstance || pChartView);
116 m_xChartView = pChartView;
117 }
118 }
119 return m_xChartView;
120}
121
123{
124 getChartView();
125
126 //obtain the ExplicitValueProvider from the chart view
127 return m_xChartView.get();
128}
129
131{
133 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
134 if( pProvider )
135 {
136 xResult = pProvider->getDrawModelWrapper()->getMainDrawPage();
137 }
138 return xResult;
139}
140
142 const rtl::Reference< Axis > & xAxis,
143 ExplicitScaleData & rOutExplicitScale,
144 ExplicitIncrementData & rOutExplicitIncrement )
145{
146 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
147 if( pProvider )
148 {
149 pProvider->getExplicitValuesForAxis(
150 xAxis, rOutExplicitScale, rOutExplicitIncrement );
151 }
152}
153
156{
159 xAxis, m_xChartModel.get()->getFirstChartDiagram() ) );
160
161 return ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( xAxis, xCooSys
162 , m_xChartModel.get() );
163}
164
166 const Reference< chart2::XDataSeries >& xSeries )
167{
168 return ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel(
169 uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ));
170}
171
173{
175}
176
177awt::Rectangle Chart2ModelContact::SubstractAxisTitleSizes( const awt::Rectangle& rPositionRect )
178{
179 awt::Rectangle aRect = ExplicitValueProvider::AddSubtractAxisTitleSizes(
180 *m_xChartModel.get(), getChartView().get(), rPositionRect, true );
181 return aRect;
182}
183
185{
186 awt::Rectangle aRect( GetDiagramRectangleIncludingAxes() );
187
188 //add axis title sizes to the diagram size
189 aRect = ExplicitValueProvider::AddSubtractAxisTitleSizes(
190 *m_xChartModel.get(), getChartView().get(), aRect, false );
191
192 return aRect;
193}
194
196{
197 awt::Rectangle aRect(0,0,0,0);
198 rtl::Reference< Diagram > xDiagram = m_xChartModel.get()->getFirstChartDiagram();
199
200 if( xDiagram && xDiagram->getDiagramPositioningMode() == DiagramPositioningMode::Including )
202 else
203 {
204 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
205 if( pProvider )
206 aRect = pProvider->getRectangleOfObject("PlotAreaIncludingAxes");
207 }
208 return aRect;
209}
210
212{
213 awt::Rectangle aRect(0,0,0,0);
214 rtl::Reference< Diagram > xDiagram = m_xChartModel.get()->getFirstChartDiagram();
215
216 if( xDiagram && xDiagram->getDiagramPositioningMode() == DiagramPositioningMode::Excluding )
218 else
219 {
220 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
221 if( pProvider )
222 aRect = pProvider->getDiagramRectangleExcludingAxes();
223 }
224 return aRect;
225}
226
228{
229 awt::Size aSize;
230 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
231 if( pProvider )
232 {
235 aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
236 }
237 return aSize;
238}
239
241{
242 awt::Point aPoint;
243 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
244 if( pProvider )
245 {
248 aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
249 }
250 return aPoint;
251}
252
254{
255 awt::Size aSize;
256 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
257 if( pProvider && xTitle.is() )
258 {
260 aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
261 }
262 return aSize;
263}
264
266{
267 awt::Point aPoint;
268 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
269 if( pProvider && xTitle.is() )
270 {
272 aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
273 }
274 return aPoint;
275}
276
278{
279 awt::Size aSize;
280 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
281 if( pProvider && xAxis.is() )
282 {
284 aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
285 }
286 return aSize;
287}
288
290{
291 awt::Point aPoint;
292 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
293 if( pProvider && xAxis.is() )
294 {
296 aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
297 }
298 return aPoint;
299}
300
301} // namespace chart::wrapper
302
303/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< uno::XComponentContext > m_xContext
static rtl::Reference< ::chart::BaseCoordinateSystem > getCoordinateSystemOfAxis(const rtl::Reference< ::chart::Axis > &xAxis, const rtl::Reference< ::chart::Diagram > &xDiagram)
Definition: AxisHelper.cxx:982
static css::awt::Size getPageSize(const rtl::Reference<::chart::ChartModel > &xModel)
The ChartView is responsible to manage the generation of Drawing Objects for visualization on a given...
Definition: ChartView.hxx:98
static css::awt::Rectangle getDiagramRectangleFromModel(const rtl::Reference<::chart::ChartModel > &xChartModel)
static rtl::Reference< ::chart::Legend > getLegend(ChartModel &rModel, const css::uno::Reference< css::uno::XComponentContext > &xContext=nullptr, bool bCreate=false)
static OUString createClassifiedIdentifierForObject(const css::uno::Reference< css::uno::XInterface > &xObject, const rtl::Reference<::chart::ChartModel > &xChartModel)
void setDocumentModel(ChartModel *pChartModel)
rtl::Reference< ChartModel > getDocumentModel() const
rtl::Reference< ChartView > const & getChartView() const
css::awt::Point GetAxisPosition(const css::uno::Reference< css::chart2::XAxis > &xAxis) const
Returns the position of the object in logic coordinates.
css::awt::Rectangle GetDiagramRectangleExcludingAxes() const
Returns the position and size of the diagram in logic coordinates (100th mm) excluding the space used...
Chart2ModelContact(const css::uno::Reference< css::uno::XComponentContext > &xContext)
css::awt::Size GetAxisSize(const css::uno::Reference< css::chart2::XAxis > &xAxis) const
Returns the size of the object in logic coordinates.
css::awt::Point GetTitlePosition(const css::uno::Reference< css::chart2::XTitle > &xTitle) const
Returns the position of the object in logic coordinates.
css::awt::Rectangle SubstractAxisTitleSizes(const css::awt::Rectangle &rPositionRect)
calculates the current axes title sizes and subtract that space them from the given rectangle
css::awt::Point GetLegendPosition() const
Returns the position of the object in logic coordinates.
sal_Int32 getExplicitNumberFormatKeyForAxis(const rtl::Reference< ::chart::Axis > &xAxis)
css::awt::Rectangle GetDiagramRectangleIncludingAxes() const
Returns the position and size of the diagram in logic coordinates (100th mm) including the space used...
std::map< OUString, css::uno::Reference< css::container::XNameContainer > > m_aTableMap
css::awt::Rectangle GetDiagramRectangleIncludingTitle() const
Returns the position and size of the diagram in logic coordinates (100th mm) including the space used...
rtl::Reference< ChartView > m_xChartView
static sal_Int32 getExplicitNumberFormatKeyForSeries(const css::uno::Reference< css::chart2::XDataSeries > &xSeries)
ExplicitValueProvider * getExplicitValueProvider() const
rtl::Reference< SvxDrawPage > getDrawPage() const
css::awt::Size GetPageSize() const
Returns the size of the page in logic coordinates.
rtl::Reference< ::chart::Diagram > getDiagram() const
css::awt::Size GetTitleSize(const css::uno::Reference< css::chart2::XTitle > &xTitle) const
Returns the size of the object in logic coordinates.
unotools::WeakReference< ChartModel > m_xChartModel
css::awt::Size GetLegendSize() const
Returns the size of the object in logic coordinates.
void getExplicitValuesForAxis(const rtl::Reference< ::chart::Axis > &xAxis, ExplicitScaleData &rOutExplicitScale, ExplicitIncrementData &rOutExplicitIncrement)
get the current values calculated for an axis in the current view in case properties are 'auto'.
rtl::Reference< interface_type > SAL_CALL get() const
#define DBG_UNHANDLED_EXCEPTION(...)
OOO_DLLPUBLIC_CHARTTOOLS css::awt::Size ToSize(const css::awt::Rectangle &rRectangle)
awt::Rect --> awt::Size (2D)
OOO_DLLPUBLIC_CHARTTOOLS css::awt::Point ToPoint(const css::awt::Rectangle &rRectangle)
awt::Rect --> awt::Point (2D)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
constexpr OUStringLiteral CHART_VIEW_SERVICE_NAME
describes how tickmarks are positioned on the scale of an axis.
This structure contains the explicit values for a scale like Minimum and Maximum.