blob: 979731094c1d320fb57a467dacf81cb45278fad0 (
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
71
72
73
74
75
76
77
78
79
80
|
#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*>());
}*/
for(int i = 0; i<diceList.size();++i)
{
Die* tmp1 = diceList[i];
int j =0;
bool found = false;
for(; ((j < diceList2.size())&&(!found)); ++j)
{
Die* tmp2 = diceList2[j];
// qDebug() << tmp1->getValue() << tmp2->getValue() << j;
if(tmp1->getValue() < tmp2->getValue())
{
found = true;
}
}
if(found)
diceList2.insert(j-1,tmp1);
else
diceList2.append(tmp1);
}
if(!m_ascending)
{
for(int i = 0; i< diceList2.size()/2; ++i)
{
diceList2.swap(i,diceList2.size()-(1+i));
}
}
m_diceResult->setResultList(diceList2);
if(NULL!=m_nextNode)
{
m_nextNode->run(this);
}
}
}
void SortResultNode::setSortAscending(bool asc)
{
m_ascending = asc;
}
|