refactor: Make paths to update Encryption and HD wallet statuses simpler #403

pull hebasto wants to merge 4 commits into bitcoin-core:master from hebasto:210811-hd changing 5 files +7 −20
  1. hebasto commented at 5:31 pm on August 11, 2021: member

    This PR makes signal-slot paths to reach setHDStatus and setEncryptionStatus functions shorter and easier to reason about them.

    Required to simplify #398 (see #398 (review)).


    Note for reviewers. Please verify that “Encrypt Wallet…” menu item, and the following icons

    DeepinScreenshot_select-area_20210811202120

    and updated properly in each and every possible scenario.

  2. hebasto added the label Refactoring on Aug 11, 2021
  3. hebasto added the label Wallet on Aug 11, 2021
  4. DrahtBot added the label Needs rebase on Aug 11, 2021
  5. in src/qt/walletframe.cpp:112 in c0f84d9d43 outdated
    102@@ -103,7 +103,8 @@ void WalletFrame::setCurrentWallet(WalletModel* wallet_model)
    103     walletView->updateGeometry();
    104 
    105     walletStack->setCurrentWidget(walletView);
    106-    walletView->updateEncryptionStatus();
    


    ryanofsky commented at 4:37 pm on August 12, 2021:

    In commit “qt: Add WalletFrame::currentWalletSet signal” (c0f84d9d4354e128b16524c14b6c2dadb891a1b6)

    Note: At was unclear to me at first if this commit was changing behavior. But it does not seem to change anything since the previous updateEncryptionStatus just called updateWalletStatus indirectly.

  6. ryanofsky approved
  7. ryanofsky commented at 4:44 pm on August 12, 2021: contributor
    Code review ACK ba9a309a4a8f7c07510e4a033fb477d14a115923. All these cleanups do look good and seem to simplify things without changing behavior.
  8. qt: Add WalletFrame::currentWalletSet signal
    The connection of the WalletFrame::currentWalletSet signal to
    the BitcoinGUI::updateWalletStatus is a shorter and more descriptive way
    to call both the setHDStatus and setEncryptionStatus member functions of
    the BitcoinGUI class in comparison to using of the
    WalletView::updateEncryptionStatus slot.
    7d0d4c0490
  9. qt, refactor: Emit WalletView::encryptionStatusChanged signal directly 37dcf161d3
  10. qt, refactor: Drop redundant signalling in WalletView::setWalletModel
    This job will be done by WalletFrame::currentWalletSet signal being
    emitted in the WalletFrame::setCurrentWallet function.
    fcdc8b0fcb
  11. qt, refactor: Replace `if` check with `assert`
    There are no ways BitcoinGUI::updateWalletStatus being called without
    an instance of the WalletFrame class.
    b8aa84b1a1
  12. hebasto force-pushed on Aug 14, 2021
  13. hebasto commented at 4:21 pm on August 14, 2021: member
    Rebased ba9a309a4a8f7c07510e4a033fb477d14a115923 -> b8aa84b1a116599a6dd3b9ddb4e6c178a6688b1b (pr403.01 -> pr403.02) due to the conflict with #399.
  14. DrahtBot removed the label Needs rebase on Aug 14, 2021
  15. in src/qt/bitcoingui.cpp:116 in b8aa84b1a1
    112@@ -113,6 +113,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
    113         connect(walletFrame, &WalletFrame::message, [this](const QString& title, const QString& message, unsigned int style) {
    114             this->message(title, message, style);
    115         });
    116+        connect(walletFrame, &WalletFrame::currentWalletSet, [this] { updateWalletStatus(); });
    


    Talkless commented at 1:32 pm on August 15, 2021:
    Do we really need to wrap that call with lambda? I see that updateWalletStatus is already a slot, or am I missing something?

    hebasto commented at 6:24 pm on August 17, 2021:

    UPDATED: #403 (review) ~No, we don’t.~

    ~The small benefit is that my editor could easy find this call site of updateWalletStatus() function member. It fails to find it by pointer &BitcoinGUI::updateWalletStatus.~

    Are there any drawbacks of such an approach?


    fanquake commented at 0:58 am on August 25, 2021:
    The drawback is writing more verbose / unnecessary code, for no reason other than to appease your editor. If it’s been questioned during review, it’s just as likely someone will open a PR to remove it later on, citing the same reasoning, that, it’s confusing / unnecessary. We really shouldn’t be bloating our codebase just because your editor doesn’t work.

    hebasto commented at 7:37 am on August 25, 2021:

    I strictly prefer QObject::connect(const QObject *sender, PointerToMemberFunction signal, Functor functor) overload over QObject::connect(const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) one for the following reasons:

    • the former states the used signal-slot parameters explicitly, i.e., here it is clear that we use no signal parameters
    • the former is less verbose, compare [this] { updateWalletStatus(); } vs this, &BitcoinGUI::updateWalletStatus

    We really shouldn’t be bloating our codebase just because your editor doesn’t work.

    Absolutely agree. But this is not that case, no?

    Btw, this–very helpful–syntax is already actively used in the code base. E.g. https://github.com/bitcoin/bitcoin/pull/14123 and other prs by @promag.


    fanquake commented at 8:31 am on August 25, 2021:
    Thanks for providing the actual reasoning; this should have been the first comment. I don’t really have an opinion on the code, but was always going to leave the response above, regardless of the change, because the justification “it’s better for my editor”, is not a good one.

    hebasto commented at 8:56 am on August 25, 2021:
    I apologize for that.

    fanquake commented at 9:39 am on August 25, 2021:
    No worries. No need for an apology. Feel free to mark as resolved and merge etc.

    Talkless commented at 12:45 pm on August 26, 2021:

    Are there any drawbacks of such an approach?

    It simply looks like unnecessary indirection, and at least raises question “why?” for some random future code reader.

    Also, “verbosiness” of [this] { updateWalletStatus(); } vs this, &BitcoinGUI::updateWalletStatus is, IMHO, debatable. Former has more of []{();} vs $:: “eye-piercing” stuff . But that’s probably just personal preference :) .

    I like argument that we explicitly see (absence of) arguments, though I would expect lambda usage for actually more complex invocation where you do have to fiddle with arguments, etc.

    Anyway, not gonna resist too much, would still give ACK.

  16. Talkless changes_requested
  17. ryanofsky approved
  18. ryanofsky commented at 6:36 pm on August 23, 2021: contributor
    Code review ACK b8aa84b1a116599a6dd3b9ddb4e6c178a6688b1b. Only change since last review was rebase
  19. jarolrod commented at 7:38 pm on August 25, 2021: member

    tACK b8aa84b1a116599a6dd3b9ddb4e6c178a6688b1b

    tested on Ubuntu 20.04, and macOS 12. I compared the behavior of the icons as I expect them on master with this PR. I cannot guarantee that I tested every variation possible, but my test wallets do cover a wide range of scenarios.

    Notes on commits

  20. Talkless commented at 12:49 pm on August 26, 2021: none
    Code review ACK b8aa84b1a116599a6dd3b9ddb4e6c178a6688b1b. Did build on Debian Sid with Qt 5.15.2 but no actual testing performed.
  21. hebasto merged this on Aug 26, 2021
  22. hebasto closed this on Aug 26, 2021

  23. hebasto deleted the branch on Aug 26, 2021
  24. sidhujag referenced this in commit 560689ab07 on Aug 28, 2021
  25. bitcoin-core locked this on Aug 26, 2022

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-21 12:20 UTC

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