Skip to content
Snippets Groups Projects
Commit 807fec5d authored by tobiglaser's avatar tobiglaser
Browse files

Worksheet 4: 3.4 done

parent 09f80386
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,10 @@ set(PROJECT_SOURCES ...@@ -23,6 +23,10 @@ set(PROJECT_SOURCES
src/ControlModel.cpp src/ControlModel.cpp
src/ControlModelRegistry.cpp src/ControlModelRegistry.cpp
src/PanelCommandTypes.cpp src/PanelCommandTypes.cpp
src/PanelConfigDirection.cpp
src/PanelConfigPause.cpp
src/PanelConfigGear.cpp
src/PanelConfigDefault.cpp
src/CommandType.cpp src/CommandType.cpp
src/CommandListOWN.cpp src/CommandListOWN.cpp
include/ComHandler.cpp include/ComHandler.cpp
......
#include <QSplitter>
#include "ControlUI.h" #include "ControlUI.h"
#include "PanelCommandTypes.h" #include "PanelCommandTypes.h"
#include "PanelConfigDirection.h"
#include "PanelConfigPause.h"
#include "PanelConfigGear.h"
#include "PanelConfigDefault.h"
#include <iostream>
ControlUI::ControlUI(QWidget *parent) ControlUI::ControlUI(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
{ {
ControlModel::getInstance().readCommands("../testCommands.txt");
setWindowTitle("ControlDeveloper"); setWindowTitle("ControlDeveloper");
PanelCommandTypes *pct = new PanelCommandTypes(&ControlModel::getInstance()); QSplitter *splitterH = new QSplitter(Qt::Horizontal);
setCentralWidget(pct); 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();
} }
#ifndef MAINWINDOW_H #pragma once
#define MAINWINDOW_H
#include <QMainWindow> #include <QMainWindow>
#include <QTableView>
class ControlUI : public QMainWindow class ControlUI : public QMainWindow
{ {
...@@ -11,5 +11,7 @@ private: ...@@ -11,5 +11,7 @@ private:
public: public:
ControlUI(QWidget *parent = nullptr); ControlUI(QWidget *parent = nullptr);
public slots:
void updateTableView();
}; };
#endif // MAINWINDOW_H
#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;
};
#include "PanelConfigDefault.h"
PanelConfigDefault::PanelConfigDefault(ControlUI *_cui)
{
cui = _cui;
}
void PanelConfigDefault::update(std::shared_ptr<ICommand> icom)
{
}
\ No newline at end of file
#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
#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
#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
#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
#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
#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
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment