[education/rkward] rkward/misc: Simplify and fix logic around object list view filtering

Thomas Friedrichsmeier null at kde.org
Sat Oct 10 15:55:37 BST 2026


Git commit a4b9ca4bf414efa5231cbe3140ef39a75fe761fa by Thomas Friedrichsmeier.
Committed on 10/10/2026 at 13:50.
Pushed by tfry into branch 'master'.

Simplify and fix logic around object list view filtering

CCBUG: 526799

M  +12   -30   rkward/misc/rkobjectlistview.cpp
M  +1    -1    rkward/misc/rkobjectlistview.h

https://invent.kde.org/education/rkward/-/commit/a4b9ca4bf414efa5231cbe3140ef39a75fe761fa

diff --git a/rkward/misc/rkobjectlistview.cpp b/rkward/misc/rkobjectlistview.cpp
index 339bd4a96..60b3c197a 100644
--- a/rkward/misc/rkobjectlistview.cpp
+++ b/rkward/misc/rkobjectlistview.cpp
@@ -365,49 +365,31 @@ bool RKObjectListViewSettings::filterAcceptsColumn(int source_column, const QMod
 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);
+	// always show the root item
+	if (!source_parent.isValid()) return true;
+	const RObject *parent = static_cast<RObject *>(source_parent.internalPointer());
+	RK_ASSERT(parent);
+	const 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()));
+		RK_DEBUG(APP, DL_ERROR, "proxy model wants row %d of %d in %s", source_row, sourceModel()->rowCount(source_parent) - 1, qPrintable(parent->getShortName()));
 		return false;
 	}
+	if (filterAcceptsObject(object)) return true;
 
+	/* This is similar to but not quite the same as QSortFilterProxyModel::recursiveFilteringEnabled(), as
+	 * we only want limited recursion (at most direct children of top level objects) */
 	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;
+		for (int row = 0, rows = object->numChildrenForObjectModel(); row < rows; ++row) {
+			if (filterAcceptsObject(object->findChildByObjectModelIndex(row))) return true;
 		}
 	}
 
 	return false;
 }
 
-bool RKObjectListViewSettings::acceptRow(int source_row, const QModelIndex &source_parent) const {
+bool RKObjectListViewSettings::filterAcceptsObject(const RObject *object) 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(u'.')) return false;
 		if (object == reinterpret_cast<RObject *>(RObjectList::getObjectList()->orphanNamespacesObject())) return false;
diff --git a/rkward/misc/rkobjectlistview.h b/rkward/misc/rkobjectlistview.h
index 9cb436b6a..52a1ceb93 100644
--- a/rkward/misc/rkobjectlistview.h
+++ b/rkward/misc/rkobjectlistview.h
@@ -103,7 +103,7 @@ class RKObjectListViewSettings : public QSortFilterProxyModel {
 
   protected:
 	bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
-	bool acceptRow(int source_row, const QModelIndex &source_parent) const;
+	bool filterAcceptsObject(const RObject *object) const;
 	bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const override;
 	bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
 



More information about the rkward-tracker mailing list