chore(WritableProxyModel): Adding possibility to get the model changes
This commit is contained in:
parent
d2030de867
commit
9d4bc9466e
|
@ -32,6 +32,11 @@ public:
|
|||
~WritableProxyModel();
|
||||
|
||||
Q_INVOKABLE QVariantMap toVariantMap() const;
|
||||
|
||||
Q_INVOKABLE QVariantList getInsertedItems() const;
|
||||
Q_INVOKABLE QVariantList getEditedItems() const;
|
||||
Q_INVOKABLE QVariantList getRemovedItems() const;
|
||||
|
||||
Q_INVOKABLE bool insert(int at, const QVariantMap& data = {});
|
||||
Q_INVOKABLE bool append(const QVariantMap& data = {});
|
||||
Q_INVOKABLE bool remove(int at);
|
||||
|
|
|
@ -421,6 +421,73 @@ QVariantMap WritableProxyModel::toVariantMap() const
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
QVariantList WritableProxyModel::getInsertedItems() const
|
||||
{
|
||||
if (!d->dirty || !sourceModel())
|
||||
return {};
|
||||
|
||||
QVariantList result;
|
||||
|
||||
for (auto iter = d->insertedRows.begin(); iter != d->insertedRows.end(); ++iter)
|
||||
{
|
||||
auto index = iter.key();
|
||||
if (!index.isValid())
|
||||
continue;
|
||||
|
||||
auto data = iter.value();
|
||||
QVariantMap rowMap;
|
||||
for (auto it = data.begin(); it != data.end(); ++it)
|
||||
rowMap[roleNames()[it.key()]] = it.value();
|
||||
result.append(rowMap);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
QVariantList WritableProxyModel::getEditedItems() const
|
||||
{
|
||||
if (!d->dirty || !sourceModel())
|
||||
return {};
|
||||
|
||||
QVariantList result;
|
||||
|
||||
for (auto iter = d->cache.begin(); iter != d->cache.end(); ++iter)
|
||||
{
|
||||
auto index = iter.key();
|
||||
if (!index.isValid())
|
||||
continue;
|
||||
|
||||
auto data = itemData(index);
|
||||
QVariantMap rowMap;
|
||||
for (auto it = data.begin(); it != data.end(); ++it)
|
||||
rowMap[roleNames()[it.key()]] = it.value();
|
||||
result.append(rowMap);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
QVariantList WritableProxyModel::getRemovedItems() const
|
||||
{
|
||||
if (!d->dirty || !sourceModel())
|
||||
return {};
|
||||
|
||||
QVariantList result;
|
||||
|
||||
for (auto iter = d->removedRows.begin(); iter != d->removedRows.end(); ++iter)
|
||||
{
|
||||
if (!iter->isValid())
|
||||
continue;
|
||||
|
||||
QVariantMap rowMap;
|
||||
auto roleNames = this->roleNames();
|
||||
for (auto it = roleNames.begin(); it != roleNames.end(); ++it)
|
||||
rowMap[it.value()] = sourceModel()->data(*iter, it.key());
|
||||
result.append(rowMap);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool WritableProxyModel::insert(int at, const QVariantMap& data)
|
||||
{
|
||||
auto rowCount = this->rowCount();
|
||||
|
|
Loading…
Reference in New Issue