From 0134061fa7e86118feac8080d5e7caf42877079e Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sun, 13 Jan 2019 16:07:30 +0100 Subject: Fix printing errors. --- cli/displaytoolbox.cpp | 104 ++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) (limited to 'cli') diff --git a/cli/displaytoolbox.cpp b/cli/displaytoolbox.cpp index 2edc17f..3c1048f 100644 --- a/cli/displaytoolbox.cpp +++ b/cli/displaytoolbox.cpp @@ -98,11 +98,11 @@ QString DisplayToolBox::makeImage(QString scalarText, QString resultStr,QJsonArr painter.save(); QPen pen = painter.pen(); QColor color; - + auto colorStr = obj["color"].toString(); if(colorStr.isEmpty()) color = QColor(Qt::black); - else + else color.setNamedColor(colorStr); pen.setColor(color); @@ -141,7 +141,7 @@ QString DisplayToolBox::makeImage(QString scalarText, QString resultStr,QJsonArr auto colorStr = obj["color"].toString(); if(colorStr.isEmpty()) color = QColor(Qt::black); - else + else color.setNamedColor(colorStr); pen.setColor(color); @@ -151,7 +151,7 @@ QString DisplayToolBox::makeImage(QString scalarText, QString resultStr,QJsonArr painter.drawText(QPoint(x,y),text); x += fm.boundingRect(text).width(); painter.restore(); - + painter.save(); text = QStringLiteral(")"); if(!last) { @@ -291,30 +291,30 @@ QJsonArray DisplayToolBox::diceToJson(QList& diceList,bool& for(int face: dice.keys()) { ListDiceResult diceResults = dice.value(face); - std::vector> sameColorDice; std::vector alreadyDoneColor; - for(auto & dice : diceResults) + std::vector> sameColorDice; + for(auto & diceResult : diceResults) { - auto it=std::find_if(alreadyDoneColor.begin(), alreadyDoneColor.end(),[dice](QString color){ - return color == dice.getColor(); - }); + if(!diceResult.getColor().isEmpty()) + { + allSameColor = false; + } + auto it=std::find_if(alreadyDoneColor.begin(), alreadyDoneColor.end(),[diceResult](QString color){ + return color == diceResult.getColor(); + }); if( it == alreadyDoneColor.end()) { sameColorDice.push_back(std::vector()); - alreadyDoneColor.push_back(dice.getColor()); + alreadyDoneColor.push_back(diceResult.getColor()); it = alreadyDoneColor.end(); --it; } auto i = std::distance(alreadyDoneColor.begin(), it); - sameColorDice[static_cast(i)].push_back(dice); + sameColorDice[static_cast(i)].push_back(diceResult); } int i = 0; - if(alreadyDoneColor.size()>1) - { - allSameColor = false; - } - for(auto it = alreadyDoneColor.begin() ; it != alreadyDoneColor.end(); ++it) + for(auto it = alreadyDoneColor.begin() ; it != alreadyDoneColor.end() && i < sameColorDice.size() ; ++it) { auto list = sameColorDice[static_cast(i)]; QJsonObject object; @@ -352,7 +352,7 @@ QString DisplayToolBox::diceResultToString(QJsonObject val) QStringList subStr; for(auto subval : subvalues) { - subStr << QString::number(subval.toDouble()); + subStr << QString::number(subval.toDouble()); } if(!subStr.isEmpty()) { @@ -363,43 +363,43 @@ QString DisplayToolBox::diceResultToString(QJsonObject val) QString DisplayToolBox::diceToText(QJsonArray array, bool withColor,bool allSameFaceCount, bool allSameColor) { Q_UNUSED(allSameColor) - QStringList result; - for(auto item : array) - { + QStringList result; + for(auto item : array) + { QString subResult(""); - auto obj = item.toObject(); - auto values= obj["values"].toArray(); + auto obj = item.toObject(); + auto values= obj["values"].toArray(); - QStringList diceResult; - for(auto valRef : values) - { - diceResult += diceResultToString(valRef.toObject()); - } - if (!diceResult.isEmpty()) - { - if(!allSameFaceCount) - { + QStringList diceResult; + for(auto valRef : values) + { + diceResult += diceResultToString(valRef.toObject()); + } + if (!diceResult.isEmpty()) + { + if(!allSameFaceCount) + { subResult += QStringLiteral("d%1:(").arg(obj["face"].toInt()); - } - if(withColor) - { - subResult += DisplayToolBox::colorToTermCode(obj["color"].toString()); - } - subResult += diceResult.join(" "); - if(withColor) - { - subResult += DisplayToolBox::colorToTermCode(QStringLiteral("reset")); - } - if(!allSameFaceCount) - { - subResult += QStringLiteral(")"); - } - } + } + if(withColor) + { + subResult += DisplayToolBox::colorToTermCode(obj["color"].toString()); + } + subResult += diceResult.join(" "); + if(withColor) + { + subResult += DisplayToolBox::colorToTermCode(QStringLiteral("reset")); + } + if(!allSameFaceCount) + { + subResult += QStringLiteral(")"); + } + } - if (!subResult.isEmpty()) - { - result += subResult; - } - } - return result.join(" - "); + if (!subResult.isEmpty()) + { + result += subResult; + } + } + return result.join(" - "); } -- cgit v1.2.3-70-g09d2