summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-09-18 19:54:27 +0100
committerCaolán McNamara <caolanm@redhat.com>2020-09-19 13:17:50 +0200
commit798ee4543a91f16340f9962b36bccd1446ccdb7f (patch)
tree1b9e988db4322e3d8ab1f85349397a00d9681da2 /sc/source
parent3b99840fde960b68c53308a56b05ad713e632b5b (diff)
tdf#136559 use freeze+all_foreach for performance
doesn't do much for the gtk case due to https://gitlab.gnome.org/GNOME/gtk/-/issues/2693 but has an impact on the vcl case CheckAllChildren is then never called with a null pParent so simplify it based on that Change-Id: I3ae639aa70c7fca5eae9d2a7257cf39e7ce79e72 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103018 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/ui/cctrl/checklistmenu.cxx42
-rw-r--r--sc/source/ui/inc/checklistmenu.hxx4
2 files changed, 25 insertions, 21 deletions
diff --git a/sc/source/ui/cctrl/checklistmenu.cxx b/sc/source/ui/cctrl/checklistmenu.cxx
index 9a9259f9f796..57167b5bbe95 100644
--- a/sc/source/ui/cctrl/checklistmenu.cxx
+++ b/sc/source/ui/cctrl/checklistmenu.cxx
@@ -579,7 +579,12 @@ void ScCheckListMenuControl::prepWindow()
void ScCheckListMenuControl::setAllMemberState(bool bSet)
{
- CheckAllChildren(nullptr, bSet);
+ mxChecks->freeze();
+ mxChecks->all_foreach([this, bSet](weld::TreeIter& rEntry){
+ mxChecks->set_toggle(rEntry, bSet ? TRISTATE_TRUE : TRISTATE_FALSE);
+ return false;
+ });
+ mxChecks->thaw();
if (!maConfig.mbAllowEmptySet)
{
@@ -747,7 +752,7 @@ IMPL_LINK( ScCheckListMenuControl, CheckHdl, const weld::TreeView::iter_col&, rR
void ScCheckListMenuControl::Check(const weld::TreeIter* pEntry)
{
if (pEntry)
- CheckEntry(pEntry, mxChecks->get_toggle(*pEntry) == TRISTATE_TRUE);
+ CheckEntry(*pEntry, mxChecks->get_toggle(*pEntry) == TRISTATE_TRUE);
size_t nNumChecked = GetCheckedEntryCount();
if (nNumChecked == maMembers.size())
// all members visible
@@ -987,33 +992,32 @@ void ScCheckListMenuControl::CheckEntry(const OUString& sName, const weld::TreeI
{
std::unique_ptr<weld::TreeIter> xEntry = FindEntry(pParent, sName);
if (xEntry)
- CheckEntry(xEntry.get(), bCheck);
+ CheckEntry(*xEntry, bCheck);
}
-// Recursively check all children of pParent
-void ScCheckListMenuControl::CheckAllChildren(const weld::TreeIter* pParent, bool bCheck)
+// Recursively check all children of rParent
+void ScCheckListMenuControl::CheckAllChildren(const weld::TreeIter& rParent, bool bCheck)
{
- if (pParent)
- mxChecks->set_toggle(*pParent, bCheck ? TRISTATE_TRUE : TRISTATE_FALSE);
- std::unique_ptr<weld::TreeIter> xEntry = mxChecks->make_iterator(pParent);
- bool bEntry = pParent ? mxChecks->iter_children(*xEntry) : mxChecks->get_iter_first(*xEntry);
+ mxChecks->set_toggle(rParent, bCheck ? TRISTATE_TRUE : TRISTATE_FALSE);
+ std::unique_ptr<weld::TreeIter> xEntry = mxChecks->make_iterator(&rParent);
+ bool bEntry = mxChecks->iter_children(*xEntry);
while (bEntry)
{
- CheckAllChildren(xEntry.get(), bCheck);
+ CheckAllChildren(*xEntry, bCheck);
bEntry = mxChecks->iter_next_sibling(*xEntry);
}
}
-void ScCheckListMenuControl::CheckEntry(const weld::TreeIter* pParent, bool bCheck)
+void ScCheckListMenuControl::CheckEntry(const weld::TreeIter& rParent, bool bCheck)
{
- // recursively check all items below pParent
- CheckAllChildren(pParent, bCheck);
- // checking pParent can affect ancestors, e.g. if ancestor is unchecked and pParent is
+ // recursively check all items below rParent
+ CheckAllChildren(rParent, bCheck);
+ // checking rParent can affect ancestors, e.g. if ancestor is unchecked and rParent is
// now checked then the ancestor needs to be checked also
- if (!(pParent && mxChecks->get_iter_depth(*pParent)))
+ if (!mxChecks->get_iter_depth(rParent))
return;
- std::unique_ptr<weld::TreeIter> xAncestor(mxChecks->make_iterator(pParent));
+ std::unique_ptr<weld::TreeIter> xAncestor(mxChecks->make_iterator(&rParent));
bool bAncestor = mxChecks->iter_parent(*xAncestor);
while (bAncestor)
{
@@ -1086,7 +1090,7 @@ std::unique_ptr<weld::TreeIter> ScCheckListMenuControl::ShowCheckEntry(const OUS
mxChecks->set_text(*xEntry, sName, 0);
}
else
- CheckEntry(xEntry.get(), bCheck);
+ CheckEntry(*xEntry, bCheck);
}
else if (xEntry)
{
@@ -1130,7 +1134,7 @@ IMPL_LINK(ScCheckListMenuControl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
if (bEntry)
{
bool bOldCheck = mxChecks->get_toggle(*xEntry) == TRISTATE_TRUE;
- CheckEntry(xEntry.get(), !bOldCheck);
+ CheckEntry(*xEntry, !bOldCheck);
bool bNewCheck = mxChecks->get_toggle(*xEntry) == TRISTATE_TRUE;
if (bOldCheck != bNewCheck)
Check(xEntry.get());
@@ -1193,7 +1197,7 @@ size_t ScCheckListMenuControl::initMembers(int nMaxMemberWidth)
{
CheckEntry(maMembers[i].maName, maMembers[i].mxParent.get(), maMembers[i].mbVisible);
// Expand first node of checked dates
- if (!maMembers[i].mxParent && IsChecked(maMembers[i].maName, maMembers[i].mxParent.get()))
+ if (!maMembers[i].mxParent && IsChecked(maMembers[i].maName, maMembers[i].mxParent.get()))
{
std::unique_ptr<weld::TreeIter> xDateEntry = FindEntry(nullptr, maMembers[i].maName);
if (xDateEntry)
diff --git a/sc/source/ui/inc/checklistmenu.hxx b/sc/source/ui/inc/checklistmenu.hxx
index f407bc96c3e3..a74775453933 100644
--- a/sc/source/ui/inc/checklistmenu.hxx
+++ b/sc/source/ui/inc/checklistmenu.hxx
@@ -181,12 +181,12 @@ private:
std::unique_ptr<weld::TreeIter> ShowCheckEntry(const OUString& sName, ScCheckListMember& rMember, bool bShow = true, bool bCheck = true);
void CheckEntry(const OUString& sName, const weld::TreeIter* pParent, bool bCheck);
- void CheckEntry(const weld::TreeIter* pEntry, bool bCheck);
+ void CheckEntry(const weld::TreeIter& rEntry, bool bCheck);
void GetRecursiveChecked(const weld::TreeIter* pEntry, std::unordered_set<OUString>& vOut, OUString& rLabel);
std::unordered_set<OUString> GetAllChecked();
bool IsChecked(const OUString& sName, const weld::TreeIter* pParent);
int GetCheckedEntryCount() const;
- void CheckAllChildren(const weld::TreeIter* pEntry, bool bCheck);
+ void CheckAllChildren(const weld::TreeIter& rEntry, bool bCheck);
void setSelectedMenuItem(size_t nPos, bool bSubMenuTimer);