File indexing completed on 2024-05-12 15:28:00
0001 /*************************************************************************** 0002 File : LiveDataDock.h 0003 Project : LabPlot 0004 Description : Dock widget for live data properties 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2017 by Fabian Kristof (fkristofszabolcs@gmail.com) 0007 Copyright : (C) 2018-2019 Kovacs Ferencz (kferike98@gmail.com) 0008 ***************************************************************************/ 0009 0010 /*************************************************************************** 0011 * * 0012 * This program is free software; you can redistribute it and/or modify * 0013 * it under the terms of the GNU General Public License as published by * 0014 * the Free Software Foundation; either version 2 of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 * This program is distributed in the hope that it will be useful, * 0018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0020 * GNU General Public License for more details. * 0021 * * 0022 * You should have received a copy of the GNU General Public License * 0023 * along with this program; if not, write to the Free Software * 0024 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0025 * Boston, MA 02110-1301 USA * 0026 * * 0027 ***************************************************************************/ 0028 #ifndef LIVEDATADOCK_H 0029 #define LIVEDATADOCK_H 0030 0031 #ifdef HAVE_MQTT 0032 #include <QtMqtt> 0033 #include <QStringList> 0034 #include <QMap> 0035 #include "backend/datasources/filters/AsciiFilter.h" 0036 #include "backend/datasources/MQTTClient.h" 0037 0038 class MQTTSubscriptionWidget; 0039 #endif 0040 0041 #include <QWidget> 0042 #include <QList> 0043 0044 #include "ui_livedatadock.h" 0045 #include "backend/datasources/LiveDataSource.h" 0046 #include "kdefrontend/dockwidgets/BaseDock.h" 0047 0048 class QTimer; 0049 class QTreeWidgetItem; 0050 class QString; 0051 class QCompleter; 0052 0053 class LiveDataDock : public BaseDock { 0054 Q_OBJECT 0055 0056 public: 0057 explicit LiveDataDock(QWidget *parent = nullptr); 0058 void setLiveDataSource(LiveDataSource* const source); 0059 ~LiveDataDock() override; 0060 0061 private: 0062 Ui::LiveDataDock ui; 0063 LiveDataSource* m_liveDataSource{nullptr}; 0064 0065 bool m_paused{false}; 0066 0067 void pauseReading(); 0068 void continueReading(); 0069 0070 private slots: 0071 void nameChanged(const QString&); 0072 void updateTypeChanged(int); 0073 void readingTypeChanged(int); 0074 void sampleSizeChanged(int); 0075 void updateIntervalChanged(int); 0076 void keepNValuesChanged(int); 0077 0078 void updateNow(); 0079 void pauseContinueReading(); 0080 0081 #ifdef HAVE_MQTT 0082 public: 0083 void setMQTTClient(MQTTClient* const client); 0084 bool testSubscribe(const QString&); 0085 bool testUnsubscribe(const QString&); 0086 0087 private slots: 0088 void useWillMessage(bool use); 0089 void willQoSChanged(int); 0090 void willRetainChanged(bool); 0091 void willTopicChanged(const QString &); 0092 void willMessageTypeChanged(MQTTClient::WillMessageType); 0093 void willOwnMessageChanged(const QString&); 0094 void willUpdateTypeChanged(int); 0095 void willUpdateNow(); 0096 void willUpdateIntervalChanged(int); 0097 void statisticsChanged(MQTTClient::WillStatisticsType); 0098 void onMQTTConnect(); 0099 void mqttMessageReceived(const QByteArray&, const QMqttTopicName&); 0100 void mqttMessageReceivedInBackground(const QByteArray&, const QMqttTopicName&); 0101 void removeClient(const QString&, quint16); 0102 void showWillSettings(); 0103 void enableWill(bool enable); 0104 0105 signals: 0106 void newTopic(const QString&); 0107 void MQTTClearTopics(); 0108 void updateSubscriptionTree(const QVector<QString>&); 0109 0110 private: 0111 void addTopicToTree(const QString&); 0112 0113 struct MQTTHost { 0114 int count; 0115 QMqttClient* client; 0116 QStringList topicList; 0117 QVector<QString> addedTopics; 0118 }; 0119 0120 MQTTClient* m_mqttClient{nullptr}; 0121 const MQTTClient* m_previousMQTTClient{nullptr}; 0122 QMap<QPair<QString, int>, MQTTHost> m_hosts; 0123 MQTTHost* m_currentHost{nullptr}; 0124 MQTTHost* m_previousHost{nullptr}; 0125 bool m_interpretMessage{true}; 0126 MQTTSubscriptionWidget* m_subscriptionWidget; 0127 QMetaObject::Connection m_updateSubscriptionConn; 0128 #endif 0129 }; 0130 0131 #endif // LIVEDATADOCK_H