summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2023-11-08 09:54:40 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-11-09 06:24:34 +0100
commita4f52e3bb7f034035ba90ac95611253098959dfd (patch)
treed77cf8d70ef323d5050a584d81ca53fe02507258 /svx
parentf843c4b57f82b282cadc8eca2d80ed15d15993eb (diff)
loplugin:fieldcast in FmXUndoEnvironment
which means we can also use unique_ptr to manage this field. Change-Id: Icf31fa718af455148601efafbcc69067c5c27a16 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159172 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/form/fmundo.cxx33
-rw-r--r--svx/source/inc/fmundo.hxx7
2 files changed, 17 insertions, 23 deletions
diff --git a/svx/source/form/fmundo.cxx b/svx/source/form/fmundo.cxx
index 0c554afb4b02..9bbe99a81d6e 100644
--- a/svx/source/form/fmundo.cxx
+++ b/svx/source/form/fmundo.cxx
@@ -151,6 +151,9 @@ struct PropertyInfo
// as if it's transient or persistent
};
+}
+
+
struct PropertySetInfo
{
typedef std::map<OUString, PropertyInfo> AllProperties;
@@ -160,17 +163,11 @@ struct PropertySetInfo
// sal_False -> the set has _no_ such property or its value isn't empty
};
-}
-
-typedef std::map<Reference< XPropertySet >, PropertySetInfo> PropertySetInfoCache;
-
-
static OUString static_STR_UNDO_PROPERTY;
FmXUndoEnvironment::FmXUndoEnvironment(FmFormModel& _rModel)
:rModel( _rModel )
- ,m_pPropertySetCache( nullptr )
,m_pScriptingEnv( new svxform::FormScriptingEnvironment( _rModel ) )
,m_Locks( 0 )
,bReadOnly( false )
@@ -189,9 +186,6 @@ FmXUndoEnvironment::~FmXUndoEnvironment()
{
if ( !m_bDisposed ) // i120746, call FormScriptingEnvironment::dispose to avoid memory leak
m_pScriptingEnv->dispose();
-
- if (m_pPropertySetCache)
- delete static_cast<PropertySetInfoCache*>(m_pPropertySetCache);
}
void FmXUndoEnvironment::dispose()
@@ -515,10 +509,9 @@ void SAL_CALL FmXUndoEnvironment::disposing(const EventObject& e)
Reference< XPropertySet > xSourceSet(e.Source, UNO_QUERY);
if (xSourceSet.is())
{
- PropertySetInfoCache* pCache = static_cast<PropertySetInfoCache*>(m_pPropertySetCache);
- PropertySetInfoCache::iterator aSetPos = pCache->find(xSourceSet);
- if (aSetPos != pCache->end())
- pCache->erase(aSetPos);
+ PropertySetInfoCache::iterator aSetPos = m_pPropertySetCache->find(xSourceSet);
+ if (aSetPos != m_pPropertySetCache->end())
+ m_pPropertySetCache->erase(aSetPos);
}
}
}
@@ -573,12 +566,11 @@ void SAL_CALL FmXUndoEnvironment::propertyChange(const PropertyChangeEvent& evt)
// which does not have a "ExternalData" property being <TRUE/>
if (!m_pPropertySetCache)
- m_pPropertySetCache = new PropertySetInfoCache;
- PropertySetInfoCache* pCache = static_cast<PropertySetInfoCache*>(m_pPropertySetCache);
+ m_pPropertySetCache = std::make_unique<PropertySetInfoCache>();
// let's see if we know something about the set
- PropertySetInfoCache::iterator aSetPos = pCache->find(xSet);
- if (aSetPos == pCache->end())
+ PropertySetInfoCache::iterator aSetPos = m_pPropertySetCache->find(xSet);
+ if (aSetPos == m_pPropertySetCache->end())
{
PropertySetInfo aNewEntry;
if (!::comphelper::hasProperty(FM_PROP_CONTROLSOURCE, xSet))
@@ -597,8 +589,8 @@ void SAL_CALL FmXUndoEnvironment::propertyChange(const PropertyChangeEvent& evt)
DBG_UNHANDLED_EXCEPTION("svx");
}
}
- aSetPos = pCache->emplace(xSet,aNewEntry).first;
- DBG_ASSERT(aSetPos != pCache->end(), "FmXUndoEnvironment::propertyChange : just inserted it ... why it's not there ?");
+ aSetPos = m_pPropertySetCache->emplace(xSet,aNewEntry).first;
+ DBG_ASSERT(aSetPos != m_pPropertySetCache->end(), "FmXUndoEnvironment::propertyChange : just inserted it ... why it's not there ?");
}
else
{ // is it the DataField property ?
@@ -711,8 +703,7 @@ void SAL_CALL FmXUndoEnvironment::propertyChange(const PropertyChangeEvent& evt)
if (m_pPropertySetCache && evt.PropertyName == FM_PROP_CONTROLSOURCE)
{
Reference< XPropertySet > xSet(evt.Source, UNO_QUERY);
- PropertySetInfoCache* pCache = static_cast<PropertySetInfoCache*>(m_pPropertySetCache);
- PropertySetInfo& rSetInfo = (*pCache)[xSet];
+ PropertySetInfo& rSetInfo = (*m_pPropertySetCache)[xSet];
rSetInfo.bHasEmptyControlSource = !evt.NewValue.hasValue() || ::comphelper::getString(evt.NewValue).isEmpty();
}
}
diff --git a/svx/source/inc/fmundo.hxx b/svx/source/inc/fmundo.hxx
index 61792e1afa3f..f0e691fe67f4 100644
--- a/svx/source/inc/fmundo.hxx
+++ b/svx/source/inc/fmundo.hxx
@@ -24,7 +24,6 @@
#include <svx/svdouno.hxx>
#include "fmscriptingenv.hxx"
-
#include <com/sun/star/util/XModifyListener.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XPropertyChangeListener.hpp>
@@ -38,10 +37,13 @@
#include <svl/lstner.hxx>
+#include <memory>
+#include <map>
class FmFormModel;
class FmFormObj;
class SdrObject;
+struct PropertySetInfo;
class FmUndoPropertyAction final : public SdrUndoAction
{
@@ -114,6 +116,7 @@ public:
static void DisposeElement( const css::uno::Reference< css::awt::XControlModel>& xReplaced );
};
+typedef std::map<css::uno::Reference< css::beans::XPropertySet >, PropertySetInfo> PropertySetInfoCache;
class FmXUndoEnvironment final
: public ::cppu::WeakImplHelper< css::beans::XPropertyChangeListener
@@ -184,7 +187,7 @@ private:
void switchListening( const css::uno::Reference< css::uno::XInterface >& _rxObject, bool _bStartListening );
FmFormModel& rModel;
- void* m_pPropertySetCache;
+ std::unique_ptr<PropertySetInfoCache> m_pPropertySetCache;
::rtl::Reference<svxform::FormScriptingEnvironment> m_pScriptingEnv;
oslInterlockedCount m_Locks;
::osl::Mutex m_aMutex;