aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--node/sortresult.cpp47
1 files changed, 32 insertions, 15 deletions
diff --git a/node/sortresult.cpp b/node/sortresult.cpp
index f842fcc..0291d14 100644
--- a/node/sortresult.cpp
+++ b/node/sortresult.cpp
@@ -1,10 +1,14 @@
#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)
{
@@ -12,22 +16,26 @@ void SortResultNode::run(ExecutionNode* node)
{
return;
}
- QList<Die> diceList=node->getResult()->getResultList();
- QList<Die> diceList2=m_result.getResultList();
-
- diceList2 = diceList;
- if(!m_ascending)
- {
- qSort(diceList2.begin(), diceList2.end(), qGreater<int>());
- }
- else
- {
- qSort(diceList2.begin(), diceList2.end(), qLess<int>());
- }
- m_result.setResultList(diceList2);
- if(NULL!=m_nextNode)
+ DiceResult* previousDiceResult = static_cast<DiceResult*>(node->getResult());
+ if(NULL!=previousDiceResult)
{
- m_nextNode->run(this);
+ 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);
+ }
}
}
@@ -35,3 +43,12 @@ 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;
+}