1
0
Fork 0

configure_dialog: reverse tab map to avoid logic based on user-facing/translatable text (#4866)

This commit is contained in:
Weiyi Wang 2019-08-10 03:00:56 -04:00 committed by Ben
parent 8131bd32e3
commit 88db89bf57
1 changed files with 17 additions and 16 deletions

View File

@ -68,19 +68,20 @@ void ConfigureDialog::ApplyConfiguration() {
Settings::LogSettings(); Settings::LogSettings();
} }
Q_DECLARE_METATYPE(QList<QWidget*>);
void ConfigureDialog::PopulateSelectionList() { void ConfigureDialog::PopulateSelectionList() {
ui->selectorList->clear(); ui->selectorList->clear();
const std::array<std::pair<QString, QStringList>, 4> items{ const std::array<std::pair<QString, QList<QWidget*>>, 4> items{
{{tr("General"), {{tr("General"), {ui->generalTab, ui->webTab, ui->debugTab, ui->uiTab}},
{QT_TR_NOOP("General"), QT_TR_NOOP("Web"), QT_TR_NOOP("Debug"), QT_TR_NOOP("UI")}}, {tr("System"), {ui->systemTab, ui->audioTab, ui->cameraTab}},
{tr("System"), {QT_TR_NOOP("System"), QT_TR_NOOP("Audio"), QT_TR_NOOP("Camera")}}, {tr("Graphics"), {ui->graphicsTab}},
{tr("Graphics"), {QT_TR_NOOP("Graphics")}}, {tr("Controls"), {ui->inputTab, ui->hotkeysTab}}}};
{tr("Controls"), {QT_TR_NOOP("Input"), QT_TR_NOOP("Hotkeys")}}}};
for (const auto& entry : items) { for (const auto& entry : items) {
auto* const item = new QListWidgetItem(entry.first); auto* const item = new QListWidgetItem(entry.first);
item->setData(Qt::UserRole, entry.second); item->setData(Qt::UserRole, QVariant::fromValue(entry.second));
ui->selectorList->addItem(item); ui->selectorList->addItem(item);
} }
@ -120,17 +121,17 @@ void ConfigureDialog::UpdateVisibleTabs() {
if (items.isEmpty()) if (items.isEmpty())
return; return;
const std::map<QString, QWidget*> widgets = { const std::map<QWidget*, QString> widgets = {
{QStringLiteral("General"), ui->generalTab}, {QStringLiteral("System"), ui->systemTab}, {ui->generalTab, tr("General")}, {ui->systemTab, tr("System")},
{QStringLiteral("Input"), ui->inputTab}, {QStringLiteral("Hotkeys"), ui->hotkeysTab}, {ui->inputTab, tr("Input")}, {ui->hotkeysTab, tr("Hotkeys")},
{QStringLiteral("Graphics"), ui->graphicsTab}, {QStringLiteral("Audio"), ui->audioTab}, {ui->graphicsTab, tr("Graphics")}, {ui->audioTab, tr("Audio")},
{QStringLiteral("Camera"), ui->cameraTab}, {QStringLiteral("Debug"), ui->debugTab}, {ui->cameraTab, tr("Camera")}, {ui->debugTab, tr("Debug")},
{QStringLiteral("Web"), ui->webTab}, {QStringLiteral("UI"), ui->uiTab}}; {ui->webTab, tr("Web")}, {ui->uiTab, tr("UI")}};
ui->tabWidget->clear(); ui->tabWidget->clear();
const QStringList tabs = items[0]->data(Qt::UserRole).toStringList(); const QList<QWidget*> tabs = qvariant_cast<QList<QWidget*>>(items[0]->data(Qt::UserRole));
for (const auto& tab : tabs) for (const auto tab : tabs)
ui->tabWidget->addTab(widgets.at(tab), tr(qPrintable(tab))); ui->tabWidget->addTab(tab, widgets.at(tab));
} }