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 #556

Merged
merged 6 commits into from
Apr 15, 2022

Conversation

jb55
Copy link
Contributor

@jb55 jb55 commented Feb 22, 2022

This is a rebased version of #60

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.

@jb55
Copy link
Contributor Author

jb55 commented Feb 22, 2022

Previous invalidated ACKS:

@Sjors tACK
@jonatack Concept ACK
@promag Code Review ACK
@jb55 Code Review 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 3466e7f

src/qt/optionsmodel.cpp Show resolved Hide resolved
@jb55 jb55 force-pushed the units-scoped-enum branch 2 times, most recently from 8df40c8 to 3fb5386 Compare February 22, 2022 20:00
src/qt/optionsmodel.cpp Outdated Show resolved Hide resolved
hebasto and others added 6 commits February 22, 2022 13:50
Since BitcoinUnits::Unit became a scoped enum, BitcoinUnits::valid
function is no longer needed.
Co-authored-by: João Barbosa <joao.paulo.barbosa@gmail.com>
I split this out from an earlier commit to make it a bit less noisy.

Signed-off-by: William Casarin <jb55@jb55.com>
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 0e5dedb

@DrahtBot
Copy link
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #435 (Move third-party tx URL setting from Display to Wallet options tab by jarolrod)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

WIP review, looked at the first commit 75832fd rebased to current master, noting my initial thoughts/questions here so far, continuing tomorrow

};
typedef BitcoinUnits::Unit BitcoinUnit;

QDataStream& operator<<(QDataStream& out, const BitcoinUnit& unit);
QDataStream& operator>>(QDataStream& in, BitcoinUnit& unit);
Copy link
Member

Choose a reason for hiding this comment

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

75832fd

Suggested change
QDataStream& operator>>(QDataStream& in, BitcoinUnit& unit);
QDataStream& operator>>(const QDataStream& in, BitcoinUnit& unit);

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@jonatack jonatack Apr 15, 2022

Choose a reason for hiding this comment

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

Sure but there's no reason for an in-param to be passed by reference instead of by reference to const, see https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f16-for-in-parameters-pass-cheaply-copied-types-by-value-and-others-by-reference-to-const. No big deal either way but I think it's clearer to show that it's an in-param that won't be mutated.

if (!settings.contains("DisplayBitcoinUnit")) {
settings.setValue("DisplayBitcoinUnit", QVariant::fromValue(BitcoinUnit::BTC));
}
QVariant unit = settings.value("DisplayBitcoinUnit");
Copy link
Member

Choose a reason for hiding this comment

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

75832fd this is just memoizing the value, so why not

Suggested change
QVariant unit = settings.value("DisplayBitcoinUnit");
const QVariant& unit = settings.value("DisplayBitcoinUnit");

@jonatack
Copy link
Member

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

Happy to re-ACK if update for the comments above.

@laanwj
Copy link
Member

laanwj commented Apr 14, 2022

Concept ACK

@hebasto hebasto merged commit 72477eb into bitcoin-core:master Apr 15, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 18, 2022
@bitcoin-core bitcoin-core locked and limited conversation to collaborators Apr 15, 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.

6 participants