Retrieving the JSON data of the current index to send to the server through the proxy model. Sending this data happens by triggering the core.
This commit is contained in:
@ -86,6 +86,8 @@ QVariant TableModel::data(const QModelIndex& index, int role) const {
|
||||
return m_items.at(row)->data(role);
|
||||
case ToStringRole:
|
||||
return m_items.at(row)->toString();
|
||||
case ToJsonRole:
|
||||
return m_items.at(row)->toJsonObject();
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
@ -169,6 +171,15 @@ QList<QStringList> TableModel::getItemsAsStringLists() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
// TODO use item selection as parameter to wrap multiple items into JSON data structure
|
||||
QByteArray TableModel::jsonDataForServer(const QModelIndex& currentIndex) const {
|
||||
const QJsonObject itemObject = data(currentIndex, ToJsonRole).toJsonObject();
|
||||
QJsonObject rootObject;
|
||||
rootObject.insert("item", itemObject);
|
||||
const QJsonDocument jsonDoc(rootObject);
|
||||
return jsonDoc.toJson(QJsonDocument::Compact);
|
||||
}
|
||||
|
||||
bool TableModel::removeRows(int firstRow, int nRows, const QModelIndex& parentIndex) {
|
||||
if (parentIndex != QModelIndex()) {
|
||||
qWarning() << "Removing of child rows is not supported yet!";
|
||||
|
||||
Reference in New Issue
Block a user