vcl/CustomTarget_qt5_moc.mk             |    1 
 vcl/CustomTarget_qt6_moc.mk             |    1 
 vcl/inc/qt5/QtInstanceDialog.hxx        |   20 ++++++---
 vcl/inc/qt5/QtInstanceMessageDialog.hxx |   19 +-------
 vcl/qt5/QtInstanceDialog.cxx            |   71 ++++++++++++++++++++++++++++++--
 vcl/qt5/QtInstanceMessageDialog.cxx     |   68 +-----------------------------
 6 files changed, 91 insertions(+), 89 deletions(-)

New commits:
commit cb7e14bf370647a3fe618492ff79d0202c64c71f
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Oct 2 09:33:08 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Oct 2 13:15:38 2024 +0200

    tdf#130857 qt weld: Move runAsync logic to QtInstanceDialog
    
    Refactor the handling for running a QtInstanceMessageDialog
    asynchronously, and reuse the logic for the QtInstanceDialog
    base class:
    
    Move implementations for both QtInstanceMessageDialog::runAsync
    methods and the involved class members from QtInstanceMessageDialog
    to QtInstanceDialog.
    
    Split the previous logic from
    QtInstanceMessageDialog::dialogFinished into two methods:
    
    * move most of the logic as is to a new virtual slot
      in the base class, QtInstanceDialog::dialogFinished
    * override the base class implementation to get the
      response code from the actually clicked button
      via the PROPERTY_VCL_RESPONSE_CODE property
      set on that button, and call the base class
      method with that one.
    
    For QtInstanceDialog, there's no QDialog::clickedButton
    method that could be used to retrieve the clicked button,
    but it's also not needed there, because there a slot
    connected to the QAbstractButton::clicked signal that triggers
    closing the dialog, and passes the proper response code of the
    corresponding button already, see
    
        commit 08b55df5c9e42c1ccb78a156261811875629342a
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Sat Sep 28 00:32:15 2024 +0200
    
            tdf#130857 qt weld: Close dialog on button click
    
    With this commit in place, QtInstanceDialog can now
    also be run asynchronously, instead of the
    QtInstanceDialog::runAsync methods
    just returning true without doing anything.
    
    This will be needed e.g. when adding support for the
    "Tools" -> "Word Count" dialog in Writer.
    
    Change-Id: I4edb9443cb11d1dc831a18f708cdbdd67c239aa6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174374
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/inc/qt5/QtInstanceDialog.hxx b/vcl/inc/qt5/QtInstanceDialog.hxx
index 6c00df7181fb..16db9acd1d1e 100644
--- a/vcl/inc/qt5/QtInstanceDialog.hxx
+++ b/vcl/inc/qt5/QtInstanceDialog.hxx
@@ -17,15 +17,20 @@ class QtInstanceDialog : public QObject, public 
QtInstanceWindow, public virtual
 
     std::unique_ptr<QDialog> m_pDialog;
 
+    // the DialogController/Dialog/function passed to the runAsync variants
+    std::shared_ptr<weld::DialogController> m_xRunAsyncDialogController;
+    std::shared_ptr<weld::Dialog> m_xRunAsyncDialog;
+    std::function<void(sal_Int32)> m_aRunAsyncFunc;
+
 public:
     QtInstanceDialog(QDialog* pDialog);
     ~QtInstanceDialog();
 
-    virtual bool runAsync(std::shared_ptr<Dialog> const&,
-                          const std::function<void(sal_Int32)>&) override;
+    virtual bool runAsync(const std::shared_ptr<weld::DialogController>& 
rxOwner,
+                          const std::function<void(sal_Int32)>& func) override;
 
-    virtual bool runAsync(const std::shared_ptr<weld::DialogController>&,
-                          const std::function<void(sal_Int32)>&) override;
+    virtual bool runAsync(std::shared_ptr<Dialog> const& rxSelf,
+                          const std::function<void(sal_Int32)>& func) override;
 
     virtual void collapse(weld::Widget*, weld::Widget*) override;
 
@@ -55,6 +60,9 @@ public:
     * int VCL response code of that button.
     */
     static const char* const PROPERTY_VCL_RESPONSE_CODE;
+
+protected slots:
+    virtual void dialogFinished(int nResult);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/qt5/QtInstanceMessageDialog.hxx 
b/vcl/inc/qt5/QtInstanceMessageDialog.hxx
index ea532a6eabb2..a410a8fd5dfc 100644
--- a/vcl/inc/qt5/QtInstanceMessageDialog.hxx
+++ b/vcl/inc/qt5/QtInstanceMessageDialog.hxx
@@ -20,11 +20,6 @@ class QtInstanceMessageDialog : public QtInstanceDialog, 
public virtual weld::Me
 private:
     QMessageBox* m_pMessageDialog;
 
-    // the DialogController/Dialog/function passed to the runAsync variants
-    std::shared_ptr<weld::DialogController> m_xRunAsyncDialogController;
-    std::shared_ptr<weld::Dialog> m_xRunAsyncDialog;
-    std::function<void(sal_Int32)> m_aRunAsyncFunc;
-
 public:
     QtInstanceMessageDialog(QMessageBox* pMessageDialog);
 
@@ -44,17 +39,13 @@ public:
     virtual void set_default_response(int nResponse) override;
     QtInstanceButton* weld_widget_for_response(int nResponse) override;
     virtual int run() override;
-    virtual bool runAsync(std::shared_ptr<weld::DialogController> const& 
rxOwner,
-                          const std::function<void(sal_Int32)>& func) override;
-    virtual bool runAsync(std::shared_ptr<Dialog> const& rxSelf,
-                          const std::function<void(sal_Int32)>& func) override;
     virtual void response(int nResponse) override;
 
 private:
     virtual QPushButton* buttonForResponseCode(int nResponse);
 
-private slots:
-    void dialogFinished(int nResult);
+protected slots:
+    virtual void dialogFinished(int nResult) override;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/QtInstanceDialog.cxx b/vcl/qt5/QtInstanceDialog.cxx
index 7e905aff980c..6a8040cfbf2c 100644
--- a/vcl/qt5/QtInstanceDialog.cxx
+++ b/vcl/qt5/QtInstanceDialog.cxx
@@ -15,6 +15,7 @@ const char* const 
QtInstanceDialog::PROPERTY_VCL_RESPONSE_CODE = "response-code"
 QtInstanceDialog::QtInstanceDialog(QDialog* pDialog)
     : QtInstanceWindow(pDialog)
     , m_pDialog(pDialog)
+    , m_aRunAsyncFunc(nullptr)
 {
 }
 
@@ -24,15 +25,48 @@ QtInstanceDialog::~QtInstanceDialog()
     GetQtInstance().RunInMainThread([&] { m_pDialog.reset(); });
 }
 
-bool QtInstanceDialog::runAsync(std::shared_ptr<Dialog> const&,
-                                const std::function<void(sal_Int32)>&)
+bool QtInstanceDialog::runAsync(const std::shared_ptr<weld::DialogController>& 
rxOwner,
+                                const std::function<void(sal_Int32)>& func)
 {
+    SolarMutexGuard g;
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
+    {
+        bool bRet = false;
+        rQtInstance.RunInMainThread([&] { bRet = runAsync(rxOwner, func); });
+        return bRet;
+    }
+
+    assert(m_pDialog);
+
+    m_xRunAsyncDialogController = rxOwner;
+    m_aRunAsyncFunc = func;
+    connect(m_pDialog.get(), &QDialog::finished, this, 
&QtInstanceDialog::dialogFinished);
+    m_pDialog->open();
+
     return true;
 }
 
-bool QtInstanceDialog::runAsync(const std::shared_ptr<weld::DialogController>&,
-                                const std::function<void(sal_Int32)>&)
+bool QtInstanceDialog::runAsync(std::shared_ptr<Dialog> const& rxSelf,
+                                const std::function<void(sal_Int32)>& func)
 {
+    SolarMutexGuard g;
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
+    {
+        bool bRet;
+        rQtInstance.RunInMainThread([&] { bRet = runAsync(rxSelf, func); });
+        return bRet;
+    }
+
+    assert(m_pDialog);
+    assert(rxSelf.get() == this);
+
+    m_xRunAsyncDialog = rxSelf;
+    m_aRunAsyncFunc = func;
+    connect(m_pDialog.get(), &QDialog::finished, this, 
&QtInstanceDialog::dialogFinished);
+    m_pDialog->open();
+
     return true;
 }
 
@@ -95,4 +129,32 @@ void QtInstanceDialog::set_default_response(int) {}
 
 weld::Container* QtInstanceDialog::weld_content_area() { return nullptr; }
 
+void QtInstanceDialog::dialogFinished(int nResult)
+{
+    SolarMutexGuard g;
+    QtInstance& rQtInstance = GetQtInstance();
+    if (!rQtInstance.IsMainThread())
+    {
+        rQtInstance.RunInMainThread([&] { dialogFinished(nResult); });
+        return;
+    }
+
+    assert(m_aRunAsyncFunc);
+
+    disconnect(m_pDialog.get(), &QDialog::finished, this, 
&QtInstanceDialog::dialogFinished);
+
+    // use local variables for these, as members might have got de-allocated 
by the time they're reset
+    std::shared_ptr<weld::Dialog> xRunAsyncDialog = m_xRunAsyncDialog;
+    std::shared_ptr<weld::DialogController> xRunAsyncDialogController = 
m_xRunAsyncDialogController;
+    std::function<void(sal_Int32)> aFunc = m_aRunAsyncFunc;
+    m_aRunAsyncFunc = nullptr;
+    m_xRunAsyncDialogController.reset();
+    m_xRunAsyncDialog.reset();
+
+    aFunc(nResult);
+
+    xRunAsyncDialogController.reset();
+    xRunAsyncDialog.reset();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/QtInstanceMessageDialog.cxx 
b/vcl/qt5/QtInstanceMessageDialog.cxx
index a907f6740960..906c17bc3aec 100644
--- a/vcl/qt5/QtInstanceMessageDialog.cxx
+++ b/vcl/qt5/QtInstanceMessageDialog.cxx
@@ -15,7 +15,6 @@
 QtInstanceMessageDialog::QtInstanceMessageDialog(QMessageBox* pMessageDialog)
     : QtInstanceDialog(pMessageDialog)
     , m_pMessageDialog(pMessageDialog)
-    , m_aRunAsyncFunc(nullptr)
 {
     assert(m_pMessageDialog);
 }
@@ -146,51 +145,6 @@ int QtInstanceMessageDialog::run()
     return pClickedButton->property(PROPERTY_VCL_RESPONSE_CODE).toInt();
 }
 
-bool QtInstanceMessageDialog::runAsync(const 
std::shared_ptr<weld::DialogController>& rxOwner,
-                                       const std::function<void(sal_Int32)>& 
func)
-{
-    SolarMutexGuard g;
-    QtInstance& rQtInstance = GetQtInstance();
-    if (!rQtInstance.IsMainThread())
-    {
-        bool bRet = false;
-        rQtInstance.RunInMainThread([&] { bRet = runAsync(rxOwner, func); });
-        return bRet;
-    }
-
-    assert(m_pMessageDialog);
-
-    m_xRunAsyncDialogController = rxOwner;
-    m_aRunAsyncFunc = func;
-    connect(m_pMessageDialog, &QDialog::finished, this, 
&QtInstanceMessageDialog::dialogFinished);
-    m_pMessageDialog->open();
-
-    return true;
-}
-
-bool QtInstanceMessageDialog::runAsync(std::shared_ptr<Dialog> const& rxSelf,
-                                       const std::function<void(sal_Int32)>& 
func)
-{
-    SolarMutexGuard g;
-    QtInstance& rQtInstance = GetQtInstance();
-    if (!rQtInstance.IsMainThread())
-    {
-        bool bRet;
-        rQtInstance.RunInMainThread([&] { bRet = runAsync(rxSelf, func); });
-        return bRet;
-    }
-
-    assert(m_pMessageDialog);
-    assert(rxSelf.get() == this);
-
-    m_xRunAsyncDialog = rxSelf;
-    m_aRunAsyncFunc = func;
-    connect(m_pMessageDialog, &QDialog::finished, this, 
&QtInstanceMessageDialog::dialogFinished);
-    m_pMessageDialog->open();
-
-    return true;
-}
-
 void QtInstanceMessageDialog::response(int nResponse)
 {
     SolarMutexGuard g;
@@ -215,28 +169,12 @@ void QtInstanceMessageDialog::dialogFinished(int nResult)
         return;
     }
 
-    assert(m_aRunAsyncFunc);
-
-    disconnect(m_pMessageDialog, &QDialog::finished, this,
-               &QtInstanceMessageDialog::dialogFinished);
-
-    // use local variables for these, as members might have got de-allocated 
by the time they're reset
-    std::shared_ptr<weld::Dialog> xRunAsyncDialog = m_xRunAsyncDialog;
-    std::shared_ptr<weld::DialogController> xRunAsyncDialogController = 
m_xRunAsyncDialogController;
-    std::function<void(sal_Int32)> aFunc = m_aRunAsyncFunc;
-    m_aRunAsyncFunc = nullptr;
-    m_xRunAsyncDialogController.reset();
-    m_xRunAsyncDialog.reset();
-
     // if a button was clicked, use its response code, otherwise the passed one
-    int nRet = nResult;
+    int nResponseCode = nResult;
     if (QAbstractButton* pClickedButton = m_pMessageDialog->clickedButton())
-        nRet = pClickedButton->property(PROPERTY_VCL_RESPONSE_CODE).toInt();
-
-    aFunc(nRet);
+        nResponseCode = 
pClickedButton->property(PROPERTY_VCL_RESPONSE_CODE).toInt();
 
-    xRunAsyncDialogController.reset();
-    xRunAsyncDialog.reset();
+    QtInstanceDialog::dialogFinished(nResponseCode);
 }
 
 QPushButton* QtInstanceMessageDialog::buttonForResponseCode(int nResponse)
commit 169c56518e1213ea29b7ccbe746f75e5f13825a3
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Oct 2 09:13:05 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Oct 2 13:15:31 2024 +0200

    tdf#130857 qt weld: Let QtInstancDialog subclass QObject
    
    ... and add the Q_OBJECT macro, in preparation of moving
    some logic from the QtInstanceMessageDialog subclass
    to QtInstanceDialog for reuse.
    
    Change-Id: Iaf76ae3efb352dd04d15716174818e8a902a16cc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174373
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/CustomTarget_qt5_moc.mk b/vcl/CustomTarget_qt5_moc.mk
index deddf68a74b1..ec580d76358a 100644
--- a/vcl/CustomTarget_qt5_moc.mk
+++ b/vcl/CustomTarget_qt5_moc.mk
@@ -14,6 +14,7 @@ $(call gb_CustomTarget_get_target,vcl/qt5) : \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtFilePicker.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtFrame.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstance.moc \
+       $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceMessageDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtMainWindow.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtMenu.moc \
diff --git a/vcl/CustomTarget_qt6_moc.mk b/vcl/CustomTarget_qt6_moc.mk
index b8103a12e787..28fb0100f40e 100644
--- a/vcl/CustomTarget_qt6_moc.mk
+++ b/vcl/CustomTarget_qt6_moc.mk
@@ -14,6 +14,7 @@ $(call gb_CustomTarget_get_target,vcl/qt6) : \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtFilePicker.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtFrame.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstance.moc \
+       $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceMessageDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtMainWindow.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtMenu.moc \
diff --git a/vcl/inc/qt5/QtInstanceDialog.hxx b/vcl/inc/qt5/QtInstanceDialog.hxx
index dcfa0197aab0..6c00df7181fb 100644
--- a/vcl/inc/qt5/QtInstanceDialog.hxx
+++ b/vcl/inc/qt5/QtInstanceDialog.hxx
@@ -11,8 +11,10 @@
 
 #include "QtInstanceWindow.hxx"
 
-class QtInstanceDialog : public QtInstanceWindow, public virtual weld::Dialog
+class QtInstanceDialog : public QObject, public QtInstanceWindow, public 
virtual weld::Dialog
 {
+    Q_OBJECT
+
     std::unique_ptr<QDialog> m_pDialog;
 
 public:
diff --git a/vcl/inc/qt5/QtInstanceMessageDialog.hxx 
b/vcl/inc/qt5/QtInstanceMessageDialog.hxx
index 5c09d5090781..ea532a6eabb2 100644
--- a/vcl/inc/qt5/QtInstanceMessageDialog.hxx
+++ b/vcl/inc/qt5/QtInstanceMessageDialog.hxx
@@ -13,11 +13,9 @@
 #include "QtInstanceDialog.hxx"
 #include <QtWidgets/QMessageBox>
 
-class QtInstanceMessageDialog : public QObject,
-                                public QtInstanceDialog,
-                                public virtual weld::MessageDialog
+class QtInstanceMessageDialog : public QtInstanceDialog, public virtual 
weld::MessageDialog
 {
-    Q_OBJECT;
+    Q_OBJECT
 
 private:
     QMessageBox* m_pMessageDialog;
diff --git a/vcl/qt5/QtInstanceDialog.cxx b/vcl/qt5/QtInstanceDialog.cxx
index 2fd0e0900a31..7e905aff980c 100644
--- a/vcl/qt5/QtInstanceDialog.cxx
+++ b/vcl/qt5/QtInstanceDialog.cxx
@@ -8,6 +8,7 @@
  */
 
 #include <QtInstanceDialog.hxx>
+#include <QtInstanceDialog.moc>
 
 const char* const QtInstanceDialog::PROPERTY_VCL_RESPONSE_CODE = 
"response-code";
 

Reply via email to