Fix bug due to early return

Github user @marioalexis84 found a bug that caused only the first page
of the most recently-added workbench to show. This refactors the
AddPage() static function to eliminate the early return statement that
was the cause of that bug.
This commit is contained in:
Chris Hennes
2021-01-03 16:01:08 -06:00
committed by wmayer
parent bd8a3c5021
commit 13e2f93bae

View File

@@ -183,18 +183,27 @@ void DlgPreferencesImp::changeGroup(QListWidgetItem *current, QListWidgetItem *p
*/
void DlgPreferencesImp::addPage(const std::string& className, const std::string& group)
{
std::list<TGroupPages>::iterator groupToAddTo = _pages.end();
for (std::list<TGroupPages>::iterator it = _pages.begin(); it != _pages.end(); ++it) {
if (it->first == group) {
it->second.push_back(className);
return;
groupToAddTo = it;
break;
}
}
std::list<std::string> pages;
pages.push_back(className);
_pages.push_back(std::make_pair(group, pages));
if (groupToAddTo != _pages.end()) {
// The group exists: add this page to the end of the list
groupToAddTo->second.push_back(className);
}
else {
// This is a new group: create it, with its one page
std::list<std::string> pages;
pages.push_back(className);
_pages.push_back(std::make_pair(group, pages));
}
if (DlgPreferencesImp::_activeDialog != nullptr) {
// If the dialog is currently showing, tell it to insert the new page
_activeDialog->reloadPages();
}
}