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

Method loadCategories

src/frontend/datasources/ImportDatasetWidget.cpp:102–170  ·  view source on GitHub ↗

* @brief Processes the json metadata file that contains the list of categories and subcategories and their datasets. */

Source from the content-addressed store, hash-verified

100 * @brief Processes the json metadata file that contains the list of categories and subcategories and their datasets.
101 */
102void ImportDatasetWidget::loadCategories() {
103 m_datasetsMap.clear();
104 ui.cbCollections->clear();
105
106 const QString collectionsFileName = m_jsonDir + QStringLiteral("/DatasetCollections.json");
107 QFile file(collectionsFileName);
108
109 if (file.open(QIODevice::ReadOnly)) {
110 QJsonDocument document = QJsonDocument::fromJson(file.readAll());
111 file.close();
112 if (!document.isArray()) {
113 QDEBUG(QStringLiteral("Invalid definition of ") + collectionsFileName);
114 return;
115 }
116
117 m_collections = document.array();
118
119 for (const QJsonValueRef col : m_collections) {
120 const QJsonObject& collection = col.toObject();
121 const QString& m_collection = collection[QLatin1String("name")].toString();
122
123 QString path = m_jsonDir + QLatin1Char('/') + m_collection + QStringLiteral(".json");
124 QFile collectionFile(path);
125 if (collectionFile.open(QIODevice::ReadOnly)) {
126 QJsonDocument collectionDocument = QJsonDocument::fromJson(collectionFile.readAll());
127 if (!collectionDocument.isObject()) {
128 QDEBUG(QStringLiteral("Invalid definition of ") + path);
129 continue;
130 }
131
132 const QJsonObject& collectionObject = collectionDocument.object();
133 const QJsonArray& categoryArray = collectionObject.value(QLatin1String("categories")).toArray();
134
135 // processing categories
136 for (const auto& cat : categoryArray) {
137 const QJsonObject& currentCategory = cat.toObject();
138 const QString& categoryName = currentCategory.value(QLatin1String("name")).toString();
139 const QJsonArray& subcategories = currentCategory.value(QLatin1String("subcategories")).toArray();
140
141 // processing subcategories
142 for (const auto& sub : subcategories) {
143 QJsonObject currentSubCategory = sub.toObject();
144 QString subcategoryName = currentSubCategory.value(QLatin1String("name")).toString();
145 const QJsonArray& datasetArray = currentSubCategory.value(QLatin1String("datasets")).toArray();
146
147 // processing the datasets of the actual subcategory
148 for (const auto& dataset : datasetArray)
149 m_datasetsMap[m_collection][categoryName][subcategoryName].push_back(
150 dataset.toObject().value(QLatin1String("filename")).toString());
151 }
152 }
153 }
154 }
155
156 if (m_model)
157 delete m_model;
158 m_model = new DatasetModel(m_datasetsMap);
159

Callers

nothing calls this directly

Calls 10

allDatasetsListMethod · 0.80
collectionsMethod · 0.80
clearMethod · 0.45
openMethod · 0.45
closeMethod · 0.45
toStringMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45
datasetCountMethod · 0.45
currentIndexMethod · 0.45

Tested by

no test coverage detected