| 224 | } |
| 225 | |
| 226 | void ImportDatasetWidget::updateCategories() { |
| 227 | m_initializing = true; |
| 228 | ui.twCategories->clear(); |
| 229 | |
| 230 | auto* rootItem = new QTreeWidgetItem(QStringList(i18n("All"))); |
| 231 | ui.twCategories->addTopLevelItem(rootItem); |
| 232 | |
| 233 | const QString& filter = ui.leSearch->text(); |
| 234 | |
| 235 | // add categories |
| 236 | for (const auto& category : m_model->categories(m_collection)) { |
| 237 | const bool categoryMatch = (filter.isEmpty() || category.startsWith(filter, Qt::CaseInsensitive)); |
| 238 | |
| 239 | if (categoryMatch) { |
| 240 | auto* const item = new QTreeWidgetItem(QStringList(category)); |
| 241 | rootItem->addChild(item); |
| 242 | |
| 243 | // add all sub-categories |
| 244 | for (const auto& subcategory : m_model->subcategories(m_collection, category)) |
| 245 | item->addChild(new QTreeWidgetItem(QStringList(subcategory))); |
| 246 | } else { |
| 247 | QTreeWidgetItem* item = nullptr; |
| 248 | for (const auto& subcategory : m_model->subcategories(m_collection, category)) { |
| 249 | bool subcategoryMatch = subcategory.startsWith(filter, Qt::CaseInsensitive); |
| 250 | |
| 251 | if (subcategoryMatch) { |
| 252 | if (!item) { |
| 253 | item = new QTreeWidgetItem(QStringList(category)); |
| 254 | rootItem->addChild(item); |
| 255 | item->setExpanded(true); |
| 256 | } |
| 257 | item->addChild(new QTreeWidgetItem(QStringList(subcategory))); |
| 258 | } else { |
| 259 | for (const QString& dataset : m_model->datasets(m_collection, category, subcategory)) { |
| 260 | bool datasetMatch = dataset.startsWith(filter, Qt::CaseInsensitive); |
| 261 | if (datasetMatch) { |
| 262 | if (!item) { |
| 263 | item = new QTreeWidgetItem(QStringList(category)); |
| 264 | rootItem->addChild(item); |
| 265 | item->setExpanded(true); |
| 266 | } |
| 267 | item->addChild(new QTreeWidgetItem(QStringList(subcategory))); |
| 268 | break; |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | // remote the root item "All" if nothing has matched to the filter string |
| 277 | if (rootItem->childCount() == 0) |
| 278 | ui.twCategories->clear(); |
| 279 | |
| 280 | // expand the root item and select the first category item |
| 281 | rootItem->setExpanded(true); |
| 282 | if (filter.isEmpty()) { |
| 283 | rootItem->setSelected(true); |
nothing calls this directly
no test coverage detected