Exemplo n.º 1
0
void QgsLayerTreeLayer::writeXML( QDomElement& parentElement )
{
    QDomDocument doc = parentElement.ownerDocument();
    QDomElement elem = doc.createElement( "layer-tree-layer" );
    elem.setAttribute( "id", mLayerId );
    elem.setAttribute( "name", layerName() );
    elem.setAttribute( "checked", QgsLayerTreeUtils::checkStateToXml( mVisible ) );
    elem.setAttribute( "expanded", mExpanded ? "1" : "0" );

    writeCommonXML( elem );

    parentElement.appendChild( elem );
}
Exemplo n.º 2
0
void SVGRadialGradient::writeXML(xmlNodePtr node, Rect& bounds, bool hasModes, double opacity) {
	Matrix m;
	
	double w = bounds.right - bounds.left;
	double h = bounds.bottom - bounds.top;
	double shift = 0;
	
	if(userSpace) {
		m *= transform;
		m.translate(cx * 20, cy * 20);
		
		if(hasFocalPoint) {
			double dx = fx - cx;
			double dy = fy - cy;
			m.rotate(atan2(dy, dx));
			shift = sqrt(pow(dx, 2) + pow(dy, 2)) / r;
		}
				
		m.scale(r * 20 / 16348.0, r * 20 / 16384.0);
	} else {
		double _cx = bounds.left + cx * w;
		double _cy = bounds.top + cy * h;
		
		m.translate(_cx, _cy);
		
		m.scale(r * w / 16348.0, r * h / 16384.0);
		
		if(hasFocalPoint) {
			double _fx = bounds.left + fx * w;
			double _fy = bounds.top + fy * h;
			
			double dx = _fx - _cx;
			double dy = _fy - _cy;
			
			m.rotate(atan2(dy, dx));
			shift = sqrt(pow(dx, 2) + pow(dy, 2)) / (r * sqrt(pow(w, 2) + pow(h, 2)) / sqrt(2));
		}		
	}
	
	xmlNodePtr topNode;
	if(hasFocalPoint) {
		topNode = xmlNewChild(node, NULL, (const xmlChar *)"ShiftedRadialGradient", NULL);
		
		char tmp[TMP_STRLEN];	
		snprintf(tmp, TMP_STRLEN, "%f", shift);
		xmlSetProp(topNode, (const xmlChar *)"shift", (const xmlChar *)tmp);
	} else {
		topNode = xmlNewChild(node, NULL, (const xmlChar *)"RadialGradient", NULL);
	}
	writeCommonXML(topNode, m, hasModes, opacity);
}
Exemplo n.º 3
0
void SVGLinearGradient::writeXML(xmlNodePtr node, Rect& bounds, bool hadModes, double opacity) {
	double w = bounds.right - bounds.left;
	double h = bounds.bottom - bounds.top;

	Matrix m;

	if(userSpace) {
		double dx = x2 - x1;
		double dy = y2 - y1;
		double d = sqrt(dx * dx + dy * dy);
		double a = atan2(dy, dx);

		m *= transform;
		m.translate((x1 + x2) / 2 * 20, (y1 + y2) / 2 * 20);
		m.rotate(a);
		m.scale(d * 20 / 32768);
	} else {
		double sx, sy;
		
		double _x1 = bounds.left + x1 * w;
		double _y1 = bounds.top + y1 * h;
		double _x2 = bounds.left + x2 * w;
		double _y2 = bounds.top + y2 * h;

		if(x1 != x2) {
			sx = (_x2 - _x1) / 32768.0;
		} else {
			sx = 1;
		}

		if(y1 != y2) {
			sy = (_y2 - _y1) / 32768.0;
		} else {
			sy = 1;
		}

		double dx = x2 - x1;
		double dy = y2 - y1;
		double d = sqrt(dx * dx + dy * dy);
		double a = atan2(dy, dx);

		m.translate((_x1 + _x2) / 2, (_y1 + _y2) / 2);
		m.scale(sx, sy);
		m.rotate(a);
		m.scale(d);
	}

	xmlNodePtr topNode = xmlNewChild(node, NULL, (const xmlChar *)"LinearGradient", NULL);
	writeCommonXML(topNode, m, hadModes, opacity);
}