34 #include <QDomDocument> 36 #include <QDomElement> 51 if ( lst.
count() < 3 )
55 int red, green, blue, alpha;
57 green = lst[1].toInt();
58 blue = lst[2].toInt();
60 if ( lst.
count() > 3 )
62 alpha = lst[3].toInt();
64 return QColor( red, green, blue, alpha );
76 if ( !ok || alpha > 1 )
87 case QFont::StyleNormal:
89 case QFont::StyleItalic:
91 case QFont::StyleOblique:
100 if ( str ==
"normal" )
return QFont::StyleNormal;
101 if ( str ==
"italic" )
return QFont::StyleItalic;
102 if ( str ==
"oblique" )
return QFont::StyleOblique;
103 return QFont::StyleNormal;
108 if ( weight == 50 )
return "normal";
109 if ( weight == 75 )
return "bold";
113 if ( weight < 0 )
return "100";
114 if ( weight > 99 )
return "900";
121 int weight = str.
toInt( &ok );
123 return static_cast< int >( QFont::Normal );
127 if ( weight > 900 )
return 99;
128 if ( weight < 100 )
return 0;
129 return ( weight - 100 ) * 99 / 800;
144 case Qt::DashDotLine:
146 case Qt::DashDotDotLine:
147 return "dash dot dot";
155 if ( str ==
"no" )
return Qt::NoPen;
156 if ( str ==
"solid" )
return Qt::SolidLine;
157 if ( str ==
"dash" )
return Qt::DashLine;
158 if ( str ==
"dot" )
return Qt::DotLine;
159 if ( str ==
"dash dot" )
return Qt::DashDotLine;
160 if ( str ==
"dash dot dot" )
return Qt::DashDotDotLine;
161 return Qt::SolidLine;
181 if ( str ==
"bevel" )
return Qt::BevelJoin;
182 if ( str ==
"miter" )
return Qt::MiterJoin;
183 if ( str ==
"round" )
return Qt::RoundJoin;
184 return Qt::BevelJoin;
204 if ( str ==
"bevel" )
return Qt::BevelJoin;
205 if ( str ==
"mitre" )
return Qt::MiterJoin;
206 if ( str ==
"round" )
return Qt::RoundJoin;
207 return Qt::BevelJoin;
227 if ( str ==
"square" )
return Qt::SquareCap;
228 if ( str ==
"flat" )
return Qt::FlatCap;
229 if ( str ==
"round" )
return Qt::RoundCap;
230 return Qt::SquareCap;
250 if ( str ==
"square" )
return Qt::SquareCap;
251 if ( str ==
"butt" )
return Qt::FlatCap;
252 if ( str ==
"round" )
return Qt::RoundCap;
253 return Qt::SquareCap;
260 case Qt::SolidPattern :
262 case Qt::HorPattern :
264 case Qt::VerPattern :
266 case Qt::CrossPattern :
268 case Qt::BDiagPattern :
270 case Qt::FDiagPattern :
272 case Qt::DiagCrossPattern :
274 case Qt::Dense1Pattern :
276 case Qt::Dense2Pattern :
278 case Qt::Dense3Pattern :
280 case Qt::Dense4Pattern :
282 case Qt::Dense5Pattern :
284 case Qt::Dense6Pattern :
286 case Qt::Dense7Pattern :
297 if ( str ==
"solid" )
return Qt::SolidPattern;
298 if ( str ==
"horizontal" )
return Qt::HorPattern;
299 if ( str ==
"vertical" )
return Qt::VerPattern;
300 if ( str ==
"cross" )
return Qt::CrossPattern;
301 if ( str ==
"b_diagonal" )
return Qt::BDiagPattern;
302 if ( str ==
"f_diagonal" )
return Qt::FDiagPattern;
303 if ( str ==
"diagonal_x" )
return Qt::DiagCrossPattern;
304 if ( str ==
"dense1" )
return Qt::Dense1Pattern;
305 if ( str ==
"dense2" )
return Qt::Dense2Pattern;
306 if ( str ==
"dense3" )
return Qt::Dense3Pattern;
307 if ( str ==
"dense4" )
return Qt::Dense4Pattern;
308 if ( str ==
"dense5" )
return Qt::Dense5Pattern;
309 if ( str ==
"dense6" )
return Qt::Dense6Pattern;
310 if ( str ==
"dense7" )
return Qt::Dense7Pattern;
311 if ( str ==
"no" )
return Qt::NoBrush;
312 return Qt::SolidPattern;
319 case Qt::CrossPattern:
321 case Qt::DiagCrossPattern:
332 case Qt::BDiagPattern:
334 case Qt::FDiagPattern:
338 case Qt::Dense1Pattern:
339 case Qt::Dense2Pattern:
340 case Qt::Dense3Pattern:
341 case Qt::Dense4Pattern:
342 case Qt::Dense5Pattern:
343 case Qt::Dense6Pattern:
344 case Qt::Dense7Pattern:
354 if ( str ==
"horline" )
return Qt::HorPattern;
355 if ( str ==
"line" )
return Qt::VerPattern;
356 if ( str ==
"cross" )
return Qt::CrossPattern;
357 if ( str ==
"slash" )
return Qt::BDiagPattern;
358 if ( str ==
"backshash" )
return Qt::FDiagPattern;
359 if ( str ==
"x" )
return Qt::DiagCrossPattern;
369 return QString(
"%1,%2" ).
arg( point.
x() ).arg( point.
y() );
375 if ( lst.
count() != 2 )
377 return QPointF( lst[0].toDouble(), lst[1].toDouble() );
392 if ( lst.
count() < 2 )
395 if ( lst.
count() < 6 )
449 *scaleFactor = 0.001;
450 return "http://www.opengeospatial.org/se/units/metre";
457 *scaleFactor = 1 / 0.28;
466 if ( str ==
"http://www.opengeospatial.org/se/units/metre" )
469 *scaleFactor = 1000.0;
472 else if ( str ==
"http://www.opengeospatial.org/se/units/foot" )
475 *scaleFactor = 304.8;
482 *scaleFactor = 1 / 0.00028;
494 vectorString.
append(
';' );
507 for ( ; it != realList.
constEnd(); ++it )
509 resultVector.
append( it->toDouble() );
523 vectorString.
append(
' ' );
536 for ( ; it != realList.
constEnd(); ++it )
538 resultVector.
append( it->toDouble() );
548 switch ( scaleMethod )
551 encodedValue =
"diameter";
554 encodedValue =
"area";
564 if ( str ==
"diameter" )
578 if ( s.
compare(
"Lighten", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Lighten;
579 if ( s.
compare(
"Screen", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Screen;
580 if ( s.
compare(
"Dodge", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_ColorDodge;
581 if ( s.
compare(
"Addition", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Plus;
582 if ( s.
compare(
"Darken", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Darken;
583 if ( s.
compare(
"Multiply", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Multiply;
584 if ( s.
compare(
"Burn", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_ColorBurn;
585 if ( s.
compare(
"Overlay", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Overlay;
586 if ( s.
compare(
"SoftLight", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_SoftLight;
587 if ( s.
compare(
"HardLight", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_HardLight;
588 if ( s.
compare(
"Difference", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Difference;
589 if ( s.
compare(
"Subtract", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Exclusion;
590 return QPainter::CompositionMode_SourceOver;
603 pixmap.
fill( Qt::transparent );
605 painter.
begin( &pixmap );
621 maxBleed = layerMaxBleed > maxBleed ? layerMaxBleed : maxBleed;
631 painter.
begin( &picture );
644 pixmap.
fill( Qt::transparent );
646 painter.
begin( &pixmap );
652 return QIcon( pixmap );
663 pixmap.
fill( Qt::transparent );
666 painter.
begin( &pixmap );
673 for (
int i = 0; i < size.
width(); i++ )
675 QPen pen( ramp->
color( static_cast< double >( i ) / size.
width() ) );
686 uchar pixDataRGB[] = { 255, 255, 255, 255,
691 QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
708 #if !defined(GEOS_VERSION_MAJOR) || !defined(GEOS_VERSION_MINOR) || \ 709 ((GEOS_VERSION_MAJOR<3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR<3))) 713 double x1 = p1.
x(), y1 = p1.
y(), x2 = p2.
x(), y2 = p2.
y();
715 if ( x1 == x2 && y1 == y2 )
719 t = ( x1 == x2 ? DBL_MAX : ( y2 - y1 ) / ( x2 - x1 ) );
723 angle = ( y2 > y1 ?
M_PI / 2 :
M_PI * 3 / 2 );
725 angle = ( x2 > x1 ? 0 :
M_PI );
727 angle = ( y2 > y1 ? atan( t ) :
M_PI + atan( t ) );
729 angle = ( y2 > y1 ?
M_PI + atan( t ) : atan( t ) );
737 return QPointF( pt.
x() + dist * cos( angle ), pt.
y() + dist * sin( angle ) );
744 if (( t1 == DBL_MAX && t2 == DBL_MAX ) || qAbs( atan( t1 ) - atan( t2 ) ) < 0.175 )
748 if ( t1 == DBL_MAX || t2 == DBL_MAX )
767 x = (( p1.
y() - p2.
y() ) + t2 * p2.
x() - t1 * p1.
x() ) / ( t2 - t1 );
770 y = p1.
y() + t1 * ( x - p1.
x() );
776 int i, pointCount = polyline.
count();
779 resultLine.
resize( pointCount );
783 for ( i = 0; i < pointCount; ++i, tempPtr++ )
784 resultLine[i] =
QPointF( tempPtr->
x(), tempPtr->
y() );
792 for (
int ring = 0; ring < polygon.
size(); ++ring )
793 resultGeom.
append( makeOffsetGeometry( polygon[ ring ] ) );
802 if ( polyline.
count() < 2 )
804 resultLine.
append( polyline );
811 #if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \ 812 ((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3))) 814 unsigned int i, pointCount = polyline.
count();
818 for ( i = 0; i < pointCount; ++i, tempPtr++ )
819 tempPolyline[i] =
QgsPoint( tempPtr->
rx(), tempPtr->
ry() );
824 int quadSegments = 0;
825 double mitreLimit = 2.0;
828 offsetGeom = tempGeometry->
buffer( -dist, quadSegments, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, mitreLimit );
830 offsetGeom = tempGeometry->
offsetCurve( dist, quadSegments, GEOSBUF_JOIN_MITRE, mitreLimit );
835 tempGeometry = offsetGeom;
842 if ( dist < 0 ) std::reverse( line.
begin(), line.
end() );
843 resultLine.
append( makeOffsetGeometry( line ) );
857 for (
int part = 0; part < tempMPolyline.
count(); ++part )
859 resultLine.
append( makeOffsetGeometry( tempMPolyline[ part ] ) );
868 for (
int part = 0; part < tempMPolygon.
count(); ++part )
870 resultLine.
append( makeOffsetGeometry( tempMPolygon[ part ] ) );
880 resultLine.
append( polyline );
885 double angle = 0.0, t_new, t_old = 0;
888 bool first_point =
true;
890 for (
int i = 1; i < polyline.
count(); i++ )
894 if ( !
lineInfo( p1, p2, angle, t_new ) )
920 resultLine.
append( newLine );
929 int pointCount = polyline.
count();
931 if ( pointCount > 3 &&
qgsDoubleNear( polyline[ 0 ].x(), polyline[ pointCount - 1 ].x() ) &&
qgsDoubleNear( polyline[ 0 ].y(), polyline[ pointCount - 1 ].y() ) )
935 else if ( pointCount > 1 )
939 return offsetLine( polyline, dist, geometryType );
950 while ( !layerNode.
isNull() )
992 if ( symbolType ==
"line" )
994 else if ( symbolType ==
"fill" )
996 else if ( symbolType ==
"marker" )
1000 QgsDebugMsg(
"unknown symbol type " + symbolType );
1039 if ( !effectElem.
isNull() )
1107 symbolElem.
save( stream, -1 );
1124 if ( symbolizerName ==
"PointSymbolizer" )
1128 if ( graphicElem.
isNull() )
1130 QgsDebugMsg(
"Graphic element not found in PointSymbolizer" );
1166 if ( symbolizerName ==
"LineSymbolizer" )
1170 if ( strokeElem.
isNull() )
1172 QgsDebugMsg(
"Stroke element not found in LineSymbolizer" );
1202 if ( symbolizerName ==
"PolygonSymbolizer" )
1209 QgsDebugMsg(
"neither Fill nor Stroke element not found in PolygonSymbolizer" );
1287 if ( strokeElem.
isNull() )
1306 if ( graphicElem.
isNull() )
1329 if ( graphicElem.
isNull() )
1333 if ( externalGraphicElem.
isNull() )
1338 if ( formatElem.
isNull() )
1342 if ( format !=
"image/svg+xml" )
1344 QgsDebugMsg(
"unsupported External Graphic format found: " + format );
1351 if ( !onlineResourceElem.
isNull() )
1356 else if ( !inlineContentElem.
isNull() )
1370 if ( graphicElem.
isNull() )
1378 if ( wellKnownNameElem.
isNull() )
1388 if ( graphicElem.
isNull() )
1397 if ( formatElem.
isNull() )
1401 if ( format !=
"ttf" )
1403 QgsDebugMsg(
"unsupported Graphic Mark format found: " + format );
1410 if ( !onlineResourceElem.
isNull() )
1414 if ( !markIndexElem.
isNull() )
1417 else if ( !inlineContentElem.
isNull() )
1433 if ( graphicElem.
isNull() )
1439 if ( it.key() ==
"widthHeightFactor" )
1451 if ( strokeElem.
isNull() )
1455 if ( graphicStrokeElem.
isNull() )
1468 if ( graphicFillElem.
isNull() )
1472 if ( graphicElem.
isNull() )
1478 QColor fillColor, borderColor;
1479 double size, borderWidth;
1480 Qt::PenStyle borderStyle;
1481 if ( !
wellKnownMarkerFromSld( graphicElem, name, fillColor, borderColor, borderStyle, borderWidth, size ) )
1484 if ( name !=
"horline" )
1501 Q_UNUSED( element );
1512 if ( graphicFillElem.
isNull() )
1537 bool validFill =
false, validBorder =
false;
1542 Qt::BrushStyle fillStyle;
1544 if (
fillFromSld( fillElem, fillStyle, fillColor ) )
1550 Qt::PenStyle borderStyle;
1551 double borderWidth = 1.0, dashOffset = 0.0;
1554 if (
lineFromSld( strokeElem, borderStyle, borderColor, borderWidth,
1555 nullptr,
nullptr, &customDashPattern, &dashOffset ) )
1558 if ( validFill || validBorder )
1561 map[
"name"] =
"square";
1562 map[
"color"] =
encodeColor( validFill ? fillColor : Qt::transparent );
1563 map[
"color_border"] =
encodeColor( validBorder ? borderColor : Qt::transparent );
1573 bool validFill =
false, validBorder =
false;
1578 QColor fillColor, borderColor;
1579 double borderWidth = 1.0, size = 0.0,
angle = 0.0;
1584 if ( !graphicFillElem.
isNull() )
1588 if ( !graphicElem.
isNull() )
1595 while ( !graphicChildElem.
isNull() )
1597 if ( graphicChildElem.
localName() ==
"Mark" )
1601 if ( !wellKnownNameElem.
isNull() )
1609 if ( graphicChildElem.
localName() ==
"ExternalGraphic" || graphicChildElem.
localName() ==
"Mark" )
1613 if ( formatElem.
isNull() )
1620 if ( graphicChildElem.
localName() ==
"ExternalGraphic" && format !=
"image/svg+xml" )
1625 if ( graphicChildElem.
localName() ==
"Mark" && format !=
"ttf" )
1632 if ( !onlineResourceElem.
isNull() )
1634 name = onlineResourceElem.
attributeNS(
"http://www.w3.org/1999/xlink",
"href" );
1636 if ( graphicChildElem.
localName() ==
"Mark" && format ==
"ttf" )
1640 name = name.
mid( 6 );
1644 if ( markIndexElem.
isNull() )
1659 else if ( !inlineContentElem.
isNull() )
1669 if ( graphicChildElem.
localName() ==
"Mark" )
1678 if ( found && graphicChildElem.
localName() ==
"Mark" )
1685 Qt::BrushStyle markFillStyle;
1688 if (
fillFromSld( markFillElem, markFillStyle, fillColor ) )
1693 Qt::PenStyle borderStyle;
1694 double borderWidth = 1.0, dashOffset = 0.0;
1698 if (
lineFromSld( markStrokeElem, borderStyle, borderColor, borderWidth,
1699 nullptr,
nullptr, &customDashPattern, &dashOffset ) )
1707 if ( !opacityElem.
isNull() )
1711 if ( !sizeElem.
isNull() )
1723 double v = angleFunc.
toDouble( &ok );
1733 if ( validFill || validBorder )
1735 if ( format ==
"image/svg+xml" )
1739 map[
"fill"] = fillColor.
name();
1740 map[
"outline"] = borderColor.
name();
1750 else if ( format ==
"ttf" )
1754 map[
"chr"] = markIndex;
1755 map[
"color"] =
encodeColor( validFill ? fillColor : Qt::transparent );
1770 layerList << layers;
1778 switch ( brushStyle )
1783 case Qt::SolidPattern:
1787 if ( color.
alpha() < 255 )
1792 case Qt::CrossPattern:
1793 case Qt::DiagCrossPattern:
1794 case Qt::HorPattern:
1795 case Qt::VerPattern:
1796 case Qt::BDiagPattern:
1797 case Qt::FDiagPattern:
1798 case Qt::Dense1Pattern:
1799 case Qt::Dense2Pattern:
1800 case Qt::Dense3Pattern:
1801 case Qt::Dense4Pattern:
1802 case Qt::Dense5Pattern:
1803 case Qt::Dense6Pattern:
1804 case Qt::Dense7Pattern:
1823 wellKnownMarkerToSld( doc, graphicElem, patternName, fillColor, borderColor, Qt::SolidLine, -1, -1 );
1830 brushStyle = Qt::SolidPattern;
1831 color =
QColor(
"#808080" );
1835 brushStyle = Qt::NoBrush;
1842 if ( graphicFillElem.
isNull() )
1849 if ( it.key() ==
"fill" )
1850 color =
QColor( it.value() );
1851 else if ( it.key() ==
"fill-opacity" )
1858 if ( graphicElem.
isNull() )
1861 QString patternName =
"square";
1862 QColor fillColor, borderColor;
1863 double borderWidth, size;
1864 Qt::PenStyle borderStyle;
1865 if ( !
wellKnownMarkerFromSld( graphicElem, patternName, fillColor, borderColor, borderStyle, borderWidth, size ) )
1869 if ( brushStyle == Qt::NoBrush )
1881 Qt::PenStyle penStyle,
const QColor& color,
double width,
1882 const Qt::PenJoinStyle *penJoinStyle,
const Qt::PenCapStyle *penCapStyle,
1888 if ( penStyle == Qt::CustomDashLine && !customDashPattern )
1890 element.
appendChild( doc.
createComment(
"WARNING: Custom dash pattern required but not provided. Using default dash pattern." ) );
1891 penStyle = Qt::DashLine;
1910 case Qt::DashDotLine:
1916 case Qt::DashDotDotLine:
1925 case Qt::CustomDashLine:
1926 Q_ASSERT( customDashPattern );
1927 pattern = customDashPattern;
1938 if ( color.
alpha() < 255 )
1958 Qt::PenStyle &penStyle,
QColor &color,
double &width,
1959 Qt::PenJoinStyle *penJoinStyle, Qt::PenCapStyle *penCapStyle,
1964 penStyle = Qt::SolidLine;
1965 color =
QColor(
"#000000" );
1968 *penJoinStyle = Qt::BevelJoin;
1970 *penCapStyle = Qt::SquareCap;
1971 if ( customDashPattern )
1972 customDashPattern->
clear();
1978 penStyle = Qt::NoPen;
1988 if ( it.key() ==
"stroke" )
1990 color =
QColor( it.value() );
1992 else if ( it.key() ==
"stroke-opacity" )
1996 else if ( it.key() ==
"stroke-width" )
1999 double w = it.value().toDouble( &ok );
2003 else if ( it.key() ==
"stroke-linejoin" && penJoinStyle )
2007 else if ( it.key() ==
"stroke-linecap" && penCapStyle )
2011 else if ( it.key() ==
"stroke-dasharray" )
2018 bool dashPatternFound =
false;
2020 if ( dashPattern.
count() == 2 )
2022 if ( dashPattern.
at( 0 ) == 4.0 &&
2023 dashPattern.
at( 1 ) == 2.0 )
2025 penStyle = Qt::DashLine;
2026 dashPatternFound =
true;
2028 else if ( dashPattern.
at( 0 ) == 1.0 &&
2029 dashPattern.
at( 1 ) == 2.0 )
2031 penStyle = Qt::DotLine;
2032 dashPatternFound =
true;
2035 else if ( dashPattern.
count() == 4 )
2037 if ( dashPattern.
at( 0 ) == 4.0 &&
2038 dashPattern.
at( 1 ) == 2.0 &&
2039 dashPattern.
at( 2 ) == 1.0 &&
2040 dashPattern.
at( 3 ) == 2.0 )
2042 penStyle = Qt::DashDotLine;
2043 dashPatternFound =
true;
2046 else if ( dashPattern.
count() == 6 )
2048 if ( dashPattern.
at( 0 ) == 4.0 &&
2049 dashPattern.
at( 1 ) == 2.0 &&
2050 dashPattern.
at( 2 ) == 1.0 &&
2051 dashPattern.
at( 3 ) == 2.0 &&
2052 dashPattern.
at( 4 ) == 1.0 &&
2053 dashPattern.
at( 5 ) == 2.0 )
2055 penStyle = Qt::DashDotDotLine;
2056 dashPatternFound =
true;
2061 if ( !dashPatternFound )
2063 if ( customDashPattern )
2065 penStyle = Qt::CustomDashLine;
2066 *customDashPattern = dashPattern;
2070 QgsDebugMsg(
"custom dash pattern required but not provided. Using default dash pattern." );
2071 penStyle = Qt::DashLine;
2076 else if ( it.key() ==
"stroke-dashoffset" && dashOffset )
2079 double d = it.value().toDouble( &ok );
2090 const QColor& color,
double size )
2110 QColor &color,
double &size )
2116 if ( externalGraphicElem.
isNull() )
2122 if ( !sizeElem.
isNull() )
2135 const QColor& color,
double size )
2151 fillToSld( doc, fillElem, Qt::SolidPattern, color );
2165 QColor &color,
double &size )
2180 if ( !markIndexElem.
isNull() )
2190 Qt::BrushStyle b = Qt::SolidPattern;
2196 if ( !sizeElem.
isNull() )
2209 double borderWidth,
double size )
2211 wellKnownMarkerToSld( doc, element, name, color, borderColor, Qt::SolidLine, borderWidth, size );
2215 const QString& name,
const QColor& color,
const QColor& borderColor, Qt::PenStyle borderStyle,
2216 double borderWidth,
double size )
2229 fillToSld( doc, fillElem, Qt::SolidPattern, color );
2237 lineToSld( doc, strokeElem, borderStyle, borderColor, borderWidth );
2252 double &borderWidth,
double &size )
2254 Qt::PenStyle borderStyle;
2260 double &borderWidth,
double &size )
2266 borderColor =
QColor(
"#000000" );
2275 if ( !wellKnownNameElem.
isNull() )
2278 QgsDebugMsg(
"found Mark with well known name: " + name );
2283 Qt::BrushStyle b = Qt::SolidPattern;
2289 lineFromSld( strokeElem, borderStyle, borderColor, borderWidth );
2294 if ( !sizeElem.
isNull() )
2307 if ( !rotationFunc.
isEmpty() )
2318 if ( !rotationElem.
isNull() )
2339 if ( !opacityElem.
isNull() )
2369 if ( displacementElem.
isNull() )
2373 if ( !dispXElem.
isNull() )
2378 offset.
setX( offsetX );
2382 if ( !dispYElem.
isNull() )
2387 offset.
setY( offsetY );
2395 const QColor& color,
double size )
2415 fillToSld( doc, fillElem, Qt::SolidPattern, color );
2421 Qt::PenJoinStyle joinStyle,
2422 Qt::PenCapStyle capStyle,
2427 penStyle.
append(
"PEN(" );
2430 penStyle.
append(
",w:" );
2436 if ( dashPattern && !dashPattern->
isEmpty() )
2438 penStyle.
append(
",p:\"" );
2440 for ( ; pIt != dashPattern->
constEnd(); ++pIt )
2453 penStyle.
append(
",cap:" );
2468 penStyle.
append(
",j:" );
2469 switch ( joinStyle )
2485 penStyle.
append(
",dp:" );
2497 brushStyle.
append(
"BRUSH(" );
2498 brushStyle.
append(
"fc:" );
2500 brushStyle.
append(
')' );
2541 if ( geometryElem.
isNull() )
2557 if ( !filterElem.
isNull() )
2572 if ( !filterElem.
isNull() )
2580 if ( element.
tagName() !=
"Filter" )
2619 onlineResourceElem.
setAttribute(
"xlink:type",
"simple" );
2633 if ( onlineResourceElem.
isNull() )
2636 path = onlineResourceElem.
attributeNS(
"http://www.w3.org/1999/xlink",
"href" );
2639 if ( formatElem.
isNull() )
2660 while ( !paramElem.
isNull() )
2662 if ( paramElem.
localName() ==
"SvgParameter" || paramElem.
localName() ==
"CssParameter" )
2668 params[ name ] = value;
2690 while ( !paramElem.
isNull() )
2696 params[ name ] = value;
2719 props[propKey] = propValue;
2747 if ( e.
tagName() ==
"symbol" )
2768 if ( it.key()[0] !=
'@' )
2772 subsymbols.
append( it.key() );
2775 if ( parts.
count() < 3 )
2777 QgsDebugMsg(
"found subsymbol with invalid name: " + it.key() );
2782 int symlayer = parts[2].toInt();
2784 if ( !symbols.
contains( symname ) )
2786 QgsDebugMsg(
"subsymbol references invalid symbol: " + symname );
2803 QgsDebugMsg(
"symbol layer refused subsymbol: " + it.key() );
2810 for (
int i = 0; i < subsymbols.
count(); i++ )
2811 symbols.
take( subsymbols[i] );
2832 qDeleteAll( symbols );
2844 if ( rampType ==
"gradient" )
2846 else if ( rampType ==
"random" )
2848 else if ( rampType ==
"colorbrewer" )
2850 else if ( rampType ==
"cpt-city" )
2854 QgsDebugMsg(
"unknown colorramp type " + rampType );
2879 return color.
name();
2889 for ( ; it != components.
end(); ++it )
2897 if ( colors.
length() > 0 )
2904 it = components.
begin();
2905 for ( ; it != components.
end(); ++it )
2913 if ( colors.
length() > 0 )
2920 it = components.
begin();
2921 for ( ; it != components.
end(); ++it )
2929 if ( colors.
length() > 0 )
2935 components = colorStr.
split(
'\n' );
2936 it = components.
begin();
2937 for ( ; it != components.
end(); ++it )
2994 if ( dragDataElem.
tagName() ==
"ColorSchemeModelDragData" )
2997 int nChildNodes = nodeList.
size();
3000 for (
int i = 0; i < nChildNodes; ++i )
3003 if ( currentElem.
isNull() )
3010 namedColor.second = currentElem.
attribute(
"label",
"" );
3012 mimeColors << namedColor;
3017 if ( mimeColors.
length() == 0 && data->
hasFormat(
"application/x-colorobject-list" ) )
3020 QByteArray encodedData = data->
data(
"application/x-colorobject-list" );
3025 if ( colorsNodes.
length() > 0 )
3029 int nChildNodes = colorNodeList.
size();
3032 for (
int i = 0; i < nChildNodes; ++i )
3036 if ( currentElem.
isNull() )
3044 if ( colorNodes.
length() > 0 )
3049 if ( colorParts.
length() < 3 )
3054 int red = colorParts.
at( 0 ).toDouble() * 255;
3055 int green = colorParts.
at( 1 ).toDouble() * 255;
3056 int blue = colorParts.
at( 2 ).toDouble() * 255;
3058 namedColor.first =
QColor( red, green, blue );
3059 if ( nameNodes.
length() > 0 )
3062 namedColor.second = nameElem.
text();
3064 mimeColors << namedColor;
3075 for ( ; it != parsedColors.
end(); ++it )
3077 mimeColors << qMakePair( *it,
QString() );
3087 mimeColors << qMakePair( mimeColor,
QString() );
3103 for ( ; colorIt != colorList.
constEnd(); ++colorIt )
3107 namedColor.
setAttribute(
"label", ( *colorIt ).second );
3120 for ( ; colorIt != colorList.
constEnd(); ++colorIt )
3122 colorListString << ( *colorIt ).
first.name();
3124 mimeData->
setText( colorListString.
join(
"\n" ) );
3127 if ( colorList.
length() > 0 )
3137 if ( !file.
open( QIODevice::ReadWrite ) )
3143 stream <<
"GIMP Palette" << endl;
3146 stream <<
"Name: QGIS Palette" << endl;
3150 stream <<
"Name: " << paletteName << endl;
3152 stream <<
"Columns: 4" << endl;
3153 stream <<
'#' << endl;
3157 QColor color = ( *colorIt ).first;
3163 stream <<
"\t" << (( *colorIt ).second.isEmpty() ? color.
name() : ( *colorIt ).second ) << endl;
3174 if ( !file.
open( QIODevice::ReadOnly ) )
3177 return importedColors;
3186 return importedColors;
3196 QRegExp nameRx(
"Name:\\s*(\\S.*)$" );
3197 if ( nameRx.
indexIn( line ) != -1 )
3199 name = nameRx.
cap( 1 );
3211 return importedColors;
3215 QRegExp rx(
"^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)(\\s.*)?$" );
3216 while ( !in.
atEnd() )
3219 if ( rx.
indexIn( line ) == -1 )
3243 importedColors << qMakePair( color, label );
3248 return importedColors;
3268 containsAlpha =
false;
3274 QRegExp hexColorAlphaRx(
"^\\s*#?([0-9a-fA-F]{6})([0-9a-fA-F]{2})\\s*$" );
3275 if ( hexColorAlphaRx.
indexIn( colorStr ) != -1 )
3280 int alphaHex = hexColorAlphaRx.
cap( 2 ).
toInt( &alphaOk, 16 );
3282 if ( parsedColor.
isValid() && alphaOk )
3285 containsAlpha =
true;
3293 QRegExp hexColorRx2(
"^\\s*(?:[0-9a-fA-F]{3}){1,2}\\s*$" );
3294 if ( hexColorRx2.
indexIn( colorStr ) != -1 )
3300 containsAlpha =
false;
3307 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*$" );
3308 if ( rgbFormatRx.
indexIn( colorStr ) != -1 )
3310 int r = rgbFormatRx.
cap( 1 ).
toInt();
3311 int g = rgbFormatRx.
cap( 2 ).
toInt();
3312 int b = rgbFormatRx.
cap( 3 ).
toInt();
3313 parsedColor.
setRgb( r, g, b );
3316 containsAlpha =
false;
3322 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*$" );
3323 if ( rgbPercentFormatRx.
indexIn( colorStr ) != -1 )
3325 int r = qRound( rgbPercentFormatRx.
cap( 1 ).
toDouble() * 2.55 );
3326 int g = qRound( rgbPercentFormatRx.
cap( 2 ).
toDouble() * 2.55 );
3327 int b = qRound( rgbPercentFormatRx.
cap( 3 ).
toDouble() * 2.55 );
3328 parsedColor.
setRgb( r, g, b );
3331 containsAlpha =
false;
3337 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*$" );
3338 if ( rgbaFormatRx.
indexIn( colorStr ) != -1 )
3340 int r = rgbaFormatRx.
cap( 1 ).
toInt();
3341 int g = rgbaFormatRx.
cap( 2 ).
toInt();
3342 int b = rgbaFormatRx.
cap( 3 ).
toInt();
3343 int a = qRound( rgbaFormatRx.
cap( 4 ).
toDouble() * 255.0 );
3344 parsedColor.
setRgb( r, g, b, a );
3347 containsAlpha =
true;
3353 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*$" );
3354 if ( rgbaPercentFormatRx.
indexIn( colorStr ) != -1 )
3356 int r = qRound( rgbaPercentFormatRx.
cap( 1 ).
toDouble() * 2.55 );
3357 int g = qRound( rgbaPercentFormatRx.
cap( 2 ).
toDouble() * 2.55 );
3358 int b = qRound( rgbaPercentFormatRx.
cap( 3 ).
toDouble() * 2.55 );
3359 int a = qRound( rgbaPercentFormatRx.
cap( 4 ).
toDouble() * 255.0 );
3360 parsedColor.
setRgb( r, g, b, a );
3363 containsAlpha =
true;
3403 double convertedSize = size * conversionFactor;
3414 return convertedSize;
3489 QImage::Format format = image->
format();
3490 if ( format != QImage::Format_ARGB32_Premultiplied && format != QImage::Format_ARGB32 )
3497 for (
int heightIndex = 0; heightIndex < image->
height(); ++heightIndex )
3499 QRgb* scanLine =
reinterpret_cast< QRgb*
>( image->
scanLine( heightIndex ) );
3500 for (
int widthIndex = 0; widthIndex < image->
width(); ++widthIndex )
3502 myRgb = scanLine[widthIndex];
3503 if ( format == QImage::Format_ARGB32_Premultiplied )
3504 scanLine[widthIndex] = qRgba( alpha * qRed( myRgb ), alpha * qGreen( myRgb ), alpha * qBlue( myRgb ), alpha * qAlpha( myRgb ) );
3506 scanLine[widthIndex] = qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), alpha * qAlpha( myRgb ) );
3514 int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
3515 int alpha = ( radius < 1 ) ? 16 : ( radius > 17 ) ? 1 : tab[radius-1];
3517 if ( image.
format() != QImage::Format_ARGB32_Premultiplied
3518 && image.
format() != QImage::Format_RGB32 )
3523 int r1 = rect.
top();
3525 int c1 = rect.
left();
3526 int c2 = rect.
right();
3536 i1 = i2 = ( QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3 );
3538 for (
int col = c1; col <= c2; col++ )
3540 p = image.
scanLine( r1 ) + col * 4;
3541 for (
int i = i1; i <= i2; i++ )
3542 rgba[i] = p[i] << 4;
3545 for (
int j = r1; j < r2; j++, p += bpl )
3546 for (
int i = i1; i <= i2; i++ )
3547 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3550 for (
int row = r1; row <= r2; row++ )
3552 p = image.
scanLine( row ) + c1 * 4;
3553 for (
int i = i1; i <= i2; i++ )
3554 rgba[i] = p[i] << 4;
3557 for (
int j = c1; j < c2; j++, p += 4 )
3558 for (
int i = i1; i <= i2; i++ )
3559 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3562 for (
int col = c1; col <= c2; col++ )
3564 p = image.
scanLine( r2 ) + col * 4;
3565 for (
int i = i1; i <= i2; i++ )
3566 rgba[i] = p[i] << 4;
3569 for (
int j = r1; j < r2; j++, p -= bpl )
3570 for (
int i = i1; i <= i2; i++ )
3571 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3574 for (
int row = r1; row <= r2; row++ )
3576 p = image.
scanLine( row ) + c2 * 4;
3577 for (
int i = i1; i <= i2; i++ )
3578 rgba[i] = p[i] << 4;
3581 for (
int j = c1; j < c2; j++, p -= 4 )
3582 for (
int i = i1; i <= i2; i++ )
3583 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3589 if ( alpha != 255 && alpha > 0 )
3593 double alphaFactor = alpha / 255.;
3594 int r = 0, g = 0, b = 0;
3595 rgb.
getRgb( &r, &g, &b );
3600 rgb.
setRgb( r, g, b, alpha );
3602 else if ( alpha == 0 )
3604 rgb.
setRgb( 0, 0, 0, 0 );
3610 if ( order == Qt::AscendingOrder )
3624 double dx = directionPoint.
x() - startPoint.
x();
3625 double dy = directionPoint.
y() - startPoint.
y();
3626 double length = sqrt( dx * dx + dy * dy );
3627 double scaleFactor = distance / length;
3628 return QPointF( startPoint.
x() + dx * scaleFactor, startPoint.
y() + dy * scaleFactor );
3638 for (
int i = 0; i < svgPaths.
size(); i++ )
3640 QDir dir( svgPaths[i] );
3641 Q_FOREACH (
const QString& item, dir.
entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
3643 svgPaths.
insert( i + 1, dir.
path() +
'/' + item );
3662 svgPaths.
append( directory );
3664 for (
int i = 0; i < svgPaths.
size(); i++ )
3666 QDir dir( svgPaths[i] );
3667 Q_FOREACH (
const QString& item, dir.
entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
3669 svgPaths.
insert( i + 1, dir.
path() +
'/' + item );
3686 if (
QFile( name ).exists() )
3695 if ( url.
scheme().
compare(
"file", Qt::CaseInsensitive ) == 0 )
3699 if (
QFile( name ).exists() )
3715 for (
int i = 0; i < svgPaths.
size(); i++ )
3717 QString svgPath = svgPaths[i];
3731 QgsDebugMsg(
"Alternative svg path: " + myLocalPath );
3732 if (
QFile( myLocalPath ).exists() )
3751 QgsDebugMsg(
"Computed alternate path but no svg there either" );
3768 bool isInSvgPathes =
false;
3769 for (
int i = 0; i < svgPaths.
size(); i++ )
3775 path = path.
mid( dir.
size() + 1 );
3776 isInSvgPathes =
true;
3781 if ( isInSvgPathes )
3790 double cx = 0, cy = 0;
3791 double area, sum = 0;
3792 for (
int i = points.
count() - 1, j = 0; j < points.
count(); i = j++ )
3794 const QPointF& p1 = points[i];
3795 const QPointF& p2 = points[j];
3796 area = p1.
x() * p2.
y() - p1.
y() * p2.
x();
3798 cx += ( p1.
x() + p2.
x() ) * area;
3799 cy += ( p1.
y() + p2.
y() ) * area;
3806 if ( points.
count() >= 2 )
3807 return QPointF(( points[0].x() + points[1].x() ) / 2, ( points[0].y() + points[1].y() ) / 2 );
3808 else if ( points.
count() == 1 )
3826 unsigned int i, pointCount = points.
count();
3829 for ( i = 0; i < pointCount; ++i ) polyline[i] =
QgsPoint( points[i].x(), points[i].y() );
3836 if ( pointOnSurfaceGeom )
3839 delete pointOnSurfaceGeom;
3852 bool inside =
false;
3854 double x = point.
x();
3855 double y = point.
y();
3857 for (
int i = 0, j = points.
count() - 1; i < points.
count(); i++ )
3859 const QPointF& p1 = points[i];
3860 const QPointF& p2 = points[j];
3865 if (( p1.
y() < y && p2.
y() >= y ) || ( p2.
y() < y && p1.
y() >= y ) )
3867 if ( p1.
x() + ( y - p1.
y() ) / ( p2.
y() - p1.
y() )*( p2.
x() - p1.
x() ) <= x )
3878 if ( fieldOrExpression.
isEmpty() )
3897 return static_cast<const QgsExpression::NodeColumnRef*>( n )->name();
3916 breaks.
append( maximum );
3920 int minimumCount =
static_cast< int >( classes ) / 3;
3921 double shrink = 0.75;
3922 double highBias = 1.5;
3923 double adjustBias = 0.5 + 1.5 * highBias;
3924 int divisions = classes;
3925 double h = highBias;
3929 double dx = maximum - minimum;
3939 cell = qMax( qAbs( minimum ), qAbs( maximum ) );
3940 if ( adjustBias >= 1.5 * h + 0.5 )
3942 U = 1 + ( 1.0 / ( 1 + h ) );
3946 U = 1 + ( 1.5 / ( 1 + adjustBias ) );
3948 small = dx < ( cell * U * qMax( 1, divisions ) * 1e-07 * 3.0 );
3955 cell = 9 + cell / 10;
3956 cell = cell * shrink;
3958 if ( minimumCount > 1 )
3960 cell = cell / minimumCount;
3966 if ( divisions > 1 )
3968 cell = cell / divisions;
3971 if ( cell < 20 * 1e-07 )
3976 double base = pow( 10.0, floor( log10( cell ) ) );
3978 if (( 2 * base ) - cell < h *( cell - unit ) )
3981 if (( 5 * base ) - cell < adjustBias *( cell - unit ) )
3984 if (( 10.0 * base ) - cell < h *( cell - unit ) )
3991 int start = floor( minimum / unit + 1e-07 );
3992 int end = ceil( maximum / unit - 1e-07 );
3995 while ( start * unit > minimum + ( 1e-07 * unit ) )
3999 while ( end * unit < maximum - ( 1e-07 * unit ) )
4007 int k = floor( 0.5 + end - start );
4008 if ( k < minimumCount )
4010 k = minimumCount - k;
4014 start = start - k / 2 + k % 2;
4018 start = start - k / 2;
4019 end = end + k / 2 + k % 2;
4022 double minimumBreak = start * unit;
4024 int count = end - start;
4027 for (
int i = 1; i < count + 1; i++ )
4029 breaks.
append( minimumBreak + i * unit );
4035 if ( breaks.
first() < minimum )
4037 breaks[0] = minimum;
4039 if ( breaks.
last() > maximum )
4041 breaks[breaks.
count()-1] = maximum;
4050 bool roundToUnit =
false;
4053 if ( props.
contains(
"uomScale" ) )
4056 scale = props.
value(
"uomScale" ).toDouble( &ok );
4065 if ( props.
value(
"uom" ) ==
"http://www.opengeospatial.org/se/units/metre" )
4096 double rescaled = size * scale;
4101 rescaled = qRound( rescaled );
4117 for ( ; it != array.
constEnd(); ++it )
4126 if ( !props.
value(
"scaleMinDenom",
"" ).isEmpty() )
4133 if ( !props.
value(
"scaleMaxDenom",
"" ).isEmpty() )
4143 if ( mScaleMinDenom != 0 )
4146 int parentScaleMinDenom = props.
value(
"scaleMinDenom",
"0" ).toInt( &ok );
4147 if ( !ok || parentScaleMinDenom <= 0 )
4150 props[
"scaleMinDenom" ] =
QString::number( qMax( parentScaleMinDenom, mScaleMinDenom ) );
4153 if ( mScaleMaxDenom != 0 )
4156 int parentScaleMaxDenom = props.
value(
"scaleMaxDenom",
"0" ).toInt( &ok );
4157 if ( !ok || parentScaleMaxDenom <= 0 )
4160 props[
"scaleMaxDenom" ] =
QString::number( qMin( parentScaleMaxDenom, mScaleMaxDenom ) );
QgsPolygon asPolygon() const
Return contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list...
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
static QString encodeOutputUnit(QgsSymbolV2::OutputUnit unit)
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
static QDomElement saveSymbols(QgsSymbolV2Map &symbols, const QString &tagName, QDomDocument &doc)
static WkbType flatType(WkbType type)
Map 2d+ to 2d type.
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").
void setForceVectorOutput(bool force)
static QgsSymbolV2::OutputUnit decodeSldUom(const QString &str, double *scaleFactor)
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
void setLocked(bool locked)
static void createRotationElement(QDomDocument &doc, QDomElement &element, const QString &rotationFunc)
QDomNodeList elementsByTagName(const QString &tagname) const
static QgsSymbolV2Map loadSymbols(QDomElement &element)
QgsMultiPolyline asMultiPolyline() const
Return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list.
virtual NodeType nodeType() const =0
Abstract virtual that returns the type of this node.
void setClipFeaturesToExtent(bool clipFeaturesToExtent)
Sets whether features drawn by the symbol should be clipped to the render context's extent...
static void externalMarkerToSld(QDomDocument &doc, QDomElement &element, const QString &path, const QString &format, int *markIndex=nullptr, const QColor &color=QColor(), double size=-1)
QString cap(int nth) const
double minSizeMM
The minimum size in millimeters, or 0.0 if unset.
QString & append(QChar ch)
static void multiplyImageOpacity(QImage *image, qreal alpha)
Multiplies opacity of image pixel values with a (global) transparency value.
QByteArray data(const QString &mimeType) const
OutputUnit
The unit of the output.
static void drawStippledBackground(QPainter *painter, QRect rect)
QGis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.)
static Qt::BrushStyle decodeBrushStyle(const QString &str)
QgsPoint asPoint() const
Return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0...
static bool lineFromSld(QDomElement &element, Qt::PenStyle &penStyle, QColor &color, double &width, Qt::PenJoinStyle *penJoinStyle=nullptr, Qt::PenCapStyle *penCapStyle=nullptr, QVector< qreal > *customDashPattern=nullptr, double *dashOffset=nullptr)
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 QList< double > prettyBreaks(double minimum, double maximum, int classes)
Computes a sequence of about 'classes' equally spaced round values which cover the range of values fr...
bool contains(const Key &key) const
static QString quotedColumnRef(QString name)
Returns a 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 QMimeData * colorToMimeData(const QColor &color)
Creates mime data from a color.
void fillRect(const QRectF &rectangle, const QBrush &brush)
static void applyScaleDependency(QDomDocument &doc, QDomElement &ruleElem, const QgsStringMap &props)
Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into t...
void setRenderHint(RenderHint hint, bool on)
QDomNode appendChild(const QDomNode &newChild)
QString readLine(qint64 maxlen)
void append(const T &value)
void fill(const QColor &color)
static double rescaleUom(double size, QgsSymbolV2::OutputUnit unit, const QgsStringMap &props)
Rescales the given size based on the uomScale found in the props, if any is found, otherwise returns the value un-modified.
static QDomElement createVendorOptionElement(QDomDocument &doc, const QString &name, const QString &value)
static void createGeometryElement(QDomDocument &doc, QDomElement &element, const QString &geomFunc)
QString attribute(const QString &name, const QString &defValue) const
static double mapUnitScaleFactor(const QgsRenderContext &c, QgsSymbolV2::OutputUnit u, const QgsMapUnitScale &scale=QgsMapUnitScale())
Returns scale factor painter units -> map units.
QString nodeValue() const
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
static QString encodeColor(const QColor &color)
static QDomElement saveColorRamp(const QString &name, QgsVectorColorRampV2 *ramp, QDomDocument &doc)
static QString encodeSldUom(QgsSymbolV2::OutputUnit unit, double *scaleFactor)
QString attributeNS(const QString nsURI, const QString &localName, const QString &defValue) const
static void externalGraphicToSld(QDomDocument &doc, QDomElement &element, const QString &path, const QString &mime, const QColor &color, double size=-1)
void setColorData(const QVariant &color)
static QgsStringMap getVendorOptionList(QDomElement &element)
static QgsSymbolV2::ScaleMethod decodeScaleMethod(const QString &str)
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the layer.
const_iterator constEnd() const
The output shall be in pixels.
Calculate scale by the diameter.
const T & at(int i) const
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
QString writePath(const QString &filename, const QString &relativeBasePath=QString::null) const
Prepare a filename to save it to the project file.
static QString ogrFeatureStyleBrush(const QColor &fillColr)
Create ogr feature style string for brush.
static QVector< qreal > decodeRealVector(const QString &s)
static QColor colorFromMimeData(const QMimeData *data, bool &hasAlpha)
Attempts to parse mime data as a color.
QString simplified() const
static bool functionFromSldElement(QDomElement &element, QString &function)
static QDomElement saveSymbol(const QString &symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
QDomElement nextSiblingElement(const QString &tagName) const
static QString encodeSldFontStyle(QFont::Style style)
double computeMapUnitsPerPixel(const QgsRenderContext &c) const
Computes a map units per pixel scaling factor, respecting the minimum and maximum scales set for the ...
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=nullptr)
Create ogr feature style string for pen.
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
static bool externalGraphicFromSld(QDomElement &element, QString &path, QString &mime, QColor &color, double &size)
A geometry is the spatial representation of a feature.
virtual QgsStringMap properties() const =0
static QPointF decodePoint(const QString &str)
static void mergeScaleDependencies(int mScaleMinDenom, int mScaleMaxDenom, QgsStringMap &props)
Merges the local scale limits, if any, with the ones already in the map, if any.
static bool convertPolygonSymbolizerToPointMarker(QDomElement &element, QgsSymbolLayerV2List &layerList)
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
static QgsSymbolLayerV2Registry * instance()
return the single instance of this class (instantiate it if not exists)
static QVector< qreal > decodeSldRealVector(const QString &s)
QDomElement documentElement() const
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static Qt::BrushStyle decodeSldBrushStyle(const QString &str)
QString join(const QString &separator) const
static void createOnlineResourceElement(QDomDocument &doc, QDomElement &element, const QString &path, const QString &format)
static QString colorToName(const QColor &color)
Returns a friendly display name for a color.
void drawLine(const QLineF &line)
static QStringList listSvgFilesAt(const QString &directory)
Return a list of svg files at the specified directory.
static void createDisplacementElement(QDomDocument &doc, QDomElement &element, QPointF offset)
void setRgb(int r, int g, int b, int a)
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Compares two QVariant values and returns whether the first is greater than the second.
void setNamedColor(const QString &name)
double toDouble(bool *ok) const
bool isValidColor(const QString &name)
QDomNodeList childNodes() const
static bool needMarkerLine(QDomElement &element)
QString parserErrorString() const
Returns parser error.
void drawPreviewIcon(QPainter *painter, QSize size, QgsRenderContext *customContext=nullptr)
Draw icon of the symbol that occupyies area given by size using the painter.
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)
Compares two QVariant values and returns whether the first is less than the second.
static QgsSymbolV2 * loadSymbol(const QDomElement &element)
Attempts to load a symbol from a DOM element.
static double pixelSizeScaleFactor(const QgsRenderContext &c, QgsSymbolV2::OutputUnit u, const QgsMapUnitScale &scale=QgsMapUnitScale())
Returns scale factor painter units -> pixel dimensions.
QgsPolyline asPolyline() const
Return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list...
bool minSizeMMEnabled
Whether the minimum size in mm should be respected.
double y() const
Get the y value of the point.
void setMapUnitScale(const QgsMapUnitScale &scale)
QDomNode nextSibling() const
static QgsSymbolV2::OutputUnit decodeOutputUnit(const QString &str)
static bool displacementFromSldElement(QDomElement &element, QPointF &offset)
const Node * rootNode() const
Returns root node of the expression. Root node is null is parsing has failed.
QDomElement toElement() const
static QString encodePenStyle(Qt::PenStyle style)
static QPointF pointOnLineWithDistance(QPointF startPoint, QPointF directionPoint, double distance)
Returns a point on the line from startPoint to directionPoint that is a certain distance away from th...
static bool createSymbolLayerV2ListFromSld(QDomElement &element, QGis::GeometryType geomType, QgsSymbolLayerV2List &layers)
int indexIn(const QString &str, int offset, CaretMode caretMode) const
int renderingPass() const
static QString symbolPathToName(QString path)
Get symbols's name from its path.
virtual double estimateMaxBleed() const
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape...
Mixed units in symbol layers.
QString canonicalFilePath() const
static QgsSymbolLayerV2 * createMarkerLayerFromSld(QDomElement &element)
static QgsRenderContext createRenderContext(QPainter *p)
Creates a render context for a pixel based device.
The output shall be in millimeters.
static QPainter::CompositionMode decodeBlendMode(const QString &s)
QString number(int n, int base)
static QIcon symbolPreviewIcon(QgsSymbolV2 *symbol, QSize size)
int count(const T &value) const
void append(const T &value)
static QString encodeSldFontWeight(int weight)
static bool fillFromSld(QDomElement &element, Qt::BrushStyle &brushStyle, QColor &color)
void setScaleFactor(double factor)
QString localName() const
QString canonicalPath() const
static bool pointInPolygon(const QPolygonF &points, QPointF point)
Calculate whether a point is within of a QPolygonF.
static QgsSymbolLayerV2 * createFillLayerFromSld(QDomElement &element)
QgsGeometry * pointOnSurface() const
Returns a point within a geometry.
static QString encodePoint(QPointF point)
bool hasAttribute(const QString &name) const
static double convertToPainterUnits(const QgsRenderContext &c, double size, QgsSymbolV2::OutputUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale())
Converts a size from the specied units to painter units.
static QPointF offsetPoint(QPointF pt, double angle, double dist)
static QString encodeSldAlpha(int alpha)
static bool needLinePatternFill(QDomElement &element)
static QgsPaintEffectRegistry * instance()
Returns a reference to the singleton instance of the paint effect registry.
The ouput shall be a percentage of another measurement (eg canvas size, feature size) ...
static QgsNamedColorList importColorsFromGpl(QFile &file, bool &ok, QString &name)
Imports colors from a gpl GIMP palette file.
static bool createExpressionElement(QDomDocument &doc, QDomElement &element, const QString &function)
Creates a OGC Expression element based on the provided function expression.
void setPen(const QColor &color)
void setRenderingPass(int renderingPass)
void setAttribute(const QString &name, const QString &value)
static QStringList listSvgFiles()
Return a list of all available svg files.
QgsGeometry * buffer(double distance, int segments) const
Returns a buffer region around this geometry having the given width and with a specified number of se...
int toInt(bool *ok, int base) const
QDomNodeList elementsByTagName(const QString &tagname) const
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
static QString symbolNameToPath(QString name)
Get symbol's path from its name.
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
The output shall be in map unitx.
static bool externalMarkerFromSld(QDomElement &element, QString &path, QString &format, int &markIndex, QColor &color, double &size)
QPaintDevice * device() const
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
static Qt::PenCapStyle decodePenCapStyle(const QString &str)
void setText(const QString &text)
void setPainter(QPainter *p)
static bool needFontMarker(QDomElement &element)
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
static void saveProperties(QgsStringMap props, QDomDocument &doc, QDomElement &element)
virtual QgsStringMap properties() const =0
Should be reimplemented by subclasses to return a string map that contains the configuration informat...
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)
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
static void lineToSld(QDomDocument &doc, QDomElement &element, Qt::PenStyle penStyle, const QColor &color, double width=-1, const Qt::PenJoinStyle *penJoinStyle=nullptr, const Qt::PenCapStyle *penCapStyle=nullptr, const QVector< qreal > *customDashPattern=nullptr, double dashOffset=0.0)
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
QVariant colorData() const
A class to represent a point.
static Qt::PenStyle decodePenStyle(const QString &str)
QString toLocalFile() const
virtual QColor color(double value) const =0
QDomText createTextNode(const QString &value)
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)
static bool geometryFromSldElement(QDomElement &element, QString &geomFunc)
static QgsSymbolLayerV2 * loadSymbolLayer(QDomElement &element)
bool contains(QChar ch, Qt::CaseSensitivity cs) const
static QgsSymbolLayerV2 * createLineLayerFromSld(QDomElement &element)
static QString encodeRealVector(const QVector< qreal > &v)
virtual QString layerType() const =0
Returns a string that represents this layer type.
QString expression() const
Return the original, unmodified expression string.
bool clipFeaturesToExtent() const
Returns whether features drawn by the symbol will be clipped to the render context's extent...
virtual QgsSymbolV2 * subSymbol()
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
SymbolType
Type of the symbol.
void setTexture(const QPixmap &pixmap)
const T & at(int i) const
const_iterator constBegin() const
Contains information about the context of a rendering operation.
void save(QTextStream &str, int indent) const
static QDomElement createSvgParameterElement(QDomDocument &doc, const QString &name, const QString &value)
QDomNode firstChild() const
QString mid(int position, int n) const
static bool createFunctionElement(QDomDocument &doc, QDomElement &element, const QString &function)
static QString encodeBrushStyle(Qt::BrushStyle style)
double maxSizeMM
The maximum size in millimeters, or 0.0 if unset.
static void fillToSld(QDomDocument &doc, QDomElement &element, Qt::BrushStyle brushStyle, const QColor &color=QColor())
static QColor parseColorWithAlpha(const QString &colorStr, bool &containsAlpha, bool strictEval=false)
Attempts to parse a string as a color using a variety of common formats, including hex codes...
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)
QgsGeometry * offsetCurve(double distance, int segments, int joinStyle, double mitreLimit) const
Returns an offset line at a given distance and side from an input line.
static QgsExpression * fieldOrExpressionToExpression(const QString &fieldOrExpression)
Return a new valid expression instance for given field or expression string.
Struct for storing maximum and minimum scales for measurements in map units.
QList< QPolygonF > offsetLine(QPolygonF polyline, double dist, QGis::GeometryType geometryType)
calculate geometry shifted by a specified distance
static QList< QColor > parseColorList(const QString &colorStr)
Attempts to parse a string as a list of colors using a variety of common formats, including hex codes...
void insert(int i, const T &value)
static QPixmap symbolPreviewPixmap(QgsSymbolV2 *symbol, QSize size, QgsRenderContext *customContext=nullptr)
QgsMultiPolygon asMultiPolygon() const
Return contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty ...
static QDomElement expressionToOgcFilter(const QgsExpression &exp, QDomDocument &doc, QString *errorMessage=nullptr)
Creates OGC filter XML element.
QStringList entryList(QFlags< QDir::Filter > filters, QFlags< QDir::SortFlag > sort) const
static QMimeData * colorListToMimeData(const QgsNamedColorList &colorList, const bool allFormats=true)
Creates mime data from a list of named colors.
static bool lineInfo(QPointF p1, QPointF p2, double &angle, double &t)
static QDomElement expressionToOgcExpression(const QgsExpression &exp, QDomDocument &doc, QString *errorMessage=nullptr)
Creates an OGC expression XML element.
static QString encodeScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
static QgsProject * instance()
access to canonical QgsProject instance
static QString symbolProperties(QgsSymbolV2 *symbol)
Returns a string representing the symbol.
QDomElement firstChildElement(const QString &tagName) const
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)
void getRgb(int *r, int *g, int *b, int *a) const
static QgsExpression * expressionFromOgcFilter(const QDomElement &element)
Parse XML with OGC filter into QGIS expression.
static QString encodeSldBrushStyle(Qt::BrushStyle style)
int count(const T &value) const
static void labelTextToSld(QDomDocument &doc, QDomElement &element, const QString &label, const QFont &font, const QColor &color=QColor(), double size=-1)
QStringList split(const QString &sep, const QString &str, bool allowEmptyEntries)
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
static QPicture symbolLayerPreviewPicture(QgsSymbolLayerV2 *layer, QgsSymbolV2::OutputUnit units, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale())
Draws a symbol layer preview to a QPicture.
static QgsGeometry * fromPolyline(const QgsPolyline &polyline)
Creates a new geometry from a QgsPolyline object.
void push_back(const T &value)
static void clearSymbolMap(QgsSymbolV2Map &symbols)
static QStringList svgPaths()
Returns the pathes to svg directories.
static bool rotationFromSldElement(QDomElement &element, QString &rotationFunc)
static Qt::PenCapStyle decodeSldLineCapStyle(const QString &str)
static QColor decodeColor(const QString &str)
iterator insert(const Key &key, const T &value)
static QgsStringMap getSvgParameterList(QDomElement &element)
static QPointF polygonCentroid(const QPolygonF &points)
Calculate the centroid point of a QPolygonF.
void setRasterScaleFactor(double factor)
Calculate scale by the area.
static QgsGeometry * fromPolygon(const QgsPolygon &polygon)
Creates a new geometry from a QgsPolygon.
static int decodeSldFontWeight(const QString &str)
static int decodeSldAlpha(const QString &str)
static QColor parseColor(const QString &colorStr, bool strictEval=false)
Attempts to parse a string as a color using a variety of common formats, including hex codes...
void setData(const QString &mimeType, const QByteArray &data)
QgsSymbolLayerV2 * createSymbolLayer(const QString &name, const QgsStringMap &properties=QgsStringMap()) const
create a new instance of symbol layer given symbol layer name and properties
QgsSymbolLayerV2 * createSymbolLayerFromSld(const QString &name, QDomElement &element) const
create a new instance of symbol layer given symbol layer name and SLD
static bool onlineResourceFromSldElement(QDomElement &element, QString &path, QString &format)
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
QgsSymbolLayerV2 * symbolLayer(int layer)
Returns a specific symbol layers contained in the symbol.
static QgsStringMap parseProperties(QDomElement &element)
double rasterScaleFactor() const
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
virtual void drawPreviewIcon(QgsSymbolV2RenderContext &context, QSize size)=0
const_iterator constBegin() const
static bool hasWellKnownMark(QDomElement &element)
static QPointF polygonPointOnSurface(const QPolygonF &points)
Calculate a point within of a QPolygonF.
static Qt::PenJoinStyle decodeSldLineJoinStyle(const QString &str)
static QFont::Style decodeSldFontStyle(const QString &str)
double scaleFactor() const
bool begin(QPaintDevice *device)
double minScale
The minimum scale, or 0.0 if unset.
int compare(const QString &other) const
static bool opacityFromSldElement(QDomElement &element, QString &alphaFunc)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
virtual bool setSubSymbol(QgsSymbolV2 *symbol)
set layer's subsymbol. takes ownership of the passed symbol
bool maxSizeMMEnabled
Whether the maximum size in mm should be respected.
static void blurImageInPlace(QImage &image, QRect rect, int radius, bool alphaOnly)
Blurs an image in place, e.g.
static bool saveColorsToGpl(QFile &file, const QString &paletteName, const QgsNamedColorList &colors)
Exports colors to a gpl GIMP palette file.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the layer.
void setOutputUnit(QgsSymbolV2::OutputUnit u)
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
QImage scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const
double x() const
Get the x value of the point.
static QString encodeSldLineCapStyle(Qt::PenCapStyle style)
static void premultiplyColor(QColor &rgb, int alpha)
Converts a QColor into a premultiplied ARGB QColor value using a specified alpha value.
QByteArray toByteArray(int indent) const
static void createOpacityElement(QDomDocument &doc, QDomElement &element, const QString &alphaFunc)
static QgsNamedColorList colorListFromMimeData(const QMimeData *data)
Attempts to parse mime data as a list of named colors.
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
QDomNode at(int index) const
const T value(const Key &key) const
static bool needEllipseMarker(QDomElement &element)
static QString encodePenCapStyle(Qt::PenCapStyle style)
static Q_DECL_DEPRECATED void wellKnownMarkerToSld(QDomDocument &doc, QDomElement &element, const QString &name, const QColor &color, const QColor &borderColor=QColor(), double borderWidth=-1, double size=-1)
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.