src/model.cpp

Sun, 03 Nov 2019 12:17:41 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 03 Nov 2019 12:17:41 +0200
changeset 8
44679e468ba9
parent 3
55a55a9ec2c2
child 12
fe67489523b5
permissions
-rw-r--r--

major update with many things

#include <QBrush>
#include <QFont>
#include "model.h"
#include "modeleditcontext.h"

Model::Model()
{

}

int Model::size() const
{
	return this->body.size();
}

Model::EditContext Model::edit()
{
	return {*this};
}

int Model::rowCount(const QModelIndex&) const
{
	return size();
}

QVariant Model::data(const QModelIndex& index, int role) const
{
	const int row = index.row();
	modelobjects::BaseObject* object = this->body[row].get();
	switch(role)
	{
	case Qt::DisplayRole:
		return object->textRepresentation();
	case Qt::ForegroundRole:
		return object->textRepresentationForeground();
	case Qt::BackgroundRole:
		return object->textRepresentationBackground();
	case Qt::FontRole:
		return object->textRepresentationFont();
	default:
		return {};
	}
}

QVariant Model::getHeaderProperty(const HeaderProperty property)
{
	switch (property)
	{
	case HeaderProperty::Name:
		return header.name;
	default:
		return {};
	}
}

void Model::append(ModelObjectPointer&& object)
{
	this->body.push_back(std::move(object));
}

mercurial