MCPcopy Create free account
hub / github.com/KDE/labplot / load

Method load

src/backend/datasources/filters/QJsonModel.cpp:84–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84QJsonTreeItem* QJsonTreeItem::load(const QJsonValue& value, QJsonTreeItem* parent) {
85 auto* rootItem = new QJsonTreeItem(parent);
86 // rootItem->setKey("root");
87
88 if (value.isObject()) {
89 const auto& object = value.toObject();
90
91 // determine the size
92 rootItem->setSize(QJsonDocument(object).toJson(QJsonDocument::Compact).size());
93
94 // read all children
95 for (const auto& k : object.keys()) {
96 const auto& v = object.value(k);
97 auto* childItem = load(v, rootItem);
98 childItem->setKey(k);
99 childItem->setType(v.type());
100 rootItem->appendChild(childItem);
101 }
102 } else if (value.isArray()) {
103 const auto& array = value.toArray();
104 rootItem->setSize(QJsonDocument(array).toJson(QJsonDocument::Compact).size());
105
106 int index = 0;
107 rootItem->reserve(array.count());
108 for (const QJsonValue& v : array) {
109 auto* childItem = load(v, rootItem);
110 childItem->setKey(QString::number(index));
111 childItem->setType(v.type());
112 rootItem->appendChild(childItem);
113 ++index;
114 }
115 } else {
116 const QString& str = value.toVariant().toString();
117 rootItem->setValue(str);
118 rootItem->setType(value.type());
119 rootItem->setSize(str.length());
120 }
121
122 return rootItem;
123}
124
125//=========================================================================
126

Callers

nothing calls this directly

Calls 15

setKeyMethod · 0.80
appendChildMethod · 0.80
lengthMethod · 0.80
QJsonDocumentClass · 0.70
setSizeMethod · 0.45
sizeMethod · 0.45
valueMethod · 0.45
setTypeMethod · 0.45
typeMethod · 0.45
reserveMethod · 0.45
countMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected