当前位置: 首页>>代码示例>>C++>>正文


C++ BaseNode::addConnectedNode方法代码示例

本文整理汇总了C++中BaseNode::addConnectedNode方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseNode::addConnectedNode方法的具体用法?C++ BaseNode::addConnectedNode怎么用?C++ BaseNode::addConnectedNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BaseNode的用法示例。


在下文中一共展示了BaseNode::addConnectedNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: openDocument

/*! Opens specified file. This function does not ask the user to save an
    unsaved modified diagram. That is the MainWindow's job. This function
    will simply clear out the node vector and load the file in.
*/
void Document::openDocument(QString openName)
{
    QDomDocument* xmlDoc = openSaveFile(openName);
    QDomElement docElem = getNextDocumentElement(xmlDoc);
    QDomElement nodesVectorElement;
    QDomElement n;
    BaseNode* newNode;

    // Clear the nodes vector
    nodes.clear();
    ordering.clear();

    // Get the diagram type
    diagramType = static_cast<BaseNode::DiagramType>(docElem.attribute("diagramType").toInt());

    // First get out the first (and hopefully only) nodes_vector_element.
    nodesVectorElement = docElem.firstChildElement("nodes_vector_element");

    // Now we have to iterate over all the Node elements and restor them.
    // This style of iteration loop was taken from the Qt documentation for
    // QDomElement.
    n = nodesVectorElement.firstChildElement("Node");
    for (; !n.isNull(); n = n.nextSiblingElement("Node")) {
      // Now that we have the QDomElement, try to produce the node
      newNode = NodeFactory::getInstance()->produceFromClassName(n.attribute("class_name"));

      // Check we failed
      if (newNode == 0) {
        qDebug() << "Document::openDocument Error: Couldn't produce a " << n.attribute("class_name") << " with the node factory.";
      } else {
        // Restore the unique id and all the properties
        newNode->from_xml(n);

        // Push the node onto the node vector
        nodes.push_back(newNode);
        ordering.push_back(nodes.size()-1);
      }
    }

    // Now that we have all the id's restored, we can restore the connections
    // between the nodes. We loop over all the Node elements in
    // node_vector_element and loop over all the ConnectedObject elements in
    // each Node.
    n = nodesVectorElement.firstChildElement("Node");
    for (; !n.isNull(); n = n.nextSiblingElement("Node")) {
      BaseNode* sourcenode;
      QUuid sourceid;

      // Find the node that we created earlier from this element
      sourceid = QUuid(n.attribute("Id"));
      sourcenode = this->findNodeById(sourceid);

      if (sourcenode == 0) {
        qDebug() << "Document::openDocument Error: Couldn't find source node by id";
      } else {
        QUuid targetid;
        BaseNode* targetnode;

        // Now that we have the element and it's associated node, iterate
        // over all of the element's children ("ConnectedObjects")
        QDomElement child = n.firstChildElement("ConnectedObject");
        for (; !child.isNull(); child = child.nextSiblingElement("ConnectedObject")) {
          // Find the targeted node by id
          targetid = QUuid(child.attribute("id"));
          targetnode = this->findNodeById(targetid);

          // Check if it failed
          if (targetnode == 0) {
            qDebug() << "Document::openDocument Error: Couldn't find a target node by id";
          } else {
            // If it didn't fail, add the connection!
            sourcenode->addConnectedNode(targetnode);
          }
        }
      }
    }

    setFilename(openName);
    setModified(false);
    update();
}
开发者ID:hexfaker,项目名称:puml,代码行数:85,代码来源:document.cpp

示例2: modelChanged

/*! Slot. Sets the second point in a new connection node.
  This function actually creates the node using the NodeFactory.
  It doesn't create the node if the first or second point is invalid.
*/
void Document::createConnectionPoint2(const QPoint &point) {
  // Create the object only if a valid first object was found
  int index;
  // creates a temp object node for self connectors
  BaseNode *tempnode;
  tempnode = NodeFactory::getInstance()->produce(newObjectID);

  if (firstConnectionIndex != -1) {
    index = getIndexAt(point);
    // And the second index was found
    if (((index != -1) &&
         (nodes.at(index)->isConnector() == false)) &&
            index != firstConnectionIndex) {
      // produce the object
      BaseNode *newNode;
      newNode = NodeFactory::getInstance()->produce(newObjectID);

      // now connect the connection to both objects, and connect the
      // objects to the connections
      newNode->addConnectedNode(nodes.at(firstConnectionIndex));
      newNode->addConnectedNode(nodes.at(index));
      nodes.at(firstConnectionIndex)->addConnectedNode(newNode);
      nodes.at(index)->addConnectedNode(newNode);

      addNodeToList(newNode);
      ordering.append(nodes.size()-1);

      nodes.at(index)->setSelectedForConnectionPoint(false);

      setModified(true);
      emit modelChanged();
    }
    //  Self connectors
    // And the second index was found
    else if ((((index != -1) &&
         (nodes.at(index)->isConnector() == false)) &&
            (index == firstConnectionIndex) &&
              (tempnode->getText() == "Collaboration Self Line")) ||
             ((index != -1) && (nodes.at(index)->isConnector() == false)
             &&(index == firstConnectionIndex) && (tempnode->getText() == "State Self Line"))) {

        // produce the object
      BaseNode *newNode;
      newNode = NodeFactory::getInstance()->produce(newObjectID);

      // now connect the connection to both objects, and connect the
      // objects to the connections
      newNode->addConnectedNode(nodes.at(firstConnectionIndex));
      newNode->addConnectedNode(nodes.at(index));
      nodes.at(firstConnectionIndex)->addConnectedNode(newNode);
      nodes.at(index)->addConnectedNode(newNode);

      addNodeToList(newNode);
      ordering.append(nodes.size()-1);

      nodes.at(index)->setSelectedForConnectionPoint(false);

      setModified(true);
      emit modelChanged();
    }
// end of  self connect
    else {
      QMessageBox::information(0, "pUML", "No second object selected");
    }
  }

  if (firstConnectionIndex != -1) {
    nodes.at(firstConnectionIndex)->setSelectedForConnectionPoint(false);
  }
}
开发者ID:hexfaker,项目名称:puml,代码行数:74,代码来源:document.cpp


注:本文中的BaseNode::addConnectedNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。