diff options
Diffstat (limited to 'chart2/source/view/main/VLegend.cxx')
-rw-r--r-- | chart2/source/view/main/VLegend.cxx | 98 |
1 files changed, 52 insertions, 46 deletions
diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx index 1dfe3653e4d1..72c0165a69f5 100644 --- a/chart2/source/view/main/VLegend.cxx +++ b/chart2/source/view/main/VLegend.cxx @@ -19,9 +19,11 @@ #include "VLegend.hxx" #include "VButton.hxx" +#include <Legend.hxx> #include <PropertyMapper.hxx> #include <ChartModel.hxx> #include <ObjectIdentifier.hxx> +#include <FormattedString.hxx> #include <RelativePositionHelper.hxx> #include <ShapeFactory.hxx> #include <RelativeSizeHelper.hxx> @@ -40,9 +42,10 @@ #include <com/sun/star/chart2/data/PivotTableFieldEntry.hpp> #include <rtl/math.hxx> #include <svl/ctloptions.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <tools/UnitConversion.hxx> +#include <utility> #include <vector> #include <algorithm> @@ -158,14 +161,17 @@ awt::Size lcl_createTextShapes( try { OUString aLabelString; - Sequence< Reference< XFormattedString2 > > aLabelSeq = rEntry.aLabel; - for( sal_Int32 i = 0; i < aLabelSeq.getLength(); ++i ) + if (rEntry.xLabel) { - // todo: support more than one text range - if( i == 1 ) - break; + // tdf#150034 limit legend label text + if (rEntry.xLabel->getString().getLength() > 520) + { + sal_Int32 nIndex = rEntry.xLabel->getString().indexOf(' ', 500); + rEntry.xLabel->setString( + rEntry.xLabel->getString().copy(0, nIndex > 500 ? nIndex : 500)); + } - aLabelString += aLabelSeq[i]->getString(); + aLabelString += rEntry.xLabel->getString(); // workaround for Issue #i67540# if( aLabelString.isEmpty()) aLabelString = " "; @@ -414,9 +420,9 @@ awt::Size lcl_placeLegendEntries( { try { - OUString aLabelString = rEntries[0].aLabel[0]->getString(); - static const OUStringLiteral sDots = u"..."; - for (sal_Int32 nNewLen = aLabelString.getLength() - sDots.getLength(); nNewLen > 0; nNewLen--) + OUString aLabelString = rEntries[0].xLabel->getString(); + static constexpr OUString sDots = u"..."_ustr; + for (sal_Int32 nNewLen = aLabelString.getLength() - sDots.getLength(); nNewLen > 0; ) { OUString aNewLabel = aLabelString.subView(0, nNewLen) + sDots; rtl::Reference<SvxShapeText> xEntry = ShapeFactory::createText( @@ -429,15 +435,21 @@ awt::Size lcl_placeLegendEntries( if (rRemainingSpace.Width - nWidth >= 0) { aTextShapes.push_back(xEntry); - rEntries[0].aLabel[0]->setString(aNewLabel); + rEntries[0].xLabel->setString(aNewLabel); aRowHeights[0] = nSumHeight; aColumnWidths[0] = nWidth; break; } } DrawModelWrapper::removeShape(xEntry); + // The intention here is to make pathological cases with extremely large labels + // converge a little faster + if (nNewLen > 10 && std::abs(nRemainingSpace) > nSumHeight / 10) + nNewLen -= nNewLen / 10; + else + --nNewLen; } - if (aTextShapes.size() == 0) + if (aTextShapes.empty()) { DrawModelWrapper::removeShape(rEntries[0].xSymbol); rEntries.pop_back(); @@ -795,7 +807,7 @@ bool lcl_shouldSymbolsBePlacedOnTheLeftSide( const Reference< beans::XPropertySe bool bSymbolsLeftSide = true; try { - if( SvtCTLOptions().IsCTLFontEnabled() ) + if( SvtCTLOptions::IsCTLFontEnabled() ) { if(xLegendProp.is()) { @@ -869,13 +881,13 @@ std::vector<std::shared_ptr<VButton>> lcl_createButtons( } // anonymous namespace VLegend::VLegend( - const Reference< XLegend > & xLegend, + rtl::Reference< Legend > xLegend, const Reference< uno::XComponentContext > & xContext, std::vector< LegendEntryProvider* >&& rLegendEntryProviderList, - const rtl::Reference<SvxShapeGroupAnyD>& xTargetPage, + rtl::Reference<SvxShapeGroupAnyD> xTargetPage, ChartModel& rModel ) - : m_xTarget(xTargetPage) - , m_xLegend(xLegend) + : m_xTarget(std::move(xTargetPage)) + , m_xLegend(std::move(xLegend)) , mrModel(rModel) , m_xContext(xContext) , m_aLegendEntryProviderList(std::move(rLegendEntryProviderList)) @@ -888,7 +900,7 @@ void VLegend::setDefaultWritingMode( sal_Int16 nDefaultWritingMode ) m_nDefaultWritingMode = nDefaultWritingMode; } -bool VLegend::isVisible( const Reference< XLegend > & xLegend ) +bool VLegend::isVisible( const rtl::Reference< Legend > & xLegend ) { if( ! xLegend.is()) return false; @@ -896,8 +908,7 @@ bool VLegend::isVisible( const Reference< XLegend > & xLegend ) bool bShow = false; try { - Reference< beans::XPropertySet > xLegendProp( xLegend, uno::UNO_QUERY_THROW ); - xLegendProp->getPropertyValue( "Show") >>= bShow; + xLegend->getPropertyValue( "Show") >>= bShow; } catch( const uno::Exception & ) { @@ -918,7 +929,7 @@ void VLegend::createShapes( try { //create shape and add to page - OUString aLegendParticle( ObjectIdentifier::createParticleForLegend( mrModel ) ); + OUString aLegendParticle( ObjectIdentifier::createParticleForLegend( &mrModel ) ); m_xShape = ShapeFactory::createGroup2D( m_xTarget, ObjectIdentifier::createClassifiedIdentifierForParticle( aLegendParticle ) ); @@ -930,36 +941,32 @@ void VLegend::createShapes( tPropertyValues aLineFillProperties; tPropertyValues aTextProperties; - Reference< beans::XPropertySet > xLegendProp( m_xLegend, uno::UNO_QUERY ); css::chart::ChartLegendExpansion eExpansion = css::chart::ChartLegendExpansion_HIGH; awt::Size aLegendSize( rAvailableSpace ); bool bCustom = false; LegendPosition eLegendPosition = LegendPosition_LINE_END; - if (xLegendProp.is()) + // get Expansion property + m_xLegend->getPropertyValue("Expansion") >>= eExpansion; + if( eExpansion == css::chart::ChartLegendExpansion_CUSTOM ) { - // get Expansion property - xLegendProp->getPropertyValue("Expansion") >>= eExpansion; - if( eExpansion == css::chart::ChartLegendExpansion_CUSTOM ) + RelativeSize aRelativeSize; + if (m_xLegend->getPropertyValue("RelativeSize") >>= aRelativeSize) { - RelativeSize aRelativeSize; - if (xLegendProp->getPropertyValue("RelativeSize") >>= aRelativeSize) - { - aLegendSize.Width = static_cast<sal_Int32>(::rtl::math::approxCeil( aRelativeSize.Primary * rPageSize.Width )); - aLegendSize.Height = static_cast<sal_Int32>(::rtl::math::approxCeil( aRelativeSize.Secondary * rPageSize.Height )); - bCustom = true; - } - else - { - eExpansion = css::chart::ChartLegendExpansion_HIGH; - } + aLegendSize.Width = static_cast<sal_Int32>(::rtl::math::approxCeil( aRelativeSize.Primary * rPageSize.Width )); + aLegendSize.Height = static_cast<sal_Int32>(::rtl::math::approxCeil( aRelativeSize.Secondary * rPageSize.Height )); + bCustom = true; + } + else + { + eExpansion = css::chart::ChartLegendExpansion_HIGH; } - xLegendProp->getPropertyValue("AnchorPosition") >>= eLegendPosition; - lcl_getProperties( xLegendProp, aLineFillProperties, aTextProperties, rPageSize ); } + m_xLegend->getPropertyValue("AnchorPosition") >>= eLegendPosition; + lcl_getProperties( m_xLegend, aLineFillProperties, aTextProperties, rPageSize ); // create entries - double fViewFontSize = lcl_CalcViewFontSize( xLegendProp, rPageSize );//todo + double fViewFontSize = lcl_CalcViewFontSize( m_xLegend, rPageSize );//todo // #i109336# Improve auto positioning in chart sal_Int32 nSymbolHeight = static_cast< sal_Int32 >( fViewFontSize * 0.6 ); sal_Int32 nSymbolWidth = nSymbolHeight; @@ -985,13 +992,13 @@ void VLegend::createShapes( if (pLegendEntryProvider) { std::vector<ViewLegendEntry> aNewEntries = pLegendEntryProvider->createLegendEntries( - aMaxSymbolExtent, eLegendPosition, xLegendProp, + aMaxSymbolExtent, eLegendPosition, m_xLegend, xLegendContainer, m_xContext, mrModel); aViewEntries.insert( aViewEntries.end(), aNewEntries.begin(), aNewEntries.end() ); } } - bool bSymbolsLeftSide = lcl_shouldSymbolsBePlacedOnTheLeftSide( xLegendProp, m_nDefaultWritingMode ); + bool bSymbolsLeftSide = lcl_shouldSymbolsBePlacedOnTheLeftSide( m_xLegend, m_nDefaultWritingMode ); uno::Reference<chart2::data::XPivotTableDataProvider> xPivotTableDataProvider( mrModel.getDataProvider(), uno::UNO_QUERY ); bool bIsPivotChart = xPivotTableDataProvider.is(); @@ -1055,18 +1062,17 @@ void VLegend::changePosition( { // determine position and alignment depending on default position awt::Size aLegendSize = m_xShape->getSize(); - Reference< beans::XPropertySet > xLegendProp( m_xLegend, uno::UNO_QUERY_THROW ); chart2::RelativePosition aRelativePosition; bool bDefaultLegendSize = rDefaultLegendSize.Width != 0 || rDefaultLegendSize.Height != 0; bool bAutoPosition = - ! (xLegendProp->getPropertyValue( "RelativePosition") >>= aRelativePosition); + ! (m_xLegend->getPropertyValue( "RelativePosition") >>= aRelativePosition); LegendPosition ePos = LegendPosition_LINE_END; - xLegendProp->getPropertyValue( "AnchorPosition") >>= ePos; + m_xLegend->getPropertyValue( "AnchorPosition") >>= ePos; bool bOverlay = false; - xLegendProp->getPropertyValue("Overlay") >>= bOverlay; + m_xLegend->getPropertyValue("Overlay") >>= bOverlay; //calculate position if( bAutoPosition ) { |