* Shows all categories and sub-categories for the currently selected collection */
| 173 | * Shows all categories and sub-categories for the currently selected collection |
| 174 | */ |
| 175 | void ImportDatasetWidget::collectionChanged(int index) { |
| 176 | m_allCollections = (index == 0); |
| 177 | |
| 178 | if (!m_allCollections) |
| 179 | m_collection = ui.cbCollections->itemData(index).toString(); |
| 180 | else |
| 181 | m_collection = QString(); |
| 182 | |
| 183 | // update the info field |
| 184 | m_collectionDescription.clear(); |
| 185 | if (!m_allCollections) { |
| 186 | for (const QJsonValueRef col : m_collections) { |
| 187 | const QJsonObject& collection = col.toObject(); |
| 188 | if (m_collection == collection[QLatin1String("name")].toString()) { |
| 189 | m_collectionDescription = collection[QLatin1String("description")].toString(); |
| 190 | m_collectionDescription += QStringLiteral("<br></hline><br>"); |
| 191 | break; |
| 192 | } |
| 193 | } |
| 194 | } else { |
| 195 | for (const QJsonValueRef col : m_collections) { |
| 196 | const QJsonObject& collection = col.toObject(); |
| 197 | m_collectionDescription = collection[QLatin1String("description")].toString(); |
| 198 | m_collectionDescription += QStringLiteral("<br>"); |
| 199 | } |
| 200 | } |
| 201 | ui.lInfo->setText(m_collectionDescription); |
| 202 | updateCategories(); |
| 203 | |
| 204 | // update the completer |
| 205 | if (m_completer) |
| 206 | delete m_completer; |
| 207 | |
| 208 | // add all categories, sub-categories and the dataset names for the current collection |
| 209 | QStringList keywords; |
| 210 | for (const auto& category : m_model->categories(m_collection)) { |
| 211 | keywords << category; |
| 212 | for (const auto& subcategory : m_model->subcategories(m_collection, category)) { |
| 213 | keywords << subcategory; |
| 214 | for (const QString& dataset : m_model->datasets(m_collection, category, subcategory)) |
| 215 | keywords << dataset; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | m_completer = new QCompleter(keywords, this); |
| 220 | m_completer->setCompletionMode(QCompleter::PopupCompletion); |
| 221 | m_completer->setCaseSensitivity(Qt::CaseInsensitive); |
| 222 | m_completer->setFilterMode(Qt::MatchContains); |
| 223 | ui.leSearch->setCompleter(m_completer); |
| 224 | } |
| 225 | |
| 226 | void ImportDatasetWidget::updateCategories() { |
| 227 | m_initializing = true; |
nothing calls this directly
no test coverage detected