Don't change combobox index after selection

Also keep the list sorted.

PR #21599.
This commit is contained in:
Chocobo1 2024-10-14 14:39:54 +08:00 committed by Vladimir Golovnev (Glassez)
parent 983b7814aa
commit 4712eba0dc
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7

View file

@ -30,6 +30,7 @@
#include "optionsdialog.h"
#include <algorithm>
#include <chrono>
#include <cstdlib>
#include <limits>
@ -60,6 +61,7 @@
#include "base/rss/rss_session.h"
#include "base/torrentfileguard.h"
#include "base/torrentfileswatcher.h"
#include "base/utils/compare.h"
#include "base/utils/io.h"
#include "base/utils/misc.h"
#include "base/utils/net.h"
@ -1689,18 +1691,12 @@ bool OptionsDialog::isSplashScreenDisabled() const
void OptionsDialog::initializeStyleCombo()
{
#ifdef Q_OS_WIN
QStringList styleNames = QStyleFactory::keys();
std::sort(styleNames.begin(), styleNames.end(), Utils::Compare::NaturalLessThan<Qt::CaseInsensitive>());
m_ui->comboStyle->addItems(styleNames);
const QString prefStyleName = Preferences::instance()->getStyle();
const QString selectedStyleName = prefStyleName.isEmpty() ? QApplication::style()->name() : prefStyleName;
QStringList styleNames = QStyleFactory::keys();
for (qsizetype i = 1, stylesCount = styleNames.size(); i < stylesCount; ++i)
{
if (selectedStyleName.compare(styleNames.at(i), Qt::CaseInsensitive) == 0)
{
styleNames.swapItemsAt(0, i);
break;
}
}
m_ui->comboStyle->addItems(styleNames);
m_ui->comboStyle->setCurrentText(selectedStyleName);
#else
m_ui->labelStyle->hide();
m_ui->comboStyle->hide();