Source

AncientDocumentEditor / documentImageCreator / src / framework / DocumentCreator / models / character.cpp

Full commit
#include "character.h"

#include <QDateTime>

namespace Models
{
    Character::Character()
    {
        initialize("unassigned_name", 0, 100, 0, 100);
    }
    Character::Character(QString s)
    {
        initialize(s,0, 100, 0, 100);
    }
    Character::Character(QString s, qreal upLine, qreal baseLine,
                          qreal leftLine, qreal rightLine)
    {
        initialize(s, upLine, baseLine, leftLine, rightLine);
    }

    void Character::add(CharacterData* cd)
    {
        if (this->_dataMap.values().contains(cd))
            return;

        this->_dataMap.insert(cd->getId(), cd);
    }

    /* Setters */
    void Character::setCharacterValue(QString s)
    {
        this->_charValue = s;
    }
    void Character::setBaseLine(qreal value)
    {
        this->_baseLine = value;
    }
    void Character::setUpLine(qreal value)
    {
        this->_upLine = value;
    }
    void Character::setLeftLine(qreal value)
    {
        this->_leftLine = value;
    }
    void Character::setRightLine(qreal value)
    {
        this->_rightLine = value;

    }

	void Character::setAllBaseLines(qreal up, qreal base, qreal left, qreal right)
	{
		setBaseLine(base);
		setUpLine(up);
		setLeftLine(left);
		setRightLine(right);
	}

    /* Getters */
    CharacterData* Character::getRandomCharacterData() const
    {
        if (this->_dataMap.values().isEmpty())
            return NULL;

        int r = qrand();
        QAtomicInt randomIndex = r % _dataMap.keys().length();

		return this->_dataMap.values().at(randomIndex);
    }

    CharacterData* Character::getCharacterData(QAtomicInt id) const
    {
        if (this->_dataMap.contains(id))
            return this->_dataMap[id];

        return NULL;
    }
    CharacterDataList Character::getAllCharacterData() const
    {
        return (CharacterDataList)this->_dataMap.values();
    }
    QString Character::getCharacterValue() const
    {
        return this->_charValue;
    }
    qreal Character::getBaseLine() const
    {
        return this->_baseLine;
    }
    qreal Character::getUpLine() const
    {
        return this->_upLine;
    }
    qreal Character::getLeftLine() const
    {
        return this->_leftLine;
    }
    qreal Character::getRightLine() const
    {
        return this->_rightLine;
    }

    /* Private methods */
    void Character::initialize(QString s, qreal upLine, qreal baseLine,
                          qreal leftLine, qreal rightLine)
    {
        this->_charValue = s;
        this->_baseLine = baseLine;
        this->_upLine = upLine;
        this->_leftLine = leftLine;
        this->_rightLine = rightLine;
    }
} // Models