| 265 | } |
| 266 | |
| 267 | void InstanceManagerDialog::updateList() |
| 268 | { |
| 269 | const auto prevSelIndex = singleSelectionIndex(); |
| 270 | const auto* prevSel = singleSelection(); |
| 271 | |
| 272 | m_model->clear(); |
| 273 | |
| 274 | std::size_t sel = NoSelection; |
| 275 | |
| 276 | // creating items for instances |
| 277 | for (std::size_t i = 0; i < m_instances.size(); ++i) { |
| 278 | const auto& ii = *m_instances[i]; |
| 279 | |
| 280 | auto* item = new QStandardItem(ii.displayName()); |
| 281 | item->setIcon(instanceIcon(m_pc, ii)); |
| 282 | |
| 283 | m_model->appendRow(item); |
| 284 | |
| 285 | if (&ii == prevSel) { |
| 286 | sel = i; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | // keep current selection or select the next one if there was a selection; |
| 291 | // there's no selection when opening the dialog, that's handled in the ctor |
| 292 | if (prevSel) { |
| 293 | if (m_instances.empty()) { |
| 294 | select(-1); |
| 295 | } else { |
| 296 | if (sel == NoSelection) { |
| 297 | if (prevSelIndex >= m_instances.size()) { |
| 298 | sel = m_instances.size() - 1; |
| 299 | } else { |
| 300 | sel = prevSelIndex; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | select(sel); |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | void InstanceManagerDialog::select(std::size_t i) |
| 310 | { |
nothing calls this directly
no test coverage detected