15 parents[&root] =
nullptr;
23 nlohmann::json*
parent = refFrom(parentIndex);
24 if (row >=
int(
parent->size()))
29 nlohmann::json* child =
nullptr;
35 else if (
parent->is_object())
38 std::advance(it, row);
40 names[child] = it.key();
48 return createIndex(row, column, child);
64 nlohmann::json* child = refFrom(
index);
65 if (!parents.count(child))
71 nlohmann::json*
parent = parents.at(child);
78 return createIndex(row, 0,
parent);
84 if (parentIndex.column() > 1)
89 nlohmann::json*
parent = refFrom(parentIndex);
109 if (!
index.isValid())
114 if (role != Qt::DisplayRole)
119 nlohmann::json* ref = refFrom(
index);
121 if (
index.column() == 0)
123 if (!names.count(ref))
126 << (ref ? ref->dump(2) :
"(null)");
129 std::string
const& name = names.at(ref);
130 return QVariant(name.c_str());
135 case nlohmann::json::value_t::null:
136 return QVariant(
"null");
137 case nlohmann::json::value_t::object:
138 return QVariant(
"object");
139 case nlohmann::json::value_t::array:
140 return QVariant(
"array");
141 case nlohmann::json::value_t::string:
142 return QVariant(ref->get<std::string>().c_str());
143 case nlohmann::json::value_t::boolean:
144 return QVariant(ref->get<
bool>());
145 case nlohmann::json::value_t::number_integer:
146 return QVariant(ref->get<
int>());
147 case nlohmann::json::value_t::number_unsigned:
148 return QVariant(ref->get<
unsigned int>());
149 case nlohmann::json::value_t::number_float:
150 return QVariant(ref->get<
float>());
153 return QVariant(
"n/a");
160 if (role != Qt::DisplayRole)
168 return QVariant(
"Name");
170 return QVariant(
"Value");
177 JSONTreeModel::refFrom(
const QModelIndex&
index)
const
181 return static_cast<nlohmann::json*
>(
index.internalPointer());