add support for turnouts
This commit is contained in:
@ -8,12 +8,14 @@ ItemStore::ItemStore(QObject *parent): QObject(parent)
|
|||||||
void ItemStore::addItem(std::shared_ptr<Item> item)
|
void ItemStore::addItem(std::shared_ptr<Item> item)
|
||||||
{
|
{
|
||||||
bool mached = false;
|
bool mached = false;
|
||||||
for(unsigned i = 0; i < items_.size(); i++ ) if(*items_[i] == *item) mached = true;
|
for(unsigned i = 0; i < items_.size(); i++ )
|
||||||
|
if(*items_[i] == *item) mached = true;
|
||||||
if(!mached)
|
if(!mached)
|
||||||
{
|
{
|
||||||
items_.push_back(std::shared_ptr<Item>(item));
|
items_.push_back(std::shared_ptr<Item>(item));
|
||||||
itemAdded(std::weak_ptr<Item>(items_.back()));
|
itemAdded(std::weak_ptr<Item>(items_.back()));
|
||||||
}
|
}
|
||||||
|
qDebug()<<"Got item: "<<item->id()<<" matched: "<<mached;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn)
|
void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn)
|
||||||
|
@ -14,19 +14,19 @@ void Train::setFunction(uint8_t funciton, bool value)
|
|||||||
{
|
{
|
||||||
Item::setFunction(funciton, value);
|
Item::setFunction(funciton, value);
|
||||||
if(micro)
|
if(micro)
|
||||||
micro->itemSetFunction(train_id_, funciton, value);
|
micro->trainSetFunction(train_id_, funciton, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Train::setValue(uint8_t value)
|
void Train::setValue(uint8_t value)
|
||||||
{
|
{
|
||||||
Item::setValue(value);
|
Item::setValue(value);
|
||||||
if(micro)
|
if(micro)
|
||||||
micro->itemSetSpeed(train_id_, value);
|
micro->trainSetSpeed(train_id_, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Train::reverse()
|
void Train::reverse()
|
||||||
{
|
{
|
||||||
if(micro)
|
if(micro)
|
||||||
micro->itemReverse(train_id_);
|
micro->trainReverse(train_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ public slots:
|
|||||||
void reverse();
|
void reverse();
|
||||||
virtual void setFunction(uint8_t function, bool on);
|
virtual void setFunction(uint8_t function, bool on);
|
||||||
virtual void setValue(uint8_t value);
|
virtual void setValue(uint8_t value);
|
||||||
|
uint8_t getTrainId(){return train_id_;}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRAIN_H
|
#endif // TRAIN_H
|
||||||
|
17
src/items/turnout.cpp
Normal file
17
src/items/turnout.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include "turnout.h"
|
||||||
|
|
||||||
|
Microcontroller *Turnout::micro = nullptr;
|
||||||
|
|
||||||
|
Turnout::Turnout(uint8_t id, uint8_t address, uint8_t subaddress)
|
||||||
|
: subaddress_(subaddress), turnoutId_(id)
|
||||||
|
{
|
||||||
|
itemId_ = address | (subaddress << 8);
|
||||||
|
name_ = QString("Turnout ")+QString::number(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Turnout::setValue(uint8_t value)
|
||||||
|
{
|
||||||
|
Item::setValue(value);
|
||||||
|
if(micro)
|
||||||
|
micro->tunoutSetDirection(turnoutId_, value);
|
||||||
|
}
|
19
src/items/turnout.h
Normal file
19
src/items/turnout.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef TURNOUT_H
|
||||||
|
#define TURNOUT_H
|
||||||
|
|
||||||
|
#include "item.h"
|
||||||
|
#include "../microcontroller.h"
|
||||||
|
|
||||||
|
class Turnout : public Item
|
||||||
|
{
|
||||||
|
uint8_t subaddress_;
|
||||||
|
uint8_t turnoutId_;
|
||||||
|
public:
|
||||||
|
static Microcontroller *micro;
|
||||||
|
|
||||||
|
explicit Turnout(uint8_t id = 0, uint8_t address = 0, uint8_t subaddress = 0);
|
||||||
|
virtual void setValue(uint8_t value);
|
||||||
|
uint8_t getTurnoutId(){return turnoutId_;}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TURNOUT_H
|
@ -11,6 +11,7 @@
|
|||||||
#include "ui/mainwindow.h"
|
#include "ui/mainwindow.h"
|
||||||
#include "items/itemstore.h"
|
#include "items/itemstore.h"
|
||||||
#include "items/train.h"
|
#include "items/train.h"
|
||||||
|
#include "items/turnout.h"
|
||||||
|
|
||||||
#define BAUD QSerialPort::Baud38400
|
#define BAUD QSerialPort::Baud38400
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ int main(int argc, char *argv[])
|
|||||||
micro.setPower(true);
|
micro.setPower(true);
|
||||||
|
|
||||||
Train::micro = µ
|
Train::micro = µ
|
||||||
|
Turnout::micro = µ
|
||||||
ItemStore items;
|
ItemStore items;
|
||||||
|
|
||||||
QObject::connect(µ, &Microcontroller::gotItemList, &items, &ItemStore::addItems);
|
QObject::connect(µ, &Microcontroller::gotItemList, &items, &ItemStore::addItems);
|
||||||
|
@ -3,8 +3,9 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include "items/train.h"
|
#include "items/train.h"
|
||||||
|
#include "items/turnout.h"
|
||||||
|
|
||||||
void Microcontroller::itemSetSpeed(uint8_t id, uint8_t speed)
|
void Microcontroller::trainSetSpeed(uint8_t id, uint8_t speed)
|
||||||
{
|
{
|
||||||
qDebug()<<__func__;
|
qDebug()<<__func__;
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
@ -12,20 +13,27 @@ void Microcontroller::itemSetSpeed(uint8_t id, uint8_t speed)
|
|||||||
write(ss.str().c_str());
|
write(ss.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::itemReverse(uint8_t id)
|
void Microcontroller::trainReverse(uint8_t id)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss<<"train "<<(unsigned)id<<" reverse\n";
|
ss<<"train "<<(unsigned)id<<" reverse\n";
|
||||||
write(ss.str().c_str());
|
write(ss.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::itemSetFunction(uint8_t id, uint8_t function, bool on)
|
void Microcontroller::trainSetFunction(uint8_t id, uint8_t function, bool on)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss<<"train "<<(unsigned)id<<" function "<<(unsigned)function<<' '<<(on ? "on" : "off")<<'\n';
|
ss<<"train "<<(unsigned)id<<" function "<<(unsigned)function<<' '<<(on ? "on" : "off")<<'\n';
|
||||||
write(ss.str().c_str());
|
write(ss.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Microcontroller::tunoutSetDirection(uint8_t id, bool direction)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss<<"turnout "<<(unsigned)id<<" set "<<(!direction ? "left" : "right")<<'\n';
|
||||||
|
write(ss.str().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
void Microcontroller::setPower(bool on)
|
void Microcontroller::setPower(bool on)
|
||||||
{
|
{
|
||||||
write(on ? "power on\n" : "power off\n");
|
write(on ? "power on\n" : "power off\n");
|
||||||
@ -68,6 +76,7 @@ bool Microcontroller::connected()
|
|||||||
void Microcontroller::requestState()
|
void Microcontroller::requestState()
|
||||||
{
|
{
|
||||||
write("train list\n");
|
write("train list\n");
|
||||||
|
write("turnout list\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
//housekeeping
|
//housekeeping
|
||||||
@ -94,19 +103,34 @@ void Microcontroller::setIODevice(QIODevice *port)
|
|||||||
std::shared_ptr<Item> Microcontroller::processTrainLine(const QString& buffer)
|
std::shared_ptr<Item> Microcontroller::processTrainLine(const QString& buffer)
|
||||||
{
|
{
|
||||||
QStringList bufferList = buffer.split(' ');
|
QStringList bufferList = buffer.split(' ');
|
||||||
if(bufferList.size() >= 9 && buffer.startsWith("NUMBER:"))
|
if(bufferList.size() >= 13 && buffer.startsWith("NUMBER:"))
|
||||||
{
|
{
|
||||||
return std::shared_ptr<Item>(new Train(bufferList[1].toInt(), bufferList[3].toInt(), bufferList[12].toInt()));
|
return std::shared_ptr<Item>(new Train(bufferList[1].toInt(), bufferList[3].toInt(), bufferList[12].toInt()));
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Item> Microcontroller::processTurnoutLine(const QString& buffer)
|
||||||
|
{
|
||||||
|
qDebug()<<__func__<<" :"<<buffer;
|
||||||
|
QStringList bufferList = buffer.split(' ');
|
||||||
|
if(bufferList.size() >= 6 && buffer.startsWith("NUMBER:"))
|
||||||
|
{
|
||||||
|
return std::shared_ptr<Item>(new Turnout(bufferList[1].toInt(), bufferList[5].toInt()));
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void Microcontroller::processList(const QString& buffer)
|
void Microcontroller::processList(const QString& buffer)
|
||||||
{
|
{
|
||||||
QStringList bufferList = buffer.split(' ');
|
QStringList bufferList = buffer.split(' ');
|
||||||
if(bufferList.size() >= 13 && buffer.startsWith("NUMBER:"))
|
qDebug()<<__func__<<" :"<<buffer<<" list mode: "<<listMode;
|
||||||
|
if(bufferList.size() >= 10 && buffer.startsWith("NUMBER:"))
|
||||||
{
|
{
|
||||||
itemList.push_back(processTrainLine(buffer));
|
if(listMode == TRAIN_LIST)
|
||||||
|
itemList.push_back(processTrainLine(buffer));
|
||||||
|
else if(listMode == TURNOUT_LIST)
|
||||||
|
itemList.push_back(processTurnoutLine(buffer));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -134,9 +158,13 @@ void Microcontroller::processMicroReturn()
|
|||||||
{
|
{
|
||||||
if(_buffer.startsWith("Trains:"))
|
if(_buffer.startsWith("Trains:"))
|
||||||
{
|
{
|
||||||
listMode = true;
|
listMode = TRAIN_LIST;
|
||||||
itemList.clear();
|
itemList.clear();
|
||||||
}
|
}
|
||||||
|
else if(_buffer.startsWith("Turnouts:"))
|
||||||
|
{
|
||||||
|
listMode = TURNOUT_LIST;
|
||||||
|
}
|
||||||
else if(_buffer.startsWith("NUMBER:"))
|
else if(_buffer.startsWith("NUMBER:"))
|
||||||
{
|
{
|
||||||
processItemState(_buffer);
|
processItemState(_buffer);
|
||||||
|
@ -30,7 +30,10 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool listMode = false;
|
static constexpr int TRAIN_LIST = 1;
|
||||||
|
static constexpr int TURNOUT_LIST = 2;
|
||||||
|
|
||||||
|
int listMode = 0;
|
||||||
|
|
||||||
//uint8_t _auxState = 0;
|
//uint8_t _auxState = 0;
|
||||||
|
|
||||||
@ -45,6 +48,7 @@ private:
|
|||||||
void processList(const QString& buffer);
|
void processList(const QString& buffer);
|
||||||
void processItemState(const QString& buffer);
|
void processItemState(const QString& buffer);
|
||||||
std::shared_ptr<Item> processTrainLine(const QString& buffer);
|
std::shared_ptr<Item> processTrainLine(const QString& buffer);
|
||||||
|
std::shared_ptr<Item> processTurnoutLine(const QString& buffer);
|
||||||
|
|
||||||
void write(char *buffer, const size_t length);
|
void write(char *buffer, const size_t length);
|
||||||
void write(const QByteArray& buffer);
|
void write(const QByteArray& buffer);
|
||||||
@ -59,9 +63,10 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void requestState();
|
void requestState();
|
||||||
|
|
||||||
void itemSetSpeed(uint8_t id, uint8_t speed);
|
void trainSetSpeed(uint8_t id, uint8_t speed);
|
||||||
void itemReverse(uint8_t id);
|
void trainReverse(uint8_t id);
|
||||||
void itemSetFunction(uint8_t id, uint8_t function, bool on);
|
void trainSetFunction(uint8_t id, uint8_t function, bool on);
|
||||||
|
void tunoutSetDirection(uint8_t id, bool direction);
|
||||||
void estop();
|
void estop();
|
||||||
void setPower(bool on);
|
void setPower(bool on);
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#include "itemscrollbox.h"
|
#include "itemscrollbox.h"
|
||||||
#include "ui_relayscrollbox.h"
|
#include "ui_relayscrollbox.h"
|
||||||
|
#include "ui_relayscrollbox.h"
|
||||||
|
#include "../items/train.h"
|
||||||
|
#include "../items/turnout.h"
|
||||||
|
|
||||||
ItemScrollBox::ItemScrollBox(QWidget *parent) :
|
ItemScrollBox::ItemScrollBox(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
@ -17,24 +20,40 @@ ItemScrollBox::~ItemScrollBox()
|
|||||||
|
|
||||||
void ItemScrollBox::addItem(std::weak_ptr<Item> item)
|
void ItemScrollBox::addItem(std::weak_ptr<Item> item)
|
||||||
{
|
{
|
||||||
static int lifetimeNum = 0;
|
|
||||||
if(auto workItem = item.lock())
|
if(auto workItem = item.lock())
|
||||||
{
|
{
|
||||||
widgets_.push_back(new ItemWidget(item, this));
|
widgets_.push_back(new ItemWidget(item, this));
|
||||||
if(lifetimeNum == 0)
|
Train* train = dynamic_cast<Train*>(workItem.get());
|
||||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_Q), QKeySequence(Qt::Key_A), QKeySequence(Qt::Key_Z));
|
Turnout* turnout = dynamic_cast<Turnout*>(workItem.get());
|
||||||
else if(lifetimeNum == 1)
|
if(train)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_W), QKeySequence(Qt::Key_S), QKeySequence(Qt::Key_X));
|
{
|
||||||
else if(lifetimeNum == 2)
|
if(train->getTrainId() == 0)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_E), QKeySequence(Qt::Key_D), QKeySequence(Qt::Key_C));
|
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_Q), QKeySequence(Qt::Key_A), QKeySequence(Qt::Key_Z));
|
||||||
else if(lifetimeNum == 3)
|
else if(train->getTrainId() == 1)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_R), QKeySequence(Qt::Key_F), QKeySequence(Qt::Key_V));
|
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_W), QKeySequence(Qt::Key_S), QKeySequence(Qt::Key_X));
|
||||||
else if(lifetimeNum == 4)
|
else if(train->getTrainId() == 2)
|
||||||
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_T), QKeySequence(Qt::Key_G), QKeySequence(Qt::Key_B));
|
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_E), QKeySequence(Qt::Key_D), QKeySequence(Qt::Key_C));
|
||||||
|
else if(train->getTrainId() == 3)
|
||||||
|
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_R), QKeySequence(Qt::Key_F), QKeySequence(Qt::Key_V));
|
||||||
|
else if(train->getTrainId() == 4)
|
||||||
|
widgets_.back()->setShortcuts(QKeySequence(Qt::Key_T), QKeySequence(Qt::Key_G), QKeySequence(Qt::Key_B));
|
||||||
|
}
|
||||||
|
else if(turnout)
|
||||||
|
{
|
||||||
|
if(turnout->getTurnoutId() == 0)
|
||||||
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_1));
|
||||||
|
else if(turnout->getTurnoutId() == 1)
|
||||||
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_2));
|
||||||
|
else if(turnout->getTurnoutId() == 2)
|
||||||
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_3));
|
||||||
|
else if(turnout->getTurnoutId() == 3)
|
||||||
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_4));
|
||||||
|
else if(turnout->getTurnoutId() == 4)
|
||||||
|
widgets_.back()->setShortcuts(QKeySequence(), QKeySequence(), QKeySequence(Qt::Key_5));
|
||||||
|
}
|
||||||
ui->relayWidgetVbox->addWidget(widgets_.back());
|
ui->relayWidgetVbox->addWidget(widgets_.back());
|
||||||
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest);
|
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest);
|
||||||
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem);
|
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem);
|
||||||
lifetimeNum++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
#include "../items/train.h"
|
#include "../items/train.h"
|
||||||
|
#include "../items/turnout.h"
|
||||||
|
|
||||||
ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
|
ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
@ -23,14 +24,29 @@ ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
|
|||||||
connect(ui->checkBox_f3, &QCheckBox::stateChanged, this, &ItemWidget::f3);
|
connect(ui->checkBox_f3, &QCheckBox::stateChanged, this, &ItemWidget::f3);
|
||||||
connect(ui->checkBox_f4, &QCheckBox::stateChanged, this, &ItemWidget::f4);
|
connect(ui->checkBox_f4, &QCheckBox::stateChanged, this, &ItemWidget::f4);
|
||||||
connect(ui->pushButton_reverse, &QPushButton::clicked, this, &ItemWidget::reverse);
|
connect(ui->pushButton_reverse, &QPushButton::clicked, this, &ItemWidget::reverse);
|
||||||
|
connect(ui->radioButton_left, &QRadioButton::clicked, this, [this](){moveToValue(0);});
|
||||||
|
connect(ui->radioButton_right, &QRadioButton::clicked, this, [this](){moveToValue(1);});
|
||||||
|
|
||||||
Train* train = dynamic_cast<Train*>(workingRelay.get());
|
Train* train = dynamic_cast<Train*>(workingRelay.get());
|
||||||
if(!train)
|
Turnout* turnout = dynamic_cast<Turnout*>(workingRelay.get());
|
||||||
{
|
|
||||||
|
if(turnout)
|
||||||
|
{
|
||||||
|
ui->checkBox_f1->hide();
|
||||||
|
ui->checkBox_f2->hide();
|
||||||
|
ui->checkBox_f3->hide();
|
||||||
|
ui->checkBox_f4->hide();
|
||||||
|
ui->slider->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!train)
|
||||||
|
{
|
||||||
ui->pushButton_reverse->hide();
|
ui->pushButton_reverse->hide();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
ui->radioButton_left->hide();
|
||||||
|
ui->radioButton_right->hide();
|
||||||
uint8_t functionMask = train->getFunctionMask();
|
uint8_t functionMask = train->getFunctionMask();
|
||||||
if(!(functionMask & (1 << 0)))
|
if(!(functionMask & (1 << 0)))
|
||||||
ui->checkBox_f1->hide();
|
ui->checkBox_f1->hide();
|
||||||
@ -40,8 +56,7 @@ ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
|
|||||||
ui->checkBox_f3->hide();
|
ui->checkBox_f3->hide();
|
||||||
if(!(functionMask & (1 << 3)))
|
if(!(functionMask & (1 << 3)))
|
||||||
ui->checkBox_f4->hide();
|
ui->checkBox_f4->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else disable();
|
else disable();
|
||||||
}
|
}
|
||||||
@ -56,11 +71,21 @@ void ItemWidget::deleteItem()
|
|||||||
|
|
||||||
void ItemWidget::moveToValue(int value)
|
void ItemWidget::moveToValue(int value)
|
||||||
{
|
{
|
||||||
qDebug()<<__func__;
|
ui->slider->blockSignals(true);
|
||||||
|
ui->radioButton_left->blockSignals(true);
|
||||||
|
ui->radioButton_right->blockSignals(true);
|
||||||
|
|
||||||
ui->pushButton_reverse->setDisabled(value != 0);
|
ui->pushButton_reverse->setDisabled(value != 0);
|
||||||
|
ui->slider->setValue(value);
|
||||||
|
ui->radioButton_left->setChecked(!value);
|
||||||
|
ui->radioButton_right->setChecked(value);
|
||||||
if(auto workingItem = item_.lock())
|
if(auto workingItem = item_.lock())
|
||||||
workingItem->setValue(value);
|
workingItem->setValue(value);
|
||||||
else disable();
|
else disable();
|
||||||
|
|
||||||
|
ui->slider->blockSignals(false);
|
||||||
|
ui->radioButton_left->blockSignals(false);
|
||||||
|
ui->radioButton_right->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::f1(int value)
|
void ItemWidget::f1(int value)
|
||||||
@ -97,10 +122,13 @@ void ItemWidget::reverse()
|
|||||||
if(auto workingItem = item_.lock())
|
if(auto workingItem = item_.lock())
|
||||||
{
|
{
|
||||||
Train* train = dynamic_cast<Train*>(workingItem.get());
|
Train* train = dynamic_cast<Train*>(workingItem.get());
|
||||||
if(train && ui->slider->value() == 0)
|
if(train && workingItem->getValue() == 0)
|
||||||
train->reverse();
|
train->reverse();
|
||||||
else
|
else
|
||||||
ui->slider->setValue(0);
|
{
|
||||||
|
qDebug()<<"!((bool)workingItem->getValue()) "<<!((bool)workingItem->getValue());
|
||||||
|
moveToValue(!((bool)workingItem->getValue()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else disable();
|
else disable();
|
||||||
}
|
}
|
||||||
@ -130,14 +158,17 @@ bool ItemWidget::controles(const ItemData& relay)
|
|||||||
|
|
||||||
void ItemWidget::stepUp()
|
void ItemWidget::stepUp()
|
||||||
{
|
{
|
||||||
ui->slider->setValue(ui->slider->value()+1);
|
moveToValue(ui->slider->value()+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::stepDown()
|
void ItemWidget::stepDown()
|
||||||
{
|
{
|
||||||
if(ui->slider->value() == 0)
|
if(ui->slider->value() == 0)
|
||||||
|
{
|
||||||
moveToValue(0);
|
moveToValue(0);
|
||||||
ui->slider->setValue(ui->slider->value()-1);
|
return;
|
||||||
|
}
|
||||||
|
moveToValue(ui->slider->value()-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::setShortcuts(QKeySequence up, QKeySequence down, QKeySequence rev)
|
void ItemWidget::setShortcuts(QKeySequence up, QKeySequence down, QKeySequence rev)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>264</width>
|
<width>280</width>
|
||||||
<height>83</height>
|
<height>83</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -67,6 +67,23 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="radioButton_left">
|
||||||
|
<property name="text">
|
||||||
|
<string>Left</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="radioButton_right">
|
||||||
|
<property name="text">
|
||||||
|
<string>Right</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_reverse">
|
<widget class="QPushButton" name="pushButton_reverse">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -4,9 +4,7 @@
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------
|
#-------------------------------------------------
|
||||||
|
|
||||||
QT += core gui widgets network multimedia
|
QT += core gui widgets network serialport
|
||||||
|
|
||||||
QT += serialport
|
|
||||||
|
|
||||||
TARGET = traincontrollerui
|
TARGET = traincontrollerui
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
@ -25,6 +23,7 @@ QMAKE_CXXFLAGS += -std=c++17 -O2
|
|||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
src/items/train.cpp \
|
src/items/train.cpp \
|
||||||
|
src/items/turnout.cpp \
|
||||||
src/mainobject.cpp \
|
src/mainobject.cpp \
|
||||||
src/ui/itemwidget.cpp \
|
src/ui/itemwidget.cpp \
|
||||||
src/ui/itemscrollbox.cpp \
|
src/ui/itemscrollbox.cpp \
|
||||||
@ -36,6 +35,7 @@ SOURCES += \
|
|||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/items/train.h \
|
src/items/train.h \
|
||||||
|
src/items/turnout.h \
|
||||||
src/mainobject.h \
|
src/mainobject.h \
|
||||||
src/ui/itemwidget.h \
|
src/ui/itemwidget.h \
|
||||||
src/ui/itemscrollbox.h \
|
src/ui/itemscrollbox.h \
|
||||||
|
Reference in New Issue
Block a user