tdf#90733 - support invertIfNegative for bar and bubble chart
[LibreOffice.git] / svl / source / items / grabbagitem.cxx
blobf5f5f2bae8861f2bb47cc4f791bf4b2075a2ffcf
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/.
8 */
10 #include <svl/grabbagitem.hxx>
11 #include <sal/config.h>
13 #include <sal/log.hxx>
14 #include <com/sun/star/beans/PropertyValue.hpp>
15 #include <com/sun/star/uno/Sequence.hxx>
16 #include <o3tl/hash_combine.hxx>
18 using namespace com::sun::star;
20 SfxGrabBagItem::SfxGrabBagItem()
21 : SfxPoolItem(0, SfxItemType::SfxGrabBagItemType)
25 SfxGrabBagItem::SfxGrabBagItem(sal_uInt16 nWhich)
26 : SfxPoolItem(nWhich, SfxItemType::SfxGrabBagItemType)
30 SfxGrabBagItem::SfxGrabBagItem(sal_uInt16 nWhich, std::map<OUString, css::uno::Any> aMap)
31 : SfxPoolItem(nWhich, SfxItemType::SfxGrabBagItemType)
32 , m_aMap(std::move(aMap))
36 SfxGrabBagItem::~SfxGrabBagItem() = default;
38 bool SfxGrabBagItem::operator==(const SfxPoolItem& rItem) const
40 return SfxPoolItem::operator==(rItem)
41 && m_aMap == static_cast<const SfxGrabBagItem*>(&rItem)->m_aMap;
44 size_t SfxGrabBagItem::hashCode() const
46 std::size_t seed(0);
47 for (const auto& rPair : m_aMap)
48 o3tl::hash_combine(seed, rPair.first.hashCode());
49 return seed;
52 SfxGrabBagItem* SfxGrabBagItem::Clone(SfxItemPool* /*pPool*/) const
54 return new SfxGrabBagItem(*this);
57 bool SfxGrabBagItem::PutValue(const uno::Any& rVal, sal_uInt8 /*nMemberId*/)
59 ASSERT_CHANGE_REFCOUNTED_ITEM;
60 uno::Sequence<beans::PropertyValue> aValue;
61 if (rVal >>= aValue)
63 m_aMap.clear();
64 for (beans::PropertyValue const& aPropertyValue : aValue)
66 m_aMap[aPropertyValue.Name] = aPropertyValue.Value;
68 return true;
71 SAL_WARN("svl", "SfxGrabBagItem::PutValue: wrong type");
72 return false;
75 bool SfxGrabBagItem::QueryValue(uno::Any& rVal, sal_uInt8 /*nMemberId*/) const
77 uno::Sequence<beans::PropertyValue> aValue(m_aMap.size());
78 beans::PropertyValue* pValue = aValue.getArray();
79 for (const auto& i : m_aMap)
81 pValue[0].Name = i.first;
82 pValue[0].Value = i.second;
83 ++pValue;
85 rVal <<= aValue;
86 return true;
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */