forked from ondra/colnod-connector
34 lines
885 B
C++
34 lines
885 B
C++
#include "subject.h"
|
|
|
|
Subject::Subject(const QString &name)
|
|
{
|
|
setName(name);
|
|
}
|
|
|
|
bool Subject::fromJson(const QByteArray &data)
|
|
{
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(data);
|
|
QJsonObject attr = doc.object()["attributes"].toObject()["items"].toObject();
|
|
auto id = doc.object()["id"].toString();
|
|
|
|
for (auto key : attr.keys()) {
|
|
auto newAtr = std::make_shared<SubjectAttribute>();
|
|
newAtr->setId(id + " " + key);
|
|
newAtr->setSubjectId(id);
|
|
newAtr->setAttributeKey(key);
|
|
newAtr->setAttributeValue(attr.value(key).toString());
|
|
attributes.append(newAtr);
|
|
}
|
|
QVariantMap variant = qvariant_cast<QVariantMap>(doc.toVariant());
|
|
|
|
// Populate this object data
|
|
bool res = fromVariantMap(variant);
|
|
return res;
|
|
}
|
|
|
|
QList<std::shared_ptr<SubjectAttribute> > Subject::getAttributes()
|
|
{
|
|
return attributes;
|
|
}
|