include/vcl/builderbase.hxx   |    2 ++
 vcl/qt5/QtBuilder.cxx         |   22 +++++++++++++++++++---
 vcl/source/window/builder.cxx |   26 +++++++++++++-------------
 3 files changed, 34 insertions(+), 16 deletions(-)

New commits:
commit 8bcdd32f2fbb8825564ec4eeabe1d6f3eed808ce
Author:     Michael Weghorn <[email protected]>
AuthorDate: Thu Oct 24 18:22:43 2024 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Fri Oct 25 08:57:58 2024 +0200

    tdf#130857 qt weld: Handle combobox entries from .ui file
    
    Implement handling for combobox items in
    QtBuilder::insertComboBoxOrListBoxItems, similar
    to the VCL implementation in , similar
    to what's done in VclBuilder::insertComboBoxOrListBoxItems.
    
    This will be used e.g. by the "File" -> "Export As" ->
    "Export as EPUB" dialog
    (writerperfect/uiconfig/ui/exportepub.ui).
    
    Change-Id: Ie7a0f17c1a8ad523ca55c09dfce65a0b5d9cc41b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175572
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index 3013cf48e4b4..cd59a1f8d3fb 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -55,10 +55,26 @@ QObject* QtBuilder::get_by_name(std::u16string_view sID)
     return nullptr;
 }
 
-void QtBuilder::insertComboBoxOrListBoxItems(QObject*, stringmap&,
-                                             const 
std::vector<ComboBoxTextItem>&)
+void QtBuilder::insertComboBoxOrListBoxItems(QObject* pObject, stringmap& rMap,
+                                             const 
std::vector<ComboBoxTextItem>& rItems)
 {
-    assert(false && "comboboxes and list boxes are not supported yet");
+    if (QComboBox* pComboBox = qobject_cast<QComboBox*>(pObject))
+    {
+        for (const ComboBoxTextItem& rItem : rItems)
+        {
+            QVariant aUserData;
+            if (!rItem.m_sId.isEmpty())
+                aUserData = QVariant::fromValue(toQString(rItem.m_sId));
+
+            pComboBox->addItem(toQString(rItem.m_sItem), aUserData);
+        }
+
+        const int nActiveId = BuilderBase::extractActive(rMap);
+        pComboBox->setCurrentIndex(nActiveId);
+        return;
+    }
+
+    assert(false && "list boxes are not supported yet");
 }
 
 QObject* QtBuilder::insertObject(QObject* pParent, const OUString& rClass, 
const OUString& rID,
commit 05a38a21092c063126d6923d0dfb47ba5d39d5c2
Author:     Michael Weghorn <[email protected]>
AuthorDate: Thu Oct 24 18:12:52 2024 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Fri Oct 25 08:57:51 2024 +0200

    tdf#130857 VclBuilder: Move extractActive to BuilderBase
    
    Turn this helper function into a static function
    in the BuilderBase class, for reuse in QtBuilder
    in an upcoming commit.
    
    Change-Id: I68c7e62816ff5fdd1c2a02cf5e42f90b32cff627
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175571
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/include/vcl/builderbase.hxx b/include/vcl/builderbase.hxx
index 64e6bf6532d1..f7216864c11e 100644
--- a/include/vcl/builderbase.hxx
+++ b/include/vcl/builderbase.hxx
@@ -44,6 +44,8 @@ public:
     typedef stringmap Adjustment;
     typedef stringmap TextBuffer;
 
+    static sal_Int32 extractActive(stringmap& rMap);
+
 protected:
     BuilderBase(std::u16string_view sUIDir, const OUString& rUIFile, bool 
bLegacy);
     virtual ~BuilderBase() = default;
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 0a820713a680..c54014053d85 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -1285,18 +1285,6 @@ bool VclBuilder::extractAdjustmentToMap(const OUString& 
id, VclBuilder::stringma
 
 namespace
 {
-    sal_Int32 extractActive(VclBuilder::stringmap &rMap)
-    {
-        sal_Int32 nActiveId = 0;
-        VclBuilder::stringmap::iterator aFind = rMap.find(u"active"_ustr);
-        if (aFind != rMap.end())
-        {
-            nActiveId = aFind->second.toInt32();
-            rMap.erase(aFind);
-        }
-        return nActiveId;
-    }
-
     bool extractSelectable(VclBuilder::stringmap &rMap)
     {
         bool bSelectable = false;
@@ -3495,7 +3483,7 @@ template<typename T> static bool insertItems(vcl::Window 
*pWindow, VclBuilder::s
     if (!pContainer)
         return false;
 
-    sal_uInt16 nActiveId = extractActive(rMap);
+    sal_uInt16 nActiveId = BuilderBase::extractActive(rMap);
     for (auto const& item : rItems)
     {
         sal_Int32 nPos = pContainer->InsertEntry(item.m_sItem);
@@ -3754,6 +3742,18 @@ bool 
BuilderBase::hasOrientationVertical(VclBuilder::stringmap &rMap)
     return bVertical;
 }
 
+sal_Int32 BuilderBase::extractActive(VclBuilder::stringmap& rMap)
+{
+    sal_Int32 nActiveId = 0;
+    VclBuilder::stringmap::iterator aFind = rMap.find(u"active"_ustr);
+    if (aFind != rMap.end())
+    {
+        nActiveId = aFind->second.toInt32();
+        rMap.erase(aFind);
+    }
+    return nActiveId;
+}
+
 bool BuilderBase::extractEntry(VclBuilder::stringmap &rMap)
 {
     bool bHasEntry = false;

Reply via email to