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:
@ -23,6 +23,11 @@ QItemSelection GeneralSortFilterModel::findItems(const QString& text) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray GeneralSortFilterModel::jsonDataForServer(const QModelIndex& proxyIndex) {
|
||||
const QModelIndex sourceIndex = mapToSource(proxyIndex);
|
||||
return m_tableModel->jsonDataForServer(sourceIndex);
|
||||
}
|
||||
|
||||
void GeneralSortFilterModel::appendItems(const QByteArray& jsonDoc) {
|
||||
m_tableModel->appendItems(jsonDoc);
|
||||
}
|
||||
|
||||
@ -18,6 +18,8 @@ class GeneralSortFilterModel : public QSortFilterProxyModel {
|
||||
*/
|
||||
QItemSelection findItems(const QString& text) const;
|
||||
|
||||
QByteArray jsonDataForServer(const QModelIndex& proxyIndex);
|
||||
|
||||
public slots:
|
||||
void appendItems(const QByteArray& jsonDoc);
|
||||
bool removeRows(int firstRow, int nRows, const QModelIndex& parentIndex = QModelIndex()) override;
|
||||
|
||||
@ -15,9 +15,11 @@ enum UserRoles {
|
||||
InfoRole,
|
||||
AmountRole,
|
||||
FactorRole,
|
||||
/// helper roles
|
||||
/// Non user facing
|
||||
IdRole,
|
||||
/// read only roles
|
||||
ToStringRole,
|
||||
IdRole
|
||||
ToJsonRole
|
||||
};
|
||||
|
||||
static UserRoles DEFAULT_ROLE = NameRole;
|
||||
|
||||
@ -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!";
|
||||
|
||||
@ -38,6 +38,8 @@ class TableModel : public QAbstractTableModel {
|
||||
QJsonDocument getAllItemsAsJsonDoc() const;
|
||||
QList<QStringList> getItemsAsStringLists() const;
|
||||
|
||||
QByteArray jsonDataForServer(const QModelIndex& currentIndex) const;
|
||||
|
||||
public slots:
|
||||
// bool insertRows(int position, int rows, const QModelIndex& parentIndex = QModelIndex())
|
||||
// override;
|
||||
|
||||
Reference in New Issue
Block a user