diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e736ad3b012c976af759facf8a41a623d46d269..e606ce689ee004680061eb0960b5ef77262d7058 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,10 @@ set(PROJECT_SOURCES src/ControlModel.cpp src/ControlModelRegistry.cpp src/PanelCommandTypes.cpp + src/PanelConfigDirection.cpp + src/PanelConfigPause.cpp + src/PanelConfigGear.cpp + src/PanelConfigDefault.cpp src/CommandType.cpp src/CommandListOWN.cpp include/ComHandler.cpp diff --git a/src/ControlUI.cpp b/src/ControlUI.cpp index 06eee0d399b05a54a750157572bc85f185f6cab1..48be7792064898f508dcfb3f333a5069d94ad60b 100644 --- a/src/ControlUI.cpp +++ b/src/ControlUI.cpp @@ -1,10 +1,41 @@ +#include <QSplitter> + #include "ControlUI.h" #include "PanelCommandTypes.h" +#include "PanelConfigDirection.h" +#include "PanelConfigPause.h" +#include "PanelConfigGear.h" +#include "PanelConfigDefault.h" + +#include <iostream> + ControlUI::ControlUI(QWidget *parent) : QMainWindow(parent) { + ControlModel::getInstance().readCommands("../testCommands.txt"); + setWindowTitle("ControlDeveloper"); - PanelCommandTypes *pct = new PanelCommandTypes(&ControlModel::getInstance()); - setCentralWidget(pct); + QSplitter *splitterH = new QSplitter(Qt::Horizontal); + setCentralWidget(splitterH); + PanelCommandTypes *pct = new PanelCommandTypes(&ControlModel::getInstance(), this); + splitterH->addWidget(pct); + + PanelConfigDirection *pcd = new PanelConfigDirection(this); + splitterH->addWidget(pcd); + PanelConfigPause *pcp = new PanelConfigPause(this); + splitterH->addWidget(pcp); + PanelConfigDefault *pcdef = new PanelConfigDefault(this); + splitterH->addWidget(pcdef); + PanelConfigGear *pcg = new PanelConfigGear(this); + splitterH->addWidget(pcg); + pcg->update(ControlModel::getInstance().getCommandList().getCommand(1)); + pcd->update(ControlModel::getInstance().getCommandList().getCommand(2)); + pcp->update(ControlModel::getInstance().getCommandList().getCommand(3)); +} + +void ControlUI::updateTableView() +{ + std::cout << "\n\nTable:\n"; + ControlModel::getInstance().getCommandList().printCommands(); } diff --git a/src/ControlUI.h b/src/ControlUI.h index ec91558d0150fd08943e9244d0b359d9e641ad52..c46ddba6df0cc8600eeb3e933b0efcfb56e23a35 100644 --- a/src/ControlUI.h +++ b/src/ControlUI.h @@ -1,7 +1,7 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H +#pragma once #include <QMainWindow> +#include <QTableView> class ControlUI : public QMainWindow { @@ -11,5 +11,7 @@ private: public: ControlUI(QWidget *parent = nullptr); + +public slots: + void updateTableView(); }; -#endif // MAINWINDOW_H diff --git a/src/PanelCommandConfig.h b/src/PanelCommandConfig.h new file mode 100644 index 0000000000000000000000000000000000000000..62e099b64e339c81063d9826b4dd01c304eeb2de --- /dev/null +++ b/src/PanelCommandConfig.h @@ -0,0 +1,14 @@ +#pragma once +#include <QWidget> +#include <memory> +#include "commandlib.h" + +class PanelCommandConfig : public QWidget +{ + +protected: + std::shared_ptr<ICommand> command; + +public: + virtual void update(std::shared_ptr<ICommand>) = 0; +}; diff --git a/src/PanelConfigDefault.cpp b/src/PanelConfigDefault.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a820e4e78ef8687298bd8087f4c052af1c5db140 --- /dev/null +++ b/src/PanelConfigDefault.cpp @@ -0,0 +1,10 @@ +#include "PanelConfigDefault.h" + +PanelConfigDefault::PanelConfigDefault(ControlUI *_cui) +{ + cui = _cui; +} + +void PanelConfigDefault::update(std::shared_ptr<ICommand> icom) +{ +} \ No newline at end of file diff --git a/src/PanelConfigDefault.h b/src/PanelConfigDefault.h new file mode 100644 index 0000000000000000000000000000000000000000..5efaa079742d3b8f5cc17f7e4fb29f1da4ec0b58 --- /dev/null +++ b/src/PanelConfigDefault.h @@ -0,0 +1,16 @@ +#pragma once +#include "PanelCommandConfig.h" +#include "ControlUI.h" + +class PanelConfigDefault : public PanelCommandConfig +{ + +Q_OBJECT + +private: + ControlUI *cui; + +public: + PanelConfigDefault(ControlUI *_cui); + void update(std::shared_ptr<ICommand>); +}; \ No newline at end of file diff --git a/src/PanelConfigDirection.cpp b/src/PanelConfigDirection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..74def63022739a670e7fa6db1ec1736b14dcc5f7 --- /dev/null +++ b/src/PanelConfigDirection.cpp @@ -0,0 +1,56 @@ +#include "PanelConfigDirection.h" +#include "Direction.h" +#include <QLayout> +#include <QFormLayout> +#include <QLabel> +#include <memory> + +PanelConfigDirection::PanelConfigDirection(ControlUI *_cui) +{ + cui = _cui; + setView(); + setController(); +} + +void PanelConfigDirection::setView() +{ + QVBoxLayout *vl = new QVBoxLayout(); + setLayout(vl); + QWidget *fw = new QWidget(); + QFormLayout *fl = new QFormLayout(); + fw->setLayout(fl); + vl->addWidget(fw); + bSave = new QPushButton("Save"); + vl->addWidget(bSave); + + tDegree = new QLineEdit(); + fl->addRow("Degree:", tDegree); + fl->addRow("", new QLabel("-90 to +90 degree")); +} + +void PanelConfigDirection::setController() +{ + connect(bSave, SIGNAL(clicked()), this, SLOT(onSaveButton())); +} + +void PanelConfigDirection::update(std::shared_ptr<ICommand> icom) +{ + command = icom; + std::shared_ptr<Direction> d = dynamic_pointer_cast<Direction>(command); + if(d) + { + int deg = d->getDegree(); + tDegree->setText(QString::number(deg)); + } +} + +void PanelConfigDirection::onSaveButton() +{ + int deg = tDegree->text().toInt(); + std::shared_ptr<Direction> d = dynamic_pointer_cast<Direction>(command); + if(d) + { + d->setDegree(deg); + cui->updateTableView(); + } +} \ No newline at end of file diff --git a/src/PanelConfigDirection.h b/src/PanelConfigDirection.h new file mode 100644 index 0000000000000000000000000000000000000000..797d06c388801b5083e3fbeb5f2de54a10a70ffc --- /dev/null +++ b/src/PanelConfigDirection.h @@ -0,0 +1,25 @@ +#pragma once +#include <QLineEdit> +#include <QPushButton> +#include "PanelCommandConfig.h" +#include "ControlUI.h" + +class PanelConfigDirection : public PanelCommandConfig +{ + +Q_OBJECT + +private: + ControlUI *cui; + void setView(); + void setController(); + QPushButton *bSave; + QLineEdit *tDegree; + +public: + PanelConfigDirection(ControlUI *_cui); + void update(std::shared_ptr<ICommand>); + +private slots: + void onSaveButton(); +}; \ No newline at end of file diff --git a/src/PanelConfigGear.cpp b/src/PanelConfigGear.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b0b11b7af8910fbda73bb0f663c3dc8a470561b6 --- /dev/null +++ b/src/PanelConfigGear.cpp @@ -0,0 +1,66 @@ +#include "PanelConfigGear.h" +#include "Gear.h" +#include <QLayout> +#include <QFormLayout> +#include <QLabel> +#include <memory> + +PanelConfigGear::PanelConfigGear(ControlUI *_cui) +{ + cui = _cui; + setView(); + setController(); +} + +void PanelConfigGear::setView() +{ + QVBoxLayout *vl = new QVBoxLayout(); + setLayout(vl); + QWidget *fw = new QWidget(); + QFormLayout *fl = new QFormLayout(); + fw->setLayout(fl); + vl->addWidget(fw); + bSave = new QPushButton("Save"); + vl->addWidget(bSave); + + tSpeed = new QLineEdit(); + fl->addRow("Speed:", tSpeed); + fl->addRow("", new QLabel("-100 to +100 %")); + tDuration = new QLineEdit(); + fl->addRow("Duration:", tDuration); + fl->addRow("", new QLabel("max 8s")); +} + +void PanelConfigGear::setController() +{ + connect(bSave, SIGNAL(clicked()), this, SLOT(onSaveButton())); +} + +void PanelConfigGear::update(std::shared_ptr<ICommand> icom) +{ + command = icom; + std::shared_ptr<Gear> g = dynamic_pointer_cast<Gear>(command); + if(g) + { + int speed = g->getSpeed(); + tSpeed->setText(QString::number(speed)); + double dur = g->getDuration(); + tDuration->setText(QString::number(dur)); + } +} + +void PanelConfigGear::onSaveButton() +{ + int speed = tSpeed->text().toInt(); + double dur = tDuration->text().toDouble(); + std::shared_ptr<Gear> g = dynamic_pointer_cast<Gear>(command); + if(g) + { + if (dur > 0 && dur < 8) + { + g->setDuration(dur); + g->setSpeed(speed); + cui->updateTableView(); + } + } +} \ No newline at end of file diff --git a/src/PanelConfigGear.h b/src/PanelConfigGear.h new file mode 100644 index 0000000000000000000000000000000000000000..e99ea0831d23ba7c8555ce615a75b9c7dc177cbb --- /dev/null +++ b/src/PanelConfigGear.h @@ -0,0 +1,26 @@ +#pragma once +#include <QLineEdit> +#include <QPushButton> +#include "PanelCommandConfig.h" +#include "ControlUI.h" + +class PanelConfigGear : public PanelCommandConfig +{ + +Q_OBJECT + +private: + ControlUI *cui; + void setView(); + void setController(); + QPushButton *bSave; + QLineEdit *tSpeed; + QLineEdit *tDuration; + +public: + PanelConfigGear(ControlUI *_cui); + void update(std::shared_ptr<ICommand>); + +private slots: + void onSaveButton(); +}; \ No newline at end of file diff --git a/src/PanelConfigPause.cpp b/src/PanelConfigPause.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e0d8b3cc2c1e3a152c6ed9417049dfc4fedffccf --- /dev/null +++ b/src/PanelConfigPause.cpp @@ -0,0 +1,59 @@ +#include "PanelConfigPause.h" +#include "Pause.h" +#include <QLayout> +#include <QFormLayout> +#include <QLabel> +#include <memory> + +PanelConfigPause::PanelConfigPause(ControlUI *_cui) +{ + cui = _cui; + setView(); + setController(); +} + +void PanelConfigPause::setView() +{ + QVBoxLayout *vl = new QVBoxLayout(); + setLayout(vl); + QWidget *fw = new QWidget(); + QFormLayout *fl = new QFormLayout(); + fw->setLayout(fl); + vl->addWidget(fw); + bSave = new QPushButton("Save"); + vl->addWidget(bSave); + + tDuration = new QLineEdit(); + fl->addRow("Duration:", tDuration); + fl->addRow("", new QLabel("max 8s")); +} + +void PanelConfigPause::setController() +{ + connect(bSave, SIGNAL(clicked()), this, SLOT(onSaveButton())); +} + +void PanelConfigPause::update(std::shared_ptr<ICommand> icom) +{ + command = icom; + std::shared_ptr<Pause> p = dynamic_pointer_cast<Pause>(command); + if(p) + { + double dur = p->getDuration(); + tDuration->setText(QString::number(dur)); + } +} + +void PanelConfigPause::onSaveButton() +{ + double dur = tDuration->text().toDouble(); + std::shared_ptr<Pause> p = dynamic_pointer_cast<Pause>(command); + if(p) + { + if (dur > 0 && dur < 8) + { + p->setDuration(dur); + cui->updateTableView(); + } + } +} \ No newline at end of file diff --git a/src/PanelConfigPause.h b/src/PanelConfigPause.h new file mode 100644 index 0000000000000000000000000000000000000000..7210acf39fab1d64445b24e0714008c767030af7 --- /dev/null +++ b/src/PanelConfigPause.h @@ -0,0 +1,25 @@ +#pragma once +#include <QLineEdit> +#include <QPushButton> +#include "PanelCommandConfig.h" +#include "ControlUI.h" + +class PanelConfigPause : public PanelCommandConfig +{ + +Q_OBJECT + +private: + ControlUI *cui; + void setView(); + void setController(); + QPushButton *bSave; + QLineEdit *tDuration; + +public: + PanelConfigPause(ControlUI *_cui); + void update(std::shared_ptr<ICommand>); + +private slots: + void onSaveButton(); +}; \ No newline at end of file