summaryrefslogtreecommitdiff
diff options
authorMichael Weghorn <m.weghorn@posteo.de>2025-04-26 17:50:54 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2025-04-27 07:24:54 +0200
commite51e4438b4c7c05de08048f82870ff46f3a54c50 (patch)
treec894487fd706e686b1c52d7d598d486040cc63c7
parented8a7a64a7f4d86c02dc3d3080179a6c80aa38db (diff)
tdf#130857 qt weld: Support non-top-level TreeView items
Drop the assert on `pParent` being null in QtInstanceTreeView::insert and instead implement handling for parent items. In most of the cases, the corresponding QAbstractItemModel methods have an optional (defaulting to `QModelIndex()`) param to specify the parent. Pass that param instead of using the default. This builds on top of this previous commit whose commit messages has some more details: Change-Id: Id829ce3a1052f0d8915f0b03a0b0786e2f3586dd Author: Michael Weghorn <m.weghorn@posteo.de> Date: Sat Apr 26 17:00:01 2025 +0200 tdf#130857 qt weld: Move TreeView method logic to overload for iters Change-Id: Ibb1a119e3fc6f0fa878babbe526990df42d78336 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184673 Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Tested-by: Jenkins
-rw-r--r--vcl/inc/qt5/QtInstanceTreeView.hxx6
-rw-r--r--vcl/qt5/QtInstanceTreeView.cxx31
2 files changed, 16 insertions, 21 deletions
diff --git a/vcl/inc/qt5/QtInstanceTreeView.hxx b/vcl/inc/qt5/QtInstanceTreeView.hxx
index 26e974c72add..c0684bafdb87 100644
--- a/vcl/inc/qt5/QtInstanceTreeView.hxx
+++ b/vcl/inc/qt5/QtInstanceTreeView.hxx
@@ -201,11 +201,11 @@ public:
using QtInstanceWidget::get_sensitive;
private:
- QModelIndex modelIndex(int nRow, int nCol = 0) const;
+ QModelIndex modelIndex(int nRow, int nCol = 0,
+ const QModelIndex& rParentIndex = QModelIndex()) const;
QModelIndex modelIndex(const weld::TreeIter& rIter, int nCol = 0) const;
- QtInstanceTreeIter treeIter(int nRow) const;
+ QtInstanceTreeIter treeIter(int nRow, const QModelIndex& rParentIndex = QModelIndex()) const;
QStandardItem* itemFromIndex(const QModelIndex& rIndex) const;
- QModelIndex toggleButtonModelIndex(int nRow) const;
QModelIndex toggleButtonModelIndex(const weld::TreeIter& rIter) const;
QModelIndex firstTextColumnModelIndex(const weld::TreeIter& rIter) const;
static QAbstractItemView::SelectionMode mapSelectionMode(SelectionMode eMode);
diff --git a/vcl/qt5/QtInstanceTreeView.cxx b/vcl/qt5/QtInstanceTreeView.cxx
index 42ec94c8d756..6caf5d5137cc 100644
--- a/vcl/qt5/QtInstanceTreeView.cxx
+++ b/vcl/qt5/QtInstanceTreeView.cxx
@@ -42,22 +42,21 @@ void QtInstanceTreeView::insert(const weld::TreeIter* pParent, int nPos, const O
VirtualDevice* pImageSurface, bool bChildrenOnDemand,
weld::TreeIter* pRet)
{
- // Only specific subset of parameters handled so far;
- // assert only these are used at the moment and implement remaining cases
- // when needed to support more dialogs, then adjust/remove asserts below
- assert(!pParent && "Not implemented yet");
assert(!bChildrenOnDemand && "Not implemented yet");
// avoid -Werror=unused-parameter for release build
- (void)pParent;
(void)bChildrenOnDemand;
SolarMutexGuard g;
GetQtInstance().RunInMainThread([&] {
+ const QModelIndex aParentIndex
+ = pParent ? static_cast<const QtInstanceTreeIter*>(pParent)->modelIndex()
+ : QModelIndex();
+
if (nPos == -1)
- nPos = m_pModel->rowCount();
- m_pModel->insertRow(nPos);
+ nPos = m_pModel->rowCount(aParentIndex);
+ m_pModel->insertRow(nPos, aParentIndex);
- const QModelIndex aIndex = modelIndex(nPos);
+ const QModelIndex aIndex = modelIndex(nPos, 0, aParentIndex);
QStandardItem* pItem = itemFromIndex(aIndex);
if (pStr)
pItem->setText(toQString(*pStr));
@@ -70,7 +69,7 @@ void QtInstanceTreeView::insert(const weld::TreeIter* pParent, int nPos, const O
pItem->setIcon(toQPixmap(*pImageSurface));
if (m_bExtraToggleButtonColumnEnabled)
- itemFromIndex(toggleButtonModelIndex(nPos))->setCheckable(true);
+ itemFromIndex(toggleButtonModelIndex(QtInstanceTreeIter(aIndex)))->setCheckable(true);
if (pRet)
static_cast<QtInstanceTreeIter*>(pRet)->setModelIndex(aIndex);
@@ -971,9 +970,10 @@ QAbstractItemView::SelectionMode QtInstanceTreeView::mapSelectionMode(SelectionM
}
}
-QModelIndex QtInstanceTreeView::modelIndex(int nRow, int nCol) const
+QModelIndex QtInstanceTreeView::modelIndex(int nRow, int nCol,
+ const QModelIndex& rParentIndex) const
{
- return modelIndex(treeIter(nRow), nCol);
+ return modelIndex(treeIter(nRow, rParentIndex), nCol);
}
QModelIndex QtInstanceTreeView::modelIndex(const weld::TreeIter& rIter, int nCol) const
@@ -985,9 +985,9 @@ QModelIndex QtInstanceTreeView::modelIndex(const weld::TreeIter& rIter, int nCol
return m_pModel->index(aModelIndex.row(), nCol, aModelIndex.parent());
}
-QtInstanceTreeIter QtInstanceTreeView::treeIter(int nRow) const
+QtInstanceTreeIter QtInstanceTreeView::treeIter(int nRow, const QModelIndex& rParentIndex) const
{
- return QtInstanceTreeIter(m_pModel->index(nRow, 0));
+ return QtInstanceTreeIter(m_pModel->index(nRow, 0, rParentIndex));
}
QStandardItem* QtInstanceTreeView::itemFromIndex(const QModelIndex& rIndex) const
@@ -996,11 +996,6 @@ QStandardItem* QtInstanceTreeView::itemFromIndex(const QModelIndex& rIndex) cons
return m_pSourceModel->itemFromIndex(aSourceIndex);
}
-QModelIndex QtInstanceTreeView::toggleButtonModelIndex(int nRow) const
-{
- return toggleButtonModelIndex(treeIter(nRow));
-}
-
QModelIndex QtInstanceTreeView::toggleButtonModelIndex(const weld::TreeIter& rIter) const
{
assert(m_bExtraToggleButtonColumnEnabled && "Special toggle button column is not enabled");
close