Skip to content

Commit c404597

Browse files
Merge #7084: fix: don't assume that successful weightFromArg links to valid index
8bba1d2 fix: don't assume that successful `weightFromArg` links to valid index (Kittywhiskers Van Gogh) Pull request description: ## Additional Information [dash#7068](#7068) introduced a regression where Qt clients with no GUI settings are unable to run at all due to failed weight to index conversion. This was covered in 9cd9d44 but made an incorrect assumption that earlier iterations of the fix (see ef34868) did not make. The assumption made that resulted in this regression was that if the argument to weight conversion is successful, then the weight to index conversion will also be successful. The earlier iteration of the fix checked the return value of the index conversion and set a sane default if it was invalid. The final iteration set the default weight value to the sane weight, expecting `weightFromArg()` to fail (hence using the sane weight), not `supportedWeightToIndex()` (which might not be able to process even a valid weight from argument). This was not caught in testing as over the course of working on [dash#6833](#6833), my GUI settings were migrated to `settings.json`, which has precedence over `QSettings` and therefore, the client always ran with known good Montserrat parameters. Fix can be verified by deleting your QSettings parameters and running the client anew. ## Breaking Changes None expected. ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)** - [x] I have added or updated relevant unit/integration/functional/e2e tests **(note: N/A)** - [x] I have made corresponding changes to the documentation **(note: N/A)** - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK 8bba1d2 PastaPastaPasta: utACK 8bba1d2 Tree-SHA512: 6772d59a8cffb43427ea83b5ff2e725efbfc741e890c40e059ffe2fe3405fbe535f975f4ebbd78fbe44bdf671deaeb1a329b3c29530a8de4cceab02f5ce6009c
2 parents 297c9cc + 8bba1d2 commit c404597

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/qt/optionsmodel.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -564,16 +564,22 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
564564
case FontScale:
565565
return settings.value("fontScale");
566566
case FontWeightNormal: {
567-
QFont::Weight weight{GUIUtil::g_font_registry.GetWeightNormalDefault()};
568-
GUIUtil::weightFromArg(settings.value("fontWeightNormal").toInt(), weight);
569-
int nIndex = GUIUtil::g_font_registry.WeightToIdx(weight);
567+
int nIndex = [&]() -> int {
568+
if (QFont::Weight weight; GUIUtil::weightFromArg(settings.value("fontWeightNormal").toInt(), weight) && GUIUtil::g_font_registry.IsValidWeight(weight)) {
569+
return GUIUtil::g_font_registry.WeightToIdx(weight);
570+
}
571+
return GUIUtil::g_font_registry.WeightToIdx(GUIUtil::g_font_registry.GetWeightNormalDefault());
572+
}();
570573
assert(nIndex != -1);
571574
return nIndex;
572575
}
573576
case FontWeightBold: {
574-
QFont::Weight weight{GUIUtil::g_font_registry.GetWeightBoldDefault()};
575-
GUIUtil::weightFromArg(settings.value("fontWeightBold").toInt(), weight);
576-
int nIndex = GUIUtil::g_font_registry.WeightToIdx(weight);
577+
int nIndex = [&]() -> int {
578+
if (QFont::Weight weight; GUIUtil::weightFromArg(settings.value("fontWeightBold").toInt(), weight) && GUIUtil::g_font_registry.IsValidWeight(weight)) {
579+
return GUIUtil::g_font_registry.WeightToIdx(weight);
580+
}
581+
return GUIUtil::g_font_registry.WeightToIdx(GUIUtil::g_font_registry.GetWeightBoldDefault());
582+
}();
577583
assert(nIndex != -1);
578584
return nIndex;
579585
}

0 commit comments

Comments
 (0)