vcl/inc/qt5/QtInstanceDialog.hxx |    4 ++++
 vcl/inc/qt5/QtInstanceWidget.hxx |    4 +++-
 vcl/qt5/QtBuilder.cxx            |   19 ++++++++-----------
 vcl/qt5/QtInstance.cxx           |    5 +++++
 vcl/qt5/QtInstanceDialog.cxx     |   11 +++++++++++
 vcl/qt5/QtInstanceWidget.cxx     |   31 +++++++++++++++++++++++++++++--
 6 files changed, 60 insertions(+), 14 deletions(-)

New commits:
commit 1d4b1feeb47bddd1743c7080dd8bd778fa770ede
Author:     Michael Weghorn <[email protected]>
AuthorDate: Fri Oct 4 14:41:29 2024 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Sat Oct 5 09:38:54 2024 +0200

    tdf#130857 qt weld: Handle help ID
    
    Implement handling for the help ID by using a
    new property PROPERTY_HELP_ID that is set
    on the QtInstanceWidget's QWidget.
    
    Implement QtInstanceWidget::set_help_id
    and QtInstanceWidget::get_help_id accordingly.
    
    For setting the ID, introduce and use a static
    helper method QtInstanceWidget::setHelpId
    and use that in QtBuilder::makeObject to
    set the help ID based on help root and widget
    ID, in line with what is done at the end of
    VclBuilder::makeObject for the vcl::Window-based
    builder.
    
    Change-Id: I274886d8045b31ccbc92f586e2ead20ff7407d15
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174481
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/vcl/inc/qt5/QtInstanceWidget.hxx b/vcl/inc/qt5/QtInstanceWidget.hxx
index e1dda3f11772..a6fbfc06950d 100644
--- a/vcl/inc/qt5/QtInstanceWidget.hxx
+++ b/vcl/inc/qt5/QtInstanceWidget.hxx
@@ -68,7 +68,7 @@ public:
 
     virtual void set_buildable_name(const OUString&) override;
 
-    virtual void set_help_id(const OUString&) override;
+    virtual void set_help_id(const OUString& rHelpId) override;
 
     virtual OUString get_help_id() const override;
 
@@ -176,6 +176,8 @@ public:
     virtual void set_background(const Color&) override;
 
     virtual void draw(OutputDevice&, const Point&, const Size&) override;
+
+    static void setHelpId(QWidget& rWidget, const OUString& rHelpId);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index 0ada179178e2..ad402df02043 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -165,6 +165,8 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, cons
         if (pParentLayout)
             pParentLayout->addWidget(pWidget);
 
+        QtInstanceWidget::setHelpId(*pWidget, getHelpRoot() + sID);
+
 #if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0)
         // Set GtkBuilder ID as accessible ID
         pWidget->setAccessibleIdentifier(toQString(sID));
diff --git a/vcl/qt5/QtInstanceWidget.cxx b/vcl/qt5/QtInstanceWidget.cxx
index e0060ebc4905..3338fcb35c73 100644
--- a/vcl/qt5/QtInstanceWidget.cxx
+++ b/vcl/qt5/QtInstanceWidget.cxx
@@ -11,6 +11,9 @@
 
 #include <vcl/transfer.hxx>
 
+/** Name of QObject property used for the help ID. */
+const char* const PROPERTY_HELP_ID = "help-id";
+
 QtInstanceWidget::QtInstanceWidget(QWidget* pWidget)
     : m_pWidget(pWidget)
 {
@@ -197,9 +200,33 @@ OUString QtInstanceWidget::get_buildable_name() const { 
return OUString(); }
 
 void QtInstanceWidget::set_buildable_name(const OUString&) {}
 
-void QtInstanceWidget::set_help_id(const OUString&) {}
+void QtInstanceWidget::setHelpId(QWidget& rWidget, const OUString& rHelpId)
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread(
+        [&] { rWidget.setProperty(PROPERTY_HELP_ID, toQString(rHelpId)); });
+}
+
+void QtInstanceWidget::set_help_id(const OUString& rHelpId) { 
setHelpId(*m_pWidget, rHelpId); }
+
+OUString QtInstanceWidget::get_help_id() const
+{
+    SolarMutexGuard g;
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
+    {
+        OUString sHelpId;
+        rQtInstance.RunInMainThread([&] { sHelpId = get_help_id(); });
+        return sHelpId;
+    }
+
+    const QVariant aHelpIdVariant = m_pWidget->property(PROPERTY_HELP_ID);
+    if (!aHelpIdVariant.isValid())
+        return OUString();
 
-OUString QtInstanceWidget::get_help_id() const { return OUString(); }
+    assert(aHelpIdVariant.canConvert<QString>());
+    return toOUString(aHelpIdVariant.toString());
+}
 
 void QtInstanceWidget::set_grid_left_attach(int) {}
 
commit fe39249c795446641e83c06d49ac3c9e196fd660
Author:     Michael Weghorn <[email protected]>
AuthorDate: Fri Oct 4 13:44:48 2024 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Sat Oct 5 09:38:46 2024 +0200

    qt: Add SolarMutexGuard in QtInstance::CreateFrame etc.
    
    These methods call QtInstance::RunInMainThread,
    so must hold the solar mutex, see the call to
    
        DBG_TESTSOLARMUTEX();
    
    at the very beginning of that method.
    
    (I've seen QtInstance::CreateFrame getting
    called without the mutex held in a WIP branch
    to add support for the "Help" button for
    native (welded) Qt dialogs.)
    
    Change-Id: I46adb708a84c031d63d94768c7600cbf3940ad21
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174480
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/vcl/qt5/QtInstance.cxx b/vcl/qt5/QtInstance.cxx
index b8ce2a796c81..8a0ace0509f9 100644
--- a/vcl/qt5/QtInstance.cxx
+++ b/vcl/qt5/QtInstance.cxx
@@ -332,6 +332,7 @@ void QtInstance::deleteObjectLater(QObject* pObject) { 
pObject->deleteLater(); }
 
 SalFrame* QtInstance::CreateChildFrame(SystemParentData* /*pParent*/, 
SalFrameStyleFlags nStyle)
 {
+    SolarMutexGuard aGuard;
     SalFrame* pRet(nullptr);
     RunInMainThread([&, this]() { pRet = new QtFrame(nullptr, nStyle, 
useCairo()); });
     assert(pRet);
@@ -340,6 +341,8 @@ SalFrame* QtInstance::CreateChildFrame(SystemParentData* 
/*pParent*/, SalFrameSt
 
 SalFrame* QtInstance::CreateFrame(SalFrame* pParent, SalFrameStyleFlags nStyle)
 {
+    SolarMutexGuard aGuard;
+
     assert(!pParent || dynamic_cast<QtFrame*>(pParent));
 
     SalFrame* pRet(nullptr);
@@ -360,6 +363,8 @@ void QtInstance::DestroyFrame(SalFrame* pFrame)
 
 SalObject* QtInstance::CreateObject(SalFrame* pParent, SystemWindowData*, bool 
bShow)
 {
+    SolarMutexGuard aGuard;
+
     assert(!pParent || dynamic_cast<QtFrame*>(pParent));
 
     SalObject* pRet(nullptr);
commit 115e812175ecc5c057bb265a97a8a4582c14bbb6
Author:     Michael Weghorn <[email protected]>
AuthorDate: Fri Oct 4 12:50:10 2024 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Sat Oct 5 09:38:39 2024 +0200

    tdf#130857 qt weld: Move button clicked logic to QtInstanceDialog
    
    Move the logic to close the dialog with the corresponding
    respone code when a button gets clicked from
    an anonymous lambda function in QtBuilder::tweakInsertedChild
    to a new static helper method in QtInstanceButton:
    QtInstanceDialog::handleButtonClick
    
    This is in preparation of adding special handling for the
    "Help" button in an upcoming commit, which - unlike other
    buttons - should not just close the dialog with a corresponding
    response code.
    
    Change-Id: Idfd08d90df930a25437f99a609a38804bf80bff7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174479
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/vcl/inc/qt5/QtInstanceDialog.hxx b/vcl/inc/qt5/QtInstanceDialog.hxx
index 16db9acd1d1e..aa0027ac75a6 100644
--- a/vcl/inc/qt5/QtInstanceDialog.hxx
+++ b/vcl/inc/qt5/QtInstanceDialog.hxx
@@ -11,6 +11,8 @@
 
 #include "QtInstanceWindow.hxx"
 
+#include <QtWidgets/QAbstractButton>
+
 class QtInstanceDialog : public QObject, public QtInstanceWindow, public 
virtual weld::Dialog
 {
     Q_OBJECT
@@ -55,6 +57,8 @@ public:
 
     virtual weld::Container* weld_content_area() override;
 
+    static void handleButtonClick(QDialog& rDialog, const QAbstractButton& 
rButton);
+
     /**
     * Name of the property to set on a QPushButton that holds the
     * int VCL response code of that button.
diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index c342e33d253b..0ada179178e2 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -217,20 +217,15 @@ void QtBuilder::tweakInsertedChild(QObject* pParent, 
QObject* pCurrentChild, std
                 pLayout->removeWidget(pButtonBox);
                 pLayout->addWidget(pButtonBox);
 
-                // let button click close dialog if response code is set
+                // connect button click handler
                 const QList<QAbstractButton*> aButtons = pButtonBox->buttons();
                 for (const QAbstractButton* pButton : aButtons)
                 {
-                    QVariant aResponseProperty
-                        = 
pButton->property(QtInstanceDialog::PROPERTY_VCL_RESPONSE_CODE);
-                    if (aResponseProperty.isValid())
-                    {
-                        assert(aResponseProperty.canConvert<int>());
-                        const int nResponseCode = aResponseProperty.toInt();
-                        QObject::connect(
-                            pButton, &QAbstractButton::clicked, pDialog,
-                            [pDialog, nResponseCode] { 
pDialog->done(nResponseCode); });
-                    }
+                    assert(pButton);
+                    QObject::connect(pButton, &QAbstractButton::clicked, 
pDialog,
+                                     [pDialog, pButton] {
+                                         
QtInstanceDialog::handleButtonClick(*pDialog, *pButton);
+                                     });
                 }
             }
         }
diff --git a/vcl/qt5/QtInstanceDialog.cxx b/vcl/qt5/QtInstanceDialog.cxx
index 6a8040cfbf2c..99e90f3548fb 100644
--- a/vcl/qt5/QtInstanceDialog.cxx
+++ b/vcl/qt5/QtInstanceDialog.cxx
@@ -157,4 +157,15 @@ void QtInstanceDialog::dialogFinished(int nResult)
     xRunAsyncDialog.reset();
 }
 
+void QtInstanceDialog::handleButtonClick(QDialog& rDialog, const 
QAbstractButton& rButton)
+{
+    QVariant aResponseProperty = 
rButton.property(QtInstanceDialog::PROPERTY_VCL_RESPONSE_CODE);
+    if (aResponseProperty.isValid())
+    {
+        assert(aResponseProperty.canConvert<int>());
+        const int nResponseCode = aResponseProperty.toInt();
+        rDialog.done(nResponseCode);
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to