From 80ff2a99b45a25695321cc84a30a3fbf3b797d54 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sat, 10 Oct 2015 17:12:45 +0200 Subject: Add way to disable alias. --- dicealias.cpp | 19 +++++++++++++++++-- dicealias.h | 7 ++++++- diceparser.cpp | 5 ++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/dicealias.cpp b/dicealias.cpp index f9c366c..3e6dc8f 100644 --- a/dicealias.cpp +++ b/dicealias.cpp @@ -22,8 +22,10 @@ #include "dicealias.h" #include -DiceAlias::DiceAlias(QString cmd, QString key, bool isReplace) - : m_command(cmd),m_value(key) +#include + +DiceAlias::DiceAlias(QString cmd, QString key, bool isReplace,bool isEnable) + : m_command(cmd),m_value(key),m_isEnable(isEnable) { if(isReplace) { @@ -42,6 +44,9 @@ DiceAlias::~DiceAlias() bool DiceAlias::resolved(QString & str) { + if(!m_isEnable) + return false; + if((m_type == REPLACE)&&(str.contains(m_command))) { str.replace(m_command,m_value); @@ -97,3 +102,13 @@ void DiceAlias::setReplace(bool b) m_type = REGEXP; } } + +bool DiceAlias::isEnable() +{ + return m_isEnable; +} + +void DiceAlias::setEnable(bool b) +{ + m_isEnable = b; +} diff --git a/dicealias.h b/dicealias.h index 5acca46..a76d47a 100644 --- a/dicealias.h +++ b/dicealias.h @@ -37,7 +37,7 @@ public: * @param key * @param isReplace */ - DiceAlias(QString cmd, QString key, bool isReplace = true); + DiceAlias(QString cmd, QString key, bool isReplace = true, bool isEnable = true); /** * @brief ~DiceAlias */ @@ -82,10 +82,15 @@ public: * @brief setReplace */ void setReplace(bool); + + bool isEnable(); + + void setEnable(bool b); private: QString m_command; QString m_value; RESOLUTION_TYPE m_type; + bool m_isEnable; }; diff --git a/diceparser.cpp b/diceparser.cpp index 802b5f2..10ba2d7 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -128,7 +128,10 @@ QString DiceParser::convertAlias(QString str) { foreach(DiceAlias* cmd, *m_aliasList) { - cmd->resolved(str); + if(cmd->isEnable()) + { + cmd->resolved(str); + } } return str; } -- cgit v1.2.3-70-g09d2 From d271811b7cf700eb22c16e4af30fc6569ac225bb Mon Sep 17 00:00:00 2001 From: Renaud G Date: Wed, 28 Oct 2015 10:56:16 +0100 Subject: Optimization about screen --- booleancondition.cpp | 14 ++++++------- diceparser.cpp | 56 +++++++++++++++++++++++++-------------------------- range.cpp | 2 +- result/diceresult.cpp | 2 +- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/booleancondition.cpp b/booleancondition.cpp index c09166e..40a3804 100644 --- a/booleancondition.cpp +++ b/booleancondition.cpp @@ -83,26 +83,26 @@ void BooleanCondition::setValue(qint64 v) } QString BooleanCondition::toString() { - QString str=""; + QString str(QStringLiteral("")); switch (m_operator) { case Equal: - str.append("="); + str.append(QStringLiteral("=")); break; case GreaterThan: - str.append(">"); + str.append(QStringLiteral(">")); break; case LesserThan: - str.append("<"); + str.append(QStringLiteral("<")); break; case GreaterOrEqual: - str.append(">="); + str.append(QStringLiteral(">=")); break; case LesserOrEqual: - str.append("<="); + str.append(QStringLiteral("<=")); break; } - return QString("[%1%2]").arg(str).arg(m_value); + return QStringLiteral("[%1%2]").arg(str).arg(m_value); } quint64 BooleanCondition::getValidRangeSize(quint64 faces) const { diff --git a/diceparser.cpp b/diceparser.cpp index 144a7d6..53dc305 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -48,17 +48,17 @@ DiceParser::DiceParser() m_parsingToolbox = new ParsingToolBox(); m_mapDiceOp = new QMap(); - m_mapDiceOp->insert("D",D); - m_mapDiceOp->insert("L",L); + m_mapDiceOp->insert(QStringLiteral("D"),D); + m_mapDiceOp->insert(QStringLiteral("L"),L); m_OptionOp = new QMap(); - m_OptionOp->insert(QObject::tr("k"),Keep); - m_OptionOp->insert(QObject::tr("K"),KeepAndExplose); - m_OptionOp->insert(QObject::tr("s"),Sort); - m_OptionOp->insert(QObject::tr("c"),Count); - m_OptionOp->insert(QObject::tr("r"),Reroll); - m_OptionOp->insert(QObject::tr("e"),Explosing); - m_OptionOp->insert(QObject::tr("a"),RerollAndAdd); + m_OptionOp->insert(QStringLiteral("k"),Keep); + m_OptionOp->insert(QStringLiteral("K"),KeepAndExplose); + m_OptionOp->insert(QStringLiteral("s"),Sort); + m_OptionOp->insert(QStringLiteral("c"),Count); + m_OptionOp->insert(QStringLiteral("r"),Reroll); + m_OptionOp->insert(QStringLiteral("e"),Explosing); + m_OptionOp->insert(QStringLiteral("a"),RerollAndAdd); //m_OptionOp->insert(QObject::tr("@"),JumpBackward); @@ -69,11 +69,11 @@ DiceParser::DiceParser() m_aliasList->append(new DiceAlias("(.*)wod(.*)","\\1d10e[=10]c[>=\\2]-@c[=1]",false));*/ m_nodeActionMap = new QMap(); - m_nodeActionMap->insert("@",JumpBackward); + m_nodeActionMap->insert(QStringLiteral("@"),JumpBackward); m_commandList = new QStringList(); - m_commandList->append("help"); - m_commandList->append("la"); + m_commandList->append(QStringLiteral("help")); + m_commandList->append(QStringLiteral("la")); } DiceParser::~DiceParser() @@ -290,8 +290,8 @@ QString DiceParser::displayResult() QTextStream stream(&str); Result* result=next->getResult(); - QString totalValue("you got %1 ;"); - QString dieValue("D%1 : {%2} "); + QString totalValue("you got %1 ;"); + QString dieValue("D%1 : {%2} "); bool scalarDone=false; while(NULL!=result) @@ -315,22 +315,22 @@ QString DiceParser::displayResult() { if(!die->hasBeenDisplayed()) { - resulStr+=QString("%1").arg(die->getValue()); + resulStr+=QStringLiteral("%1").arg(die->getValue()); die->displayed(); face = die->getFaces(); if(die->hasChildrenValue()) { - resulStr+=" ["; + resulStr+=QStringLiteral(" ["); foreach(qint64 i, die->getListValue()) { - resulStr+=QString("%1 ").arg(i); + resulStr+=QStringLiteral("%1 ").arg(i); } resulStr.remove(resulStr.size()-1,1); - resulStr+="]"; + resulStr+=QStringLiteral("]"); } - resulStr+=", "; + resulStr+=QStringLiteral(", "); } } resulStr.remove(resulStr.size()-2,2); @@ -355,7 +355,7 @@ QString DiceParser::displayResult() out << endl; - return QString("%1, you rolled:%3").arg(str.simplified()).arg(m_command) ; + return QStringLiteral("%1, you rolled:%3").arg(str.simplified()).arg(m_command) ; // qDebug() << "result count:" << resulCount; } @@ -653,14 +653,14 @@ bool DiceParser::readCommand(QString& str,ExecutionNode* & node) { if(m_commandList->contains(str)) { - if(str=="help") + if(str== QLatin1String("help")) { HelpNode* help = new HelpNode(); help->setHelpPath(m_helpPath); node = help; } - else if(str=="la") + else if(str== QLatin1String("la")) { node = new ListAliasNode(m_aliasList); } @@ -912,7 +912,7 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous, bool hasDice)/ } else { - m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,QObject::tr("Validator is missing after the %1 operator. Please, change it").arg(m_OptionOp->value(tmp)==Reroll?"r":"a")); + m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,QObject::tr("Validator is missing after the %1 operator. Please, change it").arg(m_OptionOp->value(tmp)==Reroll?QStringLiteral("r"):QStringLiteral("a"))); } } @@ -953,12 +953,12 @@ QMap DiceParser::getErrorMap() QString DiceParser::humanReadableError() { QMapIterator i(m_errorMap); - QString str=""; + QString str(""); while (i.hasNext()) { i.next(); str.append(i.value()); - str.append("\n"); + str.append(QStringLiteral("\n")); } ///list @@ -967,7 +967,7 @@ QString DiceParser::humanReadableError() { j.next(); str.append(j.value()); - str.append("\n"); + str.append(QStringLiteral("\n")); } return str; } @@ -988,9 +988,9 @@ bool DiceParser::readOperand(QString& str,ExecutionNode* & node) } void DiceParser::writeDownDotTree(QString filepath) { - QString str("digraph ExecutionTree {\n"); + QString str(QStringLiteral("digraph ExecutionTree {\n")); m_start->generateDotTree(str); - str.append("}\n"); + str.append(QStringLiteral("}\n")); QFile file(filepath); diff --git a/range.cpp b/range.cpp index 482bcff..30c0812 100644 --- a/range.cpp +++ b/range.cpp @@ -61,7 +61,7 @@ qint64 Range::hasValid(Die* m,bool recursive, bool unhighlight) const } QString Range::toString() { - return QString("[%1-%2]").arg(m_start).arg(m_end); + return QStringLiteral("[%1-%2]").arg(m_start).arg(m_end); } quint64 Range::getValidRangeSize(quint64 faces) const { diff --git a/result/diceresult.cpp b/result/diceresult.cpp index ceb77b8..ffa5d02 100644 --- a/result/diceresult.cpp +++ b/result/diceresult.cpp @@ -90,7 +90,7 @@ QString DiceResult::toString(bool wl) } if(wl) { - return QString("%3 [label=\"DiceResult Value %1 dice %2\"]").arg(getScalarResult()).arg(scalarSum.join('_')).arg(m_id); + return QStringLiteral("%3 [label=\"DiceResult Value %1 dice %2\"]").arg(getScalarResult()).arg(scalarSum.join('_')).arg(m_id); } else { -- cgit v1.2.3-70-g09d2 From f8d2d34a4ac0b9514b6eecac66ba6b54520fa550 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 12 Nov 2015 13:13:16 +0100 Subject: Add enable management of alias --- dicealias.cpp | 14 ++++++++++++-- dicealias.h | 14 +++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/dicealias.cpp b/dicealias.cpp index f9c366c..e7faa2f 100644 --- a/dicealias.cpp +++ b/dicealias.cpp @@ -22,8 +22,8 @@ #include "dicealias.h" #include -DiceAlias::DiceAlias(QString cmd, QString key, bool isReplace) - : m_command(cmd),m_value(key) +DiceAlias::DiceAlias(QString cmd, QString key, bool isReplace, bool isEnable) + : m_command(cmd),m_value(key),m_isEnable(isEnable) { if(isReplace) { @@ -42,6 +42,8 @@ DiceAlias::~DiceAlias() bool DiceAlias::resolved(QString & str) { + if(!m_isEnable) + return false; if((m_type == REPLACE)&&(str.contains(m_command))) { str.replace(m_command,m_value); @@ -97,3 +99,11 @@ void DiceAlias::setReplace(bool b) m_type = REGEXP; } } +bool DiceAlias::isEnable() const +{ + return m_isEnable; +} +void DiceAlias::setEnable(bool b) +{ + m_isEnable = b; +} diff --git a/dicealias.h b/dicealias.h index 5acca46..05d9040 100644 --- a/dicealias.h +++ b/dicealias.h @@ -37,7 +37,7 @@ public: * @param key * @param isReplace */ - DiceAlias(QString cmd, QString key, bool isReplace = true); + DiceAlias(QString cmd, QString key, bool isReplace = true, bool isEnable = true); /** * @brief ~DiceAlias */ @@ -82,10 +82,22 @@ public: * @brief setReplace */ void setReplace(bool); + /** + * @brief isEnable + * @return + */ + bool isEnable() const; + /** + * @brief setEnable + * @param b + */ + void setEnable(bool b); + private: QString m_command; QString m_value; RESOLUTION_TYPE m_type; + bool m_isEnable; }; -- cgit v1.2.3-70-g09d2 From 5cd822edaeebae07450ae3735bd2aaf7a4d28103 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sat, 21 Nov 2015 00:25:36 +0100 Subject: add const --- dicealias.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dicealias.cpp b/dicealias.cpp index 3e6dc8f..84c06d8 100644 --- a/dicealias.cpp +++ b/dicealias.cpp @@ -103,7 +103,7 @@ void DiceAlias::setReplace(bool b) } } -bool DiceAlias::isEnable() +bool DiceAlias::isEnable() const { return m_isEnable; } -- cgit v1.2.3-70-g09d2 From 6a1a9f1c7f3c50d04d89cc54e93d08ed6f2c4cc2 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 8 Jan 2016 20:12:38 +0100 Subject: -Fix cppcheck errors. --- compositevalidator.cpp | 1 + dicealias.cpp | 6 +++--- dicealias.h | 6 +++--- diceparser.cpp | 3 +-- diceparser.h | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compositevalidator.cpp b/compositevalidator.cpp index cc52fdd..167c73b 100644 --- a/compositevalidator.cpp +++ b/compositevalidator.cpp @@ -23,6 +23,7 @@ CompositeValidator::CompositeValidator() + : m_operators(NULL),m_validatorList(NULL) { } qint64 CompositeValidator::hasValid(Die* b,bool recursive,bool unhighlight) const diff --git a/dicealias.cpp b/dicealias.cpp index 84c06d8..59e8d69 100644 --- a/dicealias.cpp +++ b/dicealias.cpp @@ -75,17 +75,17 @@ void DiceAlias::setType(RESOLUTION_TYPE type) { m_type = type; } -QString DiceAlias::getCommand() +QString DiceAlias::getCommand() const { return m_command; } -QString DiceAlias::getValue() +QString DiceAlias::getValue() const { return m_value; } -bool DiceAlias::isReplace() +bool DiceAlias::isReplace() const { return (m_type == REPLACE) ? true : false; } diff --git a/dicealias.h b/dicealias.h index c902957..189b0f9 100644 --- a/dicealias.h +++ b/dicealias.h @@ -67,17 +67,17 @@ public: * @brief getCommand * @return */ - QString getCommand(); + QString getCommand() const; /** * @brief getValue * @return */ - QString getValue(); + QString getValue() const; /** * @brief isReplace * @return */ - bool isReplace(); + bool isReplace() const; /** * @brief setReplace */ diff --git a/diceparser.cpp b/diceparser.cpp index 53dc305..86fbc09 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -499,7 +499,7 @@ void DiceParser::getLastDiceResult(ExportedDiceResult& diceValues) result = result->getPrevious(); } } -QString DiceParser::getDiceCommand() +QString DiceParser::getDiceCommand() const { return m_command; } @@ -701,7 +701,6 @@ bool DiceParser::readInstructionOperator(QChar c) return true; } return false; - } bool DiceParser::readOperator(QString& str,ExecutionNode* previous) diff --git a/diceparser.h b/diceparser.h index 6b9056f..9ef2327 100644 --- a/diceparser.h +++ b/diceparser.h @@ -150,7 +150,7 @@ public: * @brief getDiceCommand * @return */ - QString getDiceCommand(); + QString getDiceCommand() const; /** * @brief hasStringResult * @return -- cgit v1.2.3-70-g09d2 From db15e41502743d1124062eddb8d2bb3617e2593c Mon Sep 17 00:00:00 2001 From: Renaud G Date: Fri, 8 Jan 2016 20:54:21 +0100 Subject: fix cppcheck errors --- diceparser.cpp | 1 - die.cpp | 6 +++--- die.h | 6 +++--- node/scalaroperatornode.cpp | 4 ---- node/scalaroperatornode.h | 6 +++--- parsingtoolbox.cpp | 43 ++++++++----------------------------------- range.cpp | 4 ++-- range.h | 2 +- result/diceresult.cpp | 21 ++++++++++----------- result/result.cpp | 2 +- result/result.h | 2 +- 11 files changed, 32 insertions(+), 65 deletions(-) diff --git a/diceparser.cpp b/diceparser.cpp index 86fbc09..796c3ce 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -114,7 +114,6 @@ DiceParser::~DiceParser() m_start = NULL; } } - ExecutionNode* DiceParser::getLatestNode(ExecutionNode* node) { ExecutionNode* next = node; diff --git a/die.cpp b/die.cpp index 1b4b246..1eb94e0 100644 --- a/die.cpp +++ b/die.cpp @@ -110,7 +110,7 @@ void Die::roll(bool adding) } } -quint64 Die::getFaces() +quint64 Die::getFaces() const { return m_faces; } @@ -128,7 +128,7 @@ qint64 Die::getLastRolledValue() else return 0; } -bool Die::hasBeenDisplayed() +bool Die::hasBeenDisplayed() const { return m_displayStatus; } @@ -141,7 +141,7 @@ void Die::setHighlighted(bool a) m_highlighted = a; } -bool Die::isHighlighted() +bool Die::isHighlighted() const { return m_highlighted; } diff --git a/die.h b/die.h index 2c10894..ffd37a1 100644 --- a/die.h +++ b/die.h @@ -99,12 +99,12 @@ public: * @brief getFaces * @return */ - quint64 getFaces(); + quint64 getFaces() const; /** * @brief hasBeenDisplayed * @return */ - bool hasBeenDisplayed(); + bool hasBeenDisplayed() const; /** * @brief displayed */ @@ -117,7 +117,7 @@ public: * @brief isHighlighted * @return */ - bool isHighlighted(); + bool isHighlighted() const; /** * @brief setBase diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp index f69cb01..67fda8d 100644 --- a/node/scalaroperatornode.cpp +++ b/node/scalaroperatornode.cpp @@ -109,7 +109,6 @@ bool ScalarOperatorNode::setOperatorChar(QChar c) return false; } - void ScalarOperatorNode::setInternalNode(ExecutionNode* node) { m_internalNode = node; @@ -118,12 +117,10 @@ qint64 ScalarOperatorNode::add(qint64 a,qint64 b) { return a+b; } - qint64 ScalarOperatorNode::substract(qint64 a,qint64 b) { return a-b; } - qreal ScalarOperatorNode::divide(qint64 a,qint64 b) { if(b==0) @@ -133,7 +130,6 @@ qreal ScalarOperatorNode::divide(qint64 a,qint64 b) } return (qreal)a/b; } - qint64 ScalarOperatorNode::multiple(qint64 a,qint64 b) { return a*b; diff --git a/node/scalaroperatornode.h b/node/scalaroperatornode.h index ea0f7e1..ca6f3ac 100644 --- a/node/scalaroperatornode.h +++ b/node/scalaroperatornode.h @@ -53,10 +53,10 @@ public: virtual QMap getExecutionErrorMap(); private: - qint64 add(qint64,qint64); - qint64 substract(qint64,qint64); + static qint64 add(qint64,qint64); + static qint64 substract(qint64,qint64); qreal divide(qint64,qint64); - qint64 multiple(qint64,qint64); + static qint64 multiple(qint64,qint64); private: ScalarOperator m_operator; diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index d511e44..495ae6e 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -80,10 +80,6 @@ ParsingToolBox::~ParsingToolBox() Validator* ParsingToolBox::readValidator(QString& str) { Validator* returnVal=NULL; - - bool isOk = true; - - BooleanCondition::LogicOperator myLogicOp = BooleanCondition::Equal; bool hasReadLogicOperator = readLogicOperator(str,myLogicOp); qint64 value=0; @@ -96,41 +92,18 @@ Validator* ParsingToolBox::readValidator(QString& str) qint64 end=0; if(readNumber(str,end)) { - /* if(expectSquareBrasket) - { - if(str.startsWith("]")) - { - str=str.remove(0,1); - isOk=true; - } - else - { - isOk=false; - } - }*/ - if(isOk) - { - str=str.remove(0,1); - Range* range = new Range(); - range->setValue(value,end); - returnVal = range; - } + str=str.remove(0,1); + Range* range = new Range(); + range->setValue(value,end); + returnVal = range; } } else { - /* if((expectSquareBrasket)&&(str.startsWith("]"))) - { - str=str.remove(0,1); - isOk=true; - }*/ - //if(isOk) - { - BooleanCondition* condition = new BooleanCondition(); - condition->setValue(value); - condition->setOperator(myLogicOp); - returnVal = condition; - } + BooleanCondition* condition = new BooleanCondition(); + condition->setValue(value); + condition->setOperator(myLogicOp); + returnVal = condition; } } return returnVal; diff --git a/range.cpp b/range.cpp index 30c0812..337cdc1 100644 --- a/range.cpp +++ b/range.cpp @@ -79,9 +79,9 @@ void Range::setEnd(qint64 end) m_hasEnd = true; } -bool Range::isFullyDefined() +bool Range::isFullyDefined() const { - return (m_hasEnd & m_hasStart); + return (m_hasEnd && m_hasStart); } qint64 Range::getStart() const { diff --git a/range.h b/range.h index f9849ce..75fc69a 100644 --- a/range.h +++ b/range.h @@ -40,7 +40,7 @@ public: virtual QString toString(); virtual quint64 getValidRangeSize(quint64 faces) const; - bool isFullyDefined(); + bool isFullyDefined() const; qint64 getStart() const; qint64 getEnd() const; diff --git a/result/diceresult.cpp b/result/diceresult.cpp index ffa5d02..74aa4e1 100644 --- a/result/diceresult.cpp +++ b/result/diceresult.cpp @@ -46,19 +46,18 @@ DiceResult::~DiceResult() } QVariant DiceResult::getResult(RESULT_TYPE type) { - switch (type) { - case SCALAR: - return getScalarResult(); - break; - case DICE_LIST: - { - return QVariant(); - break; - } - default: - break; + case SCALAR: + { + return getScalarResult(); + } + case DICE_LIST: + { + return QVariant(); + } + default: + break; } return QVariant(); diff --git a/result/result.cpp b/result/result.cpp index 7b6633c..163d539 100644 --- a/result/result.cpp +++ b/result/result.cpp @@ -37,7 +37,7 @@ void Result::setPrevious(Result* p) m_previous = p; } -bool Result::isStringResult() +bool Result::isStringResult() const { return false; } diff --git a/result/result.h b/result/result.h index 3f16535..2a5b7f9 100644 --- a/result/result.h +++ b/result/result.h @@ -62,7 +62,7 @@ public: * @brief isStringResult * @return */ - bool isStringResult(); + virtual bool isStringResult() const; /** * @brief getStringResult -- cgit v1.2.3-70-g09d2