Get the style color and number just once
[LibreOffice.git] / chart2 / source / tools / LabeledDataSequence.cxx
blob181c639625ec9362103a6d90e1dc3bd39da1d518
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <LabeledDataSequence.hxx>
21 #include <ModifyListenerHelper.hxx>
22 #include <cppuhelper/supportsservice.hxx>
23 #include <utility>
25 namespace com::sun::star::uno { class XComponentContext; }
27 using namespace ::com::sun::star;
29 using ::com::sun::star::uno::Reference;
30 using ::com::sun::star::uno::Sequence;
32 namespace chart
35 LabeledDataSequence::LabeledDataSequence() :
36 m_xModifyEventForwarder( new ModifyEventForwarder() )
39 LabeledDataSequence::LabeledDataSequence(
40 uno::Reference< chart2::data::XDataSequence > xValues ) :
41 m_xData(std::move( xValues )),
42 m_xModifyEventForwarder( new ModifyEventForwarder() )
44 ModifyListenerHelper::addListener( m_xData, m_xModifyEventForwarder );
47 LabeledDataSequence::LabeledDataSequence(
48 uno::Reference< chart2::data::XDataSequence > xValues,
49 uno::Reference< chart2::data::XDataSequence > xLabel ) :
50 m_xData(std::move( xValues )),
51 m_xLabel(std::move( xLabel )),
52 m_xModifyEventForwarder( new ModifyEventForwarder() )
54 ModifyListenerHelper::addListener( m_xData, m_xModifyEventForwarder );
55 ModifyListenerHelper::addListener( m_xLabel, m_xModifyEventForwarder );
58 LabeledDataSequence::LabeledDataSequence( const LabeledDataSequence& rSource ) :
59 impl::LabeledDataSequence_Base(),
60 m_xModifyEventForwarder( new ModifyEventForwarder() )
62 uno::Reference< chart2::data::XDataSequence > xNewValues( rSource.m_xData );
63 uno::Reference< chart2::data::XDataSequence > xNewLabel( rSource.m_xLabel );
65 uno::Reference< util::XCloneable > xLabelCloneable( rSource.m_xLabel, uno::UNO_QUERY );
66 if( xLabelCloneable.is())
67 xNewLabel.set( xLabelCloneable->createClone(), uno::UNO_QUERY );
69 uno::Reference< util::XCloneable > xValuesCloneable( rSource.m_xData, uno::UNO_QUERY );
70 if( xValuesCloneable.is())
71 xNewValues.set( xValuesCloneable->createClone(), uno::UNO_QUERY );
73 m_xData = std::move(xNewValues);
74 m_xLabel = std::move(xNewLabel);
76 ModifyListenerHelper::addListener( m_xData, m_xModifyEventForwarder );
77 ModifyListenerHelper::addListener( m_xLabel, m_xModifyEventForwarder );
80 LabeledDataSequence::~LabeledDataSequence()
82 if( m_xModifyEventForwarder.is())
84 if( m_xData.is())
85 ModifyListenerHelper::removeListener( m_xData, m_xModifyEventForwarder );
86 if( m_xLabel.is())
87 ModifyListenerHelper::removeListener( m_xLabel, m_xModifyEventForwarder );
91 // ____ XLabeledDataSequence ____
92 uno::Reference< chart2::data::XDataSequence > SAL_CALL LabeledDataSequence::getValues()
94 return m_xData;
97 void SAL_CALL LabeledDataSequence::setValues(
98 const uno::Reference< chart2::data::XDataSequence >& xSequence )
100 if( m_xData != xSequence )
102 ModifyListenerHelper::removeListener( m_xData, m_xModifyEventForwarder );
103 m_xData = xSequence;
104 ModifyListenerHelper::addListener( m_xData, m_xModifyEventForwarder );
108 uno::Reference< chart2::data::XDataSequence > SAL_CALL LabeledDataSequence::getLabel()
110 return m_xLabel;
113 void SAL_CALL LabeledDataSequence::setLabel(
114 const uno::Reference< chart2::data::XDataSequence >& xSequence )
116 if( m_xLabel != xSequence )
118 ModifyListenerHelper::removeListener( m_xLabel, m_xModifyEventForwarder );
119 m_xLabel = xSequence;
120 ModifyListenerHelper::addListener( m_xLabel, m_xModifyEventForwarder );
124 // ____ XCloneable ____
125 uno::Reference< util::XCloneable > SAL_CALL LabeledDataSequence::createClone()
127 uno::Reference< chart2::data::XDataSequence > xNewValues( m_xData );
128 uno::Reference< chart2::data::XDataSequence > xNewLabel( m_xLabel );
130 uno::Reference< util::XCloneable > xLabelCloneable( m_xLabel, uno::UNO_QUERY );
131 if( xLabelCloneable.is())
132 xNewLabel.set( xLabelCloneable->createClone(), uno::UNO_QUERY );
134 uno::Reference< util::XCloneable > xValuesCloneable( m_xData, uno::UNO_QUERY );
135 if( xValuesCloneable.is())
136 xNewValues.set( xValuesCloneable->createClone(), uno::UNO_QUERY );
138 return uno::Reference< util::XCloneable >(
139 new LabeledDataSequence( xNewValues, xNewLabel ) );
142 // ____ XModifyBroadcaster ____
143 void SAL_CALL LabeledDataSequence::addModifyListener( const Reference< util::XModifyListener >& aListener )
145 m_xModifyEventForwarder->addModifyListener( aListener );
148 void SAL_CALL LabeledDataSequence::removeModifyListener( const Reference< util::XModifyListener >& aListener )
150 m_xModifyEventForwarder->removeModifyListener( aListener );
153 OUString SAL_CALL LabeledDataSequence::getImplementationName()
155 return u"com.sun.star.comp.chart2.LabeledDataSequence"_ustr;
158 sal_Bool SAL_CALL LabeledDataSequence::supportsService( const OUString& rServiceName )
160 return cppu::supportsService(this, rServiceName);
163 css::uno::Sequence< OUString > SAL_CALL LabeledDataSequence::getSupportedServiceNames()
165 return { u"com.sun.star.chart2.data.LabeledDataSequence"_ustr };
168 } // namespace chart
170 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
171 com_sun_star_comp_chart2_LabeledDataSequence_get_implementation(css::uno::XComponentContext *,
172 css::uno::Sequence<css::uno::Any> const &)
174 return cppu::acquire(new ::chart::LabeledDataSequence );
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */