Merge pull request #15382 from Syres916/Fix_Theme_ComboBox_Lookup

[Gui] Preferences - fix the theme combobox index lookup...
This commit is contained in:
Chris Hennes
2024-07-16 23:26:47 -05:00
committed by GitHub

View File

@@ -329,8 +329,9 @@ void DlgSettingsGeneral::loadSettings()
}
QAbstractItemModel* model = ui->Languages->model();
if (model)
if (model) {
model->sort(0);
}
addIconSizes(getCurrentIconSize());
@@ -425,18 +426,44 @@ void DlgSettingsGeneral::loadThemes()
{
ui->themesCombobox->clear();
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/MainWindow");
QString currentTheme = QString::fromLatin1(hGrp->GetASCII("Theme", "").c_str());
Application::Instance->prefPackManager()->rescan();
auto packs = Application::Instance->prefPackManager()->preferencePacks();
QString currentStyleSheet = QString::fromLatin1(hGrp->GetASCII("StyleSheet", "").c_str());
QFileInfo fi(currentStyleSheet);
currentStyleSheet = fi.baseName();
QString themeClassic = QStringLiteral("classic"); // handle the upcoming name change
QString similarTheme;
QString packName;
for (const auto& pack : packs) {
if (pack.second.metadata().type() == "Theme") {
packName = QString::fromStdString(pack.first);
if (packName.contains(themeClassic, Qt::CaseInsensitive)) {
themeClassic = QString::fromStdString(pack.first);
}
if (packName.contains(currentStyleSheet, Qt::CaseInsensitive)) {
similarTheme = QString::fromStdString(pack.first);
}
ui->themesCombobox->addItem(QString::fromStdString(pack.first));
}
}
if (currentTheme.isEmpty()) {
if (!currentStyleSheet.isEmpty()
&& !similarTheme.isEmpty()) { // a user upgrading from 0.21 or earlier
hGrp->SetASCII("Theme", similarTheme.toStdString());
currentTheme = QString::fromLatin1(hGrp->GetASCII("Theme", "").c_str());
}
else { // a brand new user
hGrp->SetASCII("Theme", themeClassic.toStdString());
currentTheme = QString::fromLatin1(hGrp->GetASCII("Theme", "").c_str());
}
}
int index = ui->themesCombobox->findText(currentTheme);
if (index >= 0 && index < ui->themesCombobox->count()) {
ui->themesCombobox->setCurrentIndex(index);