bool RKObjectListViewSettings::filterAcceptsRow (int source_row, const QModelIndex& source_parent) const { // RK_TRACE (APP); // So I tried to use a KRecursiveFilterProxyModel, but // a) we don't really want recursion to the full depth. Thus limiting it, here. // b) While we don't handle insertions / removals of source indices in the presence of a filter, correctly, with KRecursiveFilterProxyModel // I got crashes on this (arguably with the depth-limit in place) if (acceptRow (source_row, source_parent)) return true; RObject *parent = static_cast<RObject*> (source_parent.internalPointer ()); if (!parent) { RK_ASSERT (parent); // should have been accepted, above return true; } RObject *object = parent->findChildByObjectModelIndex (source_row); if (!object) { RK_ASSERT (object); // should have been accepted, above RK_DEBUG (APP, DL_ERROR, "row %d of %d in %s", source_row, sourceModel ()->rowCount (source_parent), qPrintable (parent->getShortName ())); return false; } if (object->isType (RObject::ToplevelEnv | RObject::Workspace) || ((depth_limit > 0) && parent->isType (RObject::ToplevelEnv | RObject::Workspace))) { QModelIndex source_index = sourceModel ()->index (source_row, 0, source_parent); for (int row = 0, rows = sourceModel()->rowCount (source_index); row < rows; ++row) { if (filterAcceptsRow (row, source_index)) return true; } } return false; }
bool RKObjectListViewSettings::acceptRow (int source_row, const QModelIndex& source_parent) const { // RK_TRACE (APP); // always show the root item if (!source_parent.isValid ()) return true; RObject* object = static_cast<RObject*> (source_parent.internalPointer ()); // always show global env and search path if (!object) return true; if (!object->findChildByObjectModelIndex (source_row)) { return true; } object = object->findChildByObjectModelIndex (source_row); RK_ASSERT (object); if (!persistent_settings[ShowObjectsHidden]) { if (object->getShortName ().startsWith ('.')) return false; if (object == reinterpret_cast<RObject*> (RObjectList::getObjectList ()->orphanNamespacesObject ())) return false; } if (hide_functions && object->isType (RObject::Function)) return false; if (hide_non_functions && !object->isType (RObject::Function)) return false; if (filterRegExp ().isEmpty ()) return true; if (filter_on_name && object->getShortName ().contains (filterRegExp ())) return true; if (filter_on_label && object->getLabel ().contains (filterRegExp ())) return true; if (filter_on_class) { QStringList cnames = object->classNames (); for (int i = cnames.length () - 1; i >= 0; --i) { if (cnames[i].contains (filterRegExp ())) return true; } } return false; }