Items can be saved to JSON file "items.json" (in standard location).
This commit is contained in:
@ -6,6 +6,10 @@
|
||||
#include "commands/removerowscommand.h"
|
||||
#include "modelitem.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
QHash<int, QByteArray> TableModel::ROLE_NAMES = {{NameRole, "Name"},
|
||||
{DescriptionRole, "Description"},
|
||||
{InfoRole, "Info"},
|
||||
@ -241,3 +245,18 @@ bool TableModel::isEmptyValueEqualToZero(const int role) const {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonDocument TableModel::getAllItemsAsJsonDoc() const {
|
||||
QJsonDocument doc = QJsonDocument();
|
||||
QJsonObject rootObject;
|
||||
QJsonArray array;
|
||||
|
||||
foreach (shared_ptr<ModelItem> item, m_items) {
|
||||
QJsonObject itemObject = item->toJsonObject();
|
||||
array.append(itemObject);
|
||||
}
|
||||
rootObject.insert("items", array);
|
||||
|
||||
doc.setObject(rootObject);
|
||||
return doc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user