Good day everyone


I am trying to change the colour of the QGraphicsRectItems that is on a scene. QGraphicsRectItems are nodes of a network, I want that each item to be updated by a colour indicating status of the node. my question how do i write a code that will update and iterate to the next item on the scene but keep the update ? THis one below it updates them all at the same time, i mean if one is green it turns all green or if one is red it turns all red which is not desired. it does not update each item at a time and keep the status and pass to the next, which is i would like to see. my code is below


Qt Code:
  1. else if (_eType == QSubscription::UPDATED_TITLES)
  2. {
  3. C2DM::LinkState *pState = (C2DM::LinkState*)objPtr->_clone();
  4. m_pLinkStateListModel->addTitle(pState);
  5.  
  6.  
  7. foreach(QGraphicsItem *item,scene->items()) // foreach statement that updates all at the same time
  8. {
  9.  
  10. QGraphicsRectItem *rect = qgraphicsitem_cast<QGraphicsRectItem *>(item);
  11. if (!rect)
  12. continue;
  13. getTitleDescriptionColor(pState, m_backgroundColor, rect);
  14. }
To copy to clipboard, switch view to plain text mode 

The function that gets the colour (getTitleDescriptionColour) is


Qt Code:
  1. QColor getTitleDescriptionColor(const DM::Object *_pTitle, const QColor &_colorBackground, QGraphicsRectItem *_row)
  2. {
  3.  
  4. QColor ret = _colorBackground;
  5.  
  6. if (CORE::checkPtrType<C2DM::LinkState>(_pTitle) == true)
  7. {
  8.  
  9. C2DM::LinkState *pState = (C2DM::LinkState*)_pTitle;
  10.  
  11.  
  12. if (pState->m_eState == C2DM::LinkState::EIS_GOOD)
  13. {
  14. ret = QColor(Qt::green).darker(120);
  15. _row->setBrush(ret);
  16. }
  17. else if (pState->m_eState == C2DM::LinkState::EIS_BUSY)
  18. {
  19. ret = QColor(Qt::yellow).darker(120);
  20. _row->setBrush(ret);
  21. }
  22. else
  23. {
  24. ret = QColor(Qt::red).darker(120);
  25. _row->setBrush(ret);
  26. }
  27.  
  28. }
  29. else if (CORE::checkPtrType<C2DM::RouteState>(_pTitle) == true)
  30. {
  31. C2DM::RouteState *pState = (C2DM::RouteState*)_pTitle;
  32.  
  33. if (pState->m_bEnabled == false)
  34. {
  35. ret = QColor(Qt::blue).lighter(120);
  36. }
  37. else if ((pState->m_eTxLinkState != C2DM::LinkState::EInterfaceState::EIS_GOOD) ||
  38. (pState->m_eRxLinkState != C2DM::LinkState::EInterfaceState::EIS_GOOD))
  39. {
  40. ret = QColor(Qt::yellow).darker(120);
  41. }
  42. else
  43. {
  44. ret = QColor(Qt::green).darker(120);
  45. }
  46.  
  47. }
  48.  
  49. return ret;
  50. }
To copy to clipboard, switch view to plain text mode