wip item refactor
This commit is contained in:
parent
5cd7c782ce
commit
18cf2b01bd
6 changed files with 60 additions and 18 deletions
|
|
@ -79,7 +79,7 @@ bool ItemData::hasChanged(const ItemData& other)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ItemData::isHidden()
|
bool ItemData::isHidden() const
|
||||||
{
|
{
|
||||||
return hidden_;
|
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)
|
void Item::actorSetValue(uint8_t value)
|
||||||
{
|
{
|
||||||
if(!override_ && (programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
|
if(!override_ && (programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
|
||||||
|
|
@ -155,6 +179,7 @@ void Item::setValue(uint8_t value)
|
||||||
{
|
{
|
||||||
qDebug()<<__func__;
|
qDebug()<<__func__;
|
||||||
informValue(value);
|
informValue(value);
|
||||||
|
updated(*this);
|
||||||
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
|
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
|
||||||
enactValue(value);
|
enactValue(value);
|
||||||
}
|
}
|
||||||
|
|
@ -165,7 +190,6 @@ void Item::informValue(uint8_t value)
|
||||||
{
|
{
|
||||||
value_ = value;
|
value_ = value;
|
||||||
valueChanged(value_);
|
valueChanged(value_);
|
||||||
updated(*this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,12 @@ typedef enum {
|
||||||
ITEM_VALUE_NO_VALUE
|
ITEM_VALUE_NO_VALUE
|
||||||
} item_value_type_t;
|
} item_value_type_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ITEM_UPDATE_USER = 0,
|
||||||
|
ITEM_UPDATE_ACTOR,
|
||||||
|
ITEM_UPDATE_REMOTE
|
||||||
|
} item_update_type_t;
|
||||||
|
|
||||||
class ItemData
|
class ItemData
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -48,7 +54,7 @@ public:
|
||||||
uint8_t getValue() const;
|
uint8_t getValue() const;
|
||||||
bool getLoaded() const;
|
bool getLoaded() const;
|
||||||
void setLoaded(bool loaded);
|
void setLoaded(bool loaded);
|
||||||
bool isHidden();
|
bool isHidden() const;
|
||||||
void setHidden(bool hidden);
|
void setHidden(bool hidden);
|
||||||
item_value_type_t getValueType();
|
item_value_type_t getValueType();
|
||||||
virtual QString getName() const;
|
virtual QString getName() const;
|
||||||
|
|
@ -56,24 +62,26 @@ public:
|
||||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
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
|
class Item: public QObject, public ItemData
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
std::vector< std::shared_ptr<Actor> > actors_;
|
std::vector< std::shared_ptr<Actor> > actors_;
|
||||||
|
|
||||||
bool override_ = false;
|
bool override_ = false;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void valueChanged(uint8_t value);
|
void updated(ItemUpdateRequest update);
|
||||||
void updated(ItemData data);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
virtual void actorSetValue(uint8_t value);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setValue(uint8_t value);
|
void requestUpdate(ItemUpdateRequest update);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -83,6 +91,7 @@ public:
|
||||||
|
|
||||||
virtual ~Item();
|
virtual ~Item();
|
||||||
|
|
||||||
|
Item& operator=(const ItemData& other);
|
||||||
std::vector< std::shared_ptr<Actor> >& getActors();
|
std::vector< std::shared_ptr<Actor> >& getActors();
|
||||||
bool hasActors();
|
bool hasActors();
|
||||||
void addActor(std::shared_ptr<Actor> actor);
|
void addActor(std::shared_ptr<Actor> actor);
|
||||||
|
|
@ -91,7 +100,6 @@ public:
|
||||||
void setActorsActive(bool in);
|
void setActorsActive(bool in);
|
||||||
void setOverride(const bool in);
|
void setOverride(const bool in);
|
||||||
bool getOverride();
|
bool getOverride();
|
||||||
void informValue(uint8_t value);
|
|
||||||
void mergeLoaded(Item& item);
|
void mergeLoaded(Item& item);
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,8 @@ ItemStore::ItemStore(QObject *parent): QObject(parent)
|
||||||
void ItemStore::addItem(std::shared_ptr<Item> item, bool inform)
|
void ItemStore::addItem(std::shared_ptr<Item> item, bool inform)
|
||||||
{
|
{
|
||||||
std::shared_ptr<Item> matched = nullptr;
|
std::shared_ptr<Item> matched = nullptr;
|
||||||
qDebug()<<"referance"<<item->id();
|
|
||||||
for(unsigned i = 0; i < items_.size(); i++ )
|
for(unsigned i = 0; i < items_.size(); i++ )
|
||||||
{
|
{
|
||||||
qDebug()<<"avail"<<items_[i]->id();
|
|
||||||
if(*items_[i] == *item)
|
if(*items_[i] == *item)
|
||||||
{
|
{
|
||||||
matched = items_[i];
|
matched = items_[i];
|
||||||
|
|
@ -97,7 +95,8 @@ void ItemStore::updateItem(const ItemData& item, bool inform)
|
||||||
else
|
else
|
||||||
items_[i]->setValue(item.getValue());
|
items_[i]->setValue(item.getValue());
|
||||||
}
|
}
|
||||||
qDebug()<<"Item"<<items_[i]->getName()<<"updated";
|
qDebug()<<"Item"<<items_[i]->getName()<<"updated"<<(inform ? "with inform" : "");
|
||||||
|
if(!inform)
|
||||||
itemUpdated(items_[i]);
|
itemUpdated(items_[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -121,9 +120,12 @@ void ItemStore::itemUpdateSlot(ItemData data)
|
||||||
for(std::shared_ptr<Item>& item: items_)
|
for(std::shared_ptr<Item>& item: items_)
|
||||||
{
|
{
|
||||||
if(*item == data)
|
if(*item == data)
|
||||||
|
{
|
||||||
|
qDebug()<<"Item"<<data.getName()<<"updated from update slot";
|
||||||
itemUpdated(std::weak_ptr<Item>(item));
|
itemUpdated(std::weak_ptr<Item>(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<Item> ItemStore::getItem(uint32_t id)
|
std::shared_ptr<Item> ItemStore::getItem(uint32_t id)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ int main(int argc, char *argv[])
|
||||||
parser.addOption(masterOption);
|
parser.addOption(masterOption);
|
||||||
QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main", "Set server host ip addres"), "address", "0.0.0.0");
|
QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main", "Set server host ip addres"), "address", "0.0.0.0");
|
||||||
parser.addOption(hostOption);
|
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);
|
parser.addOption(portOption);
|
||||||
QCommandLineOption settingsPathOption(QStringList()<<"c"<<"config", QCoreApplication::translate("main", "Set config file"), "configFilePath",
|
QCommandLineOption settingsPathOption(QStringList()<<"c"<<"config", QCoreApplication::translate("main", "Set config file"), "configFilePath",
|
||||||
QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json");
|
QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json");
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,11 @@ public:
|
||||||
type = static_cast<sensor_type_t>(json["SensorType"].toInt(0));
|
type = static_cast<sensor_type_t>(json["SensorType"].toInt(0));
|
||||||
id = json["Id"].toInt(0);
|
id = json["Id"].toInt(0);
|
||||||
field = json["Field"].toDouble(0);
|
field = json["Field"].toDouble(0);
|
||||||
name = json["Name"].toString("Sensor");
|
|
||||||
lastSeen = QDateTime::fromString(json["LastSeen"].toString(""));
|
lastSeen = QDateTime::fromString(json["LastSeen"].toString(""));
|
||||||
hidden = json["Hidden"].toBool(false);
|
hidden = json["Hidden"].toBool(false);
|
||||||
|
name = json["Name"].toString();
|
||||||
|
if(name == "")
|
||||||
|
generateName();
|
||||||
}
|
}
|
||||||
inline bool operator==(const Sensor& in) const
|
inline bool operator==(const Sensor& in) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -46,11 +46,17 @@
|
||||||
<number>255</number>
|
<number>255</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="tracking">
|
<property name="tracking">
|
||||||
<bool>false</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="invertedAppearance">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="invertedControls">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue