Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion QJsonModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,13 @@ QVariant QJsonModel::data(const QModelIndex &index, int role) const {
if (index.column() == 0)
return QString("%1").arg(item->key());

if (index.column() == 1)
if (index.column() == 1) {
if (mQuoteVisible && item->type() == QJsonValue::String) {
QString value = item->value().toString();
return QString("\"%1\"").arg(value);
}
return item->value();
}
} else if (Qt::EditRole == role) {
if (index.column() == 1)
return item->value();
Expand Down Expand Up @@ -469,6 +474,14 @@ void QJsonModel::addException(const QStringList &exceptions) {
mExceptions = exceptions;
}

void QJsonModel::setQuoteVisible(bool visible) {
mQuoteVisible = visible;
}

bool QJsonModel::quoteVisible() const {
return mQuoteVisible;
}

QJsonValue QJsonModel::genJson(QJsonTreeItem *item) const {
auto type = item->type();
int nchild = item->childCount();
Expand Down
4 changes: 4 additions & 0 deletions include/QJsonModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,14 @@ class QJsonModel : public QAbstractItemModel {
//! List of tags to skip during JSON parsing
void addException(const QStringList &exceptions);

// Display format control
void setQuoteVisible(bool visible);
bool quoteVisible() const;
private:
QJsonValue genJson(QJsonTreeItem *) const;
QJsonTreeItem *mRootItem = nullptr;
QStringList mHeaders;
bool mQuoteVisible = false;
//! List of exceptions (e.g. comments). Case insensitive, compairs on
//! "contains".
QStringList mExceptions;
Expand Down