Skip to content

Add helper to load font - #448

Merged
hebasto merged 1 commit into
bitcoin-core:masterfrom
promag:2021-10-font-helper
Oct 9, 2021
Merged

hebasto merged 1 commit into
bitcoin-core:masterfrom
promag:2021-10-font-helper

Conversation

@promag

@promag promag commented Oct 7, 2021

Copy link
Copy Markdown
Contributor

Originally submitted as bitcoin-core/gui-qml#49.

@promag promag changed the title qt: Add helper to load font Add helper to load font Oct 7, 2021
@hebasto

hebasto commented Oct 7, 2021

Copy link
Copy Markdown
Member

Concept ACK.

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approach ACK 44f948f.

Comment thread src/qt/guiutil.cpp Outdated
return !selection.at(0).data(role).toString().isEmpty();
}

void loadFont(const QString& file_name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not return id for generality?

From Qt docs:

An ID is returned that can be used to remove the font again with removeApplicationFont() or to retrieve the list of family names contained in the font.

@promag promag Oct 7, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The helper is meant for our use case: load font; ensure it is valid; remains loaded while the application runs.

Happy to add the return value, but at the moment it is discarded at the call site.

Comment thread src/qt/guiutil.cpp Resolved
Comment thread src/qt/bitcoin.cpp Resolved

@shaavan shaavan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Concept ACK

This PR introduces a new loadFont function, which along with adding the font, also asserts that it has been properly added to the QFontDatabase. I agree with the changes in the PR because this function eliminates any chance of font not being correctly added to the Application.

@promag
promag force-pushed the 2021-10-font-helper branch from 44f948f to 98f423d Compare October 7, 2021 15:29

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK 98f423d, tested on Linux Mint 20.2 (Qt 5.12.8).

Comment thread src/qt/guiutil.h Resolved
Comment thread src/qt/guiutil.h Resolved
@promag
promag force-pushed the 2021-10-font-helper branch from 98f423d to d54ec27 Compare October 7, 2021 16:03

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

re-ACK d54ec27

@stratospher stratospher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested ACK d54ec27. Refactoring the code and defining loadFont() in src/qt/guiutil.cpp reduces redundant imports of the QFontDatabase and is a better design.

Fonts in the application remain consistent in both the PR and master.

Master PR
Screenshot 2021-10-07 at 4 38 43 PM Screenshot 2021-10-07 at 4 39 15 PM

@shaavan shaavan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK d54ec27

Changes since my last review:

  • The added function has been renamed from loadFont -> LoadFont according to the name convention
  • QStringLiteral macro is now used to ensure the input string is allocated statically.
  • const keyword is used for the id variable to indicate that it is not modified.
  • The fileName has been corrected to file_name in the comment.

@hebasto
hebasto merged commit 15587b4 into bitcoin-core:master Oct 9, 2021
@promag
promag deleted the 2021-10-font-helper branch October 9, 2021 10:44
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 9, 2021
@luke-jr

luke-jr commented Oct 11, 2021

Copy link
Copy Markdown
Contributor

Why do we want to abort if it fails??

@bitcoin-core bitcoin-core locked as resolved and limited conversation to collaborators Oct 11, 2022
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.

5 participants