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

Method updateDatasets

src/frontend/datasources/ImportDatasetWidget.cpp:300–344  ·  view source on GitHub ↗

* @brief Populates lwDatasets with the datasets of the selected subcategory or its parent * @param item the selected subcategory */

Source from the content-addressed store, hash-verified

298 * @param item the selected subcategory
299 */
300void ImportDatasetWidget::updateDatasets(QTreeWidgetItem* item) {
301 m_initializing = true;
302 ui.lwDatasets->clear();
303
304 if (!item) {
305 // no category item is selected because nothing matches the search string
306 m_initializing = false;
307 datasetChanged();
308 return;
309 }
310
311 const QString& filter = ui.leSearch->text();
312
313 if (item->childCount() == 0) {
314 // sub-category was selected -> show all its datasets
315 m_category = item->parent()->text(0);
316 m_subcategory = item->text(0);
317
318 addDatasetItems(m_collection, m_category, m_subcategory, filter);
319 } else {
320 if (!item->parent()) {
321 // top-level item "All" was selected -> show datasets for all categories and their sub-categories
322 m_category = QString();
323 m_subcategory = QString();
324
325 for (const auto& category : m_model->categories(m_collection)) {
326 for (const auto& subcategory : m_model->subcategories(m_collection, category))
327 addDatasetItems(m_collection, category, subcategory, filter);
328 }
329 } else {
330 // a category was selected -> show all its datasets
331 m_category = item->text(0);
332 m_subcategory = QString();
333
334 for (const auto& subcategory : m_model->subcategories(m_collection, m_category))
335 addDatasetItems(m_collection, m_category, subcategory, filter);
336 }
337 }
338
339 m_initializing = false;
340
341 // select the first available dataset
342 if (ui.lwDatasets->count())
343 ui.lwDatasets->setCurrentRow(0);
344}
345
346void ImportDatasetWidget::addDatasetItems(const QString& collection, const QString& category, const QString& subcategory, const QString& filter) {
347 if (!filter.isEmpty() && (category.startsWith(filter, Qt::CaseInsensitive) || subcategory.startsWith(filter, Qt::CaseInsensitive))) {

Callers

nothing calls this directly

Calls 8

categoriesMethod · 0.80
subcategoriesMethod · 0.80
QStringClass · 0.50
clearMethod · 0.45
textMethod · 0.45
childCountMethod · 0.45
parentMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected