Skip to content

Commit

Permalink
Merge pull request #26 from phoenixsc18/json-compact-output
Browse files Browse the repository at this point in the history
#25 Extend json() method in QJsonModel to take a parameter whether or…
  • Loading branch information
dridk authored Sep 1, 2023
2 parents d5c79ae + fae694b commit ede66dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions qjsonmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,17 +410,17 @@ Qt::ItemFlags QJsonModel::flags(const QModelIndex &index) const
return QAbstractItemModel::flags(index);
}

QByteArray QJsonModel::json()
QByteArray QJsonModel::json(bool compact)
{
auto jsonValue = genJson(mRootItem);
QByteArray json;
if (jsonValue.isNull())
return json;

if (jsonValue.isArray())
arrayToJson(jsonValue.toArray(), json, 0, false);
arrayToJson(jsonValue.toArray(), json, 0, compact);
else
objectToJson(jsonValue.toObject(), json, 0, false);
objectToJson(jsonValue.toObject(), json, 0, compact);

return json;
}
Expand Down
2 changes: 1 addition & 1 deletion qjsonmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class QJsonModel : public QAbstractItemModel
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
QByteArray json();
QByteArray json(bool compact = false);
QByteArray jsonToByte(QJsonValue jsonValue);
void objectToJson(QJsonObject jsonObject, QByteArray &json, int indent, bool compact);
void arrayToJson(QJsonArray jsonArray, QByteArray &json, int indent, bool compact);
Expand Down

0 comments on commit ede66dd

Please sign in to comment.