refactor: Make BitcoinUnits::Unit a scoped enum #60

pull hebasto wants to merge 5 commits into bitcoin-core:master from hebasto:200814-unit changing 19 files +189 −159
  1. hebasto commented at 10:52 am on August 14, 2020: member

    Ported from https://github.com/bitcoin/bitcoin/pull/17877.

    Since Qt 5.5 there are means to register an enum type with the meta-object system (such enum still lacks an ability to interact with QSettings::setValue() and QSettings::value() without defined stream operators).

    In order to reduce global namespace polluting and to force strong type checking, this PR makes BitcoinUnits::Unit a scoped enum (typedef BitcoinUnits::Unit BitcoinUnit;).

    No behavior change.

  2. hebasto commented at 10:57 am on August 14, 2020: member

    bitcoin/bitcoin#17877 has Concept ACKs from:


    @promag @jonasschnelli Mind reviewing this PR?

  3. DrahtBot added the label Needs rebase on Aug 26, 2020
  4. MarcoFalke added the label Refactoring on Aug 26, 2020
  5. hebasto force-pushed on Aug 26, 2020
  6. hebasto commented at 5:54 pm on August 26, 2020: member
    Rebased 243205f85b8b10e4f43865557cdd8ea3aa71c380 -> b109ae6d2b292f561d2afbc3e4985651f06575be (pr60.01 -> pr60.02) due to the conflict with #35.
  7. DrahtBot removed the label Needs rebase on Aug 26, 2020
  8. Sjors commented at 12:26 pm on August 28, 2020: member

    tACK b109ae6

    I just noticed one practical downside of this separate repo; having to add another remote: git remote add hebasto-gui git@github.com:hebasto/gui.git

  9. jonasschnelli added this to the milestone 0.22.0 on Nov 11, 2020
  10. promag commented at 9:37 am on November 20, 2020: contributor
    @Sjors I only have git@github.com:bitcoin-core/gui.git and my gui fork.
  11. MarcoFalke commented at 9:56 am on November 20, 2020: contributor
    I manually call git fetch https://github.com/hebasto/gui/ 200814-unit, which works without a remote
  12. elichai commented at 10:07 am on November 22, 2020: contributor

    FWIW, I’m like @promag and using @jonatack’s scripts to fetch all PRs:

    0[remote "upstream"]
    1        fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*
    

    then you can just git checkout upstream/pr/60.

  13. DrahtBot added the label Needs rebase on Jan 21, 2021
  14. hebasto force-pushed on Jan 21, 2021
  15. hebasto commented at 8:35 pm on January 21, 2021: member
    Rebased b109ae6d2b292f561d2afbc3e4985651f06575be -> 7e636c7fe129afff8ff248cdd6b55e59445f1e0e (pr60.02 -> pr60.03) due to the conflict with #176.
  16. DrahtBot removed the label Needs rebase on Jan 21, 2021
  17. jonatack commented at 3:13 pm on March 26, 2021: contributor
    Concept ACK
  18. in src/qt/bitcoinunits.cpp:270 in 77edf1bd01 outdated
    265+{
    266+    switch (num) {
    267+    case 3: return BitcoinUnits::SAT;
    268+    case 2: return BitcoinUnits::uBTC;
    269+    case 1: return BitcoinUnits::mBTC;
    270+    default: return BitcoinUnits::BTC;
    


    promag commented at 8:21 pm on April 19, 2021:

    77edf1bd0149bd2625dff563f3bd4032a12a2233

    Add case for 0 and an assert(false) in default?


    hebasto commented at 7:47 pm on April 20, 2021:
    Thanks! Updated.
  19. in src/qt/bitcoinunits.cpp:253 in 77edf1bd01 outdated
    247@@ -248,3 +248,39 @@ CAmount BitcoinUnits::maxMoney()
    248 {
    249     return MAX_MONEY;
    250 }
    251+
    252+namespace {
    253+qint8 ToQuint8(BitcoinUnit unit)
    


    promag commented at 8:21 pm on April 19, 2021:

    77edf1bd0149bd2625dff563f3bd4032a12a2233

    ToQint8?


    hebasto commented at 7:47 pm on April 20, 2021:
    Thanks! Updated.
  20. in src/qt/optionsmodel.cpp:75 in 77edf1bd01 outdated
    70@@ -70,9 +71,15 @@ void OptionsModel::Init(bool resetSettings)
    71     fMinimizeOnClose = settings.value("fMinimizeOnClose").toBool();
    72 
    73     // Display
    74-    if (!settings.contains("nDisplayUnit"))
    75-        settings.setValue("nDisplayUnit", BitcoinUnits::BTC);
    


    promag commented at 8:22 pm on April 19, 2021:

    77edf1bd0149bd2625dff563f3bd4032a12a2233

    Maybe it should migrate the old setting key if it exists?


    hebasto commented at 6:26 pm on April 20, 2021:
    Will it be dead code after a while?

    promag commented at 8:14 pm on April 20, 2021:
    And? For instance https://github.com/bitcoin/bitcoin/pull/20966 also tries to use old data.

    hebasto commented at 1:12 pm on May 2, 2021:

    @promag I was thinking about your suggestion, and I failed to find a safe and short (about 1..2 lines of code) solution. OTOH, adjusting this option requires only two clicks.

    Therefore, I’m going to leave it as is, leaving a room for improvements in follow ups.

  21. in src/qt/optionsmodel.cpp:511 in 77edf1bd01 outdated
    507@@ -501,12 +508,11 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
    508 /** Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal */
    509 void OptionsModel::setDisplayUnit(const QVariant &value)
    510 {
    511-    if (!value.isNull())
    512-    {
    513+    if (!value.isNull()) {
    


    promag commented at 8:26 pm on April 19, 2021:

    77edf1bd0149bd2625dff563f3bd4032a12a2233

    nit, could skip if value == m_display_unit?


    hebasto commented at 7:47 pm on April 20, 2021:
    Thanks! Updated.
  22. promag commented at 8:29 pm on April 19, 2021: contributor

    Code review ACK 7e636c7fe129afff8ff248cdd6b55e59445f1e0e with some comments.

    Will test and play around.

  23. hebasto force-pushed on Apr 20, 2021
  24. hebasto commented at 7:47 pm on April 20, 2021: member

    Updated 7e636c7fe129afff8ff248cdd6b55e59445f1e0e -> cb08a1c22d5bbf7baf5dc5003dd29185660efd78 (pr60.03 -> pr60.04, diff):

    • addressed most of @promag’s comments
  25. DrahtBot added the label Needs rebase on Apr 20, 2021
  26. hebasto force-pushed on May 2, 2021
  27. hebasto commented at 1:32 pm on May 2, 2021: member

    Updated cb08a1c22d5bbf7baf5dc5003dd29185660efd78 -> 68baad3cfac5c0daf9589a92ea1e99c20cc0e380 (pr60.04 -> pr60.05):

    • rebased due to the conflict with #263
    • option renamed s/display_unit/DisplayBitcoinUnit/ to be in line with other recently added options, see #295
  28. DrahtBot removed the label Needs rebase on May 2, 2021
  29. DrahtBot added the label Needs rebase on May 28, 2021
  30. qt: Use QVariant instead of int for BitcoinUnit in QSettings
    This change improves type safety.
    f07c8c57cb
  31. qt, refactor: Make BitcoinUnits::Unit a scoped enum a11cfe9690
  32. qt, refactor: Remove BitcoinUnits::valid function
    Since BitcoinUnits::Unit became a scoped enum, BitcoinUnits::valid
    function is no longer needed.
    7a82cdc8c9
  33. qt, refactor: Remove default cases for scoped enum 16e7d3f118
  34. qt: Skip displayUnitChanged signal if unit is not actually changed
    Co-authored-by: João Barbosa <joao.paulo.barbosa@gmail.com>
    8eb1a34937
  35. hebasto force-pushed on May 29, 2021
  36. hebasto commented at 12:47 pm on May 29, 2021: member
    Rebased 68baad3cfac5c0daf9589a92ea1e99c20cc0e380 -> 8eb1a34937990012d661d262a029e33c8cb67776 (pr60.05 -> pr60.06) due to the conflict with #275.
  37. DrahtBot removed the label Needs rebase on May 29, 2021
  38. hebasto removed this from the milestone 22.0 on Jun 14, 2021
  39. jb55 commented at 2:33 pm on June 22, 2021: contributor

    Code Review ACK 8eb1a34937990012d661d262a029e33c8cb67776

    looks like a reasonable cleanup

    note: I found this PR with a git script that emails you when someone touches a part of the codebase you’ve previously touched (via git-contacts and git-blame). I recommend using this trick to find potential reviewers: 😉

    0(for commit in $(git log --format=%H origin/master..FEATUREBRANCH); do git-contacts ${commit}^-; done) | sort | uniq -c | sort -nr
    1      5 Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
    2      4 Wladimir J. van der Laan <laanwj@gmail.com>
    3      2 William Casarin <jb55@jb55.com>
    4      2 Russell Yanofsky <russ@yanofsky.org>
    5      1 João Barbosa <joao.paulo.barbosa@gmail.com>
    6      1 GreatSock <greatsock@protonmail.com>
    
  40. DrahtBot added the label Needs rebase on Oct 5, 2021
  41. DrahtBot commented at 8:09 am on October 5, 2021: contributor

    🐙 This pull request conflicts with the target branch and needs rebase.

    Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a “draft”.

  42. jarolrod commented at 5:10 am on November 2, 2021: member
    cc @hebasto, a rebase is needed :)
  43. DrahtBot commented at 12:09 pm on February 22, 2022: contributor
    • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
    • Is it no longer relevant? ➡️ Please close.
    • Did the author lose interest or time to work on this? ➡️ Please close it and mark it ‘Up for grabs’ with the label, so that it can be picked up in the future.
  44. jb55 commented at 5:31 pm on February 22, 2022: contributor

    I have a rebased version here: https://github.com/bitcoin-core/gui/compare/master...jb55:units-scoped-enum

    I can submit a PR if you want me to take this over @hebasto

  45. hebasto commented at 5:37 pm on February 22, 2022: member

    I have a rebased version here: master…jb55:units-scoped-enum

    I can submit a PR if you want me to take this over @hebasto @jb55

    Thank you! I’ll appreciate if you do that.

  46. hebasto commented at 5:46 pm on February 22, 2022: member
    Closing in favor of #556.
  47. hebasto closed this on Feb 22, 2022

  48. hebasto referenced this in commit 72477ebb11 on Apr 15, 2022
  49. bitcoin-core locked this on Feb 22, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/gui. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-23 07:20 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me