vcl/inc/qt5/QtInstanceDialog.hxx | 7 ++++++- vcl/qt5/QtInstanceDialog.cxx | 32 ++++++++++++++++++++++++++++++-- vcl/qt5/QtInstanceMessageDialog.cxx | 22 +--------------------- 3 files changed, 37 insertions(+), 24 deletions(-)
New commits: commit d05936403f84bcab08a9811d0624877e7e4bdd8c Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Feb 22 21:11:20 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sun Feb 23 10:15:18 2025 +0100 tdf#130857 qt weld: Implement QtInstanceDialog::weld_button_for_response Change-Id: I16838459d981093a989eb500d8876c0b3d19d8eb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182044 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 753df37b04fa..dfc2ae8cdf9f 100644 --- a/vcl/inc/qt5/QtInstanceDialog.hxx +++ b/vcl/inc/qt5/QtInstanceDialog.hxx @@ -56,7 +56,7 @@ public: virtual void set_centered_on_parent(bool bTrackGeometryRequests) override; - virtual std::unique_ptr<weld::Button> weld_button_for_response(int) override; + virtual std::unique_ptr<weld::Button> weld_button_for_response(int nResponse) override; virtual void set_default_response(int) override; diff --git a/vcl/qt5/QtInstanceDialog.cxx b/vcl/qt5/QtInstanceDialog.cxx index df031f7bd8a3..3c49333a9af4 100644 --- a/vcl/qt5/QtInstanceDialog.cxx +++ b/vcl/qt5/QtInstanceDialog.cxx @@ -149,9 +149,22 @@ void QtInstanceDialog::set_centered_on_parent(bool) // QDialog is centered on parent toplevel by default } -std::unique_ptr<weld::Button> QtInstanceDialog::weld_button_for_response(int) +std::unique_ptr<weld::Button> QtInstanceDialog::weld_button_for_response(int nResponse) { - assert(false && "Not implemented yet"); + SolarMutexGuard g; + + QPushButton* pButton = nullptr; + GetQtInstance().RunInMainThread([&] { + if (QDialogButtonBox* pButtonBox = findButtonBox(m_pDialog)) + { + const QList<QAbstractButton*> aButtons = pButtonBox->buttons(); + pButton = buttonForResponseCode(aButtons, nResponse); + } + }); + + if (pButton) + return std::make_unique<QtInstanceButton>(pButton); + return nullptr; } commit 94e5e5ef062b05845f341f04dfe3508c76d6a206 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Sat Feb 22 21:07:00 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sun Feb 23 10:15:10 2025 +0100 tdf#130857 qt weld: Split QtInstanceMessageDialog::buttonForResponseCode Split the existing logic from QtInstanceMessageDialog::buttonForResponseCode into 2 methods: Extract a static helper method that takes a list of buttons as an additional parameter and move that one to the QtInstanceDialog base class, so it can be reused there in an upcoming commit. No longer explicitly make sure to run the QtInstanceMessageDialog::buttonForResponseCode logic in the main thread in that class, as that already happens in both callers. Change-Id: I0cbc73798caf4925496b2b26be73913dae4a89b7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182043 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/inc/qt5/QtInstanceDialog.hxx b/vcl/inc/qt5/QtInstanceDialog.hxx index b594606d89e7..753df37b04fa 100644 --- a/vcl/inc/qt5/QtInstanceDialog.hxx +++ b/vcl/inc/qt5/QtInstanceDialog.hxx @@ -13,6 +13,7 @@ #include <QtWidgets/QAbstractButton> #include <QtWidgets/QDialogButtonBox> +#include <QtWidgets/QPushButton> class QtInstanceDialog : public QtInstanceWindow, public virtual weld::Dialog { @@ -70,6 +71,10 @@ public: */ static const char* const PROPERTY_VCL_RESPONSE_CODE; +protected: + static QPushButton* buttonForResponseCode(const QList<QAbstractButton*>& rButtons, + int nResponse); + protected slots: virtual void dialogFinished(int nResult); }; diff --git a/vcl/qt5/QtInstanceDialog.cxx b/vcl/qt5/QtInstanceDialog.cxx index 98f3fb1bf744..df031f7bd8a3 100644 --- a/vcl/qt5/QtInstanceDialog.cxx +++ b/vcl/qt5/QtInstanceDialog.cxx @@ -223,6 +223,21 @@ QDialogButtonBox* QtInstanceDialog::findButtonBox(QDialog* pDialog) return nullptr; } +QPushButton* QtInstanceDialog::buttonForResponseCode(const QList<QAbstractButton*>& rButtons, + int nResponse) +{ + for (QAbstractButton* pAbstractButton : rButtons) + { + if (pAbstractButton->property(PROPERTY_VCL_RESPONSE_CODE).toInt() == nResponse) + { + QPushButton* pButton = qobject_cast<QPushButton*>(pAbstractButton); + assert(pButton); + return pButton; + } + } + return nullptr; +} + void QtInstanceDialog::handleButtonClick(QDialog& rDialog, QAbstractButton& rButton) { SolarMutexGuard g; diff --git a/vcl/qt5/QtInstanceMessageDialog.cxx b/vcl/qt5/QtInstanceMessageDialog.cxx index 92d8143056de..4b4e57716b82 100644 --- a/vcl/qt5/QtInstanceMessageDialog.cxx +++ b/vcl/qt5/QtInstanceMessageDialog.cxx @@ -277,28 +277,8 @@ void QtInstanceMessageDialog::positionExtraControlsContainer() QPushButton* QtInstanceMessageDialog::buttonForResponseCode(int nResponse) { - SolarMutexGuard g; - QtInstance& rQtInstance = GetQtInstance(); - if (!rQtInstance.IsMainThread()) - { - QPushButton* pButton; - rQtInstance.RunInMainThread([&] { pButton = buttonForResponseCode(nResponse); }); - return pButton; - } - - assert(m_pMessageDialog); - const QList<QAbstractButton*> aButtons = m_pMessageDialog->buttons(); - for (QAbstractButton* pAbstractButton : aButtons) - { - if (pAbstractButton->property(PROPERTY_VCL_RESPONSE_CODE).toInt() == nResponse) - { - QPushButton* pButton = qobject_cast<QPushButton*>(pAbstractButton); - assert(pButton); - return pButton; - } - } - return nullptr; + return QtInstanceDialog::buttonForResponseCode(aButtons, nResponse); } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */