diff --git a/Core/module.cpp b/Core/module.cpp index 7e5ed70eacc0549fcb203d65111b58ede5e7d2f1..c94b7b99f3934f89aa76d2e5e21fb46ab8b3f06a 100644 --- a/Core/module.cpp +++ b/Core/module.cpp @@ -1,26 +1,21 @@ #include "module.h" -Module::Module() -{ +Module::Module() { } -Module::~Module() -{ +Module::~Module() { emit eventsHandler.beforeDelete(this); } -void Module::initialize(const XmlObject ¶ms) -{ +void Module::initialize(const XmlObject ¶ms) { Q_UNUSED(params); } -ModuleEventsHandler* Module::getModuleEventsHandler() -{ +ModuleEventsHandler* Module::getModuleEventsHandler() { return &eventsHandler; } -SkywardHubCoreProxy &Module::getCore() -{ +SkywardHubCoreProxy &Module::getCore() { return coreProxy; } diff --git a/Core/module.h b/Core/module.h index d8310a7d1a56d8b27ad98073eb61183ac55e3a1b..9cffe8b6fafafdccc58e405b13bc98c1d315dea4 100644 --- a/Core/module.h +++ b/Core/module.h @@ -7,9 +7,8 @@ #include "moduleeventshandler.h" #include "Core/xmlobject.h" -class Module -{ -public: +class Module { + public: Module(); virtual ~Module(); @@ -22,10 +21,10 @@ public: SkywardHubCoreProxy& getCore(); ModuleEventsHandler* getModuleEventsHandler(); -protected: + protected: //virtual void onManagerSetted(ModulesManager *manager); -private: + private: SkywardHubCoreProxy coreProxy; ModuleEventsHandler eventsHandler; }; diff --git a/Core/moduleeventshandler.cpp b/Core/moduleeventshandler.cpp index 6055085e42f4f63f10776e4eead812a5e958fef8..1942933df9b7ad7ec878f95592da622d6ce79cd4 100644 --- a/Core/moduleeventshandler.cpp +++ b/Core/moduleeventshandler.cpp @@ -1,6 +1,5 @@ #include "moduleeventshandler.h" -ModuleEventsHandler::ModuleEventsHandler() -{ +ModuleEventsHandler::ModuleEventsHandler() { } diff --git a/Core/moduleeventshandler.h b/Core/moduleeventshandler.h index 3b0a3637bddba4df3e1c1f6d90b838e8512e804c..2c10ef967ea22375e7f81bc6749c36234ba87896 100644 --- a/Core/moduleeventshandler.h +++ b/Core/moduleeventshandler.h @@ -6,18 +6,17 @@ #include <QMenu> class Module; -class ModuleEventsHandler : public QObject -{ - Q_OBJECT +class ModuleEventsHandler : public QObject { + Q_OBJECT -public: + public: ModuleEventsHandler(); -signals: + signals: void beforeDelete(Module *module); void replaceMeWith(Module *sender, Module *newModule); void replaceMeWithModules(QList<Module*> module); - void contextMenuRequest(QMenu &menu,const QPoint &p); + void contextMenuRequest(QMenu &menu, const QPoint &p); }; #endif // MODULEEVENTSHANDLER_H diff --git a/Core/modulemessage.cpp b/Core/modulemessage.cpp index 3c7f8691ce3d0b8612de5849cd24c74eeaf009c0..0de8187b84028236fe7e048e1261944e803b634e 100644 --- a/Core/modulemessage.cpp +++ b/Core/modulemessage.cpp @@ -2,128 +2,105 @@ #include <QDateTime> -ModuleMessage::ModuleMessage() -{ +ModuleMessage::ModuleMessage() { setTimestamp(QTime::currentTime()); } -ModuleMessage::ModuleMessage(const QString &topic) : ModuleMessage() -{ +ModuleMessage::ModuleMessage(const QString &topic) : ModuleMessage() { setTopic(topic); } -ModuleMessage::ModuleMessage(const QString &topic, const QString &msg) : ModuleMessage(topic) -{ +ModuleMessage::ModuleMessage(const QString &topic, const QString &msg) : ModuleMessage(topic) { setPayload(msg); } -ModuleMessage::ModuleMessage(const QString &topic, const QString &payload, const QTime &time) : ModuleMessage(topic, payload) -{ +ModuleMessage::ModuleMessage(const QString &topic, const QString &payload, const QTime &time) : ModuleMessage(topic, payload) { setTimestamp(time); } -ModuleMessage::ModuleMessage(const ModuleMessage &other) -{ +ModuleMessage::ModuleMessage(const ModuleMessage &other) { copy(other); } -ModuleMessage ModuleMessage::operator=(const ModuleMessage &other) -{ +ModuleMessage ModuleMessage::operator=(const ModuleMessage &other) { copy(other); return *this; } -QString ModuleMessage::payload() const -{ +QString ModuleMessage::payload() const { return _payload; } -void ModuleMessage::setPayload(const QString &value) -{ +void ModuleMessage::setPayload(const QString &value) { _payload = value; } -void ModuleMessage::setPayload(int value) -{ +void ModuleMessage::setPayload(int value) { setPayload(QString::number(value)); } -QString ModuleMessage::topic() const -{ +QString ModuleMessage::topic() const { return _topic; } -void ModuleMessage::setTopic(const QString &value) -{ +void ModuleMessage::setTopic(const QString &value) { _topic = value; } -QTime ModuleMessage::timestamp() const -{ +QTime ModuleMessage::timestamp() const { return _timestamp; } -void ModuleMessage::setTimestamp(const QTime ×tamp) -{ +void ModuleMessage::setTimestamp(const QTime ×tamp) { _timestamp = timestamp; } -QString ModuleMessage::getHigherHierarchyTopic() const -{ +QString ModuleMessage::getHigherHierarchyTopic() const { int separatoIndex = _topic.lastIndexOf(_separator); - if(separatoIndex < 0){ + if(separatoIndex < 0) { separatoIndex = 0; } int len = _topic.length() - separatoIndex; - return QString(_topic).remove(separatoIndex,len); + return QString(_topic).remove(separatoIndex, len); } -QString ModuleMessage::originalTopic() const -{ +QString ModuleMessage::originalTopic() const { return _originalTopic; } -void ModuleMessage::setOriginalTopic(const QString &originalTopic) -{ +void ModuleMessage::setOriginalTopic(const QString &originalTopic) { _originalTopic = originalTopic; } -XmlObject ModuleMessage::getOptions() const -{ +XmlObject ModuleMessage::getOptions() const { return options; } -QString ModuleMessage::getOption(const QString &optionName) const -{ +QString ModuleMessage::getOption(const QString &optionName) const { return options.getAttribute(optionName); } -bool ModuleMessage::getIntOption(const QString &optionName, int &val) const -{ +bool ModuleMessage::getIntOption(const QString &optionName, int &val) const { return options.getIntAttribute(optionName, val); } -void ModuleMessage::setOptions(const XmlObject &value) -{ +void ModuleMessage::setOptions(const XmlObject &value) { options = value; } -void ModuleMessage::addOption(const QString &optionName, const QString &value) -{ +void ModuleMessage::addOption(const QString &optionName, const QString &value) { options.addAttribute(optionName, value); } -void ModuleMessage::addOption(const QString &optionName, int value) -{ +void ModuleMessage::addOption(const QString &optionName, int value) { options.addAttribute(optionName, value); } -bool ModuleMessage::getIntPayload(int &value) const -{ +bool ModuleMessage::getIntPayload(int &value) const { bool ok; - if(payload() != ""){ + if(payload() != "") { int temp = payload().toInt(&ok); - if(ok){ + if(ok) { value = temp; return true; } @@ -131,12 +108,11 @@ bool ModuleMessage::getIntPayload(int &value) const return false; } -bool ModuleMessage::getFloatPayload(float &value) const -{ +bool ModuleMessage::getFloatPayload(float &value) const { bool ok; - if(payload() != ""){ + if(payload() != "") { int temp = payload().toFloat(&ok); - if(ok){ + if(ok) { value = temp; return true; } @@ -144,19 +120,17 @@ bool ModuleMessage::getFloatPayload(float &value) const return false; } -QString ModuleMessage::toString() const -{ +QString ModuleMessage::toString() const { QString line = QDateTime::currentDateTime().toString("hh.mm.ss (zzz): ") + "(Topic) " + this->originalTopic() + " -> " + this->payload() + " (payload)"; auto i = this->getOptions().attributesIterator(); - while(i.hasNext()){ + while(i.hasNext()) { i.next(); - line = line + ", " + i.value() + " ("+i.key()+")"; + line = line + ", " + i.value() + " (" + i.key() + ")"; } return line; } -void ModuleMessage::copy(const ModuleMessage &msg) -{ +void ModuleMessage::copy(const ModuleMessage &msg) { setPayload(msg.payload()); setTopic(msg.topic()); setOriginalTopic(msg.originalTopic()); diff --git a/Core/modulemessage.h b/Core/modulemessage.h index e0f05aef80c8aeaf68a0817431fe9f978a22133d..ef0d923248297549bc59a59955ea25cd8227d3ef 100644 --- a/Core/modulemessage.h +++ b/Core/modulemessage.h @@ -6,9 +6,8 @@ #include <QDateTime> #include "xmlobject.h" -class ModuleMessage -{ -public: +class ModuleMessage { + public: ModuleMessage(); ModuleMessage(const QString &topic); ModuleMessage(const QString &_topic, const QString &payload); @@ -51,7 +50,7 @@ public: QString toString() const; -private: + private: void copy(const ModuleMessage &msg); QString _payload; diff --git a/Core/modulemessagesbroker.cpp b/Core/modulemessagesbroker.cpp index b79efaa287f3e4a82fd839534369dcfd924af552..5632ea249a0ae3a5e92a8fd673d2d748536a4b05 100644 --- a/Core/modulemessagesbroker.cpp +++ b/Core/modulemessagesbroker.cpp @@ -5,82 +5,73 @@ //ModuleMessagesBroker *ModuleMessagesBroker::modulesMsgBroker = nullptr; -ModuleMessagesBroker::ModuleMessagesBroker() -{ +ModuleMessagesBroker::ModuleMessagesBroker() { qDebug() << "ModulesManager >> Created"; } -ModuleMessagesBroker::~ModuleMessagesBroker() -{ +ModuleMessagesBroker::~ModuleMessagesBroker() { } -void ModuleMessagesBroker::subscribe(const QString &topic, Module *observer, std::function<void(const ModuleMessage &msg)> callBack) -{ +void ModuleMessagesBroker::subscribe(const QString &topic, Module *observer, std::function<void(const ModuleMessage &msg)> callBack) { observers[topic][observer].append(callBack); - connect(observer->getModuleEventsHandler(),&ModuleEventsHandler::beforeDelete, this, &ModuleMessagesBroker::onModuleDeleted); + connect(observer->getModuleEventsHandler(), &ModuleEventsHandler::beforeDelete, this, &ModuleMessagesBroker::onModuleDeleted); } -void ModuleMessagesBroker::unsubscribe(const QString &topic, Module *module) -{ - if(observers.contains(topic)){ - if(observers[topic].contains(module)){ +void ModuleMessagesBroker::unsubscribe(const QString &topic, Module *module) { + if(observers.contains(topic)) { + if(observers[topic].contains(module)) { observers[topic].remove(module); - if(observers[topic].isEmpty()){ + if(observers[topic].isEmpty()) { observers.remove(topic); } } } } -void ModuleMessagesBroker::publish(const QString &topic, const QString &msg) -{ - ModuleMessage m(topic,msg); +void ModuleMessagesBroker::publish(const QString &topic, const QString &msg) { + ModuleMessage m(topic, msg); publish(m); } -void ModuleMessagesBroker::publish(const ModuleMessage &msg) -{ +void ModuleMessagesBroker::publish(const ModuleMessage &msg) { ModuleMessage m = msg; m.setOriginalTopic(msg.topic()); - while(m.topic().length() > 0){ + while(m.topic().length() > 0) { send(m); m.setTopic(m.getHigherHierarchyTopic()); } } -void ModuleMessagesBroker::send(const ModuleMessage &msg) -{ - if(observers.contains(msg.topic())){ - for(auto calls : observers[msg.topic()].values()){ - for(auto callBack : calls){ +void ModuleMessagesBroker::send(const ModuleMessage &msg) { + if(observers.contains(msg.topic())) { + for(auto calls : observers[msg.topic()].values()) { + for(auto callBack : calls) { callBack(msg); } } } } -QList<QString> ModuleMessagesBroker::getSubscriptionsOf(Module *module) -{ +QList<QString> ModuleMessagesBroker::getSubscriptionsOf(Module *module) { QList<QString> topics; - for(auto topic : observers.keys()){ + for(auto topic : observers.keys()) { auto observer = observers[topic]; - if(observer.contains(module)){ + if(observer.contains(module)) { topics.append(topic); } } return topics; } -void ModuleMessagesBroker::onModuleDeleted(Module *module) -{ - for(auto topic : observers.keys()){ - if(observers[topic].contains(module)){ +void ModuleMessagesBroker::onModuleDeleted(Module *module) { + for(auto topic : observers.keys()) { + if(observers[topic].contains(module)) { observers[topic].remove(module); } - if(observers[topic].isEmpty()){ + if(observers[topic].isEmpty()) { observers.remove(topic); } } diff --git a/Core/modulemessagesbroker.h b/Core/modulemessagesbroker.h index 70b40cc2535171841d397b92fe5efb2555ccc288..47b76ccb2540c8b329dc9a147737ed6f48cf7255 100644 --- a/Core/modulemessagesbroker.h +++ b/Core/modulemessagesbroker.h @@ -10,11 +10,10 @@ class Module; -class ModuleMessagesBroker : public QObject -{ +class ModuleMessagesBroker : public QObject { Q_OBJECT -public: + public: ModuleMessagesBroker(); ~ModuleMessagesBroker(); @@ -25,14 +24,14 @@ public: QList<QString> getSubscriptionsOf(Module *module); -public slots: + public slots: void onModuleDeleted(Module *module); -protected: + protected: void send(const ModuleMessage &msg); -private: - QMap<QString, QMap<Module*,QList<std::function<void(const ModuleMessage &msg)>>>> observers; + private: + QMap<QString, QMap<Module*, QList<std::function<void(const ModuleMessage &msg)>>>> observers; }; #endif // MODULEMESSAGESBROKER_H diff --git a/Core/modulesmanager.cpp b/Core/modulesmanager.cpp index abf5a94f9b63ac65f93f6f9c204ae7b6d6a8ee71..91e403df2b9961665677146ef9862bd29ddd351c 100644 --- a/Core/modulesmanager.cpp +++ b/Core/modulesmanager.cpp @@ -12,38 +12,33 @@ ModulesList ModulesManager::modulesListHandler; -ModulesManager::ModulesManager() -{ +ModulesManager::ModulesManager() { } -ModulesManager::~ModulesManager() -{ +ModulesManager::~ModulesManager() { clearPages(); - for(int i = 0; i < menuActions.count(); i++){ + for(int i = 0; i < menuActions.count(); i++) { delete menuActions[i]; } menuActions.clear(); } -QString ModulesManager::getModuleName(ModuleId id) -{ +QString ModulesManager::getModuleName(ModuleId id) { if(ModulesManager::modulesListHandler.containsId(id)) return ModulesManager::modulesListHandler.getModuleName(id); return ""; } -Module *ModulesManager::instantiateModuleById(ModuleId id) -{ +Module *ModulesManager::instantiateModuleById(ModuleId id) { if(ModulesManager::modulesListHandler.containsId(id)) return ModulesManager::modulesListHandler.getFactory(id)(); return nullptr; } -Module *ModulesManager::instantiateModuleById(ModuleId id, const XmlObject ¶ms) -{ +Module *ModulesManager::instantiateModuleById(ModuleId id, const XmlObject ¶ms) { Module *m = instantiateModuleById(id); if(m != nullptr) @@ -51,13 +46,11 @@ Module *ModulesManager::instantiateModuleById(ModuleId id, const XmlObject ¶ return m; } -Module *ModulesManager::instantiateModuleByName(const QString &moduleName) -{ +Module *ModulesManager::instantiateModuleByName(const QString &moduleName) { return ModulesManager::modulesListHandler.findFactoryByModuleName(moduleName)(); } -Module *ModulesManager::instantiateModuleByName(const QString &moduleName, const XmlObject ¶ms) -{ +Module *ModulesManager::instantiateModuleByName(const QString &moduleName, const XmlObject ¶ms) { Module *m = instantiateModuleByName(moduleName); if(m != nullptr) @@ -65,15 +58,14 @@ Module *ModulesManager::instantiateModuleByName(const QString &moduleName, const return m; } -QList<Module *>ModulesManager::loadModuleFromXml(XmlObject &xml) -{ +QList<Module *>ModulesManager::loadModuleFromXml(XmlObject &xml) { QList<Module*> windows; - for(int i=0; i < xml.childCount(); i++){ + for(int i = 0; i < xml.childCount(); i++) { XmlObject *child = xml.getChild(i); QString moduleName = child->getObjectName(); Module *module = ModulesManager::instantiateModuleByName(moduleName); - if(module != nullptr){ + if(module != nullptr) { module->fromXmlObject(*child); windows.append(module); } @@ -82,54 +74,48 @@ QList<Module *>ModulesManager::loadModuleFromXml(XmlObject &xml) return windows; } -void ModulesManager::setModules(QList<Module *> modules) -{ +void ModulesManager::setModules(QList<Module *> modules) { int i; - for(i=0 ; i < pages.count() && i < modules.count(); i++ ){ + for(i = 0 ; i < pages.count() && i < modules.count(); i++ ) { Module *old = pages[i]; emit pages[i]->getModuleEventsHandler()->replaceMeWith(old, modules[i]); delete old; } - if(i < pages.count()){ - for(int c = pages.count() - 1; c > i; c-- ){ + if(i < pages.count()) { + for(int c = pages.count() - 1; c > i; c-- ) { delete pages[c]; } } - for(; i < modules.count(); i++ ){ + for(; i < modules.count(); i++ ) { addPage(modules[i]); } } -void ModulesManager::addModules(QList<Module *> modules) -{ - for(int i=0; i < modules.count(); i++){ +void ModulesManager::addModules(QList<Module *> modules) { + for(int i = 0; i < modules.count(); i++) { addPage(modules[i]); } } -void ModulesManager::addPage(Module *module) -{ +void ModulesManager::addPage(Module *module) { pages.append(module); connectModule(module); emit pageAdded(pages.indexOf(module)); } -void ModulesManager::removePage(Module *module) -{ +void ModulesManager::removePage(Module *module) { int index = pages.indexOf(module); - if(index >= 0){ + if(index >= 0) { pages.removeAt(index); disconnectModule(module); } } -Module *ModulesManager::instantiateDefaultModule() -{ +Module *ModulesManager::instantiateDefaultModule() { return ModulesManager::instantiateModuleById(ModuleId::EMPTY); } -Module *ModulesManager::invokeModulesPickerService() -{ +Module *ModulesManager::invokeModulesPickerService() { #ifdef MODULESPICKER_H ModulesPicker *p = new ModulesPicker(); @@ -139,74 +125,65 @@ Module *ModulesManager::invokeModulesPickerService() return nullptr; } -QList<QString> ModulesManager::getModulesNamesList() -{ +QList<QString> ModulesManager::getModulesNamesList() { return ModulesManager::modulesListHandler.getModulesNamesList(); } -void ModulesManager::connectModule(Module *module) -{ - if(module){ - connect(module->getModuleEventsHandler(),&ModuleEventsHandler::contextMenuRequest,this,&ModulesManager::onContextMenuRequest); - connect(module->getModuleEventsHandler(),&ModuleEventsHandler::beforeDelete,this,&ModulesManager::onModuleDeleted); - connect(module->getModuleEventsHandler(),&ModuleEventsHandler::replaceMeWith,this,&ModulesManager::onReplaceMeWith); +void ModulesManager::connectModule(Module *module) { + if(module) { + connect(module->getModuleEventsHandler(), &ModuleEventsHandler::contextMenuRequest, this, &ModulesManager::onContextMenuRequest); + connect(module->getModuleEventsHandler(), &ModuleEventsHandler::beforeDelete, this, &ModulesManager::onModuleDeleted); + connect(module->getModuleEventsHandler(), &ModuleEventsHandler::replaceMeWith, this, &ModulesManager::onReplaceMeWith); } //connect(module->getModuleEventsHandler(),&ModuleEventsHandler::replaceMeWithModules,this,&ModulesManager::openWindows); } -void ModulesManager::disconnectModule(Module *module) -{ - if(module){ - disconnect(module->getModuleEventsHandler(),&ModuleEventsHandler::contextMenuRequest,this,&ModulesManager::onContextMenuRequest); - disconnect(module->getModuleEventsHandler(),&ModuleEventsHandler::beforeDelete,this,&ModulesManager::onModuleDeleted); - disconnect(module->getModuleEventsHandler(),&ModuleEventsHandler::replaceMeWith,this,&ModulesManager::onReplaceMeWith); +void ModulesManager::disconnectModule(Module *module) { + if(module) { + disconnect(module->getModuleEventsHandler(), &ModuleEventsHandler::contextMenuRequest, this, &ModulesManager::onContextMenuRequest); + disconnect(module->getModuleEventsHandler(), &ModuleEventsHandler::beforeDelete, this, &ModulesManager::onModuleDeleted); + disconnect(module->getModuleEventsHandler(), &ModuleEventsHandler::replaceMeWith, this, &ModulesManager::onReplaceMeWith); } } -void ModulesManager::onModuleDeleted(Module *deletedModule) -{ +void ModulesManager::onModuleDeleted(Module *deletedModule) { int index = pages.indexOf(deletedModule); - if(index == 0){ + if(index == 0) { onFirstPageDeleted(); - }else{ + } else { removePage(deletedModule); } } -void ModulesManager::openNewEmptyWindow() -{ +void ModulesManager::openNewEmptyWindow() { addPage(ModulesManager::instantiateDefaultModule()); } -Module *ModulesManager::getModuleAt(int index) -{ - if(index >= 0 && index < pages.count()){ +Module *ModulesManager::getModuleAt(int index) { + if(index >= 0 && index < pages.count()) { return pages.at(index); } return nullptr; } -int ModulesManager::getModuleCount() -{ +int ModulesManager::getModuleCount() { return pages.count(); } -void ModulesManager::clearPages() -{ - for(int i=pages.count() - 1; i >= 0; i--){ +void ModulesManager::clearPages() { + for(int i = pages.count() - 1; i >= 0; i--) { delete pages[i]; } pages.clear(); } -void ModulesManager::onReplaceMeWith(Module *sender, Module *newModule) -{ - if(sender != nullptr && newModule != nullptr){ +void ModulesManager::onReplaceMeWith(Module *sender, Module *newModule) { + if(sender != nullptr && newModule != nullptr) { int index = pages.indexOf(sender); - if(index >= 0){ + if(index >= 0) { pages[index] = newModule; connectModule(newModule); disconnectModule(sender); @@ -214,47 +191,41 @@ void ModulesManager::onReplaceMeWith(Module *sender, Module *newModule) } } -bool ModulesManager::getRebuild() const -{ +bool ModulesManager::getRebuild() const { return rebuild; } -void ModulesManager::setRebuild(bool value) -{ +void ModulesManager::setRebuild(bool value) { rebuild = value; } -void ModulesManager::onContextMenuRequest(QMenu &menu, const QPoint &p) -{ +void ModulesManager::onContextMenuRequest(QMenu &menu, const QPoint &p) { QMenu hubMenu("Hub Menu"); hubMenu.addActions(getHubMenuActions()); menu.addMenu(&hubMenu); emit contextMenuRequest(menu, p); } -QList<QAction*> ModulesManager::getHubMenuActions() -{ - if(menuActions.count() == 0){ +QList<QAction*> ModulesManager::getHubMenuActions() { + if(menuActions.count() == 0) { QAction* save = new QAction("Save"); menuActions.append(save); - connect(save,&QAction::triggered,this,&ModulesManager::saveConfigurationService); + connect(save, &QAction::triggered, this, &ModulesManager::saveConfigurationService); QAction* openWindows = new QAction("New Windows"); menuActions.append(openWindows); - connect(openWindows,&QAction::triggered,this,&ModulesManager::openNewEmptyWindow); + connect(openWindows, &QAction::triggered, this, &ModulesManager::openNewEmptyWindow); } return menuActions; } -QList<ModuleInfo> ModulesManager::getModulesInfo() -{ +QList<ModuleInfo> ModulesManager::getModulesInfo() { return modulesListHandler.getModulesInfo(); } -void ModulesManager::saveConfigurationService() -{ - if(pages.isEmpty()){ +void ModulesManager::saveConfigurationService() { + if(pages.isEmpty()) { QMessageBox errorMsg; errorMsg.setText("No module to be saved found"); errorMsg.exec(); @@ -279,23 +250,23 @@ void ModulesManager::saveConfigurationService() xml.addAttribute(SkywardHubStrings::configurationIconPathAttribute, configIconPath); xml.addAttribute(SkywardHubStrings::configurationDescriptionAttribute, description); - if(ok && !configName.isEmpty()){ + if(ok && !configName.isEmpty()) { configName = configName.replace(".xml", ""); xml.addAttribute(SkywardHubStrings::configurationNameAttribute, configName); - if(configName.indexOf(".xml") < 0 ){ + if(configName.indexOf(".xml") < 0 ) { configName.append(".xml"); } - if(!QDir(SkywardHubStrings::defaultPrefabsFolder).exists()){ + if(!QDir(SkywardHubStrings::defaultPrefabsFolder).exists()) { QDir().mkpath(SkywardHubStrings::defaultPrefabsFolder); } - for(Module *module : pages){ + for(Module *module : pages) { xml.addChild(module->toXmlObject()); } QString resultTxt = "Impossible to save"; - if(xml.writeToFile(SkywardHubStrings::defaultPrefabsFolder + configName)){ + if(xml.writeToFile(SkywardHubStrings::defaultPrefabsFolder + configName)) { resultTxt = "The configuration has been saved in " + configName; } QMessageBox resultMsg; @@ -304,8 +275,7 @@ void ModulesManager::saveConfigurationService() } } -void ModulesManager::onFirstPageDeleted() -{ +void ModulesManager::onFirstPageDeleted() { if(!rebuild) return; QMessageBox msgBox; @@ -314,10 +284,9 @@ void ModulesManager::onFirstPageDeleted() msgBox.setStandardButtons(QMessageBox::Yes); msgBox.addButton(QMessageBox::No); msgBox.setDefaultButton(QMessageBox::No); - if(msgBox.exec() == QMessageBox::No){ + if(msgBox.exec() == QMessageBox::No) { emit pages[0]->getModuleEventsHandler()->replaceMeWith(pages[0], instantiateDefaultModule()); - } - else{ + } else { emit appQuitRequested(); } } diff --git a/Core/modulesmanager.h b/Core/modulesmanager.h index df6554a4d21fe88c3509df3ebb968349e3de7365..d87c6d993d871404326f34b7cf6128e24f8e101f 100644 --- a/Core/modulesmanager.h +++ b/Core/modulesmanager.h @@ -11,11 +11,10 @@ class Module; class SaveConfigurationDialog; class XmlObject; -class ModulesManager : public QObject -{ +class ModulesManager : public QObject { Q_OBJECT -public: + public: ModulesManager(); ~ModulesManager(); @@ -51,23 +50,23 @@ public: QList<QAction *> getHubMenuActions(); -signals: - void contextMenuRequest(QMenu &menu,const QPoint &p); + signals: + void contextMenuRequest(QMenu &menu, const QPoint &p); void pageAdded(int index); void appQuitRequested(); -protected: + protected: void connectModule(Module *module); void disconnectModule(Module *module); void saveConfigurationService(); void onFirstPageDeleted(); -protected slots: + protected slots: void onContextMenuRequest(QMenu &menu, const QPoint &p); void onModuleDeleted(Module *deletedModule); void onReplaceMeWith(Module *sender, Module *newModule); -private: + private: static ModulesList modulesListHandler; QList<Module*> pages; diff --git a/Core/skywardhubcore.cpp b/Core/skywardhubcore.cpp index d640220ce811fbef7929b572c1242c8f8d665ce2..76a2044e7e2ebdb40dde405f1d2a74b3f051d8a2 100644 --- a/Core/skywardhubcore.cpp +++ b/Core/skywardhubcore.cpp @@ -9,29 +9,26 @@ #include "module.h" -SkywardHubCore::SkywardHubCore() -{ +SkywardHubCore::SkywardHubCore() { modulesManager = new ModulesManager(); moduleEventsHandler = new ModuleEventsHandler(); moduleMessagesBroker = new ModuleMessagesBroker(); } -SkywardHubCore::~SkywardHubCore() -{ - if(modulesManager){ +SkywardHubCore::~SkywardHubCore() { + if(modulesManager) { delete modulesManager; } - if(moduleEventsHandler){ + if(moduleEventsHandler) { delete moduleEventsHandler; } - if(moduleMessagesBroker){ + if(moduleMessagesBroker) { delete moduleMessagesBroker; } } -void SkywardHubCore::init() -{ - if(!settings.loadFromFile(SkywardHubStrings::defaultSettingsFilePath)){ +void SkywardHubCore::init() { + if(!settings.loadFromFile(SkywardHubStrings::defaultSettingsFilePath)) { // Settings file not found or loaded incorrectly settings.reset(); settings.setObjectName(SkywardHubStrings::settingsObjectName); @@ -44,24 +41,22 @@ void SkywardHubCore::init() loadFirstPage(); } -void SkywardHubCore::checkDefaultFolders() -{ +void SkywardHubCore::checkDefaultFolders() { /* * If SkywardHubConfig is missing, it create all the missing folder */ - if(!QDir(SkywardHubStrings::defaultConfigurationFolder).exists()){ + if(!QDir(SkywardHubStrings::defaultConfigurationFolder).exists()) { QDir().mkdir(SkywardHubStrings::defaultConfigurationFolder); } - if(!QFile(SkywardHubStrings::defaultSettingsFilePath).exists()){ + if(!QFile(SkywardHubStrings::defaultSettingsFilePath).exists()) { saveSettings(); } } -void SkywardHubCore::saveSettings() -{ - if(settings.writeToFile(SkywardHubStrings::defaultSettingsFilePath)){ +void SkywardHubCore::saveSettings() { + if(settings.writeToFile(SkywardHubStrings::defaultSettingsFilePath)) { QMessageBox confirmMsg; confirmMsg.setMinimumSize(256, 256); confirmMsg.setText(SkywardHubStrings::settingsSavedCorrectlyMsg); @@ -69,12 +64,11 @@ void SkywardHubCore::saveSettings() } } -void SkywardHubCore::loadFirstPage() -{ +void SkywardHubCore::loadFirstPage() { QString pageToLoadName = settings.getChildObjectValue(SkywardHubStrings::skywardHubInitFileTag); - if(!pageToLoadName.isEmpty()){ + if(!pageToLoadName.isEmpty()) { XmlObject pageToLoad; - if(pageToLoad.loadFromFile(SkywardHubStrings::defaultPrefabsFolder + pageToLoadName)){ + if(pageToLoad.loadFromFile(SkywardHubStrings::defaultPrefabsFolder + pageToLoadName)) { modulesManager->setModules(modulesManager->loadModuleFromXml(pageToLoad)); return; } @@ -84,18 +78,15 @@ void SkywardHubCore::loadFirstPage() modulesManager->openNewEmptyWindow(); } -ModuleMessagesBroker *SkywardHubCore::getModuleMessagesBroker() -{ +ModuleMessagesBroker *SkywardHubCore::getModuleMessagesBroker() { return moduleMessagesBroker; } -ModuleEventsHandler *SkywardHubCore::getModuleEventsHandler() -{ +ModuleEventsHandler *SkywardHubCore::getModuleEventsHandler() { return moduleEventsHandler; } -ModulesManager *SkywardHubCore::getModulesManager() -{ +ModulesManager *SkywardHubCore::getModulesManager() { return modulesManager; } @@ -103,9 +94,8 @@ ModulesManager *SkywardHubCore::getModulesManager() SkywardHubCore *SkywardHubCoreProxy::core = nullptr; -SkywardHubCore *SkywardHubCoreProxy::getCore() -{ - if(SkywardHubCoreProxy::core == nullptr){ +SkywardHubCore *SkywardHubCoreProxy::getCore() { + if(SkywardHubCoreProxy::core == nullptr) { SkywardHubCoreProxy::core = new SkywardHubCore(); } return SkywardHubCoreProxy::core; @@ -113,7 +103,6 @@ SkywardHubCore *SkywardHubCoreProxy::getCore() //_________________ ModulesManagerProxy ____________________________________________________________ -XmlObject SkywardHubCore::getSettings() const -{ +XmlObject SkywardHubCore::getSettings() const { return settings; } diff --git a/Core/skywardhubcore.h b/Core/skywardhubcore.h index 65ee9fe9eca50affd45907566d2e235e68c74221..52820c96b40ec602f7758a21c0f1a7ad2a095a35 100644 --- a/Core/skywardhubcore.h +++ b/Core/skywardhubcore.h @@ -11,11 +11,10 @@ class ModuleEventsHandler; class ModuleMessagesBroker; class Module; -class SkywardHubCore : public QObject -{ +class SkywardHubCore : public QObject { Q_OBJECT -public: + public: SkywardHubCore(); ~SkywardHubCore(); @@ -27,15 +26,15 @@ public: XmlObject getSettings() const; -signals: + signals: void centralModuleChanged(Module *newModule); -protected: + protected: void checkDefaultFolders(); void saveSettings(); void loadFirstPage(); -private: + private: ModulesManager *modulesManager = nullptr; ModuleEventsHandler *moduleEventsHandler = nullptr; ModuleMessagesBroker *moduleMessagesBroker = nullptr; @@ -45,16 +44,15 @@ private: // Singleton instance of SkywardHubCore -class SkywardHubCoreProxy{ +class SkywardHubCoreProxy { -public: + public: static SkywardHubCore* getCore(); - SkywardHubCore* operator->() - { + SkywardHubCore* operator->() { return getCore(); } -private: + private: static SkywardHubCore *core; }; diff --git a/Core/xmlobject.cpp b/Core/xmlobject.cpp index bbe8bda67bf4e7269baa1494b41a8bb711118bf5..5af552eb9945bb8312fa58e6cda97413130e208e 100644 --- a/Core/xmlobject.cpp +++ b/Core/xmlobject.cpp @@ -3,23 +3,20 @@ #include <QTextStream> #include <QFile> -XmlObject::XmlObject(const QString &objectName) -{ +XmlObject::XmlObject(const QString &objectName) { setObjectName(objectName); } -XmlObject::XmlObject(const XmlObject &other) -{ +XmlObject::XmlObject(const XmlObject &other) { copy(other); } -bool XmlObject::loadFromFile(const QString &filePath) -{ +bool XmlObject::loadFromFile(const QString &filePath) { bool result = false; QFile file(filePath); - if(file.exists() && file.open(QIODevice::ReadOnly)){ + if(file.exists() && file.open(QIODevice::ReadOnly)) { QString msgDefFileContent = QTextStream(&file).readAll(); - if(msgDefFileContent != ""){ + if(msgDefFileContent != "") { this->fromXml(msgDefFileContent); result = true; } @@ -28,11 +25,10 @@ bool XmlObject::loadFromFile(const QString &filePath) return result; } -bool XmlObject::writeToFile(const QString &filePath, const QString &codec) const -{ +bool XmlObject::writeToFile(const QString &filePath, const QString &codec) const { bool result = false; QFile file(filePath); - if(file.open(QIODevice::WriteOnly)){ + if(file.open(QIODevice::WriteOnly)) { QTextStream textStream(&file); textStream.setCodec(codec.toUtf8()); textStream << this->toXml(); @@ -42,8 +38,7 @@ bool XmlObject::writeToFile(const QString &filePath, const QString &codec) const return result; } -QString XmlObject::toXml() const -{ +QString XmlObject::toXml() const { QString output; QXmlStreamWriter xWriter(&output); xWriter.setAutoFormatting(true); @@ -52,98 +47,88 @@ QString XmlObject::toXml() const } -void XmlObject::toXml(QXmlStreamWriter *xmlWriter) const -{ +void XmlObject::toXml(QXmlStreamWriter *xmlWriter) const { xmlWriter->writeStartElement(xmlObjectName); - for(QString key : attributes.keys()){ + for(QString key : attributes.keys()) { xmlWriter->writeAttribute(key, attributes[key]); } - if(getTextValue() != "" && childCount() == 0){ + if(getTextValue() != "" && childCount() == 0) { xmlWriter->writeCharacters(getTextValue()); } - for(XmlObject c : childList){ + for(XmlObject c : childList) { c.toXml(xmlWriter); } xmlWriter->writeEndElement(); } -void XmlObject::fromXml(const QString &txt) -{ +void XmlObject::fromXml(const QString &txt) { QXmlStreamReader xReader(txt); xReader.readNextStartElement(); fromXml(&xReader); } -void XmlObject::fromXml(QXmlStreamReader *xmlReader) -{ +void XmlObject::fromXml(QXmlStreamReader *xmlReader) { childList.clear(); attributes.clear(); - if(xmlReader->isStartElement()){ + if(xmlReader->isStartElement()) { setObjectName(xmlReader->name().toString()); - for(auto attr : xmlReader->attributes()){ + for(auto attr : xmlReader->attributes()) { attributes[attr.name().toString()] = attr.value().toString(); } } - while(!xmlReader->atEnd()){ + while(!xmlReader->atEnd()) { xmlReader->readNext(); - if(xmlReader->isCharacters() && !xmlReader->isWhitespace()){ + if(xmlReader->isCharacters() && !xmlReader->isWhitespace()) { setTextValue(xmlReader->text().toString()); - } - else if(xmlReader->isStartElement()){ + } else if(xmlReader->isStartElement()) { XmlObject c; c.fromXml(xmlReader); childList.append(c); - } - else if(xmlReader->isEndElement()){ + } else if(xmlReader->isEndElement()) { return; } } } -void XmlObject::copy(const XmlObject &other) -{ +void XmlObject::copy(const XmlObject &other) { childList.clear(); attributes.clear(); setObjectName(other.getObjectName()); setTextValue(other.getTextValue()); - for(QString attr : other.attributes.keys()){ + for(QString attr : other.attributes.keys()) { attributes[attr] = other.attributes[attr]; } - for(int i= 0; i< other.childCount(); i++){ + for(int i = 0; i < other.childCount(); i++) { addChild(other.childAt(i)); } } -QString XmlObject::getTextValue() const -{ +QString XmlObject::getTextValue() const { return textValue; } -void XmlObject::setTextValue(const QString &value) -{ +void XmlObject::setTextValue(const QString &value) { textValue = value; } -QList<XmlObject *> XmlObject::deepSearchObjects(const QString &objectName) -{ - auto pred = [objectName](const XmlObject *obj){ +QList<XmlObject *> XmlObject::deepSearchObjects(const QString &objectName) { + auto pred = [objectName](const XmlObject * obj) { return obj->getObjectName() == objectName; }; return deepSearchObjects(pred); } -QList<XmlObject *> XmlObject::deepSearchObjects(std::function<bool (const XmlObject *obj)> predicate) -{ +QList<XmlObject *> XmlObject::deepSearchObjects(std::function<bool (const XmlObject *obj)> predicate) { QList<XmlObject *> results; - if(predicate(this)){ + if(predicate(this)) { results.append(this); } @@ -155,88 +140,75 @@ QList<XmlObject *> XmlObject::deepSearchObjects(std::function<bool (const XmlObj return results; } -void XmlObject::operator =(const XmlObject &other) -{ +void XmlObject::operator =(const XmlObject &other) { copy(other); } -void XmlObject::removeChild(int i) -{ +void XmlObject::removeChild(int i) { if( i < childCount()) childList.removeAt(i); } -void XmlObject::swapChildAt(int i, int j) -{ - if(i > 0 && j > 0 && i < childCount() && j < childCount()){ +void XmlObject::swapChildAt(int i, int j) { + if(i > 0 && j > 0 && i < childCount() && j < childCount()) { childList.swapItemsAt(i, j); } } -QString XmlObject::getChildObjectValue(const QString &objectName) -{ - for(XmlObject child : childList){ - if(child.getObjectName() == objectName){ +QString XmlObject::getChildObjectValue(const QString &objectName) { + for(XmlObject child : childList) { + if(child.getObjectName() == objectName) { return child.getTextValue(); } } return ""; } -void XmlObject::clearAttributes() -{ +void XmlObject::clearAttributes() { attributes.clear(); } -void XmlObject::clearChilds() -{ +void XmlObject::clearChilds() { childList.clear(); } -void XmlObject::reset() -{ +void XmlObject::reset() { setObjectName(""); clearChilds(); clearAttributes(); } -bool XmlObject::isEmpty() -{ +bool XmlObject::isEmpty() { return getObjectName() == "" && childList.isEmpty() && getTextValue() == "" && attributes.isEmpty(); } -QString XmlObject::getAttribute(const QString &name) const -{ - if(attributes.contains(name)){ +QString XmlObject::getAttribute(const QString &name) const { + if(attributes.contains(name)) { return attributes[name]; } return QString(""); } -bool XmlObject::hasAttribute(const QString &name) const -{ +bool XmlObject::hasAttribute(const QString &name) const { return attributes.contains(name); } -int XmlObject::attributeCount() const -{ +int XmlObject::attributeCount() const { return attributes.count(); } -QMapIterator<QString, QString> XmlObject::attributesIterator() const -{ - return QMapIterator<QString,QString>(attributes); +QMapIterator<QString, QString> XmlObject::attributesIterator() const { + return QMapIterator<QString, QString>(attributes); } -bool XmlObject::getIntAttribute(const QString &name, int &value) const -{ +bool XmlObject::getIntAttribute(const QString &name, int &value) const { QString val = getAttribute(name); bool ok; - if(val != ""){ + if(val != "") { int temp = val.toInt(&ok); - if(ok){ + if(ok) { value = temp; return true; } @@ -244,13 +216,12 @@ bool XmlObject::getIntAttribute(const QString &name, int &value) const return false; } -bool XmlObject::getFloatAttribute(const QString &name, float &value) const -{ +bool XmlObject::getFloatAttribute(const QString &name, float &value) const { QString val = getAttribute(name); bool ok; - if(val != ""){ + if(val != "") { float temp = val.toFloat(&ok); - if(ok){ + if(ok) { value = temp; return true; } @@ -258,58 +229,48 @@ bool XmlObject::getFloatAttribute(const QString &name, float &value) const return false; } -void XmlObject::addAttribute(const QString &name, const QString &value) -{ +void XmlObject::addAttribute(const QString &name, const QString &value) { attributes[name] = value; } -void XmlObject::addAttribute(const QString &name, int value) -{ +void XmlObject::addAttribute(const QString &name, int value) { addAttribute(name, QString::number(value)); } -int XmlObject::addChild(const XmlObject &c) -{ +int XmlObject::addChild(const XmlObject &c) { childList.append(c); return childList.count() - 1; } -void XmlObject::addChilds(const QList<XmlObject> &childs) -{ +void XmlObject::addChilds(const QList<XmlObject> &childs) { childList.append(childs); } -QString XmlObject::getObjectName() const -{ +QString XmlObject::getObjectName() const { return xmlObjectName; } -void XmlObject::setObjectName(const QString &value) -{ +void XmlObject::setObjectName(const QString &value) { xmlObjectName = value; } -int XmlObject::childCount() const -{ +int XmlObject::childCount() const { return childList.count(); } -XmlObject XmlObject::childAt(int index) const -{ +XmlObject XmlObject::childAt(int index) const { return childList.at(index); } -XmlObject XmlObject::searchChild(const QString &name) const -{ - for(int i= 0; i < childCount(); i++){ - if(childList[i].getObjectName() == name){ +XmlObject XmlObject::searchChild(const QString &name) const { + for(int i = 0; i < childCount(); i++) { + if(childList[i].getObjectName() == name) { return childList[i]; } } return XmlObject(); } -XmlObject * XmlObject::getChild(int index) -{ +XmlObject * XmlObject::getChild(int index) { return &childList[index]; } diff --git a/Core/xmlobject.h b/Core/xmlobject.h index 8b64516ce74c042d24e8f8b86144631e8e65e3d0..19cac10b602614d52755c7418ea547fed2eba9c8 100644 --- a/Core/xmlobject.h +++ b/Core/xmlobject.h @@ -7,13 +7,11 @@ #include <QXmlStreamReader> #include <QMapIterator> -class XmlObject -{ -public: +class XmlObject { + public: XmlObject(const QString &objectName = "Object"); XmlObject(const XmlObject &other); - bool loadFromFile(const QString& filePath); bool writeToFile(const QString& filePath, const QString &codec = "UTF-8") const; @@ -80,13 +78,13 @@ public: void reset(); bool isEmpty(); -protected: + protected: void toXml(QXmlStreamWriter *xmlWriter) const; void fromXml(QXmlStreamReader *xmlReader); void copy(const XmlObject &other); -private: - QMap<QString,QString> attributes; + private: + QMap<QString, QString> attributes; QList<XmlObject> childList; QString textValue = ""; QString xmlObjectName = ""; diff --git a/Modules/CommandPad/commandpadmodule.cpp b/Modules/CommandPad/commandpadmodule.cpp index a1f79ead7b260eeeecab38a98648159b09bde54d..ecc79c4c6ed61ffc96ee9cbbc56d26fedbdfb4b2 100644 --- a/Modules/CommandPad/commandpadmodule.cpp +++ b/Modules/CommandPad/commandpadmodule.cpp @@ -7,43 +7,37 @@ #include "Modules/skywardhubstrings.h" #include <QDebug> -CommandPadModule::CommandPadModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::CommandPadModule) -{ +CommandPadModule::CommandPadModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::CommandPadModule) { ui->setupUi(this); defaultContextMenuSetup(); buildUI(); } -CommandPadModule::~CommandPadModule() -{ +CommandPadModule::~CommandPadModule() { delete ui; } -QWidget *CommandPadModule::toWidget() -{ +QWidget *CommandPadModule::toWidget() { return this; } -XmlObject CommandPadModule::toXmlObject() -{ +XmlObject CommandPadModule::toXmlObject() { return XmlObject(getName(ModuleId::COMMANDPAD)); } -void CommandPadModule::fromXmlObject(const XmlObject &xmlObject) -{ +void CommandPadModule::fromXmlObject(const XmlObject &xmlObject) { Q_UNUSED(xmlObject); } -void CommandPadModule::buildUI() -{ +void CommandPadModule::buildUI() { connect(ui->closeLog_button, &QPushButton::clicked, this, &CommandPadModule::onCloseLogClicked); connect(ui->wiggleARBServo_button, &QPushButton::clicked, this, &CommandPadModule::onWiggleARBServoClicked); connect(ui->resetARBServo_button, &QPushButton::clicked, this, &CommandPadModule::onResetARBServoClicked); connect(ui->wiggleDPLServo_button, &QPushButton::clicked, this, &CommandPadModule::onWiggleDPLServoClicked); connect(ui->resetDPLServo_button, &QPushButton::clicked, this, &CommandPadModule::onResetDPLServoClicked); -// connect(ui->testPrimaryCut_button, &QPushButton::clicked, this, &CommandPadModule::onTestPrimaryCutClicked); + // connect(ui->testPrimaryCut_button, &QPushButton::clicked, this, &CommandPadModule::onTestPrimaryCutClicked); connect(ui->testMode_button, &QPushButton::clicked, this, &CommandPadModule::onTestModeClicked); -// connect(ui->testBackupCut_button, &QPushButton::clicked, this, &CommandPadModule::onTestBackupCutClicked); + // connect(ui->testBackupCut_button, &QPushButton::clicked, this, &CommandPadModule::onTestBackupCutClicked); connect(ui->boardReset_button, &QPushButton::clicked, this, &CommandPadModule::onBoardResetClicked); connect(ui->testAerobrakest_button, &QPushButton::clicked, this, &CommandPadModule::onTestAerobrakesClicked); connect(ui->disableAerobrakes_button, &QPushButton::clicked, this, &CommandPadModule::onDisableAerobrakesClicked); @@ -67,8 +61,8 @@ void CommandPadModule::buildUI() connect(ui->stopTelemetry_button, &QPushButton::clicked, this, &CommandPadModule::onStopTelemetryClicked); connect(ui->cutDrogue_button, &QPushButton::clicked, this, &CommandPadModule::onCutDrogueClicked); -// connect(ui->primaryCut_button, &QPushButton::clicked, this, &CommandPadModule::onPrimaryCutClicked); -// connect(ui->backupCut_button, &QPushButton::clicked, this, &CommandPadModule::onBackupClicked); + // connect(ui->primaryCut_button, &QPushButton::clicked, this, &CommandPadModule::onPrimaryCutClicked); + // connect(ui->backupCut_button, &QPushButton::clicked, this, &CommandPadModule::onBackupClicked); } //void CommandPadModule::buildMsgKeyList() @@ -102,23 +96,20 @@ void CommandPadModule::buildUI() // }); //} -ModuleMessage CommandPadModule::createCommandMsg(const QString &msgKey) const -{ +ModuleMessage CommandPadModule::createCommandMsg(const QString &msgKey) const { ModuleMessage msg; msg.setTopic(SkywardHubStrings::commandsTopic + "/" + msgKey); return msg; } -ModuleMessage CommandPadModule::createCommandMsgWithPayload(const QString &msgKey, const QString &payload) const -{ +ModuleMessage CommandPadModule::createCommandMsgWithPayload(const QString &msgKey, const QString &payload) const { ModuleMessage msg = createCommandMsg(msgKey); msg.setPayload(payload); return msg; } -ModuleMessage CommandPadModule::createRawEventMsg(const QString &msgKey, int event_id, int topic_id) const -{ +ModuleMessage CommandPadModule::createRawEventMsg(const QString &msgKey, int event_id, int topic_id) const { ModuleMessage msg = createCommandMsg(msgKey); msg.addOption(SkywardHubStrings::raw_event_id, event_id); @@ -127,47 +118,40 @@ ModuleMessage CommandPadModule::createRawEventMsg(const QString &msgKey, int eve return msg; } -void CommandPadModule::send(const ModuleMessage &msg) -{ +void CommandPadModule::send(const ModuleMessage &msg) { getCore()->getModuleMessagesBroker()->publish(msg); } -void CommandPadModule::onStartLogClicked() -{ +void CommandPadModule::onStartLogClicked() { send(createCommandMsg("MAV_CMD_START_LOGGING")); -// if(val){ -// // Start logging -// send(createCommandMsg("MAV_CMD_START_LOGGING")); -// } -// else{ -// // Stop logging -// send(createCommandMsg("MAV_CMD_STOP_LOGGING")); -// } -} - -void CommandPadModule::onCloseLogClicked() -{ + // if(val){ + // // Start logging + // send(createCommandMsg("MAV_CMD_START_LOGGING")); + // } + // else{ + // // Stop logging + // send(createCommandMsg("MAV_CMD_STOP_LOGGING")); + // } +} + +void CommandPadModule::onCloseLogClicked() { send(createCommandMsg("MAV_CMD_CLOSE_LOG")); } -void CommandPadModule::onWiggleARBServoClicked() -{ +void CommandPadModule::onWiggleARBServoClicked() { send(createCommandMsg("MAV_CMD_ARB_WIGGLE_SERVO")); } -void CommandPadModule::onResetARBServoClicked() -{ +void CommandPadModule::onResetARBServoClicked() { send(createCommandMsg("MAV_CMD_ARB_RESET_SERVO")); } -void CommandPadModule::onWiggleDPLServoClicked() -{ +void CommandPadModule::onWiggleDPLServoClicked() { send(createCommandMsg("MAV_CMD_DPL_WIGGLE_SERVO")); } -void CommandPadModule::onResetDPLServoClicked() -{ +void CommandPadModule::onResetDPLServoClicked() { send(createCommandMsg("MAV_CMD_DPL_RESET_SERVO")); } @@ -181,56 +165,46 @@ void CommandPadModule::onResetDPLServoClicked() // send(createCommandMsg("MAV_CMD_TEST_BACKUP_CUTTER")); //} -void CommandPadModule::onTestModeClicked() -{ +void CommandPadModule::onTestModeClicked() { send(createCommandMsg("MAV_CMD_TEST_MODE")); } -void CommandPadModule::onBoardResetClicked() -{ +void CommandPadModule::onBoardResetClicked() { send(createCommandMsg("MAV_CMD_BOARD_RESET")); } -void CommandPadModule::onCalibrateALGOSClicked() -{ +void CommandPadModule::onCalibrateALGOSClicked() { send(createCommandMsg("MAV_CMD_CALIBRATE_ALGOS")); } -void CommandPadModule::onCalibrateSENSORSClicked() -{ +void CommandPadModule::onCalibrateSENSORSClicked() { send(createCommandMsg("MAV_CMD_CALIBRATE_SENSORS")); } -void CommandPadModule::onTestAerobrakesClicked() -{ +void CommandPadModule::onTestAerobrakesClicked() { send(createCommandMsg("MAV_CMD_TEST_AEROBRAKES")); } -void CommandPadModule::onDisableAerobrakesClicked() -{ +void CommandPadModule::onDisableAerobrakesClicked() { send(createCommandMsg("MAV_CMD_DISABLE_AEROBRAKES")); } -void CommandPadModule::onDeploymentAltitudeSetClicked() -{ +void CommandPadModule::onDeploymentAltitudeSetClicked() { QString payload = QString::number(ui->deploymentAltitude_spinBox->value()); send(createCommandMsgWithPayload("SET_DEPLOYMENT_ALTITUDE_TC", payload)); } -void CommandPadModule::onRefTemperatureSetClicked() -{ +void CommandPadModule::onRefTemperatureSetClicked() { QString payload = QString::number(ui->refTemperature_spinBox->value()); send(createCommandMsgWithPayload("SET_REFERENCE_TEMPERATURE_TC", payload)); } -void CommandPadModule::onRefAltitudeSetClicked() -{ +void CommandPadModule::onRefAltitudeSetClicked() { QString payload = QString::number(ui->referenceAltitude_spinBox->value()); send(createCommandMsgWithPayload("SET_REFERENCE_ALTITUDE", payload)); } -void CommandPadModule::onInitialCoordinatesSetClicked() -{ +void CommandPadModule::onInitialCoordinatesSetClicked() { ModuleMessage msg = createCommandMsg("SET_INITIAL_COORDINATES_TC"); QString lat = QString::number(ui->initialLatitude_spinBox->value()); @@ -242,14 +216,12 @@ void CommandPadModule::onInitialCoordinatesSetClicked() send(msg); } -void CommandPadModule::onAerobrakeAngleSetClicked() -{ +void CommandPadModule::onAerobrakeAngleSetClicked() { QString payload = QString::number(ui->aerobrakeAngle_spinBox->value()); send(createCommandMsgWithPayload("SET_AEROBRAKE_ANGLE_TC", payload)); } -void CommandPadModule::onInitialOrientationSetClicked() -{ +void CommandPadModule::onInitialOrientationSetClicked() { ModuleMessage msg = createCommandMsg("SET_INITIAL_ORIENTATION_TC"); QString yaw = QString::number(ui->initialOrientationYaw_spinBox->value()); @@ -263,45 +235,37 @@ void CommandPadModule::onInitialOrientationSetClicked() send(msg); } -void CommandPadModule::onArmClicked() -{ +void CommandPadModule::onArmClicked() { send(createCommandMsg("MAV_CMD_ARM")); } -void CommandPadModule::onDisarmClicked() -{ +void CommandPadModule::onDisarmClicked() { send(createCommandMsg("MAV_CMD_DISARM")); } -void CommandPadModule::onForceLaunchClicked() -{ +void CommandPadModule::onForceLaunchClicked() { send(createCommandMsg("MAV_CMD_FORCE_LAUNCH")); } -void CommandPadModule::onForceInitClicked() -{ +void CommandPadModule::onForceInitClicked() { send(createCommandMsg("MAV_CMD_FORCE_INIT")); } -void CommandPadModule::onNoseconeOpenClicked() -{ +void CommandPadModule::onNoseconeOpenClicked() { send(createCommandMsg("MAV_CMD_NOSECONE_OPEN")); } -void CommandPadModule::onEndMissionClicked() -{ +void CommandPadModule::onEndMissionClicked() { send(createCommandMsg("MAV_CMD_END_MISSION")); } -void CommandPadModule::onRawEventSendClicked() -{ +void CommandPadModule::onRawEventSendClicked() { int event_id = ui->rawEventId_spinBox->value(); int topic_id = ui->rawEventTopic_spinBox->value(); send(createRawEventMsg("RAW_EVENT_TC", event_id, topic_id)); } -void CommandPadModule::onCutDrogueClicked() -{ +void CommandPadModule::onCutDrogueClicked() { send(createCommandMsg("MAV_CMD_CUT_DROGUE")); } @@ -315,13 +279,11 @@ void CommandPadModule::onCutDrogueClicked() // send(createCommandMsg("MAV_CMD_CUT_BACKUP")); //} -void CommandPadModule::onStartTelemetryClicked() -{ +void CommandPadModule::onStartTelemetryClicked() { send(createCommandMsg("MAV_CMD_RADIO_TM")); } -void CommandPadModule::onStopTelemetryClicked() -{ +void CommandPadModule::onStopTelemetryClicked() { send(createCommandMsg("MAV_CMD_SERIAL_TM")); } diff --git a/Modules/CommandPad/commandpadmodule.h b/Modules/CommandPad/commandpadmodule.h index 6435f37a56aff85298e0699a784ac47dff7ef13c..5f8bc580f34053b8dc73eb36355fadfe147f483b 100644 --- a/Modules/CommandPad/commandpadmodule.h +++ b/Modules/CommandPad/commandpadmodule.h @@ -8,11 +8,10 @@ namespace Ui { class CommandPadModule; } -class CommandPadModule : public DefaultModule -{ +class CommandPadModule : public DefaultModule { Q_OBJECT -public: + public: explicit CommandPadModule(QWidget *parent = nullptr); ~CommandPadModule(); @@ -20,7 +19,7 @@ public: XmlObject toXmlObject() override; void fromXmlObject(const XmlObject &xmlObject) override; -protected: + protected: void buildUI(); ModuleMessage createCommandMsg(const QString &msgKey) const; ModuleMessage createCommandMsgWithPayload(const QString &msgKey, const QString &payload) const; @@ -33,9 +32,9 @@ protected: void onResetARBServoClicked(); void onWiggleDPLServoClicked(); void onResetDPLServoClicked(); -// void onTestPrimaryCutClicked(); + // void onTestPrimaryCutClicked(); void onTestModeClicked(); -// void onTestBackupCutClicked(); + // void onTestBackupCutClicked(); void onBoardResetClicked(); void onCalibrateALGOSClicked(); void onCalibrateSENSORSClicked(); @@ -55,12 +54,12 @@ protected: void onEndMissionClicked(); void onRawEventSendClicked(); void onCutDrogueClicked(); -// void onPrimaryCutClicked(); -// void onBackupClicked(); + // void onPrimaryCutClicked(); + // void onBackupClicked(); void onStartTelemetryClicked(); void onStopTelemetryClicked(); -private: + private: Ui::CommandPadModule *ui; }; diff --git a/Modules/CommandPad/telemetryrequestmodule.cpp b/Modules/CommandPad/telemetryrequestmodule.cpp index 343e7a7dcc32b6edf35c9821fd2e6684dcce13b7..b09e66f462c245e5adcaa46370fe0317afca3a71 100644 --- a/Modules/CommandPad/telemetryrequestmodule.cpp +++ b/Modules/CommandPad/telemetryrequestmodule.cpp @@ -4,42 +4,36 @@ #include "Core/modulemessagesbroker.h" #include "Modules/skywardhubstrings.h" -TelemetryRequestModule::TelemetryRequestModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::TelemetryRequestModule) -{ +TelemetryRequestModule::TelemetryRequestModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::TelemetryRequestModule) { ui->setupUi(this); defaultContextMenuSetup(); connectUI(); } -TelemetryRequestModule::~TelemetryRequestModule() -{ +TelemetryRequestModule::~TelemetryRequestModule() { delete ui; } -QWidget *TelemetryRequestModule::toWidget() -{ +QWidget *TelemetryRequestModule::toWidget() { return this; } -XmlObject TelemetryRequestModule::toXmlObject() -{ +XmlObject TelemetryRequestModule::toXmlObject() { return XmlObject(getName(ModuleId::TELEMETRYPAD)); } -void TelemetryRequestModule::fromXmlObject(const XmlObject &xmlObject) -{ +void TelemetryRequestModule::fromXmlObject(const XmlObject &xmlObject) { Q_UNUSED(xmlObject); } -void TelemetryRequestModule::connectUI() -{ +void TelemetryRequestModule::connectUI() { connect(ui->sys_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_SYS_TM_Clicked); connect(ui->fmm_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_FMM_TM_Clicked); connect(ui->logger_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_LOGGER_TM_Clicked); connect(ui->tmtc_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_TMTC_TM_Clicked); connect(ui->dpl_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_DPL_TM_Clicked); connect(ui->ada_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_ADA_TM_Clicked); -// connect(ui->can_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_CAN_TM_Clicked); + // connect(ui->can_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_CAN_TM_Clicked); connect(ui->adc_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_ADC_TM_Clicked); connect(ui->gps_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_GPS_TM_Clicked); connect(ui->hr_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_HR_TM_Clicked); @@ -53,51 +47,43 @@ void TelemetryRequestModule::connectUI() connect(ui->ms5803_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_MS5803_TM_Clicked); connect(ui->bmx160_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_BMX160_TM_Clicked); connect(ui->lis3mdl_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_LIS3MDL_TM_Clicked); -// connect(ui->strain_board_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_STRAIN_BOARD_TM_Clicked); + // connect(ui->strain_board_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_STRAIN_BOARD_TM_Clicked); connect(ui->windtunnel_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_WINDTUNNEL_TM_Clicked); connect(ui->sensors_tm_pushButton, &QPushButton::clicked, this, &TelemetryRequestModule::on_SENSORS_TM_Clicked); } -void TelemetryRequestModule::send(const ModuleMessage &msg) -{ +void TelemetryRequestModule::send(const ModuleMessage &msg) { getCore()->getModuleMessagesBroker()->publish(msg); } -ModuleMessage TelemetryRequestModule::createTmMessage(const QString &msgKey) -{ +ModuleMessage TelemetryRequestModule::createTmMessage(const QString &msgKey) { ModuleMessage msg; msg.setTopic(SkywardHubStrings::telemetryRequestTopic + "/" + msgKey); return msg; } -void TelemetryRequestModule::on_SYS_TM_Clicked() -{ +void TelemetryRequestModule::on_SYS_TM_Clicked() { send(createTmMessage("MAV_SYS_TM_ID")); } -void TelemetryRequestModule::on_FMM_TM_Clicked() -{ +void TelemetryRequestModule::on_FMM_TM_Clicked() { send(createTmMessage("MAV_FMM_TM_ID")); } -void TelemetryRequestModule::on_LOGGER_TM_Clicked() -{ +void TelemetryRequestModule::on_LOGGER_TM_Clicked() { send(createTmMessage("MAV_LOGGER_TM_ID")); } -void TelemetryRequestModule::on_TMTC_TM_Clicked() -{ +void TelemetryRequestModule::on_TMTC_TM_Clicked() { send(createTmMessage("MAV_TMTC_TM_ID")); } -void TelemetryRequestModule::on_DPL_TM_Clicked() -{ +void TelemetryRequestModule::on_DPL_TM_Clicked() { send(createTmMessage("MAV_DPL_TM_ID")); } -void TelemetryRequestModule::on_ADA_TM_Clicked() -{ +void TelemetryRequestModule::on_ADA_TM_Clicked() { send(createTmMessage("MAV_ADA_TM_ID")); } @@ -106,73 +92,59 @@ void TelemetryRequestModule::on_ADA_TM_Clicked() // send(createTmMessage("MAV_CAN_TM_ID")); //} -void TelemetryRequestModule::on_ADC_TM_Clicked() -{ +void TelemetryRequestModule::on_ADC_TM_Clicked() { send(createTmMessage("MAV_ADC_TM_ID")); } -void TelemetryRequestModule::on_GPS_TM_Clicked() -{ +void TelemetryRequestModule::on_GPS_TM_Clicked() { send(createTmMessage("MAV_GPS_TM_ID")); } -void TelemetryRequestModule::on_HR_TM_Clicked() -{ +void TelemetryRequestModule::on_HR_TM_Clicked() { send(createTmMessage("MAV_HR_TM_ID")); } -void TelemetryRequestModule::on_LR_TM_Clicked() -{ +void TelemetryRequestModule::on_LR_TM_Clicked() { send(createTmMessage("MAV_LR_TM_ID")); } -void TelemetryRequestModule::on_TEST_TM_Clicked() -{ +void TelemetryRequestModule::on_TEST_TM_Clicked() { send(createTmMessage("MAV_TEST_TM_ID")); } -void TelemetryRequestModule::on_WINDTUNNEL_TM_Clicked() -{ +void TelemetryRequestModule::on_WINDTUNNEL_TM_Clicked() { send(createTmMessage("MAV_WINDTUNNEL_TM_ID")); } -void TelemetryRequestModule::on_SENSORS_TM_Clicked() -{ +void TelemetryRequestModule::on_SENSORS_TM_Clicked() { send(createTmMessage("MAV_SENSORS_TM_ID")); } -void TelemetryRequestModule::on_PIN_OBS_TM_Clicked() -{ +void TelemetryRequestModule::on_PIN_OBS_TM_Clicked() { send(createTmMessage("MAV_PIN_OBS_TM_ID")); } -void TelemetryRequestModule::on_TASK_STATS_TM_Clicked() -{ +void TelemetryRequestModule::on_TASK_STATS_TM_Clicked() { send(createTmMessage("MAV_TASK_STATS_TM_ID")); } -void TelemetryRequestModule::on_ABK_TM_Clicked() -{ +void TelemetryRequestModule::on_ABK_TM_Clicked() { send(createTmMessage("MAV_ABK_TM_ID")); } -void TelemetryRequestModule::on_NAS_TM_Clicked() -{ +void TelemetryRequestModule::on_NAS_TM_Clicked() { send(createTmMessage("MAV_NAS_TM_ID")); } -void TelemetryRequestModule::on_MS5803_TM_Clicked() -{ +void TelemetryRequestModule::on_MS5803_TM_Clicked() { send(createTmMessage("MAV_MS5803_TM_ID")); } -void TelemetryRequestModule::on_BMX160_TM_Clicked() -{ +void TelemetryRequestModule::on_BMX160_TM_Clicked() { send(createTmMessage("MAV_BMX160_TM_ID")); } -void TelemetryRequestModule::on_LIS3MDL_TM_Clicked() -{ +void TelemetryRequestModule::on_LIS3MDL_TM_Clicked() { send(createTmMessage("MAV_LIS3MDL_TM_ID")); } diff --git a/Modules/CommandPad/telemetryrequestmodule.h b/Modules/CommandPad/telemetryrequestmodule.h index 261736d3c02020b6da59c2a078f3384a9f8fba2d..dbad2d6e46f016ae1f9102137ba65f31981affba 100644 --- a/Modules/CommandPad/telemetryrequestmodule.h +++ b/Modules/CommandPad/telemetryrequestmodule.h @@ -9,11 +9,10 @@ namespace Ui { class TelemetryRequestModule; } -class TelemetryRequestModule : public DefaultModule -{ +class TelemetryRequestModule : public DefaultModule { Q_OBJECT -public: + public: explicit TelemetryRequestModule(QWidget *parent = nullptr); ~TelemetryRequestModule(); @@ -21,7 +20,7 @@ public: XmlObject toXmlObject() override; void fromXmlObject(const XmlObject &xmlObject) override; -protected: + protected: void connectUI(); void onContextMenuRequested(const QPoint &p); void send(const ModuleMessage &msg); @@ -33,7 +32,7 @@ protected: void on_TMTC_TM_Clicked(); void on_DPL_TM_Clicked(); void on_ADA_TM_Clicked(); -// void on_CAN_TM_Clicked(); + // void on_CAN_TM_Clicked(); void on_ADC_TM_Clicked(); void on_GPS_TM_Clicked(); void on_HR_TM_Clicked(); @@ -47,12 +46,12 @@ protected: void on_MS5803_TM_Clicked(); void on_BMX160_TM_Clicked(); void on_LIS3MDL_TM_Clicked(); -// void on_STRAIN_BOARD_TM_Clicked(); + // void on_STRAIN_BOARD_TM_Clicked(); void on_WINDTUNNEL_TM_Clicked(); void on_SENSORS_TM_Clicked(); -private: + private: Ui::TelemetryRequestModule *ui; }; diff --git a/Modules/DefaultModule/defaultmodule.cpp b/Modules/DefaultModule/defaultmodule.cpp index 154086ea232c50b51fc3211d00cf7fd34493bb2c..ac9f121d7b6fcfee518fe3012cb3f061399eef92 100644 --- a/Modules/DefaultModule/defaultmodule.cpp +++ b/Modules/DefaultModule/defaultmodule.cpp @@ -4,21 +4,18 @@ #include "Modules/Utility/contextmenuseparator.h" #include "Core/modulesmanager.h" -DefaultModule::DefaultModule(QWidget *parent) : QWidget(parent) -{ +DefaultModule::DefaultModule(QWidget *parent) : QWidget(parent) { } -DefaultModule::~DefaultModule() -{ - for(int i = 0; i < menuActions.count(); i++){ +DefaultModule::~DefaultModule() { + for(int i = 0; i < menuActions.count(); i++) { delete menuActions[i]; } menuActions.clear(); } -void DefaultModule::closeEvent(QCloseEvent *event) -{ +void DefaultModule::closeEvent(QCloseEvent *event) { if (event->spontaneous()) { emit getModuleEventsHandler()->beforeDelete(this); QWidget::closeEvent(event); @@ -27,37 +24,32 @@ void DefaultModule::closeEvent(QCloseEvent *event) } } -void DefaultModule::defaultContextMenuSetup() -{ +void DefaultModule::defaultContextMenuSetup() { if(areDefaultSettingsDone) return; areDefaultSettingsDone = true; setContextMenuPolicy(Qt::CustomContextMenu); - connect(this,&DefaultModule::customContextMenuRequested, this, &DefaultModule::onCustomContextMenuRequested); + connect(this, &DefaultModule::customContextMenuRequested, this, &DefaultModule::onCustomContextMenuRequested); addDefaultActionsToMenu(); addCustomActionsToMenu(); } -void DefaultModule::onCustomContextMenuRequested(const QPoint &p) -{ +void DefaultModule::onCustomContextMenuRequested(const QPoint &p) { QMenu menu; onSkywardHubContextMenuRequested(menu, mapToGlobal(p)); } -QString DefaultModule::getName(const ModuleId id) -{ +QString DefaultModule::getName(const ModuleId id) { return getCore()->getModulesManager()->getModuleName(id); } -void DefaultModule::onSkywardHubContextMenuRequested(QMenu &menu, const QPoint &p) -{ +void DefaultModule::onSkywardHubContextMenuRequested(QMenu &menu, const QPoint &p) { QMenu newMenu(menuName); - if(!menuName.isEmpty()){ + if(!menuName.isEmpty()) { newMenu.addActions(menuActions); menu.addMenu(&newMenu); - } - else + } else menu.addActions(menuActions); ContextMenuSeparator separator; @@ -65,45 +57,39 @@ void DefaultModule::onSkywardHubContextMenuRequested(QMenu &menu, const QPoint & emit getModuleEventsHandler()->contextMenuRequest(menu, p); } -void DefaultModule::addDefaultActionsToMenu() -{ +void DefaultModule::addDefaultActionsToMenu() { QAction* close = new QAction("Close"); - connect(close,&QAction::triggered,this,[this](){ + connect(close, &QAction::triggered, this, [this]() { delete this; }); QAction* replace = new QAction("Replace"); - connect(replace,&QAction::triggered,this, &DefaultModule::onReplaceClicked); + connect(replace, &QAction::triggered, this, &DefaultModule::onReplaceClicked); addActionToMenu(close); addActionToMenu(replace); } -void DefaultModule::addActionToMenu(QAction *action) -{ +void DefaultModule::addActionToMenu(QAction *action) { menuActions.append(action); } -void DefaultModule::showMenuActionsInSeparatedMenu(const QString &menuName) -{ +void DefaultModule::showMenuActionsInSeparatedMenu(const QString &menuName) { this->menuName = menuName; } -void DefaultModule::onReplaceClicked() -{ +void DefaultModule::onReplaceClicked() { Module *newModule = getCore()->getModulesManager()->invokeModulesPickerService(); - if(newModule != nullptr){ + if(newModule != nullptr) { emit getModuleEventsHandler()->replaceMeWith(this, newModule); delete this; } } -void DefaultModule::addCustomActionsToMenu() -{ +void DefaultModule::addCustomActionsToMenu() { } -SkywardHubCoreProxy &DefaultModule::getCore() -{ +SkywardHubCoreProxy &DefaultModule::getCore() { return proxyCore; } diff --git a/Modules/DefaultModule/defaultmodule.h b/Modules/DefaultModule/defaultmodule.h index 339fb2db8a9281cdbba871d73e28de407823ac70..fd2ce87c7908fa76974e9aa44dd3b1af96b1b658 100644 --- a/Modules/DefaultModule/defaultmodule.h +++ b/Modules/DefaultModule/defaultmodule.h @@ -7,9 +7,8 @@ #include "Core/module.h" #include "Modules/moduleinfo.h" -class DefaultModule : public QWidget, public Module -{ -public: +class DefaultModule : public QWidget, public Module { + public: DefaultModule(QWidget *parent = nullptr); ~DefaultModule(); @@ -22,7 +21,7 @@ public: QString getName(const ModuleId id); -protected: + protected: void closeEvent(QCloseEvent *event) override; void addDefaultActionsToMenu(); @@ -32,7 +31,7 @@ protected: void showMenuActionsInSeparatedMenu(const QString &menuName); virtual void onReplaceClicked(); -private: + private: SkywardHubCoreProxy proxyCore; QList<QAction*> menuActions; diff --git a/Modules/Empty/emptymodule.cpp b/Modules/Empty/emptymodule.cpp index db0a1698ed171c2752fac754cf648d96fa31e798..d309d14554d9518e973c0874887f72192ba34ce6 100644 --- a/Modules/Empty/emptymodule.cpp +++ b/Modules/Empty/emptymodule.cpp @@ -7,27 +7,23 @@ #include "Modules/Utility/contextmenuseparator.h" #include "Core/modulesmanager.h" -EmptyModule::EmptyModule() : DefaultModule(), ui(new Ui::EmptyModule) -{ +EmptyModule::EmptyModule() : DefaultModule(), ui(new Ui::EmptyModule) { ui->setupUi(this); defaultContextMenuSetup(); connectUiSlots(); } -EmptyModule::~EmptyModule() -{ +EmptyModule::~EmptyModule() { delete ui; //qDebug() << "EmptyPanel >> Deleted"; } -void EmptyModule::connectUiSlots() -{ - connect(ui->selectPanel_button,&QPushButton::clicked,this,&EmptyModule::onSelectPanelClick); +void EmptyModule::connectUiSlots() { + connect(ui->selectPanel_button, &QPushButton::clicked, this, &EmptyModule::onSelectPanelClick); } -void EmptyModule::onSelectPanelClick() -{ +void EmptyModule::onSelectPanelClick() { //onModuleSelected(getManager()->InvokeModulesPickerService()); onReplaceClicked(); } @@ -37,18 +33,15 @@ void EmptyModule::onSelectPanelClick() // emit getModuleEventsHandler()->replaceMeWith(modulePointer); //} -QWidget *EmptyModule::toWidget() -{ +QWidget *EmptyModule::toWidget() { return this; } -XmlObject EmptyModule::toXmlObject() -{ +XmlObject EmptyModule::toXmlObject() { return XmlObject(getName(ModuleId::EMPTY)); } -void EmptyModule::fromXmlObject(const XmlObject &xmlObject) -{ +void EmptyModule::fromXmlObject(const XmlObject &xmlObject) { Q_UNUSED(xmlObject); } diff --git a/Modules/Empty/emptymodule.h b/Modules/Empty/emptymodule.h index b15a938e2765e33e835628642b8401d8e6c48d21..3e34237f0b9b94445d6b7a94382c43aea82ffdcf 100644 --- a/Modules/Empty/emptymodule.h +++ b/Modules/Empty/emptymodule.h @@ -11,11 +11,10 @@ namespace Ui { class EmptyModule; } -class EmptyModule : public DefaultModule -{ +class EmptyModule : public DefaultModule { Q_OBJECT -public: + public: explicit EmptyModule(); ~EmptyModule() override; @@ -25,13 +24,13 @@ public: XmlObject toXmlObject() override; void fromXmlObject(const XmlObject &xmlObject) override; -protected: + protected: void connectUiSlots(); -protected slots: + protected slots: void onSelectPanelClick(); -private: + private: Ui::EmptyModule *ui; }; diff --git a/Modules/FileStream/filestreammodule.cpp b/Modules/FileStream/filestreammodule.cpp index 557bb1909d72bb7e6bb8ea17c10bb953b002725c..2be2035ee266147429025e7a9473b4e66b1f4038 100644 --- a/Modules/FileStream/filestreammodule.cpp +++ b/Modules/FileStream/filestreammodule.cpp @@ -9,8 +9,7 @@ #include <QDesktopServices> #include <QUrl> -FileStreamModule::FileStreamModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::FileStreamModule) -{ +FileStreamModule::FileStreamModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::FileStreamModule) { ui->setupUi(this); defaultContextMenuSetup(); connectUI(); @@ -18,27 +17,24 @@ FileStreamModule::FileStreamModule(QWidget *parent) : DefaultModule(parent), ui( ui->filePath_lineEdit->setText(SkywardHubStrings::defaultStreamFile); } -FileStreamModule::~FileStreamModule() -{ +FileStreamModule::~FileStreamModule() { if(file.isOpen()) file.close(); deleteAllTopicViews(); delete ui; } -QWidget *FileStreamModule::toWidget() -{ +QWidget *FileStreamModule::toWidget() { return this; } -XmlObject FileStreamModule::toXmlObject() -{ +XmlObject FileStreamModule::toXmlObject() { XmlObject obj(getName(ModuleId::FILESTREAM)); if(getFilePath() != "") obj.addAttribute("FilePath", getFilePath()); - for(int i = 0; i < topicViewsList.count();i++){ + for(int i = 0; i < topicViewsList.count(); i++) { XmlObject subscription("Subscription"); subscription.setTextValue(topicViewsList[i]->text().trimmed()); obj.addChild(subscription); @@ -46,52 +42,46 @@ XmlObject FileStreamModule::toXmlObject() return obj; } -void FileStreamModule::fromXmlObject(const XmlObject &xmlObject) -{ - if(xmlObject.getObjectName() == getName(ModuleId::FILESTREAM)){ +void FileStreamModule::fromXmlObject(const XmlObject &xmlObject) { + if(xmlObject.getObjectName() == getName(ModuleId::FILESTREAM)) { - if(xmlObject.hasAttribute("FilePath")){ + if(xmlObject.hasAttribute("FilePath")) { ui->filePath_lineEdit->setText(xmlObject.getAttribute("FilePath")); } - for(int i = 0; i < xmlObject.childCount(); i++){ + for(int i = 0; i < xmlObject.childCount(); i++) { XmlObject child = xmlObject.childAt(i); - if(child.getObjectName() == "Subscription" && child.getTextValue() != ""){ + if(child.getObjectName() == "Subscription" && child.getTextValue() != "") { addTopic(child.getTextValue()); } } } } -void FileStreamModule::connectUI() -{ +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 -{ +QString FileStreamModule::getFilePath() const { return ui->filePath_lineEdit->text().trimmed(); } -QString FileStreamModule::getTopicName() const -{ +QString FileStreamModule::getTopicName() const { return ui->topicName_lineEdit->text().trimmed(); } -void FileStreamModule::resetTopicName() -{ +void FileStreamModule::resetTopicName() { ui->topicName_lineEdit->clear(); } -void FileStreamModule::onMsgReceived(const ModuleMessage &msg) -{ -// if(file.isOpen() ){ -// QTextStream out(&file); -// out << msg.payload() << Qt::endl; -// } +void FileStreamModule::onMsgReceived(const ModuleMessage &msg) { + // if(file.isOpen() ){ + // QTextStream out(&file); + // out << msg.payload() << Qt::endl; + // } QFile file(getFilePath()); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) @@ -101,19 +91,17 @@ void FileStreamModule::onMsgReceived(const ModuleMessage &msg) out << msg.payload() << Qt::endl; } -void FileStreamModule::onAddTopicClicked() -{ +void FileStreamModule::onAddTopicClicked() { QString topicName = getTopicName(); resetTopicName(); - if(topicName != ""){ + if(topicName != "") { addTopic(topicName); } } -void FileStreamModule::onStartClicked() -{ +void FileStreamModule::onStartClicked() { file.setFileName(getFilePath()); - if(!file.open(QIODevice::WriteOnly | QIODevice::Text)){ // Append QIODevice::ReadWrite + if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) { // Append QIODevice::ReadWrite QString msg = "FileStream: Error occurred while opening file " + getFilePath(); QMessageBox msgBox; msgBox.setText(msg); @@ -123,8 +111,8 @@ void FileStreamModule::onStartClicked() file.resize(0); disableOnStartElement(); - for(int i = 0; i < topicViewsList.count() ; i++ ){ - getCore()->getModuleMessagesBroker()->subscribe(topicViewsList[i]->text().trimmed(), this, [this](const ModuleMessage &msg){ + for(int i = 0; i < topicViewsList.count() ; i++ ) { + getCore()->getModuleMessagesBroker()->subscribe(topicViewsList[i]->text().trimmed(), this, [this](const ModuleMessage & msg) { onMsgReceived(msg); }); topicViewsList[i]->setEnabled(false); @@ -132,50 +120,44 @@ void FileStreamModule::onStartClicked() } -void FileStreamModule::onStopClicked() -{ +void FileStreamModule::onStopClicked() { if(file.isOpen()) file.close(); enableElementOnStop(); - for(int i = 0; i < topicViewsList.count(); i++ ){ + for(int i = 0; i < topicViewsList.count(); i++ ) { getCore()->getModuleMessagesBroker()->unsubscribe(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() == ""){ +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() -{ +void FileStreamModule::disableOnStartElement() { ui->start_button->setEnabled(false); ui->addTopic_button->setEnabled(false); ui->filePath_lineEdit->setEnabled(false); } -void FileStreamModule::enableElementOnStop() -{ +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() -{ +void FileStreamModule::onShowFileClick() { QDir dir(SkywardHubStrings::defaultLogsFolder); - if (dir.exists()){ + if (dir.exists()) { QDesktopServices::openUrl( QUrl::fromLocalFile(getFilePath()) ); - } - else{ + } else { QString msg = "The file does not exist." + getFilePath(); QMessageBox msgBox; msgBox.setText(msg); @@ -183,16 +165,14 @@ void FileStreamModule::onShowFileClick() } } -void FileStreamModule::addTopic(const QString &topic) -{ +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 *FileStreamModule::createTopicView(const QString &topic) const { QLineEdit* topicView = new QLineEdit(); topicView->setText(topic); @@ -200,9 +180,8 @@ QLineEdit *FileStreamModule::createTopicView(const QString &topic) const return topicView; } -void FileStreamModule::deleteAllTopicViews() -{ - for(int i = 0; i < topicViewsList.count(); i++ ){ +void FileStreamModule::deleteAllTopicViews() { + for(int i = 0; i < topicViewsList.count(); i++ ) { getCore()->getModuleMessagesBroker()->unsubscribe(topicViewsList[i]->text().trimmed(), this); ui->topics_layout->removeWidget(topicViewsList[i]); topicViewsList[i]->deleteLater(); diff --git a/Modules/FileStream/filestreammodule.h b/Modules/FileStream/filestreammodule.h index 74bb8cd0d7de82dcca0232d8a4e05db9294785b6..cc77e21403f33f5371612908c0c9b03116855a8a 100644 --- a/Modules/FileStream/filestreammodule.h +++ b/Modules/FileStream/filestreammodule.h @@ -12,11 +12,10 @@ namespace Ui { class FileStreamModule; } -class FileStreamModule : public DefaultModule -{ +class FileStreamModule : public DefaultModule { Q_OBJECT -public: + public: explicit FileStreamModule(QWidget *parent = nullptr); ~FileStreamModule(); @@ -26,7 +25,7 @@ public: void fromXmlObject(const XmlObject &xmlObject) override; -protected: + protected: void connectUI(); QString getFilePath() const; QString getTopicName() const; @@ -47,7 +46,7 @@ protected: void deleteAllTopicViews(); -private: + private: Ui::FileStreamModule *ui; QList<QLineEdit*> topicViewsList; diff --git a/Modules/Graph/graphmodule.cpp b/Modules/Graph/graphmodule.cpp index 317b27f4ba598417c762d73a9c2a2161d79a0c1a..65e61e1a642e6eb638e3d6698280864fce4f7a76 100644 --- a/Modules/Graph/graphmodule.cpp +++ b/Modules/Graph/graphmodule.cpp @@ -7,8 +7,7 @@ #include <QDebug> #include <QTimer> -GraphModule::GraphModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::GraphModule) -{ +GraphModule::GraphModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::GraphModule) { ui->setupUi(this); defaultContextMenuSetup(); buildCentralGraphView(); @@ -18,16 +17,14 @@ GraphModule::GraphModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::Gr updaterTimer.start(updatePeriod); } -GraphModule::~GraphModule() -{ +GraphModule::~GraphModule() { // QCPGraph are destroyed automatically subscriptions.clear(); delete ui; } -void GraphModule::buildCentralGraphView() -{ +void GraphModule::buildCentralGraphView() { setTheme(); graphCentralView.yAxis2->setVisible(true); @@ -42,9 +39,9 @@ void GraphModule::buildCentralGraphView() QSharedPointer<QCPAxisTickerTime> dateTimeTicker(new QCPAxisTickerTime); graphCentralView.xAxis->setTicker(dateTimeTicker); //QDateTime rangeLowerBound = QDateTime::currentDateTime().addDays(-2); -// double now = QDateTime::currentDateTime().toTime_t(); -// QDateTime rangeUpperBound = QDateTime::currentDateTime().addDays(+2); -// graphCentralView.xAxis->setRange(now, QCPAxisTickerDateTime::(rangeUpperBound)); + // double now = QDateTime::currentDateTime().toTime_t(); + // QDateTime rangeUpperBound = QDateTime::currentDateTime().addDays(+2); + // graphCentralView.xAxis->setRange(now, QCPAxisTickerDateTime::(rangeUpperBound)); dateTimeTicker->setTimeFormat(dateFormat); graphCentralView.legend->setVisible(true); @@ -63,46 +60,43 @@ void GraphModule::buildCentralGraphView() //connect(customPlot,SIGNAL(selectionChangedByUser()),this,SLOT(selectedGraphChange())); } -void GraphModule::setTheme() -{ -// QColor accentColor; -// QColor themeColor; -// QColor themeBackgroundColor; -// QColor traceColor; - -// accentColor = QColor(78, 156, 207); -// traceColor = accentColor; -// themeColor = QColor(Qt::gray); -// themeBackgroundColor = QColor(50, 50, 50); - -// foreach(QCPAxisRect* rect, graphCentralView.axisRects()){ -// foreach(QCPAxis* axis, rect->axes()){ -// axis->setLabelColor(themeColor); -// axis->setBasePen(QPen(themeColor, 1)); -// axis->setTickPen(QPen(themeColor, 1)); -// axis->setSubTickPen(QPen(themeColor, 1)); -// axis->setTickLabelColor(themeColor); -// axis->grid()->setPen(QPen(themeColor, 0.5, Qt::DotLine)); -// axis->grid()->setSubGridVisible(false); - -// axis->setSelectedTickLabelColor(accentColor); -// axis->setSelectedLabelColor(accentColor); -// axis->setSelectedBasePen(QPen(accentColor, 1)); -// axis->setSelectedSubTickPen(QPen(accentColor, 1)); -// axis->setSelectedTickPen(QPen(accentColor, 1)); -// } -// } -// graphCentralView.setBackground(QBrush(themeBackgroundColor)); +void GraphModule::setTheme() { + // QColor accentColor; + // QColor themeColor; + // QColor themeBackgroundColor; + // QColor traceColor; + + // accentColor = QColor(78, 156, 207); + // traceColor = accentColor; + // themeColor = QColor(Qt::gray); + // themeBackgroundColor = QColor(50, 50, 50); + + // foreach(QCPAxisRect* rect, graphCentralView.axisRects()){ + // foreach(QCPAxis* axis, rect->axes()){ + // axis->setLabelColor(themeColor); + // axis->setBasePen(QPen(themeColor, 1)); + // axis->setTickPen(QPen(themeColor, 1)); + // axis->setSubTickPen(QPen(themeColor, 1)); + // axis->setTickLabelColor(themeColor); + // axis->grid()->setPen(QPen(themeColor, 0.5, Qt::DotLine)); + // axis->grid()->setSubGridVisible(false); + + // axis->setSelectedTickLabelColor(accentColor); + // axis->setSelectedLabelColor(accentColor); + // axis->setSelectedBasePen(QPen(accentColor, 1)); + // axis->setSelectedSubTickPen(QPen(accentColor, 1)); + // axis->setSelectedTickPen(QPen(accentColor, 1)); + // } + // } + // graphCentralView.setBackground(QBrush(themeBackgroundColor)); // replotAll(); } -void GraphModule::onUpdateTimerTick() -{ +void GraphModule::onUpdateTimerTick() { replotAll(); } -QCPGraph *GraphModule::instantiateNewGraph() -{ +QCPGraph *GraphModule::instantiateNewGraph() { QCPGraph *graph = graphCentralView.addGraph(); int r = rand() % 255; int g = rand() % 255; @@ -114,31 +108,28 @@ QCPGraph *GraphModule::instantiateNewGraph() } -QWidget *GraphModule::toWidget() -{ +QWidget *GraphModule::toWidget() { return this; } -XmlObject GraphModule::toXmlObject() -{ +XmlObject GraphModule::toXmlObject() { XmlObject obj(getName(ModuleId::GRAPH)); QList<QString> subscriptionsList = subscriptions.keys(); - for(int i = 0; i < subscriptionsList.count();i++){ + for(int i = 0; i < subscriptionsList.count(); i++) { XmlObject subscription("Subscription"); - subscription.addAttribute("Value",subscriptionsList[i]); + subscription.addAttribute("Value", subscriptionsList[i]); obj.addChild(subscription); } return obj; } -void GraphModule::fromXmlObject(const XmlObject &xmlObject) -{ - if(xmlObject.getObjectName() == getName(ModuleId::GRAPH)){ - for(int i = 0; i < xmlObject.childCount(); i++){ +void GraphModule::fromXmlObject(const XmlObject &xmlObject) { + if(xmlObject.getObjectName() == getName(ModuleId::GRAPH)) { + for(int i = 0; i < xmlObject.childCount(); i++) { XmlObject child = xmlObject.childAt(i); - if(child.getObjectName() == "Subscription"){ + if(child.getObjectName() == "Subscription") { QString subscription = child.getAttribute("Value"); - if(subscription != ""){ + if(subscription != "") { onSubscriptionAdded(subscription); } } @@ -146,8 +137,7 @@ void GraphModule::fromXmlObject(const XmlObject &xmlObject) } } -void GraphModule::onSubscribeClicked() -{ +void GraphModule::onSubscribeClicked() { QList<QString> subs = subscriptions.keys(); SubscriptionsPanel *sPanel = new SubscriptionsPanel(&subs); sPanel->setWindowTitle("Graph Subscriptions"); @@ -157,12 +147,11 @@ void GraphModule::onSubscribeClicked() } -void GraphModule::onSubscriptionAdded(const QString &subscription) -{ +void GraphModule::onSubscriptionAdded(const QString &subscription) { QCPGraph *graph = instantiateNewGraph(); graph->setName(subscription); subscriptions[subscription] = graph; - getCore()->getModuleMessagesBroker()->subscribe(subscription,this,[this](const ModuleMessage &msg){ + getCore()->getModuleMessagesBroker()->subscribe(subscription, this, [this](const ModuleMessage & msg) { onMsgReceived(msg); }); @@ -171,8 +160,7 @@ void GraphModule::onSubscriptionAdded(const QString &subscription) graphCentralView.replot(); } -void GraphModule::onSubscriptionRemoved(const QString &subscription) -{ +void GraphModule::onSubscriptionRemoved(const QString &subscription) { QCPGraph *graph = subscriptions[subscription]; graphCentralView.removeGraph(graph); subscriptions.remove(subscription); @@ -182,55 +170,50 @@ void GraphModule::onSubscriptionRemoved(const QString &subscription) graphCentralView.replot(); } -void GraphModule::onMsgReceived(const ModuleMessage &msg) -{ - if(!subscriptions.contains(msg.originalTopic())){ +void GraphModule::onMsgReceived(const ModuleMessage &msg) { + if(!subscriptions.contains(msg.originalTopic())) { onSubscriptionAdded(msg.originalTopic()); } if(stopPlot) return; - if(subscriptions.contains(msg.originalTopic())){ + if(subscriptions.contains(msg.originalTopic())) { QCPGraph *graph = subscriptions[msg.originalTopic()]; double x = 0, y = 0; x = msg.timestamp().msecsSinceStartOfDay(); bool ok; y = msg.payload().toDouble(&ok); - if(ok && graph != nullptr){ - graph->addData(x,y); + if(ok && graph != nullptr) { + graph->addData(x, y); //Da rimuovere per performance //replotAll(); } } } -void GraphModule::setFollowedGraphIndex(bool checked) -{ - if(checked){ +void GraphModule::setFollowedGraphIndex(bool checked) { + if(checked) { QCPGraph* selectedGraph = getSelectedGraph(); - if(selectedGraph){ + if(selectedGraph) { - for(int i = 0; i < graphCentralView.graphCount(); i++){ + for(int i = 0; i < graphCentralView.graphCount(); i++) { if(selectedGraph == graphCentralView.graph(i)) followedGraphIndex = i; } - } - else if(graphCentralView.graphCount() > 0){ + } else if(graphCentralView.graphCount() > 0) { // If no graph is selected, select the first graph followedGraphIndex = 0; } - } - else{ + } else { followedGraphIndex = -1; } } -void GraphModule::onClearClicked() -{ - QMapIterator<QString,QCPGraph*> i(subscriptions); +void GraphModule::onClearClicked() { + QMapIterator<QString, QCPGraph*> i(subscriptions); while (i.hasNext()) { i.next(); i.value()->data()->clear(); @@ -239,34 +222,31 @@ void GraphModule::onClearClicked() replotAll(); } -void GraphModule::onStopClicked(bool checked) -{ +void GraphModule::onStopClicked(bool checked) { stopPlot = checked; if(stopPlot) updaterTimer.stop(); - else{ + else { updaterTimer.start(updatePeriod); } } -QCPGraph *GraphModule::getSelectedGraph() -{ +QCPGraph *GraphModule::getSelectedGraph() { QList<QCPGraph*> selection; //if(graph) selection = graphCentralView.selectedGraphs(); - if(selection.size()>0){ + if(selection.size() > 0) { return selection.first(); } return nullptr; } -void GraphModule::centerView(const QCPGraph * graph) -{ - if(!graph->data()->isEmpty()){ - double lastKey = (graph->data()->constEnd()-1)->key; - double lastValue = (graph->data()->constEnd()-1)->value; +void GraphModule::centerView(const QCPGraph * graph) { + if(!graph->data()->isEmpty()) { + double lastKey = (graph->data()->constEnd() - 1)->key; + double lastValue = (graph->data()->constEnd() - 1)->value; double size_x = graphCentralView.xAxis->range().size(); double size_y = graphCentralView.yAxis->range().size(); graphCentralView.xAxis->setRange(lastKey, size_x, Qt::AlignmentFlag::AlignCenter); @@ -274,33 +254,31 @@ void GraphModule::centerView(const QCPGraph * graph) } } -void GraphModule::replotAll() -{ - if(followedGraphIndex < graphCentralView.graphCount() && followedGraphIndex >= 0){ +void GraphModule::replotAll() { + if(followedGraphIndex < graphCentralView.graphCount() && followedGraphIndex >= 0) { centerView(graphCentralView.graph(followedGraphIndex)); } graphCentralView.replot(); } -void GraphModule::addCustomActionsToMenu() -{ +void GraphModule::addCustomActionsToMenu() { QAction* subscribe = new QAction("Subscribe"); - connect(subscribe, &QAction::triggered,this, &GraphModule::onSubscribeClicked); + connect(subscribe, &QAction::triggered, this, &GraphModule::onSubscribeClicked); QAction* clear = new QAction("Clear"); - connect(clear, &QAction::triggered,this, &GraphModule::onClearClicked); + 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); + connect(stop, &QAction::triggered, this, &GraphModule::onStopClicked); QAction* follow = new QAction("Follow"); follow->setCheckable(true); - if(followedGraphIndex >= 0){ + if(followedGraphIndex >= 0) { follow->setChecked(true); } - connect(follow,&QAction::triggered,this,&GraphModule::setFollowedGraphIndex); + connect(follow, &QAction::triggered, this, &GraphModule::setFollowedGraphIndex); addActionToMenu(follow); addActionToMenu(subscribe); diff --git a/Modules/Graph/graphmodule.h b/Modules/Graph/graphmodule.h index b2bf068794a707b198bbb0a3c7012f82daf8b66d..f070318b868e0a9c7522dd982d7059bc0593e8e0 100644 --- a/Modules/Graph/graphmodule.h +++ b/Modules/Graph/graphmodule.h @@ -13,11 +13,10 @@ namespace Ui { class GraphModule; } -class GraphModule : public DefaultModule -{ +class GraphModule : public DefaultModule { Q_OBJECT -public: + public: explicit GraphModule(QWidget *parent = nullptr); ~GraphModule(); @@ -28,7 +27,7 @@ public: void centerView(const QCPGraph * graph); void replotAll(); -public slots: + public slots: void onSubscribeClicked(); void onSubscriptionAdded(const QString &subscription); void onSubscriptionRemoved(const QString &subscription); @@ -37,7 +36,7 @@ public slots: void onClearClicked(); void onStopClicked(bool checked); -protected: + protected: void buildCentralGraphView(); QCPGraph* instantiateNewGraph(); void addCustomActionsToMenu() override; @@ -45,10 +44,10 @@ protected: void setTheme(); void onUpdateTimerTick(); -private: + private: Ui::GraphModule *ui; QCustomPlot graphCentralView; - QMap<QString,QCPGraph*> subscriptions; + QMap<QString, QCPGraph*> subscriptions; int followedGraphIndex = -1; QString dateFormat = "%h:%m:%s (%z)"; //"HH:mm:ss\n(zzz)"; diff --git a/Modules/ImageViewer/customgraphicsscene.cpp b/Modules/ImageViewer/customgraphicsscene.cpp index 3520d1f745746489e689e1b42621fd8436b92063..e8b3e47ab955d01559b426b26e7aa1d587e2c6bd 100644 --- a/Modules/ImageViewer/customgraphicsscene.cpp +++ b/Modules/ImageViewer/customgraphicsscene.cpp @@ -9,67 +9,58 @@ #include <QApplication> #include <QLabel> -CustomGraphicsScene::CustomGraphicsScene() -{ +CustomGraphicsScene::CustomGraphicsScene() { } -CustomGraphicsScene::~CustomGraphicsScene() -{ - for(int key : items.keys()){ +CustomGraphicsScene::~CustomGraphicsScene() { + for(int key : items.keys()) { removeImageViewItem(key); } } -void CustomGraphicsScene::addImageViewItem(const ImageViewerItem *item) -{ - if(items.contains(item->getId())){ +void CustomGraphicsScene::addImageViewItem(const ImageViewerItem *item) { + if(items.contains(item->getId())) { updateImageViewItem(item); - } - else{ + } else { QGraphicsPixmapItem* itemView = createGraphicsView(item); addGraphicsItem(item->getId(), itemView); } } -void CustomGraphicsScene::updateImageViewItem(const ImageViewerItem *item) -{ - if(items.contains(item->getId())){ +void CustomGraphicsScene::updateImageViewItem(const ImageViewerItem *item) { + if(items.contains(item->getId())) { QGraphicsPixmapItem* itemView = items[item->getId()]; - if(itemView != nullptr){ + if(itemView != nullptr) { setupGraphicsItem(itemView, item); } } } -void CustomGraphicsScene::removeImageViewItem(int id) -{ - if(items.contains(id)){ +void CustomGraphicsScene::removeImageViewItem(int id) { + if(items.contains(id)) { QGraphicsItem *item = items[id]; items.remove(id); delete item; } } -void CustomGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ +void CustomGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { Q_UNUSED(event); isDragActive = false; emit dragStopped(); } -void CustomGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - if(event->button() == Qt::LeftButton){ +void CustomGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { + if(event->button() == Qt::LeftButton) { dragStartPosition = event->scenePos(); isDragActive = true; dragEmitted = false; } } -void CustomGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - if(event->buttons() & Qt::LeftButton && isDragActive && !dragEmitted){ +void CustomGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + if(event->buttons() & Qt::LeftButton && isDragActive && !dragEmitted) { emit dragStarted(dragStartPosition); dragEmitted = true; } @@ -78,28 +69,24 @@ void CustomGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } -void CustomGraphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) -{ +void CustomGraphicsScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { emit doubleCLick(event->scenePos()); } -QGraphicsPixmapItem *CustomGraphicsScene::createGraphicsView(const ImageViewerItem *item) const -{ +QGraphicsPixmapItem *CustomGraphicsScene::createGraphicsView(const ImageViewerItem *item) const { QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(); setupGraphicsItem(pixmapItem, item); return pixmapItem; } -void CustomGraphicsScene::setupGraphicsItem(QGraphicsPixmapItem *viewItem, const ImageViewerItem *item) const -{ +void CustomGraphicsScene::setupGraphicsItem(QGraphicsPixmapItem *viewItem, const ImageViewerItem *item) const { QPixmap pixmap; pixmap.loadFromData(item->toXmlObject().toXml().toUtf8()); viewItem->setPixmap(pixmap); viewItem->setPos(item->getTopLeftCornerPosition()); } -void CustomGraphicsScene::addGraphicsItem(const int &id, QGraphicsPixmapItem *item) -{ +void CustomGraphicsScene::addGraphicsItem(const int &id, QGraphicsPixmapItem *item) { items[id] = item; addItem(item); } diff --git a/Modules/ImageViewer/customgraphicsscene.h b/Modules/ImageViewer/customgraphicsscene.h index ce64a71988c509c96ff3e46da76a547586150489..04dea92ac6401be125d66efcf09314907b9257fd 100644 --- a/Modules/ImageViewer/customgraphicsscene.h +++ b/Modules/ImageViewer/customgraphicsscene.h @@ -7,11 +7,10 @@ #include "imagevieweritem.h" -class CustomGraphicsScene : public QGraphicsScene -{ +class CustomGraphicsScene : public QGraphicsScene { Q_OBJECT -public: + public: CustomGraphicsScene(); ~CustomGraphicsScene(); @@ -20,14 +19,14 @@ public: void removeImageViewItem(int id); -signals: + signals: void leftMouseReleased(const QPointF &point); void mouseMoved(const QPointF &point); void dragStarted(const QPointF &initialPosition); void dragStopped(); void doubleCLick(const QPointF &point); -protected: + protected: void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; void mousePressEvent(QGraphicsSceneMouseEvent *event) override; void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override; @@ -37,9 +36,9 @@ protected: void setupGraphicsItem(QGraphicsPixmapItem* viewItem, const ImageViewerItem *item) const; void addGraphicsItem(const int &id, QGraphicsPixmapItem *item); -// void updateGraphicsItem(const ImageViewerItem &item, QGraphicsItem *viewItem); + // void updateGraphicsItem(const ImageViewerItem &item, QGraphicsItem *viewItem); -private: + private: QMap<int, QGraphicsPixmapItem*> items; QPointF dragStartPosition; bool isDragActive = false; diff --git a/Modules/ImageViewer/imagevieweritem.cpp b/Modules/ImageViewer/imagevieweritem.cpp index 1c19a7fa8f8a129096b1972832720791f98c74aa..f483138a20fecf7c34461bb85af82e9ac5f85164 100644 --- a/Modules/ImageViewer/imagevieweritem.cpp +++ b/Modules/ImageViewer/imagevieweritem.cpp @@ -3,24 +3,20 @@ #include <QSize> -ImageViewerItem::ImageViewerItem() -{ +ImageViewerItem::ImageViewerItem() { initialize(); } -ImageViewerItem::ImageViewerItem(const QPointF ¢er, const QSize &value) : ImageViewerItem() -{ +ImageViewerItem::ImageViewerItem(const QPointF ¢er, const QSize &value) : ImageViewerItem() { setSize(value); setCenter(center); } -ImageViewerItem::ImageViewerItem(const ImageViewerItem &other) : ImageViewerItem() -{ +ImageViewerItem::ImageViewerItem(const ImageViewerItem &other) : ImageViewerItem() { copy(other); } -QString ImageViewerItem::getText() const -{ +QString ImageViewerItem::getText() const { XmlObject text = xml.searchChild("text"); if(text.isEmpty()) return defaultText; @@ -28,27 +24,23 @@ QString ImageViewerItem::getText() const } -XmlObject *ImageViewerItem::findOrAddXmlObject(const QString &xmlChildName) -{ +XmlObject *ImageViewerItem::findOrAddXmlObject(const QString &xmlChildName) { QList<XmlObject*> childs = xml.deepSearchObjects(xmlChildName); - if(childs.isEmpty()){ + if(childs.isEmpty()) { XmlObject c(xmlChildName); int childIndex = xml.addChild(c); return xml.getChild(childIndex); - } - else{ + } else { return childs[0]; } } -void ImageViewerItem::setText(const QString &value) -{ +void ImageViewerItem::setText(const QString &value) { XmlObject *text = findOrAddXmlObject("text"); text->setTextValue(value); } -void ImageViewerItem::setCenter(const QPointF ¢er) -{ +void ImageViewerItem::setCenter(const QPointF ¢er) { float topX = 0; float topY = 0; @@ -58,44 +50,39 @@ void ImageViewerItem::setCenter(const QPointF ¢er) setTopLeftCornerPosition(QPointF(topX, topY)); } -int ImageViewerItem::getId() const -{ +int ImageViewerItem::getId() const { return id; } -void ImageViewerItem::setId(int value) -{ +void ImageViewerItem::setId(int value) { id = value; } -XmlObject ImageViewerItem::toXmlObject() const -{ +XmlObject ImageViewerItem::toXmlObject() const { XmlObject xmlObj = xml; xmlObj.addAttribute("topX", getTopLeftCornerPosition().x()); xmlObj.addAttribute("topY", getTopLeftCornerPosition().y()); return xmlObj; } -void ImageViewerItem::operator =(const ImageViewerItem &other) -{ +void ImageViewerItem::operator =(const ImageViewerItem &other) { copy(other); } -bool ImageViewerItem::onMouseMoved(const QPointF &point) -{ +bool ImageViewerItem::onMouseMoved(const QPointF &point) { bool needUpdate = false; -// if(isPointInsideMyArea(point)){ -// setClicked(true); -// needUpdate = true; -// } -// else{ -// if(getClicked()){ -// setClicked(false); -// needUpdate = true; -// } -// } - - if(isDragActive){ + // if(isPointInsideMyArea(point)){ + // setClicked(true); + // needUpdate = true; + // } + // else{ + // if(getClicked()){ + // setClicked(false); + // needUpdate = true; + // } + // } + + if(isDragActive) { QPointF newTopPosition(point.x() - dragOffset.x(), point.y() - dragOffset.y()); topLeftCornerPosition = newTopPosition; needUpdate = true; @@ -104,8 +91,7 @@ bool ImageViewerItem::onMouseMoved(const QPointF &point) return needUpdate; } -bool ImageViewerItem::isPointInsideMyArea(const QPointF &point) -{ +bool ImageViewerItem::isPointInsideMyArea(const QPointF &point) { float topX = getTopLeftCornerPosition().x(); float topY = getTopLeftCornerPosition().y(); @@ -113,57 +99,49 @@ bool ImageViewerItem::isPointInsideMyArea(const QPointF &point) float deltaY = point.y() - topY; if(deltaX >= 0 && deltaX <= getSize().width() && - deltaY >= 0 && deltaY <= getSize().height()){ + deltaY >= 0 && deltaY <= getSize().height()) { return true; } return false; } -void ImageViewerItem::startDrag(const QPointF &initialPosition) -{ +void ImageViewerItem::startDrag(const QPointF &initialPosition) { float offsetX = initialPosition.x() - getTopLeftCornerPosition().x(); float offsetY = initialPosition.y() - getTopLeftCornerPosition().y(); dragOffset = QPointF(offsetX, offsetY); isDragActive = true; } -void ImageViewerItem::stopDrag() -{ +void ImageViewerItem::stopDrag() { isDragActive = false; } -void ImageViewerItem::onModuleMessageReceived(const ModuleMessage &msg) -{ +void ImageViewerItem::onModuleMessageReceived(const ModuleMessage &msg) { setText(msg.payload()); } -QString ImageViewerItem::getTopic() const -{ +QString ImageViewerItem::getTopic() const { XmlObject topic = xml.searchChild("topic"); return topic.getTextValue(); } -void ImageViewerItem::copy(const ImageViewerItem &other) -{ +void ImageViewerItem::copy(const ImageViewerItem &other) { setId(other.getId()); setText(other.getText()); setTopLeftCornerPosition(other.getTopLeftCornerPosition()); setXml(other.toXmlObject()); } -void ImageViewerItem::setTopLeftCornerPosition(const QPointF &value) -{ +void ImageViewerItem::setTopLeftCornerPosition(const QPointF &value) { topLeftCornerPosition = value; } -void ImageViewerItem::setTopic(const QString &topic) -{ +void ImageViewerItem::setTopic(const QString &topic) { XmlObject *xmlTopic = findOrAddXmlObject("topic"); xmlTopic->setTextValue(topic); } -void ImageViewerItem::initialize() -{ +void ImageViewerItem::initialize() { xml.setObjectName("svg"); QSize s = defaultSize; xml.addAttribute("height", QString::number(s.height())); @@ -171,14 +149,14 @@ void ImageViewerItem::initialize() XmlObject rect("rect"); rect.addAttribute("height", QString::number(s.height())); - rect.addAttribute("width", QString::number(s.width())); + rect.addAttribute("width", QString::number(s.width())); rect.addAttribute("fill", "none"); rect.addAttribute("stroke", "#000000"); rect.addAttribute("stroke-width", "2"); XmlObject text("text"); - text.addAttribute("x",5); - text.addAttribute("y",20); + text.addAttribute("x", 5); + text.addAttribute("y", 20); text.addAttribute("fill", "#000000"); text.addAttribute("font-size", "20"); text.setTextValue(defaultText); @@ -187,25 +165,24 @@ void ImageViewerItem::initialize() xml.addChild(rect); } -void ImageViewerItem::setXml(const XmlObject &value) -{ +void ImageViewerItem::setXml(const XmlObject &value) { xml = value; int height, width; - if(xml.getIntAttribute("height", height) && xml.getIntAttribute("width", width)){ + if(xml.getIntAttribute("height", height) && xml.getIntAttribute("width", width)) { setSize(width, height); } QList<XmlObject*> childs = xml.deepSearchObjects("text"); - if(!childs.isEmpty()){ + if(!childs.isEmpty()) { XmlObject *text = childs[0]; setText(text->getTextValue()); } int topx, topy; - if(value.getIntAttribute("topX", topx) && value.getIntAttribute("topY", topy)){ + if(value.getIntAttribute("topX", topx) && value.getIntAttribute("topY", topy)) { setTopLeftCornerPosition(QPointF(topx, topy)); } } @@ -227,34 +204,30 @@ void ImageViewerItem::setXml(const XmlObject &value) // clicked = value; //} -QSize ImageViewerItem::getSize() const -{ +QSize ImageViewerItem::getSize() const { int height, width; - if(xml.getIntAttribute("height", height) && xml.getIntAttribute("width", width)){ + if(xml.getIntAttribute("height", height) && xml.getIntAttribute("width", width)) { return QSize(width, height); } return defaultSize; } -void ImageViewerItem::setSize(const QSize &value) -{ +void ImageViewerItem::setSize(const QSize &value) { xml.addAttribute("height", value.height()); xml.addAttribute("width", value.width()); QList<XmlObject*> childs = xml.deepSearchObjects("rect"); - if(!childs.isEmpty()){ + if(!childs.isEmpty()) { XmlObject *border = childs[0]; border->addAttribute("height", value.height()); border->addAttribute("width", value.width()); } } -void ImageViewerItem::setSize(int width, int height) -{ +void ImageViewerItem::setSize(int width, int height) { setSize(QSize(width, height)); } -QPointF ImageViewerItem::getTopLeftCornerPosition() const -{ +QPointF ImageViewerItem::getTopLeftCornerPosition() const { return topLeftCornerPosition; } diff --git a/Modules/ImageViewer/imagevieweritem.h b/Modules/ImageViewer/imagevieweritem.h index e6ef6ae8bd705b41b4129276a7f3a4382e61e411..8a716d8ffe7cd03857f172850df87aa1736ecbca 100644 --- a/Modules/ImageViewer/imagevieweritem.h +++ b/Modules/ImageViewer/imagevieweritem.h @@ -7,9 +7,8 @@ #include "Core/xmlobject.h" #include "Core/modulemessage.h" -class ImageViewerItem -{ -public: +class ImageViewerItem { + public: ImageViewerItem(); ImageViewerItem(const QPointF ¢er, const QSize &value); ImageViewerItem(const ImageViewerItem &other); @@ -35,8 +34,8 @@ public: int getId() const; void setId(int value); -// bool getClicked() const; -// void setClicked(bool value); + // bool getClicked() const; + // void setClicked(bool value); QString getCurrentBorderColor() const; @@ -44,22 +43,22 @@ public: void setTopLeftCornerPosition(const QPointF &value); void setTopic(const QString &topic); -protected: + protected: void copy(const ImageViewerItem &other); void initialize(); XmlObject *findOrAddXmlObject(const QString &xmlChildName); -private: + private: int id = -1; QPointF topLeftCornerPosition; -// const QString defaultBorderColor = "#000000"; -// const QString clickedBorderColor = "#32a83a"; + // const QString defaultBorderColor = "#000000"; + // const QString clickedBorderColor = "#32a83a"; const QSize defaultSize = QSize(250, 150); const QString defaultText = "New item"; -// bool clicked = false; + // bool clicked = false; QPointF dragOffset; bool isDragActive = false; diff --git a/Modules/ImageViewer/imageviewermodule.cpp b/Modules/ImageViewer/imageviewermodule.cpp index 4585d8f5884daea68c305bf535805de386432156..4f9271b05e5b4ed121fa2c753bc92bab2b652f54 100644 --- a/Modules/ImageViewer/imageviewermodule.cpp +++ b/Modules/ImageViewer/imageviewermodule.cpp @@ -11,8 +11,7 @@ #include <QMessageBox> #include <QInputDialog> -ImageViewerModule::ImageViewerModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::ImageViewerModule) -{ +ImageViewerModule::ImageViewerModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::ImageViewerModule) { ui->setupUi(this); showImage(fileName); defaultContextMenuSetup(); @@ -26,9 +25,8 @@ ImageViewerModule::ImageViewerModule(QWidget *parent) : DefaultModule(parent), u connect(&settingsPanel, &ImageViewerSettings::deleteItemRequested, this, &ImageViewerModule::onItemDeleteRequested); } -ImageViewerModule::~ImageViewerModule() -{ - for(int key : imageViewerItems.keys()){ +ImageViewerModule::~ImageViewerModule() { + for(int key : imageViewerItems.keys()) { ImageViewerItem* item = imageViewerItems[key]; delete item; } @@ -36,17 +34,15 @@ ImageViewerModule::~ImageViewerModule() delete ui; } -QWidget *ImageViewerModule::toWidget() -{ +QWidget *ImageViewerModule::toWidget() { return this; } -XmlObject ImageViewerModule::toXmlObject() -{ +XmlObject ImageViewerModule::toXmlObject() { XmlObject obj(getName(ModuleId::IMAGEVIEWER)); obj.addAttribute("ImageName", fileName); - for(int key : imageViewerItems.keys()){ + for(int key : imageViewerItems.keys()) { ImageViewerItem* item = imageViewerItems[key]; obj.addChild(item->toXmlObject()); } @@ -54,17 +50,16 @@ XmlObject ImageViewerModule::toXmlObject() return obj; } -void ImageViewerModule::fromXmlObject(const XmlObject &xmlObject) -{ - if(xmlObject.getObjectName() == getName(ModuleId::IMAGEVIEWER)){ +void ImageViewerModule::fromXmlObject(const XmlObject &xmlObject) { + if(xmlObject.getObjectName() == getName(ModuleId::IMAGEVIEWER)) { QString path = xmlObject.getAttribute("ImageName"); - if(path != ""){ + if(path != "") { this->fileName = path; showImage(fileName); } - for(int i = 0; i < xmlObject.childCount(); i++){ + for(int i = 0; i < xmlObject.childCount(); i++) { XmlObject child = xmlObject.childAt(i); - if(child.getObjectName() == "svg"){ + if(child.getObjectName() == "svg") { addItem(child); } } @@ -72,55 +67,50 @@ void ImageViewerModule::fromXmlObject(const XmlObject &xmlObject) } -void ImageViewerModule::resizeEvent(QResizeEvent *event) -{ +void ImageViewerModule::resizeEvent(QResizeEvent *event) { Q_UNUSED(event); fitImage(); } -void ImageViewerModule::showImage(const QString &filename) -{ +void ImageViewerModule::showImage(const QString &filename) { firstResizeDone = false; QString filePaht = SkywardHubStrings::defaultConfigurationFolder + "/" + filename; QPixmap pixmap(filePaht); showImage(pixmap); } -void ImageViewerModule::showImage(const QPixmap &pixmap) -{ +void ImageViewerModule::showImage(const QPixmap &pixmap) { backgroundImg.setPixmap(pixmap); scene.addItem(&backgroundImg); ui->graphicsView->setScene(&scene); fitImage(); } -void ImageViewerModule::addItem(const XmlObject &xml) -{ +void ImageViewerModule::addItem(const XmlObject &xml) { int itemId = onAddNewItemRequested(); - if(imageViewerItems.contains(itemId)){ + if(imageViewerItems.contains(itemId)) { ImageViewerItem *item = imageViewerItems[itemId]; item->setXml(xml); - if(!item->getTopic().isEmpty()){ + if(!item->getTopic().isEmpty()) { onItemTopicChanged(item); } scene.updateImageViewItem(item); } } -void ImageViewerModule::addCustomActionsToMenu() -{ +void ImageViewerModule::addCustomActionsToMenu() { QAction* settings = new QAction("Change Image Name"); - connect(settings, &QAction::triggered,this, &ImageViewerModule::onChangeImageRequested); + connect(settings, &QAction::triggered, this, &ImageViewerModule::onChangeImageRequested); QAction* fitView = new QAction("Fit Image"); - connect(fitView, &QAction::triggered,this, &ImageViewerModule::fitImage); + connect(fitView, &QAction::triggered, this, &ImageViewerModule::fitImage); QAction* addItem = new QAction("Add Item"); - connect(addItem, &QAction::triggered,this, &ImageViewerModule::onAddNewItemRequested); + connect(addItem, &QAction::triggered, this, &ImageViewerModule::onAddNewItemRequested); QAction* showInfo = new QAction("Info"); - connect(showInfo, &QAction::triggered,this, [](){ + connect(showInfo, &QAction::triggered, this, []() { QMessageBox msgBox; msgBox.setText(SkywardHubStrings::imageViewerInfo); msgBox.exec(); @@ -132,139 +122,124 @@ void ImageViewerModule::addCustomActionsToMenu() addActionToMenu(showInfo); } -void ImageViewerModule::onChangeImageRequested() -{ +void ImageViewerModule::onChangeImageRequested() { bool ok; QString text = QInputDialog::getText(this, "Select new image name", - "Input a new name for the image file. Remembre to put the extention at the end of the file and put the file in the " + SkywardHubStrings::defaultConfigurationFolder + " folder" , + "Input a new name for the image file. Remembre to put the extention at the end of the file and put the file in the " + SkywardHubStrings::defaultConfigurationFolder + " folder", QLineEdit::Normal, fileName, &ok); if (ok && !text.isEmpty()) onImageFilePathChanged(text); } -void ImageViewerModule::fitImage() -{ +void ImageViewerModule::fitImage() { ui->graphicsView->fitInView(&backgroundImg, Qt::KeepAspectRatio); } -void ImageViewerModule::onImageFilePathChanged(const QString &newFilePath) -{ +void ImageViewerModule::onImageFilePathChanged(const QString &newFilePath) { QString trimmedFilePath = newFilePath.trimmed(); - if(trimmedFilePath != ""){ + if(trimmedFilePath != "") { fileName = trimmedFilePath; showImage(fileName); } } -int ImageViewerModule::onAddNewItemRequested() -{ +int ImageViewerModule::onAddNewItemRequested() { return addNewItem(defaultCreationPoint); } -void ImageViewerModule::onMouseMoved(const QPointF &point) -{ - if(!firstResizeDone){ +void ImageViewerModule::onMouseMoved(const QPointF &point) { + if(!firstResizeDone) { firstResizeDone = true; fitImage(); } - for(int key : imageViewerItems.keys()){ + for(int key : imageViewerItems.keys()) { ImageViewerItem* item = imageViewerItems[key]; - if(item->onMouseMoved(point)){ + if(item->onMouseMoved(point)) { scene.updateImageViewItem(item); } } } -void ImageViewerModule::onDragStarted(const QPointF &initialPosition) -{ - for(int key : imageViewerItems.keys()){ +void ImageViewerModule::onDragStarted(const QPointF &initialPosition) { + for(int key : imageViewerItems.keys()) { ImageViewerItem* item = imageViewerItems[key]; - if(item->isPointInsideMyArea(initialPosition)){ + if(item->isPointInsideMyArea(initialPosition)) { item->startDrag(initialPosition); } } } -void ImageViewerModule::onDragStopped() -{ - for(int key : imageViewerItems.keys()){ +void ImageViewerModule::onDragStopped() { + for(int key : imageViewerItems.keys()) { ImageViewerItem* item = imageViewerItems[key]; item->stopDrag(); } } -void ImageViewerModule::onDoubleClick(const QPointF &point) -{ +void ImageViewerModule::onDoubleClick(const QPointF &point) { QList<ImageViewerItem*> clickedItems; - for(int key : imageViewerItems.keys()){ + for(int key : imageViewerItems.keys()) { ImageViewerItem* item = imageViewerItems[key]; - if(item->isPointInsideMyArea(point)){ + if(item->isPointInsideMyArea(point)) { clickedItems.append(item); } } // Take the last selected (the items ore ordered by creation time) - if(clickedItems.count() > 0){ + if(clickedItems.count() > 0) { showInSettings(clickedItems[clickedItems.count() - 1]); } } -int ImageViewerModule::addNewItem(const QPointF &point) -{ +int ImageViewerModule::addNewItem(const QPointF &point) { return addItem(createNewItem(point)); } -int ImageViewerModule::pickUnusedItemId() -{ - while(imageViewerItems.contains(lastUsedId)){ +int ImageViewerModule::pickUnusedItemId() { + while(imageViewerItems.contains(lastUsedId)) { lastUsedId++; } return lastUsedId; } -ImageViewerItem *ImageViewerModule::createNewItem(const QPointF &point) -{ +ImageViewerItem *ImageViewerModule::createNewItem(const QPointF &point) { ImageViewerItem* newItem = new ImageViewerItem(); newItem->setId(pickUnusedItemId()); newItem->setCenter(point); return newItem; } -int ImageViewerModule::addItem(ImageViewerItem *item) -{ +int ImageViewerModule::addItem(ImageViewerItem *item) { imageViewerItems[item->getId()] = item; scene.addImageViewItem(item); return item->getId(); } -void ImageViewerModule::showInSettings(ImageViewerItem *item) -{ +void ImageViewerModule::showInSettings(ImageViewerItem *item) { settingsPanel.setTarget(item->getId(), item->toXmlObject()); settingsPanel.show(); } -void ImageViewerModule::onSettingsSetupRequested(int id) -{ - if(imageViewerItems.contains(id)){ +void ImageViewerModule::onSettingsSetupRequested(int id) { + if(imageViewerItems.contains(id)) { ImageViewerItem* item = imageViewerItems[id]; QString previousTopic = item->getTopic(); item->setXml(settingsPanel.getDefaultSettings()); scene.updateImageViewItem(item); - if(item->getTopic() != previousTopic){ + if(item->getTopic() != previousTopic) { onItemTopicChanged(item); } } } -void ImageViewerModule::onSettingsSetupToAllRequested() -{ - for(int key : imageViewerItems.keys()){ +void ImageViewerModule::onSettingsSetupToAllRequested() { + for(int key : imageViewerItems.keys()) { ImageViewerItem* item = imageViewerItems[key]; QString previousText = item->getText(); QString previousTopic = item->getTopic(); @@ -277,28 +252,26 @@ void ImageViewerModule::onSettingsSetupToAllRequested() } } -void ImageViewerModule::onItemTopicChanged(ImageViewerItem *item) -{ - if(topicMap.contains(item->getId())){ +void ImageViewerModule::onItemTopicChanged(ImageViewerItem *item) { + if(topicMap.contains(item->getId())) { QString oldTopic = topicMap[item->getId()]; - getCore()->getModuleMessagesBroker()->unsubscribe(oldTopic,this); + getCore()->getModuleMessagesBroker()->unsubscribe(oldTopic, this); topicMap.remove(item->getId()); } QString newTopic = item->getTopic(); - if(newTopic != ""){ + if(newTopic != "") { topicMap[item->getId()] = newTopic; - getCore()->getModuleMessagesBroker()->subscribe(newTopic,this, [this](const ModuleMessage &msg){ + getCore()->getModuleMessagesBroker()->subscribe(newTopic, this, [this](const ModuleMessage & msg) { this->onReceiveMsg(msg); }); } } -void ImageViewerModule::onReceiveMsg(const ModuleMessage &msg) -{ +void ImageViewerModule::onReceiveMsg(const ModuleMessage &msg) { QList<int> keys = topicMap.keys(); - for(int key : keys){ - if(msg.topic() == topicMap[key] && imageViewerItems.contains(key)){ + for(int key : keys) { + if(msg.topic() == topicMap[key] && imageViewerItems.contains(key)) { ImageViewerItem *item = imageViewerItems[key]; item->onModuleMessageReceived(msg); scene.updateImageViewItem(item); @@ -306,14 +279,13 @@ void ImageViewerModule::onReceiveMsg(const ModuleMessage &msg) } } -void ImageViewerModule::onItemDeleteRequested(int itemId) -{ - if(imageViewerItems.contains(itemId)){ +void ImageViewerModule::onItemDeleteRequested(int itemId) { + if(imageViewerItems.contains(itemId)) { delete imageViewerItems[itemId]; imageViewerItems.remove(itemId); } - if(topicMap.contains(itemId)){ + if(topicMap.contains(itemId)) { topicMap.remove(itemId); } diff --git a/Modules/ImageViewer/imageviewermodule.h b/Modules/ImageViewer/imageviewermodule.h index c3279465e10841421d7d4aa3cfee59c653f42be6..bf81057f396de8b7b31a630fd2a59fb7f877f4f1 100644 --- a/Modules/ImageViewer/imageviewermodule.h +++ b/Modules/ImageViewer/imageviewermodule.h @@ -15,11 +15,10 @@ namespace Ui { class ImageViewerModule; } -class ImageViewerModule : public DefaultModule -{ +class ImageViewerModule : public DefaultModule { Q_OBJECT -public: + public: explicit ImageViewerModule(QWidget *parent = nullptr); ~ImageViewerModule(); @@ -31,7 +30,7 @@ public: void showImage(const QPixmap &pixmap); void addItem(const XmlObject &xml); -public slots: + public slots: void onItemTopicChanged(ImageViewerItem *item); void onReceiveMsg(const ModuleMessage &msg); @@ -39,7 +38,7 @@ public slots: void onImageFilePathChanged(const QString &newFilePath); void onItemDeleteRequested(int itemId); -protected: + protected: void resizeEvent(QResizeEvent *event) override; void addCustomActionsToMenu() override; void onChangeImageRequested(); @@ -56,7 +55,7 @@ protected: void onSettingsSetupRequested(int id); void onSettingsSetupToAllRequested(); -private: + private: Ui::ImageViewerModule *ui; CustomGraphicsScene scene; diff --git a/Modules/MainWindow/skywardhubmainwindow.cpp b/Modules/MainWindow/skywardhubmainwindow.cpp index 493cd64daadcedb0904ad6ef30c5de86122315e2..9499122e42b03ab011be95b2fff2a6715f675a95 100644 --- a/Modules/MainWindow/skywardhubmainwindow.cpp +++ b/Modules/MainWindow/skywardhubmainwindow.cpp @@ -6,8 +6,7 @@ #include "Core/module.h" #include "Core/modulesmanager.h" -SkywardHubMainWindow::SkywardHubMainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::SkywardHubMainWindow) -{ +SkywardHubMainWindow::SkywardHubMainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::SkywardHubMainWindow) { ui->setupUi(this); mainWindow = new Window(); @@ -18,31 +17,27 @@ SkywardHubMainWindow::SkywardHubMainWindow(QWidget *parent) : QMainWindow(parent core->init(); } -SkywardHubMainWindow::~SkywardHubMainWindow() -{ +SkywardHubMainWindow::~SkywardHubMainWindow() { delete ui; } -void SkywardHubMainWindow::onContextMenuRequest(QMenu &menu, const QPoint &p) -{ +void SkywardHubMainWindow::onContextMenuRequest(QMenu &menu, const QPoint &p) { QAction changeSettings("Edit Settings"); menu.addAction(&changeSettings); - connect(&changeSettings,&QAction::triggered,this,&SkywardHubMainWindow::openEditSettings); + connect(&changeSettings, &QAction::triggered, this, &SkywardHubMainWindow::openEditSettings); menu.exec(p); } -void SkywardHubMainWindow::openEditSettings() -{ +void SkywardHubMainWindow::openEditSettings() { } -void SkywardHubMainWindow::onPageAdded(int index) -{ +void SkywardHubMainWindow::onPageAdded(int index) { Module* m = core->getModulesManager()->getModuleAt(index); - if(m != nullptr){ - if(index == 0){ + if(m != nullptr) { + if(index == 0) { mainWindow->updateModule(m); return; } @@ -53,13 +48,11 @@ void SkywardHubMainWindow::onPageAdded(int index) } } -void SkywardHubMainWindow::onQuitRequested() -{ +void SkywardHubMainWindow::onQuitRequested() { QApplication::quit(); } -void SkywardHubMainWindow::closeEvent(QCloseEvent *event) -{ +void SkywardHubMainWindow::closeEvent(QCloseEvent *event) { core->getModulesManager()->setRebuild(false); QMainWindow::closeEvent(event); } diff --git a/Modules/MainWindow/skywardhubmainwindow.h b/Modules/MainWindow/skywardhubmainwindow.h index 536ad8392ab65294e2f065729c37944410435234..2feb72e69e7c1411997b79fc657b42b71b638b82 100644 --- a/Modules/MainWindow/skywardhubmainwindow.h +++ b/Modules/MainWindow/skywardhubmainwindow.h @@ -9,24 +9,23 @@ namespace Ui { class SkywardHubMainWindow; } -class SkywardHubMainWindow : public QMainWindow -{ +class SkywardHubMainWindow : public QMainWindow { Q_OBJECT -public: + public: explicit SkywardHubMainWindow(QWidget *parent = nullptr); ~SkywardHubMainWindow(); -protected slots: + protected slots: void onPageAdded(int index); void onQuitRequested(); void onContextMenuRequest(QMenu &menu, const QPoint &p); void openEditSettings(); -protected: + protected: void closeEvent(QCloseEvent *event); -private: + private: Ui::SkywardHubMainWindow *ui; SkywardHubCoreProxy core; diff --git a/Modules/MainWindow/window.cpp b/Modules/MainWindow/window.cpp index 54d7abc5c434a00ffe09416340e50b5d48fb0a7b..8255edcd5111a88807262074a1f1661230b41857 100644 --- a/Modules/MainWindow/window.cpp +++ b/Modules/MainWindow/window.cpp @@ -5,33 +5,28 @@ #include "Core/modulesmanager.h" #include <QVBoxLayout> -Window::Window(QWidget *parent) : QWidget(parent), ui(new Ui::Window) -{ +Window::Window(QWidget *parent) : QWidget(parent), ui(new Ui::Window) { ui->setupUi(this); } -Window::~Window() -{ +Window::~Window() { delete ui; } -void Window::updateModule(Module *m) -{ - if(m != nullptr){ - if(centralModule == nullptr || centralModule != m){ +void Window::updateModule(Module *m) { + if(m != nullptr) { + if(centralModule == nullptr || centralModule != m) { setCentralModule(m); } } } -Module *Window::getCentralModule() const -{ +Module *Window::getCentralModule() const { return centralModule; } -void Window::setCentralModule(Module *value) -{ - if(centralModule != nullptr){ +void Window::setCentralModule(Module *value) { + if(centralModule != nullptr) { //ui->mainLayout->removeWidget(centralModule->toWidget()); disconnect(centralModule->getModuleEventsHandler(), &QWidget::destroyed, this, &Window::onWidgetDestroyed); disconnect(centralModule->getModuleEventsHandler(), &ModuleEventsHandler::replaceMeWith, this, &Window::onReplaceRequested); @@ -43,8 +38,7 @@ void Window::setCentralModule(Module *value) } -void Window::closeEvent(QCloseEvent *event) -{ +void Window::closeEvent(QCloseEvent *event) { if(centralModule != nullptr) delete centralModule; @@ -53,15 +47,13 @@ void Window::closeEvent(QCloseEvent *event) deleteLater(); } -void Window::onWidgetDestroyed() -{ +void Window::onWidgetDestroyed() { centralModule = nullptr; close(); this->deleteLater(); } -void Window::onReplaceRequested(Module *sender, Module *newModule) -{ +void Window::onReplaceRequested(Module *sender, Module *newModule) { if(newModule != nullptr && sender != nullptr) setCentralModule(newModule); } diff --git a/Modules/MainWindow/window.h b/Modules/MainWindow/window.h index 6850be295395bc4a1c08e746db5e765e052aacc6..b6f7ecd510bf164728409d7844d7cd034147f723 100644 --- a/Modules/MainWindow/window.h +++ b/Modules/MainWindow/window.h @@ -9,11 +9,10 @@ namespace Ui { class Window; } -class Window : public QWidget -{ +class Window : public QWidget { Q_OBJECT -public: + public: explicit Window(QWidget *parent = nullptr); ~Window(); @@ -23,12 +22,12 @@ public: void setCentralModule(Module *value); -protected: + protected: void closeEvent(QCloseEvent *event) override; void onWidgetDestroyed(); void onReplaceRequested(Module *sender, Module *newModule); -private: + private: Ui::Window *ui; Module *centralModule = nullptr; diff --git a/Modules/Mavlink/mavlinkcommandadapter.cpp b/Modules/Mavlink/mavlinkcommandadapter.cpp index 798d3ba37ee7869f2e1e7541e86ea56b545ce32e..18663400a117956d5cb058fb5af2c21e5ecaed8f 100644 --- a/Modules/Mavlink/mavlinkcommandadapter.cpp +++ b/Modules/Mavlink/mavlinkcommandadapter.cpp @@ -4,114 +4,102 @@ #include "Modules/skywardhubstrings.h" -MavlinkCommandAdapter::MavlinkCommandAdapter() -{ +MavlinkCommandAdapter::MavlinkCommandAdapter() { } -void MavlinkCommandAdapter::setSerialPort(QSerialPort *value) -{ +void MavlinkCommandAdapter::setSerialPort(QSerialPort *value) { serial = value; } -mavlink_message_t MavlinkCommandAdapter::encode_PING_TC() -{ +mavlink_message_t MavlinkCommandAdapter::encode_PING_TC() { mavlink_message_t encoded_mvl_msg; auto unsignedStamp = std::chrono::system_clock::now().time_since_epoch(); std::chrono::milliseconds now = std::chrono::duration_cast<std::chrono::milliseconds>(unsignedStamp); std::uint64_t timeStamp = now.count(); - mavlink_msg_ping_tc_pack(MAV_SYS,MAV_CMP,&encoded_mvl_msg,timeStamp); + mavlink_msg_ping_tc_pack(MAV_SYS, MAV_CMP, &encoded_mvl_msg, timeStamp); return encoded_mvl_msg; } -mavlink_message_t MavlinkCommandAdapter::encode_NOARG_TC(int cmd_id) -{ +mavlink_message_t MavlinkCommandAdapter::encode_NOARG_TC(int cmd_id) { mavlink_message_t encoded_mvl_msg; uint8_t command_id = cmd_id; - mavlink_msg_noarg_tc_pack(MAV_SYS,MAV_CMP,&encoded_mvl_msg, command_id); + mavlink_msg_noarg_tc_pack(MAV_SYS, MAV_CMP, &encoded_mvl_msg, command_id); return encoded_mvl_msg; } -mavlink_message_t MavlinkCommandAdapter::encode_START_LAUNCH_TC(const ModuleMessage &msg) -{ +mavlink_message_t MavlinkCommandAdapter::encode_START_LAUNCH_TC(const ModuleMessage &msg) { mavlink_message_t encoded_mvl_msg; int temp; - if(msg.getIntPayload(temp)){ + if(msg.getIntPayload(temp)) { uint64_t launch_code = temp; - mavlink_msg_start_launch_tc_pack(MAV_SYS,MAV_CMP,&encoded_mvl_msg,launch_code); + mavlink_msg_start_launch_tc_pack(MAV_SYS, MAV_CMP, &encoded_mvl_msg, launch_code); } return encoded_mvl_msg; } -mavlink_message_t MavlinkCommandAdapter::encode_TELEMETRY_REQUEST_TC(uint8_t board_id) -{ +mavlink_message_t MavlinkCommandAdapter::encode_TELEMETRY_REQUEST_TC(uint8_t board_id) { mavlink_message_t encoded_mvl_msg; - mavlink_msg_telemetry_request_tc_pack(MAV_SYS,MAV_CMP,&encoded_mvl_msg, board_id); + mavlink_msg_telemetry_request_tc_pack(MAV_SYS, MAV_CMP, &encoded_mvl_msg, board_id); return encoded_mvl_msg; } -mavlink_message_t MavlinkCommandAdapter::encode_RAW_EVENT_TC(const ModuleMessage &msg) -{ +mavlink_message_t MavlinkCommandAdapter::encode_RAW_EVENT_TC(const ModuleMessage &msg) { mavlink_message_t encoded_mvl_msg; uint8_t event_id, topic_id; XmlObject msgOption = msg.getOptions(); int temp; - if(msgOption.getIntAttribute(SkywardHubStrings::raw_event_id,temp)){ + if(msgOption.getIntAttribute(SkywardHubStrings::raw_event_id, temp)) { event_id = temp; - if(msgOption.getIntAttribute(SkywardHubStrings::raw_event_topic_id,temp)){ + if(msgOption.getIntAttribute(SkywardHubStrings::raw_event_topic_id, temp)) { topic_id = temp; - mavlink_msg_raw_event_tc_pack(MAV_SYS,MAV_CMP,&encoded_mvl_msg,event_id,topic_id); + mavlink_msg_raw_event_tc_pack(MAV_SYS, MAV_CMP, &encoded_mvl_msg, event_id, topic_id); } } return encoded_mvl_msg; } -mavlink_message_t MavlinkCommandAdapter::encode_AEROBRAKE_ANGLE_TC(const ModuleMessage &msg) -{ +mavlink_message_t MavlinkCommandAdapter::encode_AEROBRAKE_ANGLE_TC(const ModuleMessage &msg) { mavlink_message_t encoded_mvl_msg; float angle; - if(msg.getFloatPayload(angle)){ - mavlink_msg_set_aerobrake_angle_tc_pack(MAV_SYS,MAV_CMP,&encoded_mvl_msg, angle); + if(msg.getFloatPayload(angle)) { + mavlink_msg_set_aerobrake_angle_tc_pack(MAV_SYS, MAV_CMP, &encoded_mvl_msg, angle); } return encoded_mvl_msg; } -mavlink_message_t MavlinkCommandAdapter::encode_REFERENCE_ALTITUDE_TC(const ModuleMessage &msg) -{ +mavlink_message_t MavlinkCommandAdapter::encode_REFERENCE_ALTITUDE_TC(const ModuleMessage &msg) { mavlink_message_t encoded_mvl_msg; float ref_altitude; - if(msg.getFloatPayload(ref_altitude)){ - mavlink_msg_set_reference_altitude_pack(MAV_SYS,MAV_CMP,&encoded_mvl_msg, ref_altitude); + if(msg.getFloatPayload(ref_altitude)) { + mavlink_msg_set_reference_altitude_pack(MAV_SYS, MAV_CMP, &encoded_mvl_msg, ref_altitude); } return encoded_mvl_msg; } -mavlink_message_t MavlinkCommandAdapter::encode_REFERENCE_TEMPERATURE_TC(const ModuleMessage &msg) -{ +mavlink_message_t MavlinkCommandAdapter::encode_REFERENCE_TEMPERATURE_TC(const ModuleMessage &msg) { mavlink_message_t encoded_mvl_msg; float ref_temp; - if(msg.getFloatPayload(ref_temp)){ - mavlink_msg_set_reference_temperature_tc_pack(MAV_SYS,MAV_CMP,&encoded_mvl_msg, ref_temp); + if(msg.getFloatPayload(ref_temp)) { + mavlink_msg_set_reference_temperature_tc_pack(MAV_SYS, MAV_CMP, &encoded_mvl_msg, ref_temp); } return encoded_mvl_msg; } -mavlink_message_t MavlinkCommandAdapter::encode_DEPLOYMENT_ALTITUDE_TC(const ModuleMessage &msg) -{ +mavlink_message_t MavlinkCommandAdapter::encode_DEPLOYMENT_ALTITUDE_TC(const ModuleMessage &msg) { mavlink_message_t encoded_mvl_msg; float ref_altitude; - if(msg.getFloatPayload(ref_altitude)){ - mavlink_msg_set_deployment_altitude_tc_pack(MAV_SYS,MAV_CMP,&encoded_mvl_msg, ref_altitude); + if(msg.getFloatPayload(ref_altitude)) { + mavlink_msg_set_deployment_altitude_tc_pack(MAV_SYS, MAV_CMP, &encoded_mvl_msg, ref_altitude); } return encoded_mvl_msg; } -mavlink_message_t MavlinkCommandAdapter::encode_INITIAL_ORIENTATION_TC(const ModuleMessage &msg) -{ +mavlink_message_t MavlinkCommandAdapter::encode_INITIAL_ORIENTATION_TC(const ModuleMessage &msg) { mavlink_message_t encoded_mvl_msg; float yaw, pitch, roll; XmlObject msgOption = msg.getOptions(); @@ -120,14 +108,13 @@ mavlink_message_t MavlinkCommandAdapter::encode_INITIAL_ORIENTATION_TC(const Mod ok = ok && msgOption.getFloatAttribute(SkywardHubStrings::mavlink_orientation_tc_pitch_name, pitch); ok = ok && msgOption.getFloatAttribute(SkywardHubStrings::mavlink_orientation_tc_roll_name, roll); - if(ok){ - mavlink_msg_set_initial_orientation_tc_pack(MAV_SYS,MAV_CMP,&encoded_mvl_msg, yaw, pitch, roll); + if(ok) { + mavlink_msg_set_initial_orientation_tc_pack(MAV_SYS, MAV_CMP, &encoded_mvl_msg, yaw, pitch, roll); } return encoded_mvl_msg; } -mavlink_message_t MavlinkCommandAdapter::encode_INITIAL_COORDINATES_TC(const ModuleMessage &msg) -{ +mavlink_message_t MavlinkCommandAdapter::encode_INITIAL_COORDINATES_TC(const ModuleMessage &msg) { mavlink_message_t encoded_mvl_msg; float lat, longit; XmlObject msgOption = msg.getOptions(); @@ -135,19 +122,18 @@ mavlink_message_t MavlinkCommandAdapter::encode_INITIAL_COORDINATES_TC(const Mod bool ok = msgOption.getFloatAttribute(SkywardHubStrings::mavlink_initial_coordinates_tc_latitude_name, lat); ok = ok && msgOption.getFloatAttribute(SkywardHubStrings::mavlink_initial_coordinates_tc_longitude_name, longit); - if(ok){ - mavlink_msg_set_initial_coordinates_tc_pack(MAV_SYS,MAV_CMP,&encoded_mvl_msg, lat, longit); + if(ok) { + mavlink_msg_set_initial_coordinates_tc_pack(MAV_SYS, MAV_CMP, &encoded_mvl_msg, lat, longit); } return encoded_mvl_msg; } -void MavlinkCommandAdapter::send(mavlink_message_t msg) -{ +void MavlinkCommandAdapter::send(mavlink_message_t msg) { ModuleMessage response(SkywardHubStrings::logCommandsTopic); response.addOption(SkywardHubStrings::msgIdField, QString::number(msg.msgid)); response.addOption(SkywardHubStrings::msgSequenceNumberField, QString::number(msg.seq)); - if(serial == nullptr){ + if(serial == nullptr) { response.setPayload(SkywardHubStrings::serialPortClosedErrorMsg); } else { mavlinkWriter.setPort(serial); @@ -157,10 +143,9 @@ void MavlinkCommandAdapter::send(mavlink_message_t msg) emit publishRequested(response); } -bool MavlinkCommandAdapter::produceMsgFromXml(const XmlObject &xml, mavlink_message_t *msg) -{ +bool MavlinkCommandAdapter::produceMsgFromXml(const XmlObject &xml, mavlink_message_t *msg) { bool result = false; - if(xml.getObjectName() == "ACK_TM"){ + if(xml.getObjectName() == "ACK_TM") { QString recv_string = xml.getAttribute("recv_msgid"); QString seq_string = xml.getAttribute("seq_ack"); @@ -168,7 +153,7 @@ bool MavlinkCommandAdapter::produceMsgFromXml(const XmlObject &xml, mavlink_mess uint8_t recvId = recv_string.toUInt(&ok1); uint8_t seq = seq_string.toUInt(&ok2); - if(ok1 && ok2){ + if(ok1 && ok2) { mavlink_msg_ack_tm_pack(MAV_SYS, MAV_CMP, msg, recvId, seq); } result = true; diff --git a/Modules/Mavlink/mavlinkcommandadapter.h b/Modules/Mavlink/mavlinkcommandadapter.h index b256b09bc57770dfbbcbe4ee679c90013e4067e0..fdb23bf79a0b5d64edc30ef088d1f767bb1d39f9 100644 --- a/Modules/Mavlink/mavlinkcommandadapter.h +++ b/Modules/Mavlink/mavlinkcommandadapter.h @@ -13,11 +13,10 @@ /* * This class translate commands received from the UI in mavlink messages that can be sent. */ -class MavlinkCommandAdapter : public QObject -{ +class MavlinkCommandAdapter : public QObject { Q_OBJECT -public: + public: MavlinkCommandAdapter(); @@ -38,10 +37,10 @@ public: bool produceMsgFromXml(const XmlObject &xml, mavlink_message_t *msg); -signals: + signals: void publishRequested(const ModuleMessage &msg); -private: + private: QSerialPort *serial = nullptr; MavlinkWriter mavlinkWriter; diff --git a/Modules/Mavlink/mavlinkmodule.cpp b/Modules/Mavlink/mavlinkmodule.cpp index 8ba565e967e1bcc9c3aa989f06cf98056098cc0a..cc2da2c12108bdef447fdffe12d09b0fc8802d0c 100644 --- a/Modules/Mavlink/mavlinkmodule.cpp +++ b/Modules/Mavlink/mavlinkmodule.cpp @@ -6,17 +6,16 @@ #include "Core/modulemessagesbroker.h" #include "Modules/skywardhubstrings.h" -MavlinkModule::MavlinkModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::MavlinkModule), serialPort(this) -{ +MavlinkModule::MavlinkModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::MavlinkModule), serialPort(this) { ui->setupUi(this); defaultContextMenuSetup(); initializeSerialPortView(); -// buildCentralGraphView(); + // buildCentralGraphView(); connectUiSlots(); qRegisterMetaType<ModuleMessage>(); - connect(&mavlinkReader,&MavlinkReader::msgReceived, this, &MavlinkModule::onMsgReceived); - connect(&mavlinkCommandAdapter,&MavlinkCommandAdapter::publishRequested, this, &MavlinkModule::publish); + connect(&mavlinkReader, &MavlinkReader::msgReceived, this, &MavlinkModule::onMsgReceived); + connect(&mavlinkCommandAdapter, &MavlinkCommandAdapter::publishRequested, this, &MavlinkModule::publish); connect(&linkQualityTimer, &QTimer::timeout, this, &MavlinkModule::onLinkQualityTimerTick); mavlinkCommandAdapter.setSerialPort(&serialPort); @@ -24,61 +23,53 @@ MavlinkModule::MavlinkModule(QWidget *parent) : DefaultModule(parent), ui(new Ui subscribe(); } -MavlinkModule::~MavlinkModule() -{ +MavlinkModule::~MavlinkModule() { mavlinkReader.stopReading(); delete ui; onStopClicked(); } -QWidget* MavlinkModule::toWidget() -{ +QWidget* MavlinkModule::toWidget() { return this; } -XmlObject MavlinkModule::toXmlObject() -{ +XmlObject MavlinkModule::toXmlObject() { XmlObject obj(getName(ModuleId::MAVLINK)); - obj.addAttribute("BaudRateIndex",QString::number(ui->comboBox_baudRate->currentIndex())); + obj.addAttribute("BaudRateIndex", QString::number(ui->comboBox_baudRate->currentIndex())); return obj; } -void MavlinkModule::fromXmlObject(const XmlObject &xmlObject) -{ - if(xmlObject.getObjectName() == getName(ModuleId::MAVLINK)){ +void MavlinkModule::fromXmlObject(const XmlObject &xmlObject) { + if(xmlObject.getObjectName() == getName(ModuleId::MAVLINK)) { bool ok; int index = xmlObject.getAttribute("BaudRateIndex").toInt(&ok); - if(ok){ + if(ok) { ui->comboBox_baudRate->setCurrentIndex(index); } } } -void MavlinkModule::subscribe() -{ - getCore()->getModuleMessagesBroker()->subscribe(SkywardHubStrings::commandsTopic,this,[this](const ModuleMessage &msg){ +void MavlinkModule::subscribe() { + getCore()->getModuleMessagesBroker()->subscribe(SkywardHubStrings::commandsTopic, this, [this](const ModuleMessage & msg) { onCommandReceived(msg); }); - getCore()->getModuleMessagesBroker()->subscribe(SkywardHubStrings::telemetryRequestTopic,this,[this](const ModuleMessage &msg){ + getCore()->getModuleMessagesBroker()->subscribe(SkywardHubStrings::telemetryRequestTopic, this, [this](const ModuleMessage & msg) { onTelemetryRequestReceived(msg); }); } -void MavlinkModule::publish(const ModuleMessage &msg) -{ +void MavlinkModule::publish(const ModuleMessage &msg) { getCore()->getModuleMessagesBroker()->publish(msg); } -void MavlinkModule::closePort() -{ - if(serialPort.isOpen()){ +void MavlinkModule::closePort() { + if(serialPort.isOpen()) { serialPort.close(); } } -void MavlinkModule::initializeSerialPortView() -{ +void MavlinkModule::initializeSerialPortView() { //fill the baud rate combo box QString baudPrefix = "BaudRate: "; ui->comboBox_baudRate->addItem(baudPrefix + "115200", QSerialPort::Baud115200); @@ -95,12 +86,12 @@ void MavlinkModule::initializeSerialPortView() //Check available port const auto serialPortInfos = QSerialPortInfo::availablePorts(); for (const QSerialPortInfo &serialPortInfo : serialPortInfos) { -// QString serialNumber = serialPortInfo.serialNumber(); -// QVariant data = (!serialNumber.isEmpty() ? serialNumber : "N/A"); + // QString serialNumber = serialPortInfo.serialNumber(); + // QVariant data = (!serialNumber.isEmpty() ? serialNumber : "N/A"); QVariant data(serialPortInfo.portName()); ui->comboBox_serialPort->addItem(serialPortInfo.portName(), data); - if(first){ + if(first) { ui->lineEdit_serialPort->setText(serialPortInfo.portName()); first = false; } @@ -108,8 +99,7 @@ void MavlinkModule::initializeSerialPortView() } -bool MavlinkModule::startReadingOnSerialPort() -{ +bool MavlinkModule::startReadingOnSerialPort() { QString portName = ui->lineEdit_serialPort->text().trimmed(); bool ok; int baudRate = ui->comboBox_baudRate->currentData().toInt(&ok); @@ -132,7 +122,7 @@ bool MavlinkModule::startReadingOnSerialPort() return true; } } -*/ + */ if(!ok || portName == "" || serialPort.isOpen()) return false; @@ -146,13 +136,12 @@ bool MavlinkModule::startReadingOnSerialPort() return serialPort.open(QIODevice::ReadWrite); } -void MavlinkModule::onStartClicked() -{ - if(startReadingOnSerialPort()){ +void MavlinkModule::onStartClicked() { + if(startReadingOnSerialPort()) { serialPort.open(QIODevice::OpenModeFlag::ReadWrite); - mavlinkReader.setPort(&serialPort); + mavlinkReader.setSerialPort(&serialPort); - if(ui->logEnabled_checkBox->isChecked()){ + if(ui->logEnabled_checkBox->isChecked()) { mavlinkReader.openLogFile(); } @@ -162,49 +151,41 @@ void MavlinkModule::onStartClicked() } } -void MavlinkModule::onStopClicked() -{ +void MavlinkModule::onStopClicked() { mavlinkReader.stopReading(); closePort(); } -void MavlinkModule::onMsgReceived(const ModuleMessage &msg) -{ +void MavlinkModule::onMsgReceived(const ModuleMessage &msg) { msgArrived++; publish(msg); } -void MavlinkModule::onStartStreamToggled(bool state) -{ +void MavlinkModule::onStartStreamToggled(bool state) { onLinkQualityIndicatorClicked(ui->linkQuality_groupBox->isChecked()); - if(state){ + if(state) { onStartClicked(); - } - else{ + } else { onStopClicked(); } } -void MavlinkModule::onLinkQualityIndicatorClicked(bool checked) -{ - if(checked && !linkQualityTimer.isActive()){ +void MavlinkModule::onLinkQualityIndicatorClicked(bool checked) { + if(checked && !linkQualityTimer.isActive()) { linkQualityTimer.start(linkQualityPeriod); - } - else if(!checked && linkQualityTimer.isActive()){ + } else if(!checked && linkQualityTimer.isActive()) { linkQualityTimer.stop(); } } -void MavlinkModule::onLinkQualityTimerTick() -{ - float ratio = msgArrived/ui->spinBox_maxPackets->value(); +void MavlinkModule::onLinkQualityTimerTick() { + float ratio = msgArrived / ui->spinBox_maxPackets->value(); updateLinkSignalIndicator(msgArrived, ratio); msgArrived = 0; } -void MavlinkModule::updateLinkSignalIndicator(int msgArrived, float ratio) -{ +void MavlinkModule::updateLinkSignalIndicator(int msgArrived, float ratio) { ui->msgPerSecond_label->setText(QString::number(msgArrived)); ModuleMessage linkQualityMsgNumber(SkywardHubStrings::mavlink_quality_link_topic + "/ReceivedMsgNumber", QString::number(msgArrived)); ModuleMessage linkQualityMsgRatio(SkywardHubStrings::mavlink_quality_link_topic + "/ReceivedRatio", QString::number(ratio)); @@ -213,13 +194,11 @@ void MavlinkModule::updateLinkSignalIndicator(int msgArrived, float ratio) publish(linkQualityMsgRatio); } -void MavlinkModule::onOpenLogFolderClick() -{ +void MavlinkModule::onOpenLogFolderClick() { QDir dir(SkywardHubStrings::defaultLogsFolder); - if (dir.exists()){ + if (dir.exists()) { QDesktopServices::openUrl( QUrl::fromLocalFile(SkywardHubStrings::defaultLogsFolder) ); - } - else{ + } else { QString msg = "The log folder does not exist yet.\n\nIt will be created when opening the serial port.\n\n" + SkywardHubStrings::defaultLogsFolder; QMessageBox msgBox; msgBox.setText(msg); @@ -227,261 +206,215 @@ void MavlinkModule::onOpenLogFolderClick() } } -void MavlinkModule::connectUiSlots() -{ +void MavlinkModule::connectUiSlots() { ui->startStop_button_layout->insertWidget(0, &startSerialStreamToggleButton); connect(&startSerialStreamToggleButton, &ToggleButton::toggled, this, &MavlinkModule::onStartStreamToggled); -// connect(ui->button_start,&QPushButton::clicked,this, &MavlinkModule::onStartClicked); -// connect(ui->button_stop,&QPushButton::clicked,this, &MavlinkModule::onStopClicked); -// connect(ui->spinBox_maxPackets,SIGNAL(valueChanged(int)),this,SLOT(onMaxPackedValueChanged(int))); + // connect(ui->button_start,&QPushButton::clicked,this, &MavlinkModule::onStartClicked); + // connect(ui->button_stop,&QPushButton::clicked,this, &MavlinkModule::onStopClicked); + // connect(ui->spinBox_maxPackets,SIGNAL(valueChanged(int)),this,SLOT(onMaxPackedValueChanged(int))); connect(ui->openLogFolder_button, &QPushButton::clicked, this, &MavlinkModule::onOpenLogFolderClick); connect(ui->comboBox_serialPort, SIGNAL(currentIndexChanged(int)), this, SLOT(onSerialPortIndexChanged(int))); connect(ui->linkQuality_groupBox, &QGroupBox::clicked, this, &MavlinkModule::onLinkQualityIndicatorClicked); } -void MavlinkModule::onSerialPortIndexChanged(int index) -{ +void MavlinkModule::onSerialPortIndexChanged(int index) { QVariant data = ui->comboBox_serialPort->itemData(index); ui->lineEdit_serialPort->setText(data.toString()); } -void MavlinkModule::onCommandReceived(const ModuleMessage &msg) -{ - QString arg = msg.originalTopic().replace(SkywardHubStrings::commandsTopic+"/",""); +void MavlinkModule::onCommandReceived(const ModuleMessage &msg) { + QString arg = msg.originalTopic().replace(SkywardHubStrings::commandsTopic + "/", ""); mavlink_message_t encoded_mvl_msg; - if(arg == "PING_TC"){ + if(arg == "PING_TC") { encoded_mvl_msg = mavlinkCommandAdapter.encode_PING_TC(); - } - else if(arg == "START_LAUNCH_TC"){ + } else if(arg == "START_LAUNCH_TC") { encoded_mvl_msg = mavlinkCommandAdapter.encode_START_LAUNCH_TC(msg); } - else if(arg == "SET_AEROBRAKE_ANGLE_TC"){ + else if(arg == "SET_AEROBRAKE_ANGLE_TC") { encoded_mvl_msg = mavlinkCommandAdapter.encode_AEROBRAKE_ANGLE_TC(msg); - } - else if(arg == "SET_REFERENCE_ALTITUDE"){ + } else if(arg == "SET_REFERENCE_ALTITUDE") { encoded_mvl_msg = mavlinkCommandAdapter.encode_REFERENCE_ALTITUDE_TC(msg); - } - else if(arg == "SET_REFERENCE_TEMPERATURE_TC"){ + } else if(arg == "SET_REFERENCE_TEMPERATURE_TC") { encoded_mvl_msg = mavlinkCommandAdapter.encode_REFERENCE_TEMPERATURE_TC(msg); - } - else if(arg == "SET_DEPLOYMENT_ALTITUDE_TC"){ + } else if(arg == "SET_DEPLOYMENT_ALTITUDE_TC") { encoded_mvl_msg = mavlinkCommandAdapter.encode_DEPLOYMENT_ALTITUDE_TC(msg); - } - else if(arg == "SET_INITIAL_ORIENTATION_TC"){ + } else if(arg == "SET_INITIAL_ORIENTATION_TC") { encoded_mvl_msg = mavlinkCommandAdapter.encode_INITIAL_ORIENTATION_TC(msg); - } - else if(arg == "SET_INITIAL_COORDINATES_TC"){ + } else if(arg == "SET_INITIAL_COORDINATES_TC") { encoded_mvl_msg = mavlinkCommandAdapter.encode_INITIAL_COORDINATES_TC(msg); - } - else if(arg == "RAW_EVENT_TC"){ + } else if(arg == "RAW_EVENT_TC") { encoded_mvl_msg = mavlinkCommandAdapter.encode_RAW_EVENT_TC(msg); } // NOARG_TC - else if(arg == "MAV_CMD_ARM"){ + else if(arg == "MAV_CMD_ARM") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_ARM); - } - else if(arg == "MAV_CMD_DISARM"){ + } else if(arg == "MAV_CMD_DISARM") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_DISARM); - } - else if(arg == "MAV_CMD_FORCE_LAUNCH"){ + } else if(arg == "MAV_CMD_FORCE_LAUNCH") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_FORCE_LAUNCH); - } - else if(arg == "MAV_CMD_CALIBRATE_SENSORS"){ + } else if(arg == "MAV_CMD_CALIBRATE_SENSORS") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_CALIBRATE_SENSORS); - } - else if(arg == "MAV_CMD_CALIBRATE_ALGOS"){ + } else if(arg == "MAV_CMD_CALIBRATE_ALGOS") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_CALIBRATE_ALGOS); - } - else if(arg == "MAV_CMD_FORCE_INIT"){ + } else if(arg == "MAV_CMD_FORCE_INIT") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_FORCE_INIT); - } - else if(arg == "MAV_CMD_NOSECONE_OPEN"){ + } else if(arg == "MAV_CMD_NOSECONE_OPEN") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_NOSECONE_OPEN); - } - else if(arg == "MAV_CMD_DPL_WIGGLE_SERVO"){ + } else if(arg == "MAV_CMD_DPL_WIGGLE_SERVO") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_DPL_WIGGLE_SERVO); - } - else if(arg == "MAV_CMD_ARB_WIGGLE_SERVO"){ + } else if(arg == "MAV_CMD_ARB_WIGGLE_SERVO") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_ARB_WIGGLE_SERVO); - } - else if(arg == "MAV_CMD_DPL_RESET_SERVO"){ + } else if(arg == "MAV_CMD_DPL_RESET_SERVO") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_DPL_RESET_SERVO); - } - else if(arg == "MAV_CMD_ARB_RESET_SERVO"){ + } else if(arg == "MAV_CMD_ARB_RESET_SERVO") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_ARB_RESET_SERVO); - } - else if(arg == "MAV_CMD_CUT_DROGUE"){ + } else if(arg == "MAV_CMD_CUT_DROGUE") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_CUT_DROGUE); } -// else if(arg == "MAV_CMD_CUT_PRIMARY"){ -// encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_CUT_PRIMARY); -// } -// else if(arg == "MAV_CMD_CUT_BACKUP"){ -// encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_CUT_BACKUP); -// } -// else if(arg == "MAV_CMD_TEST_PRIMARY_CUTTER"){ -// encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_TEST_PRIMARY_CUTTER); -// } -// else if(arg == "MAV_CMD_TEST_BACKUP_CUTTER"){ -// encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_TEST_BACKUP_CUTTER); -// } - else if(arg == "MAV_CMD_START_LOGGING"){ + // else if(arg == "MAV_CMD_CUT_PRIMARY"){ + // encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_CUT_PRIMARY); + // } + // else if(arg == "MAV_CMD_CUT_BACKUP"){ + // encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_CUT_BACKUP); + // } + // else if(arg == "MAV_CMD_TEST_PRIMARY_CUTTER"){ + // encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_TEST_PRIMARY_CUTTER); + // } + // else if(arg == "MAV_CMD_TEST_BACKUP_CUTTER"){ + // encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_TEST_BACKUP_CUTTER); + // } + else if(arg == "MAV_CMD_START_LOGGING") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_START_LOGGING); } -// else if(arg == "MAV_CMD_STOP_LOGGING"){ -// encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_STOP_LOGGING); -// } - else if(arg == "MAV_CMD_CLOSE_LOG"){ + // else if(arg == "MAV_CMD_STOP_LOGGING"){ + // encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_STOP_LOGGING); + // } + else if(arg == "MAV_CMD_CLOSE_LOG") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_CLOSE_LOG); - } - else if(arg == "MAV_CMD_TEST_AEROBRAKES"){ + } else if(arg == "MAV_CMD_TEST_AEROBRAKES") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_TEST_AEROBRAKES); - } - else if(arg == "MAV_CMD_DISABLE_AEROBRAKES"){ + } else if(arg == "MAV_CMD_DISABLE_AEROBRAKES") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_DISABLE_AEROBRAKES); - } - else if(arg == "MAV_CMD_END_MISSION"){ + } else if(arg == "MAV_CMD_END_MISSION") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_END_MISSION); - } - else if(arg == "MAV_CMD_BOARD_RESET"){ + } else if(arg == "MAV_CMD_BOARD_RESET") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_BOARD_RESET); - } - else if(arg == "MAV_CMD_TEST_MODE"){ + } else if(arg == "MAV_CMD_TEST_MODE") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_TEST_MODE); - } - else if(arg == "MAV_CMD_RADIO_TM"){ + } else if(arg == "MAV_CMD_RADIO_TM") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_RADIO_TM); - } - else if(arg == "MAV_CMD_SERIAL_TM"){ + } else if(arg == "MAV_CMD_SERIAL_TM") { encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_SERIAL_TM); } -// else if(arg == "MAV_CMD_WIGGLE_SERVO"){ -// encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_WIGGLE_SERVO); -// } -// else if(arg == "MAV_CMD_RESET_SERVO"){ -// encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_RESET_SERVO); -// } -// else if(arg == "MAV_CMD_CALIBRATE_ADA"){ -// encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_CALIBRATE_ADA); -// } - -// else if(arg == "MAV_SET_DEPLOYMENT_ALTITUDE"){ -// float setting_value; -// XmlObject msgOption = msg.getOptions(); -// int temp; -// if(msgOption.getIntAttribute(SkywardHubStrings::upload_settings_value, temp)){ -// setting_value = temp; -// encoded_mvl_msg = mavlinkCommandAdapter.encode_UPLOAD_SETTING_TC(MAV_SET_DEPLOYMENT_ALTITUDE_TC, setting_value); -// } -// } -// else if(arg == "MAV_SET_REFERENCE_TEMP"){ -// float setting_value; -// XmlObject msgOption = msg.getOptions(); -// int temp; -// if(msgOption.getIntAttribute(SkywardHubStrings::upload_settings_value, temp)){ -// setting_value = temp; -// encoded_mvl_msg = mavlinkCommandAdapter.encode_UPLOAD_SETTING_TC(MAV_SET_REFERENCE_TEMP, setting_value); -// } -// } -// else if(arg == "MAV_SET_REFERENCE_ALTITUDE"){ -// float setting_value; -// XmlObject msgOption = msg.getOptions(); -// int temp; -// if(msgOption.getIntAttribute(SkywardHubStrings::upload_settings_value, temp)){ -// setting_value = temp; -// encoded_mvl_msg = mavlinkCommandAdapter.encode_UPLOAD_SETTING_TC(MAV_SET_REFERENCE_ALTITUDE, setting_value); -// } -// } + // else if(arg == "MAV_CMD_WIGGLE_SERVO"){ + // encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_WIGGLE_SERVO); + // } + // else if(arg == "MAV_CMD_RESET_SERVO"){ + // encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_RESET_SERVO); + // } + // else if(arg == "MAV_CMD_CALIBRATE_ADA"){ + // encoded_mvl_msg = mavlinkCommandAdapter.encode_NOARG_TC(MAV_CMD_CALIBRATE_ADA); + // } + + // else if(arg == "MAV_SET_DEPLOYMENT_ALTITUDE"){ + // float setting_value; + // XmlObject msgOption = msg.getOptions(); + // int temp; + // if(msgOption.getIntAttribute(SkywardHubStrings::upload_settings_value, temp)){ + // setting_value = temp; + // encoded_mvl_msg = mavlinkCommandAdapter.encode_UPLOAD_SETTING_TC(MAV_SET_DEPLOYMENT_ALTITUDE_TC, setting_value); + // } + // } + // else if(arg == "MAV_SET_REFERENCE_TEMP"){ + // float setting_value; + // XmlObject msgOption = msg.getOptions(); + // int temp; + // if(msgOption.getIntAttribute(SkywardHubStrings::upload_settings_value, temp)){ + // setting_value = temp; + // encoded_mvl_msg = mavlinkCommandAdapter.encode_UPLOAD_SETTING_TC(MAV_SET_REFERENCE_TEMP, setting_value); + // } + // } + // else if(arg == "MAV_SET_REFERENCE_ALTITUDE"){ + // float setting_value; + // XmlObject msgOption = msg.getOptions(); + // int temp; + // if(msgOption.getIntAttribute(SkywardHubStrings::upload_settings_value, temp)){ + // setting_value = temp; + // encoded_mvl_msg = mavlinkCommandAdapter.encode_UPLOAD_SETTING_TC(MAV_SET_REFERENCE_ALTITUDE, setting_value); + // } + // } encoded_mvl_msg.sysid = validSysid; encoded_mvl_msg.compid = validCompid; - if(serialPort.isOpen()){ + if(serialPort.isOpen()) { mavlinkCommandAdapter.send(encoded_mvl_msg); } } -void MavlinkModule::onTelemetryRequestReceived(const ModuleMessage &msg) -{ - QString arg = msg.originalTopic().replace(SkywardHubStrings::telemetryRequestTopic+"/",""); +void MavlinkModule::onTelemetryRequestReceived(const ModuleMessage &msg) { + QString arg = msg.originalTopic().replace(SkywardHubStrings::telemetryRequestTopic + "/", ""); mavlink_message_t encoded_mvl_msg; - if(arg == "MAV_SYS_TM_ID"){ + if(arg == "MAV_SYS_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_SYS_TM_ID); - } - else if(arg == "MAV_FMM_TM_ID"){ + } else if(arg == "MAV_FMM_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_FMM_TM_ID); - } - else if(arg == "MAV_LOGGER_TM_ID"){ + } else if(arg == "MAV_LOGGER_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_LOGGER_TM_ID); - } - else if(arg == "MAV_TMTC_TM_ID"){ + } else if(arg == "MAV_TMTC_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_TMTC_TM_ID); - } - else if(arg == "MAV_DPL_TM_ID"){ + } else if(arg == "MAV_DPL_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_DPL_TM_ID); - } - else if(arg == "MAV_ADA_TM_ID"){ + } else if(arg == "MAV_ADA_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_ADA_TM_ID); } -// else if(arg == "MAV_CAN_TM_ID"){ -// encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_CAN_TM_ID); -// } - else if(arg == "MAV_ADC_TM_ID"){ + // else if(arg == "MAV_CAN_TM_ID"){ + // encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_CAN_TM_ID); + // } + else if(arg == "MAV_ADC_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_ADC_TM_ID); - } - else if(arg == "MAV_GPS_TM_ID"){ + } else if(arg == "MAV_GPS_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_GPS_TM_ID); - } - else if(arg == "MAV_HR_TM_ID"){ + } else if(arg == "MAV_HR_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_HR_TM_ID); - } - else if(arg == "MAV_LR_TM_ID"){ + } else if(arg == "MAV_LR_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_LR_TM_ID); - } - else if(arg == "MAV_TEST_TM_ID"){ + } else if(arg == "MAV_TEST_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_TEST_TM_ID); - } - else if(arg == "MAV_WINDTUNNEL_TM_ID"){ + } else if(arg == "MAV_WINDTUNNEL_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_WINDTUNNEL_TM_ID); - } - else if(arg == "MAV_SENSORS_TM_ID"){ + } else if(arg == "MAV_SENSORS_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_SENSORS_TM_ID); } - else if(arg == "MAV_PIN_OBS_TM_ID"){ + else if(arg == "MAV_PIN_OBS_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_PIN_OBS_TM_ID); - } - else if(arg == "MAV_TASK_STATS_TM_ID"){ + } else if(arg == "MAV_TASK_STATS_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_TASK_STATS_TM_ID); - } - else if(arg == "MAV_ABK_TM_ID"){ + } else if(arg == "MAV_ABK_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_ABK_TM_ID); - } - else if(arg == "MAV_NAS_TM_ID"){ + } else if(arg == "MAV_NAS_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_NAS_TM_ID); - } - else if(arg == "MAV_MS5803_TM_ID"){ + } else if(arg == "MAV_MS5803_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_MS5803_TM_ID); - } - else if(arg == "MAV_BMX160_TM_ID"){ + } else if(arg == "MAV_BMX160_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_BMX160_TM_ID); - } - else if(arg == "MAV_LIS3MDL_TM_ID"){ + } else if(arg == "MAV_LIS3MDL_TM_ID") { encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_LIS3MDL_TM_ID); } -// else if(arg == "MAV_STRAIN_BOARD_TM_ID"){ -// encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_STRAIN_BOARD_TM_ID); -// } + // else if(arg == "MAV_STRAIN_BOARD_TM_ID"){ + // encoded_mvl_msg = mavlinkCommandAdapter.encode_TELEMETRY_REQUEST_TC(MAV_STRAIN_BOARD_TM_ID); + // } encoded_mvl_msg.sysid = validSysid; encoded_mvl_msg.compid = validCompid; - if(serialPort.isOpen()){ + if(serialPort.isOpen()) { mavlinkCommandAdapter.send(encoded_mvl_msg); } } diff --git a/Modules/Mavlink/mavlinkmodule.h b/Modules/Mavlink/mavlinkmodule.h index 654299a9d89fb90e2fa468412af24eb24b9ed423..ecfd395a0e5b05e05bcf15d69d77a96de04c7709 100644 --- a/Modules/Mavlink/mavlinkmodule.h +++ b/Modules/Mavlink/mavlinkmodule.h @@ -18,11 +18,10 @@ namespace Ui { class MavlinkModule; } -class MavlinkModule : public DefaultModule -{ +class MavlinkModule : public DefaultModule { Q_OBJECT -public: + public: explicit MavlinkModule(QWidget *parent = nullptr); ~MavlinkModule(); @@ -33,14 +32,14 @@ public: void onCommandReceived(const ModuleMessage &msg); void onTelemetryRequestReceived(const ModuleMessage &msg); -public slots: + public slots: void onStartClicked(); void onStopClicked(); void onMsgReceived(const ModuleMessage &msg); void onLinkQualityIndicatorClicked(bool checked); void onLinkQualityTimerTick(); -protected: + protected: void connectUiSlots(); void initializeSerialPortView(); @@ -55,17 +54,17 @@ protected: void updateLinkSignalIndicator(int msgArrived, float ratio); void onOpenLogFolderClick(); -private slots: + private slots: void onSerialPortIndexChanged(int index); bool startReadingOnSerialPort(); void onStartStreamToggled(bool state); -private: + private: Ui::MavlinkModule *ui; -// QCustomPlot graphCentralView; -// QCPGraph *linkGraph = nullptr; + // QCustomPlot graphCentralView; + // QCPGraph *linkGraph = nullptr; ToggleButton startSerialStreamToggleButton; QString dateFormat = "HH:mm:ss\n(zzz)"; MavlinkReader mavlinkReader; diff --git a/Modules/Mavlink/mavlinkrocketmsgtestingmodule.cpp b/Modules/Mavlink/mavlinkrocketmsgtestingmodule.cpp index 2bd289145b674c075b13e6873d69e6d82ec65d24..8ae934ad6e4451cece737a7e0c2a15d9cc5b01d1 100644 --- a/Modules/Mavlink/mavlinkrocketmsgtestingmodule.cpp +++ b/Modules/Mavlink/mavlinkrocketmsgtestingmodule.cpp @@ -10,70 +10,61 @@ #include "mavlinkversionheader.h" #include "mavlinkreader.h" -MavlinkRocketMsgTestingModule::MavlinkRocketMsgTestingModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::MavlinkRocketMsgTestingModule) -{ +MavlinkRocketMsgTestingModule::MavlinkRocketMsgTestingModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::MavlinkRocketMsgTestingModule) { ui->setupUi(this); defaultContextMenuSetup(); init(); } -MavlinkRocketMsgTestingModule::~MavlinkRocketMsgTestingModule() -{ +MavlinkRocketMsgTestingModule::~MavlinkRocketMsgTestingModule() { delete ui; // This delete all the radiobutton } -void MavlinkRocketMsgTestingModule::init() -{ +void MavlinkRocketMsgTestingModule::init() { ui->lineEdit_mavlinkInputFilePath->setText(defaultMavlinkFileName); connect(ui->pushButton_sendMsg, &QPushButton::clicked, this, &MavlinkRocketMsgTestingModule::onSendMsgClicked); connect(ui->pushButton_loadInputFile, &QPushButton::clicked, this, &MavlinkRocketMsgTestingModule::onLoadFileClicked); } -QWidget *MavlinkRocketMsgTestingModule::toWidget() -{ +QWidget *MavlinkRocketMsgTestingModule::toWidget() { return this; } -XmlObject MavlinkRocketMsgTestingModule::toXmlObject() -{ +XmlObject MavlinkRocketMsgTestingModule::toXmlObject() { return XmlObject(getName(ModuleId::MAVLINK_RCK_TESTING)); } -void MavlinkRocketMsgTestingModule::fromXmlObject(const XmlObject &xmlObject) -{ +void MavlinkRocketMsgTestingModule::fromXmlObject(const XmlObject &xmlObject) { Q_UNUSED(xmlObject); } -void MavlinkRocketMsgTestingModule::createNewButton(const QString &txt, QLayout *container) -{ +void MavlinkRocketMsgTestingModule::createNewButton(const QString &txt, QLayout *container) { QRadioButton *radiobutton = new QRadioButton(txt); connectRadioButton(radiobutton); container->addWidget(radiobutton); } -void MavlinkRocketMsgTestingModule::connectRadioButton(QRadioButton *radiobutton) -{ - connect(radiobutton, &QRadioButton::clicked, this, [this, radiobutton](){ +void MavlinkRocketMsgTestingModule::connectRadioButton(QRadioButton *radiobutton) { + connect(radiobutton, &QRadioButton::clicked, this, [this, radiobutton]() { this->onRadioButtonClicked(radiobutton); }); } -void MavlinkRocketMsgTestingModule::setSelectedMsg(const QString &msgName) -{ - if(currentMsgView != nullptr){ +void MavlinkRocketMsgTestingModule::setSelectedMsg(const QString &msgName) { + if(currentMsgView != nullptr) { delete currentMsgView; currentMsgView = nullptr; } - QList<XmlObject*> clickedMsg = mavlinkMsgDefinitionFile.deepSearchObjects([this, msgName](const XmlObject *obj){ + QList<XmlObject*> clickedMsg = mavlinkMsgDefinitionFile.deepSearchObjects([this, msgName](const XmlObject * obj) { QString name = obj->getAttribute(xmlFieldName); - if(name == msgName){ + if(name == msgName) { return true; } return false; }); - if(clickedMsg.count()==1){ + if(clickedMsg.count() == 1) { currentMsgView = new MsgView(clickedMsg[0], msgName); ui->details_layout->insertWidget(0, currentMsgView->getView()); } @@ -81,68 +72,61 @@ void MavlinkRocketMsgTestingModule::setSelectedMsg(const QString &msgName) } -void MavlinkRocketMsgTestingModule::createViewFromXmlMessages(QList<XmlObject *> messagesList) -{ - for (int i = 0; i < messagesList.count(); i++ ) { +void MavlinkRocketMsgTestingModule::createViewFromXmlMessages(QList<XmlObject *> messagesList) { + for (int i = 0; i < messagesList.count(); i++) { XmlObject *xmlObj = messagesList[i]; QString msgType = xmlObj->getAttribute(xmlFieldType).trimmed(); QGroupBox* gbox = getOrCreateGBox(msgType); QString name = xmlObj->getAttribute(xmlFieldName).trimmed(); - if( name != ""){ + if(name != "") { createNewButton(xmlObj->getAttribute(xmlFieldName), gbox->layout()); } } } -QGroupBox* MavlinkRocketMsgTestingModule::getOrCreateGBox(const QString &title) -{ +QGroupBox* MavlinkRocketMsgTestingModule::getOrCreateGBox(const QString &title) { QGroupBox *gBox = nullptr; - if(title != "" && !viewGroupList.contains(title)){ + if(title != "" && !viewGroupList.contains(title)) { gBox = new QGroupBox(title); viewGroupList[title] = gBox; ui->msg_layout->insertWidget(0, gBox); gBox->setLayout(new QVBoxLayout()); - } - else if(viewGroupList.contains(title)){ + } else if(viewGroupList.contains(title)) { gBox = viewGroupList[title]; } return gBox; } -QString MavlinkRocketMsgTestingModule::getCurrentTopic() const -{ +QString MavlinkRocketMsgTestingModule::getCurrentTopic() const { return ui->lineEdit_outputTopic->text(); } -void MavlinkRocketMsgTestingModule::onRadioButtonClicked(QRadioButton *radiobutton) -{ +void MavlinkRocketMsgTestingModule::onRadioButtonClicked(QRadioButton *radiobutton) { setSelectedMsg(radiobutton->text()); } -void MavlinkRocketMsgTestingModule::clearView() -{ - if(currentMsgView != nullptr){ +void MavlinkRocketMsgTestingModule::clearView() { + if(currentMsgView != nullptr) { delete currentMsgView; currentMsgView = nullptr; } QMapIterator<QString, QGroupBox*> i(viewGroupList); QList<QGroupBox*> groupBox = viewGroupList.values(); - for(int i = 0; i < groupBox.count(); i++){ + for(int i = 0; i < groupBox.count(); i++) { delete groupBox[i]; } viewGroupList.clear(); } -void MavlinkRocketMsgTestingModule::onLoadFileClicked() -{ +void MavlinkRocketMsgTestingModule::onLoadFileClicked() { clearView(); QString filePath = SkywardHubStrings::defaultConfigurationFolder + "/" + ui->lineEdit_mavlinkInputFilePath->text().trimmed(); - if (mavlinkMsgDefinitionFile.loadFromFile(filePath)){ - QList<XmlObject*> xmlMessages = mavlinkMsgDefinitionFile.deepSearchObjects([this](const XmlObject *msg){ - if(msg->getObjectName() == xmlChildName){ + if (mavlinkMsgDefinitionFile.loadFromFile(filePath)) { + QList<XmlObject*> xmlMessages = mavlinkMsgDefinitionFile.deepSearchObjects([this](const XmlObject * msg) { + if(msg->getObjectName() == xmlChildName) { return true; } return false; @@ -152,10 +136,9 @@ void MavlinkRocketMsgTestingModule::onLoadFileClicked() } } -XmlObject MavlinkRocketMsgTestingModule::msgToXml() const -{ +XmlObject MavlinkRocketMsgTestingModule::msgToXml() const { XmlObject xmlMsg; - if(currentMsgView != nullptr){ + if(currentMsgView != nullptr) { xmlMsg.setObjectName(currentMsgView->getName()); auto fields = currentMsgView->getFields(); QMapIterator<QString, QLineEdit *> i(fields); @@ -167,39 +150,37 @@ XmlObject MavlinkRocketMsgTestingModule::msgToXml() const return xmlMsg; } -void MavlinkRocketMsgTestingModule::onSendMsgClicked() -{ - if(currentMsgView != nullptr){ +void MavlinkRocketMsgTestingModule::onSendMsgClicked() { + if(currentMsgView != nullptr) { XmlObject xmlMsg = msgToXml(); testMavlinkEncodeAndDecode(xmlMsg); } } -bool MavlinkRocketMsgTestingModule::testMavlinkEncodeAndDecode(const XmlObject &xmlMsg) -{ +bool MavlinkRocketMsgTestingModule::testMavlinkEncodeAndDecode(const XmlObject &xmlMsg) { // Test mavlink msg encoding mavlink_message_t mavMsg; bool ok = false; ok = MavlinkCommandAdapter().produceMsgFromXml(xmlMsg, &mavMsg); // Test of buffer writing -// if(MavlinkCommandAdapter().produceMsgFromXml(xmlMsg, &mavMsg)){ -// unsigned char buff[sizeof(mavlink_message_t)+1]; -// int msg_len = mavlink_msg_to_send_buffer(buff, &mavMsg); -// ok = msg_len > 0; -// } + // if(MavlinkCommandAdapter().produceMsgFromXml(xmlMsg, &mavMsg)){ + // unsigned char buff[sizeof(mavlink_message_t)+1]; + // int msg_len = mavlink_msg_to_send_buffer(buff, &mavMsg); + // ok = msg_len > 0; + // } // Test mavlink msg decoding - if(ok){ + if(ok) { MavlinkReader mavlinkReader; - QList<ModuleMessage> msgProduced = mavlinkReader.parseMavlinkMsg(&mavMsg); + QList<ModuleMessage> msgProduced = mavlinkReader.parseMavlinkMsg(mavMsg); QString currentTopic = getCurrentTopic().trimmed(); for (int i = 0; i < msgProduced.count() ; i++ ) { getCore()->getModuleMessagesBroker()->publish(msgProduced[i]); - if(currentTopic != ""){ + if(currentTopic != "") { msgProduced[i].setTopic(currentTopic); getCore()->getModuleMessagesBroker()->publish(msgProduced[i]); } @@ -233,40 +214,36 @@ bool MavlinkRocketMsgTestingModule::testMavlinkEncodeAndDecode(const XmlObject & // _______________________________________________ MsgView ___________________________________________________ -MsgView::MsgView(const XmlObject *obj, QString name) : QObject() -{ +MsgView::MsgView(const XmlObject *obj, QString name) : QObject() { this->name = name; bool ok; id = obj->getAttribute(xmlFieldId).trimmed().toInt(&ok); - if(!ok){ + if(!ok) { id = 0; } - for(int i = 0; i < obj->childCount(); i++){ + for(int i = 0; i < obj->childCount(); i++) { XmlObject fieldXml = obj->childAt(i); - if(fieldXml.getObjectName() == xmlFieldElementName){ -// auto i = fieldXml.attributesIterator(); -// while(i.hasNext()){ -// auto pair = i.next(); -// } + if(fieldXml.getObjectName() == xmlFieldElementName) { + // auto i = fieldXml.attributesIterator(); + // while(i.hasNext()){ + // auto pair = i.next(); + // } QString fieldName = fieldXml.getAttribute(xmlFieldName); QLineEdit* lineEdit = new QLineEdit(); fields[fieldName] = lineEdit; - } - else if(fieldXml.getObjectName() == xmlFieldDescr) { + } else if(fieldXml.getObjectName() == xmlFieldDescr) { description = fieldXml.getTextValue(); } } } -MsgView::~MsgView() -{ +MsgView::~MsgView() { delete view; } -QWidget *MsgView::getView() -{ - if(view == nullptr){ +QWidget *MsgView::getView() { + if(view == nullptr) { view = new QWidget(); QVBoxLayout *layout = new QVBoxLayout(); view->setLayout(layout); @@ -298,13 +275,11 @@ QWidget *MsgView::getView() return view; } -QString MsgView::getName() const -{ +QString MsgView::getName() const { return name; } -QMap<QString, QLineEdit *> MsgView::getFields() const -{ +QMap<QString, QLineEdit *> MsgView::getFields() const { return fields; } diff --git a/Modules/Mavlink/mavlinkrocketmsgtestingmodule.h b/Modules/Mavlink/mavlinkrocketmsgtestingmodule.h index 63ac08eee09629b31c3be63958834cceff4a0308..88dbd633f7e728c3b857458a42a5319cef9235cb 100644 --- a/Modules/Mavlink/mavlinkrocketmsgtestingmodule.h +++ b/Modules/Mavlink/mavlinkrocketmsgtestingmodule.h @@ -12,11 +12,10 @@ class MavlinkRocketMsgTestingModule; } -class MsgView : public QObject -{ +class MsgView : public QObject { Q_OBJECT -public: + public: MsgView(const XmlObject *obj, QString name); ~MsgView(); QWidget *getView(); @@ -25,7 +24,7 @@ public: QMap<QString, QLineEdit *> getFields() const; -private: + private: QString description; QString name; int id; @@ -39,11 +38,10 @@ private: }; -class MavlinkRocketMsgTestingModule : public DefaultModule -{ +class MavlinkRocketMsgTestingModule : public DefaultModule { Q_OBJECT -public: + public: explicit MavlinkRocketMsgTestingModule(QWidget *parent = nullptr); ~MavlinkRocketMsgTestingModule(); @@ -52,7 +50,7 @@ public: XmlObject toXmlObject() override; void fromXmlObject(const XmlObject &xmlObject) override; -protected: + protected: void init(); void createNewButton(const QString &txt, QLayout *container); void connectRadioButton(QRadioButton *radiobutton); @@ -60,17 +58,17 @@ protected: void onSendMsgClicked(); void onLoadFileClicked(); bool testMavlinkEncodeAndDecode(const XmlObject &xmlMsg); -// mavlink_message_t genericPack(string funcName, char *params[]); + // mavlink_message_t genericPack(string funcName, char *params[]); QString getCurrentTopic() const; void createViewFromXmlMessages(QList<XmlObject*> messagesList); QGroupBox* getOrCreateGBox(const QString &title); void clearView(); XmlObject msgToXml() const; -protected slots: + protected slots: void onRadioButtonClicked(QRadioButton *radiobutton); -private: + private: Ui::MavlinkRocketMsgTestingModule *ui; MsgView *currentMsgView = nullptr; diff --git a/Modules/Mavlink/mavlinkwriter.cpp b/Modules/Mavlink/mavlinkwriter.cpp index 54cbafc7d83188675d4b0156591c6efe179975d5..de6db6f176945897bf13f61ecde504b7b6b27a9e 100644 --- a/Modules/Mavlink/mavlinkwriter.cpp +++ b/Modules/Mavlink/mavlinkwriter.cpp @@ -3,37 +3,33 @@ #include <chrono> #include <QDebug> -MavlinkWriter::MavlinkWriter() -{ +MavlinkWriter::MavlinkWriter() { } -void MavlinkWriter::startAsyncWrite(mavlink_message_t msgToSend) -{ +void MavlinkWriter::startAsyncWrite(mavlink_message_t msgToSend) { this->start(); this->msgToSend = msgToSend; } -void MavlinkWriter::setPort(QSerialPort* port){ +void MavlinkWriter::setPort(QSerialPort* port) { serial = port; } -void MavlinkWriter::writeMsg(mavlink_message_t *msgToSend) -{ +void MavlinkWriter::writeMsg(mavlink_message_t *msgToSend) { mtx.lock(); - unsigned char buff[sizeof(mavlink_message_t)+1]; + unsigned char buff[sizeof(mavlink_message_t) +1]; int msg_len = mavlink_msg_to_send_buffer(buff, msgToSend); - if(serial->write(reinterpret_cast<char*>(buff), msg_len) == -1){ + if(serial->write(reinterpret_cast<char*>(buff), msg_len) == -1) { qDebug() << "MavlinkWriter: Error, writeMsg serial port error"; } mtx.unlock(); } -void MavlinkWriter::run() -{ - if(serial != nullptr){ +void MavlinkWriter::run() { + if(serial != nullptr) { writeMsg(&msgToSend); } } diff --git a/Modules/Mavlink/mavlinkwriter.h b/Modules/Mavlink/mavlinkwriter.h index 9ecb757d4bd57844d1f06ce6671fc467b6d68edb..6b2e2884db4f4ae534decfac4bba38fb2468fcf0 100644 --- a/Modules/Mavlink/mavlinkwriter.h +++ b/Modules/Mavlink/mavlinkwriter.h @@ -6,22 +6,21 @@ #include <QSerialPort> #include "mavlinkversionheader.h" -class MavlinkWriter : public QThread -{ +class MavlinkWriter : public QThread { Q_OBJECT -public: + public: MavlinkWriter(); void startAsyncWrite(mavlink_message_t msgToSend); void setPort(QSerialPort* port); -protected: + protected: void writeMsg(mavlink_message_t *msgToSend); void run(); -private: + private: QSerialPort *serial = nullptr; QMutex mtx; diff --git a/Modules/MessageViewer/messagesviewermodule.cpp b/Modules/MessageViewer/messagesviewermodule.cpp index 320c2b08eeb01917081f1d6c16ecb63963723e72..0057e003a67b9249dc00f9fcf9d581d578d46fd5 100644 --- a/Modules/MessageViewer/messagesviewermodule.cpp +++ b/Modules/MessageViewer/messagesviewermodule.cpp @@ -5,94 +5,84 @@ #include "Modules/skywardhubstrings.h" #include <QTableWidgetItem> -MessagesViewerModule::MessagesViewerModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::MessagesViewerModule) -{ +MessagesViewerModule::MessagesViewerModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::MessagesViewerModule) { ui->setupUi(this); defaultContextMenuSetup(); - getCore()->getModuleMessagesBroker()->subscribe(SkywardHubStrings::commandsTopic, this, [this](const ModuleMessage &msg){ + getCore()->getModuleMessagesBroker()->subscribe(SkywardHubStrings::commandsTopic, this, [this](const ModuleMessage & msg) { addMsgSent(msg); }); - getCore()->getModuleMessagesBroker()->subscribe(ackTopic, this, [this](const ModuleMessage &msg){ + getCore()->getModuleMessagesBroker()->subscribe(ackTopic, this, [this](const ModuleMessage & msg) { handleAck(msg); }); } -MessagesViewerModule::~MessagesViewerModule() -{ +MessagesViewerModule::~MessagesViewerModule() { delete ui; } -QWidget *MessagesViewerModule::toWidget() -{ +QWidget *MessagesViewerModule::toWidget() { return this; } -XmlObject MessagesViewerModule::toXmlObject() -{ +XmlObject MessagesViewerModule::toXmlObject() { return XmlObject(getName(ModuleId::MESSAGEVIEWER)); } -void MessagesViewerModule::fromXmlObject(const XmlObject &xmlObject) -{ +void MessagesViewerModule::fromXmlObject(const XmlObject &xmlObject) { Q_UNUSED(xmlObject); } -void MessagesViewerModule::addMsgSent(const ModuleMessage &msg) -{ +void MessagesViewerModule::addMsgSent(const ModuleMessage &msg) { int row = updateVerticalHeaders(msg); int column = 0; QString msgName = computeMsgName(msg); QTableWidgetItem *newItem = new QTableWidgetItem(msgName); newItem->setBackground(QBrush(QColor(255, 153, 51))); - newItem->setForeground(QBrush(QColor(0,0,0))); - ui->tableWidget->setItem(row,column,newItem); - registerMessage(newItem,msg); + newItem->setForeground(QBrush(QColor(0, 0, 0))); + ui->tableWidget->setItem(row, column, newItem); + registerMessage(newItem, msg); } -QString MessagesViewerModule::computeMsgName(const ModuleMessage &msg) -{ - return msg.originalTopic().replace(SkywardHubStrings::commandsTopic+"/", ""); +QString MessagesViewerModule::computeMsgName(const ModuleMessage &msg) { + return msg.originalTopic().replace(SkywardHubStrings::commandsTopic + "/", ""); } -void MessagesViewerModule::handleAck(const ModuleMessage &ack) -{ - for(int i=0; i < messages.count(); i++){ +void MessagesViewerModule::handleAck(const ModuleMessage &ack) { + for(int i = 0; i < messages.count(); i++) { ModuleMessage msg = messages[i].getMsg(); // If the two messages have the same ack and sequence number if(msg.getOptions().getAttribute(SkywardHubStrings::msgIdField) == // THE NAMES OF THE FIELDS SHOULD BE LOADED FROM THE MESSAGES DEFINITION XML - ack.getOptions().getAttribute(SkywardHubStrings::msgIdField)){ + ack.getOptions().getAttribute(SkywardHubStrings::msgIdField)) { if(msg.getOptions().getAttribute(SkywardHubStrings::msgSequenceNumberField) == - ack.getOptions().getAttribute(SkywardHubStrings::msgSequenceNumberField)){ + ack.getOptions().getAttribute(SkywardHubStrings::msgSequenceNumberField)) { messages[i].getItem()->setBackground(QBrush(QColor(0, 255, 255))); } } } } -int MessagesViewerModule::updateVerticalHeaders(const ModuleMessage &msg) -{ +int MessagesViewerModule::updateVerticalHeaders(const ModuleMessage &msg) { int row = 0; // Insert on top QString headerTxt = msg.timestamp().toString("hh.mm.ss (zzz)"); ui->tableWidget->insertRow(row); QTableWidgetItem *header = new QTableWidgetItem(headerTxt); - ui->tableWidget->setVerticalHeaderItem(row,header); + ui->tableWidget->setVerticalHeaderItem(row, header); int rowCount = ui->tableWidget->rowCount(); - if( rowCount > maxSize && rowCount > 0){ + if( rowCount > maxSize && rowCount > 0) { ui->tableWidget->removeRow(rowCount - 1); } return row; } -void MessagesViewerModule::registerMessage(QTableWidgetItem *item, const ModuleMessage &msg) -{ +void MessagesViewerModule::registerMessage(QTableWidgetItem *item, const ModuleMessage &msg) { messages.prepend(MessageLog(item, msg)); - if(messages.count() > maxSize){ + if(messages.count() > maxSize) { messages.removeLast(); } } @@ -101,28 +91,23 @@ void MessagesViewerModule::registerMessage(QTableWidgetItem *item, const ModuleM // ____________________ MESSAGE LOG CLASS _______________________________ -MessageLog::MessageLog(QTableWidgetItem *item, const ModuleMessage &msg) -{ +MessageLog::MessageLog(QTableWidgetItem *item, const ModuleMessage &msg) { setItem(item); setMsg(msg); } -QTableWidgetItem *MessageLog::getItem() const -{ +QTableWidgetItem *MessageLog::getItem() const { return item; } -void MessageLog::setItem(QTableWidgetItem *value) -{ +void MessageLog::setItem(QTableWidgetItem *value) { item = value; } -ModuleMessage MessageLog::getMsg() const -{ +ModuleMessage MessageLog::getMsg() const { return msg; } -void MessageLog::setMsg(const ModuleMessage &value) -{ +void MessageLog::setMsg(const ModuleMessage &value) { msg = value; } diff --git a/Modules/MessageViewer/messagesviewermodule.h b/Modules/MessageViewer/messagesviewermodule.h index 66fb92c6beac15e76b651193140cafebc9fde8a8..e27b3620075c9c506b156beb6830f9f6d1088319 100644 --- a/Modules/MessageViewer/messagesviewermodule.h +++ b/Modules/MessageViewer/messagesviewermodule.h @@ -8,9 +8,9 @@ class QTableWidgetItem; -class MessageLog{ +class MessageLog { -public: + public: explicit MessageLog(QTableWidgetItem *item, const ModuleMessage &msg); QTableWidgetItem *getItem() const; @@ -19,7 +19,7 @@ public: ModuleMessage getMsg() const; void setMsg(const ModuleMessage &value); -private: + private: QTableWidgetItem *item = nullptr; ModuleMessage msg; }; @@ -29,11 +29,10 @@ namespace Ui { class MessagesViewerModule; } -class MessagesViewerModule : public DefaultModule -{ +class MessagesViewerModule : public DefaultModule { Q_OBJECT -public: + public: explicit MessagesViewerModule(QWidget *parent = nullptr); ~MessagesViewerModule(); @@ -45,12 +44,12 @@ public: void addMsgSent(const ModuleMessage &msg); void handleAck(const ModuleMessage &ack); -protected: + protected: int updateVerticalHeaders(const ModuleMessage &msg); void registerMessage(QTableWidgetItem *item, const ModuleMessage &msg); QString computeMsgName(const ModuleMessage &msg); -private: + private: Ui::MessagesViewerModule *ui; QList<MessageLog> messages; QString ackTopic = SkywardHubStrings::mavlink_received_msg_ACK_topic; diff --git a/Modules/ScrollArea/scrollareamodule.cpp b/Modules/ScrollArea/scrollareamodule.cpp index 6b8928ca9b1cbf003e923990cce484e57732f503..9f926042d0f44fb6859933f613986e6a36c03c5e 100644 --- a/Modules/ScrollArea/scrollareamodule.cpp +++ b/Modules/ScrollArea/scrollareamodule.cpp @@ -5,82 +5,70 @@ #include "Core/modulesmanager.h" #include "Core/moduleeventshandler.h" -ScrollAreaModule::ScrollAreaModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::ScrollAreaModule) -{ +ScrollAreaModule::ScrollAreaModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::ScrollAreaModule) { ui->setupUi(this); defaultContextMenuSetup(); } -ScrollAreaModule::~ScrollAreaModule() -{ +ScrollAreaModule::~ScrollAreaModule() { clearModuleList(); delete ui; } -QWidget *ScrollAreaModule::toWidget() -{ +QWidget *ScrollAreaModule::toWidget() { return this; } -XmlObject ScrollAreaModule::toXmlObject() -{ +XmlObject ScrollAreaModule::toXmlObject() { return XmlObject(getName(ModuleId::SCROLLAREA)); } -void ScrollAreaModule::fromXmlObject(const XmlObject &xmlObject) -{ +void ScrollAreaModule::fromXmlObject(const XmlObject &xmlObject) { Q_UNUSED(xmlObject); } -void ScrollAreaModule::clearModuleList() -{ +void ScrollAreaModule::clearModuleList() { QList<Module*> list = this->modulesList; - for(int i = 0; i <list.count(); i++){ + for(int i = 0; i < list.count(); i++) { delete list[i]; } modulesList.clear(); } -void ScrollAreaModule::onModuleBeforeDelete(Module *module) -{ - if(module != nullptr){ +void ScrollAreaModule::onModuleBeforeDelete(Module *module) { + if(module != nullptr) { modulesList.removeAll(module); } } -void ScrollAreaModule::addCustomActionsToMenu() -{ +void ScrollAreaModule::addCustomActionsToMenu() { QAction* addItem = new QAction("Add Item"); - connect(addItem, &QAction::triggered,this, &ScrollAreaModule::onAddItemClicked); + connect(addItem, &QAction::triggered, this, &ScrollAreaModule::onAddItemClicked); addActionToMenu(addItem); } -void ScrollAreaModule::onAddItemClicked() -{ +void ScrollAreaModule::onAddItemClicked() { Module* module = getCore()->getModulesManager()->instantiateDefaultModule(); addModule(module); } -void ScrollAreaModule::addModule(Module *module, int position) -{ +void ScrollAreaModule::addModule(Module *module, int position) { ui->scrollArea_mainLayout->insertWidget(position, module->toWidget()); - if(position < modulesList.count()){ + if(position < modulesList.count()) { modulesList.insert(position, module); - } - else{ + } else { modulesList.append(module); } - connect(module->getModuleEventsHandler(),&ModuleEventsHandler::beforeDelete, this, &ScrollAreaModule::onModuleBeforeDelete); - connect(module->getModuleEventsHandler(),&ModuleEventsHandler::contextMenuRequest,this,&ScrollAreaModule::onSkywardHubContextMenuRequested); - connect(module->getModuleEventsHandler(),&ModuleEventsHandler::replaceMeWith, [this](Module* sender, Module* newModule){ - this->replace(sender,newModule); + connect(module->getModuleEventsHandler(), &ModuleEventsHandler::beforeDelete, this, &ScrollAreaModule::onModuleBeforeDelete); + connect(module->getModuleEventsHandler(), &ModuleEventsHandler::contextMenuRequest, this, &ScrollAreaModule::onSkywardHubContextMenuRequested); + connect(module->getModuleEventsHandler(), &ModuleEventsHandler::replaceMeWith, [this](Module * sender, Module * newModule) { + this->replace(sender, newModule); }); } -void ScrollAreaModule::replace(Module *oldModule, Module *newModule) -{ +void ScrollAreaModule::replace(Module *oldModule, Module *newModule) { int indexOfModule = modulesList.indexOf(oldModule); if(indexOfModule < 0) return; diff --git a/Modules/ScrollArea/scrollareamodule.h b/Modules/ScrollArea/scrollareamodule.h index 84bd332163f22e964d2eaa13522024f28f681a3e..4b9038c552952ad614231c0029326016fa7e07d6 100644 --- a/Modules/ScrollArea/scrollareamodule.h +++ b/Modules/ScrollArea/scrollareamodule.h @@ -7,11 +7,10 @@ namespace Ui { class ScrollAreaModule; } -class ScrollAreaModule : public DefaultModule -{ +class ScrollAreaModule : public DefaultModule { Q_OBJECT -public: + public: explicit ScrollAreaModule(QWidget *parent = nullptr); ~ScrollAreaModule(); @@ -19,7 +18,7 @@ public: XmlObject toXmlObject() override; void fromXmlObject(const XmlObject &xmlObject) override; -protected: + protected: void addCustomActionsToMenu() override; void onAddItemClicked(); @@ -28,7 +27,7 @@ protected: void addModule(Module *module, int position = 0); void replace(Module *oldModule, Module *newModule); -private: + private: Ui::ScrollAreaModule *ui; QList<Module*> modulesList; }; diff --git a/Modules/SkywardHub/deployer.cpp b/Modules/SkywardHub/deployer.cpp index b4c54cf3c8c4cb1f1f786f34e92b0b44856f4b17..e9d8b988f35fab6ca338379cf0550b18f4787c13 100644 --- a/Modules/SkywardHub/deployer.cpp +++ b/Modules/SkywardHub/deployer.cpp @@ -6,16 +6,14 @@ #include <QDir> -Deployer::Deployer() -{ +Deployer::Deployer() { } -bool Deployer::deploy(const QList<QString> &activeModules) -{ +bool Deployer::deploy(const QList<QString> &activeModules) { setupModulesFiles(activeModules); - if(!deployerPicker.pickDirectory()){ + if(!deployerPicker.pickDirectory()) { return false; } @@ -35,13 +33,11 @@ bool Deployer::deploy(const QList<QString> &activeModules) return showResultMessage(); } -QString Deployer::getDeployReleaseFolder() const -{ +QString Deployer::getDeployReleaseFolder() const { return deployDir + "/" + newCopyReleaseFolderName; } -void Deployer::setupModulesFiles(const QList<QString> &activeModules) -{ +void Deployer::setupModulesFiles(const QList<QString> &activeModules) { modulesFiles.clear(); modulesFiles.append("SOURCES"); modulesFiles.append("HEADERS"); @@ -74,8 +70,7 @@ void Deployer::setupModulesFiles(const QList<QString> &activeModules) // _________________________________ PRO FILE ______________________________________________________ -void Deployer::produceNewProFile() -{ +void Deployer::produceNewProFile() { QString filePath = getNewProFilePath(); QList <QString> proFile = loadFile(filePath); QList <QString> newProFile = makeNewProFile(proFile); @@ -85,20 +80,18 @@ void Deployer::produceNewProFile() -QList<QString> Deployer::makeNewProFile(const QList<QString> &oldProFile) const -{ +QList<QString> Deployer::makeNewProFile(const QList<QString> &oldProFile) const { QList<QString> newProFile; bool copy = true; - for(QString line : oldProFile){ - if(line.contains(proFileEndCopyTag)){ + for(QString line : oldProFile) { + if(line.contains(proFileEndCopyTag)) { copy = false; - } - else if(line.contains(proFileRestartCopyTag)){ + } else if(line.contains(proFileRestartCopyTag)) { copy = true; } - if(copy || line.isEmpty() || checkIfFilesIsActive(line)){ + if(copy || line.isEmpty() || checkIfFilesIsActive(line)) { newProFile.append(line); } } @@ -106,10 +99,9 @@ QList<QString> Deployer::makeNewProFile(const QList<QString> &oldProFile) const return newProFile; } -bool Deployer::checkIfFilesIsActive(const QString &line) const -{ - for(QString file : modulesFiles){ - if(line.contains(file)){ +bool Deployer::checkIfFilesIsActive(const QString &line) const { + for(QString file : modulesFiles) { + if(line.contains(file)) { return true; } } @@ -119,25 +111,22 @@ bool Deployer::checkIfFilesIsActive(const QString &line) const // _____________________________ modules list.cpp FILE ______________________________________________________ -void Deployer::produceNewModuleListFile() -{ +void Deployer::produceNewModuleListFile() { QString filePath = getModuleListFilePath(); QList <QString> oldModulesFile = loadFile(filePath); QList <QString> newModulesFile = makeNewModulesListFile(oldModulesFile); writeFile(newModulesFile, filePath); } -QList<QString> Deployer::makeNewModulesListFile(const QList<QString> &oldModulesListFile) const -{ +QList<QString> Deployer::makeNewModulesListFile(const QList<QString> &oldModulesListFile) const { QList<QString> newFile; - for(QString line : oldModulesListFile){ - if(line.contains("#include")){ - if(checkIfFilesIsActive(line)){ + for(QString line : oldModulesListFile) { + if(line.contains("#include")) { + if(checkIfFilesIsActive(line)) { newFile.append(line); } - } - else{ + } else { newFile.append(line); } } @@ -149,20 +138,19 @@ QList<QString> Deployer::makeNewModulesListFile(const QList<QString> &oldModules // _____________________________ BAT FILE ___________________________________________________________________ -QString Deployer::writeBatFile() const -{ - QString batfile_header = "set PATH=" + mingw81_64_bin + ";" + mingw810_64_bin+ ";%PATH%\n" - "cd /D " + mingw81_64_bin + "\n"; - QString batfile_core = "cd "+ deployDir + "\n" - "qmake -config release " + getNewProFilePath() + "\n" - "mingw32-make.exe -f Makefile.Release\n" - "mingw32-make.exe -f Makefile.Release clean\n" - "windeployqt release/."; +QString Deployer::writeBatFile() const { + QString batfile_header = "set PATH=" + mingw81_64_bin + ";" + mingw810_64_bin + ";%PATH%\n" + "cd /D " + mingw81_64_bin + "\n"; + QString batfile_core = "cd " + deployDir + "\n" + "qmake -config release " + getNewProFilePath() + "\n" + "mingw32-make.exe -f Makefile.Release\n" + "mingw32-make.exe -f Makefile.Release clean\n" + "windeployqt release/."; QString batfile_path = getNewSourceDir() + "\\deployer.bat"; QFile file(batfile_path); - if(file.open(QIODevice::WriteOnly)){ - QTextStream(&file) <<batfile_header<<batfile_core; + if(file.open(QIODevice::WriteOnly)) { + QTextStream(&file) << batfile_header << batfile_core; file.close(); return batfile_path; } @@ -172,8 +160,7 @@ QString Deployer::writeBatFile() const // __________________________________________________________________________________________________________ -bool Deployer::isDeployCompletedSuccessfully () -{ +bool Deployer::isDeployCompletedSuccessfully () { QDir dir(getDeployReleaseFolder()); if (dir.exists() && !dir.isEmpty()) return true; @@ -182,15 +169,14 @@ bool Deployer::isDeployCompletedSuccessfully () } -bool Deployer::showResultMessage() -{ +bool Deployer::showResultMessage() { QMessageBox confirmMsg; - if(isDeployCompletedSuccessfully()){ + if(isDeployCompletedSuccessfully()) { confirmMsg.setText("Deploy completed successfully"); confirmMsg.exec(); return true; - }else{ + } else { QString text = "Deployment Error"; QString infoMsg = "Something went wrong. \n\nCheck if the new modules specify correctly all the needed files."; confirmMsg.warning(nullptr, text, infoMsg); @@ -199,12 +185,11 @@ bool Deployer::showResultMessage() } } -bool Deployer::isDeployConfirmed() -{ +bool Deployer::isDeployConfirmed() { QMessageBox msgBox; msgBox.setWindowTitle("Deploy"); QString infoMsg = "Do you want to deploy the following project: \n" + proFilePath - + "\n\nIn the following directory: \n" + deployDir; + + "\n\nIn the following directory: \n" + deployDir; msgBox.setInformativeText(infoMsg); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Yes); @@ -215,8 +200,7 @@ bool Deployer::isDeployConfirmed() } -void Deployer::copyPath(const QString &src, const QString &dst) -{ +void Deployer::copyPath(const QString &src, const QString &dst) { QDir dir(src); if (! dir.exists()) return; @@ -224,7 +208,7 @@ void Deployer::copyPath(const QString &src, const QString &dst) foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { QString dst_path = dst + QDir::separator() + d; dir.mkpath(dst_path); - copyPath(src+ QDir::separator() + d, dst_path); + copyPath(src + QDir::separator() + d, dst_path); } foreach (QString f, dir.entryList(QDir::Files)) { @@ -234,14 +218,12 @@ void Deployer::copyPath(const QString &src, const QString &dst) -QList<QString> Deployer::loadFile(const QString &path) -{ +QList<QString> Deployer::loadFile(const QString &path) { QList<QString> stringList; QFile textFile(path); - if(textFile.open(QIODevice::ReadOnly)){ + if(textFile.open(QIODevice::ReadOnly)) { QTextStream textStream(&textFile); - while (!textStream.atEnd()) - { + while (!textStream.atEnd()) { stringList.append(textStream.readLine()); } textFile.close(); @@ -249,48 +231,41 @@ QList<QString> Deployer::loadFile(const QString &path) return stringList; } -QString Deployer::getProFileName() const -{ +QString Deployer::getProFileName() const { return QFileInfo(proFilePath).fileName(); } -QString Deployer::getSourceDir() const -{ +QString Deployer::getSourceDir() const { return QFileInfo(proFilePath).dir().absolutePath(); } -QString Deployer::getNewSourceDir() const -{ +QString Deployer::getNewSourceDir() const { return deployDir + "/" + newCopySourceFolderName; } -QString Deployer::getNewProFilePath() const -{ +QString Deployer::getNewProFilePath() const { return getNewSourceDir() + "/" + getProFileName(); } -QString Deployer::getModuleListFilePath() const -{ +QString Deployer::getModuleListFilePath() const { return getNewSourceDir() + relativeModuleFilesPath; } -void Deployer::makeDeployDir() const -{ +void Deployer::makeDeployDir() const { QDir newDir(deployDir); newDir.mkdir(newCopySourceFolderName); -// newDir.mkdir(newCopyReleaseFolderName); + // newDir.mkdir(newCopyReleaseFolderName); } -bool Deployer::writeFile(const QList<QString> &text, const QString &path) -{ +bool Deployer::writeFile(const QList<QString> &text, const QString &path) { bool result = false; QFile file(path); - if(file.open(QIODevice::WriteOnly)){ + if(file.open(QIODevice::WriteOnly)) { QTextStream writer(&file); - for(QString line : text){ - writer << line << '\n'; + for(QString line : text) { + writer << line << '\n'; } file.close(); result = true; diff --git a/Modules/SkywardHub/deployer.h b/Modules/SkywardHub/deployer.h index fca6314a15518bf24dc9e36ac6053585a0e3d37e..f136e54cfa888fb54452b9595b735f48b38314f5 100644 --- a/Modules/SkywardHub/deployer.h +++ b/Modules/SkywardHub/deployer.h @@ -7,15 +7,14 @@ #include "Core/xmlobject.h" #include "deployerpathpicker.h" -class Deployer -{ -public: +class Deployer { + public: Deployer(); bool deploy(const QList<QString> &activeModules); QString getDeployReleaseFolder() const; -protected: + protected: QString writeBatFile() const; void copyPath(const QString &src, const QString &dst); @@ -44,7 +43,7 @@ protected: bool isDeployConfirmed(); -private: + private: QList<QString> modulesFiles; QString mingw81_64_bin = "C:/Qt/5.15.1/mingw81_64/bin"; QString mingw810_64_bin = "C:/Qt/Tools/mingw810_64/bin"; diff --git a/Modules/SkywardHub/deployerpathpicker.cpp b/Modules/SkywardHub/deployerpathpicker.cpp index e098f75a1549ea98595bfcd119d284d9c6187cbd..f0d891d0516cf7ef474e89c0f9566227ec96153d 100644 --- a/Modules/SkywardHub/deployerpathpicker.cpp +++ b/Modules/SkywardHub/deployerpathpicker.cpp @@ -3,78 +3,66 @@ #include <QFileDialog> -DeployerPathPicker::DeployerPathPicker(QWidget *parent) : QDialog(parent), ui(new Ui::DeployerPathPicker) -{ +DeployerPathPicker::DeployerPathPicker(QWidget *parent) : QDialog(parent), ui(new Ui::DeployerPathPicker) { ui->setupUi(this); //this->setAttribute(Qt::WA_DeleteOnClose, true); // WA_DeleteOnClose is set to true, so this widget will be deleted on close - connect(ui->pushButton_selectDeployFolder,&QPushButton::clicked, this, &DeployerPathPicker::onSelectDeployFolderClicked); - connect(ui->pushButton_selectProFilePath,&QPushButton::clicked, this, &DeployerPathPicker::onSelectProFilePathClicked); - connect(ui->pushButton_confirm,&QPushButton::clicked, this, &DeployerPathPicker::onConfirmButtonClicked); + connect(ui->pushButton_selectDeployFolder, &QPushButton::clicked, this, &DeployerPathPicker::onSelectDeployFolderClicked); + connect(ui->pushButton_selectProFilePath, &QPushButton::clicked, this, &DeployerPathPicker::onSelectProFilePathClicked); + connect(ui->pushButton_confirm, &QPushButton::clicked, this, &DeployerPathPicker::onConfirmButtonClicked); } -DeployerPathPicker::~DeployerPathPicker() -{ +DeployerPathPicker::~DeployerPathPicker() { delete ui; } -QString DeployerPathPicker::getDeploymentFolder() const -{ +QString DeployerPathPicker::getDeploymentFolder() const { return ui->textEdit_DeploymentFolder->toPlainText().trimmed(); } -QString DeployerPathPicker::getProFilePathFolder() const -{ +QString DeployerPathPicker::getProFilePathFolder() const { return ui->textEdit_proFilePath->toPlainText().trimmed(); } -void DeployerPathPicker::onSelectDeployFolderClicked() -{ +void DeployerPathPicker::onSelectDeployFolderClicked() { QString deployDir = QFileDialog::getExistingDirectory(); setDeploymentFolder(deployDir); } -void DeployerPathPicker::onSelectProFilePathClicked() -{ - QString proFilePath = QFileDialog::getOpenFileName(nullptr, "Select .pro file","","(*.pro)"); +void DeployerPathPicker::onSelectProFilePathClicked() { + QString proFilePath = QFileDialog::getOpenFileName(nullptr, "Select .pro file", "", "(*.pro)"); setProFilePathFolder(proFilePath); } -void DeployerPathPicker::setDeploymentFolder(const QString &value) -{ +void DeployerPathPicker::setDeploymentFolder(const QString &value) { ui->textEdit_DeploymentFolder->setText(value); } -void DeployerPathPicker::setProFilePathFolder(const QString &value) -{ +void DeployerPathPicker::setProFilePathFolder(const QString &value) { ui->textEdit_proFilePath->setText(value); } -void DeployerPathPicker::onConfirmButtonClicked() -{ +void DeployerPathPicker::onConfirmButtonClicked() { QString deployDir = getDeploymentFolder(); QString proFilePath = getProFilePathFolder(); - if(deployDir.isEmpty() || proFilePath.isEmpty()){ + if(deployDir.isEmpty() || proFilePath.isEmpty()) { setPickConfirmed(false); } setPickConfirmed(true); this->close(); // In order to autodelete on close, WA_DeleteOnClose must be set to true. } -bool DeployerPathPicker::getPickConfirmed() const -{ +bool DeployerPathPicker::getPickConfirmed() const { return pickConfirmed; } -void DeployerPathPicker::setPickConfirmed(bool value) -{ +void DeployerPathPicker::setPickConfirmed(bool value) { pickConfirmed = value; } -bool DeployerPathPicker::pickDirectory() -{ +bool DeployerPathPicker::pickDirectory() { setPickConfirmed(false); this->exec(); return getPickConfirmed(); diff --git a/Modules/SkywardHub/deployerpathpicker.h b/Modules/SkywardHub/deployerpathpicker.h index 72d2c1d214dfca0a112b8a83bff688fb5a270ab8..e7193e8535e413c8bc6683c95ade640d9cb7f3ba 100644 --- a/Modules/SkywardHub/deployerpathpicker.h +++ b/Modules/SkywardHub/deployerpathpicker.h @@ -7,11 +7,10 @@ namespace Ui { class DeployerPathPicker; } -class DeployerPathPicker : public QDialog -{ +class DeployerPathPicker : public QDialog { Q_OBJECT -public: + public: explicit DeployerPathPicker(QWidget *parent = nullptr); ~DeployerPathPicker(); @@ -23,7 +22,7 @@ public: bool getPickConfirmed() const; void setPickConfirmed(bool value); -protected slots: + protected slots: void onSelectDeployFolderClicked(); void onSelectProFilePathClicked(); @@ -31,7 +30,7 @@ protected slots: void setProFilePathFolder(const QString &value); void onConfirmButtonClicked(); -private: + private: Ui::DeployerPathPicker *ui; bool pickConfirmed; }; diff --git a/Modules/SkywardHub/prefabdialog.cpp b/Modules/SkywardHub/prefabdialog.cpp index f15faa1a546e35e6ecc40a8a3babc3ab10d13efa..40e67482f7fb6637e6649dc42edb0926fc3f198d 100644 --- a/Modules/SkywardHub/prefabdialog.cpp +++ b/Modules/SkywardHub/prefabdialog.cpp @@ -3,26 +3,25 @@ PrefabDialog::PrefabDialog(QWidget *parent) : QDialog(parent), - ui(new Ui::PrefabDialog) -{ + ui(new Ui::PrefabDialog) { ui->setupUi(this); this->setFixedHeight(800); this->setMinimumWidth(800); - connect(ui->create_pushButton, &QPushButton::clicked, this , &PrefabDialog::onCreate); + connect(ui->create_pushButton, &QPushButton::clicked, this, &PrefabDialog::onCreate); this->setStyleSheet("background-color: #212121 ;"); QString groupboxStyle = "QGroupBox {" " border:1px solid #00bfff;" - " border-radius: 7px;" - " margin-top: 2ex;" - "}" + " border-radius: 7px;" + " margin-top: 2ex;" + "}" - "QGroupBox::title {" + "QGroupBox::title {" " subcontrol-origin: margin;" - " subcontrol-position: top center;" - " padding-left: 10px;" - "padding-right: 10px;" - "color: #00bfff;" - "}"; + " subcontrol-position: top center;" + " padding-left: 10px;" + "padding-right: 10px;" + "color: #00bfff;" + "}"; ui->title_groupBox->setStyleSheet(groupboxStyle); ui->caption_groupBox->setStyleSheet(groupboxStyle); ui->description_groupBox->setStyleSheet(groupboxStyle); @@ -30,12 +29,12 @@ PrefabDialog::PrefabDialog(QWidget *parent) : QString lineeditStyle = "QLineEdit" "{" - " background-color: #2d2d2d;" - " padding: 2px;" - " border-style: solid;" - "border: 1px solid #00bfff;" - "border-radius: 3px;" - "color: #00bfff;" + " background-color: #2d2d2d;" + " padding: 2px;" + " border-style: solid;" + "border: 1px solid #00bfff;" + "border-radius: 3px;" + "color: #00bfff;" "}"; ui->title_lineEdit->setStyleSheet(lineeditStyle); @@ -44,18 +43,18 @@ PrefabDialog::PrefabDialog(QWidget *parent) : QString palaintextStyle = "QPlainTextEdit" "{" - /*background-color: #201F1F;; - color: silver; - border-radius: 3px; - border: 1px solid #3A3939;*/ - - - " background-color: #2d2d2d;" - " padding: 2px;" - " border-style: solid;" - "border: 1px solid #00bfff;" - "border-radius: 3px;" - "color: #00bfff;" + /*background-color: #201F1F;; + color: silver; + border-radius: 3px; + border: 1px solid #3A3939;*/ + + + " background-color: #2d2d2d;" + " padding: 2px;" + " border-style: solid;" + "border: 1px solid #00bfff;" + "border-radius: 3px;" + "color: #00bfff;" "}"; ui->Desc_plainTextEdit->setStyleSheet(palaintextStyle); @@ -64,32 +63,30 @@ PrefabDialog::PrefabDialog(QWidget *parent) : - ui->create_pushButton->setStyleSheet("" - "QPushButton" - "{" - "background-color: none;" - "border: 2px solid #00bfff;" - "color: #00bfff;" - "border-radius: 3px;" - "}" - "QPushButton:hover" - "{" - "background-color: #474747;" - "border: 2px solid #00bfff;" - "color: #00bfff;" - "}" - "QPushButton:pressed { background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #506987, stop: 1 #00739a);}" -); + ui->create_pushButton->setStyleSheet("" + "QPushButton" + "{" + "background-color: none;" + "border: 2px solid #00bfff;" + "color: #00bfff;" + "border-radius: 3px;" + "}" + "QPushButton:hover" + "{" + "background-color: #474747;" + "border: 2px solid #00bfff;" + "color: #00bfff;" + "}" + "QPushButton:pressed { background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #506987, stop: 1 #00739a);}" + ); } -PrefabDialog::~PrefabDialog() -{ +PrefabDialog::~PrefabDialog() { delete ui; } -void PrefabDialog::onCreate() -{ +void PrefabDialog::onCreate() { QString title = ui->title_lineEdit->text(); QString caption = ui->caption_lineEdit->text(); QString description = ui->Desc_plainTextEdit->toPlainText(); diff --git a/Modules/SkywardHub/prefabdialog.h b/Modules/SkywardHub/prefabdialog.h index 6904eea16565d005c3d1e8d6e1eea4e027572863..09964300594f2e7563659d257e0207474bce16e6 100644 --- a/Modules/SkywardHub/prefabdialog.h +++ b/Modules/SkywardHub/prefabdialog.h @@ -7,22 +7,21 @@ namespace Ui { class PrefabDialog; } -class PrefabDialog : public QDialog -{ +class PrefabDialog : public QDialog { Q_OBJECT -public: + public: explicit PrefabDialog(QWidget *parent = nullptr); ~PrefabDialog(); -public slots: + public slots: void onCreate(); -signals: + signals: void newPrefabCreated(const QString &title, const QString &caption, const QString &description); -private: + private: Ui::PrefabDialog *ui; }; diff --git a/Modules/SkywardHub/prefabviewelement.cpp b/Modules/SkywardHub/prefabviewelement.cpp index 761623cb718498982015c8cbd7939dc1eec15ad3..4c645e4a99b5f7353d9994ad53837b9b1c27af8d 100644 --- a/Modules/SkywardHub/prefabviewelement.cpp +++ b/Modules/SkywardHub/prefabviewelement.cpp @@ -3,8 +3,7 @@ #include "Modules/skywardhubstrings.h" -PrefabViewElement::PrefabViewElement(const QString &name, QWidget* parent) : QWidget(parent), ui(new Ui::PrefabViewElement) -{ +PrefabViewElement::PrefabViewElement(const QString &name, QWidget* parent) : QWidget(parent), ui(new Ui::PrefabViewElement) { ui->setupUi(this); setName(name); @@ -13,29 +12,24 @@ PrefabViewElement::PrefabViewElement(const QString &name, QWidget* parent) : QWi connect(ui->pushButton_icon, &QPushButton::clicked, this, &PrefabViewElement::onIconClicked); } -PrefabViewElement::~PrefabViewElement() -{ +PrefabViewElement::~PrefabViewElement() { delete ui; } -void PrefabViewElement::setName(const QString &value) -{ +void PrefabViewElement::setName(const QString &value) { name = value; ui->label_name->setText(value); } -QString PrefabViewElement::getName() const -{ +QString PrefabViewElement::getName() const { return name; } -QString PrefabViewElement::getDesctiption() const -{ +QString PrefabViewElement::getDesctiption() const { return desctiption; } -void PrefabViewElement::setDesctiption(const QString &value) -{ +void PrefabViewElement::setDesctiption(const QString &value) { if(value.isEmpty()) return; @@ -43,13 +37,11 @@ void PrefabViewElement::setDesctiption(const QString &value) ui->label_desctiption->setText(value); } -QString PrefabViewElement::getPathToImg() const -{ +QString PrefabViewElement::getPathToImg() const { return pathToImg; } -void PrefabViewElement::setPathToImg(const QString &value) -{ +void PrefabViewElement::setPathToImg(const QString &value) { if(value.isEmpty()) return; @@ -61,80 +53,67 @@ void PrefabViewElement::setPathToImg(const QString &value) ui->pushButton_icon->setIconSize(QSize(512, 512)); } -XmlObject PrefabViewElement::getXml() const -{ +XmlObject PrefabViewElement::getXml() const { return xml; } -void PrefabViewElement::setXml(XmlObject &xml) -{ +void PrefabViewElement::setXml(XmlObject &xml) { this->xml = xml; setPathToImg(xml.getAttribute(SkywardHubStrings::configurationIconPathAttribute)); QList<XmlObject*> descr = xml.deepSearchObjects(SkywardHubStrings::configurationDescriptionAttribute); - if(descr.count() >= 1){ + if(descr.count() >= 1) { setDesctiption(descr.first()->getTextValue()); } } -void PrefabViewElement::addActiveModuleName(const QString &moduleName) -{ +void PrefabViewElement::addActiveModuleName(const QString &moduleName) { if(containsModule(moduleName)) return; activeModules.append(moduleName); } -void PrefabViewElement::removeActiveModuleName(const QString &moduleName) -{ +void PrefabViewElement::removeActiveModuleName(const QString &moduleName) { activeModules.removeAll(moduleName); } -bool PrefabViewElement::containsModule(const QString &moduleName) -{ +bool PrefabViewElement::containsModule(const QString &moduleName) { return activeModules.contains(moduleName); } -void PrefabViewElement::setDeleteButtonVisibility(bool visibility) -{ +void PrefabViewElement::setDeleteButtonVisibility(bool visibility) { ui->pushButton_delete->setVisible(visibility); } -void PrefabViewElement::setLaunchButtonText(const QString &txt) -{ +void PrefabViewElement::setLaunchButtonText(const QString &txt) { ui->pushButton_launch->setText(txt); } -void PrefabViewElement::setIconButtonVisibility(bool visibility) -{ +void PrefabViewElement::setIconButtonVisibility(bool visibility) { ui->pushButton_icon->setVisible(visibility); } -void PrefabViewElement::onIconClicked() -{ +void PrefabViewElement::onIconClicked() { emit selected(this); } -void PrefabViewElement::onLaunchClicked() -{ +void PrefabViewElement::onLaunchClicked() { emit launchRequested(this); } -void PrefabViewElement::onDeleteClicked() -{ +void PrefabViewElement::onDeleteClicked() { emit deleteRequested(this); } -QString PrefabViewElement::getFilePath() const -{ +QString PrefabViewElement::getFilePath() const { return filePath; } -void PrefabViewElement::setFilePath(const QString &value) -{ +void PrefabViewElement::setFilePath(const QString &value) { filePath = value; } diff --git a/Modules/SkywardHub/prefabviewelement.h b/Modules/SkywardHub/prefabviewelement.h index c46065e2158f6b69c8e5f80d24c8e340a83c96a6..50d47a542f7103a2822ce0a5c26fc1974625ff6b 100644 --- a/Modules/SkywardHub/prefabviewelement.h +++ b/Modules/SkywardHub/prefabviewelement.h @@ -8,11 +8,10 @@ namespace Ui { class PrefabViewElement; } -class PrefabViewElement : public QWidget -{ +class PrefabViewElement : public QWidget { Q_OBJECT -public: + public: explicit PrefabViewElement(const QString &name, QWidget *parent = nullptr); ~PrefabViewElement(); @@ -39,17 +38,17 @@ public: QString getFilePath() const; void setFilePath(const QString &value); -public slots: + public slots: void onIconClicked(); void onLaunchClicked(); void onDeleteClicked(); -signals: + signals: void selected(PrefabViewElement *prefabVElement); void launchRequested(PrefabViewElement *prefabVElement); void deleteRequested(PrefabViewElement *prefabVElement); -private: + private: Ui::PrefabViewElement *ui; QString name; diff --git a/Modules/SkywardHub/skywardhubmodule.cpp b/Modules/SkywardHub/skywardhubmodule.cpp index ec37e68b6c0211d0ff00140e91e6cd879faf7a0c..f5cb7b57f302ac5461b8e68a89bb914ad4e6c64e 100644 --- a/Modules/SkywardHub/skywardhubmodule.cpp +++ b/Modules/SkywardHub/skywardhubmodule.cpp @@ -12,8 +12,7 @@ #include "Modules/skywardhubstrings.h" #include "QMessageBox" -SkywardHubModule::SkywardHubModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::SkywardHubModule) -{ +SkywardHubModule::SkywardHubModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::SkywardHubModule) { ui->setupUi(this); defaultContextMenuSetup(); @@ -21,35 +20,36 @@ SkywardHubModule::SkywardHubModule(QWidget *parent) : DefaultModule(parent), ui( addEmptyPrefab(); loadPrefabs(); - connect(ui->pushButton_deploy, &QPushButton::clicked, this, [this](){ onPrefabDeployRequested(selectedElement); }); + connect(ui->pushButton_deploy, &QPushButton::clicked, this, [this]() { + onPrefabDeployRequested(selectedElement); + }); } -SkywardHubModule::~SkywardHubModule() -{ +SkywardHubModule::~SkywardHubModule() { clearPrefab(); delete emptyPrefab; emptyPrefab = nullptr; - for(QCheckBox *c : completeModule_checkboxList){ + for(QCheckBox *c : completeModule_checkboxList) { delete c; } delete ui; } -void SkywardHubModule::fillCompleteModulesList() -{ +void SkywardHubModule::fillCompleteModulesList() { QList<QString> completeModuleNamesList = ModulesManager::getModulesNamesList(); - for(QString s : completeModuleNamesList){ + for(QString s : completeModuleNamesList) { QCheckBox *cBox = createPanelsCheckbox(s); insertCheckBox(cBox); - connect(cBox, &QCheckBox::clicked, this, [this, cBox](){onCheckBoxClicked(cBox);}); + connect(cBox, &QCheckBox::clicked, this, [this, cBox]() { + onCheckBoxClicked(cBox); + }); } } -void SkywardHubModule::loadPrefabs() -{ +void SkywardHubModule::loadPrefabs() { clearPrefab(); nextColumn = 0; nextRow = 0; @@ -57,7 +57,7 @@ void SkywardHubModule::loadPrefabs() QString prefabsFolder = SkywardHubStrings::defaultPrefabsFolder; QDir directory(prefabsFolder); - QStringList prefabFiles = directory.entryList(QStringList() << "*.xml",QDir::Files); + QStringList prefabFiles = directory.entryList(QStringList() << "*.xml", QDir::Files); for(QString prefabName : prefabFiles) { XmlObject xml; xml.loadFromFile(prefabsFolder + prefabName); @@ -65,40 +65,36 @@ void SkywardHubModule::loadPrefabs() } } -void SkywardHubModule::updateActiveCheckboxList(PrefabViewElement *element) -{ +void SkywardHubModule::updateActiveCheckboxList(PrefabViewElement *element) { if (element == nullptr) return; - for(QCheckBox *cBox : completeModule_checkboxList){ + for(QCheckBox *cBox : completeModule_checkboxList) { bool isModuleActive = element->containsModule(cBox->text()); cBox->setChecked(isModuleActive); } } -void SkywardHubModule::initUsedModules(PrefabViewElement *element, const XmlObject &root) const -{ +void SkywardHubModule::initUsedModules(PrefabViewElement *element, const XmlObject &root) const { if(element == nullptr) return; // Set as active the used modules element->addActiveModuleName(root.getObjectName()); - for(int i = 0; i < root.childCount(); i++) - { + for(int i = 0; i < root.childCount(); i++) { initUsedModules(element, root.childAt(i)); } } -void SkywardHubModule::addEmptyPrefab() -{ +void SkywardHubModule::addEmptyPrefab() { Module *module = getCore()->getModulesManager()->instantiateDefaultModule(); - if(module != nullptr){ + if(module != nullptr) { XmlObject xmlconfig(SkywardHubStrings::configurationNameValue); xmlconfig.addAttribute(SkywardHubStrings::configurationNameAttribute, "Launch Empty Configuration"); XmlObject emptyXml = module->toXmlObject(); xmlconfig.addChild(emptyXml); PrefabViewElement* prefabView = createNewPrefab(xmlconfig); - if(prefabView != nullptr){ + if(prefabView != nullptr) { initUsedModules(prefabView, xmlconfig); prefabView->setDeleteButtonVisibility(false); prefabView->setIconButtonVisibility(false); @@ -111,10 +107,9 @@ void SkywardHubModule::addEmptyPrefab() } } -void SkywardHubModule::createAndInsertPrefabFromXml(XmlObject &xml, const QString &filePath) -{ +void SkywardHubModule::createAndInsertPrefabFromXml(XmlObject &xml, const QString &filePath) { PrefabViewElement* prefabView = createNewPrefab(xml); - if(prefabView != nullptr){ + if(prefabView != nullptr) { prefabView->setFilePath(filePath); initUsedModules(prefabView, xml); addPrefab(prefabView); @@ -123,24 +118,23 @@ void SkywardHubModule::createAndInsertPrefabFromXml(XmlObject &xml, const QStrin } -QCheckBox* SkywardHubModule::createPanelsCheckbox(const QString &text) -{ +QCheckBox* SkywardHubModule::createPanelsCheckbox(const QString &text) { QString check_stylesheet = "" - "QCheckBox" - "{" - "background-color: none;" - "border: 3px solid transparent;" - "color: #00bfff;" - "}" - "QCheckBox:hover" - "{" - "background-color: #474747;" -// "border: 3px solid #00bfff;" - "border-top: 1px solid none;border-right: 3px solid #00bfff; border-bottom: 1px solid none; border-left: 3px solid #00bfff;" - "color: #00bfff;" - "}" - "QCheckBox:checked { background-color: QLinearGradient( x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #506987, stop: 1 #00739a);" -// "border: 2px solid #00bfff;" /*#3f839a #00739a*/ + "QCheckBox" + "{" + "background-color: none;" + "border: 3px solid transparent;" + "color: #00bfff;" + "}" + "QCheckBox:hover" + "{" + "background-color: #474747;" + // "border: 3px solid #00bfff;" + "border-top: 1px solid none;border-right: 3px solid #00bfff; border-bottom: 1px solid none; border-left: 3px solid #00bfff;" + "color: #00bfff;" + "}" + "QCheckBox:checked { background-color: QLinearGradient( x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #506987, stop: 1 #00739a);" + // "border: 2px solid #00bfff;" /*#3f839a #00739a*/ "border-top: none;border-right: 3px solid #00bfff; border-bottom: none; border-left: 3px solid #00bfff;}"; @@ -149,14 +143,12 @@ QCheckBox* SkywardHubModule::createPanelsCheckbox(const QString &text) return checkBox; } -void SkywardHubModule::insertCheckBox(QCheckBox *checkBox) -{ +void SkywardHubModule::insertCheckBox(QCheckBox *checkBox) { ui->modules_layout->insertWidget(0, checkBox); completeModule_checkboxList.append(checkBox); } -void SkywardHubModule::addPrefab(PrefabViewElement *element) -{ +void SkywardHubModule::addPrefab(PrefabViewElement *element) { prefabs.append(element); connect(element, &PrefabViewElement::launchRequested, this, &SkywardHubModule::onPrefabLaunchRequested); connect(element, &PrefabViewElement::deleteRequested, this, &SkywardHubModule::onPrefabDeleteRequested); @@ -164,11 +156,10 @@ void SkywardHubModule::addPrefab(PrefabViewElement *element) } -void SkywardHubModule::insertPrefabInUi(PrefabViewElement *element) -{ +void SkywardHubModule::insertPrefabInUi(PrefabViewElement *element) { // Insert the prefabView in the correct column - if(nextColumn == maxColum){ + if(nextColumn == maxColum) { nextColumn = 0; nextRow++; } @@ -176,9 +167,8 @@ void SkywardHubModule::insertPrefabInUi(PrefabViewElement *element) nextColumn++; } -void SkywardHubModule::clearPrefab() -{ - for(PrefabViewElement *p : prefabs){ +void SkywardHubModule::clearPrefab() { + for(PrefabViewElement *p : prefabs) { delete p; } prefabs.clear(); @@ -186,11 +176,10 @@ void SkywardHubModule::clearPrefab() } -PrefabViewElement* SkywardHubModule::createNewPrefab(XmlObject &xmlPrefab) -{ - if(xmlPrefab.getObjectName() == SkywardHubStrings::configurationNameValue){ +PrefabViewElement* SkywardHubModule::createNewPrefab(XmlObject &xmlPrefab) { + if(xmlPrefab.getObjectName() == SkywardHubStrings::configurationNameValue) { QString prefName = xmlPrefab.getAttribute(SkywardHubStrings::configurationNameAttribute); - if(!prefName.isEmpty()){ + if(!prefName.isEmpty()) { PrefabViewElement* prefabView = new PrefabViewElement(prefName); prefabView->setXml(xmlPrefab); return prefabView; @@ -199,35 +188,32 @@ PrefabViewElement* SkywardHubModule::createNewPrefab(XmlObject &xmlPrefab) return nullptr; } -void SkywardHubModule::dialogRequested(){ +void SkywardHubModule::dialogRequested() { PrefabDialog dialog(this); //connect(&dialog, &PrefabDialog::newPrefabCreated, this, &SkywardHubModule::createNewPrefab); dialog.exec(); } -void SkywardHubModule::onPrefabSelected(PrefabViewElement *element) -{ +void SkywardHubModule::onPrefabSelected(PrefabViewElement *element) { selectedElement = element; updateActiveCheckboxList(selectedElement); ui->plainTextEdit->clear(); - if(element != nullptr){ + if(element != nullptr) { ui->groupBox_selectedModule->setTitle(element->getName()); ui->plainTextEdit->insertPlainText(element->getXml().toXml()); } } -void SkywardHubModule::onPrefabLaunchRequested(PrefabViewElement *element) -{ - if(element != nullptr){ +void SkywardHubModule::onPrefabLaunchRequested(PrefabViewElement *element) { + if(element != nullptr) { XmlObject xml = element->getXml(); getCore()->getModulesManager()->setModules(getCore()->getModulesManager()->loadModuleFromXml(xml)); } } -void SkywardHubModule::onPrefabDeployRequested(PrefabViewElement *element) -{ - if(element == nullptr){ +void SkywardHubModule::onPrefabDeployRequested(PrefabViewElement *element) { + if(element == nullptr) { QMessageBox msgBox; msgBox.setText("No configuration selected."); msgBox.exec(); @@ -239,8 +225,8 @@ void SkywardHubModule::onPrefabDeployRequested(PrefabViewElement *element) QList<QString> modulesFiles; QList<ModuleInfo> fullModuleList = getCore()->getModulesManager()->getModulesInfo(); - for(ModuleInfo mInfo : fullModuleList){ - if(element->containsModule(mInfo.getModuleName())){ + for(ModuleInfo mInfo : fullModuleList) { + if(element->containsModule(mInfo.getModuleName())) { modulesFiles.append(mInfo.getModuleSourceFiles()); } } @@ -252,27 +238,26 @@ void SkywardHubModule::onPrefabDeployRequested(PrefabViewElement *element) //Put the prefab config as default config QString configPath = deployer.getDeployReleaseFolder() + "/" + SkywardHubStrings::defaultConfigurationFolder; - if(!QDir(configPath).exists()){ + if(!QDir(configPath).exists()) { QDir().mkdir(configPath); } configPath += "/" + SkywardHubStrings::defaultPrefabsFolderName; - if(!QDir(configPath).exists()){ + if(!QDir(configPath).exists()) { QDir().mkdir(configPath); } element->getXml().writeToFile(configPath + "/" + SkywardHubStrings::defaultConfigurationFileName); } -void SkywardHubModule::onPrefabDeleteRequested(PrefabViewElement *element) -{ +void SkywardHubModule::onPrefabDeleteRequested(PrefabViewElement *element) { if(element == nullptr) return; QMessageBox msgBox; QString title = "Delete configuration"; - QString text = "Do you want to delete the following configuration?\n"+element->getFilePath(); - if(msgBox.question(this, title, text) == QMessageBox::Yes){ + QString text = "Do you want to delete the following configuration?\n" + element->getFilePath(); + if(msgBox.question(this, title, text) == QMessageBox::Yes) { QFile file (element->getFilePath()); - if(file.exists()){ + if(file.exists()) { file.remove(); loadPrefabs(); } @@ -280,30 +265,26 @@ void SkywardHubModule::onPrefabDeleteRequested(PrefabViewElement *element) } -void SkywardHubModule::onCheckBoxClicked(QCheckBox *cBox) -{ +void SkywardHubModule::onCheckBoxClicked(QCheckBox *cBox) { if(cBox == nullptr || selectedElement == nullptr) return; - if(cBox->isChecked()){ + if(cBox->isChecked()) { selectedElement->addActiveModuleName(cBox->text()); - }else{ + } else { selectedElement->removeActiveModuleName(cBox->text()); } } -QWidget *SkywardHubModule::toWidget() -{ +QWidget *SkywardHubModule::toWidget() { return this; } -XmlObject SkywardHubModule::toXmlObject() -{ +XmlObject SkywardHubModule::toXmlObject() { return XmlObject(getName(ModuleId::SKYWARDHUB)); } -void SkywardHubModule::fromXmlObject(const XmlObject &xmlObject) -{ +void SkywardHubModule::fromXmlObject(const XmlObject &xmlObject) { Q_UNUSED(xmlObject); } diff --git a/Modules/SkywardHub/skywardhubmodule.h b/Modules/SkywardHub/skywardhubmodule.h index aa8f6f2e76f3dc290f4800fa69d6f0a33a6dff13..6d11a8ea8a59895eaab25314408300371282d20d 100644 --- a/Modules/SkywardHub/skywardhubmodule.h +++ b/Modules/SkywardHub/skywardhubmodule.h @@ -13,11 +13,10 @@ namespace Ui { class SkywardHubModule; } -class SkywardHubModule : public DefaultModule -{ +class SkywardHubModule : public DefaultModule { Q_OBJECT -public: + public: explicit SkywardHubModule(QWidget *parent = nullptr); ~SkywardHubModule(); @@ -31,7 +30,7 @@ public: -public slots: + public slots: PrefabViewElement *createNewPrefab(XmlObject &xmlPrefab); void dialogRequested(); @@ -41,7 +40,7 @@ public slots: void onPrefabDeleteRequested(PrefabViewElement *element); void onCheckBoxClicked(QCheckBox *cBox); -protected: + protected: void fillCompleteModulesList(); void loadPrefabs(); void updateActiveCheckboxList(PrefabViewElement *element); @@ -52,7 +51,7 @@ protected: void insertPrefabInUi(PrefabViewElement *element); void clearPrefab(); -private: + private: Ui::SkywardHubModule *ui; QList <QString> panelsList; QList <QCheckBox *> completeModule_checkboxList; diff --git a/Modules/Splitter/splittermodule.cpp b/Modules/Splitter/splittermodule.cpp index 40ae2614dd1c03208b3df9aa5e0e3050346e4576..d613a0b77a1eb645a3fc10c71f9d253cfac92dce 100644 --- a/Modules/Splitter/splittermodule.cpp +++ b/Modules/Splitter/splittermodule.cpp @@ -6,47 +6,42 @@ #include <QDebug> #include "Core/modulesmanager.h" -SplitterModule::SplitterModule(Qt::Orientation orientation) : DefaultModule(), ui(new Ui::SplitterModule) -{ +SplitterModule::SplitterModule(Qt::Orientation orientation) : DefaultModule(), ui(new Ui::SplitterModule) { ui->setupUi(this); defaultContextMenuSetup(); buildUI(orientation); } -SplitterModule::~SplitterModule() -{ +SplitterModule::~SplitterModule() { delete ui; //qDebug() << "Splitter >> deleted"; - for(int i = 0; i < childList.count(); i++){ - if(childList[i]!= nullptr) + for(int i = 0; i < childList.count(); i++) { + if(childList[i] != nullptr) delete childList[i]; } } -QWidget *SplitterModule::toWidget() -{ +QWidget *SplitterModule::toWidget() { return this; } -XmlObject SplitterModule::toXmlObject() -{ +XmlObject SplitterModule::toXmlObject() { XmlObject obj(getName(ModuleId::SPLITTER)); QString orientation; - if(splitter.orientation() == Qt::Horizontal){ + if(splitter.orientation() == Qt::Horizontal) { orientation = "Horizontal"; - } - else + } else orientation = "Vertical"; obj.addAttribute("Orientation", orientation); QString sizesString = ""; - for(int i : splitter.sizes()){ - sizesString.append(QString::number(i)+","); + for(int i : splitter.sizes()) { + sizesString.append(QString::number(i) + ","); } obj.addAttribute("Sizes", sizesString); - for(Module *module : childList){ + for(Module *module : childList) { XmlObject xmlChild = module->toXmlObject(); obj.addChild(xmlChild); } @@ -54,11 +49,10 @@ XmlObject SplitterModule::toXmlObject() return obj; } -void SplitterModule::fromXmlObject(const XmlObject &xmlObject) -{ - if(xmlObject.getObjectName() == getCore()->getModulesManager()->getModuleName(ModuleId::SPLITTER)){ +void SplitterModule::fromXmlObject(const XmlObject &xmlObject) { + if(xmlObject.getObjectName() == getCore()->getModulesManager()->getModuleName(ModuleId::SPLITTER)) { QString orientation = xmlObject.getAttribute("Orientation"); - if(orientation != ""){ + if(orientation != "") { if(orientation == "Horizontal") setOrientation(Qt::Horizontal); else @@ -68,7 +62,7 @@ void SplitterModule::fromXmlObject(const XmlObject &xmlObject) QStringList sizes = xmlObject.getAttribute("Sizes").split(","); bool ok; QList<int> intSizes; - for(QString size : sizes){ + for(QString size : sizes) { int val = size.toInt(&ok); if(ok) intSizes.append(val); @@ -76,19 +70,18 @@ void SplitterModule::fromXmlObject(const XmlObject &xmlObject) int defaultChildRemaining = childList.count(); - for(int i = 0; i < xmlObject.childCount(); i++){ + for(int i = 0; i < xmlObject.childCount(); i++) { XmlObject xmlChild = xmlObject.childAt(i); Module *module = getCore()->getModulesManager()->instantiateModuleByName(xmlChild.getObjectName()); - if(module != nullptr){ + if(module != nullptr) { module->fromXmlObject(xmlChild); - } - else{ + } else { module = getCore()->getModulesManager()->instantiateDefaultModule(); } addModule(module); } - while(defaultChildRemaining > 0){ + while(defaultChildRemaining > 0) { delete childList.at(0); defaultChildRemaining--; } @@ -98,77 +91,68 @@ void SplitterModule::fromXmlObject(const XmlObject &xmlObject) } } -void SplitterModule::initialize(const XmlObject ¶ms) -{ +void SplitterModule::initialize(const XmlObject ¶ms) { int orientation; - if(params.getIntAttribute("Orientation", orientation)){ - if(orientation == Qt::Vertical){ + if(params.getIntAttribute("Orientation", orientation)) { + if(orientation == Qt::Vertical) { setOrientation(Qt::Vertical); - } - else + } else setOrientation(Qt::Horizontal); } } -void SplitterModule::addModule(Module *module) -{ +void SplitterModule::addModule(Module *module) { int count = splitter.count(); - addModule(module,count); + addModule(module, count); } -void SplitterModule::addModule(Module *module, int position) -{ - connect(module->getModuleEventsHandler(),&ModuleEventsHandler::replaceMeWith,this,[this](Module* sender, Module* newModule){ - this->replace(sender,newModule); +void SplitterModule::addModule(Module *module, int position) { + connect(module->getModuleEventsHandler(), &ModuleEventsHandler::replaceMeWith, this, [this](Module * sender, Module * newModule) { + this->replace(sender, newModule); }); - connect(module->getModuleEventsHandler(),&ModuleEventsHandler::contextMenuRequest,this,&SplitterModule::onSkywardHubContextMenuRequested); - connect(module->getModuleEventsHandler(),&ModuleEventsHandler::beforeDelete,this,&SplitterModule::onModuleDelete); + connect(module->getModuleEventsHandler(), &ModuleEventsHandler::contextMenuRequest, this, &SplitterModule::onSkywardHubContextMenuRequested); + connect(module->getModuleEventsHandler(), &ModuleEventsHandler::beforeDelete, this, &SplitterModule::onModuleDelete); if(position < childList.count()) childList.insert(position, module); else childList.append(module); - splitter.insertWidget(position,module->toWidget()); + splitter.insertWidget(position, module->toWidget()); } -void SplitterModule::replace(Module *oldModule, Module *newModule) -{ - if(oldModule != nullptr && newModule != nullptr){ +void SplitterModule::replace(Module *oldModule, Module *newModule) { + if(oldModule != nullptr && newModule != nullptr) { int i = splitter.indexOf(oldModule->toWidget()); - addModule(newModule,i); + addModule(newModule, i); //oldModule->toWidget()->deleteLater(); } } -void SplitterModule::setOrientation(Qt::Orientation orientation) -{ +void SplitterModule::setOrientation(Qt::Orientation orientation) { splitter.setOrientation(orientation); } -Qt::Orientation SplitterModule::getOrientation() const -{ +Qt::Orientation SplitterModule::getOrientation() const { return splitter.orientation(); } -void SplitterModule::swapOrientation() -{ +void SplitterModule::swapOrientation() { if(getOrientation() == Qt::Horizontal) setOrientation(Qt::Vertical); else setOrientation(Qt::Horizontal); } -void SplitterModule::buildUI(Qt::Orientation orientation) -{ +void SplitterModule::buildUI(Qt::Orientation orientation) { setOrientation(orientation); -// splitter.setStyleSheet("QSplitter::handle:horizontal {" -// "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,stop:0 #eee, stop:1 #ccc);" -// "border: 1px solid #777;" -// "width: 13px;" -// "margin-top: 2px;" -// "margin-bottom: 2px;" -// "border-radius: 4px;" -// "}"); + // splitter.setStyleSheet("QSplitter::handle:horizontal {" + // "background: qlineargradient(x1:0, y1:0, x2:1, y2:1,stop:0 #eee, stop:1 #ccc);" + // "border: 1px solid #777;" + // "width: 13px;" + // "margin-top: 2px;" + // "margin-bottom: 2px;" + // "border-radius: 4px;" + // "}"); splitter.setChildrenCollapsible(false); ui->centralGrid->addWidget(&splitter); @@ -176,16 +160,15 @@ void SplitterModule::buildUI(Qt::Orientation orientation) addModule(getCore()->getModulesManager()->instantiateDefaultModule()); } -void SplitterModule::addCustomActionsToMenu() -{ +void SplitterModule::addCustomActionsToMenu() { showMenuActionsInSeparatedMenu("Splitter"); QAction* split = new QAction("Split"); - connect(split,&QAction::triggered,this,[this](){ + connect(split, &QAction::triggered, this, [this]() { addModule(getCore()->getModulesManager()->instantiateDefaultModule()); }); QAction* changeOrientation = new QAction("Swap Orientation"); - connect(changeOrientation,&QAction::triggered,this,[this](){ + connect(changeOrientation, &QAction::triggered, this, [this]() { this->swapOrientation(); }); @@ -193,14 +176,13 @@ void SplitterModule::addCustomActionsToMenu() addActionToMenu(changeOrientation); } -void SplitterModule::onModuleDelete(Module *module) -{ +void SplitterModule::onModuleDelete(Module *module) { int index = childList.indexOf(module); - if(index >= 0){ + if(index >= 0) { childList.removeAt(index); } - if(splitter.count() == 1){ + if(splitter.count() == 1) { // When this method is called, the last module has not been deleted yet, so // we have to use "deleteLater" to correctly chain the deletation of module and then the splitter //this->deleteLater(); diff --git a/Modules/Splitter/splittermodule.h b/Modules/Splitter/splittermodule.h index be85c8cae162c4cada639f7bea058ef212426096..73276c0ae5ca99d02ed25b4d7b3795462f16931f 100644 --- a/Modules/Splitter/splittermodule.h +++ b/Modules/Splitter/splittermodule.h @@ -11,11 +11,10 @@ namespace Ui { class SplitterModule; } -class SplitterModule : public DefaultModule -{ +class SplitterModule : public DefaultModule { Q_OBJECT -public: + public: explicit SplitterModule(Qt::Orientation orientation = Qt::Horizontal); ~SplitterModule() override; @@ -35,11 +34,11 @@ public: void swapOrientation(); -protected: + protected: void buildUI(Qt::Orientation orientation = Qt::Horizontal); void onModuleDelete(Module *module); -private: + private: Ui::SplitterModule *ui; QSplitter splitter; QList<Module*> childList; diff --git a/Modules/StateViewer/stateviewermodule.cpp b/Modules/StateViewer/stateviewermodule.cpp index 226cfa84a2cc88d1b02581836b7d803cf9dd62f8..4426dc2aac3e571f434f11641ad978dc65cb3b27 100644 --- a/Modules/StateViewer/stateviewermodule.cpp +++ b/Modules/StateViewer/stateviewermodule.cpp @@ -19,8 +19,7 @@ enum states {INIT = 1, LANDED = 13 }; -StateViewerModule::StateViewerModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::StateViewerModule) -{ +StateViewerModule::StateViewerModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::StateViewerModule) { ui->setupUi(this); defaultContextMenuSetup(); @@ -36,34 +35,31 @@ StateViewerModule::StateViewerModule(QWidget *parent) : DefaultModule(parent), u QMap<int, int>indexes{ - {INIT , 0}, - {INIT_ERROR , 0}, - {INIT_DONE , 0}, - {TEST_MODE , 1}, - {SENSORS_CALIBRATION , 2}, - {ALGOS_CALIBRATION , 2}, - {DISARMED , 3 }, - {ARMED , 4}, - {ASCENDING , 5}, - {DROGUE_DESCENT , 6}, - {TERMINAL_DESCENT , 7}, - {LANDED , 8}, + {INIT, 0}, + {INIT_ERROR, 0}, + {INIT_DONE, 0}, + {TEST_MODE, 1}, + {SENSORS_CALIBRATION, 2}, + {ALGOS_CALIBRATION, 2}, + {DISARMED, 3 }, + {ARMED, 4}, + {ASCENDING, 5}, + {DROGUE_DESCENT, 6}, + {TERMINAL_DESCENT, 7}, + {LANDED, 8}, }; labelsIndexes = indexes; } -StateViewerModule::~StateViewerModule() -{ +StateViewerModule::~StateViewerModule() { delete ui; } -QWidget *StateViewerModule::toWidget() -{ +QWidget *StateViewerModule::toWidget() { return this; } -XmlObject StateViewerModule::toXmlObject() -{ +XmlObject StateViewerModule::toXmlObject() { XmlObject obj(getName(ModuleId::STATEVIEWER)); obj.addAttribute("topic", inputTopic); @@ -71,99 +67,87 @@ XmlObject StateViewerModule::toXmlObject() return obj; } -void StateViewerModule::fromXmlObject(const XmlObject &xmlObject) -{ - if(xmlObject.getObjectName() == getName(ModuleId::STATEVIEWER)){ +void StateViewerModule::fromXmlObject(const XmlObject &xmlObject) { + if(xmlObject.getObjectName() == getName(ModuleId::STATEVIEWER)) { inputTopic = xmlObject.getAttribute("topic"); - if(inputTopic != ""){ + if(inputTopic != "") { setTopic(inputTopic); } } } -void StateViewerModule::addCustomActionsToMenu() -{ +void StateViewerModule::addCustomActionsToMenu() { QAction* config = new QAction("Configure"); - connect(config, &QAction::triggered,this, &StateViewerModule::onConfigureClicked); + connect(config, &QAction::triggered, this, &StateViewerModule::onConfigureClicked); addActionToMenu(config); } -void StateViewerModule::onConfigureClicked() -{ +void StateViewerModule::onConfigureClicked() { bool ok; QString text = QInputDialog::getText(this, tr("Topic"), - tr("Insert input topic with the state information"), QLineEdit::Normal, inputTopic, &ok); + tr("Insert input topic with the state information"), QLineEdit::Normal, inputTopic, &ok); text = text.trimmed(); if (ok && !text.isEmpty()) setTopic(text); } -void StateViewerModule::setTopic(const QString &topic) -{ +void StateViewerModule::setTopic(const QString &topic) { getCore()->getModuleMessagesBroker()->unsubscribe(inputTopic, this); inputTopic = topic; - getCore()->getModuleMessagesBroker()->subscribe(inputTopic, this, [this](const ModuleMessage &msg){ + getCore()->getModuleMessagesBroker()->subscribe(inputTopic, this, [this](const ModuleMessage & msg) { onMsgReceived(msg); }); } -void StateViewerModule::onMsgReceived(const ModuleMessage &msg) -{ +void StateViewerModule::onMsgReceived(const ModuleMessage &msg) { int value = -1; - if(msg.getIntPayload(value)){ + if(msg.getIntPayload(value)) { setState(value); } } -void StateViewerModule::setState(int state) -{ - if(state != currentState){ +void StateViewerModule::setState(int state) { + if(state != currentState) { currentState = state; updateView(state); } } -void StateViewerModule::updateView(int state) -{ +void StateViewerModule::updateView(int state) { QString currentStateStyle = "background-color:yellow; color:black;"; QString completedStyle = "background-color:green;"; QString errorStyle = "background-color:red;"; - if(state == INIT){ + if(state == INIT) { ui->label_1_INIT->setStyleSheet(currentStateStyle); - } - else if(state == INIT_DONE){ + } else if(state == INIT_DONE) { ui->label_1_INIT->setStyleSheet(completedStyle); - } - else if(state == INIT_ERROR){ + } else if(state == INIT_ERROR) { ui->label_1_INIT->setStyleSheet(errorStyle); - } - else if(state > INIT_ERROR && labelsIndexes.contains(state)){ + } else if(state > INIT_ERROR && labelsIndexes.contains(state)) { int index = labelsIndexes[state]; - if(index < labels.count()){ + if(index < labels.count()) { labels[index]->setStyleSheet(currentStateStyle); } } - if(labelsIndexes.contains(state)){ - setStyleAfter(labelsIndexes[state]+1, ""); - setStyleBefore(labelsIndexes[state]-1, completedStyle); + if(labelsIndexes.contains(state)) { + setStyleAfter(labelsIndexes[state] + 1, ""); + setStyleBefore(labelsIndexes[state] - 1, completedStyle); } } -void StateViewerModule::setStyleAfter(int threshold, const QString &style) -{ +void StateViewerModule::setStyleAfter(int threshold, const QString &style) { for (int i = threshold; i < labels.count(); i++ ) { labels[i]->setStyleSheet(style); } } -void StateViewerModule::setStyleBefore(int threshold, const QString &style) -{ +void StateViewerModule::setStyleBefore(int threshold, const QString &style) { for (int i = threshold; i >= 0 && i < labels.count(); i-- ) { labels[i]->setStyleSheet(style); } diff --git a/Modules/StateViewer/stateviewermodule.h b/Modules/StateViewer/stateviewermodule.h index 6dcfbd9a79ecf6ca1780d2b366941a9bc39d0fa0..2e7a407b9d22b3179d91f42427ea347231a2cdf6 100644 --- a/Modules/StateViewer/stateviewermodule.h +++ b/Modules/StateViewer/stateviewermodule.h @@ -12,11 +12,10 @@ namespace Ui { class StateViewerModule; } -class StateViewerModule : public DefaultModule -{ +class StateViewerModule : public DefaultModule { Q_OBJECT -public: + public: explicit StateViewerModule(QWidget *parent = nullptr); ~StateViewerModule(); @@ -26,7 +25,7 @@ public: void fromXmlObject(const XmlObject &xmlObject) override; -protected: + protected: void addCustomActionsToMenu() override; void onConfigureClicked(); void setTopic(const QString &topic); @@ -36,7 +35,7 @@ protected: void setStyleAfter(int threshold, const QString &style); void setStyleBefore(int threshold, const QString &style); -private: + private: Ui::StateViewerModule *ui; QString inputTopic = ""; diff --git a/Modules/Table/tablemodule.cpp b/Modules/Table/tablemodule.cpp index 19afc6f51cd8a1d4c89aecf6e3186949e8d34b9d..43b029ba66a33de68c0178a42bad6bc1bf2d9897 100644 --- a/Modules/Table/tablemodule.cpp +++ b/Modules/Table/tablemodule.cpp @@ -6,32 +6,28 @@ #include <QInputDialog> #include <QDebug> -TableModule::TableModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::TableModule) -{ +TableModule::TableModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::TableModule) { ui->setupUi(this); defaultContextMenuSetup(); onColumnNumberChanged(ui->column_counter->value()); connectUiSlots(); } -TableModule::~TableModule() -{ +TableModule::~TableModule() { delete ui; //qDebug() << "TableModule >> Deleted"; } -QWidget *TableModule::toWidget() -{ +QWidget *TableModule::toWidget() { return this; } -XmlObject TableModule::toXmlObject() -{ +XmlObject TableModule::toXmlObject() { XmlObject obj(getName(ModuleId::TABLE)); obj.addAttribute("Column", QString::number(ui->column_counter->value())); - for(int i = 0; i < subscriptions.count();i++){ + for(int i = 0; i < subscriptions.count(); i++) { XmlObject subscription("Subscription"); subscription.setTextValue(subscriptions[i]); obj.addChild(subscription); @@ -39,26 +35,24 @@ XmlObject TableModule::toXmlObject() return obj; } -void TableModule::fromXmlObject(const XmlObject &xmlObject) -{ - if(xmlObject.getObjectName() == getName(ModuleId::TABLE)){ +void TableModule::fromXmlObject(const XmlObject & xmlObject) { + if(xmlObject.getObjectName() == getName(ModuleId::TABLE)) { int column; - if(xmlObject.getIntAttribute("Column", column)){ + if(xmlObject.getIntAttribute("Column", column)) { onColumnNumberChanged(column); } - for(int i = 0; i < xmlObject.childCount(); i++){ + for(int i = 0; i < xmlObject.childCount(); i++) { XmlObject child = xmlObject.childAt(i); - if(child.getObjectName() == "Subscription" && child.getTextValue() != ""){ + if(child.getObjectName() == "Subscription" && child.getTextValue() != "") { onSubscriptionAdded(child.getTextValue()); } } } } -void TableModule::onSubscribeClicked() -{ +void TableModule::onSubscribeClicked() { SubscriptionsPanel *sPanel = new SubscriptionsPanel(&subscriptions); sPanel->setWindowTitle("Table Subscriptions"); connect(sPanel, &SubscriptionsPanel::SubscriptionAdded, this, &TableModule::onSubscriptionAdded); @@ -66,47 +60,41 @@ void TableModule::onSubscribeClicked() sPanel->show(); } -void TableModule::onSubscriptionAdded(const QString &subscription) -{ +void TableModule::onSubscriptionAdded(const QString & subscription) { subscriptions.append(subscription); - getCore()->getModuleMessagesBroker()->subscribe(subscription,this,[this](const ModuleMessage &msg){ + getCore()->getModuleMessagesBroker()->subscribe(subscription, this, [this](const ModuleMessage & msg) { onMsgReceived(msg); }); updateVerticalHeaders(subscription); } -void TableModule::onSubscriptionRemoved(const QString &subscription) -{ +void TableModule::onSubscriptionRemoved(const QString & subscription) { subscriptions.removeOne(subscription); getCore()->getModuleMessagesBroker()->unsubscribe(subscription, this); removeRow(subscription); } -void TableModule::removeRow(const QString &txt) -{ +void TableModule::removeRow(const QString & txt) { int row = verticalHeaders.indexOf(txt); - if(row >= 0 ){ + if(row >= 0 ) { verticalHeaders.removeAt(row); ui->tableWidget->removeRow(row); } } -void TableModule::onMsgReceived(const ModuleMessage &msg) -{ +void TableModule::onMsgReceived(const ModuleMessage & msg) { int row = updateVerticalHeaders(msg.originalTopic()); int column = updateHorizontalHeaders(msg.timestamp().toString(horizontalHeaderDateFormat)); QTableWidgetItem *newItem = new QTableWidgetItem(msg.payload()); - ui->tableWidget->setItem(row,column,newItem); + ui->tableWidget->setItem(row, column, newItem); } -int TableModule::updateVerticalHeaders(const QString &txt) -{ +int TableModule::updateVerticalHeaders(const QString & txt) { int row = verticalHeaders.indexOf(txt); - if(row >= 0){ + if(row >= 0) { return row; - } - else{ + } else { verticalHeaders.append(txt); row = verticalHeaders.count() - 1; ui->tableWidget->insertRow(row); @@ -116,22 +104,20 @@ int TableModule::updateVerticalHeaders(const QString &txt) } } -int TableModule::updateHorizontalHeaders(const QString &txt) -{ +int TableModule::updateHorizontalHeaders(const QString & txt) { int column = horizontalHeaders.indexOf(txt); - if(column >= 0){ + if(column >= 0) { return column; - } - else{ - horizontalHeaders.insert(0,txt); + } else { + horizontalHeaders.insert(0, txt); column = 0; ui->tableWidget->insertColumn(column); QTableWidgetItem *header = new QTableWidgetItem(txt); - ui->tableWidget->setHorizontalHeaderItem(column,header); + ui->tableWidget->setHorizontalHeaderItem(column, header); // Siccome è stata inserita una colonna, viene rimossa l'ultima per mantenere il columnCount - ui->tableWidget->removeColumn(ui->tableWidget->columnCount()-1); - if(horizontalHeaders.count() > ui->tableWidget->columnCount()){ + ui->tableWidget->removeColumn(ui->tableWidget->columnCount() - 1); + if(horizontalHeaders.count() > ui->tableWidget->columnCount()) { horizontalHeaders.removeLast(); } return column; @@ -140,47 +126,43 @@ int TableModule::updateHorizontalHeaders(const QString &txt) -void TableModule::addCustomActionsToMenu() -{ +void TableModule::addCustomActionsToMenu() { QAction* subscribe = new QAction("Subscribe"); - connect(subscribe, &QAction::triggered,this, &TableModule::onSubscribeClicked); + connect(subscribe, &QAction::triggered, this, &TableModule::onSubscribeClicked); addActionToMenu(subscribe); } -void TableModule::onColumnNumberChanged(int columnNumber) -{ +void TableModule::onColumnNumberChanged(int columnNumber) { ui->tableWidget->setColumnCount(columnNumber); - while(horizontalHeaders.count() > columnNumber && columnNumber >= 0){ + while(horizontalHeaders.count() > columnNumber && columnNumber >= 0) { horizontalHeaders.removeLast(); } - if(ui->column_counter->value() != columnNumber){ + if(ui->column_counter->value() != columnNumber) { ui->column_counter->setValue(columnNumber); } } -void TableModule::onTableTitleRenameRequest() -{ +void TableModule::onTableTitleRenameRequest() { bool ok; - QString tableName = QInputDialog::getText(this, "Config name","Insert the name for this Table",QLineEdit::Normal, QString(),&ok); + QString tableName = QInputDialog::getText(this, "Config name", "Insert the name for this Table", QLineEdit::Normal, QString(), &ok); - if(ok && !tableName.isEmpty()){ + if(ok && !tableName.isEmpty()) { ui->label_tableTitle->setText(tableName); } } -void TableModule::connectUiSlots() -{ -// connect(ui->button_test, &QPushButton::clicked, this, [this](){ -// //this->getManager()->publish("Table/T1", "TableModule >> ciao ciao"); -// Message m("Table/T1","Bellaa", QDateTime::currentDateTime()); -// getManager()->publish(m); -// }); +void TableModule::connectUiSlots() { + // connect(ui->button_test, &QPushButton::clicked, this, [this](){ + // //this->getManager()->publish("Table/T1", "TableModule >> ciao ciao"); + // Message m("Table/T1","Bellaa", QDateTime::currentDateTime()); + // getManager()->publish(m); + // }); - connect(ui->column_counter,SIGNAL(valueChanged(int)), this, SLOT(onColumnNumberChanged(int))); + connect(ui->column_counter, SIGNAL(valueChanged(int)), this, SLOT(onColumnNumberChanged(int))); connect(ui->label_tableTitle, &QLabel::customContextMenuRequested, this, &TableModule::onTableTitleRenameRequest); -// connect(ui->lineEdit_dateFormat, &QLineEdit::editingFinished, this, [this](){ -// horizontalHeaderDateFormat = ui->lineEdit_dateFormat->text(); -// }); + // connect(ui->lineEdit_dateFormat, &QLineEdit::editingFinished, this, [this](){ + // horizontalHeaderDateFormat = ui->lineEdit_dateFormat->text(); + // }); } diff --git a/Modules/Table/tablemodule.h b/Modules/Table/tablemodule.h index 252c8632aba07b572f4e81631bed6351d6d17921..c04322ec5cc86f63c7ae2d244da856d49af297b4 100644 --- a/Modules/Table/tablemodule.h +++ b/Modules/Table/tablemodule.h @@ -12,19 +12,18 @@ namespace Ui { class TableModule; } -class TableModule : public DefaultModule -{ +class TableModule : public DefaultModule { Q_OBJECT -public: + public: explicit TableModule(QWidget *parent = nullptr); ~TableModule(); - QWidget *toWidget() override; + QWidget *toWidget() override; XmlObject toXmlObject() override; void fromXmlObject(const XmlObject &xmlObject) override; -public slots: + public slots: void onSubscribeClicked(); void onSubscriptionAdded(const QString &subscription); void onSubscriptionRemoved(const QString &subscription); @@ -32,14 +31,14 @@ public slots: void onColumnNumberChanged(int columnNumber); void onTableTitleRenameRequest(); -protected: + protected: void connectUiSlots(); int updateVerticalHeaders(const QString &txt); int updateHorizontalHeaders(const QString &txt); void removeRow(const QString &txt); void addCustomActionsToMenu() override; -private: + private: Ui::TableModule *ui; QStringList subscriptions; QStringList verticalHeaders; diff --git a/Modules/Test/testmodule.cpp b/Modules/Test/testmodule.cpp index 4a858d718cb0660328ea8bed21ffa8103dbe9b99..846e6810b61b3f5799e45d9fd8c8c3353211b674 100644 --- a/Modules/Test/testmodule.cpp +++ b/Modules/Test/testmodule.cpp @@ -5,64 +5,55 @@ #include "Core/modulesmanager.h" #include "Core/modulemessagesbroker.h" -TestModule::TestModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::TestModule) -{ +TestModule::TestModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::TestModule) { ui->setupUi(this); defaultContextMenuSetup(); maxChar = ui->maxChar_spinBox->value(); - connect(ui->maxChar_spinBox,SIGNAL(valueChanged(int)),this,SLOT(onMaxCharChanged(int))); + connect(ui->maxChar_spinBox, SIGNAL(valueChanged(int)), this, SLOT(onMaxCharChanged(int))); } -TestModule::~TestModule() -{ +TestModule::~TestModule() { delete ui; } -QWidget* TestModule::toWidget() -{ +QWidget* TestModule::toWidget() { return this; } -XmlObject TestModule::toXmlObject() -{ +XmlObject TestModule::toXmlObject() { return XmlObject(getName(ModuleId::BROKERTEST)); } -void TestModule::fromXmlObject(const XmlObject &xmlObject) -{ +void TestModule::fromXmlObject(const XmlObject &xmlObject) { Q_UNUSED(xmlObject); } -void TestModule::on_publish_button_clicked() -{ +void TestModule::on_publish_button_clicked() { QString topic = ui->topic_lineEdit->text().trimmed(); QString payload = ui->payload_lineEdit->text().trimmed(); - ModuleMessage msg(topic,payload, QTime::currentTime()); + ModuleMessage msg(topic, payload, QTime::currentTime()); getCore()->getModuleMessagesBroker()->publish(msg); } -void TestModule::on_subscribe_button_clicked() -{ - getCore()->getModuleMessagesBroker()->subscribe(ui->subscribe_lineEdit->text().trimmed(),this,[this](const ModuleMessage &msg){ +void TestModule::on_subscribe_button_clicked() { + getCore()->getModuleMessagesBroker()->subscribe(ui->subscribe_lineEdit->text().trimmed(), this, [this](const ModuleMessage & msg) { QString oldText = ui->textArea->toPlainText(); QString line = QDateTime::currentDateTime().toString("hh.mm.ss (zzz): ") + "(Topic) " + msg.originalTopic() + " -> " + msg.payload() + " (payload)"; auto i = msg.getOptions().attributesIterator(); - while(i.hasNext() && line.count() < maxChar){ + while(i.hasNext() && line.count() < maxChar) { i.next(); - line = line + ", " + i.value() + " ("+i.key()+")"; + line = line + ", " + i.value() + " (" + i.key() + ")"; } QString newText(line + '\n' + oldText); ui->textArea->setPlainText(newText.mid(0, maxChar)); }); } -void TestModule::on_unsubscribe_button_clicked() -{ - getCore()->getModuleMessagesBroker()->unsubscribe(ui->subscribe_lineEdit->text().trimmed(),this); +void TestModule::on_unsubscribe_button_clicked() { + getCore()->getModuleMessagesBroker()->unsubscribe(ui->subscribe_lineEdit->text().trimmed(), this); } -void TestModule::onMaxCharChanged(int value) -{ +void TestModule::onMaxCharChanged(int value) { maxChar = value; } diff --git a/Modules/Test/testmodule.h b/Modules/Test/testmodule.h index 377f3c4f2ff0c6290902fc8a3399d049f6fdb310..4569168e706539a5270a973105355f9310b8e84e 100644 --- a/Modules/Test/testmodule.h +++ b/Modules/Test/testmodule.h @@ -8,11 +8,10 @@ namespace Ui { class TestModule; } -class TestModule : public DefaultModule -{ +class TestModule : public DefaultModule { Q_OBJECT -public: + public: explicit TestModule(QWidget *parent = nullptr); ~TestModule(); @@ -20,7 +19,7 @@ public: XmlObject toXmlObject() override; void fromXmlObject(const XmlObject &xmlObject) override; -private slots: + private slots: void on_publish_button_clicked(); void on_subscribe_button_clicked(); @@ -28,7 +27,7 @@ private slots: void on_unsubscribe_button_clicked(); void onMaxCharChanged(int value); -private: + private: Ui::TestModule *ui; int maxChar = 2000; diff --git a/Modules/TimerController/timercontrollermodule.cpp b/Modules/TimerController/timercontrollermodule.cpp index beadef345a5ba70c6286ab611107c4574b7a2ef4..3175f2161081a3259fb3084904871b7b73afb51e 100644 --- a/Modules/TimerController/timercontrollermodule.cpp +++ b/Modules/TimerController/timercontrollermodule.cpp @@ -4,8 +4,7 @@ #include <QFile> #include <QTextStream> -TimerControllerModule::TimerControllerModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::TimerControllerModule) -{ +TimerControllerModule::TimerControllerModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::TimerControllerModule) { ui->setupUi(this); connect(ui->setTimer_pushButton, &QPushButton::clicked, this, &TimerControllerModule::onSetTimerClicked); @@ -18,88 +17,75 @@ TimerControllerModule::TimerControllerModule(QWidget *parent) : DefaultModule(pa initCurrentTime(); } -TimerControllerModule::~TimerControllerModule() -{ +TimerControllerModule::~TimerControllerModule() { delete ui; } -QWidget *TimerControllerModule::toWidget() -{ +QWidget *TimerControllerModule::toWidget() { return this; } -XmlObject TimerControllerModule::toXmlObject() -{ +XmlObject TimerControllerModule::toXmlObject() { return XmlObject(getName(ModuleId::TIMER_CONTROLLER)); } -void TimerControllerModule::fromXmlObject(const XmlObject &xmlObject) -{ +void TimerControllerModule::fromXmlObject(const XmlObject &xmlObject) { Q_UNUSED(xmlObject); } -void TimerControllerModule::onSetTimerClicked() -{ +void TimerControllerModule::onSetTimerClicked() { initCurrentTime(); } -void TimerControllerModule::onStartTimerClicked() -{ +void TimerControllerModule::onStartTimerClicked() { isHold = false; - if(!timer.isActive()){ + if(!timer.isActive()) { timer.start(timerIntervalMs); } setInfoLabel(""); } -void TimerControllerModule::initCurrentTime() -{ +void TimerControllerModule::initCurrentTime() { int hours = ui->hours_spinBox->value(); int minutes = ui->minutes_spinBox->value(); int seconds = ui->seconds_spinBox->value(); currentTime = QTime(hours, minutes, seconds); - if(ui->increment_comboBox->currentIndex() == 0){ + if(ui->increment_comboBox->currentIndex() == 0) { increment = -1; - } - else{ + } else { increment = 1; } updateTimeLabel(); } -void TimerControllerModule::onHoldTimerClicked() -{ +void TimerControllerModule::onHoldTimerClicked() { timer.stop(); isHold = true; setInfoLabel(holdTxt); } -void TimerControllerModule::onSetInfoLabelClicked() -{ +void TimerControllerModule::onSetInfoLabelClicked() { setInfoLabel(ui->labelInfo_lineEdit->text()); } -void TimerControllerModule::onTimerTick() -{ +void TimerControllerModule::onTimerTick() { currentTime = currentTime.addSecs(getIncrement()); QString output = updateTimeLabel(); updateOutputFile(output); - if(isTimeExpired()){ + if(isTimeExpired()) { increment = increment * -1; } } -void TimerControllerModule::onEnableOutputToggled(bool val) -{ +void TimerControllerModule::onEnableOutputToggled(bool val) { ui->outputFilePath_lineEdit->setEnabled(!val); isOutputEnabled = val; } -QString TimerControllerModule::updateTimeLabel() -{ +QString TimerControllerModule::updateTimeLabel() { QString newTime = currentTime.toString(timeFormat); QString newPrefix = getPrefix(); @@ -109,19 +95,17 @@ QString TimerControllerModule::updateTimeLabel() return newPrefix + newTime; } -void TimerControllerModule::setInfoLabel(const QString &txt) -{ +void TimerControllerModule::setInfoLabel(const QString &txt) { ui->Info_label->setText(txt); ui->labelInfo_lineEdit->clear(); } -void TimerControllerModule::updateOutputFile(const QString &outputTxt) const -{ - if(!isOutputEnabled){ +void TimerControllerModule::updateOutputFile(const QString &outputTxt) const { + if(!isOutputEnabled) { return; } - if(isOutputEnabled){ + if(isOutputEnabled) { QString filePath = ui->outputFilePath_lineEdit->text().trimmed(); QFile file(filePath); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) @@ -132,24 +116,21 @@ void TimerControllerModule::updateOutputFile(const QString &outputTxt) const } } -QString TimerControllerModule::getPrefix() const -{ - if(getIncrement() > 0){ +QString TimerControllerModule::getPrefix() const { + if(getIncrement() > 0) { return tPlus; - }else if (getIncrement() < 0){ + } else if (getIncrement() < 0) { return tMinus; } return ui->prefix_label->text(); } -bool TimerControllerModule::isTimeExpired() const -{ +bool TimerControllerModule::isTimeExpired() const { return currentTime.hour() == 0 && currentTime.minute() == 0 && currentTime.second() == 0; } -int TimerControllerModule::getIncrement() const -{ - if(isHold){ +int TimerControllerModule::getIncrement() const { + if(isHold) { return 0; } return increment; diff --git a/Modules/TimerController/timercontrollermodule.h b/Modules/TimerController/timercontrollermodule.h index f8cbe8168934d7d7775d90fb249e1e25c4a20a40..296cb7a5ea0716e433b889be21ad3ad378daf558 100644 --- a/Modules/TimerController/timercontrollermodule.h +++ b/Modules/TimerController/timercontrollermodule.h @@ -11,11 +11,10 @@ namespace Ui { class TimerControllerModule; } -class TimerControllerModule : public DefaultModule -{ +class TimerControllerModule : public DefaultModule { Q_OBJECT -public: + public: explicit TimerControllerModule(QWidget *parent = nullptr); ~TimerControllerModule(); @@ -25,7 +24,7 @@ public: void fromXmlObject(const XmlObject &xmlObject) override; -protected: + protected: void onSetTimerClicked(); void onStartTimerClicked(); void onHoldTimerClicked(); @@ -42,7 +41,7 @@ protected: bool isTimeExpired() const; int getIncrement() const; -private: + private: Ui::TimerControllerModule *ui; QTimer timer; QString timeFormat = "hh:mm:ss"; diff --git a/Modules/TreeViewer/treevieweritem.cpp b/Modules/TreeViewer/treevieweritem.cpp index 211277c35a4c281e09e52bc316fc4a9f316c06ca..028de6a3d37ff93d53c52daf278ad13e9235b8ea 100644 --- a/Modules/TreeViewer/treevieweritem.cpp +++ b/Modules/TreeViewer/treevieweritem.cpp @@ -1,45 +1,40 @@ #include "treevieweritem.h" -TreeViewerItem::TreeViewerItem() : QObject(), QTreeWidgetItem() -{ +TreeViewerItem::TreeViewerItem() : QObject(), QTreeWidgetItem() { } -TreeViewerItem::TreeViewerItem(const XmlObject &xml) : TreeViewerItem() -{ +TreeViewerItem::TreeViewerItem(const XmlObject &xml) : TreeViewerItem() { this->xml = xml; setText(0, xml.getObjectName()); int count = 1; auto i = xml.attributesIterator(); - while(i.hasNext()){ + while(i.hasNext()) { i.next(); // line = line + ", " + i.value() + " ("+i.key()+")"; setText(count, i.value()); } } -TreeViewerItem::~TreeViewerItem() -{ +TreeViewerItem::~TreeViewerItem() { } -QList<QString> TreeViewerItem::getAttributesNameList() const -{ +QList<QString> TreeViewerItem::getAttributesNameList() const { QList<QString> list; auto i = xml.attributesIterator(); - while(i.hasNext()){ + while(i.hasNext()) { i.next(); list.append(i.key()); } return list; } -void TreeViewerItem::setAttributesColumn(QList<QString> headers) -{ - for(int column = 0; column < headers.count(); column++){ - if(xml.hasAttribute(headers[column])){ +void TreeViewerItem::setAttributesColumn(QList<QString> headers) { + for(int column = 0; column < headers.count(); column++) { + if(xml.hasAttribute(headers[column])) { setText(column, xml.getAttribute(headers[column])); } } diff --git a/Modules/TreeViewer/treevieweritem.h b/Modules/TreeViewer/treevieweritem.h index c9a90cd094bdef80d8adfff55283b0bb2685c439..57c755797a2e6c66e2ef2f6046b34336be8d6bc3 100644 --- a/Modules/TreeViewer/treevieweritem.h +++ b/Modules/TreeViewer/treevieweritem.h @@ -5,17 +5,16 @@ #include <QTreeWidgetItem> #include "Core/xmlobject.h" -class TreeViewerItem : public QObject, public QTreeWidgetItem -{ +class TreeViewerItem : public QObject, public QTreeWidgetItem { Q_OBJECT -public: + public: TreeViewerItem(); TreeViewerItem(const XmlObject &xml); ~TreeViewerItem(); QList<QString> getAttributesNameList() const; void setAttributesColumn(QList<QString> headers); -private: + private: XmlObject xml; }; diff --git a/Modules/Utility/contextmenuseparator.cpp b/Modules/Utility/contextmenuseparator.cpp index cda7f4f81ff76d45e9d9f2ffb9977faef8feb5da..40d389173fa99f0aefcc81d5ed2f53ceece76444 100644 --- a/Modules/Utility/contextmenuseparator.cpp +++ b/Modules/Utility/contextmenuseparator.cpp @@ -1,34 +1,28 @@ #include "contextmenuseparator.h" -ContextMenuSeparator::ContextMenuSeparator(QWidget *parent) : QWidgetAction(parent) -{ +ContextMenuSeparator::ContextMenuSeparator(QWidget *parent) : QWidgetAction(parent) { build(); } -ContextMenuSeparator::ContextMenuSeparator(const QString &txt, QWidget *parent) : QWidgetAction(parent) -{ +ContextMenuSeparator::ContextMenuSeparator(const QString &txt, QWidget *parent) : QWidgetAction(parent) { setText(txt); build(); } -ContextMenuSeparator::~ContextMenuSeparator() -{ +ContextMenuSeparator::~ContextMenuSeparator() { } -void ContextMenuSeparator::setHeight(int val) -{ +void ContextMenuSeparator::setHeight(int val) { label.setMaximumHeight(val); } -void ContextMenuSeparator::setText(const QString &txt) -{ +void ContextMenuSeparator::setText(const QString &txt) { label.setText(txt); } -void ContextMenuSeparator::build() -{ +void ContextMenuSeparator::build() { setHeight(2); // grayish style label.setStyleSheet("background: #DBDBDB;"); diff --git a/Modules/Utility/contextmenuseparator.h b/Modules/Utility/contextmenuseparator.h index db7a7876de9f96728bc375ce4831ebd786a2848f..ec51c6fb2367e709168197489907a158381fd51c 100644 --- a/Modules/Utility/contextmenuseparator.h +++ b/Modules/Utility/contextmenuseparator.h @@ -5,18 +5,17 @@ #include <QWidgetAction> #include <QLabel> -class ContextMenuSeparator : public QWidgetAction -{ -public: +class ContextMenuSeparator : public QWidgetAction { + public: ContextMenuSeparator(QWidget *parent = nullptr); - ContextMenuSeparator(const QString &txt ,QWidget *parent = nullptr); + ContextMenuSeparator(const QString &txt, QWidget *parent = nullptr); ~ContextMenuSeparator(); void setHeight(int val); void setText(const QString &txt); -protected: + protected: void build(); -private: + private: QLabel label; }; diff --git a/Modules/Utility/modulespicker.cpp b/Modules/Utility/modulespicker.cpp index aa30d4d7a1dda5fa59d36bb5fcb819df2d41e1cf..18c969ece650ea5bfd24a2b41a4b84ae3bc24ed1 100644 --- a/Modules/Utility/modulespicker.cpp +++ b/Modules/Utility/modulespicker.cpp @@ -5,39 +5,38 @@ #include <QPushButton> #include <QDebug> -ModulesPicker::ModulesPicker() : QDialog(), ui(new Ui::ModulesPicker) -{ +ModulesPicker::ModulesPicker() : QDialog(), ui(new Ui::ModulesPicker) { ui->setupUi(this); createAndConnectUI(); this->setAttribute(Qt::WA_DeleteOnClose, true); // WA_DeleteOnClose is set to true, so this widget will be deleted on close } -ModulesPicker::~ModulesPicker() -{ +ModulesPicker::~ModulesPicker() { delete ui; } -void ModulesPicker::createAndConnectUI() -{ +void ModulesPicker::createAndConnectUI() { connect(ui->button_createModule, &QPushButton::clicked, this, &ModulesPicker::onCreateModuleButtonClick); // The splitter is handled separatelly from the others modules because it need parameters. // An alternative would be to remove the parameters and in the constructor of the splitter ask to the user (with a popup) // wich orientation he prefere. Or just remove the choice and use the context menu to chang orientation. - connect(ui->button_splitter,&QPushButton::clicked,this, &ModulesPicker::onSplitterButtonClick); + connect(ui->button_splitter, &QPushButton::clicked, this, &ModulesPicker::onSplitterButtonClick); /* Important: * The text of this buttons is set to be the name of the module to load onclick */ - for(ModuleInfo moduleInfo : ModulesManager::getModulesInfo()){ + for(ModuleInfo moduleInfo : ModulesManager::getModulesInfo()) { switch (moduleInfo.getModuleCategory()) { - case ModuleCategory::DEFAULT : ui->comboBox_modulesList->addItem(moduleInfo.getModuleName()); break; + case ModuleCategory::DEFAULT : + ui->comboBox_modulesList->addItem(moduleInfo.getModuleName()); + break; case ModuleCategory::DATASOURCE : ui->data_source_layout->insertWidget(0, createButton(moduleInfo.getModuleName())); break; @@ -57,26 +56,23 @@ void ModulesPicker::createAndConnectUI() } -void ModulesPicker::connectSlot(QPushButton *button) -{ - connect(button, &QPushButton::clicked, this, [this, button](){ +void ModulesPicker::connectSlot(QPushButton *button) { + connect(button, &QPushButton::clicked, this, [this, button]() { Module* module = ModulesManager::instantiateModuleByName(button->text()); - if(module != nullptr){ + if(module != nullptr) { onModuleSelected(module); } }); } -void ModulesPicker::onCreateModuleButtonClick() -{ +void ModulesPicker::onCreateModuleButtonClick() { QString moduleName = ui->comboBox_modulesList->currentText(); onModuleSelected(moduleName); } -void ModulesPicker::onSplitterButtonClick() -{ +void ModulesPicker::onSplitterButtonClick() { Qt::Orientation orientation = Qt::Horizontal; - if(ui->radioButton_vertical->isChecked()){ + if(ui->radioButton_vertical->isChecked()) { orientation = Qt::Vertical; } @@ -85,17 +81,16 @@ void ModulesPicker::onSplitterButtonClick() Module* module = ModulesManager::instantiateModuleById(ModuleId::SPLITTER); - if(module != nullptr){ + if(module != nullptr) { module->initialize(params); onModuleSelected(module); } } -QPushButton *ModulesPicker::createButton(const QString &name) -{ +QPushButton *ModulesPicker::createButton(const QString &name) { QPushButton *button = new QPushButton(name); - connect(button, &QPushButton::clicked,this, [this, button](){ - if(button != nullptr){ + connect(button, &QPushButton::clicked, this, [this, button]() { + if(button != nullptr) { onModuleSelected(button->text()); } }); @@ -104,15 +99,13 @@ QPushButton *ModulesPicker::createButton(const QString &name) } -void ModulesPicker::onModuleSelected(const QString &mName) -{ +void ModulesPicker::onModuleSelected(const QString &mName) { Module *module = ModulesManager::instantiateModuleByName(mName); if(module != nullptr) onModuleSelected(module); } -void ModulesPicker::onModuleSelected(Module *module) -{ +void ModulesPicker::onModuleSelected(Module *module) { *selectedModule = module; emit moduleSelected(module); this->close(); // WA_DeleteOnClose is set to true, so this widget will be deleted on close @@ -120,8 +113,7 @@ void ModulesPicker::onModuleSelected(Module *module) -Module *ModulesPicker::start() -{ +Module *ModulesPicker::start() { Module* mSelected = nullptr; selectedModule = &mSelected; this->exec(); diff --git a/Modules/Utility/modulespicker.h b/Modules/Utility/modulespicker.h index 6dd1688b3873b4e1f8daa81562d1e3824a3b7849..aaa76250ce3088e283519844f6b9e2b3b2db8be5 100644 --- a/Modules/Utility/modulespicker.h +++ b/Modules/Utility/modulespicker.h @@ -11,11 +11,10 @@ namespace Ui { class ModulesPicker; } -class ModulesPicker : public QDialog -{ +class ModulesPicker : public QDialog { Q_OBJECT -public: + public: explicit ModulesPicker(); ~ModulesPicker() override; @@ -24,21 +23,21 @@ public: void onModuleSelected(const QString &mName); Module* start(); -// QWidget* toWidget() override; -// XmlObject toXmlObject() override; -// void fromXmlObject(const XmlObject &xmlObject) override; + // QWidget* toWidget() override; + // XmlObject toXmlObject() override; + // void fromXmlObject(const XmlObject &xmlObject) override; -signals: + signals: void moduleSelected(Module* selectedModule); -protected: + protected: void createAndConnectUI(); void connectSlot(QPushButton *button); void onCreateModuleButtonClick(); void onSplitterButtonClick(); QPushButton* createButton(const QString &name); -private: + private: Ui::ModulesPicker *ui; Module** selectedModule = nullptr; }; diff --git a/Modules/Utility/saveconfigurationdialog.cpp b/Modules/Utility/saveconfigurationdialog.cpp index 896a20772a2e42478b25afd238893f09a603c173..227682468727c7f04034657233c7587d4c2c7881 100644 --- a/Modules/Utility/saveconfigurationdialog.cpp +++ b/Modules/Utility/saveconfigurationdialog.cpp @@ -4,8 +4,7 @@ #include <QFileDialog> -SaveConfigurationDialog::SaveConfigurationDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SaveConfigurationDialog) -{ +SaveConfigurationDialog::SaveConfigurationDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SaveConfigurationDialog) { ui->setupUi(this); this->setAttribute(Qt::WA_DeleteOnClose, true); // WA_DeleteOnClose is set to true, so this widget will be deleted on close @@ -13,13 +12,11 @@ SaveConfigurationDialog::SaveConfigurationDialog(QWidget *parent) : QDialog(pare connect(ui->pushButton_selectIcon, &QPushButton::clicked, this, &SaveConfigurationDialog::onSelectIconPathClicked); } -SaveConfigurationDialog::~SaveConfigurationDialog() -{ +SaveConfigurationDialog::~SaveConfigurationDialog() { delete ui; } -void SaveConfigurationDialog::pickConfigData(QString *name, QString *iconPath, QString *description) -{ +void SaveConfigurationDialog::pickConfigData(QString *name, QString *iconPath, QString *description) { this->name = name; this->iconPath = iconPath; this->description = description; @@ -27,44 +24,36 @@ void SaveConfigurationDialog::pickConfigData(QString *name, QString *iconPath, Q this->exec(); } -QString SaveConfigurationDialog::getConfigName() const -{ +QString SaveConfigurationDialog::getConfigName() const { return ui->textEdit_configName->text().trimmed(); } -QString SaveConfigurationDialog::getConfigIconPath() const -{ +QString SaveConfigurationDialog::getConfigIconPath() const { return ui->textEdit_iconPath->toPlainText().trimmed(); } -QString SaveConfigurationDialog::getConfigDescription() const -{ +QString SaveConfigurationDialog::getConfigDescription() const { return ui->textEdit_description->toPlainText().trimmed(); } -void SaveConfigurationDialog::setConfigName(const QString &value) -{ +void SaveConfigurationDialog::setConfigName(const QString &value) { ui->textEdit_configName->setText(value); } -void SaveConfigurationDialog::setConfigIconPath(const QString &value) -{ +void SaveConfigurationDialog::setConfigIconPath(const QString &value) { ui->textEdit_iconPath->setText(value); } -void SaveConfigurationDialog::setConfigDescription(const QString &value) -{ +void SaveConfigurationDialog::setConfigDescription(const QString &value) { ui->textEdit_description->setText(value); } -void SaveConfigurationDialog::onSelectIconPathClicked() -{ - QString filePath = QFileDialog::getOpenFileName(nullptr, "Select config icon","","(*.jpeg, *.png., *.jpg)"); +void SaveConfigurationDialog::onSelectIconPathClicked() { + QString filePath = QFileDialog::getOpenFileName(nullptr, "Select config icon", "", "(*.jpeg, *.png., *.jpg)"); setConfigIconPath(filePath); } -void SaveConfigurationDialog::onSaveConfigClicked() -{ +void SaveConfigurationDialog::onSaveConfigClicked() { (*name) = getConfigName(); (*iconPath) = getConfigIconPath(); (*description) = getConfigDescription(); diff --git a/Modules/Utility/saveconfigurationdialog.h b/Modules/Utility/saveconfigurationdialog.h index da6a11c4970864236299ebfe77e61be5404e9259..dbad5191c0883a967823ee2ea0c8eb1118704ed5 100644 --- a/Modules/Utility/saveconfigurationdialog.h +++ b/Modules/Utility/saveconfigurationdialog.h @@ -7,11 +7,10 @@ namespace Ui { class SaveConfigurationDialog; } -class SaveConfigurationDialog : public QDialog -{ +class SaveConfigurationDialog : public QDialog { Q_OBJECT -public: + public: explicit SaveConfigurationDialog(QWidget *parent = nullptr); ~SaveConfigurationDialog(); @@ -20,7 +19,7 @@ public: void setConfigIconPath(const QString &value); void setConfigDescription(const QString &value); -protected: + protected: void onSelectIconPathClicked(); @@ -30,7 +29,7 @@ protected: QString getConfigIconPath() const; QString getConfigDescription() const; -private: + private: Ui::SaveConfigurationDialog *ui; QString *name = nullptr, *iconPath = nullptr, *description = nullptr; }; diff --git a/Modules/Utility/subscriptionspanel.cpp b/Modules/Utility/subscriptionspanel.cpp index 5629ee833d8adbfc220bdddc8340bba953da823c..9c6f5558737981a43a41c18db6c826af677df7b0 100644 --- a/Modules/Utility/subscriptionspanel.cpp +++ b/Modules/Utility/subscriptionspanel.cpp @@ -3,12 +3,11 @@ #include <QDebug> -SubscriptionsPanel::SubscriptionsPanel(const QList<QString> *subscriptionsList, QWidget *parent) : QWidget(parent), ui(new Ui::SubscriptionsPanel) -{ +SubscriptionsPanel::SubscriptionsPanel(const QList<QString> *subscriptionsList, QWidget *parent) : QWidget(parent), ui(new Ui::SubscriptionsPanel) { ui->setupUi(this); this->setAttribute(Qt::WA_DeleteOnClose, true); - for(auto s : *subscriptionsList){ + for(auto s : *subscriptionsList) { addSubscription(s); } @@ -18,13 +17,11 @@ SubscriptionsPanel::SubscriptionsPanel(const QList<QString> *subscriptionsList, connect(ui->subscriptions_list, &QListWidget::itemDoubleClicked, this, &SubscriptionsPanel::onItemDoubleClick); } -SubscriptionsPanel::~SubscriptionsPanel() -{ +SubscriptionsPanel::~SubscriptionsPanel() { delete ui; } -void SubscriptionsPanel::addSubscription(const QString &s) -{ +void SubscriptionsPanel::addSubscription(const QString &s) { QListWidgetItem *listItem = new QListWidgetItem(s); //listItem->setCheckState(Qt::Checked); //listItem->setFlags(listItem->flags() | Qt::ItemIsEditable); @@ -32,32 +29,28 @@ void SubscriptionsPanel::addSubscription(const QString &s) emit SubscriptionAdded(s); } -void SubscriptionsPanel::removeSubscription(QListWidgetItem *item) -{ +void SubscriptionsPanel::removeSubscription(QListWidgetItem *item) { emit SubscriptionRemoved(item->text()); delete item; } -void SubscriptionsPanel::onAddSubscriptionClicked() -{ +void SubscriptionsPanel::onAddSubscriptionClicked() { QString newSubscription = ui->lineEdit_topic->text().trimmed(); - if(newSubscription.length()>0){ + if(newSubscription.length() > 0) { addSubscription(newSubscription); } } -void SubscriptionsPanel::onRemoveClicked() -{ +void SubscriptionsPanel::onRemoveClicked() { auto items = ui->subscriptions_list->selectedItems(); - for(auto item : items){ + for(auto item : items) { removeSubscription(item); } } -void SubscriptionsPanel::onItemDoubleClick(QListWidgetItem *item) -{ +void SubscriptionsPanel::onItemDoubleClick(QListWidgetItem *item) { ui->lineEdit_topic->setText(item->text()); } diff --git a/Modules/Utility/subscriptionspanel.h b/Modules/Utility/subscriptionspanel.h index 02819e86a44158d205bda36c978814b7aeca783b..5d1ddde50309b7cfa3d8c2250663594bcbc9e6f4 100644 --- a/Modules/Utility/subscriptionspanel.h +++ b/Modules/Utility/subscriptionspanel.h @@ -9,27 +9,26 @@ namespace Ui { class SubscriptionsPanel; } -class SubscriptionsPanel : public QWidget -{ +class SubscriptionsPanel : public QWidget { Q_OBJECT -public: + public: explicit SubscriptionsPanel(const QList<QString> *subscriptionsList, QWidget *parent = nullptr); ~SubscriptionsPanel(); void addSubscription(const QString &s); void removeSubscription(QListWidgetItem *item); -public slots: + public slots: void onAddSubscriptionClicked(); void onRemoveClicked(); void onItemDoubleClick(QListWidgetItem *item); -signals: + signals: void SubscriptionAdded(const QString &subscription); void SubscriptionRemoved(const QString &subscription); -private: + private: Ui::SubscriptionsPanel *ui; }; diff --git a/Modules/Utility/togglebutton.cpp b/Modules/Utility/togglebutton.cpp index c5ca74c0300c9fb81fce0629ef2dafa762cfdb33..ae6fac320f84d2e0cc3c59c45e5e901adc960f12 100644 --- a/Modules/Utility/togglebutton.cpp +++ b/Modules/Utility/togglebutton.cpp @@ -1,30 +1,28 @@ #include "togglebutton.h" ToggleButton::ToggleButton(QWidget *parent) : QAbstractButton(parent), -_height(16), -_opacity(0.000), -_switch(false), -_margin(3), -_thumb("#d5d5d5"), -_anim(new QPropertyAnimation(this, "offset", this)) -{ + _height(16), + _opacity(0.000), + _switch(false), + _margin(3), + _thumb("#d5d5d5"), + _anim(new QPropertyAnimation(this, "offset", this)) { setOffset(_height / 2); _y = _height / 2; setBrush(QColor("#009688")); - connect(this, &QAbstractButton::clicked, this, [this](){ + connect(this, &QAbstractButton::clicked, this, [this]() { emit toggled(_switch); }); } ToggleButton::ToggleButton(const QBrush &brush, QWidget *parent) : QAbstractButton(parent), -_height(16), -_switch(false), -_opacity(0.000), -_margin(3), -_thumb("#d5d5d5"), -_anim(new QPropertyAnimation(this, "offset", this)) -{ + _height(16), + _switch(false), + _opacity(0.000), + _margin(3), + _thumb("#d5d5d5"), + _anim(new QPropertyAnimation(this, "offset", this)) { setOffset(_height / 2); _y = _height / 2; setBrush(brush); diff --git a/Modules/Utility/togglebutton.h b/Modules/Utility/togglebutton.h index 6b1dcb676d9461dc7ea66bc57fca9d12c29dca43..9a30dd8437b19d88931bb6ae641018f0185bf53f 100644 --- a/Modules/Utility/togglebutton.h +++ b/Modules/Utility/togglebutton.h @@ -9,7 +9,7 @@ class ToggleButton : public QAbstractButton { Q_PROPERTY(int offset READ offset WRITE setOffset) Q_PROPERTY(QBrush brush READ brush WRITE setBrush) -public: + public: ToggleButton(QWidget* parent = nullptr); ToggleButton(const QBrush& brush, QWidget* parent = nullptr); @@ -18,6 +18,7 @@ public: QBrush brush() const { return _brush; } + void setBrush(const QBrush &brsh) { _brush = brsh; } @@ -30,15 +31,15 @@ public: update(); } -signals: + signals: void toggled(bool state); -protected: + protected: void paintEvent(QPaintEvent*) override; void mouseReleaseEvent(QMouseEvent*) override; void enterEvent(QEvent*) override; -private: + private: bool _switch; qreal _opacity; int _x, _y, _height, _margin; diff --git a/Modules/ValuesConverterViewer/valueelement.cpp b/Modules/ValuesConverterViewer/valueelement.cpp index 4c34f40594dbb55de9d7cf5e86b4761e76384fde..4074912e62e72be526d605b372193ab61cfa9391 100644 --- a/Modules/ValuesConverterViewer/valueelement.cpp +++ b/Modules/ValuesConverterViewer/valueelement.cpp @@ -4,23 +4,19 @@ #include <QDebug> -ValueElement::ValueElement() -{ +ValueElement::ValueElement() { } -ValueElement::~ValueElement() -{ +ValueElement::~ValueElement() { } -ValueElement::ValueElement(const ValueElement &other) -{ +ValueElement::ValueElement(const ValueElement &other) { copy(other); } -ValueElement::ValueElement(const QString &name, const QString &topic, const QString &receivedValue, const QString &displayedValue, const QString &color, const QString &outputTopic) -{ +ValueElement::ValueElement(const QString &name, const QString &topic, const QString &receivedValue, const QString &displayedValue, const QString &color, const QString &outputTopic) { setName(name); setTopic(topic); setReceivedValue(receivedValue); @@ -29,69 +25,56 @@ ValueElement::ValueElement(const QString &name, const QString &topic, const QStr setOutpuTopic(outputTopic); } -ValueElement ValueElement::operator=(const ValueElement &other) -{ +ValueElement ValueElement::operator=(const ValueElement &other) { copy(other); return *this; } -QString ValueElement::getName() const -{ +QString ValueElement::getName() const { return name; } -void ValueElement::setName(const QString &value) -{ +void ValueElement::setName(const QString &value) { name = value; } -QString ValueElement::getTopic() const -{ +QString ValueElement::getTopic() const { return topic; } -void ValueElement::setTopic(const QString &value) -{ +void ValueElement::setTopic(const QString &value) { topic = value; } -QString ValueElement::getReceivedValue() const -{ +QString ValueElement::getReceivedValue() const { return receivedValue; } -void ValueElement::setReceivedValue(const QString &value) -{ +void ValueElement::setReceivedValue(const QString &value) { receivedValue = value; } -QString ValueElement::getDisplayedValue() const -{ +QString ValueElement::getDisplayedValue() const { return displayedValue; } -void ValueElement::setDisplayedValue(const QString &value) -{ +void ValueElement::setDisplayedValue(const QString &value) { displayedValue = value; } -QString ValueElement::getColor() const -{ +QString ValueElement::getColor() const { return color; } -void ValueElement::setColor(const QString &value) -{ +void ValueElement::setColor(const QString &value) { color = value; } -QString ValueElement::toString() const -{ +QString ValueElement::toString() const { return getName() + ": " + getTopic() + " [" + getReceivedValue() + " = " + getDisplayedValue() + "] color=" + getColor(); } -XmlObject ValueElement::toXmlObject() const -{ +XmlObject ValueElement::toXmlObject() const { XmlObject obj("Rule"); obj.addAttribute("name", getName()); obj.addAttribute("topic", getTopic()); @@ -103,12 +86,11 @@ XmlObject ValueElement::toXmlObject() const return obj; } -bool ValueElement::fromXmlObject(const XmlObject &xmlObject) -{ +bool ValueElement::fromXmlObject(const XmlObject &xmlObject) { bool result = false; - if(xmlObject.getObjectName() == "Rule" && xmlObject.hasAttribute("name")){ + if(xmlObject.getObjectName() == "Rule" && xmlObject.hasAttribute("name")) { QString name = xmlObject.getAttribute("name"); - if(name != ""){ + if(name != "") { setName(name); result = true; } @@ -120,15 +102,14 @@ bool ValueElement::fromXmlObject(const XmlObject &xmlObject) setOutpuTopic(xmlObject.getAttribute("outputTopic")); int display = 1; - if(xmlObject.getIntAttribute("displayInView", display) && (display == 0 || display == 1)){ + if(xmlObject.getIntAttribute("displayInView", display) && (display == 0 || display == 1)) { setDisplayInView(display); } } return result; } -void ValueElement::copy(const ValueElement &other) -{ +void ValueElement::copy(const ValueElement &other) { setName(other.getName()); setTopic(other.getTopic()); setReceivedValue(other.getReceivedValue()); @@ -138,43 +119,35 @@ void ValueElement::copy(const ValueElement &other) setDisplayInView(other.isDisplayInView()); } -bool ValueElement::isDisplayInView() const -{ +bool ValueElement::isDisplayInView() const { return displayInView; } -void ValueElement::setDisplayInView(bool value) -{ +void ValueElement::setDisplayInView(bool value) { displayInView = value; } -QString ValueElement::getOutpuTopic() const -{ +QString ValueElement::getOutpuTopic() const { return outpuTopic; } -void ValueElement::setOutpuTopic(const QString &value) -{ +void ValueElement::setOutpuTopic(const QString &value) { outpuTopic = value; } -bool ValueElement::isEmitActive() const -{ +bool ValueElement::isEmitActive() const { return outpuTopic != ""; } -QString ValueElement::getCurrentValue() const -{ +QString ValueElement::getCurrentValue() const { return currentValue; } -bool ValueElement::updateCurrentValue(const QString &value) -{ - if(getReceivedValue() == "" || value == getReceivedValue()){ - if(getDisplayedValue() != ""){ +bool ValueElement::updateCurrentValue(const QString &value) { + if(getReceivedValue() == "" || value == getReceivedValue()) { + if(getDisplayedValue() != "") { currentValue = getDisplayedValue(); - } - else{ + } else { currentValue = value; } return true; diff --git a/Modules/ValuesConverterViewer/valueelement.h b/Modules/ValuesConverterViewer/valueelement.h index d23a978f199ed74274d7a2adc8c2af140887ace8..0406d4036644c63b70a0ffdd172384504af308ae 100644 --- a/Modules/ValuesConverterViewer/valueelement.h +++ b/Modules/ValuesConverterViewer/valueelement.h @@ -4,10 +4,9 @@ #include <QString> #include "Core/xmlobject.h" -class ValueElement -{ +class ValueElement { -public: + public: ValueElement(); ~ValueElement(); ValueElement(const ValueElement &other); @@ -45,10 +44,10 @@ public: bool isDisplayInView() const; void setDisplayInView(bool value); -protected: + protected: void copy(const ValueElement &other); -private: + private: QString name = ""; QString topic = ""; QString receivedValue = ""; diff --git a/Modules/ValuesConverterViewer/valuesconverterviewermodule.cpp b/Modules/ValuesConverterViewer/valuesconverterviewermodule.cpp index 5c0ddefde3376f7e4decdb5f718ee453ef57add7..f79078b2799864860145002509711910c991aaf0 100644 --- a/Modules/ValuesConverterViewer/valuesconverterviewermodule.cpp +++ b/Modules/ValuesConverterViewer/valuesconverterviewermodule.cpp @@ -4,49 +4,44 @@ #include "valuesviewerconfigpanel.h" #include "Core/modulemessagesbroker.h" -ValuesConverterViewerModule::ValuesConverterViewerModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::ValuesConverterViewerModule) -{ +ValuesConverterViewerModule::ValuesConverterViewerModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::ValuesConverterViewerModule) { ui->setupUi(this); defaultContextMenuSetup(); } -ValuesConverterViewerModule::~ValuesConverterViewerModule() -{ +ValuesConverterViewerModule::~ValuesConverterViewerModule() { clearLabels(); delete ui; } -QWidget *ValuesConverterViewerModule::toWidget() -{ +QWidget *ValuesConverterViewerModule::toWidget() { return this; } -XmlObject ValuesConverterViewerModule::toXmlObject() -{ +XmlObject ValuesConverterViewerModule::toXmlObject() { XmlObject obj(getName(ModuleId::VALUESCONVERTERVIEWER)); obj.addAttribute("Columns", QString::number(columns)); - for(int i = 0; i < rules.count();i++){ + for(int i = 0; i < rules.count(); i++) { obj.addChild(rules[i].toXmlObject()); } return obj; } -void ValuesConverterViewerModule::fromXmlObject(const XmlObject &xmlObject) -{ - if(xmlObject.getObjectName() == getName(ModuleId::VALUESCONVERTERVIEWER)){ +void ValuesConverterViewerModule::fromXmlObject(const XmlObject &xmlObject) { + if(xmlObject.getObjectName() == getName(ModuleId::VALUESCONVERTERVIEWER)) { int col; - if(xmlObject.getIntAttribute("Columns", col)){ + if(xmlObject.getIntAttribute("Columns", col)) { columns = col; } - for(int i = 0; i < xmlObject.childCount(); i++){ + for(int i = 0; i < xmlObject.childCount(); i++) { XmlObject child = xmlObject.childAt(i); ValueElement el; - if(el.fromXmlObject(child)){ + if(el.fromXmlObject(child)) { addRule(el); } } @@ -54,8 +49,7 @@ void ValuesConverterViewerModule::fromXmlObject(const XmlObject &xmlObject) } } -void ValuesConverterViewerModule::onConfigureClicked() -{ +void ValuesConverterViewerModule::onConfigureClicked() { ValuesViewerConfigPanel *sPanel = new ValuesViewerConfigPanel(); sPanel->setRules(rules); sPanel->setColumnsCount(columns); @@ -63,42 +57,37 @@ void ValuesConverterViewerModule::onConfigureClicked() sPanel->show(); } -void ValuesConverterViewerModule::onConfigurationSaved(ValuesViewerConfigPanel *sPanel) -{ +void ValuesConverterViewerModule::onConfigurationSaved(ValuesViewerConfigPanel *sPanel) { setRules(sPanel->getRules()); columns = sPanel->getColumnsCount(); createLabels(); } -void ValuesConverterViewerModule::addCustomActionsToMenu() -{ +void ValuesConverterViewerModule::addCustomActionsToMenu() { QAction* configure = new QAction("Configure"); - connect(configure, &QAction::triggered,this, &ValuesConverterViewerModule::onConfigureClicked); + connect(configure, &QAction::triggered, this, &ValuesConverterViewerModule::onConfigureClicked); addActionToMenu(configure); } -QLabel *ValuesConverterViewerModule::createView(const ValueElement &el) const -{ +QLabel *ValuesConverterViewerModule::createView(const ValueElement &el) const { QLabel *label = new QLabel(); label->setText(el.getName()); label->setAlignment(Qt::AlignCenter); return label; } -void ValuesConverterViewerModule::clearLabels() -{ - while(labels.count() > 0){ +void ValuesConverterViewerModule::clearLabels() { + while(labels.count() > 0) { QLabel *l = labels[0]; labels.removeAll(l); delete l; } } -void ValuesConverterViewerModule::createLabels() -{ +void ValuesConverterViewerModule::createLabels() { clearLabels(); - if(columns <= 0){ + if(columns <= 0) { columns = minColNumber; } @@ -108,17 +97,16 @@ void ValuesConverterViewerModule::createLabels() QLabel *label; int labelIndex = findLabelIndexByName(rules[i].getName()); - if(labelIndex >= 0 && labelIndex < labels.count()){ + if(labelIndex >= 0 && labelIndex < labels.count()) { label = labels[labelIndex]; - } - else{ + } else { label = createView(rules[i]); - if(col == columns){ + if(col == columns) { col = 0; row++; } - if(rules[i].isDisplayInView()){ + if(rules[i].isDisplayInView()) { ui->mainLayout_grid->addWidget(label, row, col); col++; } @@ -128,36 +116,33 @@ void ValuesConverterViewerModule::createLabels() } } -void ValuesConverterViewerModule::addRule(const ValueElement &el) -{ - if(el.getTopic() != "" && !isTopicPresent(el.getTopic())){ - getCore()->getModuleMessagesBroker()->subscribe(el.getTopic(), this, [this](const ModuleMessage &msg){ +void ValuesConverterViewerModule::addRule(const ValueElement &el) { + if(el.getTopic() != "" && !isTopicPresent(el.getTopic())) { + getCore()->getModuleMessagesBroker()->subscribe(el.getTopic(), this, [this](const ModuleMessage & msg) { onMsgReceived(msg); }); } rules.append(el); } -void ValuesConverterViewerModule::setRules(const QList<ValueElement> &rList) -{ +void ValuesConverterViewerModule::setRules(const QList<ValueElement> &rList) { clearRules(); for (int i = 0; i < rList.count(); i++ ) { addRule(rList[i]); } } -void ValuesConverterViewerModule::onMsgReceived(const ModuleMessage &msg) -{ +void ValuesConverterViewerModule::onMsgReceived(const ModuleMessage &msg) { for (int i = 0; i < rules.count(); i++ ) { - if(rules[i].getTopic() == msg.topic()){ - if(rules[i].updateCurrentValue(msg.payload())){ + if(rules[i].getTopic() == msg.topic()) { + if(rules[i].updateCurrentValue(msg.payload())) { QString time = "(" + msg.timestamp().toString("HH:mm:ss") + ")\n"; - labels[i]->setText(rules[i].getName()+"\n"+time+rules[i].getCurrentValue()); - if(rules[i].getColor() != ""){ - labels[i]->setStyleSheet("color:"+rules[i].getColor()+";"); + labels[i]->setText(rules[i].getName() + "\n" + time + rules[i].getCurrentValue()); + if(rules[i].getColor() != "") { + labels[i]->setStyleSheet("color:" + rules[i].getColor() + ";"); } - if(rules[i].isEmitActive()){ + if(rules[i].isEmitActive()) { ModuleMessage convertedMsg(msg); convertedMsg.setPayload(rules[i].getCurrentValue()); convertedMsg.setTopic(rules[i].getOutpuTopic()); @@ -168,30 +153,27 @@ void ValuesConverterViewerModule::onMsgReceived(const ModuleMessage &msg) } } -void ValuesConverterViewerModule::clearRules() -{ +void ValuesConverterViewerModule::clearRules() { for (int i = 0; i < rules.count(); i++ ) { - if(rules[i].getTopic() != ""){ + if(rules[i].getTopic() != "") { getCore()->getModuleMessagesBroker()->unsubscribe(rules[i].getTopic(), this); } } rules.clear(); } -int ValuesConverterViewerModule::findLabelIndexByName(const QString &name) -{ +int ValuesConverterViewerModule::findLabelIndexByName(const QString &name) { for (int i = 0; i < labels.count(); i++ ) { - if(labels[i]->text() == name){ + if(labels[i]->text() == name) { return i; } } return -1; } -bool ValuesConverterViewerModule::isTopicPresent(const QString &topic) -{ +bool ValuesConverterViewerModule::isTopicPresent(const QString &topic) { for (int i = 0; i < rules.count(); i++ ) { - if(rules[i].getTopic() == topic){ + if(rules[i].getTopic() == topic) { return true; } } diff --git a/Modules/ValuesConverterViewer/valuesconverterviewermodule.h b/Modules/ValuesConverterViewer/valuesconverterviewermodule.h index d203da39cae15e88a306a5023aecf8f29c96e064..bbab30256b491abb03fe8a780c93794ec73c0dda 100644 --- a/Modules/ValuesConverterViewer/valuesconverterviewermodule.h +++ b/Modules/ValuesConverterViewer/valuesconverterviewermodule.h @@ -14,11 +14,11 @@ namespace Ui { class ValuesConverterViewerModule; } -class ValuesConverterViewerModule : public DefaultModule -{ +class ValuesConverterViewerModule : public DefaultModule { + Q_OBJECT -public: + public: explicit ValuesConverterViewerModule(QWidget *parent = nullptr); ~ValuesConverterViewerModule(); @@ -28,7 +28,7 @@ public: XmlObject toXmlObject() override; void fromXmlObject(const XmlObject &xmlObject) override; -protected: + protected: void onConfigureClicked(); void onConfigurationSaved(ValuesViewerConfigPanel *sPanel); void addCustomActionsToMenu() override; @@ -42,7 +42,7 @@ protected: int findLabelIndexByName(const QString &name); bool isTopicPresent(const QString &topic); -private: + private: Ui::ValuesConverterViewerModule *ui; int minColNumber = 1; int columns = minColNumber; diff --git a/Modules/ValuesConverterViewer/valuesviewerconfigpanel.cpp b/Modules/ValuesConverterViewer/valuesviewerconfigpanel.cpp index 5f16966e185f2264dfeb378f65e4f11539d71f4a..d4abcfd2f3d5366f5d71e56c6725d5b12a9fe080 100644 --- a/Modules/ValuesConverterViewer/valuesviewerconfigpanel.cpp +++ b/Modules/ValuesConverterViewer/valuesviewerconfigpanel.cpp @@ -4,8 +4,7 @@ #include <QDebug> #include <QColorDialog> -ValuesViewerConfigPanel::ValuesViewerConfigPanel(QWidget *parent) : QWidget(parent), ui(new Ui::ValuesViewerConfigPanel) -{ +ValuesViewerConfigPanel::ValuesViewerConfigPanel(QWidget *parent) : QWidget(parent), ui(new Ui::ValuesViewerConfigPanel) { ui->setupUi(this); connect(ui->add_pushButton, &QPushButton::clicked, this, &ValuesViewerConfigPanel::onAddFieldClicked); connect(ui->edit_pushButton, &QPushButton::clicked, this, &ValuesViewerConfigPanel::onEditClicked); @@ -16,24 +15,21 @@ ValuesViewerConfigPanel::ValuesViewerConfigPanel(QWidget *parent) : QWidget(pare this->setAttribute(Qt::WA_DeleteOnClose, true); } -ValuesViewerConfigPanel::~ValuesViewerConfigPanel() -{ +ValuesViewerConfigPanel::~ValuesViewerConfigPanel() { // The QRadioButtons are destroyed automatically. delete ui; } -void ValuesViewerConfigPanel::onAddFieldClicked() -{ +void ValuesViewerConfigPanel::onAddFieldClicked() { ValueElement e = createRuleFromControls(); - if(e.getName() != ""){ + if(e.getName() != "") { int index = computeViewIndex(e.getName()); addRule(index, e); //connect(view, &QRadioButton::destroyed, this, [](){qDebug() << "ValuesViewConfigPanel: Button deleted";}); } } -ValueElement ValuesViewerConfigPanel::createRuleFromControls() -{ +ValueElement ValuesViewerConfigPanel::createRuleFromControls() { QString name = ui->name_lineEdit->text().trimmed(); QString topic = ui->topic_lineEdit->text().trimmed(); QString receivedValue = ui->receivedValue_lineEdit->text().trimmed(); @@ -47,71 +43,63 @@ ValueElement ValuesViewerConfigPanel::createRuleFromControls() } -void ValuesViewerConfigPanel::onEditClicked() -{ +void ValuesViewerConfigPanel::onEditClicked() { ValueElement e = createRuleFromControls(); - if(e.getName() != ""){ + if(e.getName() != "") { int index = findSelectedView(); - if(index>=0 && index < rules.count()){ + if(index >= 0 && index < rules.count()) { rules[index] = e; views[index]->setText(e.toString()); } } } -void ValuesViewerConfigPanel::onRemoveClicked() -{ +void ValuesViewerConfigPanel::onRemoveClicked() { int selectedView = findSelectedView(); - if(selectedView >= 0 && selectedView < rules.count()){ + if(selectedView >= 0 && selectedView < rules.count()) { rules.removeAt(selectedView); } - if(selectedView >= 0 && selectedView < views.count()){ + if(selectedView >= 0 && selectedView < views.count()) { delete views[selectedView]; views.removeAt(selectedView); } } -void ValuesViewerConfigPanel::onPickColordClicked() -{ +void ValuesViewerConfigPanel::onPickColordClicked() { QColor initial(ui->color_lineEdit->text().trimmed()); QColor color = QColorDialog::getColor(initial, this); ui->color_lineEdit->setText(color.name()); } -void ValuesViewerConfigPanel::onValueElementClicked() -{ +void ValuesViewerConfigPanel::onValueElementClicked() { int selectedView = findSelectedView(); - if(selectedView >= 0 && selectedView < rules.count()){ + if(selectedView >= 0 && selectedView < rules.count()) { setTextBoxValues(rules[selectedView]); } } -void ValuesViewerConfigPanel::onSaveClicked() -{ +void ValuesViewerConfigPanel::onSaveClicked() { emit configurationSaved(this); this->close(); } -int ValuesViewerConfigPanel::computeViewIndex(const QString &viewName) -{ +int ValuesViewerConfigPanel::computeViewIndex(const QString &viewName) { int i = 0; for (; i < rules.count(); i++ ) { - if(rules.at(i).getName().compare(viewName) >= 0){ + if(rules.at(i).getName().compare(viewName) >= 0) { return i; } } return i; } -QRadioButton *ValuesViewerConfigPanel::createView(const ValueElement &el) -{ +QRadioButton *ValuesViewerConfigPanel::createView(const ValueElement &el) { //qDebug() << "ValuesViewConfigPanel: Button created"; return new QRadioButton(el.toString()); } -void ValuesViewerConfigPanel::setTextBoxValues(const ValueElement &el) -{ +void ValuesViewerConfigPanel::setTextBoxValues(const ValueElement &el) { ui->name_lineEdit->setText(el.getName()); ui->topic_lineEdit->setText(el.getTopic()); ui->receivedValue_lineEdit->setText(el.getReceivedValue()); @@ -120,28 +108,25 @@ void ValuesViewerConfigPanel::setTextBoxValues(const ValueElement &el) ui->displayInView_checkBox->setChecked(el.isDisplayInView()); - if(el.isEmitActive()){ + if(el.isEmitActive()) { ui->outputTopic_lineEdit->setText(el.getOutpuTopic()); ui->emit_radioButton->setChecked(true); - } - else{ + } else { ui->doNotEmit_radioButton->setChecked(true); ui->outputTopic_lineEdit->setText(""); } } -int ValuesViewerConfigPanel::findSelectedView() const -{ +int ValuesViewerConfigPanel::findSelectedView() const { for (int i = 0; i < views.count(); i++) { - if(views[i]->isChecked()){ + if(views[i]->isChecked()) { return i; } } return -1; } -void ValuesViewerConfigPanel::addRule(int index, const ValueElement &el) -{ +void ValuesViewerConfigPanel::addRule(int index, const ValueElement &el) { rules.insert(index, el); QRadioButton *view = createView(el); views.insert(index, view); @@ -149,35 +134,30 @@ void ValuesViewerConfigPanel::addRule(int index, const ValueElement &el) connect(view, &QRadioButton::clicked, this, &ValuesViewerConfigPanel::onValueElementClicked); } -void ValuesViewerConfigPanel::onEmitRadioButtonToggled(bool val) -{ +void ValuesViewerConfigPanel::onEmitRadioButtonToggled(bool val) { ui->outputTopic_lineEdit->setEnabled(val); - if(val == false){ + if(val == false) { ui->outputTopic_lineEdit->setText(""); } } -void ValuesViewerConfigPanel::setRules(const QList<ValueElement> &newValues) -{ +void ValuesViewerConfigPanel::setRules(const QList<ValueElement> &newValues) { for (int i = 0; i < newValues.count(); i++ ) { addRule(i, newValues[i]); } } -QList<ValueElement> ValuesViewerConfigPanel::getRules() const -{ +QList<ValueElement> ValuesViewerConfigPanel::getRules() const { return rules; } -int ValuesViewerConfigPanel::getColumnsCount() const -{ +int ValuesViewerConfigPanel::getColumnsCount() const { return ui->columns_spinBox->value(); } -void ValuesViewerConfigPanel::setColumnsCount(int value) -{ +void ValuesViewerConfigPanel::setColumnsCount(int value) { return ui->columns_spinBox->setValue(value); } diff --git a/Modules/ValuesConverterViewer/valuesviewerconfigpanel.h b/Modules/ValuesConverterViewer/valuesviewerconfigpanel.h index aa7adb9a979e6ee0c2a99b3d630d10b71d94d7d5..cc1b78ffd575de7609030140e2b651eacdb80f24 100644 --- a/Modules/ValuesConverterViewer/valuesviewerconfigpanel.h +++ b/Modules/ValuesConverterViewer/valuesviewerconfigpanel.h @@ -9,11 +9,10 @@ namespace Ui { class ValuesViewerConfigPanel; } -class ValuesViewerConfigPanel : public QWidget -{ +class ValuesViewerConfigPanel : public QWidget { Q_OBJECT -public: + public: explicit ValuesViewerConfigPanel(QWidget *parent = nullptr); ~ValuesViewerConfigPanel(); @@ -24,10 +23,10 @@ public: void setRules(const QList<ValueElement> &newValues); QList<ValueElement> getRules() const; -signals: + signals: void configurationSaved(ValuesViewerConfigPanel *sPanel); -protected: + protected: void onAddFieldClicked(); void onRemoveClicked(); void onPickColordClicked(); @@ -43,7 +42,7 @@ protected: ValueElement createRuleFromControls(); -private: + private: Ui::ValuesViewerConfigPanel *ui; QList<ValueElement> rules; diff --git a/Modules/moduleinfo.cpp b/Modules/moduleinfo.cpp index caf0931d1dc43bf9489cfbf7d038ac4c3fffda08..6dc0f4096831ead13561f36ea3f0ce01ad71945e 100644 --- a/Modules/moduleinfo.cpp +++ b/Modules/moduleinfo.cpp @@ -1,73 +1,59 @@ #include "moduleinfo.h" -ModuleInfo::ModuleInfo() -{ +ModuleInfo::ModuleInfo() { } -ModuleInfo::ModuleInfo(const ModuleId &id, const QString &name) -{ +ModuleInfo::ModuleInfo(const ModuleId &id, const QString &name) { setId(id); setModuleName(name); } -ModuleInfo::ModuleInfo(const ModuleInfo &other) -{ +ModuleInfo::ModuleInfo(const ModuleInfo &other) { copy(other); } -ModuleInfo::ModuleInfo(const ModuleId &id, const QString &name, ModuleCategory category) : ModuleInfo(id, name) -{ +ModuleInfo::ModuleInfo(const ModuleId &id, const QString &name, ModuleCategory category) : ModuleInfo(id, name) { setCategory(category); } -ModuleId ModuleInfo::getId() const -{ +ModuleId ModuleInfo::getId() const { return moduleId; } -void ModuleInfo::setId(const ModuleId &value) -{ +void ModuleInfo::setId(const ModuleId &value) { moduleId = value; } -QString ModuleInfo::getModuleName() const -{ +QString ModuleInfo::getModuleName() const { return moduleName; } -void ModuleInfo::setModuleName(const QString &value) -{ +void ModuleInfo::setModuleName(const QString &value) { moduleName = value; } -std::function<Module *()> ModuleInfo::getFactory() const -{ +std::function<Module *()> ModuleInfo::getFactory() const { return factory; } -void ModuleInfo::setFactory(const std::function<Module *()> &value) -{ +void ModuleInfo::setFactory(const std::function<Module *()> &value) { factory = value; } -QStringList ModuleInfo::getModuleSourceFiles() const -{ +QStringList ModuleInfo::getModuleSourceFiles() const { return moduleSourceFiles; } -void ModuleInfo::addModuleSourceFiles(const QString &value) -{ +void ModuleInfo::addModuleSourceFiles(const QString &value) { moduleSourceFiles.append(value); } -void ModuleInfo::operator=(const ModuleInfo &other) -{ +void ModuleInfo::operator=(const ModuleInfo &other) { copy(other); } -void ModuleInfo::copy(const ModuleInfo &other) -{ +void ModuleInfo::copy(const ModuleInfo &other) { setId(other.getId()); setCategory(other.getModuleCategory()); setModuleName(other.getModuleName()); @@ -76,12 +62,10 @@ void ModuleInfo::copy(const ModuleInfo &other) } -ModuleCategory ModuleInfo::getModuleCategory() const -{ +ModuleCategory ModuleInfo::getModuleCategory() const { return mCategory; } -void ModuleInfo::setCategory(const ModuleCategory &value) -{ +void ModuleInfo::setCategory(const ModuleCategory &value) { mCategory = value; } diff --git a/Modules/moduleinfo.h b/Modules/moduleinfo.h index 0aa4a56db15c27b86e3e589ad88b18f94edec8e5..22234f506d5d20415ed6d19c60b9a47bace78555 100644 --- a/Modules/moduleinfo.h +++ b/Modules/moduleinfo.h @@ -5,7 +5,7 @@ class Module; -enum ModuleId{ +enum ModuleId { EMPTY, SPLITTER, SKYWARDHUB, @@ -27,7 +27,7 @@ enum ModuleId{ TIMER_CONTROLLER }; -enum ModuleCategory{ +enum ModuleCategory { HIDDEN, DEFAULT, UTILITY, @@ -36,9 +36,8 @@ enum ModuleCategory{ HOME }; -class ModuleInfo -{ -public: +class ModuleInfo { + public: ModuleInfo(); ModuleInfo(const ModuleInfo &other); ModuleInfo(const ModuleId &id, const QString &name); @@ -60,10 +59,10 @@ public: ModuleCategory getModuleCategory() const; void setCategory(const ModuleCategory &value); -protected: + protected: void copy(const ModuleInfo &other); -private: + private: ModuleId moduleId; ModuleCategory mCategory = ModuleCategory::DEFAULT; QString moduleName; diff --git a/Modules/moduleslist.cpp b/Modules/moduleslist.cpp index d05a126276c5310f89b11fb3eeacc6bfea7a5072..e0b169697fd68cc7c665f6682de5e14e1acd7e08 100644 --- a/Modules/moduleslist.cpp +++ b/Modules/moduleslist.cpp @@ -22,8 +22,7 @@ #include "Modules/ValuesConverterViewer/valuesconverterviewermodule.h" #include "Modules/TimerController/timercontrollermodule.h" -void ModulesList::createModuleList() -{ +void ModulesList::createModuleList() { /* * addModule(MODULE UNIQUE ID, MODULE UNIQUE NAME, a function that instantiate your module) * If you are creating a new Module, please add it's id in the ModuleId enum (you can find it in moduleslist.h) @@ -37,192 +36,224 @@ void ModulesList::createModuleList() * (all the files that match the strings you privide will be included) */ - #ifdef EMPTYMODULE_H +#ifdef EMPTYMODULE_H ModuleInfo empty(ModuleId::EMPTY, "EmptyModule"); - empty.setFactory([](){return new EmptyModule();}); + empty.setFactory([]() { + return new EmptyModule(); + }); empty.addModuleSourceFiles("Modules/Empty/"); addModuleInfo(empty); - #endif +#endif - #ifdef SPLITTERMODULE_H +#ifdef SPLITTERMODULE_H ModuleInfo splitter(ModuleId::SPLITTER, "Splitter"); - splitter.setFactory([](){return new SplitterModule();}); + splitter.setFactory([]() { + return new SplitterModule(); + }); splitter.addModuleSourceFiles("Modules/Splitter/"); addModuleInfo(splitter); - #endif +#endif - #ifdef SKYWARDHUBMODULE_H +#ifdef SKYWARDHUBMODULE_H ModuleInfo hub(ModuleId::SKYWARDHUB, "SkywardHub", ModuleCategory::HOME); - hub.setFactory([](){return new SkywardHubModule();}); + hub.setFactory([]() { + return new SkywardHubModule(); + }); hub.addModuleSourceFiles("Modules/SkywardHub/"); addModuleInfo(hub); - #endif +#endif - #ifdef COMMANDPADMODULE_H +#ifdef COMMANDPADMODULE_H ModuleInfo cmdPad(ModuleId::COMMANDPAD, "CommandPad", ModuleCategory::UTILITY); - cmdPad.setFactory([](){return new CommandPadModule();}); + cmdPad.setFactory([]() { + return new CommandPadModule(); + }); cmdPad.addModuleSourceFiles("Modules/CommandPad/"); addModuleInfo(cmdPad); - #endif +#endif - #ifdef TELEMETRYREQUESTMODULE_H +#ifdef TELEMETRYREQUESTMODULE_H ModuleInfo telemetryPad(ModuleId::TELEMETRYPAD, "TelemetryPad", ModuleCategory::UTILITY); - telemetryPad.setFactory([](){return new TelemetryRequestModule();}); + telemetryPad.setFactory([]() { + return new TelemetryRequestModule(); + }); telemetryPad.addModuleSourceFiles("Modules/CommandPad/"); addModuleInfo(telemetryPad); - #endif +#endif - #ifdef TESTMODULE_H +#ifdef TESTMODULE_H ModuleInfo testModule(ModuleId::BROKERTEST, "TestBroker", ModuleCategory::DEFAULT); - testModule.setFactory([](){return new TestModule();}); + testModule.setFactory([]() { + return new TestModule(); + }); testModule.addModuleSourceFiles("Modules/Test/"); addModuleInfo(testModule); - #endif +#endif - #ifdef GRAPHMODULE_H +#ifdef GRAPHMODULE_H ModuleInfo graphModule(ModuleId::GRAPH, "Graph", ModuleCategory::DATAVISUAL); - graphModule.setFactory([](){return new GraphModule();}); + graphModule.setFactory([]() { + return new GraphModule(); + }); graphModule.addModuleSourceFiles("Modules/Graph/"); addModuleInfo(graphModule); - #endif +#endif - #ifdef TABLEMODULE_H +#ifdef TABLEMODULE_H ModuleInfo tableModule(ModuleId::TABLE, "Table", ModuleCategory::DATAVISUAL); - tableModule.setFactory([](){return new TableModule();}); + tableModule.setFactory([]() { + return new TableModule(); + }); tableModule.addModuleSourceFiles("Modules/Table/"); addModuleInfo(tableModule); - #endif +#endif - #ifdef IMAGEVIEWERMODULE_H +#ifdef IMAGEVIEWERMODULE_H ModuleInfo imageViewer(ModuleId::IMAGEVIEWER, "ImageViewer", ModuleCategory::DATAVISUAL); - imageViewer.setFactory([](){return new ImageViewerModule();}); + imageViewer.setFactory([]() { + return new ImageViewerModule(); + }); imageViewer.addModuleSourceFiles("Modules/ImageViewer/"); addModuleInfo(imageViewer); - #endif +#endif - #ifdef MESSAGESVIEWERMODULE_H +#ifdef MESSAGESVIEWERMODULE_H ModuleInfo msgViewer(ModuleId::MESSAGEVIEWER, "MessageViewer", ModuleCategory::DATAVISUAL); - msgViewer.setFactory([](){return new MessagesViewerModule();}); + msgViewer.setFactory([]() { + return new MessagesViewerModule(); + }); msgViewer.addModuleSourceFiles("Modules/MessageViewer/"); addModuleInfo(msgViewer); - #endif +#endif - #ifdef MAVLINKMODULE_H +#ifdef MAVLINKMODULE_H ModuleInfo mavlink(ModuleId::MAVLINK, "Mavlink", ModuleCategory::DATASOURCE); - mavlink.setFactory([](){return new MavlinkModule();}); + mavlink.setFactory([]() { + return new MavlinkModule(); + }); mavlink.addModuleSourceFiles("Modules/Mavlink/"); addModuleInfo(mavlink); - #endif +#endif - #ifdef MAVLINKROCKETMSGTESTINGMODULE_H +#ifdef MAVLINKROCKETMSGTESTINGMODULE_H ModuleInfo mvkRckTesting(ModuleId::MAVLINK_RCK_TESTING, "MavlinkRocketMsgTesting", ModuleCategory::DEFAULT); - mvkRckTesting.setFactory([](){return new MavlinkRocketMsgTestingModule();}); + mvkRckTesting.setFactory([]() { + return new MavlinkRocketMsgTestingModule(); + }); addModuleInfo(mvkRckTesting); - #endif +#endif - #ifdef TREEVIEWERMODULE_H +#ifdef TREEVIEWERMODULE_H ModuleInfo treeViewer(ModuleId::TREEVIEWER, "TreeViewer", ModuleCategory::UTILITY); - treeViewer.setFactory([](){return new TreeViewerModule();}); + treeViewer.setFactory([]() { + return new TreeViewerModule(); + }); treeViewer.addModuleSourceFiles("Modules/TreeViewer/"); addModuleInfo(treeViewer); - #endif +#endif - #ifdef SCROLLAREAMODULE_H +#ifdef SCROLLAREAMODULE_H ModuleInfo scrollArea(ModuleId::SCROLLAREA, "ScrollArea", ModuleCategory::UTILITY); - scrollArea.setFactory([](){return new ScrollAreaModule();}); + scrollArea.setFactory([]() { + return new ScrollAreaModule(); + }); scrollArea.addModuleSourceFiles("Modules/ScrollArea/"); addModuleInfo(scrollArea); - #endif +#endif - #ifdef FILESTREAMMODULE_H +#ifdef FILESTREAMMODULE_H ModuleInfo fileStream(ModuleId::FILESTREAM, "FileStream", ModuleCategory::DATASOURCE); - fileStream.setFactory([](){return new FileStreamModule();}); + fileStream.setFactory([]() { + return new FileStreamModule(); + }); fileStream.addModuleSourceFiles("Modules/FileStream/"); addModuleInfo(fileStream); - #endif +#endif - #ifdef STATEVIEWERMODULE_H +#ifdef STATEVIEWERMODULE_H ModuleInfo stateViewer(ModuleId::STATEVIEWER, "StateViewer", ModuleCategory::DATAVISUAL); - stateViewer.setFactory([](){return new StateViewerModule();}); + stateViewer.setFactory([]() { + return new StateViewerModule(); + }); stateViewer.addModuleSourceFiles("Modules/StateViewer/"); addModuleInfo(stateViewer); - #endif +#endif - #ifdef VALUESCONVERTERVIEWERMODULE_H +#ifdef VALUESCONVERTERVIEWERMODULE_H ModuleInfo valuesconverterviewer(ModuleId::VALUESCONVERTERVIEWER, "ValuesConverterViewer", ModuleCategory::UTILITY); - valuesconverterviewer.setFactory([](){return new ValuesConverterViewerModule();}); + valuesconverterviewer.setFactory([]() { + return new ValuesConverterViewerModule(); + }); valuesconverterviewer.addModuleSourceFiles("Modules/ValuesConverterViewer/"); addModuleInfo(valuesconverterviewer); - #endif +#endif - #ifdef TIMERCONTROLLERMODULE_H +#ifdef TIMERCONTROLLERMODULE_H ModuleInfo timerController(ModuleId::TIMER_CONTROLLER, "TimerController", ModuleCategory::UTILITY); - timerController.setFactory([](){return new TimerControllerModule();}); + timerController.setFactory([]() { + return new TimerControllerModule(); + }); timerController.addModuleSourceFiles("Modules/TimerController/"); addModuleInfo(timerController); - #endif +#endif } // ____________________________________________________________________________________________ -ModulesList::ModulesList() -{ +ModulesList::ModulesList() { createModuleList(); } -bool ModulesList::containsId(ModuleId id) -{ - for(int i = 0; i< modulesInfo.count(); i++){ +bool ModulesList::containsId(ModuleId id) { + for(int i = 0; i < modulesInfo.count(); i++) { if(modulesInfo[i].getId() == id) return true; } return false; } -void ModulesList::addModuleInfo(const ModuleInfo &info) -{ +void ModulesList::addModuleInfo(const ModuleInfo &info) { modulesInfo.append(info); } -QString ModulesList::getModuleName(ModuleId id) const -{ - for(int i = 0; i< modulesInfo.count(); i++){ +QString ModulesList::getModuleName(ModuleId id) const { + for(int i = 0; i < modulesInfo.count(); i++) { if(modulesInfo[i].getId() == id) return modulesInfo[i].getModuleName(); } return ""; } -std::function<Module *()> ModulesList::getFactory(ModuleId id) const -{ - for(int i = 0; i< modulesInfo.count(); i++){ +std::function<Module *()> ModulesList::getFactory(ModuleId id) const { + for(int i = 0; i < modulesInfo.count(); i++) { if(modulesInfo[i].getId() == id) return modulesInfo[i].getFactory(); } - return [](){return nullptr;}; + return []() { + return nullptr; + }; } -std::function<Module *()> ModulesList::findFactoryByModuleName(const QString &name) -{ - for(int i = 0; i< modulesInfo.count(); i++){ +std::function<Module *()> ModulesList::findFactoryByModuleName(const QString &name) { + for(int i = 0; i < modulesInfo.count(); i++) { if(modulesInfo[i].getModuleName() == name) return modulesInfo[i].getFactory(); } - return [](){return nullptr;}; + return []() { + return nullptr; + }; } -QList<QString> ModulesList::getModulesNamesList() -{ +QList<QString> ModulesList::getModulesNamesList() { QList<QString> names; - for(int i = 0; i< modulesInfo.count(); i++){ + for(int i = 0; i < modulesInfo.count(); i++) { names.append(modulesInfo[i].getModuleName()); } return names; } -QList<ModuleInfo> ModulesList::getModulesInfo() -{ +QList<ModuleInfo> ModulesList::getModulesInfo() { return modulesInfo; } diff --git a/Modules/moduleslist.h b/Modules/moduleslist.h index 1da2ab1892c56089e511fac08073fa5e445d8eef..0609d0502b26cff53dd734fdf4c0057595bcf45e 100644 --- a/Modules/moduleslist.h +++ b/Modules/moduleslist.h @@ -5,9 +5,8 @@ #include "moduleinfo.h" -class ModulesList -{ -public: +class ModulesList { + public: ModulesList(); void createModuleList(); @@ -23,7 +22,7 @@ public: QList<ModuleInfo> getModulesInfo(); -private: + private: QList<ModuleInfo> modulesInfo; }; diff --git a/Modules/skywardhubstrings.cpp b/Modules/skywardhubstrings.cpp index 46b5acd8e665f7dab01e347fbccfcb439d880c55..31ee3fd1ecbfd86be4573e66b99b09902e43213f 100644 --- a/Modules/skywardhubstrings.cpp +++ b/Modules/skywardhubstrings.cpp @@ -7,7 +7,7 @@ const QString SkywardHubStrings::defaultSettingsFilePath = defaultConfigurationF const QString SkywardHubStrings::defaultPrefabsFolderName = "Prefabs"; const QString SkywardHubStrings::defaultLogsFolder = defaultConfigurationFolder + "/" + "Logs"; const QString SkywardHubStrings::defaultStreamFile = defaultConfigurationFolder + "/" + "StreamFile.txt"; -const QString SkywardHubStrings::defaultPrefabsFolder = defaultConfigurationFolder + "/" + defaultPrefabsFolderName +"/"; +const QString SkywardHubStrings::defaultPrefabsFolder = defaultConfigurationFolder + "/" + defaultPrefabsFolderName + "/"; const QString SkywardHubStrings::defaultConfigurationFileName = "default.xml"; const QString SkywardHubStrings::defaultConfigurationIconPath = defaultConfigurationFolder + "/" + "defaultConfigIcon.svg"; @@ -47,7 +47,6 @@ const QString SkywardHubStrings::mavlink_initial_coordinates_tc_longitude_name = const QString SkywardHubStrings::mavlink_received_msg_ACK_topic = mavlink_received_msg_topic + "/ACK_TM"; -SkywardHubStrings::SkywardHubStrings() -{ +SkywardHubStrings::SkywardHubStrings() { } diff --git a/Modules/skywardhubstrings.h b/Modules/skywardhubstrings.h index 59cc49dccaca2193f9e53d6537d0649fa523c818..1eb87d97006b44a38de672f0fb55080c9d3f1285 100644 --- a/Modules/skywardhubstrings.h +++ b/Modules/skywardhubstrings.h @@ -3,9 +3,8 @@ #include <QString> -class SkywardHubStrings -{ -public: +class SkywardHubStrings { + public: SkywardHubStrings(); static const QString defaultConfigurationFolder; diff --git a/SkywardHub.pro b/SkywardHub.pro index a4583e054f68e98f9ed7d996f0033539eaedff5a..3ba69cc8812827872fcefbdeb76bd32ed0fcaa94 100644 --- a/SkywardHub.pro +++ b/SkywardHub.pro @@ -150,3 +150,6 @@ FORMS += \ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target + +DISTFILES += \ + format.astylerc diff --git a/format.astylerc b/format.astylerc new file mode 100644 index 0000000000000000000000000000000000000000..0843d7b0f06cf4df1221c840d2f45bd566af5d43 --- /dev/null +++ b/format.astylerc @@ -0,0 +1,16 @@ +# Attached braces +--style=google + +# 4 spaces +-s4 --indent=spaces=4 + +--indent-switches + +# Comments are aligned with code +--indent-col1-comments + +# Spaces between operators +--pad-oper + +# Use CRLF instead of LF +--lineend=windows diff --git a/main.cpp b/main.cpp index d69de059a75f9e3fa6a436d18ffba332c760ddc8..57584767ac1ea2b1ea8ca4dd70087ac984f225c7 100644 --- a/main.cpp +++ b/main.cpp @@ -3,8 +3,7 @@ #include <QApplication> -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { QApplication a(argc, argv); SkywardHubMainWindow skywardHub; a.setStyleSheet(skywardHub.styleSheet());