moved checkable item(s) to separate source files

This commit is contained in:
Michael Mandl 2018-05-23 08:11:58 +02:00
parent a9718389e8
commit 6ec07a7301
7 changed files with 67 additions and 51 deletions

View file

@ -13,6 +13,8 @@ qt5_wrap_ui(UI_HEADERS
add_library(${PROJECT_NAME}
GenusWidget.cpp
GenusModel.cpp
CheckableItem.cpp
CheckableItems.cpp
${UI_HEADERS}
)

View file

@ -0,0 +1,21 @@
#include "CheckableItem.h"
CheckableItem::CheckableItem(const std::string &text)
: m_text(text)
{
}
std::string CheckableItem::getText() const
{
return m_text;
}
bool CheckableItem::isChecked() const
{
return m_checked;
}
void CheckableItem::setState(bool checked)
{
m_checked = checked;
}

View file

@ -0,0 +1,17 @@
#pragma once
#include <string>
class CheckableItem
{
private:
bool m_checked = false;
std::string m_text;
public:
CheckableItem(const std::string &text);
std::string getText() const;
bool isChecked() const;
void setState(bool checked);
};

View file

@ -0,0 +1,10 @@
#include "CheckableItems.h"
void CheckableItems::write(QJsonObject &json) const
{
for (const auto &pair : *this)
{
json[pair.second.getText().c_str()] =
pair.second.isChecked();
}
}

View file

@ -0,0 +1,14 @@
#pragma once
#include "CheckableItem.h"
#include <QJsonObject>
#include <map>
class CheckableItems : public std::map<size_t, CheckableItem>
{
public:
using std::map<size_t, CheckableItem>::map;
void write(QJsonObject &json) const;
};

View file

@ -2,15 +2,6 @@
#include <QDebug>
void CheckableItems::write(QJsonObject &json) const
{
for (const auto &pair : *this)
{
json[pair.second.getText().c_str()] =
pair.second.isChecked();
}
}
GenusModel::GenusModel(QObject *parent)
: QAbstractTableModel(parent)
{

View file

@ -1,46 +1,7 @@
#pragma once
#include <string>
class CheckableItem
{
private:
bool m_checked = false;
std::string m_text;
public:
CheckableItem(const std::string &text)
: m_text(text)
{
}
std::string getText() const
{
return m_text;
}
bool isChecked() const
{
return m_checked;
}
void setState(bool checked)
{
m_checked = checked;
}
};
#include <QJsonObject>
#include <map>
class CheckableItems : public std::map<size_t, CheckableItem>
{
public:
using std::map<size_t, CheckableItem>::map;
void write(QJsonObject &json) const;
};
#include "CheckableItem.h"
#include "CheckableItems.h"
#include <QAbstractTableModel>