[Libreoffice-commits] core.git: include/svl sfx2/source svl/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Sat Oct 5 12:07:29 UTC 2019
include/svl/aeitem.hxx | 29 ++----------
sfx2/source/appl/appcfg.cxx | 6 +-
svl/source/items/aeitem.cxx | 94 +++++++-----------------------------------
svl/source/items/poolitem.cxx | 3 -
4 files changed, 27 insertions(+), 105 deletions(-)
New commits:
commit 4f7c0393d5dab5c0451d16a694fab963bdc98966
Author: Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Fri Oct 4 18:58:20 2019 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Oct 5 14:06:33 2019 +0200
simplify SfxAllEnumItem
It is just a data carrier for an array of values for
SID_ATTR_PATHNAME, it does not need associated enum logic.
Change-Id: I547cd5580d02eb9c261feeb3545e31910a4ed644
Reviewed-on: https://gerrit.libreoffice.org/80253
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/svl/aeitem.hxx b/include/svl/aeitem.hxx
index 4c25643cf59d..a15d3a5e2332 100644
--- a/include/svl/aeitem.hxx
+++ b/include/svl/aeitem.hxx
@@ -26,37 +26,20 @@
#include <memory>
#include <vector>
-struct SfxAllEnumValue_Impl;
-typedef std::vector<SfxAllEnumValue_Impl> SfxAllEnumValueArr;
-
-// MSVC hack:
-class SAL_DLLPUBLIC_RTTI SfxAllEnumItem_Base: public SfxEnumItem<sal_uInt16> {
-protected:
- explicit SfxAllEnumItem_Base(sal_uInt16 nWhich, sal_uInt16 nValue):
- SfxEnumItem(nWhich, nValue)
- {}
-};
-
-class SVL_DLLPUBLIC SfxAllEnumItem: public SfxAllEnumItem_Base
+class SVL_DLLPUBLIC SfxAllEnumItem: public SfxPoolItem
{
- std::unique_ptr<SfxAllEnumValueArr> pValues;
-
- sal_uInt16 GetPosByValue( sal_uInt16 nValue ) const;
- std::size_t GetPosByValue_( sal_uInt16 nValue ) const;
- sal_uInt16 GetValueByPos( sal_uInt16 nPos ) const;
+ std::vector<OUString> m_Values;
public:
explicit SfxAllEnumItem( sal_uInt16 nWhich);
- SfxAllEnumItem( sal_uInt16 nWhich, sal_uInt16 nVal );
SfxAllEnumItem( const SfxAllEnumItem & );
virtual ~SfxAllEnumItem() override;
- void InsertValue( sal_uInt16 nValue );
- void InsertValue( sal_uInt16 nValue, const OUString &rText );
-
- virtual sal_uInt16 GetValueCount() const override;
- OUString const & GetValueTextByPos( sal_uInt16 nPos ) const;
+ void SetTextByPos( sal_uInt16 nPos, const OUString &rText );
+ OUString const & GetTextByPos( sal_uInt16 nPos ) const;
+ sal_Int32 GetTextCount() const;
virtual SfxPoolItem* Clone( SfxItemPool *pPool = nullptr ) const override;
+ virtual bool operator==( SfxPoolItem const & ) const override;
};
#endif
diff --git a/sfx2/source/appl/appcfg.cxx b/sfx2/source/appl/appcfg.cxx
index 323c87432d55..208c23aca8b5 100644
--- a/sfx2/source/appl/appcfg.cxx
+++ b/sfx2/source/appl/appcfg.cxx
@@ -436,7 +436,7 @@ void SfxApplication::GetOptions( SfxItemSet& rSet )
case SvtPathOptions::PATH_USERCONFIG: aValue = aPathCfg.GetUserConfigPath(); break;
case SvtPathOptions::PATH_WORK: aValue = aPathCfg.GetWorkPath(); break;
}
- aValues.InsertValue( nProp, aValue );
+ aValues.SetTextByPos( nProp, aValue );
}
if (rSet.Put(aValues))
@@ -728,11 +728,11 @@ void SfxApplication::SetOptions(const SfxItemSet &rSet)
{
DBG_ASSERT(dynamic_cast< const SfxAllEnumItem *>( pItem ) != nullptr, "AllEnumItem expected");
const SfxAllEnumItem* pEnumItem = static_cast<const SfxAllEnumItem *>(pItem);
- sal_uInt32 nCount = pEnumItem->GetValueCount();
+ sal_uInt32 nCount = pEnumItem->GetTextCount();
OUString aNoChangeStr( ' ' );
for( sal_uInt32 nPath=0; nPath<nCount; ++nPath )
{
- const OUString& sValue = pEnumItem->GetValueTextByPos(static_cast<sal_uInt16>(nPath));
+ const OUString& sValue = pEnumItem->GetTextByPos(static_cast<sal_uInt16>(nPath));
if ( sValue != aNoChangeStr )
{
switch( nPath )
diff --git a/svl/source/items/aeitem.cxx b/svl/source/items/aeitem.cxx
index 2d2ce6d10ea5..00e58d27f464 100644
--- a/svl/source/items/aeitem.cxx
+++ b/svl/source/items/aeitem.cxx
@@ -23,50 +23,29 @@
#include <climits>
#include <cstddef>
-struct SfxAllEnumValue_Impl
-{
- sal_uInt16 nValue;
- OUString aText;
-};
-
-
-SfxAllEnumItem::SfxAllEnumItem(sal_uInt16 which, sal_uInt16 nVal):
- SfxAllEnumItem_Base(which, nVal)
-{
- InsertValue( nVal );
-}
-
SfxAllEnumItem::SfxAllEnumItem(sal_uInt16 which):
- SfxAllEnumItem_Base(which, 0)
+ SfxPoolItem(which)
{
}
SfxAllEnumItem::SfxAllEnumItem(const SfxAllEnumItem &rCopy):
- SfxAllEnumItem_Base(rCopy)
+ SfxPoolItem(rCopy),
+ m_Values(rCopy.m_Values)
{
- if ( rCopy.pValues )
- pValues.reset( new SfxAllEnumValueArr(*rCopy.pValues) );
}
SfxAllEnumItem::~SfxAllEnumItem()
{
}
-sal_uInt16 SfxAllEnumItem::GetValueCount() const
-{
- return pValues ? pValues->size() : 0;
-}
-
-OUString const & SfxAllEnumItem::GetValueTextByPos( sal_uInt16 nPos ) const
+sal_Int32 SfxAllEnumItem::GetTextCount() const
{
- assert(pValues && nPos < pValues->size());
- return (*pValues)[nPos].aText;
+ return m_Values.size();
}
-sal_uInt16 SfxAllEnumItem::GetValueByPos( sal_uInt16 nPos ) const
+OUString const & SfxAllEnumItem::GetTextByPos( sal_uInt16 nPos ) const
{
- assert(pValues && nPos < pValues->size());
- return (*pValues)[nPos].nValue;
+ return m_Values[nPos];
}
SfxPoolItem* SfxAllEnumItem::Clone( SfxItemPool * ) const
@@ -74,60 +53,21 @@ SfxPoolItem* SfxAllEnumItem::Clone( SfxItemPool * ) const
return new SfxAllEnumItem(*this);
}
-/**
- * In contrast to @see GetPosByValue(sal_uInt16) const
- * this internal method returns the position the value would be for non-present values.
- */
-std::size_t SfxAllEnumItem::GetPosByValue_( sal_uInt16 nVal ) const
+void SfxAllEnumItem::SetTextByPos( sal_uInt16 nPos, const OUString &rText )
{
- if ( !pValues )
- return 0;
-
- //FIXME: Optimisation: use binary search or SortArray
- std::size_t nPos;
- for ( nPos = 0; nPos < pValues->size(); ++nPos )
- if ( (*pValues)[nPos].nValue >= nVal )
- return nPos;
- return nPos;
+ if (nPos >= m_Values.size())
+ m_Values.resize(nPos);
+ m_Values[nPos] = rText;
}
-sal_uInt16 SfxAllEnumItem::GetPosByValue( sal_uInt16 nValue ) const
+bool SfxAllEnumItem::operator==( const SfxPoolItem& rCmp ) const
{
- if ( !pValues || pValues->empty() )
- return nValue;
-
- sal_uInt16 nCount = GetValueCount();
- for (sal_uInt16 i = 0; i < nCount; ++i)
- if (GetValueByPos(i) == nValue)
- return i;
- return USHRT_MAX;
+ assert(dynamic_cast< const SfxAllEnumItem* >(&rCmp) && "operator==Types not matching");
+ const SfxAllEnumItem& rOther = static_cast<const SfxAllEnumItem&>(rCmp);
+ if (!SfxPoolItem::operator==(rCmp))
+ return false;
+ return m_Values == rOther.m_Values;
}
-void SfxAllEnumItem::InsertValue( sal_uInt16 nValue, const OUString &rValue )
-{
- SfxAllEnumValue_Impl aVal;
- aVal.nValue = nValue;
- aVal.aText = rValue;
- if ( !pValues )
- pValues.reset( new SfxAllEnumValueArr );
- else if ( sal_uInt16 nPos = GetPosByValue(nValue); nPos != USHRT_MAX )
- {
- // remove when exists
- pValues->erase( pValues->begin() + nPos );
- }
- // then insert
- pValues->insert(pValues->begin() + GetPosByValue_(nValue), aVal); // FIXME: Duplicates?
-}
-
-void SfxAllEnumItem::InsertValue( sal_uInt16 nValue )
-{
- SfxAllEnumValue_Impl aVal;
- aVal.nValue = nValue;
- aVal.aText = OUString::number(nValue);
- if ( !pValues )
- pValues.reset( new SfxAllEnumValueArr );
-
- pValues->insert(pValues->begin() + GetPosByValue_(nValue), aVal); // FIXME: Duplicates?
-}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svl/source/items/poolitem.cxx b/svl/source/items/poolitem.cxx
index 1ee28f0352f0..5c4e81c89e10 100644
--- a/svl/source/items/poolitem.cxx
+++ b/svl/source/items/poolitem.cxx
@@ -70,6 +70,7 @@
// class SfxObjectShellItem: public SfxPoolItem
// class SfxViewFrameItem: public SfxPoolItem
// class SfxWatermarkItem: public SfxPoolItem
+// class SfxAllEnumItem: public SfxPoolItem
// class SfxEnumItemInterface: public SfxPoolItem
// class SvxAdjustItem : public SfxEnumItemInterface
// class SvxEscapementItem : public SfxEnumItemInterface
@@ -91,8 +92,6 @@
// class SvxUnderlineItem : public SvxTextLineItem
// class SvxOverlineItem : public SvxTextLineItem
// class SvxWeightItem : public SfxEnumItem<FontWeight>
-// class SfxAllEnumItem_Base: public SfxEnumItem<sal_uInt16>
-// class SfxAllEnumItem: public SfxAllEnumItem_Base
// class SvxOrientationItem: public SfxEnumItem<SvxCellOrientation>
// class SvxChartRegressItem : public SfxEnumItem<SvxChartRegress>
// class SvxChartTextOrderItem : public SfxEnumItem<SvxChartTextOrder>
More information about the Libreoffice-commits
mailing list