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