vcl/inc/qt5/QtBuilder.hxx               |    6 +
 vcl/inc/qt5/QtInstanceMessageDialog.hxx |    2 
 vcl/qt5/QtBuilder.cxx                   |  155 ++++++++++++++++----------------
 vcl/qt5/QtInstanceMessageDialog.cxx     |   81 +++++++++-------
 4 files changed, 132 insertions(+), 112 deletions(-)

New commits:
commit 1f036a5cc7be95cd6e318e947193d426499de37e
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Feb 15 19:45:08 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Feb 16 11:13:03 2025 +0100

    tdf#130857 qt weld: Split QtBuilder::setProperties
    
    Split QtBuilder::setProperties into 4 more specific
    methods that handle particular widgets and call the
    methods right after the widgets have been created
    and no longer from QtBuilder::insertObject.
    
    This aligns this with how its already done for
    other widget types and removes the need to
    use qobject_cast, as the class is known at the
    point in time when the specific widgets are created.
    
    Change-Id: I230c07b97ea15cdc83ba0965f36496b930323860
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181723
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/vcl/inc/qt5/QtBuilder.hxx b/vcl/inc/qt5/QtBuilder.hxx
index f5a33571fbd8..35ebff8616ec 100644
--- a/vcl/inc/qt5/QtBuilder.hxx
+++ b/vcl/inc/qt5/QtBuilder.hxx
@@ -18,6 +18,7 @@
 #include <QtWidgets/QGridLayout>
 #include <QtWidgets/QMenu>
 #include <QtWidgets/QMessageBox>
+#include <QtWidgets/QPlainTextEdit>
 #include <QtWidgets/QPushButton>
 #include <QtWidgets/QSlider>
 #include <QtWidgets/QToolButton>
@@ -96,13 +97,16 @@ private:
     static void deleteObject(QObject* pObject);
     // remove pOldWidget from the widget hierarchy and set (child widget) 
pNewWidget in its place
     static void replaceWidget(QWidget* pOldWidget, QWidget* pNewWidget);
-    static void setProperties(QObject* obj, stringmap& rProps);
     void setButtonProperties(QAbstractButton& rButton, stringmap& rProps);
+    static void setCheckButtonProperties(QAbstractButton& rButton, stringmap& 
rProps);
+    static void setDialogProperties(QDialog& rDialog, stringmap& rProps);
     static void setEntryProperties(QLineEdit& rLineEdit, stringmap& rProps);
     static void setLabelProperties(QLabel& rLabel, stringmap& rProps);
+    static void setMessageDialogProperties(QMessageBox& rMessageBox, 
stringmap& rProps);
     void setMenuButtonProperties(QToolButton& rButton, stringmap& rProps);
     void setScaleProperties(QSlider& rSlider, stringmap& rProps);
     void setSpinButtonProperties(QDoubleSpinBox& rSpinBox, stringmap& rProps);
+    static void setTextViewProperties(QPlainTextEdit& rTextEdit, stringmap& 
rProps);
     static QWidget* windowForObject(QObject* pObject);
     static QDialogButtonBox* findButtonBox(QDialog* pDialog);
 
diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index 96de49e34bdf..a0ee0c4c9ded 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -31,7 +31,6 @@
 #include <QtWidgets/QLineEdit>
 #include <QtWidgets/QListView>
 #include <QtWidgets/QLayout>
-#include <QtWidgets/QPlainTextEdit>
 #include <QtWidgets/QProgressBar>
 #include <QtWidgets/QPushButton>
 #include <QtWidgets/QRadioButton>
@@ -102,8 +101,6 @@ QObject* QtBuilder::insertObject(QObject* pParent, const 
OUString& rClass, std::
 {
     QObject* pCurrentChild = makeObject(pParent, rClass, sType, rID, rProps);
 
-    setProperties(pCurrentChild, rProps);
-
     rProps.clear();
 
     return pCurrentChild;
@@ -131,7 +128,9 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, std:
 
     if (sName == u"GtkMessageDialog")
     {
-        pObject = new QMessageBox(pParentWidget);
+        QMessageBox* pMessageBox = new QMessageBox(pParentWidget);
+        setMessageDialogProperties(*pMessageBox, rMap);
+        pObject = pMessageBox;
     }
     else if (sName == u"GtkBox")
     {
@@ -201,7 +200,9 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, std:
     }
     else if (sName == u"GtkCheckButton")
     {
-        pObject = new QCheckBox(pParentWidget);
+        QCheckBox* pCheckBox = new QCheckBox(pParentWidget);
+        setCheckButtonProperties(*pCheckBox, rMap);
+        pObject = pCheckBox;
     }
     else if (sName == u"GtkComboBox" || sName == u"GtkComboBoxText")
     {
@@ -211,7 +212,9 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, std:
     }
     else if (sName == u"GtkDialog")
     {
-        pObject = new QDialog(pParentWidget);
+        QDialog* pDialog = new QDialog(pParentWidget);
+        setDialogProperties(*pDialog, rMap);
+        pObject = pDialog;
     }
     else if (sName == u"GtkDrawingArea")
     {
@@ -300,8 +303,11 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, std:
     }
     else if (sName == u"GtkRadioButton")
     {
-        pObject = new QRadioButton(pParentWidget);
+        QRadioButton* pRadioButton = new QRadioButton(pParentWidget);
+        // apply GtkCheckButton properties because GtkRadioButton subclasses 
GtkCheckButton in GTK 3
+        setCheckButtonProperties(*pRadioButton, rMap);
         extractRadioButtonGroup(sID, rMap);
+        pObject = pRadioButton;
     }
     else if (sName == u"GtkScrolledWindow")
     {
@@ -328,7 +334,9 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, std:
     }
     else if (sName == u"GtkTextView")
     {
-        pObject = new QPlainTextEdit(pParentWidget);
+        QPlainTextEdit* pTextEdit = new QPlainTextEdit(pParentWidget);
+        setTextViewProperties(*pTextEdit, rMap);
+        pObject = pTextEdit;
     }
     else if (sName == u"GtkToggleButton")
     {
@@ -734,70 +742,6 @@ void QtBuilder::replaceWidget(QWidget* pOldWidget, 
QWidget* pNewWidget)
     deleteObject(pOldWidget);
 }
 
-void QtBuilder::setProperties(QObject* pObject, stringmap& rProps)
-{
-    if (QMessageBox* pMessageBox = qobject_cast<QMessageBox*>(pObject))
-    {
-        for (auto const & [ rKey, rValue ] : rProps)
-        {
-            if (rKey == u"text")
-            {
-                pMessageBox->setText(toQString(rValue));
-            }
-            else if (rKey == u"title")
-            {
-                pMessageBox->setWindowTitle(toQString(rValue));
-            }
-            else if (rKey == u"secondary-text")
-            {
-                pMessageBox->setInformativeText(toQString(rValue));
-            }
-            else if (rKey == u"message-type")
-            {
-                if (rValue == u"error")
-                    pMessageBox->setIcon(QMessageBox::Critical);
-                else if (rValue == u"info")
-                    pMessageBox->setIcon(QMessageBox::Information);
-                else if (rValue == u"question")
-                    pMessageBox->setIcon(QMessageBox::Question);
-                else if (rValue == u"warning")
-                    pMessageBox->setIcon(QMessageBox::Warning);
-                else
-                    assert(false && "Unhandled message-type");
-            }
-        }
-    }
-    else if (qobject_cast<QCheckBox*>(pObject) || 
qobject_cast<QRadioButton*>(pObject))
-    {
-        QAbstractButton* pButton = static_cast<QAbstractButton*>(pObject);
-        for (auto const & [ rKey, rValue ] : rProps)
-        {
-            if (rKey == u"active")
-                pButton->setChecked(toBool(rValue));
-            else if (rKey == u"label")
-                pButton->setText(convertAccelerator(rValue));
-        }
-    }
-    else if (QDialog* pDialog = qobject_cast<QDialog*>(pObject))
-    {
-        for (auto const & [ rKey, rValue ] : rProps)
-        {
-            if (rKey == u"modal")
-                pDialog->setModal(toBool(rValue));
-            else if (rKey == u"title")
-                pDialog->setWindowTitle(toQString(rValue));
-        }
-    }
-    else if (QPlainTextEdit* pTextEdit = 
qobject_cast<QPlainTextEdit*>(pObject))
-    {
-        for (auto const & [ rKey, rValue ] : rProps)
-        {
-            if (rKey == u"accepts-tab")
-                pTextEdit->setTabChangesFocus(!toBool(rValue));
-        }
-    }
-}
-
 void QtBuilder::setButtonProperties(QAbstractButton& rButton, stringmap& 
rProps)
 {
     for (auto const & [ rKey, rValue ] : rProps)
@@ -821,6 +765,28 @@ void QtBuilder::setButtonProperties(QAbstractButton& 
rButton, stringmap& rProps)
     }
 }
 
+void QtBuilder::setCheckButtonProperties(QAbstractButton& rButton, stringmap& 
rProps)
+{
+    for (auto const & [ rKey, rValue ] : rProps)
+    {
+        if (rKey == u"active")
+            rButton.setChecked(toBool(rValue));
+        else if (rKey == u"label")
+            rButton.setText(convertAccelerator(rValue));
+    }
+}
+
+void QtBuilder::setDialogProperties(QDialog& rDialog, stringmap& rProps)
+{
+    for (auto const & [ rKey, rValue ] : rProps)
+    {
+        if (rKey == u"modal")
+            rDialog.setModal(toBool(rValue));
+        else if (rKey == u"title")
+            rDialog.setWindowTitle(toQString(rValue));
+    }
+}
+
 void QtBuilder::setEntryProperties(QLineEdit& rLineEdit, stringmap& rProps)
 {
     auto aIt = rProps.find(u"placeholder-text"_ustr);
@@ -856,6 +822,38 @@ void QtBuilder::setMenuButtonProperties(QToolButton& 
rButton, stringmap& rProps)
     setButtonProperties(rButton, rProps);
 }
 
+void QtBuilder::setMessageDialogProperties(QMessageBox& rMessageBox, 
stringmap& rProps)
+{
+    for (auto const & [ rKey, rValue ] : rProps)
+    {
+        if (rKey == u"text")
+        {
+            rMessageBox.setText(toQString(rValue));
+        }
+        else if (rKey == u"title")
+        {
+            rMessageBox.setWindowTitle(toQString(rValue));
+        }
+        else if (rKey == u"secondary-text")
+        {
+            rMessageBox.setInformativeText(toQString(rValue));
+        }
+        else if (rKey == u"message-type")
+        {
+            if (rValue == u"error")
+                rMessageBox.setIcon(QMessageBox::Critical);
+            else if (rValue == u"info")
+                rMessageBox.setIcon(QMessageBox::Information);
+            else if (rValue == u"question")
+                rMessageBox.setIcon(QMessageBox::Question);
+            else if (rValue == u"warning")
+                rMessageBox.setIcon(QMessageBox::Warning);
+            else
+                assert(false && "Unhandled message-type");
+        }
+    }
+}
+
 void QtBuilder::setScaleProperties(QSlider& rSlider, stringmap& rProps)
 {
     if (!hasOrientationVertical(rProps))
@@ -907,6 +905,15 @@ void QtBuilder::setSpinButtonProperties(QDoubleSpinBox& 
rSpinBox, stringmap& rPr
     }
 }
 
+void QtBuilder::setTextViewProperties(QPlainTextEdit& rTextEdit, stringmap& 
rProps)
+{
+    for (auto const & [ rKey, rValue ] : rProps)
+    {
+        if (rKey == u"accepts-tab")
+            rTextEdit.setTabChangesFocus(!toBool(rValue));
+    }
+}
+
 QWidget* QtBuilder::windowForObject(QObject* pObject)
 {
     if (QWidget* pWidget = qobject_cast<QWidget*>(pObject))
commit 580000aaade53c650e6da5a328f1bbc757d1ef78
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Feb 15 19:22:11 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Feb 16 11:12:56 2025 +0100

    tdf#130857 qt weld: Assign variable right away
    
    Change-Id: I1c98aef30bd263579e8c6e4bcfbaa5618bc00b5c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181722
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index cb0ceb0cda87..96de49e34bdf 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -100,9 +100,7 @@ void QtBuilder::insertComboBoxOrListBoxItems(QObject* 
pObject, stringmap& rMap,
 QObject* QtBuilder::insertObject(QObject* pParent, const OUString& rClass, 
std::string_view sType,
                                  const OUString& rID, stringmap& rProps, 
stringmap&, stringmap&)
 {
-    QObject* pCurrentChild = nullptr;
-
-    pCurrentChild = makeObject(pParent, rClass, sType, rID, rProps);
+    QObject* pCurrentChild = makeObject(pParent, rClass, sType, rID, rProps);
 
     setProperties(pCurrentChild, rProps);
 
commit 2ced62c97738b2a26e57285e3b1bf09d7fc0cf1d
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Feb 15 19:12:09 2025 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Feb 16 11:12:49 2025 +0100

    tdf#130857 qt weld: Extract logic to add buttons to static helper methods
    
    This is one step in preparation of reusing the logic in an upcoming
    commit to add support for the GtkMessageDialog:buttons property [1].
    
    [1] https://docs.gtk.org/gtk3/property.MessageDialog.buttons.html
    
    Change-Id: I19c59db5e403f07e5e50615c7cb705193dd0e72d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181721
    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 b2a366083457..ee996032949b 100644
--- a/vcl/inc/qt5/QtInstanceMessageDialog.hxx
+++ b/vcl/inc/qt5/QtInstanceMessageDialog.hxx
@@ -42,8 +42,10 @@ public:
     virtual int run() override;
 
     void addStandardButtons(VclButtonsType eButtonType);
+    static void addStandardButtons(QMessageBox& rMessageDialog, VclButtonsType 
eButtonType);
 
 private:
+    static void addButton(QMessageBox& rMessageDialog, const OUString& rText, 
int nResponse);
     void positionExtraControlsContainer();
     QPushButton* buttonForResponseCode(int nResponse);
 
diff --git a/vcl/qt5/QtInstanceMessageDialog.cxx 
b/vcl/qt5/QtInstanceMessageDialog.cxx
index b600879a08aa..92d8143056de 100644
--- a/vcl/qt5/QtInstanceMessageDialog.cxx
+++ b/vcl/qt5/QtInstanceMessageDialog.cxx
@@ -99,18 +99,7 @@ OUString QtInstanceMessageDialog::get_secondary_text() const
 
 void QtInstanceMessageDialog::add_button(const OUString& rText, int nResponse, 
const OUString&)
 {
-    SolarMutexGuard g;
-    QtInstance& rQtInstance = GetQtInstance();
-    if (!rQtInstance.IsMainThread())
-    {
-        rQtInstance.RunInMainThread([&] { add_button(rText, nResponse); });
-        return;
-    }
-
-    assert(m_pMessageDialog);
-    QPushButton* pButton = 
m_pMessageDialog->addButton(vclToQtStringWithAccelerator(rText),
-                                                       
QMessageBox::ButtonRole::ActionRole);
-    pButton->setProperty(PROPERTY_VCL_RESPONSE_CODE, 
QVariant::fromValue(nResponse));
+    addButton(*m_pMessageDialog, rText, nResponse);
 }
 
 void QtInstanceMessageDialog::set_default_response(int nResponse)
@@ -186,30 +175,50 @@ void QtInstanceMessageDialog::dialogFinished(int nResult)
 
 void QtInstanceMessageDialog::addStandardButtons(VclButtonsType eButtonType)
 {
-    switch (eButtonType)
-    {
-        case VclButtonsType::NONE:
-            break;
-        case VclButtonsType::Ok:
-            add_button(GetStandardText(StandardButtonType::OK), RET_OK);
-            break;
-        case VclButtonsType::Close:
-            add_button(GetStandardText(StandardButtonType::Close), RET_CLOSE);
-            break;
-        case VclButtonsType::Cancel:
-            add_button(GetStandardText(StandardButtonType::Cancel), 
RET_CANCEL);
-            break;
-        case VclButtonsType::YesNo:
-            add_button(GetStandardText(StandardButtonType::Yes), RET_YES);
-            add_button(GetStandardText(StandardButtonType::No), RET_NO);
-            break;
-        case VclButtonsType::OkCancel:
-            add_button(GetStandardText(StandardButtonType::OK), RET_OK);
-            add_button(GetStandardText(StandardButtonType::Cancel), 
RET_CANCEL);
-            break;
-        default:
-            assert(false && "Unhandled VCLButtonsType");
-    }
+    addStandardButtons(*m_pMessageDialog, eButtonType);
+}
+
+void QtInstanceMessageDialog::addStandardButtons(QMessageBox& rMessageDialog,
+                                                 VclButtonsType eButtonType)
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] {
+        switch (eButtonType)
+        {
+            case VclButtonsType::NONE:
+                break;
+            case VclButtonsType::Ok:
+                addButton(rMessageDialog, 
GetStandardText(StandardButtonType::OK), RET_OK);
+                break;
+            case VclButtonsType::Close:
+                addButton(rMessageDialog, 
GetStandardText(StandardButtonType::Close), RET_CLOSE);
+                break;
+            case VclButtonsType::Cancel:
+                addButton(rMessageDialog, 
GetStandardText(StandardButtonType::Cancel), RET_CANCEL);
+                break;
+            case VclButtonsType::YesNo:
+                addButton(rMessageDialog, 
GetStandardText(StandardButtonType::Yes), RET_YES);
+                addButton(rMessageDialog, 
GetStandardText(StandardButtonType::No), RET_NO);
+                break;
+            case VclButtonsType::OkCancel:
+                addButton(rMessageDialog, 
GetStandardText(StandardButtonType::OK), RET_OK);
+                addButton(rMessageDialog, 
GetStandardText(StandardButtonType::Cancel), RET_CANCEL);
+                break;
+            default:
+                assert(false && "Unhandled VCLButtonsType");
+        }
+    });
+}
+
+void QtInstanceMessageDialog::addButton(QMessageBox& rMessageDialog, const 
OUString& rText,
+                                        int nResponse)
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] {
+        QPushButton* pButton = 
rMessageDialog.addButton(vclToQtStringWithAccelerator(rText),
+                                                        
QMessageBox::ButtonRole::ActionRole);
+        pButton->setProperty(PROPERTY_VCL_RESPONSE_CODE, 
QVariant::fromValue(nResponse));
+    });
 }
 
 void QtInstanceMessageDialog::positionExtraControlsContainer()

Reply via email to