示例#1
0
  Shader loadShaderXml(QIODevice & ioDevice) {
    QDomDocument dom;
    Shader result;
    dom.setContent(&ioDevice);

    auto children = dom.documentElement().childNodes();
    for (int i = 0; i < children.count(); ++i) {
      auto child = children.at(i);
      if (child.nodeName() == "url") {
        result.url = child.firstChild().nodeValue();
      } if (child.nodeName() == XML_FRAGMENT_SOURCE) {
        result.fragmentSource = child.firstChild().nodeValue();
      } if (child.nodeName() == XML_NAME) {
        result.name = child.firstChild().nodeValue();
      } else if (child.nodeName() == XML_CHANNEL) {
        auto attributes = child.attributes();
        int channelIndex = -1;
        QString source;
        if (attributes.contains(XML_CHANNEL_ATTR_ID)) {
          channelIndex = attributes.namedItem(XML_CHANNEL_ATTR_ID).nodeValue().toInt();
        }

        if (channelIndex < 0 || channelIndex >= shadertoy::MAX_CHANNELS) {
          continue;
        }


        // Compatibility mode
        if (attributes.contains(XML_CHANNEL_ATTR_SOURCE)) {
          source = attributes.namedItem(XML_CHANNEL_ATTR_SOURCE).nodeValue();
          QRegExp re(CHANNEL_REGEX);
          if (!re.exactMatch(source)) {
            continue;
          }
          result.channelTypes[channelIndex] = channelTypeFromString(re.cap(1));
          result.channelTextures[channelIndex] = ("preset://" + re.cap(1) + "/" + re.cap(2));
          continue;
        }

        if (attributes.contains(XML_CHANNEL_ATTR_TYPE)) {
          result.channelTypes[channelIndex] = channelTypeFromString(attributes.namedItem(XML_CHANNEL_ATTR_SOURCE).nodeValue());
          result.channelTextures[channelIndex] = child.firstChild().nodeValue();
        }
      }
    }
    result.vrEnabled = result.fragmentSource.contains("#pragma vr");
    return result;
  }
HTMLFormControlsCollectionImp::HTMLFormControlsCollectionImp(const HTMLFormElementPtr& form) :
    length(0)
{
    ElementPtr i = form;
    while (i = i->getNextElement(form)) {
        if (isListedElement(i)) {
            std::u16string name;
            Nullable<std::u16string> a = i->getAttribute(u"name");
            if (a.hasValue())
                name = a.value();
            if (name.empty()) {
                a = i->getAttribute(u"id");
                if (a.hasValue())
                    name = a.value();
            }
            Object found = namedItem(name);
            if (!found) {
                map.insert(std::pair<const std::u16string, Object>(name, i));
                ++length;
                continue;
            }
            if (html::RadioNodeList::hasInstance(found)) {
                html::RadioNodeList r = interface_cast<html::RadioNodeList>(found);
                if (auto list = std::dynamic_pointer_cast<RadioNodeListImp>(r.self())) {
                    list->addItem(i);
                    ++length;
                }
                continue;
            }
            auto list = std::make_shared<RadioNodeListImp>();
            if (list) {
                list->addItem(interface_cast<Element>(found));
                list->addItem(i);
                ++length;
                map.erase(name);
                map.insert(std::pair<const std::u16string, Object>(name, list));
            }
        }
    }
}
bool DOMNamedFlowCollection::hasNamedItem(const AtomicString& name) const
{
    return namedItem(name);
}