feat(StatusQ/Testing): invert method added TestModel emiting valid layoutChanged
This commit is contained in:
parent
be218c22cd
commit
1639f1f9e7
|
@ -1,5 +1,6 @@
|
||||||
#include "testmodel.h"
|
#include "testmodel.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
TestModel::TestModel(QList<QPair<QString, QVariantList>> data)
|
TestModel::TestModel(QList<QPair<QString, QVariantList>> data)
|
||||||
: m_data(std::move(data))
|
: m_data(std::move(data))
|
||||||
|
@ -82,6 +83,22 @@ void TestModel::remove(int index)
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestModel::invert()
|
||||||
|
{
|
||||||
|
emit layoutAboutToBeChanged();
|
||||||
|
|
||||||
|
for (auto& entry : m_data)
|
||||||
|
std::reverse(entry.second.begin(), entry.second.end());
|
||||||
|
|
||||||
|
const auto persistentIndexes = persistentIndexList();
|
||||||
|
const auto count = rowCount();
|
||||||
|
|
||||||
|
for (const QModelIndex& index: persistentIndexes)
|
||||||
|
changePersistentIndex(index, createIndex(count - index.row() - 1, 0));
|
||||||
|
|
||||||
|
emit layoutChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void TestModel::initRoles()
|
void TestModel::initRoles()
|
||||||
{
|
{
|
||||||
m_roles.reserve(m_data.size());
|
m_roles.reserve(m_data.size());
|
||||||
|
|
|
@ -8,7 +8,7 @@ public:
|
||||||
explicit TestModel(QList<QPair<QString, QVariantList>> data);
|
explicit TestModel(QList<QPair<QString, QVariantList>> data);
|
||||||
explicit TestModel(QList<QString> roles);
|
explicit TestModel(QList<QString> roles);
|
||||||
|
|
||||||
int rowCount(const QModelIndex& parent) const override;
|
int rowCount(const QModelIndex& parent = {}) const override;
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
QVariant data(const QModelIndex& index, int role) const override;
|
QVariant data(const QModelIndex& index, int role) const override;
|
||||||
|
|
||||||
|
@ -16,6 +16,9 @@ public:
|
||||||
void update(int index, int role, QVariant value);
|
void update(int index, int role, QVariant value);
|
||||||
void remove(int index);
|
void remove(int index);
|
||||||
|
|
||||||
|
// inverts order of items, emits layoutAboutToBeChanged / layoutChanged
|
||||||
|
void invert();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initRoles();
|
void initRoles();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue