diff options
| author | 2014-01-07 18:57:45 +0100 | |
|---|---|---|
| committer | 2014-01-07 18:57:45 +0100 | |
| commit | 3a4149d66a300f9e762a4379e403faf31e7d03c7 (patch) | |
| tree | 2a5a95bf87b9ed8004c8db27515c33014d7780fc /node/sortresult.cpp | |
| parent | e589d00842a2b64721b94f89a48f54aa3478dd40 (diff) | |
| download | OneRoll-3a4149d66a300f9e762a4379e403faf31e7d03c7.tar.gz OneRoll-3a4149d66a300f9e762a4379e403faf31e7d03c7.zip | |
Update sortresult.cpp
add diceresult
Diffstat (limited to 'node/sortresult.cpp')
| -rw-r--r-- | node/sortresult.cpp | 47 |
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; +} |