Added system item support, support for RGBControlers with multiple item backends, and item settings widgets
This commit is contained in:
@ -4,7 +4,7 @@
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui widgets network
|
||||
QT += core gui widgets network multimedia
|
||||
|
||||
QT += serialport
|
||||
|
||||
@ -29,6 +29,7 @@ SOURCES += \
|
||||
src/broadcast.cpp \
|
||||
src/iomuliplexer.cpp \
|
||||
src/items/messageitem.cpp \
|
||||
src/items/systemitem.cpp \
|
||||
src/ui/actorwidgets/factoractorwidget.cpp \
|
||||
src/ui/itemcreationdialog.cpp \
|
||||
src/ui/itemsettingswidgets/messageitemsettingswidget.cpp \
|
||||
@ -38,6 +39,8 @@ SOURCES += \
|
||||
src/ui/actorwidgets/sensoractorwidget.cpp \
|
||||
src/ui/actorwidgets/alarmwidget.cpp \
|
||||
src/ui/actorwidgets/timeractorwidget.cpp \
|
||||
src/ui/itemsettingswidgets/relayitemsettingswidget.cpp \
|
||||
src/ui/itemsettingswidgets/systemitemsettingswidget.cpp \
|
||||
src/ui/itemwidget.cpp \
|
||||
src/ui/itemsettingsdialog.cpp \
|
||||
src/ui/itemscrollbox.cpp \
|
||||
@ -82,6 +85,7 @@ HEADERS += \
|
||||
src/broadcast.h \
|
||||
src/iomuliplexer.h \
|
||||
src/items/messageitem.h \
|
||||
src/items/systemitem.h \
|
||||
src/ui/actorwidgets/factoractorwidget.h \
|
||||
src/ui/itemcreationdialog.h \
|
||||
src/ui/itemsettingswidgets/messageitemsettingswidget.h \
|
||||
@ -91,6 +95,8 @@ HEADERS += \
|
||||
src/ui/actorwidgets/polynomalactorwidget.h \
|
||||
src/ui/actorwidgets/sensoractorwidget.h \
|
||||
src/ui/actorwidgets/timeractorwidget.h \
|
||||
src/ui/itemsettingswidgets/relayitemsettingswidget.h \
|
||||
src/ui/itemsettingswidgets/systemitemsettingswidget.h \
|
||||
src/ui/itemwidget.h \
|
||||
src/ui/itemsettingsdialog.h \
|
||||
src/ui/itemscrollbox.h \
|
||||
@ -133,6 +139,8 @@ FORMS += \
|
||||
src/ui/itemsettingswidgets/messageitemsettingswidget.ui \
|
||||
src/ui/actorsettingsdialog.ui \
|
||||
src/ui/actorwidgets/polynomalactorwidget.ui \
|
||||
src/ui/itemsettingswidgets/relayitemsettingswidget.ui \
|
||||
src/ui/itemsettingswidgets/systemitemsettingswidget.ui \
|
||||
src/ui/mainwindow.ui \
|
||||
src/ui/relayscrollbox.ui \
|
||||
src/ui/actorwidgets/sensoractorwidget.ui \
|
||||
|
@ -91,23 +91,23 @@ void Actor::onValueChanged(uint8_t value)
|
||||
|
||||
}
|
||||
|
||||
Actor* Actor::createActor(const QString& type)
|
||||
std::shared_ptr<Actor> Actor::createActor(const QString& type)
|
||||
{
|
||||
Actor* actor = nullptr;
|
||||
if(type == "Alarm") actor = new AlarmTime();
|
||||
else if(type == "Sensor") actor = new SensorActor();
|
||||
else if(type == "Timer") actor = new TimerActor();
|
||||
else if(type == "Regulator") actor = new Regulator();
|
||||
else if(type == "Polynomal") actor = new PolynomalActor();
|
||||
else if(type == "MultiFactor") actor = new MultiFactorActor();
|
||||
else if(type == "Actor") actor = new Actor();
|
||||
std::shared_ptr<Actor> actor;
|
||||
if(type == "Alarm") actor = std::shared_ptr<Actor>(new AlarmTime());
|
||||
else if(type == "Sensor") actor = std::shared_ptr<Actor>(new SensorActor());
|
||||
else if(type == "Timer") actor = std::shared_ptr<Actor>(new TimerActor());
|
||||
else if(type == "Regulator") actor = std::shared_ptr<Actor>(new Regulator());
|
||||
else if(type == "Polynomal") actor = std::shared_ptr<Actor>(new PolynomalActor());
|
||||
else if(type == "MultiFactor") actor = std::shared_ptr<Actor>(new MultiFactorActor());
|
||||
else if(type == "Actor") actor = std::shared_ptr<Actor>(new Actor());
|
||||
return actor;
|
||||
}
|
||||
|
||||
Actor* Actor::loadActor(const QJsonObject &json)
|
||||
std::shared_ptr<Actor> Actor::loadActor(const QJsonObject &json)
|
||||
{
|
||||
QString type = json["Type"].toString("Actor");
|
||||
Actor* actor = createActor(type);
|
||||
std::shared_ptr<Actor> actor = createActor(type);
|
||||
if(actor) actor->load(json);
|
||||
return actor;
|
||||
}
|
||||
|
@ -44,11 +44,11 @@ public:
|
||||
|
||||
uint8_t getTriggerValue();
|
||||
|
||||
static Actor* createActor(const QString& type);
|
||||
static std::shared_ptr<Actor> createActor(const QString& type);
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||
static Actor* loadActor(const QJsonObject& json);
|
||||
static std::shared_ptr<Actor> loadActor(const QJsonObject& json);
|
||||
};
|
||||
|
||||
#endif // ACTOR_H
|
||||
|
@ -18,8 +18,6 @@ void AlarmTime::run()
|
||||
|
||||
active = true;
|
||||
timer.start();
|
||||
|
||||
qDebug()<<"Start Alarm Time Manager\n";
|
||||
}
|
||||
|
||||
void AlarmTime::makeActive()
|
||||
@ -64,6 +62,7 @@ QString AlarmTime::getName() const
|
||||
void AlarmTime::setRepeat(const uint8_t repeat)
|
||||
{
|
||||
repeat_=repeat;
|
||||
exausted = false;
|
||||
}
|
||||
|
||||
uint8_t AlarmTime::getRepeat()
|
||||
@ -112,6 +111,7 @@ void AlarmTime::doTick()
|
||||
void AlarmTime::changeTime(const QDateTime& time)
|
||||
{
|
||||
time_=time;
|
||||
exausted = false;
|
||||
qDebug()<<"time: "<<time_;
|
||||
}
|
||||
|
||||
|
@ -42,11 +42,10 @@ QString MultiFactorActor::getName() const
|
||||
}
|
||||
}
|
||||
|
||||
void MultiFactorActor::setFactorActor(Actor* factorActor)
|
||||
void MultiFactorActor::setFactorActor(std::shared_ptr<Actor> factorActor)
|
||||
{
|
||||
if(factorActor_) delete factorActor_;
|
||||
factorActor_=factorActor;
|
||||
connect(factorActor_, &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||
connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||
}
|
||||
|
||||
void MultiFactorActor::store(QJsonObject &json)
|
||||
@ -73,7 +72,7 @@ void MultiFactorActor::load(const QJsonObject &json, bool preserve)
|
||||
}
|
||||
if(factorActor_)
|
||||
{
|
||||
connect(factorActor_, &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||
connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ class MultiFactorActor: public Actor
|
||||
{
|
||||
private:
|
||||
|
||||
Actor* factorActor_;
|
||||
std::shared_ptr<Actor> factorActor_;
|
||||
QDateTime activationTime;
|
||||
uint preCancleMin_;
|
||||
|
||||
@ -28,8 +28,8 @@ public:
|
||||
|
||||
virtual QString getName() const;
|
||||
|
||||
void setFactorActor(Actor* factorActor);
|
||||
Actor* getFactorActor(){return factorActor_;}
|
||||
void setFactorActor(std::shared_ptr<Actor> factorActor);
|
||||
std::shared_ptr<Actor> getFactorActor(){return factorActor_;}
|
||||
void setFactorDirection(const bool direction){factorDirection = direction;}
|
||||
bool getFactorDirection(){return factorDirection;}
|
||||
uint getPreCancleTime(){return preCancleMin_;}
|
||||
|
@ -76,7 +76,7 @@ QString PolynomalActor::getName() const
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = QString::number(pow3_) + "x^2 + " + QString::number(pow2_) + "x^2 + " + QString::number(pow1_) + "x + " + QString::number(pow0_) + " (x: " + sensor_.name + ")";
|
||||
string = QString::number(pow3_) + "x^3 + " + QString::number(pow2_) + "x^2 + " + QString::number(pow1_) + "x + " + QString::number(pow0_) + " (x: " + sensor_.name + ")";
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ void Regulator::sensorEvent(Sensor sensor)
|
||||
{
|
||||
if(active && sensor == sensor_)
|
||||
{
|
||||
qDebug()<<"got sensor: "<<sensor.type<<" "<<sensor.id<<" want: "<<sensor_.type<<" "<<sensor_.id;
|
||||
if( sensor.field < setPoint_-band_ && (sensor.field < sensor_.field || sensor_.field > setPoint_-band_ || first) )
|
||||
{
|
||||
sigValue(triggerValue);
|
||||
|
@ -21,7 +21,6 @@ void SensorActor::sensorEvent(Sensor sensor)
|
||||
{
|
||||
if(sensor == sensor_)
|
||||
{
|
||||
qDebug()<<"got sensor: "<<sensor.type<<" "<<sensor.id<<" want: "<<sensor_.type<<" "<<sensor_.id;
|
||||
if((sloap_ == SLOPE_UP || sloap_ == SLOPE_BOTH) && sensor_.field < threshold_ && sensor.field >= threshold_ ) performAction();
|
||||
else if((sloap_ == SLOPE_DOWN || sloap_ == SLOPE_BOTH) && sensor_.field > threshold_ && sensor.field <= threshold_) performAction();
|
||||
sensor_ = sensor;
|
||||
|
@ -39,46 +39,63 @@ void BroadCast::sendJson(const QJsonObject& json)
|
||||
write(buffer);
|
||||
}
|
||||
|
||||
void BroadCast::sendSensors()
|
||||
{
|
||||
if(iodevice_)for(auto& sensor: *globalSensors.getSensors())
|
||||
{
|
||||
iodevice_->write("bcst: "+sensor.toString().toLatin1()+'\n');
|
||||
}
|
||||
}
|
||||
|
||||
void BroadCast::requestSensors()
|
||||
{
|
||||
if(iodevice_)iodevice_->write("bcst: GETSENSORS\n");
|
||||
}
|
||||
|
||||
void BroadCast::requestJson()
|
||||
{
|
||||
if(iodevice_)iodevice_->write("bcst: GETJSN\n");
|
||||
}
|
||||
|
||||
void BroadCast::decodeMaster()
|
||||
void BroadCast::decodeMaster(const QByteArray& buffer)
|
||||
{
|
||||
if(buffer_.size() >= 6 && buffer_[0] == 'G' && buffer_[1] == 'E' && buffer_[2] == 'T' && buffer_[3] == 'J' && buffer_[4] == 'S' && buffer_[5] == 'N')
|
||||
if(buffer.startsWith("GETJSN"))
|
||||
{
|
||||
qDebug()<<"json requested";
|
||||
jsonRequested();
|
||||
}
|
||||
else if(buffer.startsWith("GETSENSORS") )
|
||||
{
|
||||
qDebug()<<"sensors requested";
|
||||
sendSensors();
|
||||
}
|
||||
}
|
||||
|
||||
void BroadCast::decode()
|
||||
void BroadCast::decode(QByteArray buffer)
|
||||
{
|
||||
if(buffer_.size() >= 6 && buffer_[0] == 'J' && buffer_[1] == 'S' && buffer_[2] == 'O' && buffer_[3] == 'N' && buffer_[4] == ':')
|
||||
qDebug()<<"decodeing: "<<buffer;
|
||||
if(buffer.size() >= 6 && buffer[0] == 'J' && buffer[1] == 'S' && buffer[2] == 'O' && buffer[3] == 'N' && buffer[4] == ':')
|
||||
{
|
||||
qDebug()<<"got json";
|
||||
buffer_.remove(0,6);
|
||||
for(int i = 0; i < buffer_.size()-1; ++i)
|
||||
buffer.remove(0,6);
|
||||
for(int i = 0; i < buffer.size()-1; ++i)
|
||||
{
|
||||
if( buffer_[i] == '\\' && buffer_[i+1] == 'n' )
|
||||
if( buffer[i] == '\\' && buffer[i+1] == 'n' )
|
||||
{
|
||||
buffer_[i] = '\n';
|
||||
buffer_.remove(i+1,1);
|
||||
buffer[i] = '\n';
|
||||
buffer.remove(i+1,1);
|
||||
}
|
||||
else if( buffer_[i] == '\\' && buffer_[i+1] == '0' )
|
||||
else if( buffer[i] == '\\' && buffer[i+1] == '0' )
|
||||
{
|
||||
buffer_[i] = '\0';
|
||||
buffer_.remove(i+1,1);
|
||||
buffer[i] = '\0';
|
||||
buffer.remove(i+1,1);
|
||||
}
|
||||
}
|
||||
|
||||
QJsonParseError error;
|
||||
QJsonDocument document = QJsonDocument::fromJson(buffer_, &error);
|
||||
QJsonDocument document = QJsonDocument::fromJson(buffer, &error);
|
||||
|
||||
qDebug()<<"orig json:";
|
||||
qDebug()<<buffer_.data();
|
||||
qDebug()<<"after parse:";
|
||||
qDebug()<<"JSON:";
|
||||
qDebug()<<document.toJson().data();
|
||||
QJsonObject jsonObject = document.object();
|
||||
if(error.error == QJsonParseError::NoError && !document.isEmpty() && !jsonObject.isEmpty()) gotJson(jsonObject);
|
||||
@ -87,9 +104,9 @@ void BroadCast::decode()
|
||||
qDebug()<<error.errorString();
|
||||
}
|
||||
}
|
||||
else if(buffer_.size() >= 6 && buffer_[0] == 'S' && buffer_[1] == 'E' && buffer_[2] == 'N' && buffer_[3] == 'S' && buffer_[4] == 'O' && buffer_[5] == 'R')
|
||||
else if(buffer.size() >= 6 && buffer[0] == 'S' && buffer[1] == 'E' && buffer[2] == 'N' && buffer[3] == 'S' && buffer[4] == 'O' && buffer[5] == 'R')
|
||||
{
|
||||
Sensor sensor = Sensor::sensorFromString(buffer_);
|
||||
Sensor sensor = Sensor::sensorFromString(buffer);
|
||||
if(sensor.type != Sensor::TYPE_DUMMY) gotSensorState(sensor);
|
||||
}
|
||||
}
|
||||
@ -102,19 +119,16 @@ void BroadCast::sendMessage(const QString &title, const QString &body)
|
||||
void BroadCast::readyRead()
|
||||
{
|
||||
buffer_.append(iodevice_->readAll());
|
||||
if(buffer_.size() >= 6)
|
||||
int newlineIndex = buffer_.indexOf('\n');
|
||||
while( newlineIndex != -1 )
|
||||
{
|
||||
if(buffer_[0] == 'b' && buffer_[1] == 'c' && buffer_[2] == 's' && buffer_[3] == 't' && buffer_[4] == ':')
|
||||
if(buffer_.startsWith("bcst: "))
|
||||
{
|
||||
if(buffer_.contains('\n'))
|
||||
{
|
||||
buffer_.remove(0,6);
|
||||
decode();
|
||||
if(master_)decodeMaster();
|
||||
buffer_.clear();
|
||||
QByteArray tmp = buffer_.mid(6,newlineIndex-6);
|
||||
decode(tmp);
|
||||
if(master_)decodeMaster(tmp);
|
||||
}
|
||||
buffer_.remove(0, newlineIndex+1);
|
||||
newlineIndex = buffer_.indexOf('\n');
|
||||
}
|
||||
}
|
||||
else buffer_.clear();
|
||||
}
|
||||
else if(buffer_.contains('\n')) buffer_.clear();
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ private:
|
||||
void write(const char * const buffer, const size_t length);
|
||||
void write(const QByteArray& buffer);
|
||||
|
||||
void decode();
|
||||
void decodeMaster();
|
||||
void decode(QByteArray buffer);
|
||||
void decodeMaster(const QByteArray& buffer);
|
||||
|
||||
private slots:
|
||||
|
||||
@ -34,6 +34,7 @@ private slots:
|
||||
public slots:
|
||||
|
||||
void requestJson();
|
||||
void requestSensors();
|
||||
|
||||
signals:
|
||||
|
||||
@ -45,6 +46,7 @@ public:
|
||||
|
||||
BroadCast(QIODevice* const iodevice = nullptr, bool master = true);
|
||||
void sendJson(const QJsonObject& json);
|
||||
void sendSensors();
|
||||
void sendMessage(const QString& title, const QString& body);
|
||||
|
||||
};
|
||||
|
@ -50,13 +50,13 @@ Item::Item(const ItemData& itemData, QObject *parent): QObject(parent), ItemDat
|
||||
|
||||
Item::~Item()
|
||||
{
|
||||
for(size_t i = 0; i < actors_.size(); i++) delete actors_[i];
|
||||
}
|
||||
|
||||
void Item::store(QJsonObject &json)
|
||||
{
|
||||
json["Name"] = name_;
|
||||
json["ItemId"] = static_cast<double>(itemId_);
|
||||
json["override"] = override_;
|
||||
QJsonArray actorsArray;
|
||||
for(size_t i = 0; i < actors_.size(); ++i)
|
||||
{
|
||||
@ -77,17 +77,23 @@ void Item::load(const QJsonObject &json, const bool preserve)
|
||||
name_ = json["Name"].toString(name_);
|
||||
itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
|
||||
}
|
||||
override_ = json["override"].toBool(false);
|
||||
const QJsonArray actorsArray(json["Actors"].toArray(QJsonArray()));
|
||||
for(int i = 0; i < actorsArray.size(); ++i)
|
||||
{
|
||||
if(actorsArray[i].isObject())
|
||||
{
|
||||
Actor* actor = Actor::loadActor(actorsArray[i].toObject());
|
||||
std::shared_ptr<Actor> actor = Actor::loadActor(actorsArray[i].toObject());
|
||||
if(actor != nullptr) addActor(actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Item::actorSetValue(uint8_t value)
|
||||
{
|
||||
if(!override_) setValue(value);
|
||||
}
|
||||
|
||||
void Item::setValue(uint8_t value)
|
||||
{
|
||||
value_ = value;
|
||||
@ -99,34 +105,32 @@ void Item::informValue(uint8_t value)
|
||||
Item::setValue(value);
|
||||
}
|
||||
|
||||
void Item::addActor(Actor* actor)
|
||||
void Item::addActor(std::shared_ptr<Actor> actor)
|
||||
{
|
||||
actor->setParent(this);
|
||||
actors_.push_back(actor);
|
||||
if(!secondaryFlag)
|
||||
{
|
||||
qDebug()<<"connecting actor";
|
||||
connect(actor, &Actor::sigValue, this, &Item::setValue);
|
||||
connect(actor.get(), &Actor::sigValue, this, &Item::actorSetValue);
|
||||
}
|
||||
connect(this, &Item::valueChanged, actor, &Actor::onValueChanged);
|
||||
connect(this, &Item::valueChanged, actor.get(), &Actor::onValueChanged);
|
||||
|
||||
SensorActor* sensorActor = dynamic_cast<SensorActor*>(actor);
|
||||
if(sensorActor != nullptr )connect(&globalSensors, &SensorStore::sensorChangedState, sensorActor, &SensorActor::sensorEvent);
|
||||
std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
|
||||
if(sensorActor)connect(&globalSensors, &SensorStore::sensorChangedState, sensorActor.get(), &SensorActor::sensorEvent);
|
||||
|
||||
Regulator* regulator = dynamic_cast<Regulator*>(actor);
|
||||
if(regulator != nullptr )connect(&globalSensors, &SensorStore::sensorChangedState, regulator, &Regulator::sensorEvent);
|
||||
std::shared_ptr<Regulator> regulator = std::dynamic_pointer_cast<Regulator>(actor);
|
||||
if(regulator)connect(&globalSensors, &SensorStore::sensorChangedState, regulator.get(), &Regulator::sensorEvent);
|
||||
|
||||
PolynomalActor* polynomalActor = dynamic_cast<PolynomalActor*>(actor);
|
||||
if(polynomalActor != nullptr )connect(&globalSensors, &SensorStore::sensorChangedState, polynomalActor, &PolynomalActor::sensorEvent);
|
||||
std::shared_ptr<PolynomalActor> polynomalActor = std::dynamic_pointer_cast<PolynomalActor>(actor);
|
||||
if(polynomalActor != nullptr )connect(&globalSensors, &SensorStore::sensorChangedState, polynomalActor.get(), &PolynomalActor::sensorEvent);
|
||||
}
|
||||
|
||||
bool Item::removeActor(Actor* actor)
|
||||
bool Item::removeActor(std::shared_ptr<Actor> actor)
|
||||
{
|
||||
for(unsigned int i = 0; i < actors_.size(); i++)
|
||||
{
|
||||
if(actors_[i] == actor)
|
||||
{
|
||||
delete actor;
|
||||
actors_.erase(actors_.begin()+i);
|
||||
return true;
|
||||
}
|
||||
@ -134,13 +138,22 @@ bool Item::removeActor(Actor* actor)
|
||||
return false;
|
||||
}
|
||||
|
||||
void Item::setOverride(const bool in)
|
||||
{
|
||||
override_ = in;
|
||||
}
|
||||
|
||||
bool Item::getOverride()
|
||||
{
|
||||
return override_;
|
||||
}
|
||||
|
||||
void Item::removeAllActors()
|
||||
{
|
||||
for(unsigned int i = 0; i < actors_.size(); i++) delete actors_[i];
|
||||
actors_.clear();
|
||||
}
|
||||
|
||||
std::vector< Actor* >& Item::getActors()
|
||||
std::vector< std::shared_ptr<Actor> >& Item::getActors()
|
||||
{
|
||||
return actors_;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <QRandomGenerator>
|
||||
#include <QSettings>
|
||||
#include <QJsonObject>
|
||||
#include <memory>
|
||||
|
||||
class Actor;
|
||||
|
||||
@ -33,7 +34,9 @@ class Item: public QObject, public ItemData
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
std::vector< Actor* > actors_;
|
||||
std::vector< std::shared_ptr<Actor> > actors_;
|
||||
|
||||
bool override_ = false;
|
||||
|
||||
public:
|
||||
|
||||
@ -43,6 +46,9 @@ signals:
|
||||
|
||||
void valueChanged(uint8_t value);
|
||||
|
||||
private slots:
|
||||
virtual void actorSetValue(uint8_t value);
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
@ -54,12 +60,14 @@ public:
|
||||
|
||||
virtual ~Item();
|
||||
|
||||
std::vector< Actor* >& getActors();
|
||||
std::vector< std::shared_ptr<Actor> >& getActors();
|
||||
bool hasActors();
|
||||
void addActor(Actor* actor);
|
||||
bool removeActor(Actor* actor);
|
||||
void addActor(std::shared_ptr<Actor> actor);
|
||||
bool removeActor(std::shared_ptr<Actor> actor);
|
||||
void removeAllActors();
|
||||
void setActorsActive(bool in);
|
||||
void setOverride(const bool in);
|
||||
bool getOverride();
|
||||
void informValue(uint8_t value);
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "itemstore.h"
|
||||
#include "relay.h"
|
||||
#include "messageitem.h"
|
||||
#include "systemitem.h"
|
||||
#include <QJsonArray>
|
||||
|
||||
ItemStore::ItemStore(QObject *parent): QObject(parent)
|
||||
@ -110,6 +111,10 @@ void ItemStore::load(const QJsonObject& json)
|
||||
{
|
||||
newItem = std::shared_ptr<MessageItem>(new MessageItem);
|
||||
}
|
||||
else if(itemObject["Type"].toString("") == "System")
|
||||
{
|
||||
newItem = std::shared_ptr<SystemItem>(new SystemItem());
|
||||
}
|
||||
else if(itemObject["Type"].toString("") == "Aux")
|
||||
{
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include "messageitem.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QSound>
|
||||
|
||||
BroadCast* MessageItem::broadCast_ = nullptr;
|
||||
BroadCast* MessageItem::broadCast = nullptr;
|
||||
|
||||
MessageItem::MessageItem(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent):
|
||||
Item(itemIdIn, name, value, parent)
|
||||
@ -26,13 +27,12 @@ void MessageItem::setValue(uint8_t value)
|
||||
Item::setValue(value);
|
||||
if(value && !messageBox_)
|
||||
{
|
||||
if(broadCast) broadCast->sendMessage(name_, message_);
|
||||
if(!alertSoundFileName.isEmpty()) QSound::play(alertSoundFileName);
|
||||
messageBox_ = new QMessageBox(QMessageBox::NoIcon, name_, message_);
|
||||
messageBox_->setModal(false);
|
||||
connect(messageBox_, &QMessageBox::finished, this, &MessageItem::closeMessageBox);
|
||||
messageBox_->show();
|
||||
if(broadCast_) broadCast_->sendMessage(name_, message_);
|
||||
|
||||
//QTimer::singleShot(600000, this, &MessageItem::closeMessageBox);
|
||||
}
|
||||
else if(!value && messageBox_)
|
||||
{
|
||||
@ -52,6 +52,16 @@ void MessageItem::closeMessageBox()
|
||||
}
|
||||
}
|
||||
|
||||
QString MessageItem::getAlert()
|
||||
{
|
||||
return alertSoundFileName;
|
||||
}
|
||||
|
||||
void MessageItem::setAlert(const QString &in)
|
||||
{
|
||||
alertSoundFileName = in;
|
||||
}
|
||||
|
||||
void MessageItem::setMessage(const QString& in)
|
||||
{
|
||||
message_ = in;
|
||||
@ -67,10 +77,12 @@ void MessageItem::store(QJsonObject &json)
|
||||
json["Type"] = "Message";
|
||||
Item::store(json);
|
||||
json["Message"] = message_;
|
||||
if(!alertSoundFileName.isEmpty()) json["Alert"] = alertSoundFileName;
|
||||
}
|
||||
|
||||
void MessageItem::load(const QJsonObject &json, const bool preserve)
|
||||
{
|
||||
Item::load(json,preserve);
|
||||
message_ = json["Message"].toString("Invalid Message");
|
||||
alertSoundFileName = json["Alert"].toString("");
|
||||
}
|
||||
|
@ -13,8 +13,10 @@ private:
|
||||
|
||||
QString message_;
|
||||
QMessageBox* messageBox_ = nullptr;
|
||||
QString alertSoundFileName = "";
|
||||
|
||||
static BroadCast* broadCast_;
|
||||
public:
|
||||
static BroadCast* broadCast;
|
||||
|
||||
private slots:
|
||||
|
||||
@ -32,6 +34,8 @@ public:
|
||||
|
||||
void setMessage(const QString& in);
|
||||
QString getMessage();
|
||||
void setAlert(const QString& in);
|
||||
QString getAlert();
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "item.h"
|
||||
#include "../sensors/sensors.h"
|
||||
#include "../sensors/sensor.h"
|
||||
#include "../microcontroller.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
43
src/items/systemitem.cpp
Normal file
43
src/items/systemitem.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include "systemitem.h"
|
||||
#include <QProcess>
|
||||
|
||||
void SystemItem::setValue(uint8_t value)
|
||||
{
|
||||
QProcess::execute(value ? onCommand_ : offCommand_);
|
||||
}
|
||||
|
||||
SystemItem::SystemItem(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent):
|
||||
Item(itemIdIn, name, value, parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SystemItem::SystemItem(const ItemData& itemData, QObject *parent):
|
||||
Item(itemData, parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SystemItem::setOnCommand(const QString& in)
|
||||
{
|
||||
onCommand_ = in;
|
||||
}
|
||||
|
||||
void SystemItem::setOffCommand(const QString& in)
|
||||
{
|
||||
offCommand_ = in;
|
||||
}
|
||||
|
||||
void SystemItem::store(QJsonObject& json)
|
||||
{
|
||||
json["Type"] = "System";
|
||||
Item::store(json);
|
||||
json["OnCommand"] = onCommand_;
|
||||
json["OffCommand"] = offCommand_;
|
||||
}
|
||||
void SystemItem::load(const QJsonObject& json, const bool preserve)
|
||||
{
|
||||
Item::load(json,preserve);
|
||||
onCommand_ = json["OnCommand"].toString("");
|
||||
offCommand_ = json["OffCommand"].toString("");
|
||||
}
|
34
src/items/systemitem.h
Normal file
34
src/items/systemitem.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef SYSTEMITEM_H
|
||||
#define SYSTEMITEM_H
|
||||
|
||||
|
||||
#include "item.h"
|
||||
|
||||
class SystemItem : public Item
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
|
||||
QString onCommand_;
|
||||
QString offCommand_;
|
||||
|
||||
public:
|
||||
|
||||
virtual void setValue(uint8_t value);
|
||||
|
||||
public:
|
||||
|
||||
SystemItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0, QObject *parent = nullptr);
|
||||
SystemItem(const ItemData& itemData, QObject *parent = nullptr);
|
||||
~SystemItem() = default;
|
||||
|
||||
void setOnCommand(const QString& in);
|
||||
void setOffCommand(const QString& in);
|
||||
QString getOnCommand(){return onCommand_;}
|
||||
QString getOffCommand(){return offCommand_;}
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||
};
|
||||
|
||||
#endif // SYSTEMITEM_H
|
@ -2,6 +2,7 @@
|
||||
#include <stdio.h>
|
||||
#include <QDebug>
|
||||
#include <QTcpSocket>
|
||||
#include <QMessageBox>
|
||||
|
||||
|
||||
#ifndef Q_OS_ANDROID
|
||||
@ -79,6 +80,7 @@ int main(int argc, char *argv[])
|
||||
if(!microSocket->waitForConnected(1000))
|
||||
{
|
||||
std::cout<<"Can not connect to to Server.\n";
|
||||
QMessageBox::critical(nullptr, "Error", "Can not connect to to Server");
|
||||
return 1;
|
||||
}
|
||||
masterIODevice = microSocket;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "mainobject.h"
|
||||
#include "items/messageitem.h"
|
||||
|
||||
MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const bool masterIn, QObject *parent) :
|
||||
QObject(parent),
|
||||
@ -9,6 +10,7 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
|
||||
broadCast(ioMultiplexer.getIoDevice(), masterIn),
|
||||
settingsPath(settingsPathIn),
|
||||
sunSensorSource(49.884450, 8.650536),
|
||||
powerItem(new PowerItem),
|
||||
rgbItem(new RgbItem(µ, 5487422, "Rgb Lights")),
|
||||
auxItem(new AuxItem(µ, 5487421, "Desk Light"))
|
||||
|
||||
@ -27,10 +29,12 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
|
||||
QObject::connect(µ, &Microcontroller::itemChanged, &items, &ItemStore::itemStateChanged);
|
||||
|
||||
//special items
|
||||
QObject::connect(&powerItem, &PowerItem::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
||||
powerItem.emmitSensor();
|
||||
QObject::connect(powerItem.get(), &PowerItem::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
||||
powerItem->emmitSensor();
|
||||
items.addItem(rgbItem);
|
||||
items.addItem(auxItem);
|
||||
MessageItem::broadCast = &broadCast;
|
||||
|
||||
|
||||
Relay::setMicrocontroller(µ);
|
||||
|
||||
@ -42,6 +46,7 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
|
||||
else
|
||||
{
|
||||
broadCast.requestJson();
|
||||
broadCast.requestSensors();
|
||||
}
|
||||
|
||||
#ifndef Q_OS_ANDROID
|
||||
@ -62,12 +67,15 @@ MainObject::~MainObject()
|
||||
void MainObject::store(QJsonObject &json)
|
||||
{
|
||||
items.store(json);
|
||||
|
||||
QJsonObject powerObject;
|
||||
powerItem.store(powerObject);
|
||||
powerItem->store(powerObject);
|
||||
json.insert("Power", powerObject);
|
||||
QJsonDocument pwrDoc(powerObject);
|
||||
|
||||
QJsonObject ocupancyObject;
|
||||
ocupancySensor.store(ocupancyObject);
|
||||
json.insert("Ocupancy", ocupancyObject);
|
||||
json.insert("Power", powerObject);
|
||||
}
|
||||
|
||||
void MainObject::load(const QJsonObject& json)
|
||||
@ -75,11 +83,11 @@ void MainObject::load(const QJsonObject& json)
|
||||
items.clear();
|
||||
rgbItem->removeAllActors();
|
||||
auxItem->removeAllActors();
|
||||
powerItem.removeAllActors();
|
||||
powerItem->removeAllActors();
|
||||
items.addItem(rgbItem);
|
||||
items.addItem(auxItem);
|
||||
items.load(json);
|
||||
powerItem.load(json["Power"].toObject());
|
||||
powerItem->load(json["Power"].toObject());
|
||||
ocupancySensor.load(json["Ocupancy"].toObject());
|
||||
qDebug()<<"aray size: "<<json.isEmpty();
|
||||
if(json["Items"].toArray().size() >= 2)
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
//items
|
||||
ItemStore items;
|
||||
|
||||
PowerItem powerItem;
|
||||
std::shared_ptr<PowerItem> powerItem;
|
||||
std::shared_ptr<RgbItem> rgbItem;
|
||||
std::shared_ptr<AuxItem> auxItem;
|
||||
|
||||
|
@ -9,7 +9,7 @@ void Microcontroller::relayToggle(int state, int relay)
|
||||
{
|
||||
char buffer[8];
|
||||
int length = sprintf(buffer, "%d \n", relay);
|
||||
state ? write("relay on ") : write("relay off ");
|
||||
state ? write("item on ") : write("item off ");
|
||||
write(buffer, length);
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ void Microcontroller::setIODevice(QIODevice *port)
|
||||
std::shared_ptr<Relay> Microcontroller::processRelayLine(const QString& buffer)
|
||||
{
|
||||
QStringList bufferList = buffer.split(' ');
|
||||
if(bufferList.size() >= 8 && buffer.startsWith("RELAY NUMBER:"))
|
||||
if(bufferList.size() >= 8 && buffer.startsWith("ITEM NUMBER:"))
|
||||
{
|
||||
QString name;
|
||||
for(int i = 8; i < bufferList.size(); i++) name.append(bufferList[i] + ' ');
|
||||
@ -139,7 +139,7 @@ std::shared_ptr<Relay> Microcontroller::processRelayLine(const QString& buffer)
|
||||
void Microcontroller::processList(const QString& buffer)
|
||||
{
|
||||
QStringList bufferList = buffer.split(' ');
|
||||
if(bufferList.size() >= 8 && buffer.startsWith("RELAY NUMBER:"))
|
||||
if(bufferList.size() >= 8 && buffer.startsWith("ITEM NUMBER:"))
|
||||
{
|
||||
relayList.push_back(processRelayLine(buffer));
|
||||
}
|
||||
@ -175,7 +175,7 @@ void Microcontroller::processMicroReturn()
|
||||
listMode = true;
|
||||
relayList.clear();
|
||||
}
|
||||
else if(_buffer.startsWith("RELAY NUMBER:"))processRelayState(_buffer);
|
||||
else if(_buffer.startsWith("ITEM NUMBER:"))processRelayState(_buffer);
|
||||
else if(_buffer.startsWith("SENSOR")) processSensorState(_buffer);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
OcupancySensorSource::OcupancySensorSource(QObject *parent, const QString& device, const QString& deviceMac): QObject (parent), deviceMac_(deviceMac), device_(device)
|
||||
{
|
||||
|
||||
QTimer::singleShot(timeoutMs, this, &OcupancySensorSource::Timeout);
|
||||
}
|
||||
|
||||
void OcupancySensorSource::sensorEvent(Sensor sensor)
|
||||
@ -15,13 +15,14 @@ void OcupancySensorSource::sensorEvent(Sensor sensor)
|
||||
if(sensor.type == Sensor::TYPE_DOOR && sensor.id == 1 && sensor.field != 0.0f)
|
||||
{
|
||||
if(occupied == false) stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, 1, "Occupancy"));
|
||||
QTimer::singleShot(600000, this, &OcupancySensorSource::Timeout);
|
||||
QTimer::singleShot(timeoutMs, this, &OcupancySensorSource::Timeout);
|
||||
}
|
||||
}
|
||||
|
||||
void OcupancySensorSource::Timeout()
|
||||
{
|
||||
int error = 0;
|
||||
qDebug()<<"testing for occupancy";
|
||||
std::vector<uint64_t> devices = ap::connectedDevices(device_.toLatin1().toStdString(), error);
|
||||
if(error == 0)
|
||||
{
|
||||
@ -32,16 +33,19 @@ void OcupancySensorSource::Timeout()
|
||||
if(mac.find(deviceMac_.toLatin1().toStdString()) != std::string::npos)
|
||||
{
|
||||
found = true;
|
||||
qDebug()<<"occupied";
|
||||
break;
|
||||
}
|
||||
}
|
||||
stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, found, "Occupancy"));
|
||||
occupied = found;
|
||||
}
|
||||
else
|
||||
{
|
||||
stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, true, "Occupancy"));
|
||||
qDebug()<<"occupancy sensor error";
|
||||
qDebug()<<"occupancy sensor error "<<error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OcupancySensorSource::store(QJsonObject &json)
|
||||
@ -54,5 +58,4 @@ void OcupancySensorSource::load(const QJsonObject &json)
|
||||
{
|
||||
device_ = json["Device"].toString("wlan0");
|
||||
deviceMac_ = json["MacAddres"].toString("60:BE:B5:25:8C:E0");
|
||||
QTimer::singleShot(600000, this, &OcupancySensorSource::Timeout);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ private:
|
||||
QString deviceMac_;
|
||||
QString device_;
|
||||
bool occupied = true;
|
||||
static constexpr unsigned timeoutMs = (15 * 60) * 1000;
|
||||
|
||||
public:
|
||||
explicit OcupancySensorSource(QObject *parent = nullptr, const QString& device = "wlan0", const QString& deviceMac = "60:BE:B5:25:8C:E0");
|
||||
|
@ -52,6 +52,11 @@ public:
|
||||
}
|
||||
else return Sensor(TYPE_DUMMY, 0, 0, "", true);
|
||||
}
|
||||
QString toString()
|
||||
{
|
||||
return QString("SENSOR TYPE: ")+QString::number(type)+" ID: "+QString::number(id)+" FIELD: "+
|
||||
QString::number((type == Sensor::TYPE_HUMIDITY || type == Sensor::TYPE_TEMPERATURE) ? field*10 : field);
|
||||
}
|
||||
inline void generateName()
|
||||
{
|
||||
if(type == TYPE_TEMPERATURE) name = "Temperature " + QString::number(id);
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <QDebug>
|
||||
#include <QSpinBox>
|
||||
|
||||
ActorSettingsDialog::ActorSettingsDialog(AlarmTime* alarm, QWidget *parent):
|
||||
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<AlarmTime> alarm, QWidget *parent):
|
||||
QDialog(parent),
|
||||
actor_(alarm),
|
||||
ui(new Ui::ActorSettingsDialog)
|
||||
@ -15,7 +15,7 @@ ActorSettingsDialog::ActorSettingsDialog(AlarmTime* alarm, QWidget *parent):
|
||||
ui->vertlayout->addWidget(widget);
|
||||
}
|
||||
|
||||
ActorSettingsDialog::ActorSettingsDialog(SensorActor* actor, QWidget *parent) :
|
||||
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<SensorActor> actor, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
actor_(actor),
|
||||
ui(new Ui::ActorSettingsDialog)
|
||||
@ -26,7 +26,7 @@ ui(new Ui::ActorSettingsDialog)
|
||||
ui->vertlayout->addWidget(widget);
|
||||
}
|
||||
|
||||
ActorSettingsDialog::ActorSettingsDialog(Regulator* actor, QWidget *parent) :
|
||||
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<Regulator> actor, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
actor_(actor),
|
||||
ui(new Ui::ActorSettingsDialog)
|
||||
@ -37,7 +37,7 @@ ActorSettingsDialog::ActorSettingsDialog(Regulator* actor, QWidget *parent) :
|
||||
ui->vertlayout->addWidget(widget);
|
||||
}
|
||||
|
||||
ActorSettingsDialog::ActorSettingsDialog(TimerActor* actor, QWidget *parent) :
|
||||
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<TimerActor> actor, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
actor_(actor),
|
||||
ui(new Ui::ActorSettingsDialog)
|
||||
@ -48,7 +48,7 @@ ui(new Ui::ActorSettingsDialog)
|
||||
ui->vertlayout->addWidget(widget);
|
||||
}
|
||||
|
||||
ActorSettingsDialog::ActorSettingsDialog(PolynomalActor* actor, QWidget *parent) :
|
||||
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<PolynomalActor> actor, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
actor_(actor),
|
||||
ui(new Ui::ActorSettingsDialog)
|
||||
@ -59,7 +59,7 @@ ui(new Ui::ActorSettingsDialog)
|
||||
ui->vertlayout->addWidget(widget);
|
||||
}
|
||||
|
||||
ActorSettingsDialog::ActorSettingsDialog(MultiFactorActor* actor, QWidget *parent) :
|
||||
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<MultiFactorActor> actor, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
actor_(actor),
|
||||
ui(new Ui::ActorSettingsDialog)
|
||||
@ -69,7 +69,7 @@ ui(new Ui::ActorSettingsDialog)
|
||||
ui->vertlayout->addWidget(widget);
|
||||
}
|
||||
|
||||
ActorSettingsDialog::ActorSettingsDialog(Actor* actor, QWidget *parent) :
|
||||
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<Actor> actor, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
actor_(actor),
|
||||
ui(new Ui::ActorSettingsDialog)
|
||||
|
@ -19,19 +19,19 @@ class ActorSettingsDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
Actor* actor_;
|
||||
std::shared_ptr<Actor> actor_;
|
||||
QWidget* widget;
|
||||
|
||||
void init();
|
||||
|
||||
public:
|
||||
ActorSettingsDialog(AlarmTime* actor, QWidget *parent = nullptr);
|
||||
ActorSettingsDialog(SensorActor* actor, QWidget *parent = nullptr);
|
||||
ActorSettingsDialog(Regulator* actor, QWidget *parent = nullptr);
|
||||
ActorSettingsDialog(TimerActor* actor, QWidget *parent = nullptr);
|
||||
ActorSettingsDialog(PolynomalActor* actor, QWidget *parent = nullptr);
|
||||
ActorSettingsDialog(MultiFactorActor* actor, QWidget *parent = nullptr);
|
||||
ActorSettingsDialog(Actor* actor, QWidget *parent);
|
||||
ActorSettingsDialog(std::shared_ptr<AlarmTime> actor, QWidget *parent = nullptr);
|
||||
ActorSettingsDialog(std::shared_ptr<SensorActor> actor, QWidget *parent = nullptr);
|
||||
ActorSettingsDialog(std::shared_ptr<Regulator> actor, QWidget *parent = nullptr);
|
||||
ActorSettingsDialog(std::shared_ptr<TimerActor> actor, QWidget *parent = nullptr);
|
||||
ActorSettingsDialog(std::shared_ptr<PolynomalActor> actor, QWidget *parent = nullptr);
|
||||
ActorSettingsDialog(std::shared_ptr<MultiFactorActor> actor, QWidget *parent = nullptr);
|
||||
ActorSettingsDialog(std::shared_ptr<Actor> actor, QWidget *parent);
|
||||
~ActorSettingsDialog();
|
||||
|
||||
void hideCancle(const bool hide);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "alarmwidget.h"
|
||||
#include "ui_alarmwidget.h"
|
||||
|
||||
AlarmWidget::AlarmWidget(AlarmTime* alarm, QWidget *parent) :
|
||||
AlarmWidget::AlarmWidget(std::shared_ptr<AlarmTime> alarm, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
alarm_(alarm),
|
||||
ui(new Ui::AlarmWidget)
|
||||
@ -35,7 +35,7 @@ AlarmWidget::AlarmWidget(AlarmTime* alarm, QWidget *parent) :
|
||||
else if(alarm_->getRepeat() == AlarmTime::REPEAT_MONTHLY)ui->radioButton_3->setChecked(true);
|
||||
else if(alarm_->getRepeat() == AlarmTime::REPEAT_YEARLY) ui->radioButton_4->setChecked(true);
|
||||
|
||||
connect(ui->dateTimeEdit, &QDateTimeEdit::dateTimeChanged, alarm, &AlarmTime::changeTime);
|
||||
connect(ui->dateTimeEdit, &QDateTimeEdit::dateTimeChanged, alarm.get(), &AlarmTime::changeTime);
|
||||
}
|
||||
|
||||
AlarmWidget::~AlarmWidget()
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define ALARMWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <memory>
|
||||
#include "../../actors/alarmtime.h"
|
||||
|
||||
namespace Ui {
|
||||
@ -12,10 +13,10 @@ class AlarmWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
AlarmTime* alarm_;
|
||||
std::shared_ptr<AlarmTime> alarm_;
|
||||
|
||||
public:
|
||||
explicit AlarmWidget(AlarmTime* alarm, QWidget *parent = nullptr);
|
||||
explicit AlarmWidget(std::shared_ptr<AlarmTime> alarm, QWidget *parent = nullptr);
|
||||
~AlarmWidget();
|
||||
|
||||
private slots:
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "ui_factoractorwidget.h"
|
||||
#include "../actorsettingsdialog.h"
|
||||
|
||||
FactorActorWidget::FactorActorWidget(MultiFactorActor* actor, QWidget *parent) :
|
||||
FactorActorWidget::FactorActorWidget(std::shared_ptr<MultiFactorActor> actor, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
actor_(actor),
|
||||
ui(new Ui::FactorActorWidget)
|
||||
@ -24,36 +24,36 @@ FactorActorWidget::~FactorActorWidget()
|
||||
void FactorActorWidget::createFactorActor()
|
||||
{
|
||||
ActorSettingsDialog* dialog = nullptr;
|
||||
Actor* actor = nullptr;
|
||||
std::shared_ptr<Actor> actor = nullptr;
|
||||
|
||||
if(ui->comboBox->currentText() == "Alarm")
|
||||
{
|
||||
AlarmTime* alarm = new AlarmTime;
|
||||
std::shared_ptr<AlarmTime> alarm = std::shared_ptr<AlarmTime>(new AlarmTime);
|
||||
actor = alarm;
|
||||
dialog = new ActorSettingsDialog(alarm, this);
|
||||
}
|
||||
else if(ui->comboBox->currentText() == "Sensor")
|
||||
{
|
||||
SensorActor* sensorActor = new SensorActor();
|
||||
std::shared_ptr<SensorActor> sensorActor = std::shared_ptr<SensorActor>(new SensorActor());
|
||||
actor = sensorActor;
|
||||
dialog = new ActorSettingsDialog(sensorActor, this);
|
||||
}
|
||||
else if(ui->comboBox->currentText() == "Timer" )
|
||||
{
|
||||
TimerActor* timerActor = new TimerActor();
|
||||
std::shared_ptr<TimerActor> timerActor = std::shared_ptr<TimerActor>(new TimerActor());
|
||||
actor = timerActor;
|
||||
dialog = new ActorSettingsDialog(timerActor, this);
|
||||
}
|
||||
else if(ui->comboBox->currentText() == "Regulator")
|
||||
{
|
||||
Regulator* regulator = new 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")
|
||||
{
|
||||
PolynomalActor* polynomalActor = new PolynomalActor();
|
||||
std::shared_ptr<PolynomalActor> polynomalActor = std::shared_ptr<PolynomalActor>(new PolynomalActor());
|
||||
actor = polynomalActor;
|
||||
dialog = new ActorSettingsDialog(polynomalActor, this);
|
||||
}
|
||||
@ -68,7 +68,6 @@ void FactorActorWidget::createFactorActor()
|
||||
actor_->setFactorActor(actor);
|
||||
ui->label_FactorActor->setText(actor->getName());
|
||||
}
|
||||
else delete actor;
|
||||
delete dialog;
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,10 @@ class FactorActorWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
MultiFactorActor* actor_;
|
||||
std::shared_ptr<MultiFactorActor> actor_;
|
||||
|
||||
public:
|
||||
explicit FactorActorWidget(MultiFactorActor* actor, QWidget *parent = nullptr);
|
||||
explicit FactorActorWidget(std::shared_ptr<MultiFactorActor> actor, QWidget *parent = nullptr);
|
||||
~FactorActorWidget();
|
||||
|
||||
private slots:
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "polynomalactorwidget.h"
|
||||
#include "ui_polynomalactorwidget.h"
|
||||
|
||||
PolynomalActorWidget::PolynomalActorWidget(PolynomalActor* actor, SensorStore* sensors, QWidget *parent):
|
||||
PolynomalActorWidget::PolynomalActorWidget(std::shared_ptr<PolynomalActor> actor, SensorStore* sensors, QWidget *parent):
|
||||
QWidget(parent),
|
||||
sensors_(sensors),
|
||||
actor_(actor),
|
||||
|
@ -12,10 +12,10 @@ class PolynomalActorWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
SensorStore* sensors_;
|
||||
PolynomalActor* actor_;
|
||||
std::shared_ptr<PolynomalActor> actor_;
|
||||
|
||||
public:
|
||||
explicit PolynomalActorWidget(PolynomalActor* regulator, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
|
||||
explicit PolynomalActorWidget(std::shared_ptr<PolynomalActor> regulator, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
|
||||
~PolynomalActorWidget();
|
||||
|
||||
private slots:
|
||||
|
@ -9,7 +9,7 @@ RegulatorWdiget::~RegulatorWdiget()
|
||||
|
||||
|
||||
|
||||
RegulatorWdiget::RegulatorWdiget(Regulator* regulator, SensorStore* sensors, QWidget *parent) :
|
||||
RegulatorWdiget::RegulatorWdiget(std::shared_ptr<Regulator> regulator, SensorStore* sensors, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
regulator_(regulator),
|
||||
sensors_(sensors),
|
||||
|
@ -12,11 +12,11 @@ class RegulatorWdiget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Regulator* regulator_;
|
||||
std::shared_ptr<Regulator> regulator_;
|
||||
SensorStore* sensors_;
|
||||
|
||||
public:
|
||||
explicit RegulatorWdiget(Regulator* regulator, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
|
||||
explicit RegulatorWdiget(std::shared_ptr<Regulator> regulator, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
|
||||
~RegulatorWdiget();
|
||||
|
||||
private slots:
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
SensorActorWidget::SensorActorWidget(SensorActor* sensorActor, SensorStore* sensors, QWidget *parent) :
|
||||
SensorActorWidget::SensorActorWidget(std::shared_ptr<SensorActor> sensorActor, SensorStore* sensors, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
sensorActor_(sensorActor),
|
||||
sensors_(sensors),
|
||||
|
@ -13,11 +13,11 @@ class SensorActorWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
SensorActor* sensorActor_;
|
||||
std::shared_ptr<SensorActor> sensorActor_;
|
||||
SensorStore* sensors_;
|
||||
|
||||
public:
|
||||
explicit SensorActorWidget(SensorActor* sensorActor, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
|
||||
explicit SensorActorWidget(std::shared_ptr<SensorActor> sensorActor, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
|
||||
~SensorActorWidget();
|
||||
|
||||
private slots:
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <QSpinBox>
|
||||
|
||||
TimerActorWidget::TimerActorWidget(TimerActor* actor, QWidget *parent) :
|
||||
TimerActorWidget::TimerActorWidget(std::shared_ptr<TimerActor> actor, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::TimerActorWidget)
|
||||
{
|
||||
@ -11,7 +11,7 @@ TimerActorWidget::TimerActorWidget(TimerActor* actor, QWidget *parent) :
|
||||
|
||||
ui->spinBox->setValue(actor->getTimeout());
|
||||
|
||||
connect(ui->spinBox, SIGNAL(valueChanged(int)), actor, SLOT(setTimeout(int)));
|
||||
connect(ui->spinBox, SIGNAL(valueChanged(int)), actor.get(), SLOT(setTimeout(int)));
|
||||
}
|
||||
|
||||
TimerActorWidget::~TimerActorWidget()
|
||||
|
@ -13,7 +13,7 @@ class TimerActorWidget : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TimerActorWidget(TimerActor* actor, QWidget *parent = nullptr);
|
||||
explicit TimerActorWidget(std::shared_ptr<TimerActor> actor, QWidget *parent = nullptr);
|
||||
~TimerActorWidget();
|
||||
|
||||
private:
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "ui_itemcreationdialog.h"
|
||||
|
||||
#include "itemsettingswidgets/messageitemsettingswidget.h"
|
||||
#include "itemsettingswidgets/systemitemsettingswidget.h"
|
||||
|
||||
ItemCreationDialog::ItemCreationDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
@ -31,7 +32,14 @@ void ItemCreationDialog::itemTypeChanged(const QString& type)
|
||||
std::shared_ptr<MessageItem> messageItem(new MessageItem);
|
||||
item = messageItem;
|
||||
widget = new MessageItemSettingsWidget(messageItem, this);
|
||||
ui->verticalLayout_2->addWidget(widget);
|
||||
ui->verticalLayout->addWidget(widget);
|
||||
}
|
||||
if(type == "System")
|
||||
{
|
||||
std::shared_ptr<SystemItem> systemItem(new SystemItem);
|
||||
item = systemItem;
|
||||
widget = new SystemItemSettingsWidget(systemItem, this);
|
||||
ui->verticalLayout->addWidget(widget);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,11 @@
|
||||
<string>Message</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>System</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -6,10 +6,14 @@
|
||||
#include "../actors/timeractor.h"
|
||||
#include "../actors/regulator.h"
|
||||
#include "../actors/factoractor.h"
|
||||
|
||||
#include "../items/messageitem.h"
|
||||
#include "../items/systemitem.h"
|
||||
#include "./itemsettingswidgets/messageitemsettingswidget.h"
|
||||
#include "./itemsettingswidgets/systemitemsettingswidget.h"
|
||||
#include "./itemsettingswidgets/relayitemsettingswidget.h"
|
||||
#include<memory>
|
||||
|
||||
ItemSettingsDialog::ItemSettingsDialog(Item* item, QWidget *parent) :
|
||||
ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
item_(item),
|
||||
ui(new Ui::ItemSettingsDialog)
|
||||
@ -19,23 +23,32 @@ ItemSettingsDialog::ItemSettingsDialog(Item* item, QWidget *parent) :
|
||||
setModal(false);
|
||||
|
||||
ui->label_name->setText(item_->getName());
|
||||
ui->checkBox_Override->setChecked(item_->getOverride());
|
||||
|
||||
if(Relay* relay = dynamic_cast<Relay*>(item_))
|
||||
|
||||
if(std::shared_ptr<Relay> relay = std::dynamic_pointer_cast<Relay>(item_))
|
||||
{
|
||||
ui->label_address->setText(QString::number(relay->getAddress(), 2));
|
||||
ui->label_id->setText(QString::number(relay->getId(), 10));
|
||||
itemSpecificWidget_ = new RelayItemSettingsWidget(relay);
|
||||
}
|
||||
else
|
||||
else if(std::shared_ptr<MessageItem> msgItem = std::dynamic_pointer_cast<MessageItem>(item_))
|
||||
{
|
||||
ui->label_address->hide();
|
||||
ui->label_id->hide();
|
||||
ui->label_address_lable->hide();
|
||||
ui->label_id_lable->hide();
|
||||
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"));
|
||||
@ -48,9 +61,15 @@ ItemSettingsDialog::ItemSettingsDialog(Item* item, QWidget *parent) :
|
||||
|
||||
ItemSettingsDialog::~ItemSettingsDialog()
|
||||
{
|
||||
if(itemSpecificWidget_) delete itemSpecificWidget_;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ItemSettingsDialog::changeOverride()
|
||||
{
|
||||
item_->setOverride(ui->checkBox_Override->isChecked());
|
||||
}
|
||||
|
||||
void ItemSettingsDialog::loadActorList()
|
||||
{
|
||||
//ui->listWidget->clear();
|
||||
@ -67,43 +86,43 @@ void ItemSettingsDialog::loadActorList()
|
||||
void ItemSettingsDialog::addActor()
|
||||
{
|
||||
ActorSettingsDialog* dialog = nullptr;
|
||||
Actor* actor = nullptr;
|
||||
std::shared_ptr<Actor> actor = nullptr;
|
||||
|
||||
if(ui->comboBox->currentText() == "Alarm")
|
||||
{
|
||||
AlarmTime* alarm = new AlarmTime;
|
||||
std::shared_ptr<AlarmTime> alarm = std::shared_ptr<AlarmTime>(new AlarmTime);
|
||||
actor = alarm;
|
||||
dialog = new ActorSettingsDialog(alarm, this);
|
||||
}
|
||||
else if(ui->comboBox->currentText() == "Sensor")
|
||||
{
|
||||
SensorActor* sensorActor = new SensorActor();
|
||||
std::shared_ptr<SensorActor> sensorActor = std::shared_ptr<SensorActor>(new SensorActor);
|
||||
actor = sensorActor;
|
||||
dialog = new ActorSettingsDialog(sensorActor, this);
|
||||
}
|
||||
else if(ui->comboBox->currentText() == "Timer" )
|
||||
{
|
||||
TimerActor* timerActor = new TimerActor();
|
||||
std::shared_ptr<TimerActor> timerActor = std::shared_ptr<TimerActor>(new TimerActor);
|
||||
actor = timerActor;
|
||||
dialog = new ActorSettingsDialog(timerActor, this);
|
||||
}
|
||||
else if(ui->comboBox->currentText() == "Regulator")
|
||||
{
|
||||
Regulator* regulator = new 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")
|
||||
{
|
||||
PolynomalActor* polynomalActor = new PolynomalActor();
|
||||
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")
|
||||
{
|
||||
MultiFactorActor* polynomalActor = new MultiFactorActor();
|
||||
std::shared_ptr<MultiFactorActor> polynomalActor = std::shared_ptr<MultiFactorActor>(new MultiFactorActor);
|
||||
actor = polynomalActor;
|
||||
dialog = new ActorSettingsDialog(polynomalActor, this);
|
||||
}
|
||||
@ -118,7 +137,6 @@ void ItemSettingsDialog::addActor()
|
||||
item_->addActor(actor);
|
||||
loadActorList();
|
||||
}
|
||||
else delete actor;
|
||||
delete dialog;
|
||||
}
|
||||
|
||||
@ -137,14 +155,14 @@ void ItemSettingsDialog::editActor()
|
||||
{
|
||||
if(item_->getActors().size() > ui->tableWidget->currentRow())
|
||||
{
|
||||
Actor* actor = item_->getActors()[ui->tableWidget->currentRow()];
|
||||
std::shared_ptr<Actor> actor = item_->getActors()[ui->tableWidget->currentRow()];
|
||||
|
||||
AlarmTime* alarmTime = dynamic_cast<AlarmTime*>(actor);
|
||||
Regulator* regulator = dynamic_cast<Regulator*>(actor);
|
||||
SensorActor* sensorActor = dynamic_cast<SensorActor*>(actor);
|
||||
TimerActor* timerActor = dynamic_cast<TimerActor*>(actor);
|
||||
PolynomalActor* polynomalActor = dynamic_cast<PolynomalActor*>(actor);
|
||||
MultiFactorActor* factorActor = dynamic_cast<MultiFactorActor*>(actor);
|
||||
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;
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include <QSettings>
|
||||
#include <memory>
|
||||
#include "../items/relay.h"
|
||||
|
||||
namespace Ui {
|
||||
@ -12,13 +13,14 @@ class ItemSettingsDialog;
|
||||
class ItemSettingsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Item* item_;
|
||||
std::shared_ptr<Item> item_;
|
||||
QWidget* itemSpecificWidget_ = nullptr;
|
||||
|
||||
private:
|
||||
void loadActorList();
|
||||
|
||||
public:
|
||||
explicit ItemSettingsDialog(Item* item, QWidget *parent = nullptr);
|
||||
explicit ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent = nullptr);
|
||||
~ItemSettingsDialog();
|
||||
|
||||
private slots:
|
||||
@ -26,6 +28,7 @@ private slots:
|
||||
void removeActor();
|
||||
void addActor();
|
||||
void editActor();
|
||||
void changeOverride();
|
||||
|
||||
private:
|
||||
Ui::ItemSettingsDialog *ui;
|
||||
|
@ -30,23 +30,16 @@
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_id_lable">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>ID:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_id">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_name">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
@ -65,35 +58,18 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_address_lable">
|
||||
<property name="text">
|
||||
<string>Address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="label_address">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" 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>
|
||||
</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">
|
||||
|
21
src/ui/itemsettingswidgets/relayitemsettingswidget.cpp
Normal file
21
src/ui/itemsettingswidgets/relayitemsettingswidget.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "relayitemsettingswidget.h"
|
||||
#include "ui_relayitemsettingswidget.h"
|
||||
|
||||
|
||||
RelayItemSettingsWidget::RelayItemSettingsWidget(std::weak_ptr<Relay> relay, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::RelayItemSettingsWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
auto relayPtr = relay.lock();
|
||||
if(relayPtr)
|
||||
{
|
||||
ui->label_ID->setText(QString::number(relayPtr->getId()));
|
||||
ui->label_Addr->setText(QString::number(relayPtr->getAddress(),2));
|
||||
}
|
||||
}
|
||||
|
||||
RelayItemSettingsWidget::~RelayItemSettingsWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
24
src/ui/itemsettingswidgets/relayitemsettingswidget.h
Normal file
24
src/ui/itemsettingswidgets/relayitemsettingswidget.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef RELAYITEMSETTINGSWIDGET_H
|
||||
#define RELAYITEMSETTINGSWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <memory>
|
||||
#include "../../items/relay.h"
|
||||
|
||||
namespace Ui {
|
||||
class RelayItemSettingsWidget;
|
||||
}
|
||||
|
||||
class RelayItemSettingsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RelayItemSettingsWidget(std::weak_ptr<Relay> relay, QWidget *parent = nullptr);
|
||||
~RelayItemSettingsWidget();
|
||||
|
||||
private:
|
||||
Ui::RelayItemSettingsWidget *ui;
|
||||
};
|
||||
|
||||
#endif // RELAYITEMSETTINGSWIDGET_H
|
85
src/ui/itemsettingswidgets/relayitemsettingswidget.ui
Normal file
85
src/ui/itemsettingswidgets/relayitemsettingswidget.ui
Normal file
@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>RelayItemSettingsWidget</class>
|
||||
<widget class="QWidget" name="RelayItemSettingsWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>58</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>ID:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Address:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="label_Addr">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_ID">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
40
src/ui/itemsettingswidgets/systemitemsettingswidget.cpp
Normal file
40
src/ui/itemsettingswidgets/systemitemsettingswidget.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include "systemitemsettingswidget.h"
|
||||
#include "ui_systemitemsettingswidget.h"
|
||||
|
||||
SystemItemSettingsWidget::SystemItemSettingsWidget(std::weak_ptr<SystemItem> item, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
item_(item),
|
||||
ui(new Ui::SystemItemSettingsWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
if(auto itemPtr = item_.lock())
|
||||
{
|
||||
ui->lineEdit_on->setText(itemPtr->getOnCommand());
|
||||
ui->lineEdit_off->setText(itemPtr->getOffCommand());
|
||||
}
|
||||
else setDisabled(true);
|
||||
|
||||
connect(ui->lineEdit_on, &QLineEdit::textChanged, this, &SystemItemSettingsWidget::setOn);
|
||||
connect(ui->lineEdit_off, &QLineEdit::textChanged, this, &SystemItemSettingsWidget::setOff);
|
||||
}
|
||||
|
||||
void SystemItemSettingsWidget::setOn(const QString& in)
|
||||
{
|
||||
if(auto itemPtr = item_.lock())
|
||||
{
|
||||
itemPtr->setOnCommand(in);
|
||||
}
|
||||
}
|
||||
|
||||
void SystemItemSettingsWidget::setOff(const QString& in)
|
||||
{
|
||||
if(auto itemPtr = item_.lock())
|
||||
{
|
||||
itemPtr->setOffCommand(in);
|
||||
}
|
||||
}
|
||||
|
||||
SystemItemSettingsWidget::~SystemItemSettingsWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
30
src/ui/itemsettingswidgets/systemitemsettingswidget.h
Normal file
30
src/ui/itemsettingswidgets/systemitemsettingswidget.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef SYSTEMITEMSETTINGSWIDGET_H
|
||||
#define SYSTEMITEMSETTINGSWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <memory>
|
||||
#include "../../items/systemitem.h"
|
||||
|
||||
namespace Ui {
|
||||
class SystemItemSettingsWidget;
|
||||
}
|
||||
|
||||
class SystemItemSettingsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
std::weak_ptr<SystemItem> item_;
|
||||
|
||||
private slots:
|
||||
|
||||
void setOn(const QString &in);
|
||||
void setOff(const QString &in);
|
||||
|
||||
public:
|
||||
explicit SystemItemSettingsWidget(std::weak_ptr<SystemItem> item, QWidget *parent = nullptr);
|
||||
~SystemItemSettingsWidget();
|
||||
|
||||
private:
|
||||
Ui::SystemItemSettingsWidget *ui;
|
||||
};
|
||||
|
||||
#endif // SYSTEMITEMSETTINGSWIDGET_H
|
47
src/ui/itemsettingswidgets/systemitemsettingswidget.ui
Normal file
47
src/ui/itemsettingswidgets/systemitemsettingswidget.ui
Normal file
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SystemItemSettingsWidget</class>
|
||||
<widget class="QWidget" name="SystemItemSettingsWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>92</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>On command</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_on"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_off"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Off command</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -64,6 +64,8 @@ void ItemWidget::disable()
|
||||
{
|
||||
ui->checkBox->setEnabled(false);
|
||||
ui->label->setEnabled(false);
|
||||
ui->slider->setEnabled(false);
|
||||
ui->pushButton_Remove->setEnabled(false);
|
||||
}
|
||||
|
||||
bool ItemWidget::controles(const ItemData& relay)
|
||||
@ -80,7 +82,7 @@ void ItemWidget::showSettingsDialog()
|
||||
{
|
||||
if(auto workingRelay = item_.lock())
|
||||
{
|
||||
ItemSettingsDialog dialog(workingRelay.get(), this);
|
||||
ItemSettingsDialog dialog(workingRelay, this);
|
||||
dialog.exec();
|
||||
}
|
||||
else disable();
|
||||
|
@ -10,7 +10,7 @@ MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
|
||||
ui(new Ui::MainWindow),
|
||||
colorChooser(this),
|
||||
_micro(&mainObject->micro),
|
||||
_powerItem(&mainObject->powerItem)
|
||||
_powerItem(mainObject->powerItem)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@ -21,7 +21,11 @@ MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
|
||||
|
||||
//Relays
|
||||
if(mainObject->master)connect(ui->pushButton_refesh, &QPushButton::clicked, _micro, &Microcontroller::requestState);
|
||||
else connect(ui->pushButton_refesh, &QPushButton::clicked, &mainObject->broadCast, &BroadCast::requestJson);
|
||||
else
|
||||
{
|
||||
connect(ui->pushButton_refesh, &QPushButton::clicked, &mainObject->broadCast, &BroadCast::requestJson);
|
||||
connect(ui->pushButton_refesh, &QPushButton::clicked, &mainObject->broadCast, &BroadCast::requestSensors);
|
||||
}
|
||||
connect(&mainObject->items, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem);
|
||||
connect(&mainObject->items, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem);
|
||||
|
||||
@ -51,7 +55,7 @@ MainWindow::~MainWindow()
|
||||
|
||||
void MainWindow::showPowerItemDialog()
|
||||
{
|
||||
ItemSettingsDialog diag(_powerItem, this);
|
||||
ItemSettingsDialog diag(std::shared_ptr<Item>(_powerItem), this);
|
||||
diag.show();
|
||||
diag.exec();
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ private:
|
||||
|
||||
Microcontroller *_micro;
|
||||
|
||||
PowerItem *_powerItem;
|
||||
std::shared_ptr<PowerItem> _powerItem;
|
||||
|
||||
signals:
|
||||
|
||||
|
@ -2,13 +2,16 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include <QHeaderView>
|
||||
#include <QScroller>
|
||||
|
||||
SensorListWidget::SensorListWidget(const bool showHidden, QWidget *parent): QTableWidget(parent), showHidden_(showHidden)
|
||||
{
|
||||
setColumnCount(2);
|
||||
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
|
||||
QScroller::grabGesture(this, QScroller::LeftMouseButtonGesture);
|
||||
setAutoScroll(true);
|
||||
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
setHorizontalHeaderItem(0, new QTableWidgetItem("Sensor"));
|
||||
setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user