diff options
| author | 2020-08-01 14:05:12 +0200 | |
|---|---|---|
| committer | 2020-08-01 20:29:20 +0200 | |
| commit | c35ae0246f09432d4ab54d6216fcab2167318967 (patch) | |
| tree | 9464593530f450780b46639de8d4013e0abf7bed | |
| parent | fc07b874ed64b065eb59b57485bc6a3379700728 (diff) | |
| download | OneRoll-c35ae0246f09432d4ab54d6216fcab2167318967.tar.gz OneRoll-c35ae0246f09432d4ab54d6216fcab2167318967.zip | |
Group Operator can display complex output
| -rw-r--r-- | include/parsingtoolbox.h | 2 | ||||
| -rw-r--r-- | node/groupnode.cpp | 23 | ||||
| -rw-r--r-- | node/groupnode.h | 6 | ||||
| -rw-r--r-- | parsingtoolbox.cpp | 12 |
4 files changed, 36 insertions, 7 deletions
diff --git a/include/parsingtoolbox.h b/include/parsingtoolbox.h index 521c9cf..40d2b33 100644 --- a/include/parsingtoolbox.h +++ b/include/parsingtoolbox.h @@ -382,6 +382,8 @@ public: QList<DiceAlias*>* aliases(); void cleanUpAliases(); + static bool readStringResultParameter(QString& str); + private: QMap<QString, BooleanCondition::LogicOperator> m_logicOp; QMap<QString, ValidatorList::LogicOperation> m_logicOperation; 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 diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index ffa5699..de7fe05 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -1508,10 +1508,11 @@ bool ParsingToolBox::readOption(QString& str, ExecutionNode* previous) //, break; case Group: { + bool stringResult= readStringResultParameter(str); qint64 groupNumber= 0; if(readNumber(str, groupNumber)) { - GroupNode* groupNode= new GroupNode(); + GroupNode* groupNode= new GroupNode(stringResult); groupNode->setGroupValue(groupNumber); previous->setNextNode(groupNode); node= groupNode; @@ -1524,6 +1525,15 @@ bool ParsingToolBox::readOption(QString& str, ExecutionNode* previous) //, } return found; } +bool ParsingToolBox::readStringResultParameter(QString& str) +{ + if(str.startsWith("s")) + { + str.remove(0, 1); + return true; + } + return false; +} bool ParsingToolBox::readIfInstruction(QString& str, ExecutionNode*& trueNode, ExecutionNode*& falseNode) { if(readBlocInstruction(str, trueNode)) |