mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
parent
63b99beedd
commit
d3102380bc
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user