LibreOffice Module chart2 (master) 1
VLegendSymbolFactory.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 <PropertyMapper.hxx>
22#include <ShapeFactory.hxx>
23#include <com/sun/star/drawing/Position3D.hpp>
24#include <com/sun/star/chart2/Symbol.hpp>
25#include <com/sun/star/drawing/Direction3D.hpp>
27#include <sal/log.hxx>
28
29using namespace ::com::sun::star;
30using ::com::sun::star::uno::Reference;
31
32namespace
33{
34
35void getPropNamesAndValues( const Reference< beans::XPropertySet >& xProp,
37 ::chart::tAnySequence& rValues,
39 const awt::Size& aMaxSymbolExtent)
40{
44
46 switch( ePropertyType )
47 {
48 case ::chart::VLegendSymbolFactory::PropertyType::FilledSeries:
49 ::chart::PropertyMapper::getValueMap( aValueMap, aFilledSeriesNameMap, xProp );
50 break;
51 case ::chart::VLegendSymbolFactory::PropertyType::LineSeries:
52 ::chart::PropertyMapper::getValueMap( aValueMap, aLineSeriesNameMap, xProp );
53 break;
54 case ::chart::VLegendSymbolFactory::PropertyType::Line:
55 ::chart::PropertyMapper::getValueMap( aValueMap, aLineNameMap, xProp );
56 break;
57 }
58
60
61 uno::Any* pLineWidthAny = ::chart::PropertyMapper::getValuePointer(rValues,rNames,u"LineWidth");
62 sal_Int32 nLineWidth = 0;
63 if( pLineWidthAny && (*pLineWidthAny>>=nLineWidth) )
64 {
65 // use legend entry height as upper limit for line width
66 sal_Int32 nMaxLineWidthForLegend = aMaxSymbolExtent.Height;
67 if( nLineWidth>nMaxLineWidthForLegend )
68 *pLineWidthAny <<= nMaxLineWidthForLegend;
69 }
70}
71
72void lcl_setPropertiesToShape(
73 const Reference< beans::XPropertySet > & xProp,
74 const rtl::Reference< SvxShape > & xShape,
76 const awt::Size& aMaxSymbolExtent)
77{
79 ::chart::tAnySequence aPropValues;
80 getPropNamesAndValues( xProp, aPropNames, aPropValues,
81 ePropertyType, aMaxSymbolExtent );
82
83 ::chart::PropertyMapper::setMultiProperties( aPropNames, aPropValues, *xShape );
84}
85
86} // anonymous namespace
87
88namespace chart
89{
90
92 const awt::Size& rEntryKeyAspectRatio,
93 const rtl::Reference<SvxShapeGroupAnyD>& rSymbolContainer,
94 LegendSymbolStyle eStyle,
95 const Reference< beans::XPropertySet > & xLegendEntryProperties,
96 PropertyType ePropertyType, const uno::Any& rExplicitSymbol )
97{
99
100 if( !rSymbolContainer)
101 return xResult;
102
103 xResult = ShapeFactory::createGroup2D( rSymbolContainer );
104 if( ! xResult)
105 return xResult;
106
107 rtl::Reference<SvxShapeGroupAnyD> xResultGroup = xResult;
108
109 // add an invisible square box to maintain aspect ratio
110 ShapeFactory::createInvisibleRectangle( xResultGroup, rEntryKeyAspectRatio );
111
112 // create symbol
113 try
114 {
115 if( eStyle == LegendSymbolStyle::Line )
116 {
118 ShapeFactory::createLine( xResultGroup, awt::Size( rEntryKeyAspectRatio.Width, 0 ),
119 awt::Point( 0, rEntryKeyAspectRatio.Height/2 ));
120 lcl_setPropertiesToShape( xLegendEntryProperties, xLine, ePropertyType, rEntryKeyAspectRatio );
121
122 const sal_Int32 nSize = std::min(rEntryKeyAspectRatio.Width,rEntryKeyAspectRatio.Height);
123 chart2::Symbol aSymbol;
124 if( rExplicitSymbol >>= aSymbol )
125 {
126 drawing::Direction3D aSymbolSize( nSize, nSize, 0 );
127 drawing::Position3D aPos( rEntryKeyAspectRatio.Width/2.0, rEntryKeyAspectRatio.Height/2.0, 0 );
128 if( aSymbol.Style == chart2::SymbolStyle_STANDARD )
129 {
130 // take series color as fill color
131 xLegendEntryProperties->getPropertyValue( "Color") >>= aSymbol.FillColor;
132 // border of symbols always same as fill color
133 aSymbol.BorderColor = aSymbol.FillColor;
134
136 xResultGroup,
137 aPos,
138 aSymbolSize,
139 aSymbol.StandardSymbol,
140 aSymbol.BorderColor,
141 aSymbol.FillColor );
142 }
143 else if( aSymbol.Style == chart2::SymbolStyle_GRAPHIC )
144 {
146 xResultGroup,
147 aPos,
148 aSymbolSize,
149 aSymbol.Graphic );
150 }
151 else if( aSymbol.Style == chart2::SymbolStyle_AUTO )
152 {
153 SAL_WARN("chart2", "the given parameter is not allowed to contain an automatic symbol style");
154 }
155 }
156 }
157 else if( eStyle == LegendSymbolStyle::Circle )
158 {
159 sal_Int32 nSize = std::min( rEntryKeyAspectRatio.Width, rEntryKeyAspectRatio.Height );
161 ShapeFactory::createCircle( xResultGroup, awt::Size( nSize, nSize ),
162 awt::Point( rEntryKeyAspectRatio.Width/2-nSize/2, rEntryKeyAspectRatio.Height/2-nSize/2 ));
163 lcl_setPropertiesToShape( xLegendEntryProperties, xShape, ePropertyType, awt::Size(0,0) ); // PropertyType::FilledSeries );
164 }
165 else // eStyle == LegendSymbolStyle::Box
166 {
168 tAnySequence aPropValues;
169
170 getPropNamesAndValues( xLegendEntryProperties, aPropNames, aPropValues,
171 ePropertyType, awt::Size(0,0) );// PropertyType::FilledSeries
172
173 ShapeFactory::createRectangle( xResultGroup,
174 rEntryKeyAspectRatio, awt::Point( 0, 0 ),
175 aPropNames, aPropValues );
176 }
177 }
178 catch( const uno::Exception & )
179 {
180 DBG_UNHANDLED_EXCEPTION("chart2");
181 }
182
183 return xResult;
184}
185
186} // namespace chart
187
188/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nLineWidth
static css::uno::Any * getValuePointer(tAnySequence &rPropValues, const tNameSequence &rPropNames, std::u16string_view rPropName)
static void setMultiProperties(const tNameSequence &rNames, const tAnySequence &rValues, SvxShape &xTarget)
static const tPropertyNameMap & getPropertyNameMapForLineProperties()
static const tPropertyNameMap & getPropertyNameMapForFilledSeriesProperties()
static void getMultiPropertyListsFromValueMap(tNameSequence &rNames, tAnySequence &rValues, const tPropertyNameValueMap &rValueMap)
static const tPropertyNameMap & getPropertyNameMapForLineSeriesProperties()
static void getValueMap(tPropertyNameValueMap &rValueMap, const tPropertyNameMap &rNameMap, const css::uno::Reference< css::beans::XPropertySet > &xSourceProp)
Fetch property values from the source object and map it to the destination container.
static rtl::Reference< SvxShapeRect > createRectangle(const rtl::Reference< SvxShapeGroupAnyD > &xTarget, const css::awt::Size &rSize, const css::awt::Point &rPosition, const tNameSequence &rPropNames, const tAnySequence &rPropValues, StackPosition ePos=StackPosition::Top)
static rtl::Reference< SvxShapePolyPolygon > createLine(const rtl::Reference< SvxShapeGroupAnyD > &xTarget, const css::awt::Size &rSize, const css::awt::Point &rPosition)
static rtl::Reference< SvxShapeRect > createInvisibleRectangle(const rtl::Reference< SvxShapeGroupAnyD > &xTarget, const css::awt::Size &rSize)
static rtl::Reference< SvxGraphicObject > createGraphic2D(const rtl::Reference< SvxShapeGroupAnyD > &xTarget, const css::drawing::Position3D &rPos, const css::drawing::Direction3D &rSize, const css::uno::Reference< css::graphic::XGraphic > &xGraphic)
static rtl::Reference< SvxShapeGroup > createGroup2D(const rtl::Reference< SvxShapeGroupAnyD > &xTarget, const OUString &aName=OUString())
static rtl::Reference< SvxShapeCircle > createCircle(const rtl::Reference< SvxShapeGroupAnyD > &xTarget, const css::awt::Size &rSize, const css::awt::Point &rPosition)
static rtl::Reference< SvxShapePolyPolygon > createSymbol2D(const rtl::Reference< SvxShapeGroupAnyD > &xTarget, const css::drawing::Position3D &rPos, const css::drawing::Direction3D &rSize, sal_Int32 nStandardSymbol, sal_Int32 nBorderColor, sal_Int32 nFillColor)
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN(area, stream)
rtl::Reference< SvxShapeGroup > createSymbol(const css::awt::Size &rEntryKeyAspectRatio, const rtl::Reference< SvxShapeGroupAnyD > &rSymbolContainer, LegendSymbolStyle eStyle, const css::uno::Reference< css::beans::XPropertySet > &xLegendEntryProperties, PropertyType ePropertyType, const css::uno::Any &rExplicitSymbol)
css::uno::Sequence< OUString > tNameSequence
@ Circle
A bordered circle which has the same bounding-box as the <member>BOX</member>.
@ Line
A line like with a symbol.
std::unordered_map< OUString, OUString > tPropertyNameMap
css::uno::Sequence< css::uno::Any > tAnySequence
std::unordered_map< OUString, css::uno::Any > tPropertyNameValueMap
const PropertyStruct aPropNames[]