added rudimentary genus model class
This commit is contained in:
parent
168d6f6cc9
commit
de9518ae43
@ -12,6 +12,7 @@ qt5_wrap_ui(UI_HEADERS
|
||||
|
||||
add_library(${PROJECT_NAME}
|
||||
GenusWidget.cpp
|
||||
GenusModel.cpp
|
||||
${UI_HEADERS}
|
||||
)
|
||||
|
||||
|
80
source/Genus/GenusModel.cpp
Normal file
80
source/Genus/GenusModel.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
#include "GenusModel.h"
|
||||
|
||||
GenusModel::GenusModel(QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
int GenusModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
int GenusModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
QVariant GenusModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
return "Hello";
|
||||
}
|
||||
|
||||
if (role == Qt::CheckStateRole)
|
||||
{
|
||||
return Qt::Unchecked;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags GenusModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
return QAbstractTableModel::flags(index) | Qt::ItemIsEnabled
|
||||
| Qt::ItemIsUserCheckable;
|
||||
}
|
||||
|
||||
bool GenusModel::setData(
|
||||
const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
if (role != Qt::EditRole)
|
||||
{
|
||||
return QAbstractTableModel::setData(index, value, role);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant GenusModel::headerData(
|
||||
int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
if (orientation == Qt::Vertical)
|
||||
{
|
||||
switch (section)
|
||||
{
|
||||
case 0:
|
||||
return "Tiere";
|
||||
case 1:
|
||||
return "Futter";
|
||||
case 2:
|
||||
return "Zirkus";
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void GenusModel::write(QJsonObject &json) const
|
||||
{
|
||||
}
|
||||
|
||||
void GenusModel::read(const QJsonObject &json)
|
||||
{
|
||||
}
|
25
source/Genus/GenusModel.h
Normal file
25
source/Genus/GenusModel.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QJsonObject>
|
||||
|
||||
class GenusModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GenusModel(QObject *parent);
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(
|
||||
const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole) override;
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
|
||||
void write(QJsonObject &json) const;
|
||||
void read(const QJsonObject &json);
|
||||
};
|
@ -1,11 +1,16 @@
|
||||
#include "GenusWidget.h"
|
||||
#include "ui_GenusWidget.h"
|
||||
|
||||
#include "GenusModel.h"
|
||||
|
||||
GenusWidget::GenusWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::GenusWidget)
|
||||
, m_model(new GenusModel(this))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->tableView->setModel(m_model);
|
||||
}
|
||||
|
||||
GenusWidget::~GenusWidget()
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class GenusModel;
|
||||
|
||||
namespace Ui {
|
||||
class GenusWidget;
|
||||
};
|
||||
@ -12,6 +14,7 @@ class GenusWidget : public QWidget
|
||||
|
||||
private:
|
||||
Ui::GenusWidget *ui;
|
||||
GenusModel *m_model;
|
||||
|
||||
public:
|
||||
GenusWidget(QWidget *parent = nullptr);
|
||||
|
Reference in New Issue
Block a user