moved checkable item(s) to separate source files

pull/12/head
mandlm 2018-05-23 08:11:58 +02:00
parent a9718389e8
commit 6ec07a7301
7 changed files with 67 additions and 51 deletions

View File

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

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>