Very basic subtest 2 print output

This commit is contained in:
Michael Mandl 2018-12-02 18:26:22 +01:00
parent bcd0b17caa
commit b06e717575
16 changed files with 272 additions and 130 deletions

View file

@ -34,24 +34,3 @@ unsigned int CheckableItem::points() const
{
return m_checked ? m_value : 0;
}
void CheckableItem::write(QJsonObject &json) const
{
json["text"] = m_text.c_str();
json["checked"] = m_checked;
}
void CheckableItem::read(const QJsonObject &json)
{
const auto &text = json["text"];
if (text.isString())
{
m_text = text.toString().toStdString();
}
const auto &checked = json["checked"];
if (checked.isBool())
{
m_checked = checked.toBool();
}
}

View file

@ -24,7 +24,4 @@ public:
void setValue(unsigned int value);
unsigned int points() const;
void write(QJsonObject &json) const;
void read(const QJsonObject &json);
};

View file

@ -2,6 +2,8 @@
#include <QJsonArray>
#include <numeric>
CheckableItems::CheckableItems(std::initializer_list<std::string> itemNames)
{
for (const auto &itemName : itemNames)
@ -10,27 +12,9 @@ CheckableItems::CheckableItems(std::initializer_list<std::string> itemNames)
}
}
void CheckableItems::write(QJsonArray &json) const
unsigned int CheckableItems::getPoints() const
{
for (const auto &item : *this)
{
QJsonObject itemObject;
item.write(itemObject);
json.append(itemObject);
}
}
void CheckableItems::read(const QJsonArray &json)
{
clear();
for (const auto &itemObject : json)
{
if (itemObject.isObject())
{
CheckableItem item;
item.read(itemObject.toObject());
emplace_back(item);
}
}
return std::accumulate(begin(), end(), 0, [](int base, const CheckableItem &item) {
return base + item.points();
});
}

View file

@ -10,6 +10,5 @@ class CheckableItems : public std::vector<CheckableItem>
public:
CheckableItems(std::initializer_list<std::string> itemNames);
void write(QJsonArray &json) const;
void read(const QJsonArray &json);
unsigned int getPoints() const;
};