vcl/inc/qt5/QtInstanceTreeView.hxx |    6 +-
 vcl/qt5/QtBuilder.cxx              |   13 ++++-
 vcl/qt5/QtInstanceBuilder.cxx      |    1 
 vcl/qt5/QtInstanceTreeView.cxx     |   93 +++++++++++++++++++++++++++++++------
 4 files changed, 96 insertions(+), 17 deletions(-)

New commits:
commit 5d94ffde5125960fff0c177635292b2de5e20d38
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Nov 29 15:44:55 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Nov 30 09:39:14 2024 +0100

    tdf#130857 qt weld: Support Calc's "Show Sheet" dialog
    
    This means that native Qt widgets are used for that dialog
    now when using the qt5 or qt6 VCL plugin and starting LO with
    environment variable SAL_VCL_QT_USE_WELDED_WIDGETS=1 set.
    
    This is the first supported dialog making use of
    weld::TreeView.
    
    To trigger the dialog:
    
    * start Calc
    * add more sheets
    * hide some of the sheets (e.g. by right-clicking them
      in the bar at the bottom, "Hide Sheet")
    * select "Sheet" -> "Show Sheet" in the menubar
    
    Change-Id: I4c4c0dca67dd6325f7145254f40452cc7000a783
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177542
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx
index d3239f5cb56b..c4c5caa375eb 100644
--- a/vcl/qt5/QtInstanceBuilder.cxx
+++ b/vcl/qt5/QtInstanceBuilder.cxx
@@ -58,6 +58,7 @@ bool QtInstanceBuilder::IsUIFileSupported(const OUString& 
rUIFile)
         u"modules/scalc/ui/inputstringdialog.ui"_ustr,
         u"modules/scalc/ui/insertcells.ui"_ustr,
         u"modules/scalc/ui/selectsource.ui"_ustr,
+        u"modules/scalc/ui/showsheetdialog.ui"_ustr,
         u"modules/schart/ui/insertaxisdlg.ui"_ustr,
         u"modules/smath/ui/alignmentdialog.ui"_ustr,
         u"modules/swriter/ui/endnotepage.ui"_ustr,
commit 5d8fb68823c3f6fdc0ab3d1abfac8c7283f22eb9
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Nov 29 15:44:47 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Nov 30 09:39:05 2024 +0100

    tdf#130857 qt weld: Implement basic tree view logic
    
    Implement a small subset of the QtInstanceTreeView
    methods - basically what is used by Calc's
    "Sheets" -> "Show Sheets" dialog for which
    support will be declared in an upcoming commit.
    
    In QtBuilder, ignore "GtkCellRendererText" and
    "GtkTreeSelection" objects, just as VclBuilder
    does.
    For now, also don't implement logic for handling
    "GtkTreeViewColumn" objects yet, but add a warning
    that this is still missing.
    
    Use QStandardItemModel for the tree view's
    model.
    
    For those methods where not all possible
    parameters are handled yet, add asserts
    that will trigger when called with currently
    still unsupported ones, so this can easily
    be identified when working on support for
    dialogs using more complex tree views in the
    future.
    
    QtInstanceTreeView::get_height_rows logic
    to return the required height to show n
    entries also still needs some thought, so the
    method simply warns and returns 0 for now, which
    means that the tree view might not be shown with
    the ideal initial height, but resizing the dialog
    is sufficient to work around that for now if needed.
    
    Change-Id: I13d9bd4a742c29a3dfc2c17b6c1a13f9fe40270e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177541
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/inc/qt5/QtInstanceTreeView.hxx 
b/vcl/inc/qt5/QtInstanceTreeView.hxx
index 5cd107dc4862..89959b08af7f 100644
--- a/vcl/inc/qt5/QtInstanceTreeView.hxx
+++ b/vcl/inc/qt5/QtInstanceTreeView.hxx
@@ -11,6 +11,7 @@
 
 #include "QtInstanceWidget.hxx"
 
+#include <QtGui/QStandardItemModel>
 #include <QtWidgets/QTreeView>
 
 class QtInstanceTreeView : public QObject, public QtInstanceWidget, public 
virtual weld::TreeView
@@ -18,6 +19,7 @@ class QtInstanceTreeView : public QObject, public 
QtInstanceWidget, public virtu
     Q_OBJECT
 
     QTreeView* m_pTreeView;
+    QStandardItemModel* m_pModel;
 
 public:
     QtInstanceTreeView(QTreeView* pTreeView);
@@ -37,10 +39,10 @@ public:
     virtual void set_clicks_to_toggle(int nToggleBehavior) override;
 
     virtual int get_selected_index() const override;
-    virtual void select(int pos) override;
+    virtual void select(int nPos) override;
     virtual void unselect(int pos) override;
     virtual void remove(int pos) override;
-    virtual OUString get_text(int row, int col = -1) const override;
+    virtual OUString get_text(int nRow, int nCol = -1) const override;
     virtual void set_text(int row, const OUString& rText, int col = -1) 
override;
     virtual void set_sensitive(int row, bool bSensitive, int col = -1) 
override;
     virtual bool get_sensitive(int row, int col) const override;
diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index 0cf1712073c6..d2835099ff9b 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -19,6 +19,7 @@
 #include <rtl/ustrbuf.hxx>
 #include <vcl/qt/QtUtils.hxx>
 
+#include <QtGui/QStandardItemModel>
 #include <QtWidgets/QCheckBox>
 #include <QtWidgets/QComboBox>
 #include <QtWidgets/QDialog>
@@ -106,6 +107,10 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, std:
     if (sName.empty())
         return nullptr;
 
+    // nothing to do for these
+    if (sName == u"GtkCellRendererText" || sName == u"GtkTreeSelection")
+        return nullptr;
+
     QWidget* pParentWidget = qobject_cast<QWidget*>(pParent);
     QLayout* pParentLayout = qobject_cast<QLayout*>(pParent);
 
@@ -283,7 +288,13 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, std:
     }
     else if (sName == u"GtkTreeView")
     {
-        pObject = new QTreeView(pParentWidget);
+        QTreeView* pTreeView = new QTreeView(pParentWidget);
+        pTreeView->setModel(new QStandardItemModel(pTreeView));
+        pObject = pTreeView;
+    }
+    else if (sName == u"GtkTreeViewColumn")
+    {
+        SAL_WARN("vcl.qt", "GtkTreeViewColumn properties not evaluated yet");
     }
     else
     {
diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx
index 7cda3a3694ad..e570e38a4537 100644
--- a/vcl/qt5/QtInstanceTreeView.cxx
+++ b/vcl/qt5/QtInstanceTreeView.cxx
@@ -17,12 +17,42 @@ QtInstanceTreeView::QtInstanceTreeView(QTreeView* pTreeView)
     , m_pTreeView(pTreeView)
 {
     assert(m_pTreeView);
-}
 
-void QtInstanceTreeView::insert(const weld::TreeIter*, int, const OUString*, 
const OUString*,
-                                const OUString*, VirtualDevice*, bool, 
weld::TreeIter*)
-{
-    assert(false && "Not implemented yet");
+    m_pModel = qobject_cast<QStandardItemModel*>(m_pTreeView->model());
+    assert(m_pModel && "tree view doesn't have expected item model set");
+}
+
+void QtInstanceTreeView::insert(const weld::TreeIter* pParent, int pos, const 
OUString* pStr,
+                                const OUString* pId, const OUString* pIconName,
+                                VirtualDevice* pImageSurface, bool 
bChildrenOnDemand,
+                                weld::TreeIter* pRet)
+{
+    // Only specific subset of parameters handled so far;
+    // assert only these are used at the moment and implement remaining cases
+    // when needed to support more dialogs, then adjust/remove asserts below
+    assert(!pParent && "Not implemented yet");
+    assert(pos == -1 && "Not implemented yet");
+    assert(!pId && "Not implemented yet");
+    assert(!pIconName && "Not implemented yet");
+    assert(!pImageSurface && "Not implemented yet");
+    assert(!bChildrenOnDemand && "Not implemented yet");
+    assert(!pRet && "Not implemented yet");
+    // avoid -Werror=unused-parameter for release build
+    (void)pParent;
+    (void)pos;
+    (void)pId;
+    (void)pIconName;
+    (void)pImageSurface;
+    (void)bChildrenOnDemand;
+    (void)pRet;
+
+    assert(pStr && "No string passed, which is currently the only 
supported/implemented case");
+
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] {
+        QStandardItem* pItem = new QStandardItem(toQString(*pStr));
+        m_pModel->appendRow(pItem);
+    });
 }
 
 void QtInstanceTreeView::insert_separator(int, const OUString&)
@@ -55,16 +85,36 @@ int QtInstanceTreeView::get_selected_index() const
     return -1;
 }
 
-void QtInstanceTreeView::select(int) { assert(false && "Not implemented yet"); 
}
+void QtInstanceTreeView::select(int nPos)
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] {
+        QItemSelectionModel* pSelectionModel = m_pTreeView->selectionModel();
+        assert(pSelectionModel);
+        pSelectionModel->select(m_pModel->index(nPos, 0), 
QItemSelectionModel::Select);
+    });
+}
 
 void QtInstanceTreeView::unselect(int) { assert(false && "Not implemented 
yet"); }
 
 void QtInstanceTreeView::remove(int) { assert(false && "Not implemented yet"); 
}
 
-OUString QtInstanceTreeView::get_text(int, int) const
+OUString QtInstanceTreeView::get_text(int nRow, int nCol) const
 {
-    assert(false && "Not implemented yet");
-    return OUString();
+    assert(nCol == -1 && "Column support not implemented yet");
+    (void)nCol; // for release build
+
+    SolarMutexGuard g;
+
+    OUString sText;
+    GetQtInstance().RunInMainThread([&] {
+        const QModelIndex aIndex = m_pModel->index(nRow, 0);
+        const QVariant aData = m_pModel->data(aIndex);
+        assert(aData.canConvert<QString>() && "model data not a string");
+        sText = toOUString(aData.toString());
+    });
+
+    return sText;
 }
 
 void QtInstanceTreeView::set_text(int, const OUString&, int)
@@ -125,8 +175,19 @@ void QtInstanceTreeView::swap(int, int) { assert(false && 
"Not implemented yet")
 
 std::vector<int> QtInstanceTreeView::get_selected_rows() const
 {
-    assert(false && "Not implemented yet");
-    return std::vector<int>();
+    SolarMutexGuard g;
+
+    std::vector<int> aSelectedRows;
+
+    GetQtInstance().RunInMainThread([&] {
+        QItemSelectionModel* pSelectionModel = m_pTreeView->selectionModel();
+        assert(pSelectionModel);
+        const QModelIndexList aSelectionIndexes = 
pSelectionModel->selection().indexes();
+        for (const QModelIndex& aIndex : aSelectionIndexes)
+            aSelectedRows.push_back(aIndex.row());
+    });
+
+    return aSelectedRows;
 }
 
 void QtInstanceTreeView::set_font_color(int, const Color&)
@@ -441,8 +502,12 @@ void 
QtInstanceTreeView::enable_drag_source(rtl::Reference<TransferDataContainer
 
 int QtInstanceTreeView::n_children() const
 {
-    assert(false && "Not implemented yet");
-    return 0;
+    SolarMutexGuard g;
+
+    int nChildCount;
+    GetQtInstance().RunInMainThread(
+        [&] { nChildCount = 
m_pModel->rowCount(m_pModel->invisibleRootItem()->index()); });
+    return nChildCount;
 }
 
 void QtInstanceTreeView::make_sorted() { assert(false && "Not implemented 
yet"); }
@@ -480,7 +545,7 @@ void QtInstanceTreeView::clear() { assert(false && "Not 
implemented yet"); }
 
 int QtInstanceTreeView::get_height_rows(int) const
 {
-    assert(false && "Not implemented yet");
+    SAL_WARN("vcl.qt", "QtInstanceTreeView::get_height_rows just returns 0 for 
now");
     return 0;
 }
 

Reply via email to