Beispiel #1
0
QDomDocumentFragment QDomDocumentProto::toDocumentFragment() const
{
    QDomDocument *item = qscriptvalue_cast<QDomDocument*>(thisObject());
    if (item)
        return item->toDocumentFragment();
    return QDomDocumentFragment();
}
Beispiel #2
0
QDomDocumentFragment QDomDocumentProto::createDocumentFragment()
{
    QDomDocument *item = qscriptvalue_cast<QDomDocument*>(thisObject());
    if (item)
        return item->createDocumentFragment();
    return QDomDocumentFragment();
}
Beispiel #3
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;
}