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() )
2581 if ( element.
tagName() !=
"Filter" )
2620 onlineResourceElem.
setAttribute(
"xlink:type",
"simple" );
2634 if ( onlineResourceElem.
isNull() )
2637 path = onlineResourceElem.
attributeNS(
"http://www.w3.org/1999/xlink",
"href" );
2640 if ( formatElem.
isNull() )
2662 while ( !paramElem.
isNull() )
2664 if ( paramElem.
localName() ==
"SvgParameter" || paramElem.
localName() ==
"CssParameter" )
2686 params[ name ] = value;
2708 while ( !paramElem.
isNull() )
2714 params[ name ] = value;
2737 props[propKey] = propValue;
2765 if ( e.
tagName() ==
"symbol" )
2786 if ( it.key()[0] !=
'@' )
2790 subsymbols.
append( it.key() );
2793 if ( parts.
count() < 3 )
2795 QgsDebugMsg(
"found subsymbol with invalid name: " + it.key() );
2800 int symlayer = parts[2].toInt();
2802 if ( !symbols.
contains( symname ) )
2804 QgsDebugMsg(
"subsymbol references invalid symbol: " + symname );
2821 QgsDebugMsg(
"symbol layer refused subsymbol: " + it.key() );
2828 for (
int i = 0; i < subsymbols.
count(); i++ )
2829 symbols.
take( subsymbols[i] );
2850 qDeleteAll( symbols );
2862 if ( rampType ==
"gradient" )
2864 else if ( rampType ==
"random" )
2866 else if ( rampType ==
"colorbrewer" )
2868 else if ( rampType ==
"cpt-city" )
2872 QgsDebugMsg(
"unknown colorramp type " + rampType );
2897 return color.
name();
2907 for ( ; it != components.
end(); ++it )
2915 if ( colors.
length() > 0 )
2922 it = components.
begin();
2923 for ( ; it != components.
end(); ++it )
2931 if ( colors.
length() > 0 )
2938 it = components.
begin();
2939 for ( ; it != components.
end(); ++it )
2947 if ( colors.
length() > 0 )
2953 components = colorStr.
split(
'\n' );
2954 it = components.
begin();
2955 for ( ; it != components.
end(); ++it )
3012 if ( dragDataElem.
tagName() ==
"ColorSchemeModelDragData" )
3015 int nChildNodes = nodeList.
size();
3018 for (
int i = 0; i < nChildNodes; ++i )
3021 if ( currentElem.
isNull() )
3028 namedColor.second = currentElem.
attribute(
"label",
"" );
3030 mimeColors << namedColor;
3035 if ( mimeColors.
length() == 0 && data->
hasFormat(
"application/x-colorobject-list" ) )
3038 QByteArray encodedData = data->
data(
"application/x-colorobject-list" );
3043 if ( colorsNodes.
length() > 0 )
3047 int nChildNodes = colorNodeList.
size();
3050 for (
int i = 0; i < nChildNodes; ++i )
3054 if ( currentElem.
isNull() )
3062 if ( colorNodes.
length() > 0 )
3067 if ( colorParts.
length() < 3 )
3072 int red = colorParts.
at( 0 ).toDouble() * 255;
3073 int green = colorParts.
at( 1 ).toDouble() * 255;
3074 int blue = colorParts.
at( 2 ).toDouble() * 255;
3076 namedColor.first =
QColor( red, green, blue );
3077 if ( nameNodes.
length() > 0 )
3080 namedColor.second = nameElem.
text();
3082 mimeColors << namedColor;
3093 for ( ; it != parsedColors.
end(); ++it )
3095 mimeColors << qMakePair( *it,
QString() );
3105 mimeColors << qMakePair( mimeColor,
QString() );
3121 for ( ; colorIt != colorList.
constEnd(); ++colorIt )
3125 namedColor.
setAttribute(
"label", ( *colorIt ).second );
3138 for ( ; colorIt != colorList.
constEnd(); ++colorIt )
3140 colorListString << ( *colorIt ).
first.name();
3142 mimeData->
setText( colorListString.
join(
"\n" ) );
3145 if ( colorList.
length() > 0 )
3155 if ( !file.
open( QIODevice::ReadWrite ) )
3161 stream <<
"GIMP Palette" << endl;
3164 stream <<
"Name: QGIS Palette" << endl;
3168 stream <<
"Name: " << paletteName << endl;
3170 stream <<
"Columns: 4" << endl;
3171 stream <<
'#' << endl;
3175 QColor color = ( *colorIt ).first;
3181 stream <<
"\t" << (( *colorIt ).second.isEmpty() ? color.
name() : ( *colorIt ).second ) << endl;
3192 if ( !file.
open( QIODevice::ReadOnly ) )
3195 return importedColors;
3204 return importedColors;
3214 QRegExp nameRx(
"Name:\\s*(\\S.*)$" );
3215 if ( nameRx.
indexIn( line ) != -1 )
3217 name = nameRx.
cap( 1 );
3229 return importedColors;
3233 QRegExp rx(
"^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)(\\s.*)?$" );
3234 while ( !in.
atEnd() )
3237 if ( rx.
indexIn( line ) == -1 )
3261 importedColors << qMakePair( color, label );
3266 return importedColors;
3286 containsAlpha =
false;
3292 QRegExp hexColorAlphaRx(
"^\\s*#?([0-9a-fA-F]{6})([0-9a-fA-F]{2})\\s*$" );
3293 if ( hexColorAlphaRx.
indexIn( colorStr ) != -1 )
3298 int alphaHex = hexColorAlphaRx.
cap( 2 ).
toInt( &alphaOk, 16 );
3300 if ( parsedColor.
isValid() && alphaOk )
3303 containsAlpha =
true;
3311 QRegExp hexColorRx2(
"^\\s*(?:[0-9a-fA-F]{3}){1,2}\\s*$" );
3312 if ( hexColorRx2.
indexIn( colorStr ) != -1 )
3318 containsAlpha =
false;
3325 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*$" );
3326 if ( rgbFormatRx.
indexIn( colorStr ) != -1 )
3328 int r = rgbFormatRx.
cap( 1 ).
toInt();
3329 int g = rgbFormatRx.
cap( 2 ).
toInt();
3330 int b = rgbFormatRx.
cap( 3 ).
toInt();
3331 parsedColor.
setRgb( r, g, b );
3334 containsAlpha =
false;
3340 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*$" );
3341 if ( rgbPercentFormatRx.
indexIn( colorStr ) != -1 )
3343 int r = qRound( rgbPercentFormatRx.
cap( 1 ).
toDouble() * 2.55 );
3344 int g = qRound( rgbPercentFormatRx.
cap( 2 ).
toDouble() * 2.55 );
3345 int b = qRound( rgbPercentFormatRx.
cap( 3 ).
toDouble() * 2.55 );
3346 parsedColor.
setRgb( r, g, b );
3349 containsAlpha =
false;
3355 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*$" );
3356 if ( rgbaFormatRx.
indexIn( colorStr ) != -1 )
3358 int r = rgbaFormatRx.
cap( 1 ).
toInt();
3359 int g = rgbaFormatRx.
cap( 2 ).
toInt();
3360 int b = rgbaFormatRx.
cap( 3 ).
toInt();
3361 int a = qRound( rgbaFormatRx.
cap( 4 ).
toDouble() * 255.0 );
3362 parsedColor.
setRgb( r, g, b, a );
3365 containsAlpha =
true;
3371 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*$" );
3372 if ( rgbaPercentFormatRx.
indexIn( colorStr ) != -1 )
3374 int r = qRound( rgbaPercentFormatRx.
cap( 1 ).
toDouble() * 2.55 );
3375 int g = qRound( rgbaPercentFormatRx.
cap( 2 ).
toDouble() * 2.55 );
3376 int b = qRound( rgbaPercentFormatRx.
cap( 3 ).
toDouble() * 2.55 );
3377 int a = qRound( rgbaPercentFormatRx.
cap( 4 ).
toDouble() * 255.0 );
3378 parsedColor.
setRgb( r, g, b, a );
3381 containsAlpha =
true;
3421 double convertedSize = size * conversionFactor;
3432 return convertedSize;
3507 QImage::Format format = image->
format();
3508 if ( format != QImage::Format_ARGB32_Premultiplied && format != QImage::Format_ARGB32 )
3515 for (
int heightIndex = 0; heightIndex < image->
height(); ++heightIndex )
3517 QRgb* scanLine =
reinterpret_cast< QRgb*
>( image->
scanLine( heightIndex ) );
3518 for (
int widthIndex = 0; widthIndex < image->
width(); ++widthIndex )
3520 myRgb = scanLine[widthIndex];
3521 if ( format == QImage::Format_ARGB32_Premultiplied )
3522 scanLine[widthIndex] = qRgba( alpha * qRed( myRgb ), alpha * qGreen( myRgb ), alpha * qBlue( myRgb ), alpha * qAlpha( myRgb ) );
3524 scanLine[widthIndex] = qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), alpha * qAlpha( myRgb ) );
3532 int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
3533 int alpha = ( radius < 1 ) ? 16 : ( radius > 17 ) ? 1 : tab[radius-1];
3535 if ( image.
format() != QImage::Format_ARGB32_Premultiplied
3536 && image.
format() != QImage::Format_RGB32 )
3541 int r1 = rect.
top();
3543 int c1 = rect.
left();
3544 int c2 = rect.
right();
3554 i1 = i2 = ( QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3 );
3556 for (
int col = c1; col <= c2; col++ )
3558 p = image.
scanLine( r1 ) + col * 4;
3559 for (
int i = i1; i <= i2; i++ )
3560 rgba[i] = p[i] << 4;
3563 for (
int j = r1; j < r2; j++, p += bpl )
3564 for (
int i = i1; i <= i2; i++ )
3565 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3568 for (
int row = r1; row <= r2; row++ )
3570 p = image.
scanLine( row ) + c1 * 4;
3571 for (
int i = i1; i <= i2; i++ )
3572 rgba[i] = p[i] << 4;
3575 for (
int j = c1; j < c2; j++, p += 4 )
3576 for (
int i = i1; i <= i2; i++ )
3577 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3580 for (
int col = c1; col <= c2; col++ )
3582 p = image.
scanLine( r2 ) + col * 4;
3583 for (
int i = i1; i <= i2; i++ )
3584 rgba[i] = p[i] << 4;
3587 for (
int j = r1; j < r2; j++, p -= bpl )
3588 for (
int i = i1; i <= i2; i++ )
3589 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3592 for (
int row = r1; row <= r2; row++ )
3594 p = image.
scanLine( row ) + c2 * 4;
3595 for (
int i = i1; i <= i2; i++ )
3596 rgba[i] = p[i] << 4;
3599 for (
int j = c1; j < c2; j++, p -= 4 )
3600 for (
int i = i1; i <= i2; i++ )
3601 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3607 if ( alpha != 255 && alpha > 0 )
3611 double alphaFactor = alpha / 255.;
3612 int r = 0, g = 0, b = 0;
3613 rgb.
getRgb( &r, &g, &b );
3618 rgb.
setRgb( r, g, b, alpha );
3620 else if ( alpha == 0 )
3622 rgb.
setRgb( 0, 0, 0, 0 );
3628 if ( order == Qt::AscendingOrder )
3642 double dx = directionPoint.
x() - startPoint.
x();
3643 double dy = directionPoint.
y() - startPoint.
y();
3644 double length = sqrt( dx * dx + dy * dy );
3645 double scaleFactor = distance / length;
3646 return QPointF( startPoint.
x() + dx * scaleFactor, startPoint.
y() + dy * scaleFactor );
3656 for (
int i = 0; i < svgPaths.
size(); i++ )
3658 QDir dir( svgPaths[i] );
3659 Q_FOREACH (
const QString& item, dir.
entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
3661 svgPaths.
insert( i + 1, dir.
path() +
'/' + item );
3680 svgPaths.
append( directory );
3682 for (
int i = 0; i < svgPaths.
size(); i++ )
3684 QDir dir( svgPaths[i] );
3685 Q_FOREACH (
const QString& item, dir.
entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
3687 svgPaths.
insert( i + 1, dir.
path() +
'/' + item );
3704 if (
QFile( name ).exists() )
3713 if ( url.
scheme().
compare(
"file", Qt::CaseInsensitive ) == 0 )
3717 if (
QFile( name ).exists() )
3733 for (
int i = 0; i < svgPaths.
size(); i++ )
3735 QString svgPath = svgPaths[i];
3749 QgsDebugMsg(
"Alternative svg path: " + myLocalPath );
3750 if (
QFile( myLocalPath ).exists() )
3769 QgsDebugMsg(
"Computed alternate path but no svg there either" );
3786 bool isInSvgPathes =
false;
3787 for (
int i = 0; i < svgPaths.
size(); i++ )
3793 path = path.
mid( dir.
size() + 1 );
3794 isInSvgPathes =
true;
3799 if ( isInSvgPathes )
3808 double cx = 0, cy = 0;
3809 double area, sum = 0;
3810 for (
int i = points.
count() - 1, j = 0; j < points.
count(); i = j++ )
3812 const QPointF& p1 = points[i];
3813 const QPointF& p2 = points[j];
3814 area = p1.
x() * p2.
y() - p1.
y() * p2.
x();
3816 cx += ( p1.
x() + p2.
x() ) * area;
3817 cy += ( p1.
y() + p2.
y() ) * area;
3824 if ( points.
count() >= 2 )
3825 return QPointF(( points[0].x() + points[1].x() ) / 2, ( points[0].y() + points[1].y() ) / 2 );
3826 else if ( points.
count() == 1 )
3844 unsigned int i, pointCount = points.
count();
3847 for ( i = 0; i < pointCount; ++i ) polyline[i] =
QgsPoint( points[i].x(), points[i].y() );
3854 if ( pointOnSurfaceGeom )
3857 delete pointOnSurfaceGeom;
3870 bool inside =
false;
3872 double x = point.
x();
3873 double y = point.
y();
3875 for (
int i = 0, j = points.
count() - 1; i < points.
count(); i++ )
3877 const QPointF& p1 = points[i];
3878 const QPointF& p2 = points[j];
3883 if (( p1.
y() < y && p2.
y() >= y ) || ( p2.
y() < y && p1.
y() >= y ) )
3885 if ( p1.
x() + ( y - p1.
y() ) / ( p2.
y() - p1.
y() )*( p2.
x() - p1.
x() ) <= x )
3896 if ( fieldOrExpression.
isEmpty() )
3915 return static_cast<const QgsExpression::NodeColumnRef*>( n )->name();
3934 breaks.
append( maximum );
3938 int minimumCount =
static_cast< int >( classes ) / 3;
3939 double shrink = 0.75;
3940 double highBias = 1.5;
3941 double adjustBias = 0.5 + 1.5 * highBias;
3942 int divisions = classes;
3943 double h = highBias;
3947 double dx = maximum - minimum;
3957 cell = qMax( qAbs( minimum ), qAbs( maximum ) );
3958 if ( adjustBias >= 1.5 * h + 0.5 )
3960 U = 1 + ( 1.0 / ( 1 + h ) );
3964 U = 1 + ( 1.5 / ( 1 + adjustBias ) );
3966 small = dx < ( cell * U * qMax( 1, divisions ) * 1e-07 * 3.0 );
3973 cell = 9 + cell / 10;
3974 cell = cell * shrink;
3976 if ( minimumCount > 1 )
3978 cell = cell / minimumCount;
3984 if ( divisions > 1 )
3986 cell = cell / divisions;
3989 if ( cell < 20 * 1e-07 )
3994 double base = pow( 10.0, floor( log10( cell ) ) );
3996 if (( 2 * base ) - cell < h *( cell - unit ) )
3999 if (( 5 * base ) - cell < adjustBias *( cell - unit ) )
4002 if (( 10.0 * base ) - cell < h *( cell - unit ) )
4009 int start = floor( minimum / unit + 1e-07 );
4010 int end = ceil( maximum / unit - 1e-07 );
4013 while ( start * unit > minimum + ( 1e-07 * unit ) )
4017 while ( end * unit < maximum - ( 1e-07 * unit ) )
4025 int k = floor( 0.5 + end - start );
4026 if ( k < minimumCount )
4028 k = minimumCount - k;
4032 start = start - k / 2 + k % 2;
4036 start = start - k / 2;
4037 end = end + k / 2 + k % 2;
4040 double minimumBreak = start * unit;
4042 int count = end - start;
4045 for (
int i = 1; i < count + 1; i++ )
4047 breaks.
append( minimumBreak + i * unit );
4053 if ( breaks.
first() < minimum )
4055 breaks[0] = minimum;
4057 if ( breaks.
last() > maximum )
4059 breaks[breaks.
count()-1] = maximum;
4068 bool roundToUnit =
false;
4071 if ( props.
contains(
"uomScale" ) )
4074 scale = props.
value(
"uomScale" ).toDouble( &ok );
4083 if ( props.
value(
"uom" ) ==
"http://www.opengeospatial.org/se/units/metre" )
4114 double rescaled = size * scale;
4119 rescaled = qRound( rescaled );
4135 for ( ; it != array.
constEnd(); ++it )
4144 if ( !props.
value(
"scaleMinDenom",
"" ).isEmpty() )
4151 if ( !props.
value(
"scaleMaxDenom",
"" ).isEmpty() )
4161 if ( mScaleMinDenom != 0 )
4164 int parentScaleMinDenom = props.
value(
"scaleMinDenom",
"0" ).toInt( &ok );
4165 if ( !ok || parentScaleMinDenom <= 0 )
4168 props[
"scaleMinDenom" ] =
QString::number( qMax( parentScaleMinDenom, mScaleMinDenom ) );
4171 if ( mScaleMaxDenom != 0 )
4174 int parentScaleMaxDenom = props.
value(
"scaleMaxDenom",
"0" ).toInt( &ok );
4175 if ( !ok || parentScaleMaxDenom <= 0 )
4178 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)
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)
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.