File indexing completed on 2024-05-19 15:01:38

0001 /***************************************************************************
0002 File        : MQTTTopic.h
0003 Project     : LabPlot
0004 Description : Represents a topic of a MQTTSubscription
0005 --------------------------------------------------------------------
0006 Copyright   : (C) 2018 Kovacs Ferencz (kferike98@gmail.com)
0007 
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 
0029 #ifndef MQTTTOPIC_H
0030 #define MQTTTOPIC_H
0031 
0032 #include "backend/spreadsheet/Spreadsheet.h"
0033 
0034 class MQTTSubscription;
0035 class MQTTClient;
0036 
0037 class AsciiFilter;
0038 
0039 class MQTTTopic : public Spreadsheet {
0040     Q_OBJECT
0041 
0042 public:
0043     MQTTTopic(const QString& name, MQTTSubscription* subscription, bool loading = false);
0044     ~MQTTTopic() override;
0045 
0046     void setFilter(AsciiFilter*);
0047     AsciiFilter* filter() const;
0048 
0049     QIcon icon() const override;
0050     QMenu* createContextMenu() override;
0051     QWidget* view() const override;
0052 
0053     QString topicName() const;
0054     MQTTClient* mqttClient() const;
0055     void newMessage(const QString&);
0056 
0057     void save(QXmlStreamWriter*) const override;
0058     bool load(XmlStreamReader*, bool preview) override;
0059 
0060 private:
0061     void initActions();
0062 
0063     QString m_topicName;
0064     MQTTClient* m_MQTTClient;
0065     AsciiFilter* m_filter;
0066     QVector<QString> m_messagePuffer;
0067     QAction* m_plotDataAction;
0068 
0069 public slots:
0070     void read();
0071 
0072 private slots:
0073     void plotData();
0074 
0075 signals:
0076     void readOccured();
0077 };
0078 
0079 #endif // MQTTTOPIC_H