Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Typedefs | Functions | Variables
GUIUtil Namespace Reference

Utility functions used by the Bitcoin Qt UI. More...

Classes

class  ClickableLabel
 
class  ClickableProgressBar
 
class  ItemDelegate
 
class  LabelOutOfFocusEventFilter
 Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and resets their ‘textInteractionFlags’ property to get rid of the visible cursor. More...
 
class  ThemedLabel
 
class  ToolTipToRichTextFilter
 Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text representation if needed. More...
 

Typedefs

typedef ClickableProgressBar ProgressBar
 

Functions

QString dateTimeStr (const QDateTime &date)
 
QString dateTimeStr (qint64 nTime)
 
QFont fixedPitchFont (bool use_embedded_font)
 
static std::string DummyAddress (const CChainParams &params)
 
void setupAddressWidget (QValidatedLineEdit *widget, QWidget *parent)
 
void AddButtonShortcut (QAbstractButton *button, const QKeySequence &shortcut)
 Connects an additional shortcut to a QAbstractButton. More...
 
bool parseBitcoinURI (const QUrl &uri, SendCoinsRecipient *out)
 
bool parseBitcoinURI (QString uri, SendCoinsRecipient *out)
 
QString formatBitcoinURI (const SendCoinsRecipient &info)
 
bool isDust (interfaces::Node &node, const QString &address, const CAmount &amount)
 
QString HtmlEscape (const QString &str, bool fMultiLine)
 
QString HtmlEscape (const std::string &str, bool fMultiLine)
 
void copyEntryData (const QAbstractItemView *view, int column, int role=Qt::EditRole)
 Copy a field of the currently selected entry of a view to the clipboard. More...
 
QList< QModelIndex > getEntryData (const QAbstractItemView *view, int column)
 Return a field of the currently selected entry as a QString. More...
 
bool hasEntryData (const QAbstractItemView *view, int column, int role)
 Returns true if the specified field of the currently selected view entry is not empty. More...
 
void LoadFont (const QString &file_name)
 Loads the font from the file specified by file_name, aborts if it fails. More...
 
QString getDefaultDataDirectory ()
 Determine default data directory for operating system. More...
 
QString ExtractFirstSuffixFromFilter (const QString &filter)
 Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...). More...
 
QString getSaveFileName (QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
 Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when no suffix is provided by the user. More...
 
QString getOpenFileName (QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedSuffixOut)
 Get open filename, convenience wrapper for QFileDialog::getOpenFileName. More...
 
Qt::ConnectionType blockingGUIThreadConnection ()
 Get connection type to call object slot in GUI thread with invokeMethod. More...
 
bool checkPoint (const QPoint &p, const QWidget *w)
 
bool isObscured (QWidget *w)
 
void bringToFront (QWidget *w)
 
void handleCloseWindowShortcut (QWidget *w)
 
void openDebugLogfile ()
 
bool openBitcoinConf ()
 
bool GetStartOnSystemStartup ()
 
bool SetStartOnSystemStartup (bool fAutoStart)
 
void setClipboard (const QString &str)
 
fs::path QStringToPath (const QString &path)
 Convert QString to OS specific boost path through UTF-8. More...
 
QString PathToQString (const fs::path &path)
 Convert OS specific boost path to QString through UTF-8. More...
 
QString NetworkToQString (Network net)
 Convert enum Network to QString. More...
 
QString ConnectionTypeToQString (ConnectionType conn_type, bool prepend_direction)
 Convert enum ConnectionType to QString. More...
 
QString formatDurationStr (std::chrono::seconds dur)
 Convert seconds into a QString with days, hours, mins, secs. More...
 
QString FormatPeerAge (std::chrono::seconds time_connected)
 Convert peer connection time to a QString denominated in the most relevant unit. More...
 
QString formatServicesStr (quint64 mask)
 Format CNodeStats.nServices bitmask into a user-readable string. More...
 
QString formatPingTime (std::chrono::microseconds ping_time)
 Format a CNodeStats.m_last_ping_time into a user-readable string or display N/A, if 0. More...
 
QString formatTimeOffset (int64_t time_offset)
 Format a CNodeStateStats.time_offset into a user-readable string. More...
 
QString formatNiceTimeOffset (qint64 secs)
 
QString formatBytes (uint64_t bytes)
 
qreal calculateIdealFontSize (int width, const QString &text, QFont font, qreal minPointSize, qreal font_size)
 
void PolishProgressDialog (QProgressDialog *dialog)
 
int TextWidth (const QFontMetrics &fm, const QString &text)
 Returns the distance in pixels appropriate for drawing a subsequent character after text. More...
 
void LogQtInfo ()
 Writes to debug.log short info about the used Qt and the host system. More...
 
void PopupMenu (QMenu *menu, const QPoint &point, QAction *at_action=nullptr)
 Call QMenu::popup() only on supported QT_QPA_PLATFORM. More...
 
QDateTime StartOfDay (const QDate &date)
 Returns the start-moment of the day in local time. More...
 
bool HasPixmap (const QLabel *label)
 Returns true if pixmap has been set. More...
 
QImage GetImage (const QLabel *label)
 
QString MakeHtmlLink (const QString &source, const QString &link)
 Replaces a plain text link with an HTML tagged one. More...
 
void PrintSlotException (const std::exception *exception, const QObject *sender, const QObject *receiver)
 
void ShowModalDialogAsynchronously (QDialog *dialog)
 Shows a QDialog instance asynchronously, and deletes it on close. More...
 
QString WalletDisplayName (const QString &name)
 
QString WalletDisplayName (const std::string &name)
 
template<typename SeparatorType >
QStringList SplitSkipEmptyParts (const QString &string, const SeparatorType &separator)
 Splits the string into substrings wherever separator occurs, and returns the list of those strings. More...
 
template<typename Sender , typename Signal , typename Receiver , typename Slot >
auto ExceptionSafeConnect (Sender sender, Signal signal, Receiver receiver, Slot method, Qt::ConnectionType type=Qt::AutoConnection)
 A drop-in replacement of QObject::connect function (see: https://doc.qt.io/qt-5/qobject.html#connect-3), that guaranties that all exceptions are handled within the slot. More...
 
bool IsEscapeOrBack (int key)
 

Variables

constexpr auto dialog_flags = Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint
 

Detailed Description

Utility functions used by the Bitcoin Qt UI.

Typedef Documentation

◆ ProgressBar

Definition at line 300 of file guiutil.h.

Function Documentation

◆ AddButtonShortcut()

void GUIUtil::AddButtonShortcut ( QAbstractButton *  button,
const QKeySequence &  shortcut 
)

Connects an additional shortcut to a QAbstractButton.

Works around the one shortcut limitation of the button's shortcut property.

Parameters
[in]buttonQAbstractButton to assign shortcut to
[in]shortcutQKeySequence to use as shortcut

Definition at line 144 of file guiutil.cpp.

Here is the caller graph for this function:

◆ blockingGUIThreadConnection()

Qt::ConnectionType GUIUtil::blockingGUIThreadConnection ( )

Get connection type to call object slot in GUI thread with invokeMethod.

The call will be blocking.

Returns
If called from the GUI thread, return a Qt::DirectConnection. If called from another thread, return a Qt::BlockingQueuedConnection.

Definition at line 378 of file guiutil.cpp.

Here is the caller graph for this function:

◆ bringToFront()

void GUIUtil::bringToFront ( QWidget *  w)

Definition at line 406 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculateIdealFontSize()

qreal GUIUtil::calculateIdealFontSize ( int  width,
const QString &  text,
QFont  font,
qreal  minPointSize,
qreal  font_size 
)

Definition at line 836 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkPoint()

bool GUIUtil::checkPoint ( const QPoint &  p,
const QWidget *  w 
)

Definition at line 390 of file guiutil.cpp.

Here is the caller graph for this function:

◆ ConnectionTypeToQString()

QString GUIUtil::ConnectionTypeToQString ( ConnectionType  conn_type,
bool  prepend_direction 
)

Convert enum ConnectionType to QString.

Definition at line 707 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyEntryData()

void GUIUtil::copyEntryData ( const QAbstractItemView *  view,
int  column,
int  role = Qt::EditRole 
)

Copy a field of the currently selected entry of a view to the clipboard.

Does nothing if nothing is selected.

Parameters
[in]columnData column to extract from the model
[in]roleData role to extract from the model
See also
TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress

Definition at line 264 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dateTimeStr() [1/2]

QString GUIUtil::dateTimeStr ( const QDateTime &  date)

Definition at line 90 of file guiutil.cpp.

Here is the caller graph for this function:

◆ dateTimeStr() [2/2]

QString GUIUtil::dateTimeStr ( qint64  nTime)

Definition at line 95 of file guiutil.cpp.

Here is the call graph for this function:

◆ DummyAddress()

static std::string GUIUtil::DummyAddress ( const CChainParams params)
static

Definition at line 109 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExceptionSafeConnect()

template<typename Sender , typename Signal , typename Receiver , typename Slot >
auto GUIUtil::ExceptionSafeConnect ( Sender  sender,
Signal  signal,
Receiver  receiver,
Slot  method,
Qt::ConnectionType  type = Qt::AutoConnection 
)

A drop-in replacement of QObject::connect function (see: https://doc.qt.io/qt-5/qobject.html#connect-3), that guaranties that all exceptions are handled within the slot.

NOTE: This function is incompatible with Qt private signals.

Definition at line 391 of file guiutil.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExtractFirstSuffixFromFilter()

QString GUIUtil::ExtractFirstSuffixFromFilter ( const QString &  filter)

Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...).

Parameters
[in]filterFilter specification such as "Comma Separated Files (*.csv)"
Returns
QString

Definition at line 302 of file guiutil.cpp.

Here is the caller graph for this function:

◆ fixedPitchFont()

QFont GUIUtil::fixedPitchFont ( bool  use_embedded_font)

Definition at line 100 of file guiutil.cpp.

Here is the caller graph for this function:

◆ formatBitcoinURI()

QString GUIUtil::formatBitcoinURI ( const SendCoinsRecipient info)

Definition at line 211 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ formatBytes()

QString GUIUtil::formatBytes ( uint64_t  bytes)

Definition at line 824 of file guiutil.cpp.

Here is the caller graph for this function:

◆ formatDurationStr()

QString GUIUtil::formatDurationStr ( std::chrono::seconds  dur)

Convert seconds into a QString with days, hours, mins, secs.

Definition at line 736 of file guiutil.cpp.

Here is the caller graph for this function:

◆ formatNiceTimeOffset()

QString GUIUtil::formatNiceTimeOffset ( qint64  secs)

Definition at line 787 of file guiutil.cpp.

Here is the caller graph for this function:

◆ FormatPeerAge()

QString GUIUtil::FormatPeerAge ( std::chrono::seconds  time_connected)

Convert peer connection time to a QString denominated in the most relevant unit.

Definition at line 751 of file guiutil.cpp.

Here is the caller graph for this function:

◆ formatPingTime()

QString GUIUtil::formatPingTime ( std::chrono::microseconds  ping_time)

Format a CNodeStats.m_last_ping_time into a user-readable string or display N/A, if 0.

Definition at line 775 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ formatServicesStr()

QString GUIUtil::formatServicesStr ( quint64  mask)

Format CNodeStats.nServices bitmask into a user-readable string.

Definition at line 761 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ formatTimeOffset()

QString GUIUtil::formatTimeOffset ( int64_t  time_offset)

Format a CNodeStateStats.time_offset into a user-readable string.

Definition at line 782 of file guiutil.cpp.

Here is the caller graph for this function:

◆ getDefaultDataDirectory()

QString GUIUtil::getDefaultDataDirectory ( )

Determine default data directory for operating system.

Definition at line 297 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getEntryData()

QList< QModelIndex > GUIUtil::getEntryData ( const QAbstractItemView *  view,
int  column 
)

Return a field of the currently selected entry as a QString.

Does nothing if nothing is selected.

Parameters
[in]columnData column to extract from the model
See also
TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress

Definition at line 277 of file guiutil.cpp.

Here is the caller graph for this function:

◆ GetImage()

QImage GUIUtil::GetImage ( const QLabel *  label)

Definition at line 973 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getOpenFileName()

QString GUIUtil::getOpenFileName ( QWidget *  parent,
const QString &  caption,
const QString &  dir,
const QString &  filter,
QString *  selectedSuffixOut 
)

Get open filename, convenience wrapper for QFileDialog::getOpenFileName.

Parameters
[in]parentParent window (or 0)
[in]captionWindow caption (or empty, for default)
[in]dirStarting directory (or empty, to default to documents directory)
[in]filterFilter specification such as "Comma Separated Files (*.csv)"
[out]selectedSuffixOutPointer to return the suffix (file type) that was selected (or 0). Can be useful when choosing the save file format based on suffix.

Definition at line 353 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSaveFileName()

QString GUIUtil::getSaveFileName ( QWidget *  parent,
const QString &  caption,
const QString &  dir,
const QString &  filter,
QString *  selectedSuffixOut 
)

Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when no suffix is provided by the user.

Parameters
[in]parentParent window (or 0)
[in]captionWindow caption (or empty, for default)
[in]dirStarting directory (or empty, to default to documents directory)
[in]filterFilter specification such as "Comma Separated Files (*.csv)"
[out]selectedSuffixOutPointer to return the suffix (file type) that was selected (or 0). Can be useful when choosing the save file format based on suffix.

Definition at line 313 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetStartOnSystemStartup()

bool GUIUtil::GetStartOnSystemStartup ( )

Definition at line 663 of file guiutil.cpp.

Here is the caller graph for this function:

◆ handleCloseWindowShortcut()

void GUIUtil::handleCloseWindowShortcut ( QWidget *  w)

Definition at line 431 of file guiutil.cpp.

Here is the caller graph for this function:

◆ hasEntryData()

bool GUIUtil::hasEntryData ( const QAbstractItemView *  view,
int  column,
int  role 
)

Returns true if the specified field of the currently selected view entry is not empty.

Parameters
[in]columnData column to extract from the model
[in]roleData role to extract from the model
See also
TransactionView::contextualMenu

Definition at line 284 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HasPixmap()

bool GUIUtil::HasPixmap ( const QLabel *  label)

Returns true if pixmap has been set.

QPixmap* QLabel::pixmap() is deprecated since Qt 5.15.

Definition at line 964 of file guiutil.cpp.

Here is the caller graph for this function:

◆ HtmlEscape() [1/2]

QString GUIUtil::HtmlEscape ( const QString &  str,
bool  fMultiLine 
)

Definition at line 249 of file guiutil.cpp.

Here is the caller graph for this function:

◆ HtmlEscape() [2/2]

QString GUIUtil::HtmlEscape ( const std::string &  str,
bool  fMultiLine 
)

Definition at line 259 of file guiutil.cpp.

Here is the call graph for this function:

◆ isDust()

bool GUIUtil::isDust ( interfaces::Node node,
const QString &  address,
const CAmount amount 
)

Definition at line 241 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsEscapeOrBack()

bool GUIUtil::IsEscapeOrBack ( int  key)
inline

Definition at line 430 of file guiutil.h.

Here is the caller graph for this function:

◆ isObscured()

bool GUIUtil::isObscured ( QWidget *  w)

Definition at line 397 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadFont()

void GUIUtil::LoadFont ( const QString &  file_name)

Loads the font from the file specified by file_name, aborts if it fails.

Definition at line 291 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LogQtInfo()

void GUIUtil::LogQtInfo ( )

Writes to debug.log short info about the used Qt and the host system.

Definition at line 920 of file guiutil.cpp.

Here is the caller graph for this function:

◆ MakeHtmlLink()

QString GUIUtil::MakeHtmlLink ( const QString &  source,
const QString &  link 
)

Replaces a plain text link with an HTML tagged one.

Definition at line 986 of file guiutil.cpp.

Here is the caller graph for this function:

◆ NetworkToQString()

QString GUIUtil::NetworkToQString ( Network  net)

Convert enum Network to QString.

Definition at line 687 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openBitcoinConf()

bool GUIUtil::openBitcoinConf ( )

Definition at line 445 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openDebugLogfile()

void GUIUtil::openDebugLogfile ( )

Definition at line 436 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseBitcoinURI() [1/2]

bool GUIUtil::parseBitcoinURI ( const QUrl &  uri,
SendCoinsRecipient out 
)

Definition at line 149 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parseBitcoinURI() [2/2]

bool GUIUtil::parseBitcoinURI ( QString  uri,
SendCoinsRecipient out 
)

Definition at line 205 of file guiutil.cpp.

Here is the call graph for this function:

◆ PathToQString()

QString GUIUtil::PathToQString ( const fs::path path)

Convert OS specific boost path to QString through UTF-8.

Definition at line 682 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PolishProgressDialog()

void GUIUtil::PolishProgressDialog ( QProgressDialog *  dialog)

Definition at line 901 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PopupMenu()

void GUIUtil::PopupMenu ( QMenu *  menu,
const QPoint &  point,
QAction *  at_action 
)

Call QMenu::popup() only on supported QT_QPA_PLATFORM.

Definition at line 948 of file guiutil.cpp.

Here is the caller graph for this function:

◆ PrintSlotException()

void GUIUtil::PrintSlotException ( const std::exception *  exception,
const QObject *  sender,
const QObject *  receiver 
)

Definition at line 993 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ QStringToPath()

fs::path GUIUtil::QStringToPath ( const QString &  path)

Convert QString to OS specific boost path through UTF-8.

Definition at line 677 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setClipboard()

void GUIUtil::setClipboard ( const QString &  str)

Definition at line 668 of file guiutil.cpp.

Here is the caller graph for this function:

◆ SetStartOnSystemStartup()

bool GUIUtil::SetStartOnSystemStartup ( bool  fAutoStart)

Definition at line 664 of file guiutil.cpp.

Here is the caller graph for this function:

◆ setupAddressWidget()

void GUIUtil::setupAddressWidget ( QValidatedLineEdit widget,
QWidget *  parent 
)

Definition at line 131 of file guiutil.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ShowModalDialogAsynchronously()

void GUIUtil::ShowModalDialogAsynchronously ( QDialog *  dialog)

Shows a QDialog instance asynchronously, and deletes it on close.

Definition at line 1004 of file guiutil.cpp.

Here is the caller graph for this function:

◆ SplitSkipEmptyParts()

template<typename SeparatorType >
QStringList GUIUtil::SplitSkipEmptyParts ( const QString &  string,
const SeparatorType &  separator 
)

Splits the string into substrings wherever separator occurs, and returns the list of those strings.

Empty strings do not appear in the result.

QString::split() signature differs in different Qt versions:

  • QString::SplitBehavior is deprecated since Qt 5.15
  • Qt::SplitBehavior was introduced in Qt 5.14 If {QString|Qt}::SkipEmptyParts behavior is required, use this function instead of QString::split().

Definition at line 363 of file guiutil.h.

Here is the caller graph for this function:

◆ StartOfDay()

QDateTime GUIUtil::StartOfDay ( const QDate &  date)

Returns the start-moment of the day in local time.

QDateTime::QDateTime(const QDate& date) is deprecated since Qt 5.15. QDate::startOfDay() was introduced in Qt 5.14.

Definition at line 955 of file guiutil.cpp.

Here is the caller graph for this function:

◆ TextWidth()

int GUIUtil::TextWidth ( const QFontMetrics &  fm,
const QString &  text 
)

Returns the distance in pixels appropriate for drawing a subsequent character after text.

In Qt 5.12 and before the QFontMetrics::width() is used and it is deprecated since Qt 5.13. In Qt 5.11 the QFontMetrics::horizontalAdvance() was introduced.

Definition at line 915 of file guiutil.cpp.

Here is the caller graph for this function:

◆ WalletDisplayName() [1/2]

QString GUIUtil::WalletDisplayName ( const QString &  name)

Definition at line 1011 of file guiutil.cpp.

Here is the caller graph for this function:

◆ WalletDisplayName() [2/2]

QString GUIUtil::WalletDisplayName ( const std::string &  name)

Definition at line 1016 of file guiutil.cpp.

Here is the call graph for this function:

Variable Documentation

◆ dialog_flags

constexpr auto GUIUtil::dialog_flags = Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint
constexpr

Definition at line 60 of file guiutil.h.