feat(StatusQ/TestHelpers): Add method to test model removing items and emiting layoutChanged
This commit is contained in:
parent
42a60642e8
commit
598a389c3e
|
@ -85,6 +85,9 @@ void TestModel::remove(int index)
|
|||
|
||||
void TestModel::invert()
|
||||
{
|
||||
if (m_data.size() < 2)
|
||||
return;
|
||||
|
||||
emit layoutAboutToBeChanged();
|
||||
|
||||
for (auto& entry : m_data)
|
||||
|
@ -99,6 +102,32 @@ void TestModel::invert()
|
|||
emit layoutChanged();
|
||||
}
|
||||
|
||||
void TestModel::removeEverySecond()
|
||||
{
|
||||
if (m_data.empty())
|
||||
return;
|
||||
|
||||
emit layoutAboutToBeChanged();
|
||||
|
||||
for (auto& entry : m_data) {
|
||||
QVariantList& data = entry.second;
|
||||
|
||||
for (auto i = 0; i < data.size(); i++)
|
||||
data.removeAt(i);
|
||||
}
|
||||
|
||||
const auto persistentIndexes = persistentIndexList();
|
||||
|
||||
for (const QModelIndex& index : persistentIndexes) {
|
||||
if (index.row() % 2 == 0)
|
||||
changePersistentIndex(index, {});
|
||||
else
|
||||
changePersistentIndex(index, createIndex(index.row() / 2, 0));
|
||||
}
|
||||
|
||||
emit layoutChanged();
|
||||
}
|
||||
|
||||
void TestModel::initRoles()
|
||||
{
|
||||
m_roles.reserve(m_data.size());
|
||||
|
|
|
@ -19,6 +19,13 @@ public:
|
|||
// inverts order of items, emits layoutAboutToBeChanged / layoutChanged
|
||||
void invert();
|
||||
|
||||
// removes every second item from the model but doesn't emit
|
||||
// rowsAboutToBeRemoved/rowsRemoved. The update is notified via
|
||||
// layoutAboutToBeChanged/layoutChanged. It's useful for testing proxy
|
||||
// models against that scenario, which may occur in some circumstances, e.g.
|
||||
// during SFPM initialization where initial filtering is notified this way.
|
||||
void removeEverySecond();
|
||||
|
||||
private:
|
||||
void initRoles();
|
||||
|
||||
|
|
Loading…
Reference in New Issue