From 3a4149d66a300f9e762a4379e403faf31e7d03c7 Mon Sep 17 00:00:00 2001 From: obiwankennedy Date: Tue, 7 Jan 2014 18:57:45 +0100 Subject: Update sortresult.cpp add diceresult --- node/sortresult.cpp | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'node/sortresult.cpp') 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 +#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 diceList=node->getResult()->getResultList(); - QList diceList2=m_result.getResultList(); - - diceList2 = diceList; - if(!m_ascending) - { - qSort(diceList2.begin(), diceList2.end(), qGreater()); - } - else - { - qSort(diceList2.begin(), diceList2.end(), qLess()); - } - m_result.setResultList(diceList2); - if(NULL!=m_nextNode) + DiceResult* previousDiceResult = static_cast(node->getResult()); + if(NULL!=previousDiceResult) { - m_nextNode->run(this); + QList diceList=previousDiceResult->getResultList(); + QList diceList2=m_diceResult->getResultList(); + + diceList2 = diceList; + if(!m_ascending) + { + qSort(diceList2.begin(), diceList2.end(), qGreater()); + } + else + { + qSort(diceList2.begin(), diceList2.end(), qLess()); + } + 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()