#25 Extend json() method in QJsonModel to take a parameter whether or not to format the output compact. Be default it is false to lessen impact on existing use of this method.
This commit is contained in:
parent
cef8105002
commit
fae694be15
@ -399,7 +399,7 @@ 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;
|
||||
@ -407,9 +407,9 @@ QByteArray QJsonModel::json()
|
||||
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;
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ public:
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user