diff options
| author | 2016-11-01 12:10:54 +0100 | |
|---|---|---|
| committer | 2016-11-01 12:10:54 +0100 | |
| commit | d5876d9b88c2f695592338335308a32e584d86a4 (patch) | |
| tree | bb0c3f757512fb913812902143b73b7380451502 /node | |
| parent | d29b6d34b713d9241eb96cb99802ca8bc24cc3bd (diff) | |
| download | OneRoll-d5876d9b88c2f695592338335308a32e584d86a4.tar.gz OneRoll-d5876d9b88c2f695592338335308a32e584d86a4.zip | |
-add management of string node to display text in some condition.
Diffstat (limited to 'node')
| -rw-r--r-- | node/stringnode.cpp | 115 | ||||
| -rw-r--r-- | node/stringnode.h | 18 |
2 files changed, 131 insertions, 2 deletions
diff --git a/node/stringnode.cpp b/node/stringnode.cpp index 5dc99fd..157f595 100644 --- a/node/stringnode.cpp +++ b/node/stringnode.cpp @@ -1,6 +1,121 @@ #include "stringnode.h" StringNode::StringNode() + : m_stringResult(new StringResult()) { + m_result = m_stringResult; +} + +void StringNode::run(ExecutionNode *previous) +{ + m_previousNode = previous; + if(NULL!=previous) + { + m_result->setPrevious(previous->getResult()); + } + if(NULL!=m_nextNode) + { + m_nextNode->run(this); + } +} + +void StringNode::setString(QString str) +{ + m_data = str; + m_stringResult->setText(m_data); +} +QString StringNode::toString(bool withLabel) const +{ + if(withLabel) + { + return QString("%1 [label=\"StringNode %2\"]").arg(m_id).arg(m_data); + } + else + { + return m_id; + } +} +/*void StringNode::getScalarResult() +{ + QString scalarText; + + if(m_diceParser->hasIntegerResultNotInFirst()) + { + scalarText = QStringLiteral("%1").arg(m_diceParser->getLastIntegerResult()); + } + else if(hasDiceList) + { + scalarText = QStringLiteral("%1").arg(m_diceParser->getSumOfDiceResult()); + } +}*/ + +/*bool StringNode::getMessageResult(QString& value, QString& command, QString& list) +{ + QString scalarText; + QString diceText; + //QString pattern(""); + + + + bool hasDiceList = false; + if(m_diceParser->hasDiceResult()) + { + ExportedDiceResult diceList; + bool ok; + m_diceParser->getLastDiceResult(diceList,ok);//fills the ExportedDiceResult + diceText = diceToText(diceList); + hasDiceList= true; + } + if(m_diceParser->hasSeparator()) + { + bool ok; + QStringList allStringlist = m_diceParser->getAllDiceResult(ok); + if(ok) + { + QString patternColor("<span class=\"dice\">%1</span>"); + list = patternColor.arg(allStringlist.join(' ')); + scalarText = list; + } + } + else if(m_diceParser->hasIntegerResultNotInFirst()) + { + scalarText = QStringLiteral("%1").arg(m_diceParser->getLastIntegerResult()); + } + else if(hasDiceList) + { + scalarText = QStringLiteral("%1").arg(m_diceParser->getSumOfDiceResult()); + } + value=scalarText; + list = diceText.trimmed(); + command = m_diceParser->getDiceCommand().toHtmlEscaped(); + if(m_diceParser->hasStringResult()) + { + bool ok; + QStringList allStringlist = m_diceParser->getAllStringResult(ok); + if(ok) + { + QString patternColor("<span class=\"dice\">%1</span>"); + list = patternColor.arg(allStringlist.join(' ')); + value = list; + } + else + { + value = m_diceParser->getStringResult().replace("\n","<br/>"); + list = allStringlist.join(' '); + return true; + } + } + + return false; +}*/ +qint64 StringNode::getPriority() const +{ + qint64 priority=0; + if(NULL!=m_nextNode) + { + priority = m_nextNode->getPriority(); + } + + return priority; } diff --git a/node/stringnode.h b/node/stringnode.h index 6f01fe8..cf70d02 100644 --- a/node/stringnode.h +++ b/node/stringnode.h @@ -1,11 +1,25 @@ #ifndef STRINGNODE_H #define STRINGNODE_H +#include "node/executionnode.h" +#include "result/stringresult.h" -class StringNode +/** + * @brief The StringNode class is an ExecutionNode. It is dedicated to store string and display result. + */ +class StringNode : public ExecutionNode { public: StringNode(); + void run(ExecutionNode* previous); + void setString(QString str); + virtual QString toString(bool withLabel)const; + virtual qint64 getPriority() const; + +private: + QString m_data; + StringResult* m_stringResult; + }; -#endif // STRINGNODE_H
\ No newline at end of file +#endif // STRINGNODE_H |