Merge branch 'tabattempt'

This commit is contained in:
Carl Philipp Klemm 2026-04-06 09:08:18 +02:00
commit cd7d44a5a5
29 changed files with 527 additions and 181 deletions

View file

@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 4.0)
project(SHinterface VERSION 1.0 LANGUAGES CXX) project(SHinterface VERSION 1.0 LANGUAGES CXX)
# Set C++ standard # Set C++ standard
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Enable all warnings # Enable all warnings

View file

@ -24,6 +24,7 @@ void Actor::performValueAction(uint8_t value)
ItemUpdateRequest request; ItemUpdateRequest request;
request.type = ITEM_UPDATE_ACTOR; request.type = ITEM_UPDATE_ACTOR;
request.payload = ItemData(QRandomGenerator::global()->generate(), "Item", value); request.payload = ItemData(QRandomGenerator::global()->generate(), "Item", value);
request.changes.value = true;
sigItemUpdate(request); sigItemUpdate(request);
} }
} }
@ -47,9 +48,12 @@ void Actor::makeInactive()
QString Actor::actionName() QString Actor::actionName()
{ {
QString string; QString string;
if(triggerValue == 0 ) string = "off"; if(triggerValue == 0 )
else if(triggerValue == 1 ) string = "on"; string = "off";
else string = "value to " + QString::number(triggerValue); else if(triggerValue == 1 )
string = "on";
else
string = "value to " + QString::number(triggerValue);
return string; return string;
} }

View file

@ -39,13 +39,13 @@ public:
virtual void load(const QJsonObject& json, const bool preserve = false); virtual void load(const QJsonObject& json, const bool preserve = false);
uint8_t getRepeat(); uint8_t getRepeat();
virtual QString getName() const;
public slots: public slots:
void run(); void run();
virtual void makeActive(); virtual void makeActive();
virtual void makeInactive(); virtual void makeInactive();
virtual QString getName() const;
void doTick(); void doTick();
void changeTime(const QDateTime& time); void changeTime(const QDateTime& time);
void setRepeat(const uint8_t repeat); void setRepeat(const uint8_t repeat);

View file

@ -7,11 +7,13 @@ TimerActor::TimerActor(const int timeoutSec, QObject *parent): Actor(parent), ti
timer.setSingleShot(true); timer.setSingleShot(true);
} }
void TimerActor::onValueChanged(uint8_t state) void TimerActor::onItemUpdated(ItemUpdateRequest update)
{ {
if((state && !triggerValue) || (!state && triggerValue)) if(update.changes.value && ((update.payload.getValue() && !triggerValue) || (!update.payload.getValue() && triggerValue)))
{ {
if(timer.isActive()) timer.stop(); qDebug()<<"Timer started";
if(timer.isActive())
timer.stop();
timer.setInterval(timeoutMsec_); timer.setInterval(timeoutMsec_);
timer.start(); timer.start();
} }

View file

@ -16,15 +16,15 @@ private slots:
public slots: public slots:
virtual void onValueChanged(uint8_t state); virtual void onItemUpdated(ItemUpdateRequest update) override;
void setTimeout(const int timeoutSec); void setTimeout(const int timeoutSec);
public: public:
explicit TimerActor(const int timeoutSec = 60, QObject *parent = nullptr); explicit TimerActor(const int timeoutSec = 60, QObject *parent = nullptr);
virtual QString getName() const; virtual QString getName() const override;
int getTimeout(); int getTimeout();
virtual void store(QJsonObject& json); virtual void store(QJsonObject& json) override;
virtual void load(const QJsonObject& json, bool preserve); virtual void load(const QJsonObject& json, bool preserve) override;
}; };

View file

@ -10,5 +10,19 @@ FixedItemSource::FixedItemSource(Microcontroller* micro, QObject *parent):
void FixedItemSource::refresh() void FixedItemSource::refresh()
{ {
gotItems({powerItem, rgbItem, auxItem}, ITEM_UPDATE_BACKEND); std::vector<ItemAddRequest> requests;
ItemAddRequest request;
request.type = ITEM_UPDATE_BACKEND;
request.payload = powerItem;
requests.push_back(request);
request.payload = rgbItem;
requests.push_back(request);
request.payload = auxItem;
requests.push_back(request);
gotItems(requests);
} }

View file

@ -46,21 +46,49 @@ uint32_t ItemData::id() const
void ItemData::store(QJsonObject &json) void ItemData::store(QJsonObject &json)
{ {
json["Name"] = name_; storeWithChanges(json, ItemFieldChanges(true));
}
void ItemData::storeWithChanges(QJsonObject& json, const ItemFieldChanges& changes)
{
json["ItemId"] = static_cast<double>(itemId_); json["ItemId"] = static_cast<double>(itemId_);
json["ValueType"] = type_;
if(changes.name)
json["Name"] = name_;
if(changes.value)
json["Value"] = static_cast<double>(value_); json["Value"] = static_cast<double>(value_);
if(changes.groupName)
json["GroupName"] = groupName_; json["GroupName"] = groupName_;
} }
void ItemData::load(const QJsonObject &json, const bool preserve) void ItemData::load(const QJsonObject &json, const bool preserve)
{ {
loadWithChanges(json, preserve);
}
ItemFieldChanges ItemData::loadWithChanges(const QJsonObject& json, const bool preserve)
{
ItemFieldChanges changes;
if(!preserve) if(!preserve)
{ {
name_ = json["Name"].toString(name_); if(json.contains("Name"))
itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0)); {
value_ = json["Value"].toInt(); name_ = json["Name"].toString();
groupName_ = json["GroupName"].toString("All"); changes.name = true;
} }
if(json.contains("Value"))
{
value_ = json["Value"].toInt();
changes.value = true;
}
if(json.contains("GroupName"))
{
groupName_ = json["GroupName"].toString();
changes.groupName = true;
}
itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
}
return changes;
} }
bool ItemData::getLoaded() const bool ItemData::getLoaded() const
@ -73,15 +101,23 @@ void ItemData::setLoaded(bool loaded)
loaded_ = loaded; loaded_ = loaded;
} }
bool ItemData::hasChanged(const ItemData& other) bool ItemData::hasChanged(const ItemData& other) const
{ {
if(other != *this) ItemFieldChanges changes(true);
return false; return hasChanged(other, changes);
if(other.getName() != getName()) }
bool ItemData::hasChanged(const ItemData& other, const ItemFieldChanges& changes) const
{
if(changes.name && other.getName() != getName())
return true; return true;
if(other.getValue() != getValue()) if(changes.value && other.getValue() != getValue())
return true; return true;
if(other.getLoaded() != getLoaded()) if(changes.hidden && other.isHidden() != isHidden())
return true;
if(changes.groupName && other.getGroupName() != getGroupName())
return true;
if(changes.actors)
return true; return true;
return false; return false;
} }
@ -143,7 +179,6 @@ void Item::store(QJsonObject &json)
} }
} }
json["Actors"] = actorsArray; json["Actors"] = actorsArray;
json["ValueType"] = type_;
} }
void Item::load(const QJsonObject &json, const bool preserve) void Item::load(const QJsonObject &json, const bool preserve)
@ -175,7 +210,14 @@ Item& Item::operator=(const ItemData& other)
void Item::requestUpdate(ItemUpdateRequest update) void Item::requestUpdate(ItemUpdateRequest update)
{ {
assert(update.type != ITEM_UPDATE_INVALID); assert(update.type != ITEM_UPDATE_INVALID);
if(update.type != ITEM_UPDATE_LOADED && value_ == update.payload.getValue()) assert(!update.changes.isNone());
if(update.type == ITEM_UPDATE_LOADED)
{
qDebug()<<__func__<<update.changes.actors<<update.newActors.size();
}
if(!hasChanged(update.payload, update.changes))
return; return;
if(update.type == ITEM_UPDATE_ACTOR && override_) if(update.type == ITEM_UPDATE_ACTOR && override_)
@ -183,20 +225,24 @@ void Item::requestUpdate(ItemUpdateRequest update)
qDebug()<<"Item Update Request for"<<getName()<<" type "<<update.type<<" value "<<update.payload.getValue(); qDebug()<<"Item Update Request for"<<getName()<<" type "<<update.type<<" value "<<update.payload.getValue();
if(update.type != ITEM_UPDATE_LOADED && if(update.type != ITEM_UPDATE_LOADED && update.type != ITEM_UPDATE_BACKEND &&
update.type != ITEM_UPDATE_BACKEND && (programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY) &&
(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)) update.changes.value)
enactValue(update.payload.getValue()); enactValue(update.payload.getValue());
if(update.type != ITEM_UPDATE_LOADED)
{ if(update.changes.value)
value_ = update.payload.getValue(); value_ = update.payload.getValue();
} if(update.changes.name)
else
{
name_ = update.payload.getName(); name_ = update.payload.getName();
//itemId_ = update.payload.id(); if(update.changes.hidden)
hidden_ = update.payload.isHidden(); hidden_ = update.payload.isHidden();
if(update.changes.groupName)
groupName_ = update.payload.getGroupName();
if(update.changes.type)
type_ = update.payload.getValueType();
if(update.changes.actors)
{
actors_.clear(); actors_.clear();
for(std::shared_ptr<Actor>& actor : update.newActors) for(std::shared_ptr<Actor>& actor : update.newActors)
addActor(actor); addActor(actor);
@ -302,14 +348,12 @@ std::shared_ptr<Item> Item::loadItem(const QJsonObject& json)
return newItem; return newItem;
} }
ItemUpdateRequest Item::createValueUpdateRequest(uint8_t value, ItemUpdateRequest Item::createValueUpdateRequest(item_update_type_t type,
item_update_type_t type,
bool withActors) bool withActors)
{ {
ItemUpdateRequest update; ItemUpdateRequest update;
update.type = type; update.type = type;
update.payload = *this; update.payload = *this;
update.payload.setValueData(value);
if(withActors) if(withActors)
update.newActors = actors_; update.newActors = actors_;
return update; return update;

View file

@ -24,6 +24,9 @@ typedef enum {
ITEM_UPDATE_INVALID ITEM_UPDATE_INVALID
} item_update_type_t; } item_update_type_t;
struct ItemFieldChanges;
struct ItemUpdateRequest;
class ItemData class ItemData
{ {
protected: protected:
@ -43,7 +46,7 @@ public:
bool loaded = false, bool loaded = false,
bool hidden = false, bool hidden = false,
item_value_type_t type = ITEM_VALUE_BOOL, item_value_type_t type = ITEM_VALUE_BOOL,
QString groupName = "All"); QString groupName = "");
inline bool operator==(const ItemData& in) const inline bool operator==(const ItemData& in) const
{ {
@ -56,7 +59,8 @@ public:
uint32_t id() const; uint32_t id() const;
bool hasChanged(const ItemData& other); bool hasChanged(const ItemData& other) const;
bool hasChanged(const ItemData& other, const ItemFieldChanges& changes) const;
void setName(QString name); void setName(QString name);
uint8_t getValue() const; uint8_t getValue() const;
void setValueData(uint8_t value); void setValueData(uint8_t value);
@ -67,19 +71,13 @@ public:
item_value_type_t getValueType(); item_value_type_t getValueType();
QString getGroupName() const; QString getGroupName() const;
void setGroupName(QString groupName); void setGroupName(QString groupName);
void storeWithChanges(QJsonObject& json, const ItemFieldChanges& changes);
ItemFieldChanges loadWithChanges(const QJsonObject& json, const bool preserve = false);
virtual QString getName() const; virtual QString getName() const;
virtual void store(QJsonObject& json); virtual void store(QJsonObject& json);
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 = ITEM_UPDATE_INVALID;
ItemData payload;
std::vector<std::shared_ptr<Actor> > newActors;
};
class Item: public QObject, public ItemData class Item: public QObject, public ItemData
{ {
Q_OBJECT Q_OBJECT
@ -110,8 +108,7 @@ public:
void setActorsActive(bool in); void setActorsActive(bool in);
void setOverride(const bool in); void setOverride(const bool in);
bool getOverride(); bool getOverride();
ItemUpdateRequest createValueUpdateRequest(uint8_t value, ItemUpdateRequest createValueUpdateRequest(item_update_type_t type,
item_update_type_t type,
bool withActors = false); bool withActors = false);
virtual void store(QJsonObject& json); virtual void store(QJsonObject& json);
@ -124,3 +121,52 @@ protected:
}; };
struct ItemFieldChanges
{
bool name :1;
bool value :1;
bool hidden :1;
bool type :1;
bool groupName :1;
bool actors :1;
ItemFieldChanges(bool defaultVal = false)
{
name = defaultVal;
value = defaultVal;
hidden = defaultVal;
type = defaultVal;
groupName = defaultVal;
actors = false;
}
inline bool isNone() const
{
return !name && !value && !hidden && !type && !groupName && !actors;
}
};
struct ItemUpdateRequest
{
item_update_type_t type = ITEM_UPDATE_INVALID;
ItemData payload;
ItemFieldChanges changes;
std::vector<std::shared_ptr<Actor> > newActors;
};
struct ItemAddRequest
{
item_update_type_t type = ITEM_UPDATE_INVALID;
std::shared_ptr<Item> payload;
ItemFieldChanges changes;
inline ItemUpdateRequest updateRequest() const
{
ItemUpdateRequest update;
update.payload = *payload;
update.type = type;
update.changes = changes;
if(changes.actors)
update.newActors = payload->getActors();
return update;
}
};

View file

@ -10,7 +10,7 @@ ItemLoaderSource::ItemLoaderSource(const QJsonObject& json, QObject *parent):
void ItemLoaderSource::refresh() void ItemLoaderSource::refresh()
{ {
std::vector<std::shared_ptr<Item>> items; std::vector<ItemAddRequest> itemAddRequests;
const QJsonArray itemsArray(json["Items"].toArray()); const QJsonArray itemsArray(json["Items"].toArray());
for(int i = 0; i < itemsArray.size(); ++i) for(int i = 0; i < itemsArray.size(); ++i)
{ {
@ -21,11 +21,15 @@ void ItemLoaderSource::refresh()
std::shared_ptr<Item> newItem = Item::loadItem(itemObject); std::shared_ptr<Item> newItem = Item::loadItem(itemObject);
if(newItem) if(newItem)
{ {
items.push_back(newItem);
qDebug()<<"Loaded item"<<newItem->getName(); qDebug()<<"Loaded item"<<newItem->getName();
ItemAddRequest request;
request.type = ITEM_UPDATE_LOADED;
request.payload = newItem;
request.changes = ItemFieldChanges(true);
itemAddRequests.push_back(request);
} }
} }
gotItems(items, ITEM_UPDATE_LOADED); gotItems(itemAddRequests);
} }
void ItemLoaderSource::updateJson(const QJsonObject& json) void ItemLoaderSource::updateJson(const QJsonObject& json)

View file

@ -17,7 +17,7 @@ public slots:
virtual void refresh() = 0; virtual void refresh() = 0;
signals: signals:
void gotItems(std::vector<std::shared_ptr<Item>> items, item_update_type_t updateType); void gotItems(std::vector<ItemAddRequest> items);
void requestReplaceItems(std::vector<std::shared_ptr<Item>> items); void requestReplaceItems(std::vector<std::shared_ptr<Item>> items);
void updateItems(std::vector<ItemUpdateRequest> updates); void updateItems(std::vector<ItemUpdateRequest> updates);
}; };

View file

@ -6,39 +6,38 @@ ItemStore::ItemStore(QObject *parent): QObject(parent)
{ {
} }
void ItemStore::addItem(const std::shared_ptr<Item>& item, item_update_type_t updateType) void ItemStore::addItem(const ItemAddRequest& item)
{ {
qDebug()<<"Item add request for"<<item.payload->getName()<<item.payload->id();
std::shared_ptr<Item> matched = nullptr; std::shared_ptr<Item> matched = nullptr;
for(unsigned i = 0; i < items_.size(); i++ ) for(unsigned i = 0; i < items_.size(); i++ )
{ {
if(*items_[i] == *item) if(*items_[i] == *item.payload)
{ {
matched = items_[i]; matched = items_[i];
assert(matched->id() == items_[i]->id());
break; break;
} }
} }
if(!matched) if(!matched)
{ {
items_.push_back(std::shared_ptr<Item>(item)); items_.push_back(item.payload);
connect(item.get(), &Item::updated, this, &ItemStore::itemUpdateSlot); connect(item.payload.get(), &Item::updated, this, &ItemStore::itemUpdateSlot);
qDebug()<<"Item"<<item->getName()<<"added"<<(item->getLoaded() ? "from loaded" : ""); qDebug()<<"Item"<<item.payload->getName()<<"added"<<(item.payload->getLoaded() ? "from loaded" : "");
itemAdded(std::weak_ptr<Item>(items_.back())); itemAdded(std::weak_ptr<Item>(items_.back()));
} }
else else if(!item.changes.isNone())
{ {
ItemUpdateRequest request = item->createValueUpdateRequest(item->getValue(), qDebug()<<"Item"<<item.payload->getName()<<"was matched with"<<matched->getName()<<"and has changes";
updateType, ItemUpdateRequest request = item.updateRequest();
updateType == ITEM_UPDATE_LOADED);
request.newActors = item->getActors();
updateItem(request); updateItem(request);
} }
} }
void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn, void ItemStore::addItems(const std::vector<ItemAddRequest>& itemIn)
item_update_type_t updateType)
{ {
for(unsigned j = 0; j < itemIn.size(); j++) for(unsigned j = 0; j < itemIn.size(); j++)
addItem(itemIn[j], updateType); addItem(itemIn[j]);
} }
void ItemStore::removeItem(const ItemData& item) void ItemStore::removeItem(const ItemData& item)
@ -57,8 +56,15 @@ void ItemStore::removeItem(const ItemData& item)
void ItemStore::replaceItems(const std::vector<std::shared_ptr<Item>>& items) void ItemStore::replaceItems(const std::vector<std::shared_ptr<Item>>& items)
{ {
qDebug()<<__func__; for(const std::shared_ptr<Item>& item : items)
addItems(items, ITEM_UPDATE_LOADED); {
ItemAddRequest request;
request.changes = ItemFieldChanges(true);
request.changes.actors = true;
request.type = ITEM_UPDATE_LOADED;
request.payload = item;
addItem(request);
}
std::vector<ItemData> deletedItems; std::vector<ItemData> deletedItems;
for(std::shared_ptr<Item> item : items_) for(std::shared_ptr<Item> item : items_)
{ {

View file

@ -39,8 +39,8 @@ signals:
public slots: public slots:
void removeItem(const ItemData& item); void removeItem(const ItemData& item);
void addItem(const std::shared_ptr<Item>& item, item_update_type_t updateType); void addItem(const ItemAddRequest& item);
void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn, item_update_type_t updateType); void addItems(const std::vector<ItemAddRequest>& itemsIn);
void replaceItems(const std::vector<std::shared_ptr<Item>>& items); void replaceItems(const std::vector<std::shared_ptr<Item>>& items);
void updateItems(const std::vector<ItemUpdateRequest>& updates); void updateItems(const std::vector<ItemUpdateRequest>& updates);
void updateItem(const ItemUpdateRequest& update); void updateItem(const ItemUpdateRequest& update);

View file

@ -115,12 +115,7 @@ int main(int argc, char *argv[])
QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), w, SLOT(changeHeaderLableText(QString))); QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), w, SLOT(changeHeaderLableText(QString)));
QObject::connect(w, &MainWindow::sigSetRgb, &mainObject.micro, &Microcontroller::changeRgbColor); QObject::connect(w, &MainWindow::sigSetRgb, &mainObject.micro, &Microcontroller::changeRgbColor);
QObject::connect(w, &MainWindow::sigSave, &mainObject, [&mainObject, settingsPath](){mainObject.storeToDisk(settingsPath);}); QObject::connect(w, &MainWindow::sigSave, &mainObject, [&mainObject, settingsPath](){mainObject.storeToDisk(settingsPath);});
QObject::connect(w, QObject::connect(w, &MainWindow::createdItem, &globalItems, &ItemStore::addItem);
&MainWindow::createdItem,
&globalItems,
[](std::shared_ptr<Item> item) {
globalItems.addItem(item, ITEM_UPDATE_USER);
});
w->show(); w->show();
} }
retVal = a.exec(); retVal = a.exec();
@ -132,9 +127,7 @@ int main(int argc, char *argv[])
{ {
SecondaryMainObject mainObject(parser.value(hostOption), parser.value(portOption).toInt()); SecondaryMainObject mainObject(parser.value(hostOption), parser.value(portOption).toInt());
MainWindow w(&mainObject); MainWindow w(&mainObject);
QObject::connect(&w, &MainWindow::createdItem, &globalItems, [](std::shared_ptr<Item> item) { QObject::connect(&w, &MainWindow::createdItem, &globalItems, &ItemStore::addItem);
globalItems.addItem(item, ITEM_UPDATE_USER);
});
QObject::connect(&w, &MainWindow::sigSave, mainObject.tcpClient, &TcpClient::sendItems); QObject::connect(&w, &MainWindow::sigSave, mainObject.tcpClient, &TcpClient::sendItems);
w.show(); w.show();

View file

@ -157,16 +157,31 @@ void Microcontroller::processList(const QString& buffer)
else if(buffer.contains("EOL")) else if(buffer.contains("EOL"))
{ {
listMode = false; listMode = false;
gotItems(relayList, ITEM_UPDATE_BACKEND); std::vector<ItemAddRequest> requests;
for(const std::shared_ptr<Item>& item : relayList)
{
ItemAddRequest request;
request.changes.name = true;
request.changes.value = true;
request.payload = item;
request.type = ITEM_UPDATE_BACKEND;
requests.push_back(request);
}
gotItems(requests);
relayList.clear(); relayList.clear();
} }
else listMode = false; else
{
listMode = false;
}
} }
void Microcontroller::processRelayState(const QString& buffer) void Microcontroller::processRelayState(const QString& buffer)
{ {
ItemUpdateRequest update; ItemUpdateRequest update;
update.type = ITEM_UPDATE_BACKEND; update.type = ITEM_UPDATE_BACKEND;
update.changes.name = true;
update.changes.value = true;
update.payload = static_cast<ItemData>(*processRelayLine(buffer)); update.payload = static_cast<ItemData>(*processRelayLine(buffer));
updateItems({update}); updateItems({update});
} }

View file

@ -25,6 +25,7 @@ void Server::processIncomeingJson(const QByteArray& jsonbytes)
QJsonArray data = json["Data"].toArray(); QJsonArray data = json["Data"].toArray();
bool FullList = json["FullList"].toBool(false); bool FullList = json["FullList"].toBool(false);
std::vector<std::shared_ptr<Item>> items; std::vector<std::shared_ptr<Item>> items;
std::vector<ItemFieldChanges> fieldChanges;
for(QJsonValueRef itemjson : data) for(QJsonValueRef itemjson : data)
{ {
QJsonObject jsonobject = itemjson.toObject(); QJsonObject jsonobject = itemjson.toObject();
@ -33,6 +34,7 @@ void Server::processIncomeingJson(const QByteArray& jsonbytes)
{ {
qDebug()<<"Server got item"<<item->getName(); qDebug()<<"Server got item"<<item->getName();
item->setLoaded(FullList); item->setLoaded(FullList);
fieldChanges.push_back(item->loadWithChanges(jsonobject));
items.push_back(item); items.push_back(item);
} }
} }
@ -43,7 +45,16 @@ void Server::processIncomeingJson(const QByteArray& jsonbytes)
} }
else if(!items.empty()) else if(!items.empty())
{ {
gotItems(items, ITEM_UPDATE_REMOTE); std::vector<ItemUpdateRequest> updates;
for(size_t i = 0; i < items.size(); i++)
{
ItemUpdateRequest request;
request.payload = *items[i];
request.changes = fieldChanges[i];
request.type = ITEM_UPDATE_REMOTE;
updates.push_back(request);
}
updateItems(updates);
} }
} }
else else

View file

@ -63,7 +63,6 @@ void Service::sendItems()
sendJson(json); sendJson(json);
} }
void Service::processIncomeingJson(const QByteArray& jsonbytes) void Service::processIncomeingJson(const QByteArray& jsonbytes)
{ {
QJsonDocument doc = QJsonDocument::fromJson(jsonbytes); QJsonDocument doc = QJsonDocument::fromJson(jsonbytes);
@ -82,7 +81,6 @@ void Service::processIncomeingJson(const QByteArray& jsonbytes)
else if(type == "SensorUpdate") else if(type == "SensorUpdate")
{ {
QJsonArray data = json["Data"].toArray(); QJsonArray data = json["Data"].toArray();
qWarning()<<"Got sensor update with no/empty sensors array";
for(QJsonValueRef sensorjson : data) for(QJsonValueRef sensorjson : data)
{ {
QJsonObject jsonobject = sensorjson.toObject(); QJsonObject jsonobject = sensorjson.toObject();

View file

@ -34,20 +34,40 @@ void TcpClient::processIncomeingJson(const QByteArray& jsonbytes)
if(type == "ItemUpdate") if(type == "ItemUpdate")
{ {
QJsonArray data = json["Data"].toArray(); QJsonArray data = json["Data"].toArray();
bool FullList = json["FullList"].toBool(false);
std::vector<std::shared_ptr<Item>> items; std::vector<std::shared_ptr<Item>> items;
std::vector<ItemFieldChanges> fieldChanges;
for(QJsonValueRef itemjson : data) for(QJsonValueRef itemjson : data)
{ {
QJsonObject jsonobject = itemjson.toObject(); QJsonObject jsonobject = itemjson.toObject();
std::shared_ptr<Item> item = Item::loadItem(jsonobject); std::shared_ptr<Item> item = Item::loadItem(jsonobject);
if(item) if(item)
{ {
qDebug()<<"Client got item"<<item->getName(); item->setLoaded(FullList);
item->setLoaded(false); fieldChanges.push_back(item->loadWithChanges(jsonobject));
items.push_back(item); items.push_back(item);
} }
} }
if(!items.empty()) if(FullList && !items.empty())
gotItems(items, ITEM_UPDATE_REMOTE); {
qDebug()<<"Client replaceing items";
requestReplaceItems(items);
}
else if(!items.empty())
{
std::vector<ItemAddRequest> itemAddRequests;
qDebug()<<"Client updateing items";
for(size_t i = 0; i < items.size(); i++)
{
ItemAddRequest request;
request.type = ITEM_UPDATE_REMOTE;
request.payload = items[i];
request.changes = fieldChanges[i];
itemAddRequests.push_back(request);
qDebug()<<"Payload"<<request.payload->id();
}
gotItems(itemAddRequests);
}
} }
else else
{ {

View file

@ -106,8 +106,11 @@ ActorSettingsDialog::~ActorSettingsDialog()
void ActorSettingsDialog::editAsItem() void ActorSettingsDialog::editAsItem()
{ {
ItemSettingsDialog itemSettingsDiag(actor_, this); setModal(false);
ItemSettingsDialog itemSettingsDiag(actor_, false, this);
itemSettingsDiag.setModal(false);
itemSettingsDiag.exec(); itemSettingsDiag.exec();
setModal(true);
} }
void ActorSettingsDialog::setEnabled() void ActorSettingsDialog::setEnabled()

View file

@ -1,15 +1,16 @@
#include "itemscrollbox.h" #include "itemscrollbox.h"
#include "ui_relayscrollbox.h" #include "ui_relayscrollbox.h"
#include "../items/auxitem.h" #include <QScrollArea>
#include "../items/messageitem.h" #include <QFrame>
ItemScrollBox::ItemScrollBox(QWidget *parent) : ItemScrollBox::ItemScrollBox(QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::RelayScrollBox) ui(new Ui::RelayScrollBox)
{ {
ui->setupUi(this); ui->setupUi(this);
QScroller::grabGesture(ui->scrollArea, QScroller::TouchGesture);
QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture); ensureTabExists("All");
ui->tabWidget->setCurrentIndex(0);
} }
ItemScrollBox::~ItemScrollBox() ItemScrollBox::~ItemScrollBox()
@ -23,24 +24,166 @@ void ItemScrollBox::addItem(std::weak_ptr<Item> item)
{ {
if(workItem->isHidden()) if(workItem->isHidden())
return; return;
widgets_.push_back(new ItemWidget(item));
ui->relayWidgetVbox->addWidget(widgets_.back()); // Add to "All" tab
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest); widgets_["All"].push_back(new ItemWidget(item, false));
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem); QWidget* allScrollContent = tabs_["All"].content;
QLayout* layout = allScrollContent->layout();
layout->removeItem(tabs_["All"].spacer);
layout->addWidget(widgets_["All"].back());
layout->addItem(tabs_["All"].spacer);
connect(widgets_["All"].back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest);
connect(widgets_["All"].back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem);
addItemToTabs(item);
}
}
void ItemScrollBox::addItemToTabs(std::weak_ptr<Item> item)
{
if(auto workItem = item.lock())
{
if(workItem->isHidden())
return;
QString groupName = workItem->getGroupName();
if(groupName.isEmpty() || groupName != "All")
{
ensureTabExists(groupName);
ItemWidget* groupWidget = new ItemWidget(item, true);
widgets_[groupName].push_back(groupWidget);
QWidget* scrollContent = tabs_[groupName].content;
QLayout* groupLayout = scrollContent->layout();
groupLayout->removeItem(tabs_[groupName].spacer);
groupLayout->addWidget(groupWidget);
groupLayout->addItem(tabs_[groupName].spacer);
connect(groupWidget, &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest);
connect(groupWidget, &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem);
connect(widgets_[groupName].back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest);
connect(widgets_[groupName].back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem);
}
} }
} }
void ItemScrollBox::removeItem(const ItemData& item) void ItemScrollBox::removeItem(const ItemData& item)
{ {
for(unsigned i = 0; i < widgets_.size(); i++) QString key = "All";
std::vector<ItemWidget*>& widgets = widgets_[key];
for(unsigned i = 0; i < widgets.size(); i++)
{ {
if(widgets_[i]->controles(item)) if(widgets[i]->controles(item))
{ {
ui->relayWidgetVbox->removeWidget(widgets_[i]); QWidget* tabContent = tabs_[key].content;
delete widgets_[i]; if(tabContent)
widgets_.erase(widgets_.begin()+i); {
QLayout* layout = tabContent->layout();
if(layout)
layout->removeWidget(widgets[i]);
}
delete widgets[i];
widgets.erase(widgets.begin()+i);
break;
}
}
removeItemFromTabs(item);
cleanupEmptyTabs();
}
void ItemScrollBox::removeItemFromTabs(const ItemData& item)
{
for(const QString& key : widgets_.keys())
{
if(key == "All")
continue;
std::vector<ItemWidget*>& widgets = widgets_[key];
for(unsigned i = 0; i < widgets.size(); i++)
{
if(widgets[i]->controles(item))
{
QWidget* tabContent = tabs_[key].content;
if(tabContent)
{
QLayout* layout = tabContent->layout();
if(layout)
layout->removeWidget(widgets[i]);
}
delete widgets[i];
widgets.erase(widgets.begin()+i);
break;
}
}
}
cleanupEmptyTabs();
}
void ItemScrollBox::onItemUpdate(const ItemUpdateRequest& update)
{
if(!update.changes.groupName)
return;
for(ItemWidget* widget : widgets_["All"])
{
if(widget->controles(update.payload))
{
qDebug()<<"ItemUpdate with group change";
std::weak_ptr<Item> item = widget->getItem();
removeItemFromTabs(update.payload);
addItemToTabs(item);
} }
} }
} }
void ItemScrollBox::ensureTabExists(const QString& groupName)
{
if(!tabs_.contains(groupName))
{
Tab tab;
tab.scroller = new QScrollArea(ui->tabWidget);
tab.scroller->setWidgetResizable(true);
tab.scroller->setFrameShape(QFrame::NoFrame);
tab.scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
tab.content = new QWidget(tab.scroller);
QVBoxLayout* scrollLayout = new QVBoxLayout(tab.content);
scrollLayout->setContentsMargins(0, 0, 0, 0);
tab.content->setLayout(scrollLayout);
tab.content->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
tab.scroller->setWidget(tab.content);
tab.spacer = new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Expanding);
scrollLayout->addSpacerItem(tab.spacer);
ui->tabWidget->addTab(tab.scroller, groupName);
tabs_[groupName] = tab;
}
}
void ItemScrollBox::cleanupEmptyTabs()
{
for(auto it = tabs_.begin(); it != tabs_.end(); ++it)
{
QString groupName = it.key();
if(groupName == "All")
continue;
qDebug()<<__func__<<it.value().content->layout()->count();
if(it.value().content->layout()->count() <= 1)
{
int index = ui->tabWidget->indexOf(tabs_[groupName].scroller);
if(index >= 0)
ui->tabWidget->removeTab(index);
Tab tab = tabs_.take(groupName);
delete tab.content;
delete tab.scroller;
cleanupEmptyTabs();
break;
}
}
}

View file

@ -4,9 +4,9 @@
#include <QWidget> #include <QWidget>
#include <vector> #include <vector>
#include <memory> #include <memory>
#include <QScroller> #include <QScrollArea>
#include <QSpacerItem>
#include "itemwidget.h" #include "itemwidget.h"
#include "../items/relay.h"
#include "../items/item.h" #include "../items/item.h"
#include "../items/itemstore.h" #include "../items/itemstore.h"
@ -20,7 +20,16 @@ class ItemScrollBox : public QWidget
{ {
Q_OBJECT Q_OBJECT
private: private:
std::vector< ItemWidget* > widgets_; struct Tab
{
QScrollArea* scroller;
QWidget* content;
QSpacerItem* spacer;
};
QMap<QString, Tab> tabs_;
QMap<QString, std::vector<ItemWidget*>> widgets_;
Ui::RelayScrollBox *ui;
signals: signals:
void deleteRequest(const ItemData& item); void deleteRequest(const ItemData& item);
@ -36,9 +45,15 @@ public slots:
void addItem(std::weak_ptr<Item> item); void addItem(std::weak_ptr<Item> item);
void removeItem(const ItemData& item); void removeItem(const ItemData& item);
void onItemUpdate(const ItemUpdateRequest& update);
private: private:
Ui::RelayScrollBox *ui; void ensureTabExists(const QString& groupName);
void cleanupEmptyTabs();
private:
void addItemToTabs(std::weak_ptr<Item> item);
void removeItemFromTabs(const ItemData& item);
}; };
#endif // RELAYSCROLLBOX_H #endif // RELAYSCROLLBOX_H

View file

@ -1,5 +1,6 @@
#include "itemsettingsdialog.h" #include "itemsettingsdialog.h"
#include "ui_itemsettingsdialog.h" #include "ui_itemsettingsdialog.h"
#include "../items/itemstore.h"
#include "actorsettingsdialog.h" #include "actorsettingsdialog.h"
#include "../actors/alarmtime.h" #include "../actors/alarmtime.h"
#include "../actors/sensoractor.h" #include "../actors/sensoractor.h"
@ -13,7 +14,7 @@
#include "itemsettingswidgets/relayitemsettingswidget.h" #include "itemsettingswidgets/relayitemsettingswidget.h"
#include<memory> #include<memory>
ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent) : ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr<Item> item, bool noGroup, QWidget *parent) :
QDialog(parent), QDialog(parent),
item_(item), item_(item),
ui(new Ui::ItemSettingsDialog) ui(new Ui::ItemSettingsDialog)
@ -22,9 +23,17 @@ ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *pare
setModal(false); setModal(false);
if(noGroup)
ui->comboBox_Group->setEnabled(false);
ui->label_name->setText(item_->getName()); ui->label_name->setText(item_->getName());
ui->checkBox_Override->setChecked(item_->getOverride()); ui->checkBox_Override->setChecked(item_->getOverride());
// Setup group combobox with editable mode for creating new groups
ui->comboBox_Group->setEditable(true);
ui->comboBox_Group->addItem("All");
ui->comboBox_Group->addItems(getExistingGroups());
ui->comboBox_Group->setCurrentText(item_->getGroupName());
if(std::shared_ptr<Relay> relay = std::dynamic_pointer_cast<Relay>(item_)) if(std::shared_ptr<Relay> relay = std::dynamic_pointer_cast<Relay>(item_))
{ {
@ -48,6 +57,7 @@ ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *pare
connect(ui->pushButton_remove, &QPushButton::clicked, this, &ItemSettingsDialog::removeActor); connect(ui->pushButton_remove, &QPushButton::clicked, this, &ItemSettingsDialog::removeActor);
connect(ui->pushButton_edit, &QPushButton::clicked, this, &ItemSettingsDialog::editActor); connect(ui->pushButton_edit, &QPushButton::clicked, this, &ItemSettingsDialog::editActor);
connect(ui->checkBox_Override, &QPushButton::clicked, this, &ItemSettingsDialog::changeOverride); connect(ui->checkBox_Override, &QPushButton::clicked, this, &ItemSettingsDialog::changeOverride);
connect(ui->comboBox_Group, &QComboBox::currentTextChanged, this, &ItemSettingsDialog::changeGroup);
ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Actor")); ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Actor"));
@ -61,10 +71,23 @@ ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *pare
ItemSettingsDialog::~ItemSettingsDialog() ItemSettingsDialog::~ItemSettingsDialog()
{ {
if(itemSpecificWidget_) delete itemSpecificWidget_; if(itemSpecificWidget_)
delete itemSpecificWidget_;
delete ui; delete ui;
} }
void ItemSettingsDialog::changeGroup()
{
QString newGroup = ui->comboBox_Group->currentText();
if(newGroup != item_->getGroupName())
{
ItemUpdateRequest update = item_->createValueUpdateRequest(ITEM_UPDATE_USER);
update.payload.setGroupName(newGroup);
update.changes.groupName = true;
item_->requestUpdate(update);
}
}
void ItemSettingsDialog::changeOverride() void ItemSettingsDialog::changeOverride()
{ {
item_->setOverride(ui->checkBox_Override->isChecked()); item_->setOverride(ui->checkBox_Override->isChecked());
@ -166,14 +189,21 @@ void ItemSettingsDialog::editActor()
ActorSettingsDialog* dialog; ActorSettingsDialog* dialog;
if(alarmTime) dialog = new ActorSettingsDialog(alarmTime, this); if(alarmTime)
else if(regulator) dialog = new ActorSettingsDialog(regulator, this); dialog = new ActorSettingsDialog(alarmTime, this);
else if(sensorActor) dialog = new ActorSettingsDialog(sensorActor, this); else if(regulator)
else if(timerActor) dialog = new ActorSettingsDialog(timerActor, this); dialog = new ActorSettingsDialog(regulator, this);
else if(polynomalActor) dialog = new ActorSettingsDialog(polynomalActor, this); else if(sensorActor)
else if(factorActor) dialog = new ActorSettingsDialog(factorActor, this); dialog = new ActorSettingsDialog(sensorActor, this);
else dialog = new ActorSettingsDialog(actor, this); else if(timerActor)
dialog->setParent(this); dialog = new ActorSettingsDialog(timerActor, this);
else if(polynomalActor)
dialog = new ActorSettingsDialog(polynomalActor, this);
else if(factorActor)
dialog = new ActorSettingsDialog(factorActor, this);
else
dialog = new ActorSettingsDialog(actor, this);
dialog->show(); dialog->show();
dialog->exec(); dialog->exec();
@ -183,5 +213,19 @@ void ItemSettingsDialog::editActor()
ui->tableWidget->item(i, 1)->setText(item_->getActors()[i]->actionName()); ui->tableWidget->item(i, 1)->setText(item_->getActors()[i]->actionName());
ui->tableWidget->item(i, 2)->setText(item_->getActors()[i]->isActive() ? "Y" : "N"); ui->tableWidget->item(i, 2)->setText(item_->getActors()[i]->isActive() ? "Y" : "N");
} }
delete dialog;
} }
} }
QStringList ItemSettingsDialog::getExistingGroups()
{
QSet<QString> uniqueGroups;
for(const auto& item : *globalItems.getItems())
{
if(!item->getGroupName().isEmpty() && item->getGroupName() != "All")
{
uniqueGroups.insert(item->getGroupName());
}
}
return uniqueGroups.values();
}

View file

@ -19,9 +19,10 @@ class ItemSettingsDialog : public QDialog
private: private:
void loadActorList(); void loadActorList();
QStringList getExistingGroups();
public: public:
explicit ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent = nullptr); explicit ItemSettingsDialog(std::shared_ptr<Item> item, bool noGroup = false, QWidget *parent = nullptr);
~ItemSettingsDialog(); ~ItemSettingsDialog();
private slots: private slots:
@ -30,6 +31,7 @@ private slots:
void addActor(); void addActor();
void editActor(); void editActor();
void changeOverride(); void changeOverride();
void changeGroup();
private: private:
Ui::ItemSettingsDialog *ui; Ui::ItemSettingsDialog *ui;

View file

@ -63,6 +63,20 @@
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"/> <layout class="QVBoxLayout" name="verticalLayout_2"/>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_group">
<item>
<widget class="QLabel" name="label_Group">
<property name="text">
<string>Group:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_Group"/>
</item>
</layout>
</item>
<item> <item>
<widget class="QCheckBox" name="checkBox_Override"> <widget class="QCheckBox" name="checkBox_Override">
<property name="text"> <property name="text">

View file

@ -4,10 +4,12 @@
#include <QCheckBox> #include <QCheckBox>
#include <QDebug> #include <QDebug>
#include <QSlider> #include <QSlider>
#include "itemsettingsdialog.h"
ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) : ItemWidget::ItemWidget(std::weak_ptr<Item> item, bool noGroupEdit, QWidget *parent) :
QWidget(parent), QWidget(parent),
item_(item), item_(item),
noGroupEdit_(noGroupEdit),
ui(new Ui::ItemWidget) ui(new Ui::ItemWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -40,12 +42,13 @@ ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog); connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog);
connect(workingItem.get(), &Item::updated, this, &ItemWidget::onItemUpdated); connect(workingItem.get(), &Item::updated, this, &ItemWidget::onItemUpdated);
connect(ui->pushButton_Remove, &QPushButton::clicked, this, &ItemWidget::deleteItem); connect(ui->pushButton_Remove, &QPushButton::clicked, this, &ItemWidget::deleteItem);
} }
else else
{ {
disable(); disable();
} }
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
} }
void ItemWidget::deleteItem() void ItemWidget::deleteItem()
@ -60,7 +63,9 @@ void ItemWidget::moveToValue(int value)
{ {
if(auto workingItem = item_.lock()) if(auto workingItem = item_.lock())
{ {
ItemUpdateRequest request = workingItem->createValueUpdateRequest(value, ITEM_UPDATE_USER); ItemUpdateRequest request = workingItem->createValueUpdateRequest(ITEM_UPDATE_USER);
request.payload.setValueData(value);
request.changes.value = true;
workingItem->requestUpdate(request); workingItem->requestUpdate(request);
} }
else else
@ -71,15 +76,7 @@ void ItemWidget::moveToValue(int value)
void ItemWidget::moveToState(bool state) void ItemWidget::moveToState(bool state)
{ {
if(auto workingItem = item_.lock()) moveToValue(state);
{
ItemUpdateRequest request = workingItem->createValueUpdateRequest(state, ITEM_UPDATE_USER);
workingItem->requestUpdate(request);
}
else
{
disable();
}
} }
void ItemWidget::disable() void ItemWidget::disable()
@ -104,8 +101,9 @@ void ItemWidget::showSettingsDialog()
{ {
if(auto workingItem = item_.lock()) if(auto workingItem = item_.lock())
{ {
ItemSettingsDialog dialog(workingItem, this); ItemSettingsDialog dialog(workingItem, noGroupEdit_, this);
dialog.exec(); dialog.exec();
} }
else disable(); else disable();
} }

View file

@ -3,7 +3,6 @@
#include <QWidget> #include <QWidget>
#include <memory> #include <memory>
#include "itemsettingsdialog.h"
#include "../items/item.h" #include "../items/item.h"
namespace Ui namespace Ui
@ -16,6 +15,7 @@ class ItemWidget : public QWidget
Q_OBJECT Q_OBJECT
private: private:
std::weak_ptr<Item> item_; std::weak_ptr<Item> item_;
bool noGroupEdit_;
void disable(); void disable();
@ -30,7 +30,7 @@ private slots:
void deleteItem(); void deleteItem();
public: public:
explicit ItemWidget(std::weak_ptr<Item> item, QWidget *parent = nullptr); explicit ItemWidget(std::weak_ptr<Item> item, bool noGroupEdit = false, QWidget *parent = nullptr);
std::weak_ptr<Item> getItem(); std::weak_ptr<Item> getItem();
bool controles(const ItemData& relay); bool controles(const ItemData& relay);
~ItemWidget(); ~ItemWidget();

View file

@ -24,6 +24,7 @@ MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
connect(ui->pushButton_refesh, &QPushButton::clicked, mainObject, &MainObject::refresh); connect(ui->pushButton_refesh, &QPushButton::clicked, mainObject, &MainObject::refresh);
connect(&globalItems, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem); connect(&globalItems, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem);
connect(&globalItems, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem); connect(&globalItems, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem);
connect(&globalItems, &ItemStore::itemUpdated, ui->relayList, &ItemScrollBox::onItemUpdate);
for(size_t i = 0; i < globalItems.getItems()->size(); ++i) for(size_t i = 0; i < globalItems.getItems()->size(); ++i)
ui->relayList->addItem(globalItems.getItems()->at(i)); ui->relayList->addItem(globalItems.getItems()->at(i));
@ -65,7 +66,7 @@ void MainWindow::showPowerItemDialog()
} }
if(powerItem) if(powerItem)
{ {
ItemSettingsDialog diag(std::shared_ptr<Item>(powerItem), this); ItemSettingsDialog diag(std::shared_ptr<Item>(powerItem), false, this);
diag.show(); diag.show();
diag.exec(); diag.exec();
} }
@ -79,7 +80,13 @@ void MainWindow::showItemCreationDialog()
ItemCreationDialog diag(this); ItemCreationDialog diag(this);
diag.show(); diag.show();
if(diag.exec()) if(diag.exec())
createdItem(diag.item); {
ItemAddRequest request;
request.type = ITEM_UPDATE_USER;
request.changes = ItemFieldChanges(true);
request.payload = diag.item;
createdItem(request);
}
} }
void MainWindow::changeHeaderLableText(QString string) void MainWindow::changeHeaderLableText(QString string)

View file

@ -32,7 +32,7 @@ private:
signals: signals:
void sigSave(); void sigSave();
void createdItem(std::shared_ptr<Item> item); void createdItem(ItemAddRequest request);
void sigSetRgb(const QColor color); void sigSetRgb(const QColor color);
private slots: private slots:

View file

@ -94,7 +94,7 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>400</width> <width>350</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>

View file

@ -13,52 +13,15 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>388</width>
<height>288</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QVBoxLayout" name="relayWidgetVbox"/> <widget class="QTabWidget" name="tabWidget">
</item> <property name="tabsClosable">
<item> <bool>false</bool>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="movable">
<size> <bool>true</bool>
<width>20</width>
<height>40</height>
</size>
</property> </property>
</spacer>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
</layout> </layout>