aboutsummaryrefslogtreecommitdiff
path: root/src/qt/guiutil.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/qt/guiutil.h')
-rw-r--r--src/qt/guiutil.h74
1 files changed, 66 insertions, 8 deletions
diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h
index ea72ec0ffa..edfb5b13a2 100644
--- a/src/qt/guiutil.h
+++ b/src/qt/guiutil.h
@@ -7,16 +7,18 @@
#include <amount.h>
#include <fs.h>
+#include <net.h>
+#include <netaddress.h>
#include <QEvent>
#include <QHeaderView>
#include <QItemDelegate>
+#include <QLabel>
#include <QMessageBox>
#include <QObject>
#include <QProgressBar>
#include <QString>
#include <QTableView>
-#include <QLabel>
class QValidatedLineEdit;
class SendCoinsRecipient;
@@ -221,22 +223,28 @@ namespace GUIUtil
bool GetStartOnSystemStartup();
bool SetStartOnSystemStartup(bool fAutoStart);
- /* Convert QString to OS specific boost path through UTF-8 */
+ /** Convert QString to OS specific boost path through UTF-8 */
fs::path qstringToBoostPath(const QString &path);
- /* Convert OS specific boost path to QString through UTF-8 */
+ /** Convert OS specific boost path to QString through UTF-8 */
QString boostPathToQString(const fs::path &path);
- /* Convert seconds into a QString with days, hours, mins, secs */
+ /** Convert enum Network to QString */
+ QString NetworkToQString(Network net);
+
+ /** Convert enum ConnectionType to QString */
+ QString ConnectionTypeToQString(ConnectionType conn_type, bool relay_txes);
+
+ /** Convert seconds into a QString with days, hours, mins, secs */
QString formatDurationStr(int secs);
- /* Format CNodeStats.nServices bitmask into a user-readable string */
+ /** Format CNodeStats.nServices bitmask into a user-readable string */
QString formatServicesStr(quint64 mask);
- /* Format a CNodeStats.m_ping_usec into a user-readable string or display N/A, if 0*/
+ /** Format a CNodeStats.m_ping_usec into a user-readable string or display N/A, if 0 */
QString formatPingTime(int64_t ping_usec);
- /* Format a CNodeCombinedStats.nTimeOffset into a user-readable string. */
+ /** Format a CNodeCombinedStats.nTimeOffset into a user-readable string */
QString formatTimeOffset(int64_t nTimeOffset);
QString formatNiceTimeOffset(qint64 secs);
@@ -292,7 +300,7 @@ namespace GUIUtil
/**
* 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 13.0.
+ * 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.
*/
int TextWidth(const QFontMetrics& fm, const QString& text);
@@ -306,6 +314,56 @@ namespace GUIUtil
* Call QMenu::popup() only on supported QT_QPA_PLATFORM.
*/
void PopupMenu(QMenu* menu, const QPoint& point, QAction* at_action = nullptr);
+
+ /**
+ * 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.
+ */
+ QDateTime StartOfDay(const QDate& date);
+
+ /**
+ * Returns true if pixmap has been set.
+ *
+ * QPixmap* QLabel::pixmap() is deprecated since Qt 5.15.
+ */
+ bool HasPixmap(const QLabel* label);
+ QImage GetImage(const QLabel* label);
+
+ /**
+ * 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().
+ */
+ template <typename SeparatorType>
+ QStringList SplitSkipEmptyParts(const QString& string, const SeparatorType& separator)
+ {
+ #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
+ return string.split(separator, Qt::SkipEmptyParts);
+ #else
+ return string.split(separator, QString::SkipEmptyParts);
+ #endif
+ }
+
+ /**
+ * Queue a function to run in an object's event loop. This can be
+ * replaced by a call to the QMetaObject::invokeMethod functor overload after Qt 5.10, but
+ * for now use a QObject::connect for compatibility with older Qt versions, based on
+ * https://stackoverflow.com/questions/21646467/how-to-execute-a-functor-or-a-lambda-in-a-given-thread-in-qt-gcd-style
+ */
+ template <typename Fn>
+ void ObjectInvoke(QObject* object, Fn&& function, Qt::ConnectionType connection = Qt::QueuedConnection)
+ {
+ QObject source;
+ QObject::connect(&source, &QObject::destroyed, object, std::forward<Fn>(function), connection);
+ }
+
} // namespace GUIUtil
#endif // BITCOIN_QT_GUIUTIL_H