summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2023-11-22 22:16:35 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-11-23 09:31:53 +0100
commit2b403a8ddce089689ed3baefa75e0ea5c77724e1 (patch)
tree3bbc040ba687745ce90d67dc953cc49be1c85b7f
parent693735e4d39b92d7a16e855cfd9d99d9d150ea75 (diff)
loplugin:fieldcast in DbGridControl
Change-Id: I87b1aa0326cbd4270ca54831b3388a5da9c9416d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159842 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--compilerplugins/clang/fieldcast.results6
-rw-r--r--include/svx/gridctrl.hxx4
-rw-r--r--svx/source/fmcomp/gridctrl.cxx69
3 files changed, 22 insertions, 57 deletions
diff --git a/compilerplugins/clang/fieldcast.results b/compilerplugins/clang/fieldcast.results
index c794886ec751..6b16aeb370f9 100644
--- a/compilerplugins/clang/fieldcast.results
+++ b/compilerplugins/clang/fieldcast.results
@@ -88,9 +88,6 @@ editeng/source/editeng/impedit.hxx:506
extensions/source/update/check/updatecheck.hxx:164
UpdateCheck m_pThread WorkerThread *
(anonymous namespace)::UpdateCheckThread
-framework/inc/uielement/uielement.hxx:89
- framework::UIElement m_xUIElement css::uno::Reference<css::ui::XUIElement>
- framework::AddonsToolBarWrapper
i18npool/inc/calendarImpl.hxx:103
i18npool::CalendarImpl xCalendar css::uno::Reference<css::i18n::XCalendar4>
i18npool::Calendar_gregorian
@@ -178,9 +175,6 @@ include/svx/AccessibleShape.hxx:391
include/svx/fmsrcimp.hxx:161
FmSearchEngine m_xSearchCursor CursorWrapper
com::sun::star::uno::Reference
-include/svx/gridctrl.hxx:255
- DbGridControl m_pFieldListeners void *
- std::map
include/svx/svdhdl.hxx:136
SdrHdl m_pObj SdrObject *
SdrEdgeObj
diff --git a/include/svx/gridctrl.hxx b/include/svx/gridctrl.hxx
index b8057fd61823..f47520090fba 100644
--- a/include/svx/gridctrl.hxx
+++ b/include/svx/gridctrl.hxx
@@ -27,6 +27,7 @@
#include <osl/mutex.hxx>
#include <svx/svxdllapi.h>
#include <o3tl/typed_flags_set.hxx>
+#include <map>
#include <memory>
#include <vector>
@@ -40,6 +41,7 @@ namespace com::sun::star::util { class XNumberFormatter; }
namespace weld { class Menu; }
class CursorWrapper;
+class GridFieldValueListener;
bool CompareBookmark(const css::uno::Any& aLeft, const css::uno::Any& aRight);
@@ -252,7 +254,7 @@ private:
css::uno::Reference< css::sdb::XRowsChangeListener>
m_xRowSetListener; // get notification when rows were changed
- void* m_pFieldListeners;
+ std::map<sal_uInt16, GridFieldValueListener*> m_aFieldListeners;
// property listeners for field values
std::unique_ptr<DisposeListenerGridBridge> m_pCursorDisposeListener;
diff --git a/svx/source/fmcomp/gridctrl.cxx b/svx/source/fmcomp/gridctrl.cxx
index fce266d26a6c..627c41c5468d 100644
--- a/svx/source/fmcomp/gridctrl.cxx
+++ b/svx/source/fmcomp/gridctrl.cxx
@@ -60,7 +60,6 @@
#include <algorithm>
#include <cstdlib>
-#include <map>
#include <memory>
using namespace ::dbtools;
@@ -121,9 +120,6 @@ private:
}
};
-class GridFieldValueListener;
-typedef std::map<sal_uInt16, GridFieldValueListener*> ColumnFieldValueListeners;
-
class GridFieldValueListener : protected ::comphelper::OPropertyChangeListener
{
osl::Mutex m_aMutex;
@@ -693,7 +689,6 @@ DbGridControl::DbGridControl(
,m_aBar(VclPtr<NavigationBar>::Create(this))
,m_nAsynAdjustEvent(nullptr)
,m_pDataSourcePropListener(nullptr)
- ,m_pFieldListeners(nullptr)
,m_pGridListener(nullptr)
,m_nSeekPos(-1)
,m_nTotalCount(-1)
@@ -755,7 +750,7 @@ void DbGridControl::dispose()
m_bWantDestruction = true;
osl::MutexGuard aGuard(m_aDestructionSafety);
- if (m_pFieldListeners)
+ if (!m_aFieldListeners.empty())
DisconnectFromFields();
m_pCursorDisposeListener.reset();
@@ -3205,15 +3200,11 @@ IMPL_LINK(DbGridControl, OnAsyncAdjust, void*, pAdjustWhat, void)
void DbGridControl::BeginCursorAction()
{
- if (m_pFieldListeners)
+ for (const auto& rListener : m_aFieldListeners)
{
- ColumnFieldValueListeners* pListeners = static_cast<ColumnFieldValueListeners*>(m_pFieldListeners);
- for (const auto& rListener : *pListeners)
- {
- GridFieldValueListener* pCurrent = rListener.second;
- if (pCurrent)
- pCurrent->suspend();
- }
+ GridFieldValueListener* pCurrent = rListener.second;
+ if (pCurrent)
+ pCurrent->suspend();
}
if (m_pDataSourcePropListener)
@@ -3222,15 +3213,11 @@ void DbGridControl::BeginCursorAction()
void DbGridControl::EndCursorAction()
{
- if (m_pFieldListeners)
+ for (const auto& rListener : m_aFieldListeners)
{
- ColumnFieldValueListeners* pListeners = static_cast<ColumnFieldValueListeners*>(m_pFieldListeners);
- for (const auto& rListener : *pListeners)
- {
- GridFieldValueListener* pCurrent = rListener.second;
- if (pCurrent)
- pCurrent->resume();
- }
+ GridFieldValueListener* pCurrent = rListener.second;
+ if (pCurrent)
+ pCurrent->resume();
}
if (m_pDataSourcePropListener)
@@ -3239,14 +3226,7 @@ void DbGridControl::EndCursorAction()
void DbGridControl::ConnectToFields()
{
- ColumnFieldValueListeners* pListeners = static_cast<ColumnFieldValueListeners*>(m_pFieldListeners);
- DBG_ASSERT(!pListeners || pListeners->empty(), "DbGridControl::ConnectToFields : please call DisconnectFromFields first !");
-
- if (!pListeners)
- {
- pListeners = new ColumnFieldValueListeners;
- m_pFieldListeners = pListeners;
- }
+ DBG_ASSERT(m_aFieldListeners.empty(), "DbGridControl::ConnectToFields : please call DisconnectFromFields first !");
for (auto const & pCurrent : m_aColumns)
{
@@ -3259,7 +3239,7 @@ void DbGridControl::ConnectToFields()
continue;
// column is visible and bound here
- GridFieldValueListener*& rpListener = (*pListeners)[pCurrent->GetId()];
+ GridFieldValueListener*& rpListener = m_aFieldListeners[pCurrent->GetId()];
DBG_ASSERT(!rpListener, "DbGridControl::ConnectToFields : already a listener for this column ?!");
rpListener = new GridFieldValueListener(*this, xField, pCurrent->GetId());
}
@@ -3267,19 +3247,15 @@ void DbGridControl::ConnectToFields()
void DbGridControl::DisconnectFromFields()
{
- if (!m_pFieldListeners)
+ if (m_aFieldListeners.empty())
return;
- ColumnFieldValueListeners* pListeners = static_cast<ColumnFieldValueListeners*>(m_pFieldListeners);
- while (!pListeners->empty())
+ while (!m_aFieldListeners.empty())
{
- sal_Int32 nOldSize = pListeners->size();
- pListeners->begin()->second->dispose();
- DBG_ASSERT(nOldSize > static_cast<sal_Int32>(pListeners->size()), "DbGridControl::DisconnectFromFields : dispose on a listener should result in a removal from my list !");
+ sal_Int32 nOldSize = m_aFieldListeners.size();
+ m_aFieldListeners.begin()->second->dispose();
+ DBG_ASSERT(nOldSize > static_cast<sal_Int32>(m_aFieldListeners.size()), "DbGridControl::DisconnectFromFields : dispose on a listener should result in a removal from my list !");
}
-
- delete pListeners;
- m_pFieldListeners = nullptr;
}
void DbGridControl::FieldValueChanged(sal_uInt16 _nId)
@@ -3313,15 +3289,8 @@ void DbGridControl::FieldValueChanged(sal_uInt16 _nId)
void DbGridControl::FieldListenerDisposing(sal_uInt16 _nId)
{
- ColumnFieldValueListeners* pListeners = static_cast<ColumnFieldValueListeners*>(m_pFieldListeners);
- if (!pListeners)
- {
- OSL_FAIL("DbGridControl::FieldListenerDisposing : invalid call (have no listener array) !");
- return;
- }
-
- ColumnFieldValueListeners::const_iterator aPos = pListeners->find(_nId);
- if (aPos == pListeners->end())
+ auto aPos = m_aFieldListeners.find(_nId);
+ if (aPos == m_aFieldListeners.end())
{
OSL_FAIL("DbGridControl::FieldListenerDisposing : invalid call (did not find the listener) !");
return;
@@ -3329,7 +3298,7 @@ void DbGridControl::FieldListenerDisposing(sal_uInt16 _nId)
delete aPos->second;
- pListeners->erase(aPos);
+ m_aFieldListeners.erase(aPos);
}
void DbGridControl::disposing(sal_uInt16 _nId)