weld: Return std::unique_ptr in weld::ItemView::get_selected

So far, the method had a weld:::TreeView* out param
and a bool return value, which indicated whether
or not a selected item actually exists (and was
set in the passed TreeIter).

Drop the method param and instead return a
std::unique_ptr<weld::TreeIter>. If it doesn't
own a pointer, there is no selection (i.e. the
case previously indicated by a `false` return
value). If it owns a weld::TreeIter, then
that one points to the (first) selected item.

This simplifies using this as it is no longer
necessary to separately create weld::TreeIter to
pass as an out param first, e.g.

    std::unique_ptr<weld::TreeIter> pEntry = rMyIconView.make_iterator());
    if (rMyIconView.get_selected(xEntry.get()))
    {
        // do sth
    }

now turns into

    if (std::unique_ptr<weld::TreeIter> xEntry = rMyIconView->get_selected())
    {
        // do sth
    }

Adjust all callers accordingly.

It might be worth looking into doing something
similar for other methods (e.g.
weld::ItemView::get_iter_first) as well.

Change-Id: I83146fc8d68a92d50eed9bd635bf91b1450ce495
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196039
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Michael Weghorn
2025-12-22 09:18:39 +01:00
parent 4035f51534
commit 82edaf048b
58 changed files with 331 additions and 409 deletions
@@ -334,8 +334,7 @@ void CertificateViewerCertPathTP::ActivatePage()
IMPL_LINK_NOARG(CertificateViewerCertPathTP, ViewCertHdl, weld::Button&, void)
{
std::unique_ptr<weld::TreeIter> xIter = mxCertPathLB->make_iterator();
if (mxCertPathLB->get_selected(xIter.get()))
if (std::unique_ptr<weld::TreeIter> xIter = mxCertPathLB->get_selected())
{
if (mxCertificateViewer)
mxCertificateViewer->response(RET_OK);
@@ -351,9 +350,8 @@ IMPL_LINK_NOARG(CertificateViewerCertPathTP, CertSelectHdl, weld::TreeView&, voi
{
OUString sStatus;
std::unique_ptr<weld::TreeIter> xIter = mxCertPathLB->make_iterator();
bool bEntry = mxCertPathLB->get_selected(xIter.get());
if (bEntry)
std::unique_ptr<weld::TreeIter> xIter = mxCertPathLB->get_selected();
if (xIter)
{
CertPath_UserData* pData = weld::fromId<CertPath_UserData*>(mxCertPathLB->get_id(*xIter));
if (pData)
@@ -363,7 +361,7 @@ IMPL_LINK_NOARG(CertificateViewerCertPathTP, CertSelectHdl, weld::TreeView&, voi
mxCertStatusML->set_text(sStatus);
bool bSensitive = false;
if (bEntry)
if (xIter)
{
// if has children, so not the last one in the chain
if (mxCertPathLB->iter_children(*xIter))