34 #include <QDomDocument>
36 #include <QDomElement>
43 return QString(
"%1,%2,%3,%4" ).arg( color.red() ).arg( color.green() ).arg( color.blue() ).arg( color.alpha() );
48 QStringList lst = str.split(
"," );
49 if ( lst.count() < 3 )
53 int red, green, blue, alpha;
55 green = lst[1].toInt();
56 blue = lst[2].toInt();
58 if ( lst.count() > 3 )
60 alpha = lst[3].toInt();
62 return QColor( red, green, blue, alpha );
67 return QString::number( alpha / 255.0,
'f', 2 );
73 double alpha = str.toDouble( &ok );
74 if ( !ok || alpha > 1 )
85 case QFont::StyleNormal:
return "normal";
86 case QFont::StyleItalic:
return "italic";
87 case QFont::StyleOblique:
return "oblique";
94 if ( str ==
"normal" )
return QFont::StyleNormal;
95 if ( str ==
"italic" )
return QFont::StyleItalic;
96 if ( str ==
"oblique" )
return QFont::StyleOblique;
97 return QFont::StyleNormal;
102 if ( weight == 50 )
return "normal";
103 if ( weight == 75 )
return "bold";
107 if ( weight < 0 )
return "100";
108 if ( weight > 99 )
return "900";
109 return QString::number( weight * 800 / 99 + 100 );
115 int weight = str.toInt( &ok );
116 if ( !ok )
return (
int ) QFont::Normal;
120 if ( weight > 900 )
return 99;
121 if ( weight < 100 )
return 0;
122 return ( weight - 100 ) * 99 / 800;
129 case Qt::NoPen:
return "no";
130 case Qt::SolidLine:
return "solid";
131 case Qt::DashLine:
return "dash";
132 case Qt::DotLine:
return "dot";
133 case Qt::DashDotLine:
return "dash dot";
134 case Qt::DashDotDotLine:
return "dash dot dot";
135 default:
return "???";
141 if ( str ==
"no" )
return Qt::NoPen;
142 if ( str ==
"solid" )
return Qt::SolidLine;
143 if ( str ==
"dash" )
return Qt::DashLine;
144 if ( str ==
"dot" )
return Qt::DotLine;
145 if ( str ==
"dash dot" )
return Qt::DashDotLine;
146 if ( str ==
"dash dot dot" )
return Qt::DashDotDotLine;
147 return Qt::SolidLine;
154 case Qt::BevelJoin:
return "bevel";
155 case Qt::MiterJoin:
return "miter";
156 case Qt::RoundJoin:
return "round";
157 default:
return "???";
163 if ( str ==
"bevel" )
return Qt::BevelJoin;
164 if ( str ==
"miter" )
return Qt::MiterJoin;
165 if ( str ==
"round" )
return Qt::RoundJoin;
166 return Qt::BevelJoin;
173 case Qt::BevelJoin:
return "bevel";
174 case Qt::MiterJoin:
return "mitre";
175 case Qt::RoundJoin:
return "round";
182 if ( str ==
"bevel" )
return Qt::BevelJoin;
183 if ( str ==
"mitre" )
return Qt::MiterJoin;
184 if ( str ==
"round" )
return Qt::RoundJoin;
185 return Qt::BevelJoin;
192 case Qt::SquareCap:
return "square";
193 case Qt::FlatCap:
return "flat";
194 case Qt::RoundCap:
return "round";
195 default:
return "???";
201 if ( str ==
"square" )
return Qt::SquareCap;
202 if ( str ==
"flat" )
return Qt::FlatCap;
203 if ( str ==
"round" )
return Qt::RoundCap;
204 return Qt::SquareCap;
211 case Qt::SquareCap:
return "square";
212 case Qt::FlatCap:
return "butt";
213 case Qt::RoundCap:
return "round";
220 if ( str ==
"square" )
return Qt::SquareCap;
221 if ( str ==
"butt" )
return Qt::FlatCap;
222 if ( str ==
"round" )
return Qt::RoundCap;
223 return Qt::SquareCap;
230 case Qt::SolidPattern :
return "solid";
231 case Qt::HorPattern :
return "horizontal";
232 case Qt::VerPattern :
return "vertical";
233 case Qt::CrossPattern :
return "cross";
234 case Qt::BDiagPattern :
return "b_diagonal";
235 case Qt::FDiagPattern :
return "f_diagonal";
236 case Qt::DiagCrossPattern :
return "diagonal_x";
237 case Qt::Dense1Pattern :
return "dense1";
238 case Qt::Dense2Pattern :
return "dense2";
239 case Qt::Dense3Pattern :
return "dense3";
240 case Qt::Dense4Pattern :
return "dense4";
241 case Qt::Dense5Pattern :
return "dense5";
242 case Qt::Dense6Pattern :
return "dense6";
243 case Qt::Dense7Pattern :
return "dense7";
244 case Qt::NoBrush :
return "no";
245 default:
return "???";
251 if ( str ==
"solid" )
return Qt::SolidPattern;
252 if ( str ==
"horizontal" )
return Qt::HorPattern;
253 if ( str ==
"vertical" )
return Qt::VerPattern;
254 if ( str ==
"cross" )
return Qt::CrossPattern;
255 if ( str ==
"b_diagonal" )
return Qt::BDiagPattern;
256 if ( str ==
"f_diagonal" )
return Qt::FDiagPattern;
257 if ( str ==
"diagonal_x" )
return Qt::DiagCrossPattern;
258 if ( str ==
"dense1" )
return Qt::Dense1Pattern;
259 if ( str ==
"dense2" )
return Qt::Dense2Pattern;
260 if ( str ==
"dense3" )
return Qt::Dense3Pattern;
261 if ( str ==
"dense4" )
return Qt::Dense4Pattern;
262 if ( str ==
"dense5" )
return Qt::Dense5Pattern;
263 if ( str ==
"dense6" )
return Qt::Dense6Pattern;
264 if ( str ==
"dense7" )
return Qt::Dense7Pattern;
265 if ( str ==
"no" )
return Qt::NoBrush;
266 return Qt::SolidPattern;
273 case Qt::CrossPattern:
return "cross";
274 case Qt::DiagCrossPattern:
return "x";
280 case Qt::HorPattern:
return "horline";
281 case Qt::VerPattern:
return "line";
282 case Qt::BDiagPattern:
return "slash";
283 case Qt::FDiagPattern:
return "backslash";
286 case Qt::Dense1Pattern:
287 case Qt::Dense2Pattern:
288 case Qt::Dense3Pattern:
289 case Qt::Dense4Pattern:
290 case Qt::Dense5Pattern:
291 case Qt::Dense6Pattern:
292 case Qt::Dense7Pattern:
302 if ( str ==
"horline" )
return Qt::HorPattern;
303 if ( str ==
"line" )
return Qt::VerPattern;
304 if ( str ==
"cross" )
return Qt::CrossPattern;
305 if ( str ==
"slash" )
return Qt::BDiagPattern;
306 if ( str ==
"backshash" )
return Qt::FDiagPattern;
307 if ( str ==
"x" )
return Qt::DiagCrossPattern;
309 if ( str.startsWith(
"brush://" ) )
317 return QString(
"%1,%2" ).arg( point.x() ).arg( point.y() );
322 QStringList lst = str.split(
',' );
323 if ( lst.count() != 2 )
324 return QPointF( 0, 0 );
325 return QPointF( lst[0].toDouble(), lst[1].toDouble() );
330 return QString(
"%1,%2" ).arg( mapUnitScale.
minScale ).arg( mapUnitScale.
maxScale );
335 QStringList lst = str.split(
',' );
336 if ( lst.count() != 2 )
360 else if ( str ==
"MapUnit" )
375 *scaleFactor = 0.001;
376 return "http://www.opengeospatial.org/se/units/metre";
392 if ( str ==
"http://www.opengeospatial.org/se/units/metre" )
395 *scaleFactor = 1000.0;
398 else if ( str ==
"http://www.opengeospatial.org/se/units/foot" )
401 *scaleFactor = 304.8;
408 *scaleFactor = 1 / 0.00028;
414 QString vectorString;
415 QVector<qreal>::const_iterator it = v.constBegin();
416 for ( ; it != v.constEnd(); ++it )
418 if ( it != v.constBegin() )
420 vectorString.append(
";" );
422 vectorString.append( QString::number( *it ) );
429 QVector<qreal> resultVector;
431 QStringList realList = s.split(
";" );
432 QStringList::const_iterator it = realList.constBegin();
433 for ( ; it != realList.constEnd(); ++it )
435 resultVector.append( it->toDouble() );
443 QString vectorString;
444 QVector<qreal>::const_iterator it = v.constBegin();
445 for ( ; it != v.constEnd(); ++it )
447 if ( it != v.constBegin() )
449 vectorString.append(
" " );
451 vectorString.append( QString::number( *it ) );
458 QVector<qreal> resultVector;
460 QStringList realList = s.split(
" " );
461 QStringList::const_iterator it = realList.constBegin();
462 for ( ; it != realList.constEnd(); ++it )
464 resultVector.append( it->toDouble() );
472 QString encodedValue;
474 switch ( scaleMethod )
477 encodedValue =
"diameter";
480 encodedValue =
"area";
490 if ( str ==
"diameter" )
511 QPixmap pixmap( size );
512 pixmap.fill( Qt::transparent );
514 painter.begin( &pixmap );
515 painter.setRenderHint( QPainter::Antialiasing );
528 maxBleed = layerMaxBleed > maxBleed ? layerMaxBleed : maxBleed;
536 QPixmap pixmap( size );
537 pixmap.fill( Qt::transparent );
539 painter.begin( &pixmap );
540 painter.setRenderHint( QPainter::Antialiasing );
545 return QIcon( pixmap );
555 QPixmap pixmap( size );
556 pixmap.fill( Qt::transparent );
559 painter.begin( &pixmap );
566 for (
int i = 0; i < size.width(); i++ )
568 QPen pen( ramp->
color((
double ) i / size.width() ) );
569 painter.setPen( pen );
570 painter.drawLine( i, 0, i, size.height() - 1 );
579 uchar pixDataRGB[] = { 255, 255, 255, 255,
584 QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
586 int width = ( rect.width() < rect.height() ) ?
587 rect.width() / 2.5 : rect.height() / 2.5;
588 QPixmap pix = QPixmap::fromImage( img.scaled( width, width ) );
591 brush.setTexture( pix );
592 painter->fillRect( rect, brush );
601 #if !defined(GEOS_VERSION_MAJOR) || !defined(GEOS_VERSION_MINOR) || \
602 ((GEOS_VERSION_MAJOR<3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR<3)))
606 double x1 = p1.x(), y1 = p1.y(), x2 = p2.x(), y2 = p2.y();
608 if ( x1 == x2 && y1 == y2 )
612 t = ( x1 == x2 ? DBL_MAX : ( y2 - y1 ) / ( x2 - x1 ) );
616 angle = ( y2 > y1 ?
M_PI / 2 :
M_PI * 3 / 2 );
618 angle = ( x2 > x1 ? 0 :
M_PI );
620 angle = ( y2 > y1 ? atan( t ) :
M_PI + atan( t ) );
622 angle = ( y2 > y1 ?
M_PI + atan( t ) : atan( t ) );
630 return QPointF( pt.x() + dist * cos( angle ), pt.y() + dist * sin( angle ) );
637 if (( t1 == DBL_MAX && t2 == DBL_MAX ) || qAbs( atan( t1 ) - atan( t2 ) ) < 0.175 )
641 if ( t1 == DBL_MAX || t2 == DBL_MAX )
647 QPointF pSwp = p1; p1 = p2; p2 = pSwp;
648 double tSwp = t1; t1 = t2; t2 = tSwp;
656 x = (( p1.y() - p2.y() ) + t2 * p2.x() - t1 * p1.x() ) / ( t2 - t1 );
659 y = p1.y() + t1 * ( x - p1.x() );
660 return QPointF( x, y );
663 static QPolygonF makeOffsetGeometry(
const QgsPolyline& polyline )
665 int i, pointCount = polyline.count();
667 QPolygonF resultLine;
668 resultLine.resize( pointCount );
670 const QgsPoint* tempPtr = polyline.data();
672 for ( i = 0; i < pointCount; ++i, tempPtr++ )
673 resultLine[i] = QPointF( tempPtr->
x(), tempPtr->
y() );
677 static QList<QPolygonF> makeOffsetGeometry(
const QgsPolygon& polygon )
679 QList<QPolygonF> resultGeom;
680 for (
int ring = 0; ring < polygon.size(); ++ring ) resultGeom.append( makeOffsetGeometry( polygon[ ring ] ) );
687 QList<QPolygonF> resultLine;
689 if ( polyline.count() < 2 )
691 resultLine.append( polyline );
698 #if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
699 ((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
701 unsigned int i, pointCount = polyline.count();
704 QPointF* tempPtr = polyline.data();
705 for ( i = 0; i < pointCount; ++i, tempPtr++ )
706 tempPolyline[i] =
QgsPoint( tempPtr->rx(), tempPtr->ry() );
711 int quadSegments = 0;
712 double mitreLimit = 2.0;
715 offsetGeom = tempGeometry->
buffer( -dist, quadSegments, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, mitreLimit );
717 offsetGeom = tempGeometry->
offsetCurve( dist, quadSegments, GEOSBUF_JOIN_MITRE, mitreLimit );
722 tempGeometry = offsetGeom;
726 resultLine.append( makeOffsetGeometry( tempGeometry->
asPolyline() ) );
732 resultLine.append( makeOffsetGeometry( tempGeometry->
asPolygon() ) );
740 for (
int part = 0; part < tempMPolyline.count(); ++part )
742 resultLine.append( makeOffsetGeometry( tempMPolyline[ part ] ) );
751 for (
int part = 0; part < tempMPolygon.count(); ++part )
753 resultLine.append( makeOffsetGeometry( tempMPolygon[ part ] ) );
763 resultLine.append( polyline );
768 double angle = 0.0, t_new, t_old = 0;
769 QPointF pt_old, pt_new;
770 QPointF p1 = polyline[0], p2;
771 bool first_point =
true;
773 for (
int i = 1; i < polyline.count(); i++ )
777 if ( !
lineInfo( p1, p2, angle, t_new ) )
787 if ( !pt_tmp.isNull() )
791 newLine.append( pt_new );
801 newLine.append( pt_new );
803 resultLine.append( newLine );
808 QList<QPolygonF>
offsetLine( QPolygonF polyline,
double dist )
811 int pointCount = polyline.count();
813 if ( pointCount > 3 && polyline[ 0 ].x() == polyline[ pointCount - 1 ].x() && polyline[ 0 ].y() == polyline[ pointCount - 1 ].y() )
817 else if ( pointCount > 1 )
821 return offsetLine( polyline, dist, geometryType );
830 QDomNode layerNode = element.firstChild();
832 while ( !layerNode.isNull() )
834 QDomElement e = layerNode.toElement();
837 if ( e.tagName() !=
"layer" )
848 QDomElement s = e.firstChildElement(
"symbol" );
855 QgsDebugMsg(
"symbol layer refused subsymbol: " + s.attribute(
"name" ) );
858 layers.append( layer );
862 layerNode = layerNode.nextSibling();
865 if ( layers.count() == 0 )
871 QString symbolType = element.attribute(
"type" );
874 if ( symbolType ==
"line" )
876 else if ( symbolType ==
"fill" )
878 else if ( symbolType ==
"marker" )
882 QgsDebugMsg(
"unknown symbol type " + symbolType );
886 if ( element.hasAttribute(
"outputUnit" ) )
890 if ( element.hasAttribute((
"mapUnitScale" ) ) )
893 mapUnitScale.
minScale = element.attribute(
"mapUnitMinScale",
"0.0" ).toDouble();
894 mapUnitScale.
maxScale = element.attribute(
"mapUnitMaxScale",
"0.0" ).toDouble();
897 symbol->
setAlpha( element.attribute(
"alpha",
"1.0" ).toDouble() );
904 QString layerClass = element.attribute(
"class" );
905 bool locked = element.attribute(
"locked" ).toInt();
906 int pass = element.attribute(
"pass" ).toInt();
940 QDomElement symEl = doc.createElement(
"symbol" );
942 symEl.setAttribute(
"name", name );
943 symEl.setAttribute(
"alpha", QString::number( symbol->
alpha() ) );
950 QDomElement layerEl = doc.createElement(
"layer" );
951 layerEl.setAttribute(
"class", layer->
layerType() );
952 layerEl.setAttribute(
"locked", layer->
isLocked() );
957 QString subname = QString(
"@%1@%2" ).arg( name ).arg( i );
959 layerEl.appendChild( subEl );
961 symEl.appendChild( layerEl );
974 if ( element.isNull() )
979 QString symbolizerName = element.localName();
981 if ( symbolizerName ==
"PointSymbolizer" )
984 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
985 if ( graphicElem.isNull() )
987 QgsDebugMsg(
"Graphic element not found in PointSymbolizer" );
1023 if ( symbolizerName ==
"LineSymbolizer" )
1026 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1027 if ( strokeElem.isNull() )
1029 QgsDebugMsg(
"Stroke element not found in LineSymbolizer" );
1057 if ( symbolizerName ==
"PolygonSymbolizer" )
1060 QDomElement fillElem = element.firstChildElement(
"Fill" );
1061 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1062 if ( fillElem.isNull() && strokeElem.isNull() )
1064 QgsDebugMsg(
"neither Fill nor Stroke element not found in PolygonSymbolizer" );
1118 QDomElement fillElem = element.firstChildElement(
"Fill" );
1119 if ( fillElem.isNull() )
1141 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1142 if ( strokeElem.isNull() )
1160 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1161 if ( graphicElem.isNull() )
1183 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1184 if ( graphicElem.isNull() )
1187 QDomElement externalGraphicElem = graphicElem.firstChildElement(
"ExternalGraphic" );
1188 if ( externalGraphicElem.isNull() )
1192 QDomElement formatElem = externalGraphicElem.firstChildElement(
"Format" );
1193 if ( formatElem.isNull() )
1196 QString format = formatElem.firstChild().nodeValue();
1197 if ( format !=
"image/svg+xml" )
1199 QgsDebugMsg(
"unsupported External Graphic format found: " + format );
1204 QDomElement onlineResourceElem = externalGraphicElem.firstChildElement(
"OnlineResource" );
1205 QDomElement inlineContentElem = externalGraphicElem.firstChildElement(
"InlineContent" );
1206 if ( !onlineResourceElem.isNull() )
1211 else if ( !inlineContentElem.isNull() )
1224 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1225 if ( graphicElem.isNull() )
1228 QDomElement markElem = graphicElem.firstChildElement(
"Mark" );
1229 if ( markElem.isNull() )
1232 QDomElement wellKnownNameElem = markElem.firstChildElement(
"WellKnownName" );
1233 if ( wellKnownNameElem.isNull() )
1242 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1243 if ( graphicElem.isNull() )
1246 QDomElement markElem = graphicElem.firstChildElement(
"Mark" );
1247 if ( markElem.isNull() )
1251 QDomElement formatElem = markElem.firstChildElement(
"Format" );
1252 if ( formatElem.isNull() )
1255 QString format = formatElem.firstChild().nodeValue();
1256 if ( format !=
"ttf" )
1258 QgsDebugMsg(
"unsupported Graphic Mark format found: " + format );
1263 QDomElement onlineResourceElem = markElem.firstChildElement(
"OnlineResource" );
1264 QDomElement inlineContentElem = markElem.firstChildElement(
"InlineContent" );
1265 if ( !onlineResourceElem.isNull() )
1268 QDomElement markIndexElem = markElem.firstChildElement(
"MarkIndex" );
1269 if ( !markIndexElem.isNull() )
1272 else if ( !inlineContentElem.isNull() )
1287 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1288 if ( graphicElem.isNull() )
1292 for ( QgsStringMap::iterator it = vendorOptions.begin(); it != vendorOptions.end(); ++it )
1294 if ( it.key() ==
"widthHeightFactor" )
1305 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1306 if ( strokeElem.isNull() )
1309 QDomElement graphicStrokeElem = strokeElem.firstChildElement(
"GraphicStroke" );
1310 if ( graphicStrokeElem.isNull() )
1318 QDomElement fillElem = element.firstChildElement(
"Fill" );
1319 if ( fillElem.isNull() )
1322 QDomElement graphicFillElem = fillElem.firstChildElement(
"GraphicFill" );
1323 if ( graphicFillElem.isNull() )
1326 QDomElement graphicElem = graphicFillElem.firstChildElement(
"Graphic" );
1327 if ( graphicElem.isNull() )
1333 QColor fillColor, borderColor;
1334 double size, borderWidth;
1335 Qt::PenStyle borderStyle;
1336 if ( !
wellKnownMarkerFromSld( graphicElem, name, fillColor, borderColor, borderStyle, borderWidth, size ) )
1339 if ( name !=
"horline" )
1347 double angle = angleFunc.toDouble( &ok );
1348 if ( !ok || angle == 0 )
1356 Q_UNUSED( element );
1362 QDomElement fillElem = element.firstChildElement(
"Fill" );
1363 if ( fillElem.isNull() )
1366 QDomElement graphicFillElem = fillElem.firstChildElement(
"GraphicFill" );
1367 if ( graphicFillElem.isNull() )
1387 QDomElement fillElem = element.firstChildElement(
"Fill" );
1388 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1392 bool validFill =
false, validBorder =
false;
1397 Qt::BrushStyle fillStyle;
1399 if (
fillFromSld( fillElem, fillStyle, fillColor ) )
1405 Qt::PenStyle borderStyle;
1406 double borderWidth = 1.0, dashOffset = 0.0;
1407 QVector<qreal> customDashPattern;
1409 if (
lineFromSld( strokeElem, borderStyle, borderColor, borderWidth,
1410 0, 0, &customDashPattern, &dashOffset ) )
1413 if ( validFill || validBorder )
1416 map[
"name"] =
"square";
1417 map[
"color"] =
encodeColor( validFill ? fillColor : Qt::transparent );
1418 map[
"color_border"] =
encodeColor( validBorder ? borderColor : Qt::transparent );
1419 map[
"size"] = QString::number( 6 );
1420 map[
"angle"] = QString::number( 0 );
1428 bool validFill =
false, validBorder =
false;
1431 QString name, format;
1433 QColor fillColor, borderColor;
1434 double borderWidth = 1.0,
size = 0.0,
angle = 0.0;
1435 QPointF anchor, offset;
1438 QDomElement graphicFillElem = fillElem.firstChildElement(
"GraphicFill" );
1439 if ( !graphicFillElem.isNull() )
1442 QDomElement graphicElem = graphicFillElem.firstChildElement(
"Graphic" );
1443 if ( !graphicElem.isNull() )
1449 QDomElement graphicChildElem = graphicElem.firstChildElement();
1450 while ( !graphicChildElem.isNull() )
1452 if ( graphicChildElem.localName() ==
"Mark" )
1455 QDomElement wellKnownNameElem = graphicChildElem.firstChildElement(
"WellKnownName" );
1456 if ( !wellKnownNameElem.isNull() )
1458 name = wellKnownNameElem.firstChild().nodeValue();
1464 if ( graphicChildElem.localName() ==
"ExternalGraphic" || graphicChildElem.localName() ==
"Mark" )
1467 QDomElement formatElem = graphicChildElem.firstChildElement(
"Format" );
1468 if ( formatElem.isNull() )
1471 format = formatElem.firstChild().nodeValue();
1475 if ( graphicChildElem.localName() ==
"ExternalGraphic" && format !=
"image/svg+xml" )
1480 if ( graphicChildElem.localName() ==
"Mark" && format !=
"ttf" )
1484 QDomElement onlineResourceElem = graphicChildElem.firstChildElement(
"OnlineResource" );
1485 QDomElement inlineContentElem = graphicChildElem.firstChildElement(
"InlineContent" );
1487 if ( !onlineResourceElem.isNull() )
1489 name = onlineResourceElem.attributeNS(
"http://www.w3.org/1999/xlink",
"href" );
1491 if ( graphicChildElem.localName() ==
"Mark" && format ==
"ttf" )
1494 if ( name.startsWith(
"ttf://" ) )
1495 name = name.mid( 6 );
1498 QDomElement markIndexElem = graphicChildElem.firstChildElement(
"MarkIndex" );
1499 if ( markIndexElem.isNull() )
1503 int v = markIndexElem.firstChild().nodeValue().toInt( &ok );
1514 else if ( !inlineContentElem.isNull() )
1524 if ( graphicChildElem.localName() ==
"Mark" )
1533 if ( found && graphicChildElem.localName() ==
"Mark" )
1540 Qt::BrushStyle markFillStyle;
1542 QDomElement markFillElem = graphicChildElem.firstChildElement(
"Fill" );
1543 if (
fillFromSld( markFillElem, markFillStyle, fillColor ) )
1548 Qt::PenStyle borderStyle;
1549 double borderWidth = 1.0, dashOffset = 0.0;
1550 QVector<qreal> customDashPattern;
1552 QDomElement markStrokeElem = graphicChildElem.firstChildElement(
"Stroke" );
1553 if (
lineFromSld( markStrokeElem, borderStyle, borderColor, borderWidth,
1554 0, 0, &customDashPattern, &dashOffset ) )
1561 QDomElement opacityElem = graphicElem.firstChildElement(
"Opacity" );
1562 if ( !opacityElem.isNull() )
1563 fillColor.setAlpha(
decodeSldAlpha( opacityElem.firstChild().nodeValue() ) );
1565 QDomElement sizeElem = graphicElem.firstChildElement(
"Size" );
1566 if ( !sizeElem.isNull() )
1569 double v = sizeElem.firstChild().nodeValue().toDouble( &ok );
1578 double v = angleFunc.toDouble( &ok );
1588 if ( validFill || validBorder )
1590 if ( format ==
"image/svg+xml" )
1594 map[
"fill"] = fillColor.name();
1595 map[
"outline"] = borderColor.name();
1596 map[
"outline-width"] = QString::number( borderWidth );
1598 map[
"size"] = QString::number(
size );
1600 map[
"angle"] = QString::number(
angle );
1601 if ( !offset.isNull() )
1605 else if ( format ==
"ttf" )
1609 map[
"chr"] = markIndex;
1610 map[
"color"] =
encodeColor( validFill ? fillColor : Qt::transparent );
1612 map[
"size"] = QString::number(
size );
1614 map[
"angle"] = QString::number(
angle );
1615 if ( !offset.isNull() )
1622 if ( layers.isEmpty() )
1625 layerList << layers;
1632 QString patternName;
1633 switch ( brushStyle )
1638 case Qt::SolidPattern:
1639 if ( color.isValid() )
1642 if ( color.alpha() < 255 )
1647 case Qt::CrossPattern:
1648 case Qt::DiagCrossPattern:
1649 case Qt::HorPattern:
1650 case Qt::VerPattern:
1651 case Qt::BDiagPattern:
1652 case Qt::FDiagPattern:
1653 case Qt::Dense1Pattern:
1654 case Qt::Dense2Pattern:
1655 case Qt::Dense3Pattern:
1656 case Qt::Dense4Pattern:
1657 case Qt::Dense5Pattern:
1658 case Qt::Dense6Pattern:
1659 case Qt::Dense7Pattern:
1664 element.appendChild( doc.createComment( QString(
"Qt::BrushStyle '%1'' not supported yet" ).arg( brushStyle ) ) );
1668 QDomElement graphicFillElem = doc.createElement(
"se:GraphicFill" );
1669 element.appendChild( graphicFillElem );
1671 QDomElement graphicElem = doc.createElement(
"se:Graphic" );
1672 graphicFillElem.appendChild( graphicElem );
1674 QColor fillColor = patternName.startsWith(
"brush://" ) ? color : QColor();
1675 QColor borderColor = !patternName.startsWith(
"brush://" ) ? color : QColor();
1678 wellKnownMarkerToSld( doc, graphicElem, patternName, fillColor, borderColor, Qt::SolidLine, -1, -1 );
1685 brushStyle = Qt::SolidPattern;
1686 color = QColor(
"#808080" );
1688 if ( element.isNull() )
1690 brushStyle = Qt::NoBrush;
1695 QDomElement graphicFillElem = element.firstChildElement(
"GraphicFill" );
1697 if ( graphicFillElem.isNull() )
1700 for ( QgsStringMap::iterator it = svgParams.begin(); it != svgParams.end(); ++it )
1702 QgsDebugMsg( QString(
"found SvgParameter %1: %2" ).arg( it.key() ).arg( it.value() ) );
1704 if ( it.key() ==
"fill" )
1705 color = QColor( it.value() );
1706 else if ( it.key() ==
"fill-opacity" )
1712 QDomElement graphicElem = graphicFillElem.firstChildElement(
"Graphic" );
1713 if ( graphicElem.isNull() )
1716 QString patternName =
"square";
1717 QColor fillColor, borderColor;
1718 double borderWidth,
size;
1719 Qt::PenStyle borderStyle;
1720 if ( !
wellKnownMarkerFromSld( graphicElem, patternName, fillColor, borderColor, borderStyle, borderWidth, size ) )
1724 if ( brushStyle == Qt::NoBrush )
1727 QColor c = patternName.startsWith(
"brush://" ) ? fillColor : borderColor;
1736 Qt::PenStyle penStyle, QColor color,
double width,
1737 const Qt::PenJoinStyle *penJoinStyle,
const Qt::PenCapStyle *penCapStyle,
1738 const QVector<qreal> *customDashPattern,
double dashOffset )
1740 QVector<qreal> dashPattern;
1741 const QVector<qreal> *pattern = &dashPattern;
1743 if ( penStyle == Qt::CustomDashLine && !customDashPattern )
1745 element.appendChild( doc.createComment(
"WARNING: Custom dash pattern required but not provided. Using default dash pattern." ) );
1746 penStyle = Qt::DashLine;
1758 dashPattern.push_back( 4.0 );
1759 dashPattern.push_back( 2.0 );
1762 dashPattern.push_back( 1.0 );
1763 dashPattern.push_back( 2.0 );
1765 case Qt::DashDotLine:
1766 dashPattern.push_back( 4.0 );
1767 dashPattern.push_back( 2.0 );
1768 dashPattern.push_back( 1.0 );
1769 dashPattern.push_back( 2.0 );
1771 case Qt::DashDotDotLine:
1772 dashPattern.push_back( 4.0 );
1773 dashPattern.push_back( 2.0 );
1774 dashPattern.push_back( 1.0 );
1775 dashPattern.push_back( 2.0 );
1776 dashPattern.push_back( 1.0 );
1777 dashPattern.push_back( 2.0 );
1780 case Qt::CustomDashLine:
1781 Q_ASSERT( customDashPattern );
1782 pattern = customDashPattern;
1786 element.appendChild( doc.createComment( QString(
"Qt::BrushStyle '%1'' not supported yet" ).arg( penStyle ) ) );
1790 if ( color.isValid() )
1793 if ( color.alpha() < 255 )
1803 if ( pattern->size() > 0 )
1813 Qt::PenStyle &penStyle, QColor &color,
double &width,
1814 Qt::PenJoinStyle *penJoinStyle, Qt::PenCapStyle *penCapStyle,
1815 QVector<qreal> *customDashPattern,
double *dashOffset )
1819 penStyle = Qt::SolidLine;
1820 color = QColor(
"#000000" );
1823 *penJoinStyle = Qt::BevelJoin;
1825 *penCapStyle = Qt::SquareCap;
1826 if ( customDashPattern )
1827 customDashPattern->clear();
1831 if ( element.isNull() )
1833 penStyle = Qt::NoPen;
1839 for ( QgsStringMap::iterator it = svgParams.begin(); it != svgParams.end(); ++it )
1841 QgsDebugMsg( QString(
"found SvgParameter %1: %2" ).arg( it.key() ).arg( it.value() ) );
1843 if ( it.key() ==
"stroke" )
1845 color = QColor( it.value() );
1847 else if ( it.key() ==
"stroke-opacity" )
1851 else if ( it.key() ==
"stroke-width" )
1854 double w = it.value().toDouble( &ok );
1858 else if ( it.key() ==
"stroke-linejoin" && penJoinStyle )
1862 else if ( it.key() ==
"stroke-linecap" && penCapStyle )
1866 else if ( it.key() ==
"stroke-dasharray" )
1869 if ( dashPattern.size() > 0 )
1873 bool dashPatternFound =
false;
1875 if ( dashPattern.count() == 2 )
1877 if ( dashPattern.at( 0 ) == 4.0 &&
1878 dashPattern.at( 1 ) == 2.0 )
1880 penStyle = Qt::DashLine;
1881 dashPatternFound =
true;
1883 else if ( dashPattern.at( 0 ) == 1.0 &&
1884 dashPattern.at( 1 ) == 2.0 )
1886 penStyle = Qt::DotLine;
1887 dashPatternFound =
true;
1890 else if ( dashPattern.count() == 4 )
1892 if ( dashPattern.at( 0 ) == 4.0 &&
1893 dashPattern.at( 1 ) == 2.0 &&
1894 dashPattern.at( 2 ) == 1.0 &&
1895 dashPattern.at( 3 ) == 2.0 )
1897 penStyle = Qt::DashDotLine;
1898 dashPatternFound =
true;
1901 else if ( dashPattern.count() == 6 )
1903 if ( dashPattern.at( 0 ) == 4.0 &&
1904 dashPattern.at( 1 ) == 2.0 &&
1905 dashPattern.at( 2 ) == 1.0 &&
1906 dashPattern.at( 3 ) == 2.0 &&
1907 dashPattern.at( 4 ) == 1.0 &&
1908 dashPattern.at( 5 ) == 2.0 )
1910 penStyle = Qt::DashDotDotLine;
1911 dashPatternFound =
true;
1916 if ( !dashPatternFound )
1918 if ( customDashPattern )
1920 penStyle = Qt::CustomDashLine;
1921 *customDashPattern = dashPattern;
1925 QgsDebugMsg(
"custom dash pattern required but not provided. Using default dash pattern." );
1926 penStyle = Qt::DashLine;
1931 else if ( it.key() ==
"stroke-dashoffset" && dashOffset )
1934 double d = it.value().toDouble( &ok );
1944 QString path, QString mime,
1945 QColor color,
double size )
1947 QDomElement externalGraphicElem = doc.createElement(
"se:ExternalGraphic" );
1948 element.appendChild( externalGraphicElem );
1957 QDomElement sizeElem = doc.createElement(
"se:Size" );
1958 sizeElem.appendChild( doc.createTextNode( QString::number( size ) ) );
1959 element.appendChild( sizeElem );
1964 QString &path, QString &mime,
1965 QColor &color,
double &
size )
1970 QDomElement externalGraphicElem = element.firstChildElement(
"ExternalGraphic" );
1971 if ( externalGraphicElem.isNull() )
1976 QDomElement sizeElem = element.firstChildElement(
"Size" );
1977 if ( !sizeElem.isNull() )
1980 double s = sizeElem.firstChild().nodeValue().toDouble( &ok );
1989 QString path, QString format,
int *markIndex,
1990 QColor color,
double size )
1992 QDomElement markElem = doc.createElement(
"se:Mark" );
1993 element.appendChild( markElem );
1999 QDomElement markIndexElem = doc.createElement(
"se:MarkIndex" );
2000 markIndexElem.appendChild( doc.createTextNode( QString::number( *markIndex ) ) );
2001 markElem.appendChild( markIndexElem );
2005 QDomElement fillElem = doc.createElement(
"se:Fill" );
2006 fillToSld( doc, fillElem, Qt::SolidPattern, color );
2007 markElem.appendChild( fillElem );
2012 QDomElement sizeElem = doc.createElement(
"se:Size" );
2013 sizeElem.appendChild( doc.createTextNode( QString::number( size ) ) );
2014 element.appendChild( sizeElem );
2019 QString &path, QString &format,
int &markIndex,
2020 QColor &color,
double &
size )
2028 QDomElement markElem = element.firstChildElement(
"Mark" );
2029 if ( markElem.isNull() )
2034 QDomElement markIndexElem = markElem.firstChildElement(
"MarkIndex" );
2035 if ( !markIndexElem.isNull() )
2038 int i = markIndexElem.firstChild().nodeValue().toInt( &ok );
2044 QDomElement fillElem = markElem.firstChildElement(
"Fill" );
2045 Qt::BrushStyle b = Qt::SolidPattern;
2050 QDomElement sizeElem = element.firstChildElement(
"Size" );
2051 if ( !sizeElem.isNull() )
2054 double s = sizeElem.firstChild().nodeValue().toDouble( &ok );
2063 QString name, QColor color, QColor borderColor,
2064 double borderWidth,
double size )
2066 wellKnownMarkerToSld( doc, element, name, color, borderColor, Qt::SolidLine, borderWidth, size );
2070 QString name, QColor color, QColor borderColor, Qt::PenStyle borderStyle,
2071 double borderWidth,
double size )
2073 QDomElement markElem = doc.createElement(
"se:Mark" );
2074 element.appendChild( markElem );
2076 QDomElement wellKnownNameElem = doc.createElement(
"se:WellKnownName" );
2077 wellKnownNameElem.appendChild( doc.createTextNode( name ) );
2078 markElem.appendChild( wellKnownNameElem );
2081 if ( color.isValid() )
2083 QDomElement fillElem = doc.createElement(
"se:Fill" );
2084 fillToSld( doc, fillElem, Qt::SolidPattern, color );
2085 markElem.appendChild( fillElem );
2089 if ( borderColor.isValid() )
2091 QDomElement strokeElem = doc.createElement(
"se:Stroke" );
2092 lineToSld( doc, strokeElem, borderStyle, borderColor, borderWidth );
2093 markElem.appendChild( strokeElem );
2099 QDomElement sizeElem = doc.createElement(
"se:Size" );
2100 sizeElem.appendChild( doc.createTextNode( QString::number( size ) ) );
2101 element.appendChild( sizeElem );
2106 QString &name, QColor &color, QColor &borderColor,
2107 double &borderWidth,
double &
size )
2109 Qt::PenStyle borderStyle;
2114 QString &name, QColor &color, QColor &borderColor, Qt::PenStyle &borderStyle,
2115 double &borderWidth,
double &
size )
2121 borderColor = QColor(
"#000000" );
2125 QDomElement markElem = element.firstChildElement(
"Mark" );
2126 if ( markElem.isNull() )
2129 QDomElement wellKnownNameElem = markElem.firstChildElement(
"WellKnownName" );
2130 if ( !wellKnownNameElem.isNull() )
2132 name = wellKnownNameElem.firstChild().nodeValue();
2133 QgsDebugMsg(
"found Mark with well known name: " + name );
2137 QDomElement fillElem = markElem.firstChildElement(
"Fill" );
2138 Qt::BrushStyle b = Qt::SolidPattern;
2143 QDomElement strokeElem = markElem.firstChildElement(
"Stroke" );
2144 lineFromSld( strokeElem, borderStyle, borderColor, borderWidth );
2148 QDomElement sizeElem = element.firstChildElement(
"Size" );
2149 if ( !sizeElem.isNull() )
2152 double s = sizeElem.firstChild().nodeValue().toDouble( &ok );
2162 if ( !rotationFunc.isEmpty() )
2164 QDomElement rotationElem = doc.createElement(
"se:Rotation" );
2166 element.appendChild( rotationElem );
2172 QDomElement rotationElem = element.firstChildElement(
"Rotation" );
2173 if ( !rotationElem.isNull() )
2183 if ( !alphaFunc.isEmpty() )
2185 QDomElement opacityElem = doc.createElement(
"se:Opacity" );
2187 element.appendChild( opacityElem );
2193 QDomElement opacityElem = element.firstChildElement(
"Opacity" );
2194 if ( !opacityElem.isNull() )
2203 if ( offset.isNull() )
2206 QDomElement displacementElem = doc.createElement(
"se:Displacement" );
2207 element.appendChild( displacementElem );
2209 QDomElement dispXElem = doc.createElement(
"se:DisplacementX" );
2210 dispXElem.appendChild( doc.createTextNode( QString::number( offset.x() ) ) );
2212 QDomElement dispYElem = doc.createElement(
"se:DisplacementY" );
2213 dispYElem.appendChild( doc.createTextNode( QString::number( offset.y() ) ) );
2215 displacementElem.appendChild( dispXElem );
2216 displacementElem.appendChild( dispYElem );
2221 offset = QPointF( 0, 0 );
2223 QDomElement displacementElem = element.firstChildElement(
"Displacement" );
2224 if ( displacementElem.isNull() )
2227 QDomElement dispXElem = displacementElem.firstChildElement(
"DisplacementX" );
2228 if ( !dispXElem.isNull() )
2231 double offsetX = dispXElem.firstChild().nodeValue().toDouble( &ok );
2233 offset.setX( offsetX );
2236 QDomElement dispYElem = displacementElem.firstChildElement(
"DisplacementY" );
2237 if ( !dispYElem.isNull() )
2240 double offsetY = dispYElem.firstChild().nodeValue().toDouble( &ok );
2242 offset.setY( offsetY );
2249 QString label, QFont font,
2250 QColor color,
double size )
2252 QDomElement labelElem = doc.createElement(
"se:Label" );
2253 labelElem.appendChild( doc.createTextNode( label ) );
2254 element.appendChild( labelElem );
2256 QDomElement fontElem = doc.createElement(
"se:Font" );
2257 element.appendChild( fontElem );
2261 fontElem.appendChild( createSldParameterElement( doc,
"font-style",
encodeSldFontStyle( font.style() ) ) );
2262 fontElem.appendChild( createSldParameterElement( doc,
"font-weight",
encodeSldFontWeight( font.weight() ) ) );
2267 if ( color.isValid() )
2269 QDomElement fillElem = doc.createElement(
"Fill" );
2270 fillToSld( doc, fillElem, Qt::SolidPattern, color );
2271 element.appendChild( fillElem );
2276 Qt::PenJoinStyle joinStyle,
2277 Qt::PenCapStyle capStyle,
2279 const QVector<qreal>* dashPattern )
2282 penStyle.append(
"PEN(" );
2283 penStyle.append(
"c:" );
2284 penStyle.append( c.name() );
2285 penStyle.append(
",w:" );
2287 penStyle.append( QString::number( width * mmScaleFactor ) );
2288 penStyle.append(
"mm" );
2291 if ( dashPattern && dashPattern->size() > 0 )
2293 penStyle.append(
",p:\"" );
2294 QVector<qreal>::const_iterator pIt = dashPattern->constBegin();
2295 for ( ; pIt != dashPattern->constEnd(); ++pIt )
2297 if ( pIt != dashPattern->constBegin() )
2299 penStyle.append(
" " );
2301 penStyle.append( QString::number( *pIt * mapUnitScaleFactor ) );
2302 penStyle.append(
"g" );
2304 penStyle.append(
"\"" );
2308 penStyle.append(
",cap:" );
2312 penStyle.append(
"p" );
2315 penStyle.append(
"r" );
2319 penStyle.append(
"b" );
2323 penStyle.append(
",j:" );
2324 switch ( joinStyle )
2327 penStyle.append(
"b" );
2330 penStyle.append(
"r" );
2334 penStyle.append(
"m" );
2340 penStyle.append(
",dp:" );
2341 penStyle.append( QString::number( offset * mapUnitScaleFactor ) );
2342 penStyle.append(
"g" );
2345 penStyle.append(
")" );
2352 brushStyle.append(
"BRUSH(" );
2353 brushStyle.append(
"fc:" );
2354 brushStyle.append( fillColor.name() );
2355 brushStyle.append(
")" );
2361 if ( geomFunc.isEmpty() )
2364 QDomElement geometryElem = doc.createElement(
"Geometry" );
2365 element.appendChild( geometryElem );
2395 QDomElement geometryElem = element.firstChildElement(
"Geometry" );
2396 if ( geometryElem.isNull() )
2408 element.appendChild( doc.createComment(
"Parser Error: " + expr.
parserErrorString() +
" - Expression was: " + function ) );
2412 if ( !filterElem.isNull() )
2413 element.appendChild( filterElem );
2421 if ( element.tagName() ==
"Filter" )
2427 QDomNodeList filterNodes = element.elementsByTagName(
"Filter" );
2428 if ( filterNodes.size() > 0 )
2430 elem = filterNodes.at( 0 ).toElement();
2434 if ( elem.isNull() )
2459 QString path, QString format )
2463 QDomElement onlineResourceElem = doc.createElement(
"se:OnlineResource" );
2464 onlineResourceElem.setAttribute(
"xlink:type",
"simple" );
2465 onlineResourceElem.setAttribute(
"xlink:href", url );
2466 element.appendChild( onlineResourceElem );
2468 QDomElement formatElem = doc.createElement(
"se:Format" );
2469 formatElem.appendChild( doc.createTextNode( format ) );
2470 element.appendChild( formatElem );
2477 QDomElement onlineResourceElem = element.firstChildElement(
"OnlineResource" );
2478 if ( onlineResourceElem.isNull() )
2481 path = onlineResourceElem.attributeNS(
"http://www.w3.org/1999/xlink",
"href" );
2483 QDomElement formatElem = element.firstChildElement(
"Format" );
2484 if ( formatElem.isNull() )
2487 format = formatElem.firstChild().nodeValue();
2494 QDomElement nodeElem = doc.createElement(
"se:SvgParameter" );
2495 nodeElem.setAttribute(
"name", name );
2496 nodeElem.appendChild( doc.createTextNode( value ) );
2504 QDomElement paramElem = element.firstChildElement();
2505 while ( !paramElem.isNull() )
2507 if ( paramElem.localName() ==
"SvgParameter" || paramElem.localName() ==
"CssParameter" )
2509 QString name = paramElem.attribute(
"name" );
2510 QString value = paramElem.firstChild().nodeValue();
2512 if ( !name.isEmpty() && !value.isEmpty() )
2513 params[ name ] = value;
2516 paramElem = paramElem.nextSiblingElement();
2524 QDomElement nodeElem = doc.createElement(
"VendorOption" );
2525 nodeElem.setAttribute(
"name", name );
2526 nodeElem.appendChild( doc.createTextNode( value ) );
2534 QDomElement paramElem = element.firstChildElement(
"VendorOption" );
2535 while ( !paramElem.isNull() )
2537 QString name = paramElem.attribute(
"name" );
2538 QString value = paramElem.firstChild().nodeValue();
2540 if ( !name.isEmpty() && !value.isEmpty() )
2541 params[ name ] = value;
2543 paramElem = paramElem.nextSiblingElement(
"VendorOption" );
2553 QDomElement e = element.firstChildElement();
2554 while ( !e.isNull() )
2556 if ( e.tagName() !=
"prop" )
2562 QString propKey = e.attribute(
"k" );
2563 QString propValue = e.attribute(
"v" );
2564 props[propKey] = propValue;
2566 e = e.nextSiblingElement();
2574 for ( QgsStringMap::iterator it = props.begin(); it != props.end(); ++it )
2576 QDomElement propEl = doc.createElement(
"prop" );
2577 propEl.setAttribute(
"k", it.key() );
2578 propEl.setAttribute(
"v", it.value() );
2579 element.appendChild( propEl );
2588 QDomElement e = element.firstChildElement();
2590 while ( !e.isNull() )
2592 if ( e.tagName() ==
"symbol" )
2595 if ( symbol != NULL )
2596 symbols.insert( e.attribute(
"name" ), symbol );
2602 e = e.nextSiblingElement();
2609 QStringList subsymbols;
2611 for ( QMap<QString, QgsSymbolV2*>::iterator it = symbols.begin(); it != symbols.end(); ++it )
2613 if ( it.key()[0] !=
'@' )
2617 subsymbols.append( it.key() );
2619 QStringList parts = it.key().split(
"@" );
2620 if ( parts.count() < 3 )
2622 QgsDebugMsg(
"found subsymbol with invalid name: " + it.key() );
2626 QString symname = parts[1];
2627 int symlayer = parts[2].toInt();
2629 if ( !symbols.contains( symname ) )
2631 QgsDebugMsg(
"subsymbol references invalid symbol: " + symname );
2639 QgsDebugMsg(
"subsymbol references invalid symbol layer: " + QString::number( symlayer ) );
2648 QgsDebugMsg(
"symbol layer refused subsymbol: " + it.key() );
2655 for (
int i = 0; i < subsymbols.count(); i++ )
2656 symbols.take( subsymbols[i] );
2663 QDomElement symbolsElem = doc.createElement( tagName );
2666 for ( QMap<QString, QgsSymbolV2*>::iterator its = symbols.begin(); its != symbols.end(); ++its )
2668 QDomElement symEl =
saveSymbol( its.key(), its.value(), doc );
2669 symbolsElem.appendChild( symEl );
2677 foreach ( QString name, symbols.keys() )
2679 delete symbols.value( name );
2687 QString rampType = element.attribute(
"type" );
2692 if ( rampType ==
"gradient" )
2694 else if ( rampType ==
"random" )
2696 else if ( rampType ==
"colorbrewer" )
2698 else if ( rampType ==
"cpt-city" )
2702 QgsDebugMsg(
"unknown colorramp type " + rampType );
2710 QDomElement rampEl = doc.createElement(
"colorramp" );
2711 rampEl.setAttribute(
"type", ramp->
type() );
2712 rampEl.setAttribute(
"name", name );
2729 if ( QColor::isValidColor( colorStr ) )
2732 parsedColor.setNamedColor( colorStr );
2733 if ( parsedColor.isValid() )
2735 containsAlpha =
false;
2741 QRegExp hexColorRx2(
"^\\s*(?:[0-9a-fA-F]{3}){1,2}\\s*$" );
2742 if ( hexColorRx2.indexIn( colorStr ) != -1 )
2745 parsedColor.setNamedColor( QString(
"#" ) + colorStr );
2746 if ( parsedColor.isValid() )
2748 containsAlpha =
false;
2754 QRegExp rgbFormatRx(
"^\\s*(?:rgb)?\\(?\\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\s*,\\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\s*,\\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\s*\\)?\\s*;?\\s*$" );
2755 if ( rgbFormatRx.indexIn( colorStr ) != -1 )
2757 int r = rgbFormatRx.cap( 1 ).toInt();
2758 int g = rgbFormatRx.cap( 2 ).toInt();
2759 int b = rgbFormatRx.cap( 3 ).toInt();
2760 parsedColor.setRgb( r, g, b );
2761 if ( parsedColor.isValid() )
2763 containsAlpha =
false;
2769 QRegExp rgbPercentFormatRx(
"^\\s*(?:rgb)?\\(?\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(100|0*\\d{1,2})\\s*%\\s*\\)?\\s*;?\\s*$" );
2770 if ( rgbPercentFormatRx.indexIn( colorStr ) != -1 )
2772 int r = qRound( rgbPercentFormatRx.cap( 1 ).toDouble() * 2.55 );
2773 int g = qRound( rgbPercentFormatRx.cap( 2 ).toDouble() * 2.55 );
2774 int b = qRound( rgbPercentFormatRx.cap( 3 ).toDouble() * 2.55 );
2775 parsedColor.setRgb( r, g, b );
2776 if ( parsedColor.isValid() )
2778 containsAlpha =
false;
2784 QRegExp rgbaFormatRx(
"^\\s*(?:rgba)?\\(?\\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\s*,\\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\s*,\\s*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\s*,\\s*(0|0?\\.\\d*|1(?:\\.0*)?)\\s*\\)?\\s*;?\\s*$" );
2785 if ( rgbaFormatRx.indexIn( colorStr ) != -1 )
2787 int r = rgbaFormatRx.cap( 1 ).toInt();
2788 int g = rgbaFormatRx.cap( 2 ).toInt();
2789 int b = rgbaFormatRx.cap( 3 ).toInt();
2790 int a = qRound( rgbaFormatRx.cap( 4 ).toDouble() * 255.0 );
2791 parsedColor.setRgb( r, g, b, a );
2792 if ( parsedColor.isValid() )
2794 containsAlpha =
true;
2800 QRegExp rgbaPercentFormatRx(
"^\\s*(?:rgba)?\\(?\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(100|0*\\d{1,2})\\s*%\\s*,\\s*(0|0?\\.\\d*|1(?:\\.0*)?)\\s*\\)?\\s*;?\\s*$" );
2801 if ( rgbaPercentFormatRx.indexIn( colorStr ) != -1 )
2803 int r = qRound( rgbaPercentFormatRx.cap( 1 ).toDouble() * 2.55 );
2804 int g = qRound( rgbaPercentFormatRx.cap( 2 ).toDouble() * 2.55 );
2805 int b = qRound( rgbaPercentFormatRx.cap( 3 ).toDouble() * 2.55 );
2806 int a = qRound( rgbaPercentFormatRx.cap( 4 ).toDouble() * 255.0 );
2807 parsedColor.setRgb( r, g, b, a );
2808 if ( parsedColor.isValid() )
2810 containsAlpha =
true;
2865 if ( p && p->device() )
2884 QImage::Format format = image->format();
2885 if ( format != QImage::Format_ARGB32_Premultiplied && format != QImage::Format_ARGB32 )
2892 for (
int heightIndex = 0; heightIndex < image->height(); ++heightIndex )
2894 QRgb* scanLine = ( QRgb* )image->scanLine( heightIndex );
2895 for (
int widthIndex = 0; widthIndex < image->width(); ++widthIndex )
2897 myRgb = scanLine[widthIndex];
2898 if ( format == QImage::Format_ARGB32_Premultiplied )
2899 scanLine[widthIndex] = qRgba( alpha * qRed( myRgb ), alpha * qGreen( myRgb ), alpha * qBlue( myRgb ), alpha * qAlpha( myRgb ) );
2901 scanLine[widthIndex] = qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), alpha * qAlpha( myRgb ) );
2909 int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
2910 int alpha = ( radius < 1 ) ? 16 : ( radius > 17 ) ? 1 : tab[radius-1];
2912 if ( image.format() != QImage::Format_ARGB32_Premultiplied
2913 && image.format() != QImage::Format_RGB32 )
2915 image = image.convertToFormat( QImage::Format_ARGB32_Premultiplied );
2918 int r1 = rect.top();
2919 int r2 = rect.bottom();
2920 int c1 = rect.left();
2921 int c2 = rect.right();
2923 int bpl = image.bytesPerLine();
2931 i1 = i2 = ( QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3 );
2933 for (
int col = c1; col <= c2; col++ )
2935 p = image.scanLine( r1 ) + col * 4;
2936 for (
int i = i1; i <= i2; i++ )
2937 rgba[i] = p[i] << 4;
2940 for (
int j = r1; j < r2; j++, p += bpl )
2941 for (
int i = i1; i <= i2; i++ )
2942 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
2945 for (
int row = r1; row <= r2; row++ )
2947 p = image.scanLine( row ) + c1 * 4;
2948 for (
int i = i1; i <= i2; i++ )
2949 rgba[i] = p[i] << 4;
2952 for (
int j = c1; j < c2; j++, p += 4 )
2953 for (
int i = i1; i <= i2; i++ )
2954 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
2957 for (
int col = c1; col <= c2; col++ )
2959 p = image.scanLine( r2 ) + col * 4;
2960 for (
int i = i1; i <= i2; i++ )
2961 rgba[i] = p[i] << 4;
2964 for (
int j = r1; j < r2; j++, p -= bpl )
2965 for (
int i = i1; i <= i2; i++ )
2966 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
2969 for (
int row = r1; row <= r2; row++ )
2971 p = image.scanLine( row ) + c2 * 4;
2972 for (
int i = i1; i <= i2; i++ )
2973 rgba[i] = p[i] << 4;
2976 for (
int j = c1; j < c2; j++, p -= 4 )
2977 for (
int i = i1; i <= i2; i++ )
2978 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
2984 int r = 0, g = 0, b = 0;
2985 double alphaFactor = 1.0;
2987 if ( alpha != 255 && alpha > 0 )
2992 rgb.getRgb( &r, &g, &b );
2994 alphaFactor = alpha / 255.;
2998 rgb.setRgb( r, g, b, alpha );
3000 else if ( alpha == 0 )
3002 rgb.setRgb( 0, 0, 0, 0 );
3007 static bool _QVariantLessThan(
const QVariant& lhs,
const QVariant& rhs )
3009 switch ( lhs.type() )
3012 return lhs.toInt() < rhs.toInt();
3013 case QVariant::UInt:
3014 return lhs.toUInt() < rhs.toUInt();
3015 case QVariant::LongLong:
3016 return lhs.toLongLong() < rhs.toLongLong();
3017 case QVariant::ULongLong:
3018 return lhs.toULongLong() < rhs.toULongLong();
3019 case QVariant::Double:
3020 return lhs.toDouble() < rhs.toDouble();
3021 case QVariant::Char:
3022 return lhs.toChar() < rhs.toChar();
3023 case QVariant::Date:
3024 return lhs.toDate() < rhs.toDate();
3025 case QVariant::Time:
3026 return lhs.toTime() < rhs.toTime();
3027 case QVariant::DateTime:
3028 return lhs.toDateTime() < rhs.toDateTime();
3030 return QString::localeAwareCompare( lhs.toString(), rhs.toString() ) < 0;
3034 static bool _QVariantGreaterThan(
const QVariant& lhs,
const QVariant& rhs )
3036 return ! _QVariantLessThan( lhs, rhs );
3042 if ( order == Qt::AscendingOrder )
3056 double dx = directionPoint.x() - startPoint.x();
3057 double dy = directionPoint.y() - startPoint.y();
3058 double length = sqrt( dx * dx + dy * dy );
3059 double scaleFactor = distance / length;
3060 return QPointF( startPoint.x() + dx * scaleFactor, startPoint.y() + dy * scaleFactor );
3070 for (
int i = 0; i < svgPaths.size(); i++ )
3072 QDir dir( svgPaths[i] );
3073 foreach ( QString item, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
3075 svgPaths.insert( i + 1, dir.path() +
"/" + item );
3078 foreach ( QString item, dir.entryList( QStringList(
"*.svg" ), QDir::Files ) )
3081 list.append( dir.path() +
"/" + item );
3093 QStringList svgPaths;
3094 svgPaths.append( directory );
3096 for (
int i = 0; i < svgPaths.size(); i++ )
3098 QDir dir( svgPaths[i] );
3099 foreach ( QString item, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
3101 svgPaths.insert( i + 1, dir.path() +
"/" + item );
3104 foreach ( QString item, dir.entryList( QStringList(
"*.svg" ), QDir::Files ) )
3106 list.append( dir.path() +
"/" + item );
3118 if ( QFile( name ).exists() )
3119 return QFileInfo( name ).canonicalFilePath();
3122 if ( name.contains(
"://" ) )
3125 if ( url.isValid() && !url.scheme().isEmpty() )
3127 if ( url.scheme().compare(
"file", Qt::CaseInsensitive ) == 0 )
3130 name = url.toLocalFile();
3131 if ( QFile( name ).exists() )
3133 return QFileInfo( name ).canonicalFilePath();
3147 for (
int i = 0; i < svgPaths.size(); i++ )
3149 QString svgPath = svgPaths[i];
3150 if ( svgPath.endsWith( QString(
"/" ) ) )
3161 QString myLocalPath = svgPath + QDir::separator() + name;
3163 QgsDebugMsg(
"Alternative svg path: " + myLocalPath );
3164 if ( QFile( myLocalPath ).exists() )
3167 return QFileInfo( myLocalPath ).canonicalFilePath();
3172 QString alternatePath = pfi.canonicalPath() + QDir::separator() + name;
3173 if ( pfi.exists() && QFile( alternatePath ).exists() )
3176 return QFileInfo( alternatePath ).canonicalFilePath();
3183 QgsDebugMsg(
"Computed alternate path but no svg there either" );
3192 QFileInfo fi( path );
3196 path = fi.canonicalFilePath();
3200 bool isInSvgPathes =
false;
3201 for (
int i = 0; i < svgPaths.size(); i++ )
3203 QString dir = QFileInfo( svgPaths[i] ).canonicalFilePath();
3205 if ( !dir.isEmpty() && path.startsWith( dir ) )
3207 path = path.mid( dir.size() + 1 );
3208 isInSvgPathes =
true;
3213 if ( isInSvgPathes )
3222 double cx = 0, cy = 0;
3223 double area, sum = 0;
3224 for (
int i = points.count() - 1, j = 0; j < points.count(); i = j++ )
3226 const QPointF& p1 = points[i];
3227 const QPointF& p2 = points[j];
3228 area = p1.x() * p2.y() - p1.y() * p2.x();
3230 cx += ( p1.x() + p2.x() ) * area;
3231 cy += ( p1.y() + p2.y() ) * area;
3237 return QPointF( cx, cy );
3247 unsigned int i, pointCount = points.count();
3250 for ( i = 0; i < pointCount; ++i ) polyline[i] =
QgsPoint( points[i].x(), points[i].y() );
3257 if ( pointOnSurfaceGeom )
3260 delete pointOnSurfaceGeom;
3263 return QPointF( point.
x(), point.
y() );
3273 bool inside =
false;
3275 double x = point.x();
3276 double y = point.y();
3278 for (
int i = 0, j = points.count() - 1; i < points.count(); i++ )
3280 const QPointF& p1 = points[i];
3281 const QPointF& p2 = points[j];
3283 if ( p1.x() == x && p1.y() == y )
3286 if (( p1.y() < y && p2.y() >= y ) || ( p2.y() < y && p1.y() >= y ) )
3288 if ( p1.x() + ( y - p1.y() ) / ( p2.y() - p1.y() )*( p2.x() - p1.x() ) <= x )
3299 if ( fieldOrExpression.isEmpty() )
3318 return static_cast<const QgsExpression::NodeColumnRef*>( n )->name();
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
static QString encodeOutputUnit(QgsSymbolV2::OutputUnit unit)
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
QMap< QString, QgsSymbolV2 * > QgsSymbolV2Map
static QString encodeSldLineJoinStyle(Qt::PenJoinStyle style)
static void sortVariantList(QList< QVariant > &list, Qt::SortOrder order)
Sorts the passed list in requested order.
Class for parsing and evaluation of expressions (formerly called "search strings").
static Qt::BrushStyle decodeBrushStyle(QString str)
void setLocked(bool locked)
static QgsSymbolV2Map loadSymbols(QDomElement &element)
static Qt::PenCapStyle decodeSldLineCapStyle(QString str)
virtual NodeType nodeType() const =0
static void multiplyImageOpacity(QImage *image, qreal alpha)
Multiplies opacity of image pixel values with a (global) transparency value.
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
QgsSymbolLayerV2 * createSymbolLayer(QString name, const QgsStringMap &properties=QgsStringMap()) const
create a new instance of symbol layer given symbol layer name and properties
static QIcon colorRampPreviewIcon(QgsVectorColorRampV2 *ramp, QSize size)
virtual QString type() const =0
static QIcon symbolLayerPreviewIcon(QgsSymbolLayerV2 *layer, QgsSymbolV2::OutputUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale())
static QPixmap colorRampPreviewPixmap(QgsVectorColorRampV2 *ramp, QSize size)
static QString quotedColumnRef(QString name)
return quoted column reference (in double quotes)
static Q_DECL_DEPRECATED bool wellKnownMarkerFromSld(QDomElement &element, QString &name, QColor &color, QColor &borderColor, double &borderWidth, double &size)
static QgsVectorColorRampV2 * loadColorRamp(QDomElement &element)
static const QStringList svgPaths()
Returns the pathes to svg directories.
const QString expression() const
Alias for dump()
void drawPreviewIcon(QPainter *painter, QSize size)
static QString encodeSldUom(QgsSymbolV2::OutputUnit unit, double *scaleFactor)
QgsMultiPolyline asMultiPolyline() const
return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list
static void createRotationElement(QDomDocument &doc, QDomElement &element, QString rotationFunc)
QVector< QgsPoint > QgsPolyline
polyline is represented as a vector of points
static QgsStringMap getVendorOptionList(QDomElement &element)
double computeMapUnitsPerPixel(const QgsRenderContext &c) const
QgsPolygon asPolygon() const
return contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list ...
static QString ogrFeatureStyleBrush(const QColor &fillColr)
Create ogr feature style string for brush.
static void fillToSld(QDomDocument &doc, QDomElement &element, Qt::BrushStyle brushStyle, QColor color=QColor())
static QVector< qreal > decodeRealVector(const QString &s)
static bool functionFromSldElement(QDomElement &element, QString &function)
static QString encodeSldFontStyle(QFont::Style style)
static QPointF decodePoint(QString str)
static bool externalGraphicFromSld(QDomElement &element, QString &path, QString &mime, QColor &color, double &size)
virtual QgsStringMap properties() const =0
static QDomElement createVendorOptionElement(QDomDocument &doc, QString name, QString value)
static QColor decodeColor(QString str)
static bool convertPolygonSymbolizerToPointMarker(QDomElement &element, QgsSymbolLayerV2List &layerList)
static QDomElement createSvgParameterElement(QDomDocument &doc, QString name, QString value)
static QgsSymbolLayerV2Registry * instance()
return the single instance of this class (instantiate it if not exists)
static QVector< qreal > decodeSldRealVector(const QString &s)
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
double scaleFactor() const
static void createDisplacementElement(QDomDocument &doc, QDomElement &element, QPointF offset)
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
static void createOnlineResourceElement(QDomDocument &doc, QDomElement &element, QString path, QString format)
QgsSymbolLayerV2 * createSymbolLayerFromSld(QString name, QDomElement &element) const
create a new instance of symbol layer given symbol layer name and SLD
static bool needMarkerLine(QDomElement &element)
QMap< QString, QString > QgsStringMap
static bool needPointPatternFill(QDomElement &element)
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
double maxScale
The maximum scale, or 0.0 if unset.
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
static double pixelSizeScaleFactor(const QgsRenderContext &c, QgsSymbolV2::OutputUnit u, const QgsMapUnitScale &scale=QgsMapUnitScale())
Returns scale factor painter units -> pixel dimensions.
void setMapUnitScale(const QgsMapUnitScale &scale)
QgsMultiPolygon asMultiPolygon() const
return contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty ...
virtual double estimateMaxBleed() const
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape...
static QString encodeColor(QColor color)
QgsGeometry * offsetCurve(double distance, int segments, int joinStyle, double mitreLimit)
Returns an offset line at a given distance and side from an input line.
static Qt::BrushStyle decodeSldBrushStyle(QString str)
static bool displacementFromSldElement(QDomElement &element, QPointF &offset)
static WkbType flatType(WkbType type)
static QString encodePenStyle(Qt::PenStyle style)
static QDomElement saveSymbol(QString symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
static QDomElement expressionToOgcFilter(const QgsExpression &exp, QDomDocument &doc, QString *errorMessage=0)
Creates OGC filter XML element.
static bool createSymbolLayerV2ListFromSld(QDomElement &element, QGis::GeometryType geomType, QgsSymbolLayerV2List &layers)
static QString symbolPathToName(QString path)
Get symbols's name from its path.
static QgsSymbolLayerV2 * createMarkerLayerFromSld(QDomElement &element)
static QgsRenderContext createRenderContext(QPainter *p)
Creates a render context for a pixel based device.
static QIcon symbolPreviewIcon(QgsSymbolV2 *symbol, QSize size)
static QString encodeSldFontWeight(int weight)
static QString ogrFeatureStylePen(double width, double mmScaleFactor, double mapUnitsScaleFactor, const QColor &c, Qt::PenJoinStyle joinStyle=Qt::MiterJoin, Qt::PenCapStyle capStyle=Qt::FlatCap, double offset=0.0, const QVector< qreal > *dashPattern=0)
Create ogr feature style string for pen.
static QDomElement saveColorRamp(QString name, QgsVectorColorRampV2 *ramp, QDomDocument &doc)
static bool fillFromSld(QDomElement &element, Qt::BrushStyle &brushStyle, QColor &color)
void setScaleFactor(double factor)
QgsGeometry * buffer(double distance, int segments)
Returns a buffer region around this geometry having the given width and with a specified number of se...
static QgsSymbolLayerV2 * createFillLayerFromSld(QDomElement &element)
static QString encodePoint(QPointF point)
static QPointF offsetPoint(QPointF pt, double angle, double dist)
static QString encodeSldAlpha(int alpha)
static bool needLinePatternFill(QDomElement &element)
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
static Qt::PenCapStyle decodePenCapStyle(QString str)
static Qt::PenStyle decodePenStyle(QString str)
void setRenderingPass(int renderingPass)
static bool createFunctionElement(QDomDocument &doc, QDomElement &element, QString function)
static QStringList listSvgFiles()
Return a list of all available svg files.
static QDomElement saveSymbols(QgsSymbolV2Map &symbols, QString tagName, QDomDocument &doc)
const Node * rootNode() const
Returns root node of the expression. Root node is null is parsing has failed.
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
static QString symbolNameToPath(QString name)
Get symbol's path from its name.
static bool externalMarkerFromSld(QDomElement &element, QString &path, QString &format, int &markIndex, QColor &color, double &size)
QVector< QgsPolygon > QgsMultiPolygon
a collection of QgsPolygons that share a common collection of attributes
static QFont::Style decodeSldFontStyle(QString str)
static QgsSymbolV2::OutputUnit decodeSldUom(QString str, double *scaleFactor)
QString writePath(QString filename) const
prepare a filename to save it to the project file
void setPainter(QPainter *p)
static bool needFontMarker(QDomElement &element)
double rasterScaleFactor() const
static void saveProperties(QgsStringMap props, QDomDocument &doc, QDomElement &element)
virtual QgsStringMap properties() const =0
QGis::WkbType wkbType() const
Returns type of wkb (point / linestring / polygon etc.)
static Qt::PenJoinStyle decodeSldLineJoinStyle(QString str)
QVector< QgsPolyline > QgsPolygon
polygon: first item of the list is outer ring, inner rings (if any) start from second item ...
static double estimateMaxSymbolBleed(QgsSymbolV2 *symbol)
Returns the maximum estimated bleed for the symbol.
static bool hasExternalGraphic(QDomElement &element)
static QStringList listSvgFilesAt(QString directory)
Return a list of svg files at the specified directory.
A class to represent a point geometry.
virtual QColor color(double value) const =0
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
static bool needSvgMarker(QDomElement &element)
static bool needSvgFill(QDomElement &element)
QgsGeometry * pointOnSurface()
Returns a point within a geometry.
static bool geometryFromSldElement(QDomElement &element, QString &geomFunc)
static QgsSymbolLayerV2 * loadSymbolLayer(QDomElement &element)
static bool pointInPolygon(const QPolygonF &points, const QPointF &point)
Calculate whether a point is within of a QPolygonF.
static QgsSymbolLayerV2 * createLineLayerFromSld(QDomElement &element)
static QString encodeRealVector(const QVector< qreal > &v)
int renderingPass() const
virtual QString layerType() const =0
static QColor parseColor(QString colorStr)
Attempts to parse a string as a color using a variety of common formats, including hex codes...
QVector< QgsPolyline > QgsMultiPolyline
a collection of QgsPolylines that share a common collection of attributes
virtual QgsSymbolV2 * subSymbol()
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
QgsPolyline asPolyline() const
return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list ...
static void labelTextToSld(QDomDocument &doc, QDomElement &element, QString label, QFont font, QColor color=QColor(), double size=-1)
static void lineToSld(QDomDocument &doc, QDomElement &element, Qt::PenStyle penStyle, QColor color, double width=-1, const Qt::PenJoinStyle *penJoinStyle=0, const Qt::PenCapStyle *penCapStyle=0, const QVector< qreal > *customDashPattern=0, double dashOffset=0.0)
static void createGeometryElement(QDomDocument &doc, QDomElement &element, QString geomFunc)
Contains information about the context of a rendering operation.
static int decodeSldFontWeight(QString str)
static void createOpacityElement(QDomDocument &doc, QDomElement &element, QString alphaFunc)
static QString encodeBrushStyle(Qt::BrushStyle style)
static double lineWidthScaleFactor(const QgsRenderContext &c, QgsSymbolV2::OutputUnit u, const QgsMapUnitScale &scale=QgsMapUnitScale())
Returns the line width scale factor depending on the unit and the paint device.
static QPointF linesIntersection(QPointF p1, double t1, QPointF p2, double t2)
static QgsExpression * fieldOrExpressionToExpression(const QString &fieldOrExpression)
Return a new valid expression instance for given field or expression string.
QList< QPolygonF > offsetLine(QPolygonF polyline, double dist, QGis::GeometryType geometryType)
calculate geometry shifted by a specified distance
QList< QgsSymbolLayerV2 * > QgsSymbolLayerV2List
static bool lineInfo(QPointF p1, QPointF p2, double &angle, double &t)
static QString encodeScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
static QgsProject * instance()
access to canonical QgsProject instance
static QString _nameForSymbolType(QgsSymbolV2::SymbolType type)
static QString fieldOrExpressionFromExpression(QgsExpression *expression)
Return a field name if the whole expression is just a name of the field .
static QString encodeSldRealVector(const QVector< qreal > &v)
static QgsExpression * expressionFromOgcFilter(const QDomElement &element)
Parse XML with OGC filter into QGIS expression.
static QString encodeSldBrushStyle(Qt::BrushStyle style)
static void externalGraphicToSld(QDomDocument &doc, QDomElement &element, QString path, QString mime, QColor color, double size=-1)
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
static QPixmap symbolPreviewPixmap(QgsSymbolV2 *symbol, QSize size)
static Q_DECL_DEPRECATED void wellKnownMarkerToSld(QDomDocument &doc, QDomElement &element, QString name, QColor color, QColor borderColor=QColor(), double borderWidth=-1, double size=-1)
static QgsGeometry * fromPolyline(const QgsPolyline &polyline)
construct geometry from a polyline
static Qt::PenJoinStyle decodePenJoinStyle(QString str)
static void clearSymbolMap(QgsSymbolV2Map &symbols)
static int decodeSldAlpha(QString str)
static bool rotationFromSldElement(QDomElement &element, QString &rotationFunc)
static QgsSymbolV2::ScaleMethod decodeScaleMethod(QString str)
static QColor parseColorWithAlpha(const QString colorStr, bool &containsAlpha)
Attempts to parse a string as a color using a variety of common formats, including hex codes...
static QgsStringMap getSvgParameterList(QDomElement &element)
static QPointF polygonCentroid(const QPolygonF &points)
Calculate the centroid point of a QPolygonF.
static QgsSymbolV2 * loadSymbol(QDomElement &element)
void setRasterScaleFactor(double factor)
static QgsGeometry * fromPolygon(const QgsPolygon &polygon)
construct geometry from a polygon
static void drawStippledBackround(QPainter *painter, QRect rect)
static bool onlineResourceFromSldElement(QDomElement &element, QString &path, QString &format)
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
QgsSymbolLayerV2 * symbolLayer(int layer)
static QgsStringMap parseProperties(QDomElement &element)
virtual void drawPreviewIcon(QgsSymbolV2RenderContext &context, QSize size)=0
static bool hasWellKnownMark(QDomElement &element)
static bool lineFromSld(QDomElement &element, Qt::PenStyle &penStyle, QColor &color, double &width, Qt::PenJoinStyle *penJoinStyle=0, Qt::PenCapStyle *penCapStyle=0, QVector< qreal > *customDashPattern=0, double *dashOffset=0)
static QPointF polygonPointOnSurface(const QPolygonF &points)
Calculate a point within of a QPolygonF.
QgsPoint asPoint() const
return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0...
static QPointF pointOnLineWithDistance(const QPointF &startPoint, const QPointF &directionPoint, double distance)
Returns a point on the line from startPoint to directionPoint that is a certain distance away from th...
double minScale
The minimum scale, or 0.0 if unset.
static bool opacityFromSldElement(QDomElement &element, QString &alphaFunc)
QString parserErrorString() const
Returns parser error.
virtual bool setSubSymbol(QgsSymbolV2 *symbol)
void setOutputUnit(QgsSymbolV2::OutputUnit u)
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
static void blurImageInPlace(QImage &image, const QRect &rect, int radius, bool alphaOnly)
Blurs an image in place, e.g.
static QgsSymbolV2::OutputUnit decodeOutputUnit(QString str)
static QString encodeSldLineCapStyle(Qt::PenCapStyle style)
static void externalMarkerToSld(QDomDocument &doc, QDomElement &element, QString path, QString format, int *markIndex=0, QColor color=QColor(), double size=-1)
static void premultiplyColor(QColor &rgb, int alpha)
Converts a QColor into a premultiplied ARGB QColor value using a specified alpha value.
static bool needEllipseMarker(QDomElement &element)
static QString encodePenCapStyle(Qt::PenCapStyle style)