include/vcl/weld.hxx               |    8 ++++----
 vcl/inc/qt5/QtInstanceIconView.hxx |    3 +++
 vcl/inc/qt5/QtInstanceTreeView.hxx |    3 +++
 vcl/inc/salvtables.hxx             |    6 ++++++
 vcl/qt5/QtInstanceIconView.cxx     |   12 ++++++++++++
 vcl/qt5/QtInstanceTreeView.cxx     |   16 ++++++++++++++--
 vcl/source/app/salvtables.cxx      |    8 ++++++++
 vcl/unx/gtk3/gtkinst.cxx           |    8 ++++++++
 8 files changed, 58 insertions(+), 6 deletions(-)

New commits:
commit 83e63f8e052f7d567e097a5a30d616e6ee61b815
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Feb 21 19:07:22 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Feb 22 10:54:49 2025 +0100

    tdf#130857 weld: Make {Icon,Tree}View::{,un}select_all purely virtual
    
    No longer let the base class implementation
    `weld::TreeView::select_all()` call `weld::Treeview::unselect(-1)`
    and similar, but make them purely virtual and implement in
    the subclasses instead.
    
    This introduces a working implementation for QtInstanceTreeView,
    where the special value of -1 wasn't handled in the `select()` and
    `unselect()` implementations.
    (It also doesn't feel very "natural"/obvious to me and wasn't explicitly
    documented for `select` and `unselect`.)
    
    For the GTK and VCL implementation, leave the logic as it was
    for maximum backward compatibility for now.
    
    I noticed this in a WIP branch declaring support for
    the "Tools" -> "Spelling" -> "Options" -> "Edit" dialog in Writer
    where typing a new word not yet in the list would not result in
    the previously selected word in the treeview to become unselected
    despite SvxEditDictionaryDialog::ModifyHdl calling
    
        m_pWordsLB->unselect_all();
    
    Change-Id: I2f681e2297a553beedd10fd7054adc539ac13ddc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182013
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 638d5d5e3f70..85ac1f11964d 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -1344,8 +1344,8 @@ public:
     void connect_drag_begin(const Link<bool&, bool>& rLink) { m_aDragBeginHdl 
= rLink; }
 
     //all of them. Don't select when frozen, select after thaw. Note selection 
doesn't survive a freeze.
-    void select_all() { unselect(-1); }
-    void unselect_all() { select(-1); }
+    virtual void select_all() = 0;
+    virtual void unselect_all() = 0;
 
     // return the number of toplevel nodes
     virtual int n_children() const = 0;
@@ -1537,8 +1537,8 @@ public:
     virtual void selected_foreach(const std::function<bool(TreeIter&)>& func) 
= 0;
 
     //all of them. Don't select when frozen, select after thaw. Note selection 
doesn't survive a freeze.
-    void select_all() { unselect(-1); }
-    void unselect_all() { select(-1); }
+    virtual void select_all() = 0;
+    virtual void unselect_all() = 0;
 
     // return the number of toplevel nodes
     virtual int n_children() const = 0;
diff --git a/vcl/inc/qt5/QtInstanceIconView.hxx 
b/vcl/inc/qt5/QtInstanceIconView.hxx
index dd2126c83e4a..6bc4aed56a7b 100644
--- a/vcl/inc/qt5/QtInstanceIconView.hxx
+++ b/vcl/inc/qt5/QtInstanceIconView.hxx
@@ -67,6 +67,9 @@ public:
 
     virtual void selected_foreach(const std::function<bool(weld::TreeIter&)>& 
func) override;
 
+    virtual void select_all() override;
+    virtual void unselect_all() override;
+
     virtual int n_children() const override;
 
     virtual bool eventFilter(QObject* pObject, QEvent* pEvent) override;
diff --git a/vcl/inc/qt5/QtInstanceTreeView.hxx 
b/vcl/inc/qt5/QtInstanceTreeView.hxx
index 59574cd75eee..ce6c6b9b8cad 100644
--- a/vcl/inc/qt5/QtInstanceTreeView.hxx
+++ b/vcl/inc/qt5/QtInstanceTreeView.hxx
@@ -143,6 +143,9 @@ public:
     virtual void enable_drag_source(rtl::Reference<TransferDataContainer>& 
rTransferable,
                                     sal_uInt8 eDNDConstants) override;
 
+    virtual void select_all() override;
+    virtual void unselect_all() override;
+
     virtual int n_children() const override;
 
     virtual void make_sorted() override;
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index f9793e2d6771..20fc7cf064ef 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -1645,6 +1645,9 @@ public:
 
     virtual void clear() override;
 
+    virtual void select_all() override;
+    virtual void unselect_all() override;
+
     virtual int n_children() const override;
 
     virtual int iter_n_children(const weld::TreeIter& rIter) const override;
@@ -1957,6 +1960,9 @@ public:
 
     virtual void unselect(int pos) override;
 
+    virtual void select_all() override;
+    virtual void unselect_all() override;
+
     virtual int n_children() const override;
 
     virtual std::unique_ptr<weld::TreeIter> make_iterator(const 
weld::TreeIter* pOrig
diff --git a/vcl/qt5/QtInstanceIconView.cxx b/vcl/qt5/QtInstanceIconView.cxx
index 2642d3636bf4..068dded10330 100644
--- a/vcl/qt5/QtInstanceIconView.cxx
+++ b/vcl/qt5/QtInstanceIconView.cxx
@@ -268,6 +268,18 @@ void QtInstanceIconView::selected_foreach(const 
std::function<bool(weld::TreeIte
     assert(false && "Not implemented yet");
 }
 
+void QtInstanceIconView::select_all()
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { m_pListView->selectAll(); });
+}
+
+void QtInstanceIconView::unselect_all()
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { m_pListView->clearSelection(); });
+}
+
 int QtInstanceIconView::n_children() const
 {
     SolarMutexGuard g;
diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx
index 1bd484f79e62..4cabfa4662b8 100644
--- a/vcl/qt5/QtInstanceTreeView.cxx
+++ b/vcl/qt5/QtInstanceTreeView.cxx
@@ -729,6 +729,18 @@ void 
QtInstanceTreeView::enable_drag_source(rtl::Reference<TransferDataContainer
     assert(false && "Not implemented yet");
 }
 
+void QtInstanceTreeView::select_all()
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { m_pTreeView->selectAll(); });
+}
+
+void QtInstanceTreeView::unselect_all()
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { m_pTreeView->clearSelection(); });
+}
+
 int QtInstanceTreeView::n_children() const
 {
     SolarMutexGuard g;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 0b24c467a368..3c66d4a2284e 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -4164,6 +4164,10 @@ void SalInstanceTreeView::clear()
     enable_notify_events();
 }
 
+void SalInstanceTreeView::select_all() { unselect(-1); }
+
+void SalInstanceTreeView::unselect_all() { select(-1); }
+
 int SalInstanceTreeView::n_children() const
 {
     return m_xTreeView->GetModel()->GetChildList(nullptr).size();
@@ -5622,6 +5626,10 @@ void SalInstanceIconView::unselect(int pos)
     enable_notify_events();
 }
 
+void SalInstanceIconView::select_all() { unselect(-1); }
+
+void SalInstanceIconView::unselect_all() { select(-1); }
+
 int SalInstanceIconView::n_children() const
 {
     return m_xIconView->GetModel()->GetChildList(nullptr).size();
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index bd6de88d7c77..74a7df140d44 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -15513,6 +15513,10 @@ public:
         gtk_tree_sortable_sort_column_changed(pSortable);
     }
 
+    virtual void select_all() override { unselect(-1); }
+
+    virtual void unselect_all() override { select(-1); }
+
     virtual int n_children() const override
     {
         return gtk_tree_model_iter_n_children(m_pTreeModel, nullptr);
@@ -17563,6 +17567,10 @@ public:
         g_list_free_full(pList, 
reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
     }
 
+    virtual void select_all() override { unselect(-1); }
+
+    virtual void unselect_all() override { select(-1); }
+
     virtual int n_children() const override
     {
         return gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_pTreeStore), 
nullptr);
commit d08b41c6708e0b469af10a0d61617213b2cd8900
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Feb 21 18:33:51 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Feb 22 10:54:41 2025 +0100

    tdf#130857 qt weld: Don't assert text has been set when getting it
    
    If QStandardItemModel::data returns a QVariant that cannot
    be converted to QString (most likely an invalid QVariant
    because no data has explicitly been set), simply return an empty
    string QtInstanceTreeView::get_text and don't assert.
    
    This assert was e.g. triggered for the "Tools" -> "Spelling"
    -> "Options" -> "Edit" dialog in Writer in a WIP branch
    where support for that dialog is declared.
    
    Change-Id: Ic5782c418758becdc636356c13ab878f5fd2f007
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182012
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx
index b7bb97e0593e..1bd484f79e62 100644
--- a/vcl/qt5/QtInstanceTreeView.cxx
+++ b/vcl/qt5/QtInstanceTreeView.cxx
@@ -175,8 +175,8 @@ OUString QtInstanceTreeView::get_text(int nRow, int nCol) 
const
         const QModelIndex aIndex
             = nCol == -1 ? firstTextColumnModelIndex(nRow) : modelIndex(nRow, 
nCol);
         const QVariant aData = m_pModel->data(aIndex);
-        assert(aData.canConvert<QString>() && "model data not a string");
-        sText = toOUString(aData.toString());
+        if (aData.canConvert<QString>())
+            sText = toOUString(aData.toString());
     });
 
     return sText;

Reply via email to