diff --git a/SkywardHub.pro b/SkywardHub.pro index bb8bef9b122c16d782de33cee6f9aee3dd6eee0f..f0265883fb5d99ba4885bf4c335e1372884c01d7 100644 --- a/SkywardHub.pro +++ b/SkywardHub.pro @@ -33,7 +33,6 @@ SOURCES += \ src/shared/Modules/SkywardHub/Deployer.cpp \ src/shared/Modules/SkywardHub/SkywardHubModule.cpp \ src/shared/Modules/StateViewer/StateViewer.cpp \ - src/shared/Modules/FileStream/FileStreamModule.cpp \ src/shared/Modules/Graph/Graph.cpp \ src/shared/Modules/Test/TestModule.cpp \ src/shared/Modules/ModulesList.cpp \ @@ -92,7 +91,6 @@ HEADERS += \ src/shared/Modules/SkywardHub/PrefabViewElement.h \ src/shared/Modules/StateViewer/StatesList.h \ src/shared/Modules/StateViewer/StateViewer.h \ - src/shared/Modules/FileStream/FileStreamModule.h \ src/shared/Modules/Graph/Graph.h \ src/shared/Modules/Test/TestModule.h \ src/shared/Modules/SkywardHubStrings.h \ @@ -145,7 +143,6 @@ FORMS += \ src/shared/Modules/SkywardHub/PrefabViewElement.ui \ src/shared/Modules/SkywardHub/PrefabDialog.ui \ src/shared/Modules/SkywardHub/DeployerPathPicker.ui \ - src/shared/Modules/FileStream/FileStreamModule.ui \ src/shared/Modules/Test/TestModule.ui \ src/shared/Modules/MainWindow/Window.ui \ src/shared/Modules/Mavlink/MavlinkRocketMsgTestingModule.ui \ diff --git a/src/shared/Modules/FileStream/FileStreamModule.cpp b/src/shared/Modules/FileStream/FileStreamModule.cpp deleted file mode 100644 index a1fcf669aa15c0ff2b7fab5823221d13b38a80e6..0000000000000000000000000000000000000000 --- a/src/shared/Modules/FileStream/FileStreamModule.cpp +++ /dev/null @@ -1,228 +0,0 @@ -#include "FileStreamModule.h" - -#include <Core/MessageBroker/MessageBroker.h> - -#include <QDebug> -#include <QDesktopServices> -#include <QDir> -#include <QMessageBox> -#include <QUrl> - -#include "Modules/SkywardHubStrings.h" -#include "ui_FileStreamModule.h" - -FileStreamModule::FileStreamModule(QWidget* parent) - : DefaultModule(parent), ui(new Ui::FileStreamModule) -{ - ui->setupUi(this); - defaultContextMenuSetup(); - connectUI(); - - ui->filePath_lineEdit->setText(SkywardHubStrings::defaultStreamFile); -} - -FileStreamModule::~FileStreamModule() -{ - if (file.isOpen()) - file.close(); - deleteAllTopicViews(); - delete ui; -} - -QWidget* FileStreamModule::toWidget() { return this; } - -XmlObject FileStreamModule::toXmlObject() -{ - XmlObject obj(getName(ModuleId::FILESTREAM)); - - if (getFilePath() != "") - obj.addAttribute("FilePath", getFilePath()); - - for (int i = 0; i < topicViewsList.count(); i++) - { - XmlObject subscription("Subscription"); - subscription.setTextValue(topicViewsList[i]->text().trimmed()); - obj.addChild(subscription); - } - return obj; -} - -void FileStreamModule::fromXmlObject(const XmlObject& xmlObject) -{ - if (xmlObject.getObjectName() == getName(ModuleId::FILESTREAM)) - { - - if (xmlObject.hasAttribute("FilePath")) - { - ui->filePath_lineEdit->setText(xmlObject.getAttribute("FilePath")); - } - - for (int i = 0; i < xmlObject.childCount(); i++) - { - XmlObject child = xmlObject.childAt(i); - if (child.getObjectName() == "Subscription" && - child.getTextValue() != "") - { - addTopic(child.getTextValue()); - } - } - } -} - -void FileStreamModule::connectUI() -{ - connect(ui->start_button, &QPushButton::clicked, this, - &FileStreamModule::onStartClicked); - connect(ui->stop_button, &QPushButton::clicked, this, - &FileStreamModule::onStopClicked); - connect(ui->addTopic_button, &QPushButton::clicked, this, - &FileStreamModule::onAddTopicClicked); - connect(ui->showFile_button, &QPushButton::clicked, this, - &FileStreamModule::onShowFileClick); -} - -QString FileStreamModule::getFilePath() const -{ - return ui->filePath_lineEdit->text().trimmed(); -} - -QString FileStreamModule::getTopicName() const -{ - return ui->topicName_lineEdit->text().trimmed(); -} - -void FileStreamModule::resetTopicName() { ui->topicName_lineEdit->clear(); } - -void FileStreamModule::onMsgReceived(const Message& msg) -{ - // if(file.isOpen() ){ - // QTextStream out(&file); - // out << msg.payload() << Qt::endl; - // } - - QFile file(getFilePath()); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) - return; - - QTextStream out(&file); - out << msg.toString() << Qt::endl; -} - -void FileStreamModule::onAddTopicClicked() -{ - QString topicName = getTopicName(); - resetTopicName(); - if (topicName != "") - { - addTopic(topicName); - } -} - -void FileStreamModule::onStartClicked() -{ - file.setFileName(getFilePath()); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) - { // Append QIODevice::ReadWrite - error(tr("FileStream"), - tr("Error occurred while opening file ") + getFilePath()); - return; - } - - file.resize(0); - disableOnStartElement(); - for (int i = 0; i < topicViewsList.count(); i++) - { - getCore()->getMessageBroker()->subscribe( - Filter::fromString(topicViewsList[i]->text().trimmed()), this, - [this](const Message& message, const Filter& filter) - { onMsgReceived(message); }); - topicViewsList[i]->setEnabled(false); - } -} - -void FileStreamModule::onStopClicked() -{ - if (file.isOpen()) - file.close(); - enableElementOnStop(); - - for (int i = 0; i < topicViewsList.count(); i++) - { - getCore()->getMessageBroker()->unsubscribe( - Filter::fromString(topicViewsList[i]->text().trimmed()), this); - topicViewsList[i]->setEnabled(true); - } -} - -void FileStreamModule::onTopicEdit() -{ - for (int i = topicViewsList.count() - 1; i >= 0; i--) - { - if (topicViewsList[i]->text().trimmed() == "") - { - topicViewsList[i]->deleteLater(); - topicViewsList.removeAt(i); - } - } -} - -void FileStreamModule::disableOnStartElement() -{ - ui->start_button->setEnabled(false); - ui->addTopic_button->setEnabled(false); - ui->filePath_lineEdit->setEnabled(false); -} - -void FileStreamModule::enableElementOnStop() -{ - ui->start_button->setEnabled(true); - ui->addTopic_button->setEnabled(true); - ui->filePath_lineEdit->setEnabled(true); - ui->writeOnFile_radioButton->setEnabled(true); -} - -void FileStreamModule::onShowFileClick() -{ - QDir dir(SkywardHubStrings::defaultLogsFolder); - if (dir.exists()) - { - QDesktopServices::openUrl(QUrl::fromLocalFile(getFilePath())); - } - else - { - QString msg = "The file does not exist." + getFilePath(); - QMessageBox msgBox; - msgBox.setText(msg); - msgBox.exec(); - } -} - -void FileStreamModule::addTopic(const QString& topic) -{ - QLineEdit* topicView = createTopicView(topic); - - topicViewsList.append(topicView); - ui->topics_layout->addWidget(topicView); -} - -QLineEdit* FileStreamModule::createTopicView(const QString& topic) const -{ - QLineEdit* topicView = new QLineEdit(); - topicView->setText(topic); - - connect(topicView, &QLineEdit::textEdited, this, - &FileStreamModule::onTopicEdit); - return topicView; -} - -void FileStreamModule::deleteAllTopicViews() -{ - for (int i = 0; i < topicViewsList.count(); i++) - { - getCore()->getMessageBroker()->unsubscribe( - Filter::fromString(topicViewsList[i]->text().trimmed()), this); - ui->topics_layout->removeWidget(topicViewsList[i]); - topicViewsList[i]->deleteLater(); - } - topicViewsList.clear(); -} diff --git a/src/shared/Modules/FileStream/FileStreamModule.h b/src/shared/Modules/FileStream/FileStreamModule.h deleted file mode 100644 index 1e778559e1d41624e61619c783b5ade8b429b4b0..0000000000000000000000000000000000000000 --- a/src/shared/Modules/FileStream/FileStreamModule.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include <Core/Message/Message.h> -#include <Modules/DefaultModule/DefaultModule.h> - -#include <QFile> -#include <QLineEdit> -#include <QWidget> - -namespace Ui -{ -class FileStreamModule; -} - -class FileStreamModule : public DefaultModule -{ - Q_OBJECT - -public: - explicit FileStreamModule(QWidget* parent = nullptr); - ~FileStreamModule(); - - QWidget* toWidget() override; - - XmlObject toXmlObject() override; - void fromXmlObject(const XmlObject& xmlObject) override; - -protected: - void connectUI(); - QString getFilePath() const; - QString getTopicName() const; - void resetTopicName(); - void onMsgReceived(const Message& msg); - - void onAddTopicClicked(); - void onStartClicked(); - void onStopClicked(); - void onTopicEdit(); - void disableOnStartElement(); - void enableElementOnStop(); - void onFileChanged(); - void onShowFileClick(); - - void addTopic(const QString& topic); - QLineEdit* createTopicView(const QString& topic) const; - - void deleteAllTopicViews(); - -private: - Ui::FileStreamModule* ui; - - QList<QLineEdit*> topicViewsList; - QFile file; -}; diff --git a/src/shared/Modules/FileStream/FileStreamModule.ui b/src/shared/Modules/FileStream/FileStreamModule.ui deleted file mode 100644 index 85693220457cc6d9b16ac3231d87d1d4e0186018..0000000000000000000000000000000000000000 --- a/src/shared/Modules/FileStream/FileStreamModule.ui +++ /dev/null @@ -1,155 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>FileStreamModule</class> - <widget class="QWidget" name="FileStreamModule"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>508</width> - <height>209</height> - </rect> - </property> - <property name="windowTitle"> - <string>Form</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="2"> - <widget class="QScrollArea" name="scrollArea"> - <property name="widgetResizable"> - <bool>true</bool> - </property> - <widget class="QWidget" name="scrollAreaWidgetContents"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>486</width> - <height>187</height> - </rect> - </property> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <widget class="QRadioButton" name="writeOnFile_radioButton"> - <property name="text"> - <string>Write the messages received from the topic into the specified file</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_4"> - <item> - <widget class="QLineEdit" name="filePath_lineEdit"> - <property name="placeholderText"> - <string>File path</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="showFile_button"> - <property name="text"> - <string>Show</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <layout class="QVBoxLayout" name="topics_layout"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Topic List </string> - </property> - </widget> - </item> - <item> - <widget class="QLineEdit" name="topicName_lineEdit"> - <property name="placeholderText"> - <string>Topic name</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="addTopic_button"> - <property name="text"> - <string>Add</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string>To remove a topic, clear the Line Edit control</string> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QPushButton" name="stop_button"> - <property name="text"> - <string>Stop</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="start_button"> - <property name="text"> - <string>Start</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections/> -</ui>