vcl/inc/qt5/QtInstanceMessageDialog.hxx | 3 +++ vcl/qt5/QtInstanceMessageDialog.cxx | 31 ++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 11 deletions(-)
New commits: commit 877075e3abe5378b359cf7f069a859b91eb2d6d7 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Tue Aug 6 15:04:57 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Aug 7 07:09:09 2024 +0200 tdf#162351 tdf#130857 qt weld: Extract helper function to get button ... for response code. The new helper method `QtInstanceMessageDialog::buttonForResponseCode` will be reused elsewhere in an upcoming commit. Change-Id: Ie7ee065fb68f936b79ac96ba70dc85ffa18c9859 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171550 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/inc/qt5/QtInstanceMessageDialog.hxx b/vcl/inc/qt5/QtInstanceMessageDialog.hxx index c12243b5945c..bc6971210e06 100644 --- a/vcl/inc/qt5/QtInstanceMessageDialog.hxx +++ b/vcl/inc/qt5/QtInstanceMessageDialog.hxx @@ -50,6 +50,9 @@ public: 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); }; diff --git a/vcl/qt5/QtInstanceMessageDialog.cxx b/vcl/qt5/QtInstanceMessageDialog.cxx index cbda4c6ae0dd..ec5761bca75a 100644 --- a/vcl/qt5/QtInstanceMessageDialog.cxx +++ b/vcl/qt5/QtInstanceMessageDialog.cxx @@ -62,17 +62,9 @@ void QtInstanceMessageDialog::set_default_response(int nResponse) { 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 = dynamic_cast<QPushButton*>(pAbstractButton); - assert(pButton); - m_pMessageDialog->setDefaultButton(pButton); - return; - } - } + QPushButton* pButton = buttonForResponseCode(nResponse); + if (pButton) + m_pMessageDialog->setDefaultButton(pButton); } int QtInstanceMessageDialog::run() @@ -144,4 +136,21 @@ void QtInstanceMessageDialog::dialogFinished(int nResult) xRunAsyncDialog.reset(); } +QPushButton* QtInstanceMessageDialog::buttonForResponseCode(int nResponse) +{ + 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 = dynamic_cast<QPushButton*>(pAbstractButton); + assert(pButton); + return pButton; + } + } + return nullptr; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */