From 186af57e85671f0c9c4b2b1faf0d2065f4b0f222 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Tue, 21 Apr 2015 10:43:08 +0200 Subject: prepare much better way to give the result --- diceparser.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'diceparser.cpp') diff --git a/diceparser.cpp b/diceparser.cpp index 6933071..a2fa137 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -400,10 +400,12 @@ QString DiceParser::getStringResult() QString DiceParser::getLastDiceResult() { ExecutionNode* next = getLeafNode(); - QString str; - QTextStream stream(&str); + // QString str; + // QTextStream stream(&str); Result* result=next->getResult(); - QString dieValue("D%1 : {%2} "); + QMap diceValues; + //QString dieValue("%2 (D%1)"); + bool first=true; while(NULL!=result) { if(result->hasResultOfType(Result::DICE_LIST)) @@ -423,17 +425,16 @@ QString DiceParser::getLastDiceResult() die->displayed(); face = die->getFaces(); - if(die->hasChildrenValue()) { - resulStr+=" ["; + QString childDice(""); foreach(qint64 i, die->getListValue()) { - resulStr+=QString("%1,").arg(i); + childDice+=QString("%1,").arg(i); } - resulStr.remove(resulStr.size()-1,1); - resulStr+="]"; + childDice.remove(childDice.size()-1,1); + resulStr+=QString("[%1]").arg(childDice); } resulStr+=", "; } @@ -442,7 +443,17 @@ QString DiceParser::getLastDiceResult() if(!resulStr.isEmpty()) { - stream << dieValue.arg(face).arg(resulStr); + if(!diceValues.contains(face)) + { + diceValues.insert(face,resulStr); + } + else + { + QString tmp = diceValues.value(face); + tmp+=resulStr; + diceValues.insert(face,tmp); + } + //stream << dieValue.arg(face).arg(resulStr); } } } @@ -450,7 +461,8 @@ QString DiceParser::getLastDiceResult() result = result->getPrevious(); } - return str.simplified(); + //return str.simplified(); + return diceValues; } QString DiceParser::getDiceCommand() { -- cgit v1.2.3-70-g09d2