aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2020-08-01 14:05:12 +0200
committerRenaud G <renaud@rolisteam.org>2020-08-01 20:29:20 +0200
commitc35ae0246f09432d4ab54d6216fcab2167318967 (patch)
tree9464593530f450780b46639de8d4013e0abf7bed /node
parentfc07b874ed64b065eb59b57485bc6a3379700728 (diff)
downloadOneRoll-c35ae0246f09432d4ab54d6216fcab2167318967.tar.gz
OneRoll-c35ae0246f09432d4ab54d6216fcab2167318967.zip
Group Operator can display complex output
Diffstat (limited to 'node')
-rw-r--r--node/groupnode.cpp23
-rw-r--r--node/groupnode.h6
2 files changed, 23 insertions, 6 deletions
diff --git a/node/groupnode.cpp b/node/groupnode.cpp
index a077bce..0ad5cfe 100644
--- a/node/groupnode.cpp
+++ b/node/groupnode.cpp
@@ -56,12 +56,18 @@ void DieGroup::setExceptedValue(qint64 exceptedValue)
}
//---------------------
-GroupNode::GroupNode() : m_scalarResult(new ScalarResult())
+GroupNode::GroupNode(bool complexOutput)
+ : m_scalarResult(new ScalarResult), m_stringResult(new StringResult), m_complexOutput(complexOutput)
{
- m_result= m_scalarResult;
}
+
void GroupNode::run(ExecutionNode* previous)
{
+ if(m_complexOutput)
+ m_result= m_stringResult;
+ else
+ m_result= m_scalarResult;
+
m_previousNode= previous;
if(nullptr != previous)
{
@@ -83,6 +89,15 @@ void GroupNode::run(ExecutionNode* previous)
{
auto const die= getGroup(allResult);
m_scalarResult->setValue(die.size());
+ QStringList list;
+ for(auto group : die)
+ {
+ QStringList values;
+ std::transform(group.begin(), group.end(), std::back_inserter(values),
+ [](qint64 val) { return QString::number(val); });
+ list << QStringLiteral("{%1}").arg(values.join(","));
+ }
+ m_stringResult->addText(QStringLiteral("%1 (%2)").arg(die.size()).arg(list.join(",")));
}
else
{
@@ -119,7 +134,7 @@ qint64 GroupNode::getPriority() const
}
ExecutionNode* GroupNode::getCopy() const
{
- GroupNode* node= new GroupNode();
+ GroupNode* node= new GroupNode(m_complexOutput);
if(nullptr != m_nextNode)
{
node->setNextNode(m_nextNode->getCopy());
@@ -191,7 +206,7 @@ bool GroupNode::composeWithPrevious(DieGroup previous, qint64 first, qint64 curr
}
}
std::sort(possibleUnion.begin(), possibleUnion.end(),
- [=](const DieGroup& a, const DieGroup& b) { return a.getLost() > b.getLost(); });
+ [=](const DieGroup& a, const DieGroup& b) { return a.getLost() > b.getLost(); });
bool found= false;
for(int i= 0; (!found && i < possibleUnion.size()); ++i)
{
diff --git a/node/groupnode.h b/node/groupnode.h
index afef8c0..84ff2bb 100644
--- a/node/groupnode.h
+++ b/node/groupnode.h
@@ -24,7 +24,7 @@
#include "node/executionnode.h"
#include "result/scalarresult.h"
-// typedef QList<qint64> DieGroup;
+#include "result/stringresult.h"
#include <QList>
class DieGroup : public QList<qint64>
@@ -47,7 +47,7 @@ private:
class GroupNode : public ExecutionNode
{
public:
- GroupNode();
+ GroupNode(bool complexOutput= false);
void run(ExecutionNode* previous);
virtual QString toString(bool withLabel) const;
virtual qint64 getPriority() const;
@@ -63,8 +63,10 @@ protected:
private:
ScalarResult* m_scalarResult;
+ StringResult* m_stringResult;
qint64 m_groupValue;
QList<DieGroup> m_groupsList;
+ bool m_complexOutput= false;
};
#endif // GROUPNODE_H