LibreOffice Module cui (master) 1
cfgchart.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
20#include <com/sun/star/uno/Sequence.hxx>
21#include <tools/debug.hxx>
22#include <sal/log.hxx>
23#include "cfgchart.hxx"
24#include <dialmgr.hxx>
25#include <strings.hrc>
26#include <utility>
27
28#define ROW_COLOR_COUNT 12
29
30using namespace com::sun::star;
31
32// accessors
34{
35 return m_aColorEntries.size();
36}
37
38const XColorEntry & SvxChartColorTable::operator[]( size_t _nIndex ) const
39{
40 if ( _nIndex >= m_aColorEntries.size() )
41 {
42 SAL_WARN( "cui.options", "SvxChartColorTable::[] invalid index" );
43 return m_aColorEntries[ 0 ];
44 }
45
46 return m_aColorEntries[ _nIndex ];
47}
48
49Color SvxChartColorTable::getColor( size_t _nIndex ) const
50{
51 if ( _nIndex >= m_aColorEntries.size() )
52 {
53 SAL_WARN( "cui.options", "SvxChartColorTable::getColorData invalid index" );
54 return COL_BLACK;
55 }
56
57 return m_aColorEntries[ _nIndex ].GetColor().GetRGBColor();
58}
59
60// mutators
62{
63 m_aColorEntries.clear();
64}
65
67{
68 m_aColorEntries.push_back( _rEntry );
69}
70
71void SvxChartColorTable::remove( size_t _nIndex )
72{
73 if (!m_aColorEntries.empty())
74 m_aColorEntries.erase( m_aColorEntries.begin() + _nIndex);
75
76 for (size_t i=0 ; i<m_aColorEntries.size(); i++)
77 {
78 m_aColorEntries[ i ].SetName( getDefaultName( i ) );
79 }
80}
81
82void SvxChartColorTable::replace( size_t _nIndex, const XColorEntry & _rEntry )
83{
84 DBG_ASSERT( _nIndex <= m_aColorEntries.size(),
85 "SvxChartColorTable::replace invalid index" );
86
87 m_aColorEntries[ _nIndex ] = _rEntry;
88}
89
91{
92 static const Color aColors[] = {
93 Color( 0x00, 0x45, 0x86 ),
94 Color( 0xff, 0x42, 0x0e ),
95 Color( 0xff, 0xd3, 0x20 ),
96 Color( 0x57, 0x9d, 0x1c ),
97 Color( 0x7e, 0x00, 0x21 ),
98 Color( 0x83, 0xca, 0xff ),
99 Color( 0x31, 0x40, 0x04 ),
100 Color( 0xae, 0xcf, 0x00 ),
101 Color( 0x4b, 0x1f, 0x6f ),
102 Color( 0xff, 0x95, 0x0e ),
103 Color( 0xc5, 0x00, 0x0b ),
104 Color( 0x00, 0x84, 0xd1 )
105 };
106
107 clear();
108
109 for( sal_Int32 i=0; i<ROW_COLOR_COUNT; i++ )
110 {
111 append( XColorEntry( aColors[ i % sizeof( aColors ) ], getDefaultName( i ) ));
112 }
113}
114
115OUString SvxChartColorTable::getDefaultName( size_t _nIndex )
116{
117 OUString aName;
118
119 std::u16string_view sDefaultNamePrefix;
120 std::u16string_view sDefaultNamePostfix;
121 OUString aResName( CuiResId( RID_CUISTR_DIAGRAM_ROW ) );
122 sal_Int32 nPos = aResName.indexOf( "$(ROW)" );
123 if( nPos != -1 )
124 {
125 sDefaultNamePrefix = aResName.subView( 0, nPos );
126 sDefaultNamePostfix = aResName.subView( nPos + sizeof( "$(ROW)" ) - 1 );
127 }
128 else
129 {
130 sDefaultNamePrefix = aResName;
131 }
132
133 aName = sDefaultNamePrefix + OUString::number(_nIndex + 1) + sDefaultNamePostfix;
134
135 return aName;
136}
137
138// comparison
140{
141 // note: XColorEntry has no operator ==
142 bool bEqual = ( m_aColorEntries.size() == _rOther.m_aColorEntries.size() );
143
144 if( bEqual )
145 {
146 for( size_t i = 0; i < m_aColorEntries.size(); ++i )
147 {
148 if( getColor( i ) != _rOther.getColor( i ))
149 {
150 bEqual = false;
151 break;
152 }
153 }
154 }
155
156 return bEqual;
157}
158
159
160
161
163 ::utl::ConfigItem( "Office.Chart" ),
164 mbIsInitialized( false ),
165 maPropertyNames{ "DefaultColor/Series" }
166{
167}
168
170{
171}
172
174{
175 if ( !mbIsInitialized )
177 return maDefColors;
178}
179
181{
182 maDefColors = aCol;
183 SetModified();
184}
185
187{
188 // get sequence containing all properties
189
191 uno::Sequence< uno::Any > aProperties( aNames.getLength());
192 aProperties = GetProperties( aNames );
193
194 if( aProperties.getLength() != aNames.getLength())
195 return false;
196
197 // 1. default colors for series
200 aProperties[ 0 ] >>= aColorSeq;
201
202 sal_Int32 nCount = aColorSeq.getLength();
203 Color aCol;
204
205 // create strings for entry names
206 OUString aResName( CuiResId( RID_CUISTR_DIAGRAM_ROW ) );
207 std::u16string_view aPrefix, aPostfix;
208 OUString aName;
209 sal_Int32 nPos = aResName.indexOf( "$(ROW)" );
210 if( nPos != -1 )
211 {
212 aPrefix = aResName.subView( 0, nPos );
213 sal_Int32 idx = nPos + sizeof( "$(ROW)" ) - 1;
214 aPostfix = aResName.subView( idx );
215 }
216 else
217 aPrefix = aResName;
218
219 // set color values
220 for( sal_Int32 i=0; i < nCount; i++ )
221 {
222 aCol = Color(ColorTransparency, aColorSeq[ i ]);
223
224 aName = aPrefix + OUString::number(i + 1) + aPostfix;
225
227 }
228 return true;
229}
230
232{
234 uno::Sequence< uno::Any > aValues( aNames.getLength());
235
236 if( aValues.hasElements() )
237 {
238 // 1. default colors for series
239 // convert list to sequence
240 const size_t nCount = maDefColors.size();
242 auto aColorsRange = asNonConstRange(aColors);
243 for( size_t i=0; i < nCount; i++ )
244 {
246 aColorsRange[ i ] = sal_uInt32(aData);
247 }
248
249 aValues.getArray()[0] <<= aColors;
250 }
251
252 PutProperties( aNames, aValues );
253}
254
255void SvxChartOptions::Notify( const css::uno::Sequence< OUString >& )
256{
257}
258
259
260
261
263 SfxPoolItem( nWhich_ ),
264 m_aColorTable(std::move( aTable ))
265{
266}
267
269{
270 return new SvxChartColorTableItem( *this );
271}
272
274{
275 assert(SfxPoolItem::operator==(rAttr));
276
277 return static_cast<const SvxChartColorTableItem & >( rAttr ).m_aColorTable == m_aColorTable;
278}
279
280/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
#define ROW_COLOR_COUNT
Definition: cfgchart.cxx:28
virtual SvxChartColorTableItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: cfgchart.cxx:268
SvxChartColorTableItem(sal_uInt16 nWhich, SvxChartColorTable)
Definition: cfgchart.cxx:262
SvxChartColorTable m_aColorTable
Definition: cfgchart.hxx:97
virtual bool operator==(const SfxPoolItem &) const override
Definition: cfgchart.cxx:273
void remove(size_t _nIndex)
Definition: cfgchart.cxx:71
bool operator==(const SvxChartColorTable &_rOther) const
Definition: cfgchart.cxx:139
std::vector< XColorEntry > m_aColorEntries
Definition: cfgchart.hxx:31
size_t size() const
Definition: cfgchart.cxx:33
void replace(size_t _nIndex, const XColorEntry &_rEntry)
Definition: cfgchart.cxx:82
const XColorEntry & operator[](size_t _nIndex) const
Definition: cfgchart.cxx:38
static OUString getDefaultName(size_t _nIndex)
Definition: cfgchart.cxx:115
void append(const XColorEntry &_rEntry)
Definition: cfgchart.cxx:66
Color getColor(size_t _nIndex) const
Definition: cfgchart.cxx:49
void SetDefaultColors(const SvxChartColorTable &aCol)
Definition: cfgchart.cxx:180
const css::uno::Sequence< OUString > & GetPropertyNames() const
Definition: cfgchart.hxx:63
virtual ~SvxChartOptions() override
Definition: cfgchart.cxx:169
bool RetrieveOptions()
Definition: cfgchart.cxx:186
SvxChartColorTable maDefColors
Definition: cfgchart.hxx:57
bool mbIsInitialized
Definition: cfgchart.hxx:58
virtual void ImplCommit() override
Definition: cfgchart.cxx:231
virtual void Notify(const css::uno::Sequence< OUString > &_rPropertyNames) override
Definition: cfgchart.cxx:255
const SvxChartColorTable & GetDefaultColors()
Definition: cfgchart.cxx:173
static bool PutProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, const css::uno::Sequence< css::uno::Any > &rValues, bool bAllLocales)
static css::uno::Sequence< css::uno::Any > GetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, bool bAllLocales)
ColorTransparency
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
OUString CuiResId(TranslateId aKey)
Definition: cuiresmgr.cxx:23
int nCount
#define DBG_ASSERT(sCon, aError)
const sal_uInt16 idx[]
OUString aName
sal_uInt16 nPos
#define SAL_WARN(area, stream)
constexpr OUStringLiteral aData
int i