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;
375 if ( lst.
count() != 2 )
377 return QPointF( lst[0].toDouble(), lst[1].toDouble() );
393 if ( lst.
count() < 2 )
396 if ( lst.
count() < 6 )
450 *scaleFactor = 0.001;
451 return "http://www.opengeospatial.org/se/units/metre";
458 *scaleFactor = 1 / 0.28;
467 if ( str ==
"http://www.opengeospatial.org/se/units/metre" )
470 *scaleFactor = 1000.0;
473 else if ( str ==
"http://www.opengeospatial.org/se/units/foot" )
476 *scaleFactor = 304.8;
483 *scaleFactor = 1 / 0.00028;
495 vectorString.
append(
';' );
508 for ( ; it != realList.
constEnd(); ++it )
510 resultVector.
append( it->toDouble() );
524 vectorString.
append(
' ' );
537 for ( ; it != realList.
constEnd(); ++it )
539 resultVector.
append( it->toDouble() );
549 switch ( scaleMethod )
552 encodedValue =
"diameter";
555 encodedValue =
"area";
565 if ( str ==
"diameter" )
579 if ( s.
compare(
"Lighten", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Lighten;
580 if ( s.
compare(
"Screen", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Screen;
581 if ( s.
compare(
"Dodge", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_ColorDodge;
582 if ( s.
compare(
"Addition", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Plus;
583 if ( s.
compare(
"Darken", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Darken;
584 if ( s.
compare(
"Multiply", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Multiply;
585 if ( s.
compare(
"Burn", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_ColorBurn;
586 if ( s.
compare(
"Overlay", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Overlay;
587 if ( s.
compare(
"SoftLight", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_SoftLight;
588 if ( s.
compare(
"HardLight", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_HardLight;
589 if ( s.
compare(
"Difference", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Difference;
590 if ( s.
compare(
"Subtract", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Exclusion;
591 return QPainter::CompositionMode_SourceOver;
604 pixmap.
fill( Qt::transparent );
606 painter.
begin( &pixmap );
622 maxBleed = layerMaxBleed > maxBleed ? layerMaxBleed : maxBleed;
632 painter.
begin( &picture );
645 pixmap.
fill( Qt::transparent );
647 painter.
begin( &pixmap );
653 return QIcon( pixmap );
664 pixmap.
fill( Qt::transparent );
667 painter.
begin( &pixmap );
674 for (
int i = 0; i < size.
width(); i++ )
676 QPen pen( ramp->
color( static_cast< double >( i ) / size.
width() ) );
687 uchar pixDataRGB[] = { 255, 255, 255, 255,
692 QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
709 #if !defined(GEOS_VERSION_MAJOR) || !defined(GEOS_VERSION_MINOR) || \ 710 ((GEOS_VERSION_MAJOR<3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR<3))) 714 double x1 = p1.
x(), y1 = p1.
y(), x2 = p2.
x(), y2 = p2.
y();
716 if ( x1 == x2 && y1 == y2 )
720 t = ( x1 == x2 ? DBL_MAX : ( y2 - y1 ) / ( x2 - x1 ) );
724 angle = ( y2 > y1 ?
M_PI / 2 :
M_PI * 3 / 2 );
726 angle = ( x2 > x1 ? 0 :
M_PI );
728 angle = ( y2 > y1 ? atan( t ) :
M_PI + atan( t ) );
730 angle = ( y2 > y1 ?
M_PI + atan( t ) : atan( t ) );
738 return QPointF( pt.
x() + dist * cos( angle ), pt.
y() + dist * sin( angle ) );
745 if (( t1 == DBL_MAX && t2 == DBL_MAX ) || qAbs( atan( t1 ) - atan( t2 ) ) < 0.175 )
749 if ( t1 == DBL_MAX || t2 == DBL_MAX )
768 x = (( p1.
y() - p2.
y() ) + t2 * p2.
x() - t1 * p1.
x() ) / ( t2 - t1 );
771 y = p1.
y() + t1 * ( x - p1.
x() );
777 int i, pointCount = polyline.
count();
780 resultLine.
resize( pointCount );
784 for ( i = 0; i < pointCount; ++i, tempPtr++ )
785 resultLine[i] =
QPointF( tempPtr->
x(), tempPtr->
y() );
793 for (
int ring = 0; ring < polygon.
size(); ++ring )
794 resultGeom.
append( makeOffsetGeometry( polygon[ ring ] ) );
803 if ( polyline.
count() < 2 )
805 resultLine.
append( polyline );
812 #if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \ 813 ((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3))) 815 unsigned int i, pointCount = polyline.
count();
819 for ( i = 0; i < pointCount; ++i, tempPtr++ )
820 tempPolyline[i] =
QgsPoint( tempPtr->
rx(), tempPtr->
ry() );
825 int quadSegments = 0;
826 double mitreLimit = 2.0;
829 offsetGeom = tempGeometry->
buffer( -dist, quadSegments, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, mitreLimit );
831 offsetGeom = tempGeometry->
offsetCurve( dist, quadSegments, GEOSBUF_JOIN_MITRE, mitreLimit );
836 tempGeometry = offsetGeom;
843 if ( dist < 0 ) std::reverse( line.
begin(), line.
end() );
844 resultLine.
append( makeOffsetGeometry( line ) );
858 for (
int part = 0; part < tempMPolyline.
count(); ++part )
860 resultLine.
append( makeOffsetGeometry( tempMPolyline[ part ] ) );
869 for (
int part = 0; part < tempMPolygon.
count(); ++part )
871 resultLine.
append( makeOffsetGeometry( tempMPolygon[ part ] ) );
881 resultLine.
append( polyline );
886 double angle = 0.0, t_new, t_old = 0;
889 bool first_point =
true;
891 for (
int i = 1; i < polyline.
count(); i++ )
895 if ( !
lineInfo( p1, p2, angle, t_new ) )
921 resultLine.
append( newLine );
930 int pointCount = polyline.
count();
932 if ( pointCount > 3 &&
qgsDoubleNear( polyline[ 0 ].x(), polyline[ pointCount - 1 ].x() ) &&
qgsDoubleNear( polyline[ 0 ].y(), polyline[ pointCount - 1 ].y() ) )
936 else if ( pointCount > 1 )
940 return offsetLine( polyline, dist, geometryType );
951 while ( !layerNode.
isNull() )
993 if ( symbolType ==
"line" )
995 else if ( symbolType ==
"fill" )
997 else if ( symbolType ==
"marker" )
1001 QgsDebugMsg(
"unknown symbol type " + symbolType );
1040 if ( !effectElem.
isNull() )
1108 symbolElem.
save( stream, -1 );
1125 if ( symbolizerName ==
"PointSymbolizer" )
1129 if ( graphicElem.
isNull() )
1131 QgsDebugMsg(
"Graphic element not found in PointSymbolizer" );
1167 if ( symbolizerName ==
"LineSymbolizer" )
1171 if ( strokeElem.
isNull() )
1173 QgsDebugMsg(
"Stroke element not found in LineSymbolizer" );
1203 if ( symbolizerName ==
"PolygonSymbolizer" )
1210 QgsDebugMsg(
"neither Fill nor Stroke element not found in PolygonSymbolizer" );
1288 if ( strokeElem.
isNull() )
1307 if ( graphicElem.
isNull() )
1330 if ( graphicElem.
isNull() )
1334 if ( externalGraphicElem.
isNull() )
1339 if ( formatElem.
isNull() )
1343 if ( format !=
"image/svg+xml" )
1345 QgsDebugMsg(
"unsupported External Graphic format found: " + format );
1352 if ( !onlineResourceElem.
isNull() )
1357 else if ( !inlineContentElem.
isNull() )
1371 if ( graphicElem.
isNull() )
1379 if ( wellKnownNameElem.
isNull() )
1389 if ( graphicElem.
isNull() )
1398 if ( formatElem.
isNull() )
1402 if ( format !=
"ttf" )
1404 QgsDebugMsg(
"unsupported Graphic Mark format found: " + format );
1411 if ( !onlineResourceElem.
isNull() )
1415 if ( !markIndexElem.
isNull() )
1418 else if ( !inlineContentElem.
isNull() )
1434 if ( graphicElem.
isNull() )
1440 if ( it.key() ==
"widthHeightFactor" )
1452 if ( strokeElem.
isNull() )
1456 if ( graphicStrokeElem.
isNull() )
1469 if ( graphicFillElem.
isNull() )
1473 if ( graphicElem.
isNull() )
1479 QColor fillColor, borderColor;
1480 double size, borderWidth;
1481 Qt::PenStyle borderStyle;
1482 if ( !
wellKnownMarkerFromSld( graphicElem, name, fillColor, borderColor, borderStyle, borderWidth, size ) )
1485 if ( name !=
"horline" )
1502 Q_UNUSED( element );
1513 if ( graphicFillElem.
isNull() )
1538 bool validFill =
false, validBorder =
false;
1543 Qt::BrushStyle fillStyle;
1545 if (
fillFromSld( fillElem, fillStyle, fillColor ) )
1551 Qt::PenStyle borderStyle;
1552 double borderWidth = 1.0, dashOffset = 0.0;
1555 if (
lineFromSld( strokeElem, borderStyle, borderColor, borderWidth,
1556 nullptr,
nullptr, &customDashPattern, &dashOffset ) )
1559 if ( validFill || validBorder )
1562 map[
"name"] =
"square";
1563 map[
"color"] =
encodeColor( validFill ? fillColor : Qt::transparent );
1564 map[
"color_border"] =
encodeColor( validBorder ? borderColor : Qt::transparent );
1574 bool validFill =
false, validBorder =
false;
1579 QColor fillColor, borderColor;
1580 double borderWidth = 1.0, size = 0.0,
angle = 0.0;
1585 if ( !graphicFillElem.
isNull() )
1589 if ( !graphicElem.
isNull() )
1596 while ( !graphicChildElem.
isNull() )
1598 if ( graphicChildElem.
localName() ==
"Mark" )
1602 if ( !wellKnownNameElem.
isNull() )
1610 if ( graphicChildElem.
localName() ==
"ExternalGraphic" || graphicChildElem.
localName() ==
"Mark" )
1614 if ( formatElem.
isNull() )
1621 if ( graphicChildElem.
localName() ==
"ExternalGraphic" && format !=
"image/svg+xml" )
1626 if ( graphicChildElem.
localName() ==
"Mark" && format !=
"ttf" )
1633 if ( !onlineResourceElem.
isNull() )
1635 name = onlineResourceElem.
attributeNS(
"http://www.w3.org/1999/xlink",
"href" );
1637 if ( graphicChildElem.
localName() ==
"Mark" && format ==
"ttf" )
1641 name = name.
mid( 6 );
1645 if ( markIndexElem.
isNull() )
1660 else if ( !inlineContentElem.
isNull() )
1670 if ( graphicChildElem.
localName() ==
"Mark" )
1679 if ( found && graphicChildElem.
localName() ==
"Mark" )
1686 Qt::BrushStyle markFillStyle;
1689 if (
fillFromSld( markFillElem, markFillStyle, fillColor ) )
1694 Qt::PenStyle borderStyle;
1695 double borderWidth = 1.0, dashOffset = 0.0;
1699 if (
lineFromSld( markStrokeElem, borderStyle, borderColor, borderWidth,
1700 nullptr,
nullptr, &customDashPattern, &dashOffset ) )
1708 if ( !opacityElem.
isNull() )
1712 if ( !sizeElem.
isNull() )
1724 double v = angleFunc.
toDouble( &ok );
1734 if ( validFill || validBorder )
1736 if ( format ==
"image/svg+xml" )
1740 map[
"fill"] = fillColor.
name();
1741 map[
"outline"] = borderColor.
name();
1751 else if ( format ==
"ttf" )
1755 map[
"chr"] = markIndex;
1756 map[
"color"] =
encodeColor( validFill ? fillColor : Qt::transparent );
1771 layerList << layers;
1779 switch ( brushStyle )
1784 case Qt::SolidPattern:
1788 if ( color.
alpha() < 255 )
1793 case Qt::CrossPattern:
1794 case Qt::DiagCrossPattern:
1795 case Qt::HorPattern:
1796 case Qt::VerPattern:
1797 case Qt::BDiagPattern:
1798 case Qt::FDiagPattern:
1799 case Qt::Dense1Pattern:
1800 case Qt::Dense2Pattern:
1801 case Qt::Dense3Pattern:
1802 case Qt::Dense4Pattern:
1803 case Qt::Dense5Pattern:
1804 case Qt::Dense6Pattern:
1805 case Qt::Dense7Pattern:
1824 wellKnownMarkerToSld( doc, graphicElem, patternName, fillColor, borderColor, Qt::SolidLine, -1, -1 );
1831 brushStyle = Qt::SolidPattern;
1832 color =
QColor(
"#808080" );
1836 brushStyle = Qt::NoBrush;
1843 if ( graphicFillElem.
isNull() )
1850 if ( it.key() ==
"fill" )
1851 color =
QColor( it.value() );
1852 else if ( it.key() ==
"fill-opacity" )
1859 if ( graphicElem.
isNull() )
1862 QString patternName =
"square";
1863 QColor fillColor, borderColor;
1864 double borderWidth, size;
1865 Qt::PenStyle borderStyle;
1866 if ( !
wellKnownMarkerFromSld( graphicElem, patternName, fillColor, borderColor, borderStyle, borderWidth, size ) )
1870 if ( brushStyle == Qt::NoBrush )
1882 Qt::PenStyle penStyle,
const QColor& color,
double width,
1883 const Qt::PenJoinStyle *penJoinStyle,
const Qt::PenCapStyle *penCapStyle,
1889 if ( penStyle == Qt::CustomDashLine && !customDashPattern )
1891 element.
appendChild( doc.
createComment(
"WARNING: Custom dash pattern required but not provided. Using default dash pattern." ) );
1892 penStyle = Qt::DashLine;
1911 case Qt::DashDotLine:
1917 case Qt::DashDotDotLine:
1926 case Qt::CustomDashLine:
1927 Q_ASSERT( customDashPattern );
1928 pattern = customDashPattern;
1939 if ( color.
alpha() < 255 )
1959 Qt::PenStyle &penStyle,
QColor &color,
double &width,
1960 Qt::PenJoinStyle *penJoinStyle, Qt::PenCapStyle *penCapStyle,
1965 penStyle = Qt::SolidLine;
1966 color =
QColor(
"#000000" );
1969 *penJoinStyle = Qt::BevelJoin;
1971 *penCapStyle = Qt::SquareCap;
1972 if ( customDashPattern )
1973 customDashPattern->
clear();
1979 penStyle = Qt::NoPen;
1989 if ( it.key() ==
"stroke" )
1991 color =
QColor( it.value() );
1993 else if ( it.key() ==
"stroke-opacity" )
1997 else if ( it.key() ==
"stroke-width" )
2000 double w = it.value().toDouble( &ok );
2004 else if ( it.key() ==
"stroke-linejoin" && penJoinStyle )
2008 else if ( it.key() ==
"stroke-linecap" && penCapStyle )
2012 else if ( it.key() ==
"stroke-dasharray" )
2019 bool dashPatternFound =
false;
2021 if ( dashPattern.
count() == 2 )
2023 if ( dashPattern.
at( 0 ) == 4.0 &&
2024 dashPattern.
at( 1 ) == 2.0 )
2026 penStyle = Qt::DashLine;
2027 dashPatternFound =
true;
2029 else if ( dashPattern.
at( 0 ) == 1.0 &&
2030 dashPattern.
at( 1 ) == 2.0 )
2032 penStyle = Qt::DotLine;
2033 dashPatternFound =
true;
2036 else if ( dashPattern.
count() == 4 )
2038 if ( dashPattern.
at( 0 ) == 4.0 &&
2039 dashPattern.
at( 1 ) == 2.0 &&
2040 dashPattern.
at( 2 ) == 1.0 &&
2041 dashPattern.
at( 3 ) == 2.0 )
2043 penStyle = Qt::DashDotLine;
2044 dashPatternFound =
true;
2047 else if ( dashPattern.
count() == 6 )
2049 if ( dashPattern.
at( 0 ) == 4.0 &&
2050 dashPattern.
at( 1 ) == 2.0 &&
2051 dashPattern.
at( 2 ) == 1.0 &&
2052 dashPattern.
at( 3 ) == 2.0 &&
2053 dashPattern.
at( 4 ) == 1.0 &&
2054 dashPattern.
at( 5 ) == 2.0 )
2056 penStyle = Qt::DashDotDotLine;
2057 dashPatternFound =
true;
2062 if ( !dashPatternFound )
2064 if ( customDashPattern )
2066 penStyle = Qt::CustomDashLine;
2067 *customDashPattern = dashPattern;
2071 QgsDebugMsg(
"custom dash pattern required but not provided. Using default dash pattern." );
2072 penStyle = Qt::DashLine;
2077 else if ( it.key() ==
"stroke-dashoffset" && dashOffset )
2080 double d = it.value().toDouble( &ok );
2091 const QColor& color,
double size )
2111 QColor &color,
double &size )
2117 if ( externalGraphicElem.
isNull() )
2123 if ( !sizeElem.
isNull() )
2136 const QColor& color,
double size )
2152 fillToSld( doc, fillElem, Qt::SolidPattern, color );
2166 QColor &color,
double &size )
2181 if ( !markIndexElem.
isNull() )
2191 Qt::BrushStyle b = Qt::SolidPattern;
2197 if ( !sizeElem.
isNull() )
2210 double borderWidth,
double size )
2212 wellKnownMarkerToSld( doc, element, name, color, borderColor, Qt::SolidLine, borderWidth, size );
2216 const QString& name,
const QColor& color,
const QColor& borderColor, Qt::PenStyle borderStyle,
2217 double borderWidth,
double size )
2230 fillToSld( doc, fillElem, Qt::SolidPattern, color );
2238 lineToSld( doc, strokeElem, borderStyle, borderColor, borderWidth );
2253 double &borderWidth,
double &size )
2255 Qt::PenStyle borderStyle;
2261 double &borderWidth,
double &size )
2267 borderColor =
QColor(
"#000000" );
2276 if ( !wellKnownNameElem.
isNull() )
2279 QgsDebugMsg(
"found Mark with well known name: " + name );
2284 Qt::BrushStyle b = Qt::SolidPattern;
2290 lineFromSld( strokeElem, borderStyle, borderColor, borderWidth );
2295 if ( !sizeElem.
isNull() )
2308 if ( !rotationFunc.
isEmpty() )
2319 if ( !rotationElem.
isNull() )
2340 if ( !opacityElem.
isNull() )
2370 if ( displacementElem.
isNull() )
2374 if ( !dispXElem.
isNull() )
2379 offset.
setX( offsetX );
2383 if ( !dispYElem.
isNull() )
2388 offset.
setY( offsetY );
2396 const QColor& color,
double size )
2416 fillToSld( doc, fillElem, Qt::SolidPattern, color );
2422 Qt::PenJoinStyle joinStyle,
2423 Qt::PenCapStyle capStyle,
2428 penStyle.
append(
"PEN(" );
2431 penStyle.
append(
",w:" );
2437 if ( dashPattern && !dashPattern->
isEmpty() )
2439 penStyle.
append(
",p:\"" );
2441 for ( ; pIt != dashPattern->
constEnd(); ++pIt )
2454 penStyle.
append(
",cap:" );
2469 penStyle.
append(
",j:" );
2470 switch ( joinStyle )
2486 penStyle.
append(
",dp:" );
2498 brushStyle.
append(
"BRUSH(" );
2499 brushStyle.
append(
"fc:" );
2501 brushStyle.
append(
')' );
2542 if ( geometryElem.
isNull() )
2558 if ( !filterElem.
isNull() )
2573 if ( !filterElem.
isNull() )
2582 if ( element.
tagName() !=
"Filter" )
2621 onlineResourceElem.
setAttribute(
"xlink:type",
"simple" );
2635 if ( onlineResourceElem.
isNull() )
2638 path = onlineResourceElem.
attributeNS(
"http://www.w3.org/1999/xlink",
"href" );
2641 if ( formatElem.
isNull() )
2663 while ( !paramElem.
isNull() )
2665 if ( paramElem.
localName() ==
"SvgParameter" || paramElem.
localName() ==
"CssParameter" )
2687 params[ name ] = value;
2709 while ( !paramElem.
isNull() )
2715 params[ name ] = value;
2738 props[propKey] = propValue;
2766 if ( e.
tagName() ==
"symbol" )
2787 if ( it.key()[0] !=
'@' )
2791 subsymbols.
append( it.key() );
2794 if ( parts.
count() < 3 )
2796 QgsDebugMsg(
"found subsymbol with invalid name: " + it.key() );
2801 int symlayer = parts[2].toInt();
2803 if ( !symbols.
contains( symname ) )
2805 QgsDebugMsg(
"subsymbol references invalid symbol: " + symname );
2822 QgsDebugMsg(
"symbol layer refused subsymbol: " + it.key() );
2829 for (
int i = 0; i < subsymbols.
count(); i++ )
2830 symbols.
take( subsymbols[i] );
2851 qDeleteAll( symbols );
2863 if ( rampType ==
"gradient" )
2865 else if ( rampType ==
"random" )
2867 else if ( rampType ==
"colorbrewer" )
2869 else if ( rampType ==
"cpt-city" )
2873 QgsDebugMsg(
"unknown colorramp type " + rampType );
2898 return color.
name();
2908 for ( ; it != components.
end(); ++it )
2916 if ( colors.
length() > 0 )
2923 it = components.
begin();
2924 for ( ; it != components.
end(); ++it )
2932 if ( colors.
length() > 0 )
2939 it = components.
begin();
2940 for ( ; it != components.
end(); ++it )
2948 if ( colors.
length() > 0 )
2954 components = colorStr.
split(
'\n' );
2955 it = components.
begin();
2956 for ( ; it != components.
end(); ++it )
3013 if ( dragDataElem.
tagName() ==
"ColorSchemeModelDragData" )
3016 int nChildNodes = nodeList.
size();
3019 for (
int i = 0; i < nChildNodes; ++i )
3022 if ( currentElem.
isNull() )
3029 namedColor.second = currentElem.
attribute(
"label",
"" );
3031 mimeColors << namedColor;
3036 if ( mimeColors.
length() == 0 && data->
hasFormat(
"application/x-colorobject-list" ) )
3039 QByteArray encodedData = data->
data(
"application/x-colorobject-list" );
3044 if ( colorsNodes.
length() > 0 )
3048 int nChildNodes = colorNodeList.
size();
3051 for (
int i = 0; i < nChildNodes; ++i )
3055 if ( currentElem.
isNull() )
3063 if ( colorNodes.
length() > 0 )
3068 if ( colorParts.
length() < 3 )
3073 int red = colorParts.
at( 0 ).toDouble() * 255;
3074 int green = colorParts.
at( 1 ).toDouble() * 255;
3075 int blue = colorParts.
at( 2 ).toDouble() * 255;
3077 namedColor.first =
QColor( red, green, blue );
3078 if ( nameNodes.
length() > 0 )
3081 namedColor.second = nameElem.
text();
3083 mimeColors << namedColor;
3094 for ( ; it != parsedColors.
end(); ++it )
3096 mimeColors << qMakePair( *it,
QString() );
3106 mimeColors << qMakePair( mimeColor,
QString() );
3122 for ( ; colorIt != colorList.
constEnd(); ++colorIt )
3126 namedColor.
setAttribute(
"label", ( *colorIt ).second );
3139 for ( ; colorIt != colorList.
constEnd(); ++colorIt )
3141 colorListString << ( *colorIt ).
first.name();
3143 mimeData->
setText( colorListString.
join(
"\n" ) );
3146 if ( colorList.
length() > 0 )
3156 if ( !file.
open( QIODevice::ReadWrite ) )
3162 stream <<
"GIMP Palette" << endl;
3165 stream <<
"Name: QGIS Palette" << endl;
3169 stream <<
"Name: " << paletteName << endl;
3171 stream <<
"Columns: 4" << endl;
3172 stream <<
'#' << endl;
3176 QColor color = ( *colorIt ).first;
3182 stream <<
"\t" << (( *colorIt ).second.isEmpty() ? color.
name() : ( *colorIt ).second ) << endl;
3193 if ( !file.
open( QIODevice::ReadOnly ) )
3196 return importedColors;
3205 return importedColors;
3215 QRegExp nameRx(
"Name:\\s*(\\S.*)$" );
3216 if ( nameRx.
indexIn( line ) != -1 )
3218 name = nameRx.
cap( 1 );
3230 return importedColors;
3234 QRegExp rx(
"^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)(\\s.*)?$" );
3235 while ( !in.
atEnd() )
3238 if ( rx.
indexIn( line ) == -1 )
3262 importedColors << qMakePair( color, label );
3267 return importedColors;
3280 QRegExp hexColorAlphaRx(
"^\\s*#?([0-9a-fA-F]{6})([0-9a-fA-F]{2})\\s*$" );
3281 int hexColorIndex = hexColorAlphaRx.
indexIn( colorStr );
3290 containsAlpha =
false;
3296 if ( hexColorIndex > -1 )
3301 int alphaHex = hexColorAlphaRx.
cap( 2 ).
toInt( &alphaOk, 16 );
3303 if ( parsedColor.
isValid() && alphaOk )
3306 containsAlpha =
true;
3314 QRegExp hexColorRx2(
"^\\s*(?:[0-9a-fA-F]{3}){1,2}\\s*$" );
3315 if ( hexColorRx2.
indexIn( colorStr ) != -1 )
3321 containsAlpha =
false;
3328 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*$" );
3329 if ( rgbFormatRx.
indexIn( colorStr ) != -1 )
3331 int r = rgbFormatRx.
cap( 1 ).
toInt();
3332 int g = rgbFormatRx.
cap( 2 ).
toInt();
3333 int b = rgbFormatRx.
cap( 3 ).
toInt();
3334 parsedColor.
setRgb( r, g, b );
3337 containsAlpha =
false;
3343 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*$" );
3344 if ( rgbPercentFormatRx.
indexIn( colorStr ) != -1 )
3346 int r = qRound( rgbPercentFormatRx.
cap( 1 ).
toDouble() * 2.55 );
3347 int g = qRound( rgbPercentFormatRx.
cap( 2 ).
toDouble() * 2.55 );
3348 int b = qRound( rgbPercentFormatRx.
cap( 3 ).
toDouble() * 2.55 );
3349 parsedColor.
setRgb( r, g, b );
3352 containsAlpha =
false;
3358 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*$" );
3359 if ( rgbaFormatRx.
indexIn( colorStr ) != -1 )
3361 int r = rgbaFormatRx.
cap( 1 ).
toInt();
3362 int g = rgbaFormatRx.
cap( 2 ).
toInt();
3363 int b = rgbaFormatRx.
cap( 3 ).
toInt();
3364 int a = qRound( rgbaFormatRx.
cap( 4 ).
toDouble() * 255.0 );
3365 parsedColor.
setRgb( r, g, b, a );
3368 containsAlpha =
true;
3374 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*$" );
3375 if ( rgbaPercentFormatRx.
indexIn( colorStr ) != -1 )
3377 int r = qRound( rgbaPercentFormatRx.
cap( 1 ).
toDouble() * 2.55 );
3378 int g = qRound( rgbaPercentFormatRx.
cap( 2 ).
toDouble() * 2.55 );
3379 int b = qRound( rgbaPercentFormatRx.
cap( 3 ).
toDouble() * 2.55 );
3380 int a = qRound( rgbaPercentFormatRx.
cap( 4 ).
toDouble() * 255.0 );
3381 parsedColor.
setRgb( r, g, b, a );
3384 containsAlpha =
true;
3424 double convertedSize = size * conversionFactor;
3435 return convertedSize;
3447 double minSizeMU = -DBL_MAX;
3456 size = qMax( size, minSizeMU );
3458 double maxSizeMU = DBL_MAX;
3467 size = qMin( size, maxSizeMU );
3560 QImage::Format format = image->
format();
3561 if ( format != QImage::Format_ARGB32_Premultiplied && format != QImage::Format_ARGB32 )
3568 for (
int heightIndex = 0; heightIndex < image->
height(); ++heightIndex )
3570 QRgb* scanLine =
reinterpret_cast< QRgb*
>( image->
scanLine( heightIndex ) );
3571 for (
int widthIndex = 0; widthIndex < image->
width(); ++widthIndex )
3573 myRgb = scanLine[widthIndex];
3574 if ( format == QImage::Format_ARGB32_Premultiplied )
3575 scanLine[widthIndex] = qRgba( alpha * qRed( myRgb ), alpha * qGreen( myRgb ), alpha * qBlue( myRgb ), alpha * qAlpha( myRgb ) );
3577 scanLine[widthIndex] = qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), alpha * qAlpha( myRgb ) );
3585 int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
3586 int alpha = ( radius < 1 ) ? 16 : ( radius > 17 ) ? 1 : tab[radius-1];
3588 if ( image.
format() != QImage::Format_ARGB32_Premultiplied
3589 && image.
format() != QImage::Format_RGB32 )
3594 int r1 = rect.
top();
3596 int c1 = rect.
left();
3597 int c2 = rect.
right();
3607 i1 = i2 = ( QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3 );
3609 for (
int col = c1; col <= c2; col++ )
3611 p = image.
scanLine( r1 ) + col * 4;
3612 for (
int i = i1; i <= i2; i++ )
3613 rgba[i] = p[i] << 4;
3616 for (
int j = r1; j < r2; j++, p += bpl )
3617 for (
int i = i1; i <= i2; i++ )
3618 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3621 for (
int row = r1; row <= r2; row++ )
3623 p = image.
scanLine( row ) + c1 * 4;
3624 for (
int i = i1; i <= i2; i++ )
3625 rgba[i] = p[i] << 4;
3628 for (
int j = c1; j < c2; j++, p += 4 )
3629 for (
int i = i1; i <= i2; i++ )
3630 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3633 for (
int col = c1; col <= c2; col++ )
3635 p = image.
scanLine( r2 ) + col * 4;
3636 for (
int i = i1; i <= i2; i++ )
3637 rgba[i] = p[i] << 4;
3640 for (
int j = r1; j < r2; j++, p -= bpl )
3641 for (
int i = i1; i <= i2; i++ )
3642 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3645 for (
int row = r1; row <= r2; row++ )
3647 p = image.
scanLine( row ) + c2 * 4;
3648 for (
int i = i1; i <= i2; i++ )
3649 rgba[i] = p[i] << 4;
3652 for (
int j = c1; j < c2; j++, p -= 4 )
3653 for (
int i = i1; i <= i2; i++ )
3654 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3660 if ( alpha != 255 && alpha > 0 )
3664 double alphaFactor = alpha / 255.;
3665 int r = 0, g = 0, b = 0;
3666 rgb.
getRgb( &r, &g, &b );
3671 rgb.
setRgb( r, g, b, alpha );
3673 else if ( alpha == 0 )
3675 rgb.
setRgb( 0, 0, 0, 0 );
3681 if ( order == Qt::AscendingOrder )
3695 double dx = directionPoint.
x() - startPoint.
x();
3696 double dy = directionPoint.
y() - startPoint.
y();
3697 double length = sqrt( dx * dx + dy * dy );
3698 double scaleFactor = distance / length;
3699 return QPointF( startPoint.
x() + dx * scaleFactor, startPoint.
y() + dy * scaleFactor );
3709 for (
int i = 0; i < svgPaths.
size(); i++ )
3711 QDir dir( svgPaths[i] );
3712 Q_FOREACH (
const QString& item, dir.
entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
3714 svgPaths.
insert( i + 1, dir.
path() +
'/' + item );
3733 svgPaths.
append( directory );
3735 for (
int i = 0; i < svgPaths.
size(); i++ )
3737 QDir dir( svgPaths[i] );
3738 Q_FOREACH (
const QString& item, dir.
entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
3740 svgPaths.
insert( i + 1, dir.
path() +
'/' + item );
3757 if (
QFile( name ).exists() )
3766 if ( url.
scheme().
compare(
"file", Qt::CaseInsensitive ) == 0 )
3770 if (
QFile( name ).exists() )
3786 for (
int i = 0; i < svgPaths.
size(); i++ )
3788 QString svgPath = svgPaths[i];
3802 QgsDebugMsg(
"Alternative svg path: " + myLocalPath );
3803 if (
QFile( myLocalPath ).exists() )
3811 if (
QFile( alternatePath ).exists() )
3821 QgsDebugMsg(
"Computed alternate path but no svg there either" );
3838 bool isInSvgPathes =
false;
3839 for (
int i = 0; i < svgPaths.
size(); i++ )
3845 path = path.
mid( dir.
size() + 1 );
3846 isInSvgPathes =
true;
3851 if ( isInSvgPathes )
3860 double cx = 0, cy = 0;
3861 double area, sum = 0;
3862 for (
int i = points.
count() - 1, j = 0; j < points.
count(); i = j++ )
3864 const QPointF& p1 = points[i];
3865 const QPointF& p2 = points[j];
3866 area = p1.
x() * p2.
y() - p1.
y() * p2.
x();
3868 cx += ( p1.
x() + p2.
x() ) * area;
3869 cy += ( p1.
y() + p2.
y() ) * area;
3876 if ( points.
count() >= 2 )
3877 return QPointF(( points[0].x() + points[1].x() ) / 2, ( points[0].y() + points[1].y() ) / 2 );
3878 else if ( points.
count() == 1 )
3896 unsigned int i, pointCount = points.
count();
3899 for ( i = 0; i < pointCount; ++i ) polyline[i] =
QgsPoint( points[i].x(), points[i].y() );
3906 if ( pointOnSurfaceGeom )
3909 delete pointOnSurfaceGeom;
3922 bool inside =
false;
3924 double x = point.
x();
3925 double y = point.
y();
3927 for (
int i = 0, j = points.
count() - 1; i < points.
count(); i++ )
3929 const QPointF& p1 = points[i];
3930 const QPointF& p2 = points[j];
3935 if (( p1.
y() < y && p2.
y() >= y ) || ( p2.
y() < y && p1.
y() >= y ) )
3937 if ( p1.
x() + ( y - p1.
y() ) / ( p2.
y() - p1.
y() )*( p2.
x() - p1.
x() ) <= x )
3948 if ( fieldOrExpression.
isEmpty() )
3967 return static_cast<const QgsExpression::NodeColumnRef*>( n )->name();
3986 breaks.
append( maximum );
3990 int minimumCount =
static_cast< int >( classes ) / 3;
3991 double shrink = 0.75;
3992 double highBias = 1.5;
3993 double adjustBias = 0.5 + 1.5 * highBias;
3994 int divisions = classes;
3995 double h = highBias;
3999 double dx = maximum - minimum;
4009 cell = qMax( qAbs( minimum ), qAbs( maximum ) );
4010 if ( adjustBias >= 1.5 * h + 0.5 )
4012 U = 1 + ( 1.0 / ( 1 + h ) );
4016 U = 1 + ( 1.5 / ( 1 + adjustBias ) );
4018 small = dx < ( cell * U * qMax( 1, divisions ) * 1e-07 * 3.0 );
4025 cell = 9 + cell / 10;
4026 cell = cell * shrink;
4028 if ( minimumCount > 1 )
4030 cell = cell / minimumCount;
4036 if ( divisions > 1 )
4038 cell = cell / divisions;
4041 if ( cell < 20 * 1e-07 )
4046 double base = pow( 10.0, floor( log10( cell ) ) );
4048 if (( 2 * base ) - cell < h *( cell - unit ) )
4051 if (( 5 * base ) - cell < adjustBias *( cell - unit ) )
4054 if (( 10.0 * base ) - cell < h *( cell - unit ) )
4061 int start = floor( minimum / unit + 1e-07 );
4062 int end = ceil( maximum / unit - 1e-07 );
4065 while ( start * unit > minimum + ( 1e-07 * unit ) )
4069 while ( end * unit < maximum - ( 1e-07 * unit ) )
4077 int k = floor( 0.5 + end - start );
4078 if ( k < minimumCount )
4080 k = minimumCount - k;
4084 start = start - k / 2 + k % 2;
4088 start = start - k / 2;
4089 end = end + k / 2 + k % 2;
4092 double minimumBreak = start * unit;
4094 int count = end - start;
4097 for (
int i = 1; i < count + 1; i++ )
4099 breaks.
append( minimumBreak + i * unit );
4105 if ( breaks.
first() < minimum )
4107 breaks[0] = minimum;
4109 if ( breaks.
last() > maximum )
4111 breaks[breaks.
count()-1] = maximum;
4120 bool roundToUnit =
false;
4123 if ( props.
contains(
"uomScale" ) )
4126 scale = props.
value(
"uomScale" ).toDouble( &ok );
4135 if ( props.
value(
"uom" ) ==
"http://www.opengeospatial.org/se/units/metre" )
4166 double rescaled = size * scale;
4171 rescaled = qRound( rescaled );
4187 for ( ; it != array.
constEnd(); ++it )
4196 if ( !props.
value(
"scaleMinDenom",
"" ).isEmpty() )
4203 if ( !props.
value(
"scaleMaxDenom",
"" ).isEmpty() )
4213 if ( mScaleMinDenom != 0 )
4216 int parentScaleMinDenom = props.
value(
"scaleMinDenom",
"0" ).toInt( &ok );
4217 if ( !ok || parentScaleMinDenom <= 0 )
4220 props[
"scaleMinDenom" ] =
QString::number( qMax( parentScaleMinDenom, mScaleMinDenom ) );
4223 if ( mScaleMaxDenom != 0 )
4226 int parentScaleMaxDenom = props.
value(
"scaleMaxDenom",
"0" ).toInt( &ok );
4227 if ( !ok || parentScaleMaxDenom <= 0 )
4230 props[
"scaleMaxDenom" ] =
QString::number( qMin( parentScaleMaxDenom, mScaleMaxDenom ) );
4238 if ( uom ==
QLatin1String(
"http://www.opengeospatial.org/se/units/metre" ) )
4240 scale = 1.0 / 0.00028;
4242 else if ( uom ==
QLatin1String(
"http://www.opengeospatial.org/se/units/foot" ) )
4244 scale = 304.8 / 0.28;
4251 return size * scale;
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.
double rendererScale() const
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
Returns a string representing the color ramp type.
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
static double sizeInPixelsFromSldUom(const QString &uom, double size)
Returns the size scaled in pixels according to the uom attribute.
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.
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
Returns a string map containing all the color ramp's properties.
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)
NodeType nodeType() const
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)
Compare two doubles (but allow some difference)
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
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
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
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)
double mapUnitsPerPixel() const
Return current map units per pixel.
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)
static double convertToMapUnits(const QgsRenderContext &c, double size, QgsSymbolV2::OutputUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale())
Converts a size from the specied units to map units.
QString toLocalFile() const
virtual QColor color(double value) const =0
Returns the color corresponding to a specified value.
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())
Creates a new QgsVectorColorRampV2 from a map of properties.
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
const QgsMapToPixel & mapToPixel() 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)
QString readPath(QString filename, const QString &relativeBasePath=QString()) const
Turn filename read from the project file to an absolute path.
static QgsProject * instance()
Returns the QgsProject singleton 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
Abstract base class for color ramps.
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)
QString writePath(const QString &filename, const QString &relativeBasePath=QString()) const
Prepare a filename to save it to the project file.
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.