summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolan.mcnamara@collabora.com>2023-06-05 20:15:16 +0100
committerCaolán McNamara <caolan.mcnamara@collabora.com>2023-06-06 18:01:31 +0200
commit4df278b4a98637aa5050abfd752eae0a9081b752 (patch)
tree6e5baa87f2e49daccc7e40403ca9df4733df1267 /vcl
parent9b03f778adfb87a10d781860930ed4d09410af9c (diff)
perf: cache the generated json for an iconview image
before: |--13.95%--JSDialogNotifyIdle::Invoke | | | |--13.01%--JSDialogNotifyIdle::generateWidgetUpdate | | | | | |--11.03%--IconView::DumpAsPropertyTree | | | lcl_DumpEntryAndSiblings (inlined) | | | | | | | |--10.94%--extractPngString (inlined) after: |--4.86%--JSDialogNotifyIdle::Invoke ... | |--2.90%--JSDialogNotifyIdle::generateWidgetUpdate | | | | | |--0.76%--IconView::DumpAsPropertyTree | | | IconView::DumpEntryAndSiblings | | | Link<std::tuple<tools::JsonWriter&, rtl::OUString const&, std::basic_string_view<char, std::char_traits<char> > > const&, bool>::Call (inlined) | | | StylesPreviewWindow_Base::DoJsonProperty | | | | | | | |--0.55%--StylesPreviewWindow_Base::GetCachedPreviewJson Change-Id: Id234a84e36710794822945584be3adf028808625 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152630 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/iconview.hxx8
-rw-r--r--vcl/inc/salvtables.hxx3
-rw-r--r--vcl/source/app/salvtables.cxx6
-rw-r--r--vcl/source/treelist/iconview.cxx28
-rw-r--r--vcl/unx/gtk3/gtkinst.cxx5
5 files changed, 39 insertions, 11 deletions
diff --git a/vcl/inc/iconview.hxx b/vcl/inc/iconview.hxx
index c5ece6d4aeb1..bc84a6ea436d 100644
--- a/vcl/inc/iconview.hxx
+++ b/vcl/inc/iconview.hxx
@@ -20,6 +20,7 @@
#ifndef INCLUDED_SVTOOLS_ICONVIEW_HXX
#define INCLUDED_SVTOOLS_ICONVIEW_HXX
+#include <tools/json_writer.hxx>
#include <vcl/toolkit/treelistbox.hxx>
class IconView final : public SvTreeListBox
@@ -47,11 +48,18 @@ public:
virtual FactoryFunction GetUITestFactory() const override;
virtual void DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) override;
+ void SetDumpElemToPropertyTreeHdl(const Link<const tools::json_prop_query&, bool>& rLink)
+ {
+ maDumpElemToPropertyTreeHdl = rLink;
+ }
+
protected:
virtual void CalcEntryHeight(SvTreeListEntry const* pEntry) override;
private:
Link<SvTreeListEntry*, OUString> maEntryAccessibleDescriptionHdl;
+ Link<const tools::json_prop_query&, bool> maDumpElemToPropertyTreeHdl;
+ void DumpEntryAndSiblings(tools::JsonWriter& rJsonWriter, SvTreeListEntry* pEntry);
};
#endif
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index 096675cf9a49..65d9b4cb1a47 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -1942,6 +1942,9 @@ public:
virtual void connect_query_tooltip(const Link<const weld::TreeIter&, OUString>& rLink) override;
+ virtual void
+ connect_get_property_tree_elem(const Link<const tools::json_prop_query&, bool>& rLink) override;
+
virtual OUString get_selected_id() const override;
virtual OUString get_selected_text() const override;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index f01c28219142..1ea5c985ecc2 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -5532,6 +5532,12 @@ void SalInstanceIconView::connect_query_tooltip(const Link<const weld::TreeIter&
m_xIconView->SetTooltipHdl(LINK(this, SalInstanceIconView, TooltipHdl));
}
+void SalInstanceIconView::connect_get_property_tree_elem(
+ const Link<const tools::json_prop_query&, bool>& rLink)
+{
+ m_xIconView->SetDumpElemToPropertyTreeHdl(rLink);
+}
+
OUString SalInstanceIconView::get_selected_id() const
{
assert(m_xIconView->IsUpdateMode() && "don't request selection when frozen");
diff --git a/vcl/source/treelist/iconview.cxx b/vcl/source/treelist/iconview.cxx
index 568e1070545d..6ff3a3556967 100644
--- a/vcl/source/treelist/iconview.cxx
+++ b/vcl/source/treelist/iconview.cxx
@@ -278,8 +278,7 @@ static OString extractPngString(const SvLBoxContextBmp* pBmpItem)
return "";
}
-static void lcl_DumpEntryAndSiblings(tools::JsonWriter& rJsonWriter, SvTreeListEntry* pEntry,
- const SvTreeListBox* pTabListBox)
+void IconView::DumpEntryAndSiblings(tools::JsonWriter& rJsonWriter, SvTreeListEntry* pEntry)
{
while (pEntry)
{
@@ -290,24 +289,31 @@ static void lcl_DumpEntryAndSiblings(tools::JsonWriter& rJsonWriter, SvTreeListE
if (pIt)
rJsonWriter.put("text", static_cast<const SvLBoxString*>(pIt)->GetText());
- pIt = pEntry->GetFirstItem(SvLBoxItemType::ContextBmp);
- if (pIt)
+ const OUString* pId = static_cast<const OUString*>(pEntry->GetUserData());
+ const bool bHandled = pId && maDumpElemToPropertyTreeHdl.IsSet()
+ && maDumpElemToPropertyTreeHdl.Call(
+ tools::json_prop_query(rJsonWriter, *pId, "image"));
+ if (!bHandled)
{
- const SvLBoxContextBmp* pBmpItem = static_cast<const SvLBoxContextBmp*>(pIt);
- if (pBmpItem)
- rJsonWriter.put("image", extractPngString(pBmpItem));
+ pIt = pEntry->GetFirstItem(SvLBoxItemType::ContextBmp);
+ if (pIt)
+ {
+ const SvLBoxContextBmp* pBmpItem = static_cast<const SvLBoxContextBmp*>(pIt);
+ if (pBmpItem)
+ rJsonWriter.put("image", extractPngString(pBmpItem));
+ }
}
- if (const OUString tooltip = pTabListBox->GetEntryTooltip(pEntry); !tooltip.isEmpty())
+ if (const OUString tooltip = GetEntryTooltip(pEntry); !tooltip.isEmpty())
rJsonWriter.put("tooltip", tooltip);
- if (pTabListBox->IsSelected(pEntry))
+ if (IsSelected(pEntry))
rJsonWriter.put("selected", true);
if (pEntry->GetFlags() & SvTLEntryFlags::IS_SEPARATOR)
rJsonWriter.put("separator", true);
- rJsonWriter.put("row", pTabListBox->GetModel()->GetAbsPos(pEntry));
+ rJsonWriter.put("row", GetModel()->GetAbsPos(pEntry));
pEntry = pEntry->NextSibling();
}
@@ -319,7 +325,7 @@ void IconView::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter)
rJsonWriter.put("type", "iconview");
rJsonWriter.put("singleclickactivate", GetActivateOnSingleClick());
auto aNode = rJsonWriter.startArray("entries");
- lcl_DumpEntryAndSiblings(rJsonWriter, First(), this);
+ DumpEntryAndSiblings(rJsonWriter, First());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 29c95858e87f..9ba8d6caa8f8 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -17035,6 +17035,11 @@ public:
gtk_widget_set_has_tooltip(GTK_WIDGET(m_pIconView), true);
}
+ virtual void connect_get_property_tree_elem(const Link<const tools::json_prop_query&, bool>& /*rLink*/) override
+ {
+ //not implemented for the gtk variant
+ }
+
virtual OUString get_selected_id() const override
{
assert(gtk_icon_view_get_model(m_pIconView) && "don't request selection when frozen");