Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 5 commits into from

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Aug 14, 2020

Ported from bitcoin/bitcoin#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.

@hebasto
Copy link
Member Author

hebasto commented Aug 14, 2020

bitcoin/bitcoin#17877 has Concept ACKs from:


@promag @jonasschnelli Mind reviewing this PR?

@hebasto
Copy link
Member Author

hebasto commented Aug 26, 2020

Rebased 243205f -> b109ae6 (pr60.01 -> pr60.02) due to the conflict with #35.

@Sjors
Copy link
Member

Sjors commented Aug 28, 2020

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

@jonasschnelli jonasschnelli added this to the 0.22.0 milestone Nov 11, 2020
@promag
Copy link
Contributor

promag commented Nov 20, 2020

@Sjors I only have git@github.com:bitcoin-core/gui.git and my gui fork.

@maflcko
Copy link
Contributor

maflcko commented Nov 20, 2020

I manually call git fetch https://github.com/hebasto/gui/ 200814-unit, which works without a remote

@elichai
Copy link
Contributor

elichai commented Nov 22, 2020

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

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

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

@hebasto
Copy link
Member Author

hebasto commented Jan 21, 2021

Rebased b109ae6 -> 7e636c7 (pr60.02 -> pr60.03) due to the conflict with #176.

@jonatack
Copy link
Member

Concept ACK

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 7e636c7 with some comments.

Will test and play around.

src/qt/bitcoinunits.cpp Outdated Show resolved Hide resolved
src/qt/bitcoinunits.cpp Outdated Show resolved Hide resolved
@@ -70,9 +71,15 @@ void OptionsModel::Init(bool resetSettings)
fMinimizeOnClose = settings.value("fMinimizeOnClose").toBool();

// Display
if (!settings.contains("nDisplayUnit"))
settings.setValue("nDisplayUnit", BitcoinUnits::BTC);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

77edf1b

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be dead code after a while?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And? For instance bitcoin/bitcoin#20966 also tries to use old data.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

src/qt/optionsmodel.cpp Outdated Show resolved Hide resolved
@hebasto
Copy link
Member Author

hebasto commented Apr 20, 2021

Updated 7e636c7 -> cb08a1c (pr60.03 -> pr60.04, diff):

  • addressed most of @promag's comments

@hebasto
Copy link
Member Author

hebasto commented May 2, 2021

Updated cb08a1c -> 68baad3 (pr60.04 -> pr60.05):

Co-authored-by: João Barbosa <joao.paulo.barbosa@gmail.com>
@hebasto
Copy link
Member Author

hebasto commented May 29, 2021

Rebased 68baad3 -> 8eb1a34 (pr60.05 -> pr60.06) due to the conflict with #275.

@hebasto hebasto removed this from the 22.0 milestone Jun 14, 2021
@jb55
Copy link
Contributor

jb55 commented Jun 22, 2021

Code Review ACK 8eb1a34

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: 😉

(for commit in $(git log --format=%H origin/master..FEATUREBRANCH); do git-contacts ${commit}^-; done) | sort | uniq -c | sort -nr
      5 Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
      4 Wladimir J. van der Laan <laanwj@gmail.com>
      2 William Casarin <jb55@jb55.com>
      2 Russell Yanofsky <russ@yanofsky.org>
      1 João Barbosa <joao.paulo.barbosa@gmail.com>
      1 GreatSock <greatsock@protonmail.com>

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 5, 2021

🐙 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".

@jarolrod
Copy link
Member

jarolrod commented Nov 2, 2021

cc @hebasto, a rebase is needed :)

@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase. What is the status here?
  • 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.

@jb55
Copy link
Contributor

jb55 commented Feb 22, 2022

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

@hebasto
Copy link
Member Author

hebasto commented Feb 22, 2022

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.

@hebasto
Copy link
Member Author

hebasto commented Feb 22, 2022

Closing in favor of #556.

@hebasto hebasto closed this Feb 22, 2022
hebasto added a commit that referenced this pull request Apr 15, 2022
0e5dedb qt/wallettests: sort includes (William Casarin)
0554251 qt: Skip displayUnitChanged signal if unit is not actually changed (Hennadii Stepanov)
ffbc2fe qt, refactor: Remove default cases for scoped enum (Hennadii Stepanov)
152d5ba qt, refactor: Remove BitcoinUnits::valid function (Hennadii Stepanov)
aa23960 qt, refactor: Make BitcoinUnits::Unit a scoped enum (Hennadii Stepanov)
75832fd qt: Use QVariant instead of int for BitcoinUnit in QSettings (Hennadii Stepanov)

Pull request description:

  This is a rebased version of #60

  Since Qt 5.5 there are [means](https://doc.qt.io/qt-5/qobject.html#Q_ENUM) to register an enum type with the meta-object system (such enum still lacks an ability to interact with [QSettings::setValue()](https://doc.qt.io/qt-5/qsettings.html#setValue) and [QSettings::value()](https://doc.qt.io/qt-5/qsettings.html#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.

ACKs for top commit:
  jonatack:
    ACK 0e5dedb, review and debug build of each commit after rebase on current master, lightly tested running the GUI, changing units a few times, and verifying persistence after restarting
  promag:
    Code review ACK 0e5dedb

Tree-SHA512: 39ec0d7e4f0b9b25be287888121a8db6b282339674e37ec3a3554da63a9e22d6fe079e8310ca289b2a0356a19b3c7e55afa17d09dd34e0f222177f603bb053a3
@bitcoin-core bitcoin-core locked and limited conversation to collaborators Feb 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants