void EnhancedTagAttributeTree::NodeSelected(Node *node)
{
  curNode = node;
  //We don't want to be able to edit the text node but it's parent.
  if (node && node->tag->type == Tag::Text)
    curNode = node = node->parent;
  showCaption();
  emit newNodeSelected(node);
}
Example #2
0
void Packing::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    qDebug() << "scene got mouse press event";
    //update the property window
    QPointF pos = mouseEvent->scenePos();
    QList<QGraphicsItem*> items = this->items(pos);
    //cycle through the items to find one which is a circle.
    Node *n = nullptr;
    Circle *c = nullptr;
    for(auto item: items){
        c = dynamic_cast<Circle*>(item);
        if(c == nullptr) continue;
        else{
            n = c->getNode();
            break;
        }
    }
    if(n != nullptr) emit newNodeSelected(n);
    //handle circle visual selection
    if(c != nullptr){
        if(c == this->selectedCircle){
            c->setSelectionState(Circle::SelectionState::None);
            this->selectedCircle = nullptr;
        }
        else{
            if(this->selectedCircle != nullptr){
                this->selectedCircle->setSelectionState(Circle::SelectionState::None);
            }
            c->setSelectionState(Circle::SelectionState::Selected);
            this->selectedCircle = c;
        }
    }
    //pass mouse event on to circle.
    //QGraphicsScene::mousePressEvent(mouseEvent);
    this->update();
}
void TagAttributeTree::setCurrentNode(Node *node)
{
  if (m_node == node)
    return;
  m_node = node;
  emit newNodeSelected(node);
  if (!rebuildEnabled)
      return;
  clear();
  m_parentItem = 0L;
  //We don't want to be able to edit the text node but it's parent.
  if (node && node->tag->type == Tag::Text)
    m_node = node = node->parent;
  if (!node)
      return;
#ifdef HEAVY_DEBUG
  kafkaCommon::coutTree(baseNode, 2);
  KafkaDocument::ref()->coutLinkTree(baseNode, 2);
#endif
  AttributeItem *item = 0L;
  TopLevelItem *group = 0L;
  QString attrName;
  QTag *qTag = QuantaCommon::tagFromDTD(node);
  Node *n = node->parent;
  while (n)
  {
    if (n->tag->type == Tag::XmlTag)
    {
      if (!m_parentItem)
      {
        group = new TopLevelItem(this, 0L, i18n("Parent tags"));
        m_parentItem = new ParentItem(this, group);
      }
      m_parentItem->addNode(n);
    }
    n = n->parent;
  }

  if (m_parentItem)
      m_parentItem->showList(true);
  if (group)
     group->setOpen(true);
//  if (!node->tag->nameSpace.isEmpty())

  if(node->tag->type == Tag::XmlTag || node->tag->type == Tag::XmlTagEnd)
  {
    QString nameSpace = node->tag->nameSpace;
    if (node->tag->type == Tag::XmlTagEnd)
     nameSpace.remove('/');
    group = new TopLevelItem(this, group, i18n("Namespace"));
    item = new AttributeNameSpaceItem(this, group, i18n("prefix"), nameSpace);
    group->setOpen(true);
  }
   if (qTag)
  {
    group = new TopLevelItem(this, group, i18n("Attributes"));
    QStringList list;
    for (int i = 0; i < qTag->attributeCount(); i++)
    {
      list += qTag->attributeAt(i)->name;
    }
    list.sort();
    QStringList::Iterator it = list.end();
    --it;
    while (it != list.end())
    {
      Attribute *attr = qTag->attribute(*it);
      if (attr->type == "check")
      {
        item = new AttributeBoolItem(this, group, attr->name, node->tag->attributeValue(attr->name));
      } else
      if (attr->type == "url")
      {
        item = new AttributeUrlItem(this, group, attr->name, node->tag->attributeValue(attr->name));
      } else
      if (attr->type == "list")
      {
        item = new AttributeListItem(this, group, attr->name, node->tag->attributeValue(attr->name));
      } else
      if (attr->type == "color")
      {
        item = new AttributeColorItem(this, group, attr->name, node->tag->attributeValue(attr->name));
      } else
      {
        item = new AttributeItem(this, group, attr->name, node->tag->attributeValue(attr->name));
      }
      item->setRenameEnabled(1, true);
      if (it != list.begin())
        --it;
      else
        break;
    }
    group->setOpen(true);
    for (uint i = 0; i < qTag->commonGroups.count(); i++)
    {
      group = new TopLevelItem(this, group, i18n(qTag->commonGroups[i].utf8()));
      AttributeList *groupAttrs = qTag->parentDTD->commonAttrs->find(qTag->commonGroups[i]);
      for (uint j = 0; j < groupAttrs->count(); j++)
      {
        Attribute *attr = groupAttrs->at(j);
        attrName = attr->name;
        if (attr->type == "check")
        {
          item = new AttributeBoolItem(this, group, attrName, node->tag->attributeValue(attrName));
        } else
        if (attr->type == "url")
        {
          item = new AttributeUrlItem(this, group, attr->name, node->tag->attributeValue(attr->name));
        } else
        if (attr->type == "list")
        {
          item = new AttributeListItem(this, group, attr->name, node->tag->attributeValue(attr->name), attr);
        } else
        if (attr->type == "color")
        {
          item = new AttributeColorItem(this, group, attr->name, node->tag->attributeValue(attr->name));
        } else
        if (attr->type == "css-style")
        {
          item = new AttributeStyleItem(this, group, attr->name, node->tag->attributeValue(attr->name));
        } else
        {
          item = new AttributeItem(this, group, attrName, node->tag->attributeValue(attrName));
        }
        item->setRenameEnabled(1, true);
      }
      group->setOpen(true);
    }

  }
  connect(this, SIGNAL(collapsed(QListViewItem*)), SLOT(slotCollapsed(QListViewItem*)));
  connect(this, SIGNAL(expanded(QListViewItem*)), SLOT(slotExpanded(QListViewItem*)));
}