formatting and include fix
This commit is contained in:
parent
27ace83ddd
commit
060933f716
8 changed files with 85 additions and 83 deletions
|
@ -1,42 +1,42 @@
|
|||
#include "CheckableItem.h"
|
||||
|
||||
CheckableItem::CheckableItem(const std::string &text)
|
||||
: m_text(text)
|
||||
: m_text(text)
|
||||
{
|
||||
}
|
||||
|
||||
std::string CheckableItem::getText() const
|
||||
{
|
||||
return m_text;
|
||||
return m_text;
|
||||
}
|
||||
|
||||
bool CheckableItem::isChecked() const
|
||||
{
|
||||
return m_checked;
|
||||
return m_checked;
|
||||
}
|
||||
|
||||
void CheckableItem::setState(bool checked)
|
||||
{
|
||||
m_checked = checked;
|
||||
m_checked = checked;
|
||||
}
|
||||
|
||||
void CheckableItem::write(QJsonObject &json) const
|
||||
{
|
||||
json["text"] = m_text.c_str();
|
||||
json["checked"] = m_checked;
|
||||
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 &text = json["text"];
|
||||
if (text.isString())
|
||||
{
|
||||
m_text = text.toString().toStdString();
|
||||
}
|
||||
|
||||
const auto &checked = json["checked"];
|
||||
if (checked.isBool())
|
||||
{
|
||||
m_checked = checked.toBool();
|
||||
}
|
||||
const auto &checked = json["checked"];
|
||||
if (checked.isBool())
|
||||
{
|
||||
m_checked = checked.toBool();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,17 +7,17 @@
|
|||
class CheckableItem
|
||||
{
|
||||
private:
|
||||
bool m_checked = false;
|
||||
std::string m_text;
|
||||
bool m_checked = false;
|
||||
std::string m_text;
|
||||
|
||||
public:
|
||||
CheckableItem() = default;
|
||||
CheckableItem(const std::string &text);
|
||||
CheckableItem() = default;
|
||||
CheckableItem(const std::string &text);
|
||||
|
||||
std::string getText() const;
|
||||
bool isChecked() const;
|
||||
void setState(bool checked);
|
||||
std::string getText() const;
|
||||
bool isChecked() const;
|
||||
void setState(bool checked);
|
||||
|
||||
void write(QJsonObject &json) const;
|
||||
void read(const QJsonObject &json);
|
||||
void write(QJsonObject &json) const;
|
||||
void read(const QJsonObject &json);
|
||||
};
|
||||
|
|
|
@ -4,33 +4,33 @@
|
|||
|
||||
CheckableItems::CheckableItems(std::initializer_list<std::string> itemNames)
|
||||
{
|
||||
for (const auto &itemName : itemNames)
|
||||
{
|
||||
emplace_back(itemName);
|
||||
}
|
||||
for (const auto &itemName : itemNames)
|
||||
{
|
||||
emplace_back(itemName);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckableItems::write(QJsonArray &json) const
|
||||
{
|
||||
for (const auto &item : *this)
|
||||
{
|
||||
QJsonObject itemObject;
|
||||
item.write(itemObject);
|
||||
json.append(itemObject);
|
||||
}
|
||||
for (const auto &item : *this)
|
||||
{
|
||||
QJsonObject itemObject;
|
||||
item.write(itemObject);
|
||||
json.append(itemObject);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckableItems::read(const QJsonArray &json)
|
||||
{
|
||||
clear();
|
||||
clear();
|
||||
|
||||
for (const auto &itemObject : json)
|
||||
{
|
||||
if (itemObject.isObject())
|
||||
{
|
||||
CheckableItem item;
|
||||
item.read(itemObject.toObject());
|
||||
emplace_back(item);
|
||||
}
|
||||
}
|
||||
for (const auto &itemObject : json)
|
||||
{
|
||||
if (itemObject.isObject())
|
||||
{
|
||||
CheckableItem item;
|
||||
item.read(itemObject.toObject());
|
||||
emplace_back(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
#include "CheckableItem.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class CheckableItems : public std::vector<CheckableItem>
|
||||
{
|
||||
public:
|
||||
CheckableItems(std::initializer_list<std::string> itemNames);
|
||||
CheckableItems(std::initializer_list<std::string> itemNames);
|
||||
|
||||
void write(QJsonArray &json) const;
|
||||
void read(const QJsonArray &json);
|
||||
void write(QJsonArray &json) const;
|
||||
void read(const QJsonArray &json);
|
||||
};
|
||||
|
|
|
@ -105,35 +105,35 @@ QVariant GenusModel::headerData(
|
|||
|
||||
void GenusModel::write(QJsonObject &json) const
|
||||
{
|
||||
QJsonArray tiere;
|
||||
QJsonArray tiere;
|
||||
m_tiere.write(tiere);
|
||||
json["Tiere"] = tiere;
|
||||
|
||||
QJsonArray futter;
|
||||
QJsonArray futter;
|
||||
m_futter.write(futter);
|
||||
json["Futter"] = futter;
|
||||
|
||||
QJsonArray zirkus;
|
||||
QJsonArray zirkus;
|
||||
m_zirkus.write(zirkus);
|
||||
json["Zirkus"] = zirkus;
|
||||
}
|
||||
|
||||
void GenusModel::read(const QJsonObject &json)
|
||||
{
|
||||
if (json["Tiere"].isArray())
|
||||
{
|
||||
m_tiere.read(json["Tiere"].toArray());
|
||||
}
|
||||
if (json["Tiere"].isArray())
|
||||
{
|
||||
m_tiere.read(json["Tiere"].toArray());
|
||||
}
|
||||
|
||||
if (json["Futter"].isArray())
|
||||
{
|
||||
m_futter.read(json["Futter"].toArray());
|
||||
}
|
||||
if (json["Futter"].isArray())
|
||||
{
|
||||
m_futter.read(json["Futter"].toArray());
|
||||
}
|
||||
|
||||
if (json["Zirkus"].isArray())
|
||||
{
|
||||
m_zirkus.read(json["Zirkus"].toArray());
|
||||
}
|
||||
if (json["Zirkus"].isArray())
|
||||
{
|
||||
m_zirkus.read(json["Zirkus"].toArray());
|
||||
}
|
||||
}
|
||||
|
||||
bool GenusModel::isValidIndex(const QModelIndex &index) const
|
||||
|
@ -141,11 +141,11 @@ bool GenusModel::isValidIndex(const QModelIndex &index) const
|
|||
switch (index.row())
|
||||
{
|
||||
case 0:
|
||||
return index.column() < m_tiere.size();
|
||||
return index.column() < m_tiere.size();
|
||||
case 1:
|
||||
return index.column() < m_futter.size();
|
||||
return index.column() < m_futter.size();
|
||||
case 2:
|
||||
return index.column() < m_zirkus.size();
|
||||
return index.column() < m_zirkus.size();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -188,21 +188,21 @@ const CheckableItems &GenusModel::getItems(const QModelIndex &index) const
|
|||
CheckableItem &GenusModel::getItem(const QModelIndex &index)
|
||||
{
|
||||
auto &items = getItems(index);
|
||||
if (index.column() < items.size())
|
||||
{
|
||||
return items.at(index.column());
|
||||
}
|
||||
if (index.column() < items.size())
|
||||
{
|
||||
return items.at(index.column());
|
||||
}
|
||||
|
||||
throw std::runtime_error("invalid index");
|
||||
}
|
||||
|
||||
const CheckableItem &GenusModel::getItem(const QModelIndex &index) const
|
||||
{
|
||||
auto &items = getItems(index);
|
||||
if (index.column() < items.size())
|
||||
{
|
||||
return items.at(index.column());
|
||||
}
|
||||
auto &items = getItems(index);
|
||||
if (index.column() < items.size())
|
||||
{
|
||||
return items.at(index.column());
|
||||
}
|
||||
|
||||
throw std::runtime_error("invalid index");
|
||||
}
|
||||
|
|
|
@ -10,9 +10,11 @@ class GenusModel : public QAbstractTableModel
|
|||
Q_OBJECT
|
||||
|
||||
private:
|
||||
CheckableItems m_tiere = { "Tiger", "Bär", "Katze", "Pferd", "Gans", "Elefant", "Katze", "Hund" };
|
||||
CheckableItems m_futter = { "Salat", "Fleisch", "Knocken", "Banane", "Apfel", "Möhre", "Honig", "Zucker" };
|
||||
CheckableItems m_zirkus = { "Kiste", "Holz", "Vorhang", "Baum" };
|
||||
CheckableItems m_tiere = {
|
||||
"Tiger", "Bär", "Katze", "Pferd", "Gans", "Elefant", "Katze", "Hund"};
|
||||
CheckableItems m_futter = {"Salat", "Fleisch", "Knocken", "Banane", "Apfel",
|
||||
"Möhre", "Honig", "Zucker"};
|
||||
CheckableItems m_zirkus = {"Kiste", "Holz", "Vorhang", "Baum"};
|
||||
|
||||
public:
|
||||
GenusModel(QObject *parent);
|
||||
|
|
|
@ -9,15 +9,15 @@ GenusWidget::GenusWidget(QWidget *parent)
|
|||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->genusTableView->horizontalHeader()->hide();
|
||||
ui->genusTableView->horizontalHeader()->hide();
|
||||
}
|
||||
|
||||
GenusWidget::~GenusWidget()
|
||||
{
|
||||
delete ui;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void GenusWidget::setModel(GenusModel *model)
|
||||
{
|
||||
ui->genusTableView->setModel(model);
|
||||
ui->genusTableView->setModel(model);
|
||||
}
|
||||
|
|
|
@ -19,5 +19,5 @@ public:
|
|||
GenusWidget(QWidget *parent = nullptr);
|
||||
~GenusWidget();
|
||||
|
||||
void setModel(GenusModel *model);
|
||||
void setModel(GenusModel *model);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue