vcl/qt5/QtInstanceTreeView.cxx |   56 ++++++++++++++++++++++++++++++-----------
 1 file changed, 41 insertions(+), 15 deletions(-)

New commits:
commit 0361f96e463e3db7d771fd9a30e3ae27b5a94ee8
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Apr 26 20:15:47 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Apr 27 07:25:23 2025 +0200

    tdf#130857 qt weld: Implement QtInstanceTreeView::iter_*
    
    Implement methods to get previous/next sibling, parent
    or first child.
    
    Change-Id: Icc32b980b595f23d727f0563afdad9e42a05d2b9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184677
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx
index 59988976cc9a..508c0ee73590 100644
--- a/vcl/qt5/QtInstanceTreeView.cxx
+++ b/vcl/qt5/QtInstanceTreeView.cxx
@@ -374,16 +374,24 @@ bool QtInstanceTreeView::get_iter_first(weld::TreeIter& 
rIter) const
     return aIndex.isValid();
 }
 
-bool QtInstanceTreeView::iter_next_sibling(weld::TreeIter&) const
+bool QtInstanceTreeView::iter_next_sibling(weld::TreeIter& rIter) const
 {
-    assert(false && "Not implemented yet");
-    return false;
+    QtInstanceTreeIter& rQtIter = static_cast<QtInstanceTreeIter&>(rIter);
+    const QModelIndex aIndex = rQtIter.modelIndex();
+    const QModelIndex aSiblingIndex = m_pModel->sibling(aIndex.row() + 1, 0, 
aIndex);
+    rQtIter.setModelIndex(aSiblingIndex);
+
+    return aSiblingIndex.isValid();
 }
 
-bool QtInstanceTreeView::iter_previous_sibling(weld::TreeIter&) const
+bool QtInstanceTreeView::iter_previous_sibling(weld::TreeIter& rIter) const
 {
-    assert(false && "Not implemented yet");
-    return false;
+    QtInstanceTreeIter& rQtIter = static_cast<QtInstanceTreeIter&>(rIter);
+    const QModelIndex aIndex = rQtIter.modelIndex();
+    const QModelIndex aSiblingIndex = m_pModel->sibling(aIndex.row() - 1, 0, 
aIndex);
+    rQtIter.setModelIndex(aSiblingIndex);
+
+    return aSiblingIndex.isValid();
 }
 
 bool QtInstanceTreeView::iter_next(weld::TreeIter&) const
@@ -398,16 +406,22 @@ bool QtInstanceTreeView::iter_previous(weld::TreeIter&) 
const
     return false;
 }
 
-bool QtInstanceTreeView::iter_children(weld::TreeIter&) const
+bool QtInstanceTreeView::iter_children(weld::TreeIter& rIter) const
 {
-    assert(false && "Not implemented yet");
-    return false;
+    QtInstanceTreeIter& rQtIter = static_cast<QtInstanceTreeIter&>(rIter);
+    const QModelIndex aChildIndex = m_pModel->index(0, 0, 
rQtIter.modelIndex());
+    rQtIter.setModelIndex(aChildIndex);
+
+    return aChildIndex.isValid();
 }
 
-bool QtInstanceTreeView::iter_parent(weld::TreeIter&) const
+bool QtInstanceTreeView::iter_parent(weld::TreeIter& rIter) const
 {
-    assert(false && "Not implemented yet");
-    return false;
+    QtInstanceTreeIter& rQtIter = static_cast<QtInstanceTreeIter&>(rIter);
+    const QModelIndex aParentIndex = rQtIter.modelIndex().parent();
+    rQtIter.setModelIndex(aParentIndex);
+
+    return aParentIndex.isValid();
 }
 
 int QtInstanceTreeView::get_iter_depth(const weld::TreeIter& rIter) const
commit 873e22528cf6749520fb7f03f58c4f52fbb9dc03
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Apr 26 19:33:56 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Apr 27 07:25:16 2025 +0200

    tdf#130857 qt weld: Implement QtInstanceTreeView::get_iter_depth
    
    The implementations in GtkInstanceTreeView::get_iter_depth
    and SalInstanceTreeView::get_iter_depth suggest that
    the iter depth for top-level items is 0 (not 1), so implement
    it likewise.
    
    Change-Id: I61d9700ddd47d2088823c6440d5a8c0d5194a1f7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184676
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx
index 1bf05b28eb59..59988976cc9a 100644
--- a/vcl/qt5/QtInstanceTreeView.cxx
+++ b/vcl/qt5/QtInstanceTreeView.cxx
@@ -410,10 +410,18 @@ bool QtInstanceTreeView::iter_parent(weld::TreeIter&) 
const
     return false;
 }
 
-int QtInstanceTreeView::get_iter_depth(const weld::TreeIter&) const
+int QtInstanceTreeView::get_iter_depth(const weld::TreeIter& rIter) const
 {
-    assert(false && "Not implemented yet");
-    return -1;
+    const QtInstanceTreeIter& rQtIter = static_cast<const 
QtInstanceTreeIter&>(rIter);
+    int nDepth = 0;
+    QModelIndex aParentIndex = rQtIter.modelIndex().parent();
+    while (aParentIndex.isValid())
+    {
+        nDepth++;
+        aParentIndex = aParentIndex.parent();
+    }
+
+    return nDepth;
 }
 
 int QtInstanceTreeView::get_iter_index_in_parent(const weld::TreeIter&) const
commit 8e5b08ad0e7c7c2e470f2dc927427eb620ce6dcf
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Apr 26 19:18:52 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Apr 27 07:25:10 2025 +0200

    tdf#130857 qt weld: Ensure tree view col count is same on all levels
    
    Other than GtkTreeModel, where the same columns are always
    used on all hierarchy levels, QAbstractItemModel allows
    that to differ on each level/for each parent.
    
    This was seen causing a crash in a WIP branch experimenting
    with adding support for the "Tools" -> "AutoText" dialog
    because
    
            const QModelIndex aIndex = modelIndex(nPos, 0, aParentIndex);
            QStandardItem* pItem = itemFromIndex(aIndex);
            if (pStr)
                pItem->setText(toQString(*pStr));
    
    inside QtInstanceTreeView::insert would result in
    trying to retrieve the index/item for column 0
    when there were actually no columns in the model
    for the non-top-level item.
    
    Make sure the amount of columns matches by inserting
    them when there are none yet.
    
    Change-Id: I3bca4eb2e036e682298db7a205279bfddf0e8805
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184675
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx
index d8b39479e879..1bf05b28eb59 100644
--- a/vcl/qt5/QtInstanceTreeView.cxx
+++ b/vcl/qt5/QtInstanceTreeView.cxx
@@ -56,6 +56,10 @@ void QtInstanceTreeView::insert(const weld::TreeIter* 
pParent, int nPos, const O
             nPos = m_pModel->rowCount(aParentIndex);
         m_pModel->insertRow(nPos, aParentIndex);
 
+        // ensure parent has same column count as top-level
+        if (aParentIndex.isValid() && m_pModel->columnCount(aParentIndex) == 0)
+            m_pModel->insertColumns(0, m_pModel->columnCount(), aParentIndex);
+
         const QModelIndex aIndex = modelIndex(nPos, 0, aParentIndex);
         QStandardItem* pItem = itemFromIndex(aIndex);
         if (pStr)

Reply via email to