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