vcl/inc/qt5/QtBuilder.hxx |    1 +
 vcl/qt5/QtBuilder.cxx     |   25 ++++++++++++++-----------
 2 files changed, 15 insertions(+), 11 deletions(-)

New commits:
commit a43d2aa3bc063d264b5d0a968664f0edb4eedf9f
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Nov 8 22:19:59 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Nov 9 19:02:48 2024 +0100

    tdf#130857 qt weld: Extract setting label props
    
    Move logic to set "GtkLabel" properties on
    a QLabel to a new helper method
    QtBuilder::setLabelProperties and call it right
    after creating the QLabel for a "GtkLabel", and only
    for that case.
    
    This also prevents potentially overwriting the
    text of a QtHyperlinkLabel widget created for a
    "GtkLinkButton" object in a .ui file, as that
    class also derives from QLabel, but has specialized
    handling for setting the label text to be a hyperlink.
    
    Change-Id: I8bfcc31a503a1c9deec32bcd584e1a86c3dfff19
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176296
    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 a3faaa84a0ab..d77ada13bea4 100644
--- a/vcl/inc/qt5/QtBuilder.hxx
+++ b/vcl/inc/qt5/QtBuilder.hxx
@@ -73,6 +73,7 @@ public:
 
 private:
     void setProperties(QObject* obj, stringmap& rProps);
+    static void setLabelProperties(QLabel& rLabel, stringmap& rProps);
     void setSpinButtonProperties(QDoubleSpinBox& rSpinBox, 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 1b219567c199..b5838e191bfa 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -221,8 +221,10 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, cons
     }
     else if (sName == u"GtkLabel")
     {
+        QLabel* pLabel = new QLabel(pParentWidget);
+        setLabelProperties(*pLabel, rMap);
         extractMnemonicWidget(sID, rMap);
-        pObject = new QLabel(pParentWidget);
+        pObject = pLabel;
     }
     else if (sName == u"GtkLevelBar" || sName == u"GtkProgressBar")
     {
@@ -519,16 +521,6 @@ void QtBuilder::setProperties(QObject* pObject, stringmap& 
rProps)
                 pDialog->setWindowTitle(toQString(rValue));
         }
     }
-    else if (QLabel* pLabel = qobject_cast<QLabel*>(pObject))
-    {
-        for (auto const & [ rKey, rValue ] : rProps)
-        {
-            if (rKey == u"label")
-                pLabel->setText(convertAccelerator(rValue));
-            else if (rKey == u"wrap")
-                pLabel->setWordWrap(toBool(rValue));
-        }
-    }
     else if (QPlainTextEdit* pTextEdit = 
qobject_cast<QPlainTextEdit*>(pObject))
     {
         for (auto const & [ rKey, rValue ] : rProps)
@@ -563,6 +555,17 @@ void QtBuilder::setProperties(QObject* pObject, stringmap& 
rProps)
     }
 }
 
+void QtBuilder::setLabelProperties(QLabel& rLabel, stringmap& rProps)
+{
+    for (auto const & [ rKey, rValue ] : rProps)
+    {
+        if (rKey == u"label")
+            rLabel.setText(convertAccelerator(rValue));
+        else if (rKey == u"wrap")
+            rLabel.setWordWrap(toBool(rValue));
+    }
+}
+
 void QtBuilder::setSpinButtonProperties(QDoubleSpinBox& rSpinBox, stringmap& 
rProps)
 {
     auto aDigitsIt = rProps.find(u"digits"_ustr);

Reply via email to