void ConversationData::deserialize(QDomDocument &doc) {
    auto datas = doc.elementsByTagName("data");
    if(datas.length() != 1) {
        qDebug("Expected exactly one <data> element! Found %d.", datas.length());
        return;
    }
    auto data = datas.at(0);
    auto cnamess = data.toElement().elementsByTagName("character-names");
    if(cnamess.length() != 1) {
        qDebug("Expected exactly one <character-names> element!");
        return;
    }
    auto cnames = cnamess.at(0);
    auto nodes = cnames.childNodes();
    for(int i = 0; i < nodes.length(); i ++) {
        auto name = nodes.at(i);
        m_characterNames.push_back(
            name.toElement().attribute("name", "???"));
    }

    auto contextss = data.toElement().elementsByTagName("contexts");
    if(contextss.length() != 1) {
        qDebug("Expected exactly one <contexts> element!");
        return;
    }
    auto contexts = contextss.at(0);
    nodes = contexts.childNodes();
    // first pass to construct everything
    for(int i = 0; i < nodes.length(); i ++) {
        auto context = nodes.at(i);
        int id = context.toElement().attribute("id").toInt();
        QString label = context.toElement().attribute("label");

        auto con = m_contexts[id] = new ConversationContext(id);
        con->setLabel(label);
    }
    // second pass to set parents
    for(int i = 0; i < nodes.length(); i ++) {
        auto context = nodes.at(i);
        int id = context.toElement().attribute("id").toInt();
        bool hasParent = false;
        int parentID =
            context.toElement().attribute("parent").toInt(&hasParent);
        if(hasParent) m_contexts[id]->setParent(m_contexts[parentID]);
    }

    m_rootContext = m_contexts[contexts.toElement().attribute("root").toInt()];
}
Ejemplo n.º 2
0
void WTreeTableNode::setTable(WTreeTable *table)
{
  if (table_ != table) {
    table_ = table;

    for (unsigned i = 0; i < childNodes().size(); ++i)
      dynamic_cast<WTreeTableNode *>(childNodes()[i])->setTable(table);

    createExtraColumns(table->columnCount() - 1);

    for (unsigned i = 0; i < columnWidgets_.size(); ++i) {
      WWidget *w = columnWidgets_[i].widget;
      w->resize(columnWidth(i + 1), w->height());
    }
  }
}
Ejemplo n.º 3
0
QList<ZConfigElement> ZConfigElement::children(QString tagName) const{
    QList<ZConfigElement> rv;
    QDomNodeList nodes = childNodes();

    for(int i = 0; i < nodes.count(); i++){
        if(nodes.at(i).isElement()){
            QDomElement cel = nodes.at(i).toElement();
            if(tagName.isEmpty() ||
               (!tagName.isEmpty() && cel.tagName() == tagName))
            {
                rv << cel;
            }
        }
    }

    return rv;
}
Ejemplo n.º 4
0
void Viewport::onPaste()
{
    auto data = QApplication::clipboard()->mimeData();
    if (data->hasFormat("sb::viewport"))
    {
        auto g = App::instance()->getGraph();
        const uint64_t new_uid = g->getUIDs(1).front();

        // Update this node's UID and store the change in uid_map
        auto n = QJsonDocument::fromJson(
                data->data("sb::viewport")).object();

        n["uid"] = int(new_uid);

        auto name = n["name"].toString();
        if (!g->isNameUnique(name.toStdString()))
        {
            // Trim trailing numbers from the node's name
            while (name.at(name.size() - 1).isNumber())
                name = name.left(name.size() - 1);
            if (name.isEmpty())
                name = "n";
            // Then use the remaining string as a prefix
            n["name"] = QString::fromStdString(g->nextName(name.toStdString()));
        }

        // Deserialize this node
        SceneDeserializer::Info ds;
        SceneDeserializer::deserializeNode(n, g, &ds);

        // Update the inspector positions by shifting a bit down and over
        for (auto& i : ds.inspectors)
            i += QPointF(10, 10);
        App::instance()->getGraphScene()->setInspectorPositions(ds.inspectors);

        App::instance()->pushStack(
                new UndoAddNodeCommand(g->childNodes().back(), "'paste'"));
    }
}
Ejemplo n.º 5
0
std::vector<XmlNode>::iterator XmlNode::begin()
{
	_childIteratorList = childNodes();
	return _childIteratorList.begin();
}