diff --git a/.vscode/settings.json b/.vscode/settings.json index 9f25ba9ffc4ef50e7318f7376545c5a0bf91e6be..8b8f9068e0501fd9b122b1df720c3f68a9560e09 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -104,7 +104,11 @@ "unordered_set": "cpp", "qtimer": "cpp", "*.inc": "cpp", - "qlist": "cpp" + "qlist": "cpp", + "qsplitter": "cpp", + "qdebug": "cpp", + "qcloseevent": "cpp", + "qthread": "cpp" }, "editor.defaultFormatter": "chiehyu.vscode-astyle", "[xml]": { @@ -113,6 +117,7 @@ "cSpell.words": [ "Mavlink", "Plottables", + "qobject", "replot" ] } \ No newline at end of file diff --git a/Components/ModulesPicker/modulespicker.cpp b/Components/ModulesPicker/modulespicker.cpp index 1553cf8e5dfee6f83942f6d6ee8efb22b5641680..c8d58b06f7f6a49fffc006cac86b4affd6975aea 100644 --- a/Components/ModulesPicker/modulespicker.cpp +++ b/Components/ModulesPicker/modulespicker.cpp @@ -1,5 +1,7 @@ #include "modulespicker.h" +#include <Modules/Splitter/Splitter.h> + #include <QDebug> #include <QPushButton> @@ -83,13 +85,11 @@ void ModulesPicker::onCreateModuleButtonClick() void ModulesPicker::createSplitter(Qt::Orientation orientation) { - XmlObject params; - params.addAttribute("Orientation", orientation); - - Module* module = ModulesManager::instantiateModuleById(ModuleId::SPLITTER); - if (module != nullptr) + Splitter* module = qobject_cast<Splitter*>( + ModulesManager::instantiateModuleById(ModuleId::SPLITTER)); + if (module) { - module->initialize(params); + module->setOrientation(orientation); onModuleSelected(module); } } @@ -120,8 +120,7 @@ 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 + this->close(); } Module* ModulesPicker::start() @@ -131,18 +130,3 @@ Module* ModulesPicker::start() this->exec(); return mSelected; } - -// QWidget *PanelsPickerModule::toWidget() -//{ -// return this; -// } - -// XmlObject PanelsPickerModule::toXmlObject() -//{ - -//} - -// void PanelsPickerModule::fromXmlObject(const XmlObject &xmlObject) -//{ -// Q_UNUSED(xmlObject); -// } diff --git a/Core/module.cpp b/Core/module.cpp index c94b7b99f3934f89aa76d2e5e21fb46ab8b3f06a..ce1ef9a7422026eba3335a5dc9d12b82b792170b 100644 --- a/Core/module.cpp +++ b/Core/module.cpp @@ -1,21 +1,7 @@ #include "module.h" -Module::Module() { +Module::Module(QWidget *parent) : QWidget(parent) {} -} +ModuleEventsHandler *Module::getModuleEventsHandler() { return &eventsHandler; } -Module::~Module() { - emit eventsHandler.beforeDelete(this); -} - -void Module::initialize(const XmlObject ¶ms) { - Q_UNUSED(params); -} - -ModuleEventsHandler* Module::getModuleEventsHandler() { - return &eventsHandler; -} - -SkywardHubCoreProxy &Module::getCore() { - return coreProxy; -} +SkywardHubCoreProxy &Module::getCore() { return coreProxy; } diff --git a/Core/module.h b/Core/module.h index 07507d0a4c103f79cd2992451e4b75fd2c139e15..7c4dd91d484534c9ab6dd177b3414c5c3ef0a09b 100644 --- a/Core/module.h +++ b/Core/module.h @@ -1,19 +1,19 @@ #ifndef MODULE_H #define MODULE_H -#include <QObject> +#include <QWidget> #include "Core/xmlobject.h" #include "moduleeventshandler.h" #include "skywardhubcore.h" -class Module +class Module : public QWidget { + Q_OBJECT + public: - Module(); - virtual ~Module(); + Module(QWidget* parent = nullptr); - virtual void initialize(const XmlObject& params); virtual QWidget* toWidget() = 0; virtual XmlObject toXmlObject() = 0; virtual void fromXmlObject(const XmlObject& xmlObject) = 0; diff --git a/Core/modulesmanager.cpp b/Core/modulesmanager.cpp index 21632ab532835da01f1fee993cb59b4b58baa506..cdccc73fbbe29a9f1effbc8eccfd8700a5bf5e27 100644 --- a/Core/modulesmanager.cpp +++ b/Core/modulesmanager.cpp @@ -9,7 +9,6 @@ #include "Core/module.h" #include "Core/xmlobject.h" #include "Modules/skywardhubstrings.h" - ModulesList ModulesManager::modulesListHandler; ModulesManager::ModulesManager() {} @@ -40,32 +39,12 @@ Module* ModulesManager::instantiateModuleById(ModuleId id) return nullptr; } -Module* ModulesManager::instantiateModuleById(ModuleId id, - const XmlObject& params) -{ - Module* m = instantiateModuleById(id); - - if (m != nullptr) - m->initialize(params); - return m; -} - Module* ModulesManager::instantiateModuleByName(const QString& moduleName) { return ModulesManager::modulesListHandler.findFactoryByModuleName( moduleName)(); } -Module* ModulesManager::instantiateModuleByName(const QString& moduleName, - const XmlObject& params) -{ - Module* m = instantiateModuleByName(moduleName); - - if (m != nullptr) - m->initialize(params); - return m; -} - QList<Module*> ModulesManager::loadModuleFromXml(XmlObject& xml) { QList<Module*> windows; @@ -74,7 +53,9 @@ QList<Module*> ModulesManager::loadModuleFromXml(XmlObject& xml) { XmlObject* child = xml.getChild(i); QString moduleName = child->getObjectName(); + Module* module = ModulesManager::instantiateModuleByName(moduleName); + if (module != nullptr) { module->fromXmlObject(*child); @@ -92,7 +73,6 @@ void ModulesManager::setModules(QList<Module*> modules) { Module* old = pages[i]; emit pages[i]->getModuleEventsHandler()->replaceMeWith(old, modules[i]); - delete old; } if (i < pages.count()) { @@ -228,17 +208,14 @@ void ModulesManager::onReplaceMeWith(Module* sender, Module* newModule) pages[index] = newModule; connectModule(newModule); disconnectModule(sender); + delete sender; } } } -bool ModulesManager::getRebuild() const { return rebuild; } - -void ModulesManager::setRebuild(bool value) { rebuild = value; } - void ModulesManager::onContextMenuRequest(QMenu& menu, const QPoint& p) { - QMenu hubMenu("Hub Menu"); + QMenu hubMenu("Global menu"); hubMenu.addActions(getHubMenuActions()); menu.addMenu(&hubMenu); emit contextMenuRequest(menu, p); @@ -251,7 +228,7 @@ QList<QAction*> ModulesManager::getHubMenuActions() QAction* save = new QAction("Save"); menuActions.append(save); connect(save, &QAction::triggered, this, - &ModulesManager::saveConfigurationService); + &ModulesManager::openConfigurationWindow); QAction* openWindows = new QAction("New Window"); menuActions.append(openWindows); @@ -267,7 +244,7 @@ QList<ModuleInfo> ModulesManager::getModulesInfo() return modulesListHandler.getModulesInfo(); } -void ModulesManager::saveConfigurationService() +void ModulesManager::openConfigurationWindow() { if (pages.isEmpty()) { @@ -329,25 +306,3 @@ void ModulesManager::saveConfigurationService() resultMsg.exec(); } } - -void ModulesManager::onFirstPageDeleted() -{ - if (!rebuild) - return; - QMessageBox msgBox; - msgBox.setWindowTitle("title"); - msgBox.setText("Do you want to close the App?"); - msgBox.setStandardButtons(QMessageBox::Yes); - msgBox.addButton(QMessageBox::No); - msgBox.setDefaultButton(QMessageBox::No); - - if (msgBox.exec() == QMessageBox::No) - { - emit pages[0]->getModuleEventsHandler()->replaceMeWith( - pages[0], instantiateDefaultModule()); - } - else - { - emit appQuitRequested(); - } -} diff --git a/Core/modulesmanager.h b/Core/modulesmanager.h index d87c6d993d871404326f34b7cf6128e24f8e101f..4288010bae1fb0eb812b17d12ae3d93b4551f8b2 100644 --- a/Core/modulesmanager.h +++ b/Core/modulesmanager.h @@ -1,77 +1,69 @@ #ifndef MODULESMANAGER_H #define MODULESMANAGER_H -#include <QObject> -#include <QString> #include <QMap> #include <QMenu> +#include <QObject> +#include <QString> + #include "Modules/moduleslist.h" class Module; class SaveConfigurationDialog; class XmlObject; -class ModulesManager : public QObject { +class ModulesManager : public QObject +{ Q_OBJECT - public: +public: ModulesManager(); ~ModulesManager(); - static Module* instantiateDefaultModule(); - static Module* invokeModulesPickerService(); + static Module *instantiateDefaultModule(); + static Module *invokeModulesPickerService(); static QList<QString> getModulesNamesList(); static QString getModuleName(ModuleId id); - static Module* instantiateModuleById(ModuleId id); - static Module* instantiateModuleById(ModuleId id, const XmlObject ¶ms); + static Module *instantiateModuleById(ModuleId id); - static Module* instantiateModuleByName(const QString &moduleName); - static Module* instantiateModuleByName(const QString &moduleName, const XmlObject ¶ms); + static Module *instantiateModuleByName(const QString &moduleName); static QList<Module *> loadModuleFromXml(XmlObject &xml); static QList<ModuleInfo> getModulesInfo(); - - - void setModules(QList<Module*> modules); - void addModules(QList<Module*> modules); + void setModules(QList<Module *> modules); + void addModules(QList<Module *> modules); void addPage(Module *module); void removePage(Module *module); - void openNewEmptyWindow(); - Module* getModuleAt(int index); + Module *getModuleAt(int index); int getModuleCount(); void clearPages(); - - bool getRebuild() const; - void setRebuild(bool value); - - QList<QAction *> getHubMenuActions(); - signals: +public slots: + void openNewEmptyWindow(); + void openConfigurationWindow(); + +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; - QList<QAction*> menuActions; - bool rebuild = true; + QList<Module *> pages; + QList<QAction *> menuActions; }; -#endif // MODULESMANAGER_H +#endif // MODULESMANAGER_H diff --git a/Core/skywardhubcore.cpp b/Core/skywardhubcore.cpp index 76a2044e7e2ebdb40dde405f1d2a74b3f051d8a2..6edd6fdf9cb019d89695a2bb63f8ba3e85e7224e 100644 --- a/Core/skywardhubcore.cpp +++ b/Core/skywardhubcore.cpp @@ -1,39 +1,47 @@ #include "skywardhubcore.h" +#include <QDebug> #include <QDir> #include <QMessageBox> -#include "modulesmanager.h" +#include "module.h" #include "moduleeventshandler.h" #include "modulemessagesbroker.h" +#include "modulesmanager.h" -#include "module.h" - -SkywardHubCore::SkywardHubCore() { - modulesManager = new ModulesManager(); - moduleEventsHandler = new ModuleEventsHandler(); +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); XmlObject defaultConfig(SkywardHubStrings::skywardHubInitFileTag); - defaultConfig.setTextValue(SkywardHubStrings::defaultConfigurationFileName); + defaultConfig.setTextValue( + SkywardHubStrings::defaultConfigurationFileName); settings.addChild(defaultConfig); } @@ -41,22 +49,27 @@ 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); @@ -64,45 +77,54 @@ void SkywardHubCore::saveSettings() { } } -void SkywardHubCore::loadFirstPage() { - QString pageToLoadName = settings.getChildObjectValue(SkywardHubStrings::skywardHubInitFileTag); - if(!pageToLoadName.isEmpty()) { +void SkywardHubCore::loadFirstPage() +{ + QString pageToLoadName = + settings.getChildObjectValue(SkywardHubStrings::skywardHubInitFileTag); + + if (!pageToLoadName.isEmpty()) + { XmlObject pageToLoad; - if(pageToLoad.loadFromFile(SkywardHubStrings::defaultPrefabsFolder + pageToLoadName)) { - modulesManager->setModules(modulesManager->loadModuleFromXml(pageToLoad)); + if (pageToLoad.loadFromFile(SkywardHubStrings::defaultPrefabsFolder + + pageToLoadName)) + { + modulesManager->setModules( + modulesManager->loadModuleFromXml(pageToLoad)); return; } } - // if first page not found, init with empy module + // If first page not found, init with empty module modulesManager->openNewEmptyWindow(); } -ModuleMessagesBroker *SkywardHubCore::getModuleMessagesBroker() { +ModuleMessagesBroker *SkywardHubCore::getModuleMessagesBroker() +{ return moduleMessagesBroker; } -ModuleEventsHandler *SkywardHubCore::getModuleEventsHandler() { +ModuleEventsHandler *SkywardHubCore::getModuleEventsHandler() +{ return moduleEventsHandler; } -ModulesManager *SkywardHubCore::getModulesManager() { - return modulesManager; -} +ModulesManager *SkywardHubCore::getModulesManager() { return modulesManager; } -//_________________ SkywardHubCoreProxy ____________________________________________________________ +//_________________ SkywardHubCoreProxy +//____________________________________________________________ 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; } -//_________________ ModulesManagerProxy ____________________________________________________________ +//_________________ ModulesManagerProxy +//____________________________________________________________ -XmlObject SkywardHubCore::getSettings() const { - return settings; -} +XmlObject SkywardHubCore::getSettings() const { return settings; } diff --git a/Core/skywardhubcore.h b/Core/skywardhubcore.h index 52820c96b40ec602f7758a21c0f1a7ad2a095a35..ccc724a4888fc67eee886747d8e72302d054ff77 100644 --- a/Core/skywardhubcore.h +++ b/Core/skywardhubcore.h @@ -1,20 +1,21 @@ #ifndef SKYWARDHUBCORE_H #define SKYWARDHUBCORE_H - #include <QObject> -#include "xmlobject.h" + #include "Modules/skywardhubstrings.h" +#include "xmlobject.h" class ModulesManager; class ModuleEventsHandler; class ModuleMessagesBroker; class Module; -class SkywardHubCore : public QObject { +class SkywardHubCore : public QObject +{ Q_OBJECT - public: +public: SkywardHubCore(); ~SkywardHubCore(); @@ -26,17 +27,17 @@ class SkywardHubCore : public QObject { XmlObject getSettings() const; - signals: +signals: void centralModuleChanged(Module *newModule); - protected: +protected: void checkDefaultFolders(); void saveSettings(); void loadFirstPage(); - private: - ModulesManager *modulesManager = nullptr; - ModuleEventsHandler *moduleEventsHandler = nullptr; +private: + ModulesManager *modulesManager = nullptr; + ModuleEventsHandler *moduleEventsHandler = nullptr; ModuleMessagesBroker *moduleMessagesBroker = nullptr; XmlObject settings; @@ -44,16 +45,15 @@ class SkywardHubCore : public QObject { // Singleton instance of SkywardHubCore -class SkywardHubCoreProxy { +class SkywardHubCoreProxy +{ - public: - static SkywardHubCore* getCore(); - SkywardHubCore* operator->() { - return getCore(); - } +public: + static SkywardHubCore *getCore(); + SkywardHubCore *operator->() { return getCore(); } - private: +private: static SkywardHubCore *core; }; -#endif // SKYWARDHUBCORE_H +#endif // SKYWARDHUBCORE_H diff --git a/Modules/DefaultModule/defaultmodule.cpp b/Modules/DefaultModule/defaultmodule.cpp index 4fcc978826ec7f28ab1e31435408628f2b75294c..9ce6b0c9714bc5744e167fd92b1a0be12d74a619 100644 --- a/Modules/DefaultModule/defaultmodule.cpp +++ b/Modules/DefaultModule/defaultmodule.cpp @@ -1,11 +1,12 @@ #include "defaultmodule.h" #include <QCloseEvent> +#include <QThread> #include "Components/ContextMenuSeparator/contextmenuseparator.h" #include "Core/modulesmanager.h" -DefaultModule::DefaultModule(QWidget* parent) : QWidget(parent) {} +DefaultModule::DefaultModule(QWidget* parent) : Module(parent) {} DefaultModule::~DefaultModule() { @@ -32,7 +33,7 @@ void DefaultModule::defaultContextMenuSetup() void DefaultModule::addCustomActionsToMenu() {} void DefaultModule::onSkywardHubContextMenuRequested(QMenu& menu, - const QPoint& p) + const QPoint& pos) { QMenu newMenu(menuName); if (!menuName.isEmpty()) @@ -43,17 +44,17 @@ void DefaultModule::onSkywardHubContextMenuRequested(QMenu& menu, else menu.addActions(menuActions); - ContextMenuSeparator separator; - menu.addAction(&separator); - emit getModuleEventsHandler()->contextMenuRequest(menu, p); + menu.addSeparator(); + + emit getModuleEventsHandler()->contextMenuRequest(menu, pos); } SkywardHubCoreProxy& DefaultModule::getCore() { return proxyCore; } -void DefaultModule::onCustomContextMenuRequested(const QPoint& p) +void DefaultModule::onCustomContextMenuRequested(const QPoint& pos) { QMenu menu; - onSkywardHubContextMenuRequested(menu, mapToGlobal(p)); + onSkywardHubContextMenuRequested(menu, mapToGlobal(pos)); } QString DefaultModule::getName(const ModuleId id) @@ -132,9 +133,10 @@ void DefaultModule::onReplaceClicked() getCore()->getModulesManager()->invokeModulesPickerService(); if (newModule != nullptr) { + QThread::msleep(200); + emit getModuleEventsHandler()->replaceMeWith(this, newModule); - delete this; } } -void DefaultModule::onCloseClicked() { delete this; } +void DefaultModule::onCloseClicked() { close(); } diff --git a/Modules/DefaultModule/defaultmodule.h b/Modules/DefaultModule/defaultmodule.h index a8ee3523fb6c5a000f2f4530bc194d52cc883616..a2266aa42c2187a0831bdd55b1746fa0fdbe354a 100644 --- a/Modules/DefaultModule/defaultmodule.h +++ b/Modules/DefaultModule/defaultmodule.h @@ -1,16 +1,16 @@ #ifndef DEFAULTMODULE_H #define DEFAULTMODULE_H -#include <QWidget> - #include "Components/ErrorDisplayer/errordisplayer.h" #include "Core/module.h" #include "Core/skywardhubcore.h" #include "Modules/MainWindow/window.h" #include "Modules/moduleinfo.h" -class DefaultModule : public QWidget, public Module +class DefaultModule : public Module { + Q_OBJECT + public: static constexpr int LONG_ERROR_DURATION = 1500; static constexpr int MEDIUM_ERROR_DURATION = 10000; diff --git a/Modules/Empty/emptymodule.cpp b/Modules/Empty/emptymodule.cpp index 0e3ec8472131518dda27e1347bcf1076bbbd58e7..098dad04c54a5c3e4700ea3bb531aee4ac0e7783 100644 --- a/Modules/Empty/emptymodule.cpp +++ b/Modules/Empty/emptymodule.cpp @@ -1,40 +1,38 @@ #include "emptymodule.h" -#include "ui_emptymodule.h" -#include <QDebug> #include <QAction> -#include <QPoint> #include <QMessageBox> +#include <QPoint> + #include "Components/ContextMenuSeparator/contextmenuseparator.h" #include "Core/modulesmanager.h" +#include "ui_emptymodule.h" -EmptyModule::EmptyModule() : DefaultModule(), ui(new Ui::EmptyModule) { +EmptyModule::EmptyModule() : DefaultModule(), ui(new Ui::EmptyModule) +{ ui->setupUi(this); defaultContextMenuSetup(); connectUiSlots(); } -EmptyModule::~EmptyModule() { - delete ui; -} +EmptyModule::~EmptyModule() { delete ui; } -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() { - onReplaceClicked(); -} +void EmptyModule::onSelectPanelClick() { onReplaceClicked(); } -QWidget* EmptyModule::toWidget() { - return this; -} +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/MainWindow/skywardhubmainwindow.cpp b/Modules/MainWindow/skywardhubmainwindow.cpp index bb7efead5b38916199cb784e93255dfd212641be..a11868111191d972ee695a98335ba47895b39f09 100644 --- a/Modules/MainWindow/skywardhubmainwindow.cpp +++ b/Modules/MainWindow/skywardhubmainwindow.cpp @@ -1,63 +1,52 @@ #include "skywardhubmainwindow.h" -#include "ui_skywardhubmainwindow.h" -#include <QMenu> #include <QFile> +#include <QMenu> #include "Core/module.h" #include "Core/modulesmanager.h" -SkywardHubMainWindow::SkywardHubMainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::SkywardHubMainWindow) { - ui->setupUi(this); - +SkywardHubMainWindow::SkywardHubMainWindow(QWidget* parent) + : QMainWindow(parent) +{ QFile styleSheet(":/Resources/Styles/global.qss"); styleSheet.open(QFile::ReadOnly); setStyleSheet(styleSheet.readAll()); mainWindow = new Window(); + mainWindow->setWindowTitle("Skyward Hub - 1"); setCentralWidget(mainWindow); - connect(core->getModulesManager(), &ModulesManager::contextMenuRequest, this, &SkywardHubMainWindow::onContextMenuRequest); - connect(core->getModulesManager(), &ModulesManager::pageAdded, this, &SkywardHubMainWindow::onPageAdded); - connect(core->getModulesManager(), &ModulesManager::appQuitRequested, this, &SkywardHubMainWindow::onQuitRequested); - core->init(); -} - -SkywardHubMainWindow::~SkywardHubMainWindow() { - delete ui; -} -void SkywardHubMainWindow::onContextMenuRequest(QMenu& menu, const QPoint& p) { - QAction changeSettings("Edit Settings"); - menu.addAction(&changeSettings); - connect(&changeSettings, &QAction::triggered, this, &SkywardHubMainWindow::openEditSettings); + connect(core->getModulesManager(), &ModulesManager::contextMenuRequest, + this, &SkywardHubMainWindow::onContextMenuRequest); + connect(core->getModulesManager(), &ModulesManager::pageAdded, this, + &SkywardHubMainWindow::onPageAdded); - menu.exec(p); + core->init(); } -void SkywardHubMainWindow::openEditSettings() { - +void SkywardHubMainWindow::onContextMenuRequest(QMenu& menu, const QPoint& pos) +{ + menu.exec(pos); } -void SkywardHubMainWindow::onPageAdded(int index) { - Module* m = core->getModulesManager()->getModuleAt(index); +void SkywardHubMainWindow::onPageAdded(int index) +{ + Module* module = core->getModulesManager()->getModuleAt(index); - if(m != nullptr) { - if(index == 0) { - mainWindow->updateModule(m); - return; + if (module != nullptr) + { + if (index == 0) + { + mainWindow->updateModule(module); + } + else + { + Window* window = new Window(); + window->setWindowTitle("Skyward Hub - " + + QString::number(index + 1)); + window->setCentralModule(module); + window->show(); } - Window* window = new Window(); - window->setWindowTitle("Window " + QString::number(index)); - window->setCentralModule(m); - window->show(); } } - -void SkywardHubMainWindow::onQuitRequested() { - QApplication::quit(); -} - -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 2feb72e69e7c1411997b79fc657b42b71b638b82..8c2683aa17eafbe2de9663d8653a616025318d32 100644 --- a/Modules/MainWindow/skywardhubmainwindow.h +++ b/Modules/MainWindow/skywardhubmainwindow.h @@ -2,34 +2,24 @@ #define SKYWARDHUBMAINWINDOW_H #include <QMainWindow> + #include "Core/skywardhubcore.h" #include "window.h" -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: - void closeEvent(QCloseEvent *event); - - private: - Ui::SkywardHubMainWindow *ui; +private: SkywardHubCoreProxy core; - Window *mainWindow = nullptr; + Window *mainWindow; }; -#endif // SKYWARDHUBMAINWINDOW_H +#endif // SKYWARDHUBMAINWINDOW_H diff --git a/Modules/MainWindow/skywardhubmainwindow.ui b/Modules/MainWindow/skywardhubmainwindow.ui deleted file mode 100644 index 51a961c08d23489ab381c4f323166df9aa2a7b9e..0000000000000000000000000000000000000000 --- a/Modules/MainWindow/skywardhubmainwindow.ui +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>SkywardHubMainWindow</class> - <widget class="QMainWindow" name="SkywardHubMainWindow"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>800</width> - <height>600</height> - </rect> - </property> - <property name="windowTitle"> - <string>MainWindow</string> - </property> - <property name="styleSheet"> - <string notr="true"/> - </property> - <widget class="QWidget" name="centralwidget"/> - </widget> - <resources/> - <connections/> -</ui> diff --git a/Modules/MainWindow/window.cpp b/Modules/MainWindow/window.cpp index ea1c3ce17a1d464d9d92d86e14d258575289f7c9..e04516a8aebd9f3203ee27e6824f8ea8139de544 100644 --- a/Modules/MainWindow/window.cpp +++ b/Modules/MainWindow/window.cpp @@ -1,48 +1,61 @@ #include "window.h" -#include "ui_window.h" + +#include <QVBoxLayout> #include "Core/module.h" #include "Core/modulesmanager.h" -#include <QVBoxLayout> +#include "ui_window.h" -Window::Window(QWidget* parent) : QWidget(parent), ui(new Ui::Window) { +Window::Window(QWidget* parent) : QWidget(parent), ui(new Ui::Window) +{ ui->setupUi(this); errorDisplayer = new ErrorDisplayer(this); } -Window::~Window() { +Window::~Window() +{ delete ui; delete errorDisplayer; } -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 { - return centralModule; -} +Module* Window::getCentralModule() const { return centralModule; } -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); +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); } centralModule = value; ui->mainLayout->addWidget(value->toWidget()); - connect(value->getModuleEventsHandler(), &QWidget::destroyed, this, &Window::onWidgetDestroyed); - connect(value->getModuleEventsHandler(), &ModuleEventsHandler::replaceMeWith, this, &Window::onReplaceRequested); + connect(value->getModuleEventsHandler(), &QWidget::destroyed, this, + &Window::onWidgetDestroyed); + connect(value->getModuleEventsHandler(), + &ModuleEventsHandler::replaceMeWith, this, + &Window::onReplaceRequested); value->toWidget()->lower(); } -void Window::closeEvent(QCloseEvent* event) { - if(centralModule != nullptr) +void Window::closeEvent(QCloseEvent* event) +{ + if (centralModule != nullptr) delete centralModule; QWidget::closeEvent(event); @@ -50,19 +63,24 @@ void Window::closeEvent(QCloseEvent* event) { deleteLater(); } -void Window::onWidgetDestroyed() { +void Window::onWidgetDestroyed() +{ centralModule = nullptr; close(); this->deleteLater(); } -void Window::onReplaceRequested(Module* sender, Module* newModule) { - if(newModule != nullptr && sender != nullptr) { +void Window::onReplaceRequested(Module* sender, Module* newModule) +{ + if (newModule != nullptr && sender != nullptr) + { setCentralModule(newModule); + delete sender; } } -void Window::resizeEvent(QResizeEvent* event) { +void Window::resizeEvent(QResizeEvent* event) +{ Q_UNUSED(event); errorDisplayer->reposition(); } diff --git a/Modules/Mavlink/mavlinkreader.cpp b/Modules/Mavlink/mavlinkreader.cpp index 990432f613bfc407c38315969c855b4fc7174c9b..79d66f58e5dee0ea14a014c68e1455cc5c5c46e2 100644 --- a/Modules/Mavlink/mavlinkreader.cpp +++ b/Modules/Mavlink/mavlinkreader.cpp @@ -40,25 +40,16 @@ const mavlink_message_info_t& MavlinkReader::getMessageFormat(uint8_t messageId) void MavlinkReader::onReadyRead() { if (serialPort == nullptr) - { - qDebug() << "Error: serialPort is nullptr"; return; - } auto bytes = serialPort->readAll(); for (auto it = bytes.begin(); it != bytes.end(); ++it) - { if (mavlink_parse_char(MAVLINK_COMM_0, *it, &decodedMessage, &mavlinkStatus)) - { emit msgReceived(generateModuleMessage(decodedMessage)); - } - } if (logFile.isOpen()) - { logFile.write(bytes.constData(), sizeof(char) * bytes.length()); - } } void MavlinkReader::setSerialPort(QSerialPort* port) { serialPort = port; } @@ -69,9 +60,7 @@ ModuleMessage MavlinkReader::generateModuleMessage(const mavlink_message_t& msg) QMap<QString, MessageField> fields; for (unsigned i = 0; i < info.num_fields; i++) - { fields[QString(info.fields[i].name)] = decodeField(msg, info.fields[i]); - } ModuleMessage output; output.setTopic(SkywardHubStrings::mavlink_received_msg_topic + "/" + diff --git a/Modules/Mavlink/mavlinkreader.h b/Modules/Mavlink/mavlinkreader.h index 2270ecbbbb73c8cf07aaf0dd4215a267cf5bcf3f..41b53bdd4239342f5e9862caae5adeda4fcf1399 100644 --- a/Modules/Mavlink/mavlinkreader.h +++ b/Modules/Mavlink/mavlinkreader.h @@ -1,20 +1,20 @@ #ifndef MAVLINKREADER_H #define MAVLINKREADER_H -#include <QSerialPort> -#include <QThread> #include <QDateTime> -#include "Core/xmlobject.h" -#include "mavlinkversionheader.h" +#include <QFile> +#include <QSerialPort> #include "Core/Message/modulemessage.h" -#include <QFile> +#include "Core/xmlobject.h" +#include "mavlinkversionheader.h" class MavlinkModule; -class MavlinkReader : public QObject { +class MavlinkReader : public QObject +{ Q_OBJECT - public: +public: MavlinkReader(MavlinkModule* parent); ~MavlinkReader(); @@ -29,22 +29,24 @@ class MavlinkReader : public QObject { static const mavlink_message_info_t& getMessageFormat(uint8_t messageId); - signals: +signals: void msgReceived(const ModuleMessage& msg); - private slots: +private slots: void onReadyRead(); - protected: +protected: /* convert a field of any type to a string */ - MessageField decodeField(const mavlink_message_t& msg, const mavlink_field_info_t& field); + MessageField decodeField(const mavlink_message_t& msg, + const mavlink_field_info_t& field); /* if field is an array, decode every element in the array */ - MessageField decodeArrayElement(const mavlink_message_t& msg, const mavlink_field_info_t& field, int idx); + MessageField decodeArrayElement(const mavlink_message_t& msg, + const mavlink_field_info_t& field, int idx); void setLogFilePath(); - private: +private: mavlink_message_t decodedMessage; mavlink_status_t mavlinkStatus; @@ -55,4 +57,4 @@ class MavlinkReader : public QObject { QFile logFile; }; -#endif // MAVLINKREADER_H +#endif // MAVLINKREADER_H diff --git a/Modules/Mavlink/mavlinkwriter.cpp b/Modules/Mavlink/mavlinkwriter.cpp index 259339c5acf2ea0ce6768cae61bcba22362b9b6e..23168fb6e327c20cb16311d3c54d063650dd37ef 100644 --- a/Modules/Mavlink/mavlinkwriter.cpp +++ b/Modules/Mavlink/mavlinkwriter.cpp @@ -1,25 +1,23 @@ #include "mavlinkwriter.h" #include <chrono> -#include <QDebug> -MavlinkWriter::MavlinkWriter() { +MavlinkWriter::MavlinkWriter() {} -} - -void MavlinkWriter::write(const mavlink_message_t& message) { - if(serial == nullptr) +void MavlinkWriter::write(const mavlink_message_t& message) +{ + if (serial == nullptr) return; - unsigned char buff[sizeof(mavlink_message_t) +1]; - int msg_len = mavlink_msg_to_send_buffer(buff, &message); + unsigned char buff[sizeof(mavlink_message_t) + 1]; + + // int msg_len = mavlink_msg_to_send_buffer(buff, &message); + // if (serial->write(reinterpret_cast<char*>(buff), msg_len) == -1) + // { + // qDebug() << "MavlinkWriter: Error, writeMsg serial port error"; + // } - if(serial->write(reinterpret_cast<char*>(buff), msg_len) == -1) { - qDebug() << "MavlinkWriter: Error, writeMsg serial port error"; - } serial->flush(); } -void MavlinkWriter::setSerialPort(QSerialPort* port) { - serial = port; -} +void MavlinkWriter::setSerialPort(QSerialPort* port) { serial = port; } diff --git a/Modules/Mavlink/mavlinkwriter.h b/Modules/Mavlink/mavlinkwriter.h index e993c415da22f3ae6ea61b0f2482bd7f29ae471e..8b3d4489b5ae4bc80e6f808577997db79fb47e7a 100644 --- a/Modules/Mavlink/mavlinkwriter.h +++ b/Modules/Mavlink/mavlinkwriter.h @@ -1,23 +1,24 @@ #ifndef MAVLINKWRITER_H #define MAVLINKWRITER_H -#include <QThread> #include <QMutex> #include <QSerialPort> + #include "mavlinkversionheader.h" -class MavlinkWriter : public QObject { +class MavlinkWriter : public QObject +{ Q_OBJECT - public: +public: MavlinkWriter(); void setSerialPort(QSerialPort* port); void write(const mavlink_message_t& message); - private: +private: QSerialPort* serial = nullptr; QMutex mtx; }; -#endif // MAVLINKWRITER_H +#endif // MAVLINKWRITER_H diff --git a/Modules/SkywardHub/skywardhubmodule.cpp b/Modules/SkywardHub/skywardhubmodule.cpp index f5cb7b57f302ac5461b8e68a89bb914ad4e6c64e..7ef12dcd113304329500288c3d442a895d20a342 100644 --- a/Modules/SkywardHub/skywardhubmodule.cpp +++ b/Modules/SkywardHub/skywardhubmodule.cpp @@ -1,18 +1,22 @@ #include "skywardhubmodule.h" -#include "ui_skywardhubmodule.h" -#include "prefabdialog.h" + +#include <QDir> +#include <QGridLayout> #include <QLabel> #include <QPushButton> -#include <QGridLayout> -#include <QDir> -#include "Modules/MainWindow/skywardhubmainwindow.h" + #include "Core/modulesmanager.h" -#include "prefabviewelement.h" -#include "deployer.h" +#include "Modules/MainWindow/skywardhubmainwindow.h" #include "Modules/skywardhubstrings.h" #include "QMessageBox" +#include "deployer.h" +#include "prefabdialog.h" +#include "prefabviewelement.h" +#include "ui_skywardhubmodule.h" -SkywardHubModule::SkywardHubModule(QWidget *parent) : DefaultModule(parent), ui(new Ui::SkywardHubModule) { +SkywardHubModule::SkywardHubModule(QWidget *parent) + : DefaultModule(parent), ui(new Ui::SkywardHubModule) +{ ui->setupUi(this); defaultContextMenuSetup(); @@ -20,96 +24,115 @@ 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() +{ + QList<QString> completeModuleNamesList = + ModulesManager::getModulesNamesList(); -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; + nextRow = 0; QString prefabsFolder = SkywardHubStrings::defaultPrefabsFolder; QDir directory(prefabsFolder); - QStringList prefabFiles = directory.entryList(QStringList() << "*.xml", QDir::Files); - for(QString prefabName : prefabFiles) { + QStringList prefabFiles = + directory.entryList(QStringList() << "*.xml", QDir::Files); + for (QString prefabName : prefabFiles) + { XmlObject xml; xml.loadFromFile(prefabsFolder + prefabName); createAndInsertPrefabFromXml(xml, prefabsFolder + prefabName); } } -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 { - if(element == nullptr) +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"); + xmlconfig.addAttribute(SkywardHubStrings::configurationNameAttribute, + "Launch Empty Configuration"); XmlObject emptyXml = module->toXmlObject(); xmlconfig.addChild(emptyXml); - PrefabViewElement* prefabView = createNewPrefab(xmlconfig); - if(prefabView != nullptr) { + PrefabViewElement *prefabView = createNewPrefab(xmlconfig); + if (prefabView != nullptr) + { initUsedModules(prefabView, xmlconfig); prefabView->setDeleteButtonVisibility(false); prefabView->setIconButtonVisibility(false); prefabView->setLaunchButtonText("+"); - prefabView->setDesctiption("Create your custom configuration and then save it (Right Click -> HubMenu -> Save)"); + prefabView->setDesctiption( + "Create your custom configuration and then save it (Right " + "Click -> HubMenu -> Save)"); emptyPrefab = prefabView; - connect(prefabView, &PrefabViewElement::launchRequested, this, &SkywardHubModule::onPrefabLaunchRequested); + connect(prefabView, &PrefabViewElement::launchRequested, this, + &SkywardHubModule::onPrefabLaunchRequested); ui->layout_addNewConfig->addWidget(prefabView); } } } -void SkywardHubModule::createAndInsertPrefabFromXml(XmlObject &xml, const QString &filePath) { - PrefabViewElement* prefabView = createNewPrefab(xml); - if(prefabView != nullptr) { +void SkywardHubModule::createAndInsertPrefabFromXml(XmlObject &xml, + const QString &filePath) +{ + PrefabViewElement *prefabView = createNewPrefab(xml); + if (prefabView != nullptr) + { prefabView->setFilePath(filePath); initUsedModules(prefabView, xml); addPrefab(prefabView); @@ -117,49 +140,59 @@ void SkywardHubModule::createAndInsertPrefabFromXml(XmlObject &xml, const QStrin } } - -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*/ - "border-top: none;border-right: 3px solid #00bfff; border-bottom: none; border-left: 3px solid #00bfff;}"; - - - QCheckBox* checkBox = new QCheckBox(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*/ + "border-top: none;border-right: 3px solid #00bfff; border-bottom: " + "none; border-left: 3px solid #00bfff;}"; + + QCheckBox *checkBox = new QCheckBox(text); checkBox->setStyleSheet(check_stylesheet); 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); - connect(element, &PrefabViewElement::selected, this, &SkywardHubModule::onPrefabSelected); + connect(element, &PrefabViewElement::launchRequested, this, + &SkywardHubModule::onPrefabLaunchRequested); + connect(element, &PrefabViewElement::deleteRequested, this, + &SkywardHubModule::onPrefabDeleteRequested); + connect(element, &PrefabViewElement::selected, this, + &SkywardHubModule::onPrefabSelected); } - -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++; } @@ -167,20 +200,25 @@ void SkywardHubModule::insertPrefabInUi(PrefabViewElement *element) { nextColumn++; } -void SkywardHubModule::clearPrefab() { - for(PrefabViewElement *p : prefabs) { +void SkywardHubModule::clearPrefab() +{ + for (PrefabViewElement *p : prefabs) + { delete p; } prefabs.clear(); onPrefabSelected(nullptr); } - -PrefabViewElement* SkywardHubModule::createNewPrefab(XmlObject &xmlPrefab) { - if(xmlPrefab.getObjectName() == SkywardHubStrings::configurationNameValue) { - QString prefName = xmlPrefab.getAttribute(SkywardHubStrings::configurationNameAttribute); - if(!prefName.isEmpty()) { - PrefabViewElement* prefabView = new PrefabViewElement(prefName); +PrefabViewElement *SkywardHubModule::createNewPrefab(XmlObject &xmlPrefab) +{ + if (xmlPrefab.getObjectName() == SkywardHubStrings::configurationNameValue) + { + QString prefName = xmlPrefab.getAttribute( + SkywardHubStrings::configurationNameAttribute); + if (!prefName.isEmpty()) + { + PrefabViewElement *prefabView = new PrefabViewElement(prefName); prefabView->setXml(xmlPrefab); return prefabView; } @@ -188,32 +226,41 @@ PrefabViewElement* SkywardHubModule::createNewPrefab(XmlObject &xmlPrefab) { return nullptr; } -void SkywardHubModule::dialogRequested() { +void SkywardHubModule::dialogRequested() +{ PrefabDialog dialog(this); - //connect(&dialog, &PrefabDialog::newPrefabCreated, this, &SkywardHubModule::createNewPrefab); + // 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)); + 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(); @@ -223,68 +270,81 @@ void SkywardHubModule::onPrefabDeployRequested(PrefabViewElement *element) { Deployer deployer; QList<QString> modulesFiles; - QList<ModuleInfo> fullModuleList = getCore()->getModulesManager()->getModulesInfo(); + 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()); } } bool deployResult = deployer.deploy(modulesFiles); - if(deployResult == false) + if (deployResult == false) return; - //Put the prefab config as default config - QString configPath = deployer.getDeployReleaseFolder() + "/" + SkywardHubStrings::defaultConfigurationFolder; - if(!QDir(configPath).exists()) { + // Put the prefab config as default config + QString configPath = deployer.getDeployReleaseFolder() + "/" + + SkywardHubStrings::defaultConfigurationFolder; + if (!QDir(configPath).exists()) + { QDir().mkdir(configPath); } - configPath += "/" + SkywardHubStrings::defaultPrefabsFolderName; - if(!QDir(configPath).exists()) { + configPath += "/" + SkywardHubStrings::defaultPrefabsFolderName; + if (!QDir(configPath).exists()) + { QDir().mkdir(configPath); } - element->getXml().writeToFile(configPath + "/" + SkywardHubStrings::defaultConfigurationFileName); + element->getXml().writeToFile( + configPath + "/" + SkywardHubStrings::defaultConfigurationFileName); } -void SkywardHubModule::onPrefabDeleteRequested(PrefabViewElement *element) { - if(element == nullptr) +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) { - QFile file (element->getFilePath()); - if(file.exists()) { + 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()) + { file.remove(); loadPrefabs(); } } - } -void SkywardHubModule::onCheckBoxClicked(QCheckBox *cBox) { - if(cBox == nullptr || selectedElement == nullptr) +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() { return this; } -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/Splitter/Splitter.cpp b/Modules/Splitter/Splitter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..69275707a100e450938ec3e3d69f87a843b14310 --- /dev/null +++ b/Modules/Splitter/Splitter.cpp @@ -0,0 +1,175 @@ +#include "Splitter.h" + +#include <Components/ContextMenuSeparator/contextmenuseparator.h> +#include <Core/modulesmanager.h> + +#include <QDebug> +#include <QLabel> +#include <QThread> + +Splitter::Splitter(Qt::Orientation orientation, QWidget* parent) + : DefaultModule(parent) +{ + setupUi(orientation); + defaultContextMenuSetup(); +} + +QWidget* Splitter::toWidget() { return this; } + +XmlObject Splitter::toXmlObject() +{ + XmlObject obj(getName(ModuleId::SPLITTER)); + + // Orientation + if (splitter->orientation() == Qt::Horizontal) + obj.addAttribute("orientation", "horizontal"); + else + obj.addAttribute("orientation", "vertical"); + + QString sizes; + for (int i = 0; i < splitter->sizes().size(); i++) + { + sizes += QString::number(splitter->sizes()[i]); + + if (i < splitter->sizes().size() - 1) + sizes += ","; + } + + obj.addAttribute("sizes", sizes); + + for (int i = 0; i < splitter->count(); i++) + { + DefaultModule* module = + qobject_cast<DefaultModule*>(splitter->widget(i)); + + if (module) + obj.addChild(module->toXmlObject()); + } + + return obj; +} + +void Splitter::fromXmlObject(const XmlObject& obj) +{ + QString orientation = obj.getAttribute("orientation"); + if (orientation == "vertical") + splitter->setOrientation(Qt::Vertical); + else + splitter->setOrientation(Qt::Horizontal); + QList<int> intSizes; + for (QString size : obj.getAttribute("sizes").split(",")) + intSizes.append(size.toInt()); + + for (int i = 0; i < obj.childCount(); i++) + { + XmlObject xmlChild = obj.childAt(i); + Module* module = + getCore()->getModulesManager()->instantiateModuleByName( + xmlChild.getObjectName()); + + if (module) + module->fromXmlObject(xmlChild); + else + module = getCore()->getModulesManager()->instantiateDefaultModule(); + + addModule(module, i); + } + + splitter->setSizes(intSizes); +} + +void Splitter::addModule(Module* module) +{ + int count = splitter->count(); + addModule(module, count); +} + +void Splitter::addModule(Module* module, int position) +{ + connect(module->getModuleEventsHandler(), + &ModuleEventsHandler::replaceMeWith, this, &Splitter::replace); + connect(module->getModuleEventsHandler(), + &ModuleEventsHandler::contextMenuRequest, this, + &Splitter::onSkywardHubContextMenuRequested); + connect(module->getModuleEventsHandler(), + &ModuleEventsHandler::beforeDelete, this, + &Splitter::onModuleDelete); + + if (position < splitter->count()) + delete splitter->widget(position); + + splitter->insertWidget(position, qobject_cast<QWidget*>(module)); +} + +void Splitter::replace(Module* oldModule, Module* newModule) +{ + if (oldModule && newModule) + addModule(newModule, splitter->indexOf(oldModule->toWidget())); +} + +Qt::Orientation Splitter::getOrientation() const +{ + return splitter->orientation(); +} + +void Splitter::setOrientation(Qt::Orientation orientation) +{ + splitter->setOrientation(orientation); +} + +void Splitter::swapOrientation() +{ + if (getOrientation() == Qt::Horizontal) + splitter->setOrientation(Qt::Vertical); + else + splitter->setOrientation(Qt::Horizontal); +} + +void Splitter::onModuleDelete(Module* module) +{ + qDebug() << "onModuleDelete" << module->metaObject()->className(); + QThread::msleep(200); + + // int index = splitter->indexOf(qobject_cast<QWidget*>(module)); + + // if (index == !-1) + // delete splitter->widget(index); + + // TODO: When a single module remains, the splitter should be removed +} + +void Splitter::addCustomActionsToMenu() +{ + showMenuActionsInSeparatedMenu("Splitter"); + QAction* split = new QAction("Split"); + connect(split, &QAction::triggered, this, + [this]() { + addModule( + getCore()->getModulesManager()->instantiateDefaultModule()); + }); + + QAction* changeOrientation = new QAction("Swap Orientation"); + connect(changeOrientation, &QAction::triggered, this, + [this]() { this->swapOrientation(); }); + + addActionToMenu(split); + addActionToMenu(changeOrientation); +} + +void Splitter::setupUi(Qt::Orientation orientation) +{ + QVBoxLayout* outerLayout = new QVBoxLayout; + outerLayout->setContentsMargins(0, 0, 0, 0); + + splitter = new QSplitter(); + splitter->setOrientation(orientation); + splitter->setChildrenCollapsible(false); + splitter->setHandleWidth(0); + outerLayout->addWidget(splitter); + + // By default add two default modules + addModule(getCore()->getModulesManager()->instantiateDefaultModule()); + addModule(getCore()->getModulesManager()->instantiateDefaultModule()); + + setLayout(outerLayout); +} diff --git a/Modules/Splitter/splittermodule.h b/Modules/Splitter/Splitter.h similarity index 61% rename from Modules/Splitter/splittermodule.h rename to Modules/Splitter/Splitter.h index c7b93744b8e7700c8817295b2df1436074074b87..ae9074cf50c7b51c58297e23b545f418ea0a509f 100644 --- a/Modules/Splitter/splittermodule.h +++ b/Modules/Splitter/Splitter.h @@ -1,5 +1,4 @@ -#ifndef SPLITTERMODULE_H -#define SPLITTERMODULE_H +#pragma once #include <QSplitter> #include <QWidget> @@ -7,36 +6,35 @@ #include "Core/module.h" #include "Modules/DefaultModule/defaultmodule.h" -class SplitterModule : public DefaultModule +class Splitter : public DefaultModule { Q_OBJECT public: - explicit SplitterModule(Qt::Orientation orientation = Qt::Horizontal); - ~SplitterModule() override; + explicit Splitter(Qt::Orientation orientation = Qt::Horizontal, + QWidget *parent = nullptr); QWidget *toWidget() override; XmlObject toXmlObject() override; - void fromXmlObject(const XmlObject &xmlObject) override; - - void initialize(const XmlObject ¶ms) override; - void addCustomActionsToMenu() override; + void fromXmlObject(const XmlObject &obj) override; void addModule(Module *module); void addModule(Module *module, int position); - void replace(Module *oldModule, Module *newModule); Qt::Orientation getOrientation() const; + void setOrientation(Qt::Orientation orientation); void swapOrientation(); -protected: - void setupUi(Qt::Orientation orientation = Qt::Horizontal); +public slots: + void replace(Module *oldModule, Module *newModule); + +private slots: void onModuleDelete(Module *module); private: + void addCustomActionsToMenu() override; + void setupUi(Qt::Orientation orientation = Qt::Horizontal); + QSplitter *splitter; - QList<Module *> childList; }; - -#endif // SPLITTERMODULE_H diff --git a/Modules/Splitter/splittermodule.cpp b/Modules/Splitter/splittermodule.cpp deleted file mode 100644 index 5c691be1c1cc00970947269899fcde338e1f79d2..0000000000000000000000000000000000000000 --- a/Modules/Splitter/splittermodule.cpp +++ /dev/null @@ -1,215 +0,0 @@ -#include "splittermodule.h" - -#include <QDebug> -#include <QLabel> - -#include "Components/ContextMenuSeparator/contextmenuseparator.h" -#include "Core/modulesmanager.h" - -SplitterModule::SplitterModule(Qt::Orientation orientation) : DefaultModule() -{ - setupUi(orientation); - defaultContextMenuSetup(); -} - -SplitterModule::~SplitterModule() -{ - while (!childList.isEmpty()) - delete childList.takeFirst(); -} - -QWidget* SplitterModule::toWidget() { return this; } - -XmlObject SplitterModule::toXmlObject() -{ - XmlObject obj(getName(ModuleId::SPLITTER)); - QString orientation; - if (splitter->orientation() == Qt::Horizontal) - orientation = "Horizontal"; - else - orientation = "Vertical"; - - obj.addAttribute("Orientation", orientation); - - QString sizesString = ""; - for (int i : splitter->sizes()) - { - sizesString.append(QString::number(i) + ","); - } - obj.addAttribute("Sizes", sizesString); - - for (Module* module : childList) - { - XmlObject xmlChild = module->toXmlObject(); - obj.addChild(xmlChild); - } - - return obj; -} - -void SplitterModule::fromXmlObject(const XmlObject& xmlObject) -{ - if (xmlObject.getObjectName() == - getCore()->getModulesManager()->getModuleName(ModuleId::SPLITTER)) - { - QString orientation = xmlObject.getAttribute("Orientation"); - if (orientation != "") - { - if (orientation == "Horizontal") - splitter->setOrientation(Qt::Horizontal); - else - splitter->setOrientation(Qt::Vertical); - } - - QStringList sizes = xmlObject.getAttribute("Sizes").split(","); - bool ok; - QList<int> intSizes; - for (QString size : sizes) - { - int val = size.toInt(&ok); - if (ok) - intSizes.append(val); - } - - int defaultChildRemaining = childList.count(); - - for (int i = 0; i < xmlObject.childCount(); i++) - { - XmlObject xmlChild = xmlObject.childAt(i); - Module* module = - getCore()->getModulesManager()->instantiateModuleByName( - xmlChild.getObjectName()); - if (module != nullptr) - { - module->fromXmlObject(xmlChild); - } - else - { - module = - getCore()->getModulesManager()->instantiateDefaultModule(); - } - addModule(module); - } - - while (defaultChildRemaining > 0) - { - delete childList.at(0); - defaultChildRemaining--; - } - - if (!intSizes.isEmpty()) - splitter->setSizes(intSizes); - } -} - -void SplitterModule::initialize(const XmlObject& params) -{ - int orientation; - if (params.getAttribute("Orientation", orientation)) - { - if (orientation == Qt::Vertical) - splitter->setOrientation(Qt::Vertical); - else - splitter->setOrientation(Qt::Horizontal); - } -} - -void SplitterModule::addModule(Module* module) -{ - int count = splitter->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); }); - 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()); -} - -void SplitterModule::replace(Module* oldModule, Module* newModule) -{ - if (oldModule != nullptr && newModule != nullptr) - { - int i = splitter->indexOf(oldModule->toWidget()); - addModule(newModule, i); - } -} - -Qt::Orientation SplitterModule::getOrientation() const -{ - return splitter->orientation(); -} - -void SplitterModule::swapOrientation() -{ - if (getOrientation() == Qt::Horizontal) - splitter->setOrientation(Qt::Vertical); - else - splitter->setOrientation(Qt::Horizontal); -} - -void SplitterModule::addCustomActionsToMenu() -{ - showMenuActionsInSeparatedMenu("Splitter"); - QAction* split = new QAction("Split"); - connect(split, &QAction::triggered, this, - [this]() { - addModule( - getCore()->getModulesManager()->instantiateDefaultModule()); - }); - - QAction* changeOrientation = new QAction("Swap Orientation"); - connect(changeOrientation, &QAction::triggered, this, - [this]() { this->swapOrientation(); }); - - addActionToMenu(split); - addActionToMenu(changeOrientation); -} - -void SplitterModule::onModuleDelete(Module* module) -{ - int index = childList.indexOf(module); - if (index >= 0) - { - childList.removeAt(index); - } - - 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(); - } -} - -void SplitterModule::setupUi(Qt::Orientation orientation) -{ - QVBoxLayout* outerLayout = new QVBoxLayout; - outerLayout->setContentsMargins(0, 0, 0, 0); - - splitter = new QSplitter(); - splitter->setOrientation(orientation); - splitter->setChildrenCollapsible(false); - splitter->setHandleWidth(0); - outerLayout->addWidget(splitter); - - addModule(getCore()->getModulesManager()->instantiateDefaultModule()); - addModule(getCore()->getModulesManager()->instantiateDefaultModule()); - - setLayout(outerLayout); -} diff --git a/Modules/StateViewer/StateViewer.cpp b/Modules/StateViewer/StateViewer.cpp index 2490b51938b4daab2d306745f3a4dab1cb6a4618..735b48808204a533a4dc0393168afabcbb888e47 100644 --- a/Modules/StateViewer/StateViewer.cpp +++ b/Modules/StateViewer/StateViewer.cpp @@ -92,10 +92,7 @@ void StateViewerModule::onMsgReceived(const ModuleMessage& msg) static_cast<StatesList::State>(field.getUInteger(-1)); if (state == StatesList::State::INVALID) - { - qDebug() << "Invalid state"; return; - } if (state != currentState) { diff --git a/Modules/Tabs/tabsmodule.cpp b/Modules/Tabs/tabsmodule.cpp index f1a938c666caa7b608b650f1474ca4d7793a81c6..2ab442812f8088ebb689b1d1671b99e20bc5dc16 100644 --- a/Modules/Tabs/tabsmodule.cpp +++ b/Modules/Tabs/tabsmodule.cpp @@ -121,7 +121,6 @@ QString TabsModule::generateUniqueTabName() void TabsModule::replaceTabContent(Module* from, Module* to) { - int index = contentModules.indexOf(from); if (index == -1) @@ -146,6 +145,8 @@ void TabsModule::replaceTabContent(Module* from, Module* to) // forces UI update tabContents->update(); + + delete from; } void TabsModule::onTabDeleted(Module* module) diff --git a/Modules/ValuesConverterViewer/valuesviewerconfigpanel.cpp b/Modules/ValuesConverterViewer/valuesviewerconfigpanel.cpp index 6ec8c1ef5d0e190b37c36737e2d36a6c7a2bfa7d..6fbfa97590a658b479548ce736700307029e9a10 100644 --- a/Modules/ValuesConverterViewer/valuesviewerconfigpanel.cpp +++ b/Modules/ValuesConverterViewer/valuesviewerconfigpanel.cpp @@ -1,105 +1,131 @@ #include "valuesviewerconfigpanel.h" -#include "ui_valuesviewerconfigpanel.h" -#include <QDebug> #include <QColorDialog> +#include <QDebug> + +#include "ui_valuesviewerconfigpanel.h" -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); - connect(ui->remove_pushButton, &QPushButton::clicked, this, &ValuesViewerConfigPanel::onRemoveClicked); - connect(ui->pickColor_pushButton, &QPushButton::clicked, this, &ValuesViewerConfigPanel::onPickColordClicked); - connect(ui->save_pushButton, &QPushButton::clicked, this, &ValuesViewerConfigPanel::onSaveClicked); - connect(ui->emit_radioButton, &QRadioButton::toggled, this, &ValuesViewerConfigPanel::onEmitRadioButtonToggled); + connect(ui->add_pushButton, &QPushButton::clicked, this, + &ValuesViewerConfigPanel::onAddFieldClicked); + connect(ui->edit_pushButton, &QPushButton::clicked, this, + &ValuesViewerConfigPanel::onEditClicked); + connect(ui->remove_pushButton, &QPushButton::clicked, this, + &ValuesViewerConfigPanel::onRemoveClicked); + connect(ui->pickColor_pushButton, &QPushButton::clicked, this, + &ValuesViewerConfigPanel::onPickColordClicked); + connect(ui->save_pushButton, &QPushButton::clicked, this, + &ValuesViewerConfigPanel::onSaveClicked); + connect(ui->emit_radioButton, &QRadioButton::toggled, this, + &ValuesViewerConfigPanel::onEmitRadioButtonToggled); 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() { - QString name = ui->name_lineEdit->text().trimmed(); - QString topic = ui->topic_lineEdit->text().trimmed(); - QString receivedValue = ui->receivedValue_lineEdit->text().trimmed(); +ValueElement ValuesViewerConfigPanel::createRuleFromControls() +{ + QString name = ui->name_lineEdit->text().trimmed(); + QString topic = ui->topic_lineEdit->text().trimmed(); + QString receivedValue = ui->receivedValue_lineEdit->text().trimmed(); QString displayedValue = ui->displayedValue_lineEdit->text().trimmed(); - QString color = ui->color_lineEdit->text().trimmed(); - QString outpuTopic = ui->outputTopic_lineEdit->text().trimmed(); - bool isDisplayView = ui->displayInView_checkBox->isChecked(); - ValueElement e(name, topic, receivedValue, displayedValue, color, outpuTopic); + QString color = ui->color_lineEdit->text().trimmed(); + QString outpuTopic = ui->outputTopic_lineEdit->text().trimmed(); + bool isDisplayView = ui->displayInView_checkBox->isChecked(); + ValueElement e(name, topic, receivedValue, displayedValue, color, + outpuTopic); e.setDisplayInView(isDisplayView); return e; } - -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++ ) { + 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) { - //qDebug() << "ValuesViewConfigPanel: Button created"; +QRadioButton* ValuesViewerConfigPanel::createView(const ValueElement& el) +{ 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()); @@ -108,65 +134,66 @@ void ValuesViewerConfigPanel::setTextBoxValues(const ValueElement& el) { ui->displayInView_checkBox->setChecked(el.isDisplayInView()); - if(el.isEmitActive()) { + if (el.isEmitActive()) + { ui->outputTopic_lineEdit->setText(el.getOutputTopic()); ui->emit_radioButton->setChecked(true); - } else { + } + else + { ui->doNotEmit_radioButton->setChecked(true); ui->outputTopic_lineEdit->setText(""); } } -int ValuesViewerConfigPanel::findSelectedView() const { - for (int i = 0; i < views.count(); i++) { - if(views[i]->isChecked()) { +int ValuesViewerConfigPanel::findSelectedView() const +{ + for (int i = 0; i < views.count(); i++) + { + 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); ui->fieldsLayout->insertWidget(index, view); - connect(view, &QRadioButton::clicked, this, &ValuesViewerConfigPanel::onValueElementClicked); + 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) { - for (int i = 0; i < newValues.count(); i++ ) { +void ValuesViewerConfigPanel::setRules(const QList<ValueElement>& newValues) +{ + for (int i = 0; i < newValues.count(); i++) + { addRule(i, newValues[i]); } } -QList<ValueElement> ValuesViewerConfigPanel::getRules() const { - return rules; -} +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/moduleslist.cpp b/Modules/moduleslist.cpp index 0fb40f009506af33133b947edb6d85ac0a57fd2a..5e7aab13919d4ddbf42d1d1e4d2312d44d00a58d 100644 --- a/Modules/moduleslist.cpp +++ b/Modules/moduleslist.cpp @@ -11,7 +11,7 @@ #include <Modules/Mavlink/mavlinkrocketmsgtestingmodule.h> #include <Modules/OutgoingMessagesViewer/outgoingmessagesviewermodule.h> #include <Modules/SkywardHub/skywardhubmodule.h> -#include <Modules/Splitter/splittermodule.h> +#include <Modules/Splitter/Splitter.h> #include <Modules/StateViewer/StateViewer.h> #include <Modules/Tabs/tabsmodule.h> #include <Modules/Test/testmodule.h> @@ -55,12 +55,10 @@ void ModulesList::createModuleList() compactCommandPad.addModuleSourceFiles("Modules/CompactCommandPad/"); addModuleInfo(compactCommandPad); -#ifdef SPLITTERMODULE_H ModuleInfo splitter(ModuleId::SPLITTER, "Splitter"); - splitter.setFactory([]() { return new SplitterModule(); }); + splitter.setFactory([]() { return new Splitter(); }); splitter.addModuleSourceFiles("Modules/Splitter/"); addModuleInfo(splitter); -#endif #ifdef SKYWARDHUBMODULE_H ModuleInfo hub(ModuleId::SKYWARDHUB, "SkywardHub", ModuleCategory::HOME); diff --git a/SkywardHub.pro b/SkywardHub.pro index 53d3865d59dd7fffa7b2cb2904c026e04711a8f0..c8faf643739bff01bb9d73dbedff5c367962438f 100644 --- a/SkywardHub.pro +++ b/SkywardHub.pro @@ -53,7 +53,7 @@ SOURCES += \ Modules/SkywardHub/prefabdialog.cpp \ Modules/SkywardHub/prefabviewelement.cpp \ Modules/SkywardHub/skywardhubmodule.cpp \ - Modules/Splitter/splittermodule.cpp \ + Modules/Splitter/Splitter.cpp \ Modules/StateViewer/StateViewer.cpp \ Modules/Tabs/tabsmodule.cpp \ Modules/Test/testmodule.cpp \ @@ -112,7 +112,7 @@ HEADERS += \ Modules/SkywardHub/prefabdialog.h \ Modules/SkywardHub/prefabviewelement.h \ Modules/SkywardHub/skywardhubmodule.h \ - Modules/Splitter/splittermodule.h \ + Modules/Splitter/Splitter.h \ Modules/StateViewer/StateViewer.h \ Modules/Tabs/tabsmodule.h \ Modules/Test/testmodule.h \ @@ -130,7 +130,6 @@ FORMS += \ Components/SubscriptionsPanel/subscriptionspanel.ui \ Modules/Empty/emptymodule.ui \ Modules/FileStream/filestreammodule.ui \ - Modules/MainWindow/skywardhubmainwindow.ui \ Modules/MainWindow/window.ui \ Modules/Mavlink/mavlinkrocketmsgtestingmodule.ui \ Modules/OutgoingMessagesViewer/outgoingmessagesviewermodule.ui \ diff --git a/main.cpp b/main.cpp index 57584767ac1ea2b1ea8ca4dd70087ac984f225c7..3a9bbd43c54c6d25da1701e8d99959bb4388de92 100644 --- a/main.cpp +++ b/main.cpp @@ -1,12 +1,15 @@ -#include "Modules/MainWindow/skywardhubmainwindow.h" - #include <QApplication> +#include "Modules/MainWindow/skywardhubmainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication application(argc, argv); -int main(int argc, char *argv[]) { - QApplication a(argc, argv); SkywardHubMainWindow skywardHub; - a.setStyleSheet(skywardHub.styleSheet()); + application.setStyleSheet(skywardHub.styleSheet()); skywardHub.show(); - return a.exec(); + application.exec(); + + return 0; }