14 parents[&root] =
nullptr;
21 nlohmann::json*
parent = refFrom(parentIndex);
22 if (row >=
int(
parent->size()))
27 nlohmann::json* child =
nullptr;
33 else if (
parent->is_object())
36 std::advance(it, row);
38 names[child] = it.key();
46 return createIndex(row, column, child);
62 nlohmann::json* child = refFrom(
index);
63 if (!parents.count(child))
69 nlohmann::json*
parent = parents.at(child);
76 return createIndex(row, 0,
parent);
81 if (parentIndex.column() > 1)
86 nlohmann::json*
parent = refFrom(parentIndex);
104 if (!
index.isValid())
109 if (role != Qt::DisplayRole)
114 nlohmann::json* ref = refFrom(
index);
116 if (
index.column() == 0)
118 if (!names.count(ref))
121 (ref ? ref->dump(2) :
"(null)");
124 std::string
const& name = names.at(ref);
125 return QVariant(name.c_str());
130 case nlohmann::json::value_t::null:
131 return QVariant(
"null");
132 case nlohmann::json::value_t::object:
133 return QVariant(
"object");
134 case nlohmann::json::value_t::array:
135 return QVariant(
"array");
136 case nlohmann::json::value_t::string:
137 return QVariant(ref->get<std::string>().c_str());
138 case nlohmann::json::value_t::boolean:
139 return QVariant(ref->get<
bool>());
140 case nlohmann::json::value_t::number_integer:
141 return QVariant(ref->get<
int>());
142 case nlohmann::json::value_t::number_unsigned:
143 return QVariant(ref->get<
unsigned int>());
144 case nlohmann::json::value_t::number_float:
145 return QVariant(ref->get<
float>());
148 return QVariant(
"n/a");
154 if (role != Qt::DisplayRole)
162 return QVariant(
"Name");
164 return QVariant(
"Value");
170 nlohmann::json* JSONTreeModel::refFrom(
const QModelIndex&
index)
const
174 return static_cast<nlohmann::json*
>(
index.internalPointer());