Skip to content

Commit 36ad63b

Browse files
Remember category expansion state when regenerating music list (#1083)
* remember category expansion state when regenerating musiclist * don't do file i/o here actually --------- Co-authored-by: stonedDiscord <Tukz@gmx.de>
1 parent 50075c7 commit 36ad63b

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/courtroom.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,17 @@ void Courtroom::enter_courtroom()
16781678
// Todo: multithread this due to some servers having large as hell music list
16791679
void Courtroom::list_music()
16801680
{
1681+
// remember collapsed categories
1682+
QStringList collapsed_categories;
1683+
for (int i = 0; i < ui_music_list->topLevelItemCount(); ++i)
1684+
{
1685+
const auto pCategory = ui_music_list->topLevelItem(i);
1686+
if (!pCategory->isExpanded())
1687+
{
1688+
collapsed_categories.append(pCategory->text(0));
1689+
}
1690+
}
1691+
16811692
ui_music_list->clear();
16821693
// ui_music_search->setText("");
16831694

@@ -1767,9 +1778,23 @@ void Courtroom::list_music()
17671778
}
17681779
}
17691780

1770-
ui_music_list->expandAll(); // Needs to somehow remember which categories were
1771-
// expanded/collapsed if the music list didn't
1772-
// change since last time
1781+
ui_music_list->expandAll();
1782+
1783+
// restore expanded state from before the list was reset
1784+
// disable animations while we do this
1785+
bool was_animated = ui_music_list->isAnimated();
1786+
ui_music_list->setAnimated(false);
1787+
for (int i = 0; i < ui_music_list->topLevelItemCount(); ++i)
1788+
{
1789+
const auto pCategory = ui_music_list->topLevelItem(i);
1790+
if (collapsed_categories.contains(pCategory->text(0)))
1791+
{
1792+
pCategory->setExpanded(false);
1793+
}
1794+
}
1795+
// restore animated state
1796+
ui_music_list->setAnimated(was_animated);
1797+
17731798
if (ui_music_search->text() != "")
17741799
{
17751800
on_music_search_edited(ui_music_search->text());

0 commit comments

Comments
 (0)