Fixed selection of view rows when changing to filtered data

* return values for select functions
* select function must be "public override"
* reselect filtered data as well
This commit is contained in:
Klaus Basan
2019-03-23 19:56:08 +01:00
committed by Mat Sutcliffe
parent 88e82404e2
commit 30b65d6c36
7 changed files with 54 additions and 27 deletions

View File

@@ -176,9 +176,10 @@ namespace BlackGui
this->beginResetModel();
m_container = performSort ? sortedContainer : container;
this->updateFilteredContainer();
this->updateFilteredContainer(); // use sorted container for filtered if applicable
this->endResetModel();
// reselect if implemented in specialized view
if (!selection.isEmpty())
{
m_selectionModel->selectObjects(selection);
@@ -265,6 +266,12 @@ namespace BlackGui
template <typename T, bool UseCompare>
void CListModelBase<T, UseCompare>::takeFilterOwnership(std::unique_ptr<IModelFilter<ContainerType> > &filter)
{
ContainerType selection;
if (m_selectionModel)
{
selection = m_selectionModel->selectedObjects();
}
if (!filter)
{
this->removeFilter(); // clear filter
@@ -283,6 +290,12 @@ namespace BlackGui
// invalid filter, so clear filter
this->removeFilter();
}
// reselect if implemented in specialized views
if (!selection.isEmpty())
{
m_selectionModel->selectObjects(selection);
}
}
template <typename T, bool UseCompare>

View File

@@ -138,8 +138,8 @@ namespace BlackGui
int removeIf(K0 k0, V0 v0, KeysValues... keysValues)
{
int c = m_container.removeIf(BlackMisc::Predicates::MemberEqual(k0, v0, keysValues...));
if (c > 0) { this->emitModelDataChanged();}
this->updateFilteredContainer();
if (c > 0) { this->emitModelDataChanged();}
return c;
}