[LyX/master] Amend ac275a66b5

Juergen Spitzmueller spitz at lyx.org
Mon Sep 18 06:10:11 UTC 2023


commit d3102380bcd163ab19c9b1e14d82af0eaaf246ef
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Mon Sep 18 09:27:38 2023 +0200

    Amend ac275a66b5
    
    Set depth correctly in the active branch
---
 src/frontends/qt/TocWidget.cpp |   17 ++++++++++++++++-
 src/frontends/qt/TocWidget.h   |    2 ++
 2 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/src/frontends/qt/TocWidget.cpp b/src/frontends/qt/TocWidget.cpp
index 4cbcf96..0770cf3 100644
--- a/src/frontends/qt/TocWidget.cpp
+++ b/src/frontends/qt/TocWidget.cpp
@@ -611,6 +611,19 @@ QModelIndex TocWidget::getAncestor(QModelIndex const & descendant) const
 }
 
 
+int TocWidget::getItemDepth(QModelIndex const & index_in)
+{
+	QModelIndex index = index_in;
+	int depth = 1;
+	while (index.parent().isValid())
+	{
+		index = index.parent();
+		++depth;
+	}
+	return depth;
+}
+
+
 void TocWidget::collapseAllOthers(int const depth)
 {
 	if (!tocTV->model())
@@ -620,11 +633,13 @@ void TocWidget::collapseAllOthers(int const depth)
 
 	int size = indices.size();
 	// collapse parents which are not in our ancestry line
+	// and which exceed the requested depth
 	for (int i = size - 1; i >= 0; i--) {
 		QModelIndex index = indices[i];
 		if (tocTV->isExpanded(index)
 		    && !isAncestor(index, tocTV->currentIndex())) {
-			tocTV->collapse(index);
+			if (depth < getItemDepth(index))
+				tocTV->collapse(index);
 			if (depth > 0 && index.parent() == QModelIndex())
 				tocTV->expandRecursively(index, depth - 1);
 		}
diff --git a/src/frontends/qt/TocWidget.h b/src/frontends/qt/TocWidget.h
index c56d0ae..72c6089 100644
--- a/src/frontends/qt/TocWidget.h
+++ b/src/frontends/qt/TocWidget.h
@@ -108,6 +108,8 @@ private:
 	QModelIndex getAncestor(QModelIndex const & descendant) const;
 	/// \returns \c true if \p ancestor is an ancestor (parent, grandparent, etc.) of \p descendant
 	bool isAncestor(QModelIndex const & ancestor, QModelIndex const & descendant) const;
+	/// \returns depth of the current item
+	int getItemDepth(QModelIndex const & index);
 	/// collapse all nodes to \c depth except for the branch of the currently active item
 	void collapseAllOthers(int const depth);
 	///


More information about the lyx-cvs mailing list