File indexing completed on 2024-05-12 05:39:29
0001 #include "variablenode.h" 0002 0003 #include "diceresult.h" 0004 #include <diceparser/parsingtoolbox.h> 0005 0006 VariableNode::VariableNode() {} 0007 0008 void VariableNode::run(ExecutionNode* previous) 0009 { 0010 m_previousNode= previous; 0011 if((nullptr != m_data) && (m_data->size() > m_index)) 0012 { 0013 auto value= (*m_data)[m_index]; 0014 value= ParsingToolBox::getLeafNode(value); 0015 if(nullptr == value) 0016 return; 0017 0018 auto result= value->getResult(); 0019 if(!result) 0020 return; 0021 0022 m_result= result->getCopy(); 0023 auto diceResult= dynamic_cast<DiceResult*>(result); 0024 if(nullptr != diceResult) 0025 { 0026 for(auto& die : diceResult->getResultList()) 0027 { 0028 die->setDisplayed(false); 0029 } 0030 } 0031 0032 if(nullptr != m_nextNode) 0033 { 0034 m_nextNode->run(this); 0035 } 0036 } 0037 else 0038 { 0039 m_errors.insert(Dice::ERROR_CODE::NO_VARIBALE, QObject::tr("No variable at index:%1").arg(m_index + 1)); 0040 } 0041 } 0042 0043 void VariableNode::setDisplayed() 0044 { 0045 if(!m_result) 0046 return; 0047 auto diceResult= dynamic_cast<DiceResult*>(m_result); 0048 if(nullptr == diceResult) 0049 return; 0050 0051 for(auto& die : diceResult->getResultList()) 0052 { 0053 die->setDisplayed(true); 0054 } 0055 } 0056 0057 QString VariableNode::toString(bool withLabel) const 0058 { 0059 if(withLabel) 0060 { 0061 return QString("%1 [label=\"VariableNode index: %2\"]").arg(m_id).arg(m_index + 1); 0062 } 0063 else 0064 { 0065 return m_id; 0066 } 0067 } 0068 0069 qint64 VariableNode::getPriority() const 0070 { 0071 qint64 priority= 4; 0072 if(nullptr != m_previousNode) 0073 { 0074 priority= m_previousNode->getPriority(); 0075 } 0076 return priority; 0077 } 0078 0079 ExecutionNode* VariableNode::getCopy() const 0080 { 0081 VariableNode* node= new VariableNode(); 0082 node->setIndex(m_index); 0083 if(nullptr != m_data) 0084 { 0085 node->setData(m_data); 0086 } 0087 if(nullptr != m_nextNode) 0088 { 0089 node->setNextNode(m_nextNode->getCopy()); 0090 } 0091 return node; 0092 } 0093 0094 quint64 VariableNode::getIndex() const 0095 { 0096 return m_index; 0097 } 0098 0099 void VariableNode::setIndex(quint64 index) 0100 { 0101 m_index= index; 0102 } 0103 0104 std::vector<ExecutionNode*>* VariableNode::getData() const 0105 { 0106 return m_data; 0107 } 0108 0109 void VariableNode::setData(std::vector<ExecutionNode*>* data) 0110 { 0111 m_data= data; 0112 }