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

Method filter

src/frontend/widgets/TreeViewComboBox.cpp:271–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269}
270
271bool 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

Callers 3

unsubscribeTopicMethod · 0.45
mqttMessageReceivedMethod · 0.45

Calls 6

rowCountMethod · 0.45
modelMethod · 0.45
indexMethod · 0.45
containsMethod · 0.45
nameMethod · 0.45
setRowHiddenMethod · 0.45

Tested by

no test coverage detected