tdf#130857 qt weld: Implement more TreeView methods wrt selection

Change-Id: I3479b138a0986f1fbac7745e575e318bf63c1911
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177576
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Tested-by: Jenkins
This commit is contained in:
Michael Weghorn 2024-11-30 02:17:21 +01:00
parent ec395cfd20
commit 05c8f91d5a
2 changed files with 20 additions and 4 deletions

View file

@ -41,7 +41,7 @@ public:
virtual int get_selected_index() const override;
virtual void select(int nPos) override;
virtual void unselect(int pos) override;
virtual void unselect(int nPos) override;
virtual void remove(int pos) override;
virtual OUString get_text(int nRow, int nCol = -1) const override;
virtual void set_text(int row, const OUString& rText, int col = -1) override;

View file

@ -113,8 +113,18 @@ void QtInstanceTreeView::set_clicks_to_toggle(int) { assert(false && "Not implem
int QtInstanceTreeView::get_selected_index() const
{
assert(false && "Not implemented yet");
return -1;
SolarMutexGuard g;
int nIndex = -1;
GetQtInstance().RunInMainThread([&] {
const QModelIndexList aSelectedIndexes = m_pSelectionModel->selectedIndexes();
if (aSelectedIndexes.empty())
return;
nIndex = aSelectedIndexes.first().row();
});
return nIndex;
}
void QtInstanceTreeView::select(int nPos)
@ -124,7 +134,13 @@ void QtInstanceTreeView::select(int nPos)
[&] { m_pSelectionModel->select(m_pModel->index(nPos, 0), QItemSelectionModel::Select); });
}
void QtInstanceTreeView::unselect(int) { assert(false && "Not implemented yet"); }
void QtInstanceTreeView::unselect(int nPos)
{
SolarMutexGuard g;
GetQtInstance().RunInMainThread([&] {
m_pSelectionModel->select(m_pModel->index(nPos, 0), QItemSelectionModel::Deselect);
});
}
void QtInstanceTreeView::remove(int) { assert(false && "Not implemented yet"); }