vcl/qt5/QtInstanceTreeView.cxx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
New commits: commit ef4314436d24d2733d268d714ad4bcc2e9fed626 Author: Michael Weghorn <[email protected]> AuthorDate: Fri Feb 21 15:08:22 2025 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Sat Feb 22 10:52:29 2025 +0100 tdf#130857 qt weld: Let QStandardItemModel::itemFromIndex create item QStandardItemModel::itemFromIndex "will lazily create an item for the index (using itemPrototype()), and set it in the parent item's child table, if no item already exists at that index." [1]. Make use of that instead of manually calling the QStandardItem ctor. The main motivation is that this simplifies an upcoming change. [1] https://doc.qt.io/qt-6/qstandarditemmodel.html#itemFromIndex Change-Id: I371cdf8bd46b5f640c57760e4b52dda6489876c6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182005 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx index 2a87f398f5af..f0a678e0a79a 100644 --- a/vcl/qt5/QtInstanceTreeView.cxx +++ b/vcl/qt5/QtInstanceTreeView.cxx @@ -50,7 +50,12 @@ void QtInstanceTreeView::insert(const weld::TreeIter* pParent, int nPos, const O SolarMutexGuard g; GetQtInstance().RunInMainThread([&] { - QStandardItem* pItem = new QStandardItem; + if (nPos == -1) + nPos = m_pModel->rowCount(); + m_pModel->insertRow(nPos); + + const QModelIndex aIndex = modelIndex(nPos); + QStandardItem* pItem = m_pModel->itemFromIndex(aIndex); if (pStr) pItem->setText(toQString(*pStr)); if (pId) @@ -61,12 +66,8 @@ void QtInstanceTreeView::insert(const weld::TreeIter* pParent, int nPos, const O else if (pImageSurface) pItem->setIcon(toQPixmap(*pImageSurface)); - if (nPos == -1) - nPos = m_pModel->rowCount(); - m_pModel->insertRow(nPos, pItem); - if (pRet) - static_cast<QtInstanceTreeIter*>(pRet)->setModelIndex(modelIndex(nPos)); + static_cast<QtInstanceTreeIter*>(pRet)->setModelIndex(aIndex); }); }
