diff --git a/src/items/item.cpp b/src/items/item.cpp index 49f418a..53790ae 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -79,7 +79,7 @@ bool ItemData::hasChanged(const ItemData& other) return false; } -bool ItemData::isHidden() +bool ItemData::isHidden() const { return hidden_; } @@ -145,6 +145,30 @@ void Item::load(const QJsonObject &json, const bool preserve) } } +Item& Item::operator=(const ItemData& other) +{ + name_ = other.getName(); + value_ = other.getValue(); + itemId_ = other.id(); + hidden_ = other.isHidden(); + return *this; +} + +void Item::requestUpdate(ItemUpdateRequest update) +{ + if(!hasChanged(update.data)) + return; + + if(update.type == ITEM_UPDATE_USER || (update.type == ITEM_UPDATE_ACTOR && !override_) || update.type == ITEM_UPDATE_REMOTE) + { + if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY) + enactValue(update.data.getValue()); + *this = update.data; + update.data = *this; + updated(update); + } +} + void Item::actorSetValue(uint8_t value) { if(!override_ && (programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)) @@ -155,6 +179,7 @@ void Item::setValue(uint8_t value) { qDebug()<<__func__; informValue(value); + updated(*this); if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY) enactValue(value); } @@ -165,7 +190,6 @@ void Item::informValue(uint8_t value) { value_ = value; valueChanged(value_); - updated(*this); } } diff --git a/src/items/item.h b/src/items/item.h index 1aaa090..4fbf23f 100644 --- a/src/items/item.h +++ b/src/items/item.h @@ -14,6 +14,12 @@ typedef enum { ITEM_VALUE_NO_VALUE } item_value_type_t; +typedef enum { + ITEM_UPDATE_USER = 0, + ITEM_UPDATE_ACTOR, + ITEM_UPDATE_REMOTE +} item_update_type_t; + class ItemData { protected: @@ -48,7 +54,7 @@ public: uint8_t getValue() const; bool getLoaded() const; void setLoaded(bool loaded); - bool isHidden(); + bool isHidden() const; void setHidden(bool hidden); item_value_type_t getValueType(); virtual QString getName() const; @@ -56,24 +62,26 @@ public: virtual void load(const QJsonObject& json, const bool preserve = false); }; +struct ItemUpdateRequest +{ + item_update_type_t type; + ItemData data; + bool valueOnly; +}; + class Item: public QObject, public ItemData { Q_OBJECT private: std::vector< std::shared_ptr > actors_; - bool override_ = false; signals: - void valueChanged(uint8_t value); - void updated(ItemData data); - -private slots: - virtual void actorSetValue(uint8_t value); + void updated(ItemUpdateRequest update); public slots: - void setValue(uint8_t value); + void requestUpdate(ItemUpdateRequest update); public: @@ -83,6 +91,7 @@ public: virtual ~Item(); + Item& operator=(const ItemData& other); std::vector< std::shared_ptr >& getActors(); bool hasActors(); void addActor(std::shared_ptr actor); @@ -91,7 +100,6 @@ public: void setActorsActive(bool in); void setOverride(const bool in); bool getOverride(); - void informValue(uint8_t value); void mergeLoaded(Item& item); virtual void store(QJsonObject& json); diff --git a/src/items/itemstore.cpp b/src/items/itemstore.cpp index 37c3889..e601aee 100644 --- a/src/items/itemstore.cpp +++ b/src/items/itemstore.cpp @@ -9,10 +9,8 @@ ItemStore::ItemStore(QObject *parent): QObject(parent) void ItemStore::addItem(std::shared_ptr item, bool inform) { std::shared_ptr matched = nullptr; - qDebug()<<"referance"<id(); for(unsigned i = 0; i < items_.size(); i++ ) { - qDebug()<<"avail"<id(); if(*items_[i] == *item) { matched = items_[i]; @@ -97,8 +95,9 @@ void ItemStore::updateItem(const ItemData& item, bool inform) else items_[i]->setValue(item.getValue()); } - qDebug()<<"Item"<getName()<<"updated"; - itemUpdated(items_[i]); + qDebug()<<"Item"<getName()<<"updated"<<(inform ? "with inform" : ""); + if(!inform) + itemUpdated(items_[i]); } } } @@ -121,7 +120,10 @@ void ItemStore::itemUpdateSlot(ItemData data) for(std::shared_ptr& item: items_) { if(*item == data) + { + qDebug()<<"Item"<(item)); + } } } diff --git a/src/main.cpp b/src/main.cpp index 8e5ca4c..75c8e3d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) parser.addOption(masterOption); QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main", "Set server host ip addres"), "address", "0.0.0.0"); parser.addOption(hostOption); - QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main", "Set server Port"), "port", "104476"); + QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main", "Set server Port"), "port", "38940"); parser.addOption(portOption); QCommandLineOption settingsPathOption(QStringList()<<"c"<<"config", QCoreApplication::translate("main", "Set config file"), "configFilePath", QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json"); diff --git a/src/sensors/sensor.h b/src/sensors/sensor.h index 10a7316..86fa5cb 100644 --- a/src/sensors/sensor.h +++ b/src/sensors/sensor.h @@ -53,9 +53,11 @@ public: type = static_cast(json["SensorType"].toInt(0)); id = json["Id"].toInt(0); field = json["Field"].toDouble(0); - name = json["Name"].toString("Sensor"); lastSeen = QDateTime::fromString(json["LastSeen"].toString("")); hidden = json["Hidden"].toBool(false); + name = json["Name"].toString(); + if(name == "") + generateName(); } inline bool operator==(const Sensor& in) const { diff --git a/src/ui/itemwidget.ui b/src/ui/itemwidget.ui index 91d92f5..96b625e 100644 --- a/src/ui/itemwidget.ui +++ b/src/ui/itemwidget.ui @@ -46,11 +46,17 @@ 255 - false + true Qt::Orientation::Horizontal + + false + + + false +