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#include <officecfg/Office/Chart.hxx>
28
29#define ROW_COLOR_COUNT 12
30
31using namespace com::sun::star;
32
33// accessors
35{
36 return m_aColorEntries.size();
37}
38
39const XColorEntry & SvxChartColorTable::operator[]( size_t _nIndex ) const
40{
41 if ( _nIndex >= m_aColorEntries.size() )
42 {
43 SAL_WARN( "cui.options", "SvxChartColorTable::[] invalid index" );
44 return m_aColorEntries[ 0 ];
45 }
46
47 return m_aColorEntries[ _nIndex ];
48}
49
50Color SvxChartColorTable::getColor( size_t _nIndex ) const
51{
52 if ( _nIndex >= m_aColorEntries.size() )
53 {
54 SAL_WARN( "cui.options", "SvxChartColorTable::getColorData invalid index" );
55 return COL_BLACK;
56 }
57
58 return m_aColorEntries[ _nIndex ].GetColor().GetRGBColor();
59}
60
61// mutators
63{
64 m_aColorEntries.clear();
65}
66
68{
69 m_aColorEntries.push_back( _rEntry );
70}
71
72void SvxChartColorTable::remove( size_t _nIndex )
73{
74 if (!m_aColorEntries.empty())
75 m_aColorEntries.erase( m_aColorEntries.begin() + _nIndex);
76
77 for (size_t i=0 ; i<m_aColorEntries.size(); i++)
78 {
79 m_aColorEntries[ i ].SetName( getDefaultName( i ) );
80 }
81}
82
83void SvxChartColorTable::replace( size_t _nIndex, const XColorEntry & _rEntry )
84{
85 DBG_ASSERT( _nIndex <= m_aColorEntries.size(),
86 "SvxChartColorTable::replace invalid index" );
87
88 m_aColorEntries[ _nIndex ] = _rEntry;
89}
90
92{
93 static const Color aColors[] = {
94 Color( 0x00, 0x45, 0x86 ),
95 Color( 0xff, 0x42, 0x0e ),
96 Color( 0xff, 0xd3, 0x20 ),
97 Color( 0x57, 0x9d, 0x1c ),
98 Color( 0x7e, 0x00, 0x21 ),
99 Color( 0x83, 0xca, 0xff ),
100 Color( 0x31, 0x40, 0x04 ),
101 Color( 0xae, 0xcf, 0x00 ),
102 Color( 0x4b, 0x1f, 0x6f ),
103 Color( 0xff, 0x95, 0x0e ),
104 Color( 0xc5, 0x00, 0x0b ),
105 Color( 0x00, 0x84, 0xd1 )
106 };
107
108 clear();
109
110 for( sal_Int32 i=0; i<ROW_COLOR_COUNT; i++ )
111 {
112 append( XColorEntry( aColors[ i % sizeof( aColors ) ], getDefaultName( i ) ));
113 }
114}
115
116OUString SvxChartColorTable::getDefaultName( size_t _nIndex )
117{
118 OUString aName;
119
120 std::u16string_view sDefaultNamePrefix;
121 std::u16string_view sDefaultNamePostfix;
122 OUString aResName( CuiResId( RID_CUISTR_DIAGRAM_ROW ) );
123 sal_Int32 nPos = aResName.indexOf( "$(ROW)" );
124 if( nPos != -1 )
125 {
126 sDefaultNamePrefix = aResName.subView( 0, nPos );
127 sDefaultNamePostfix = aResName.subView( nPos + sizeof( "$(ROW)" ) - 1 );
128 }
129 else
130 {
131 sDefaultNamePrefix = aResName;
132 }
133
134 aName = sDefaultNamePrefix + OUString::number(_nIndex + 1) + sDefaultNamePostfix;
135
136 return aName;
137}
138
139// comparison
141{
142 // note: XColorEntry has no operator ==
143 bool bEqual = ( m_aColorEntries.size() == _rOther.m_aColorEntries.size() );
144
145 if( bEqual )
146 {
147 for( size_t i = 0; i < m_aColorEntries.size(); ++i )
148 {
149 if( getColor( i ) != _rOther.getColor( i ))
150 {
151 bEqual = false;
152 break;
153 }
154 }
155 }
156
157 return bEqual;
158}
159
160
161
162
164{
165 // 1. default colors for series
166 uno::Sequence< sal_Int64 > aColorSeq = officecfg::Office::Chart::DefaultColor::Series::get();
167
168 sal_Int32 nCount = aColorSeq.getLength();
169 Color aCol;
170
171 // create strings for entry names
172 OUString aResName( CuiResId( RID_CUISTR_DIAGRAM_ROW ) );
173 std::u16string_view aPrefix, aPostfix;
174 OUString aName;
175 sal_Int32 nPos = aResName.indexOf( "$(ROW)" );
176 if( nPos != -1 )
177 {
178 aPrefix = aResName.subView( 0, nPos );
179 sal_Int32 idx = nPos + sizeof( "$(ROW)" ) - 1;
180 aPostfix = aResName.subView( idx );
181 }
182 else
183 aPrefix = aResName;
184
185 // set color values
186 SvxChartColorTable aDefColors;
187 for( sal_Int32 i=0; i < nCount; i++ )
188 {
189 aCol = Color(ColorTransparency, aColorSeq[ i ]);
190
191 aName = aPrefix + OUString::number(i + 1) + aPostfix;
192
193 aDefColors.append( XColorEntry( aCol, aName ));
194 }
195
196 return aDefColors;
197}
198
200{
201 // 1. default colors for series
202 // convert list to sequence
203 const size_t nCount = rDefColors.size();
205 auto aColorsRange = asNonConstRange(aColors);
206 for( size_t i=0; i < nCount; i++ )
207 {
208 Color aData = rDefColors.getColor( i );
209 aColorsRange[ i ] = sal_uInt32(aData);
210 }
211 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
212 officecfg::Office::Chart::DefaultColor::Series::set(aColors, batch);
213 batch->commit();
214}
215
216
218 SfxPoolItem( nWhich_ ),
219 m_aColorTable(std::move( aTable ))
220{
221}
222
224{
225 return new SvxChartColorTableItem( *this );
226}
227
229{
230 assert(SfxPoolItem::operator==(rAttr));
231
232 return static_cast<const SvxChartColorTableItem & >( rAttr ).m_aColorTable == m_aColorTable;
233}
234
235/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define ROW_COLOR_COUNT
Definition: cfgchart.cxx:29
virtual SvxChartColorTableItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: cfgchart.cxx:223
SvxChartColorTableItem(sal_uInt16 nWhich, SvxChartColorTable)
Definition: cfgchart.cxx:217
SvxChartColorTable m_aColorTable
Definition: cfgchart.hxx:76
virtual bool operator==(const SfxPoolItem &) const override
Definition: cfgchart.cxx:228
void remove(size_t _nIndex)
Definition: cfgchart.cxx:72
bool operator==(const SvxChartColorTable &_rOther) const
Definition: cfgchart.cxx:140
std::vector< XColorEntry > m_aColorEntries
Definition: cfgchart.hxx:29
size_t size() const
Definition: cfgchart.cxx:34
void replace(size_t _nIndex, const XColorEntry &_rEntry)
Definition: cfgchart.cxx:83
const XColorEntry & operator[](size_t _nIndex) const
Definition: cfgchart.cxx:39
static OUString getDefaultName(size_t _nIndex)
Definition: cfgchart.cxx:116
void append(const XColorEntry &_rEntry)
Definition: cfgchart.cxx:67
Color getColor(size_t _nIndex) const
Definition: cfgchart.cxx:50
static std::shared_ptr< ConfigurationChanges > create()
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
void SetDefaultColors(const SvxChartColorTable &aCol)
Definition: cfgchart.cxx:199
SvxChartColorTable GetDefaultColors()
Definition: cfgchart.cxx:163
int i