vcl/qt5/QtBuilder.cxx | 45 +++++++++------------------------------------ 1 file changed, 9 insertions(+), 36 deletions(-)
New commits: commit 3e28b4f0c97d011cf4222941f019ce05fe6b0313 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Oct 25 21:21:25 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Oct 26 13:12:05 2024 +0200 tdf#130857 qt weld: Simplify QtBuilder::applyGridPackingProperties No longer try to retrieve the current row and column of the widget in the QGridLayout and apply the "top-attach" and "left-attach" properties to set the new row and column separately. Instead, assume (and assert), that both, the new row and column properties are set, get them and then set the position using both of them at the same time. If any of the properties is missing, that most likely needs to be fixed in the .ui file. As a side note, something similar to the previous algorithm to determine the grid position might be useful to implement QtInstanceWidget::get_grid_left_attach etc. at some point. Change-Id: I22e34275e3974f42ca3ee43fa6cb66624e917443 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175661 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx index d59f76a3ed35..9bb32a642288 100644 --- a/vcl/qt5/QtBuilder.cxx +++ b/vcl/qt5/QtBuilder.cxx @@ -350,44 +350,17 @@ void QtBuilder::applyGridPackingProperties(QObject& rCurrentChild, QGridLayout& if (!rCurrentChild.isWidgetType()) return; - QWidget& rCurrentWidget = static_cast<QWidget&>(rCurrentChild); + assert(rPackingProperties.contains(u"left-attach"_ustr) + && "left-attach property missing for grid item"); + assert(rPackingProperties.contains(u"top-attach"_ustr) + && "top-attach property missing for grid item"); - int nCurrentRow = -1; - int nCurrentColumn = -1; - for (int i = 0; i < rGrid.rowCount(); i++) - { - for (int j = 0; j < rGrid.columnCount(); j++) - { - if (QLayoutItem* pLayoutItem = rGrid.itemAtPosition(i, j)) - { - if (pLayoutItem->widget() == &rCurrentWidget) - { - nCurrentRow = i; - nCurrentColumn = j; - break; - } - } - } - } - assert(nCurrentRow >= 0 && nCurrentColumn >= 0 && "Widget not contained in parent grid layout"); + const sal_Int32 nColumn = rPackingProperties.at(u"left-attach"_ustr).toInt32(); + const sal_Int32 nRow = rPackingProperties.at(u"top-attach"_ustr).toInt32(); - for (auto const & [ rKey, rValue ] : rPackingProperties) - { - if (rKey == u"left-attach") - { - const sal_Int32 nNewColumn = rValue.toInt32(); - rGrid.removeWidget(&rCurrentWidget); - rGrid.addWidget(&rCurrentWidget, nCurrentRow, nNewColumn); - nCurrentColumn = nNewColumn; - } - else if (rKey == u"top-attach") - { - const sal_Int32 nNewRow = rValue.toInt32(); - rGrid.removeWidget(&rCurrentWidget); - rGrid.addWidget(&rCurrentWidget, nNewRow, nCurrentColumn); - nCurrentRow = nNewRow; - } - } + QWidget& rCurrentWidget = static_cast<QWidget&>(rCurrentChild); + rGrid.removeWidget(&rCurrentWidget); + rGrid.addWidget(&rCurrentWidget, nRow, nColumn); } void QtBuilder::applyPackingProperties(QObject* pCurrentChild, QObject* pParent,