aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/result/stringresult.cpp
blob: d5a7880be326660845e18fba41544d10c02fd17c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "stringresult.h"

StringResult::StringResult()
{
    m_highlight= true;
    m_resultTypes= static_cast<int>(Dice::RESULT_TYPE::STRING);
}
void StringResult::setText(QString text)
{
    m_value= text;
}
StringResult::~StringResult() {}
bool StringResult::hasResultOfType(Dice::RESULT_TYPE resultType) const
{

    if(resultType == Dice::RESULT_TYPE::STRING)
    {
        return true;
    }
    else if(resultType == Dice::RESULT_TYPE::SCALAR)
    {
        bool ok= false;
        getText().toInt(&ok);
        return ok;
    }
    return false;
}
QString StringResult::getText() const
{
    return m_value;
}
QVariant StringResult::getResult(Dice::RESULT_TYPE type)
{
    switch(type)
    {
    case Dice::RESULT_TYPE::STRING:
        return getText();
    case Dice::RESULT_TYPE::SCALAR:
        return getText().toInt();
    default:
        return QVariant();
    }
}
QString StringResult::toString(bool wl)
{
    if(wl)
    {
        return QString("%2 [label=\"StringResult_value_%1\"]").arg(getText().replace("%", "_"), m_id);
    }
    else
    {
        return m_id;
    }
}
void StringResult::setHighLight(bool b)
{
    m_highlight= b;
}

bool StringResult::hasHighLight() const
{
    return m_highlight;
}
Result* StringResult::getCopy() const
{
    auto copy= new StringResult();
    copy->setHighLight(m_highlight);
    copy->setText(m_value);
    return copy;
}