Debugged changing of the assets

This commit is contained in:
Blue 2024-04-07 20:02:00 -03:00
parent aa815a5bd7
commit 4ed280a550
Signed by: blue
GPG key ID: 9B203B252A63EE38
6 changed files with 51 additions and 3 deletions

View file

@ -57,6 +57,20 @@ void Models::Assets::remove (Asset::ID id) {
endRemoveRows();
}
void Models::Assets::change (const Asset& asset) {
int index = getIndexByID(asset.id);
if (index == -1)
throw std::runtime_error("An attempt to change non existing Asset in asset model");
records[index] = asset;
emit dataChanged(createIndex(index, 0, &records[index]), createIndex(index, 0, &records[index]));
}
void Models::Assets::change (const std::deque<Asset>& assets) {
for (const Asset& asset : assets)
change(asset);
}
Models::Asset Models::Assets::get (Asset::ID id) const {
int index = getIndexByID(id);
if (index == -1)
@ -163,7 +177,7 @@ QVariantMap Models::Assets::getAssetByIndex (int index) const {
return result;
QModelIndex idx = createIndex(index, 0, &records[index]);
for (int role = Roles::Title; role != Roles::ID; ++role)
for (int role = Roles::Title; role <= Roles::ID; ++role)
result[roles[role]] = data(idx, role);
return result;

View file

@ -47,6 +47,8 @@ public:
void add (const Asset& asset);
void add (const std::deque<Asset>& assets);
void remove (Asset::ID id);
void change (const Asset& asset);
void change (const std::deque<Asset>& assets);
Asset get(Asset::ID id) const;

View file

@ -221,6 +221,15 @@ bool Models::Magpie::handleAssetChanges (const QVariantMap& changes) {
}
}
aItr = changes.constFind("changed");
if (aItr != changes.constEnd() && aItr.value().canConvert<QVariantList>()) {
std::deque<Models::Asset> changes;
if (!Models::Assets::deserialize(qast<QVariantList>(aItr.value()), changes))
qDebug() << "Error deserializng changed assets";
else
assets.change(changes);
}
return true;
}