Beispiel #1
0
QString QDomDocumentFragmentProto::toString() const
{
  QDomDocumentFragment *item = qscriptvalue_cast<QDomDocumentFragment*>(thisObject());
  if (item)
    return QString("[QDomDocumentFragment(nodeType=%1)]").arg(item->nodeType());
  return QString("[QDomDocumentFragment(unknown)]");
}
Beispiel #2
0
int QDomDocumentFragmentProto:: nodeType() const
{
  QDomDocumentFragment *item = qscriptvalue_cast<QDomDocumentFragment*>(thisObject());
  if (item)
    return item->nodeType();
  return 0;
}
Beispiel #3
0
// Author & Date: Ehsan Azar       5 April 2012
// Purpose: Get document fragment one level deep
//           this fragment can be imported in other documents
// Outputs:
//   Returns a document fragment
QDomDocumentFragment XmlFile::getFragment()
{
    QDomElement node;
    if (m_nodes.isEmpty())
        node = m_doc.firstChildElement();
    else
        node = m_nodes.last();
    QDomDocumentFragment frag = m_doc.createDocumentFragment();
    QDomNodeList list = node.childNodes();
    for (uint i = 0; i < list.length(); ++i)
    {
        QDomNode node = list.item(i).cloneNode();
        frag.appendChild(node);
    }
    return frag;
}
Beispiel #4
0
QDomNode WbNewItem::serializeToSvg(QDomDocument *doc) {
	if(!graphicsItem()) {
		return QDomDocumentFragment();
	}

	// Generate the SVG using QSvgGenerator
	QBuffer buffer;

	QSvgGenerator generator;
	generator.setOutputDevice(&buffer);

	QPainter painter;
	QStyleOptionGraphicsItem options;
	painter.begin(&generator);
	graphicsItem()->paint(&painter, &options);
	painter.end();

	// qDebug("Serialized SVG doc:");
	// qDebug(buffer.buffer());

	// Parse the children of the new root <svg/> from the buffer to a document fragment
	// also add an 'id' attribute to each of the children
	doc->setContent(buffer.buffer());
	QDomDocumentFragment fragment = doc->createDocumentFragment();

	for(QDomNode n = doc->documentElement().lastChild(); !n.isNull(); n = n.previousSibling()) {
		// skip <title/>, <desc/>, and <defs/>
		if(n.isElement() &&
			!(n.nodeName() == "title"
				|| n.nodeName() == "desc"
				|| n.nodeName() == "defs")) {
			n.toElement().setAttribute("id", "e" + SxeSession::generateUUID());
			fragment.insertBefore(n, QDomNode());
		}
	}

	return fragment;
}
Beispiel #5
0
void Fidelity::GUI::ComponentLinkItem::compileXmlFragment(QDomDocumentFragment& fragment) const
{
	// Construct new link element
	QDomElement link = fragment.ownerDocument().createElement("link");

	// Construct first component element
	QDomElement startComponent = fragment.ownerDocument().createElement("component");
	startComponent.setAttribute("nodeName",m_StartNodeItem->Node()->Name());
	startComponent.setAttribute("uuid",m_StartComponentID);

	// Construct second component element
	QDomElement endComponent = fragment.ownerDocument().createElement("component");
	endComponent.setAttribute("nodeName",m_EndNodeItem->Node()->Name());
	endComponent.setAttribute("uuid",m_EndComponentID);
	
	// Handle nodeType attributenode where the link starts
	if(m_LinkType == BeamLink) {
		link.setAttribute("nodeType","beam");
	}
	else {
		link.setAttribute("nodeType","control");
	}

	// Handle directionality attribute
	if(m_Directionality == Unidirectional) {
		link.setAttribute("directionality","unidirectional");
		startComponent.setAttribute("role","source");
		endComponent.setAttribute("role","destination");
	}
	else {
		link.setAttribute("directionality","bidirectional");
	}

	// Put it all together
	link.appendChild(startComponent);
	link.appendChild(endComponent);
	fragment.appendChild(link);
}