From a817fcbaa3350a59790d9b264d8eb613df80703d Mon Sep 17 00:00:00 2001 From: Renaud G Date: Sun, 28 Jul 2019 01:41:34 +0200 Subject: Add bool return to manage no parameter on painter node --- include/parsingtoolbox.h | 2 +- parsingtoolbox.cpp | 38 +++++++++++++++++++++----------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/include/parsingtoolbox.h b/include/parsingtoolbox.h index 9e246d6..8d5f62b 100644 --- a/include/parsingtoolbox.h +++ b/include/parsingtoolbox.h @@ -206,7 +206,7 @@ public: bool readArithmeticOperator(QString& str, Die::ArithmeticOperator& op); - static void readPainterParameter(PainterNode* painter, QString& str); + static bool readPainterParameter(PainterNode* painter, QString& str); static QHash getVariableHash(); static void setVariableHash(const QHash& variableHash); diff --git a/parsingtoolbox.cpp b/parsingtoolbox.cpp index 4084825..7caeefe 100644 --- a/parsingtoolbox.cpp +++ b/parsingtoolbox.cpp @@ -661,28 +661,32 @@ ParsingToolBox::LIST_OPERATOR ParsingToolBox::readListOperator(QString& str) return NONE; } -void ParsingToolBox::readPainterParameter(PainterNode* painter, QString& str) +bool ParsingToolBox::readPainterParameter(PainterNode* painter, QString& str) { - if(str.startsWith('[')) - { - str= str.remove(0, 1); - int pos= str.indexOf(']'); + if(!str.startsWith('[')) + return false; + + str= str.remove(0, 1); + int pos= str.indexOf(']'); - if(pos > -1) + if(pos == -1) + return false; + + QString data= str.left(pos); + str= str.remove(0, pos + 1); + QStringList duos= data.split(','); + bool result= false; + for(QString& duoStr : duos) + { + QStringList keyValu= duoStr.split(':'); + if(keyValu.size() == 2) { - QString data= str.left(pos); - str= str.remove(0, pos + 1); - QStringList duos= data.split(','); - for(QString& duoStr : duos) - { - QStringList keyValu= duoStr.split(':'); - if(keyValu.size() == 2) - { - painter->insertColorItem(keyValu[1], keyValu[0].toInt()); - } - } + painter->insertColorItem(keyValu[1], keyValu[0].toInt()); + result= true; } } + + return result; } QHash ParsingToolBox::getVariableHash() -- cgit v1.2.3-70-g09d2