void
RoutingStatsScene::reloadContent(bool force)
{
    if(m_nodeIdProxyWidgets.empty())
    {
        return;
    }

    m_lastX = 0;
    m_lastY = 0;
    m_bottomY = 0;
    qreal currentTime = StatsMode::getInstance()->getCurrentTime();

    qreal currentMaxHeight = 0;
    for(NodeIdProxyWidgetMap_t::const_iterator i = m_nodeIdProxyWidgets.begin();
        i != m_nodeIdProxyWidgets.end();
        ++i)
    {
        QGraphicsProxyWidget * pw = i->second;

        if((force) || (!m_lastTime) || (m_lastTime != currentTime))
        {
            updateContent(i->first, pw);
        }


        bool nodeIsActive = StatsMode::getInstance()->isNodeActive(i->first);
        pw->setVisible(nodeIsActive);
        if(nodeIsActive)
        {
            qreal newX = m_lastX + pw->size().width();
            currentMaxHeight = qMax(currentMaxHeight, pw->size().height());
            if(newX >= sceneRect().right())
            {
                m_lastX = 0;
                m_lastY += currentMaxHeight + INTERSTATS_SPACE;
                currentMaxHeight = 0;
            }
            pw->setPos(m_lastX, m_lastY);
            m_lastX = pw->pos().x() + pw->size().width() + INTERSTATS_SPACE;
            m_lastY = pw->pos().y();
            m_bottomY = m_lastY + currentMaxHeight;
            adjustRect();
        }

    }

    m_lastTime = currentTime;


}
void
FlowMonStatsScene::align()
{
    m_lastX = 0;
    m_lastY = 0;
    m_bottomY = 0;
    qreal currentMaxHeight = 0;

    for(FlowIdProxyWidgetMap_t::const_iterator i = m_flowIdProxyWidgets.begin();
        i != m_flowIdProxyWidgets.end();
        ++i)
    {
        QGraphicsProxyWidget * pw = i->second;
        bool flowIsActive = StatsMode::getInstance()->isNodeActive(i->first);
        pw->setVisible(flowIsActive);
        if(flowIsActive)
        {
            TextBubble * tb = (TextBubble *) pw->widget();
            QFont f(tb->font());
            f.setPointSizeF(StatsMode::getInstance()->getCurrentFontSize());
            tb->setFont(f);

            QFontMetrics fm(f);
            pw->setMaximumHeight(fm.height() * tb->text().count("\n"));
            pw->adjustSize();

            qreal newX = m_lastX + pw->size().width();
            currentMaxHeight = qMax(currentMaxHeight, pw->size().height());
            if(newX >= sceneRect().right())
            {
                m_lastX = 0;
                m_lastY += currentMaxHeight + INTERSTATS_SPACE;
                currentMaxHeight = 0;
            }
            pw->setPos(m_lastX, m_lastY);
            m_lastX = pw->pos().x() + pw->size().width() + INTERSTATS_SPACE;
            m_lastY = pw->pos().y();
            m_bottomY = m_lastY + currentMaxHeight;
            adjustRect();
        }
    }
    if(m_flowProbeWidget)
    {
            QGraphicsProxyWidget * pw = m_flowProbeWidget;
            TextBubble * tb = (TextBubble *) pw->widget();
            QFont f(tb->font());
            f.setPointSizeF(StatsMode::getInstance()->getCurrentFontSize());
            tb->setFont(f);

            QFontMetrics fm(f);
            pw->setMaximumHeight(fm.height() * tb->text().count("\n"));
            pw->adjustSize();

            qreal newX = m_lastX + pw->size().width();
            currentMaxHeight = qMax(currentMaxHeight, pw->size().height());
            if(newX >= sceneRect().right())
            {
                m_lastX = 0;
                m_lastY += currentMaxHeight + INTERSTATS_SPACE;
                currentMaxHeight = 0;
            }
            pw->setPos(m_lastX, m_lastY);
            m_lastX = pw->pos().x() + pw->size().width() + INTERSTATS_SPACE;
            m_lastY = pw->pos().y();
            m_bottomY = m_lastY + currentMaxHeight;
            adjustRect();

    }

}
void
InterfaceStatsScene::add (uint32_t nodeId, QString pointADescription, uint32_t otherNodeId, QString pointBDescription, QString linkDescription)
{
  if (!StatsMode::getInstance ()->isNodeActive (nodeId))
    {
      return;
    }
  if (!pointADescription.contains ("~"))
    {
      return;
    }
  showInfoWidget (false);
  QStringList parts = pointADescription.split ('~');
  //qDebug (pointADescription);
  QString IP = parts.at (0);
  //qDebug (IP);
  QString MAC = parts.at (1);
  QString otherIP = "";
  QString otherMAC = "";

  if (pointBDescription != "")
    {
      parts = pointBDescription.split ('~');
      otherIP = parts.at (0);
      otherMAC = parts.at (1);
    }

  QString title = "Node:" + QString::number (nodeId);
  QString content = "IP:" + IP ;
  content += "\nMAC:" + MAC ;

  if (pointBDescription != "")
    {
      content += "\nOther Node:" + QString::number (otherNodeId) ;
      content += "\nOther IP:" + otherIP;
      content += "\nOther MAC:" + otherMAC;
      content += "\nInfo:" + linkDescription;
    }
  TextBubble * tb = new TextBubble (title, content);
  QGraphicsProxyWidget * pw = addWidget (tb);
  QFont f (tb->font ());
  f.setPointSizeF (StatsMode::getInstance ()->getCurrentFontSize ());
  tb->setFont (f);
  QFontMetrics fm (f);
  pw->setMaximumHeight (fm.height () * tb->text ().count ("\n"));

  addToProxyWidgetsMap (nodeId, pw);
  qreal newX = m_lastX + pw->widget ()->width ();
  m_currentMaxHeight = qMax (m_currentMaxHeight, pw->size ().height ());
  if (newX >= sceneRect ().right ())
    {
      m_lastX = 0;
      m_lastY += m_currentMaxHeight + INTERSTATS_SPACE;
      m_currentMaxHeight = 0;
    }
  pw->setPos (m_lastX, m_lastY);
  m_lastX = pw->pos ().x () + pw->widget ()->width () + INTERSTATS_SPACE;
  m_lastY = pw->pos ().y ();
  m_bottomY = m_lastY + m_currentMaxHeight;
  //qDebug (QString ("Last X" + QString::number (m_lastX) + " w:" + QString::number (pw->widget ()->width ())));
  adjustRect ();

}