| 269 | } |
| 270 | |
| 271 | bool TreeViewComboBox::filter(const QModelIndex& index, const QString& text) { |
| 272 | bool childVisible = false; |
| 273 | const int rows = index.model()->rowCount(index); |
| 274 | for (int i = 0; i < rows; i++) { |
| 275 | QModelIndex child = index.model()->index(i, 0, index); |
| 276 | auto* aspect = static_cast<AbstractAspect*>(child.internalPointer()); |
| 277 | bool topLevel = isTopLevel(aspect); |
| 278 | if (!topLevel) |
| 279 | continue; |
| 280 | |
| 281 | bool visible = aspect->name().contains(text, Qt::CaseInsensitive); |
| 282 | |
| 283 | if (visible) { |
| 284 | // current item is visible -> make all its children (allowed top level types only and not hidden) visible without applying the filter |
| 285 | for (int j = 0; j < child.model()->rowCount(child); ++j) { |
| 286 | AbstractAspect* aspect = static_cast<AbstractAspect*>((child.model()->index(j, 0, child)).internalPointer()); |
| 287 | m_treeView->setRowHidden(j, child, !(isTopLevel(aspect) && !isHidden(aspect))); |
| 288 | } |
| 289 | |
| 290 | childVisible = true; |
| 291 | } else { |
| 292 | // check children items. if one of the children is visible, make the parent (current) item visible too. |
| 293 | visible = filter(child, text); |
| 294 | if (visible) |
| 295 | childVisible = true; |
| 296 | } |
| 297 | |
| 298 | m_treeView->setRowHidden(i, index, !(visible && !isHidden(aspect))); |
| 299 | } |
| 300 | |
| 301 | return childVisible; |
| 302 | } |
| 303 | |
| 304 | /*! |
| 305 | checks whether \c aspect is one of the allowed top level types |
no test coverage detected