From 09e90773708b115afbd0784d7fca939bf45ee56e Mon Sep 17 00:00:00 2001 From: Pos <pierpaolo.mancini@mail.polimi.it> Date: Sat, 24 Jul 2021 14:15:30 +0200 Subject: [PATCH] Fixed broker error, improved graph --- Core/modulemessagesbroker.cpp | 7 ++--- Modules/CommandPad/commandpadmodule.ui | 38 ++++++++++++++---------- Modules/Graph/graphmodule.cpp | 41 +++++++++++++++++++++++++- Modules/Graph/graphmodule.h | 4 ++- SkywardHub.pro.user | 2 +- 5 files changed, 69 insertions(+), 23 deletions(-) diff --git a/Core/modulemessagesbroker.cpp b/Core/modulemessagesbroker.cpp index baeb46b4..b79efaa2 100644 --- a/Core/modulemessagesbroker.cpp +++ b/Core/modulemessagesbroker.cpp @@ -77,11 +77,10 @@ QList<QString> ModuleMessagesBroker::getSubscriptionsOf(Module *module) void ModuleMessagesBroker::onModuleDeleted(Module *module) { for(auto topic : observers.keys()){ - auto observer = observers[topic]; - if(observer.contains(module)){ - observer.remove(module); + if(observers[topic].contains(module)){ + observers[topic].remove(module); } - if(observer.isEmpty()){ + if(observers[topic].isEmpty()){ observers.remove(topic); } } diff --git a/Modules/CommandPad/commandpadmodule.ui b/Modules/CommandPad/commandpadmodule.ui index f62621cb..789d9a0e 100644 --- a/Modules/CommandPad/commandpadmodule.ui +++ b/Modules/CommandPad/commandpadmodule.ui @@ -49,7 +49,7 @@ </font> </property> <property name="text"> - <string>R2A - Ground Station</string> + <string>Ground Station</string> </property> </widget> </item> @@ -495,13 +495,6 @@ <set>Qt::AlignCenter</set> </property> <layout class="QGridLayout" name="gridLayout_4"> - <item row="0" column="1"> - <widget class="QPushButton" name="disarm_button"> - <property name="text"> - <string>DISARM</string> - </property> - </widget> - </item> <item row="0" column="0"> <widget class="QPushButton" name="arm_button"> <property name="text"> @@ -509,14 +502,21 @@ </property> </widget> </item> - <item row="1" column="0"> + <item row="0" column="1"> <widget class="QPushButton" name="forceLaunch_button"> <property name="text"> <string>FORCE LAUNCH</string> </property> </widget> </item> - <item row="1" column="1"> + <item row="0" column="2"> + <widget class="QPushButton" name="disarm_button"> + <property name="text"> + <string>DISARM</string> + </property> + </widget> + </item> + <item row="0" column="3"> <widget class="QPushButton" name="forceInit_button"> <property name="text"> <string>FORCE INIT</string> @@ -534,13 +534,19 @@ <property name="alignment"> <set>Qt::AlignCenter</set> </property> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="checked"> + <bool>false</bool> + </property> <layout class="QGridLayout" name="gridLayout_3"> <item row="1" column="0"> <widget class="QPushButton" name="endMission_button"> <property name="minimumSize"> <size> - <width>50</width> - <height>50</height> + <width>20</width> + <height>40</height> </size> </property> <property name="text"> @@ -552,8 +558,8 @@ <widget class="QPushButton" name="noseconeOpen_button"> <property name="minimumSize"> <size> - <width>50</width> - <height>50</height> + <width>20</width> + <height>40</height> </size> </property> <property name="text"> @@ -565,8 +571,8 @@ <widget class="QPushButton" name="cutDrogue_button"> <property name="minimumSize"> <size> - <width>50</width> - <height>50</height> + <width>20</width> + <height>40</height> </size> </property> <property name="text"> diff --git a/Modules/Graph/graphmodule.cpp b/Modules/Graph/graphmodule.cpp index 6ecf3395..bb931369 100644 --- a/Modules/Graph/graphmodule.cpp +++ b/Modules/Graph/graphmodule.cpp @@ -20,6 +20,9 @@ GraphModule::GraphModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::Gr GraphModule::~GraphModule() { + // QCPGraph are destroyed automatically + + subscriptions.clear(); delete ui; } @@ -153,6 +156,7 @@ void GraphModule::onSubscribeClicked() sPanel->show(); } + void GraphModule::onSubscriptionAdded(const QString &subscription) { QCPGraph *graph = instantiateNewGraph(); @@ -184,6 +188,9 @@ void GraphModule::onMsgReceived(const ModuleMessage &msg) onSubscriptionAdded(msg.originalTopic()); } + if(stopPlot) + return; + if(subscriptions.contains(msg.originalTopic())){ QCPGraph *graph = subscriptions[msg.originalTopic()]; @@ -221,6 +228,28 @@ void GraphModule::setFollowedGraphIndex(bool checked) } } +void GraphModule::onClearClicked() +{ + QMapIterator<QString,QCPGraph*> i(subscriptions); + while (i.hasNext()) { + i.next(); + i.value()->data()->clear(); + } + + replotAll(); +} + +void GraphModule::onStopClicked(bool checked) +{ + stopPlot = checked; + + if(stopPlot) + updaterTimer.stop(); + else{ + updaterTimer.start(updatePeriod); + } +} + QCPGraph *GraphModule::getSelectedGraph() { @@ -258,6 +287,14 @@ void GraphModule::addCustomActionsToMenu() QAction* subscribe = new QAction("Subscribe"); connect(subscribe, &QAction::triggered,this, &GraphModule::onSubscribeClicked); + QAction* clear = new QAction("Clear"); + connect(clear, &QAction::triggered,this, &GraphModule::onClearClicked); + + QAction* stop = new QAction("Stop"); + stop->setCheckable(true); + stop->setChecked(stopPlot); + connect(stop,&QAction::triggered,this,&GraphModule::onStopClicked); + QAction* follow = new QAction("Follow"); follow->setCheckable(true); if(followedGraphIndex >= 0){ @@ -265,7 +302,9 @@ void GraphModule::addCustomActionsToMenu() } connect(follow,&QAction::triggered,this,&GraphModule::setFollowedGraphIndex); - addActionToMenu(subscribe); addActionToMenu(follow); + addActionToMenu(subscribe); + addActionToMenu(clear); + addActionToMenu(stop); } diff --git a/Modules/Graph/graphmodule.h b/Modules/Graph/graphmodule.h index 95baf59d..8d4c2728 100644 --- a/Modules/Graph/graphmodule.h +++ b/Modules/Graph/graphmodule.h @@ -34,7 +34,8 @@ public slots: void onSubscriptionRemoved(const QString &subscription); void onMsgReceived(const ModuleMessage &msg); void setFollowedGraphIndex(bool checked); - + void onClearClicked(); + void onStopClicked(bool checked); protected: void buildCentralGraphView(); @@ -54,6 +55,7 @@ private: //QSharedPointer<QCPAxisTickerDateTime> dateTicker; QTimer updaterTimer; int updatePeriod = 1000; // [ms] + bool stopPlot = false; }; #endif // GRAPHMODULE_H diff --git a/SkywardHub.pro.user b/SkywardHub.pro.user index c86aea08..0cb2cc50 100644 --- a/SkywardHub.pro.user +++ b/SkywardHub.pro.user @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE QtCreatorProject> -<!-- Written by QtCreator 4.14.2, 2021-07-20T21:19:28. --> +<!-- Written by QtCreator 4.14.2, 2021-07-21T17:14:25. --> <qtcreator> <data> <variable>EnvironmentId</variable> -- GitLab