blob: 0291d141ff53f14a98509ff5b4c1d2332ca5073f (
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
|
#include "sortresult.h"
#include <QDebug>
#include "die.h"
SortResultNode::SortResultNode()
: m_diceResult(new DiceResult)
{
m_ascending = true;
m_result = m_diceResult;
}
void SortResultNode::run(ExecutionNode* node)
{
if(NULL==node)
{
return;
}
DiceResult* previousDiceResult = static_cast<DiceResult*>(node->getResult());
if(NULL!=previousDiceResult)
{
QList<Die> diceList=previousDiceResult->getResultList();
QList<Die> diceList2=m_diceResult->getResultList();
diceList2 = diceList;
if(!m_ascending)
{
qSort(diceList2.begin(), diceList2.end(), qGreater<Die>());
}
else
{
qSort(diceList2.begin(), diceList2.end(), qLess<Die>());
}
m_diceResult->setResultList(diceList2);
if(NULL!=m_nextNode)
{
m_nextNode->run(this);
}
}
}
void SortResultNode::setSortAscending(bool asc)
{
m_ascending = asc;
}
bool operator<(Die const &a, Die const& b)
{
if(a.getValue()<b.getValue())
return true;
else
return false;
}
|