QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
StatusTextHandler.h
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4
5#include <QtCore/QByteArray>
6#include <QtCore/QList>
7#include <QtCore/QMap>
8#include <QtCore/QObject>
9
10#include "MAVLinkEnums.h"
11#include "MAVLinkMessageType.h"
12
14class QTimer;
15
17{
18public:
19 StatusText(MAV_COMPONENT componentid, MAV_SEVERITY severity, const QString &text);
20
21 bool severityIsError() const;
22 bool severityIsWarning() const;
23
24 MAV_COMPONENT getComponentID() const { return m_compId; }
25 MAV_SEVERITY getSeverity() const { return m_severity; }
26 QString getText() const { return m_text; }
27 QString getFormattedText() const { return m_formatedText; }
28
29 bool isRead() const { return m_read; }
30
31 void setFormatedText(const QString& formatedText) { m_formatedText = formatedText; }
32
33 void markRead() { m_read = true; }
34
35private:
36 MAV_COMPONENT m_compId;
37 MAV_SEVERITY m_severity;
38 QString m_text;
39 QString m_formatedText;
40 bool m_read = false;
41};
42
43class StatusTextHandler : public QObject
44{
45 Q_OBJECT
46
47public:
48 explicit StatusTextHandler(QObject *parent = nullptr);
50
51 void mavlinkMessageReceived(const mavlink_message_t &message);
52 void handleHTMLEscapedTextMessage(MAV_COMPONENT componentid, MAV_SEVERITY severity, const QString &text, const QString &description);
53
54 void clearMessages();
55 void markAllRead();
56
57 const QList<StatusText*>& messages() const { return m_messages; }
58
60 QString formattedMessages() const;
61
62 uint32_t unreadCriticalMessageCount() const { return m_unreadCriticalMessageCount; }
63
65 uint32_t unreadWarningMessageCount() const { return m_unreadWarningMessageCount; }
66
67 bool hasUnreadMessages() const { return m_unreadMessageCount != 0; }
68
70 uint32_t unreadMessageCount() const { return m_unreadMessageCount; }
71
72 static QString getMessageText(const mavlink_message_t &message);
73
74signals:
75 void newFormattedMessage(QString message);
76 void textMessageReceived(MAV_COMPONENT componentid, MAV_SEVERITY severity, QString text, QString description);
82 void newErrorMessage(QString message);
83
84private slots:
85 void _chunkedStatusTextTimeout();
86
87private:
88 void _handleStatusText(const mavlink_message_t &message);
89 void _chunkedStatusTextCompleted(MAV_COMPONENT compId);
90 void _resetUnreadSeverityCounts();
91 static QString _displayText(const StatusText& message);
92
93 QTimer *m_chunkedStatusTextTimer = nullptr;
94
95 bool m_multiComp = false;
96 MAV_COMPONENT m_activeComponent = MAV_COMPONENT::MAV_COMPONENT_ENUM_END;
97 uint32_t m_unreadCriticalMessageCount = 0;
98 uint32_t m_unreadWarningMessageCount = 0;
99 uint32_t m_unreadMessageCount = 0;
100
101 QVector<StatusText*> m_messages;
102
103 typedef struct __ChunkedStatusTextInfo {
104 uint16_t chunkId;
105 MAV_SEVERITY severity;
106 // nullopt marks a chunk that was never received; an empty value is a received NUL-first terminator
107 QList<std::optional<QByteArray>> rgMessageChunks;
108 } ChunkedStatusTextInfo_t;
109
110 QMap<MAV_COMPONENT, ChunkedStatusTextInfo_t> m_chunkedStatusTextInfoMap;
111};
struct __mavlink_message mavlink_message_t
void unreadMessageCountChanged()
uint32_t unreadMessageCount() const
All unread messages, including critical ones.
StatusTextHandler(QObject *parent=nullptr)
void handleHTMLEscapedTextMessage(MAV_COMPONENT componentid, MAV_SEVERITY severity, const QString &text, const QString &description)
const QList< StatusText * > & messages() const
void formattedMessagesChanged()
void hasUnreadMessagesChanged()
void newErrorMessage(QString message)
static QString getMessageText(const mavlink_message_t &message)
void mavlinkMessageReceived(const mavlink_message_t &message)
bool hasUnreadMessages() const
void textMessageReceived(MAV_COMPONENT componentid, MAV_SEVERITY severity, QString text, QString description)
uint32_t unreadWarningMessageCount() const
Unread Warning and Notice messages.
void newFormattedMessage(QString message)
QString formattedMessages() const
Unread messages are wrapped in so they render bold.
void unreadWarningMessageCountChanged()
uint32_t unreadCriticalMessageCount() const
void unreadCriticalMessageCountChanged()
StatusText(MAV_COMPONENT componentid, MAV_SEVERITY severity, const QString &text)
bool isRead() const
bool severityIsWarning() const
MAV_COMPONENT getComponentID() const
bool severityIsError() const
void setFormatedText(const QString &formatedText)
QString getFormattedText() const
QString getText() const
MAV_SEVERITY getSeverity() const