Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/controller/itemsetwrapper/TitleItemConverter.cxx
Line
Count
Source
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
20
#include <TitleItemConverter.hxx>
21
#include "SchWhichPairs.hxx"
22
#include <ItemPropertyMap.hxx>
23
#include <GraphicPropertyItemConverter.hxx>
24
#include <CharacterPropertyItemConverter.hxx>
25
#include <MultipleItemConverter.hxx>
26
#include <ChartModel.hxx>
27
#include <svx/sdangitm.hxx>
28
#include <rtl/math.hxx>
29
30
#include <com/sun/star/chart2/XTitle.hpp>
31
#include <com/sun/star/beans/XPropertySet.hpp>
32
33
#include <memory>
34
35
using namespace ::com::sun::star;
36
37
namespace chart::wrapper {
38
39
namespace {
40
41
ItemPropertyMapType & lcl_GetTitlePropertyMap()
42
0
{
43
0
    static ItemPropertyMapType aTitlePropertyMap{
44
0
        {SCHATTR_TEXT_STACKED, {"StackCharacters", 0}}};
45
0
    return aTitlePropertyMap;
46
0
};
47
48
class FormattedStringsConverter : public MultipleItemConverter
49
{
50
public:
51
    FormattedStringsConverter(
52
        const uno::Sequence< uno::Reference< chart2::XFormattedString > > & aStrings,
53
        SfxItemPool & rItemPool,
54
        const std::optional<awt::Size>& pRefSize,
55
        const uno::Reference< beans::XPropertySet > & xParentProp );
56
57
protected:
58
    virtual const WhichRangesContainer& GetWhichPairs() const override;
59
};
60
61
} // anonymous namespace
62
63
FormattedStringsConverter::FormattedStringsConverter(
64
    const uno::Sequence< uno::Reference< chart2::XFormattedString > > & aStrings,
65
    SfxItemPool & rItemPool,
66
    const std::optional<awt::Size>& pRefSize,
67
    const uno::Reference< beans::XPropertySet > & xParentProp ) :
68
0
        MultipleItemConverter( rItemPool )
69
0
{
70
0
    bool bHasRefSize = (pRefSize && xParentProp.is());
71
0
    for( uno::Reference< chart2::XFormattedString > const & formattedStr : aStrings )
72
0
    {
73
0
        uno::Reference< beans::XPropertySet > xProp( formattedStr, uno::UNO_QUERY );
74
0
        if( xProp.is())
75
0
        {
76
0
            if( bHasRefSize )
77
0
                m_aConverters.emplace_back(
78
0
                    new CharacterPropertyItemConverter(
79
0
                        xProp, rItemPool, pRefSize, u"ReferencePageSize"_ustr, xParentProp));
80
0
            else
81
0
                m_aConverters.emplace_back( new CharacterPropertyItemConverter( xProp, rItemPool ));
82
0
        }
83
0
    }
84
0
}
85
86
const WhichRangesContainer& FormattedStringsConverter::GetWhichPairs() const
87
0
{
88
0
    return nCharacterPropertyWhichPairs;
89
0
}
90
91
TitleItemConverter::TitleItemConverter(
92
    const uno::Reference<beans::XPropertySet> & rPropertySet,
93
    SfxItemPool& rItemPool,
94
    SdrModel& rDrawModel,
95
    const rtl::Reference< ChartModel > & xChartModel,
96
    const std::optional<awt::Size>& pRefSize ) :
97
0
        ItemConverter( rPropertySet, rItemPool )
98
0
{
99
0
    m_aConverters.emplace_back( new GraphicPropertyItemConverter(
100
0
                                 rPropertySet, rItemPool, rDrawModel,
101
0
                                 xChartModel,
102
0
                                 GraphicObjectType::LineAndFillProperties ));
103
104
    // CharacterProperties are not at the title but at its contained XFormattedString objects
105
    // take the first formatted string in the sequence
106
0
    uno::Reference< chart2::XTitle > xTitle( rPropertySet, uno::UNO_QUERY );
107
0
    if( xTitle.is())
108
0
    {
109
0
        uno::Sequence< uno::Reference< chart2::XFormattedString > > aStringSeq( xTitle->getText());
110
0
        if( aStringSeq.hasElements() )
111
0
        {
112
0
            m_aConverters.emplace_back(
113
0
                new FormattedStringsConverter( aStringSeq, rItemPool, pRefSize, rPropertySet ));
114
0
        }
115
0
    }
116
0
}
117
118
TitleItemConverter::~TitleItemConverter()
119
0
{
120
0
}
121
122
void TitleItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
123
0
{
124
0
    for( const auto& pConv : m_aConverters )
125
0
        pConv->FillItemSet( rOutItemSet );
126
127
    // own items
128
0
    ItemConverter::FillItemSet( rOutItemSet );
129
0
}
130
131
bool TitleItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
132
0
{
133
0
    bool bResult = false;
134
135
0
    for( const auto& pConv : m_aConverters )
136
0
        bResult = pConv->ApplyItemSet( rItemSet ) || bResult;
137
138
    // own items
139
0
    return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
140
0
}
141
142
const WhichRangesContainer& TitleItemConverter::GetWhichPairs() const
143
0
{
144
    // must span all used items!
145
0
    return nTitleWhichPairs;
146
0
}
147
148
bool TitleItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
149
0
{
150
0
    ItemPropertyMapType & rMap( lcl_GetTitlePropertyMap());
151
0
    ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
152
153
0
    if( aIt == rMap.end())
154
0
        return false;
155
156
0
    rOutProperty =(*aIt).second;
157
0
    return true;
158
0
}
159
160
bool TitleItemConverter::ApplySpecialItem(
161
    sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
162
0
{
163
0
    bool bChanged = false;
164
165
0
    switch( nWhichId )
166
0
    {
167
0
        case SCHATTR_TEXT_DEGREES:
168
0
        {
169
            // convert int to double (divided by 100)
170
0
            double fVal = static_cast< double >(
171
0
                static_cast< const SdrAngleItem & >(
172
0
                    rItemSet.Get( nWhichId )).GetValue().get()) / 100.0;
173
0
            double fOldVal = 0.0;
174
0
            bool bPropExisted =
175
0
                ( GetPropertySet()->getPropertyValue( u"TextRotation"_ustr ) >>= fOldVal );
176
177
0
            if( ! bPropExisted || fOldVal != fVal )
178
0
            {
179
0
                GetPropertySet()->setPropertyValue( u"TextRotation"_ustr , uno::Any( fVal ));
180
0
                bChanged = true;
181
0
            }
182
0
        }
183
0
        break;
184
0
    }
185
186
0
    return bChanged;
187
0
}
188
189
void TitleItemConverter::FillSpecialItem(
190
    sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
191
0
{
192
0
    switch( nWhichId )
193
0
    {
194
0
        case SCHATTR_TEXT_DEGREES:
195
0
        {
196
            // convert double to int (times 100)
197
0
            double fVal = 0;
198
199
0
            if( GetPropertySet()->getPropertyValue( u"TextRotation"_ustr ) >>= fVal )
200
0
            {
201
0
                rOutItemSet.Put( SdrAngleItem( SCHATTR_TEXT_DEGREES, Degree100(static_cast< sal_Int32 >(
202
0
                                                   ::rtl::math::round( fVal * 100.0 ) ) )));
203
0
            }
204
0
        }
205
0
        break;
206
0
   }
207
0
}
208
209
} //  namespace chart::wrapper
210
211
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */