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
else if (_eType == QSubscription::UPDATED_TITLES)
{
C2DM::LinkState *pState = (C2DM::LinkState*)objPtr->_clone();
m_pLinkStateListModel->addTitle(pState);
foreach
(QGraphicsItem *item,scene
->items
()) // foreach statement that updates all at the same time {
if (!rect)
continue;
getTitleDescriptionColor(pState, m_backgroundColor, rect);
}
else if (_eType == QSubscription::UPDATED_TITLES)
{
C2DM::LinkState *pState = (C2DM::LinkState*)objPtr->_clone();
m_pLinkStateListModel->addTitle(pState);
foreach(QGraphicsItem *item,scene->items()) // foreach statement that updates all at the same time
{
QGraphicsRectItem *rect = qgraphicsitem_cast<QGraphicsRectItem *>(item);
if (!rect)
continue;
getTitleDescriptionColor(pState, m_backgroundColor, rect);
}
To copy to clipboard, switch view to plain text mode
The function that gets the colour (getTitleDescriptionColour) is
{
QColor ret
= _colorBackground;
if (CORE::checkPtrType<C2DM::LinkState>(_pTitle) == true)
{
C2DM::LinkState *pState = (C2DM::LinkState*)_pTitle;
if (pState->m_eState == C2DM::LinkState::EIS_GOOD)
{
ret
= QColor(Qt
::green).
darker(120);
_row->setBrush(ret);
}
else if (pState->m_eState == C2DM::LinkState::EIS_BUSY)
{
ret
= QColor(Qt
::yellow).
darker(120);
_row->setBrush(ret);
}
else
{
ret
= QColor(Qt
::red).
darker(120);
_row->setBrush(ret);
}
}
else if (CORE::checkPtrType<C2DM::RouteState>(_pTitle) == true)
{
C2DM::RouteState *pState = (C2DM::RouteState*)_pTitle;
if (pState->m_bEnabled == false)
{
ret
= QColor(Qt
::blue).
lighter(120);
}
else if ((pState->m_eTxLinkState != C2DM::LinkState::EInterfaceState::EIS_GOOD) ||
(pState->m_eRxLinkState != C2DM::LinkState::EInterfaceState::EIS_GOOD))
{
ret
= QColor(Qt
::yellow).
darker(120);
}
else
{
ret
= QColor(Qt
::green).
darker(120);
}
}
return ret;
}
QColor getTitleDescriptionColor(const DM::Object *_pTitle, const QColor &_colorBackground, QGraphicsRectItem *_row)
{
QColor ret = _colorBackground;
if (CORE::checkPtrType<C2DM::LinkState>(_pTitle) == true)
{
C2DM::LinkState *pState = (C2DM::LinkState*)_pTitle;
if (pState->m_eState == C2DM::LinkState::EIS_GOOD)
{
ret = QColor(Qt::green).darker(120);
_row->setBrush(ret);
}
else if (pState->m_eState == C2DM::LinkState::EIS_BUSY)
{
ret = QColor(Qt::yellow).darker(120);
_row->setBrush(ret);
}
else
{
ret = QColor(Qt::red).darker(120);
_row->setBrush(ret);
}
}
else if (CORE::checkPtrType<C2DM::RouteState>(_pTitle) == true)
{
C2DM::RouteState *pState = (C2DM::RouteState*)_pTitle;
if (pState->m_bEnabled == false)
{
ret = QColor(Qt::blue).lighter(120);
}
else if ((pState->m_eTxLinkState != C2DM::LinkState::EInterfaceState::EIS_GOOD) ||
(pState->m_eRxLinkState != C2DM::LinkState::EInterfaceState::EIS_GOOD))
{
ret = QColor(Qt::yellow).darker(120);
}
else
{
ret = QColor(Qt::green).darker(120);
}
}
return ret;
}
To copy to clipboard, switch view to plain text mode
Bookmarks