inital commit
This commit is contained in:
commit
fede535b95
18
src/auxitem.cpp
Normal file
18
src/auxitem.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "auxitem.h"
|
||||
|
||||
AuxItem::AuxItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AuxItem::setValue(uint8_t value)
|
||||
{
|
||||
Item::setValue(value);
|
||||
micro_->setAuxPwm(value);
|
||||
}
|
||||
|
||||
void AuxItem::store(QJsonObject &json)
|
||||
{
|
||||
json["Type"] = "Aux";
|
||||
Item::store(json);
|
||||
}
|
20
src/auxitem.h
Normal file
20
src/auxitem.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "item.h"
|
||||
#include "../microcontroller.h"
|
||||
|
||||
class AuxItem: public Item
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
Microcontroller* micro_;
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
|
||||
public:
|
||||
AuxItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr);
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
};
|
18
src/items/auxitem.cpp
Normal file
18
src/items/auxitem.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "auxitem.h"
|
||||
|
||||
AuxItem::AuxItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AuxItem::setValue(uint8_t value)
|
||||
{
|
||||
Item::setValue(value);
|
||||
micro_->setAuxPwm(value);
|
||||
}
|
||||
|
||||
void AuxItem::store(QJsonObject &json)
|
||||
{
|
||||
json["Type"] = "Aux";
|
||||
Item::store(json);
|
||||
}
|
20
src/items/auxitem.h
Normal file
20
src/items/auxitem.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "item.h"
|
||||
#include "../microcontroller.h"
|
||||
|
||||
class AuxItem: public Item
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
Microcontroller* micro_;
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
|
||||
public:
|
||||
AuxItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr);
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
};
|
62
src/items/item.cpp
Normal file
62
src/items/item.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
#include "item.h"
|
||||
#include "../microcontroller.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
|
||||
ItemData::ItemData(uint32_t itemIdIn, QString name, uint8_t value): name_(name), value_(value), itemId_(itemIdIn)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString ItemData::getName() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
void ItemData::setName(QString name)
|
||||
{
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
uint8_t ItemData::getValue() const
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
uint32_t ItemData::id() const
|
||||
{
|
||||
return itemId_;
|
||||
}
|
||||
|
||||
|
||||
//item
|
||||
|
||||
Item::Item(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent): QObject(parent), ItemData (itemIdIn, name, value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Item::Item(const ItemData& itemData, QObject *parent): QObject(parent), ItemData(itemData)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Item::~Item()
|
||||
{
|
||||
}
|
||||
|
||||
void Item::setFunction(uint8_t function, bool on)
|
||||
{
|
||||
functionChanged(function, on);
|
||||
}
|
||||
|
||||
void Item::setValue(uint8_t value)
|
||||
{
|
||||
value_ = value;
|
||||
valueChanged(value_);
|
||||
}
|
||||
|
||||
void Item::informValue(uint8_t value)
|
||||
{
|
||||
Item::setValue(value);
|
||||
}
|
58
src/items/item.h
Normal file
58
src/items/item.h
Normal file
@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
#include <vector>
|
||||
#include <QRandomGenerator>
|
||||
#include <QSettings>
|
||||
#include <QJsonObject>
|
||||
#include <memory>
|
||||
|
||||
class Actor;
|
||||
|
||||
class ItemData
|
||||
{
|
||||
protected:
|
||||
QString name_;
|
||||
uint8_t value_;
|
||||
uint32_t itemId_;
|
||||
|
||||
public:
|
||||
|
||||
ItemData(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0);
|
||||
|
||||
inline bool operator==(const ItemData& in) const{ return itemId_==in.itemId_; }
|
||||
inline bool operator!=(const ItemData& in) const{ return itemId_!=in.itemId_; }
|
||||
|
||||
uint32_t id() const;
|
||||
|
||||
void setName(QString name);
|
||||
uint8_t getValue() const;
|
||||
virtual QString getName() const;
|
||||
};
|
||||
|
||||
|
||||
class Item: public QObject, public ItemData
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
|
||||
signals:
|
||||
|
||||
void valueChanged(uint8_t value);
|
||||
void functionChanged(uint8_t function, bool on);
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
virtual void setFunction(uint8_t funciton, bool value);
|
||||
|
||||
public:
|
||||
|
||||
Item(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0, QObject *parent = nullptr);
|
||||
Item(const ItemData& itemData, QObject *parent = nullptr);
|
||||
|
||||
virtual ~Item();
|
||||
|
||||
void informValue(uint8_t value);
|
||||
|
||||
};
|
||||
|
59
src/items/itemstore.cpp
Normal file
59
src/items/itemstore.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include "itemstore.h"
|
||||
#include <QJsonArray>
|
||||
|
||||
ItemStore::ItemStore(QObject *parent): QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void ItemStore::addItem(std::shared_ptr<Item> item)
|
||||
{
|
||||
bool mached = false;
|
||||
for(unsigned i = 0; i < items_.size(); i++ ) if(*items_[i] == *item) mached = true;
|
||||
if(!mached)
|
||||
{
|
||||
items_.push_back(std::shared_ptr<Item>(item));
|
||||
itemAdded(std::weak_ptr<Item>(items_.back()));
|
||||
}
|
||||
}
|
||||
|
||||
void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn)
|
||||
{
|
||||
for(unsigned j = 0; j < itemIn.size(); j++)
|
||||
addItem(itemIn[j]);
|
||||
|
||||
}
|
||||
|
||||
void ItemStore::removeItem(const ItemData& item)
|
||||
{
|
||||
for(unsigned j = 0; j < items_.size(); j++)
|
||||
{
|
||||
if(item == *items_[j])
|
||||
{
|
||||
items_.erase(items_.begin()+j);
|
||||
--j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ItemStore::clear()
|
||||
{
|
||||
for(size_t i = 0; i < items_.size(); ++i) itemDeleted(*items_[i]);
|
||||
items_.clear();
|
||||
}
|
||||
|
||||
|
||||
void ItemStore::itemStateChanged(const ItemData& item)
|
||||
{
|
||||
|
||||
for(unsigned i = 0; i < items_.size(); i++ )
|
||||
{
|
||||
if(items_[i]->operator==(item))
|
||||
{
|
||||
|
||||
if(items_[i]->getValue() != item.getValue())items_[i]->informValue(item.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
34
src/items/itemstore.h
Normal file
34
src/items/itemstore.h
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "item.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
|
||||
class ItemStore: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
std::vector< std::shared_ptr<Item> > items_;
|
||||
|
||||
public:
|
||||
|
||||
ItemStore(QObject *parent = nullptr);
|
||||
virtual ~ItemStore(){}
|
||||
|
||||
inline std::vector< std::shared_ptr<Item> >* getItems(){ return &items_; }
|
||||
|
||||
void clear();
|
||||
|
||||
signals:
|
||||
|
||||
void itemDeleted(ItemData item);
|
||||
void itemAdded(std::weak_ptr<Item> Item);
|
||||
|
||||
public slots:
|
||||
|
||||
void removeItem(const ItemData& item);
|
||||
void addItem(std::shared_ptr<Item> item);
|
||||
void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn);
|
||||
void itemStateChanged(const ItemData& item);
|
||||
};
|
32
src/items/train.cpp
Normal file
32
src/items/train.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include "train.h"
|
||||
|
||||
Train::Train(uint8_t id, uint8_t address, uint8_t functionMask):
|
||||
functionMask_(functionMask),
|
||||
train_id_(id)
|
||||
{
|
||||
itemId_ = address;
|
||||
name_ = QString("Train ")+QString::number(id);
|
||||
}
|
||||
|
||||
Microcontroller *Train::micro = nullptr;
|
||||
|
||||
void Train::setFunction(uint8_t funciton, bool value)
|
||||
{
|
||||
Item::setFunction(funciton, value);
|
||||
if(micro)
|
||||
micro->itemSetFunction(train_id_, funciton, value);
|
||||
}
|
||||
|
||||
void Train::setValue(uint8_t value)
|
||||
{
|
||||
Item::setValue(value);
|
||||
if(micro)
|
||||
micro->itemSetSpeed(train_id_, value);
|
||||
}
|
||||
|
||||
void Train::reverse()
|
||||
{
|
||||
if(micro)
|
||||
micro->itemReverse(train_id_);
|
||||
}
|
||||
|
25
src/items/train.h
Normal file
25
src/items/train.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef TRAIN_H
|
||||
#define TRAIN_H
|
||||
|
||||
#include "item.h"
|
||||
#include "../microcontroller.h"
|
||||
|
||||
class Train : public Item
|
||||
{
|
||||
Q_OBJECT
|
||||
uint8_t functionMask_;
|
||||
uint8_t train_id_;
|
||||
public:
|
||||
static Microcontroller *micro;
|
||||
|
||||
Train(uint8_t id = 0, uint8_t address = 0, uint8_t functionMask = 0);
|
||||
|
||||
uint8_t getFunctionMask() {return functionMask_;}
|
||||
|
||||
public slots:
|
||||
void reverse();
|
||||
virtual void setFunction(uint8_t function, bool on);
|
||||
virtual void setValue(uint8_t value);
|
||||
};
|
||||
|
||||
#endif // TRAIN_H
|
106
src/main.cpp
Normal file
106
src/main.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <stdio.h>
|
||||
#include <QDebug>
|
||||
#include <QTcpSocket>
|
||||
#include <QMessageBox>
|
||||
#include <QtSerialPort/QtSerialPort>
|
||||
#include <QtSerialPort/QSerialPortInfo>
|
||||
#include <QCommandLineParser>
|
||||
|
||||
#include "microcontroller.h"
|
||||
#include "ui/mainwindow.h"
|
||||
#include "items/itemstore.h"
|
||||
#include "items/train.h"
|
||||
|
||||
#define BAUD QSerialPort::Baud38400
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
//set info
|
||||
QCoreApplication::setOrganizationName("UVOS");
|
||||
QCoreApplication::setOrganizationDomain("uvos.xyz");
|
||||
QCoreApplication::setApplicationName("traincontrollerui");
|
||||
QCoreApplication::setApplicationVersion("0.1");
|
||||
|
||||
QDir::setCurrent(a.applicationDirPath());
|
||||
|
||||
//parse comand line
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription("Smart Home Interface");
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
QCommandLineOption tcpOption(QStringList() << "t" << "tcp", QCoreApplication::translate("main", "Use Tcp connection"));
|
||||
parser.addOption(tcpOption);
|
||||
QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main", "Set server host ip addres"), "adress");
|
||||
parser.addOption(hostOption);
|
||||
QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main", "Set server Port in TCP mode or Serial port in serial mode"), "port");
|
||||
parser.addOption(portOption);
|
||||
QCommandLineOption serialOption(QStringList() << "s" << "serial", QCoreApplication::translate("main", "Use serial connection"));
|
||||
parser.addOption(serialOption);
|
||||
QCommandLineOption baudOption(QStringList() << "b" << "baud", QCoreApplication::translate("main", "Set Baud Rate"));
|
||||
parser.addOption(baudOption);
|
||||
parser.process(a);
|
||||
|
||||
QIODevice* masterIODevice = nullptr;
|
||||
|
||||
if(parser.isSet(tcpOption))
|
||||
{
|
||||
QTcpSocket* microSocket = new QTcpSocket;
|
||||
|
||||
int port = 6856;
|
||||
if(parser.isSet(portOption)) port = parser.value(portOption).toInt();
|
||||
|
||||
QString host("127.0.0.1");
|
||||
if(parser.isSet(hostOption)) host = parser.value(hostOption);
|
||||
std::cout<<"connecting to "<<host.toStdString()<<':'<<port<<'\n';
|
||||
microSocket->connectToHost(host, port, QIODevice::ReadWrite);
|
||||
if(!microSocket->waitForConnected(3000))
|
||||
{
|
||||
std::cout<<"Can not connect to to Server.\n";
|
||||
QMessageBox::critical(nullptr, "Error", "Can not connect to to Server");
|
||||
return 1;
|
||||
}
|
||||
masterIODevice = microSocket;
|
||||
}
|
||||
else
|
||||
{
|
||||
QSerialPort* microPort = new QSerialPort;
|
||||
if(parser.isSet(portOption)) microPort->setPortName(parser.value(portOption));
|
||||
else microPort->setPortName("ttyUSB0");
|
||||
|
||||
if(parser.isSet(portOption)) microPort->setBaudRate(parser.value(baudOption).toInt());
|
||||
else microPort->setBaudRate(BAUD);
|
||||
|
||||
if(!microPort->open(QIODevice::ReadWrite))
|
||||
{
|
||||
QMessageBox::critical(nullptr, "Error", QString("Can not open serial port ")+microPort->portName());
|
||||
std::cout<<"Can not open serial port "<<microPort->portName().toStdString()<<". Continueing in demo mode"<<'\n';
|
||||
return 1;
|
||||
}
|
||||
masterIODevice = microPort;
|
||||
}
|
||||
|
||||
Microcontroller micro(masterIODevice);
|
||||
micro.setPower(true);
|
||||
|
||||
Train::micro = µ
|
||||
|
||||
ItemStore items;
|
||||
|
||||
QObject::connect(µ, &Microcontroller::gotItemList, &items, &ItemStore::addItems);
|
||||
|
||||
//mainwindow
|
||||
MainWindow w(µ, &items);
|
||||
|
||||
w.show();
|
||||
|
||||
int retVal = a.exec();
|
||||
micro.setPower(false);
|
||||
|
||||
if(masterIODevice)
|
||||
delete masterIODevice;
|
||||
return retVal;
|
||||
}
|
||||
|
14
src/mainobject.cpp
Normal file
14
src/mainobject.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "mainobject.h"
|
||||
|
||||
MainObject::MainObject(QIODevice* ioDevice) :
|
||||
masterIODevice(ioDevice),
|
||||
micro(masterIODevice)
|
||||
{
|
||||
//connect item store
|
||||
QObject::connect(µ, &Microcontroller::gotItemList, &items, &ItemStore::addItems);
|
||||
}
|
||||
|
||||
MainObject::~MainObject()
|
||||
{
|
||||
}
|
||||
|
47
src/mainobject.h
Normal file
47
src/mainobject.h
Normal file
@ -0,0 +1,47 @@
|
||||
#ifndef MAINOBJECT_H
|
||||
#define MAINOBJECT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <stdio.h>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QTcpSocket>
|
||||
#include <QFileInfo>
|
||||
#include <QJsonDocument>
|
||||
#include <QStandardPaths>
|
||||
#include <memory>
|
||||
|
||||
|
||||
#ifndef Q_OS_ANDROID
|
||||
#include <QtSerialPort/QtSerialPort>
|
||||
#include <QtSerialPort/QSerialPortInfo>
|
||||
#include <QCommandLineParser>
|
||||
#endif
|
||||
|
||||
#include "microcontroller.h"
|
||||
#include "ui/mainwindow.h"
|
||||
#include "items/itemstore.h"
|
||||
#include "items/auxitem.h"
|
||||
|
||||
class MainObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
//io
|
||||
QIODevice * const masterIODevice = nullptr;
|
||||
|
||||
Microcontroller micro;
|
||||
|
||||
const QString settingsPath;
|
||||
|
||||
//items
|
||||
ItemStore items;
|
||||
|
||||
public:
|
||||
explicit MainObject(QIODevice* ioDevice);
|
||||
~MainObject();
|
||||
};
|
||||
|
||||
#endif // MAINOBJECT_H
|
166
src/microcontroller.cpp
Normal file
166
src/microcontroller.cpp
Normal file
@ -0,0 +1,166 @@
|
||||
#include "microcontroller.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include "items/train.h"
|
||||
|
||||
void Microcontroller::itemSetSpeed(uint8_t id, uint8_t speed)
|
||||
{
|
||||
qDebug()<<__func__;
|
||||
std::stringstream ss;
|
||||
ss<<"train "<<(unsigned)id<<" speed "<<(unsigned)speed<<'\n';
|
||||
write(ss.str().c_str());
|
||||
}
|
||||
|
||||
void Microcontroller::itemReverse(uint8_t id)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss<<"train "<<(unsigned)id<<" reverse\n";
|
||||
write(ss.str().c_str());
|
||||
}
|
||||
|
||||
void Microcontroller::itemSetFunction(uint8_t id, uint8_t function, bool on)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss<<"train "<<(unsigned)id<<" function "<<(unsigned)function<<' '<<(on ? "on" : "off")<<'\n';
|
||||
write(ss.str().c_str());
|
||||
}
|
||||
|
||||
void Microcontroller::setPower(bool on)
|
||||
{
|
||||
write(on ? "power on\n" : "power off\n");
|
||||
}
|
||||
|
||||
void Microcontroller::estop()
|
||||
{
|
||||
write("stop\n");
|
||||
}
|
||||
|
||||
void Microcontroller::write(const QByteArray& buffer)
|
||||
{
|
||||
qDebug()<<buffer;
|
||||
if(_port != nullptr)
|
||||
{
|
||||
_port->write(buffer);
|
||||
_port->waitForBytesWritten(1000);
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(40));
|
||||
}
|
||||
|
||||
void Microcontroller::write(char* buffer, const size_t length)
|
||||
{
|
||||
qDebug()<<buffer;
|
||||
if(_port != nullptr)
|
||||
{
|
||||
_port->write(buffer, length);
|
||||
_port->waitForBytesWritten(1000);
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(40));
|
||||
}
|
||||
|
||||
bool Microcontroller::connected()
|
||||
{
|
||||
if(_port != nullptr)
|
||||
return _port->isOpen();
|
||||
else return false;
|
||||
}
|
||||
|
||||
void Microcontroller::requestState()
|
||||
{
|
||||
write("train list\n");
|
||||
}
|
||||
|
||||
//housekeeping
|
||||
|
||||
Microcontroller::Microcontroller(QIODevice* port)
|
||||
{
|
||||
setIODevice(port);
|
||||
}
|
||||
|
||||
Microcontroller::Microcontroller()
|
||||
{
|
||||
}
|
||||
|
||||
Microcontroller::~Microcontroller()
|
||||
{
|
||||
}
|
||||
|
||||
void Microcontroller::setIODevice(QIODevice *port)
|
||||
{
|
||||
_port = port;
|
||||
QObject::connect(_port, &QIODevice::readyRead, this, &Microcontroller::isReadyRead);
|
||||
}
|
||||
|
||||
std::shared_ptr<Item> Microcontroller::processTrainLine(const QString& buffer)
|
||||
{
|
||||
QStringList bufferList = buffer.split(' ');
|
||||
if(bufferList.size() >= 9 && buffer.startsWith("NUMBER:"))
|
||||
{
|
||||
return std::shared_ptr<Item>(new Train(bufferList[1].toInt(), bufferList[3].toInt(), bufferList[12].toInt()));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Microcontroller::processList(const QString& buffer)
|
||||
{
|
||||
QStringList bufferList = buffer.split(' ');
|
||||
if(bufferList.size() >= 13 && buffer.startsWith("NUMBER:"))
|
||||
{
|
||||
itemList.push_back(processTrainLine(buffer));
|
||||
}
|
||||
else
|
||||
{
|
||||
listMode = false;
|
||||
if(!itemList.empty())
|
||||
{
|
||||
qDebug()<<"got item list " << itemList.size();
|
||||
gotItemList(itemList);
|
||||
itemList.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Microcontroller::processItemState(const QString& buffer)
|
||||
{
|
||||
itemChanged(static_cast<ItemData>(*processTrainLine(buffer)));
|
||||
}
|
||||
|
||||
|
||||
void Microcontroller::processMicroReturn()
|
||||
{
|
||||
if(listMode)
|
||||
processList(_buffer);
|
||||
else
|
||||
{
|
||||
if(_buffer.startsWith("Trains:"))
|
||||
{
|
||||
listMode = true;
|
||||
itemList.clear();
|
||||
}
|
||||
else if(_buffer.startsWith("NUMBER:"))
|
||||
{
|
||||
processItemState(_buffer);
|
||||
}
|
||||
else if(_buffer.startsWith("TrainController"))
|
||||
{
|
||||
requestState();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Microcontroller::isReadyRead()
|
||||
{
|
||||
char charBuf;
|
||||
while(_port->getChar(&charBuf))
|
||||
{
|
||||
_buffer.push_back(charBuf);
|
||||
if( _buffer.endsWith('\n') )
|
||||
{
|
||||
_buffer.remove('\n');
|
||||
processMicroReturn();
|
||||
textRecived(_buffer);
|
||||
_buffer.clear();
|
||||
}
|
||||
}
|
||||
}
|
78
src/microcontroller.h
Normal file
78
src/microcontroller.h
Normal file
@ -0,0 +1,78 @@
|
||||
#ifndef MICROCONTROLLER_H
|
||||
#define MICROCONTROLLER_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QObject>
|
||||
#include <QColor>
|
||||
#include <QIODevice>
|
||||
#include <QString>
|
||||
#include <QRunnable>
|
||||
#include <QDebug>
|
||||
#include <QEventLoop>
|
||||
#include <QTimer>
|
||||
#include <QAbstractButton>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include "items/item.h"
|
||||
|
||||
class Microcontroller : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
static constexpr char AMP_RELAY = 0;
|
||||
static constexpr char SENSOR_TEMPERATURE = 1;
|
||||
static constexpr char SENSOR_DOOR = 0 ;
|
||||
|
||||
private:
|
||||
|
||||
bool listMode = false;
|
||||
|
||||
//uint8_t _auxState = 0;
|
||||
|
||||
QIODevice* _port = nullptr;
|
||||
|
||||
std::vector< std::shared_ptr<Item> > itemList;
|
||||
|
||||
QScopedPointer<QEventLoop> loop;
|
||||
QString _buffer;
|
||||
|
||||
void processMicroReturn();
|
||||
void processList(const QString& buffer);
|
||||
void processItemState(const QString& buffer);
|
||||
std::shared_ptr<Item> processTrainLine(const QString& buffer);
|
||||
|
||||
void write(char *buffer, const size_t length);
|
||||
void write(const QByteArray& buffer);
|
||||
|
||||
public:
|
||||
Microcontroller(QIODevice* port);
|
||||
Microcontroller();
|
||||
~Microcontroller();
|
||||
bool connected();
|
||||
void setIODevice(QIODevice* port);
|
||||
|
||||
public slots:
|
||||
void requestState();
|
||||
|
||||
void itemSetSpeed(uint8_t id, uint8_t speed);
|
||||
void itemReverse(uint8_t id);
|
||||
void itemSetFunction(uint8_t id, uint8_t function, bool on);
|
||||
void estop();
|
||||
void setPower(bool on);
|
||||
|
||||
private slots:
|
||||
void isReadyRead();
|
||||
|
||||
signals:
|
||||
void textRecived(const QString string);
|
||||
void itemChanged(ItemData relay);
|
||||
void auxStateChanged(int value);
|
||||
void gotItemList(std::vector< std::shared_ptr<Item> >&);
|
||||
};
|
||||
|
||||
#endif // MICROCONTROLLER_H
|
142
src/ui/alarmsettingsdialog.ui.orig
Normal file
142
src/ui/alarmsettingsdialog.ui.orig
Normal file
@ -0,0 +1,142 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AlarmSettingsDialog</class>
|
||||
<widget class="QDialog" name="AlarmSettingsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>423</width>
|
||||
<height>281</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Sound File:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Change</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Sunrise</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>Enable</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>AlarmSettingsDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>AlarmSettingsDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
30
src/ui/itemcreationdialog.cpp
Normal file
30
src/ui/itemcreationdialog.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include "itemcreationdialog.h"
|
||||
#include "ui_itemcreationdialog.h"
|
||||
|
||||
ItemCreationDialog::ItemCreationDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ItemCreationDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->comboBox, &QComboBox::currentTextChanged, this, &ItemCreationDialog::itemTypeChanged);
|
||||
connect(ui->lineEdit, &QLineEdit::textChanged, this, &ItemCreationDialog::itemNameChanged);
|
||||
}
|
||||
|
||||
ItemCreationDialog::~ItemCreationDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ItemCreationDialog::itemTypeChanged(const QString& type)
|
||||
{
|
||||
ui->verticalLayout->removeWidget(widget);
|
||||
}
|
||||
|
||||
void ItemCreationDialog::itemNameChanged(const QString& name)
|
||||
{
|
||||
if(item)
|
||||
{
|
||||
item->setName(name);
|
||||
}
|
||||
}
|
||||
|
33
src/ui/itemcreationdialog.h
Normal file
33
src/ui/itemcreationdialog.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef ITEMCREATIONDIALOG_H
|
||||
#define ITEMCREATIONDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <memory>
|
||||
#include "../items/item.h"
|
||||
|
||||
namespace Ui {
|
||||
class ItemCreationDialog;
|
||||
}
|
||||
|
||||
class ItemCreationDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QWidget* widget;
|
||||
|
||||
public:
|
||||
explicit ItemCreationDialog(QWidget *parent = nullptr);
|
||||
~ItemCreationDialog();
|
||||
|
||||
std::shared_ptr<Item> item;
|
||||
|
||||
private slots:
|
||||
|
||||
void itemTypeChanged(const QString& type);
|
||||
void itemNameChanged(const QString& name);
|
||||
|
||||
private:
|
||||
Ui::ItemCreationDialog *ui;
|
||||
};
|
||||
|
||||
#endif // ITEMCREATIONDIALOG_H
|
116
src/ui/itemcreationdialog.ui
Normal file
116
src/ui/itemcreationdialog.ui
Normal file
@ -0,0 +1,116 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ItemCreationDialog</class>
|
||||
<widget class="QDialog" name="ItemCreationDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>140</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Create Item</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../../resources.qrc">
|
||||
<normaloff>:/images/UVOSicon.bmp</normaloff>:/images/UVOSicon.bmp</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Message</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>System</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit">
|
||||
<property name="text">
|
||||
<string>Item</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../resources.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ItemCreationDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ItemCreationDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
54
src/ui/itemscrollbox.cpp
Normal file
54
src/ui/itemscrollbox.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include "itemscrollbox.h"
|
||||
#include "ui_relayscrollbox.h"
|
||||
|
||||
ItemScrollBox::ItemScrollBox(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::RelayScrollBox)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
QScroller::grabGesture(ui->scrollArea, QScroller::TouchGesture);
|
||||
QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture);
|
||||
}
|
||||
|
||||
ItemScrollBox::~ItemScrollBox()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ItemScrollBox::addItem(std::weak_ptr<Item> item)
|
||||
{
|
||||
static int lifetimeNum = 0;
|
||||
if(auto workItem = item.lock())
|
||||
{
|
||||
widgets_.push_back(new ItemWidget(item, this));
|
||||
if(lifetimeNum == 0)
|
||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_Q), QKeySequence(Qt::Key_A), QKeySequence(Qt::Key_Z));
|
||||
else if(lifetimeNum == 1)
|
||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_W), QKeySequence(Qt::Key_S), QKeySequence(Qt::Key_X));
|
||||
else if(lifetimeNum == 2)
|
||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_E), QKeySequence(Qt::Key_D), QKeySequence(Qt::Key_C));
|
||||
else if(lifetimeNum == 3)
|
||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_R), QKeySequence(Qt::Key_F), QKeySequence(Qt::Key_V));
|
||||
else if(lifetimeNum == 4)
|
||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_T), QKeySequence(Qt::Key_G), QKeySequence(Qt::Key_B));
|
||||
ui->relayWidgetVbox->addWidget(widgets_.back());
|
||||
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest);
|
||||
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem);
|
||||
lifetimeNum++;
|
||||
}
|
||||
}
|
||||
|
||||
void ItemScrollBox::removeItem(const ItemData& item)
|
||||
{
|
||||
for(unsigned i = 0; i < widgets_.size(); i++)
|
||||
{
|
||||
if(widgets_[i]->controles(item))
|
||||
{
|
||||
ui->relayWidgetVbox->removeWidget(widgets_[i]);
|
||||
delete widgets_[i];
|
||||
widgets_.erase(widgets_.begin()+i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
44
src/ui/itemscrollbox.h
Normal file
44
src/ui/itemscrollbox.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef RELAYSCROLLBOX_H
|
||||
#define RELAYSCROLLBOX_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <QScroller>
|
||||
#include "itemwidget.h"
|
||||
#include "../items/item.h"
|
||||
#include "../items/itemstore.h"
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class RelayScrollBox;
|
||||
}
|
||||
|
||||
class ItemScrollBox : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
std::vector< ItemWidget* > widgets_;
|
||||
|
||||
signals:
|
||||
void deleteRequest(const ItemData& item);
|
||||
|
||||
|
||||
public:
|
||||
explicit ItemScrollBox(QWidget *parent = nullptr);
|
||||
~ItemScrollBox();
|
||||
|
||||
void setItemStore(ItemStore* itemStore);
|
||||
|
||||
public slots:
|
||||
|
||||
void addItem(std::weak_ptr<Item> item);
|
||||
void removeItem(const ItemData& item);
|
||||
|
||||
private:
|
||||
Ui::RelayScrollBox *ui;
|
||||
};
|
||||
|
||||
#endif // RELAYSCROLLBOX_H
|
||||
|
||||
|
176
src/ui/itemsettingsdialog.cpp
Normal file
176
src/ui/itemsettingsdialog.cpp
Normal file
@ -0,0 +1,176 @@
|
||||
#include "itemsettingsdialog.h"
|
||||
#include "ui_itemsettingsdialog.h"
|
||||
#include<memory>
|
||||
|
||||
ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
item_(item),
|
||||
ui(new Ui::ItemSettingsDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
setModal(false);
|
||||
|
||||
ui->label_name->setText(item_->getName());
|
||||
ui->checkBox_Override->setChecked(item_->getOverride());
|
||||
|
||||
|
||||
if(std::shared_ptr<Relay> relay = std::dynamic_pointer_cast<Relay>(item_))
|
||||
{
|
||||
itemSpecificWidget_ = new RelayItemSettingsWidget(relay);
|
||||
}
|
||||
else if(std::shared_ptr<MessageItem> msgItem = std::dynamic_pointer_cast<MessageItem>(item_))
|
||||
{
|
||||
itemSpecificWidget_ = new MessageItemSettingsWidget(msgItem);
|
||||
}
|
||||
else if(std::shared_ptr<SystemItem> sysItem = std::dynamic_pointer_cast<SystemItem>(item_))
|
||||
{
|
||||
itemSpecificWidget_ = new SystemItemSettingsWidget(sysItem);
|
||||
}
|
||||
|
||||
if(itemSpecificWidget_)
|
||||
{
|
||||
ui->verticalLayout_2->addWidget(itemSpecificWidget_);
|
||||
}
|
||||
|
||||
connect(ui->pushButton_add, &QPushButton::clicked, this, &ItemSettingsDialog::addActor);
|
||||
connect(ui->pushButton_remove, &QPushButton::clicked, this, &ItemSettingsDialog::removeActor);
|
||||
connect(ui->pushButton_edit, &QPushButton::clicked, this, &ItemSettingsDialog::editActor);
|
||||
connect(ui->checkBox_Override, &QPushButton::clicked, this, &ItemSettingsDialog::changeOverride);
|
||||
|
||||
|
||||
ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Actor"));
|
||||
ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Action"));
|
||||
ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Enabled"));
|
||||
ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
ui->tableWidget->horizontalHeader()->resizeSection(1, 60);
|
||||
ui->tableWidget->horizontalHeader()->resizeSection(2, 75);
|
||||
loadActorList();
|
||||
}
|
||||
|
||||
ItemSettingsDialog::~ItemSettingsDialog()
|
||||
{
|
||||
if(itemSpecificWidget_) delete itemSpecificWidget_;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ItemSettingsDialog::changeOverride()
|
||||
{
|
||||
item_->setOverride(ui->checkBox_Override->isChecked());
|
||||
}
|
||||
|
||||
void ItemSettingsDialog::loadActorList()
|
||||
{
|
||||
//ui->listWidget->clear();
|
||||
ui->tableWidget->setRowCount(item_->getActors().size());
|
||||
|
||||
for(unsigned i = 0; i < item_->getActors().size(); i++)
|
||||
{
|
||||
ui->tableWidget->setItem(i, 0, new QTableWidgetItem(item_->getActors()[i]->getName()));
|
||||
ui->tableWidget->setItem(i, 1, new QTableWidgetItem(item_->getActors()[i]->actionName()));
|
||||
ui->tableWidget->setItem(i, 2, new QTableWidgetItem(item_->getActors()[i]->isActive() ? "Y" : "N"));
|
||||
}
|
||||
}
|
||||
|
||||
void ItemSettingsDialog::addActor()
|
||||
{
|
||||
ActorSettingsDialog* dialog = nullptr;
|
||||
std::shared_ptr<Actor> actor = nullptr;
|
||||
|
||||
if(ui->comboBox->currentText() == "Alarm")
|
||||
{
|
||||
std::shared_ptr<AlarmTime> alarm = std::shared_ptr<AlarmTime>(new AlarmTime);
|
||||
actor = alarm;
|
||||
dialog = new ActorSettingsDialog(alarm, this);
|
||||
}
|
||||
else if(ui->comboBox->currentText() == "Sensor")
|
||||
{
|
||||
std::shared_ptr<SensorActor> sensorActor = std::shared_ptr<SensorActor>(new SensorActor);
|
||||
actor = sensorActor;
|
||||
dialog = new ActorSettingsDialog(sensorActor, this);
|
||||
}
|
||||
else if(ui->comboBox->currentText() == "Timer" )
|
||||
{
|
||||
std::shared_ptr<TimerActor> timerActor = std::shared_ptr<TimerActor>(new TimerActor);
|
||||
actor = timerActor;
|
||||
dialog = new ActorSettingsDialog(timerActor, this);
|
||||
}
|
||||
else if(ui->comboBox->currentText() == "Regulator")
|
||||
{
|
||||
std::shared_ptr<Regulator> regulator = std::shared_ptr<Regulator>(new Regulator);
|
||||
actor = regulator;
|
||||
dialog = new ActorSettingsDialog(regulator, this);
|
||||
}
|
||||
|
||||
else if(ui->comboBox->currentText() == "Polynomal")
|
||||
{
|
||||
std::shared_ptr<PolynomalActor> polynomalActor = std::shared_ptr<PolynomalActor>(new PolynomalActor);
|
||||
actor = polynomalActor;
|
||||
dialog = new ActorSettingsDialog(polynomalActor, this);
|
||||
}
|
||||
|
||||
else if(ui->comboBox->currentText() == "Multi Factor")
|
||||
{
|
||||
std::shared_ptr<MultiFactorActor> polynomalActor = std::shared_ptr<MultiFactorActor>(new MultiFactorActor);
|
||||
actor = polynomalActor;
|
||||
dialog = new ActorSettingsDialog(polynomalActor, this);
|
||||
}
|
||||
|
||||
|
||||
if(dialog != nullptr)
|
||||
{
|
||||
dialog->setParent(this);
|
||||
dialog->show();
|
||||
if(dialog->exec() == QDialog::Accepted)
|
||||
{
|
||||
item_->addActor(actor);
|
||||
loadActorList();
|
||||
}
|
||||
delete dialog;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ItemSettingsDialog::removeActor()
|
||||
{
|
||||
if(item_->getActors().size() > ui->tableWidget->currentRow())
|
||||
{
|
||||
item_->removeActor(item_->getActors().at(ui->tableWidget->currentRow()));
|
||||
loadActorList();
|
||||
}
|
||||
}
|
||||
|
||||
void ItemSettingsDialog::editActor()
|
||||
{
|
||||
if(item_->getActors().size() > ui->tableWidget->currentRow())
|
||||
{
|
||||
std::shared_ptr<Actor> actor = item_->getActors()[ui->tableWidget->currentRow()];
|
||||
|
||||
std::shared_ptr<AlarmTime> alarmTime = std::dynamic_pointer_cast<AlarmTime>(actor);
|
||||
std::shared_ptr<Regulator> regulator = std::dynamic_pointer_cast<Regulator>(actor);
|
||||
std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
|
||||
std::shared_ptr<TimerActor> timerActor = std::dynamic_pointer_cast<TimerActor>(actor);
|
||||
std::shared_ptr<PolynomalActor> polynomalActor = std::dynamic_pointer_cast<PolynomalActor>(actor);
|
||||
std::shared_ptr<MultiFactorActor> factorActor = std::dynamic_pointer_cast<MultiFactorActor>(actor);
|
||||
|
||||
ActorSettingsDialog* dialog;
|
||||
|
||||
if(alarmTime) dialog = new ActorSettingsDialog(alarmTime, this);
|
||||
else if(regulator) dialog = new ActorSettingsDialog(regulator, this);
|
||||
else if(sensorActor) dialog = new ActorSettingsDialog(sensorActor, this);
|
||||
else if(timerActor) dialog = new ActorSettingsDialog(timerActor, this);
|
||||
else if(polynomalActor) dialog = new ActorSettingsDialog(polynomalActor, this);
|
||||
else if(factorActor) dialog = new ActorSettingsDialog(factorActor, this);
|
||||
else dialog = new ActorSettingsDialog(actor, this);
|
||||
dialog->setParent(this);
|
||||
dialog->show();
|
||||
dialog->exec();
|
||||
|
||||
for(int i = 0; i < ui->tableWidget->rowCount() && i < item_->getActors().size(); ++i)
|
||||
{
|
||||
ui->tableWidget->item(i, 0)->setText(item_->getActors()[i]->getName());
|
||||
ui->tableWidget->item(i, 1)->setText(item_->getActors()[i]->actionName());
|
||||
ui->tableWidget->item(i, 2)->setText(item_->getActors()[i]->isActive() ? "Y" : "N");
|
||||
}
|
||||
}
|
||||
}
|
37
src/ui/itemsettingsdialog.h
Normal file
37
src/ui/itemsettingsdialog.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef RELAYSETTINGSDIALOG_H
|
||||
#define RELAYSETTINGSDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QSettings>
|
||||
#include <memory>
|
||||
#include "../items/item.h"
|
||||
|
||||
namespace Ui {
|
||||
class ItemSettingsDialog;
|
||||
}
|
||||
|
||||
class ItemSettingsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
std::shared_ptr<Item> item_;
|
||||
QWidget* itemSpecificWidget_ = nullptr;
|
||||
|
||||
private:
|
||||
void loadActorList();
|
||||
|
||||
public:
|
||||
explicit ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent = nullptr);
|
||||
~ItemSettingsDialog();
|
||||
|
||||
private slots:
|
||||
|
||||
void removeActor();
|
||||
void addActor();
|
||||
void editActor();
|
||||
void changeOverride();
|
||||
|
||||
private:
|
||||
Ui::ItemSettingsDialog *ui;
|
||||
};
|
||||
|
||||
#endif // RELAYSETTINGSDIALOG_H
|
274
src/ui/itemsettingsdialog.ui
Normal file
274
src/ui/itemsettingsdialog.ui
Normal file
@ -0,0 +1,274 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ItemSettingsDialog</class>
|
||||
<widget class="QDialog" name="ItemSettingsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>577</width>
|
||||
<height>390</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Item Settings</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../../resources.qrc">
|
||||
<normaloff>:/images/UVOSicon.bmp</normaloff>:/images/UVOSicon.bmp</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_name">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>5</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_Override">
|
||||
<property name="text">
|
||||
<string>Override</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="autoScroll">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="tabKeyNavigation">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="showDropIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="dragDropOverwriteMode">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="showGrid">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="gridStyle">
|
||||
<enum>Qt::SolidLine</enum>
|
||||
</property>
|
||||
<property name="cornerButtonEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="rowCount">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderMinimumSectionSize">
|
||||
<number>32</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderHighlightSections">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>32</number>
|
||||
</attribute>
|
||||
<column/>
|
||||
<column/>
|
||||
<column/>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_remove">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_edit">
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Act on</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Sensor</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Polynomal</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Regulator</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Alarm</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Timer</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Multi Factor</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_add">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../resources.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ItemSettingsDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ItemSettingsDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
170
src/ui/itemwidget.cpp
Normal file
170
src/ui/itemwidget.cpp
Normal file
@ -0,0 +1,170 @@
|
||||
#include "itemwidget.h"
|
||||
#include "ui_itemwidget.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QDebug>
|
||||
#include <QSlider>
|
||||
#include "../items/train.h"
|
||||
|
||||
ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
item_(item),
|
||||
ui(new Ui::ItemWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
if(auto workingRelay = item_.lock())
|
||||
{
|
||||
ui->label->setText(workingRelay->getName());
|
||||
|
||||
connect(ui->slider, &QSlider::valueChanged, this, &ItemWidget::moveToValue);
|
||||
connect(ui->checkBox_f1, &QCheckBox::stateChanged, this, &ItemWidget::f1);
|
||||
connect(ui->checkBox_f2, &QCheckBox::stateChanged, this, &ItemWidget::f2);
|
||||
connect(ui->checkBox_f3, &QCheckBox::stateChanged, this, &ItemWidget::f3);
|
||||
connect(ui->checkBox_f4, &QCheckBox::stateChanged, this, &ItemWidget::f4);
|
||||
connect(ui->pushButton_reverse, &QPushButton::clicked, this, &ItemWidget::reverse);
|
||||
|
||||
Train* train = dynamic_cast<Train*>(workingRelay.get());
|
||||
if(!train)
|
||||
{
|
||||
ui->pushButton_reverse->hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t functionMask = train->getFunctionMask();
|
||||
if(!(functionMask & (1 << 0)))
|
||||
ui->checkBox_f1->hide();
|
||||
if(!(functionMask & (1 << 1)))
|
||||
ui->checkBox_f2->hide();
|
||||
if(!(functionMask & (1 << 2)))
|
||||
ui->checkBox_f3->hide();
|
||||
if(!(functionMask & (1 << 3)))
|
||||
ui->checkBox_f4->hide();
|
||||
}
|
||||
|
||||
}
|
||||
else disable();
|
||||
}
|
||||
|
||||
void ItemWidget::deleteItem()
|
||||
{
|
||||
if(auto workingItem = item_.lock())
|
||||
{
|
||||
deleteRequest(*workingItem);
|
||||
}
|
||||
}
|
||||
|
||||
void ItemWidget::moveToValue(int value)
|
||||
{
|
||||
qDebug()<<__func__;
|
||||
ui->pushButton_reverse->setDisabled(value != 0);
|
||||
if(auto workingItem = item_.lock())
|
||||
workingItem->setValue(value);
|
||||
else disable();
|
||||
}
|
||||
|
||||
void ItemWidget::f1(int value)
|
||||
{
|
||||
if(auto workingItem = item_.lock())
|
||||
workingItem->setFunction(0, value == Qt::Checked);
|
||||
else disable();
|
||||
}
|
||||
|
||||
void ItemWidget::f2(int value)
|
||||
{
|
||||
if(auto workingItem = item_.lock())
|
||||
workingItem->setFunction(1, value == Qt::Checked);
|
||||
else disable();
|
||||
}
|
||||
|
||||
|
||||
void ItemWidget::f3(int value)
|
||||
{
|
||||
if(auto workingItem = item_.lock())
|
||||
workingItem->setFunction(2, value == Qt::Checked);
|
||||
else disable();
|
||||
}
|
||||
|
||||
void ItemWidget::f4(int value)
|
||||
{
|
||||
if(auto workingItem = item_.lock())
|
||||
workingItem->setFunction(3, value == Qt::Checked);
|
||||
else disable();
|
||||
}
|
||||
|
||||
void ItemWidget::reverse()
|
||||
{
|
||||
if(auto workingItem = item_.lock())
|
||||
{
|
||||
Train* train = dynamic_cast<Train*>(workingItem.get());
|
||||
if(train && ui->slider->value() == 0)
|
||||
train->reverse();
|
||||
else
|
||||
ui->slider->setValue(0);
|
||||
}
|
||||
else disable();
|
||||
}
|
||||
|
||||
void ItemWidget::disable()
|
||||
{
|
||||
ui->checkBox_f1->setEnabled(false);
|
||||
ui->checkBox_f2->setEnabled(false);
|
||||
ui->checkBox_f3->setEnabled(false);
|
||||
ui->checkBox_f4->setEnabled(false);
|
||||
ui->label->setEnabled(false);
|
||||
ui->slider->setEnabled(false);
|
||||
ui->pushButton_reverse->setEnabled(false);
|
||||
}
|
||||
|
||||
bool ItemWidget::controles(const ItemData& relay)
|
||||
{
|
||||
if(auto workingRelay = item_.lock())
|
||||
{
|
||||
if(relay == *workingRelay)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ItemWidget::stepUp()
|
||||
{
|
||||
ui->slider->setValue(ui->slider->value()+1);
|
||||
}
|
||||
|
||||
void ItemWidget::stepDown()
|
||||
{
|
||||
if(ui->slider->value() == 0)
|
||||
moveToValue(0);
|
||||
ui->slider->setValue(ui->slider->value()-1);
|
||||
}
|
||||
|
||||
void ItemWidget::setShortcuts(QKeySequence up, QKeySequence down, QKeySequence rev)
|
||||
{
|
||||
shortcuts_.clear();
|
||||
shortcuts_.push_back(std::unique_ptr<QShortcut>(new QShortcut(up, this)));
|
||||
connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::stepUp);
|
||||
shortcuts_.push_back(std::unique_ptr<QShortcut>(new QShortcut(down, this)));
|
||||
connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::stepDown);
|
||||
shortcuts_.push_back(std::unique_ptr<QShortcut>(new QShortcut(rev, this)));
|
||||
connect(shortcuts_.back().get(), &QShortcut::activated, this, &ItemWidget::reverse);
|
||||
}
|
||||
|
||||
std::weak_ptr<Item> ItemWidget::getItem()
|
||||
{
|
||||
return item_;
|
||||
}
|
||||
|
||||
void ItemWidget::stateChanged(int state)
|
||||
{
|
||||
qDebug()<<"widget got state "<<state;
|
||||
ui->slider->blockSignals(true);
|
||||
ui->slider->setValue(state);
|
||||
ui->slider->blockSignals(false);
|
||||
}
|
||||
|
||||
ItemWidget::~ItemWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
56
src/ui/itemwidget.h
Normal file
56
src/ui/itemwidget.h
Normal file
@ -0,0 +1,56 @@
|
||||
#ifndef RELAYWIDGET_H
|
||||
#define RELAYWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <memory>
|
||||
#include <QShortcut>
|
||||
#include "itemsettingsdialog.h"
|
||||
#include "../items/item.h"
|
||||
|
||||
namespace Ui {
|
||||
class ItemWidget;
|
||||
}
|
||||
|
||||
class ItemWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
std::weak_ptr<Item> item_;
|
||||
|
||||
std::vector< std::unique_ptr<QShortcut> > shortcuts_;
|
||||
|
||||
void disable();
|
||||
|
||||
signals:
|
||||
|
||||
void deleteRequest(const ItemData& item);
|
||||
|
||||
private slots:
|
||||
void moveToValue(int value);
|
||||
void deleteItem();
|
||||
|
||||
void stepUp();
|
||||
void stepDown();
|
||||
|
||||
void f1(int state);
|
||||
void f2(int state);
|
||||
void f3(int state);
|
||||
void f4(int state);
|
||||
void reverse();
|
||||
|
||||
public:
|
||||
explicit ItemWidget(std::weak_ptr<Item> item, QWidget *parent);
|
||||
std::weak_ptr<Item> getItem();
|
||||
bool controles(const ItemData& relay);
|
||||
~ItemWidget();
|
||||
void setShortcuts(QKeySequence up, QKeySequence down, QKeySequence rev);
|
||||
|
||||
public slots:
|
||||
|
||||
void stateChanged(int state);
|
||||
|
||||
private:
|
||||
Ui::ItemWidget *ui;
|
||||
};
|
||||
|
||||
#endif // RELAYWIDGET_H
|
126
src/ui/itemwidget.ui
Normal file
126
src/ui/itemwidget.ui
Normal file
@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ItemWidget</class>
|
||||
<widget class="QWidget" name="ItemWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>264</width>
|
||||
<height>83</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QSlider" name="slider">
|
||||
<property name="maximum">
|
||||
<number>14</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="tracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_reverse">
|
||||
<property name="text">
|
||||
<string>Reverse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_f1">
|
||||
<property name="text">
|
||||
<string>F1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_f2">
|
||||
<property name="text">
|
||||
<string>F2</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_f3">
|
||||
<property name="text">
|
||||
<string>F3</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_f4">
|
||||
<property name="text">
|
||||
<string>F4</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
45
src/ui/mainwindow.cpp
Normal file
45
src/ui/mainwindow.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "itemscrollbox.h"
|
||||
#include "itemsettingsdialog.h"
|
||||
#include "itemcreationdialog.h"
|
||||
|
||||
MainWindow::MainWindow(Microcontroller * const micro, ItemStore* items, QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
stopShort(QKeySequence(Qt::Key_Space), this),
|
||||
ui(new Ui::MainWindow),
|
||||
_micro(micro)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(&stopShort, &QShortcut::activated, _micro, &Microcontroller::estop);
|
||||
connect(ui->pushButton_stop, &QPushButton::clicked, _micro, &Microcontroller::estop);
|
||||
connect(ui->pushButton_refesh, &QPushButton::clicked, _micro, &Microcontroller::requestState);
|
||||
|
||||
connect(items, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem);
|
||||
connect(items, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem);
|
||||
|
||||
for(size_t i = 0; i < items->getItems()->size(); ++i)
|
||||
{
|
||||
ui->relayList->addItem(items->getItems()->at(i));
|
||||
}
|
||||
|
||||
connect(ui->relayList, &ItemScrollBox::deleteRequest, items, &ItemStore::removeItem);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
/*
|
||||
void MainWindow::showItemCreationDialog()
|
||||
{
|
||||
ItemCreationDialog diag(this);
|
||||
diag.show();
|
||||
if(diag.exec())
|
||||
{
|
||||
createdItem(diag.item);
|
||||
}
|
||||
}
|
||||
*/
|
46
src/ui/mainwindow.h
Normal file
46
src/ui/mainwindow.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QColorDialog>
|
||||
#include <QListWidgetItem>
|
||||
#include <QTime>
|
||||
#include <QShortcut>
|
||||
#include <vector>
|
||||
#include "../microcontroller.h"
|
||||
#include "../items/itemstore.h"
|
||||
|
||||
|
||||
class MainObject;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
QShortcut stopShort;
|
||||
|
||||
public:
|
||||
explicit MainWindow(Microcontroller * const micro, ItemStore* items, QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
Microcontroller *_micro;
|
||||
|
||||
signals:
|
||||
|
||||
void createdItem(std::shared_ptr<Item> item);
|
||||
|
||||
private slots:
|
||||
|
||||
//void showItemCreationDialog();
|
||||
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
129
src/ui/mainwindow.ui
Normal file
129
src/ui/mainwindow.ui
Normal file
@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>844</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>50</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>300</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Train Controller</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<normaloff>:/images/UVOSicon.bmp</normaloff>:/images/UVOSicon.bmp</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_10" stretch="0">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,0">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="ItemScrollBox" name="relayList" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_refesh">
|
||||
<property name="text">
|
||||
<string>Refesh</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_stop">
|
||||
<property name="text">
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_addItem">
|
||||
<property name="text">
|
||||
<string>Add Item</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ItemScrollBox</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>itemscrollbox.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
68
src/ui/relayscrollbox.ui
Normal file
68
src/ui/relayscrollbox.ui
Normal file
@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>RelayScrollBox</class>
|
||||
<widget class="QWidget" name="RelayScrollBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>388</width>
|
||||
<height>288</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="relayWidgetVbox"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
54
trainControllerUI.pro
Normal file
54
trainControllerUI.pro
Normal file
@ -0,0 +1,54 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2017-06-01T22:31:38
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui widgets network multimedia
|
||||
|
||||
QT += serialport
|
||||
|
||||
TARGET = traincontrollerui
|
||||
TEMPLATE = app
|
||||
|
||||
INCLUDEPATH += /usr/include/libnl3/
|
||||
|
||||
LIBS += -lnl-3 -lnl-genl-3
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which as been marked as deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
QMAKE_CXXFLAGS += -std=c++17 -O2
|
||||
|
||||
SOURCES += \
|
||||
src/items/train.cpp \
|
||||
src/mainobject.cpp \
|
||||
src/ui/itemwidget.cpp \
|
||||
src/ui/itemscrollbox.cpp \
|
||||
src/ui/mainwindow.cpp \
|
||||
src/items/item.cpp \
|
||||
src/items/itemstore.cpp\
|
||||
src/main.cpp \
|
||||
src/microcontroller.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/items/train.h \
|
||||
src/mainobject.h \
|
||||
src/ui/itemwidget.h \
|
||||
src/ui/itemscrollbox.h \
|
||||
src/ui/mainwindow.h \
|
||||
src/items/item.h \
|
||||
src/items/itemstore.h
|
||||
|
||||
HEADERS += \
|
||||
src/microcontroller.h \
|
||||
|
||||
INCLUDEPATH += src/ui/
|
||||
|
||||
FORMS += \
|
||||
src/ui/mainwindow.ui \
|
||||
src/ui/relayscrollbox.ui \
|
||||
src/ui/itemwidget.ui
|
Loading…
x
Reference in New Issue
Block a user